forwardOrAssignFieldMapper.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2019-2023 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
27 
28 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
29 
30 void Foam::forwardOrAssignFieldMapper::unmappedError() const
31 {
33  << "A field could not be mapped because a value was not provided for "
34  << "unmapped elements" << exit(FatalError);
35 }
36 
37 
38 void Foam::forwardOrAssignPatchFieldMapper::unmappedError() const
39 {
41  << "The " << fieldTypeName_ << " " << fieldBaseTypeName_
42  << " for patch " << patchName_ << " of field " << internalFieldName_
43  << " could not be mapped because a value was not provided for "
44  << "unmapped elements " << exit(FatalError);
45 }
46 
47 
48 template<class Type>
49 void Foam::forwardOrAssignFieldMapper::map
50 (
51  Field<Type>& f,
52  const Field<Type>& mapF
53 ) const
54 {
55  if (hasUnmapped_)
56  {
57  unmappedError();
58  }
59 
60  f.map(mapF, addressing_);
61 }
62 
63 
64 template<class Type>
65 Foam::tmp<Foam::Field<Type>> Foam::forwardOrAssignFieldMapper::map
66 (
67  const Field<Type>& mapF
68 ) const
69 {
70  tmp<Field<Type>> tf(new Field<Type>(addressing_.size()));
71  map(tf.ref(), mapF);
72  return tf;
73 }
74 
75 
76 template<class Type>
77 void Foam::forwardOrAssignFieldMapper::mapOrAssign
78 (
79  Field<Type>& f,
80  const Field<Type>& mapF,
81  const Type& unmappedVal
82 ) const
83 {
84  if (hasUnmapped_)
85  {
86  f = unmappedVal;
87  }
88 
89  f.map(mapF, addressing_);
90 }
91 
92 
93 template<class Type>
94 Foam::tmp<Foam::Field<Type>> Foam::forwardOrAssignFieldMapper::mapOrAssign
95 (
96  const Field<Type>& mapF,
97  const Type& unmappedVal
98 ) const
99 {
100  tmp<Field<Type>> tf(new Field<Type>(addressing_.size()));
101  mapOrAssign(tf.ref(), mapF, unmappedVal);
102  return tf;
103 }
104 
105 
106 template<class Type>
107 void Foam::forwardOrAssignFieldMapper::mapOrAssign
108 (
109  Field<Type>& f,
110  const Field<Type>& mapF,
111  const FieldFunctor<Type>& unmappedFunc
112 ) const
113 {
114  if (hasUnmapped_)
115  {
116  f = unmappedFunc();
117  }
118 
119  f.map(mapF, addressing_);
120 }
121 
122 
123 template<class Type>
124 Foam::tmp<Foam::Field<Type>> Foam::forwardOrAssignFieldMapper::mapOrAssign
125 (
126  const Field<Type>& mapF,
127  const FieldFunctor<Type>& unmappedFunc
128 ) const
129 {
130  tmp<Field<Type>> tf(new Field<Type>(addressing_.size()));
131  mapOrAssign(tf.ref(), mapF, unmappedFunc);
132  return tf;
133 }
134 
135 
136 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
137 
139 (
142 )
143 
144 
146 
147 
149 (
152 )
153 
154 
156 
157 
158 // ************************************************************************* //
Pre-declare SubField and related Field type.
Definition: Field.H:83
Class used to lazily evaluate fields.
Definition: fieldMapper.H:176
Forward field mapper that permits assigning a value on unmapped elements.
A class for managing temporary objects.
Definition: tmp.H:55
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
#define IMPLEMENT_FIELD_MAPPER_MAP_OPERATOR(Type, mapperType)
Definition: fieldMapperM.H:69
#define IMPLEMENT_FIELD_MAPPER_MAP_OR_ASSIGN_OPERATOR(Type, mapperType)
Definition: fieldMapperM.H:89
const tensorField & tf
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
error FatalError
FOR_ALL_FIELD_TYPES(makeFieldSourceTypedef)
labelList f(nPoints)