advectionDiffusionPatchDistMethod.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 | Copyright (C) 2015 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
27 #include "surfaceInterpolate.H"
28 #include "fvcGrad.H"
29 #include "fvcDiv.H"
30 #include "fvmDiv.H"
31 #include "fvmLaplacian.H"
32 #include "fvmSup.H"
34 
37 
38 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
39 
40 namespace Foam
41 {
42 namespace patchDistMethods
43 {
46 }
47 }
48 
49 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
50 
51 Foam::patchDistMethods::advectionDiffusion::advectionDiffusion
52 (
53  const dictionary& dict,
54  const fvMesh& mesh,
55  const labelHashSet& patchIDs
56 )
57 :
58  patchDistMethod(mesh, patchIDs),
59  coeffs_(dict.subDict(type() + "Coeffs")),
60  pdmPredictor_
61  (
63  (
64  coeffs_,
65  mesh,
66  patchIDs
67  )
68  ),
69  epsilon_(coeffs_.lookupOrDefault<scalar>("epsilon", 0.1)),
70  tolerance_(coeffs_.lookupOrDefault<scalar>("tolerance", 1e-3)),
71  maxIter_(coeffs_.lookupOrDefault<int>("maxIter", 10)),
72  predicted_(false)
73 {}
74 
75 
76 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
77 
79 {
80  return correct(y, const_cast<volVectorField&>(volVectorField::null()));
81 }
82 
83 
85 (
86  volScalarField& y,
88 )
89 {
90  if (!predicted_)
91  {
92  pdmPredictor_->correct(y);
93  predicted_ = true;
94  }
95 
97  (
98  IOobject
99  (
100  "ny",
101  mesh_.time().timeName(),
102  mesh_,
105  false
106  ),
107  mesh_,
109  patchTypes<vector>(mesh_, patchIDs_)
110  );
111 
112  const fvPatchList& patches = mesh_.boundary();
113 
114  forAllConstIter(labelHashSet, patchIDs_, iter)
115  {
116  label patchi = iter.key();
117  ny.boundaryField()[patchi] == -patches[patchi].nf();
118  }
119 
120  int iter = 0;
121  scalar initialResidual = 0;
122 
123  do
124  {
125  ny = fvc::grad(y);
126  ny /= (mag(ny) + SMALL);
127 
129  nf /= (mag(nf) + SMALL);
130 
131  surfaceScalarField yPhi("yPhi", mesh_.Sf() & nf);
132 
133  fvScalarMatrix yEqn
134  (
135  fvm::div(yPhi, y)
136  - fvm::Sp(fvc::div(yPhi), y)
137  - epsilon_*y*fvm::laplacian(y)
138  ==
139  dimensionedScalar("1", dimless, 1.0)
140  );
141 
142  yEqn.relax();
143  initialResidual = yEqn.solve().initialResidual();
144 
145  } while (initialResidual > tolerance_ && ++iter < maxIter_);
146 
147  // Only calculate n if the field is defined
148  if (notNull(n))
149  {
150  n = -ny;
151  }
152 
153  return true;
154 }
155 
156 
157 // ************************************************************************* //
tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > interpolate(const GeometricField< Type, fvPatchField, volMesh > &vf, const surfaceScalarField &faceFlux, Istream &schemeData)
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
Calculate the matrix for implicit and explicit sources.
tmp< fvMatrix< Type > > div(const surfaceScalarField &flux, const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
Definition: fvmDiv.C:46
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:61
dimensioned< scalar > mag(const dimensioned< Type > &)
GeometricBoundaryField & boundaryField()
Return reference to GeometricBoundaryField.
defineTypeNameAndDebug(advectionDiffusion, 0)
Info<< "Predicted p max-min : "<< max(p).value()<< " "<< min(p).value()<< endl;rho==max(psi *p+alphal *rhol0+((alphav *psiv+alphal *psil)-psi)*pSat, rhoMin);#1"/home/dm2/henry/OpenFOAM/OpenFOAM-3.0.x/applications/solvers/multiphase/cavitatingFoam/alphavPsi.H"1{alphav=max(min((rho-rholSat)/(rhovSat-rholSat), scalar(1)), scalar(0));alphal=1.0-alphav;Info<< "max-min alphav: "<< max(alphav).value()<< " "<< min(alphav).value()<< endl;psiModel-> correct()
Definition: pEqn.H:74
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
tmp< fvMatrix< Type > > laplacian(const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
Definition: fvmLaplacian.C:46
Calculate the matrix for the divergence of the given field and flux.
Surface Interpolation.
A special matrix type and solver, designed for finite volume solutions of scalar equations. Face addressing is used to make all matrix assembly and solution loops vectorise.
Definition: fvPatchField.H:68
bool notNull(const T &t)
Return true if t is not a reference to the nullObject of type T.
Definition: nullObjectI.H:46
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:638
tmp< fvMatrix< Type > > Sp(const DimensionedField< scalar, volMesh > &, const GeometricField< Type, fvPatchField, volMesh > &)
Namespace for OpenFOAM.
patches[0]
Calculate the gradient of the given field.
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
const double e
Elementary charge.
Definition: doubleFloat.H:78
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
label patchi
Macros for easy insertion into run-time selection tables.
dimensioned< vector > dimensionedVector
Dimensioned vector obtained from generic dimensioned type.
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:589
Calculate the matrix for the laplacian of the field.
addToRunTimeSelectionTable(patchDistMethod, advectionDiffusion, dictionary)
static const GeometricField< vector, fvPatchField, volMesh > & null()
Return a null geometric field.
Calculate the divergence of the given field.
Specialisation of patchDist for wall distance calculation.
static const Vector zero
Definition: Vector.H:80
Calculation of approximate distance to nearest patch for all cells and boundary by solving the Eikona...
static autoPtr< patchDistMethod > New(const dictionary &dict, const fvMesh &mesh, const labelHashSet &patchIDs)
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:47
tmp< GeometricField< Type, fvPatchField, volMesh > > div(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Definition: fvcDiv.C:47
tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh >> grad(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Definition: fvcGrad.C:52
virtual bool correct(volScalarField &y)
Correct the given distance-to-patch field.
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.