TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Field_base.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 <Field_base.h>
17
18Implemente_base_sans_constructeur(Field_base,"Field_base",Objet_U);
19// XD field_base objet_u champ_base INHERITS_BRACE Basic class of fields.
20
21
23
24Sortie& Field_base::printOn(Sortie& s ) const { return s; }
25Entree& Field_base::readOn(Entree& is ) { return is; }
26
27/*! @brief Returns the name of the field.
28 *
29 */
30const Nom& Field_base::le_nom() const
31{
32 return nom_;
33}
34
35/*! @brief Gives a name to the field
36 *
37 * @param (Nom& name) the name to give to the field
38 */
39void Field_base::nommer(const Nom& name)
40{
41 nom_ = name ;
42}
43
44/*! @brief Sets the number of components of the field.
45 *
46 * The field is vectorial if it has the same dimension as the space.
47 *
48 * @param (int i) the number of components of the field
49 */
51{
52 // Prohibition to change the field nature once the nb_valeurs_nodales is set.
53 nb_compo_ = i;
54 noms_compo_.dimensionner(i);
55
56 if (i == dimension) fixer_nature_du_champ(vectoriel);
57 else if (i > dimension) fixer_nature_du_champ(multi_scalaire);
58}
59
60/*! @brief Sets the names of the field components
61 *
62 * @param (Noms& noms) the array of names to give to the field components
63 * @return (Noms&) the array of names of the field components
64 */
66{
67 // teo boutin: not sure this assert is in line with the use of the method.
68 // Maybe a madman sets the first 2 fields here then uses fixer_nom_compo(2, xxx) for the third one
69 // Remove the assert for now, but I think it is necessary. Though a lot of tests may fail
70 // assert(noms.size() == nb_comp());
71 return noms_compo_ = noms;
72}
73
74/*! @brief Returns the array of names of the field components
75 *
76 */
78{
79 return noms_compo_;
80}
81
82/*! @brief Sets the name of the i-th component of the field
83 *
84 * @param (int i) the index of the field component whose name we want to specify
85 * @param (Nom& nom) the name to give to the i-th component of the field
86 * @return (Nom&) the name of i-th component of the field
87 * @throws invalid field component index
88 */
89const Nom& Field_base::fixer_nom_compo(int i, const Nom& nom)
90{
91 assert(i < nb_comp());
92 return noms_compo_[i] = nom;
93}
94
95/*! @brief Returns the name of the i-th component of the field
96 *
97 * @param (int i) the index of the field component whose name we want to specify
98 * @return (Nom& nom) the name of i-th component of the field
99 * @throws invalid field component index
100 */
101const Nom& Field_base::nom_compo(int i) const
102{
103 // teo boutin: those are not intensive operation I think. Maybe check those bounds all the time and exit in case of mistakes.
104 // assert should be kept for very intensive operations in big loops, otherwise users who are also developers will make mistakes and never know... because they only run big simulations in optim
105 assert(i < nb_comp());
106
107 // it is important to check this bound too...
108 // Surprinsingly otherwise does not cause a segfault. only valgrind error...
109 assert(i < noms_compo_.size());
110 return noms_compo_[i];
111}
112
113/*! @brief Sets the name of a scalar field
114 *
115 * @param (Nom& nom) the name to give to the field (scalar)
116 * @return (Nom&) the name of the scalar field
117 * @throws the field is not scalar
118 */
120{
121 assert(nb_comp() == 1);
122 nommer(nom);
123 noms_compo_.dimensionner_force(1);
124 return noms_compo_[0] = nom;
125}
126
127/*! @brief Returns the name of a scalar field
128 *
129 */
131{
132 assert(nb_comp() == 1);
133 return le_nom();
134}
135
136/*! @brief Specifies the units of the field components.
137 *
138 * These units are specified through an array of Nom and can be different for each component of the field.
139 *
140 * @param (Noms& noms) the names of the units of the field components
141 */
143{
144 unite_.dimensionner_force(nb_comp());
145 fixer_nature_du_champ(multi_scalaire);
146 return unite_ = noms;
147}
148
149/*! @brief Returns the units of the field components
150 *
151 * @return (Noms&) the names of the units of the field components
152 */
154{
155 return unite_;
156}
157
158/*! @brief Specifies the unit of the i-th component of the field Meaning: the index of the field component whose unit we want to specify
159 *
160 * @param (Nom& nom) the type of unit to specify
161 * @return (Nom&) the type of unit of the i-th component of the field
162 */
163const Nom& Field_base::fixer_unite(int i, const Nom& nom)
164{
165 fixer_nature_du_champ(multi_scalaire);
166 return unite_[i] = nom;
167}
168
169/*! @brief Returns the unit of the i-th component of the field
170 *
171 * @param (int i) the index of the field component whose unit we want to know
172 * @return (Nom&) the unit of the i-th component of the field
173 */
174const Nom& Field_base::unite(int i) const
175{
176 return unite_[i];
177}
178
179/*! @brief Specifies the unit of a scalar field or whose all components have the same unit
180 *
181 * @param (Nom& nom) the unit to specify
182 * @return (Nom&) the unit of the field
183 */
185{
186 unite_.dimensionner_force(1);
187 return unite_[0] = nom;
188}
189
190/*! @brief Returns the unit of a scalar field whose all components have the same unit
191 *
192 * @return (Nom&) the (common) unit of the field components
193 */
194const Nom& Field_base::unite() const
195{
196 assert(unite_.size() == 1);
197 return unite_[0];
198}
199
200/*! @brief Sets the nature of a field: scalar, multiscalar, vectorial.
201 *
202 * The type (enum) Nature_du_champ is defined in Ch_base.h.
203 *
204 * @param (Nature_du_champ n) the nature to assign to the field
205 */
206Nature_du_champ Field_base::fixer_nature_du_champ(Nature_du_champ n)
207{
208 return nature_ = n;
209}
210
211/*! @brief Returns the order of the basis functions
212 *
213 */
215{
216 switch (nature_)
217 {
218 case scalaire:
219 case vectoriel:
220 case quadrature_scalaire:
221 case quadrature_vectoriel:
222 case multi_scalaire:
223 return 0;
224 case basis_function_order_1_scalar:
225 case basis_function_order_1_vectorial:
226 return 1;
227 case basis_function_order_2_scalar:
228 case basis_function_order_2_vectorial:
229 return 2;
230 }
231 return 0;
232}
233
235{
236 switch (nature_)
237 {
238 case scalaire:
239 case multi_scalaire:
240 return nb_compo_;
241 case quadrature_scalaire:
242 case basis_function_order_1_scalar:
243 case basis_function_order_2_scalar:
244 return 1;
245 case vectoriel:
246 case quadrature_vectoriel:
247 case basis_function_order_1_vectorial:
248 case basis_function_order_2_vectorial:
249 return Objet_U::dimension;
250 }
251 return 0;
252}
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
const Nom & nom_compo() const
Returns the name of a scalar field.
virtual void fixer_nb_comp(int i)
Sets the number of components of the field.
const Nom & le_nom() const override
Returns the name of the field.
virtual int nb_vect_comp() const
Noms noms_compo_
Definition Field_base.h:94
virtual const Noms & fixer_unites(const Noms &)
Specifies the units of the field components.
void nommer(const Nom &) override
Gives a name to the field.
virtual const Nom & fixer_unite(const Nom &)
Specifies the unit of a scalar field or whose all components have the same unit.
const Nom & unite() const
Returns the unit of a scalar field whose all components have the same unit.
virtual Nature_du_champ fixer_nature_du_champ(Nature_du_champ nat)
Sets the nature of a field: scalar, multiscalar, vectorial.
virtual int nb_comp() const
Definition Field_base.h:56
virtual const Noms & fixer_noms_compo(const Noms &)
Sets the names of the field components.
virtual const Nom & fixer_nom_compo(int, const Nom &)
Sets the name of the i-th component of the field.
int nb_compo_
Definition Field_base.h:95
Nature_du_champ nature_
Definition Field_base.h:96
Noms unite_
Definition Field_base.h:94
const Noms & unites() const
Returns the units of the field components.
const Noms & noms_compo() const
Returns the array of names of the field components.
int order_field() const
Returns the order of the basis functions.
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
An array of character strings (VECT(Nom)).
Definition Noms.h:26
Base class for TRUST objects (Objet_U).
Definition Objet_U.h:68
static int dimension
Definition Objet_U.h:94
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
Base class for output streams.
Definition Sortie.h:52