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-2025 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 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
29 
30 template<class Type>
31 bool 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 
56 template<class Type>
57 bool 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 
90 template<class Type1, class Type2>
91 bool Foam::functionObjects::multiply::multiplyFieldType
92 (
93  GeometricField<Type1, fvPatchField, volMesh>& result,
94  const word& fieldName,
95  bool& processed
96 )
97 {
98  if (processed) return processed;
99 
100  typedef GeometricField<Type2, fvPatchField, volMesh> volFieldType;
101 
102  auto* fieldPtr = mesh_.cfindObject<volFieldType>(fieldName);
103 
104  if (fieldPtr)
105  {
106  if constexpr
107  (
108  Foam::functionObjects::multiply::is_valid_op<Type1, Type2>::value
109  )
110  {
111  Log << " Performing "
112  << result.name() << " * " << fieldPtr->name()
113  << endl;
114 
115  auto newResult(result*(*fieldPtr));
116  result.checkOut();
117 
118  store(resultName_, newResult);
119 
120  processed = true;
121  }
122  else
123  {
124  Info<< " Unsupported operation for "
125  << result.name() << '(' << pTraits<Type1>::typeName << ')'
126  << " * "
127  << fieldPtr->name() << '(' << pTraits<Type2>::typeName << ')'
128  << endl;
129  }
130  }
131 
132  return processed;
133 }
134 
135 
136 // ************************************************************************* //
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:529
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
Return non-const pointer to the object of the given Type, using a const-cast to have it behave like a...
bool store(word &fieldName, const tmp< ObjectType > &tfield, bool cacheable=false)
Store the field in the (sub) objectRegistry under the given name.
static tmp< T > New(Args &&... args)
Construct tmp with forwarding arguments.
Definition: tmp.H:206
word resultName_
Name of result fields.
#define Log
Definition: PDRblock.C:28
messageStream Info
Information stream (stdout output on master, null elsewhere)
const fvMesh & mesh_
Reference to the fvMesh.