v0.15.5
Loading...
Searching...
No Matches
EshelbianTopologicalDerivative.cpp
Go to the documentation of this file.
1/**
2 * @file EshelbianTopologicalDerivative.cpp
3 * @author your name (you@domain.com)
4 * @brief
5 * @version 0.1
6 * @date 2026-02-21
7 *
8 * @copyright Copyright (c) 2026
9 *
10 */
11
12#define SINGULARITY
13#include <MoFEM.hpp>
14using namespace MoFEM;
15
17#include <EshelbianAux.hpp>
18#include <TSElasticPostStep.hpp>
19
20#include <boost/math/constants/constants.hpp>
22
25
26using namespace EshelbianPlasticity;
27using namespace ShapeOptimization;
28
29namespace EshelbianPlasticity {
30
33 EshelbianCore *ep,
34 ForcesAndSourcesCore::GaussHookFun set_integration_at_interior,
35 ForcesAndSourcesCore::GaussHookFun set_integration_at_face,
36 SmartPetscObj<TS> time_solver)
37 : ep_ptr(ep), integrationAtInterior(set_integration_at_interior),
38 integrationAtFace(set_integration_at_face), timeSolver(time_solver),
39
40 geometryVec(CommInterface::createEntitiesPetscVector(
41 ep->mField.get_comm(), ep->mField.get_moab(), 0, 3, Sev::noisy)),
42 gradJVec(CommInterface::createEntitiesPetscVector(
43 ep->mField.get_comm(), ep->mField.get_moab(), 0, 3, Sev::noisy)) {}
44
45private:
50
53
57
60 return field_ptr->th_FieldDataVerts;
61 }
62
63 Tag getTag(moab::Interface &moab, std::string tag_name, int size) {
64 Tag tag;
65 rval = moab.tag_get_handle(tag_name.c_str(), size, MB_TYPE_DOUBLE, tag,
66 MB_TAG_CREAT | MB_TAG_DENSE, NULL);
67 if (rval == MB_ALREADY_ALLOCATED)
68 rval = MB_SUCCESS;
69 CHK_MOAB_THROW(rval, "Failed to get tag " + tag_name);
70 return tag;
71 };
72
73 Tag getJdXTag() { return getTag(ep_ptr->mField.get_moab(), "DJ_DX", 3); }
74
76 PetscReal *f,
77 Vec g, void *ctx);
78
80 const double alpha,
81 const double rho,
82 const double alpha_omega);
83};
84
85boost::shared_ptr<TopologicalTAOCtx> createTopologicalTAOCtx(
86 EshelbianCore *ep,
87 ForcesAndSourcesCore::GaussHookFun set_integration_at_interior,
88 ForcesAndSourcesCore::GaussHookFun set_integration_at_face,
89 SmartPetscObj<TS> time_solver) {
90 return boost::make_shared<TopologicalTAOCtxImpl>(
91 ep, set_integration_at_interior, set_integration_at_face, time_solver);
92}
93}
94
97
98namespace EshelbianPlasticity {
99
101 const double alpha, const double rho,
102 const double alpha_omega) {
103
105 auto *ctx_impl_ptr = dynamic_cast<TopologicalTAOCtxImpl *>(ctx_ptr);
106 if (!ctx_impl_ptr)
107 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
108 "Invalid context pointer type");
109 auto &ep = *ctx_impl_ptr->ep_ptr;
110 auto &m_field = ep.mField;
111 auto interior_integration_hook = ctx_impl_ptr->integrationAtInterior;
112 auto boundary_integration_hook = ctx_impl_ptr->integrationAtFace;
113 auto th_top_tag = ctx_impl_ptr->getVertexMaterialH1PositionsTag();
114 auto th_grad_tag = ctx_impl_ptr->getJdXTag(m_field.get_moab());
115
116 boost::shared_ptr<double> J_ptr = boost::make_shared<double>(0.);
117 auto dJ_dX_vec = ctx_impl_ptr->gradJVec.second;
118
119 auto fe_spatial =
120 boost::make_shared<VolumeElementForcesAndSourcesCore>(m_field);
121 auto dJ_dx_vec = pushTopologicalSpatialOps(
122 ep, fe_spatial, interior_integration_hook, boundary_integration_hook);
123 auto fe_material =
124 boost::make_shared<VolumeElementForcesAndSourcesCore>(m_field);
125 CHKERR pushTopologicalMaterialOps(ep, fe_material, interior_integration_hook,
126 boundary_integration_hook, J_ptr,
127 th_grad_tag);
128
129 auto lambda_vec = createDMVector(ep.dmElastic);
130 auto ksp = snesGetKSP(tsGetSNES(ctx_impl_ptr->timeSolver));
131 CHKERR KSPSolveTranspose(ksp, dJ_dx_vec, lambda_vec);
132
133 auto fe_adjoint =
134 boost::make_shared<VolumeElementForcesAndSourcesCore>(m_field);
135 auto dJ_adjoint_vec = pushTopologicalOps_dJ_adjont_gradient(
136 ep, fe_adjoint, interior_integration_hook, boundary_integration_hook,
137 lambda_vec, dJ_dX_vec, alpha, rho, alpha_omega);
138
140}
141
142}
Auxilary functions for Eshelbian plasticity.
Eshelbian plasticity interface.
Interface for Python-based objective function evaluation in topology optimization.
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
#define CHK_MOAB_THROW(err, msg)
Check error code of MoAB function and throw MoFEM exception.
@ MOFEM_DATA_INCONSISTENCY
Definition definitions.h:31
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
auto createDMVector(DM dm)
Get smart vector from DM.
Definition DMMoFEM.hpp:1234
virtual const Field * get_field_structure(const std::string &name, enum MoFEMTypes bh=MF_EXIST) const =0
get field structure
SeverityLevel
Severity levels.
boost::shared_ptr< TopologicalTAOCtx > createTopologicalTAOCtx(EshelbianCore *ep, ForcesAndSourcesCore::GaussHookFun set_integration_at_interior, ForcesAndSourcesCore::GaussHookFun set_integration_at_face, SmartPetscObj< TS > time_solver)
MoFEMErrorCode pushTopologicalOps_dJ_adjont_gradient(EshelbianCore &ep, boost::shared_ptr< VolumeElementForcesAndSourcesCore > fe, ForcesAndSourcesCore::GaussHookFun interior_integration_hook, ForcesAndSourcesCore::GaussHookFun boundary_integration_hook, SmartPetscObj< Vec > lambda_vec, Tag th_grad_tag, const double alpha, const double rho, const double alpha_omega)
SmartPetscObj< Vec > pushTopologicalSpatialOps(EshelbianCore &ep, boost::shared_ptr< VolumeElementForcesAndSourcesCore > fe, ForcesAndSourcesCore::GaussHookFun interior_integration_hook, ForcesAndSourcesCore::GaussHookFun boundary_integration_hook)
MoFEMErrorCode testTopologicalDerivative(EshelbianCore &ep, boost::shared_ptr< VolumeElementForcesAndSourcesCore > fe, ForcesAndSourcesCore::GaussHookFun interior_integration_hook, ForcesAndSourcesCore::GaussHookFun boundary_integration_hook, const double alpha, const double rho, const double alpha_omega)
MoFEMErrorCode pushTopologicalMaterialOps(EshelbianCore &ep, boost::shared_ptr< VolumeElementForcesAndSourcesCore > fe, ForcesAndSourcesCore::GaussHookFun interior_integration_hook, ForcesAndSourcesCore::GaussHookFun boundary_integration_hook, boost::shared_ptr< double > J_ptr, Tag th_grad_tag)
static MoFEMErrorCodeGeneric< moab::ErrorCode > rval
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
implementation of Data Operators for Forces and Sources
Definition Common.hpp:10
auto snesGetKSP(SNES snes)
auto tsGetSNES(TS ts)
constexpr double g
MoFEM::Interface & mField
const std::string materialH1Positions
TopologicalTAOCtxImpl(EshelbianCore *ep, ForcesAndSourcesCore::GaussHookFun set_integration_at_interior, ForcesAndSourcesCore::GaussHookFun set_integration_at_face, SmartPetscObj< TS > time_solver)
friend MoFEMErrorCode cohesiveEvaluateObjectiveAndGradient(Tao tao, Vec x, PetscReal *f, Vec g, void *ctx)
friend MoFEMErrorCode testTopologicalDerivative(TopologicalTAOCtx *ctx_ptr, const double alpha, const double rho, const double alpha_omega)
Tag getTag(moab::Interface &moab, std::string tag_name, int size)
Managing BitRefLevels.
std::pair< std::pair< Range, Range >, SmartPetscObj< Vec > > EntitiesPetscVector
virtual moab::Interface & get_moab()=0
boost::function< MoFEMErrorCode(ForcesAndSourcesCore *fe_raw_ptr, int order_row, int order_col, int order_data)> GaussHookFun
intrusive_ptr for managing petsc objects
double rho
Definition plastic.cpp:144