DNDSR 0.1.0.dev1+gcd065ad
Distributed Numeric Data Structure for CFV
Loading...
Searching...
No Matches
ModelEvaluator.cpp
Go to the documentation of this file.
1#include "ModelEvaluator.hpp"
2#include "DNDS/Defines.hpp"
3
4namespace DNDS::CFV
5{
9 {
10 using namespace Geom;
11 int cnvars = u.father->MatRowSize();
12 static const auto Seq012 = Eigen::seq(Eigen::fix<0>, Eigen::fix<dim - 1>);
13 static const auto SeqG012 = Eigen::seq(Eigen::fix<0>, Eigen::fix<dim - 1>);
14 static const auto SeqG123 = Eigen::seq(Eigen::fix<1>, Eigen::fix<dim>);
15
16 bool direct2ndRec = options.direct2ndRec;
17 bool direct2ndRec1stConv = options.direct2ndRec1stConv;
18
19 for (index iCell = 0; iCell < mesh->NumCell(); iCell++)
20 rhs[iCell].setZero();
21
22 if (direct2ndRec)
23 {
24 vfv->DoReconstruction2ndGrad<nVarsFixed>(uGradBuf, u, this->get_FBoundary(t), 1 /* green gauss*/);
25 uGradBuf.trans.startPersistentPull();
26 uGradBuf.trans.waitPersistentPull();
27 }
28
29 for (index iFace = 0; iFace < mesh->NumFaceProc(); iFace++)
30 {
31 auto f2c = mesh->face2cell[iFace];
32 Elem::Quadrature gFace = direct2ndRec ? vfv->GetFaceQuadO1(iFace) : vfv->GetFaceQuad(iFace);
33 Eigen::Matrix<real, nVarsFixed, 1, Eigen::ColMajor> fluxEs(cnvars, 1);
34 fluxEs.setZero();
35
36 auto faceBndID = mesh->GetFaceZone(iFace);
37 gFace.IntegrationSimple(
38 fluxEs,
39 [&](decltype(fluxEs) &finc, int iG, real w)
40 {
41 int iGQ = direct2ndRec ? -1 : iG;
42 TVec unitNorm = vfv->GetFaceNorm(iFace, iGQ)(Seq012);
43 TMat normBase = Geom::NormBuildLocalBaseV<dim>(unitNorm);
44
45 TU ULxy = u[f2c[0]];
46 if (direct2ndRec && !direct2ndRec1stConv)
47 ULxy += uGradBuf[f2c[0]].transpose() * (vfv->GetFaceQuadraturePPhysFromCell(iFace, f2c[0], 0, -1) - vfv->GetCellQuadraturePPhys(f2c[0], -1))(SeqG012);
48 else if (!direct2ndRec1stConv)
49 ULxy += (vfv->GetIntPointDiffBaseValue(f2c[0], iFace, 0, iGQ, std::array<int, 1>{0}, 1) *
50 uRec[f2c[0]])
51 .transpose();
52 TU URxy;
53 TDiffU GradULxy, GradURxy;
54 URxy.setZero(cnvars);
55 GradULxy.setZero(dim, cnvars), GradURxy.setZero(dim, cnvars);
56
57 if (direct2ndRec && !direct2ndRec1stConv)
58 GradULxy(SeqG012, EigenAll) = uGradBuf[f2c[0]];
59 else if (!direct2ndRec1stConv)
60 GradULxy(SeqG012, EigenAll) =
61 vfv->GetIntPointDiffBaseValue(f2c[0], iFace, 0, iGQ, SeqG123, 3) *
62 uRec[f2c[0]];
63
64 real minVol = vfv->GetCellVol(f2c[0]);
65 real distBary = veryLargeReal;
66 if (f2c[1] != UnInitIndex)
67 {
68 URxy = u[f2c[1]];
69 if (direct2ndRec && !direct2ndRec1stConv)
70 URxy += uGradBuf[f2c[1]].transpose() * (vfv->GetFaceQuadraturePPhysFromCell(iFace, f2c[1], 1, -1) - vfv->GetCellQuadraturePPhys(f2c[1], -1))(SeqG012);
71 else if (!direct2ndRec1stConv)
72 URxy += (vfv->GetIntPointDiffBaseValue(f2c[1], iFace, 1, iGQ, std::array<int, 1>{0}, 1) *
73 uRec[f2c[1]])
74 .transpose();
75
76 if (direct2ndRec && !direct2ndRec1stConv)
77 GradURxy(SeqG012, EigenAll) = uGradBuf[f2c[1]];
78 else if (!direct2ndRec1stConv)
79 GradURxy(SeqG012, EigenAll) =
80 vfv->GetIntPointDiffBaseValue(f2c[1], iFace, 1, iGQ, SeqG123, 3) *
81 uRec[f2c[1]];
82 distBary = (vfv->GetOtherCellBaryFromCell(f2c[0], f2c[1], iFace) - vfv->GetCellBary(f2c[0])).norm();
83 minVol = std::min(minVol, vfv->GetCellVol(f2c[1]));
84 }
85 else
86 {
87 GradURxy = GradULxy;
89 ULxy, u[f2c[0]], f2c[0], iFace, iGQ,
90 unitNorm,
91 normBase,
92 vfv->GetFaceQuadraturePPhys(iFace, iGQ),
93 t,
94 mesh->GetFaceZone(iFace), true, 0);
95 distBary = (vfv->GetFaceQuadraturePPhysFromCell(iFace, f2c[0], 0, -1) - vfv->GetCellBary(f2c[0])).norm() * 2.;
96 }
97
98 real distGRP = minVol / vfv->GetFaceArea(iFace) * 2;
99
100 if (direct2ndRec1stConv)
101 distGRP = distBary;
102 TDiffU GradUMeanXy = (GradURxy + GradULxy) * 0.5;
103 GradUMeanXy += (1.0 / distGRP) *
104 (unitNorm * (URxy - ULxy).transpose());
105 real an = unitNorm(0) * settings.ax + unitNorm(1) * settings.ay;
106 finc = -(an * URxy + an * ULxy) * 0.5 + 0.5 * std::abs(an) * (URxy - ULxy);
107 // viscous:
108 finc += GradUMeanXy.transpose() * unitNorm * settings.sigma;
109 finc *= vfv->GetFaceJacobiDet(iFace, iG);
110 });
111 rhs[f2c[0]] += fluxEs / vfv->GetCellVol(f2c[0]);
112 if (f2c[1] != UnInitIndex)
113 rhs[f2c[1]] += -fluxEs / vfv->GetCellVol(f2c[1]);
114 }
115 }
116}
Core type aliases, constants, and metaprogramming utilities for the DNDS framework.
Primary solver state container: an ArrayEigenMatrix pair with MPI-collective vector-space operations.
Definition ArrayDOF.hpp:172
Eigen::Matrix< real, dim, dim > TMat
void EvaluateRHS(tUDof< nVarsFixed > &rhs, tUDof< nVarsFixed > &u, tURec< nVarsFixed > &uRec, real t, const EvaluateRHSOptions &options=EvaluateRHSOptions{})
Eigen::Matrix< real, nVarsFixed, 1 > TU
Eigen::Matrix< real, dim, nVarsFixed > TDiffU
Tvfv_FBoundary get_FBoundary(real t)
Eigen::Matrix< real, dim, 1 > TVec
TU generateBoundaryValue(TU &ULxy, const TU &ULMeanXy, index iCell, index iFace, int iG, const TVec &uNorm, const TMat &normBase, const Geom::tPoint &pPhysics, real t, Geom::t_index btype, bool fixUL=false, int geomMode=0, int linMode=0)
DNDS_CONSTANT const index UnInitIndex
Sentinel "not initialised" index value (= INT64_MIN).
Definition Defines.hpp:176
int64_t index
Global row / DOF index type (signed 64-bit; handles multi-billion-cell meshes).
Definition Defines.hpp:107
double real
Canonical floating-point scalar used throughout DNDSR (double precision).
Definition Defines.hpp:105
DNDS_CONSTANT const real veryLargeReal
Catch-all upper bound ("practically infinity") for physical scalars.
Definition Defines.hpp:190
ssp< TArray > father
Owned-side array (must be resized before ghost setup).