TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
Parser_Eval.cpp
1/****************************************************************************
2* Copyright (c) 2023, 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 <Parser_Eval.h>
17
18double Parser_Eval::eval_fct_single_position_single_compo(const DoubleVect& position, const double* t, const double* val_param, const int ncomp) const
19{
20 const int D = position.size();
21 const int with_time = t ? 1 : 0;
22
23 Parser_U& fct = parser(ncomp);
24 if (with_time) fct.setVar(0, *t);
25 for (int d = 0; d < D; d++)
26 fct.setVar(with_time + d, position(d));
27 if (val_param) fct.setVar(4, *val_param);
28 return fct.eval();
29}
30
31void Parser_Eval::eval_fct_single_position(const DoubleVect& position, const double* t, const double* val_param, DoubleVect& val) const
32{
33 for (int k = 0; k < fonction_.size(); k++)
34 val(k) = eval_fct_single_position_single_compo(position, t, val_param, k);
35}
36
37void Parser_Eval::eval_fct_single_compo(const DoubleTab& positions, const double* t, DoubleVect& val, const int ncomp) const
38{
39 const int pos_size = positions.dimension(0), D = positions.dimension(1);
40 DoubleVect position(D);
41
42 for (int i = 0; i < pos_size; i++)
43 {
44 for (int d = 0; d < D; d++) position(d) = positions(i, d);
45 val(i) = eval_fct_single_position_single_compo(position, t, nullptr, ncomp);
46 }
47}
48
49void Parser_Eval::eval_fct_(const DoubleTab& positions, const double* t, const DoubleTab* val_param, DoubleTab& val) const
50{
51 const int pos_size = positions.dimension(0), D = positions.dimension(1);
52 DoubleVect position(D);
53
54 for (int i = 0; i < pos_size; i++)
55 {
56 for (int d = 0; d < D; d++) position(d) = positions(i, d);
57 for (int k = 0; k < fonction_.size(); k++)
58 val(i, k) = eval_fct_single_position_single_compo(position, t, val_param ? &(*val_param)(i) : nullptr, k);
59 }
60}
61
62void Parser_Eval::eval_fct(const DoubleTabs& variables, DoubleTab& val) const
63{
64 int dim;
65 int pos_size = val.dimension(0);
66
67 assert(fonction_.size() == 1);
68
69 int nb_dim = val.nb_dim();
70 int nbvars = variables.size();
71
72 Parser_U& fct = parser(0);
73
74 if (nb_dim==1)
75 {
76 for (int i=0; i<pos_size; i++)
77 {
78 for (int ivar=0; ivar<nbvars; ivar++)
79 fct.setVar(ivar,variables[ivar](i));
80
81 val(i) = fct.eval();
82 }
83 }
84 else
85 {
86 dim = val.dimension(1);
87 for (int i=0; i<pos_size; i++)
88 {
89 for(int k=0; k<dim; k++)
90 {
91 for (int ivar=0; ivar<nbvars; ivar++)
92 fct.setVar(ivar,variables[ivar](i,k));
93 val(i,k) = fct.eval();
94 }
95 }
96 }
97}
98
Parser_U & parser(int i)
Definition Parser_Eval.h:32
void eval_fct(const DoubleTab &positions, DoubleTab &val) const
Definition Parser_Eval.h:36
classe Parser_U Version de la classe Parser, derivant de Objet_U.
Definition Parser_U.h:32
void setVar(const char *sv, double val)
Definition Parser_U.h:149
double eval()
Definition Parser_U.h:125
int nb_dim() const
Definition TRUSTTab.h:199
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133
_SIZE_ size() const
Definition TRUSTVect.tpp:45
int size() const