TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Source_Qdm_EF.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 <Domaine_Cl_dis_base.h>
17#include <Champ_Uniforme.h>
18
19#include <Source_Qdm_EF.h>
20#include <Equation_base.h>
21#include <Probleme_base.h>
22#include <Domaine_Cl_EF.h>
23#include <Domaine_EF.h>
24#include <Domaine.h>
25
26Implemente_instanciable(Source_Qdm_EF,"Source_Qdm_EF",Source_base);
27
29{
30 return s << que_suis_je() ;
31}
32
34{
35 Motcle type;
36 s >> type;
37 la_source_lu.typer(type);
38 Champ_Don_base& ch_source_lu = ref_cast(Champ_Don_base,la_source_lu.valeur());
39 s >> ch_source_lu;
40 const int nb_comp = ch_source_lu.nb_comp();
41
42 if (ch_source_lu.nb_comp() != dimension)
43 {
44 Cerr << "Error reading the source term of type " << que_suis_je() << finl;
45 Cerr << "the source field must have " << dimension << " components" << finl;
46 exit();
47 }
48
49 equation().probleme().discretisation().discretiser_champ("champ_elem", equation().domaine_dis(), "Source_Qdm", "N/m3",nb_comp,0., la_source);
50 la_source_lu->fixer_nb_comp(nb_comp);
51 if (ch_source_lu.le_nom()=="anonyme") ch_source_lu.nommer("Source_Qdm");
52
53 for (int n = 0; n < nb_comp; n++) la_source_lu->fixer_nom_compo(n, ch_source_lu.le_nom() + (nb_comp > 1 ? Nom(n) :""));
54 for (int n = 0; n < nb_comp; n++) la_source->fixer_nom_compo(n, ch_source_lu.le_nom() + (nb_comp > 1 ? Nom(n) :""));
55 // PL: nommer_completer_champ_physique must be called for both fields (crash otherwise for a Champ_fonc_tabule source type)
56 equation().discretisation().nommer_completer_champ_physique(equation().domaine_dis(),ch_source_lu.le_nom(),"N/m3",la_source_lu,equation().probleme());
57 equation().discretisation().nommer_completer_champ_physique(equation().domaine_dis(),ch_source_lu.le_nom(),"N/m3",la_source,equation().probleme());
58 la_source->valeurs() = 0.;
59 la_source->affecter(ch_source_lu);
60
61 return s ;
62}
63
65{
66 ;
67}
68
70 const Domaine_Cl_dis_base& domaine_Cl_dis)
71{
72 le_dom_EF = ref_cast(Domaine_EF, domaine_dis);
73 le_dom_Cl_EF = ref_cast(Domaine_Cl_EF, domaine_Cl_dis);
74}
75
76
77DoubleTab& Source_Qdm_EF::ajouter(DoubleTab& resu) const
78{
79 const Domaine_EF& domaine_EF = le_dom_EF.valeur();
80 int ncomp=dimension;
81 const IntTab& elems= domaine_EF.domaine().les_elems() ;
82 int nb_som_elem=domaine_EF.domaine().nb_som_elem();
83 int nb_elems=domaine_EF.domaine().nb_elem_tot();
84 const DoubleTab& IPhi_thilde=domaine_EF.IPhi_thilde();
85 int is_source_unif=0;
86
87 if (sub_type(Champ_Uniforme,la_source.valeur()))
88 is_source_unif=1;
89 const DoubleTab& tab_source=la_source->valeurs();
90 for (int num_elem=0; num_elem<nb_elems; num_elem++)
91 for (int comp=0; comp<ncomp; comp++)
92 {
93 double sourcel ;
94 int cc=0;
95 if (!is_source_unif) cc=num_elem;
96 sourcel=tab_source(cc,comp);
97 for (int i=0; i<nb_som_elem; i++)
98 {
99 // assert is wrong if porosities are present
100 // assert(est_egal(domaine_EF.volumes(num_elem)/nb_som_elem,IPhi_thilde(num_elem,i)));
101 resu(elems(num_elem,i),comp)+=sourcel*IPhi_thilde(num_elem,i);
102 }
103 }
104
105 return resu;
106}
107
108DoubleTab& Source_Qdm_EF::calculer(DoubleTab& resu) const
109{
110 resu = 0;
111 return ajouter(resu);
112}
113
115{
116 la_source_lu->mettre_a_jour(temps);
117 la_source->affecter(la_source_lu.valeur());
118}
119
120
121/*##################################################################################################
122####################################################################################################
123################################# POSTRAITEMENT ####################################################
124####################################################################################################
125##################################################################################################*/
126
128{
129 if (motlu=="source_qdm" && !champ_source_qdm_)
130 {
131 Motcle directive("champ_elem");
132 int nb_comp = dimension;
133 Noms noms(nb_comp);
134 noms[0]="source_qdm";
135 Noms unites(nb_comp);
136 unites[0] = "N/m3";
137 double temps=0.;
138 equation().discretisation().discretiser_champ(directive,equation().domaine_dis(),vectoriel,noms,unites,nb_comp,temps,champ_source_qdm_);
139 champs_compris_.ajoute_champ(champ_source_qdm_);
140 }
141}
142
143bool Source_Qdm_EF::has_champ(const Motcle& nom, OBS_PTR(Champ_base) &ref_champ) const
144{
145 if (nom == "source_qdm" && champ_source_qdm_)
146 {
147 ref_champ = Source_Qdm_EF::get_champ(nom);
148 return true;
149 }
150 else
151 return false; /* nothing found */
152}
153
154bool Source_Qdm_EF::has_champ(const Motcle& nom) const
155{
156 if (Source_base::has_champ(nom)) return true;
157
158 if (nom == "source_qdm" && champ_source_qdm_)
159 return true;
160 else
161 return false; /* nothing found */
162}
163
165{
166 if (nom=="source_qdm")
167 {
168 if (!champ_source_qdm_)
169 throw std::runtime_error(std::string("Field ") + nom.getString() + std::string(" not found !"));
170
171 int is_source_unif=0;
172 if (sub_type(Champ_Uniforme,la_source.valeur()))
173 is_source_unif=1;
174
175 // Initialize the post-processing field to 0
176 DoubleTab& valeurs = champ_source_qdm_->valeurs();
177 valeurs=0.;
178 const DoubleTab& tab_source=la_source->valeurs();
179 if (tab_source.size_array()>0)
180 {
181 int nb_elem=tab_source.dimension(0);
182 for (int num_el=0; num_el<nb_elem; num_el++)
183 for (int k=0; k<dimension; k++)
184 {
185 int cc=0;
186 if (!is_source_unif) cc=num_el;
187 valeurs(num_el,k)=tab_source(cc,k);
188 }
189 }
190 valeurs.echange_espace_virtuel();
191 champ_source_qdm_->mettre_a_jour(equation().probleme().schema_temps().temps_courant());
192 return champs_compris_.get_champ(nom);
193 }
194 else
195 return champs_compris_.get_champ(nom);
196}
197
199{
201
202 Noms noms_compris = champs_compris_.liste_noms_compris();
203 noms_compris.add("source_qdm");
204 if (opt==DESCRIPTION)
205 Cerr<<" Source_Qdm_EF : "<< noms_compris <<finl;
206 else
207 nom.add(noms_compris);
208}
Champ_Uniforme Represents a field that is constant in space and time.
class Champ_base This class is the base of the fields hierarchy.
Definition Champ_base.h:43
void nommer_completer_champ_physique(const Domaine_dis_base &domaine_vdf, const Nom &nom_champ, const Nom &unite, Champ_base &champ, const Probleme_base &pbi) const
void discretiser_champ(const Motcle &directive, const Domaine_dis_base &z, const Nom &nom, const Nom &unite, int nb_comp, int nb_pas_dt, double temps, OWN_PTR(Champ_Inc_base)&champ, const Nom &sous_type=NOM_VIDE) const
int nb_som_elem() const
Returns the number of vertices of the geometric elements that make up the domain.
Definition Domaine.h:474
int_t nb_elem_tot() const
Definition Domaine.h:132
IntTab_t & les_elems()
Definition Domaine.h:129
class Domaine_Cl_dis_base Domaine_Cl_dis_base objects represent discretized boundary conditions
class Domaine_EF
Definition Domaine_EF.h:56
const DoubleTab & IPhi_thilde() const
Definition Domaine_EF.h:92
class Domaine_dis_base This class is the base of the hierarchy of discretized domains.
const Domaine & domaine() const
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
const Discretisation_base & discretisation() const
Returns the discretization associated with the equation.
Probleme_base & probleme()
Returns the problem associated with the equation.
const Nom & le_nom() const override
Returns the name of the field.
void nommer(const Nom &) override
Gives a name to the field.
virtual int nb_comp() const
Definition Field_base.h:56
const Equation_base & equation() const
Returns the reference to the equation pointed to by MorEqn::mon_equation.
Definition MorEqn.h:62
A character string (Nom) in uppercase.
Definition Motcle.h:26
const std::string & getString() const
Definition Nom.h:92
An array of character strings (VECT(Nom)).
Definition Noms.h:26
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
class Probleme_base It is a Probleme_U that is not a coupling.
const Discretisation_base & discretisation() const
Returns the discretization associated with the problem.
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
class Source_Qdm_EF
OBS_PTR(Domaine_EF) le_dom_EF
const Champ_base & get_champ(const Motcle &nom) const override
void creer_champ(const Motcle &motlu) override
bool has_champ(const Motcle &nom, OBS_PTR(Champ_base) &ref_champ) const override
DoubleTab & calculer(DoubleTab &) const override
DoubleTab & ajouter(DoubleTab &) const override
void get_noms_champs_postraitables(Noms &nom, Option opt=NONE) const override
void associer_domaines(const Domaine_dis_base &, const Domaine_Cl_dis_base &) override
void associer_pb(const Probleme_base &) override
void mettre_a_jour(double) override
DOES NOTHING - to override in derived classes.
Source_base A Source_base object is a term appearing on the right-hand side of an.
Definition Source_base.h:42
Champs_compris champs_compris_
bool has_champ(const Motcle &nom, OBS_PTR(Champ_base) &ref_champ) const override
void get_noms_champs_postraitables(Noms &nom, Option opt=NONE) const override
_SIZE_ size_array() const
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133
virtual void echange_espace_virtuel(IsExchangeBlocking exchange_type=IsExchangeBlocking::DefaultBlocking, const std::string kernel_name="noname")