v0.15.5
Loading...
Searching...
No Matches
AdolCOps.hpp
Go to the documentation of this file.
1/**
2 * \file AdolCOps.hpp
3 * \example mofem/tutorials/vec-2_nonlinear_elasticity/src/AdolCOps.hpp
4 *
5 * @copyright Copyright (c) 2023
6 */
7
8#ifndef __ADOLC_OPS_HPP__
9#define __ADOLC_OPS_HPP__
10
11namespace AdolCOps {
12
14
15 static auto atTagName(std::string name) { return tagNameVsTag.at(name); }
16 static auto setTagName(std::string name, int tag = -1) {
17 MOFEM_LOG_CHANNEL("WORLD");
18
19 auto it = tagNameVsTag.find(name);
20
21 if (tag >= 0) {
22 if (it != tagNameVsTag.end()) {
23 MOFEM_LOG("WORLD", Sev::warning)
24 << "Tag name: " << name
25 << " is already registered with tag: " << it->second
26 << ". Overwriting with new tag: " << tag;
27 it->second = -1; // set it to invalid value to avoid confusion
28 }
29 for (auto &p : tagNameVsTag) {
30 if (p.second == tag) {
32 "Tag: " + std::to_string(tag) +
33 " is already registered with name: " + p.first);
34 }
35 }
36 // register new tag
37 tagNameVsTag[name] = tag;
38 return tag;
39 }
40
41 int max_tag = 0;
42 for (auto &p : tagNameVsTag) {
43 if (p.second > max_tag) {
44 max_tag = p.second;
45 }
46 }
47
48 if (it == tagNameVsTag.end()) {
49 tagNameVsTag[name] = max_tag + 1;
50 }
51
52 MOFEM_LOG("WORLD", Sev::inform)
53 << "Tag name: " << name
54 << " is registered with tag: " << tagNameVsTag[name];
55
56 return tagNameVsTag[name];
57 }
58
59private:
60 static int getTagByName(std::string name) {
61 auto it = tagNameVsTag.find(name);
62 if (it == tagNameVsTag.end()) {
63 int new_tag = tagNameVsTag.size() + 1;
64 tagNameVsTag[name] = new_tag;
65 return new_tag;
66 }
67 return it->second;
68 }
69
70 static inline std::map<std::string, int> tagNameVsTag;
71};
72
73/** \name ADOL-C Data Interface */
74/**@{*/
75struct ADolCData : public boost::enable_shared_from_this<ADolCData> {
76 virtual ~ADolCData() = default;
77
78 using MatrixPtr = boost::shared_ptr<MatrixDouble>;
79
80 virtual std::pair<bool, MatrixPtr>
81 insertCommonData(const std::string &name,
82 const MatrixDouble &data = MatrixDouble(),
83 int shift = 0) = 0;
84
85 virtual std::pair<bool, MatrixPtr>
86 insertActiveData(const std::string &name,
87 const MatrixDouble &data = MatrixDouble(),
88 int shift = 0) = 0;
89
90 virtual std::pair<bool, MatrixPtr>
91 insertDependentData(const std::string &name,
92 const MatrixDouble &data = MatrixDouble(),
93 int shift = 0) = 0;
94
95 virtual std::pair<bool, MatrixPtr>
96 insertDependentDerivativesData(const std::string &name,
97 const MatrixDouble &data = MatrixDouble(),
98 int shift = 0) = 0;
99
100 virtual MatrixPtr getCommonDataPtr(const std::string &name) = 0;
101 virtual MatrixPtr getActiveDataPtr(const std::string &name) = 0;
102 virtual MatrixPtr getDependentDataPtr(const std::string &name) = 0;
103 virtual MatrixPtr getDependentDerivativesDataPtr(const std::string &name) = 0;
104
105 virtual MoFEMErrorCode
106 setActiveContinuousVector(std::vector<double> &active_variables) = 0;
107 virtual MoFEMErrorCode
108 setDependentContinuousVector(std::vector<double> &dependent_variables) = 0;
110 std::vector<double> &dependent_variables_derivatives) = 0;
111
112 virtual MoFEMErrorCode
113 getActiveContinuousVector(const std::vector<double> &active_variables) = 0;
114 virtual MoFEMErrorCode getDependentContinuousVector(
115 const std::vector<double> &dependent_variables) = 0;
117 const std::vector<double> &dependent_variables_derivatives) = 0;
118};
119/**@}*/
120
121/** \name Physical Equation Interface */
122/**@{*/
124
127 boost::shared_ptr<ADolCData> adolc_data_ptr, int tag,
128 boost::shared_ptr<std::map<int, Range>> tag_vs_range_ptr = nullptr)
129 : adolcDataPtr(adolc_data_ptr), tAg(tag),
130 tagVsRangePtr(tag_vs_range_ptr) {}
131 virtual ~PhysicalEquations() = default;
132
133 virtual MoFEMErrorCode
134 getOptions(MoFEM::Interface *m_field_ptr = nullptr) = 0;
135 virtual MoFEMErrorCode setParams(EntityHandle ent, int gg) = 0;
136 virtual MoFEMErrorCode recordTape() = 0;
137
138 virtual ForcesAndSourcesCore::UserDataOperator *
139 createOp(boost::shared_ptr<PhysicalEquations> physical_ptr, bool eval_stress,
140 bool eval_tangent) = 0;
141
142 MoFEMErrorCode setActiveContinuousVector() {
143 return adolcDataPtr->setActiveContinuousVector(activeVariables);
144 }
146 return adolcDataPtr->setDependentContinuousVector(dependentVariables);
147 }
149 return adolcDataPtr->setDependentDerivativesContinuousVector(
151 }
152 MoFEMErrorCode getActiveContinuousVector() {
153 return adolcDataPtr->getActiveContinuousVector(activeVariables);
154 }
156 return adolcDataPtr->getDependentContinuousVector(dependentVariables);
157 }
159 return adolcDataPtr->getDependentDerivativesContinuousVector(
161 }
162
163 int tAg;
164 boost::shared_ptr<std::map<int, Range>> tagVsRangePtr;
165 std::vector<std::pair<Range, std::vector<double>>> paramVecByRange;
166
167 boost::shared_ptr<ADolCData> adolcDataPtr;
168 std::vector<double> activeVariables;
169 std::vector<double> dependentVariables;
170 std::vector<double> dependentVariablesDerivatives;
171};
172/**@}*/
173
174/** \name Data Factory */
175/**@{*/
176boost::shared_ptr<ADolCData> createADolCDataPtr();
177/**@}*/
178
179/** \name Generic Operator Factory */
180/**@{*/
187
188struct MODEL {
189 MODEL() = delete;
190};
191
192template <class MODEL, int MODEL_TYPE>
193boost::shared_ptr<PhysicalEquations>
194createAdolCPhysicalEquationsPtr(boost::shared_ptr<ADolCData> adolc_data_ptr,
195 int tag);
196
197template <class MODEL, int MODEL_TYPE> struct OpMaterialFactory {
199};
200/**@}*/
201
202} // namespace AdolCOps
203
204
205#endif // __ADOLC_OPS_HPP__
#define CHK_THROW_MESSAGE(err, msg)
Check and throw MoFEM exception.
@ MOFEM_OPERATION_UNSUCCESSFUL
Definition definitions.h:34
#define MOFEM_LOG(channel, severity)
Log.
#define MOFEM_LOG_CHANNEL(channel)
Set and reset channel.
boost::shared_ptr< ADolCData > createADolCDataPtr()
Definition AdolOps.cpp:245
boost::shared_ptr< PhysicalEquations > createAdolCPhysicalEquationsPtr(boost::shared_ptr< ADolCData > adolc_data_ptr, int tag)
@ MODEL_AXISYMMETRIC
Definition AdolCOps.hpp:185
@ MODEL_2D_PLANE_STRESS
Definition AdolCOps.hpp:184
@ MODEL_2D_PLANE_STRAIN
Definition AdolCOps.hpp:183
virtual MoFEMErrorCode getActiveContinuousVector(const std::vector< double > &active_variables)=0
virtual std::pair< bool, MatrixPtr > insertDependentDerivativesData(const std::string &name, const MatrixDouble &data=MatrixDouble(), int shift=0)=0
virtual std::pair< bool, MatrixPtr > insertActiveData(const std::string &name, const MatrixDouble &data=MatrixDouble(), int shift=0)=0
virtual MoFEMErrorCode getDependentDerivativesContinuousVector(const std::vector< double > &dependent_variables_derivatives)=0
virtual MatrixPtr getActiveDataPtr(const std::string &name)=0
virtual MoFEMErrorCode setActiveContinuousVector(std::vector< double > &active_variables)=0
virtual MatrixPtr getDependentDataPtr(const std::string &name)=0
virtual MatrixPtr getCommonDataPtr(const std::string &name)=0
boost::shared_ptr< MatrixDouble > MatrixPtr
Definition AdolCOps.hpp:78
virtual std::pair< bool, MatrixPtr > insertDependentData(const std::string &name, const MatrixDouble &data=MatrixDouble(), int shift=0)=0
virtual MatrixPtr getDependentDerivativesDataPtr(const std::string &name)=0
virtual MoFEMErrorCode setDependentContinuousVector(std::vector< double > &dependent_variables)=0
virtual ~ADolCData()=default
virtual MoFEMErrorCode getDependentContinuousVector(const std::vector< double > &dependent_variables)=0
virtual MoFEMErrorCode setDependentDerivativesContinuousVector(std::vector< double > &dependent_variables_derivatives)=0
virtual std::pair< bool, MatrixPtr > insertCommonData(const std::string &name, const MatrixDouble &data=MatrixDouble(), int shift=0)=0
static std::map< std::string, int > tagNameVsTag
Definition AdolCOps.hpp:70
static auto atTagName(std::string name)
Definition AdolCOps.hpp:15
static int getTagByName(std::string name)
Definition AdolCOps.hpp:60
static auto setTagName(std::string name, int tag=-1)
Definition AdolCOps.hpp:16
MoFEMErrorCode setDependentDerivativesContinuousVector()
Definition AdolCOps.hpp:148
MoFEMErrorCode getDependentDerivativesContinuousVector()
Definition AdolCOps.hpp:158
std::vector< std::pair< Range, std::vector< double > > > paramVecByRange
Definition AdolCOps.hpp:165
virtual ForcesAndSourcesCore::UserDataOperator * createOp(boost::shared_ptr< PhysicalEquations > physical_ptr, bool eval_stress, bool eval_tangent)=0
std::vector< double > dependentVariablesDerivatives
Definition AdolCOps.hpp:170
MoFEMErrorCode setActiveContinuousVector()
Definition AdolCOps.hpp:142
MoFEMErrorCode getActiveContinuousVector()
Definition AdolCOps.hpp:152
std::vector< double > dependentVariables
Definition AdolCOps.hpp:169
PhysicalEquations(boost::shared_ptr< ADolCData > adolc_data_ptr, int tag, boost::shared_ptr< std::map< int, Range > > tag_vs_range_ptr=nullptr)
Definition AdolCOps.hpp:126
MoFEMErrorCode getDependentContinuousVector()
Definition AdolCOps.hpp:155
virtual ~PhysicalEquations()=default
boost::shared_ptr< std::map< int, Range > > tagVsRangePtr
Definition AdolCOps.hpp:164
MoFEMErrorCode setDependentContinuousVector()
Definition AdolCOps.hpp:145
virtual MoFEMErrorCode recordTape()=0
virtual MoFEMErrorCode getOptions(MoFEM::Interface *m_field_ptr=nullptr)=0
boost::shared_ptr< ADolCData > adolcDataPtr
Definition AdolCOps.hpp:167
virtual MoFEMErrorCode setParams(EntityHandle ent, int gg)=0
std::vector< double > activeVariables
Definition AdolCOps.hpp:168
Deprecated interface functions.