TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
Ensemble_Lagrange_base.cpp
1/****************************************************************************
2* Copyright (c) 2024, 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#include <Ensemble_Lagrange_base.h>
16#include <Sous_Domaine.h>
17#include <Domaine.h>
18#include <communications.h>
19Implemente_base_sans_constructeur(Ensemble_Lagrange_base,"Ensemble_Lagrange_base",Objet_U);
20
26
28{
29 return os;
30}
31
33{
34 return is;
35}
36
37void Ensemble_Lagrange_base::associer_domaine(const Domaine& un_domaine)
38{
39 mon_dom_=un_domaine;
40}
41
43{
44 //Premier cas : les sommets ont ete lus dans un fichier
45 //On copie sommets_lu_ dans un tableau temporaire sommets_tmp
46
47 if (sommets_lu_.dimension(0)!=0)
48 {
49 const DoubleTab& som_lu = sommets_lu() ;
50 int dim0=som_lu.dimension(0);
51 int dim1=som_lu.dimension(1);
52 soms_tmp.resize(dim0,dim1);
53 soms_tmp = som_lu;
54 }
55 else if (nb_marqs_par_sz().size()!=0)
56 //Deuxieme cas : les sommets sont crees dans des sous domaines
57 //On remplit le tableau temporaire
58 generer_marqueurs_sz(soms_tmp);
59 else
60 soms_tmp.resize(0,0);
61}
62
63//Generation des coordonnees des particules sur une ou plusieurs sous domaines
64//Pour chacune des sous domaines :
65// - Etape 1 : On determine le min et max pour x, y et z en tenant compte de tous les processeurs
66// - Etape 2 : Le processeur maitre va calculer les coordonnees des particules
67// -soit avec une distribution uniforme
68// -soit avec une distribution aleatoire
69// - Etape 3 : Le processeur maitre envoie les valeurs des coordonnees aux autres processeurs
70
72{
73 const Domaine& madomaine = mon_dom_.valeur();
74 const Domaine& dom = madomaine;
75 int nb_sz,nb_marq_sz, old_size, dim;
76 soms_tmp.resize(0);
78 nb_sz=nb_marqs_sz.size();
79
80 for (int i=0; i<nb_sz; i++)
81 {
82 const Nom& nom = nom_sz[i];
83 const Sous_Domaine& sz = dom.ss_domaine(nom);
84 int nb_elem = sz.nb_elem_tot();
85
86 int nb_som = madomaine.nb_som_elem();
87 int le_poly,poly,le_som;
88
89 double xmoy,ymoy,zmoy,deltax,deltay,deltaz;
90 double xmin,xmax,ymin,ymax,zmin,zmax;
91 xmin = ymin = zmin = 1.e8;
92 xmax = ymax = zmax= -1.e8;
93
94 if (dim==2)
95 {
96 zmin = zmax = 0.;
97 }
98
99 //Etape 1 : On determine le min et max en tenant compte de tous les processeurs
100 if (nb_elem!=0)
101 {
102 poly = sz(0);
103 le_som = 0;
104
105 xmin=dom.coord(madomaine.sommet_elem(poly,le_som),0);
106 ymin=dom.coord(madomaine.sommet_elem(poly,le_som),1);
107 if (dim==3)
108 zmin=dom.coord(madomaine.sommet_elem(poly,le_som),2);
109 xmax=xmin;
110 ymax=ymin;
111 if (dim==3)
112 zmax=zmin;
113
114 for (le_poly=0; le_poly<nb_elem; le_poly++)
115 for(le_som=0; le_som<nb_som; le_som++)
116 {
117 poly = sz(le_poly);
118 xmin=std::min(xmin,dom.coord(madomaine.sommet_elem(poly,le_som),0));
119 ymin=std::min(ymin,dom.coord(madomaine.sommet_elem(poly,le_som),1));
120 if (dim==3)
121 zmin=std::min(zmin,dom.coord(madomaine.sommet_elem(poly,le_som),2));
122 xmax=std::max(xmax,dom.coord(madomaine.sommet_elem(poly,le_som),0));
123 ymax=std::max(ymax,dom.coord(madomaine.sommet_elem(poly,le_som),1));
124 if (dim==3)
125 zmax=std::max(zmax,dom.coord(madomaine.sommet_elem(poly,le_som),2));
126 }
127 } //Fin if (nb_elem!=0)
128
129
130 xmin = Process::mp_min(xmin);
131 xmax = Process::mp_max(xmax);
132 ymin = Process::mp_min(ymin);
133 ymax = Process::mp_max(ymax);
134 if (dim==3)
135 {
136 zmin = Process::mp_min(zmin);
137 zmax = Process::mp_max(zmax);
138 }
139
140 //Etape 2 : Le processeur maitre va calculer les coordonnees des particules
141 if (je_suis_maitre())
142 {
143
144 xmoy = (xmax+xmin)/2.;
145 ymoy = (ymax+ymin)/2.;
146 zmoy = (zmax+zmin)/2.;
147
148 deltax = (xmax-xmin)/2.;
149 deltay = (ymax-ymin)/2.;
150 deltaz = (zmax-zmin)/2.;
151
152 nb_marq_sz = nb_marqs_sz(i);
153 old_size = soms_tmp.dimension(0);
154 soms_tmp.resize(old_size+nb_marq_sz,dim);
155 int marq;
156
157 //Cas d une distribution aleatoire
158 if (nb_marqs_par_dir(i,0)==0)
159 {
160 //double a,b,c;
161 srand48(1);
162 for (marq=0; marq<nb_marq_sz; marq++)
163 {
164 soms_tmp(old_size+marq,0) = xmoy + deltax*(-1.+2.*drand48());
165 soms_tmp(old_size+marq,1) = ymoy + deltay*(-1.+2.*drand48());
166 if (dim==3)
167 soms_tmp(old_size+marq,2) = zmoy + deltaz*(-1.+2.*drand48());
168 }
169 }
170 //Cas d une distribution uniforme
171 else
172 {
173 double dx, dy, dz;
174 int nx_max = nb_marqs_par_dir(i,0);
175 int ny_max = nb_marqs_par_dir(i,1);
176 dx = 2.*deltax/double(nx_max+1);
177 dy = 2.*deltay/double(ny_max+1);
178
179 if (dim==2)
180 {
181 for (int ny=1; ny<ny_max+1; ny++)
182 for (int nx=1; nx<nx_max+1; nx++)
183 {
184 marq = nx + (ny-1)*nx_max-1;
185 soms_tmp(old_size+marq,0) = xmin + nx*dx;
186 soms_tmp(old_size+marq,1) = ymin + ny*dy;
187 }
188 }
189 else if (dim==3)
190 {
191 int nz_max = nb_marqs_par_dir(i,2);
192 dz = 2.*deltaz/double(nz_max+1);
193 for (int nz=1; nz<nz_max+1; nz++)
194 for (int ny=1; ny<ny_max+1; ny++)
195 for (int nx=1; nx<nx_max+1; nx++)
196 {
197 marq = nx + (ny-1)*nx_max + (nz-1)*nx_max*ny_max-1;
198 soms_tmp(old_size+marq,0) = xmin + nx*dx;
199 soms_tmp(old_size+marq,1) = ymin + ny*dy;
200 soms_tmp(old_size+marq,2) = zmin + nz*dz;
201 }
202 }
203 }
204 }//Fin de if je_suis_maitre()
205
206 //Etape 3 : Le processeur maitre envoie les valeurs des coordonnees calculees (soms_tmp)
207 // aux autres processeurs
208 if (je_suis_maitre())
209 for(int p=1; p<Process::nproc(); p++)
210 envoyer(soms_tmp,0, p, 0);
211 for(int p=1; p<Process::nproc(); p++)
212 recevoir(soms_tmp,0,p,0);
213 }
214}
const Sous_Domaine_t & ss_domaine(int i) const
Definition Domaine.h:290
int nb_som_elem() const
Renvoie le nombre de sommets des elements geometriques constituants le domaine.
Definition Domaine.h:474
double coord(int_t i, int j) const
Definition Domaine.h:110
int_t sommet_elem(int_t i, int j) const
Renvoie le numero (global) du j-ieme sommet du i-ieme element.
Definition Domaine.h:136
classe Ensemble_Lagrange_base Classe de base des classes representant une structure geometrique const...
void associer_domaine(const Domaine &domaine)
void remplir_sommets_tmp(DoubleTab &soms_tmp)
const DoubleTab & sommets_lu() const
const IntVect & nb_marqs_par_sz() const
void generer_marqueurs_sz(DoubleTab &soms_tmp)
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
class Nom Une chaine de caractere pour nommer les objets de TRUST
Definition Nom.h:31
classe Objet_U Cette classe est la classe de base des Objets de TRUST
Definition Objet_U.h:73
static int dimension
Definition Objet_U.h:99
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
static double mp_min(double)
Definition Process.cpp:386
static double mp_max(double)
Definition Process.cpp:376
static int nproc()
renvoie le nombre de processeurs dans le groupe courant Voir Comm_Group::nproc() et PE_Groups::curren...
Definition Process.cpp:104
static int je_suis_maitre()
renvoie 1 si on est sur le processeur maitre du groupe courant (c'est a dire me() == 0),...
Definition Process.cpp:86
Classe de base des flux de sortie.
Definition Sortie.h:52
int_t nb_elem_tot() 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