v0.14.0
adolc_plasticity.cpp

\brife Implementation of plasticity problem using ADOLC-C

/**
* \file adolc_plasticity.cpp
* \ingroup adoc_plasticity
* \example adolc_plasticity.cpp
*
* \brife Implementation of plasticity problem using ADOLC-C
*
*/
#include <MoFEM.hpp>
using namespace MoFEM;
constexpr int SPACE_DIM =
EXECUTABLE_DIMENSION; //< Space dimension of problem, mesh
/** Select finite element type for integration on domain based on problem
* dimension
*/
/** Select finite element type for integrate on boundary based on problem
* dimension
*/
using BoundaryEle =
/** Operators used to assemble domain integrals
*/
/** Operators used to assemble boundary integrals
*/
/** Linear forms used to integrate body forces
*/
/** Select linear froms reading data from blockest (e.g. "BODY_FORCE") and
* applying body force.
*/
using OpBodyForce =
// Select natural BC boundary condition
// Use natural boundary conditions implemented with adv-1 example which includes
// spring BC
/** Use Gauss quadrature rule and PETSc assembly to integrate neural boundary
* conditions. Select linear forms operators.
*/
/* Use specialization from adv-1 integrating boundary conditions on forces and
* with springs. OP is used to integrate the right hand side
*/
/** Use Gauss quadrature rule and PETSc assembly to integrate neural boundary
* conditions. Select bi-linear forms operators.
*/
/** Use specialization from adv-1 integrating boundary conditions on forces and
* with springs
*/
// Note: We create only skin post-processing mesh.
template <int DIM>
struct PostProcEleByDim; //< Select finite elements and operators used for
// postprocessing
template <> struct PostProcEleByDim<2> {
};
template <> struct PostProcEleByDim<3> {
};
using namespace ADOLCPlasticity;
PlasticProblem(MoFEM::Interface &m_field) : mField(m_field) {}
MoFEMErrorCode runProblem();
private:
MoFEMErrorCode readMesh();
MoFEMErrorCode setupProblem();
MoFEMErrorCode boundaryCondition();
MoFEMErrorCode assembleSystem();
MoFEMErrorCode solveSystem();
MoFEMErrorCode gettingNorms();
MoFEMErrorCode outputResults();
MoFEMErrorCode checkResults();
int approxOrder = 2;
boost::shared_ptr<ClosestPointProjection> cpPtr; ///< Closest point
///< projection
};
//! [Run problem]
CHKERR readMesh();
CHKERR setupProblem();
CHKERR boundaryCondition();
CHKERR assembleSystem();
CHKERR solveSystem();
CHKERR gettingNorms();
CHKERR outputResults();
CHKERR checkResults();
}
//! [Run problem]
//! [Read mesh]
auto simple = mField.getInterface<Simple>();
CHKERR simple->getOptions();
CHKERR simple->loadFile();
if (simple->getDim() != SPACE_DIM)
SETERRQ2(PETSC_COMM_WORLD, MOFEM_DATA_INCONSISTENCY,
"Wrong dimension of mesh %d != %d", simple->getDim(), SPACE_DIM);
}
//! [Read mesh]
//! [Set up problem]
Simple *simple = mField.getInterface<Simple>();
enum bases { AINSWORTH, DEMKOWICZ, LASBASETOPT };
const char *list_bases[LASBASETOPT] = {"ainsworth", "demkowicz"};
PetscInt choice_base_value = AINSWORTH;
CHKERR PetscOptionsGetEList(PETSC_NULL, NULL, "-base", list_bases,
LASBASETOPT, &choice_base_value, PETSC_NULL);
switch (choice_base_value) {
case AINSWORTH:
MOFEM_LOG("WORLD", Sev::inform)
<< "Set AINSWORTH_LEGENDRE_BASE for displacements";
break;
case DEMKOWICZ:
approxBase = DEMKOWICZ_JACOBI_BASE;
MOFEM_LOG("WORLD", Sev::inform)
<< "Set DEMKOWICZ_JACOBI_BASE for displacements";
break;
default:
approxBase = LASTBASE;
break;
}
// Add field
CHKERR simple->addDomainField("U", H1, approxBase, SPACE_DIM);
CHKERR simple->addBoundaryField("U", H1, approxBase, SPACE_DIM);
CHKERR PetscOptionsGetInt(PETSC_NULL, "", "-order", &approxOrder, PETSC_NULL);
CHKERR simple->setFieldOrder("U", approxOrder);
CHKERR simple->setUp();
//! [Material models selection]
/**
* FIXME: Here only array of material models is initalized. Each model has
* unique set of the ADOL-C tags. Pointer is attached based on block name to
* which entity belongs. That will enable heterogeneity of the model, in
* addition of heterogeneity of the material properties.
*/
enum MaterialModel {
VonMisses,
VonMissesPlaneStress,
Paraboloidal,
LastModel
};
const char *list_materials[LastModel] = {"VonMisses", "VonMissesPlaneStress",
"Paraboloidal"};
PetscInt choice_material = VonMisses;
CHKERR PetscOptionsGetEList(PETSC_NULL, NULL, "-material", list_materials,
LastModel, &choice_material, PETSC_NULL);
switch (choice_material) {
case VonMisses:
cpPtr = createMaterial<J2Plasticity<3>>();
break;
case VonMissesPlaneStress:
if (SPACE_DIM != 2)
SETERRQ(PETSC_COMM_WORLD, MOFEM_DATA_INCONSISTENCY,
"VonMissesPlaneStrain is only for 2D case");
cpPtr = createMaterial<J2Plasticity<2>>();
break;
case Paraboloidal:
cpPtr = createMaterial<ParaboloidalPlasticity>();
break;
default:
SETERRQ(PETSC_COMM_WORLD, MOFEM_DATA_INCONSISTENCY, "Wrong material model");
}
if (approxBase == DEMKOWICZ_JACOBI_BASE && SPACE_DIM == 2)
cpPtr->integrationRule = [](int, int, int p) { return 2 * (p - 2); };
//! [Material models selection]
}
//! [Set up problem]
//! [Boundary condition]
auto *pipeline_mng = mField.getInterface<PipelineManager>();
auto simple = mField.getInterface<Simple>();
auto bc_mng = mField.getInterface<BcManager>();
auto time_scale = boost::make_shared<TimeScale>();
auto rule = [](int, int, int p) { return 2 * p; };
CHKERR pipeline_mng->setDomainRhsIntegrationRule(cpPtr->integrationRule);
CHKERR pipeline_mng->setDomainLhsIntegrationRule(cpPtr->integrationRule);
CHKERR pipeline_mng->setBoundaryRhsIntegrationRule(rule);
// Add Natural BCs to RHS
pipeline_mng->getOpBoundaryRhsPipeline(), mField, "U", {time_scale},
Sev::inform);
// Add Natural BCs to LHS
pipeline_mng->getOpBoundaryRhsPipeline(), mField, "U", Sev::inform);
//! Add body froces
pipeline_mng->getOpDomainRhsPipeline(), mField, "U", {time_scale},
"BODY_FORCE", Sev::inform);
// Essential BC
CHKERR bc_mng->removeBlockDOFsOnEntities(simple->getProblemName(), "REMOVE_X",
"U", 0, 0);
CHKERR bc_mng->removeBlockDOFsOnEntities(simple->getProblemName(), "REMOVE_Y",
"U", 1, 1);
CHKERR bc_mng->removeBlockDOFsOnEntities(simple->getProblemName(), "REMOVE_Z",
"U", 2, 2);
CHKERR bc_mng->pushMarkDOFsOnEntities<DisplacementCubitBcData>(
simple->getProblemName(), "U");
}
//! [Boundary condition]
//! [Push operators to pipeline]
auto *simple = mField.getInterface<Simple>();
auto *pipeline_mng = mField.getInterface<PipelineManager>();
// assemble operator to the right hand side
auto add_domain_ops_lhs = [&](auto &pip) {
// push forward finite element bases from reference to physical element
// create local common data
auto common_data_ptr = boost::make_shared<ADOLCPlasticity::CommonData>();
// calculate displacement gradients at integration points
"U", common_data_ptr->getGardAtGaussPtsPtr()));
// assemble tangent operator
CHKERR opFactoryDomainLhs<SPACE_DIM, PETSC, GAUSS, DomainEleOp>(
mField, "U", pip, "ADOLCMAT", common_data_ptr, cpPtr);
};
auto add_domain_ops_rhs = [&](auto &pip) {
// push forward finite element bases from reference to physical element
// create local common data
auto common_data_ptr = boost::make_shared<ADOLCPlasticity::CommonData>();
// calculate displacement gradients at integration points
"U", common_data_ptr->getGardAtGaussPtsPtr()));
// assemble residual
CHKERR opFactoryDomainRhs<SPACE_DIM, PETSC, GAUSS, DomainEleOp>(
mField, "U", pip, "ADOLCMAT", common_data_ptr, cpPtr, Sev::inform);
};
// Push operators to the left hand side pipeline. Indicate that domain (i.e.
// volume/interior) element is used.
CHKERR add_domain_ops_lhs(pipeline_mng->getOpDomainLhsPipeline());
// Push operators to the right hand side pipeline.
CHKERR add_domain_ops_rhs(pipeline_mng->getOpDomainRhsPipeline());
}
//! [Push operators to pipeline]
/**
* @brief Monitor solution
*
* This functions is called by TS solver at the end of each step. It is used
* to output results to the hard drive.
*/
struct Monitor : public FEMethod {
std::pair<boost::shared_ptr<PostProcEleDomain>,
boost::shared_ptr<PostProcEleBdy>>
pair_post_proc_fe,
boost::shared_ptr<DomainEle> reaction_fe,
std::vector<boost::shared_ptr<ScalingMethod>> smv)
: dM(dm), reactionFE(reaction_fe), vecOfTimeScalingMethods(smv) {
fRes = createDMVector(dM);
domainPostProcFe = pair_post_proc_fe.first;
skinPostProcFe = pair_post_proc_fe.second;
}
MoFEMErrorCode postProcess() {
CHKERR PetscOptionsGetInt(PETSC_NULL, "", "-save_every_nth_step",
&save_every_nth_step, PETSC_NULL);
auto make_vtk = [&]() {
if (domainPostProcFe) {
CHKERR DMoFEMLoopFiniteElements(dM, "dFE", domainPostProcFe,
getCacheWeakPtr());
CHKERR domainPostProcFe->writeFile(
"out_plastic_" + boost::lexical_cast<std::string>(ts_step) +
".h5m");
}
if (skinPostProcFe) {
CHKERR DMoFEMLoopFiniteElements(dM, "bFE", skinPostProcFe,
getCacheWeakPtr());
CHKERR skinPostProcFe->writeFile(
"out_skin_plastic_" + boost::lexical_cast<std::string>(ts_step) +
".h5m");
}
};
if (!(ts_step % save_every_nth_step)) {
CHKERR make_vtk();
}
if (reactionFE) {
CHKERR VecZeroEntries(fRes);
reactionFE->f = fRes;
CHKERR DMoFEMLoopFiniteElements(dM, "dFE", reactionFE, getCacheWeakPtr());
CHKERR VecAssemblyBegin(fRes);
CHKERR VecAssemblyEnd(fRes);
CHKERR VecGhostUpdateBegin(fRes, ADD_VALUES, SCATTER_REVERSE);
CHKERR VecGhostUpdateEnd(fRes, ADD_VALUES, SCATTER_REVERSE);
MoFEM::Interface *m_field_ptr;
CHKERR DMoFEMGetInterfacePtr(dM, &m_field_ptr);
*m_field_ptr, reactionFE, fRes)();
double nrm;
CHKERR VecNorm(fRes, NORM_2, &nrm);
MOFEM_LOG("PlasticPrb", Sev::verbose)
<< "Residual norm " << nrm << " at time step " << ts_step;
}
auto get_min_max_displacement = [&]() {
MoFEM::Interface *m_field_ptr;
CHKERR DMoFEMGetInterfacePtr(dM, &m_field_ptr);
std::array<double, 4> a_min = {DBL_MAX, DBL_MAX, DBL_MAX, 0};
std::array<double, 4> a_max = {-DBL_MAX, -DBL_MAX, -DBL_MAX, 0};
auto get_min_max = [&](boost::shared_ptr<FieldEntity> field_entity_ptr) {
int d = 0;
for (auto v : field_entity_ptr->getEntFieldData()) {
a_min[d] = std::min(a_min[d], v);
a_max[d] = std::max(a_max[d], v);
++d;
}
};
a_min[SPACE_DIM] = 0;
a_max[SPACE_DIM] = 0;
Range verts;
CHKERR m_field_ptr->get_field_entities_by_type("U", MBVERTEX, verts);
CHKERR m_field_ptr->getInterface<FieldBlas>()->fieldLambdaOnEntities(
get_min_max, "U", &verts);
auto mpi_reduce = [&](auto &a, auto op) {
std::array<double, 3> a_mpi = {0, 0, 0};
MPI_Allreduce(a.data(), a_mpi.data(), 3, MPI_DOUBLE, op,
m_field_ptr->get_comm());
return a_mpi;
};
auto a_min_mpi = mpi_reduce(a_min, MPI_MIN);
auto a_max_mpi = mpi_reduce(a_max, MPI_MAX);
MOFEM_LOG("PlasticPrb", Sev::inform)
<< "Min displacement " << a_min_mpi[0] << " " << a_min_mpi[1] << " "
<< a_min_mpi[2];
MOFEM_LOG("PlasticPrb", Sev::inform)
<< "Max displacement " << a_max_mpi[0] << " " << a_max_mpi[1] << " "
<< a_max_mpi[2];
};
CHKERR get_min_max_displacement();
double scale = 1;
for (auto s : vecOfTimeScalingMethods) {
scale *= s->getScale(this->ts_t);
}
MOFEM_LOG("PlasticPrb", Sev::inform)
<< "Time: " << this->ts_t << " scale: " << scale;
}
private:
boost::shared_ptr<PostProcEleDomain> domainPostProcFe;
boost::shared_ptr<PostProcEleBdy> skinPostProcFe;
boost::shared_ptr<FEMethod> reactionFE;
VecOfTimeScalingMethods vecOfTimeScalingMethods;
};
static boost::shared_ptr<TSUpdate> ts_update_ptr = nullptr;
//! [Solve]
auto *simple = mField.getInterface<Simple>();
auto *pipeline_mng = mField.getInterface<PipelineManager>();
auto dm = simple->getDM();
auto time_scale = boost::make_shared<TimeScale>();
// Setup postprocessing
auto create_post_proc_fe = [dm, this, simple]() {
//! [DG projection]
// Post-process domain, i.e. volume elements. If 3d case creates stresses
// are evaluated at points which are trace of the volume element on boundary
auto post_proc_ele_domain = [this](auto &pip_domain, auto &fe_name) {
// Push bases on reference element to the phyiscal element
// calculate displacement gradients at nodes of post processing mesh. For
// gradient DG projection is obsolete, since displacements can be
// evaluated at arbitrary points.
auto grad_ptr = boost::make_shared<MatrixDouble>();
pip_domain.push_back(
grad_ptr));
// Create operator to run (neted) pipeline in operator. InteriorElem
// element will have iteration rule and bases as domain element used to
// solve problem, and remember history variables.
using InteriorElem = DomainEle;
auto op_this = new OpLoopThis<InteriorElem>(mField, fe_name, Sev::noisy);
// add interior element to post-processing pipeline
pip_domain.push_back(op_this);
// get pointer to interior element, which is in essence pipeline which
// pipeline.
auto fe_physics = op_this->getThisFEPtr();
auto evaluate_stress_on_physical_element = [&]() {
// evaluate stress and plastic strain at Gauss points
fe_physics->getRuleHook = cpPtr->integrationRule;
fe_physics->getOpPtrVector(), {H1});
auto common_data_ptr =
boost::make_shared<ADOLCPlasticity::CommonData>();
// note that gradient of displacements is evaluate again, at
// physical nodes
fe_physics->getOpPtrVector().push_back(
"U", common_data_ptr->getGardAtGaussPtsPtr()));
CHKERR cpPtr->addMatBlockOps(mField, fe_physics->getOpPtrVector(),
"ADOLCMAT", Sev::noisy);
fe_physics->getOpPtrVector().push_back(
getRawPtrOpCalculateStress<SPACE_DIM>(mField, common_data_ptr,
cpPtr, false));
return common_data_ptr;
};
auto dg_projection_froward_and_back = [&](auto &common_data_ptr) {
// here we do actual projection of stress and plastic strain to DG space
int dg_order = approxOrder - 1;
auto entity_data_l2 =
boost::make_shared<EntitiesFieldData>(MBENTITYSET);
auto mass_ptr =
boost::make_shared<MatrixDouble>(); //< projection operator (mass
// matrix)
fe_physics->getOpPtrVector().push_back(new OpDGProjectionMassMatrix(
dg_order, mass_ptr, entity_data_l2, approxBase, L2));
auto coeffs_ptr_stress = boost::make_shared<MatrixDouble>();
// project stress on DG space on physical element
fe_physics->getOpPtrVector().push_back(new OpDGProjectionCoefficients(
common_data_ptr->getStressMatrixPtr(), coeffs_ptr_stress, mass_ptr,
entity_data_l2, approxBase, L2));
// project strains plastic strains DG space on physical element
auto coeffs_ptr_plastic_strain = boost::make_shared<MatrixDouble>();
fe_physics->getOpPtrVector().push_back(new OpDGProjectionCoefficients(
common_data_ptr->getPlasticStrainMatrixPtr(),
coeffs_ptr_plastic_strain, mass_ptr, entity_data_l2, approxBase,
L2));
// project stress and plastic strain for DG space on post-process
// element
pip_domain.push_back(new OpDGProjectionEvaluation(
common_data_ptr->getStressMatrixPtr(), coeffs_ptr_stress,
entity_data_l2, approxBase, L2));
pip_domain.push_back(new OpDGProjectionEvaluation(
common_data_ptr->getPlasticStrainMatrixPtr(),
coeffs_ptr_plastic_strain, entity_data_l2, approxBase, L2));
};
auto common_data_ptr = evaluate_stress_on_physical_element();
dg_projection_froward_and_back(common_data_ptr);
return boost::make_tuple(grad_ptr, common_data_ptr->getStressMatrixPtr(),
common_data_ptr->getPlasticStrainMatrixPtr());
};
//! [DG projection]
// Create tags on post-processing mesh, i.e. those tags are visible in
// Preview
auto add_post_proc_map = [&](auto post_proc_fe, auto u_ptr, auto grad_ptr,
auto stress_ptr, auto plastic_strain_ptr) {
post_proc_fe->getOpPtrVector().push_back(
new OpPPMapSPACE_DIM(
post_proc_fe->getPostProcMesh(), post_proc_fe->getMapGaussPts(),
{},
{{"U", u_ptr}},
{{"GRAD", grad_ptr}},
{}
)
);
using OpPPMap3D = OpPostProcMapInMoab<3, 3>;
post_proc_fe->getOpPtrVector().push_back(
new OpPPMap3D(
post_proc_fe->getPostProcMesh(), post_proc_fe->getMapGaussPts(),
{},
{},
{},
{{"STRESS", stress_ptr}, {"PLASTIC_STRAIN", plastic_strain_ptr}}
)
);
return post_proc_fe;
};
auto vol_post_proc = [this, simple, post_proc_ele_domain,
add_post_proc_map]() {
PetscBool post_proc_vol = PETSC_FALSE;
if (SPACE_DIM == 2)
post_proc_vol = PETSC_TRUE;
CHKERR PetscOptionsGetBool(PETSC_NULL, "", "-post_proc_vol",
&post_proc_vol, PETSC_NULL);
if (post_proc_vol == PETSC_FALSE)
return boost::shared_ptr<PostProcEleDomain>();
auto post_proc_fe = boost::make_shared<PostProcEleDomain>(mField);
auto u_ptr = boost::make_shared<MatrixDouble>();
post_proc_fe->getOpPtrVector().push_back(
auto [grad_ptr, stress_ptr, plastic_strain_ptr] = post_proc_ele_domain(
post_proc_fe->getOpPtrVector(), simple->getDomainFEName());
return add_post_proc_map(post_proc_fe, u_ptr, grad_ptr, stress_ptr,
plastic_strain_ptr);
};
auto skin_post_proc = [this, simple, post_proc_ele_domain,
add_post_proc_map]() {
// create skin of the volume mesh for post-processing,
// i.e. boundary of the volume mesh
PetscBool post_proc_skin = PETSC_TRUE;
if (SPACE_DIM == 2)
post_proc_skin = PETSC_FALSE;
CHKERR PetscOptionsGetBool(PETSC_NULL, "", "-post_proc_skin",
&post_proc_skin, PETSC_NULL);
if (post_proc_skin == PETSC_FALSE)
return boost::shared_ptr<PostProcEleBdy>();
auto post_proc_fe = boost::make_shared<PostProcEleBdy>(mField);
auto u_ptr = boost::make_shared<MatrixDouble>();
post_proc_fe->getOpPtrVector().push_back(
auto op_loop_side =
new OpLoopSide<SideEle>(mField, simple->getDomainFEName(), SPACE_DIM);
auto [grad_ptr, stress_ptr, plastic_strain_ptr] = post_proc_ele_domain(
op_loop_side->getOpPtrVector(), simple->getDomainFEName());
post_proc_fe->getOpPtrVector().push_back(op_loop_side);
return add_post_proc_map(post_proc_fe, u_ptr, grad_ptr, stress_ptr,
plastic_strain_ptr);
};
return std::make_pair(vol_post_proc(), skin_post_proc());
};
auto create_reaction_fe = [&]() {
auto fe_ptr = boost::make_shared<DomainEle>(mField);
fe_ptr->getRuleHook = cpPtr->integrationRule;
auto &pip = fe_ptr->getOpPtrVector();
auto common_data_ptr = boost::make_shared<ADOLCPlasticity::CommonData>();
"U", common_data_ptr->getGardAtGaussPtsPtr()));
CHKERR opFactoryDomainRhs<SPACE_DIM, PETSC, GAUSS, DomainEleOp>(
mField, "U", pip, "ADOLCMAT", common_data_ptr, cpPtr, Sev::noisy);
return fe_ptr;
};
auto add_extra_finite_elements_to_ksp_solver_pipelines = [&]() {
auto pre_proc_ptr = boost::make_shared<FEMethod>();
auto post_proc_rhs_ptr = boost::make_shared<FEMethod>();
auto post_proc_lhs_ptr = boost::make_shared<FEMethod>();
auto get_bc_hook_rhs = [this, pre_proc_ptr, time_scale]() {
{time_scale}, false)();
};
pre_proc_ptr->preProcessHook = get_bc_hook_rhs;
auto get_post_proc_hook_rhs = [this, post_proc_rhs_ptr]() {
mField, post_proc_rhs_ptr, nullptr, Sev::verbose)();
mField, post_proc_rhs_ptr, 1.)();
};
auto get_post_proc_hook_lhs = [this, post_proc_lhs_ptr]() {
mField, post_proc_lhs_ptr, 1.)();
};
post_proc_rhs_ptr->postProcessHook = get_post_proc_hook_rhs;
post_proc_lhs_ptr->postProcessHook = get_post_proc_hook_lhs;
// This is low level pushing finite elements (pipelines) to solver
auto ts_ctx_ptr = getDMTsCtx(simple->getDM());
ts_ctx_ptr->getPreProcessIFunction().push_front(pre_proc_ptr);
ts_ctx_ptr->getPreProcessIJacobian().push_front(pre_proc_ptr);
ts_ctx_ptr->getPostProcessIFunction().push_back(post_proc_rhs_ptr);
ts_ctx_ptr->getPostProcessIJacobian().push_back(post_proc_lhs_ptr);
};
// Add extra finite elements to SNES solver pipelines to resolve essential
// boundary conditions
CHKERR add_extra_finite_elements_to_ksp_solver_pipelines();
auto create_monitor_fe = [dm, time_scale](auto &&post_proc_fe,
auto &&reaction_fe) {
return boost::make_shared<Monitor>(
dm, post_proc_fe, reaction_fe,
std::vector<boost::shared_ptr<ScalingMethod>>{time_scale});
};
//! [Set up post-step]
auto set_up_post_step = [&](auto ts) {
// create finite element (pipeline) and populate it with operators to
// update history variables
auto create_update_ptr = [&]() {
auto fe_ptr = boost::make_shared<DomainEle>(mField);
fe_ptr->getRuleHook = cpPtr->integrationRule;
{H1});
auto common_data_ptr = boost::make_shared<ADOLCPlasticity::CommonData>();
fe_ptr->getOpPtrVector().push_back(
"U", common_data_ptr->getGardAtGaussPtsPtr()));
opFactoryDomainUpdate<SPACE_DIM>(mField, fe_ptr->getOpPtrVector(),
"ADOLCMAT", common_data_ptr, cpPtr),
"push update ops");
return fe_ptr;
};
// ts_update_ptr is global static variable
createTSUpdate(simple->getDomainFEName(), create_update_ptr());
//! [TS post-step function]
// This is pure "C" function which we can to the TS solver
auto ts_step_post_proc = [](TS ts) {
CHKERR ts_update_ptr->postProcess(ts);
};
//! [TS post-step function]
// finally set up post-step
CHKERR TSSetPostStep(ts, ts_step_post_proc);
};
//! [Set up post-step]
// Set monitor which postprocessing results and saves them to the hard drive
auto set_up_monitor = [&](auto ts) {
boost::shared_ptr<FEMethod> null_fe;
auto monitor_ptr =
create_monitor_fe(create_post_proc_fe(), create_reaction_fe());
CHKERR DMMoFEMTSSetMonitor(dm, ts, simple->getDomainFEName(), null_fe,
null_fe, monitor_ptr);
};
auto set_up_adapt = [&](auto ts) {
TSAdapt adapt;
CHKERR TSGetAdapt(ts, &adapt);
};
//! [Create TS]
auto ts = pipeline_mng->createTSIM();
// Set time solver
double ftime = 1;
CHKERR TSSetMaxTime(ts, ftime);
CHKERR TSSetExactFinalTime(ts, TS_EXACTFINALTIME_MATCHSTEP);
auto D = createDMVector(simple->getDM());
CHKERR TSSetSolution(ts, D);
// Set monitor, step adaptivity, and post-step to update history variables
CHKERR set_up_monitor(ts);
CHKERR set_up_post_step(ts);
CHKERR set_up_adapt(ts);
CHKERR TSSetFromOptions(ts);
CHKERR TSSolve(ts, NULL);
//! [Create TS]
CHKERR TSGetTime(ts, &ftime);
PetscInt steps, snesfails, rejects, nonlinits, linits;
CHKERR TSGetStepNumber(ts, &steps);
CHKERR TSGetSNESFailures(ts, &snesfails);
CHKERR TSGetStepRejections(ts, &rejects);
CHKERR TSGetSNESIterations(ts, &nonlinits);
CHKERR TSGetKSPIterations(ts, &linits);
MOFEM_LOG_C("PlasticPrb", Sev::inform,
"steps %d (%d rejected, %d SNES fails), ftime %g, nonlinits "
"%d, linits %d",
steps, rejects, snesfails, ftime, nonlinits, linits);
}
//! [Solve]
//! [Getting norms]
auto dm = simple->getDM();
auto T = createDMVector(simple->getDM());
CHKERR DMoFEMMeshToLocalVector(simple->getDM(), T, INSERT_VALUES,
SCATTER_FORWARD);
double nrm2;
CHKERR VecNorm(T, NORM_2, &nrm2);
MOFEM_LOG("PlasticPrb", Sev::inform) << "Solution norm " << nrm2;
auto post_proc_norm_fe = boost::make_shared<DomainEle>(mField);
post_proc_norm_fe->getRuleHook = cpPtr->integrationRule;
post_proc_norm_fe->getOpPtrVector(), {H1});
enum NORMS { U_NORM_L2 = 0, PIOLA_NORM, LAST_NORM };
auto norms_vec =
(mField.get_comm_rank() == 0) ? LAST_NORM : 0, LAST_NORM);
CHKERR VecZeroEntries(norms_vec);
auto u_ptr = boost::make_shared<MatrixDouble>();
post_proc_norm_fe->getOpPtrVector().push_back(
post_proc_norm_fe->getOpPtrVector().push_back(
new OpCalcNormL2Tensor1<SPACE_DIM>(u_ptr, norms_vec, U_NORM_L2));
CHKERR DMoFEMLoopFiniteElements(dm, simple->getDomainFEName(),
post_proc_norm_fe);
CHKERR VecAssemblyBegin(norms_vec);
CHKERR VecAssemblyEnd(norms_vec);
MOFEM_LOG_CHANNEL("SELF"); // Clear channel from old tags
if (mField.get_comm_rank() == 0) {
const double *norms;
CHKERR VecGetArrayRead(norms_vec, &norms);
MOFEM_TAG_AND_LOG("SELF", Sev::inform, "example")
<< "norm_u: " << std::scientific << std::sqrt(norms[U_NORM_L2]);
CHKERR VecRestoreArrayRead(norms_vec, &norms);
}
}
//! [Getting norms]
//! [Postprocessing results]
PetscInt test_nb = 0;
PetscBool test_flg = PETSC_FALSE;
CHKERR PetscOptionsGetInt(PETSC_NULL, "", "-test", &test_nb, &test_flg);
if (test_flg) {
auto T = createDMVector(simple->getDM());
CHKERR DMoFEMMeshToLocalVector(simple->getDM(), T, INSERT_VALUES,
SCATTER_FORWARD);
double nrm2;
CHKERR VecNorm(T, NORM_2, &nrm2);
MOFEM_LOG("PlasticPrb", Sev::verbose) << "Regression norm " << nrm2;
double regression_value = 0;
switch (test_nb) {
default:
SETERRQ(PETSC_COMM_WORLD, MOFEM_ATOM_TEST_INVALID, "Wrong test number.");
break;
}
if (fabs(nrm2 - regression_value) > 1e-2)
SETERRQ2(PETSC_COMM_WORLD, MOFEM_ATOM_TEST_INVALID,
"Regression test field; wrong norm value. %6.4e != %6.4e", nrm2,
regression_value);
}
}
//! [Postprocessing results]
//! [Check]
}
//! [Check]
static char help[] = "...\n\n";
int main(int argc, char *argv[]) {
// Initialisation of MoFEM/PETSc and MOAB data structures
const char param_file[] = "param_file.petsc";
MoFEM::Core::Initialize(&argc, &argv, param_file, help);
// Add logging channel for example
auto core_log = logging::core::get();
core_log->add_sink(
LogManager::createSink(LogManager::getStrmWorld(), "PlasticPrb"));
LogManager::setLog("PlasticPrb");
MOFEM_LOG_TAG("PlasticPrb", "PlasticPrb");
MOFEM_LOG("PlasticPrb", Sev::inform) << "SPACE_DIM " << SPACE_DIM;
try {
//! [Register MoFEM discrete manager in PETSc]
DMType dm_name = "DMMOFEM";
//! [Register MoFEM discrete manager in PETSc
//! [Create MoAB]
moab::Core mb_instance; ///< mesh database
moab::Interface &moab = mb_instance; ///< mesh database interface
//! [Create MoAB]
//! [Create MoFEM]
MoFEM::Core core(moab); ///< finite element database
MoFEM::Interface &m_field = core; ///< finite element database interface
//! [Create MoFEM]
//! [PlasticProblem]
PlasticProblem ex(m_field);
CHKERR ex.runProblem();
//! [PlasticProblem]
}
}
PostProcEleDomain
PostProcEleByDim< SPACE_DIM >::PostProcEleDomain PostProcEleDomain
Definition: adolc_plasticity.cpp:97
MoFEM::NaturalBC::Assembly::LinearForm
Definition: Natural.hpp:67
MoFEMFunctionReturnHot
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:447
MoFEM::UnknownInterface::getInterface
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface refernce to pointer of interface.
Definition: UnknownInterface.hpp:93
MoFEM::EntitiesFieldData::EntData
Data on single entity (This is passed as argument to DataOperator::doWork)
Definition: EntitiesFieldData.hpp:127
EXECUTABLE_DIMENSION
#define EXECUTABLE_DIMENSION
Definition: plastic.cpp:13
SPACE_DIM
constexpr int SPACE_DIM
Definition: adolc_plasticity.cpp:15
BoundaryEle
ElementsAndOps< SPACE_DIM >::BoundaryEle BoundaryEle
Definition: child_and_parent.cpp:39
PlasticProblem::solveSystem
MoFEMErrorCode solveSystem()
[Solve]
Definition: adolc_plasticity.cpp:463
MoFEM::EssentialPreProcReaction< DisplacementCubitBcData >
Specialization for DisplacementCubitBcData.
Definition: EssentialDisplacementCubitBcData.hpp:151
MoFEM::CoreTmp< 0 >
Core (interface) class.
Definition: Core.hpp:82
H1
@ H1
continuous field
Definition: definitions.h:85
sdf_hertz.d
float d
Definition: sdf_hertz.py:5
LASTBASE
@ LASTBASE
Definition: definitions.h:69
MoFEM::OpLoopThis
Execute "this" element in the operator.
Definition: DGProjection.hpp:68
MOFEM_LOG_CHANNEL
#define MOFEM_LOG_CHANNEL(channel)
Set and reset channel.
Definition: LogManager.hpp:284
ADOLCPlasticity::createTSUpdate
boost::shared_ptr< TSUpdate > createTSUpdate(std::string fe_name, boost::shared_ptr< FEMethod > fe_ptr)
MoFEM::FEMethod
structure for User Loop Methods on finite elements
Definition: LoopMethods.hpp:369
MoFEM::OpFluxRhsImpl
Definition: Natural.hpp:39
MoFEM::PipelineManager::ElementsAndOpsByDim
Definition: PipelineManager.hpp:38
MoFEM::EssentialPostProcLhs< DisplacementCubitBcData >
Specialization for DisplacementCubitBcData.
Definition: EssentialDisplacementCubitBcData.hpp:130
MoFEM::CoreInterface::get_comm
virtual MPI_Comm & get_comm() const =0
MoFEM::NaturalBC::Assembly::BiLinearForm
Definition: Natural.hpp:74
CHK_THROW_MESSAGE
#define CHK_THROW_MESSAGE(err, msg)
Check and throw MoFEM exception.
Definition: definitions.h:596
L2
@ L2
field with C-1 continuity
Definition: definitions.h:88
MoFEM::Exceptions::MoFEMErrorCode
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:56
MoFEM::OpCalculateVectorFieldValues
Get values at integration pts for tensor filed rank 1, i.e. vector field.
Definition: UserDataOperators.hpp:466
MoFEM::CoreInterface::get_comm_rank
virtual int get_comm_rank() const =0
ts_update_ptr
static boost::shared_ptr< TSUpdate > ts_update_ptr
Definition: adolc_plasticity.cpp:460
MoFEM::EssentialPostProcRhs< DisplacementCubitBcData >
Specialization for DisplacementCubitBcData.
Definition: EssentialDisplacementCubitBcData.hpp:111
MoFEM::PETSC
@ PETSC
Definition: FormsIntegrators.hpp:104
MoFEM::PipelineManager
PipelineManager interface.
Definition: PipelineManager.hpp:24
MoFEM.hpp
MoFEM::OpDGProjectionCoefficients
Definition: DGProjection.hpp:119
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:527
MoFEM::DisplacementCubitBcData
Definition of the displacement bc data structure.
Definition: BCData.hpp:76
MoFEM::CoreTmp< 0 >::Finalize
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition: Core.cpp:112
help
static char help[]
[Check]
Definition: adolc_plasticity.cpp:912
SideEle
PostProcEleByDim< SPACE_DIM >::SideEle SideEle
Definition: adolc_plasticity.cpp:98
MoFEM::Simple
Simple interface for fast problem set-up.
Definition: Simple.hpp:27
MoFEM::DeprecatedCoreInterface
Deprecated interface functions.
Definition: DeprecatedCoreInterface.hpp:16
MoFEM::OpFluxLhsImpl
Definition: Natural.hpp:43
MoFEM::Interface
DeprecatedCoreInterface Interface
Definition: Interface.hpp:1975
PostProcEleBdy
PostProcEleByDim< SPACE_DIM >::PostProcEleBdy PostProcEleBdy
Definition: adolc_plasticity.cpp:99
PlasticProblem
Definition: adolc_plasticity.cpp:105
PlasticProblem::outputResults
MoFEMErrorCode outputResults()
[Getting norms]
Definition: adolc_plasticity.cpp:876
PostProcEleByDim
Definition: adolc_plasticity.cpp:82
PlasticProblem::gettingNorms
MoFEMErrorCode gettingNorms()
[Solve]
Definition: adolc_plasticity.cpp:823
save_every_nth_step
int save_every_nth_step
Definition: photon_diffusion.cpp:67
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:535
ContactOps::scale
double scale
Definition: EshelbianContact.hpp:22
MoFEM::createDMVector
auto createDMVector(DM dm)
Get smart vector from DM.
Definition: DMMoFEM.hpp:1018
MoFEM::EssentialPreProc< DisplacementCubitBcData >
Specialization for DisplacementCubitBcData.
Definition: EssentialDisplacementCubitBcData.hpp:91
MoFEM
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:10
a
constexpr double a
Definition: approx_sphere.cpp:30
MoFEM::BcManager
Simple interface for fast problem set-up.
Definition: BcManager.hpp:25
MoFEM::FaceElementForcesAndSourcesCore::UserDataOperator
default operator for TRI element
Definition: FaceElementForcesAndSourcesCore.hpp:94
MOFEM_LOG_C
#define MOFEM_LOG_C(channel, severity, format,...)
Definition: LogManager.hpp:311
PlasticProblem::setupProblem
MoFEMErrorCode setupProblem()
[Read mesh]
Definition: adolc_plasticity.cpp:160
simple
void simple(double P1[], double P2[], double P3[], double c[], const int N)
Definition: acoustic.cpp:69
MoFEM::DMRegister_MoFEM
PetscErrorCode DMRegister_MoFEM(const char sname[])
Register MoFEM problem.
Definition: DMMoFEM.cpp:47
MatrixFunction.hpp
MoFEM::AddFluxToLhsPipelineImpl
Definition: Natural.hpp:49
MoFEM::OpCalcNormL2Tensor1
Get norm of input MatrixDouble for Tensor1.
Definition: NormsOperators.hpp:42
TSADAPTMOFEM
#define TSADAPTMOFEM
Definition: TsCtx.hpp:10
MOFEM_LOG_TAG
#define MOFEM_LOG_TAG(channel, tag)
Tag channel.
Definition: LogManager.hpp:339
MoFEM::AddFluxToRhsPipelineImpl
Definition: Natural.hpp:46
ADOLCPlasticity
Definition: ADOLCPlasticity.hpp:24
PlasticProblem::readMesh
MoFEMErrorCode readMesh()
[Run problem]
Definition: adolc_plasticity.cpp:145
BiLinearForm
MoFEM::PostProcBrokenMeshInMoabBase
Definition: PostProcBrokenMeshInMoabBase.hpp:94
PlasticProblem::boundaryCondition
MoFEMErrorCode boundaryCondition()
[Set up problem]
Definition: adolc_plasticity.cpp:241
PlasticProblem::assembleSystem
MoFEMErrorCode assembleSystem()
[Boundary condition]
Definition: adolc_plasticity.cpp:281
MoFEM::AddHOOps
Add operators pushing bases from local to physical configuration.
Definition: HODataOperators.hpp:503
MoFEM::OpCalculateVectorFieldGradient
Get field gradients at integration pts for scalar filed rank 0, i.e. vector field.
Definition: UserDataOperators.hpp:1536
PlasticProblem::checkResults
MoFEMErrorCode checkResults()
[Postprocessing results]
Definition: adolc_plasticity.cpp:906
v
const double v
phase velocity of light in medium (cm/ns)
Definition: initial_diffusion.cpp:40
DomainEle
PipelineManager::ElementsAndOpsByDim< SPACE_DIM >::DomainEle DomainEle
Definition: adolc_plasticity.cpp:23
Range
DomainEleOp
MoFEM::CoreTmp< 0 >::Initialize
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
Definition: Core.cpp:72
EntData
EntitiesFieldData::EntData EntData
Definition: adolc_plasticity.cpp:18
MOFEM_TAG_AND_LOG
#define MOFEM_TAG_AND_LOG(channel, severity, tag)
Tag and log in channel.
Definition: LogManager.hpp:362
main
int main(int argc, char *argv[])
Definition: adolc_plasticity.cpp:914
MOFEM_LOG
#define MOFEM_LOG(channel, severity)
Log.
Definition: LogManager.hpp:308
MoFEM::NaturalBC::Assembly
Assembly methods.
Definition: Natural.hpp:65
CATCH_ERRORS
#define CATCH_ERRORS
Catch errors.
Definition: definitions.h:372
DEMKOWICZ_JACOBI_BASE
@ DEMKOWICZ_JACOBI_BASE
Definition: definitions.h:66
MoFEM::OpDGProjectionEvaluation
Definition: DGProjection.hpp:136
MoFEM::Core
CoreTmp< 0 > Core
Definition: Core.hpp:1094
MoFEM::DMoFEMGetInterfacePtr
PetscErrorCode DMoFEMGetInterfacePtr(DM dm, MoFEM::Interface **m_field_ptr)
Get pointer to MoFEM::Interface.
Definition: DMMoFEM.cpp:418
ADOLCPlasticityMaterialModels.hpp
Matetial models for plasticity.
UserDataOperator
ForcesAndSourcesCore::UserDataOperator UserDataOperator
Definition: HookeElement.hpp:75
ADOLCPlasticity.hpp
Monitor
[Push operators to pipeline]
Definition: adolc_plasticity.cpp:333
MoFEM::VecOfTimeScalingMethods
std::vector< boost::shared_ptr< ScalingMethod > > VecOfTimeScalingMethods
Vector of time scaling methods.
Definition: Natural.hpp:20
MoFEM::DMMoFEMTSSetMonitor
PetscErrorCode DMMoFEMTSSetMonitor(DM dm, TS ts, const std::string fe_name, boost::shared_ptr< MoFEM::FEMethod > method, boost::shared_ptr< MoFEM::BasicMethod > pre_only, boost::shared_ptr< MoFEM::BasicMethod > post_only)
Set Monitor To TS solver.
Definition: DMMoFEM.cpp:1060
AINSWORTH_LEGENDRE_BASE
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
Definition: definitions.h:60
MOFEM_DATA_INCONSISTENCY
@ MOFEM_DATA_INCONSISTENCY
Definition: definitions.h:31
MoFEM::PetscOptionsGetEList
PetscErrorCode PetscOptionsGetEList(PetscOptions *, const char pre[], const char name[], const char *const *list, PetscInt next, PetscInt *value, PetscBool *set)
Definition: DeprecatedPetsc.hpp:203
MoFEM::createVectorMPI
auto createVectorMPI(MPI_Comm comm, PetscInt n, PetscInt N)
Create MPI Vector.
Definition: PetscSmartObj.hpp:198
FieldApproximationBase
FieldApproximationBase
approximation base
Definition: definitions.h:58
PlasticProblem::cpPtr
boost::shared_ptr< ClosestPointProjection > cpPtr
Definition: adolc_plasticity.cpp:125
ReactionDiffusionEquation::D
const double D
diffusivity
Definition: reaction_diffusion.cpp:20
ContactNaturalBC.hpp
MOFEM_ATOM_TEST_INVALID
@ MOFEM_ATOM_TEST_INVALID
Definition: definitions.h:40
MoFEMFunctionBeginHot
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:440
DomainEle
ElementsAndOps< SPACE_DIM >::DomainEle DomainEle
Definition: child_and_parent.cpp:34
MoFEM::SmartPetscObj< DM >
PlasticProblem::runProblem
MoFEMErrorCode runProblem()
[Run problem]
Definition: adolc_plasticity.cpp:130
MoFEM::CoreInterface::get_field_entities_by_type
virtual MoFEMErrorCode get_field_entities_by_type(const std::string name, EntityType type, Range &ents) const =0
get entities in the field by type
MoFEM::DMoFEMLoopFiniteElements
PetscErrorCode DMoFEMLoopFiniteElements(DM dm, const char fe_name[], MoFEM::FEMethod *method, CacheTupleWeakPtr cache_ptr=CacheTupleSharedPtr())
Executes FEMethod for finite elements in DM.
Definition: DMMoFEM.cpp:590
convert.int
int
Definition: convert.py:64
MoFEM::PetscOptionsGetInt
PetscErrorCode PetscOptionsGetInt(PetscOptions *, const char pre[], const char name[], PetscInt *ivalue, PetscBool *set)
Definition: DeprecatedPetsc.hpp:142
MoFEMFunctionReturn
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:416
MoFEM::FieldBlas
Basic algebra on fields.
Definition: FieldBlas.hpp:21
MoFEM::getDMTsCtx
auto getDMTsCtx(DM dm)
Get TS context data structure used by DM.
Definition: DMMoFEM.hpp:1060
MoFEM::OpLoopSide
Element used to execute operators on side of the element.
Definition: ForcesAndSourcesCore.hpp:1289
MoFEMFunctionBegin
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:346
PlasticProblem::mField
MoFEM::Interface & mField
Definition: adolc_plasticity.cpp:112
MoFEM::PetscOptionsGetBool
PetscErrorCode PetscOptionsGetBool(PetscOptions *, const char pre[], const char name[], PetscBool *bval, PetscBool *set)
Definition: DeprecatedPetsc.hpp:182
MoFEM::OpPostProcMapInMoab
Post post-proc data at points from hash maps.
Definition: PostProcBrokenMeshInMoabBase.hpp:698
MoFEM::TSAdaptCreateMoFEM
PetscErrorCode TSAdaptCreateMoFEM(TSAdapt adapt)
Craete MOFEM adapt.
Definition: TsCtx.cpp:797
MoFEM::OpDGProjectionMassMatrix
Definition: DGProjection.hpp:106