TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
Champ_som_lu_VEF.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
16#include <Champ_som_lu_VEF.h>
17
18#include <EFichier.h>
19#include <TRUSTTab.h>
20#include <Domaine.h>
21
22Implemente_instanciable(Champ_som_lu_VEF,"Champ_som_lu_VEF",Champ_som_lu);
23// XD champ_som_lu_vef champ_don_base champ_som_lu_vef NO_BRACE Keyword to read in a file values located at the nodes of
24// XD_CONT a mesh in VEF discretization.
25// XD attr domain_name ref_domaine domain_name REQ Name of the domain.
26// XD attr dim entier dim REQ Value of the dimension of the field.
27// XD attr tolerance floattant tolerance REQ Value of the tolerance to check the coordinates of the nodes.
28// XD attr file chaine file REQ Name of the file. NL2 This file has the following format: NL2 Xi Yi Zi -> Coordinates of
29// XD_CONT the node NL2 Ui Vi Wi -> Value of the field on this node NL2 Xi+1 Yi+1 Zi+1 -> Next point NL2 Ui+1 Vi+1 Zi+1
30// XD_CONT -> Next value ...
31
32
35
36DoubleVect& Champ_som_lu_VEF::valeur_a_compo(const DoubleVect& positions, DoubleVect& tab_valeurs, int ncomp) const
37{
38 int nb_pos = positions.size();
39 assert(nb_pos == 1);
40 tab_valeurs.resize(nb_pos);
41 assert(ncomp < 3);
42 switch(dimension)
43 {
44 case 1:
45 {
46 Cerr << "Il y a un pbl !! Il faut etre en 2D ou 3D !!" << finl;
47 break;
48 }
49 case 2:
50 {
51 break;
52 }
53 case 3:
54 {
55 break;
56 }
57 }
58 return tab_valeurs;
59}
60
61DoubleVect& Champ_som_lu_VEF::valeur_a_elem_compo(const DoubleVect& positions, DoubleVect& tab_valeurs, int, int ncomp) const
62{
63 return valeur_a_compo(positions, tab_valeurs, ncomp);
64}
65
66double Champ_som_lu_VEF::valeur_a_compo(const DoubleVect&, int ) const
67{
68 return not_implemented_champ_<double>(__func__);
69}
70
71double Champ_som_lu_VEF::valeur_a_elem_compo(const DoubleVect&, int ,int ) const
72{
73 return not_implemented_champ_<double>(__func__);;
74}
75
76DoubleTab& Champ_som_lu_VEF::valeur_aux_elems(const DoubleTab& positions, const IntVect& les_polys, DoubleTab& val) const
77{
78 int som, le_poly;
79 double xs, ys, zs;
80
81 const DoubleTab& coord = mon_domaine->coord_sommets();
82 const IntTab& sommet_poly = mon_domaine->les_elems();
83
84 if (val.nb_dim() > 2) erreur_champ_(__func__);
85
86 if (dimension == 2)
87 {
88 Cerr << "ATTENTION : Cela n a pas encore ete teste en 2D!!!" << finl;
89 Cerr << "Il manque les fonctions de forme en 2D!! A vous de jouer!!" << finl;
90 }
91
92 const DoubleTab& ch = valeurs();
93
94 for (int rang_poly = 0; rang_poly < les_polys.size(); rang_poly++)
95 {
96 le_poly = les_polys(rang_poly);
97 if (le_poly == -1)
98 for (int ncomp = 0; ncomp < nb_compo_; ncomp++) val(rang_poly, ncomp) = 0;
99 else
100 for (int ncomp = 0; ncomp < nb_compo_; ncomp++)
101 {
102 val(rang_poly, ncomp) = 0;
103 xs = positions(rang_poly, 0);
104 ys = positions(rang_poly, 1);
105 zs = (dimension == 3) ? positions(rang_poly, 2) : 0.;
106 for (int i = 0; i < dimension + 1; i++)
107 {
108 som = sommet_poly(le_poly, i);
109 val(rang_poly, ncomp) += ch(som, ncomp)
110 * ((dimension == 2) ? coord_barycentrique2D(sommet_poly, coord, xs, ys, le_poly, i) : coord_barycentrique3D(sommet_poly, coord, xs, ys, zs, le_poly, i));
111 }
112 }
113 }
114 return val;
115}
116
117DoubleVect& Champ_som_lu_VEF::valeur_aux_elems_compo(const DoubleTab& positions, const IntVect& les_polys, DoubleVect& val, int ncomp) const
118{
119 int som, le_poly;
120 double xs, ys, zs;
121 const DoubleTab& coord = mon_domaine->coord_sommets();
122 const IntTab& sommet_poly = mon_domaine->les_elems();
123 assert(val.size_totale() >= les_polys.size());
124 const DoubleTab& ch = valeurs();
125
126 if (dimension == 2)
127 {
128 Cerr << "ATTENTION : Cela n a pas encore ete teste en 2D!!!" << finl;
129 Cerr << "Il manque les fonctions de forme en 2D!! A vous de jouer!!" << finl;
131 }
132
133 for (int rang_poly = 0; rang_poly < les_polys.size(); rang_poly++)
134 {
135 le_poly = les_polys(rang_poly);
136 if (le_poly == -1) val(rang_poly) = 0;
137 else
138 {
139 val(rang_poly) = 0;
140 xs = positions(rang_poly, 0);
141 ys = positions(rang_poly, 1);
142 zs = (dimension == 3) ? positions(rang_poly, 2) : 0.;
143 for (int i = 0; i < dimension + 1; i++)
144 {
145 som = sommet_poly(le_poly, i);
146 val(rang_poly) += ch(som, ncomp) * ((dimension == 2) ? coord_barycentrique2D(sommet_poly, coord, xs, ys, le_poly, i) : coord_barycentrique3D(sommet_poly, coord, xs, ys, zs, le_poly, i));
147 }
148 }
149 }
150 return val;
151}
152
153double coord_barycentrique3D(const IntTab& polys, const DoubleTab& coord, double x, double y, double z, int le_poly, int i)
154{
155 int som0, som1, som2, som3;
156
157 switch(i)
158 {
159 case 0:
160 {
161 som0 = polys(le_poly, 0);
162 som1 = polys(le_poly, 1);
163 som2 = polys(le_poly, 2);
164 som3 = polys(le_poly, 3);
165 break;
166 }
167 case 1:
168 {
169 som0 = polys(le_poly, 1);
170 som1 = polys(le_poly, 2);
171 som2 = polys(le_poly, 3);
172 som3 = polys(le_poly, 0);
173 break;
174 }
175 case 2:
176 {
177 som0 = polys(le_poly, 2);
178 som1 = polys(le_poly, 3);
179 som2 = polys(le_poly, 0);
180 som3 = polys(le_poly, 1);
181 break;
182 }
183 case 3:
184 {
185 som0 = polys(le_poly, 3);
186 som1 = polys(le_poly, 0);
187 som2 = polys(le_poly, 1);
188 som3 = polys(le_poly, 2);
189 break;
190 }
191 default:
192 {
193 som0 = som1 = som2 = som3 = -1;
194 assert(0);
196 break;
197 }
198 }
199
200 double xp = (coord(som2, 1) - coord(som1, 1)) * (coord(som0, 2) - coord(som1, 2)) - (coord(som2, 2) - coord(som1, 2)) * (coord(som0, 1) - coord(som1, 1));
201 double yp = (coord(som2, 2) - coord(som1, 2)) * (coord(som0, 0) - coord(som1, 0)) - (coord(som2, 0) - coord(som1, 0)) * (coord(som0, 2) - coord(som1, 2));
202 double zp = (coord(som2, 0) - coord(som1, 0)) * (coord(som0, 1) - coord(som1, 1)) - (coord(som2, 1) - coord(som1, 1)) * (coord(som0, 0) - coord(som1, 0));
203 double den = xp * (coord(som3, 0) - coord(som1, 0)) + yp * (coord(som3, 1) - coord(som1, 1)) + zp * (coord(som3, 2) - coord(som1, 2));
204
205 xp = (coord(som2, 1) - coord(som1, 1)) * (z - coord(som1, 2)) - (coord(som2, 2) - coord(som1, 2)) * (y - coord(som1, 1));
206 yp = (coord(som2, 2) - coord(som1, 2)) * (x - coord(som1, 0)) - (coord(som2, 0) - coord(som1, 0)) * (z - coord(som1, 2));
207 zp = (coord(som2, 0) - coord(som1, 0)) * (y - coord(som1, 1)) - (coord(som2, 1) - coord(som1, 1)) * (x - coord(som1, 0));
208 double num = xp * (coord(som3, 0) - coord(som1, 0)) + yp * (coord(som3, 1) - coord(som1, 1)) + zp * (coord(som3, 2) - coord(som1, 2));
209
210 assert(den != 0.);
211 double coord_bary = num / den;
212 assert(sup_ou_egal(coord_bary, 0) && inf_ou_egal(coord_bary, 1));
213 return coord_bary;
214}
215
216double coord_barycentrique2D(const IntTab& polys, const DoubleTab& coord, double x, double y, int le_poly, int i)
217{
218 int som0 = polys(le_poly, i), som1 = polys(le_poly, 1);
219
220 if (i == 1) som1 = polys(le_poly, 0);
221
222 double xref = coord(som1, 0) - coord(som0, 0);
223 double yref = coord(som1, 1) - coord(som0, 1);
224
225 double xp = x - coord(som0, 0);
226 double yp = y - coord(som0, 1);
227
228 double pscal = (xref * xp) + (yref * yp);
229 double norm = (xref * xref) + (yref * yref);
230
231 assert(norm != 0.);
232 double coord_bary = pscal / norm;
233 assert(sup_ou_egal(coord_bary, 0) && inf_ou_egal(coord_bary, 1));
234 return coord_bary;
235}
DoubleTab & valeurs() override
Surcharge Champ_base::valeurs() Renvoie le tableau des valeurs.
DoubleVect & valeur_aux_elems_compo(const DoubleTab &positions, const IntVect &les_polys, DoubleVect &valeurs, int ncomp) const override
provoque une erreur ! doit etre surchargee par les classes derivees
DoubleVect & valeur_a_compo(const DoubleVect &position, DoubleVect &valeurs, int ncomp) const
DoubleVect & valeur_a_elem_compo(const DoubleVect &position, DoubleVect &valeurs, int le_poly, int ncomp) const
DoubleTab & valeur_aux_elems(const DoubleTab &positions, const IntVect &les_polys, DoubleTab &valeurs) const override
provoque une erreur ! doit etre surchargee par les classes derivees
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
int nb_compo_
Definition Field_base.h:95
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 void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.cpp:455
Classe de base des flux de sortie.
Definition Sortie.h:52
int nb_dim() const
Definition TRUSTTab.h:199
_SIZE_ size() const
Definition TRUSTVect.tpp:45
_SIZE_ size_totale() const
Definition TRUSTVect.tpp:61
void resize(_SIZE_, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTVect.tpp:91