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();
double vol = 0;
for (int gg = 0; gg != nb_int_pts; gg++) {
++t_w;
}
CHKERR VecSetValue(vOl, 0, vol, ADD_VALUES);
}
MoFEMErrorCode doWork(
int row_side,
int col_side, EntityType row_type,
EntityType col_type,
}
};
vOl(vol) {}
const int nb_int_pts = getGaussPts().size2();
auto t_normal = getFTensor1NormalsAtGaussPts();
auto t_w = getFTensor0IntegrationWeight();
auto t_coords = getFTensor1CoordsAtGaussPts();
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";
{
auto dm = simple_interface->
getDM();
auto domain_fe =
boost::make_shared<VolumeElementForcesAndSourcesCore>(m_field);
auto boundary_fe =
boost::make_shared<FaceElementForcesAndSourcesCore>(m_field);
domain_fe->getRuleHook =
VolRule();
int ghosts[] = {0};
auto material_grad_mat = boost::make_shared<MatrixDouble>();
auto material_det_vec = boost::make_shared<VectorDouble>();
domain_fe->getOpPtrVector().push_back(
material_grad_mat));
material_grad_mat, material_det_vec, nullptr));
domain_fe->getOpPtrVector().push_back(
domain_fe->getOpPtrVector().push_back(
domain_fe->getOpPtrVector().push_back(
new OpVolume(
"MESH_NODE_POSITIONS", vol));
boundary_fe->getOpPtrVector().push_back(
boundary_fe->getOpPtrVector().push_back(
new OpFace(
"MESH_NODE_POSITIONS", surf_vol));
domain_fe);
boundary_fe);
auto skeleton_fe = boost::make_shared<FEMethod>();
skeleton_fe->B = B;
skeleton_fe->x = x;
skeleton_fe->x_t = x_t;
skeleton_fe->x_tt = x_tt;
skeleton_fe->preProcessHook = [&]() {
if (
f != skeleton_fe->ts_F)
if (
A != skeleton_fe->ts_A)
if (B != skeleton_fe->ts_B)
if (x != skeleton_fe->ts_u)
if (x_t != skeleton_fe->ts_u_t)
if (x_tt != skeleton_fe->ts_u_tt)
};
skeleton_fe->postProcessHook = []() { return 0; };
skeleton_fe->operatorHook = []() { return 0; };
skeleton_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;
}