v0.14.0
Classes | Functions | Variables
simple_interface.cpp File Reference
#include <MoFEM.hpp>

Go to the source code of this file.

Classes

struct  OpVolume
 
struct  OpFace
 
struct  VolRule
 Set integration rule to volume elements. More...
 
struct  FaceRule
 Set integration rule to boundary elements. More...
 

Functions

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

Variables

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

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)
Examples
simple_interface.cpp.

Definition at line 95 of file simple_interface.cpp.

95  {
96 
97  // initialize petsc
98  MoFEM::Core::Initialize(&argc, &argv, (char *)0, help);
99 
100  auto core_log = logging::core::get();
101  core_log->add_sink(
102  LogManager::createSink(LogManager::getStrmWorld(), "TEST"));
103  LogManager::setLog("TEST");
104  MOFEM_LOG_TAG("TEST", "atom_test");
105  core_log->add_sink(
106  LogManager::createSink(LogManager::getStrmSync(), "TESTSYNC"));
107  LogManager::setLog("TESTSYNC");
108  MOFEM_LOG_TAG("TESTSYNC", "atom_test");
109 
110  try {
111 
112  // Create MoAB database
113  moab::Core moab_core;
114  moab::Interface &moab = moab_core;
115 
116  // Create MoFEM database and link it to MoAB
117  MoFEM::Core mofem_core(moab);
118  MoFEM::Interface &m_field = mofem_core;
119 
120  // Register DM Manager
121  DMType dm_name = "DMMOFEM";
122  CHKERR DMRegister_MoFEM(dm_name);
123 
124  // Simple interface
125  Simple *simple_interface;
126  CHKERR m_field.getInterface(simple_interface);
127  {
128  // get options from command line
129  CHKERR simple_interface->getOptions();
130  // load mesh file
131  CHKERR simple_interface->loadFile();
132  // add fields
133  CHKERR simple_interface->addDomainField("MESH_NODE_POSITIONS", H1,
135  CHKERR simple_interface->addBoundaryField("MESH_NODE_POSITIONS", H1,
137  CHKERR simple_interface->addSkeletonField("MESH_NODE_POSITIONS", H1,
139 
140  CHKERR simple_interface->addMeshsetField("GLOBAL", NOFIELD, NOBASE, 3);
141  CHKERR simple_interface->addMeshsetField("MESH_NODE_POSITIONS", H1,
143 
144  // Note:: two "meshset" elements are created, one with GOLOBAL field and
145  // vertices with "MESH_NODE_POSITIONS" field, and other with "GLOABL"
146  // field and edges with "MESH_NODE_POSITIONS" field.
147  // That us only to test API, and data structures, potential application is
148  // here not known.
149  Range verts;
150  CHKERR m_field.get_moab().get_entities_by_type(0, MBVERTEX, verts);
151  simple_interface->getMeshsetFiniteElementEntities().push_back(verts);
152  Range edge;
153  CHKERR m_field.get_moab().get_entities_by_type(0, MBEDGE, edge);
154  simple_interface->getMeshsetFiniteElementEntities().push_back(edge);
155 
156  // set fields order
157  CHKERR simple_interface->setFieldOrder("MESH_NODE_POSITIONS", 1);
158  // setup problem
159  CHKERR simple_interface->setUp();
160  // Project mesh coordinate on mesh
161  Projection10NodeCoordsOnField ent_method(m_field, "MESH_NODE_POSITIONS");
162  CHKERR m_field.loop_dofs("MESH_NODE_POSITIONS", ent_method);
163  // get dm
164  auto dm = simple_interface->getDM();
165  // create elements
166  auto domain_fe =
167  boost::make_shared<VolumeElementForcesAndSourcesCore>(m_field);
168  auto boundary_fe =
169  boost::make_shared<FaceElementForcesAndSourcesCore>(m_field);
170 
171  // set integration rule
172  domain_fe->getRuleHook = VolRule();
173  boundary_fe->getRuleHook = FaceRule();
174  // create distributed vector to accumulate values from processors.
175  int ghosts[] = {0};
176 
177  auto vol = createGhostVector(
178  PETSC_COMM_WORLD, m_field.get_comm_rank() == 0 ? 1 : 0, 1,
179  m_field.get_comm_rank() == 0 ? 0 : 1, ghosts);
180  auto surf_vol = vectorDuplicate(vol);
181 
182  // set operator to the volume element
183  auto material_grad_mat = boost::make_shared<MatrixDouble>();
184  auto material_det_vec = boost::make_shared<VectorDouble>();
185 
186  domain_fe->getOpPtrVector().push_back(
187  new OpCalculateVectorFieldGradient<3, 3>("MESH_NODE_POSITIONS",
188  material_grad_mat));
189  domain_fe->getOpPtrVector().push_back(
190  new OpInvertMatrix<3>(material_grad_mat, material_det_vec, nullptr));
191  domain_fe->getOpPtrVector().push_back(
192  new OpSetHOWeights(material_det_vec));
193  domain_fe->getOpPtrVector().push_back(
194  new OpCalculateHOCoords("MESH_NODE_POSITIONS"));
195  domain_fe->getOpPtrVector().push_back(
196  new OpVolume("MESH_NODE_POSITIONS", vol));
197  // set operator to the face element
198  boundary_fe->getOpPtrVector().push_back(
199  new OpCalculateHOCoords("MESH_NODE_POSITIONS"));
200  boundary_fe->getOpPtrVector().push_back(
201  new OpFace("MESH_NODE_POSITIONS", surf_vol));
202  // make integration in volume (here real calculations starts)
203  CHKERR DMoFEMLoopFiniteElements(dm, simple_interface->getDomainFEName(),
204  domain_fe);
205  // make integration on boundary
206  CHKERR DMoFEMLoopFiniteElements(dm, simple_interface->getBoundaryFEName(),
207  boundary_fe);
208 
209  auto skeleton_fe = boost::make_shared<FEMethod>();
210  auto A = createDMMatrix(dm);
211  auto B = createDMMatrix(dm);
212  auto f = createDMVector(dm);
213  auto x = createDMVector(dm);
214  auto x_t = createDMVector(dm);
215  auto x_tt = createDMVector(dm);
216  skeleton_fe->f = f;
217  skeleton_fe->A = A;
218  skeleton_fe->B = B;
219  skeleton_fe->x = x;
220  skeleton_fe->x_t = x_t;
221  skeleton_fe->x_tt = x_tt;
222 
223  skeleton_fe->preProcessHook = [&]() {
225  if (f != skeleton_fe->ts_F)
226  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "Wrong ptr");
227  if (A != skeleton_fe->ts_A)
228  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "Wrong ptr");
229  if (B != skeleton_fe->ts_B)
230  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "Wrong ptr");
231  if (x != skeleton_fe->ts_u)
232  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "Wrong ptr");
233  if (x_t != skeleton_fe->ts_u_t)
234  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "Wrong ptr");
235  if (x_tt != skeleton_fe->ts_u_tt)
236  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY, "Wrong ptr");
238  };
239 
240  skeleton_fe->postProcessHook = []() { return 0; };
241  skeleton_fe->operatorHook = []() { return 0; };
242 
243  CHKERR DMoFEMLoopFiniteElements(dm, simple_interface->getSkeletonFEName(),
244  skeleton_fe);
245 
246  // assemble volumes from processors and accumulate on processor of rank 0
247  CHKERR VecAssemblyBegin(vol);
248  CHKERR VecAssemblyEnd(vol);
249  CHKERR VecGhostUpdateBegin(vol, ADD_VALUES, SCATTER_REVERSE);
250  CHKERR VecGhostUpdateEnd(vol, ADD_VALUES, SCATTER_REVERSE);
251  CHKERR VecAssemblyBegin(surf_vol);
252  CHKERR VecAssemblyEnd(surf_vol);
253  CHKERR VecGhostUpdateBegin(surf_vol, ADD_VALUES, SCATTER_REVERSE);
254  CHKERR VecGhostUpdateEnd(surf_vol, ADD_VALUES, SCATTER_REVERSE);
255  if (m_field.get_comm_rank() == 0) {
256  double *a_vol;
257  CHKERR VecGetArray(vol, &a_vol);
258  double *a_surf_vol;
259  CHKERR VecGetArray(surf_vol, &a_surf_vol);
260  MOFEM_LOG("TEST", Sev::inform) << "Volume = " << a_vol[0];
261  MOFEM_LOG("TEST", Sev::inform) << "Surf Volume = " << a_surf_vol[0];
262  if (fabs(a_vol[0] - a_surf_vol[0]) > 1e-12) {
263  SETERRQ(PETSC_COMM_SELF, MOFEM_ATOM_TEST_INVALID, "Should be zero");
264  }
265  CHKERR VecRestoreArray(vol, &a_vol);
266  CHKERR VecRestoreArray(vol, &a_surf_vol);
267  }
268 
269  struct MeshsetFE : public ForcesAndSourcesCore {
273  const auto type = numeredEntFiniteElementPtr->getEntType();
274  if (type != MBENTITYSET) {
275  SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
276  "Expected entity set as a finite element");
277  }
280  }
281  MoFEMErrorCode preProcess() { return 0; }
282  MoFEMErrorCode postProcess() { return 0; }
283  };
284 
285  auto fe_ptr = boost::make_shared<MeshsetFE>(m_field);
286 
287  struct OpMeshset : ForcesAndSourcesCore::UserDataOperator {
289  using OP::OP;
290 
291  MoFEMErrorCode doWork(int side, EntityType type,
294  MOFEM_LOG("TESTSYNC", Sev::inform) << data.getIndices();
296  }
297 
298  MoFEMErrorCode doWork(int row_side, int col_side, EntityType row_type,
299  EntityType col_type,
300  EntitiesFieldData::EntData &row_data,
301  EntitiesFieldData::EntData &col_data) {
303  MOFEM_LOG("TESTSYNC", Sev::inform)
304  << row_data.getIndices() << " " << col_data.getIndices() << endl;
306  }
307  };
308 
309  fe_ptr->getOpPtrVector().push_back(
310  new OpMeshset("GLOBAL", OpMeshset::OPROW));
311  fe_ptr->getOpPtrVector().push_back(
312  new OpMeshset("GLOBAL", "GLOBAL", OpMeshset::OPROWCOL));
313 
315  dm, simple_interface->getMeshsetFEName(), fe_ptr, 0,
316  m_field.get_comm_size());
317  MOFEM_LOG_SEVERITY_SYNC(m_field.get_comm(), Sev::inform);
318  }
319  }
320  CATCH_ERRORS;
321 
322  // finish work cleaning memory, getting statistics, etc.
324 
325  return 0;
326 }

