Skip to content

Commit b8dfc36

Browse files
committed
U p
1 parent f29f5b9 commit b8dfc36

File tree

3 files changed

+373
-100
lines changed

3 files changed

+373
-100
lines changed

src/dfGenMatrixIncompressible/GenMatrix_U.C

Lines changed: 244 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,233 @@
1717
#include "autoPtr.H"
1818
#include "runTimeSelectionTables.H"
1919

20+
#include "gaussGrad.H"
21+
#include "extrapolatedCalculatedFvPatchField.H"
22+
2023
namespace Foam{
2124

25+
template<class Type>
26+
tmp
27+
<
28+
GeometricField
29+
<
30+
typename outerProduct<vector, Type>::type,
31+
fvPatchField,
32+
volMesh
33+
>
34+
>
35+
gaussGradCalcGrad
36+
(
37+
const GeometricField<Type, fvPatchField, volMesh>& vsf,
38+
const word& name
39+
);
40+
41+
template<class Type>
42+
void gaussGradCorrectBoundaryConditions
43+
(
44+
const GeometricField<Type, fvPatchField, volMesh>& vsf,
45+
GeometricField
46+
<
47+
typename outerProduct<vector, Type>::type, fvPatchField, volMesh
48+
>& gGrad
49+
);
50+
51+
template<class Type>
52+
tmp
53+
<
54+
GeometricField
55+
<
56+
typename outerProduct<vector, Type>::type,
57+
fvPatchField,
58+
volMesh
59+
>
60+
>
61+
gaussGradGradf
62+
(
63+
const GeometricField<Type, fvsPatchField, surfaceMesh>& ssf,
64+
const word& name
65+
);
66+
67+
// // 专门用于计算 grad(U) 的函数
68+
// tmp<volTensorField> calcGradU(const volVectorField& U)
69+
// {
70+
// const fvMesh& mesh = U.mesh();
71+
72+
// // 创建线性插值方案
73+
// tmp<surfaceInterpolationScheme<vector>> tinterpScheme =
74+
// tmp<surfaceInterpolationScheme<vector>>
75+
// (
76+
// new linear<vector>(mesh)
77+
// );
78+
79+
// // 插值到场表面
80+
// tmp<surfaceVectorField> tinterpolate = tinterpScheme().interpolate(U);
81+
82+
// // 计算梯度
83+
// tmp<volTensorField> tgGrad = gaussGradGradf(tinterpolate(), "grad(" + U.name() + ')');
84+
// volTensorField& gGrad = tgGrad.ref();
85+
86+
// // 修正边界条件
87+
// gaussGradCorrectBoundaryConditions(U, gGrad);
88+
89+
// return tgGrad;
90+
// }
91+
92+
// 梯度计算核心函数实现
93+
template<class Type>
94+
tmp
95+
<
96+
GeometricField
97+
<
98+
typename outerProduct<vector, Type>::type,
99+
fvPatchField,
100+
volMesh
101+
>
102+
>
103+
gaussGradCalcGrad
104+
(
105+
const GeometricField<Type, fvPatchField, volMesh>& vsf,
106+
const word& name
107+
)
108+
{
109+
const fvMesh& mesh = vsf.mesh();
110+
111+
tmp<surfaceInterpolationScheme<Type>> tinterpScheme_ =
112+
tmp<surfaceInterpolationScheme<Type>>
113+
(
114+
new linear<Type>(mesh)
115+
);
116+
117+
typedef typename outerProduct<vector, Type>::type GradType;
118+
119+
tmp<GeometricField<Type, fvsPatchField, surfaceMesh>> tinterpolate = tinterpScheme_().interpolate(vsf);
120+
121+
tmp<GeometricField<GradType, fvPatchField, volMesh>> tgGrad
122+
(
123+
gaussGradGradf(tinterpolate.ref(), name)
124+
);
125+
GeometricField<GradType, fvPatchField, volMesh>& gGrad = tgGrad.ref();
126+
127+
gaussGradCorrectBoundaryConditions(vsf, gGrad);
128+
129+
return tgGrad;
130+
}
131+
132+
template<class Type>
133+
void gaussGradCorrectBoundaryConditions
134+
(
135+
const GeometricField<Type, fvPatchField, volMesh>& vsf,
136+
GeometricField
137+
<
138+
typename outerProduct<vector, Type>::type, fvPatchField, volMesh
139+
>& gGrad
140+
)
141+
{
142+
typename GeometricField
143+
<
144+
typename outerProduct<vector, Type>::type, fvPatchField, volMesh
145+
>::Boundary& gGradbf = gGrad.boundaryFieldRef();
146+
147+
forAll(vsf.boundaryField(), patchi)
148+
{
149+
if (!vsf.boundaryField()[patchi].coupled())
150+
{
151+
const vectorField n
152+
(
153+
vsf.mesh().Sf().boundaryField()[patchi]
154+
/ vsf.mesh().magSf().boundaryField()[patchi]
155+
);
156+
157+
gGradbf[patchi] += n *
158+
(
159+
vsf.boundaryField()[patchi].snGrad()
160+
- (n & gGradbf[patchi])
161+
);
162+
}
163+
}
164+
}
165+
166+
template<class Type>
167+
tmp
168+
<
169+
GeometricField
170+
<
171+
typename outerProduct<vector, Type>::type,
172+
fvPatchField,
173+
volMesh
174+
>
175+
>
176+
gaussGradGradf
177+
(
178+
const GeometricField<Type, fvsPatchField, surfaceMesh>& ssf,
179+
const word& name
180+
)
181+
{
182+
typedef typename outerProduct<vector, Type>::type GradType;
183+
184+
const fvMesh& mesh = ssf.mesh();
185+
186+
tmp<GeometricField<GradType, fvPatchField, volMesh>> tgGrad
187+
(
188+
new GeometricField<GradType, fvPatchField, volMesh>
189+
(
190+
IOobject
191+
(
192+
name,
193+
ssf.instance(),
194+
mesh,
195+
IOobject::NO_READ,
196+
IOobject::NO_WRITE
197+
),
198+
mesh,
199+
dimensioned<GradType>
200+
(
201+
"0",
202+
ssf.dimensions()/dimLength,
203+
Zero
204+
),
205+
extrapolatedCalculatedFvPatchField<GradType>::typeName
206+
)
207+
);
208+
GeometricField<GradType, fvPatchField, volMesh>& gGrad = tgGrad.ref();
209+
210+
const labelUList& owner = mesh.owner();
211+
const labelUList& neighbour = mesh.neighbour();
212+
const vectorField& Sf = mesh.Sf();
213+
214+
Field<GradType>& igGrad = gGrad;
215+
const Field<Type>& issf = ssf;
216+
217+
forAll(owner, facei)
218+
{
219+
GradType Sfssf = Sf[facei]*issf[facei];
220+
221+
igGrad[owner[facei]] += Sfssf;
222+
igGrad[neighbour[facei]] -= Sfssf;
223+
}
224+
225+
forAll(mesh.boundary(), patchi)
226+
{
227+
const labelUList& pFaceCells =
228+
mesh.boundary()[patchi].faceCells();
229+
230+
const vectorField& pSf = mesh.Sf().boundaryField()[patchi];
231+
232+
const fvsPatchField<Type>& pssf = ssf.boundaryField()[patchi];
233+
234+
forAll(mesh.boundary()[patchi], facei)
235+
{
236+
igGrad[pFaceCells[facei]] += pSf[facei]*pssf[facei];
237+
}
238+
}
239+
240+
igGrad /= mesh.V();
241+
242+
gGrad.correctBoundaryConditions();
243+
244+
return tgGrad;
245+
}
246+
22247
tmp<fvVectorMatrix>
23248
GenMatrix_U(
24249
const volScalarField& rho,
@@ -246,21 +471,22 @@ GenMatrix_U(
246471

247472
// --------------------------------------------------------------------------------------------------------------
248473

474+
Info << "UEqn Calculating grad(U) using extracted functions" << endl;
475+
tmp<surfaceInterpolationScheme<vector>> tinterpScheme =
476+
tmp<surfaceInterpolationScheme<vector>>
477+
(
478+
new linear<vector>(mesh)
479+
);
480+
tmp<surfaceVectorField> tinterpolate = tinterpScheme().interpolate(U);
481+
tmp<volTensorField> tgGradU = gaussGradGradf(tinterpolate(), "grad(" + U.name() + ')');
482+
volTensorField& gGrad = tgGradU.ref();
483+
gaussGradCorrectBoundaryConditions(U, gGrad);
249484

485+
const volTensorField& gradU = tgGradU();
486+
// const volScalarField alphaEff = turbulence.alpha()*rho*turbulence.nuEff();
250487

251488

252489

253-
254-
255-
256-
257-
258-
259-
260-
261-
262-
263-
264490
// -------------------------------------------------------
265491
// interFoam
266492
// const alphaField& alpha;
@@ -272,7 +498,8 @@ GenMatrix_U(
272498
// + fvm::div(rhoPhi, U)
273499
// + MRF.DDt(rho, U)
274500
// + turbulence.divDevRhoReff(rho, U)
275-
- fvc::div((turbulence.alpha()*rho*turbulence.nuEff())*dev2(T(fvc::grad(U))))
501+
// - fvc::div((turbulence.alpha()*rho*turbulence.nuEff())*dev2(T(fvc::grad(U))))
502+
- fvc::div((turbulence.alpha()*rho*turbulence.nuEff())*dev2(T(gradU)))
276503

277504
// - fvm::laplacian(turbulence.alpha()*rho*turbulence.nuEff(), U)
278505
// - fvOptions(rho, U)
@@ -307,4 +534,8 @@ GenMatrix_U(
307534
// fvOptions(rho, U)
308535
// );
309536
// fvVectorMatrix& UEqn_answer = tUEqn_answer.ref();
310-
// check_fvmatrix_equal(UEqn_answer, UEqn, "UEqn");
537+
// check_fvmatrix_equal(UEqn_answer, UEqn, "UEqn");
538+
539+
540+
541+

0 commit comments

Comments
 (0)