v0.14.0
Functions | Variables
thermal_stress_elem.cpp File Reference
#include <BasicFiniteElements.hpp>

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Variables

static char help [] = "...\n\n"
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 12 of file thermal_stress_elem.cpp.

12  {
13 
14  MoFEM::Core::Initialize(&argc, &argv, (char *)0, help);
15 
16  try {
17 
18  moab::Core mb_instance;
19  moab::Interface &moab = mb_instance;
20  int rank;
21  MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
22 
23  PetscBool flg = PETSC_TRUE;
24  char mesh_file_name[255];
25  CHKERR PetscOptionsGetString(PETSC_NULL, PETSC_NULL, "-my_file",
26  mesh_file_name, 255, &flg);
27  if (flg != PETSC_TRUE) {
28  SETERRQ(PETSC_COMM_SELF, 1, "*** ERROR -my_file (MESH FILE NEEDED)");
29  }
30 
31  const char *option;
32  option = "";
33  CHKERR moab.load_file(mesh_file_name, 0, option);
34 
35  // Create MoFEM (Joseph) database
36  MoFEM::Core core(moab);
37  MoFEM::Interface &m_field = core;
38 
39  // set entitities bit level
40  BitRefLevel bit_level0;
41  bit_level0.set(0);
42  EntityHandle meshset_level0;
43  CHKERR moab.create_meshset(MESHSET_SET, meshset_level0);
44  CHKERR m_field.getInterface<BitRefManager>()->setBitRefLevelByDim(
45  0, 3, bit_level0);
46 
47  // Fields
48  CHKERR m_field.add_field("DISP", H1, AINSWORTH_LEGENDRE_BASE, 3);
49  CHKERR m_field.add_field("TEMP", H1, AINSWORTH_LEGENDRE_BASE, 1);
50 
51  // Problem
52  CHKERR m_field.add_problem("PROB");
53 
54  // set refinement level for problem
55  CHKERR m_field.modify_problem_ref_level_add_bit("PROB", bit_level0);
56 
57  // meshset consisting all entities in mesh
58  EntityHandle root_set = moab.get_root_set();
59  // add entities to field
60  CHKERR m_field.add_ents_to_field_by_type(root_set, MBTET, "TEMP");
61  CHKERR m_field.add_ents_to_field_by_type(root_set, MBTET, "DISP");
62 
63  // set app. order
64  // see Hierarchic Finite Element Bases on Unstructured Tetrahedral Meshes
65  // (Mark Ainsworth & Joe Coyle)
66  int order_temp = 2;
67  CHKERR m_field.set_field_order(root_set, MBTET, "TEMP", order_temp);
68  CHKERR m_field.set_field_order(root_set, MBTRI, "TEMP", order_temp);
69  CHKERR m_field.set_field_order(root_set, MBEDGE, "TEMP", order_temp);
70  CHKERR m_field.set_field_order(root_set, MBVERTEX, "TEMP", 1);
71 
72  int order_disp = 3;
73  CHKERR m_field.set_field_order(root_set, MBTET, "DISP", order_disp);
74  CHKERR m_field.set_field_order(root_set, MBTRI, "DISP", order_disp);
75  CHKERR m_field.set_field_order(root_set, MBEDGE, "DISP", order_disp);
76  CHKERR m_field.set_field_order(root_set, MBVERTEX, "DISP", 1);
77 
78  ThermalStressElement thermal_stress_elem(m_field);
79  CHKERR thermal_stress_elem.addThermalStressElement("ELAS", "DISP", "TEMP");
80  CHKERR m_field.modify_problem_add_finite_element("PROB", "ELAS");
81 
82  /****/
83  // build database
84  // build field
85  CHKERR m_field.build_fields();
86  // build finite elemnts
87  CHKERR m_field.build_finite_elements();
88  // build adjacencies
89  CHKERR m_field.build_adjacencies(bit_level0);
90 
91  // build problem
92  ProblemsManager *prb_mng_ptr;
93  CHKERR m_field.getInterface(prb_mng_ptr);
94  CHKERR prb_mng_ptr->buildProblem("PROB", true);
95  // mesh partitioning
96  // partition
97  CHKERR prb_mng_ptr->partitionSimpleProblem("PROB");
98  CHKERR prb_mng_ptr->partitionFiniteElements("PROB");
99  // what are ghost nodes, see Petsc Manual
100  CHKERR prb_mng_ptr->partitionGhostDofs("PROB");
101 
102  // set temerature at nodes
104  MBVERTEX, dof)) {
105  EntityHandle ent = dof->get()->getEnt();
106  VectorDouble coords(3);
107  CHKERR moab.get_coords(&ent, 1, &coords[0]);
108  dof->get()->getFieldData() = 1;
109  }
110 
111  Vec F;
112  CHKERR m_field.getInterface<VecManager>()->vecCreateGhost("PROB", ROW, &F);
113  CHKERR thermal_stress_elem.setThermalStressRhsOperators("DISP", "TEMP", F,
114  1);
115 
117  "PROB", "ELAS", thermal_stress_elem.getLoopThermalStressRhs());
118  CHKERR VecAssemblyBegin(F);
119  CHKERR VecAssemblyEnd(F);
120 
121  // PetscViewer viewer;
122  // CHKERR
123  // PetscViewerASCIIOpen(PETSC_COMM_WORLD,"forces_and_sources_thermal_stress_elem.txt",&viewer);
124  // CHKERR VecChop(F,1e-4);
125  // CHKERR VecView(F,viewer);
126  // CHKERR PetscViewerDestroy(&viewer);
127 
128  double sum = 0;
129  CHKERR VecSum(F, &sum);
130  CHKERR PetscPrintf(PETSC_COMM_WORLD, "sum = %9.8f\n", sum);
131  double fnorm;
132  CHKERR VecNorm(F, NORM_2, &fnorm);
133  CHKERR PetscPrintf(PETSC_COMM_WORLD, "fnorm = %9.8e\n", fnorm);
134  if (fabs(sum) > 1e-7) {
135  SETERRQ(PETSC_COMM_WORLD, MOFEM_ATOM_TEST_INVALID, "Failed to pass test");
136  }
137  if (fabs(fnorm - 2.64638118e+00) > 1e-7) {
138  SETERRQ(PETSC_COMM_WORLD, MOFEM_ATOM_TEST_INVALID, "Failed to pass test");
139  }
140 
141  CHKERR VecZeroEntries(F);
142  CHKERR VecDestroy(&F);
143  }
144  CATCH_ERRORS;
145 
147 
148  return 0;
149 }

