TrioCFD 1.9.8
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; // pour planter si on a oublie un sous-domaine
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. lecture du sous-domaine */
57 OBS_PTR(Sous_Domaine) refssz = les_sous_domaines.add(mon_domaine->ss_domaine(nom));
58 Sous_Domaine& ssz = refssz.valeur();
59
60 /* 2. lecture des champs parametres */
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); //ajout aux listes pour ce morceau et globale
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. lecture de la grille de parametres */
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. lecture des valeurs des parametres */
95 // taille totale du tableau de valeurs
96 int size = nbcomp;
97 for (int n = 0; n < nb_param; n++) size *= params[n].size();
98
99 // lecture : tout dans un tableau 1D
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 /* remplissage de ch_param (pointeurs vers les champs) et des i_ch (champs utilises par chaque morceau) */
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) /* (probleme, champ) -> pointeurs */
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; /* valeurs des parametres */
142 std::vector<DoubleTrav> tval; /* tableaux temporaires */
143 std::vector<bool> is_multi; /* true si le champ correspondant est multi_composantes */
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()); //pour ignorer les variables aux de PolyMAC_HFV
148 if (tab.get_md_vector() == part[0].get_md_vector()) /* on est bien aux elements -> utilisation directe */
149 pval.push_back(&pch->valeurs());
150 else /* sinon -> calcul des valeurs aux elems et stockage dans un tableau de tval */
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]])); /* si le champ parametre est multi-compo, on prend la meme que celle du champ */
170 tab(e, n) = mor.la_table.val(vals, n);
171 }
172 }
174}
DoubleTab & valeurs() override
Surcharge Champ_base::valeurs() Renvoie le tableau des valeurs.
DoubleTab valeurs_
classe Champ_Fonc_Tabule_Morceaux Cette classe represente un champ prenant par morceaux des valuers f...
int initialiser(const double temps) override
NE FAIT RIEN.
void mettre_a_jour(double temps) override
Mise a jour en temps.
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 de la dimension du champ Renvoie la dimension du champ.
Champ_base()
Constructeur par defaut d'un 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)
Fixe le nombre de composantes du champ.
static Objet_U & objet(const Nom &)
Voir Interprete_bloc::objet_global() BM: la classe Interprete n'est pas le meilleur endroit pour cett...
class Nom Une chaine de caractere pour nommer les objets de TRUST
Definition Nom.h:31
const Nom & que_suis_je() const
renvoie la chaine identifiant la classe.
Definition Objet_U.cpp:104
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
classe Probleme_base C'est un Probleme_U qui n'est pas un couplage.
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)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.cpp:455
Classe de base des flux de sortie.
Definition Sortie.h:52
const Nom & le_nom() const override
Donne le nom de l'Objet_U Methode a surcharger : renvoie "neant" dans cette implementation.
int_t nb_elem_tot() const
int initialiser(const double temps) override
NE FAIT RIEN.
_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:130
double val(const double val_param, int ncomp=0) const
Definition Table.cpp:145