TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Extraire_domaine.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 <Extraire_domaine.h>
17#include <Probleme_base.h>
18#include <Equation_base.h>
19#include <NettoieNoeuds.h>
20#include <Sous_Domaine.h>
21#include <Parser_U.h>
22#include <Domaine_VF.h>
23#include <Domaine.h>
24#include <Scatter.h>
25#include <Param.h>
26#include <ParserView.h>
27
28Implemente_instanciable(Extraire_domaine,"Extraire_Domaine",Interprete_geometrique_base);
29// XD extraire_domaine interprete extraire_domaine BRACE Keyword to create a new domain built with the domain elements
30// XD_CONT of the pb_name problem verifying the two conditions given by Condition_elements. The problem pb_name should
31// XD_CONT have been discretized.
32
35
37{
38 Nom nom_pb;
39 Nom nom_dom;
40 Nom nom_sous_domaine;
41 Parser_U condition_elements;
42 Nom expr_elements("1");
43 condition_elements.setNbVar(dimension);
44 condition_elements.addVar("x");
45 condition_elements.addVar("y");
46 if (dimension==3)
47 condition_elements.addVar("z");
48
49 Param param(que_suis_je());
50 param.ajouter("domaine",&nom_dom,Param::REQUIRED); // XD_ADD_P ref_domaine
51 // XD_CONT Domain in which faces are saved
52 param.ajouter("probleme",&nom_pb,Param::REQUIRED); // XD_ADD_P ref_Pb_base
53 // XD_CONT Problem from which faces should be extracted
54 param.ajouter("condition_elements",&expr_elements); // XD_ADD_P chaine
55 // XD_CONT not_set
56 param.ajouter("sous_domaine|sous_zone",&nom_sous_domaine); // XD_ADD_P ref_sous_zone
57 // XD_CONT not_set
59
60 condition_elements.setString(expr_elements);
61 condition_elements.parseString();
62
63 associer_domaine(nom_dom);
64 Domaine& dom=domaine();
65 // retrieve the problem
66 if(! sub_type(Probleme_base, objet(nom_pb)))
67 {
68 Cerr << nom_pb << " is of type " << objet(nom_pb).que_suis_je() << finl;
69 Cerr << "and not of type Probleme_base" << finl;
70 exit();
71 }
72 Probleme_base& pb=ref_cast(Probleme_base, objet(nom_pb));
73 const Domaine_VF& domaine_vf=ref_cast(Domaine_VF,pb.domaine_dis());
74 dom.les_sommets()=domaine_vf.domaine().les_sommets();
75 dom.typer(domaine_vf.domaine().type_elem()->que_suis_je());
76
77 int nb_elem=domaine_vf.nb_elem();
78 IntTrav tab_marq_elem;
79 domaine_vf.domaine().creer_tableau_elements(tab_marq_elem);
80 IntArrView marq_elem = static_cast<ArrOfInt&>(tab_marq_elem).view_wo();
81 int nb_elem_m=0;
82 // mark the elements of interest
83 if (nom_sous_domaine== Nom())
84 {
85 int dim = Objet_U::dimension;
86 ParserView parser_condition_elements(condition_elements);
87 parser_condition_elements.parseString();
88 CDoubleTabView xp = domaine_vf.xp().view_ro();
89 Kokkos::parallel_reduce(start_gpu_timer(__KERNEL_NAME__), nb_elem, KOKKOS_LAMBDA(const int elem, int& local_nb_elem_m)
90 {
91 int threadId = parser_condition_elements.acquire();
92 parser_condition_elements.setVar(0,xp(elem,0),threadId);
93 parser_condition_elements.setVar(1,xp(elem,1),threadId);
94 if (dim==3)
95 parser_condition_elements.setVar(2,xp(elem,2),threadId);
96 double res=parser_condition_elements.eval(threadId);
97 parser_condition_elements.release(threadId);
98 if (std::fabs(res)>1e-5)
99 {
100 marq_elem(elem)=1;
101 local_nb_elem_m++;
102 }
103 else
104 marq_elem(elem)=0;
105 }, nb_elem_m);
106 end_gpu_timer(__KERNEL_NAME__);
107 }
108 else
109 {
110 const Sous_Domaine& ssz= ref_cast(Sous_Domaine,objet(nom_sous_domaine));
111 CIntArrView les_elems = ssz.les_elems().view_ro();
112 Kokkos::parallel_reduce(start_gpu_timer(__KERNEL_NAME__), ssz.nb_elem_tot(), KOKKOS_LAMBDA(const int i, int& local_nb_elem_m)
113 {
114 int elem = les_elems(i);
115 if (elem<nb_elem)
116 {
117 marq_elem(elem)=1;
118 local_nb_elem_m++;
119 }
120 }, nb_elem_m);
121 end_gpu_timer(__KERNEL_NAME__);
122 }
123 // Note: trick - we do not exchange virtual spaces so that the joint becomes a boundary
124 // marq_elem.echange_espace_virtuel();
125 int nb_faces=domaine_vf.nb_faces();
126 // find the faces on the boundary of the domain (joints included)
127 int nb_t=0;
128 ArrOfInt tab_marq(nb_faces);
129 IntArrView marq = tab_marq.view_rw();
130 CIntTabView face_voisin = domaine_vf.face_voisins().view_ro();
131 Kokkos::parallel_reduce(start_gpu_timer(__KERNEL_NAME__), nb_faces, KOKKOS_LAMBDA(const int fac, int& local_nb_t)
132 {
133 int elem0 = face_voisin(fac, 0);
134 int elem1 = face_voisin(fac, 1);
135 int val0 = -1;
136 if (elem0 != -1) val0 = marq_elem(elem0);
137 int val1 = -1;
138 if (elem1 != -1) val1 = marq_elem(elem1);
139
140 if (val0 != val1)
141 {
142 if ((val0 == 1) || (val1 == 1))
143 {
144 if (marq[fac] != -1) //not a joint
145 {
146 marq[fac] = 1;
147 local_nb_t++;
148 }
149 }
150 }
151 }, nb_t);
152 end_gpu_timer(__KERNEL_NAME__);
153
154 IntTab& les_elems=dom.les_elems();
155 const IntTab& les_elems_old=domaine_vf.domaine().les_elems();
156 int nb_som_elem=les_elems_old.dimension(1);
157 les_elems.resize(nb_elem_m,nb_som_elem);
158 const IntTab& face_sommets=domaine_vf.face_sommets();
159 int nb=0;
160 ToDo_Kokkos("critical");
161 for (int elem=0; elem<nb_elem; elem++)
162 {
163 if (tab_marq_elem(elem)==1)
164 {
165 for (int k=0; k<nb_som_elem; k++)
166 les_elems(nb,k)=les_elems_old(elem,k);
167 nb++;
168 }
169 }
170 assert(nb==nb_elem_m);
171 Bord faces;
172 faces.nommer("Bord");
173 faces.typer_faces(domaine_vf.domaine().type_elem()->type_face());
174 Faces& les_faces=faces.faces();
175 int nb_som_face=face_sommets.dimension(1);
176 IntTab& indfaces=les_faces.les_sommets();
177 indfaces.resize(nb_t,nb_som_face);
178 IntTab& facesv=les_faces.voisins();
179 facesv.resize(nb_t,2);
180 facesv=-1;
181 nb=0;
182 ToDo_Kokkos("critical");
183 for (int fac=0; fac<nb_faces; fac++)
184 if (tab_marq[fac]==1)
185 {
186 for (int s=0; s<nb_som_face; s++)
187 indfaces(nb,s)=face_sommets(fac,s);
188 // compute the normal
189 nb++;
190 }
191 Cerr<<finl;;
192 dom.faces_bord().add(faces);
193 dom.faces_bord().associer_domaine(dom);
194 dom.type_elem()->associer_domaine(dom);
196
197 assert(nb==nb_t);
199
200 return is;
201}
void associer_domaine(const Domaine_t &)
Associates a domain to all boundaries in the list.
Definition Bords.cpp:32
virtual void creer_tableau_elements(Array_base &, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT) const
Creates a parallel array of values at elements.
Definition Domaine.cpp:850
DoubleTab_t & les_sommets()
Definition Domaine.h:113
Bords_t & faces_bord()
Definition Domaine.h:198
IntTab_t & les_elems()
Definition Domaine.h:129
void fixer_premieres_faces_frontiere()
Definition Domaine.cpp:1101
void typer(const Nom &)
Sets the element type of the domain using the name passed as parameter.
Definition Domaine.h:457
class Domaine_VF
Definition Domaine_VF.h:44
int nb_faces() const
Returns the total number of faces.
Definition Domaine_VF.h:471
int face_sommets(int i, int j) const
Returns the index of the i-th vertex of face num_face.
Definition Domaine_VF.h:582
double xp(int num_elem, int k) const
Definition Domaine_VF.h:77
int face_voisins(int num_face, int i) const
Returns the neighbouring element of num_face in direction i.
Definition Domaine_VF.h:418
const Domaine & domaine() const
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
Class Extraire_domaine Reading a file.
Entree & interpreter_(Entree &) override
IntTab_t & voisins()
Returns the array of neighbors (of the faces).
Definition Faces.h:89
const IntTab_t & les_sommets() const
Returns the array of vertices of all faces.
Definition Faces.h:74
void nommer(const Nom &) override
Gives a name to the boundary.
Definition Frontiere.cpp:74
void typer_faces(const Motcle &)
Sets the type of the boundary faces.
Definition Frontiere.cpp:96
const Faces_t & faces() const
Definition Frontiere.h:54
static Objet_U & objet(const Nom &)
See Interprete_bloc::objet_global(). BM: the Interprete class is not the best place for this.
static void nettoie(Domaine_t &)
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
friend class Entree
Definition Objet_U.h:71
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
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
int lire_avec_accolades_depuis(Entree &is)
Parse the parameter block { ... } from is.
Definition Param.cpp:32
KOKKOS_INLINE_FUNCTION int acquire() const
Definition ParserView.h:77
KOKKOS_INLINE_FUNCTION void setVar(int i, double val, int threadId) const
Definition ParserView.h:64
void parseString() override
Definition ParserView.h:52
KOKKOS_INLINE_FUNCTION void release(int threadId) const
Definition ParserView.h:79
KOKKOS_INLINE_FUNCTION double eval(int threadId) const
Definition ParserView.h:69
class Parser_U Version of the Parser class, deriving from Objet_U.
Definition Parser_U.h:32
void setString(const std::string &s)
Definition Parser_U.h:194
void setNbVar(int nvar)
Definition Parser_U.h:174
void parseString()
Definition Parser_U.h:116
void addVar(const char *v)
Definition Parser_U.h:183
class Probleme_base It is a Probleme_U that is not a coupling.
const Domaine_dis_base & domaine_dis() const
Returns the discretized domain associated with the problem (const version).
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Definition Process.cpp:466
Base class for output streams.
Definition Sortie.h:52
int_t nb_elem_tot() const
const IntVect_t & les_elems() const
void resize(_SIZE_ n, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTTab.tpp:469
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133