TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Champ_Fonc_Tabule_Morceaux.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 <Champ_Fonc_Tabule_Morceaux.h>
17#include <Domaine.h>
18#include <TRUSTTrav.h>
19#include <Domaine_VF.h>
20#include <TRUSTTab_parts.h>
21
22Implemente_instanciable(Champ_Fonc_Tabule_Morceaux, "Champ_Fonc_Tabule_Morceaux|Champ_Tabule_Morceaux", TRUSTChamp_Morceaux_generique<Champ_Morceaux_Type::FONC_TABULE>);
23// XD Champ_Fonc_Tabule_Morceaux champ_don_base Champ_Tabule_Morceaux NO_BRACE Field defined by tabulated data in each
24// XD_CONT sub-domaine. It makes possible the definition of a field which is a function of other fields.
25// XD attr domain_name ref_domaine domain_name REQ Name of the domain.
26// XD attr nb_comp entier nb_comp REQ Number of field components.
27// XD attr data bloc_lecture data REQ { Defaut val_def sous_domaine_1 val_1 ... sous_domaine_i val_i } By default, the
28// XD_CONT value val_def is assigned to the field. It takes the sous_domaine_i identifier Sous_Domaine (sub_area) type
29// XD_CONT object function, val_i. Sous_Domaine (sub_area) type objects must have been previously defined if the
30// XD_CONT operator wishes to use a champ_fonc_tabule_morceaux type object.
31
32Sortie& Champ_Fonc_Tabule_Morceaux::printOn(Sortie& os) const { return os << valeurs(); }
33
35{
36 Nom nom, nom_ch;
37 is >> nom;
39 mon_domaine->creer_tableau_elements(i_mor);
40 i_mor = -1; // to crash if a sub-domain was forgotten
41
42 int nbcomp;
43 is >> nbcomp;
44
45 fixer_nb_comp(nbcomp);
46 valeurs_.resize(0, nbcomp);
47 mon_domaine->creer_tableau_elements(valeurs_);
48
49 is >> nom;
50 if(nom != "{")
51 Process::exit(que_suis_je() + " : { expected instead of " + nom);
52
53 for (is >> nom; nom != "}"; is >> nom)
54 {
55 CHTAB ch_lu;
56 /* 1. reading the subdomain */
57 OBS_PTR(Sous_Domaine) refssz = les_sous_domaines.add(mon_domaine->ss_domaine(nom));
58 Sous_Domaine& ssz = refssz.valeur();
59
60 /* 2. reading the parameter fields */
61 is >> nom, m_pb_ch.push_back({});
62 if (nom != "{")
63 {
64 Cerr << "Errror reading old syntax: " << que_suis_je() << " " << domaine()->le_nom() << " " << nbcomp << " { " << ssz.le_nom() << " " << nom << " 1 { ... } ... }" << finl;
65 Cerr << "New syntax is like : " << que_suis_je() << " " << domaine()->le_nom() << " " << nbcomp << " { " << ssz.le_nom() << " { problem_name " << nom << " } { ... } ... }" << finl;
66 Cerr << "Check the doc or release notes." << finl;
68 }
69 else for (is >> nom; nom != "}"; is >> nom)
70 {
71 is >> nom_ch;
72 Nom nat = "";
73 if (is_interp_) is >> nat;
74 std::array<std::string, 3> pb_ch = { nom.getString(), nom_ch.getString(), nat.getString() };
75 s_pb_ch.insert(pb_ch), m_pb_ch.back().push_back(pb_ch); //add to the lists for this piece and globally
76 }
77
78 const int nb_param = (int)m_pb_ch.back().size();
79
80 is >> nom;
81 if (nom != "{")
82 Process::exit(que_suis_je() + " : { expected instead of " + nom);
83
84 /* 1. reading the parameter grid */
85 DoubleVects params;
86 for (int n = 0; n < nb_param; n++)
87 {
88 const int nb_val = lire_dimension(is, que_suis_je());
89 DoubleVect param(nb_val);
90 for (int i = 0; i < nb_val; i++) is >> param[i];
91 params.add(param);
92 }
93
94 /* 2. reading the parameter values */
95 // total size of the value array
96 int size = nbcomp;
97 for (int n = 0; n < nb_param; n++) size *= params[n].size();
98
99 // reading: everything into a 1D array
100 DoubleVect tab_valeurs(size);
101 for (int i = 0; i < size; i++) is >> tab_valeurs[i];
102 ch_lu.la_table.remplir(params, tab_valeurs);
103
104 is >> nom;
105 if (nom != "}")
106 Process::exit(que_suis_je() + " : } expected instead of "+ nom);
107 for (int i = 0; i < ssz.nb_elem_tot(); i++) i_mor(ssz(i)) = (int)morceaux.size();
108 morceaux.push_back(ch_lu);
109 }
110 if (mp_min_vect(i_mor) == -1)
111 Process::exit(que_suis_je() + " : some pieces of the field are missing!");
112
113 return is;
114}
115
117{
118 /* fill ch_param (pointers to the fields) and i_ch (fields used by each piece) */
119 std::vector<std::array<std::string, 3>> v_pb_ch(s_pb_ch.begin(), s_pb_ch.end()); //set -> vector
120 for (auto &&pb_ch : v_pb_ch) /* (problem, field) -> pointers */
121 {
122 const Nom pb_nom = Nom(pb_ch[0]);
123 const Probleme_base& pb = ref_cast(Probleme_base, Interprete::objet(pb_nom));
124 const Champ_base& ch = pb.has_champ(Nom(pb_ch[1])) ? pb.get_champ(Nom(pb_ch[1])) : pb.get_champ_post(Nom(pb_ch[1])).get_champ(espace_stockage_);
125 ch_param.push_back(&ch);
126 }
127 for (int i = 0; i < (int) m_pb_ch.size(); i++)
128 for (auto && pb_ch : m_pb_ch[i]) /* indices */
129 morceaux[i].i_ch.push_back((int)(std::lower_bound(v_pb_ch.begin(), v_pb_ch.end(), pb_ch) - v_pb_ch.begin()));
130
131 m_pb_ch.clear();
132 s_pb_ch.clear();
133
135}
136
138{
139
140 DoubleTab& tab = valeurs(), vide;
141 std::vector<const DoubleTab* > pval; /* parameter values */
142 std::vector<DoubleTrav> tval; /* temporary arrays */
143 std::vector<bool> is_multi; /* true if the corresponding field is multi-component */
144 pval.reserve(ch_param.size()), tval.reserve(ch_param.size()), is_multi.reserve(ch_param.size());
145 for (auto &&pch : ch_param)
146 {
147 ConstDoubleTab_parts part(pch->valeurs()); //to ignore auxiliary variables of PolyMAC_HFV
148 if (tab.get_md_vector() == part[0].get_md_vector()) /* we are indeed at elements -> direct use */
149 pval.push_back(&pch->valeurs());
150 else /* otherwise -> compute values at elements and store in a tval array */
151 {
152 IntVect polys(tab.dimension_tot(0));
153 for (int i = 0; i < tab.dimension_tot(0); i++) polys[i] = i;
154 tval.push_back(DoubleTab(tab.dimension_tot(0), pch->nb_comp()));
155 pch->valeur_aux_elems(pch->a_un_domaine_dis_base() ? ref_cast(Domaine_VF, pch->domaine_dis_base()).xp() : vide, polys, tval.back());
156 pval.push_back(&tval.back());
157 }
158 is_multi.push_back(pval.back()->dimension(1) > 1);
159 }
160 std::vector<double> vals(ch_param.size());
161 for (int e = 0; e < mon_domaine->nb_elem(); e++)
162 {
163 const CHTAB& mor = morceaux[i_mor(e)];
164 int N = tab.dimension(1), M = (int) mor.i_ch.size();
165 if (N == 1 && M == 1)
166 tab(e, 0) = mor.la_table.val_simple((*pval[mor.i_ch[0]])(e, 0));
167 else for (int n = 0, m; n < N; n++)
168 {
169 for (vals.clear(), m = 0; m < M; m++) vals.push_back((*pval[mor.i_ch[m]])(e, n * is_multi[mor.i_ch[m]])); /* if the parameter field is multi-component, take the same component as the field */
170 tab(e, n) = mor.la_table.val(vals, n);
171 }
172 }
174}
DoubleTab & valeurs() override
Overrides Champ_base::valeurs() Returns the array of values.
DoubleTab valeurs_
class Champ_Fonc_Tabule_Morceaux
int initialiser(const double temps) override
DOES NOTHING.
void mettre_a_jour(double temps) override
Time update.
std::vector< const Champ_base * > ch_param
std::vector< std::vector< ArrStr > > m_pb_ch
virtual const Champ_base & get_champ(OWN_PTR(Champ_base) &espace_stockage) const =0
int lire_dimension(Entree &, const Nom &)
Verification of the field dimension Returns the dimension of the field.
Champ_base()
Default constructor of a Champ_base.
class Domaine_VF
Definition Domaine_VF.h:44
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 Objet_U & objet(const Nom &)
See Interprete_bloc::objet_global(). BM: the Interprete class is not the best place for this.
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
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
class Probleme_base It is a Probleme_U that is not a coupling.
bool has_champ(const Motcle &nom, OBS_PTR(Champ_base) &ref_champ) const override
const Champ_base & get_champ(const Motcle &nom) const override
virtual const Champ_Generique_base & get_champ_post(const Motcle &nom) const
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
const Nom & le_nom() const override
Returns the name of the Objet_U. Virtual method to override: returns "neant" in this implementation.
int_t nb_elem_tot() const
int initialiser(const double temps) override
DOES NOTHING.
_SIZE_ dimension_tot(int) const override
Definition TRUSTTab.tpp:160
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133
virtual const MD_Vector & get_md_vector() const
Definition TRUSTVect.h:123
virtual void echange_espace_virtuel(IsExchangeBlocking exchange_type=IsExchangeBlocking::DefaultBlocking, const std::string kernel_name="noname")
value_type & add()=delete
int size() const
double val_simple(double vals_param) const
Definition Table.cpp:128
double val(const double val_param, int ncomp=0) const
Definition Table.cpp:143