Variable Documentation

◆ help

char help[] = "...\n\n"
static

Definition at line 10 of file thermal_stress_elem.cpp.

MoFEM::UnknownInterface::getInterface
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface refernce to pointer of interface.
Definition: UnknownInterface.hpp:93
MoFEM::CoreInterface::loop_finite_elements
virtual MoFEMErrorCode loop_finite_elements(const std::string problem_name, const std::string &fe_name, FEMethod &method, boost::shared_ptr< NumeredEntFiniteElement_multiIndex > fe_ptr=nullptr, MoFEMTypes bh=MF_EXIST, CacheTupleWeakPtr cache_ptr=CacheTupleSharedPtr(), int verb=DEFAULT_VERBOSITY)=0
Make a loop over finite elements.
MoFEM::ProblemsManager::buildProblem
MoFEMErrorCode buildProblem(const std::string name, const bool square_matrix, int verb=VERBOSE)
build problem data structures
Definition: ProblemsManager.cpp:87
MoFEM::CoreTmp< 0 >
Core (interface) class.
Definition: Core.hpp:82
H1
@ H1
continuous field
Definition: definitions.h:85
EntityHandle
MoFEM::ProblemsManager
Problem manager is used to build and partition problems.
Definition: ProblemsManager.hpp:21
MoFEM::CoreTmp< 0 >::Finalize
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition: Core.cpp:112
MoFEM::CoreInterface::add_ents_to_field_by_type
virtual MoFEMErrorCode add_ents_to_field_by_type(const Range &ents, const EntityType type, const std::string &name, int verb=DEFAULT_VERBOSITY)=0
Add entities to field meshset.
MoFEM::DeprecatedCoreInterface
Deprecated interface functions.
Definition: DeprecatedCoreInterface.hpp:16
ROW
@ ROW
Definition: definitions.h:123
MoFEM::Interface
DeprecatedCoreInterface Interface
Definition: Interface.hpp:1975
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:535
MoFEM::CoreInterface::build_finite_elements
virtual MoFEMErrorCode build_finite_elements(int verb=DEFAULT_VERBOSITY)=0
Build finite elements.
MoFEM::CoreInterface::add_field
virtual MoFEMErrorCode add_field(const std::string &name, const FieldSpace space, const FieldApproximationBase base, const FieldCoefficientsNumber nb_of_coefficients, const TagType tag_type=MB_TAG_SPARSE, const enum MoFEMTypes bh=MF_EXCL, int verb=DEFAULT_VERBOSITY)=0
Add field.
MoFEM::ProblemsManager::partitionFiniteElements
MoFEMErrorCode partitionFiniteElements(const std::string name, bool part_from_moab=false, int low_proc=-1, int hi_proc=-1, int verb=VERBOSE)
partition finite elements
Definition: ProblemsManager.cpp:2167
MoFEM::CoreInterface::modify_problem_ref_level_add_bit
virtual MoFEMErrorCode modify_problem_ref_level_add_bit(const std::string &name_problem, const BitRefLevel &bit)=0
add ref level to problem
MoFEM::VecManager
Vector manager is used to create vectors \mofem_vectors.
Definition: VecManager.hpp:23
mesh_file_name
char mesh_file_name[255]
Definition: mesh_smoothing.cpp:23
MoFEM::CoreTmp< 0 >::Initialize
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
Definition: Core.cpp:72
CATCH_ERRORS
#define CATCH_ERRORS
Catch errors.
Definition: definitions.h:372
MoFEM::Core
CoreTmp< 0 > Core
Definition: Core.hpp:1094
MoFEM::ProblemsManager::partitionSimpleProblem
MoFEMErrorCode partitionSimpleProblem(const std::string name, int verb=VERBOSE)
partition problem dofs
Definition: ProblemsManager.cpp:1537
help
static char help[]
Definition: thermal_stress_elem.cpp:10
AINSWORTH_LEGENDRE_BASE
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
Definition: definitions.h:60
EigenMatrix::Vec
const FTensor::Tensor2< T, Dim, Dim > Vec
Definition: MatrixFunction.hpp:66
MoFEM::PetscOptionsGetString
PetscErrorCode PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)
Definition: DeprecatedPetsc.hpp:172
MoFEM::CoreInterface::build_fields
virtual MoFEMErrorCode build_fields(int verb=DEFAULT_VERBOSITY)=0
MoFEM::Types::VectorDouble
UBlasVector< double > VectorDouble
Definition: Types.hpp:68
MoFEM::BitRefManager
Managing BitRefLevels.
Definition: BitRefManager.hpp:21
MoFEM::CoreInterface::modify_problem_add_finite_element
virtual MoFEMErrorCode modify_problem_add_finite_element(const std::string name_problem, const std::string &fe_name)=0
add finite element to problem, this add entities assigned to finite element to a particular problem
MoFEM::Types::BitRefLevel
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
Definition: Types.hpp:40
MOFEM_ATOM_TEST_INVALID
@ MOFEM_ATOM_TEST_INVALID
Definition: definitions.h:40
MoFEM::CoreInterface::build_adjacencies
virtual MoFEMErrorCode build_adjacencies(const Range &ents, int verb=DEFAULT_VERBOSITY)=0
build adjacencies
MoFEM::CoreInterface::set_field_order
virtual MoFEMErrorCode set_field_order(const EntityHandle meshset, const EntityType type, const std::string &name, const ApproximationOrder order, int verb=DEFAULT_VERBOSITY)=0
Set order approximation of the entities in the field.
MoFEM::ProblemsManager::partitionGhostDofs
MoFEMErrorCode partitionGhostDofs(const std::string name, int verb=VERBOSE)
determine ghost nodes
Definition: ProblemsManager.cpp:2339
MoFEM::CoreInterface::add_problem
virtual MoFEMErrorCode add_problem(const std::string &name, enum MoFEMTypes bh=MF_EXCL, int verb=DEFAULT_VERBOSITY)=0
Add problem.
_IT_GET_DOFS_FIELD_BY_NAME_AND_TYPE_FOR_LOOP_
#define _IT_GET_DOFS_FIELD_BY_NAME_AND_TYPE_FOR_LOOP_(MFIELD, NAME, TYPE, IT)
loop over all dofs from a moFEM field and particular field
Definition: Interface.hpp:1925
ThermalStressElement
Implentation of thermal stress element.
Definition: ThermalStressElement.hpp:15
F
@ F
Definition: free_surface.cpp:394