TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Sources.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 <Matrice_Morse.h>
17#include <TRUSTTab.h>
18#include <Sources.h>
19
20Implemente_instanciable(Sources, "Sources", LIST(Source));
21// XD sources listobj sources INHERITS_BRACE source_base INHERITS_COMMA The sources.
22
23Sortie& Sources::printOn(Sortie& os) const { return LIST(Source)::printOn(os); }
24
25/*! @brief Reading of a list of sources from an input stream.
26 *
27 * Reads a list of sources separated by commas
28 * and adds it to the list.
29 * format:
30 * {
31 * reading block of a source
32 * [, reading block of a source]
33 * ...
34 * }
35 *
36 * @param (Entree& is) the input stream
37 * @return (Entree&) the modified input stream
38 * @throws opening brace expected
39 * @throws closing brace or comma expected
40 */
41Entree& Sources::readOn(Entree& is)
42{
43 Nom accouverte="{";
44 Nom accfermee="}";
45 Nom virgule=",";
46 Nom typ;
47 is >> typ;
48 if (typ!=accouverte)
49 {
50 Cerr << "We were waiting for { before " << typ << finl;
51 exit();
52 }
53 Source t;
54 is >> typ;
55 if(typ==accfermee)
56 return is;
57 while(1)
58 {
59 Source& so=add(t);
60 Cerr << "Reading of term " << typ << finl;
61 Cerr << "and typing: ";
62 // Cout << ">>>>>>>>>>>>>>>>>>>> Type de Source = " << typ << finl;
63 so.typer(typ,mon_equation.valeur());
64 so->associer_eqn(mon_equation.valeur());
65 is >> so.valeur();
66 is >> typ;
67 if(typ==accfermee)
68 return is;
69 if(typ!=virgule)
70 {
71 Cerr << typ << " : we expected a ',' or a '}'" << finl;
72 exit();
73 }
74 assert (typ==virgule);
75 is >> typ;
76 }
77}
78
79
80/*! @brief Adds the contribution of all sources in the list to the array passed as parameter, and returns this array.
81 *
82 * @param (DoubleTab& xx) the array in which the contribution of the source terms should be accumulated
83 * @return (DoubleTab&) the modified parameter xx
84 */
85DoubleTab& Sources::ajouter(DoubleTab& xx) const
86{
87 for (const auto& itr : *this) itr.ajouter(xx);
88 return xx;
89}
90
91/*! @brief Calculates the contribution of all sources in the list and stores the result in the array passed as parameter,
92 *
93 * and returns this array.
94 *
95 * @param (DoubleTab& xx) the array in which the sum of source contributions should be stored
96 * @return (DoubleTab&) the modified parameter xx
97 */
98DoubleTab& Sources::calculer(DoubleTab& xx) const
99{
100 xx = 0.;
101 for (const auto& itr : *this) itr.ajouter(xx);
102 return xx;
103}
104
105/*! @brief Time update of all sources in the list
106 *
107 * @param (double temps) the time step for update
108 */
109void Sources::mettre_a_jour(double temps)
110{
111 for (auto& itr : *this) itr->mettre_a_jour(temps);
112}
113
114/*! @brief Rest all sources to a given time
115 * See ProblemeTrio::resetTime()
116 */
117void Sources::resetTime(double temps)
118{
119 for (auto& itr : *this) itr->resetTime(temps);
120}
121
122/*! @brief Calls Source::completer() on all sources in the list.
123 *
124 * See Source_base::completer().
125 *
126 */
128{
129 for (auto& itr : *this) itr->completer();
130}
131
132/*! @brief For each source in the list, calls the associer_champ_rho method of the source.
133 *
134 * If the density is variable, the density field must be declared
135 * to the sources using this method (front-tracking)
136 * Otherwise, by default, calculations are performed with rho=1
137 *
138 */
140{
141 for (auto& itr : *this)
142 {
143 Source& src = itr;
144 Source_base& src_base = src.valeur();
145 src_base.associer_champ_rho(champ_rho);
146 }
147}
148
149/*! @brief For each source in the list, calls a_pour_Champ_Fonc(mot,ch_ref).
150 *
151 * This method is called by Equation_base::a_pour_Champ_Fonc.
152 *
153 */
155 OBS_PTR(Champ_base)& ch_ref) const
156{
157 int ok = 0;
158 for (const auto& itr : *this)
159 {
160 const Source& src = itr;
161 const Source_base& src_base = src.valeur();
162 if (src_base.a_pour_Champ_Fonc(mot, ch_ref))
163 {
164 ok = 1;
165 break;
166 }
167 }
168 return ok;
169}
170
171/*! @brief Calls Source::impr() on all sources in the list.
172 *
173 * See Source_base::impr().
174 *
175 */
176int Sources::impr(Sortie& os) const
177{
178 for (const auto& itr : *this) itr->impr(os);
179 return 1;
180}
181
182/*! @brief Sizing of the implicit matrix of source terms.
183 *
184 * Traverses all sources in the list to size the matrix.
185 *
186 */
188{
189 for (const auto& itr : *this)
190 {
191 const Source& src = itr;
192 const Source_base& src_base = src.valeur();
193 Matrice_Morse mat;
194 src_base.dimensionner(mat);
195 if (mat.nb_colonnes()) matrice += mat;
196 }
197}
198/*! @brief Contribution to the implicit matrix of source terms. By default, no contribution.
199 *
200 */
201void Sources::contribuer_a_avec(const DoubleTab& a, Matrice_Morse& matrice) const
202{
203 for (const auto& itr : *this)
204 {
205 const Source& src = itr;
206 const Source_base& src_base = src.valeur();
207 src_base.contribuer_a_avec(a,matrice);
208 }
209}
210
212{
213 for (const auto& itr : *this)
214 {
215 const Source& src = itr;
216 const Source_base& src_base = src.valeur();
217 src_base.contribuer_jacobienne(matrice, n);
218 }
219}
220
221/*! @brief Calls Source::initialiser(temps) on all sources in the list.
222 *
223 * See Source_base::initialiser(double temps).
224 *
225 */
226int Sources::initialiser(double temps)
227{
228 int ok=1;
229 for (auto& itr : *this)
230 ok = ok && itr->initialiser(temps);
231 return ok;
232}
233
235{
236 for (const auto& itr : *this)
237 {
238 const Source& src = itr;
239 const Source_base& src_base = src.valeur();
241 }
242}
class Champ_base This class is the base of the fields hierarchy.
Definition Champ_base.h:43
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
Matrice_Morse class - Represents a (sparse) matrix M, not necessarily square,.
int nb_colonnes() const override
Return local number of columns (=size on the current proc).
virtual void check_multiphase_compatibility() const
Definition MorEqn.cpp:50
OBS_PTR(Equation_base) mon_equation
A character string (Nom) in uppercase.
Definition Motcle.h:26
Base class for output streams.
Definition Sortie.h:52
Source_base A Source_base object is a term appearing on the right-hand side of an.
Definition Source_base.h:42
virtual void associer_champ_rho(const Champ_base &champ_rho)
This method (or the method of the derived class) is called by Sources::associer_champ_rho for each so...
virtual void contribuer_a_avec(const DoubleTab &, Matrice_Morse &) const
contribution to the implicit matrix of source terms, by default no contribution
virtual void contribuer_jacobienne(Matrice_Bloc &, int) const
Definition Source_base.h:63
virtual int a_pour_Champ_Fonc(const Motcle &mot, OBS_PTR(Champ_base) &ch_ref) const
If the source understands the keyword "mot", it fills the reference to ch_ref and returns 1,...
virtual void dimensionner(Matrice_Morse &) const
Sizing of the implicit matrix of source terms.
Source Generic class of the source term hierarchy. A Source object can.
Definition Source.h:33
void typer(const Nom &, const Equation_base &)
Types the source by computing the required type name from the provided parameters.
Definition Source.cpp:52
class Sources Sources represents a list of Source objects.
Definition Sources.h:31
void contribuer_jacobienne(Matrice_Bloc &matrice, int n) const
Definition Sources.cpp:211
int impr(Sortie &) const
Calls Source::impr() on all sources in the list.
Definition Sources.cpp:176
void contribuer_a_avec(const DoubleTab &, Matrice_Morse &) const
Contribution to the implicit matrix of source terms. By default, no contribution.
Definition Sources.cpp:201
int initialiser(double temps)
Calls Source::initialiser(temps) on all sources in the list.
Definition Sources.cpp:226
void resetTime(double temps)
Rest all sources to a given time See ProblemeTrio::resetTime().
Definition Sources.cpp:117
void mettre_a_jour(double temps)
Time update of all sources in the list.
Definition Sources.cpp:109
virtual int a_pour_Champ_Fonc(const Motcle &mot, OBS_PTR(Champ_base)&ch_ref) const
For each source in the list, calls a_pour_Champ_Fonc(mot,ch_ref).
Definition Sources.cpp:154
void check_multiphase_compatibility() const override
Definition Sources.cpp:234
void dimensionner(Matrice_Morse &) const
Sizing of the implicit matrix of source terms.
Definition Sources.cpp:187
void completer()
Calls Source::completer() on all sources in the list.
Definition Sources.cpp:127
virtual void associer_champ_rho(const Champ_base &champ_rho)
For each source in the list, calls the associer_champ_rho method of the source.
Definition Sources.cpp:139
DoubleTab & ajouter(DoubleTab &) const
Adds the contribution of all sources in the list to the array passed as parameter,...
Definition Sources.cpp:85
DoubleTab & calculer(DoubleTab &) const
Calculates the contribution of all sources in the list and stores the result in the array passed as p...
Definition Sources.cpp:98