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-2021 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 const dictionary* transformDict =
88 coeffsDict_.findDict("transform", keyType::LITERAL);
89
90 if (transformDict)
91 {
92 csys_ = coordinateSystem(*transformDict);
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
115 csys_ = coordinateSystem(coordinateRotations::specified(rot));
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
153(
154 const word& derivedType,
155 const dictionary& decompDict,
156 int select
157)
158:
159 decompositionMethod(decompDict),
160 delta_(0.001),
161 csys_(),
162 n_(1,1,1),
163 order_(0,1,2),
164 coeffsDict_(findCoeffsDict(derivedType + "Coeffs", select))
165{
166 readCoeffs();
167}
168
169
171(
172 const word& derivedType,
173 const dictionary& decompDict,
174 const word& regionName,
175 int select
176)
177:
178 decompositionMethod(decompDict, regionName),
179 delta_(0.001),
180 csys_(),
181 n_(1,1,1),
182 order_(0,1,2),
183 coeffsDict_(findCoeffsDict(derivedType + "Coeffs", select))
184{
185 readCoeffs();
186}
187
188
189// ************************************************************************* //
Templated 3D Vector derived from VectorSpace adding construction from 3 components,...
Definition: Vector.H:65
Abstract base class for domain decomposition.
const dictionary & decompDict_
Top-level decomposition dictionary (eg, decomposeParDict)
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Base for geometrical domain decomposition methods.
Definition: geomDecomp.H:89
const dictionary & coeffsDict_
Coefficients for all derived methods.
Definition: geomDecomp.H:121
Vector< direction > order_
Decomposition order in terms of components (optional)
Definition: geomDecomp.H:118
tmp< pointField > adjustPoints(const pointField &) const
Apply delta (jitter) or rotation to coordinates.
Definition: geomDecomp.C:122
void checkDecompositionDirections(const Vector< label > &) const
Check that mesh directions are compatible with decomposition.
Definition: geomDecomp.C:131
@ LITERAL
String literal.
Definition: keyType.H:81
Tensor of scalars, i.e. Tensor<scalar>.
A class for managing temporary objects.
Definition: tmp.H:65
A class for handling words, derived from Foam::string.
Definition: word.H:68
Foam::word regionName(Foam::polyMesh::defaultRegion)
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
const pointField & points
#define WarningInFunction
Report a warning using Foam::Warning.
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
bool equal(const T &s1, const T &s2)
Compare two values for equality.
Definition: doubleFloat.H:46
uint8_t direction
Definition: direction.H:56
IOerror FatalIOError
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53