zeroGradientTemplates.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) 2016 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
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 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "polyPatch.H"
29 #include "Time.H"
31 
32 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
33 
34 template<class Type>
35 bool Foam::functionObjects::zeroGradient::accept
36 (
37  const GeometricField<Type, fvPatchField, volMesh>& input
38 )
39 {
40  const typename GeometricField<Type, fvPatchField, volMesh>::Boundary&
41  patches = input.boundaryField();
42 
43  forAll(patches, patchi)
44  {
45  if (!polyPatch::constraintType(patches[patchi].patch().patch().type()))
46  {
47  return true;
48  }
49  }
50 
51  return false;
52 }
53 
54 
55 template<class Type>
56 int Foam::functionObjects::zeroGradient::apply
57 (
58  const word& inputName,
59  int& state
60 )
61 {
62  typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
63 
64  // State: return 0 (not-processed), -1 (skip), +1 ok
65 
66  // Already done, or not available
67  if (state || !foundObject<VolFieldType>(inputName))
68  {
69  return state;
70  }
71 
72  const VolFieldType& input = lookupObject<VolFieldType>(inputName);
73 
74  if (!returnReduce(accept(input), orOp<bool>()))
75  {
76  state = -1;
77  return state;
78  }
79 
80  word outputName(resultName_);
81  outputName.replace("@@", inputName);
82 
83  // Also save the field-type, just in case we want it later
84  results_.set(outputName, VolFieldType::typeName);
85 
86  if (!foundObject<VolFieldType>(outputName))
87  {
88  auto tzeroGrad = tmp<VolFieldType>::New
89  (
90  IOobject
91  (
92  outputName,
93  time_.timeName(),
94  mesh_,
97  ),
98  mesh_,
99  dimensioned<Type>(input.dimensions(), Zero),
100  zeroGradientFvPatchField<Type>::typeName
101  );
102 
103  store(outputName, tzeroGrad);
104  }
105 
106  VolFieldType& output = lookupObjectRef<VolFieldType>(outputName);
107 
108  output = input;
109  output.correctBoundaryConditions();
110 
111  state = +1;
112  return state;
113 }
114 
115 
116 // ************************************************************************* //
Foam::IOobject::NO_WRITE
Definition: IOobject.H:195
Foam::output
static Ostream & output(Ostream &os, const IntRange< T > &range)
Definition: IntRanges.C:66
Foam::returnReduce
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
Definition: PstreamReduceOps.H:94
polyPatch.H
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
zeroGradientFvPatchField.H
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
outputName
word outputName("finiteArea-edges.obj")
Foam::polyPatch::constraintType
static bool constraintType(const word &pt)
Return true if the given type is a constraint type.
Definition: polyPatch.C:277
Time.H
Foam::foamVersion::patch
const std::string patch
OpenFOAM patch number as a std::string.
Foam::functionObject::type
virtual const word & type() const =0
Runtime type information.
Foam::tmp::New
static tmp< T > New(Args &&... args)
Construct tmp of T with forwarding arguments.
patches
const polyBoundaryMesh & patches
Definition: convertProcessorPatches.H:65
Foam::input
static Istream & input(Istream &is, IntRange< T > &range)
Definition: IntRanges.C:55
Foam::IOobject::NO_READ
Definition: IOobject.H:188