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 -------------------------------------------------------------------------------
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  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 // ************************************************************************* //
geomDecomp.H
Foam::geomDecomp::coeffsDict_
const dictionary & coeffsDict_
Coefficients for all derived methods.
Definition: geomDecomp.H:121
Foam::decompositionMethod::decompDict_
const dictionary & decompDict_
Top-level decomposition dictionary (eg, decomposeParDict)
Definition: decompositionMethod.H:89
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::FatalIOError
IOerror FatalIOError
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
specifiedRotation.H
regionName
Foam::word regionName
Definition: createNamedDynamicFvMesh.H:1
Foam::Field< vector >
Foam::geomDecomp::order_
Vector< direction > order_
Decomposition order in terms of components (optional)
Definition: geomDecomp.H:118
Foam::geomDecomp::geomDecomp
geomDecomp(const word &derivedType, const dictionary &decompDict, int select=selectionType::DEFAULT)
Construct for derived type name and decomposition dictionary.
Definition: geomDecomp.C:153
Foam::geomDecomp::checkDecompositionDirections
void checkDecompositionDirections(const Vector< label > &) const
Check that mesh directions are compatible with decomposition.
Definition: geomDecomp.C:131
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::decompositionMethod
Abstract base class for domain decomposition.
Definition: decompositionMethod.H:51
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:51
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::Vector< label >
Foam::geomDecomp::adjustPoints
tmp< pointField > adjustPoints(const pointField &) const
Apply delta (jitter) or rotation to coordinates.
Definition: geomDecomp.C:122
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::direction
uint8_t direction
Definition: direction.H:52
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
Foam::keyType::LITERAL
String literal.
Definition: keyType.H:81
Foam::dictionary::getOrDefault
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:148
Foam::equal
bool equal(const T &s1, const T &s2)
Compare two values for equality.
Definition: doubleFloat.H:46
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:328
Foam::tensor
Tensor< scalar > tensor
Tensor of scalars, i.e. Tensor<scalar>.
Definition: symmTensor.H:61