11 using namespace boost::numeric;
20 int nb_gauss_pts = data.
getN().size1();
23 commonData.gradAtGaussPts.resize(nb_gauss_pts, 3);
24 if (
type == MBVERTEX) {
25 std::fill(commonData.gradAtGaussPts.data().begin(),
26 commonData.gradAtGaussPts.data().end(), 0);
29 for (
int gg = 0; gg < nb_gauss_pts; gg++) {
30 ublas::noalias(commonData.getGradAtGaussPts(gg)) +=
42 if (dAta.tEts.find(getNumeredEntFiniteElementPtr()->getEnt()) ==
50 Nf.resize(nb_row_dofs);
53 for (
unsigned int gg = 0; gg < data.
getN().size1(); gg++) {
56 dAta.cOnductivity_mat * getVolume() * getGaussPts()(3, gg);
59 ublas::noalias(Nf) += prod(prod(data.
getDiffN(gg, nb_row_dofs), val),
60 commonData.getGradAtGaussPts(gg));
75 int row_side,
int col_side, EntityType row_type, EntityType col_type,
80 if (dAta.tEts.find(getNumeredEntFiniteElementPtr()->getEnt()) ==
90 int nb_row = row_data.
getN().size2();
91 int nb_col = col_data.
getN().size2();
92 K.resize(nb_row, nb_col);
94 for (
unsigned int gg = 0; gg < row_data.
getN().size1(); gg++) {
97 dAta.cOnductivity_mat * getVolume() * getGaussPts()(3, gg);
101 noalias(
K) += prod(K1, trans(col_data.
getDiffN(gg, nb_col)));
105 const_cast<FEMethod *
>(getFEMethod())->ts_B =
A;
108 nb_col, &col_data.
getIndices()[0], &
K(0, 0), ADD_VALUES);
109 if (row_side != col_side || row_type != col_type) {
110 transK.resize(nb_col, nb_row);
111 noalias(transK) = trans(
K);
114 &row_data.
getIndices()[0], &transK(0, 0), ADD_VALUES);
124 if (dAta.tEts.find(getNumeredEntFiniteElementPtr()->getEnt()) ==
131 int nb_row = data.
getN().size2();
134 for (
unsigned int gg = 0; gg < data.
getN().size1(); gg++) {
135 double val = getGaussPts()(3, gg);
136 val *= commonData.temperatureRateAtGaussPts[gg];
141 ublas::noalias(Nf) += val * data.
getN(gg);
143 Nf *= getVolume() * dAta.cApacity;
152 int row_side,
int col_side, EntityType row_type, EntityType col_type,
157 if (dAta.tEts.find(getNumeredEntFiniteElementPtr()->getEnt()) ==
167 int nb_row = row_data.
getN().size2();
168 int nb_col = col_data.
getN().size2();
169 M.resize(nb_row, nb_col);
172 for (
unsigned int gg = 0; gg < row_data.
getN().size1(); gg++) {
174 double val = getGaussPts()(3, gg);
178 val * outer_prod(row_data.
getN(gg, nb_row), col_data.
getN(gg, nb_col));
181 M *= getVolume() * dAta.cApacity * getFEMethod()->ts_a;
184 nb_col, &col_data.
getIndices()[0], &
M(0, 0), ADD_VALUES);
185 if (row_side != col_side || row_type != col_type) {
186 transM.resize(nb_col, nb_row);
187 noalias(transM) = trans(
M);
190 &row_data.
getIndices()[0], &transM(0, 0), ADD_VALUES);
201 if (dAta.tRis.find(getNumeredEntFiniteElementPtr()->getEnt()) ==
209 int rank = dof_ptr->getNbOfCoeffs();
211 int nb_dofs = data.
getIndices().size() / rank;
216 for (
unsigned int gg = 0; gg < data.
getN().size1(); gg++) {
218 double val = getGaussPts()(2, gg);
221 const double area = norm_2(getNormalsAtGaussPts(gg)) * 0.5;
222 flux = dAta.dAta.data.value1 * area;
224 flux = dAta.dAta.data.value1 * getArea();
226 ublas::noalias(Nf) += val * flux * data.
getN(gg, nb_dofs);
229 if (useTsF ||
F == PETSC_NULL) {
241 int row_side,
int col_side, EntityType row_type, EntityType col_type,
246 if (dAta.tRis.find(getNumeredEntFiniteElementPtr()->getEnt()) ==
256 int nb_row = row_data.
getN().size2();
257 int nb_col = col_data.
getN().size2();
259 N.resize(nb_row, nb_col);
262 for (
unsigned int gg = 0; gg < row_data.
getN().size1(); gg++) {
263 double T3_at_Gauss_pt = pow(commonData.temperatureAtGaussPts[gg], 3.0);
265 double radiationConst;
267 double area = norm_2(getNormalsAtGaussPts(gg)) * 0.5;
268 radiationConst = dAta.sIgma * dAta.eMissivity * area;
270 radiationConst = dAta.sIgma * dAta.eMissivity * getArea();
272 const double fOur = 4.0;
273 double val = fOur * getGaussPts()(2, gg) * radiationConst * T3_at_Gauss_pt;
275 val * outer_prod(row_data.
getN(gg, nb_row), col_data.
getN(gg, nb_col));
279 const_cast<FEMethod *
>(getFEMethod())->ts_B =
A;
282 nb_col, &col_data.
getIndices()[0], &
N(0, 0), ADD_VALUES);
283 if (row_side != col_side || row_type != col_type) {
284 transN.resize(nb_col, nb_row);
285 noalias(transN) = trans(
N);
288 &row_data.
getIndices()[0], &transN(0, 0), ADD_VALUES);
298 if (dAta.tRis.find(getNumeredEntFiniteElementPtr()->getEnt()) ==
306 int rank = dof_ptr->getNbOfCoeffs();
307 int nb_row_dofs = data.
getIndices().size() / rank;
312 for (
unsigned int gg = 0; gg < data.
getN().size1(); gg++) {
314 double T4_at_Gauss_pt = pow(commonData.temperatureAtGaussPts[gg], 4.0);
315 double ambientTemp = pow(dAta.aMbienttEmp, 4.0);
318 if (ambientTemp > 0) {
319 tEmp = -ambientTemp + T4_at_Gauss_pt;
322 double val = getGaussPts()(2, gg);
323 double radiationConst;
326 double area = norm_2(getNormalsAtGaussPts(gg)) * 0.5;
327 radiationConst = dAta.sIgma * dAta.eMissivity * tEmp * area;
329 radiationConst = dAta.sIgma * dAta.eMissivity * tEmp * getArea();
331 ublas::noalias(Nf) += val * radiationConst * data.
getN(gg, nb_row_dofs);
349 if (dAta.tRis.find(getNumeredEntFiniteElementPtr()->getEnt()) ==
357 int rank = dof_ptr->getNbOfCoeffs();
359 int nb_row_dofs = data.
getIndices().size() / rank;
364 for (
unsigned int gg = 0; gg < data.
getN().size1(); gg++) {
366 double T_at_Gauss_pt = commonData.temperatureAtGaussPts[gg];
367 double convectionConst;
369 double area = norm_2(getNormalsAtGaussPts(gg)) * 0.5;
371 dAta.cOnvection * area * (T_at_Gauss_pt - dAta.tEmperature);
374 dAta.cOnvection * getArea() * (T_at_Gauss_pt - dAta.tEmperature);
376 double val = getGaussPts()(2, gg) * convectionConst;
377 ublas::noalias(Nf) += val * data.
getN(gg, nb_row_dofs);
392 int row_side,
int col_side, EntityType row_type, EntityType col_type,
397 if (dAta.tRis.find(getNumeredEntFiniteElementPtr()->getEnt()) ==
406 int nb_row = row_data.
getN().size2();
407 int nb_col = col_data.
getN().size2();
408 K.resize(nb_row, nb_col);
411 for (
unsigned int gg = 0; gg < row_data.
getN().size1(); gg++) {
413 double convectionConst;
415 double area = norm_2(getNormalsAtGaussPts(gg)) * 0.5;
416 convectionConst = dAta.cOnvection * area;
418 convectionConst = dAta.cOnvection * getArea();
420 double val = getGaussPts()(2, gg) * convectionConst;
422 val * outer_prod(row_data.
getN(gg, nb_row), col_data.
getN(gg, nb_col));
426 const_cast<FEMethod *
>(getFEMethod())->ts_B =
A;
429 nb_col, &col_data.
getIndices()[0], &
K(0, 0), ADD_VALUES);
430 if (row_side != col_side || row_type != col_type) {
431 transK.resize(nb_col, nb_row);
432 noalias(transK) = trans(
K);
435 &row_data.
getIndices()[0], &transK(0, 0), ADD_VALUES);
444 problemPtr, tempName, rateName,
ROW, ts_u_t, INSERT_VALUES,
458 problemPtr,
ROW, ts_u, INSERT_VALUES, SCATTER_REVERSE);
460 BitRefLevel proble_bit_level = problemPtr->getBitRefLevel();
463 CHKERR mField.getInterface(recorder_ptr);
469 auto post_proc_at_points = [&](std::array<double, 3> point,
int num) {
472 dataFieldEval->setEvalPoints(point.data(), point.size() / 3);
474 struct OpPrint :
public VolOp {
476 std::array<double, 3> pointCoords;
478 boost::shared_ptr<VectorDouble> tempPtr;
480 OpPrint(boost::shared_ptr<VectorDouble> temp_ptr,
481 std::array<double, 3> &point_coords,
int point_num)
483 pointCoords(point_coords), pointNum(point_num) {}
488 if (
type == MBVERTEX) {
489 if (getGaussPts().size2()) {
494 <<
"Pnt: " << std::to_string(pointNum)
503 if (
auto fe_ptr = dataFieldEval->feMethodPtr.lock()) {
504 fe_ptr->getOpPtrVector().push_back(
new OpPrint(tempPtr, point, num));
506 point.data(), 1e-12,
"DMTHERMAL",
"THERMAL_FE", dataFieldEval,
507 mField.get_comm_rank(), mField.get_comm_rank(),
nullptr,
MF_EXIST,
509 fe_ptr->getOpPtrVector().pop_back();
515 if (!evalPoints.empty()) {
517 for (
auto p : evalPoints)
518 CHKERR post_proc_at_points(p, num++);
528 const std::string mesh_nodals_positions) {
532 CHKERR mField.modify_finite_element_add_field_row(
"THERMAL_FE",
field_name);
533 CHKERR mField.modify_finite_element_add_field_col(
"THERMAL_FE",
field_name);
534 CHKERR mField.modify_finite_element_add_field_data(
"THERMAL_FE",
field_name);
535 if (mField.check_field(mesh_nodals_positions)) {
536 CHKERR mField.modify_finite_element_add_field_data(
"THERMAL_FE",
537 mesh_nodals_positions);
547 ierr = it->getAttributeDataStructure(temp_data);
549 setOfBlocks[it->getMeshsetId()].cOnductivity_mat.resize(
551 setOfBlocks[it->getMeshsetId()].cOnductivity_mat.clear();
552 setOfBlocks[it->getMeshsetId()].cOnductivity_mat(0, 0) =
553 temp_data.
data.Conductivity;
554 setOfBlocks[it->getMeshsetId()].cOnductivity_mat(1, 1) =
555 temp_data.
data.Conductivity;
556 setOfBlocks[it->getMeshsetId()].cOnductivity_mat(2, 2) =
557 temp_data.
data.Conductivity;
560 setOfBlocks[it->getMeshsetId()].cApacity = temp_data.
data.HeatCapacity;
561 if (temp_data.
data.User2 != 0) {
562 setOfBlocks[it->getMeshsetId()].initTemp = temp_data.
data.User2;
564 CHKERR mField.get_moab().get_entities_by_type(
565 it->meshset, MBTET, setOfBlocks[it->getMeshsetId()].tEts,
true);
566 CHKERR mField.add_ents_to_finite_element_by_type(
567 setOfBlocks[it->getMeshsetId()].tEts, MBTET,
"THERMAL_FE");
575 const std::string mesh_nodals_positions) {
578 CHKERR mField.add_finite_element(
"THERMAL_FLUX_FE",
MF_ZERO);
579 CHKERR mField.modify_finite_element_add_field_row(
"THERMAL_FLUX_FE",
581 CHKERR mField.modify_finite_element_add_field_col(
"THERMAL_FLUX_FE",
583 CHKERR mField.modify_finite_element_add_field_data(
"THERMAL_FLUX_FE",
585 if (mField.check_field(mesh_nodals_positions)) {
586 CHKERR mField.modify_finite_element_add_field_data(
"THERMAL_FLUX_FE",
587 mesh_nodals_positions);
592 CHKERR it->getBcDataStructure(setOfFluxes[it->getMeshsetId()].dAta);
593 CHKERR mField.get_moab().get_entities_by_type(
594 it->meshset, MBTRI, setOfFluxes[it->getMeshsetId()].tRis,
true);
595 CHKERR mField.add_ents_to_finite_element_by_type(
596 setOfFluxes[it->getMeshsetId()].tRis, MBTRI,
"THERMAL_FLUX_FE");
602 if (std::regex_match(it->getName(), std::regex(
"(.*)HEAT_FLUX(.*)"))) {
603 std::vector<double> data;
604 CHKERR it->getAttributes(data);
605 if (data.size() != 1) {
606 SETERRQ(PETSC_COMM_SELF, 1,
"Data inconsistency");
608 strcpy(setOfFluxes[it->getMeshsetId()].dAta.data.name,
"HeatFlu");
609 setOfFluxes[it->getMeshsetId()].dAta.data.flag1 = 1;
610 setOfFluxes[it->getMeshsetId()].dAta.data.value1 = data[0];
611 CHKERR mField.get_moab().get_entities_by_type(
612 it->meshset, MBTRI, setOfFluxes[it->getMeshsetId()].tRis,
true);
613 CHKERR mField.add_ents_to_finite_element_by_type(
614 setOfFluxes[it->getMeshsetId()].tRis, MBTRI,
"THERMAL_FLUX_FE");
622 const std::string
field_name,
const std::string mesh_nodals_positions) {
625 CHKERR mField.add_finite_element(
"THERMAL_CONVECTION_FE",
MF_ZERO);
626 CHKERR mField.modify_finite_element_add_field_row(
"THERMAL_CONVECTION_FE",
628 CHKERR mField.modify_finite_element_add_field_col(
"THERMAL_CONVECTION_FE",
630 CHKERR mField.modify_finite_element_add_field_data(
"THERMAL_CONVECTION_FE",
632 if (mField.check_field(mesh_nodals_positions)) {
633 CHKERR mField.modify_finite_element_add_field_data(
"THERMAL_CONVECTION_FE",
634 mesh_nodals_positions);
640 if (std::regex_match(it->getName(), std::regex(
"(.*)CONVECTION(.*)"))) {
641 std::vector<double> data;
642 CHKERR it->getAttributes(data);
643 if (data.size() != 2) {
644 SETERRQ(PETSC_COMM_SELF, 1,
"Data inconsistency");
646 setOfConvection[it->getMeshsetId()].cOnvection = data[0];
647 setOfConvection[it->getMeshsetId()].tEmperature = data[1];
648 CHKERR mField.get_moab().get_entities_by_type(
649 it->meshset, MBTRI, setOfConvection[it->getMeshsetId()].tRis,
true);
650 CHKERR mField.add_ents_to_finite_element_by_type(
651 setOfConvection[it->getMeshsetId()].tRis, MBTRI,
652 "THERMAL_CONVECTION_FE");
660 const std::string
field_name,
const std::string mesh_nodals_positions) {
663 CHKERR mField.add_finite_element(
"THERMAL_RADIATION_FE",
MF_ZERO);
664 CHKERR mField.modify_finite_element_add_field_row(
"THERMAL_RADIATION_FE",
666 CHKERR mField.modify_finite_element_add_field_col(
"THERMAL_RADIATION_FE",
668 CHKERR mField.modify_finite_element_add_field_data(
"THERMAL_RADIATION_FE",
670 if (mField.check_field(mesh_nodals_positions)) {
671 CHKERR mField.modify_finite_element_add_field_data(
"THERMAL_RADIATION_FE",
672 mesh_nodals_positions);
678 if (std::regex_match(it->getName(), std::regex(
"(.*)RADIATION(.*)"))) {
679 std::vector<double> data;
680 ierr = it->getAttributes(data);
681 if (data.size() != 3) {
682 SETERRQ(PETSC_COMM_SELF, 1,
"Data inconsistency");
684 setOfRadiation[it->getMeshsetId()].sIgma = data[0];
685 setOfRadiation[it->getMeshsetId()].eMissivity = data[1];
686 setOfRadiation[it->getMeshsetId()].aMbienttEmp = data[2];
687 CHKERR mField.get_moab().get_entities_by_type(
688 it->meshset, MBTRI, setOfRadiation[it->getMeshsetId()].tRis,
true);
689 CHKERR mField.add_ents_to_finite_element_by_type(
690 setOfRadiation[it->getMeshsetId()].tRis, MBTRI,
691 "THERMAL_RADIATION_FE");
701 std::map<int, BlockData>::iterator sit = setOfBlocks.begin();
702 feRhs.getOpPtrVector().push_back(
704 for (; sit != setOfBlocks.end(); sit++) {
706 feRhs.getOpPtrVector().push_back(
715 std::map<int, BlockData>::iterator sit = setOfBlocks.begin();
716 for (; sit != setOfBlocks.end(); sit++) {
718 feLhs.getOpPtrVector().push_back(
725 string field_name,
Vec &
F,
const std::string mesh_nodals_positions) {
727 bool hoGeometry =
false;
728 if (mField.check_field(mesh_nodals_positions)) {
731 std::map<int, FluxData>::iterator sit = setOfFluxes.begin();
732 for (; sit != setOfFluxes.end(); sit++) {
734 feFlux.getOpPtrVector().push_back(
741 string field_name,
Vec &
F,
const std::string mesh_nodals_positions) {
743 bool hoGeometry =
false;
744 if (mField.check_field(mesh_nodals_positions)) {
747 std::map<int, ConvectionData>::iterator sit = setOfConvection.begin();
748 for (; sit != setOfConvection.end(); sit++) {
750 feConvectionRhs.getOpPtrVector().push_back(
753 field_name,
F, sit->second, commonData, hoGeometry));
759 string field_name, Mat
A,
const std::string mesh_nodals_positions) {
761 bool hoGeometry =
false;
762 if (mField.check_field(mesh_nodals_positions)) {
765 std::map<int, ConvectionData>::iterator sit = setOfConvection.begin();
766 for (; sit != setOfConvection.end(); sit++) {
768 feConvectionLhs.getOpPtrVector().push_back(
776 const std::string mesh_nodals_positions) {
779 bool hoGeometry =
false;
780 if (mField.check_field(mesh_nodals_positions)) {
785 std::map<int, BlockData>::iterator sit = setOfBlocks.begin();
786 for (; sit != setOfBlocks.end(); sit++) {
791 feLhs.getOpPtrVector().push_back(
793 feLhs.getOpPtrVector().push_back(
796 feRhs.getOpPtrVector().push_back(
798 feRhs.getOpPtrVector().push_back(
800 feRhs.getOpPtrVector().push_back(
802 feRhs.getOpPtrVector().push_back(
804 feRhs.getOpPtrVector().push_back(
811 std::map<int, FluxData>::iterator sit = setOfFluxes.begin();
812 for (; sit != setOfFluxes.end(); sit++) {
813 feFlux.getOpPtrVector().push_back(
820 std::map<int, ConvectionData>::iterator sit = setOfConvection.begin();
821 for (; sit != setOfConvection.end(); sit++) {
822 feConvectionRhs.getOpPtrVector().push_back(
824 feConvectionRhs.getOpPtrVector().push_back(
829 std::map<int, ConvectionData>::iterator sit = setOfConvection.begin();
830 for (; sit != setOfConvection.end(); sit++) {
831 feConvectionLhs.getOpPtrVector().push_back(
838 std::map<int, RadiationData>::iterator sit = setOfRadiation.begin();
839 for (; sit != setOfRadiation.end(); sit++) {
840 feRadiationRhs.getOpPtrVector().push_back(
842 feRadiationRhs.getOpPtrVector().push_back(
847 std::map<int, RadiationData>::iterator sit = setOfRadiation.begin();
848 for (; sit != setOfRadiation.end(); sit++) {
849 feRadiationLhs.getOpPtrVector().push_back(
851 feRadiationLhs.getOpPtrVector().push_back(
861 const std::string mesh_nodals_positions) {
864 CHKERR setTimeSteppingProblem(
field_name, rate_name, mesh_nodals_positions);
870 loops_to_do_Rhs.push_back(
872 if (mField.check_finite_element(
"THERMAL_CONVECTION_FE"))
873 loops_to_do_Rhs.push_back(
875 if (mField.check_finite_element(
"THERMAL_RADIATION_FE"))
876 loops_to_do_Rhs.push_back(
883 if (mField.check_finite_element(
"THERMAL_CONVECTION_FE"))
884 loops_to_do_Mat.push_back(
886 if (mField.check_finite_element(
"THERMAL_RADIATION_FE"))
887 loops_to_do_Mat.push_back(