1 /*!
2  * \file   mfront/include/MFront/ModelDescription.hxx
3  * \brief
4  * \author Thomas Helfer
5  * \brief  12 jun 2010
6  * \copyright Copyright (C) 2006-2018 CEA/DEN, EDF R&D. All rights
7  * reserved.
8  * This project is publicly released under either the GNU GPL Licence
9  * or the CECILL-A licence. A copy of thoses licences are delivered
10  * with the sources of TFEL. CEA or EDF may also distribute this
11  * project under specific licensing conditions.
12  */
13 
14 #ifndef LIB_MFRONT_MODELDESCRIPTION_HXX
15 #define LIB_MFRONT_MODELDESCRIPTION_HXX
16 
17 #include <set>
18 #include <map>
19 #include <string>
20 
21 #include "MFront/MFrontConfig.hxx"
22 #include "MFront/VariableDescription.hxx"
23 #include "MFront/StaticVariableDescription.hxx"
24 #include "MFront/VariableBoundsDescription.hxx"
25 
26 namespace mfront {
27 
28   //! Class describing a model
29   struct MFRONT_VISIBILITY_EXPORT ModelDescription {
30     //! a model may contain several function
31     struct MFRONT_VISIBILITY_EXPORT Function {
32       //! default constructor
33       Function();
34       //! copy constructor
35       Function(const Function&);
36       //! move constructor
37       Function(Function&&);
38       //! assignement
39       Function& operator=(const Function&);
40       //! move assignement
41       Function& operator=(Function&&);
42       //! destructor
43       ~Function();
44       //! list of variables used by the function
45       std::set<std::string> usedVariables;
46       //! list of variables modified by the function
47       std::set<std::string> modifiedVariables;
48       //! list of constant material properties used by the function
49       std::set<std::string> constantMaterialProperties;
50       //! list of parameters used by the function
51       std::set<std::string> parameters;
52       //! depths of each variables
53       std::map<std::string, unsigned short> depths;
54       //! name of the function
55       std::string name;
56       //! body of the function
57       std::string body;
58       //! line starting the definition of the function in the initial
59       //! MFront file
60       unsigned int line = 0u;
61       //! if true, the body of the function uses the time increment dt
62       bool useTimeIncrement = false;
63     };  // end of struct MFrontData::Function
64         /*!
65          * \brief decompose a variable name to get the basis and the depth
66          * of the variable
67          */
68     std::pair<std::string, unsigned short> decomposeVariableName(
69         const std::string&) const;
70     //! defaut constructor
71     ModelDescription();
72     //! copy constructor
73     ModelDescription(const ModelDescription&);
74     //! move constructor
75     ModelDescription(ModelDescription&&);
76     //! assignement operator
77     ModelDescription& operator=(const ModelDescription&);
78     //! move assignement operator
79     ModelDescription& operator=(ModelDescription&&);
80     /*!
81      * \return the variable description with the given name
82      * \param[in] n: variable name
83      */
84     const VariableDescription& getVariableDescription(const std::string&) const;
85     /*!
86      * \brief associate a glossary name to a variable
87      * \param[in] v: variable name
88      * \param[in] g: glossary name
89      */
90     void setGlossaryName(const std::string&, const std::string&);
91     /*!
92      * \brief associate a glossary name to a variable
93      * \param[in] v: variable name
94      * \param[in] g: glossary name
95      */
96     void setEntryName(const std::string&, const std::string&);
97     /*!
98      * \brief add a material law
99      * \param[in] m : added material law name
100      */
101     void addMaterialLaw(const std::string&);
102     /*!
103      * \brief append the given code to the includes
104      */
105     void appendToIncludes(const std::string&);
106     /*!
107      * \brief append the given code to the members
108      */
109     void appendToMembers(const std::string&);
110     /*!
111      * \brief append the given code to the private code
112      */
113     void appendToPrivateCode(const std::string&);
114     /*!
115      * \brief append the given code to the sources
116      */
117     void appendToSources(const std::string&);
118     //! \brief destructor
119     virtual ~ModelDescription();
120     /*!
121      * \brief register a name.
122      * \param[in] n : name
123      * \param[in] b : if false, don't check if variable has already
124      * been reserved yet. If true, check if the variable has alredy
125      * been registred and throws an exception if it does, register it
126      * otherwise
127      * \note this method is called internally by the registerVariable
128      * and registerStaticVariable methods.
129      */
130     void reserveName(const std::string&);
131     /*!
132      * \brief register a static member name
133      * \param[in] n : name
134      */
135     void registerMemberName(const std::string&);
136     /*!
137      * \brief register a static member name
138      * \param[in] n : name
139      */
140     void registerStaticMemberName(const std::string&);
141     /*!
142      * \brief look if a name is reserved
143      * \param[in] n : name
144      */
145     bool isNameReserved(const std::string&) const;
146     //! \brief \return the list of reserved names
147     std::set<std::string>& getReservedNames();
148     //! \brief list of functions declared
149     std::vector<Function> functions;
150     //! \brief list of all outputs
151     VariableDescriptionContainer outputs;
152     //! \brief list of all inputs
153     VariableDescriptionContainer inputs;
154     //! \brief list of all parameters
155     VariableDescriptionContainer parameters;
156     //! \brief list of all constant material properties
157     VariableDescriptionContainer constantMaterialProperties;
158     //! \brief static variables
159     StaticVariableDescriptionContainer staticVars;
160     //! \brief material name
161     std::string material;
162     //! \brief library name
163     std::string library;
164     //! \brief class name
165     std::string className;
166     //! \brief name of the model
167     std::string modelName;
168     //! \brief additionnal header files
169     std::string includes;
170     //! \brief specific sources
171     std::string sources;
172     //! \brief private code
173     std::string privateCode;
174     //! \brief class member
175     std::string members;
176     std::set<std::string> domains;
177     //! \brief list of material laws used
178     std::vector<std::string> materialLaws;
179     //! \brief list of variables names
180     std::set<std::string> memberNames;
181     //! \brief list of variables names
182     std::set<std::string> staticMemberNames;
183     //! \brief overriding parameters
184     std::map<std::string, double> overriding_parameters;
185 
186    protected:
187     /*!
188      * check that a variable exists
189      * \param[in] v: variable name
190      */
191     void checkVariableExistence(const std::string&) const;
192     //! \brief \return the list of reserved names
193     const std::set<std::string>& getReservedNames() const;
194 
195    private:
196     /*!
197      * \return the variable description with the given name
198      * \param[in] n: variable name
199      */
200     VariableDescription& getVariableDescription(const std::string&);
201     //! \brief set glossary names
202     std::map<std::string, std::string> glossaryNames;
203     //! \brief entry names
204     std::map<std::string, std::string> entryNames;
205     //! \brief list of reserved names
206     std::set<std::string> reservedNames;
207   };  // end of struct ModelDescription
208 
209 }  // end of namespace mfront
210 
211 #endif /* LIB_MFRONT_MODELDESCRIPTION_HXX */
212