8#ifndef __MAGNETICELEMENT_HPP__
9#define __MAGNETICELEMENT_HPP__
104 if (
bit->getName().compare(0, 9,
"NATURALBC") == 0) {
122 ParallelComm *pcomm =
126 if (
bit->getName().compare(0, 10,
"ESSENTIALBC") == 0) {
140 CHKERR skin.find_skin(0, tets,
false, skin_faces);
143 CHKERR pcomm->filter_pstatus(skin_faces,
144 PSTATUS_SHARED | PSTATUS_MULTISHARED,
145 PSTATUS_NOT, -1, &proc_skin);
166 0, 3, BitRefLevel().set(0));
206 "MESH_NODE_POSITIONS");
218 Projection10NodeCoordsOnField ent_method_material(
mField,
219 "MESH_NODE_POSITIONS");
245 "MESH_NODE_POSITIONS");
281 CHKERR DMRegister_MoFEM(
"DMMOFEM");
285 BitRefLevel().set(0));
323 auto material_grad_mat = boost::make_shared<MatrixDouble>();
324 auto material_det_vec = boost::make_shared<VectorDouble>();
325 auto material_inv_grad_mat = boost::make_shared<MatrixDouble>();
327 "MESH_NODE_POSITIONS");
334 new OpGetHONormalsOnFace(
"MESH_NODE_POSITIONS"));
336 new OpCalculateHOCoords(
"MESH_NODE_POSITIONS"));
338 new OpHOSetCovariantPiolaTransformOnFace3D(
HCURL));
350 ->createMPIAIJ<PetscGlobalIdx_mi_tag>(problem_ptr->
getName(),
371 CHKERR KSPCreate(PETSC_COMM_WORLD, &solver);
373 CHKERR KSPSetFromOptions(solver);
376 CHKERR KSPDestroy(&solver);
383 if (regression_test) {
387 const double expected_value = 4.6772e+01;
388 const double tol = 1e-4;
389 if ((nrm2 - expected_value) / expected_value >
tol) {
391 "Regression test failed %6.4e != %6.4e", nrm2, expected_value);
410 PostProcBrokenMeshInMoab<VolumeElementForcesAndSourcesCore> post_proc(
414 "MESH_NODE_POSITIONS");
416 auto pos_ptr = boost::make_shared<MatrixDouble>();
417 auto field_val_ptr = boost::make_shared<MatrixDouble>();
419 post_proc.getOpPtrVector().push_back(
420 new OpCalculateVectorFieldValues<3>(
"MESH_NODE_POSITIONS", pos_ptr));
421 post_proc.getOpPtrVector().push_back(
424 using OpPPMap = OpPostProcMapInMoab<3, 3>;
426 post_proc.getOpPtrVector().push_back(
430 post_proc.getPostProcMesh(), post_proc.getMapGaussPts(),
434 {{
"MESH_NODE_POSITIONS", pos_ptr},
435 {blockData.fieldName, field_val_ptr}},
445 post_proc.getOpPtrVector().push_back(
new OpPostProcessCurl(
446 blockData, post_proc.getPostProcMesh(), post_proc.getMapGaussPts()));
449 CHKERR post_proc.writeFile(
"out_values.h5m");
490 MoFEMErrorCode
doWork(
int row_side,
int col_side, EntityType row_type,
492 EntitiesFieldData::EntData &row_data,
493 EntitiesFieldData::EntData &col_data) {
496 if (row_type == MBVERTEX)
498 if (col_type == MBVERTEX)
501 const int nb_row_dofs = row_data.getN().size2() / 3;
502 if (nb_row_dofs == 0)
504 const int nb_col_dofs = col_data.getN().size2() / 3;
505 if (nb_col_dofs == 0)
507 entityLocalMatrix.resize(nb_row_dofs, nb_col_dofs,
false);
508 entityLocalMatrix.clear();
510 if (nb_row_dofs !=
static_cast<int>(row_data.getFieldData().size())) {
512 "Number of base functions and DOFs on entity is different on "
514 nb_row_dofs, row_data.getFieldData().size());
516 if (nb_col_dofs !=
static_cast<int>(col_data.getFieldData().size())) {
518 "Number of base functions and DOFs on entity is different on "
520 nb_col_dofs, col_data.getFieldData().size());
523 MatrixDouble row_curl_mat, col_curl_mat;
528 const double c0 = 1. / blockData.
mU;
529 const int nb_gauss_pts = row_data.getN().size1();
530 auto t_row_curl_base = row_data.getFTensor2DiffN<3, 3>();
532 for (
int gg = 0; gg != nb_gauss_pts; gg++) {
535 double w = getGaussPts()(3, gg) * getVolume();
538 for (
int aa = 0; aa != nb_row_dofs; aa++) {
539 t_row_curl(
i) = levi_civita(
j,
i,
k) * t_row_curl_base(
j,
k);
544 auto t_col_curl_base = col_data.getFTensor2DiffN<3, 3>(gg, 0);
545 for (
int bb = 0; bb != nb_col_dofs; bb++) {
546 t_col_curl(
i) = levi_civita(
j,
i,
k) * t_col_curl_base(
j,
k);
547 t_local_mat += c0 * w * t_row_curl(
i) * t_col_curl(
i);
556 CHKERR MatSetValues(blockData.
A, nb_row_dofs, &row_data.getIndices()[0],
557 nb_col_dofs, &col_data.getIndices()[0],
558 &entityLocalMatrix(0, 0), ADD_VALUES);
560 if (row_side != col_side || row_type != col_type) {
561 entityLocalMatrix = trans(entityLocalMatrix);
562 CHKERR MatSetValues(blockData.
A, nb_col_dofs, &col_data.getIndices()[0],
563 nb_row_dofs, &row_data.getIndices()[0],
564 &entityLocalMatrix(0, 0), ADD_VALUES);
604 MoFEMErrorCode
doWork(
int row_side,
int col_side, EntityType row_type,
606 EntitiesFieldData::EntData &row_data,
607 EntitiesFieldData::EntData &col_data) {
610 if (row_type == MBVERTEX)
612 if (col_type == MBVERTEX)
615 const int nb_row_dofs = row_data.getN().size2() / 3;
616 if (nb_row_dofs == 0)
618 const int nb_col_dofs = col_data.getN().size2() / 3;
619 if (nb_col_dofs == 0)
621 entityLocalMatrix.resize(nb_row_dofs, nb_col_dofs,
false);
622 entityLocalMatrix.clear();
624 if (nb_row_dofs !=
static_cast<int>(row_data.getFieldData().size())) {
626 "Number of base functions and DOFs on entity is different on "
628 nb_row_dofs, row_data.getFieldData().size());
630 if (nb_col_dofs !=
static_cast<int>(col_data.getFieldData().size())) {
632 "Number of base functions and DOFs on entity is different on "
634 nb_col_dofs, col_data.getFieldData().size());
637 MatrixDouble row_curl_mat, col_curl_mat;
640 const double c0 = 1. / blockData.
mU;
641 const double c1 = blockData.
ePsilon * c0;
642 const int nb_gauss_pts = row_data.getN().size1();
644 for (
int gg = 0; gg != nb_gauss_pts; gg++) {
647 double w = getGaussPts()(3, gg) * getVolume();
650 &row_data.getVectorN<3>(gg)(0,
HVEC0),
651 &row_data.getVectorN<3>(gg)(0,
HVEC1),
652 &row_data.getVectorN<3>(gg)(0,
HVEC2), 3);
654 for (
int aa = 0; aa != nb_row_dofs; aa++) {
657 &col_data.getVectorN<3>(gg)(0,
HVEC0),
658 &col_data.getVectorN<3>(gg)(0,
HVEC1),
659 &col_data.getVectorN<3>(gg)(0,
HVEC2), 3);
660 for (
int bb = 0; bb != nb_col_dofs; bb++) {
661 t_local_mat += c1 * w * t_row_base(
i) * t_col_base(
i);
672 CHKERR MatSetValues(blockData.
A, nb_row_dofs, &row_data.getIndices()[0],
673 nb_col_dofs, &col_data.getIndices()[0],
674 &entityLocalMatrix(0, 0), ADD_VALUES);
676 if (row_side != col_side || row_type != col_type) {
677 entityLocalMatrix = trans(entityLocalMatrix);
678 CHKERR MatSetValues(blockData.
A, nb_col_dofs, &col_data.getIndices()[0],
679 nb_row_dofs, &row_data.getIndices()[0],
680 &entityLocalMatrix(0, 0), ADD_VALUES);
720 MoFEMErrorCode
doWork(
int row_side, EntityType row_type,
721 EntitiesFieldData::EntData &row_data) {
724 if (row_type == MBVERTEX)
727 const int nb_row_dofs = row_data.getN().size2() / 3;
728 if (nb_row_dofs == 0)
730 naturalBC.resize(nb_row_dofs,
false);
735 const int nb_gauss_pts = row_data.getN().size1();
736 auto t_row_base = row_data.getFTensor1N<3>();
738 for (
int gg = 0; gg != nb_gauss_pts; gg++) {
742 area = norm_2(getNormalsAtGaussPts(gg)) * 0.5;
743 double w = getGaussPts()(2, gg) * area;
747 const double x = getCoordsAtGaussPts()(gg, 0);
748 const double y = getCoordsAtGaussPts()(gg, 1);
749 const double r = sqrt(x * x + y * y);
763 for (
int aa = 0; aa != nb_row_dofs; aa++) {
764 t_f += w * t_row_base(
i) * t_j(
i);
770 CHKERR VecSetValues(blockData.
F, row_data.getIndices().size(),
771 &row_data.getIndices()[0], &naturalBC[0], ADD_VALUES);
788 std::vector<EntityHandle> &map_gauss_pts)
791 blockData(data), postProcMesh(post_proc_mesh),
792 mapGaussPts(map_gauss_pts) {}
794 MoFEMErrorCode
doWork(
int row_side, EntityType row_type,
795 EntitiesFieldData::EntData &row_data) {
798 if (row_type == MBVERTEX)
802 double def_val[] = {0, 0, 0};
803 CHKERR postProcMesh.tag_get_handle(
"MAGNETIC_INDUCTION_FIELD", 3,
805 MB_TAG_CREAT | MB_TAG_SPARSE, def_val);
806 const int nb_row_dofs = row_data.getN().size2() / 3;
807 if (nb_row_dofs == 0)
809 const void *tags_ptr[mapGaussPts.size()];
811 if (nb_row_dofs != row_data.getFieldData().size())
813 "Wrong number of base functions and DOFs %d != %zu",
814 nb_row_dofs, row_data.getFieldData().size());
819 const int nb_gauss_pts = row_data.getN().size1();
820 if (nb_gauss_pts !=
static_cast<int>(mapGaussPts.size())) {
822 "Inconsistency number of dofs %d!=%zu", nb_gauss_pts,
825 CHKERR postProcMesh.tag_get_by_ptr(th, &mapGaussPts[0],
826 mapGaussPts.size(), tags_ptr);
827 auto t_curl_base = row_data.getFTensor2DiffN<3, 3>();
828 for (
int gg = 0; gg != nb_gauss_pts; gg++) {
831 double *ptr = &((
double *)tags_ptr[gg])[0];
835 auto t_dof = row_data.getFTensor0FieldData();
836 for (
int aa = 0; aa != nb_row_dofs; aa++) {
837 t_curl(
i) += t_dof * (levi_civita(
j,
i,
k) * t_curl_base(
j,
k));
ForcesAndSourcesCore::UserDataOperator UserDataOperator
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
@ HCURL
field with continuous tangents
#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.
PetscErrorCode DMoFEMLoopFiniteElements(DM dm, const char fe_name[], MoFEM::FEMethod *method, CacheTupleWeakPtr cache_ptr=CacheTupleSharedPtr())
Executes FEMethod for finite elements in DM.
virtual MoFEMErrorCode add_finite_element(const std::string &fe_name, enum MoFEMTypes bh=MF_EXCL, int verb=DEFAULT_VERBOSITY)=0
add finite element
virtual MoFEMErrorCode build_finite_elements(int verb=DEFAULT_VERBOSITY)=0
Build finite elements.
virtual MoFEMErrorCode modify_finite_element_add_field_col(const std::string &fe_name, const std::string name_row)=0
set field col which finite element use
virtual MoFEMErrorCode add_ents_to_finite_element_by_type(const EntityHandle entities, const EntityType type, const std::string name, const bool recursive=true)=0
add entities to finite element
virtual MoFEMErrorCode modify_finite_element_add_field_row(const std::string &fe_name, const std::string name_row)=0
set field row which finite element use
virtual MoFEMErrorCode modify_finite_element_add_field_data(const std::string &fe_name, const std::string name_field)=0
set finite element field data
virtual MoFEMErrorCode build_fields(int verb=DEFAULT_VERBOSITY)=0
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.
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.
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.
#define _IT_CUBITMESHSETS_BY_SET_TYPE_FOR_LOOP_(MESHSET_MANAGER, CUBITBCTYPE, IT)
Iterator that loops over a specific Cubit MeshSet having a particular BC meshset in a moFEM field.
FTensor::Index< 'i', SPACE_DIM > i
FTensor::Index< 'j', 3 > j
FTensor::Index< 'k', 3 > k
implementation of Data Operators for Forces and Sources
OpPostProcMapInMoab< SPACE_DIM, SPACE_DIM > OpPPMap
data structure storing material constants, model parameters, matrices, etc.
int oRder
approximation order
const string feNaturalBCName
double mU
magnetic constant N / A2
double ePsilon
regularization paramater
calculate and assemble CurlCurl matrix
MatrixDouble entityLocalMatrix
MoFEMErrorCode doWork(int row_side, int col_side, EntityType row_type, EntityType col_type, EntitiesFieldData::EntData &row_data, EntitiesFieldData::EntData &col_data)
integrate matrix
OpCurlCurl(BlockData &data)
calculate essential boundary conditions
OpNaturalBC(BlockData &data)
MoFEMErrorCode doWork(int row_side, EntityType row_type, EntitiesFieldData::EntData &row_data)
integrate matrix
calculate and assemble CurlCurl matrix
moab::Interface & postProcMesh
std::vector< EntityHandle > & mapGaussPts
OpPostProcessCurl(BlockData &data, moab::Interface &post_proc_mesh, std::vector< EntityHandle > &map_gauss_pts)
MoFEMErrorCode doWork(int row_side, EntityType row_type, EntitiesFieldData::EntData &row_data)
calculate and assemble stabilization matrix
MatrixDouble entityLocalMatrix
MoFEMErrorCode doWork(int row_side, int col_side, EntityType row_type, EntityType col_type, EntitiesFieldData::EntData &row_data, EntitiesFieldData::EntData &col_data)
integrate matrix
TriFE(MoFEM::Interface &m_field)
definition of volume element
VolumeFE(MoFEM::Interface &m_field)
Implementation of magneto-static problem (basic Implementation)
MoFEMErrorCode createFields()
build problem data structures
MoFEMErrorCode createElements()
create finite elements
MoFEMErrorCode destroyProblem()
destroy Distributed mesh manager
MoFEMErrorCode postProcessResults()
post-process results, i.e. save solution on the mesh
MoFEMErrorCode createProblem()
create problem
MoFEM::Interface & mField
MoFEMErrorCode getEssentialBc()
get essential boundary conditions (only homogenous case is considered)
MoFEMErrorCode getNaturalBc()
get natural boundary conditions
MagneticElement(MoFEM::Interface &m_field)
virtual ~MagneticElement()=default
MoFEMErrorCode solveProblem(const bool regression_test=false)
solve problem
virtual moab::Interface & get_moab()=0
virtual MoFEMErrorCode build_adjacencies(const Range &ents, int verb=DEFAULT_VERBOSITY)=0
build adjacencies
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.
Deprecated interface functions.
default operator for TRI element
std::string meshPositionsFieldName
boost::ptr_deque< UserDataOperator > & getOpPtrVector()
Use to push back operator for row operator.
Post post-proc data at points from hash maps.
keeps basic data about problem
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
Volume finite element base.
VolumeElementForcesAndSourcesCore(Interface &m_field)