IjkField.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) 2019 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// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
29
30template<class Type>
32(
33 const labelVector& newSizes,
34 const Type& val
35)
36{
37 labelVector& ourSizes = sizes();
38
39 if (ijk_.empty() || !cmptProduct(newSizes))
40 {
41 // Either/both are empty, can redimension directly
42 ourSizes = newSizes;
43 Field<Type>::resize(ijk_.size(), val);
44 return;
45 }
46
47 const unsigned diffs
48 (
49 (ourSizes.x() != newSizes.x() ? 0x100 : 0)
50 | (ourSizes.y() != newSizes.y() ? 0x010 : 0)
51 | (ourSizes.z() != newSizes.z() ? 0x001 : 0)
52 );
53
54 switch (diffs)
55 {
56 case 0x000:
57 // No change
58 return;
59 break;
60
61 case 0x001:
62 // Change in k only, can redimension directly
63 ourSizes = newSizes;
64 Field<Type>::resize(ijk_.size(), val);
65 return;
66 break;
67
68 case 0x010:
69 // 2D change in j only, can redimension directly
70 if (ourSizes.z() == 1)
71 {
72 ourSizes = newSizes;
73 Field<Type>::resize(ijk_.size(), val);
74 return;
75 }
76 break;
77 }
78
79
80 if ((ourSizes.x()*ourSizes.y()) == newSizes.x()*newSizes.y())
81 {
82 // Re-partition i,j with the same size
83 ourSizes = newSizes;
84 Field<Type>::resize(ijk_.size(), val);
85 return;
86 }
87
88
89 IjkField<Type>& ourContent = *this;
90
91 IjkField<Type> newContent(newSizes, val);
92
93 // Need new addressing space
94 const label ni = min(ourSizes.x(), newSizes.x());
95 const label nj = min(ourSizes.y(), newSizes.y());
96 const label nk = min(ourSizes.z(), newSizes.z());
97
98 for (label k=0; k<nk; ++k)
99 {
100 for (label j=0; j<nj; ++j)
101 {
102 for (label i=0; i<ni; ++i)
103 {
104 newContent(i,j,k) = ourContent(i,j,k);
105 }
106 }
107 }
108
109 ourSizes = newSizes;
110 Field<Type>::transfer(newContent);
111}
112
113
114template<class Type>
116{
117 resize(newSizes, Zero);
118}
119
120
121// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
122
123template<class Type>
125{
126 if (this != &rhs)
127 {
128 sizes() = rhs.sizes();
129
131 }
132}
133
134
135template<class Type>
137{
138 if (this != &(rhs()))
139 {
140 sizes() = rhs().sizes();
141
143 }
144}
145
146
147// ************************************************************************* //
label k
virtual bool resize()
Resize the ODE solver.
Definition: Euler.C:53
Generic templated field type.
Definition: Field.H:82
Generic templated field type with i-j-k addressing.
Definition: IjkField.H:56
const labelVector & sizes() const
Return i,j,k addressing sizes.
Definition: IjkFieldI.H:149
void operator=(const IjkField< Type > &rhs)
Copy assignment.
Definition: IjkField.C:124
const Cmpt & z() const
Access to the vector z component.
Definition: VectorI.H:85
const Cmpt & y() const
Access to the vector y component.
Definition: VectorI.H:79
const Cmpt & x() const
Access to the vector x component.
Definition: VectorI.H:73
A class for managing temporary objects.
Definition: tmp.H:65
patchWriters resize(patchIds.size())
Cmpt cmptProduct(const VectorSpace< Form, Cmpt, Ncmpts > &vs)
Definition: VectorSpaceI.H:598
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33