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);
40  defineRunTimeSelectionTable(controlPointsDefinition, dictionary);
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_.replace(0, cps_.component(0)*scale.x());
66  cps_.replace(1, cps_.component(1)*scale.y());
67  cps_.replace(2, cps_.component(2)*scale.z());
68 
69  // Rotation matrices
70  tensor Rx
71  (
72  1, 0 , 0,
73  0, ::cos(rotation.x()), -::sin(rotation.x()),
74  0, ::sin(rotation.x()), ::cos(rotation.x())
75  );
76  tensor Ry
77  (
78  ::cos(rotation.y()), 0, ::sin(rotation.y()),
79  0 , 1, 0,
80  -::sin(rotation.y()), 0, ::cos(rotation.y())
81  );
82  tensor Rz
83  (
84  ::cos(rotation.z()), -::sin(rotation.z()), 0,
85  ::sin(rotation.z()), ::cos(rotation.z()), 0,
86  0, 0 , 1
87  );
88 
89  // Comined rotation matrix
90  tensor R = (Rz & Rx) & Ry;
91 
92  // Rotate cps
93  cps_ = R & cps_;
94 
95  // Translate cps
96  cps_ += position;
97 }
98 
99 
100 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
101 
102 Foam::controlPointsDefinition::controlPointsDefinition
103 (
104  NURBS3DVolume& box
105 )
106 :
107  box_(box),
108  cps_(box.getControlPoints())
109 {}
110 
111 
112 // * * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * //
113 
115 (
116  NURBS3DVolume& box
117 )
118 {
119  const dictionary& dict = box.dict();
120  const word type(dict.get<word>("controlPointsDefinition"));
121 
122  Info<< "controlPointsDefinition type : " << type << endl;
123 
124  auto* ctorPtr = dictionaryConstructorTable(type);
125 
126  if (!ctorPtr)
127  {
129  (
130  dict,
131  "controlPointsDefinition",
132  type,
133  *dictionaryConstructorTablePtr_
134  ) << exit(FatalIOError);
135  }
136 
137  return autoPtr<controlPointsDefinition>(ctorPtr(box));
138 }
139 
140 
141 // ************************************************************************* //
Foam::NURBS3DVolume::dict
const dictionary & dict() const
Get dictionary.
Definition: NURBS3DVolumeI.H:106
Foam::Tensor< scalar >
Foam::Vector::x
const Cmpt & x() const
Access to the vector x component.
Definition: VectorI.H:73
mathematicalConstants.H
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::defineRunTimeSelectionTable
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
Foam::sin
dimensionedScalar sin(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:264
Foam::NURBS3DVolume
NURBS3DVolume morpher. Includes support functions for gradient computations Base class providing supp...
Definition: NURBS3DVolume.H:72
Foam::Ry
tensor Ry(const scalar &omega)
Rotational transformation tensor about the y-axis by omega radians.
Definition: transform.H:99
Foam::FatalIOError
IOerror FatalIOError
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::Rz
tensor Rz(const scalar &omega)
Rotational transformation tensor about the z-axis by omega radians.
Definition: transform.H:113
Foam::Vector::z
const Cmpt & z() const
Access to the vector z component.
Definition: VectorI.H:85
Foam::Rx
tensor Rx(const scalar &omega)
Rotational transformation tensor about the x-axis by omega radians.
Definition: transform.H:85
controlPointsDefinition.H
R
#define R(A, B, C, D, E, F, K, M)
FatalIOErrorInLookup
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
Definition: error.H:478
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::controlPointsDefinition::New
static autoPtr< controlPointsDefinition > New(NURBS3DVolume &box)
Return a reference to the selected controlPointsDefinition model.
Definition: controlPointsDefinition.C:115
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::Vector::y
const Cmpt & y() const
Access to the vector y component.
Definition: VectorI.H:79
Foam::constant::mathematical::pi
constexpr scalar pi(M_PI)
Foam::Vector< scalar >
Foam::controlPointsDefinition::transformControlPoints
void transformControlPoints(const vector &geometryMin, const vector &geometryMax)
Definition: controlPointsDefinition.C:47
Foam::roots::type
type
Types of root.
Definition: Roots.H:54
Foam::NURBS3DVolume::getControlPoints
const vectorField & getControlPoints() const
Get control points.
Definition: NURBS3DVolumeI.H:52
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::cos
dimensionedScalar cos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:265