TrioCFD 1.9.9_beta
TrioCFD documentation
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 //First case: the vertices were read from a file
45 //Copy sommets_lu_ into a temporary array 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 //Second case: the vertices are created in sub-domains
57 //Fill the temporary array
58 generer_marqueurs_sz(soms_tmp);
59 else
60 soms_tmp.resize(0,0);
61}
62
63//Generation of particle coordinates over one or several sub-domains
64//For each sub-domain:
65// - Step 1: determine the min and max for x, y and z, taking all processors into account
66// - Step 2: the master processor computes the particle coordinates
67// -either with a uniform distribution
68// -or with a random distribution
69// - Step 3: the master processor sends the computed coordinate values to the other processors
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 //Step 1: determine the min and max taking all processors into account
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 } //End 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 //Step 2: the master processor will compute the particle coordinates
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 //Case of a random distribution
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 //Case of a uniform distribution
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 }//End of if je_suis_maitre()
205
206 //Step 3: the master processor sends the computed coordinate values (soms_tmp)
207 // to the other processors
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
Returns the number of vertices of the geometric elements that make up the domain.
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
Returns the (global) number of the j-th vertex of the i-th element.
Definition Domaine.h:136
class Ensemble_Lagrange_base Base class for classes representing a geometric structure made up
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: a character string for naming TRUST objects.
Definition Nom.h:31
Base class for TRUST objects (Objet_U).
Definition Objet_U.h:68
static int dimension
Definition Objet_U.h:94
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
static double mp_min(double)
Definition Process.cpp:391
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 int je_suis_maitre()
Returns 1 if on the master processor of the current group (i.e. me() == 0), 0 otherwise.
Definition Process.cpp:82
Base class for output streams.
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