TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Champ_Fonc_Tabule.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.h>
17#include <Champ_Uniforme.h>
18#include <algorithm>
19#include <string>
20
21Implemente_instanciable(Champ_Fonc_Tabule,"Champ_Fonc_Tabule",Champ_Fonc_base);
22// XD champ_fonc_tabule champ_don_base champ_fonc_tabule NO_BRACE Field that is tabulated as a function of another
23// XD_CONT field.
24// XD attr pb_field bloc_lecture pb_field REQ block similar to { pb1 field1 } or { pb1 field1 ... pbN fieldN }
25// XD attr dim entier dim REQ Number of field components.
26// XD attr bloc bloc_lecture bloc REQ Values (the table (the value of the field at any time is calculated by linear
27// XD_CONT interpolation from this table) or the analytical expression (with keyword expression to use an analytical
28// XD_CONT expression)).
29
30void Champ_Fonc_Tabule::Warn_old_chp_fonc_syntax_V_184(const char *nom_class, const Nom& val1, const Nom& val2)
31{
32 bool isNum = Check_if_int(val1);
33 if (isNum)
34 {
35 Cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << finl;
36 Cerr << "Error: you are using an obsolete syntax for the keyword " << nom_class << " :" << finl;
37 Cerr << "Your should specify the problem name first instead of " << val1 << finl;
38 Cerr << "New syntax is: " << nom_class << " problem_name field_name ncomp expression" << finl;
40 }
41 isNum = Check_if_int(val2);
42 if (isNum)
43 {
44 Cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << finl;
45 Cerr << "Error: you are using an obsolete syntax for the keyword " << nom_class << " :" << finl;
46 Cerr << "Your should specify the field name instead of " << val2 << finl;
47 Cerr << "New syntax is: " << nom_class << " problem_name field_name ncomp expression" << finl;
49 }
50}
51
53{
54 std::string s((const char*) val);
55 // lambda checking whehter a char is not a digit:
56 auto checkNotDig = [](unsigned char c)
57 { return !std::isdigit(c);};
58 return (!s.empty() && std::find_if(s.begin(), s.end(), checkNotDig) == s.end());
59}
60
62{
63 return os;
64}
65
66/*! @brief Read the field from an input stream. (Only scalar fields are handled.)
67 *
68 * example:
69 * Champ_Fonc_Tabule { problem ch }
70 * 1 (number of components)
71 * {
72 * 2
73 * 0 500 0 250 (ch(0)=0 && ch(500)=250
74 * }
75 *
76 * @param (Entree& is) an input stream
77 * @return (Entree&) the modified input stream
78 * @throws closing brace expected
79 * @throws opening brace expected
80 */
82{
83 int nbcomp;
84 Nom motlu;
85 const Motcle accolade_ouverte("{"), accolade_fermee("}");
86 is >> motlu;
87 if (motlu != accolade_ouverte)
88 {
89 Cerr << "You are using an old syntaxe, you should now use:"<< finl;
90 Cerr << "Champ_Fonc_Tabule { problem_name field_name } ncomp { table }" << finl;
91 exit();
92 }
93 else
94 {
95 while (true)
96 {
97 is >> motlu;
98 if (motlu == "}")
99 break;
100 noms_pbs_.add(motlu);
101 is >> motlu;
102 noms_champs_parametre_.add(motlu);
103 }
104 }
105 const int nb_param = noms_champs_parametre_.size();
106
107 is >> nbcomp;
108 fixer_nb_comp(nbcomp);
109 is >> motlu;
110 if (motlu == accolade_ouverte)
111 {
112 /* 1. reading the parameter grid */
113 DoubleVects params;
114 for (int n = 0; n < nb_param; n++)
115 {
116 const int nb_val = lire_dimension(is, que_suis_je());
117 DoubleVect param(nb_val);
118 for (int i = 0; i < nb_val; i++)
119 is >> param[i];
120 params.add(param);
121 }
122
123 /* 2. reading the parameter values */
124 // total size of the values array
125 int size = nbcomp;
126 for (int n = 0; n < nb_param; n++)
127 size *= params[n].size();
128
129 // reading: all values in a 1D array
130 DoubleVect tab_valeurs(size);
131 for (int i = 0; i < size; i++)
132 is >> tab_valeurs[i];
133 la_table.remplir(params, tab_valeurs);
134
135 is >> motlu;
136 if (motlu != accolade_fermee)
137 {
138 Cerr << "Error reading from an object of type Champ_Fonc_Tabule" << finl;
139 Cerr << "We expected keyword } instead of " << motlu << finl;
140 exit();
141 }
142 }
143 else if (motlu == "fonction")
144 {
145 Cerr << "The syntax has changed..." << finl;
146 Cerr << "The syntax is now Champ_Fonc_fonction problem field 1 field_expression" << finl;
147 exit();
148 }
149 else
150 {
151 Cerr << "Error reading from an object of type Champ_Fonc_Tabule" << finl;
152 Cerr << "We expected keyword { or fonction instead of " << motlu << finl;
153 exit();
154 }
155 return is;
156}
157
159{
160 if (!le_champ_tabule_dis)
161 Cerr << le_nom() << "type : " << que_suis_je() << " can not be assigned to " << ch.le_nom() << " because " << le_nom() << " is incomplete " << finl;
162 else
163 {
164 if (sub_type(Champ_Uniforme, ch))
165 valeurs() = ch.valeurs()(0, 0);
166 else
167 valeurs() = ch.valeurs();
168 }
169 return *this;
170}
Class Champ_Fonc_Tabule Derived class of Champ_Fonc_base representing.
Champ_base & affecter_(const Champ_base &) override
Assigns a Champ_base to a Champ_Fonc_base.
const DoubleTab & valeurs() const override
static bool Check_if_int(const Nom &val)
static void Warn_old_chp_fonc_syntax_V_184(const char *nom_class, const Nom &val1, const Nom &val2)
class Champ_Fonc_base Base class of fields that are functions of a calculated quantity
virtual DoubleTab & valeurs()=0
int lire_dimension(Entree &, const Nom &)
Verification of the field dimension Returns the dimension of the field.
Champ_Uniforme Represents a field that is constant in space and time.
Champ_base()
Default constructor of a Champ_base.
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)
Sets the number of components of the field.
const Nom & le_nom() const override
Returns the name of the field.
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
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
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
value_type & add()=delete