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 -------------------------------------------------------------------------------
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 
31 #include "mathematicalConstants.H"
32 
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38  defineTypeNameAndDebug(controlPointsDefinition, 0);
39  defineRunTimeSelectionTable(controlPointsDefinition, dictionary);
40 }
41 
42 
43 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
44 
46 (
47  const vector& geometryMin,
48  const vector& geometryMax
49 )
50 {
51  const dictionary& dict = box_.dict();
52  // Translation vector
53  vector position(dict.get<vector>("translation"));
54 
55  // Rotation vector
56  vector rotation(dict.get<vector>("rotation"));
57  const scalar deg2rad(constant::mathematical::pi/180.0);
58  rotation *= deg2rad;
59 
60  // Scaling
61  vector scale(dict.get<vector>("scale"));
62 
63  // Scale box
64  cps_.replace(0, cps_.component(0)*scale.x());
65  cps_.replace(1, cps_.component(1)*scale.y());
66  cps_.replace(2, cps_.component(2)*scale.z());
67 
68  // Rotation matrices
69  tensor Rx
70  (
71  1, 0 , 0,
72  0, ::cos(rotation.x()), -::sin(rotation.x()),
73  0, ::sin(rotation.x()), ::cos(rotation.x())
74  );
75  tensor Ry
76  (
77  ::cos(rotation.y()), 0, ::sin(rotation.y()),
78  0 , 1, 0,
79  -::sin(rotation.y()), 0, ::cos(rotation.y())
80  );
81  tensor Rz
82  (
83  ::cos(rotation.z()), -::sin(rotation.z()), 0,
84  ::sin(rotation.z()), ::cos(rotation.z()), 0,
85  0, 0 , 1
86  );
87 
88  // Comined rotation matrix
89  tensor R = (Rz & Rx) & Ry;
90 
91  // Rotate cps
92  cps_ = R & cps_;
93 
94  // Translate cps
95  cps_ += position;
96 }
97 
98 
99 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
100 
101 Foam::controlPointsDefinition::controlPointsDefinition
102 (
103  NURBS3DVolume& box
104 )
105 :
106  box_(box),
107  cps_(box.getControlPoints())
108 {}
109 
110 
111 // * * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * //
112 
114 (
115  NURBS3DVolume& box
116 )
117 {
118  const dictionary& dict = box.dict();
119  const word type(dict.get<word>("controlPointsDefinition"));
120 
121  Info<< "controlPointsDefinition type : " << type << endl;
122 
123  auto cstrIter = dictionaryConstructorTablePtr_->cfind(type);
124 
125  if (!cstrIter.found())
126  {
128  (
129  dict,
130  "controlPointsDefinition",
131  type,
132  *dictionaryConstructorTablePtr_
133  ) << exit(FatalIOError);
134  }
135 
136  return autoPtr<controlPointsDefinition>(cstrIter()(box));
137 }
138 
139 
140 // ************************************************************************* //
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:62
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:350
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:406
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
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:121
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:114
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:46
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