TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
Champ_input_P0.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_input_P0.h>
17#include <Probleme_base.h>
18#include <Schema_Temps_base.h>
19#include <Interprete.h>
20#include <Domaine.h>
21#include <Sous_Domaine.h>
22#include <ICoCoExceptions.h>
23
24#include <Convert_ICoCoTrioField.h>
25#include <Domaine_VF.h>
26
27Implemente_instanciable(Champ_input_P0,"Champ_input_P0",Champ_Fonc_P0_base);
28// XD champ_input_p0 champ_input_base champ_input_p0 BRACE not_set
29
30
31using ICoCo::WrongArgument;
32
34{
35//#ifdef INT_is_64_
36// Cerr << "Champ_input_P0 uses medcoupling and is not supported for 64bits integer indices" << finl;
37// Process::exit();
38//#endif
39
40 sous_domaine_ok=true;
41 read(is);
42
43 valeurs_.resize(0, nb_compo_);
44 mon_pb->domaine().creer_tableau_elements(valeurs_);
45 associer_domaine_dis_base(mon_pb->domaine_dis());
46 mon_pb->addInputField(*this);
47
48
49 if (initial_value_.size_array()>0)
50 {
51 int nb_elem_tot=valeurs_.dimension_tot(0);
52 for (int ele=0; ele< nb_elem_tot; ele++)
53 for (int c=0; c<nb_compo_; c++)
54 valeurs_(ele,c)=initial_value_[c];
55 }
56
57 if (mon_sous_domaine)
58 {
59 const Sous_Domaine& ssz=mon_sous_domaine.valeur();
60 nb_elems_reels_loc_ = mon_pb->domaine().les_elems().dimension(0);
61 for (int i = 0; i < ssz.nb_elem_tot(); i++)
62 nb_elems_reels_sous_domaine_ += (ssz[i] < nb_elems_reels_loc_);
63 }
64 return is;
65}
66
68{
69 return os;
70}
71
73{
75}
76
78{
79 nommer(name);
80}
81
83{
84 return le_nom();
85}
86
87/*! @brief Provides afield with a name, a time interval, components, and no field ownership.
88 *
89 * The geometry includes all nodes of the domain and all elements of the sous_domaine or domain.
90 * WEC : optimization possible here (recalculated each time)
91 *
92 */
93void Champ_input_P0::getTemplate(TrioField& afield) const
94{
95
96 afield.clear();
97 afield.setName(le_nom().getChar());
98
99 afield._time1=mon_pb->presentTime();
100 afield._time2=mon_pb->futureTime();
101
102 afield._nb_field_components=nb_comp();
103
104 /* coordonnees */
105 const DoubleTab& sommets=mon_pb->domaine().les_sommets();
106 afield._nbnodes=sommets.dimension(0);
107 afield._mesh_dim = afield._space_dim = sommets.dimension(1);
108 affecte_double_avec_doubletab(&afield._coords,sommets);
109
110 /* connectivites */
111 const Domaine_VF& zvf = domaine_vf();
112 afield._nb_elems = mon_sous_domaine ? nb_elems_reels_sous_domaine_ : zvf.nb_elem();
113 Motcle type_elem = zvf.domaine().type_elem()->que_suis_je();
114 if (type_elem != "POLYEDRE") //cas simple -> il suffit de copier les_elems
115 {
116 const IntTab& conn = zvf.domaine().les_elems();
117 //le seul moyen qu'on a d'eviter que des polygones soient pris pour des quadrilateres est d'avoir un tableau de connectivite de largeur > 4...
118 afield._nodes_per_elem = std::max(conn.dimension(1), type_elem == "POLYGONE" ? (int) 5 : 0);
119 afield._connectivity = new int[afield._nb_elems * afield._nodes_per_elem];
120 for (int i = 0; i < afield._nb_elems; i++)
121 for (int j = 0; j < afield._nodes_per_elem; j++)
122 {
123 const int e = mon_sous_domaine ? mon_sous_domaine.valeur()[i] : i; //numero de l'element
124 afield._connectivity[afield._nodes_per_elem * i + j] = j < conn.dimension(1) ? conn(e, j) : -1;
125 }
126 }
127 else //polyedres -> il faut reconstruire une connectivite de type MEDCoupling a la main
128 {
129 afield._nodes_per_elem = zvf.elem_faces().dimension(1) * (zvf.face_sommets().dimension(1) + 1); //un -1 apres chaque face
130 int *p = afield._connectivity = new int[afield._nb_elems * afield._nodes_per_elem];
131 for (int i = 0, j, k, e, f, s; i < (mon_sous_domaine ? mon_sous_domaine->nb_elem_tot() : zvf.nb_elem()); i++)
132 {
133 if (mon_sous_domaine && mon_sous_domaine.valeur()[i] >= zvf.nb_elem()) continue; //element non reel du sous-domaine -> on saute
134 e = mon_sous_domaine ? mon_sous_domaine.valeur()[i] : i; //numero de l'element
135 int *pf = p + afield._nodes_per_elem; //fin de la ligne
136 /* insertion de la connectivite de chaque face, suivie d'un -1 */
137 for (j = 0; j < zvf.elem_faces().dimension(1) && (f = zvf.elem_faces(e, j)) >= 0; j++, *p = -1, p++)
138 for (k = 0; k < zvf.face_sommets().dimension(1) && (s = zvf.face_sommets(f, k)) >= 0; k++) *p = s, p++;
139 /* des -1 jusqu'a la ligne suivante */
140 for ( ; p < pf; p++) *p = -1;
141 }
142 }
143}
144
145/*! @brief Fills valeurs_ on either the whole domain or a subdomaine
146 *
147 */
148void Champ_input_P0::setValue(const TrioField& afield)
149{
150 if (mon_sous_domaine)
151 {
152 const Sous_Domaine& ssz=mon_sous_domaine.valeur();
153 if (afield._nb_elems != nb_elems_reels_sous_domaine_)
154 throw WrongArgument(mon_pb->le_nom().getChar(),"setInputField","afield","should have the same _nb_elems as returned by getInputFieldTemplate");
155 assert(valeurs_.dimension(1)==nb_compo_);
156 if (afield._nb_field_components!=valeurs_.dimension(1))
157 throw WrongArgument(mon_pb->le_nom().getChar(),"setInputField","afield","should have the same _nb_field_components as returned by getInputFieldTemplate");
158 for (int i=0, j, k = -1; i<ssz.nb_elem_tot(); i++)
159 if (ssz[i] < nb_elems_reels_loc_)
160 for (j = 0, k++ ; j<nb_compo_; j++)
161 valeurs_(ssz[i],j)=afield._field[k*nb_compo_+j];
162 }
163 else
165
166}
DoubleTab valeurs_
void associer_domaine_dis_base(const Domaine_dis_base &) override
virtual const Domaine_VF & domaine_vf() const
void setValueOnTab(const TrioField &afield, DoubleTab &tab)
void read(Entree &is)
Lecture d'un champ input dans un flot d'entree Factorisation des readOn des differents Champ_input.
ArrOfDouble initial_value_
class Champ_input_P0
void set_nb_comp(int i) override
void set_name(const Nom &) override
void setValue(const TrioField &afield) override
Fills valeurs_ on either the whole domain or a subdomaine.
virtual const Nom & get_name() const
void getTemplate(TrioField &afield) const override
Provides afield with a name, a time interval, components, and no field ownership.
IntTab_t & les_elems()
Definition Domaine.h:129
class Domaine_VF
Definition Domaine_VF.h:44
int face_sommets(int i, int j) const
renvoie le numero du ieme sommet de la face num_face.
Definition Domaine_VF.h:583
int elem_faces(int i, int j) const
renvoie le numero de le ieme face de la maille num_elem la facon dont ces faces sont numerotees est
Definition Domaine_VF.h:543
const Domaine & domaine() const
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.
const Nom & le_nom() const override
Renvoie le nom du champ.
void nommer(const Nom &) override
Donne un nom au champ.
virtual int nb_comp() const
Definition Field_base.h:56
int nb_compo_
Definition Field_base.h:95
Une chaine de caractere (Nom) en majuscules.
Definition Motcle.h:26
class Nom Une chaine de caractere pour nommer les objets de TRUST
Definition Nom.h:31
static int dimension
Definition Objet_U.h:99
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 de base des flux de sortie.
Definition Sortie.h:52
int_t nb_elem_tot() const
Domaine_t & domaine()
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133