v0.14.0
TSElasticPostStep.cpp
Go to the documentation of this file.
1 /** @file TSElasticPostStep.cpp
2  * @brief
3  * @date 2023-05-13
4  *
5  * @license{This project is released under the MIT License.}
6  *
7  */
8 
10 
11  static MoFEMErrorCode postStepInitialise(EshelbianCore *ep_ptr) {
13 
14  epPtr = ep_ptr;
15 
16  auto create_post_step_ksp = [&]() {
17  auto ksp = createKSP(epPtr->mField.get_comm());
18 
19  auto set_up = [&]() {
21  using DomainEle = VolumeElementForcesAndSourcesCore;
23  using OpDomainMass = FormsIntegrators<DomainEleOp>::Assembly<
25  using OpRhs = FormsIntegrators<DomainEleOp>::Assembly<
26  PETSC>::LinearForm<GAUSS>::OpBaseTimesVector<1, 3, 1>;
27  auto fe_lhs = boost::make_shared<DomainEle>(ep_ptr->mField);
28  auto fe_rhs = boost::make_shared<DomainEle>(ep_ptr->mField);
29 
30  fe_lhs->getUserPolynomialBase() =
31  boost::shared_ptr<BaseFunction>(new CGGUserPolynomialBase());
32  fe_rhs->getUserPolynomialBase() =
33  boost::shared_ptr<BaseFunction>(new CGGUserPolynomialBase());
34  CHKERR
36  fe_lhs->getOpPtrVector(), {L2}, ep_ptr->materialH1Positions,
37  ep_ptr->frontAdjEdges);
38  CHKERR
40  fe_rhs->getOpPtrVector(), {L2}, ep_ptr->materialH1Positions,
41  ep_ptr->frontAdjEdges);
42 
43  fe_lhs->getOpPtrVector().push_back(
44  new OpDomainMass(ep_ptr->spatialH1Disp, ep_ptr->spatialH1Disp));
45  auto w_ptr = boost::make_shared<MatrixDouble>();
46  fe_rhs->getOpPtrVector().push_back(
47  new OpCalculateVectorFieldValues<3>(ep_ptr->spatialL2Disp, w_ptr));
48  fe_rhs->getOpPtrVector().push_back(
49  new OpRhs(ep_ptr->spatialH1Disp, w_ptr));
50 
51  CHKERR DMMoFEMKSPSetComputeOperators(ep_ptr->dmPrjSpatial,
52  ep_ptr->elementVolumeName, fe_lhs,
53  nullptr, nullptr);
54  CHKERR DMMoFEMKSPSetComputeRHS(ep_ptr->dmPrjSpatial,
55  ep_ptr->elementVolumeName, fe_rhs,
56  nullptr, nullptr);
57 
58  // preProcRhs = boost::make_shared<FEMethod>();
59  // struct MinusOne : public ScalingMethod {
60  // double getScale(const double time) { return -time; }
61  // };
62  // preProcRhs->preProcessHook = EssentialPreProc<DisplacementCubitBcData>(
63  // ep_ptr->mField, preProcRhs, {boost::make_shared<MinusOne>()});
64 
65  CHKERR KSPAppendOptionsPrefix(ksp, "prjspatial_");
66  CHKERR KSPSetFromOptions(ksp);
67  CHKERR KSPSetDM(ksp, ep_ptr->dmPrjSpatial);
68  CHKERR KSPSetUp(ksp);
70  };
71 
72  CHK_THROW_MESSAGE(set_up(), "set up");
73 
74  return ksp;
75  };
76 
77  prjKsp = create_post_step_ksp();
78  prjD = createDMVector(ep_ptr->dmPrjSpatial);
80  prjDM = ep_ptr->dmPrjSpatial;
81 
83  };
84 
87  prjKsp.reset();
88  prjD.reset();
89  prjF.reset();
90  prjDM.reset();
91  preProcRhs.reset();
93  };
94 
95  static MoFEMErrorCode preStepFun(TS ts) {
97  MOFEM_LOG("EP", Sev::inform) << "Pre step";
98 
99  Vec T;
100  CHKERR TSGetSolution(ts, &T);
101 
102  auto zero_filled = [&](auto name) {
104  auto is_mng = epPtr->mField.getInterface<ISManager>();
105  SmartPetscObj<IS> is;
106  CHKERR is_mng->isCreateProblemFieldAndRankLocal(
107  "ELASTIC_PROBLEM", ROW, name, 0, MAX_DOFS_ON_ENTITY, is);
108  const int *index_ptr;
109  CHKERR ISGetIndices(is, &index_ptr);
110  int size;
111  CHKERR ISGetLocalSize(is, &size);
112  double *a;
113  CHKERR VecGetArray(T, &a);
114  for (auto i = 0; i != size; i++) {
115  a[index_ptr[i]] = 0;
116  }
117  CHKERR VecRestoreArray(T, &a);
118  CHKERR ISRestoreIndices(is, &index_ptr);
120  };
121 
122  switch (EshelbianCore::gradApproximator) {
123  case NO_H1_CONFIGURATION:
124  break;
125  case LARGE_ROT:
126  MOFEM_LOG("EP", Sev::verbose) << "Zeroing (large) fields";
127  CHKERR zero_filled(epPtr->stretchTensor);
128  CHKERR zero_filled(epPtr->rotAxis);
129  break;
130  case MODERATE_ROT:
131  MOFEM_LOG("EP", Sev::verbose) << "Zeroing (moderate) fields";
132  CHKERR zero_filled(epPtr->stretchTensor);
133  CHKERR zero_filled(epPtr->rotAxis);
134  break;
135  case SMALL_ROT:
136  MOFEM_LOG("EP", Sev::verbose) << "Zeroing (small) fields";
137  CHKERR zero_filled(epPtr->stretchTensor);
138  CHKERR zero_filled(epPtr->rotAxis);
139  break;
140  }
141 
143  }
144 
145  static MoFEMErrorCode postStepFun(TS ts) {
147  MOFEM_LOG("EP", Sev::inform) << "Solve H1 post-step";
148  CHKERR VecZeroEntries(prjF);
149  CHKERR KSPSolve(prjKsp, prjF, prjD);
150  CHKERR VecGhostUpdateBegin(prjD, INSERT_VALUES, SCATTER_FORWARD);
151  CHKERR VecGhostUpdateEnd(prjD, INSERT_VALUES, SCATTER_FORWARD);
152  CHKERR DMoFEMMeshToLocalVector(prjDM, prjD, INSERT_VALUES, SCATTER_REVERSE);
153  // double time;
154  // CHKERR TSGetTime(ts, &time);
155  // preProcRhs->ts_t = time;
156  // CHKERR DMoFEMPreProcessFiniteElements(prjDM, preProcRhs.get());
158  };
159 
160 private:
161  static SmartPetscObj<KSP> prjKsp;
162  static SmartPetscObj<Vec> prjD;
163  static SmartPetscObj<Vec> prjF;
164  static SmartPetscObj<DM> prjDM;
165  static EshelbianCore *epPtr;
166 
167  static boost::shared_ptr<FEMethod> preProcRhs;
168 };
169 
170 SmartPetscObj<KSP> TSElasticPostStep::prjKsp;
171 SmartPetscObj<Vec> TSElasticPostStep::prjD;
172 SmartPetscObj<Vec> TSElasticPostStep::prjF;
173 SmartPetscObj<DM> TSElasticPostStep::prjDM;
174 EshelbianCore *TSElasticPostStep::epPtr;
175 boost::shared_ptr<FEMethod> TSElasticPostStep::preProcRhs;
MoFEM::DMMoFEMKSPSetComputeRHS
PetscErrorCode DMMoFEMKSPSetComputeRHS(DM dm, const char fe_name[], MoFEM::FEMethod *method, MoFEM::BasicMethod *pre_only, MoFEM::BasicMethod *post_only)
set KSP right hand side evaluation function
Definition: DMMoFEM.cpp:637
CHK_THROW_MESSAGE
#define CHK_THROW_MESSAGE(err, msg)
Check and throw MoFEM exception.
Definition: definitions.h:609
TSElasticPostStep::postStepFun
static MoFEMErrorCode postStepFun(TS ts)
Definition: TSElasticPostStep.cpp:145
MoFEM::Exceptions::MoFEMErrorCode
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:56
EshelbianPlasticity::AddHOOps
Definition: EshelbianPlasticity.hpp:1150
MoFEM::PETSC
@ PETSC
Definition: FormsIntegrators.hpp:105
MoFEM::DMoFEMMeshToLocalVector
PetscErrorCode DMoFEMMeshToLocalVector(DM dm, Vec l, InsertMode mode, ScatterMode scatter_mode)
set local (or ghosted) vector values on mesh for partition only
Definition: DMMoFEM.cpp:523
MoFEM::createKSP
auto createKSP(MPI_Comm comm)
Definition: PetscSmartObj.hpp:261
EshelbianPlasticity::NO_H1_CONFIGURATION
@ NO_H1_CONFIGURATION
Definition: EshelbianPlasticity.hpp:43
MoFEM::DMMoFEMKSPSetComputeOperators
PetscErrorCode DMMoFEMKSPSetComputeOperators(DM dm, const char fe_name[], MoFEM::FEMethod *method, MoFEM::BasicMethod *pre_only, MoFEM::BasicMethod *post_only)
Set KSP operators and push mofem finite element methods.
Definition: DMMoFEM.cpp:678
OpDomainMass
FormsIntegrators< DomainEleOp >::Assembly< PETSC >::BiLinearForm< GAUSS >::OpMass< 1, FIELD_DIM > OpDomainMass
Definition: child_and_parent.cpp:53
TSElasticPostStep
Definition: TSElasticPostStep.cpp:9
ROW
@ ROW
Definition: definitions.h:136
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:548
MoFEM::createDMVector
auto createDMVector(DM dm)
Get smart vector from DM.
Definition: DMMoFEM.hpp:1099
TSElasticPostStep::prjKsp
static SmartPetscObj< KSP > prjKsp
Definition: TSElasticPostStep.cpp:158
TSElasticPostStep::preStepFun
static MoFEMErrorCode preStepFun(TS ts)
Definition: TSElasticPostStep.cpp:95
a
constexpr double a
Definition: approx_sphere.cpp:30
TSElasticPostStep::epPtr
static EshelbianCore * epPtr
Definition: TSElasticPostStep.cpp:165
i
FTensor::Index< 'i', SPACE_DIM > i
Definition: hcurl_divergence_operator_2d.cpp:27
BiLinearForm
TSElasticPostStep::postStepDestroy
static MoFEMErrorCode postStepDestroy()
Definition: TSElasticPostStep.cpp:85
OpRhs
Definition: approx_sphere.cpp:68
TSElasticPostStep::preProcRhs
static boost::shared_ptr< FEMethod > preProcRhs
Definition: TSElasticPostStep.cpp:167
TSElasticPostStep::prjF
static SmartPetscObj< Vec > prjF
Definition: TSElasticPostStep.cpp:163
MAX_DOFS_ON_ENTITY
#define MAX_DOFS_ON_ENTITY
Maximal number of DOFs on entity.
Definition: definitions.h:249
DomainEleOp
EshelbianPlasticity::SMALL_ROT
@ SMALL_ROT
Definition: EshelbianPlasticity.hpp:43
MOFEM_LOG
#define MOFEM_LOG(channel, severity)
Log.
Definition: LogManager.hpp:308
MoFEM::vectorDuplicate
SmartPetscObj< Vec > vectorDuplicate(Vec vec)
Create duplicate vector of smart vector.
Definition: PetscSmartObj.hpp:221
EshelbianPlasticity::LARGE_ROT
@ LARGE_ROT
Definition: EshelbianPlasticity.hpp:43
UserDataOperator
ForcesAndSourcesCore::UserDataOperator UserDataOperator
Definition: HookeElement.hpp:75
TSElasticPostStep::prjD
static SmartPetscObj< Vec > prjD
Definition: TSElasticPostStep.cpp:162
EigenMatrix::Vec
const FTensor::Tensor2< T, Dim, Dim > Vec
Definition: MatrixFunction.hpp:66
TSElasticPostStep::postStepInitialise
static MoFEMErrorCode postStepInitialise(EshelbianCore *ep_ptr)
Definition: TSElasticPostStep.cpp:11
DomainEle
ElementsAndOps< SPACE_DIM >::DomainEle DomainEle
Definition: child_and_parent.cpp:34
EshelbianPlasticity::MODERATE_ROT
@ MODERATE_ROT
Definition: EshelbianPlasticity.hpp:43
MoFEMFunctionReturn
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:429
MoFEMFunctionBegin
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:359
TSElasticPostStep::prjDM
static SmartPetscObj< DM > prjDM
Definition: TSElasticPostStep.cpp:164