TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Create_domain_from_sub_domain.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 <Create_domain_from_sub_domain.h>
17#include <Domaine.h>
18#include <Param.h>
19#include <DomaineCutter.h>
20#include <Scatter.h>
21#include <Sous_Domaine.h>
22#include <SFichier.h>
23#include <Synonyme_info.h>
24
25Implemente_instanciable(Create_domain_from_sub_domain,"Create_domain_from_sub_domain|Create_domain_from_sub_domains",Interprete_geometrique_base);
26// XD Create_domain_from_sub_domain interprete_geometrique_base Create_domain_from_sub_domain BRACE This keyword fills
27// XD_CONT the domain domaine_final with the subdomaine par_sous_zone from the domain domaine_init. It is very useful
28// XD_CONT when meshing several mediums with Gmsh. Each medium will be defined as a subdomaine into Gmsh. A MED mesh
29// XD_CONT file will be saved from Gmsh and read with Lire_Med keyword by the TRUST data file. And with this keyword, a
30// XD_CONT domain will be created for each medium in the TRUST data file.
31
32Add_synonym(Create_domain_from_sub_domain, "Create_domain_from_sous_zone");
33
35{
36 return Interprete::printOn(os);
37}
39{
40 return Interprete::readOn(is);
41}
42
44{
45 if (mot=="domaines" || mot=="zones")
46 {
47 noms_sous_domaines.reset(), noms_doms.reset();
48 Nom ssz, dom;
49 is >> ssz;
50 if (ssz != "{") Process::exit("Create_domain_from_sub_domain::domaines : { expected");
51 for (is >> ssz; ssz != "}"; is >> ssz)
52 is >> dom, noms_sous_domaines.add(ssz), noms_doms.add(dom);
53 return 1;
54 }
55 return 0;
56}
57
59{
60 Nom nom_dom_org;
61 noms_sous_domaines.dimensionner(1), noms_doms.dimensionner(1);
62 Param param(que_suis_je());
63 param.ajouter("domaine_final",&noms_doms[0]); // XD_ADD_P ref_domaine
64 // XD_CONT new domain in which faces are stored
65 param.ajouter("par_sous_zone|par_sous_dom",&noms_sous_domaines[0]); // XD_ADD_P chaine
66 // XD_CONT a sub-area (a group in a MED file) allowing to choose the elements
67 param.ajouter("domaine_init",&nom_dom_org,Param::REQUIRED); // XD_ADD_P ref_domaine
68 // XD_CONT initial domain
69 param.ajouter_non_std("domaines|zones", this);
71
72 if (nproc()>1)
73 {
74 Cerr<<"Options par_sous_zone and par_sous_zones of "<<que_suis_je()<<" are for sequential." <<finl;
75 exit();
76 }
77
78 const Domaine& domaine_org=ref_cast(Domaine, objet(nom_dom_org));
79
80 DomaineCutter cutter;
81
82 IntTab index(domaine_org.nb_elem()); //0 -> first domain, ..., n_dom + 1 -> the rest
83 int nb_dom = noms_doms.size();
84 index = 0; //by default, nothing is selected
85 for (int i = 0; i < nb_dom; i++)
86 {
87 const Sous_Domaine& ssz=ref_cast(Sous_Domaine,objet(noms_sous_domaines[i]));
88 for (int j = 0; j < ssz.nb_elem_tot(); j++)
89 {
90 if (index(ssz(j))) /* element already taken -> error */
91 Process::exit(Nom("Create_domain_from_sub_domain : collision detected between ") + noms_sous_domaines[i] + " and " + noms_sous_domaines[index(ssz(j)) - 1] + " !");
92 index(ssz(j)) = i + 1;
93 }
94 }
95
96 cutter.initialiser(domaine_org, index, noms_doms.size() + 1,1, true);
97 for (int i = 0; i < nb_dom; i++)
98 {
99 Domaine& dom = ref_cast(Domaine, objet(noms_doms[i]));
100 cutter.construire_sous_domaine(i + 1, dom);
101 Bords& bords=dom.faces_bord();
102
103 if (cutter.bords_internes().size()>0)
104 dom.faces_joint().vide();
105 else
106 {
107 // convert joints to boundaries
108 Joints& joints= dom.faces_joint();
109 for (int j=joints.size()-1; j>=0; j--)
110 {
111 Cout <<"The joint"<<j<<" becomes a boundary"<<finl;
112 Bord b;
113 ref_cast(Frontiere,b)=ref_cast(Frontiere,joints(j));
114 b.nommer(Nom("Couture_")+Nom(j));
115 bords.add(b);
116
117 joints.suppr(joints(j));
118 }
119 }
120
121 for (int b=bords.size()-1; b>=0; b--)
122 if (bords(b).nb_faces()==0)
123 {
124 Cout << bords(b).le_nom()<<" deleted"<<finl;
125 bords.suppr(bords(b));
126 }
127 Raccords& listrac=dom.faces_raccord();
128
129 for (int b=bords.size()-1; b>=0; b--)
130 {
131 if (cutter.bords_internes().rang(bords(b).le_nom())>=0)
132 {
133 Cout << bords(b).le_nom() <<" becomes a connection "<<finl;
134 Raccord racc_base;
135 racc_base.typer("Raccord_local_homogene");
136 Raccord_base& racc=racc_base.valeur();
137 // cast to Frontiere to allow copying ...
138 ref_cast(Frontiere,racc)=ref_cast(Frontiere,bords(b));
139 listrac.add(racc_base);
140
141 bords.suppr(bords(b));
142 }
143 }
144
145 //and the sub-domains?
146 const LIST(OBS_PTR(Sous_Domaine)) & liste_sous_domaines = domaine_org.ss_domaines();
147 int nb_sous_domaines = liste_sous_domaines.size();
148 const Sous_Domaine& ssz=ref_cast(Sous_Domaine,objet(noms_sous_domaines[i]));
149 ArrOfInt rev_ssz(domaine_org.nb_elem());
150 rev_ssz = -1;
151 for (int j = 0; j < ssz.nb_elem_tot(); j++)
152 rev_ssz[ssz[j]] = j;
153
154 Nom jdd(" "), jdd_par(" ");
155 int ecr_jdd = 0;
156 for (int j = 0; j < nb_sous_domaines; j++)
157 if (liste_sous_domaines[j]->le_nom() != noms_sous_domaines[i])
158 {
159 //list of elements of the sub-sub-domain
160 ArrOfInt polys;
161
162 for (int k = 0, l; k < liste_sous_domaines[j]->nb_elem_tot(); k++)
163 if ((l = rev_ssz[liste_sous_domaines[j].valeur()[k]]) >= 0)
164 polys.append_array(l);
165
166 if (!polys.size_array())
167 continue; //empty sub-sub-domain!
168
169 Nom nom_ssz(noms_doms[i] + "_" + liste_sous_domaines[j]->le_nom()), file_ssz(nom_ssz + ".file");
170
171 //contribution to the input data files of the sub-sub-domains
172 jdd += Nom("export Sous_Domaine ") + nom_ssz + "\n";
173 jdd += Nom("Associer ") + nom_ssz + " " + noms_doms[i] + "\n";
174 jdd += Nom("Lire ") + nom_ssz + " { fichier " + file_ssz + " }" + "\n";
175 jdd_par += Nom("export Sous_Domaine ") + nom_ssz + "\n";
176 jdd_par += Nom("Associer ") + nom_ssz + " " + noms_doms[i] + "\n";
177 jdd_par += Nom("Lire ") + nom_ssz + " { fichier " + nom_ssz + ".ssz }" + "\n";
178 ecr_jdd = 1;
179
180 //file of the sub-sub-domain
181 SFichier f_ssz(file_ssz);
182 f_ssz << polys;
183 }
184
185 if (ecr_jdd)
186 {
187 SFichier f_jdd(noms_doms[i] + "_ssz.geo");
188 SFichier f_jdd_par(noms_doms[i] + "_ssz_par.geo");
189 f_jdd << jdd;
190 f_jdd_par << jdd_par;
191 }
192
193 dom.nommer(noms_doms[i]);
195 }
196
197 return is;
198}
Class Create_domain_from_sub_domain File reading.
int lire_motcle_non_standard(const Motcle &, Entree &) override
Reads non-simple-type parameters of an Objet_U from an input stream.
const Noms & bords_internes() const
void initialiser(const Domaine_t &domaine_global, const BigIntVect_t &elem_part, const int nb_parts, const int epaisseur_joint, const bool permissif=false)
Prepares the data structures for building sub-domains based on a partitioning provided in elem_part.
void construire_sous_domaine(const int part, DomaineCutter_Correspondance_t &correspondance, Domaine32 &sous_domaine, const Static_Int_Lists_t *som_raccord=nullptr) const
Fills the "correspondance" structure and the "sous_domaine" for part "part".
Bords_t & faces_bord()
Definition Domaine.h:198
Raccords_t & faces_raccord()
Definition Domaine.h:253
int_t nb_elem() const
Definition Domaine.h:131
Joints_t & faces_joint()
Definition Domaine.h:265
void nommer(const Nom &nom) override
Assigns a name to the Objet_U. Virtual method to override.
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
void nommer(const Nom &) override
Gives a name to the boundary.
Definition Frontiere.cpp:74
static Objet_U & objet(const Nom &)
See Interprete_bloc::objet_global(). BM: the Interprete class is not the best place for this.
A character string (Nom) in uppercase.
Definition Motcle.h:26
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
int rang(const char *const ch) const
Definition Noms.cpp:65
friend class Entree
Definition Objet_U.h:71
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
virtual const Nom & le_nom() const
Returns the name of the Objet_U. Virtual method to override: returns "neant" in this implementation.
Definition Objet_U.cpp:317
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(const char *keyword, const int *value, Param::Nature nat=Param::OPTIONAL)
Register an integer parameter.
Definition Param.cpp:364
@ REQUIRED
Definition Param.h:115
void ajouter_non_std(const char *keyword, const Objet_U *value, Param::Nature nat=Param::OPTIONAL)
Register a keyword handled by Objet_U::lire_motcle_non_standard.
Definition Param.cpp:489
int lire_avec_accolades_depuis(Entree &is)
Parse the parameter block { ... } from is.
Definition Param.cpp:32
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 void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Definition Process.cpp:466
SFichier is to the C++ ofstream class what Sortie is to the C++ ostream class.
Definition SFichier.h:29
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
Base class for output streams.
Definition Sortie.h:52
int_t nb_elem_tot() const
void append_array(_TYPE_ valeur)
_SIZE_ size_array() const
_SIZE_ size() const
Definition TRUSTVect.tpp:45