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-------------------------------------------------------------------------------
10License
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
34template<class Type>
35bool 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 {
45 {
46 return true;
47 }
48 }
49
50 return false;
51}
52
53
54template<class Type>
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 (!returnReduce(accept(input), orOp<bool>()))
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 (
92 time_.timeName(),
93 mesh_,
96 ),
97 mesh_,
98 dimensioned<Type>(input.dimensions(), Zero),
100 );
101
102 store(outputName, tzeroGrad);
103 }
104
105 VolFieldType& output = lookupObjectRef<VolFieldType>(outputName);
106
107 output = input;
108 output.correctBoundaryConditions();
109
110 state = +1;
111 return state;
112}
113
114
115// ************************************************************************* //
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
virtual void apply()=0
Apply bins.
virtual const word & constraintType() const
Return the constraint type this pointPatch implements.
virtual const word & type() const =0
Runtime type information.
const polyBoundaryMesh & patches
word outputName("finiteArea-edges.obj")
const std::string patch
OpenFOAM patch number as a std::string.
static Istream & input(Istream &is, IntRange< T > &range)
Definition: IntRanges.C:55
static Ostream & output(Ostream &os, const IntRange< T > &range)
Definition: IntRanges.C:66
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Reduce (copy) and return value.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333
static const char *const typeName
The type name used in ensight case files.