v0.16.3
Loading...
Searching...
No Matches
Classes | Static Public Member Functions | Static Private Member Functions | Static Private Attributes | List of all members
EshelbianPlasticity::TSElasticPreAndPostStep Struct Reference

#include "users_modules/eshelbian_plasticity/src/TSElasticPreAndPostStep.hpp"

Collaboration diagram for EshelbianPlasticity::TSElasticPreAndPostStep:
[legend]

Classes

struct  ProjectionScope
 

Static Public Member Functions

static MoFEMErrorCode setPreStep (EshelbianCore *ep_ptr, TS ts, bool h1_update=false)
 
static MoFEMErrorCode preStepFun (TS ts)
 
static MoFEMErrorCode postStepFun (TS ts)
 

Static Private Member Functions

static MoFEMErrorCode postStepInitialise (EshelbianCore *ep_ptr)
 
static MoFEMErrorCode postStepDestroy ()
 

Static Private Attributes

static SmartPetscObj< KSP > prjKsp
 
static SmartPetscObj< Vec > prjD
 
static SmartPetscObj< Vec > prjF
 
static SmartPetscObj< DM > dmPrjSpatial
 
static EshelbianCore * epPtr
 

Detailed Description

Definition at line 10 of file TSElasticPreAndPostStep.hpp.

Member Function Documentation

◆ postStepDestroy()

MoFEMErrorCode EshelbianPlasticity::TSElasticPreAndPostStep::postStepDestroy ( )
staticprivate

Definition at line 340 of file TSElasticPreAndPostStep.cpp.

340 {
342 prjKsp.reset();
343 prjD.reset();
344 prjF.reset();
345 if (dmPrjSpatial) {
346 // Break DM/pipeline reference cycles while the parent problem is alive.
348 dmPrjSpatial.reset();
349 }
350 epPtr = nullptr;
352};
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
PetscErrorCode DMMoFEMClearDMCtx(DM dm)
Clear solver and Schur data owned by a MoFEM DM context.
Definition DMMoFEM.cpp:79

◆ postStepFun()

MoFEMErrorCode EshelbianPlasticity::TSElasticPreAndPostStep::postStepFun ( TS  ts)
static

Definition at line 451 of file TSElasticPreAndPostStep.cpp.

451 {
453
454 double time;
455 CHKERR TSGetTime(ts, &time);
456
457 MOFEM_LOG("EP", Sev::inform) << "Solve H1 post-step";
458 CHKERR VecZeroEntries(prjF);
459 CHKERR KSPSolve(prjKsp, prjF, prjD);
460 CHKERR VecGhostUpdateBegin(prjD, INSERT_VALUES, SCATTER_FORWARD);
461 CHKERR VecGhostUpdateEnd(prjD, INSERT_VALUES, SCATTER_FORWARD);
463 SCATTER_REVERSE);
464
465 // The projected H1 field now carries the accepted deformation. Reset the
466 // incremental stretch and rotation before crack calculations and TS
467 // monitors so that the accepted increment is not applied a second time.
468 CHKERR resetIncrementalKinematics(epPtr, ts);
469
472 case GRIFFITH_FORCE:
474 MOFEM_LOG("EP", Sev::inform) << "Calculate Griffith force";
476 break;
477 default:
478 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
479 "Energy release selector not handled");
480 };
482 std::numeric_limits<double>::epsilon()) {
483 MOFEM_LOG("EP", Sev::inform) << "Calculate faces orientation";
484
487 }
489 }
490
491 // Clear history after rebasing incremental kinematics onto the H1 field.
492 // With no H1 configuration, retain it until the next pre-step copy.
494 CHKERR VecZeroEntries(epPtr->solTSStep);
495
496 PetscBool local_stop = PETSC_FALSE;
497 PetscBool global_stop = PETSC_FALSE;
501 const double area_increase =
503 const bool crack_arrest_stops =
506 if (area_increase > EshelbianCore::maxCrackExtension ||
508 crack_arrest_stops) {
509 MOFEM_LOG_C("EP", Sev::warning,
510 "Stopping crack growth. Area increase: %3.12e, "
511 "average Griffiths energy: %3.12e, critical Griffiths "
512 "energy: %3.12e",
513 area_increase, epPtr->avgGriffithsEnergy,
515 local_stop = PETSC_TRUE;
516 }
517 }
518 MPI_Bcast(&local_stop, 1, MPIU_BOOL, 0, PETSC_COMM_WORLD);
519 global_stop = local_stop;
520
521 if (global_stop) {
522 TSSetConvergedReason(ts, TS_CONVERGED_USER);
525 } else {
528 }
529 break;
530 default:
531 break;
532 }
533
535};
#define MOFEM_LOG_C(channel, severity, format,...)
@ MOFEM_DATA_INCONSISTENCY
Definition definitions.h:31
PetscErrorCode DMoFEMMeshToLocalVector(DM dm, Vec l, InsertMode mode, ScatterMode scatter_mode, RowColData rc=RowColData::COL)
set local (or ghosted) vector values on mesh for partition only
Definition DMMoFEM.cpp:543
#define MOFEM_LOG(channel, severity)
Log.
MoFEM::Interface & mField
static enum SolverType solverType
static bool noCrackExtension
static PetscBool crackingOn
static double griffithEnergy
Griffith energy.
static enum RotSelector gradApproximator
static double maxCrackExtension
static double crackingStartTime
MoFEMErrorCode calculateCrackArea(boost::shared_ptr< double > &area_ptr)
MoFEMErrorCode calculateOrientation(const int tag, bool set_orientation)
static int nbStepsNoCrackExtension
boost::shared_ptr< double > currentCrackAreaPtr
double avgGriffithsEnergy
MoFEMErrorCode calculateFaceMaterialForce(const int tag, TS ts, SmartPetscObj< Vec > *adjoint_gradient_vector=nullptr)
static bool potentialCrackArrest
static PetscBool propagateUnderCompression
static enum EnergyReleaseSelector energyReleaseSelector
SmartPetscObj< Vec > solTSStep
virtual int get_comm_rank() const =0

