1 /*!
2  * \file   mfront/include/MFront/AnsysInterface.hxx
3  * \brief
4  * \author Thomas Helfer
5  * \date   17 mars 2016
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_ANSYSINTERFACE_HXX
15 #define LIB_MFRONT_ANSYSINTERFACE_HXX
16 
17 #include<string>
18 #include<iosfwd>
19 
20 #include"TFEL/Utilities/CxxTokenizer.hxx"
21 #include"MFront/UMATInterfaceBase.hxx"
22 
23 namespace mfront{
24 
25   /*!
26    * \brief This class provide an interface to the Ansys/APDL finite
27    * element solver
28    */
29   struct AnsysInterface
30     : public UMATInterfaceBase
31   {
32     //! name of finite strain strategy attribute
33     static const char *const finiteStrainStrategy;
34     /*!
35      * \return the name of the interface
36      */
37     static std::string getName();
38     /*!
39      * \return true if a finite strain strategy has been set up
40      * \param[in] bd: behaviour description
41      */
42     static bool hasFiniteStrainStrategy(const BehaviourDescription&);
43     /*!
44      * \return the name of the finite strain strategy that has been set up
45      * \param[in] bd: behaviour description
46      */
47     static std::string getFiniteStrainStrategy(const BehaviourDescription &);
48     std::pair<bool, tokens_iterator> treatKeyword(
49         BehaviourDescription &,
50         const std::string &,
51         const std::vector<std::string> &,
52         tokens_iterator,
53         const tokens_iterator) override;
54     void endTreatment(const BehaviourDescription&,
55 		      const FileDescription&) const override;
56     void getTargetsDescription(TargetsDescription&,
57 			       const BehaviourDescription&) override;
58     //! destructor
59     ~AnsysInterface() override;
60   protected:
61     /*!
62      * \brief return the state variable offset used for variables used
63      * internally by the ansys interface
64      * \param[in] mb: behaviour description
65      * \param[in] h:  modelling hypothesis
66      */
67    virtual unsigned short getStateVariablesOffset(const BehaviourDescription &,
68                                                   const Hypothesis) const;
69    std::string getLibraryName(const BehaviourDescription &) const override;
70    /*!
71     * \brief write a  specialisation of the AnsysTraits class
72     * \param[in] out : ouptut file
73     * \param[in] mb  : behaviour description
74     * \param[in] h   : modelling hypothesis
75     */
76    virtual void writeAnsysBehaviourTraits(std::ostream &,
77                                           const BehaviourDescription &,
78                                           const Hypothesis) const;
79    void writeMTestFileGeneratorSetModellingHypothesis(
80        std::ostream &) const override;
81    std::string getFunctionNameBasis(const std::string &) const override;
82    /*!
83     * \return the name of the function generated by the interface
84     * \param[in] n: name of the behaviour as defined by interface
85     *               (generally taking into account the material
86     *               and the behaviour name)
87     * \param[in] h: modelling hypothesis
88     */
89    virtual std::string getFunctionNameForHypothesis(const std::string &,
90                                                     const Hypothesis) const;
91    std::set<Hypothesis> getModellingHypothesesToBeTreated(
92        const BehaviourDescription &) const override;
93    /*!
94     * \return the input file example
95     * \param[in] mb: behaviour description
96     * \param[in] fd: file description
97     */
98    virtual void writeInputFileExample(const BehaviourDescription &,
99                                       const FileDescription &) const;
100 
101    virtual std::string getInterfaceName() const override;
102    void writeBehaviourDataMainVariablesSetters(
103        std::ostream &, const BehaviourDescription &) const override;
104    void writeBehaviourDataGradientSetter(
105        std::ostream &,
106        const Gradient &,
107        const SupportedTypes::TypeSize) const override;
108    void writeIntegrationDataGradientSetter(
109        std::ostream &,
110        const Gradient &,
111        const SupportedTypes::TypeSize) const override;
112    void exportThermodynamicForce(std::ostream &,
113                                  const std::string &,
114                                  const ThermodynamicForce &,
115                                  const SupportedTypes::TypeSize) const override;
116    void writeInterfaceSpecificIncludes(
117        std::ostream &, const BehaviourDescription &) const override;
118    void writeBehaviourDataThermodynamicForceSetter(
119        std::ostream &,
120        const ThermodynamicForce &,
121        const SupportedTypes::TypeSize) const override;
122    std::vector<std::pair<std::string, std::string>>
123    getBehaviourDataConstructorAdditionalVariables() const override;
124    void completeBehaviourDataConstructor(
125        std::ostream &,
126        const Hypothesis,
127        const BehaviourDescription &) const override;
128    /*!
129     * \brief write the call to the base function
130     * \param[in] out:  output file
131     * \param[in] mb:   mechanical behaviour description
132     * \param[in] name: name of the behaviour as defined by interface
133     *                  (generally taking into account the material
134     *                  and the behaviour name)
135     * \param[in] sfeh: name of the function used to handle the stress
136     *                  expansion
137     * \param[in] h:    modelling hypothesis
138     */
139    virtual void writeFunctionBase(std::ostream &,
140                                   const BehaviourDescription &,
141                                   const std::string &,
142                                   const std::string &,
143                                   const Hypothesis) const;
144    /*!
145     * \brief write the call to the base function
146     * \param[in] out:  output file
147     * \param[in] mb:   mechanical behaviour description
148     * \param[in] name: name of the behaviour as defined by interface
149     *                  (generally taking into account the material
150     *                  and the behaviour name)
151     * \param[in] h:    modelling hypothesis
152     */
153    virtual void writeSmallStrainFunction(std::ostream &,
154                                          const BehaviourDescription &,
155                                          const std::string &,
156                                          const Hypothesis) const;
157    /*!
158     * \brief write the call to the base function
159     * \param[in] out:  output file
160     * \param[in] mb:   mechanical behaviour description
161     * \param[in] name: name of the behaviour as defined by interface
162     *                  (generally taking into account the material
163     *                  and the behaviour name)
164     * \param[in] h:    modelling hypothesis
165     */
166    virtual void writeFiniteStrainFunction(std::ostream &,
167                                           const BehaviourDescription &,
168                                           const std::string &,
169                                           const Hypothesis) const;
170    /*!
171     * \brief write the call to the base function
172     * \param[in] out:  output file
173     * \param[in] mb:   mechanical behaviour description
174     * \param[in] name: name of the behaviour as defined by interface
175     *                  (generally taking into account the material
176     *                  and the behaviour name)
177     * \param[in] h:    modelling hypothesis
178     */
179    virtual void writeFiniteRotationSmallStrainFunction(
180        std::ostream &,
181        const BehaviourDescription &,
182        const std::string &,
183        const Hypothesis) const;
184    /*!
185     * \brief write the call to the base function
186     * \param[in] out:  output file
187     * \param[in] mb:   mechanical behaviour description
188     * \param[in] name: name of the behaviour as defined by interface
189     *                  (generally taking into account the material
190     *                  and the behaviour name)
191     * \param[in] h:    modelling hypothesis
192     */
193    virtual void writeMieheApelLambrechtLogarithmicStrainFunction(
194        std::ostream &,
195        const BehaviourDescription &,
196        const std::string &,
197        const Hypothesis) const;
198    //! \return true if the interface handles external state variables
199    virtual bool areExternalStateVariablesSupported() const override;
200    /*!
201     * \brief boolean stating the we want a comparison of the user
202     * defined tangent operator with a numerical approximation.
203     */
204    bool compareToNumericalTangentOperator = false;
205    /*!
206     * \brief perturbation value used for the computation of the
207     * numerical approximation of the tangent operator
208     */
209    double strainPerturbationValue = 1.e-6;
210    /*!
211     * \brief comparison critera value used for comparing of the user
212     * defined tangent operator with a numerical approximation.
213     */
214    double tangentOperatorComparisonCriterion = 1.e7;
215   }; // end of struct AnsysInterface
216 
217 } // end of namespace mfront
218 
219 #endif /* LIB_MFRONT_ANSYSINTERFACE_HXX */
220