Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
11License
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
34void 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"
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"
64 break;
65 }
66 }
67}
68
69
70void 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_
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(
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;
146 }
147}
148
149
150// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
151
153:
154 decompositionMethod(divisions.x()*divisions.y()*divisions.z()),
155 delta_(0.001),
156 csys_(),
157 n_(divisions),
158 order_(0,1,2),
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// ************************************************************************* //
scalar y
static const char *const componentNames[]
Templated 3D Vector derived from VectorSpace adding construction from 3 components,...
Definition Vector.H:61
An user-specified coordinateRotation, primarily to be used internally within coding when the rotation...
Base class for coordinate system specification, the default coordinate system type is cartesian .
Abstract base class for domain decomposition.
const dictionary & decompDict_
Top-level decomposition dictionary (eg, decomposeParDict).
decompositionMethod(const label numDomains)
Construct with specified number of domains, no coefficients or constraints.
static FOAM_NO_DANGLING_REFERENCE const dictionary & findCoeffsDict(const dictionary &dict, const word &coeffsName, int select=selectionType::DEFAULT)
Locate coeffsName dictionary or the fallback "coeffs" dictionary within an enclosing dictionary.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
const dictionary & coeffsDict_
Coefficients for all derived methods.
Definition geomDecomp.H:132
Vector< direction > order_
Decomposition order in terms of components (optional).
Definition geomDecomp.H:127
tmp< pointField > adjustPoints(const pointField &) const
Apply delta (jitter) or rotation to coordinates.
Definition geomDecomp.C:115
Vector< label > n_
The divisions.
Definition geomDecomp.H:122
geomDecomp(const Vector< label > &divisions)
Construct with number of x/y/z division (no coefficients or constraints).
Definition geomDecomp.C:145
void checkDecompositionDirections(const Vector< label > &) const
Check that mesh directions are compatible with decomposition.
Definition geomDecomp.C:124
A class for managing temporary objects.
Definition tmp.H:75
A class for handling words, derived from Foam::string.
Definition word.H:66
Foam::word regionName(args.getOrDefault< word >("region", Foam::polyMesh::defaultRegion))
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition error.H:629
const pointField & points
#define WarningInFunction
Report a warning using Foam::Warning.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
bool equal(const T &a, const T &b)
Compare two values for equality.
Definition label.H:180
Tensor< scalar > tensor
Definition symmTensor.H:57
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
uint8_t direction
Definition direction.H:49
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
vectorField pointField
pointField is a vectorField.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50