◆ postStepInitialise()

MoFEMErrorCode EshelbianPlasticity::TSElasticPreAndPostStep::postStepInitialise ( EshelbianCore *  ep_ptr)
staticprivate

Definition at line 266 of file TSElasticPreAndPostStep.cpp.

266 {
268
269 epPtr = ep_ptr;
270
271 // H1 displacement may be excluded from dmElastic; use the full parent DM.
272 dmPrjSpatial = createDM(ep_ptr->mField.get_comm(), "DMMOFEM");
273 CHKERR DMMoFEMCreateSubDM(dmPrjSpatial, ep_ptr->dM, "PROJECT_SPATIAL");
279 CHKERR DMSetUp(dmPrjSpatial);
280
281 auto create_post_step_ksp = [&]() {
282 auto ksp = createKSP(epPtr->mField.get_comm());
283
284 auto set_up = [&]() {
287 using DomainEleOp = DomainEle::UserDataOperator;
291 GAUSS>::OpBaseTimesVector<1, 3, 3>;
292 auto fe_lhs = boost::make_shared<DomainEle>(ep_ptr->mField);
293 auto fe_rhs = boost::make_shared<DomainEle>(ep_ptr->mField);
294
295 fe_lhs->getUserPolynomialBase() = boost::shared_ptr<BaseFunction>(
296 new CGGUserPolynomialBase(nullptr, true));
297 fe_rhs->getUserPolynomialBase() = boost::shared_ptr<BaseFunction>(
298 new CGGUserPolynomialBase(nullptr, true));
299 CHKERR
300 EshelbianPlasticity::AddHOOps<SPACE_DIM, SPACE_DIM, SPACE_DIM>::add(
301 fe_lhs->getOpPtrVector(), {L2}, ep_ptr->materialH1Positions,
302 ep_ptr->frontAdjEdges);
303 CHKERR
304 EshelbianPlasticity::AddHOOps<SPACE_DIM, SPACE_DIM, SPACE_DIM>::add(
305 fe_rhs->getOpPtrVector(), {L2}, ep_ptr->materialH1Positions,
306 ep_ptr->frontAdjEdges);
307
308 fe_lhs->getOpPtrVector().push_back(
309 new OpDomainMass(ep_ptr->spatialH1Disp, ep_ptr->spatialH1Disp));
310 auto w_ptr = boost::make_shared<MatrixDouble>();
311 fe_rhs->getOpPtrVector().push_back(
313 fe_rhs->getOpPtrVector().push_back(
314 new OpRhs(ep_ptr->spatialH1Disp, w_ptr));
315
317 dmPrjSpatial, ep_ptr->elementVolumeName, fe_lhs, nullptr, nullptr);
319 fe_rhs, nullptr, nullptr);
320
321 CHKERR KSPAppendOptionsPrefix(ksp, "prjspatial_");
322 CHKERR KSPSetFromOptions(ksp);
323 CHKERR KSPSetDM(ksp, dmPrjSpatial);
324 CHKERR KSPSetUp(ksp);
326 };
327
328 CHK_THROW_MESSAGE(set_up(), "set up");
329
330 return ksp;
331 };
332
333 prjKsp = create_post_step_ksp();
336
338};
SmartPetscObj< KSP > ksp
ElementsAndOps< SPACE_DIM >::DomainEle DomainEle
FormsIntegrators< DomainEleOp >::Assembly< PETSC >::BiLinearForm< GAUSS >::OpMass< 1, FIELD_DIM > OpDomainMass
#define CHK_THROW_MESSAGE(err, msg)
Check and throw MoFEM exception.
PetscErrorCode DMMoFEMSetIsPartitioned(DM dm, PetscBool is_partitioned)
Definition DMMoFEM.cpp:1142
PetscErrorCode DMMoFEMCreateSubDM(DM subdm, DM dm, const char problem_name[])
Must be called by user to set Sub DM MoFEM data structures.
Definition DMMoFEM.cpp:244
PetscErrorCode DMMoFEMAddElement(DM dm, std::string fe_name)
add element to dm
Definition DMMoFEM.cpp:517
PetscErrorCode DMMoFEMSetSquareProblem(DM dm, PetscBool square_problem)
set squared problem
Definition DMMoFEM.cpp:479
PetscErrorCode DMMoFEMAddSubFieldRow(DM dm, const char field_name[])
Definition DMMoFEM.cpp:267
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:656
auto createDMVector(DM dm, RowColData rc=RowColData::COL)
Get smart vector from DM.
Definition DMMoFEM.hpp:1250
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:697
@ GAUSS
Gaussian quadrature integration.
@ PETSC
Standard PETSc assembly.
auto createKSP(MPI_Comm comm)
PetscErrorCode DMMoFEMSetDestroyProblem(DM dm, PetscBool destroy_problem)
Definition DMMoFEM.cpp:463
SmartPetscObj< Vec > vectorDuplicate(Vec vec)
Create duplicate vector of smart vector.
auto createDM(MPI_Comm comm, const std::string dm_type_name)
Creates smart DM object.
CGG User Polynomial Base.
boost::shared_ptr< Range > frontAdjEdges
const std::string spatialL2Disp
SmartPetscObj< DM > dM
Coupled problem all fields.
const std::string materialH1Positions
const std::string elementVolumeName
const std::string spatialH1Disp
virtual MPI_Comm & get_comm() const =0
Specialization for MatrixDouble vector field values calculation.

