19Implemente_instanciable_sans_constructeur_ni_destructeur(
Table,
"Table",
Objet_U);
40 fval.dimensionner(nb_comp);
41 for (
int i = 0; i < nb_comp; i++)
44 Cerr <<
"Reading and interpretation of the function " << tmp << finl;
46 fval[i].setString(tmp);
47 fval[i].addVar(
"val");
48 fval[i].parseString();
50 Cerr <<
"Interpretation of the function " << tmp <<
" OK" << finl;
64 fval.dimensionner(dim);
65 for (
int i=0; i<dim; i++)
69 fval[i].setString(tmp);
74 fval[i].addVar(
"val");
75 fval[i].parseString();
77 Cerr <<
"Interpretation of the function " << tmp <<
" OK" << finl;
109double nlinear_interpolation(
const std::vector<double>& x,
const std::vector<std::pair<double, double>>& gridpoints,
const std::vector<double>& data)
111 const int n = (int)x.size();
114 std::vector<double> weight(n);
115 for (
int i = 0; i < n; i++)
116 weight[i] = std::min(1.0, std::max(0.0, (x[i] - gridpoints[i].first) / (gridpoints[i].second - gridpoints[i].first)));
120 double interpolant = 0.0, prod;
121 for (
int j = 0, i; j < (1<<n); interpolant += prod, j++)
122 for (prod = data[j], i = 0; i < n; i++) prod *= (j >> (n - 1 - i)) & 1 ? weight[i] : 1.0 - weight[i];
130 assert(les_parametres.size() == 1);
131 const DoubleVect& p = les_parametres[0];
132 const int size = p.
size();
133 if (p[0] >= vp)
return les_valeurs(0);
136 for (
int i = 1; i < size; i++)
137 if (p[i] == vp)
return les_valeurs(i);
138 else if (p[i] > vp)
return (les_valeurs(i - 1) + ((les_valeurs(i) - les_valeurs(i - 1)) / (p[i] - p[i - 1])) * (vp - p[i - 1]));
140 return les_valeurs(size - 1);
145 std::vector<double> vals_param {val_param};
146 return val(vals_param, ncomp);
149double Table::val(
const std::vector<double>& vals_param,
int ncomp)
const
151 const int nb_param = les_parametres.size();
152 int nb_comp = les_valeurs.size();
153 if (nb_param == (
int)vals_param.size())
155 std::vector<double> data;
156 std::vector<int> icube;
157 std::vector<std::pair<double, double>> gridpoints;
159 for (
int ip = 0; ip < nb_param; ip++)
161 const DoubleVect& p = les_parametres[ip];
164 Cerr <<
"Error, a table should have more than one single value." << finl;
168 int i_interval = p.
size() - 1;
169 for (
int i = 1; i < p.
size(); i++)
170 if (vals_param[ip] < p[i])
175 icube.push_back(i_interval - 1);
176 gridpoints.push_back({p[i_interval - 1], p[i_interval]});
178 for (
int j = 0; j < (1 << nb_param); j++)
180 std::vector<int> index(nb_param, 0);
181 for (
int k = 0; k < nb_param; k++) index[nb_param - 1 - k] = icube[nb_param - 1 - k] + ((j >> k) & 1);
185 for (
int i = 1; i < nb_param; i++)
186 k = k * les_parametres[i].size() + index[i];
187 k = k * nb_comp + ncomp;
189 data.push_back(les_valeurs[k]);
192 return nlinear_interpolation(vals_param, gridpoints, data);
194 else if (isf == 1 && vals_param.size() == 1)
200 else Process::exit(
"Error in a Table::val : wrong number of parameters.");
210 Cerr <<
"Table::val(const DoubleVect& ) is not coded yet." << finl;
229 if (les_parametres.size() == 1)
232 const DoubleVect& p = les_parametres[0];
234 if (p[0] >= val_param)
237 for(
int j=0; j<size; j++)
238 x[j] = les_valeurs(0,j);
240 else if (p[size_p-1] <= val_param)
243 for(
int j=0; j<size; j++)
244 x[j] = les_valeurs(size_p-1,j);
248 for (
int i=1; i<size_p; i++)
249 if (p[i] == val_param)
252 for(
int j=0; j<size; j++)
253 x[j] = les_valeurs(i,j);
256 else if (p[i] > val_param)
259 for(
int j=0; j<size; j++)
260 x[j] = les_valeurs(i-1,j)+
261 ((les_valeurs(i,j)-les_valeurs(i-1,j))/(p[i]-p[i-1]))
262 *(val_param-p[i-1]) ;
269 Cerr <<
"Error in a Table : it misses some parameters." << finl;
280 Cerr <<
"Table::val(const DoubleVect& ) is not coded yet." << finl;
287DoubleTab&
Table::valeurs(
const DoubleTab& val_param,
const DoubleTab& pos,
const double tps,DoubleTab& aval)
const
302 double val_ = param[0];
303 for (
int i = 1; i < param.
size(); i++)
304 if (val_ < param[i]) val_ = param[i];
307 les_valeurs.ref(aval);
308 les_parametres.dimensionner(1);
309 les_parametres[0].ref(param);
315 for (
int n = 0; n < params.
size(); n++)
317 double val_ = params[n][0];
318 for (
int i = 1; i < params[n].
size(); i++)
319 if (val_ < params[n][i]) val_ = params[n][i];
324 les_parametres.dimensionner(params.
size());
325 for (
int i = 0; i < params.
size(); i++) les_parametres[i].ref(params[i]);
328static bool checked=
false;
333 for (
int comp = 0; comp < les_valeurs.dimension(1); comp++)
335 double val_ = les_valeurs(0, comp);
336 for (
int i = 1; i < les_valeurs.dimension(0); i++)
337 if (val_ != les_valeurs(i, comp))
338 instationnaire_ =
true;
342 return instationnaire_;
Class defining operators and methods for all reading operation in an input flow (file,...
class Nom: a character string for naming TRUST objects.
Base class for TRUST objects (Objet_U).
const Nom & que_suis_je() const
Returns the string identifying the class.
virtual Entree & readOn(Entree &)
Reads an Objet_U from an input stream. Virtual method to override.
Objet_U()
Default constructor: assigns a unique identifier to the object (object_id_) and registers the object ...
virtual const Nom & le_nom() const
Returns the name of the Objet_U. Virtual method to override: returns "neant" in this implementation.
virtual Sortie & printOn(Sortie &) const
Writes the object to an output stream. Virtual method to override.
Parser_Eval class - Evaluates the values taken by an analytic function.
VECT(Parser_U) &fonction()
void eval_fct(const DoubleTab &positions, DoubleTab &val) const
class Parser_U Version of the Parser class, deriving from Objet_U.
void setVar(const char *sv, double val)
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Base class for output streams.
Table()
Default constructor. Creates an empty table.
void remplir(const DoubleVect ¶m, const DoubleTab &val)
Sets the parameters and values of the table.
double val_simple(double vals_param) const
double val(const double val_param, int ncomp=0) const
DoubleTab & valeurs(const DoubleTab &val_param, const DoubleTab &pos, const double tps, DoubleTab &val) const
Entree & lire_f(Entree &is, const int nb_comp)
Entree & lire_fxyzt(Entree &is, const int dim)
bool instationnaire() const