TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Raffiner_isotrope_parallele.cpp
1/****************************************************************************
2* Copyright (c) 2026, CEA
3* All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9*
10* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
11* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
12* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13*
14*****************************************************************************/
15
16#include <Raffiner_isotrope_parallele.h>
17#include <Reordonner_faces_periodiques.h>
18#include <LecFicDistribue.h>
19#include <EcrFicCollecte.h>
20#include <FichierHDFPar.h>
21#include <LecFicDiffuse.h>
22#include <TRUSTArrays.h>
23#include <Schema_Comm.h>
24#include <TRUSTTabs.h>
25#include <SFichier.h>
26#include <Domaine.h>
27#include <Scatter.h>
28#include <Param.h>
29#include <Nom.h>
30
31Implemente_instanciable( Raffiner_isotrope_parallele, "Raffiner_isotrope_parallele", Raffiner_Simplexes ) ;
32
34{
36 return os;
37}
38
40{
42 return is;
43}
44
45
47{
48 int form=0;
49 bool format_hdf = false;
50 Nom org,newd;
51 Param param(que_suis_je());
52
53 // XD Raffiner_isotrope_parallele interprete Raffiner_isotrope_parallele BRACE Refine parallel mesh in parallel
54 param.ajouter("name_of_initial_domaines|name_of_initial_zones",&org,Param::REQUIRED); // XD_ADD_P chaine
55 // XD_CONT name of initial Domaines
56 param.ajouter("name_of_new_domaines|name_of_new_zones",&newd,Param::REQUIRED); // XD_ADD_P chaine
57 // XD_CONT name of new Domaines
58 param.ajouter("ascii",&form); // XD_ADD_P flag
59 // XD_CONT writing Domaines in ascii format
60 param.ajouter_flag("single_hdf",&format_hdf); // XD_ADD_P rien
61 // XD_CONT writing Domaines in hdf format
62 param.lire_avec_accolades(is);
63
64 // Force a single file beyond a certain number of MPI ranks:
65 if (Process::force_single_file(Process::nproc(), org+".Zones"))
66 format_hdf = true;
67 int binaire=!form;
68 if (form && format_hdf)
69 {
70 Cerr << "Raffiner_isotrope_parallele::interpreter(): options 'ascii' and 'single_hdf' are mutually exclusive!" << finl;
72 }
73 Domaine dom_org;
74 Noms& liste_bords_periodiques = dom_org.bords_perio();
75
76 org+=".Zones";
77
78 Nom copy(org);
79 copy = copy.nom_me(Process::nproc(), "p", 1);
80 //bool is_hdf = FichierHDF::is_hdf5(copy);
81 LecFicDiffuse test;
82 bool is_hdf = test.ouvrir(copy) && FichierHDF::is_hdf5(copy);
83 bool has_perio = false;
84
85 if (!is_hdf)
86 {
87 LecFicDistribue fichier;
88 fichier.set_bin(binaire);
89 fichier.ouvrir(org);
90 dom_org.readOn_has_perio(fichier, has_perio);
91 dom_org.set_fichier_lu(org);
92 if (!has_perio) // Old (pre TRUST 1.9.8) Domain format - periodic boundaries stored after:
93 fichier >> liste_bords_periodiques;
94 }
95 else
96 {
97 FichierHDFPar fic_hdf;
98 org = copy;
99 fic_hdf.open(org, true);
100 Entree_Brute data;
101 fic_hdf.read_dataset("//zone", Process::me(), data);
102 // Feed TRUST objects:
103 dom_org.readOn_has_perio(data, has_perio);
104 dom_org.set_fichier_lu(org);
105 if (!has_perio) // Old (pre TRUST 1.9.8) Domain format - periodic boundaries stored after:
106 data >> liste_bords_periodiques;
107 fic_hdf.close();
108 }
109
111 Domaine dom_new(dom_org);
112 dom_new.typer(dom_org.type_elem()->que_suis_je());
113
114 refine_domain(dom_org,dom_new);
115
116 // After spliting the mesh and the boundaries, we reorder perdiodic faces:
117 for (auto nom_bord : liste_bords_periodiques)
118 {
119 Cerr << "Reordering faces of the periodic boundary " << nom_bord << finl;
120 ArrOfDouble direction_perio;
121 Reordonner_faces_periodiques::chercher_direction_perio(direction_perio, dom_new, nom_bord);
122 Bord& bord = dom_new.bord(nom_bord);
123 IntTab& faces = bord.faces().les_sommets();
125 }
126
127 if (nproc() > 1)
128 {
130 int nb_sommet_avant_completion=dom_new.nb_som();
132
133 // Rebuild the correspondance between vertices, knowing that the number of common items
134 // has potentially changed.
135 statistics().begin_count(STD_COUNTERS::parallel_meshing,statistics().get_last_opened_counter_level()+1);
136 Scatter::construire_correspondance_sommets_par_coordonnees(dom_new, true /* allow resize of items_communs */);
137#ifndef NDEBUG
138 // In debug mode, we ensure exact matching of the updated items_communs by running the exchange a second time
139 // without expecting a resize of items_communs:
141#endif
142 double maxtime = mp_max(statistics().get_time_since_last_open(STD_COUNTERS::parallel_meshing));
143 statistics().end_count(STD_COUNTERS::parallel_meshing);
144 Cerr << "Scatter::construire_correspondance_sommets_par_coordonnees fin, time:"
145 << maxtime
146 << finl;
147
148 statistics().begin_count(STD_COUNTERS::parallel_meshing,statistics().get_last_opened_counter_level()+1);
150 maxtime = mp_max(statistics().get_time_since_last_open(STD_COUNTERS::parallel_meshing));
151 statistics().end_count(STD_COUNTERS::parallel_meshing);
152 Cerr << "Scatter::construire_structures_paralleles, time:" << maxtime << finl;
153
154 int ecrit=1;
155 if (ecrit)
156 {
157 int nb_elem_reel=dom_new.nb_elem();
159 dom_new.les_elems().resize( nb_elem_reel,dom_new.les_elems().dimension(1));
160 dom_new.les_sommets().resize(nb_sommet_avant_completion,dimension);
161
163 newd+=".Zones";
164
165 if( !format_hdf )
166 {
168 os.set_bin(binaire);
169 os.ouvrir(newd);
170 if (!binaire)
171 {
172 os.setf(ios::scientific);
174 }
175 os << dom_new;
176 }
177 else
178 {
179 Sortie_Brute os_hdf;
180 os_hdf << dom_new;
181 FichierHDFPar fic_hdf;
182 newd = newd.nom_me(Process::nproc(), "p", 1);
183 fic_hdf.create(newd);
184 fic_hdf.create_and_fill_dataset_MW("/zone", os_hdf);
185 fic_hdf.close();
186 }
187 }
188 }
189 else
191
192 return is;
193}
DoubleTab_t & les_sommets()
Definition Domaine.h:113
Entree & readOn_has_perio(Entree &s, bool &has_perio)
Reads the objects constituting a Domain from an input stream.
Definition Domaine.cpp:208
IntTab_t & les_elems()
Definition Domaine.h:129
int_t nb_elem() const
Definition Domaine.h:131
Bord_t & bord(int i)
Definition Domaine.h:193
void typer(const Nom &)
Sets the element type of the domain using the name passed as parameter.
Definition Domaine.h:457
Joints_t & faces_joint()
Definition Domaine.h:265
int_t nb_som() const
Returns the number of vertices of the domain.
Definition Domaine.h:121
const Noms & bords_perio() const
Definition Domaine.h:278
void set_fichier_lu(Nom &nom)
Writing to a file. This class implements the operators and virtual methods of the SFichier class as f...
int ouvrir(const char *name, IOS_OPEN_MODE mode=ios::out) override
Opens the file with the given mode and prot parameters. These parameters are the parameters of the st...
An Entree whose main source of data is an arbitrary binary buffer set using the set_data() method.
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
void set_bin(bool bin) override
Changes the file write mode.
Definition Entree.cpp:291
const IntTab_t & les_sommets() const
Returns the array of vertices of all faces.
Definition Faces.h:74
Parallel collective version of FichierHDF, to be used for all concurrent reading/writing on HDF files...
static bool is_hdf5(const char *file_name)
virtual void create_and_fill_dataset_MW(Nom dataset_basename, Sortie_Brute &sortie)
virtual void read_dataset(Nom dataset_basename, int proc_rank, Entree_Brute &entree)
virtual void open(Nom filename, bool readOnly)
virtual void close()
virtual void create(Nom filename)
const Faces_t & faces() const
Definition Frontiere.h:54
This class implements the operators and virtual methods of the EFichier class as follows: The file to...
int ouvrir(const char *name, IOS_OPEN_MODE mode=ios::in) override
Opens the file.
This class implements the operators and virtual methods of the EFichier class as follows: there are a...
int ouvrir(const char *name, IOS_OPEN_MODE mode=ios::in) override
Opens the file with the given mode and prot parameters. These parameters are the parameters of the st...
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
Nom nom_me(int, const char *prefix=0, int without_padding=0) const
Inserts _prefix000n (n=me() or nproc()) into a file name (e.g. toto.titi) to produce toto_prefix000n....
Definition Nom.cpp:380
An array of character strings (VECT(Nom)).
Definition Noms.h:26
static int dimension
Definition Objet_U.h:94
const Nom & que_suis_je() const
Returns the string identifying the class.
Definition Objet_U.cpp:104
virtual Entree & readOn(Entree &)
Reads an Objet_U from an input stream. Virtual method to override.
Definition Objet_U.cpp:289
static double precision_geom
Definition Objet_U.h:81
static int format_precision_geom
Definition Objet_U.h:95
virtual Sortie & printOn(Sortie &) const
Writes the object to an output stream. Virtual method to override.
Definition Objet_U.cpp:278
Helper class to factorize the readOn method of Objet_U classes.
Definition Param.h:112
void ajouter_flag(const char *keyword, const bool *value)
Register a boolean flag whose mere presence switches it to true.
Definition Param.cpp:474
void ajouter(const char *keyword, const int *value, Param::Nature nat=Param::OPTIONAL)
Register an integer parameter.
Definition Param.cpp:364
@ REQUIRED
Definition Param.h:115
int lire_avec_accolades(Entree &is)
Alias of lire_avec_accolades_depuis.
Definition Param.h:577
static double mp_max(double)
Definition Process.cpp:379
static int nproc()
Returns the number of processors in the current group. See Comm_Group::nproc() and PE_Groups::current...
Definition Process.cpp:102
static bool force_single_file(const int ranks, const Nom &filename)
Definition Process.cpp:57
static int me()
Returns the rank of the local processor in the current communication group. See Comm_Group::rank() an...
Definition Process.cpp:122
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Definition Process.cpp:466
void refine_domain(const Domaine_t &src, Domaine_t &dest)
Refine the mesh once it has been partitionned, in a parallel fashion.
Entree & interpreter(Entree &is) override
static void chercher_direction_perio(ArrOfDouble &direction_perio, const Domaine_32_64< int > &dom, const Nom &bord)
static int reordonner_faces_periodiques(const Domaine_32_64< int > &domaine, IntTab_T< int > &faces, const ArrOfDouble &direction_perio, const double epsilon)
static void init_sequential_domain(Domaine_32_64< _SIZE_ > &dom)
Create parallel descriptors for the vertex and element arrays of the domain (necessary because Scatte...
Definition Scatter.cpp:2739
static void construire_structures_paralleles(Domaine &dom)
Builds the parallel structures of the domain (determination of distant elements as a function of join...
Definition Scatter.cpp:673
static void construire_correspondance_sommets_par_coordonnees(Domaine &dom, bool allow_resize=false)
Builds the joint_item(JOINT_ITEM::SOMMET).items_communs arrays for all joints of the domain dom.
Definition Scatter.cpp:2674
static void trier_les_joints(Joints &joints)
Sort joints by increasing neighbor proc number.
Definition Scatter.cpp:712
static void uninit_sequential_domain(Domaine_32_64< _SIZE_ > &dom)
Method used by interpreters that modify the domain (sequential), destroys the descriptors of vertices...
Definition Scatter.cpp:2754
This derived class of Sortie stacks whatever it receives in an internal binary buffer.
void precision(int pre) override
void setf(IOS_FORMAT code) override
Base class for output streams.
Definition Sortie.h:52
void set_bin(bool bin) override
Changes the write mode of the file.
Definition Sortie.cpp:252
void resize(_SIZE_ n, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTTab.tpp:469
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133