v0.16.3
Loading...
Searching...
No Matches
post_processing.cpp
Go to the documentation of this file.
1/** \file post_processing.cpp
2 * \brief Plotting projects accepted UMAT history without evaluating the UMAT.
3 */
4#include <MoFEM.hpp>
5#include <MatrixFunction.hpp>
6using namespace MoFEM;
7
8constexpr int SPACE_DIM = 3;
12using DomainEleOp = DomainEle::UserDataOperator;
13using BoundaryEleOp = BoundaryEle::UserDataOperator;
26#include <Monitor.hpp>
27#include <UmatExample.hpp>
28
29namespace {
30MoFEMErrorCode require(bool condition, const char *message) {
32 if (!condition)
33 SETERRQ(PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID, "%s", message);
35}
36
37struct Example : UmatExample {
39
46 auto &mb = mField.get_moab();
49 CHKERR mb.get_entities_by_dimension(0, 3, cells);
50 CHKERR require(cells.size() == 1, "Expected the one-hex fixture");
51 const auto cell = cells.front();
52
53 auto physical_fe = boost::make_shared<DomainEle>(mField);
54 physical_fe->getRuleHook = updateFe->getRuleHook;
55 auto values = boost::make_shared<MatrixDouble>();
56 physical_fe->getOpPtrVector().push_back(
59 physical_fe);
60 const auto material_points = values->size1();
61 CHKERR require(material_points > 0, "Missing physical integration points");
62
63 // Seed accepted history at the physical quadrature. The deliberately
64 // missing UMAT library must never be loaded by either output pipeline.
65 const auto state_tags = physicalEquationsPtr->matOpsDataPtr->getStateTags();
66 for (const auto &[name, tag, components] : state_tags) {
67 const int size = components * material_points;
68 const std::vector<double> values(size, 1.25);
69 const void *ptr = values.data();
70 CHKERR mb.tag_set_by_ptr(tag, &cell, 1, &ptr, &size);
71 }
72
73 const auto check_output = [&](auto &fe, const std::string &fe_name) {
75 CHKERR require(static_cast<bool>(fe), "Missing output pipeline");
76 // This is the accepted endpoint after a cooling increment.
77 fe->ts_t = 5.0000001;
78 fe->ts_dt = 1e-7;
80 auto &output = fe->getPostProcMesh();
82 CHKERR output.get_entities_by_type(0, MBVERTEX, vertices);
83 CHKERR require(vertices.size() > 1, "Expected several plotting points");
84 for (const auto &[name, tag, components] : postProcStateTags) {
85 Tag output_tag;
86 CHKERR output.tag_get_handle(name.c_str(), output_tag);
87 int output_components;
88 CHKERR output.tag_get_length(output_tag, output_components);
89 std::vector<double> values(vertices.size() * output_components);
90 CHKERR output.tag_get_data(output_tag, vertices, values.data());
91 for (const auto v : values)
92 CHKERR require(std::abs(v - 1.25) < 1e-12,
93 "Output differs from accepted material history");
94 }
95 for (const auto &[name, tag, components] : state_tags) {
96 const void *ptr;
97 int size;
98 CHKERR mb.tag_get_by_ptr(tag, &cell, 1, &ptr, &size);
99 CHKERR require(size == components * material_points,
100 "Plotting added entries to material history");
101 const auto *values = static_cast<const double *>(ptr);
102 for (int i = 0; i != size; ++i)
103 CHKERR require(values[i] == 1.25,
104 "Plotting changed accepted material history");
105 }
107 };
110 MOFEM_LOG("WORLD", Sev::inform) << "UMAT post-processing checks passed";
112 }
113};
114} // namespace
115
116int main(int argc, char **argv) {
117 MoFEM::Core::Initialize(&argc, &argv, nullptr, nullptr);
118 logging::core::get()->add_sink(
120 LogManager::setLog("EXAMPLE");
121 try {
122 CHKERR DMRegister_MoFEM("DMMOFEM");
123 moab::Core mb;
124 MoFEM::Core core(mb);
126 Example example(core);
127 CHKERR example.run();
128 }
131 return 0;
132}
std::vector< int > size
std::vector< int > vertices
std::vector< Cell > cells
moab::Interface & mb
Tag tag
int components
Inferred from the source tag length.
SmartPetscObj< Vec > values
std::string name
int main()
ElementsAndOps< SPACE_DIM >::DomainEle DomainEle
ElementsAndOps< SPACE_DIM >::BoundaryEle BoundaryEle
#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.
PostProcEleByDim< SPACE_DIM >::PostProcEleDomain PostProcEleDomain
PostProcEleByDim< SPACE_DIM >::PostProcEleBdy PostProcEleBdy
PetscErrorCode DMRegister_MoFEM(const char sname[])
Register MoFEM problem.
Definition DMMoFEM.cpp:43
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:662
@ PETSC
Standard PETSc assembly.
static LoggerType & setLog(const std::string channel)
Set ans resset chanel logger.
#define MOFEM_LOG(channel, severity)
Log.
FTensor::Index< 'i', SPACE_DIM > i
const double v
phase velocity of light in medium (cm/ns)
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
implementation of Data Operators for Forces and Sources
Definition Common.hpp:10
ElementsAndOps< SPACE_DIM >::SideEle SideEle
Definition plastic.cpp:62
constexpr int SPACE_DIM
[Example]
Definition plastic.cpp:209
MoFEMErrorCode boundaryCondition()
[Set up problem]
MoFEMErrorCode readMesh()
[Run problem]
Simple * simple
MoFEMErrorCode run()
MoFEM::Interface & mField
Reference to MoFEM interface.
Definition plastic.cpp:219
MoFEMErrorCode setupProblem()
[Run problem]
Definition plastic.cpp:266
virtual moab::Interface & get_moab()=0
Core (interface) class.
Definition Core.hpp:83
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
Data on single entity (This is passed as argument to DataOperator::doWork)
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.
Assembly methods.
Definition Natural.hpp:65
Specialization for MatrixDouble vector field values calculation.
Template struct for dimension-specific finite element types.
Simple interface for fast problem set-up.
Definition Simple.hpp:27
const std::string getBoundaryFEName() const
Get the Boundary FE Name.
Definition Simple.hpp:436
MoFEMErrorCode getDM(DM *dm)
Get DM.
Definition Simple.cpp:802
const std::string getDomainFEName() const
Get the Domain FE Name.
Definition Simple.hpp:429
Force scale operator for reading two columns.
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
MatOps::StateTags postProcStateTags
UmatExample(MoFEM::Interface &m_field)
boost::shared_ptr< PostProcEleBdy > postProcBdyFe
MoFEMErrorCode assembleSystemAdolc()
boost::shared_ptr< MatOps::PhysicalEquations > physicalEquationsPtr
boost::shared_ptr< PostProcEleDomain > postProcDomainFe
boost::shared_ptr< DomainEle > updateFe