geomDecomp.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) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2018-2023 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "geomDecomp.H"
30 #include "specifiedRotation.H"
31 
32 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
33 
34 void Foam::geomDecomp::setOrder()
35 {
36  const word order(coeffsDict_.getOrDefault<word>("order", ""));
37 
38  if (order.empty())
39  {
40  return;
41  }
42  else if (order.size() != 3)
43  {
45  << "Number of characters in order (" << order << ") != 3"
46  << exit(FatalIOError);
47  }
48 
49  for (int i = 0; i < 3; ++i)
50  {
51  // Change [x-z] -> [0-2]
52 
53  switch (order[i])
54  {
55  case 'x': order_[i] = 0; break;
56  case 'y': order_[i] = 1; break;
57  case 'z': order_[i] = 2; break;
58 
59  default:
61  << "Illegal decomposition order " << order << nl
62  << "It should only contain x, y or z"
63  << exit(FatalIOError);
64  break;
65  }
66  }
67 }
68 
69 
70 void Foam::geomDecomp::readCoeffs()
71 {
72  coeffsDict_.readIfPresent("delta", delta_);
73 
74  coeffsDict_.readEntry("n", n_);
75 
76  if (nDomains_ != n_.x()*n_.y()*n_.z())
77  {
78  // Verify that the input makes sense
79  FatalIOErrorInFunction(coeffsDict_)
80  << "Wrong number of domain divisions in geomDecomp:" << nl
81  << "Number of domains : " << nDomains_ << nl
82  << "Wanted decomposition : " << n_
83  << exit(FatalIOError);
84  }
85  setOrder();
86 
87  // Optional (cartesian) coordinate system transform
88  auto csysPtr = coordinateSystem::NewIfPresent(coeffsDict_, "transform");
89 
90  if (csysPtr)
91  {
92  csys_ = csysPtr();
93  }
94  else if (equal(delta_, 0))
95  {
96  csys_.clear(); // Reset to identity
97  }
98  else
99  {
100  const scalar d = 1 - 0.5*delta_*delta_;
101  const scalar d2 = sqr(d);
102 
103  const scalar a = delta_;
104  const scalar a2 = sqr(a);
105 
106  // Direction (forward/reverse) doesn't matter much
107  tensor rot
108  (
109  d2, -a*d, a,
110  a*d - a2*d, a*a2 + d2, -2*a*d,
111  a*d2 + a2, a*d - a2*d, d2 - a2
112  );
113 
114  // origin=0
116  }
117 }
118 
119 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
120 
122 (
123  const pointField& points
124 ) const
125 {
126  return csys_.localPosition(points);
127 }
128 
129 
131 (
132  const Vector<label>& meshDirs
133 ) const
134 {
135  for (direction dir = 0; dir < Vector<label>::nComponents; ++dir)
136  {
137  if (n_[dir] > 1 && meshDirs[dir] == -1)
138  {
140  << "Trying to decompose a 1/2D mesh"
141  << " into " << n_[dir]
142  << " parts in direction "
144  << endl;
145  }
146  }
147 }
148 
149 
150 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
151 
152 Foam::geomDecomp::geomDecomp(const Vector<label>& divisions)
153 :
154  decompositionMethod(divisions.x()*divisions.y()*divisions.z()),
155  delta_(0.001),
156  csys_(),
157  n_(divisions),
158  order_(0,1,2),
159  coeffsDict_(dictionary::null)
160 {}
161 
162 
164 (
165  const word& derivedType,
166  const dictionary& decompDict,
167  int select
168 )
169 :
170  decompositionMethod(decompDict),
171  delta_(0.001),
172  csys_(),
173  n_(1,1,1),
174  order_(0,1,2),
175  coeffsDict_(findCoeffsDict(derivedType + "Coeffs", select))
176 {
177  readCoeffs();
178 }
179 
180 
182 (
183  const word& derivedType,
184  const dictionary& decompDict,
185  const word& regionName,
186  int select
187 )
188 :
189  decompositionMethod(decompDict, regionName),
190  delta_(0.001),
191  csys_(),
192  n_(1,1,1),
193  order_(0,1,2),
194  coeffsDict_(findCoeffsDict(derivedType + "Coeffs", select))
195 {
196  readCoeffs();
197 }
198 
199 
200 // ************************************************************************* //
Base class for coordinate system specification, the default coordinate system type is cartesian ...
uint8_t direction
Definition: direction.H:46
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
bool equal(const T &a, const T &b)
Compare two values for equality.
Definition: label.H:164
dimensionedSymmTensor sqr(const dimensionedVector &dv)
List< bool > select(const label n, const labelUList &locations)
Construct a selection list of bools (all false) with the given pre-size, subsequently add specified l...
Definition: BitOps.C:134
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Tensor< scalar > tensor
Definition: symmTensor.H:57
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
An user-specified coordinateRotation, primarily to be used internally within coding when the rotation...
::Foam::direction nComponents(const expressions::valueTypeCode) noexcept
The number of components associated with given valueTypeCode.
Definition: exprTraits.C:40
Vector< direction > order_
Decomposition order in terms of components (optional)
Definition: geomDecomp.H:127
scalar y
void checkDecompositionDirections(const Vector< label > &) const
Check that mesh directions are compatible with decomposition.
Definition: geomDecomp.C:124
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
const pointField & points
A class for handling words, derived from Foam::string.
Definition: word.H:63
Abstract base class for domain decomposition.
tmp< pointField > adjustPoints(const pointField &) const
Apply delta (jitter) or rotation to coordinates.
Definition: geomDecomp.C:115
#define WarningInFunction
Report a warning using Foam::Warning.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:627
Foam::word regionName(args.getOrDefault< word >("region", Foam::polyMesh::defaultRegion))
geomDecomp(const Vector< label > &divisions)
Construct with number of x/y/z division (no coefficients or constraints)
Definition: geomDecomp.C:145
const dictionary & decompDict_
Top-level decomposition dictionary (eg, decomposeParDict)
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T, or return the given default value. FatalIOError if it is found and the number of...
const dictionary & coeffsDict_
Coefficients for all derived methods.
Definition: geomDecomp.H:132
A class for managing temporary objects.
Definition: HashPtrTable.H:50
IOerror FatalIOError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL IO ERROR&#39; header text and ...