◆ preStepFun()

MoFEMErrorCode EshelbianPlasticity::TSElasticPreAndPostStep::preStepFun ( TS  ts)
static

Definition at line 354 of file TSElasticPreAndPostStep.cpp.

354 {
356 MOFEM_LOG("EP", Sev::inform) << "Pre step";
357
358 double time;
359 CHKERR TSGetTime(ts, &time);
360
362
363 auto debug_crack = [&]() {
365
366 PetscBool debug_crack_mesh = PETSC_FALSE;
367 CHKERR PetscOptionsGetBool(PETSC_NULLPTR, "", "-debug_crack_mesh",
368 &debug_crack_mesh, PETSC_NULLPTR);
369 if (debug_crack_mesh) {
370
371 auto append_meshsets_from_block = [](MoFEM::Interface &m_field,
372 const std::string &block_name,
373 const int dim,
374 std::vector<EntityHandle> &r) {
376 auto mesh_mng = m_field.getInterface<MeshsetsManager>();
377 auto bcs = mesh_mng->getCubitMeshsetPtr(
378
379 std::regex((boost::format("%s(.*)") % block_name).str())
380
381 );
382
383 for (auto bc : bcs) {
384 Range ents;
385 CHKERR m_field.get_moab().get_entities_by_dimension(
386 bc->getMeshset(), dim, ents, true);
387 if (!ents.empty()) {
388 r.push_back(bc->getMeshset());
389 }
390 }
391
393 };
394
395 if (!epPtr->mField.get_comm_rank() &&
397 if (epPtr->maxMovedFaces) {
399 ->addEntitiesToMeshset(BLOCKSET, epPtr->addCrackMeshsetId,
401 }
402
403 auto meshset_ptr = get_temp_meshset_ptr(epPtr->mField.get_moab());
404 Range tets;
405 CHKERR epPtr->mField.get_moab().get_entities_by_dimension(
406 *meshset_ptr, 3, tets);
407 CHKERR epPtr->mField.get_moab().add_entities(*meshset_ptr, tets);
408
409 std::vector<EntityHandle> meshsets;
410 meshsets.push_back(*meshset_ptr);
411
412 CHKERR append_meshsets_from_block(epPtr->mField, "CRACK", 2,
413 meshsets);
414 CHKERR append_meshsets_from_block(epPtr->mField, "FRONT", 1,
415 meshsets);
416 CHKERR append_meshsets_from_block(epPtr->mField, "EDGE", 1,
417 meshsets);
418
419 int time_step = 0;
420 CHKERR TSGetStepNumber(ts, &time_step);
421 std::string file_name =
422 "crack_meshsets_" + std::to_string(time_step) + ".h5m";
423 CHKERR epPtr->mField.get_moab().write_file(file_name.c_str(), "MOAB",
424 nullptr, meshsets.data(),
425 static_cast<int>(meshsets.size()));
426 }
427 }
428
430 };
431
434 CHKERR debug_crack();
436 }
437 CHKERR epPtr->projectGeometry(0, time);
439 }
440
441 Vec T;
442 CHKERR TSGetSolution(ts, &T);
443
444 CHKERR VecCopy(T, epPtr->solTSStep);
445 CHKERR VecGhostUpdateBegin(epPtr->solTSStep, INSERT_VALUES, SCATTER_FORWARD);
446 CHKERR VecGhostUpdateEnd(epPtr->solTSStep, INSERT_VALUES, SCATTER_FORWARD);
447
449}
@ BLOCKSET
MoFEMErrorCode getCubitMeshsetPtr(const int ms_id, const CubitBCType cubit_bc_type, const CubitMeshSets **cubit_meshset_ptr) const
get cubit meshset
const FTensor::Tensor2< T, Dim, Dim > Vec
PetscErrorCode PetscOptionsGetBool(PetscOptions *, const char pre[], const char name[], PetscBool *bval, PetscBool *set)
auto get_temp_meshset_ptr(moab::Interface &moab)
Create smart pointer to temporary meshset.
int r
Definition sdf.py:205
boost::shared_ptr< Range > maxMovedFaces
MoFEMErrorCode setNewFrontCoordinates()
MoFEMErrorCode projectGeometry(const EntityHandle meshset=0, double time=0)
MoFEMErrorCode projectMaterialTags(const EntityHandle meshset=0)
MoFEMErrorCode addCrackSurfaces(const bool debug=false)
static int addCrackMeshsetId
virtual moab::Interface & get_moab()=0
Deprecated interface functions.
Interface for managing meshsets containing materials and boundary conditions.
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.

