59 using namespace Geom::Elem;
60 using namespace Geom::Base;
66 this->MakePairDefaultOnCell(baseWeight_.cellBaseMoment,
"VR::cellBaseMoment", maxNDOF);
67 if (settings.cacheDiffBase)
69 this->MakePairDefaultOnCell(
70 baseWeight_.cellDiffBaseCache,
"VR::cellDiffBaseCache",
71 std::min(
maxNDIFF,
static_cast<int>(settings.cacheDiffBaseSize)), maxNDOF);
72 this->MakePairDefaultOnCell(
73 baseWeight_.cellDiffBaseCacheCent,
"VR::cellDiffBaseCacheCent",
74 std::min(
maxNDIFF,
static_cast<int>(settings.cacheDiffBaseSize)), maxNDOF);
76 if (coefficients_.needVolIntCholeskyL)
77 coefficients_.volIntCholeskyL.resize(mesh->NumCellProc());
79# pragma omp parallel for
83 GetCellAtr(
iCell).relax = settings.jacobiRelax;
86 auto qCellMax = Quadrature{mesh->GetCellElement(
iCell), INT_ORDER_MAX};
87 if (settings.cacheDiffBase)
89 baseWeight_.cellDiffBaseCache.ResizeRow(
iCell,
qCell.GetNumPoints());
94 Eigen::RowVector<real, Eigen::Dynamic> m;
95 m.setZero(GetCellAtr(
iCell).NDOF);
102 Eigen::RowVector<real, Eigen::Dynamic>
vv;
108 baseWeight_.cellBaseMoment[
iCell] = m.transpose() / m(0);
114 if (settings.cacheDiffBase)
118 std::min(GetCellAtr(iCell).NDIFF, settings.cacheDiffBaseSize),
119 GetCellAtr(iCell).NDOF);
120 this->FDiffBaseValue(dbv, this->GetCellQuadraturePPhys(iCell, iG), iCell, -1, iG, 0);
121 baseWeight_.cellDiffBaseCache(iCell, iG) = dbv;
128 if (settings.cacheDiffBase)
132 std::min(GetCellAtr(iCell).NDIFF, settings.cacheDiffBaseSize),
133 GetCellAtr(iCell).NDOF);
134 this->FDiffBaseValue(dbv, this->GetCellQuadraturePPhys(iCell, -1), iCell, -1, -1, 0);
135 baseWeight_.cellDiffBaseCacheCent[iCell] = dbv;
147 this->GetIntPointDiffBaseValue(
iCell, -1, -1,
iG, std::array<int, 1>{0}, 1);
148 vInc = (D0Bj.transpose() * D0Bj);
151 if (coefficients_.needVolIntCholeskyL)
152 coefficients_.volIntCholeskyL.at(
iCell).resizeLike(
MBiBj),
153 coefficients_.volIntCholeskyL.at(
iCell) =
MBiBj.llt().matrixL();
159 this->MakePairDefaultOnFace(baseWeight_.faceWeight,
"VR::faceWeight", settings.maxOrder + 1);
160 this->MakePairDefaultOnFace(baseWeight_.faceAlignedScales,
"VR::faceAlignedScales");
161 this->MakePairDefaultOnFace(baseWeight_.faceMajorCoordScale,
"VR::faceMajorCoordScale", 3, 3);
162 if (settings.cacheDiffBase)
164 this->MakePairDefaultOnFace(
165 baseWeight_.faceDiffBaseCache,
"VR::faceDiffBaseCache",
166 std::min(
maxNDIFF,
static_cast<int>(settings.cacheDiffBaseSize)), maxNDOF);
167 this->MakePairDefaultOnFace(
168 baseWeight_.faceDiffBaseCacheCent,
"VR::faceDiffBaseCacheCent",
169 std::min(
maxNDIFF,
static_cast<int>(settings.cacheDiffBaseSize)), maxNDOF * 2);
172# pragma omp parallel for
178 if (settings.cacheDiffBase)
179 baseWeight_.faceDiffBaseCache.ResizeRow(
iFace, 2 *
qFace.GetNumPoints());
182 mesh->GetCoordsOnFace(
iFace, coords);
193 if (FaceIDIsExternalBC(mesh->GetFaceZone(
iFace)))
195 else if (FaceIDIsPeriodic(mesh->GetFaceZone(
iFace)))
204 if (settings.cacheDiffBase)
208 std::min(GetFaceAtr(iFace).NDIFF, settings.cacheDiffBaseSize),
209 GetCellAtr(iCell).NDOF);
210 this->FDiffBaseValue(dbv, this->GetFaceQuadraturePPhysFromCell(iFace, iCell, if2c, iG), iCell, iFace, iG, 0);
211 baseWeight_.faceDiffBaseCache(iFace, if2c * qFace.GetNumPoints() + iG) = dbv;
218 if (settings.cacheDiffBase)
222 std::min(GetFaceAtr(iFace).NDIFF, settings.cacheDiffBaseSize),
223 GetCellAtr(iCell).NDOF);
224 this->FDiffBaseValue(dbv, this->GetFaceQuadraturePPhysFromCell(iFace, iCell, if2c, -1), iCell, iFace, -1, 0);
225 int maxNDOF = GetNDof<dim>(settings.maxOrder);
226 baseWeight_.faceDiffBaseCacheCent[iFace](
228 Eigen::seq(if2c * maxNDOF,
229 if2c * maxNDOF + maxNDOF - 1)) = dbv;
243 if (FaceIDIsExternalBC(mesh->GetFaceZone(
iFace)))
245 else if (FaceIDIsPeriodic(mesh->GetFaceZone(
iFace)))
260 this->GetOtherCellBaryFromCell(mesh->face2cell(
iFace, 0),
262 this->GetCellBary(mesh->face2cell(
iFace, 0));
268 mesh->face2cell(
iFace, 0), 0, -1) -
269 this->GetCellBary(mesh->face2cell(
iFace, 0));
270 auto uNorm = this->GetFaceNormFromCell(
272 mesh->face2cell(
iFace, 0), 0, -1);
275 this->GetFaceNorm(
iFace, -1);
279 this->GetCellBary(mesh->face2cell(
iFace, 0)) -
280 this->GetFaceQuadraturePPhysFromCell(
iFace, mesh->face2cell(
iFace, 0), 0, -1);
283 volL =
volR = std::pow(GetCellVol(mesh->face2cell(
iFace, 0)) +
verySmallReal, settings.functionalSettings.inertiaWeightPower);
288 volR = std::pow(GetCellVol(mesh->face2cell(
iFace, 1)) +
verySmallReal, settings.functionalSettings.inertiaWeightPower);
290 mesh->face2cell(
iFace, 0),
299 if constexpr (dim == 3)
315 coordsL.array().abs().rowwise().maxCoeff().max(
316 coordsR.array().abs().rowwise().maxCoeff());
320 real AR2 = baseWeight_.faceMajorCoordScale[
iFace].col(0).norm() / baseWeight_.faceMajorCoordScale[
iFace].col(1).norm();
324 if constexpr (dim == 2)
325 baseWeight_.faceAlignedScales[
iFace](2) = 1;
331 wg = settings.functionalSettings.geomWeightBias +
332 std::pow(std::pow(this->GetFaceArea(
iFace), 1. /
real(dim - 1)) /
faceBaryDiffV.norm(), settings.functionalSettings.geomWeightPower * 0.5);
334 wg = settings.functionalSettings.geomWeightBias +
335 std::pow(this->GetFaceArea(
iFace), settings.functionalSettings.geomWeightPower1 * 0.5) *
336 std::pow(
faceBaryDiffV.norm(), settings.functionalSettings.geomWeightPower2 * 0.5);
339 Eigen::Vector<real, Eigen::Dynamic>
wd;
340 wd.resize(settings.maxOrder + 1);
341 switch (settings.functionalSettings.dirWeightScheme)
344 for (
int p = 0; p <
wd.size(); p++)
345 wd[p] = 1. / factorials[p];
348 switch (settings.maxOrder)
354 wd[0] = 1,
wd[1] = 0.4643,
wd[2] = 0.1559;
357 wd[0] = 1,
wd[1] = .5295,
wd[2] =
wd[3] = .2117;
365 switch (settings.maxOrder)
368 wd[3] = settings.functionalSettings.manualDirWeights[3];
371 wd[2] = settings.functionalSettings.manualDirWeights[2];
374 wd[1] = settings.functionalSettings.manualDirWeights[1];
375 wd[0] = settings.functionalSettings.manualDirWeights[0];
384 if (settings.maxOrder != 3)
386 switch (settings.maxOrder)
389 wd[3] = settings.functionalSettings.manualDirWeights[3];
392 wd[2] = settings.functionalSettings.manualDirWeights[2];
395 wd[1] = settings.functionalSettings.manualDirWeights[1];
396 wd[0] = settings.functionalSettings.manualDirWeights[0];
414 wd[0] = std::sqrt(std::pow(1.0031 + 0.86 * std::pow(
r1 *
r2, 0.5327), 0.98132));
415 wd[1] =
wd[0] * std::sqrt(0.3604 - 0.0774 * std::exp(-0.5 *
sqr((
lrr - 1.8e-10) / 0.1325)));
416 wd[2] =
wd[0] * std::sqrt(0.0676 - 0.0547 * std::exp(-0.5 *
sqr((
lrr + 2.74e-10) / 0.1376)));
417 wd[3] =
wd[0] * std::sqrt(5.299e-2 - 4.63e-2 * std::exp(-0.5 *
sqr((
lrr - 9.028e-12) / 0.175)));
424 wd[0] = std::sqrt(std::pow(1.00745 +
r, 1.004));
425 wd[1] =
wd[0] * std::sqrt(0.359 - 0.0674 * std::exp(-
sqr(
lr - 5.18e-11) / (2 *
sqr(0.124))));
426 wd[2] =
wd[0] * std::sqrt(0.0676 - 0.0507 * std::exp(-
sqr(
lr - 3.15e-10) / (2 *
sqr(0.137))));
427 wd[3] =
wd[0] * std::sqrt(0.0529 - 0.0487 * std::exp(-
sqr(
lr - 1.33e-10) / (2 *
sqr(0.167))));
437 if (FaceIDIsExternalBC(mesh->GetFaceZone(
iFace)))
445 if (settings.cacheDiffBase)
447 baseWeight_.faceDiffBaseCache.CompressBoth();
448 baseWeight_.cellDiffBaseCache.CompressBoth();
451 if (!settings.intOrderVRBCIsSame())
466 auto qFace = Quadrature(mesh->GetFaceElement(
iFace), settings.intOrderVRBCValue());
467 baseWeight_.bndVRCaches[
iFace].reserve(
qFace.GetNumPoints());
469 mesh->GetCoordsOnFace(
iFace, coords);
475 tPoint
pPhy = Elem::PPhysicsCoordD01Nj(coords,
DiNj);
476 tJacobi
J = Elem::ShapeJacobianCoordD01Nj(coords,
DiNj);
482 dbv =
dbvD(0, Eigen::seq(Eigen::fix<1>, EigenLast));
495 if (mpi.rank == mRank)
497 <<
"VariationalReconstruction<dim>::ConstructBaseAndWeight() done" << std::endl;
511 auto &
c_ = coefficients_;
512 static const auto Seq012 = Eigen::seq(Eigen::fix<0>, Eigen::fix<dim - 1>);
513 static const auto Seq123 = Eigen::seq(Eigen::fix<1>, Eigen::fix<dim>);
514 using namespace Geom;
515 using namespace Geom::Elem;
516 using namespace Geom::Base;
518 if (
c_.needOriginalMatrix)
519 this->MakePairDefaultOnCell(
c_.matrixAB,
"VR::matrixAB", maxNDOF - 1, maxNDOF - 1);
520 this->MakePairDefaultOnCell(
c_.matrixAAInvB,
"VR::matrixAAInvB", maxNDOF - 1, maxNDOF - 1);
521 if (
c_.needOriginalMatrix)
522 this->MakePairDefaultOnCell(
c_.vectorB,
"VR::vectorB", maxNDOF - 1, 1);
523 this->MakePairDefaultOnCell(
c_.vectorAInvB,
"VR::vectorAInvB", maxNDOF - 1, 1);
524 if (settings.functionalSettings.greenGauss1Weight != 0)
525 this->MakePairDefaultOnCell(
c_.matrixAHalf_GG,
"VR::matrixAHalf_GG", dim, (maxNDOF - 1));
526 this->MakePairDefaultOnCell(
c_.matrixA,
"VR::matrixA", (maxNDOF - 1), (maxNDOF - 1));
527 if (
c_.needMatrixACholeskyL)
528 c_.matrixACholeskyL.resize(mesh->NumCellProc());
531# pragma omp parallel for
535 if (
c_.needOriginalMatrix)
536 c_.matrixAB.ResizeRow(
iCell, mesh->cell2face.RowSize(
iCell) + 1);
537 c_.matrixAAInvB.ResizeRow(
iCell, mesh->cell2face.RowSize(
iCell) + 1);
538 if (
c_.needOriginalMatrix)
539 c_.vectorB.ResizeRow(
iCell, mesh->cell2face.RowSize(
iCell));
540 c_.vectorAInvB.ResizeRow(
iCell, mesh->cell2face.RowSize(
iCell));
542 std::vector<Eigen::Vector<real, Eigen::Dynamic>>
local_bs;
547 A.setZero(GetCellAtr(
iCell).NDOF - 1, GetCellAtr(
iCell).NDOF - 1);
554 : settings.intOrderVRValue());
558 mesh->GetCoordsOnFace(
iFace, coords);
568 JDet = this->GetFaceJacobiDet(
iFace,
iG);
572 tPoint
pPhy = Elem::PPhysicsCoordD01Nj(coords,
DiNj);
573 JDet = FaceJacobianDet(dim, coords,
DiNj) * (axisSymmetric ?
pPhy(1) : 1.);
577 DiffI =
dbv(EigenAll, Eigen::seq(Eigen::fix<1>, EigenLast));
583 Eigen::Matrix<real, dim, Eigen::Dynamic>
AHalf_GG;
584 if (settings.functionalSettings.greenGauss1Weight != 0)
587 AHalf_GG.resize(Eigen::NoChange,
A.cols());
591 qCell.IntegrationSimple(
595 inc = this->GetIntPointDiffBaseValue(
597 Eigen::seq(Eigen::fix<1>, Eigen::fix<dim>), dim + 1);
607 qFace.IntegrationSimple(
614 this->GetIntPointDiffBaseValue(
617 inc *= (1 - settings.functionalSettings.greenGauss1Bias);
625 settings.functionalSettings.greenGauss1Penalty;
628 inc *= (-1) * this->GetFaceJacobiDet(
iFace,
iG);
643 : settings.intOrderVRValue());
647 mesh->GetCoordsOnFace(
iFace, coords);
650 if (FaceIDIsExternalBC(mesh->GetFaceZone(
iFace)))
658 B.setZero(GetCellAtr(
iCell).NDOF - 1, GetCellAtr(
iCellOther).NDOF - 1);
668 JDet = this->GetFaceJacobiDet(
iFace,
iG);
674 tPoint
pPhy = Elem::PPhysicsCoordD01Nj(coords,
DiNj);
675 JDet = FaceJacobianDet(dim, coords,
DiNj) * (axisSymmetric ?
pPhy(1) : 1.);
682 DiffI =
dbvI(EigenAll, Eigen::seq(Eigen::fix<1>, EigenLast));
683 DiffJ =
dbvJ(EigenAll, Eigen::seq(Eigen::fix<1>, EigenLast));
685 if (mesh->isPeriodic)
690 periodicity.TransDiValueInplace<dim>(
DiffJ,
faceID);
695 periodicity.TransDiValueBackInplace<dim>(
DiffJ,
faceID);
702 if (settings.functionalSettings.greenGauss1Weight != 0)
705 BHalf_GG.resize(Eigen::NoChange, B.cols());
707 qFace.IntegrationSimple(
715 inc *= settings.functionalSettings.greenGauss1Bias;
721 settings.functionalSettings.greenGauss1Penalty;
728 if (
c_.needOriginalMatrix)
730 local_Bs.emplace_back(std::move(B));
742 : settings.intOrderVRValue());
746 mesh->GetCoordsOnFace(
iFace, coords);
748 b.setZero(GetCellAtr(
iCell).NDOF - 1, 1);
753 Eigen::RowVector<real, Eigen::Dynamic>
DiffI;
757 JDet = this->GetFaceJacobiDet(
iFace,
iG);
758 DiffI = this->GetIntPointDiffBaseValue(
iCell,
iFace, -1,
iG, std::array<int, 1>{0}, 1);
762 tPoint
pPhy = Elem::PPhysicsCoordD01Nj(coords,
DiNj);
763 JDet = FaceJacobianDet(dim, coords,
DiNj) * (axisSymmetric ?
pPhy(1) : 1.);
765 dbv.resize(1, GetCellAtr(
iCell).NDOF);
767 DiffI =
dbv(EigenAll, Eigen::seq(Eigen::fix<1>, EigenLast));
772 if (settings.functionalSettings.greenGauss1Weight != 0)
774 Eigen::Matrix<real, dim, 1>
bHalf_GG;
776 qFace.IntegrationSimple(
778 [&](
auto &
inc,
int iG)
782 inc *= settings.functionalSettings.greenGauss1Bias * this->GetFaceJacobiDet(
iFace,
iG);
786 if (
c_.needOriginalMatrix)
795 if (settings.svdTolerance)
799 if (
c_.needOriginalMatrix)
805 if (
c_.needMatrixACholeskyL)
806 c_.matrixACholeskyL.at(
iCell) =
A.llt().matrixL();
817 if (FaceIDIsExternalBC(mesh->GetFaceZone(
iFace)))
826 if (
c_.needOriginalMatrix)
827 c_.matrixAB.CompressBoth();
828 c_.matrixAAInvB.CompressBoth();
829 c_.vectorAInvB.CompressBoth();
830 if (
c_.needOriginalMatrix)
831 c_.vectorB.CompressBoth();
832 c_.matrixAHalf_GG.CompressBoth();
835 c_.matrixA.TransAttach();
836 c_.matrixA.trans.BorrowGGIndexing(mesh->cell2cell.trans);
837 c_.matrixA.trans.createMPITypes();
838 c_.matrixA.trans.pullOnce();
841 this->MakePairDefaultOnFace(
c_.matrixSecondary,
"VR::matrixSecondary", maxNDOF - 1, (maxNDOF - 1) * 2);
857 EigenAll, Eigen::seq(
861 EigenAll, Eigen::seq(
865 c_.matrixSecondary.CompressBoth();
869 if (mesh->getMPI().rank == 0)
870 log() << std::scientific << std::setprecision(3)
871 <<
"VariationalReconstruction<dim>::ConstructRecCoeff() === A cond Max: [ " <<
maxCondAll <<
"] " << std::endl;