TrioCFD 1.9.8
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 Lecture du Champ a partir d'un flot d'entree, (On ne sait traiter que les champs scalaires.
67 *
68 * )
69 * exemple:
70 * Champ_Fonc_Tabule { probleme ch }
71 * 1 (nombre de composantes)
72 * {
73 * 2
74 * 0 500 0 250 (ch(0)=0 && ch(500)=250
75 * }
76 *
77 * @param (Entree& is) un flot d'entree
78 * @return (Entree&) le flot d'entree modifie
79 * @throws accolade fermante attendue
80 * @throws accolade ouvrante attendue
81 */
83{
84 int nbcomp;
85 Nom motlu;
86 const Motcle accolade_ouverte("{"), accolade_fermee("}");
87 is >> motlu;
88 if (motlu != accolade_ouverte)
89 {
90 Cerr << "You are using an old syntaxe, you should now use:"<< finl;
91 Cerr << "Champ_Fonc_Tabule { problem_name field_name } ncomp { table }" << finl;
92 exit();
93 }
94 else
95 {
96 while (true)
97 {
98 is >> motlu;
99 if (motlu == "}")
100 break;
101 noms_pbs_.add(motlu);
102 is >> motlu;
103 noms_champs_parametre_.add(motlu);
104 }
105 }
106 const int nb_param = noms_champs_parametre_.size();
107
108 is >> nbcomp;
109 fixer_nb_comp(nbcomp);
110 is >> motlu;
111 if (motlu == accolade_ouverte)
112 {
113 /* 1. lecture de la grille de parametres */
114 DoubleVects params;
115 for (int n = 0; n < nb_param; n++)
116 {
117 const int nb_val = lire_dimension(is, que_suis_je());
118 DoubleVect param(nb_val);
119 for (int i = 0; i < nb_val; i++)
120 is >> param[i];
121 params.add(param);
122 }
123
124 /* 2. lecture des valeurs des parametres */
125 // taille totale du tableau de valeurs
126 int size = nbcomp;
127 for (int n = 0; n < nb_param; n++)
128 size *= params[n].size();
129
130 // lecture : tout dans un tableau 1D
131 DoubleVect tab_valeurs(size);
132 for (int i = 0; i < size; i++)
133 is >> tab_valeurs[i];
134 la_table.remplir(params, tab_valeurs);
135
136 is >> motlu;
137 if (motlu != accolade_fermee)
138 {
139 Cerr << "Error reading from an object of type Champ_Fonc_Tabule" << finl;
140 Cerr << "We expected keyword } instead of " << motlu << finl;
141 exit();
142 }
143 }
144 else if (motlu == "fonction")
145 {
146 Cerr << "The syntax has changed..." << finl;
147 Cerr << "The syntax is now Champ_Fonc_fonction problem field 1 field_expression" << finl;
148 exit();
149 }
150 else
151 {
152 Cerr << "Error reading from an object of type Champ_Fonc_Tabule" << finl;
153 Cerr << "We expected keyword { or fonction instead of " << motlu << finl;
154 exit();
155 }
156 return is;
157}
158
160{
161 if (!le_champ_tabule_dis)
162 Cerr << le_nom() << "type : " << que_suis_je() << " can not be assigned to " << ch.le_nom() << " because " << le_nom() << " is incomplete " << finl;
163 else
164 {
165 if (sub_type(Champ_Uniforme, ch))
166 valeurs() = ch.valeurs()(0, 0);
167 else
168 valeurs() = ch.valeurs();
169 }
170 return *this;
171}
Classe Champ_Fonc_Tabule Classe derivee de Champ_Fonc_base qui represente les.
Champ_base & affecter_(const Champ_base &) override
Affecte un Champ_base dans un 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)
classe Champ_Fonc_base Classe de base des champs qui sont fonction d'une grandeur calculee
virtual DoubleTab & valeurs()=0
int lire_dimension(Entree &, const Nom &)
Verification de la dimension du champ Renvoie la dimension du champ.
classe Champ_Uniforme Represente un champ constant dans l'espace et dans le temps.
Champ_base()
Constructeur par defaut d'un 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)
Fixe le nombre de composantes du champ.
const Nom & le_nom() const override
Renvoie le nom du champ.
class Nom Une chaine de caractere pour nommer les objets de TRUST
Definition Nom.h:31
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
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.cpp:455
Classe de base des flux de sortie.
Definition Sortie.h:52
value_type & add()=delete