v0.16.0
Loading...
Searching...
No Matches
EshelbianTopologicalDerivative.hpp
Go to the documentation of this file.
1/**
2 * @file EshelbianTopologicalDerivative.hpp
3 * @brief
4 * @version 0.1
5 * @date 2026-02-11
6 *
7 * @copyright Copyright (c) 2026
8 *
9 */
10
11#ifndef ESHELBIAN_TOPOLOGICAL_DERIVATIVE_HPP
12#define ESHELBIAN_TOPOLOGICAL_DERIVATIVE_HPP
13
14namespace EshelbianPlasticity {
15
17 : public boost::enable_shared_from_this<MatOpsTopoData> {
18
21 matOpsData->insertCommonData("jacobianAtPts");
22 matOpsData->insertCommonData("invJacobianAtPtr");
23 matOpsData->insertCommonData("detJacobianAtPts");
24 matOpsData->insertCommonData("tangent1AtPts");
25 matOpsData->insertCommonData("tangent2AtPts");
26 matOpsData->insertCommonData("normalAtPts");
27 matOpsData->insertCommonData("objAtPts");
28 matOpsData->insertCommonData("objDStrainAtPts");
29 matOpsData->insertCommonData("objDStressAtPts");
30 matOpsData->insertCommonData("objDRotationAtPts");
31 matOpsData->insertCommonData("objDDisplacementAtPts");
32 }
33
34 boost::shared_ptr<MatOps::MatOpsData> matOpsData;
35};
36
38
40
42
43 template <class Tensor>
44 static inline auto getFTensor(MatrixDouble &m, const int nb_gauss_pts) {
45 return MatrixSizeHelper<Tensor, DL>::get(m, nb_gauss_pts)();
46 }
47
48 template <class Tensor>
49 static inline auto getFTensor(MatrixPtr m, const int nb_gauss_pts) {
50 return getFTensor<Tensor>(*m, nb_gauss_pts);
51 }
52
53 static inline auto getFTensor0(MatrixPtr m, const int nb_gauss_pts) {
54#ifndef NDEBUG
55 if (!m)
56 THROW_MESSAGE("TopologicalData matrix pointer is not available");
57
58 const auto nb = static_cast<size_t>(nb_gauss_pts);
59 if (!((m->size1() == nb && m->size2() == 1) ||
60 (m->size1() == 1 && m->size2() == nb)))
61 THROW_MESSAGE("Scalar matrix size is not compatible with the number of "
62 "integration points");
63#endif
64 return getFTensor0FromMat(*m);
65 }
66
67 inline auto getFTensorJacobian(const int nb_gauss_pts) {
68 return getFTensor<
69 GetFTensor2FromMatType<SPACE_DIM, SPACE_DIM, -1, DL>>(
70 matOpsData->getCommonDataPtr("jacobianAtPts"), nb_gauss_pts);
71 }
72
73 inline auto getFTensorInvJacobian(const int nb_gauss_pts) {
74 return getFTensor<
75 GetFTensor2FromMatType<SPACE_DIM, SPACE_DIM, -1, DL>>(
76 matOpsData->getCommonDataPtr("invJacobianAtPtr"), nb_gauss_pts);
77 }
78
79 inline auto getFTensorDetJacobian(const int nb_gauss_pts) {
80 return getFTensor0(matOpsData->getCommonDataPtr("detJacobianAtPts"),
81 nb_gauss_pts);
82 }
83
84 inline auto getFTensorTangent1(const int nb_gauss_pts) {
85 return getFTensor<GetFTensor1FromMatType<SPACE_DIM, -1, DL>>(
86 matOpsData->getCommonDataPtr("tangent1AtPts"), nb_gauss_pts);
87 }
88
89 inline auto getFTensorTangent2(const int nb_gauss_pts) {
90 return getFTensor<GetFTensor1FromMatType<SPACE_DIM, -1, DL>>(
91 matOpsData->getCommonDataPtr("tangent2AtPts"), nb_gauss_pts);
92 }
93
94 inline auto getFTensorNormal(const int nb_gauss_pts) {
95 return getFTensor<GetFTensor1FromMatType<SPACE_DIM, -1, DL>>(
96 matOpsData->getCommonDataPtr("normalAtPts"), nb_gauss_pts);
97 }
98
99 inline auto getFTensorObj(const int nb_gauss_pts) {
100 return getFTensor0(matOpsData->getCommonDataPtr("objAtPts"),
101 nb_gauss_pts);
102 }
103
104 inline auto getFTensorObjDStrain(const int nb_gauss_pts) {
105 return getFTensor<
106 GetFTensor2FromMatType<SPACE_DIM, SPACE_DIM, -1, DL>>(
107 matOpsData->getCommonDataPtr("objDStrainAtPts"), nb_gauss_pts);
108 }
109
110 inline auto getFTensorObjDStress(const int nb_gauss_pts) {
111 return getFTensor<
112 GetFTensor2FromMatType<SPACE_DIM, SPACE_DIM, -1, DL>>(
113 matOpsData->getCommonDataPtr("objDStressAtPts"), nb_gauss_pts);
114 }
115
116 inline auto getFTensorObjDDisplacement(const int nb_gauss_pts) {
117 return getFTensor<GetFTensor1FromMatType<SPACE_DIM, -1, DL>>(
118 matOpsData->getCommonDataPtr("objDDisplacementAtPts"), nb_gauss_pts);
119 }
120
121 inline auto getFTensorObjDRotation(const int nb_gauss_pts) {
122 return getFTensor<GetFTensor1FromMatType<SPACE_DIM, -1, DL>>(
123 matOpsData->getCommonDataPtr("objDRotationAtPts"), nb_gauss_pts);
124 }
125
126 inline auto getJacobianAtPts() {
127 return matOpsData->getCommonDataPtr("jacobianAtPts");
128 }
129
130 inline auto getInvJacobianAtPts() {
131 return matOpsData->getCommonDataPtr("invJacobianAtPtr");
132 }
133
134 inline auto getDetJacobianAtPts() {
135 return matOpsData->getCommonDataPtr("detJacobianAtPts");
136 }
137
138 inline auto getTangent1AtPts() {
139 return matOpsData->getCommonDataPtr("tangent1AtPts");
140 }
141
142 inline auto getTangent2AtPts() {
143 return matOpsData->getCommonDataPtr("tangent2AtPts");
144 }
145
146 inline auto getNormalAtPts() {
147 return matOpsData->getCommonDataPtr("normalAtPts");
148 }
149
150 inline auto getObjAtPts() {
151 return matOpsData->getCommonDataPtr("objAtPts");
152 }
153
154 inline auto getObjDStrainAtPts() {
155 return matOpsData->getCommonDataPtr("objDStrainAtPts");
156 }
157
158 inline auto getObjDStressAtPts() {
159 return matOpsData->getCommonDataPtr("objDStressAtPts");
160 }
161
163 return matOpsData->getCommonDataPtr("objDDisplacementAtPts");
164 }
165
166 inline auto getObjDRotationAtPts() {
167 return matOpsData->getCommonDataPtr("objDRotationAtPts");
168 }
169
170};
171
173 TopologicalTAOCtx() = default;
174 virtual ~TopologicalTAOCtx() = default;
175};
176
177
178boost::shared_ptr<TopologicalTAOCtx> createTopologicalTAOCtx(
179 EshelbianCore *ep,
180 ForcesAndSourcesCore::GaussHookFun set_integration_at_interior,
181 ForcesAndSourcesCore::GaussHookFun set_integration_at_face,
182 SmartPetscObj<TS> time_solver);
183
184MoFEMErrorCode topologicalEvaluateObjectiveAndGradient(Tao tao, Vec sol,
185 PetscReal *f, Vec g,
186 void *ctx);
187
188MoFEMErrorCode evaluateGradient(TopologicalTAOCtx *ctx_ptr, double *f, Vec g,
189 ObjectiveModelType eval_energy_model);
190
191MoFEMErrorCode testTopologicalDerivative(TopologicalTAOCtx *ctx_ptr, Vec sol,
192 PetscReal *f, Vec g,
193 ObjectiveModelType eval_energy_model);
194}
195
196#endif // ESHELBIAN_TOPOLOGICAL_DERIVATIVE_HPP
constexpr int SPACE_DIM
#define THROW_MESSAGE(msg)
Throw MoFEM exception.
boost::shared_ptr< TopologicalTAOCtx > createTopologicalTAOCtx(EshelbianCore *ep, ForcesAndSourcesCore::GaussHookFun set_integration_at_interior, ForcesAndSourcesCore::GaussHookFun set_integration_at_face, SmartPetscObj< TS > time_solver)
boost::shared_ptr< MatrixDouble > MatrixPtr
MoFEMErrorCode evaluateGradient(TopologicalTAOCtx *ctx_ptr, double *f, Vec g, ObjectiveModelType eval_energy_model)
DataLayoutTraits< DataLayout::GaussByCoeffs > DL
MoFEMErrorCode topologicalEvaluateObjectiveAndGradient(Tao tao, Vec sol, PetscReal *f, Vec g, void *ctx)
MoFEMErrorCode testTopologicalDerivative(TopologicalTAOCtx *ctx_ptr, Vec sol, PetscReal *f, Vec g, ObjectiveModelType eval_energy_model)
boost::shared_ptr< MatOpsData > createMatOpsDataPtr()
Definition MatOps.cpp:671
constexpr double g
FTensor::Index< 'm', 3 > m
boost::shared_ptr< MatOps::MatOpsData > matOpsData
static auto getFTensor(MatrixDouble &m, const int nb_gauss_pts)
static auto getFTensor0(MatrixPtr m, const int nb_gauss_pts)
static auto getFTensor(MatrixPtr m, const int nb_gauss_pts)