Variable Documentation

◆ help

char help[] = "...\n\n"
static
Examples
simple_interface.cpp.

Definition at line 16 of file simple_interface.cpp.

MoFEM::UnknownInterface::getInterface
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
Definition: UnknownInterface.hpp:93
MoFEM::EntitiesFieldData::EntData
Data on single entity (This is passed as argument to DataOperator::doWork)
Definition: EntitiesFieldData.hpp:128
MoFEM::CoreInterface::loop_dofs
virtual MoFEMErrorCode loop_dofs(const Problem *problem_ptr, const std::string &field_name, RowColData rc, DofMethod &method, int lower_rank, int upper_rank, int verb=DEFAULT_VERBOSITY)=0
Make a loop over dofs.
MoFEM::CoreTmp< 0 >
Core (interface) class.
Definition: Core.hpp:82
H1
@ H1
continuous field
Definition: definitions.h:85
MOFEM_LOG_SEVERITY_SYNC
#define MOFEM_LOG_SEVERITY_SYNC(comm, severity)
Synchronise "SYNC" on curtain severity level.
Definition: LogManager.hpp:352
MoFEM::CoreInterface::get_comm
virtual MPI_Comm & get_comm() const =0
NOBASE
@ NOBASE
Definition: definitions.h:59
MoFEM::Exceptions::MoFEMErrorCode
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:56
MoFEM::CoreInterface::get_comm_rank
virtual int get_comm_rank() const =0
MoFEM::Simple::getSkeletonFEName
const std::string getSkeletonFEName() const
Get the Skeleton FE Name.
Definition: Simple.hpp:401
MoFEM::Simple::loadFile
MoFEMErrorCode loadFile(const std::string options, const std::string mesh_file_name, LoadFileFunc loadFunc=defaultLoadFileFunc)
Load mesh file.
Definition: Simple.cpp:194
A
constexpr AssemblyType A
Definition: operators_tests.cpp:30
VolRule
Set integration rule to volume elements.
Definition: simple_interface.cpp:88
MoFEM::Projection10NodeCoordsOnField
Projection of edge entities with one mid-node on hierarchical basis.
Definition: Projection10NodeCoordsOnField.hpp:24
MoFEM::CoreTmp< 0 >::Finalize
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition: Core.cpp:112
MoFEM::ForcesAndSourcesCore::preProcess
virtual MoFEMErrorCode preProcess()
function is run at the beginning of loop
Definition: ForcesAndSourcesCore.cpp:2011
MoFEM::Simple
Simple interface for fast problem set-up.
Definition: Simple.hpp:27
MoFEM::DataOperator::doWork
virtual MoFEMErrorCode doWork(int row_side, int col_side, EntityType row_type, EntityType col_type, EntitiesFieldData::EntData &row_data, EntitiesFieldData::EntData &col_data)
Operator for bi-linear form, usually to calculate values on left hand side.
Definition: DataOperators.hpp:40
MoFEM::OpCalculateHOCoords
Calculate HO coordinates at gauss points.
Definition: HODataOperators.hpp:41
MoFEM::createDMMatrix
auto createDMMatrix(DM dm)
Get smart matrix from DM.
Definition: DMMoFEM.hpp:1056
MoFEM::DeprecatedCoreInterface
Deprecated interface functions.
Definition: DeprecatedCoreInterface.hpp:16
MoFEM::Interface
DeprecatedCoreInterface Interface
Definition: Interface.hpp:2010
MoFEM::Simple::addMeshsetField
MoFEMErrorCode addMeshsetField(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_ZERO, int verb=-1)
Add meshset field.
Definition: Simple.cpp:414
MoFEM::Simple::getOptions
MoFEMErrorCode getOptions()
get options
Definition: Simple.cpp:180
MoFEM::Simple::getDM
MoFEMErrorCode getDM(DM *dm)
Get DM.
Definition: Simple.cpp:829
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:548
MoFEM::createDMVector
auto createDMVector(DM dm)
Get smart vector from DM.
Definition: DMMoFEM.hpp:1099
MoFEM::createGhostVector
auto createGhostVector(MPI_Comm comm, PetscInt n, PetscInt N, PetscInt nghost, const PetscInt ghosts[])
Create smart ghost vector.
Definition: PetscSmartObj.hpp:179
MoFEM::CoreInterface::get_moab
virtual moab::Interface & get_moab()=0
MoFEM::DMoFEMLoopFiniteElementsUpAndLowRank
PetscErrorCode DMoFEMLoopFiniteElementsUpAndLowRank(DM dm, const char fe_name[], MoFEM::FEMethod *method, int low_rank, int up_rank, CacheTupleWeakPtr cache_ptr=CacheTupleSharedPtr())
Executes FEMethod for finite elements in DM.
Definition: DMMoFEM.cpp:567
MoFEM::ForcesAndSourcesCore::UserDataOperator
Definition: ForcesAndSourcesCore.hpp:549
convert.type
type
Definition: convert.py:64
MoFEM::Simple::getMeshsetFiniteElementEntities
auto & getMeshsetFiniteElementEntities()
Get the Domain Fields.
Definition: Simple.hpp:443
MoFEM::EntitiesFieldData::EntData::getIndices
const VectorInt & getIndices() const
Get global indices of dofs on entity.
Definition: EntitiesFieldData.hpp:1214
MoFEM::ForcesAndSourcesCore::ForcesAndSourcesCore
ForcesAndSourcesCore(Interface &m_field)
Definition: ForcesAndSourcesCore.cpp:40
MoFEM::DMRegister_MoFEM
PetscErrorCode DMRegister_MoFEM(const char sname[])
Register MoFEM problem.
Definition: DMMoFEM.cpp:43
OpFace
Definition: boundary_marker.cpp:19
MoFEM::CoreInterface::get_comm_size
virtual int get_comm_size() const =0
MoFEM::Simple::getDomainFEName
const std::string getDomainFEName() const
Get the Domain FE Name.
Definition: Simple.hpp:387
MoFEM::Simple::addBoundaryField
MoFEMErrorCode addBoundaryField(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_ZERO, int verb=-1)
Add field on boundary.
Definition: Simple.cpp:358
MoFEM::ForcesAndSourcesCore::operator()
virtual MoFEMErrorCode operator()()
function is run for every finite element
Definition: ForcesAndSourcesCore.cpp:2019
FaceRule
Set integration rule to boundary elements.
Definition: simple_interface.cpp:91
MOFEM_LOG_TAG
#define MOFEM_LOG_TAG(channel, tag)
Tag channel.
Definition: LogManager.hpp:339
MoFEM::ForcesAndSourcesCore::UserDataOperator
friend class UserDataOperator
Definition: ForcesAndSourcesCore.hpp:482
help
static char help[]
Definition: simple_interface.cpp:16
MoFEM::Simple::setFieldOrder
MoFEMErrorCode setFieldOrder(const std::string field_name, const int order, const Range *ents=NULL)
Set field order.
Definition: Simple.cpp:599
MoFEM::OpCalculateVectorFieldGradient
Get field gradients at integration pts for scalar filed rank 0, i.e. vector field.
Definition: UserDataOperators.hpp:1535
MoFEM::ForcesAndSourcesCore
structure to get information form mofem into EntitiesFieldData
Definition: ForcesAndSourcesCore.hpp:22
Range
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
MOFEM_LOG
#define MOFEM_LOG(channel, severity)
Log.
Definition: LogManager.hpp:308
MoFEM::vectorDuplicate
SmartPetscObj< Vec > vectorDuplicate(Vec vec)
Create duplicate vector of smart vector.
Definition: PetscSmartObj.hpp:221
CATCH_ERRORS
#define CATCH_ERRORS
Catch errors.
Definition: definitions.h:385
MoFEM::Core
CoreTmp< 0 > Core
Definition: Core.hpp:1148
HenckyOps::f
auto f
Definition: HenckyOps.hpp:15
MoFEM::OpSetHOWeights
Set inverse jacobian to base functions.
Definition: HODataOperators.hpp:159
AINSWORTH_LEGENDRE_BASE
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
Definition: definitions.h:60
MoFEM::Simple::getBoundaryFEName
const std::string getBoundaryFEName() const
Get the Boundary FE Name.
Definition: Simple.hpp:394
MOFEM_DATA_INCONSISTENCY
@ MOFEM_DATA_INCONSISTENCY
Definition: definitions.h:31
MoFEM::OpInvertMatrix
Definition: UserDataOperators.hpp:3249
MoFEM::Simple::getMeshsetFEName
std::string & getMeshsetFEName()
Get the Skeleton FE Name.
Definition: Simple.hpp:436
MoFEM::Simple::addSkeletonField
MoFEMErrorCode addSkeletonField(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_ZERO, int verb=-1)
Add field on skeleton.
Definition: Simple.cpp:376
MoFEM::ForcesAndSourcesCore::loopOverOperators
MoFEMErrorCode loopOverOperators()
Iterate user data operators.
Definition: ForcesAndSourcesCore.cpp:1379
MOFEM_ATOM_TEST_INVALID
@ MOFEM_ATOM_TEST_INVALID
Definition: definitions.h:40
MoFEM::ForcesAndSourcesCore::postProcess
virtual MoFEMErrorCode postProcess()
function is run at the end of loop
Definition: ForcesAndSourcesCore.cpp:2034
MoFEM::Simple::setUp
MoFEMErrorCode setUp(const PetscBool is_partitioned=PETSC_TRUE)
Setup problem.
Definition: Simple.cpp:765
MoFEM::DMoFEMLoopFiniteElements
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:586
OP
MoFEMFunctionReturn
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:429
MoFEM::Simple::addDomainField
MoFEMErrorCode addDomainField(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_ZERO, int verb=-1)
Add field on domain.
Definition: Simple.cpp:264
OpVolume
Definition: simple_interface.cpp:18
MoFEMFunctionBegin
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:359
NOFIELD
@ NOFIELD
scalar or vector of scalars describe (no true field)
Definition: definitions.h:84