All Classes Namespaces Files Functions Variables Typedefs Friends Macros Groups
leastSquaresStencil.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2019 OpenCFD Ltd.
10  Copyright (C) 2016-2019 ISP RAS (www.ispras.ru) UniCFD Group (www.unicfd.ru)
11 -------------------------------------------------------------------------------
12 License
13  This file is part of QGDsolver library, based on OpenFOAM+.
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22  You should have received a copy of the GNU General Public License
23  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
24 Class
25  Foam::fvsc::leastSquares::leastSquaresStencil
26 Description
27  Realisation least squares method for calculationg of differential operators
28 \*---------------------------------------------------------------------------*/
29 
30 #include "leastSquaresStencil.H"
31 #include "polyMesh.H"
32 #include "fvMesh.H"
33 #include "word.H"
34 #include "IOstream.H"
35 #include "Ostream.H"
36 #include <HashTable.H>
37 #include "addToRunTimeSelectionTable.H"
38 #include "faceSet.H"
39 
40 namespace Foam
41 {
42 namespace fvsc
43 {
44  defineTypeNameAndDebug(leastSquares,0);
46  (
48  leastSquares,
49  components
50  );
51 }
52 }
53 
54 
55 // constructors
57 :
58  fvscStencil(io),
59  leastSquaresBase(mesh_)
60 {
61  faceSet degenerateFacesSet
62  (
63  //faceSetHeader
64  mesh_,
65  "degenerateStencilFaces",
66  IOobject::READ_IF_PRESENT,
67  IOobject::NO_WRITE
68  );
69 
70  if (degenerateFacesSet.size() > 0) //.headerOk())
71  {
72  Info << "Found set with faces for reduced approximation QGD terms" << endl;
73 
74  //read list of degenerated faces
75 
76 
77  const labelList degenerateFaces = degenerateFacesSet.toc();
78 
79  labelHashSet intDegFaces;
80  List<labelHashSet> procDegFaces (procDegFaces_.size());
81 
82  forAll(degenerateFaces, iDegFace)
83  {
84  label faceId = degenerateFaces[iDegFace];
85 
86  if (mesh_.isInternalFace(faceId))
87  {
88  intDegFaces.insert(faceId);
89  }
90  else
91  {
92  label patchId = mesh_.boundaryMesh().whichPatch(faceId);
93  label iPatch = -1;
94  forAll(procPairs_, iPP)
95  {
96  if (procPairs_[iPP] == patchId)
97  {
98  iPatch = iPP;
99  break;
100  }
101  }
102 
103  if (iPatch > -1)
104  {
105  procDegFaces[iPatch].insert
106  (
107  faceId
108  -
109  mesh_.boundaryMesh()[patchId].start()
110  );
111  }
112  }
113  }
114 
115  internalDegFaces_.append(intDegFaces.toc());
116  forAll(procDegFaces, iProcPair)
117  {
118  if (procDegFaces[iProcPair].toc().size() > 0)
119  {
120  procDegFaces_[iProcPair].append
121  (
122  procDegFaces[iProcPair].toc()
123  );
124  }
125  }
126  }
127  else
128  {
129  Info << "Set \"degenerateStencilFaces\" with faces for reduced approximation QGD terms not found" << endl;
130  }
131 }
132 
134 {
135 }
136 
137 //- Calculate gradient of volume vector field on the faces.
138 //
139 // \param iVF Internal vector field.
140 // Allowable values: constant reference to the volVectorField.
141 //
142 // \return Gradient of iVF (tensor field) which was computed on the faces of mesh.
143 Foam::tmp<Foam::surfaceTensorField> Foam::fvsc::leastSquares::Grad(const volVectorField& iVF)
144 {
145  surfaceVectorField gradComp0col = Grad(iVF.component(0));
146  surfaceVectorField gradComp1col = Grad(iVF.component(1));
147  surfaceVectorField gradComp2col = Grad(iVF.component(2));
148 
149  tmp<surfaceTensorField> tgradIVF(0* nf_* fvc::snGrad(iVF));
150  surfaceTensorField& gradIVF = tgradIVF.ref();
151 
152  //set internal field
153  gradIVF.primitiveFieldRef().replace(0, gradComp0col.primitiveField().component(0));
154  gradIVF.primitiveFieldRef().replace(1, gradComp1col.primitiveField().component(0));
155  gradIVF.primitiveFieldRef().replace(2, gradComp2col.primitiveField().component(0));
156 
157  gradIVF.primitiveFieldRef().replace(3, gradComp0col.primitiveField().component(1));
158  gradIVF.primitiveFieldRef().replace(4, gradComp1col.primitiveField().component(1));
159  gradIVF.primitiveFieldRef().replace(5, gradComp2col.primitiveField().component(1));
160 
161  gradIVF.primitiveFieldRef().replace(6, gradComp0col.primitiveField().component(2));
162  gradIVF.primitiveFieldRef().replace(7, gradComp1col.primitiveField().component(2));
163  gradIVF.primitiveFieldRef().replace(8, gradComp2col.primitiveField().component(2));
164 
165  //set external fields
166  forAll(mesh_.boundaryMesh(), patchi)
167  {
168  forAll(mesh_.boundary()[patchi], facei)
169  {
170  gradIVF.boundaryFieldRef()[patchi][facei].component(0) =
171  gradComp0col.boundaryField()[patchi][facei].component(0);
172  gradIVF.boundaryFieldRef()[patchi][facei].component(1) =
173  gradComp1col.boundaryField()[patchi][facei].component(0);
174  gradIVF.boundaryFieldRef()[patchi][facei].component(2) =
175  gradComp2col.boundaryField()[patchi][facei].component(0);
176 
177  gradIVF.boundaryFieldRef()[patchi][facei].component(3) =
178  gradComp0col.boundaryField()[patchi][facei].component(1);
179  gradIVF.boundaryFieldRef()[patchi][facei].component(4) =
180  gradComp1col.boundaryField()[patchi][facei].component(1);
181  gradIVF.boundaryFieldRef()[patchi][facei].component(5) =
182  gradComp2col.boundaryField()[patchi][facei].component(1);
183 
184  gradIVF.boundaryFieldRef()[patchi][facei].component(6) =
185  gradComp0col.boundaryField()[patchi][facei].component(2);
186  gradIVF.boundaryFieldRef()[patchi][facei].component(7) =
187  gradComp1col.boundaryField()[patchi][facei].component(2);
188  gradIVF.boundaryFieldRef()[patchi][facei].component(8) =
189  gradComp2col.boundaryField()[patchi][facei].component(2);
190  }
191  }
192 
193  return tgradIVF;
194 };
195 
196 //- Calculate divergence of volume vector field on the faces.
197 //
198 // \param iVF Internal vector field.
199 // Allowable values: constant reference to the volVectorField.
200 //
201 // \return Divergence of iVF (scalar field) which was computed on the faces of mesh.
202 Foam::tmp<Foam::surfaceScalarField> Foam::fvsc::leastSquares::Div(const volVectorField& iVF)
203 {
204  surfaceVectorField gradComp0 = Grad(iVF.component(0));
205  surfaceVectorField gradComp1 = Grad(iVF.component(1));
206  surfaceVectorField gradComp2 = Grad(iVF.component(2));
207 
208  tmp<surfaceScalarField> tdivIVF(0 * (nf_ & fvc::snGrad(iVF)));
209  surfaceScalarField& divIVF = tdivIVF.ref();
210 
211  divIVF.primitiveFieldRef() = gradComp0.primitiveField().component(0)
212  + gradComp1.primitiveField().component(1)
213  + gradComp2.primitiveField().component(2);
214 
215  forAll(mesh_.boundary(), patchi)
216  {
217  divIVF.boundaryFieldRef()[patchi] =
218  gradComp0.boundaryField()[patchi].component(0)
219  +
220  gradComp1.boundaryField()[patchi].component(1)
221  +
222  gradComp2.boundaryField()[patchi].component(2);
223  }
224 
225  return tdivIVF;
226 };
227 
228 //- Calculate divergence of volume tensor field on the faces.
229 //
230 // \param iTF Internal tensor field.
231 // Allowable values: constant reference to the volTensorField.
232 //
233 // \return Divergence of iTF (vector field) which was computed on the faces of mesh.
234 Foam::tmp<Foam::surfaceVectorField> Foam::fvsc::leastSquares::Div(const volTensorField& iTF)
235 {
236  tmp<surfaceVectorField> gradComp0 (Grad(iTF.component(0)));
237  tmp<surfaceVectorField> gradComp1 (Grad(iTF.component(1)));
238  tmp<surfaceVectorField> gradComp2 (Grad(iTF.component(2)));
239 
240  tmp<surfaceVectorField> gradComp3 (Grad(iTF.component(3)));
241  tmp<surfaceVectorField> gradComp4 (Grad(iTF.component(4)));
242  tmp<surfaceVectorField> gradComp5 (Grad(iTF.component(5)));
243 
244  tmp<surfaceVectorField> gradComp6 (Grad(iTF.component(6)));
245  tmp<surfaceVectorField> gradComp7 (Grad(iTF.component(7)));
246  tmp<surfaceVectorField> gradComp8 (Grad(iTF.component(8)));
247 
248  tmp<surfaceScalarField> divComp0 (gradComp0().component(0) + gradComp3().component(1) + gradComp6().component(2));
249  tmp<surfaceScalarField> divComp1 (gradComp1().component(0) + gradComp4().component(1) + gradComp7().component(2));
250  tmp<surfaceScalarField> divComp2 (gradComp2().component(0) + gradComp5().component(1) + gradComp8().component(2));
251 
252  tmp<surfaceVectorField> tdivITF(0*nf_*fvc::snGrad(iTF.component(0)));
253  surfaceVectorField& divITF = tdivITF.ref();
254 
255  divITF.primitiveFieldRef().replace(0, divComp0().primitiveField());
256  divITF.primitiveFieldRef().replace(1, divComp1().primitiveField());
257  divITF.primitiveFieldRef().replace(2, divComp2().primitiveField());
258 
259  forAll(mesh_.boundary(), patchi)
260  {
261  forAll(mesh_.boundary()[patchi], facei)
262  {
263  divITF.boundaryFieldRef()[patchi][facei].component(0) =
264  divComp0().boundaryField()[patchi][facei];
265  divITF.boundaryFieldRef()[patchi][facei].component(1) =
266  divComp1().boundaryField()[patchi][facei];
267  divITF.boundaryFieldRef()[patchi][facei].component(2) =
268  divComp2().boundaryField()[patchi][facei];
269  }
270  }
271 
272  return tdivITF;
273 }
274 
275 //
276 //END-OF-FILE
277 //
278 
279 
List< DynamicList< label > > procDegFaces_
tmp< surfaceVectorField > Grad(const volScalarField &iF)
Calculate gradient of volume scalar function on the faces.
tmp< surfaceScalarField > Div(const volVectorField &iVF)
Calculate divergence of volume vector field on the faces.
addToRunTimeSelectionTable(fvscStencil, GaussVolPoint, components)
surfaceVectorField nf_
Definition: fvscStencil.H:54
HashSet< label, Hash< label > > labelHashSet
const fvMesh & mesh_
Definition: fvscStencil.H:44
leastSquares(const IOobject &)
Construct from IOobject. Optional flag for if IOobject is the.
forAll(Y, i)
Definition: QGDYEqn.H:36
fvscStencil(const IOobject &io)
Construct from components.
virtual tmp< surfaceVectorField > Grad(const volScalarField &vF)
Definition: fvscStencil.H:118
defineTypeNameAndDebug(fvscStencil, 0)
DynamicList< label > internalDegFaces_