v0.16.3
Loading...
Searching...
No Matches
ts_elastic_projection_atom.cpp
Go to the documentation of this file.
1/** @file ts_elastic_projection_atom.cpp
2 * @brief Verify elastic projection ownership and cleanup on failed solves.
3 */
4
5#include <MoFEM.hpp>
6using namespace MoFEM;
9using namespace EshelbianPlasticity;
10
11namespace {
12
13MoFEMErrorCode checkProjection(EshelbianCore &ep, const bool present) {
15 if (ep.mField.check_problem("PROJECT_SPATIAL") != present)
17 "Unexpected spatial projection lifetime");
18 if (present) {
19 const Problem *problem;
20 CHKERR ep.mField.get_problem("PROJECT_SPATIAL", &problem);
21 if (!problem->getNbDofsRow() ||
22 problem->getNbDofsRow() != problem->getNbDofsCol())
24 "Spatial projection must be a nonempty square problem");
25 for (const auto &dof : *problem->getNumeredRowDofsPtr())
26 if (dof->getName() != ep.spatialH1Disp)
27 SETERRQ(ep.mField.get_comm(), MOFEM_ATOM_TEST_INVALID,
28 "Spatial projection contains a non-H1-displacement field");
29 }
31}
32
33MoFEMErrorCode runProjectionAtom(EshelbianCore &ep) {
35 CHKERR checkProjection(ep, false);
36 {
38 CHKERR checkProjection(ep, true);
39 CHKERR projection.close();
40 CHKERR projection.close();
41 CHKERR checkProjection(ep, false);
42 }
43
44 // A solver error must release the subproblem before its Core is destroyed.
45 const auto failed_solve = [&]() -> MoFEMErrorCode {
47 CHKERR checkProjection(ep, true);
48 return PETSC_ERR_USER;
49 };
50 if (failed_solve() != PETSC_ERR_USER)
52 "Expected simulated solver failure");
53 CHKERR checkProjection(ep, false);
54 try {
56 THROW_MESSAGE("Simulated solve exception");
57 } catch (const MoFEMException &) {
58 }
59 CHKERR checkProjection(ep, false);
60
61 // Fail KSP setup after the DM/pipelines exist, then initialise again.
62 char previous_type[256] = "";
63 PetscBool found;
64 CHKERR PetscOptionsGetString(nullptr, nullptr, "-prjspatial_ksp_type",
65 previous_type, sizeof(previous_type), &found);
66 CHKERR PetscOptionsSetValue(nullptr, "-prjspatial_ksp_type",
67 "invalid_projection_ksp");
68 CHKERR PetscPushErrorHandler(PetscReturnErrorHandler, nullptr);
69 bool failed_initialisation = false;
70 try {
72 } catch (const MoFEMException &) {
73 failed_initialisation = true;
74 }
75 CHKERR PetscPopErrorHandler();
76 if (found)
77 CHKERR PetscOptionsSetValue(nullptr, "-prjspatial_ksp_type", previous_type);
78 else
79 CHKERR PetscOptionsClearValue(nullptr, "-prjspatial_ksp_type");
80 if (!failed_initialisation)
82 "Invalid projection KSP type must fail initialisation");
83 CHKERR checkProjection(ep, false);
84 {
86 CHKERR checkProjection(ep, true);
87 }
88 CHKERR checkProjection(ep, false);
89 CHKERR PetscPrintf(ep.mField.get_comm(),
90 "Elastic spatial projection lifecycle atom passed\n");
92}
93
94} // namespace
95
96static char help[] = "Verify elastic projection resource ownership.\n";
97
98int main(int argc, char *argv[]) {
99 MoFEM::Core::Initialize(&argc, &argv, nullptr, help);
100 auto core_log = logging::core::get();
101 core_log->add_sink(LogManager::createSink(LogManager::getStrmWorld(), "EP"));
102 LogManager::setLog("EP");
103 core_log->add_sink(
105 LogManager::setLog("EPSELF");
106 core_log->add_sink(
108 LogManager::setLog("EPSYNC");
109 try {
110 CHKERR runAuxiliaryLogarithmicStressTest(runProjectionAtom);
111 }
114 return 0;
115}
Shared mesh and problem setup for auxiliary formulation atoms.
EshelbianCore * ep
Elastic TS pre/post-step registration and H1 transfer lifecycle.
boost::shared_ptr< ConstrainMatrixCtx > projection
int main()
#define CATCH_ERRORS
Catch errors.
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ MOFEM_ATOM_TEST_INVALID
Definition definitions.h:40
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
#define THROW_MESSAGE(msg)
Throw MoFEM exception.
virtual const Problem * get_problem(const std::string problem_name) const =0
Get the problem object.
static LoggerType & setLog(const std::string channel)
Set ans resset chanel logger.
virtual bool check_problem(const std::string name)=0
check if problem exist
MoFEMErrorCode runAuxiliaryLogarithmicStressTest(const std::function< MoFEMErrorCode(EshelbianCore &)> &test)
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
implementation of Data Operators for Forces and Sources
Definition Common.hpp:10
PetscErrorCode PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)
MoFEM::Interface & mField
virtual MPI_Comm & get_comm() const =0
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
Definition Core.cpp:68
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition Core.cpp:123
static boost::shared_ptr< SinkType > createSink(boost::shared_ptr< std::ostream > stream_ptr, std::string comm_filter)
Create a sink object.
static boost::shared_ptr< std::ostream > getStrmWorld()
Get the strm world object.
static boost::shared_ptr< std::ostream > getStrmSync()
Get the strm sync object.
static boost::shared_ptr< std::ostream > getStrmSelf()
Get the strm self object.
keeps basic data about problem
DofIdx getNbDofsRow() const
DofIdx getNbDofsCol() const
static char help[]