1 /*!
2  * \file  mfront/include/MFront/UMATInterfaceBase.hxx
3  * \brief
4  * \author Thomas Helfer
5  * \brief 10 juil. 2013
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_MFRONTUMATINTERFACEBASE_HXX
15 #define LIB_MFRONT_MFRONTUMATINTERFACEBASE_HXX
16 
17 #include "TFEL/Utilities/CxxTokenizer.hxx"
18 #include "MFront/VariableDescription.hxx"
19 #include "MFront/BehaviourDescription.hxx"
20 #include "MFront/StandardBehaviourInterface.hxx"
21 
22 namespace mfront {
23 
24   // forward declaration
25   struct VariableDescriptionContainer;
26   // forward declaration
27   struct Gradient;
28   // forward declaration
29   struct ThermodynamicForce;
30 
31   /*!
32    * This class provides some helper function for behaviours
33    * interfaces based on the UMAT standard or its derivative:
34    * - `Abaqus/Standard`
35    * - `Abaqus/Explicit`
36    * - `Code_Aster`
37    * - `CalculiX`
38    * - `Cyrano`
39    * - `Europlexus`
40    * - etc..
41    */
42   struct MFRONT_VISIBILITY_EXPORT UMATInterfaceBase
43       : public StandardBehaviourInterface {
44     //! constructor
45     UMATInterfaceBase();
46 
47     void exportMechanicalData(
48         std::ostream&,
49         const Hypothesis,
50         const BehaviourDescription&) const override;
51     /*!
52      * \param[out] f      : output file
53      * \param[out] first  : true if not initializer has been declared yet
54      * \param[in]  v      : variables to be initialized
55      * \param[in]  src    : name of the array from which the variables are
56      * initialized
57      * \param[in]  prefix : prefix added to variable's names
58      * \param[in]  suffix : suffix added to variable's names
59      * \param[in]  o      : offset in the array from which the variables are
60      * initialized
61      */
62     virtual void writeVariableInitializersInBehaviourDataConstructorI(
63         std::ostream&,
64         bool&,
65         const VariableDescriptionContainer&,
66         const std::string&,
67         const std::string&,
68         const std::string&) const;
69     /*!
70      * \param[out] f      : output file
71      * \param[out] first  : true if not initializer has been declared yet
72      * \param[in]  b      : iterator to the first variable to be initialized
73      * \param[in]  e      : iterator past the last variable to be initialized
74      * \param[in]  src    : name of the array from which the variables are
75      * initialized
76      * \param[in]  prefix : prefix added to variable's names
77      * \param[in]  suffix : suffix added to variable's names
78      * \param[in]  o      : offset in the array from which the variables are
79      * initialized
80      */
81     virtual void writeVariableInitializersInBehaviourDataConstructorI(
82         std::ostream&,
83         bool&,
84         const VariableDescriptionContainer::const_iterator&,
85         const VariableDescriptionContainer::const_iterator&,
86         const std::string&,
87         const std::string&,
88         const std::string&) const;
89     /*!
90      * \param[out] f      : output file
91      * \param[in] mb      : behaviour description
92      * \param[in]  v      : variables to be initialized
93      * \param[in]  src    : name of the array from which the variables are
94      * initialized
95      * \param[in]  prefix : prefix added to variable's names
96      * \param[in]  suffix : suffix added to variable's names
97      * \param[in]  o      : offset in the array from which the variables are
98      * initialized
99      */
100     virtual void writeVariableInitializersInBehaviourDataConstructorII(
101         std::ostream&,
102         const BehaviourDescription&,
103         const VariableDescriptionContainer&,
104         const std::string&,
105         const std::string&,
106         const std::string&) const;
107     /*!
108      * \param[out] f      : output file
109      * \param[in]  mb     : behaviour description
110      * \param[in]  b      : iterator to the first variable to be initialized
111      * \param[in]  e      : iterator past the last variable to be initialized
112      * \param[in]  src    : name of the array from which the variables are
113      * initialized
114      * \param[in]  prefix : prefix added to variable's names
115      * \param[in]  suffix : suffix added to variable's names
116      * \param[in]  o      : offset in the array from which the variables are
117      * initialized
118      */
119     virtual void writeVariableInitializersInBehaviourDataConstructorII(
120         std::ostream&,
121         const BehaviourDescription&,
122         const VariableDescriptionContainer::const_iterator&,
123         const VariableDescriptionContainer::const_iterator&,
124         const std::string&,
125         const std::string&,
126         const std::string&) const;
127     /*!
128      * \param[out] f     : output file
129      * \param[in]   mb   : behaviour description
130      * \param[in]  v     : variables to be initialized
131      * \param[in]  src   : name of the array to which the variables are exported
132      */
133     virtual void exportResults(std::ostream&,
134                                const BehaviourDescription&,
135                                const VariableDescriptionContainer&,
136                                const std::string&) const;
137 
138     virtual void writeResultsArrayResize(
139         std::ostream&,
140         const std::string&,
141         const VariableDescriptionContainer&) const;
142 
143     virtual void writeResultsArrayResize(std::ostream&,
144                                          const std::string&,
145                                          const SupportedTypes::TypeSize&) const;
146     /*!
147      * \brief write the instruction of exporting a thermodynamic force in an
148      * array
149      * \param[out] out : output stream
150      * \param[in]  a   : array name
151      * \param[in]  f   : thermodynamic force
152      * \param[in]  o   : thermodynamic force offset
153      */
154     virtual void exportThermodynamicForce(std::ostream&,
155                                           const std::string&,
156                                           const ThermodynamicForce&,
157                                           const SupportedTypes::TypeSize) const;
158     /*!
159      * \return the list of additional variables to be passed to the
160      * behaviour data and integration data constructors which are
161      * specific to the interface.
162      *
163      * For each item in the list, the first element is the variable
164      * name and the second element is the variable description.
165      */
166     virtual std::vector<std::pair<std::string, std::string>>
167     getBehaviourConstructorsAdditionalVariables() const;
168     /*!
169      * \return the list of additional variables to be passed to the
170      * behaviour data constructor which are specific to the interface.
171      *
172      * For each item in the list, the first element is the variable
173      * name and the second element is the variable description.
174      */
175     virtual std::vector<std::pair<std::string, std::string>>
176     getBehaviourDataConstructorAdditionalVariables() const;
177     /*!
178      * \return the list of additional variables to be passed to the
179      * integration data constructor which are specific to the interface.
180      *
181      * For each item in the list, the first element is the variable
182      * name and the second element is the variable description.
183      */
184     virtual std::vector<std::pair<std::string, std::string>>
185     getIntegrationDataConstructorAdditionalVariables() const;
186     void writeBehaviourConstructorHeader(std::ostream&,
187 					 const BehaviourDescription&,
188 					 const Hypothesis,
189 					 const std::string&) const override;
190     void writeBehaviourConstructorBody(std::ostream&,
191 				       const BehaviourDescription&,
192 				       const Hypothesis) const override;
193     void writeBehaviourDataConstructor(std::ostream&,
194 				       const Hypothesis,
195 				       const BehaviourDescription&) const override;
196     /*!
197      * \brief add interface specific lines at the end of the behaviour
198      * data constructor
199      * \param[in] behaviourFile : output file
200      * \param[in] h             : modelling hypothesis
201      * \param[in] mb            : behaviour description
202      */
203     virtual void completeBehaviourDataConstructor(
204         std::ostream&, const Hypothesis, const BehaviourDescription&) const;
205 
206     void writeBehaviourDataMainVariablesSetters(std::ostream&, const BehaviourDescription&) const override;
207     /*!
208      * \brief write the initialisation of a driving variables
209      * \param[in] os : output file
210      * \param[in] v  : variable to be initialised
211      * \param[in] o  : variable offsert
212      */
213     virtual void writeBehaviourDataGradientSetter(std::ostream&,
214 							 const Gradient&,
215 							 const SupportedTypes::TypeSize) const;
216     /*!
217      * \brief write the initialisation of a thermodynamic force
218      * \param[in] os : output file
219      * \param[in] v  : variable to be initialised
220      * \param[in] o  : variable offsert
221      */
222     virtual void writeBehaviourDataThermodynamicForceSetter(std::ostream&,
223 							    const ThermodynamicForce&,
224 							    const SupportedTypes::TypeSize) const;
225 
226     void writeIntegrationDataConstructor(std::ostream&,
227 					 const Hypothesis,
228 					 const BehaviourDescription&) const override;
229     virtual void writeIntegrationDataMainVariablesSetters(
230         std::ostream&, const BehaviourDescription&) const override;
231     /*!
232      * \brief write the initialisation of a driving variables
233      * \param[in] os : output file
234      * \param[in] v  : variable to be initialised
235      * \param[in] o  : variable offsert
236      */
237     virtual void writeIntegrationDataGradientSetter(
238         std::ostream&,
239         const Gradient&,
240         const SupportedTypes::TypeSize) const;
241     //! destructor
242     ~UMATInterfaceBase() override;
243 
244    protected:
245 
246     /*!
247      * \return the name of the generated library
248      * \param[in] mb : behaviour description
249      */
250     virtual std::string getLibraryName(const BehaviourDescription&) const = 0;
251 
252     /*!
253      * \param[out] f      : output file
254      * \param[out] first  : boolean stating if the an initializer has already
255      * been declared
256      * \param[in]  h      : modelling hypothesis
257      * \param[in]  mb     : behaviour description
258      * \param[in]  v      : variables to be initialized
259      * \param[in]  iv     : indirection vector
260      * \param[in]  o      : offset in the indirection vector
261      * \param[in]  src    : name of the array from which the variables are
262      * initialized
263      * \param[in]  prefix : prefix added to variable's names
264      * \param[in]  suffix : suffix added to variable's names
265      */
266     virtual void writeMaterialPropertiesInitializersInBehaviourDataConstructorI(
267         std::ostream&,
268         bool& first,
269         const Hypothesis,
270         const BehaviourDescription&,
271         const std::vector<BehaviourMaterialProperty>&,
272         const SupportedTypes::TypeSize,
273         const std::string&,
274         const std::string&,
275         const std::string&) const;
276     /*!
277      * \param[out] f      : output file
278      * \param[in]  h      : modelling hypothesis
279      * \param[in]  mb     : behaviour description
280      * \param[in]  v      : variables to be initialized
281      * \param[in]  iv     : indirection vector
282      * \param[in]  o      : offset in the indirection vector
283      * \param[in]  src    : name of the array from which the variables are
284      * initialized
285      * \param[in]  prefix : prefix added to variable's names
286      * \param[in]  suffix : suffix added to variable's names
287      */
288     virtual void
289     writeMaterialPropertiesInitializersInBehaviourDataConstructorII(
290         std::ostream&,
291         const Hypothesis,
292         const BehaviourDescription&,
293         const std::vector<BehaviourMaterialProperty>&,
294         const SupportedTypes::TypeSize,
295         const std::string&,
296         const std::string&,
297         const std::string&) const;
298 
299     virtual void getExtraSrcIncludes(std::ostream&,
300                                      const BehaviourDescription&) const;
301 
302     /*!
303      * \brief write the first part of the code used to generate a MTest file
304      * \param[out] out: output stream
305      * \param[in] bd: behaviour description
306      */
307     virtual void generateMTestFile1(std::ostream&,
308                                     const BehaviourDescription&) const;
309     /*!
310      * \brief write the second part of the code used to generate a MTest file.
311      * This method shall be called when only one function is generated for all
312      * modelling hypotheses. This methods calls the
313      * `gatherModellingHypothesesAndTests` to make an appropriate dispatch among
314      * hypotheses. For each hypothesis, the `generateMTestFileForHypothesis` is
315      * called.
316      * \param[out] out: output stream
317      * \param[out] bd: behaviour description
318      */
319     virtual void generateMTestFile2(std::ostream&,
320                                     const BehaviourDescription&,
321                                     const BehaviourDescription::BehaviourType,
322                                     const std::string&,
323                                     const std::string&) const;
324     /*!
325      * \brief write the code used to generate a MTest file for a given hypotesis
326      * \param[out] out: output stream
327      * \param[out] bd: behaviour description
328      */
329     virtual void generateMTestFileForHypothesis(
330         std::ostream&,
331         const BehaviourDescription&,
332         const BehaviourDescription::BehaviourType,
333         const std::string&,
334         const std::string&,
335         const Hypothesis) const;
336 
337     virtual void writeMTestFileGeneratorSetRotationMatrix(
338         std::ostream&, const BehaviourDescription&) const;
339     /*!
340      * \param[in] out : output file
341      */
342     virtual void writeMTestFileGeneratorSetModellingHypothesis(
343         std::ostream&) const = 0;
344     /*!
345      * \brief When the interface only provide one entry point (i.e. does not
346      * provide an entry point by modelling hypothesis), the generation of
347      * `MTest` files, provided by the `generateMTestFile2` method, must have
348      * access to tests to distinguish modelling hypotheses.
349      * \return a map associating each distinct modelling hypothesis to
350      * appropriate tests.
351      * This method is called internally by `generateMTestFile2` method.
352      * \param[in] mb : behaviour description
353      */
354     virtual std::map<Hypothesis, std::string> gatherModellingHypothesesAndTests(
355         const BehaviourDescription&) const;
356     /*!
357      * \return a test for the given modelling hypotesis
358      * This method is called by the `gatherModellingHypothesesAndTests`.
359      * As this method is only meaningfull for interfaces which only provide one
360      * entry point (i.e. does not provide an entry point by modelling
361      * hypothesis), the default implementation throws an exception.
362      */
363     virtual std::string getModellingHypothesisTest(const Hypothesis) const;
364     //! \return true if the interface handles external state variables
365     virtual bool areExternalStateVariablesSupported() const;
366     //! \return true if the interface handles temperature increment
367     virtual bool isTemperatureIncrementSupported() const;
368   };  // end of struct UMATInterfaceBase
369 
370 }  // end of namespace mfront
371 
372 #endif /* LIB_MFRONT_MFRONTUMATINTERFACEBASE_HXX */
373