v0.14.0
edge_and_bubble_shape_functions_on_quad.cpp

Testing edge and bubble shape functions on a quad face

/** \file edge_and_bubble_shape_functions_on_quad.cpp
\example edge_and_bubble_shape_functions_on_quad.cpp
\brief Testing edge and bubble shape functions on a quad face
*/
#include <MoFEM.hpp>
using namespace MoFEM;
static char help[] = "...\n\n";
static double sum_matrix(MatrixDouble &m) {
double s = 0;
for (unsigned int ii = 0; ii < m.size1(); ii++) {
for (unsigned int jj = 0; jj < m.size2(); jj++) {
s += std::abs(m(ii, jj));
}
}
return s;
}
int main(int argc, char *argv[]) {
MoFEM::Core::Initialize(&argc, &argv, (char *)0, help);
try {
moab::Core mb_instance;
moab::Interface &moab = mb_instance;
MoFEM::Core core(moab);
PetscBool flg = PETSC_TRUE;
char mesh_file_name[255];
#if PETSC_VERSION_GE(3, 6, 4)
CHKERR PetscOptionsGetString(PETSC_NULL, "", "-my_file", mesh_file_name,
255, &flg);
#else
CHKERR PetscOptionsGetString(PETSC_NULL, PETSC_NULL, "-my_file",
mesh_file_name, 255, &flg);
#endif
if (flg != PETSC_TRUE) {
SETERRQ(PETSC_COMM_SELF, 1, "Error -my_file (mesh file needed)");
}
const char *option;
option = "";
CHKERR moab.load_file(mesh_file_name, 0, option);
Range verts;
CHKERR moab.get_entities_by_type(0, MBVERTEX, verts, true);
MatrixDouble coords(verts.size(), 3);
MatrixDouble N(verts.size(), 4);
MatrixDouble diffN(verts.size(), 8);
CHKERR moab.get_coords(verts, &coords(0, 0));
for (int i = 0; i < verts.size(); ++i) {
N(i, 0) = N_MBQUAD0(coords(i, 0), coords(i, 1));
N(i, 1) = N_MBQUAD1(coords(i, 0), coords(i, 1));
N(i, 2) = N_MBQUAD2(coords(i, 0), coords(i, 1));
N(i, 3) = N_MBQUAD3(coords(i, 0), coords(i, 1));
diffN(i, 0) = diffN_MBQUAD0x(coords(i, 1));
diffN(i, 1) = diffN_MBQUAD0y(coords(i, 0));
diffN(i, 2) = diffN_MBQUAD1x(coords(i, 1));
diffN(i, 3) = diffN_MBQUAD1y(coords(i, 0));
diffN(i, 4) = diffN_MBQUAD2x(coords(i, 1));
diffN(i, 5) = diffN_MBQUAD2y(coords(i, 0));
diffN(i, 6) = diffN_MBQUAD3x(coords(i, 1));
diffN(i, 7) = diffN_MBQUAD3y(coords(i, 0));
}
/* BUBBLES */
{
std::array<int, 4> faces_nodes = {0, 1, 2, 3};
int p = 7;
int P = NBFACEQUAD_H1(p);
MatrixDouble quad_bubbles(verts.size(), P);
MatrixDouble quad_diff_bubbles(verts.size(), P * 2);
constexpr double eps = 1e-4;
double quad_bubbles_sum = 3.275491e+01;
double quad_diff_bubbles_sum = 5.838131e+02;
faces_nodes.data(), p, &*N.data().begin(), &*diffN.data().begin(),
&*quad_bubbles.data().begin(), &*quad_diff_bubbles.data().begin(),
verts.size(), Legendre_polynomials);
if (std::abs(quad_bubbles_sum - sum_matrix(quad_bubbles)) > eps) {
SETERRQ1(PETSC_COMM_WORLD, MOFEM_ATOM_TEST_INVALID,
"wrong result = %8.6e", sum_matrix(quad_bubbles));
}
if (std::abs(quad_diff_bubbles_sum - sum_matrix(quad_diff_bubbles)) >
eps) {
SETERRQ1(PETSC_COMM_WORLD, MOFEM_ATOM_TEST_INVALID,
"wrong result = %8.6e", sum_matrix(quad_diff_bubbles));
}
}
/* EDGES */
{
int sense[] = {1, -1, 1, -1};
int p[] = {3, 4, 5, 6};
int P[4];
int ee = 0;
for (; ee < 4; ee++) {
P[ee] = NBEDGE_H1(p[ee]);
}
double *quad_edges_ptr[4];
std::array<MatrixDouble, 4> quad_edges;
for (auto ee : {0, 1, 2, 3}) {
quad_edges[ee] = MatrixDouble(verts.size(), P[ee]);
quad_edges_ptr[ee] = &quad_edges[ee](0, 0);
}
double *quad_diff_edges_ptr[4];
std::array<MatrixDouble, 4> quad_diff_edges;
for (auto ee : {0, 1, 2, 3}) {
quad_diff_edges[ee] = MatrixDouble(verts.size(), P[ee] * 2);
quad_diff_edges_ptr[ee] = &quad_diff_edges[ee](0, 0);
}
double eps = 1e-4;
double quad_edges_sum[] = {1.237500e+01, 1.535050e+01, 1.781890e+01,
2.015678e+01};
double quad_diff_edges_sum[] = {8.470000e+01, 1.192510e+02, 1.580128e+02,
1.976378e+02};
sense, p, &*N.data().begin(), &*diffN.data().begin(), quad_edges_ptr,
quad_diff_edges_ptr, verts.size(), Legendre_polynomials);
for (int ee = 0; ee < 4; ++ee) {
if (std::abs(quad_edges_sum[ee] - sum_matrix(quad_edges[ee])) > eps)
SETERRQ2(PETSC_COMM_WORLD, MOFEM_ATOM_TEST_INVALID,
"edge %d wrong result = %8.6e", ee,
sum_matrix(quad_edges[ee]));
if (std::abs(quad_diff_edges_sum[ee] -
sum_matrix(quad_diff_edges[ee])) > eps)
SETERRQ2(PETSC_COMM_WORLD, MOFEM_ATOM_TEST_INVALID,
"edge %d wrong result = %8.6e", ee,
sum_matrix(quad_diff_edges[ee]));
}
}
}
}
MoFEM::CoreTmp< 0 >
Core (interface) class.
Definition: Core.hpp:82
NBEDGE_H1
#define NBEDGE_H1(P)
Number of base function on edge for H1 space.
Definition: h1_hdiv_hcurl_l2.h:55
diffN_MBQUAD1x
#define diffN_MBQUAD1x(y)
Definition: fem_tools.h:63
H1_EdgeShapeFunctions_MBQUAD
PetscErrorCode H1_EdgeShapeFunctions_MBQUAD(int *sense, int *p, double *N, double *diffN, double *edgeN[4], double *diff_edgeN[4], int GDIM, PetscErrorCode(*base_polynomials)(int p, double s, double *diff_s, double *L, double *diffL, const int dim))
Definition: h1.c:1091
diffN_MBQUAD1y
#define diffN_MBQUAD1y(x)
Definition: fem_tools.h:64
MoFEM::Types::MatrixDouble
UBlasMatrix< double > MatrixDouble
Definition: Types.hpp:77
H1_QuadShapeFunctions_MBQUAD
PetscErrorCode H1_QuadShapeFunctions_MBQUAD(int *faces_nodes, int p, double *N, double *diffN, double *faceN, double *diff_faceN, int GDIM, PetscErrorCode(*base_polynomials)(int p, double s, double *diff_s, double *L, double *diffL, const int dim))
Definition: h1.c:959
diffN_MBQUAD2x
#define diffN_MBQUAD2x(y)
Definition: fem_tools.h:65
MoFEM.hpp
help
static char help[]
Definition: edge_and_bubble_shape_functions_on_quad.cpp:10
MoFEM::CoreTmp< 0 >::Finalize
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition: Core.cpp:112
N_MBQUAD2
#define N_MBQUAD2(x, y)
quad shape function
Definition: fem_tools.h:59
MoFEM::Interface
DeprecatedCoreInterface Interface
Definition: Interface.hpp:2010
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:548
diffN_MBQUAD3x
#define diffN_MBQUAD3x(y)
Definition: fem_tools.h:67
MoFEM
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:10
EshelbianPlasticity::P
@ P
Definition: EshelbianContact.cpp:197
N_MBQUAD1
#define N_MBQUAD1(x, y)
quad shape function
Definition: fem_tools.h:58
diffN_MBQUAD2y
#define diffN_MBQUAD2y(x)
Definition: fem_tools.h:66
Legendre_polynomials
PetscErrorCode Legendre_polynomials(int p, double s, double *diff_s, double *L, double *diffL, const int dim)
Calculate Legendre approximation basis.
Definition: base_functions.c:15
NBFACEQUAD_H1
#define NBFACEQUAD_H1(P)
Number of base functions on quad for H1 space.
Definition: h1_hdiv_hcurl_l2.h:65
diffN_MBQUAD0x
#define diffN_MBQUAD0x(y)
Definition: fem_tools.h:61
i
FTensor::Index< 'i', SPACE_DIM > i
Definition: hcurl_divergence_operator_2d.cpp:27
diffN_MBQUAD0y
#define diffN_MBQUAD0y(x)
Definition: fem_tools.h:62
diffN_MBQUAD3y
#define diffN_MBQUAD3y(x)
Definition: fem_tools.h:68
mesh_file_name
char mesh_file_name[255]
Definition: mesh_smoothing.cpp:22
N
const int N
Definition: speed_test.cpp:3
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
CATCH_ERRORS
#define CATCH_ERRORS
Catch errors.
Definition: definitions.h:385
MoFEM::Core
CoreTmp< 0 > Core
Definition: Core.hpp:1148
eps
static const double eps
Definition: check_base_functions_derivatives_on_tet.cpp:11
N_MBQUAD0
#define N_MBQUAD0(x, y)
quad shape function
Definition: fem_tools.h:57
MoFEM::PetscOptionsGetString
PetscErrorCode PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)
Definition: DeprecatedPetsc.hpp:172
m
FTensor::Index< 'm', 3 > m
Definition: shallow_wave.cpp:80
N_MBQUAD3
#define N_MBQUAD3(x, y)
quad shape function
Definition: fem_tools.h:60
MOFEM_ATOM_TEST_INVALID
@ MOFEM_ATOM_TEST_INVALID
Definition: definitions.h:40
sum_matrix
static double sum_matrix(MatrixDouble &m)
Definition: edge_and_bubble_shape_functions_on_quad.cpp:12
main
int main(int argc, char *argv[])
Definition: edge_and_bubble_shape_functions_on_quad.cpp:22