TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
VerifierCoin.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 <LecFicDiffuse.h>
17#include <VerifierCoin.h>
18#include <Scatter.h>
19#include <Domaine.h>
20#include <Param.h>
21#include <time.h>
22
23Implemente_instanciable(VerifierCoin,"VerifierCoin",Interprete_geometrique_base);
24
25/*! @brief Simple appel a: Interprete::printOn(Sortie&) */
27
28/*! @brief Simple appel a: Interprete::readOn(Entree&) */
30
31// Split element `elem` into (dimension+1) sub-elements by inserting a centroid node.
32// The centroid coordinates are taken from xp(elem,:).
33// New elements are appended to les_elems; the sub-domains index is updated accordingly.
34void VerifierCoin::cut_elem(int elem, const DoubleTab& xp)
35{
36 Domaine& dom=domaine();
37 DoubleTab& sommets = dom.les_sommets();
38 int nouveau_sommet = sommets.dimension(0);
39 IntTab& les_elems=dom.les_elems();
40 sommets.resize(nouveau_sommet+1, dimension);
41 for (int j = 0; j < dimension; j++)
42 sommets(nouveau_sommet,j) = xp(elem,j);
43
44 int oldsz = les_elems.dimension(0);
45 les_elems.resize(oldsz+dimension, dimension+1);
46 Cerr << "-> The element number " << elem << " is cut in " << dimension+1 << " elements." << finl;
47
48 int i0 = les_elems(elem,0);
49 int i1 = les_elems(elem,1);
50 int i2 = les_elems(elem,2);
51
52 les_elems(elem,0) = i0;
53 les_elems(elem,1) = i1;
54 les_elems(elem,2) = nouveau_sommet;
55
56 les_elems(oldsz,0) = i1;
57 les_elems(oldsz,1) = i2;
58 les_elems(oldsz,2) = nouveau_sommet;
59
60 les_elems(oldsz+1,0) = i0;
61 les_elems(oldsz+1,1) = i2;
62 les_elems(oldsz+1,2) = nouveau_sommet;
63
64 if (dimension == 3)
65 {
66 int i3 = les_elems(elem,3);
67
68 les_elems(elem,3) = i3;
69 les_elems(oldsz,3) = i3;
70 les_elems(oldsz+1,3)= i3;
71
72 les_elems(oldsz+2,0) = i0;
73 les_elems(oldsz+2,1) = i1;
74 les_elems(oldsz+2,2) = i2;
75 les_elems(oldsz+2,3) = nouveau_sommet;
76 }
77
78 mettre_a_jour_sous_domaine(dom, elem, oldsz, dimension);
79}
80
81/*! @brief Fonction principale de l'interprete: resoudre un probleme
82 *
83 * On cherche dynamiquement le type du probleme a resoudre
84 * on resoud le probleme et on effectue les postraitements.
85 *
86 * @param (Entree& is) un flot d'entree
87 * @return (Entree&) le flot d'entree modifie
88 * @throws type de probleme inconnu
89 */
91{
92// XD verifiercoin interprete verifiercoin INHERITS_BRACE This keyword subdivides inconsistent 2D/3D cells used with
93// XD_CONT VEFPreP1B discretization. Must be used before the mesh is discretized. NL1 The Read_file option can be used
94// XD_CONT only if the file.decoupage_som was previously created by TRUST. This option, only in 2D, reverses the common
95// XD_CONT face at two cells (at least one is inconsistent), through the nodes opposed. In 3D, the option has no effect.
96// XD attr domain_name ref_domaine dom REQ Name of the domaine
97// XD attr bloc verifiercoin_bloc bloc REQ not_set
98// XD verifiercoin_bloc objet_lecture nul BRACE not_set
99// XD attr Read_file|Lire_fichier chaine filename OPT name of the *.decoupage_som file
100
101
103 Domaine& dom=domaine();
104 if (dom.type_elem()->que_suis_je() != "Triangle" && dom.type_elem()->que_suis_je() != "Tetraedre")
105 {
106 Cerr << "Error for "<<que_suis_je() <<" interpreter : it can be applied only for triangular or tetraedral meshing." << finl;
107 exit();
108 }
109
110 Nom decoup_som("");
111 Param param(que_suis_je());
112 param.ajouter("Lire_fichier|Read_file",&decoup_som);
113 bool expert_only_obsolete = false;
114 param.ajouter_flag("expert_only",&expert_only_obsolete);
116 if (expert_only_obsolete) Process::exit("Error: expert_only is not supported anymore for VerifierCoin");
117 int lecture_decoupage_som=(decoup_som!=""?1:0);
118
120 {
121 Cerr << que_suis_je() << " interpreter can be used only for sequential calculation." << finl;
122 Cerr << "For parallel calculation, please use "<< que_suis_je() <<" interpreter" << finl;
123 Cerr << "during the domain partitioning step." << finl;
124 exit();
125 }
127 DoubleTab xp;
129 DoubleTab& sommets = dom.les_sommets();
130 int nbsom=sommets.dimension(0);
131
132 IntTab& les_elems=dom.les_elems();
133 int nbelem=dom.nb_elem();
134
135 // On compte les elements attaches a chaque sommet:
136 ArrOfInt nb_elem_per_som(nbsom);
137 nb_elem_per_som = 0;
138 for (int ne = 0; ne < nbelem; ne++)
139 for (int ns = 0; ns < dimension+1; ns++)
140 nb_elem_per_som(les_elems(ne,ns))++;
141
142 //On decoupe les elements pour le sommet qui pose probleme
143 // PQ : 25/05/07
144 // - soit de maniere automatique (tout sommet rattache qu'a un seul element)
145 // - soit a partir d'une liste de sommets (liste generee lors d'un pre-calcul et tenant compte du type de CL)
146 // avec comme option de decoupage dans ce cas (lue dans le fichier "decoupage_som") :
147 //
148 // 0 : decoupage traditionnel (centre de gravite)
149 // 1 : decoupage en passant par le sommet oppose de l'element voisin
150
151 int option_decoupage=-1;
152
153 LecFicDiffuse fic;
154 if (lecture_decoupage_som)
155 {
156 Cerr<<"The file" << decoup_som <<" is checked before reading."<<finl;
157 fic.ouvrir(decoup_som);
158 if(fic.good())
159 {
160 int dim_cas, nbsom_cas;
161 fic >> option_decoupage;
162 fic >> dim_cas;
163 fic >> nbsom_cas;
164 if(dim_cas!=dimension)
165 {
166 Cerr << "Error for " <<que_suis_je()<<"::interpreter_" << finl;
167 Cerr << "The file " << decoup_som << " is planned for a case of dimension " << dim_cas << "D" << finl;
168 Cerr << "while the considered domain " << dom.le_nom() << " has a dimension " << dimension << "D." << finl;
170 }
171 if(nbsom!=nbsom_cas)
172 {
173 Cerr << "Error for " <<que_suis_je()<<"::interpreter_" << finl;
174 Cerr << "The nodes number (" <<nbsom_cas<< ") readen in the file " << decoup_som << finl;
175 Cerr << "dot not correspond to those of the meshing (" << nbsom << ")" << finl;
176 Cerr << "Please check that the file you have specified " << decoup_som << finl;
177 Cerr << "is the one to consider for this meshing." << finl;
179 }
180 }
181 else
182 {
183 Cerr << "Error for " <<que_suis_je()<<"::interpreter_" << finl;
184 Cerr << "Problem while trying to open the file " << decoup_som << finl;
186 }
187 Cerr << "option_decoupage " << option_decoupage << finl;
188
189 for (int somm=0; somm<nbsom; somm++)
190 {
191 if (nb_elem_per_som(somm) != 1) continue;
192 //On decoupe les elements pour le sommet qui pose probleme
193 int somm_lu = -1, elem_opp, somm_opp, somm1, somm2, elem;
194 fic >> somm_lu >> somm_opp >> somm1 >> somm2;
195 if (dimension==3)
196 {
197 int somm3;
198 fic >> somm3;
199 }
200 fic >> elem >> elem_opp;
201 if(somm_lu!=-1) somm = somm_lu; // -1 indice de fin de fichier
202 if(nbsom<=somm)
203 {
204 Cerr << "Error in VerifierCoin::interpreter" << finl;
205 Cerr << "The node " << somm << " is not found." << finl;
206 Cerr << "Check the .Zones files are up to date with your mesh file." << finl;
208 }
209 Cerr<<"-> VerifierCoin is applied on the node "<<somm<< " of coordinates: ";
210 for(int dir=0; dir<dimension; dir++) Cerr<<sommets(somm,dir)<<" ";
211 Cerr<<"..."<<finl;
212
213 if (option_decoupage==1 && dimension==2 && somm_lu!=-1) // inversion des sommets
214 {
215 les_elems(elem,0) = somm ;
216 les_elems(elem,1) = somm_opp ;
217 les_elems(elem,2) = somm1 ;
218
219 les_elems(elem_opp,0) = somm ;
220 les_elems(elem_opp,1) = somm_opp ;
221 les_elems(elem_opp,2) = somm2 ;
222 }
223 else // creation d'un nouveau sommet au centre de gravite de l'element
224 cut_elem(elem, xp);
225 }
226 }
227 else
228 {
229 std::map<int,int> som_elem; // Pour trier les sommets comme avant
230 for (int elem = 0; elem < nbelem; elem++)
231 for (int ns = 0; ns < dimension+1; ns++)
232 {
233 int somm = les_elems(elem, ns);
234 if (nb_elem_per_som(somm) == 1) som_elem.insert({somm, elem});
235 }
236 for (auto pair : som_elem)
237 {
238 int somm = pair.first;
239 int elem = pair.second;
240 nb_elem_per_som(somm) = 0; // mark: vertex processed, avoid double split
241 Cerr << "-> VerifierCoin is applied on the node " << somm << " of coordinates: ";
242 for (int dir = 0; dir < dimension; dir++) Cerr << sommets(somm, dir) << " ";
243 Cerr << "..." << finl;
244 cut_elem(elem, xp);
245 }
246 }
247
249
250 return is;
251}
void calculer_centres_gravite(DoubleTab_t &xp) const
Calcule les centres de gravites des elements du domaine.
Definition Domaine.h:503
DoubleTab_t & les_sommets()
Definition Domaine.h:113
IntTab_t & les_elems()
Definition Domaine.h:129
int_t nb_elem() const
Definition Domaine.h:131
const Nom & le_nom() const override
Donne le nom de l'Objet_U Methode a surcharger : renvoie "neant" dans cette implementation.
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
void mettre_a_jour_sous_domaine(Domaine_t &domaine, int_t &elem, int_t num_premier_elem, int_t nb_elem) const
Cette classe implemente les operateurs et les methodes virtuelles de la classe EFichier de la facon s...
int ouvrir(const char *name, IOS_OPEN_MODE mode=ios::in) override
Ouverture du fichier.
class Nom Une chaine de caractere pour nommer les objets de TRUST
Definition Nom.h:31
friend class Entree
Definition Objet_U.h:76
static int dimension
Definition Objet_U.h:99
const Nom & que_suis_je() const
renvoie la chaine identifiant la classe.
Definition Objet_U.cpp:104
virtual Entree & readOn(Entree &)
Lecture d'un Objet_U sur un flot d'entree Methode a surcharger.
Definition Objet_U.cpp:293
virtual Sortie & printOn(Sortie &) const
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
Definition Objet_U.cpp:282
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
int lire_avec_accolades_depuis(Entree &is)
Parse the parameter block { ... } from is.
Definition Param.cpp:32
static bool is_parallel()
Definition Process.cpp:110
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.cpp:455
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:2742
static void uninit_sequential_domain(Domaine_32_64< _SIZE_ > &dom)
methode utilisee par les interpretes qui modifient le domaine (sequentiel), detruit les descripteurs ...
Definition Scatter.cpp:2757
Classe de base des flux de sortie.
Definition Sortie.h:52
void resize(_SIZE_ n, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTTab.tpp:469
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133
classe VerifierCoin Interprete qui resoud un probleme:
Entree & interpreter_(Entree &) override
Fonction principale de l'interprete: resoudre un probleme.