v0.16.3
Loading...
Searching...
No Matches
mofem/tutorials/vec-11_elastic_tie_mesh/elastic_tie_mesh.cpp

Elastic mesh tie example with a tie-aware partitioned mesh loader.

Elastic mesh tie example with a tie-aware partitioned mesh loader

/**
* @file elastic_tie_mesh.cpp
* @example mofem/tutorials/vec-11_elastic_tie_mesh/elastic_tie_mesh.cpp
* @brief Elastic mesh tie example with a tie-aware partitioned mesh loader
*
* @copyright Anonymous authors (c) 2025 under the MIT license
*/
#include <MoFEM.hpp>
using namespace MoFEM;
constexpr AssemblyType A =
(SCHUR_ASSEMBLE) ? AssemblyType::BLOCK_SCHUR : AssemblyType::PETSC;
constexpr IntegrationType I = IntegrationType::GAUSS;
using BoundaryEle =
using DomainEleOp = DomainEle::UserDataOperator;
using BoundaryEleOp = BoundaryEle::UserDataOperator;
struct DomainBCs {};
struct BoundaryBCs {};
using OpDomainRhsBCs = DomainRhsBCs::OpFlux<DomainBCs, 1, SPACE_DIM>;
using OpBoundaryRhsBCs = BoundaryRhsBCs::OpFlux<BoundaryBCs, 1, SPACE_DIM>;
using OpBoundaryLhsBCs = BoundaryLhsBCs::OpFlux<BoundaryBCs, 1, SPACE_DIM>;
#include <ElasticTie.hpp>
using ElasticTieMeshExample::ElasticTieMeshExample;
private:
};
auto norm_fe = boost::make_shared<DomainEle>(mField);
norm_fe->getRuleHook = [](int, int, int approx_order) {
return 2 * approx_order + 1;
};
norm_fe->getOpPtrVector(), {H1}, "GEOMETRY");
auto common_ptr = HookeOps::commonDataFactory<SPACE_DIM, GAUSS, DomainEle>(
mField, norm_fe->getOpPtrVector(), "U", "MAT_ELASTIC", Sev::verbose);
auto exact_stress_ptr = boost::make_shared<MatrixDouble>();
constexpr double uniaxial_stress_xx = 1e3 * 0.3 / 3.0;
auto uniaxial_stress = [](const double, const double, const double) {
MatrixDouble stress((SPACE_DIM * (SPACE_DIM + 1)) / 2, 1);
stress.clear();
auto t_stress = getFTensor2SymmetricFromMat<
t_stress(0, 0) = uniaxial_stress_xx;
return stress;
};
lame_solution(0.5, 1.0, 2.0, 1.0, 1e3, 0.3);
auto lame_stress = [&lame_solution](const double x, const double y,
const double z) {
return lame_solution.stress(x, y, z);
};
MatrixFunc stress_func = (test == 11) ? MatrixFunc(lame_stress)
: MatrixFunc(uniaxial_stress);
norm_fe->getOpPtrVector().push_back(
exact_stress_ptr, stress_func));
enum Norms { STRESS_ERROR_L2 = 0, STRESS_EXACT_L2, LAST_NORM };
auto norms_vec =
(mField.get_comm_rank() == 0) ? LAST_NORM : 0,
LAST_NORM);
CHKERR VecZeroEntries(norms_vec);
norm_fe->getOpPtrVector().push_back(
exact_stress_ptr, norms_vec, STRESS_EXACT_L2));
norm_fe->getOpPtrVector().push_back(
common_ptr->getMatCauchyStress(), norms_vec, STRESS_ERROR_L2,
exact_stress_ptr));
CHKERR DMoFEMLoopFiniteElements(simple->getDM(), simple->getDomainFEName(),
norm_fe);
CHKERR VecAssemblyBegin(norms_vec);
CHKERR VecAssemblyEnd(norms_vec);
if (mField.get_comm_rank() == 0) {
const double *norms;
CHKERR VecGetArrayRead(norms_vec, &norms);
const double error_l2 = std::sqrt(norms[STRESS_ERROR_L2]);
const double exact_l2 = std::sqrt(norms[STRESS_EXACT_L2]);
MOFEM_LOG_C("WORLD", Sev::inform, "STRESS_ERROR_L2 = %.16e\n", error_l2);
MOFEM_LOG_C("WORLD", Sev::inform, "STRESS_EXACT_L2 = %.16e\n", exact_l2);
CHKERR VecRestoreArrayRead(norms_vec, &norms);
double max_error_l2 = 1e-2;
CHKERR PetscOptionsGetReal(PETSC_NULLPTR, "", "-stress_error_l2_tol",
&max_error_l2, PETSC_NULLPTR);
if (error_l2 >= max_error_l2) {
SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
"Stress L2 error %.16e exceeds tolerance %.16e", error_l2,
max_error_l2);
}
}
}
int test = 0;
CHKERR PetscOptionsGetInt(PETSC_NULLPTR, "", "-test", &test, PETSC_NULLPTR);
if (test == 10 || test == 11)
}
static char help[] = "...\n\n";
int main(int argc, char *argv[]) {
const char param_file[] = "param_file.petsc";
MoFEM::Core::Initialize(&argc, &argv, param_file, help);
MeshsetsManager::broadcastMeshsetsOn = false;
auto core_log = logging::core::get();
core_log->add_sink(
LogManager::createSink(LogManager::getStrmWorld(), "TIMER"));
core_log->add_sink(
LogManager::createSink(LogManager::getStrmSync(), "FieldEvaluator"));
LogManager::setLog("FieldEvaluator");
MOFEM_LOG_TAG("FieldEvaluator", "field_eval");
try {
DMType dm_name = "DMMOFEM";
DMType dm_name_mg = "DMMOFEM_MG";
moab::Core mb_instance;
moab::Interface &moab = mb_instance;
MoFEM::Core core(moab);
MoFEM::Interface &m_field = core;
CHKERR ex.runProblem();
}
}
const AnalyticalSolutions::HollowCylinderUnderRadialPressure< SPACE_DIM > lame_solution(0.5, 1.0, 2.0, 1.0, 1e3, 0.3)
TIE constraint support for the elastic tutorial.
#define MOFEM_LOG_C(channel, severity, format,...)
void simple(double P1[], double P2[], double P3[], double c[], const int N)
Definition acoustic.cpp:69
static char help[]
int main()
constexpr int SPACE_DIM
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_DATA_INCONSISTENCY
Definition definitions.h:31
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
constexpr int SPACE_DIM
PetscErrorCode DMRegister_MoFEM(const char sname[])
Register MoFEM problem.
Definition DMMoFEM.cpp:43
MoFEMErrorCode DMRegister_MGViaApproxOrders(const char sname[])
Register DM for Multi-Grid via approximation orders.
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:576
IntegrationType
Form integrator integration types.
AssemblyType
[Storage and set boundary conditions]
#define MOFEM_LOG_TAG(channel, tag)
Tag channel.
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
UBlasMatrix< double > MatrixDouble
Definition Types.hpp:77
implementation of Data Operators for Forces and Sources
Definition Common.hpp:10
PetscErrorCode PetscOptionsGetInt(PetscOptions *, const char pre[], const char name[], PetscInt *ivalue, PetscBool *set)
PetscErrorCode PetscOptionsGetReal(PetscOptions *, const char pre[], const char name[], PetscReal *dval, PetscBool *set)
static auto getFTensor2SymmetricFromMat(M &data)
Get symmetric tensor rank 2 (matrix) form data matrix.
auto createVectorMPI(MPI_Comm comm, PetscInt n, PetscInt N)
Create MPI Vector.
boost::function< MatrixDouble(const double, const double, const double)> MatrixFunc
constexpr IntegrationType I
constexpr AssemblyType A
static constexpr int approx_order
Lamé analytical solution for a hollow cylinder under radial pressure with a linear isotropic Hooke ma...
Boundary conditions marker.
Definition elastic.cpp:39
[Define entities]
Definition elastic.cpp:38
MoFEM::Interface & mField
ElasticExample extension providing reusable TIE mesh behaviour.
MoFEMErrorCode checkStressError(const int test)
MoFEMErrorCode checkResults() override
[Postprocess results]
virtual MPI_Comm & get_comm() const =0
virtual int get_comm_rank() const =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
Deprecated interface functions.
Data on single entity (This is passed as argument to DataOperator::doWork)
Assembly methods.
Definition Natural.hpp:65
Get norm of input MatrixDouble for symmetric Tensor2.
Get values from matrix function in symmetric tensor storage at integration points and save them to Ma...
Template struct for dimension-specific finite element types.
Simple interface for fast problem set-up.
Definition Simple.hpp:27
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
NaturalBC< BoundaryEleOp >::Assembly< AT >::BiLinearForm< IT > BoundaryLhsBCs
Definition plastic.cpp:175
NaturalBC< BoundaryEleOp >::Assembly< AT >::LinearForm< IT > BoundaryRhsBCs
Definition plastic.cpp:172
#define EXECUTABLE_DIMENSION
Definition plastic.cpp:13
BoundaryLhsBCs::OpFlux< PlasticOps::BoundaryBCs, 1, SPACE_DIM > OpBoundaryLhsBCs
Definition plastic.cpp:177
NaturalBC< DomainEleOp >::Assembly< AT >::LinearForm< IT > DomainRhsBCs
Definition plastic.cpp:169
DomainRhsBCs::OpFlux< PlasticOps::DomainBCs, 1, SPACE_DIM > OpDomainRhsBCs
Definition plastic.cpp:171
BoundaryRhsBCs::OpFlux< PlasticOps::BoundaryBCs, 1, SPACE_DIM > OpBoundaryRhsBCs
Definition plastic.cpp:174
ElementsAndOps< SPACE_DIM >::SideEle SideEle
Definition plastic.cpp:61
#define SCHUR_ASSEMBLE
Definition contact.cpp:18