transformList.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 | Copyright (C) 2011-2015 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 
26 #include "transformList.H"
27 
28 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
29 
30 template<class T>
32 (
33  const tensor& rotTensor,
34  const UList<T>& field
35 )
36 {
37  List<T> newField(field.size());
38 
39  forAll(field, i)
40  {
41  newField[i] = transform(rotTensor, field[i]);
42  }
43 
44  return newField;
45 }
46 
47 
48 template<class T>
49 void Foam::transformList(const tensor& rotTensor, UList<T>& field)
50 {
51  forAll(field, i)
52  {
53  field[i] = transform(rotTensor, field[i]);
54  }
55 }
56 
57 
58 template<class T>
59 void Foam::transformList(const tensorField& rotTensor, UList<T>& field)
60 {
61  if (rotTensor.size() == 1)
62  {
63  forAll(field, i)
64  {
65  field[i] = transform(rotTensor[0], field[i]);
66  }
67  }
68  else if (rotTensor.size() == field.size())
69  {
70  forAll(field, i)
71  {
72  field[i] = transform(rotTensor[i], field[i]);
73  }
74  }
75  else
76  {
78  << "Sizes of field and transformation not equal. field:"
79  << field.size() << " transformation:" << rotTensor.size()
80  << abort(FatalError);
81  }
82 }
83 
84 
85 template<class T>
86 void Foam::transformList(const tensor& rotTensor, Map<T>& field)
87 {
88  forAllIter(typename Map<T>, field, iter)
89  {
90  iter() = transform(rotTensor[0], iter());
91  }
92 }
93 
94 
95 template<class T>
96 void Foam::transformList(const tensorField& rotTensor, Map<T>& field)
97 {
98  if (rotTensor.size() == 1)
99  {
100  forAllIter(typename Map<T>, field, iter)
101  {
102  iter() = transform(rotTensor[0], iter());
103  }
104  }
105  else
106  {
108  << "Multiple transformation tensors not supported. field:"
109  << field.size() << " transformation:" << rotTensor.size()
110  << abort(FatalError);
111  }
112 }
113 
114 
115 template<class T>
116 void Foam::transformList(const tensor& rotTensor, EdgeMap<T>& field)
117 {
118  forAllIter(typename EdgeMap<T>, field, iter)
119  {
120  iter() = transform(rotTensor[0], iter());
121  }
122 }
123 
124 
125 template<class T>
126 void Foam::transformList(const tensorField& rotTensor, EdgeMap<T>& field)
127 {
128  if (rotTensor.size() == 1)
129  {
130  forAllIter(typename EdgeMap<T>, field, iter)
131  {
132  iter() = transform(rotTensor[0], iter());
133  }
134  }
135  else
136  {
138  << "Multiple transformation tensors not supported. field:"
139  << field.size() << " transformation:" << rotTensor.size()
140  << abort(FatalError);
141  }
142 }
143 
144 
145 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
#define forAllIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:453
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
label size() const
Return number of elements in table.
void transformList(const tensor &, UList< T > &)
Apply transformation to list. Either single transformation tensor.
Definition: transformList.C:49
errorManip< error > abort(error &err)
Definition: errorManip.H:131
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:60
Map from edge (expressed as its endpoints) to value.
Definition: EdgeMap.H:47
Spatial transformation functions for primitive fields.
label size() const
Return the number of elements in the UList.
Definition: UListI.H:299
Tensor< scalar > tensor
Tensor of scalars.
Definition: tensor.H:51
dimensionSet transform(const dimensionSet &)
Definition: dimensionSet.C:465
A HashTable to objects of type <T> with a label key.
Definition: Map.H:49