multiplyTemplates.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) 2020 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// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
29
30template<class Type>
31bool Foam::functionObjects::multiply::initialiseResult(const word& fieldName)
32{
33 typedef GeometricField<Type, fvPatchField, volMesh> volFieldType;
34
35 auto* fieldPtr = mesh_.cfindObject<volFieldType>(fieldName);
36
37 if (fieldPtr)
38 {
39 auto* resultFieldPtr = mesh_.getObjectPtr<regIOobject>(resultName_);
40
41 if (resultFieldPtr)
42 {
43 resultFieldPtr->checkOut();
44 }
45
46 Log << " Initialising "
47 << resultName_ << " to " << fieldPtr->name() << endl;
48
49 return store(resultName_, tmp<volFieldType>::New(*fieldPtr));
50 }
51
52 return false;
53}
54
55
56template<class Type>
57bool Foam::functionObjects::multiply::multiplyResult
58(
59 const word& fieldName,
60 bool& processed
61)
62{
63 typedef GeometricField<Type, fvPatchField, volMesh> volFieldType;
64
65 auto* resultFieldPtr = mesh_.getObjectPtr<volFieldType>(resultName_);
66
67 if (resultFieldPtr)
68 {
69 multiplyFieldType<Type, scalar>(*resultFieldPtr, fieldName, processed);
70 multiplyFieldType<Type, vector>(*resultFieldPtr, fieldName, processed);
71 multiplyFieldType<Type, sphericalTensor>
72 (
73 *resultFieldPtr,
74 fieldName,
75 processed
76 );
77 multiplyFieldType<Type, symmTensor>
78 (
79 *resultFieldPtr,
80 fieldName,
81 processed
82 );
83 multiplyFieldType<Type, tensor>(*resultFieldPtr, fieldName, processed);
84 }
85
86 return processed;
87}
88
89
90template<class Type1, class Type2>
91typename std::enable_if
92<
93 Foam::functionObjects::multiply::is_valid_op<Type1, Type2>::value, bool
94>::type
95Foam::functionObjects::multiply::multiplyFieldType
96(
97 GeometricField<Type1, fvPatchField, volMesh>& result,
98 const word& fieldName,
99 bool& processed
100)
101{
102 if (processed) return processed;
103
104 typedef GeometricField<Type2, fvPatchField, volMesh> volFieldType;
105
106 auto* fieldPtr = mesh_.cfindObject<volFieldType>(fieldName);
107
108 if (fieldPtr)
109 {
110 Log << " Performing " << result.name() << " * " << fieldPtr->name()
111 << endl;
112
113 auto newResult(result*(*fieldPtr));
114 result.checkOut();
115
116 store(resultName_, newResult);
117
118 processed = true;
119 }
120
121 return processed;
122}
123
124
125template<class Type1, class Type2>
126typename std::enable_if
127<
128 !Foam::functionObjects::multiply::is_valid_op<Type1, Type2>::value, bool
129>::type
130Foam::functionObjects::multiply::multiplyFieldType
131(
132 GeometricField<Type1, fvPatchField, volMesh>& result,
133 const word& fieldName,
134 bool& processed
135)
136{
137 if (processed) return processed;
138
139 typedef GeometricField<Type2, fvPatchField, volMesh> volFieldType;
140
141 auto* fieldPtr = mesh_.cfindObject<volFieldType>(fieldName);
142
143 if (fieldPtr)
144 {
145 Info<< " Unsupported operation for "
146 << result.name() << '(' << pTraits<Type1>::typeName << ')'
147 << " * "
148 << fieldPtr->name() << '(' << pTraits<Type2>::typeName << ')'
149 << endl;
150 }
151
152 return processed;
153}
154
155
156// ************************************************************************* //
#define Log
Definition: PDRblock.C:35
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
word resultName_
Name of result fields.
const fvMesh & mesh_
Reference to the fvMesh.
bool store(word &fieldName, const tmp< ObjectType > &tfield, bool cacheable=false)
Store the field in the (sub) objectRegistry under the given name.
const Type * cfindObject(const word &name, const bool recursive=false) const
Return const pointer to the object of the given Type.
Type * getObjectPtr(const word &name, const bool recursive=false) const
messageStream Info
Information stream (stdout output on master, null elsewhere)
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:598
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
static const char *const typeName
The type name used in ensight case files.