v0.13.1
Loading...
Searching...
No Matches
PlasticOpsMonitor.hpp
/** \file PlasticOpsMonitor.hpp
* \example PlasticOpsMonitor.hpp
*/
namespace PlasticOps {
struct Monitor : public FEMethod {
Monitor(SmartPetscObj<DM> &dm, boost::shared_ptr<PostProcEle> post_proc_fe,
boost::shared_ptr<DomainEle> reaction_fe,
std::tuple<SmartPetscObj<Vec>, SmartPetscObj<VecScatter>> ux_scatter,
std::tuple<SmartPetscObj<Vec>, SmartPetscObj<VecScatter>> uy_scatter,
std::tuple<SmartPetscObj<Vec>, SmartPetscObj<VecScatter>> uz_scatter)
: dM(dm), postProcFe(post_proc_fe), reactionFe(reaction_fe),
uXScatter(ux_scatter), uYScatter(uy_scatter), uZScatter(uz_scatter){};
MoFEMErrorCode preProcess() { return 0; }
MoFEMErrorCode operator()() { return 0; }
MoFEMErrorCode postProcess() {
auto make_vtk = [&]() {
CHKERR DMoFEMLoopFiniteElements(dM, "dFE", postProcFe, getCacheWeakPtr());
CHKERR postProcFe->writeFile(
"out_plastic_" + boost::lexical_cast<std::string>(ts_step) + ".h5m");
};
auto calculate_reaction = [&]() {
auto r = smartCreateDMVector(dM);
reactionFe->f = r;
CHKERR VecZeroEntries(r);
CHKERR DMoFEMLoopFiniteElements(dM, "dFE", reactionFe);
CHKERR VecGhostUpdateBegin(r, ADD_VALUES, SCATTER_REVERSE);
CHKERR VecGhostUpdateEnd(r, ADD_VALUES, SCATTER_REVERSE);
CHKERR VecAssemblyBegin(r);
CHKERR VecAssemblyEnd(r);
double sum;
CHKERR VecSum(r, &sum);
MOFEM_LOG_C("EXAMPLE", Sev::inform, "reaction time %3.4e %3.4e", ts_t,
sum);
};
auto print_max_min = [&](auto &tuple, const std::string msg) {
CHKERR VecScatterBegin(std::get<1>(tuple), ts_u, std::get<0>(tuple),
INSERT_VALUES, SCATTER_FORWARD);
CHKERR VecScatterEnd(std::get<1>(tuple), ts_u, std::get<0>(tuple),
INSERT_VALUES, SCATTER_FORWARD);
double max, min;
CHKERR VecMax(std::get<0>(tuple), PETSC_NULL, &max);
CHKERR VecMin(std::get<0>(tuple), PETSC_NULL, &min);
MOFEM_LOG_C("EXAMPLE", Sev::inform, "%s time %3.4e min %3.4e max %3.4e",
msg.c_str(), ts_t, min, max);
};
CHKERR make_vtk();
CHKERR calculate_reaction();
CHKERR print_max_min(uXScatter, "Ux");
CHKERR print_max_min(uYScatter, "Uy");
if constexpr (SPACE_DIM == 3)
CHKERR print_max_min(uZScatter, "Uz");
}
private:
SmartPetscObj<DM> dM;
boost::shared_ptr<PostProcEle> postProcFe;
boost::shared_ptr<DomainEle> reactionFe;
std::tuple<SmartPetscObj<Vec>, SmartPetscObj<VecScatter>> uXScatter;
std::tuple<SmartPetscObj<Vec>, SmartPetscObj<VecScatter>> uYScatter;
std::tuple<SmartPetscObj<Vec>, SmartPetscObj<VecScatter>> uZScatter;
};
}; // namespace PlasticOps
#define MOFEM_LOG_C(channel, severity, format,...)
Definition: LogManager.hpp:304
constexpr int SPACE_DIM
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:346
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:416
#define CHKERR
Inline error check.
Definition: definitions.h:535
Monitor solution.
SmartPetscObj< DM > dM
std::tuple< SmartPetscObj< Vec >, SmartPetscObj< VecScatter > > uXScatter
std::tuple< SmartPetscObj< Vec >, SmartPetscObj< VecScatter > > uZScatter
MoFEMErrorCode preProcess()
MoFEMErrorCode postProcess()
boost::shared_ptr< PostProcEle > postProcFe
std::tuple< SmartPetscObj< Vec >, SmartPetscObj< VecScatter > > uYScatter
MoFEMErrorCode operator()()
boost::shared_ptr< DomainEle > reactionFe