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>();
326 CHKERR addHOOpsVol(
"MESH_NODE_POSITIONS", vol_fe,
false,
true,
false,
true);
333 new OpGetHONormalsOnFace(
"MESH_NODE_POSITIONS"));
335 new OpCalculateHOCoords(
"MESH_NODE_POSITIONS"));
337 new OpHOSetCovariantPiolaTransformOnFace3D(
HCURL));
349 ->createMPIAIJ<PetscGlobalIdx_mi_tag>(problem_ptr->
getName(),
370 CHKERR KSPCreate(PETSC_COMM_WORLD, &solver);
372 CHKERR KSPSetFromOptions(solver);
375 CHKERR KSPDestroy(&solver);
382 if (regression_test) {
386 const double expected_value = 4.6772e+01;
387 const double tol = 1e-4;
388 if ((nrm2 - expected_value) / expected_value >
tol) {
390 "Regression test failed %6.4e != %6.4e", nrm2, expected_value);
409 PostProcBrokenMeshInMoab<VolumeElementForcesAndSourcesCore> post_proc(
412 CHKERR addHOOpsVol(
"MESH_NODE_POSITIONS", post_proc,
false,
true,
false,
415 auto pos_ptr = boost::make_shared<MatrixDouble>();
416 auto field_val_ptr = boost::make_shared<MatrixDouble>();
418 post_proc.getOpPtrVector().push_back(
419 new OpCalculateVectorFieldValues<3>(
"MESH_NODE_POSITIONS", pos_ptr));
420 post_proc.getOpPtrVector().push_back(
423 using OpPPMap = OpPostProcMapInMoab<3, 3>;
425 post_proc.getOpPtrVector().push_back(
429 post_proc.getPostProcMesh(), post_proc.getMapGaussPts(),
433 {{
"MESH_NODE_POSITIONS", pos_ptr},
434 {blockData.fieldName, field_val_ptr}},
444 post_proc.getOpPtrVector().push_back(
new OpPostProcessCurl(
445 blockData, post_proc.getPostProcMesh(), post_proc.getMapGaussPts()));
448 CHKERR post_proc.writeFile(
"out_values.h5m");
491 EntitiesFieldData::EntData &row_data,
492 EntitiesFieldData::EntData &col_data) {
495 if (row_type == MBVERTEX)
497 if (col_type == MBVERTEX)
500 const int nb_row_dofs = row_data.getN().size2() / 3;
501 if (nb_row_dofs == 0)
503 const int nb_col_dofs = col_data.getN().size2() / 3;
504 if (nb_col_dofs == 0)
506 entityLocalMatrix.resize(nb_row_dofs, nb_col_dofs,
false);
507 entityLocalMatrix.clear();
509 if (nb_row_dofs !=
static_cast<int>(row_data.getFieldData().size())) {
511 "Number of base functions and DOFs on entity is different on "
513 nb_row_dofs, row_data.getFieldData().size());
515 if (nb_col_dofs !=
static_cast<int>(col_data.getFieldData().size())) {
518 "Number of base functions and DOFs on entity is different on cols",
519 nb_col_dofs, col_data.getFieldData().size());
522 MatrixDouble row_curl_mat, col_curl_mat;
527 const double c0 = 1. / blockData.
mU;
528 const int nb_gauss_pts = row_data.getN().size1();
529 auto t_row_curl_base = row_data.getFTensor2DiffN<3, 3>();
531 for (
int gg = 0; gg != nb_gauss_pts; gg++) {
534 double w = getGaussPts()(3, gg) * getVolume();
537 for (
int aa = 0; aa != nb_row_dofs; aa++) {
538 t_row_curl(
i) = levi_civita(
j,
i,
k) * t_row_curl_base(
j,
k);
543 auto t_col_curl_base = col_data.getFTensor2DiffN<3, 3>(gg, 0);
544 for (
int bb = 0; bb != nb_col_dofs; bb++) {
545 t_col_curl(
i) = levi_civita(
j,
i,
k) * t_col_curl_base(
j,
k);
546 t_local_mat += c0 * w * t_row_curl(
i) * t_col_curl(
i);
555 CHKERR MatSetValues(blockData.
A, nb_row_dofs, &row_data.getIndices()[0],
556 nb_col_dofs, &col_data.getIndices()[0],
557 &entityLocalMatrix(0, 0), ADD_VALUES);
559 if (row_side != col_side || row_type != col_type) {
560 entityLocalMatrix = trans(entityLocalMatrix);
561 CHKERR MatSetValues(blockData.
A, nb_col_dofs, &col_data.getIndices()[0],
562 nb_row_dofs, &row_data.getIndices()[0],
563 &entityLocalMatrix(0, 0), ADD_VALUES);
605 EntitiesFieldData::EntData &row_data,
606 EntitiesFieldData::EntData &col_data) {
609 if (row_type == MBVERTEX)
611 if (col_type == MBVERTEX)
614 const int nb_row_dofs = row_data.getN().size2() / 3;
615 if (nb_row_dofs == 0)
617 const int nb_col_dofs = col_data.getN().size2() / 3;
618 if (nb_col_dofs == 0)
620 entityLocalMatrix.resize(nb_row_dofs, nb_col_dofs,
false);
621 entityLocalMatrix.clear();
623 if (nb_row_dofs !=
static_cast<int>(row_data.getFieldData().size())) {
625 "Number of base functions and DOFs on entity is different on "
627 nb_row_dofs, row_data.getFieldData().size());
629 if (nb_col_dofs !=
static_cast<int>(col_data.getFieldData().size())) {
632 "Number of base functions and DOFs on entity is different on cols",
633 nb_col_dofs, col_data.getFieldData().size());
636 MatrixDouble row_curl_mat, col_curl_mat;
639 const double c0 = 1. / blockData.
mU;
640 const double c1 = blockData.
ePsilon * c0;
641 const int nb_gauss_pts = row_data.getN().size1();
643 for (
int gg = 0; gg != nb_gauss_pts; gg++) {
646 double w = getGaussPts()(3, gg) * getVolume();
649 &row_data.getVectorN<3>(gg)(0,
HVEC0),
650 &row_data.getVectorN<3>(gg)(0,
HVEC1),
651 &row_data.getVectorN<3>(gg)(0,
HVEC2), 3);
653 for (
int aa = 0; aa != nb_row_dofs; aa++) {
656 &col_data.getVectorN<3>(gg)(0,
HVEC0),
657 &col_data.getVectorN<3>(gg)(0,
HVEC1),
658 &col_data.getVectorN<3>(gg)(0,
HVEC2), 3);
659 for (
int bb = 0; bb != nb_col_dofs; bb++) {
660 t_local_mat += c1 * w * t_row_base(
i) * t_col_base(
i);
671 CHKERR MatSetValues(blockData.
A, nb_row_dofs, &row_data.getIndices()[0],
672 nb_col_dofs, &col_data.getIndices()[0],
673 &entityLocalMatrix(0, 0), ADD_VALUES);
675 if (row_side != col_side || row_type != col_type) {
676 entityLocalMatrix = trans(entityLocalMatrix);
677 CHKERR MatSetValues(blockData.
A, nb_col_dofs, &col_data.getIndices()[0],
678 nb_row_dofs, &row_data.getIndices()[0],
679 &entityLocalMatrix(0, 0), ADD_VALUES);
720 EntitiesFieldData::EntData &row_data) {
723 if (row_type == MBVERTEX)
726 const int nb_row_dofs = row_data.getN().size2() / 3;
727 if (nb_row_dofs == 0)
729 naturalBC.resize(nb_row_dofs,
false);
734 const int nb_gauss_pts = row_data.getN().size1();
735 auto t_row_base = row_data.getFTensor1N<3>();
737 for (
int gg = 0; gg != nb_gauss_pts; gg++) {
741 area = norm_2(getNormalsAtGaussPts(gg)) * 0.5;
742 double w = getGaussPts()(2, gg) * area;
746 const double x = getCoordsAtGaussPts()(gg, 0);
747 const double y = getCoordsAtGaussPts()(gg, 1);
748 const double r = sqrt(x * x + y * y);
762 for (
int aa = 0; aa != nb_row_dofs; aa++) {
763 t_f += w * t_row_base(
i) * t_j(
i);
769 CHKERR VecSetValues(blockData.
F, row_data.getIndices().size(),
770 &row_data.getIndices()[0], &naturalBC[0], ADD_VALUES);
787 std::vector<EntityHandle> &map_gauss_pts)
790 blockData(data), postProcMesh(post_proc_mesh),
791 mapGaussPts(map_gauss_pts) {}
794 EntitiesFieldData::EntData &row_data) {
797 if (row_type == MBVERTEX)
801 double def_val[] = {0, 0, 0};
802 CHKERR postProcMesh.tag_get_handle(
"MAGNETIC_INDUCTION_FIELD", 3,
804 MB_TAG_CREAT | MB_TAG_SPARSE, def_val);
805 const int nb_row_dofs = row_data.getN().size2() / 3;
806 if (nb_row_dofs == 0)
808 const void *tags_ptr[mapGaussPts.size()];
810 if (nb_row_dofs != row_data.getFieldData().size())
812 "Wrong number of base functions and DOFs %d != %d",
813 nb_row_dofs, row_data.getFieldData().size());
818 const int nb_gauss_pts = row_data.getN().size1();
819 if (nb_gauss_pts !=
static_cast<int>(mapGaussPts.size())) {
821 "Inconsistency number of dofs %d!=%d", nb_gauss_pts,
824 CHKERR postProcMesh.tag_get_by_ptr(th, &mapGaussPts[0],
825 mapGaussPts.size(), tags_ptr);
826 auto t_curl_base = row_data.getFTensor2DiffN<3, 3>();
827 for (
int gg = 0; gg != nb_gauss_pts; gg++) {
830 double *ptr = &((
double *)tags_ptr[gg])[0];
834 auto t_dof = row_data.getFTensor0FieldData();
835 for (
int aa = 0; aa != nb_row_dofs; aa++) {
836 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_data(const std::string &fe_name, const std::string name_filed)=0
set finite element field data
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 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_vector< 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 refernce to pointer of interface.
Volume finite element base.
VolumeElementForcesAndSourcesCore(Interface &m_field, const EntityType type=MBTET)