46 for (
int d = 0; d < max_dim; ++d) {
48 CHKERR moab.get_adjacencies(ents, d,
false, adj, moab::Interface::UNION);
51 CHKERR moab.create_meshset(MESHSET_SET, meshset);
52 CHKERR moab.add_entities(meshset, closure);
57 Range physical_ents = ents.subset_by_type(MBTET);
58 physical_ents.merge(ents.subset_by_type(MBHEX));
63 Range &triangle_faces) {
65 triangle_faces.clear();
66 const auto prisms = ents.subset_by_type(MBPRISM);
67 if (!prisms.empty()) {
68 CHKERR moab.get_adjacencies(prisms, 2,
false, triangle_faces,
69 moab::Interface::UNION);
70 triangle_faces = triangle_faces.subset_by_type(MBTRI);
80 boost::shared_ptr<ElasticTie::CommonData>
tieData =
nullptr;
106 CHKERR moab.load_file(file_name, 0,
107 "PARALLEL=BCAST;PARTITION=PARALLEL_PARTITION;");
110 if (pcomm ==
nullptr)
111 pcomm =
new ParallelComm(&moab, mf.
get_comm());
113 const auto rank = pcomm->rank();
114 Tag part_tag = pcomm->part_tag();
115 Range all_ents, tagged_sets, proc_ents, off_proc_ents;
116 CHKERR moab.get_entities_by_handle(0, all_ents,
false);
117 CHKERR moab.get_entities_by_type_and_tag(
118 0, MBENTITYSET, &part_tag, NULL, 1, tagged_sets,
119 moab::Interface::UNION);
121 for (
auto meshset : tagged_sets) {
123 CHKERR moab.tag_get_data(part_tag, &meshset, 1, &part);
125 CHKERR moab.get_entities_by_handle(meshset, meshset_ents,
true);
127 proc_ents.merge(meshset_ents);
129 off_proc_ents.merge(meshset_ents);
130 CHKERR moab.tag_clear_data(part_tag, meshset_ents, &part);
133 const auto all_volume_ents = all_ents.subset_by_dimension(3);
134 const auto proc_volume_ents = proc_ents.subset_by_dimension(3);
138 std::array<Range, 4> proc_ents_skin;
140 Range all_skin, proc_skin;
141 CHKERR skin.find_skin(0, all_volume_ents,
false, all_skin);
142 CHKERR skin.find_skin(0, proc_volume_ents,
false, proc_skin);
143 proc_ents_skin[2] = subtract(proc_skin, all_skin);
145 Range all_phys_skin, local_phys_faces, physical_boundary_faces;
146 CHKERR skin.find_skin(0, all_phys_ents.subset_by_dimension(3),
false,
148 CHKERR moab.get_adjacencies(proc_phys_ents, 2,
false, local_phys_faces,
149 moab::Interface::UNION);
150 physical_boundary_faces = intersect(all_phys_skin, local_phys_faces);
151 if (!physical_boundary_faces.empty()) {
152 CHKERR moab.tag_clear_data(pcomm->partition_tag(), physical_boundary_faces,
155 proc_ents_skin[2].merge(physical_boundary_faces);
157 Range prism_triangle_faces;
159 proc_ents_skin[2].merge(prism_triangle_faces);
160 CHKERR moab.get_adjacencies(proc_ents_skin[2], 1,
false,
162 moab::Interface::UNION);
163 CHKERR moab.get_connectivity(proc_ents_skin[2], proc_ents_skin[0],
166 auto to_remove = off_proc_ents;
167 for (
int d = 2; d >= 0; --d)
168 to_remove = subtract(to_remove, proc_ents_skin[d]);
171 CHKERR moab.get_entities_by_type(0, MBENTITYSET, all_meshsets,
true);
172 for (
auto meshset : all_meshsets)
173 CHKERR moab.remove_entities(meshset, to_remove);
175 for (
int d = 3; d > 0; --d) {
176 Range ents = to_remove.subset_by_dimension(d);
178 CHKERR moab.delete_entities(ents);
182 CHKERR pcomm->resolve_shared_ents(0, proc_ents, 3, -1,
183 proc_ents_skin.data());
197 CHKERR meshset_mng->setMeshsetFromFile();
205 enum bases { AINSWORTH, DEMKOWICZ, LASBASETOPT };
206 const char *list_bases[LASBASETOPT] = {
"ainsworth",
"demkowicz"};
207 PetscInt choice_base_value = AINSWORTH;
209 LASBASETOPT, &choice_base_value, PETSC_NULLPTR);
212 switch (choice_base_value) {
233 if (!tet_hex_ents.empty()) {
237 simple->getMeshset() = domain_meshset;
239 Range boundary_faces;
243 CHKERR skin.find_skin(0, tet_hex_ents,
false, local_skin);
249 CHKERR skin.find_skin(0, tet_hex_ents,
false, boundary_faces);
254 simple->getBoundaryMeshSet() = boundary_meshset;
285 auto norm_fe = boost::make_shared<DomainEle>(
mField);
291 norm_fe->getOpPtrVector(), {H1},
"GEOMETRY");
293 auto common_ptr = HookeOps::commonDataFactory<SPACE_DIM, GAUSS, DomainEle>(
294 mField, norm_fe->getOpPtrVector(),
"U",
"MAT_ELASTIC", Sev::verbose);
296 auto exact_stress_ptr = boost::make_shared<MatrixDouble>();
298 constexpr double uniaxial_stress_xx = 1e3 * 0.3 / 3.0;
304 t_stress(0, 0) = uniaxial_stress_xx;
309 lame_solution(0.5, 1.0, 2.0, 1.0, 1e3, 0.3);
310 auto lame_stress = [&lame_solution](
const double x,
const double y,
312 return lame_solution.
stress(x, y, z);
317 norm_fe->getOpPtrVector().push_back(
319 exact_stress_ptr, stress_func));
321 enum Norms { STRESS_ERROR_L2 = 0, STRESS_EXACT_L2, LAST_NORM };
326 CHKERR VecZeroEntries(norms_vec);
328 norm_fe->getOpPtrVector().push_back(
330 exact_stress_ptr, norms_vec, STRESS_EXACT_L2));
331 norm_fe->getOpPtrVector().push_back(
333 common_ptr->getMatCauchyStress(), norms_vec, STRESS_ERROR_L2,
338 CHKERR VecAssemblyBegin(norms_vec);
339 CHKERR VecAssemblyEnd(norms_vec);
343 CHKERR VecGetArrayRead(norms_vec, &norms);
345 const double error_l2 = std::sqrt(norms[STRESS_ERROR_L2]);
346 const double exact_l2 = std::sqrt(norms[STRESS_EXACT_L2]);
348 MOFEM_LOG_C(
"WORLD", Sev::inform,
"STRESS_ERROR_L2 = %.16e\n", error_l2);
349 MOFEM_LOG_C(
"WORLD", Sev::inform,
"STRESS_EXACT_L2 = %.16e\n", exact_l2);
351 CHKERR VecRestoreArrayRead(norms_vec, &norms);
353 double max_error_l2 = 1e-2;
355 &max_error_l2, PETSC_NULLPTR);
356 if (error_l2 >= max_error_l2) {
358 "Stress L2 error %.16e exceeds tolerance %.16e", error_l2,
371 if (test == 10 || test == 11)
378int main(
int argc,
char *argv[]) {
380 const char param_file[] =
"param_file.petsc";
385 auto core_log = logging::core::get();
394 DMType dm_name =
"DMMOFEM";
396 DMType dm_name_mg =
"DMMOFEM_MG";
399 moab::Core mb_instance;
400 moab::Interface &moab = mb_instance;
Implementation of elastic example class.
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)
ElementsAndOps< SPACE_DIM >::DomainEle DomainEle
ElementsAndOps< SPACE_DIM >::BoundaryEle BoundaryEle
#define CATCH_ERRORS
Catch errors.
FieldApproximationBase
approximation base
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
#define MYPCOMM_INDEX
default communicator number PCOMM
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ MOFEM_DATA_INCONSISTENCY
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
constexpr IntegrationType I
PetscErrorCode DMRegister_MoFEM(const char sname[])
Register MoFEM problem.
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.
static LoggerType & setLog(const std::string channel)
Set ans resset chanel logger.
#define MOFEM_LOG_TAG(channel, tag)
Tag channel.
Range getPhysicalVolumeEntities(const Range &ents)
MoFEMErrorCode initializeTieConstraints(MoFEM::Interface &mField, boost::shared_ptr< CommonData > &tie_data, const std::string &field_name, FieldApproximationBase base, int order)
MoFEMErrorCode getPrismTriangleFaces(moab::Interface &moab, const Range &ents, Range &triangle_faces)
MoFEMErrorCode logTieDisplacementNorms(MoFEM::Interface &mField, const boost::shared_ptr< CommonData > &tie_data, const std::string &field_name)
MoFEMErrorCode makeClosureMeshset(moab::Interface &moab, const Range &ents, const int max_dim, EntityHandle &meshset)
MoFEMErrorCode setupTieSolver(MoFEM::Interface &mField, boost::shared_ptr< CommonData > tie_data, SmartPetscObj< KSP > solver)
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
implementation of Data Operators for Forces and Sources
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
PetscErrorCode PetscOptionsGetEList(PetscOptions *, const char pre[], const char name[], const char *const *list, PetscInt next, PetscInt *value, PetscBool *set)
static constexpr int approx_order
Lamé analytical solution for a hollow cylinder under radial pressure with a linear isotropic Hooke ma...
MoFEM::MatrixDouble stress(const double x, const double y, const double) const
Return the Cauchy stress in symmetric tensor storage at point (x, y, z).
Boundary conditions marker.
virtual MoFEMErrorCode setupProblem()
[Read mesh]
virtual MoFEMErrorCode kspSetUpAndSolve(SmartPetscObj< KSP > solver)
MoFEMErrorCode runProblem()
[Run problem]
MoFEM::Interface & mField
ElasticExample(MoFEM::Interface &m_field)
MoFEMErrorCode readMesh() override
[Run problem]
MoFEMErrorCode setupProblem() override
[Read mesh]
boost::shared_ptr< ElasticTie::CommonData > tieData
MoFEMErrorCode checkStressError(const int test)
MoFEMErrorCode checkResults() override
[Postprocess results]
MoFEMErrorCode setUpSolver(SmartPetscObj< KSP > solver) override
[Push operators to pipeline]
Range physicalBoundaryFaces
MoFEMErrorCode kspSetUpAndSolve(SmartPetscObj< KSP > solver) override
Add operators pushing bases from local to physical configuration.
virtual int get_comm_size() const =0
virtual moab::Interface & get_moab()=0
virtual MPI_Comm & get_comm() const =0
virtual int get_comm_rank() const =0
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Deprecated interface functions.
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.
static boost::shared_ptr< std::ostream > getStrmSync()
Get the strm sync object.
Interface for managing meshsets containing materials and boundary conditions.
static bool broadcastMeshsetsOn
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.
intrusive_ptr for managing petsc objects
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
#define EXECUTABLE_DIMENSION
ElementsAndOps< SPACE_DIM >::SideEle SideEle