v0.13.0
PlasticOpsMonitor.hpp
/* This file is part of MoFEM.
* MoFEM is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* MoFEM is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with MoFEM. If not, see <http://www.gnu.org/licenses/>. */
/** \file PlasticOpsMonitor.hpp
* \example PlasticOpsMonitor.hpp
*/
namespace PlasticOps {
const std::string field_name, moab::Interface &post_proc_mesh,
std::vector<EntityHandle> &map_gauss_pts,
boost::shared_ptr<CommonData> common_data_ptr)
: DomainEleOp(field_name, DomainEleOp::OPROW), postProcMesh(post_proc_mesh),
mapGaussPts(map_gauss_pts), commonDataPtr(common_data_ptr) {
// Opetor is only executed for vertices
std::fill(&doEntities[MBEDGE], &doEntities[MBMAXTYPE], false);
}
//! [Postprocessing]
EntData &data) {
std::array<double, 9> def;
std::fill(def.begin(), def.end(), 0);
auto get_tag = [&](const std::string name, size_t size) {
Tag th;
CHKERR postProcMesh.tag_get_handle(name.c_str(), size, MB_TYPE_DOUBLE, th,
MB_TAG_CREAT | MB_TAG_SPARSE,
def.data());
return th;
};
MatrixDouble3by3 mat(3, 3);
auto set_matrix_3d = [&](auto &t) -> MatrixDouble3by3 & {
mat.clear();
for (size_t r = 0; r != SPACE_DIM; ++r)
for (size_t c = 0; c != SPACE_DIM; ++c)
mat(r, c) = t(r, c);
return mat;
};
auto set_scalar = [&](auto t) -> MatrixDouble3by3 & {
mat.clear();
mat(0, 0) = t;
return mat;
};
auto set_float_precision = [](const double x) {
if (std::abs(x) < std::numeric_limits<float>::epsilon())
return 0.;
else
return x;
};
auto set_tag = [&](auto th, auto gg, MatrixDouble3by3 &mat) {
for (auto &v : mat.data())
v = set_float_precision(v);
return postProcMesh.tag_set_data(th, &mapGaussPts[gg], 1,
&*mat.data().begin());
};
auto th_plastic_surface = get_tag("PLASTIC_SURFACE", 1);
auto th_hardening = get_tag("HARDENING", 1);
auto th_tau = get_tag("PLASTIC_MULTIPLIER", 1);
auto th_temperature = get_tag("TEMPERATURE", 1);
auto th_plastic_flow = get_tag("PLASTIC_FLOW", 9);
auto th_plastic_strain = get_tag("PLASTIC_STRAIN", 9);
auto t_flow =
getFTensor2SymmetricFromMat<SPACE_DIM>(commonDataPtr->plasticFlow);
auto t_plastic_strain =
getFTensor2SymmetricFromMat<SPACE_DIM>(commonDataPtr->plasticStrain);
if (commonDataPtr->tempVal.size() != commonDataPtr->plasticSurface.size()) {
commonDataPtr->tempVal.resize(commonDataPtr->plasticSurface.size(), 0);
commonDataPtr->tempVal.clear();
}
size_t gg = 0;
for (int gg = 0; gg != commonDataPtr->plasticSurface.size(); ++gg) {
const double temp = (commonDataPtr->tempVal)[gg];
const double tau = (commonDataPtr->plasticTau)[gg];
const double f = (commonDataPtr->plasticSurface)[gg];
const double h = hardening(tau, temp);
CHKERR set_tag(th_plastic_surface, gg, set_scalar(f));
CHKERR set_tag(th_hardening, gg, set_scalar(h));
CHKERR set_tag(th_tau, gg, set_scalar(tau));
CHKERR set_tag(th_temperature, gg, set_scalar(temp));
CHKERR set_tag(th_plastic_flow, gg, set_matrix_3d(t_flow));
CHKERR set_tag(th_plastic_strain, gg, set_matrix_3d(t_plastic_strain));
++t_flow;
++t_plastic_strain;
}
}
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; }
auto make_vtk = [&]() {
CHKERR postProcFe->writeFile(
"out_plastic_" + boost::lexical_cast<std::string>(ts_step) + ".h5m");
};
auto calculate_reaction = [&]() {
reactionFe->f = r;
CHKERR VecZeroEntries(r);
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 (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:314
constexpr int SPACE_DIM
DomainEle::UserDataOperator DomainEleOp
Finire element operator type.
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:359
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:429
#define CHKERR
Inline error check.
Definition: definitions.h:548
void temp(int x, int y=10)
Definition: simple.cpp:4
auto smartCreateDMVector
Get smart vector from DM.
Definition: DMMoFEM.hpp:956
PetscErrorCode DMoFEMLoopFiniteElements(DM dm, const char fe_name[], MoFEM::FEMethod *method, CacheTupleWeakPtr cache_ptr=CacheTupleSharedPtr())
Executes FEMethod for finite elements in DM.
Definition: DMMMoFEM.cpp:544
double v
phase velocity of light in medium (cm/ns)
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:67
MatrixBoundedArray< double, 9 > MatrixDouble3by3
Definition: Types.hpp:116
DeprecatedCoreInterface Interface
Definition: Interface.hpp:1965
auto hardening(long double tau)
const double r
rate factor
double h
convective heat coefficient
constexpr double t
plate stiffness
Definition: plate.cpp:76
Data on single entity (This is passed as argument to DataOperator::doWork)
[Push operators to pipeline]
SmartPetscObj< DM > dM
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)
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
boost::shared_ptr< CommonData > commonDataPtr
Definition: PlasticOps.hpp:289
std::vector< EntityHandle > & mapGaussPts
Definition: PlasticOps.hpp:288
OpPostProcPlastic(const std::string field_name, moab::Interface &post_proc_mesh, std::vector< EntityHandle > &map_gauss_pts, boost::shared_ptr< CommonData > common_data_ptr)
moab::Interface & postProcMesh
Definition: PlasticOps.hpp:287
MoFEMErrorCode doWork(int side, EntityType type, EntData &data)
[Postprocessing]