Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
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 for (const auto& pfld : input.boundaryField())
41 {
42 if (!polyPatch::constraintType(pfld.patch().patch().type()))
43 {
44 return true;
45 }
46 }
47
48 return false;
49}
50
51
52template<class Type>
53int Foam::functionObjects::zeroGradient::apply
54(
55 const word& inputName,
56 int& state
57)
58{
59 typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
60
61 // State: return 0 (not-processed), -1 (skip), +1 ok
62
63 // Already done, or not available
64 if (state || !foundObject<VolFieldType>(inputName))
65 {
66 return state;
67 }
68
69 const VolFieldType& input = lookupObject<VolFieldType>(inputName);
70
71 if (!returnReduceOr(accept(input)))
72 {
73 state = -1;
74 return state;
75 }
76
77 word outputName(resultName_);
78 outputName.replace("@@", inputName);
79
80 // Also save the field-type, just in case we want it later
81 results_.set(outputName, VolFieldType::typeName);
82
83 if (!foundObject<VolFieldType>(outputName))
84 {
85 auto tzeroGrad = tmp<VolFieldType>::New
86 (
87 IOobject
88 (
90 time_.timeName(),
91 mesh_,
95 ),
96 mesh_,
97 dimensioned<Type>(input.dimensions(), Zero),
99 );
100
101 store(outputName, tzeroGrad);
102 }
103
104 VolFieldType& output = lookupObjectRef<VolFieldType>(outputName);
105
106 output = input;
107 output.correctBoundaryConditions();
108
109 state = +1;
110 return state;
111}
112
113
114// ************************************************************************* //
@ REGISTER
Request registration (bool: true).
@ NO_READ
Nothing to be read.
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
static const word & zeroGradientType() noexcept
The type name for zeroGradient patch fields.
static bool constraintType(const word &patchType)
Return true if the given type is a constraint type.
Definition polyPatch.C:255
static tmp< T > New(Args &&... args)
Construct tmp with forwarding arguments.
Definition tmp.H:215
word outputName("finiteArea-edges.obj")
bool returnReduceOr(const bool value, const int communicator=UPstream::worldComm)
Perform logical (or) MPI Allreduce on a copy. Uses UPstream::reduceOr.
static constexpr const zero Zero
Global zero (0).
Definition zero.H:127