TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Champ_Uniforme_Morceaux.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_Uniforme_Morceaux.h>
17
18Implemente_instanciable(Champ_Uniforme_Morceaux,"Champ_Uniforme_Morceaux",Champ_Don_base);
19// XD champ_uniforme_morceaux champ_don_base champ_uniforme_morceaux NO_BRACE Field which is partly constant in space
20// XD_CONT and stationary.
21// XD attr nom_dom ref_domaine nom_dom REQ Name of the domain to which the sub-areas belong.
22// XD attr nb_comp entier nb_comp REQ Number of field components.
23// XD attr data bloc_lecture data REQ { Defaut val_def sous_zone_1 val_1 ... sous_zone_i val_i } By default, the value
24// XD_CONT val_def is assigned to the field. It takes the sous_zone_i identifier Sous_Zone (sub_area) type object value,
25// XD_CONT val_i. Sous_Zone (sub_area) type objects must have been previously defined if the operator wishes to use a
26// XD_CONT Champ_Uniforme_Morceaux(partly_uniform_field) type object.
27
28
29Sortie& Champ_Uniforme_Morceaux::printOn(Sortie& os) const { return os << valeurs(); }
30
31/*! @brief Reads the values of the piecewise uniform field from an input stream.
32 *
33 * Reads the domain name (nom_domaine), the number of field components (nb_comp), the default value
34 * of the field and the values on the subdomains.
35 * Format:
36 * Champ_Uniforme_Morceaux nom_domaine nb_comp
37 * { Defaut val_def sous_domaine_1 val_1 ... sous_domaine_i val_i }
38 *
39 */
41{
42 int dim;
43 Motcle motlu;
44 Nom nom;
45 int k, poly;
46 is >> nom;
48 Domaine& le_domaine=mon_domaine.valeur();
49 const IntTab& les_elems=le_domaine.les_elems();
50 const int nb_som_elem = le_domaine.nb_som_elem();
51 double x=0,y=0,z=0;
52
54 fixer_nb_comp(dim);
55 valeurs_.resize(0, dim);
57 is >> nom;
58 motlu=nom;
59 if(motlu != Motcle("{") )
60 {
61 Cerr << "Error while reading a " << que_suis_je() << finl;
62 Cerr << "We expected a { instead of " << nom << finl;
63 exit();
64 }
65 is >> nom;
66 motlu=nom;
67 if(motlu != Motcle("defaut") )
68 {
69 Cerr << "Error while reading a " << que_suis_je() << finl;
70 Cerr << "We expected defaut instead of " << nom << finl;
71 exit();
72 }
73
74 VECT(Parser_U) fxyz(dim);
75 for( k=0; k< dim; k++)
76 {
77 Nom tmp;
78 is >> tmp;
79 fxyz[k].setNbVar(3);
80 fxyz[k].setString(tmp);
81 fxyz[k].addVar("x");
82 fxyz[k].addVar("y");
83 fxyz[k].addVar("z");
84 fxyz[k].parseString();
85 }
86
87 for( poly=0; poly<le_domaine.nb_elem(); poly++)
88 {
89 x = y = z = 0;
90 int nsom = 0, e=-1;
91 for (int isom = 0; isom<nb_som_elem; isom++)
92 if ((e = les_elems(poly,isom)) >= 0)
93 {
94 x += le_domaine.coord(e,0);
95 y += le_domaine.coord(e,1);
96 if (dimension == 3) z += le_domaine.coord(e,2);
97 nsom++;
98 }
99 x = x/nsom;
100 y = y/nsom;
101 z = z/nsom;
102 for( k=0; k< dim; k++)
103 {
104 fxyz[k].setVar("x",x);
105 fxyz[k].setVar("y",y);
106 fxyz[k].setVar("z",z);
107 valeurs_(poly,k)=fxyz[k].eval();
108 }
109 }
110
111 is >> nom;
112 motlu=nom;
113 while (motlu != Motcle("}") )
114 {
115 OBS_PTR(Sous_Domaine) refssz=les_sous_domaines.add(le_domaine.ss_domaine(nom));
116 Sous_Domaine& ssz = refssz.valeur();
117 for( k=0; k< dim; k++)
118 {
119 Nom tmp;
120 is >> tmp;
121 fxyz[k].setString(tmp);
122 fxyz[k].parseString();
123 }
124 for( poly=0; poly<ssz.nb_elem_tot(); poly++)
125 {
126 x = y = z = 0;
127 int nsom = 0, e=-1;
128 for (int isom = 0; isom<nb_som_elem; isom++)
129 if ((e = les_elems(ssz(poly),isom)) >= 0)
130 {
131 x += le_domaine.coord(e,0);
132 y += le_domaine.coord(e,1);
133 if (dimension == 3) z += le_domaine.coord(e,2);
134 nsom++;
135 }
136 x = x/nsom;
137 y = y/nsom;
138 z = z/nsom;
139 for( k=0; k< dim; k++)
140 {
141 fxyz[k].setVar("x",x);
142 fxyz[k].setVar("y",y);
143 fxyz[k].setVar("z",z);
144 valeurs_(ssz(poly),k)=fxyz[k].eval();
145 }
146 }
147 is >> nom;
148 motlu=nom;
149 }
151 return is;
152}
153
155{
156 if (sub_type(Champ_Uniforme_Morceaux, ch))
157 {
158 const Champ_Uniforme_Morceaux& chum = ref_cast(Champ_Uniforme_Morceaux, ch);
159 les_sous_domaines = chum.sous_domaines();
160 mon_domaine = chum.domaine();
161 valeurs_ = chum.valeurs();
162 }
163 else if (sub_type(Champ_Uniforme, ch))
164 {
165 const Champ_Uniforme& chu = ref_cast(Champ_Uniforme, ch);
166 const int nb_poly = valeurs_.dimension(0), dim = valeurs_.dimension(1);
167 const DoubleTab& ch_val = chu.valeurs();
168 for (int k = 0; k < dim; k++)
169 for (int poly = 0; poly < nb_poly; poly++) valeurs_(poly, k) = ch_val(0, k);
170 }
171 else
172 {
173 Cerr << "It is not known to affect a " << ch.que_suis_je() << " at a " << que_suis_je() << finl;
175 }
176 return *this;
177}
class Champ_Don_base base class of Given Fields (not calculated)
DoubleTab & valeurs() override
Overrides Champ_base::valeurs() Returns the array of values.
DoubleTab valeurs_
int lire_dimension(Entree &, const Nom &)
Verification of the field dimension Returns the dimension of the field.
Champ_Uniforme_Morceaux This class represents a piecewise constant-in-space field.
Champ_base & affecter_(const Champ_base &ch) override
Causes an error! To be overridden by derived classes! Not a pure virtual for development convenience!
Champ_Uniforme Represents a field that is constant in space and time.
Champ_base()
Default constructor of a Champ_base.
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
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
IntTab_t & les_elems()
Definition Domaine.h:129
int_t nb_elem() const
Definition Domaine.h:131
double coord(int_t i, int j) const
Definition Domaine.h:110
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
virtual void fixer_nb_comp(int i)
Sets the number of components of the field.
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
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
virtual void echange_espace_virtuel(IsExchangeBlocking exchange_type=IsExchangeBlocking::DefaultBlocking, const std::string kernel_name="noname")