◆ setPreStep()

MoFEMErrorCode EshelbianPlasticity::TSElasticPreAndPostStep::setPreStep ( EshelbianCore *  ep_ptr,
TS  ts,
bool  h1_update = false 
)
static

Register coefficient reset before solves, with optional H1 bookkeeping.

Definition at line 208 of file TSElasticPreAndPostStep.cpp.

209 {
211 PetscContainer container = nullptr;
212 CHKERR PetscObjectQuery(getPetscObject(ts), elasticPreStepKey,
213 reinterpret_cast<PetscObject *>(&container));
214 if (!container) {
215 CHKERR PetscContainerCreate(ep_ptr->mField.get_comm(), &container);
216 auto *context = new ElasticPreStepContext{ep_ptr, h1_update};
217 CHKERR PetscContainerSetPointer(container, context);
218 CHKERR PetscContainerSetUserDestroy(container, [](void *pointer) {
220 delete static_cast<ElasticPreStepContext *>(pointer);
222 });
223 CHKERR PetscObjectCompose(getPetscObject(ts), elasticPreStepKey,
224 getPetscObject(container));
225 CHKERR PetscContainerDestroy(&container);
226 } else {
227 void *pointer = nullptr;
228 CHKERR PetscContainerGetPointer(container, &pointer);
229 auto &context = *static_cast<ElasticPreStepContext *>(pointer);
230 context.ep = ep_ptr;
231 context.h1Update = h1_update;
232 }
233 CHKERR TSSetPreStep(ts, elasticPreStep);
235}
boost::shared_ptr< IncrementalOptimizationContext > context
PetscObject getPetscObject(T obj)

Member Data Documentation

◆ dmPrjSpatial

SmartPetscObj<DM> EshelbianPlasticity::TSElasticPreAndPostStep::dmPrjSpatial
inlinestaticprivate

Definition at line 39 of file TSElasticPreAndPostStep.hpp.

◆ epPtr

EshelbianCore* EshelbianPlasticity::TSElasticPreAndPostStep::epPtr
inlinestaticprivate

Definition at line 40 of file TSElasticPreAndPostStep.hpp.

◆ prjD

SmartPetscObj<Vec> EshelbianPlasticity::TSElasticPreAndPostStep::prjD
inlinestaticprivate

Definition at line 37 of file TSElasticPreAndPostStep.hpp.

◆ prjF

SmartPetscObj<Vec> EshelbianPlasticity::TSElasticPreAndPostStep::prjF
inlinestaticprivate

Definition at line 38 of file TSElasticPreAndPostStep.hpp.

◆ prjKsp

SmartPetscObj<KSP> EshelbianPlasticity::TSElasticPreAndPostStep::prjKsp
inlinestaticprivate

Definition at line 36 of file TSElasticPreAndPostStep.hpp.


The documentation for this struct was generated from the following files: