controlPointsDefinition.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) 2020 PCOpt/NTUA
9  Copyright (C) 2020 FOSS GP
10  Copyright (C) 2021 OpenCFD Ltd.
11 -------------------------------------------------------------------------------
12 License
13  This file is part of OpenFOAM.
14 
15  OpenFOAM is free software: you can redistribute it and/or modify it
16  under the terms of the GNU General Public License as published by
17  the Free Software Foundation, either version 3 of the License, or
18  (at your option) any later version.
19 
20  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
21  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
22  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23  for more details.
24 
25  You should have received a copy of the GNU General Public License
26  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
27 
28 \*---------------------------------------------------------------------------*/
29 
32 #include "mathematicalConstants.H"
33 
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39  defineTypeNameAndDebug(controlPointsDefinition, 0);
41 }
42 
43 
44 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
45 
47 (
48  const vector& geometryMin,
49  const vector& geometryMax
50 )
51 {
52  const dictionary& dict = box_.dict();
53  // Translation vector
54  vector position(dict.get<vector>("translation"));
55 
56  // Rotation vector
57  vector rotation(dict.get<vector>("rotation"));
58  const scalar deg2rad(constant::mathematical::pi/180.0);
59  rotation *= deg2rad;
60 
61  // Scaling
62  vector scale(dict.get<vector>("scale"));
63 
64  // Scale box
65  cps_ = cmptMultiply(cps_, scale);
66 
67  // Rotation matrices
68  tensor Rx
69  (
70  1, 0 , 0,
71  0, ::cos(rotation.x()), -::sin(rotation.x()),
72  0, ::sin(rotation.x()), ::cos(rotation.x())
73  );
74  tensor Ry
75  (
76  ::cos(rotation.y()), 0, ::sin(rotation.y()),
77  0 , 1, 0,
78  -::sin(rotation.y()), 0, ::cos(rotation.y())
79  );
80  tensor Rz
81  (
82  ::cos(rotation.z()), -::sin(rotation.z()), 0,
83  ::sin(rotation.z()), ::cos(rotation.z()), 0,
84  0, 0 , 1
85  );
86 
87  // Comined rotation matrix
88  tensor R = (Rz & Rx) & Ry;
89 
90  // Rotate cps
91  cps_ = R & cps_;
92 
93  // Translate cps
94  cps_ += position;
95 }
96 
97 
98 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
99 
100 Foam::controlPointsDefinition::controlPointsDefinition
101 (
102  NURBS3DVolume& box
103 )
104 :
105  box_(box),
106  cps_(box.getControlPoints())
107 {}
108 
109 
110 // * * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * //
111 
113 (
114  NURBS3DVolume& box
115 )
116 {
117  const dictionary& dict = box.dict();
118  const word type(dict.get<word>("controlPointsDefinition"));
119 
120  Info<< "controlPointsDefinition type : " << type << endl;
121 
122  auto* ctorPtr = dictionaryConstructorTable(type);
123 
124  if (!ctorPtr)
125  {
127  (
128  dict,
129  "controlPointsDefinition",
130  type,
131  *dictionaryConstructorTablePtr_
132  ) << exit(FatalIOError);
133  }
134 
135  return autoPtr<controlPointsDefinition>(ctorPtr(box));
136 }
137 
138 
139 // ************************************************************************* //
dictionary dict
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
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T. FatalIOError if not found, or if the number of tokens is incorrect.
NURBS3DVolume morpher. Includes support functions for gradient computations Base class providing supp...
Definition: NURBS3DVolume.H:69
Macros for easy insertion into run-time selection tables.
tensor Rz(const scalar omega)
Rotational transformation tensor about the z-axis by omega radians.
Definition: transform.H:115
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: POSIX.C:799
dimensionedScalar cos(const dimensionedScalar &ds)
A class for handling words, derived from Foam::string.
Definition: word.H:63
vectorField & cps_
The volumetric B-Splines control points.
void transformControlPoints(const vector &geometryMin, const vector &geometryMax)
Transform control points using the equivalent position, rotation and scale values from the Paraview c...
constexpr scalar pi(M_PI)
dimensioned< Type > cmptMultiply(const dimensioned< Type > &, const dimensioned< Type > &)
NURBS3DVolume & box_
The volumetric B-Splines box.
dimensionedScalar sin(const dimensionedScalar &ds)
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
defineTypeNameAndDebug(combustionModel, 0)
tensor Ry(const scalar omega)
Rotational transformation tensor about the y-axis by omega radians.
Definition: transform.H:99
#define R(A, B, C, D, E, F, K, M)
messageStream Info
Information stream (stdout output on master, null elsewhere)
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
Abstract base for selecting how to construct the control points of a volumetric B-Splines morpher...
Tensor of scalars, i.e. Tensor<scalar>.
tensor Rx(const scalar omega)
Rotational transformation tensor about the x-axis by omega radians.
Definition: transform.H:83
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
Definition: error.H:635
const dictionary & dict() const
Get dictionary.
static autoPtr< controlPointsDefinition > New(NURBS3DVolume &box)
Return a reference to the selected controlPointsDefinition model.
Namespace for OpenFOAM.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL IO ERROR&#39; header text and ...