Calculate volume by integrating volume elements and using divergence theorem by integrating surface elements.
static char help[] =
"...\n\n";
vOl(vol) {}
const int nb_int_pts = getGaussPts().size2();
auto t_w = getFTensor0IntegrationWeight();
auto t_ho_det = getFTenosr0HoMeasure();
double v = getMeasure();
double vol = 0;
for (int gg = 0; gg != nb_int_pts; gg++) {
vol += t_w * t_ho_det * v;
++t_w;
++t_ho_det;
}
CHKERR VecSetValue(vOl, 0, vol, ADD_VALUES);
}
MoFEMErrorCode doWork(
int row_side,
int col_side, EntityType row_type,
EntityType col_type,
}
};
OpFace(
const std::string &field_name,
Vec vol)
vOl(vol) {}
const int nb_int_pts = getGaussPts().size2();
auto t_normal = getFTensor1NormalsAtGaussPts();
auto t_w = getFTensor0IntegrationWeight();
auto t_coords = getFTensor1HoCoordsAtGaussPts();
double vol = 0;
for (int gg = 0; gg != nb_int_pts; gg++) {
vol += (t_coords(
i) * t_normal(
i)) * t_w;
++t_normal;
++t_w;
++t_coords;
}
vol /= 6;
CHKERR VecSetValue(vOl, 0, vol, ADD_VALUES);
}
MoFEMErrorCode doWork(
int row_side,
int col_side, EntityType row_type,
EntityType col_type,
}
};
int operator()(int, int, int) const { return 2; }
};
int operator()(int, int, int) const { return 4; }
};
int main(
int argc,
char *argv[]) {
try {
DMType dm_name = "DMMOFEM";
Simple *simple_interface;
{
CHKERR simple_interface->getOptions();
CHKERR simple_interface->loadFile();
CHKERR simple_interface->addDomainField(
"MESH_NODE_POSITIONS",
H1,
CHKERR simple_interface->addBoundaryField(
"MESH_NODE_POSITIONS",
H1,
CHKERR simple_interface->setFieldOrder(
"MESH_NODE_POSITIONS", 1);
CHKERR simple_interface->setUp();
Projection10NodeCoordsOnField ent_method(m_field, "MESH_NODE_POSITIONS");
auto dm = simple_interface->getDM();
boost::shared_ptr<ForcesAndSourcesCore> domain_fe =
boost::shared_ptr<ForcesAndSourcesCore>(
boost::shared_ptr<ForcesAndSourcesCore> boundary_fe =
boost::shared_ptr<ForcesAndSourcesCore>(
domain_fe->getRuleHook =
VolRule();
int ghosts[] = {0};
domain_fe->getOpPtrVector().push_back(
new OpVolume(
"MESH_NODE_POSITIONS", vol));
boundary_fe->getOpPtrVector().push_back(
new OpFace(
"MESH_NODE_POSITIONS", surf_vol));
domain_fe);
boundary_fe);
CHKERR VecGhostUpdateBegin(vol, ADD_VALUES, SCATTER_REVERSE);
CHKERR VecGhostUpdateEnd(vol, ADD_VALUES, SCATTER_REVERSE);
CHKERR VecAssemblyBegin(surf_vol);
CHKERR VecAssemblyEnd(surf_vol);
CHKERR VecGhostUpdateBegin(surf_vol, ADD_VALUES, SCATTER_REVERSE);
CHKERR VecGhostUpdateEnd(surf_vol, ADD_VALUES, SCATTER_REVERSE);
double *a_vol;
CHKERR VecGetArray(vol, &a_vol);
double *a_surf_vol;
CHKERR VecGetArray(surf_vol, &a_surf_vol);
cout << "Volume = " << a_vol[0] << endl;
cout << "Surf Volume = " << a_surf_vol[0] << endl;
if (fabs(a_vol[0] - a_surf_vol[0]) > 1e-12) {
}
CHKERR VecRestoreArray(vol, &a_vol);
CHKERR VecRestoreArray(vol, &a_surf_vol);
}
}
}
return 0;
}
ForcesAndSourcesCore::UserDataOperator UserDataOperator
#define CATCH_ERRORS
Catch errors.
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ MOFEM_ATOM_TEST_INVALID
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
PetscErrorCode DMoFEMLoopFiniteElements(DM dm, const char fe_name[], MoFEM::FEMethod *method)
Executes FEMethod for finite elements in DM.
PetscErrorCode DMRegister_MoFEM(const char sname[])
Register MoFEM problem.
FaceElementForcesAndSourcesCoreSwitch< 0 > FaceElementForcesAndSourcesCore
Face finite element default.
VolumeElementForcesAndSourcesCoreSwitch< 0 > VolumeElementForcesAndSourcesCore
Volume finite element default.
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.
FTensor::Index< 'i', 3 > i
const FTensor::Tensor2< T, Dim, Dim > Vec
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
implementation of Data Operators for Forces and Sources
auto createSmartGhostVector
Create smart ghost vector.
DeprecatedCoreInterface Interface
SmartPetscObj< Vec > smartVectorDuplicate(SmartPetscObj< Vec > &vec)
Create duplicate vector of smart vector.
DataForcesAndSourcesCore::EntData EntData
int main(int argc, char *argv[])
Set integration rule to boundary elements.
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.
MoFEMErrorCode getInterface(const MOFEMuuid &uuid, IFACE *&iface) const
Get interface by uuid and return reference to pointer of interface.
VolumeElementForcesAndSourcesCoreBase::UserDataOperator UserDataOperator