Tetsing entities cache. Entities acache is data abstraction enabling user to pass data between operators, finite elements, and problems, in convinient way.
It can be used to store indices, or history variables, and any other data, which I can not imagine at that moment of time, and how to make use of it depends on user creativity and imagination.
static char help[] =
"...\n\n";
};
entsIndices.clear();
auto field_ents = data.getFieldEntities();
if (auto e_ptr = field_ents[0]) {
entsIndices.push_back(boost::make_shared<MyStorage>(data.getIndices()));
e_ptr->getWeakStoragePtr() = entsIndices.back();
MOFEM_LOG(
"SYNC", Sev::inform) <<
"Set " << e_ptr->getEntTypeName() <<
" "
<< side << " : " << entsIndices.size();
if (auto ptr = e_ptr->getSharedStoragePtr<EntityStorage>()) {
if (auto cast_ptr = boost::dynamic_pointer_cast<MyStorage>(ptr))
MOFEM_LOG(
"SYNC", Sev::noisy) <<
"Cast works";
else
} else {
"Pointer to stored data is expected to be set");
}
if (
auto ptr = e_ptr->getSharedStoragePtr<
MyStorage>()) {
<< data.getIndices() << " : " << ptr->globalIndices;
} else {
"Pointer to stored data is expected to be set");
}
} else {
"Pointer to entity should be set by finite element");
}
}
using SharedVecInt = boost::shared_ptr<MyStorage>;
static std::vector<SharedVecInt>
entsIndices;
};
auto field_ents = data.getFieldEntities();
if (auto e_ptr = field_ents[0]) {
<< "Test " << e_ptr->getEntTypeName() << " " << side;
if (
auto ptr = e_ptr->getSharedStoragePtr<
MyStorage>()) {
<< data.getIndices() << " : " << ptr->globalIndices;
auto diff = data.getIndices() - ptr->globalIndices;
auto dot = inner_prod(diff, diff);
if (dot > 0)
} else {
"Pointer to stored data is expected to be set");
}
} else {
"Pointer to entity should be set by finite element");
}
}
};
:
VolOp(field_name, OPROW), V(v) {}
auto nb_dofs = data.getIndices().size();
if (nb_dofs) {
std::vector<double> v(nb_dofs, 1);
}
}
private:
};
int operator()(int, int, int) const { return 1; }
};
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(
"FIELD",
H1,
CHKERR simple_interface->setFieldOrder(
"FIELD", 4);
CHKERR simple_interface->setUp();
auto dm = simple_interface->getDM();
auto domain_fe = boost::make_shared<VolEle>(m_field);
domain_fe->getRuleHook =
VolRule();
auto get_skin = [&]() {
Range ents;
CHKERR m_field.
get_moab().get_entities_by_dimension(0, 3, ents,
true);
Range skin_ents;
CHKERR skin.find_skin(0, ents,
false, skin_ents);
ParallelComm *pcomm =
Range proc_skin;
CHKERR pcomm->filter_pstatus(skin_ents,
PSTATUS_SHARED | PSTATUS_MULTISHARED,
PSTATUS_NOT, -1, &proc_skin);
Range adj;
moab::Interface::UNION);
return proc_skin;
};
auto get_mark_skin_dofs = [&](Range &&skin) {
auto problem_manager = m_field.
getInterface<ProblemsManager>();
auto marker_ptr = boost::make_shared<std::vector<bool>>();
problem_manager->markDofs(simple_interface->getProblemName(),
ROW, skin,
*marker_ptr);
return marker_ptr;
};
SmartPetscObj<Vec> v;
auto mark_dofs = get_mark_skin_dofs(get_skin());
domain_fe->getOpPtrVector().push_back(
new OpVolumeSet(
"FIELD"));
domain_fe->getOpPtrVector().push_back(
new OpVolumeTest(
"FIELD"));
domain_fe->getOpPtrVector().push_back(
new OpSetBc("FIELD", true, mark_dofs));
domain_fe->getOpPtrVector().push_back(new OpUnSetBc("FIELD"));
domain_fe);
CHKERR VecGhostUpdateBegin(v, ADD_VALUES, SCATTER_REVERSE);
CHKERR VecGhostUpdateEnd(v, ADD_VALUES, SCATTER_REVERSE);
CHKERR VecGhostUpdateBegin(v, INSERT_VALUES, SCATTER_FORWARD);
CHKERR VecGhostUpdateEnd(v, INSERT_VALUES, SCATTER_FORWARD);
INSERT_VALUES, SCATTER_REVERSE);
double *array;
CHKERR VecGetArray(v, &array);
auto loc_idx = dof->getPetscLocalDofIdx();
if (dof->getFieldData() != array[loc_idx])
"Data inconsistency");
if ((*mark_dofs)[loc_idx]) {
if (array[loc_idx] != 0)
"Dof assembled, but it should be not");
} else {
if (array[loc_idx] == 0)
"Dof not assembled, but it should be");
}
}
CHKERR VecRestoreArray(v, &array);
}
}
return 0;
}
ForcesAndSourcesCore::UserDataOperator UserDataOperator
#define MOFEM_LOG_SYNCHRONISE(comm)
Synchronise "SYNC" channel.
MoFEM::FaceElementForcesAndSourcesCore FaceEle
#define CATCH_ERRORS
Catch errors.
@ 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_ATOM_TEST_INVALID
@ MOFEM_DATA_INCONSISTENCY
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
PetscErrorCode DMoFEMLoopFiniteElements(DM dm, const char fe_name[], MoFEM::FEMethod *method)
Executes FEMethod for finite elements in DM.
PetscErrorCode DMoFEMMeshToLocalVector(DM dm, Vec l, InsertMode mode, ScatterMode scatter_mode)
set local (or ghosted) vector values on mesh for partition only
PetscErrorCode DMMoFEMGetProblemPtr(DM dm, const MoFEM::Problem **problem_ptr)
Get pointer to problem data structure.
PetscErrorCode DMRegister_MoFEM(const char sname[])
Register MoFEM problem.
PetscErrorCode DMCreateGlobalVector_MoFEM(DM dm, Vec *g)
DMShellSetCreateGlobalVector.
FaceElementForcesAndSourcesCoreSwitch< 0 > FaceElementForcesAndSourcesCore
Face finite element default.
VolumeElementForcesAndSourcesCoreSwitch< 0 > VolumeElementForcesAndSourcesCore
Volume finite element default.
#define MOFEM_LOG(channel, severity)
Log.
#define MOFEM_LOG_TAG(channel, tag)
Tag channel.
#define MOFEM_LOG_CHANNEL(channel)
Set and reset channel.
const FTensor::Tensor2< T, Dim, Dim > Vec
const Tensor1_Expr< const dTensor0< T, Dim, i >, typename promote< T, double >::V, Dim, i > d(const Tensor0< T * > &a, const Index< i, Dim > index, const Tensor1< int, Dim > &d_ijk, const Tensor1< double, Dim > &d_xyz)
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
ublas::vector< int, IntAllocator > VectorInt
implementation of Data Operators for Forces and Sources
DeprecatedCoreInterface Interface
DataForcesAndSourcesCore::EntData EntData
virtual moab::Interface & get_moab()=0
virtual MPI_Comm & get_comm() 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.
keeps basic data about problem
boost::shared_ptr< NumeredDofEntity_multiIndex > & getNumeredRowDofsPtr() const
get access to numeredRowDofsPtr storing DOFs on rows
MoFEMErrorCode getInterface(const MOFEMuuid &uuid, IFACE *&iface) const
Get interface by uuid and return reference to pointer of interface.
default operator for TET element
Volume finite element with switches.
VolumeElementForcesAndSourcesCoreBase::UserDataOperator UserDataOperator
Operator set cache stored data, in this example, global indices, but it can be any structure.
static std::vector< SharedVecInt > entsIndices
This is global static storage.
Test if cached data can be accessed, and check consistency of data.
int main(int argc, char *argv[])
FaceEle::UserDataOperator FaceOp