TRUST 1.9.8
HPC thermohydraulic platform
Loading...
Searching...
No Matches
UserUnaryFunction.cpp
1/****************************************************************************
2* Copyright (c) 2022, 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#include <UserUnaryFunction.h>
16// il faut include LecFicDiffuse.h pour la definition du label AVEC_PARSER
17#include <LecFicDiffuse.h>
18#include <algorithm>
19
20Implemente_instanciable(UserUnaryFunction,"UserUnaryFunction",UnaryFunction);
21
22
23
24
25/*! @brief Ecriture sur un flot de sortie Ecrit la valeur de la constante
26 *
27 * @param (Sortie& os) le flot de sortie a utiliser
28 * @return (Sortie&) le flot de sortie modifie
29 */
31{
32
33 return os;
34}
35
36
37/*! @brief Lit la valeur de la constante
38 *
39 * @param (Entree& is) le flot d'entree a utiliser
40 * @return (Entree&) le flot d'entree modifie
41 */
43{
44#ifdef AVEC_PARSER
45 Nom sfunc, nom, inco;
46
47 is >> nom;
48 is >> inco;
49 is >> sfunc;
50
51
52 setFunction(nom,inco, sfunc);
53
54 LecFicDiffuse& f = verif_cast(LecFicDiffuse&, is);
55 {
56 f.parser().addFunc(*this);
57 p.setPere(f.parser());
58 }
59 p.parseString();
60 Cerr << "Interpretation of the function " << sfunc << " OK" << finl;
61
62
63#else
64 Cerr << " UserUnaryFunction : TRUST must be re-compiled with accounting for the PARSER mode" << finl;
65 Cerr <<" See file Lec_Fic_Dif.h" << finl;
66 exit();
67#endif
68 return is;
69}
70
71void UserUnaryFunction::setFunction(Nom& name, Nom& inco, Nom& func)
72{
73 nom_ = name;
74 inconnue = inco;
75
76 std::string sfunc(func.getString());
77 std::transform(sfunc.begin(), sfunc.end(), sfunc.begin(), ::toupper);
78
79 p.setString(sfunc);
80 p.addVar(inco.getChar());
81}
82
84{
85 p.setVar(0,x);
86 return p.eval();
87}
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
class Nom Une chaine de caractere pour nommer les objets de TRUST
Definition Nom.h:31
const char * getChar() const
Definition Nom.h:91
const std::string & getString() const
Definition Nom.h:92
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
Definit une constante dans le jeu de donnees.
Permet de definir une fonction utilisateur dans le jeu de donnees.
void setFunction(Nom &name, Nom &inco, Nom &func)
double eval(double x) override