TrioCFD 1.9.9_beta
TrioCFD documentation
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 Writes to an output stream. Writes the value of the constant
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 Reads the value of the constant
38 *
39 * @param (Entree& is) the input stream to use
40 * @return (Entree&) the modified input stream
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: a character string for naming TRUST objects.
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 &)
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
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