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-2022 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 auto& patches = input.boundaryField();
41 
42  forAll(patches, patchi)
43  {
44  if (!polyPatch::constraintType(patches[patchi].patch().patch().type()))
45  {
46  return true;
47  }
48  }
49 
50  return false;
51 }
52 
53 
54 template<class Type>
55 int Foam::functionObjects::zeroGradient::apply
56 (
57  const word& inputName,
58  int& state
59 )
60 {
61  typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
62 
63  // State: return 0 (not-processed), -1 (skip), +1 ok
64 
65  // Already done, or not available
66  if (state || !foundObject<VolFieldType>(inputName))
67  {
68  return state;
69  }
70 
71  const VolFieldType& input = lookupObject<VolFieldType>(inputName);
72 
73  if (!returnReduceOr(accept(input)))
74  {
75  state = -1;
76  return state;
77  }
78 
79  word outputName(resultName_);
80  outputName.replace("@@", inputName);
81 
82  // Also save the field-type, just in case we want it later
83  results_.set(outputName, VolFieldType::typeName);
84 
85  if (!foundObject<VolFieldType>(outputName))
86  {
87  auto tzeroGrad = tmp<VolFieldType>::New
88  (
89  IOobject
90  (
91  outputName,
92  time_.timeName(),
93  mesh_,
97  ),
98  mesh_,
99  dimensioned<Type>(input.dimensions(), Zero),
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 // ************************************************************************* //
static const word & zeroGradientType() noexcept
The type name for zeroGradient patch fields.
Definition: fvPatchField.H:221
Ignore writing from objectRegistry::writeObject()
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
word outputName("finiteArea-edges.obj")
static Istream & input(Istream &is, IntRange< T > &range)
Definition: IntRanges.C:33
virtual const word & type() const =0
Runtime type information.
static tmp< T > New(Args &&... args)
Construct tmp with forwarding arguments.
Definition: tmp.H:206
static bool constraintType(const word &patchType)
Return true if the given type is a constraint type.
Definition: polyPatch.C:269
const polyBoundaryMesh & patches
Nothing to be read.
const std::string patch
OpenFOAM patch number as a std::string.
static Ostream & output(Ostream &os, const IntRange< T > &range)
Definition: IntRanges.C:44
bool returnReduceOr(const bool value, const label comm=UPstream::worldComm)
Perform logical (or) MPI Allreduce on a copy. Uses UPstream::reduceOr.
Request registration (bool: true)
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127