calcMagTemplates.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-2013 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 "Time.H"
28 #include "volFields.H"
29 #include "surfaceFields.H"
30 
31 template<class FieldType>
32 FieldType& Foam::calcMag::magField
33 (
34  const word& magName,
35  const dimensionSet& dims
36 )
37 {
38  const fvMesh& mesh = refCast<const fvMesh>(obr_);
39 
40  if (!mesh.foundObject<FieldType>(magName))
41  {
42  FieldType* magFieldPtr
43  (
44  new FieldType
45  (
46  IOobject
47  (
48  magName,
49  mesh.time().timeName(),
50  mesh,
51  IOobject::NO_READ,
52  IOobject::NO_WRITE
53  ),
54  mesh,
55  dimensionedScalar("zero", dims, 0.0)
56  )
57  );
58 
59  mesh.objectRegistry::store(magFieldPtr);
60  }
61 
62  const FieldType& f = mesh.lookupObject<FieldType>(magName);
63 
64  return const_cast<FieldType&>(f);
65 }
66 
67 
68 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
69 
70 template<class Type>
72 (
73  const word& fieldName,
74  const word& resultName,
75  bool& processed
76 )
77 {
80 
81  const fvMesh& mesh = refCast<const fvMesh>(obr_);
82 
83  if (mesh.foundObject<vfType>(fieldName))
84  {
85  const vfType& vf = mesh.lookupObject<vfType>(fieldName);
86 
87  volScalarField& field =
88  magField<volScalarField>(resultName_, vf.dimensions());
89 
90  field = mag(vf);
91 
92  processed = true;
93  }
94  else if (mesh.foundObject<sfType>(fieldName))
95  {
96  const sfType& sf = mesh.lookupObject<sfType>(fieldName);
97 
98  surfaceScalarField& field =
99  magField<surfaceScalarField>(resultName_, sf.dimensions());
100 
101  field = mag(sf);
102 
103  processed = true;
104  }
105 }
106 
107 
108 // ************************************************************************* //
volFields.H
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::calcMag::calc
void calc(const word &fieldName, const word &resultName, bool &processed)
Helper function to calculate the magnitude of different field types.
Definition: calcMagTemplates.C:72
surfaceFields.H
Foam::surfaceFields.
Foam::dimensionSet
Dimension set for the base types.
Definition: dimensionSet.H:116
Foam::mag
dimensioned< scalar > mag(const dimensioned< Type > &)
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)
f
labelList f(nPoints)
Foam::calcMag::magField
FieldType & magField(const word &magName, const dimensionSet &dims)
Helper function to create/store/return the mag field.
Definition: calcMagTemplates.C:33
Foam::GeometricField
Generic GeometricField class.
Definition: surfaceFieldsFwd.H:52