calcFvcGradTemplates.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) 2012-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 
26 #include "fvMesh.H"
27 #include "fvcGrad.H"
28 
29 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
30 
31 template<class Type>
33 <
37 >&
38 Foam::calcFvcGrad::gradField(const word& gradName, const dimensionSet& dims)
39 {
40  Info<< "gradField" << endl;
41 
42  typedef typename outerProduct<vector, Type>::type gradType;
44 
45  const fvMesh& mesh = refCast<const fvMesh>(obr_);
46 
47  if (!mesh.foundObject<vfGradType>(gradName))
48  {
49  vfGradType* gradFieldPtr
50  (
51  new vfGradType
52  (
53  IOobject
54  (
55  gradName,
56  mesh.time().timeName(),
57  mesh,
60  ),
61  mesh,
63  (
64  "zero",
65  dims/dimLength,
67  )
68  )
69  );
70 
71  mesh.objectRegistry::store(gradFieldPtr);
72  }
73 
74  const vfGradType& field = mesh.lookupObject<vfGradType>(gradName);
75 
76  return const_cast<vfGradType&>(field);
77 }
78 
79 
80 template<class Type>
82 (
83  const word& fieldName,
84  const word& resultName,
85  bool& processed
86 )
87 {
90 
91  typedef typename outerProduct<vector, Type>::type gradType;
93 
94  const fvMesh& mesh = refCast<const fvMesh>(obr_);
95 
96 
97  if (mesh.foundObject<vfType>(fieldName))
98  {
99  const vfType& vf = mesh.lookupObject<vfType>(fieldName);
100 
101  vfGradType& field = gradField<Type>(resultName, vf.dimensions());
102 
103  // De-reference the tmp to avoid a clash with the cached grad field
104  field = fvc::grad(vf)();
105 
106  processed = true;
107  }
108  else if (mesh.foundObject<sfType>(fieldName))
109  {
110  const sfType& sf = mesh.lookupObject<sfType>(fieldName);
111 
112  vfGradType& field = gradField<Type>(resultName, sf.dimensions());
113 
114  // De-reference the tmp to avoid a clash with the cached grad field
115  field = fvc::grad(sf)();
116 
117  processed = true;
118  }
119 }
120 
121 
122 // ************************************************************************* //
Foam::fvPatchField
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:65
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Foam::fvc::grad
tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh >> grad(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Definition: fvcGrad.C:52
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::dimLength
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:50
Foam::calcFvcGrad::calcGrad
void calcGrad(const word &fieldName, const word &resultName, bool &processed)
Helper function to calculate the gradient of different field types.
Definition: calcFvcGradTemplates.C:82
Foam::volMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: volMesh.H:47
Foam::outerProduct::type
typeOfRank< typename pTraits< arg1 >::cmptType, int(pTraits< arg1 >::rank)+int(pTraits< arg2 >::rank) >::type type
Definition: products.H:72
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::dimensionSet
Dimension set for the base types.
Definition: dimensionSet.H:116
Foam::IOobject::NO_WRITE
@ NO_WRITE
Definition: IOobject.H:118
Foam::IOobject::NO_READ
@ NO_READ
Definition: IOobject.H:111
Foam::Info
messageStream Info
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::dimensioned
Generic dimensioned Type class.
Definition: dimensionedScalarFwd.H:41
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
fvMesh.H
sf
volScalarField sf(fieldObject, mesh)
Foam::calcFvcGrad::obr_
const objectRegistry & obr_
Reference to the database.
Definition: calcFvcGrad.H:118
Foam::objectRegistry::foundObject
bool foundObject(const word &name) const
Is the named Type found?
Definition: objectRegistryTemplates.C:142
Foam::pTraits
Traits class for primitives.
Definition: pTraits.H:50
fvcGrad.H
Calculate the gradient of the given field.
Foam::objectRegistry::lookupObject
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type.
Definition: objectRegistryTemplates.C:165
Foam::calcFvcGrad::gradField
GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh > & gradField(const word &gradName, const dimensionSet &dims)
Helper function to create/store/return the gradient field.
Foam::GeometricField
Generic GeometricField class.
Definition: surfaceFieldsFwd.H:52