VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
CoordinateTransformation3D.cpp
Go to the documentation of this file.
1//=======================================================================================
2// ____ ____ __ ______ __________ __ __ __ __
3// \ \ | | | | | _ \ |___ ___| | | | | / \ | |
4// \ \ | | | | | |_) | | | | | | | / \ | |
5// \ \ | | | | | _ / | | | | | | / /\ \ | |
6// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____
7// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______|
8// \ \ | | ________________________________________________________________
9// \ \ | | | ______________________________________________________________|
10// \ \| | | | __ __ __ __ ______ _______
11// \ | | |_____ | | | | | | | | | _ \ / _____)
12// \ | | _____| | | | | | | | | | | \ \ \_______
13// \ | | | | |_____ | \_/ | | | | |_/ / _____ |
14// \ _____| |__| |________| \_______/ |__| |______/ (_______/
15//
16// This file is part of VirtualFluids. VirtualFluids is free software: you can
17// redistribute it and/or modify it under the terms of the GNU General Public
18// License as published by the Free Software Foundation, either version 3 of
19// the License, or (at your option) any later version.
20//
21// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT
22// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24// for more details.
25//
26// SPDX-License-Identifier: GPL-3.0-or-later
27// SPDX-FileCopyrightText: Copyright © VirtualFluids Project contributors, see AUTHORS.md in root folder
28//
33//=======================================================================================
36
37using namespace std;
38
40{
41 this->setTransformationValues(0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0);
42}
43/*======================================================*/
45 const double &originX3, const double &dx1, const double &dx2,
46 const double &dx3, const double &alpha, const double &beta,
47 const double &gamma)
48{
49 this->setTransformationValues(originX1, originX2, originX3, dx1, dx2, dx3, alpha, beta, gamma);
50}
51/*======================================================*/
53 const double &originX3, const double &dx1, const double &dx2,
54 const double &dx3)
55{
56 this->setTransformationValues(originX1, originX2, originX3, dx1, dx2, dx3, 0.0, 0.0, 0.0);
57}
58/*======================================================*/
60{
61 this->setTransformationValues(transformation->Tx1, transformation->Tx2, transformation->Tx3, transformation->Sx1,
62 transformation->Sx2, transformation->Sx3, transformation->alpha, transformation->beta,
63 transformation->gamma);
64}
65/*======================================================*/
66// void CoordinateTransformation3D::init()
67// {
68// this->Tx1 = 0.0; this->Tx2 = 0.0; this->Tx3 = 0.0;
69// this->Sx1 = 1.0; this->Sx2 = 1.0; this->Sx3 = 1.0;
70// this->alpha = 0.0; this->beta = 0.0; this->gamma = 0.0;
71//
72// this->toX1factorX1 = 1.0; this->toX1factorX2 = 0.0; this->toX1factorX3 = 0.0;
73// this->toX2factorX1 = 0.0; this->toX2factorX2 = 1.0; this->toX2factorX3 = 0.0;
74// this->toX3factorX1 = 0.0; this->toX3factorX2 = 0.0; this->toX3factorX3 = 1.0;
75// this->toX1delta = 0.0; this->toX2delta = 0.0; this->toX3delta = 0.0;
76// this->fromX1factorX1 = 1.0; this->fromX1factorX2 = 0.0; this->fromX1factorX3 = 0.0;
77// this->fromX2factorX1 = 0.0; this->fromX2factorX2 = 1.0; this->fromX2factorX3 = 0.0;
78// this->fromX3factorX1 = 0.0; this->fromX3factorX2 = 0.0; this->fromX3factorX3 = 1.0;
79//
80// this->active = false;
81// this->transformation = false;
82// }
83/*======================================================*/
84
101 const double &originX3, const double &dx1, const double &dx2,
102 const double &dx3, const double &alpha, const double &beta,
103 const double &gamma)
104{
106 throw UbException(UB_EXARGS, "error: at least one delta==0.0");
107
108 this->Tx1 = originX1;
109 this->Tx2 = originX2;
110 this->Tx3 = originX3;
111 this->Sx1 = dx1;
112 this->Sx2 = dx2;
113 this->Sx3 = dx3;
114 this->alpha = alpha;
115 this->beta = beta;
116 this->gamma = gamma;
117
118 double ra = ub_math::PI * alpha / 180.0;
119 double cosA = cos(ra);
120 double sinA = sin(ra);
121 double rb = ub_math::PI * beta / 180.0;
122 double cosB = cos(rb);
123 double sinB = sin(rb);
124 double rg = ub_math::PI * gamma / 180.0;
125 double cosG = cos(rg);
126 double sinG = sin(rg);
127
128 // Matrix-Werte von T_invers (indizes: 12 = spalte 1 zeile 2)
129 double divisor = (Sx1 * Sx2 * Sx3);
130
131 this->toX1factorX1 = +cosB * cosA * Sx2 * Sx3 / divisor;
132 this->toX1factorX2 = -cosB * sinA * Sx1 * Sx3 / divisor;
133 this->toX1factorX3 = +sinB * Sx1 * Sx2 / divisor;
134 this->toX1delta =
135 (-Tx3 * Sx1 * Sx2 * sinB + Tx2 * Sx1 * Sx3 * sinA * cosB - Tx1 * Sx2 * Sx3 * cosB * cosA) / divisor;
136
137 this->toX2factorX1 = Sx2 * Sx3 * (sinG * sinB * cosA + cosG * sinA) / divisor;
138 this->toX2factorX2 = Sx1 * Sx3 * (-sinG * sinB * sinA + cosG * cosA) / divisor;
139 this->toX2factorX3 = -Sx1 * Sx2 * cosB * sinG / divisor;
140 this->toX2delta =
141 (-Tx2 * Sx1 * Sx3 * cosG * cosA + Tx3 * Sx1 * Sx2 * sinG * cosB + Tx2 * Sx1 * Sx3 * sinG * sinA * sinB -
142 Tx1 * Sx2 * Sx3 * cosG * sinA - Tx1 * Sx2 * Sx3 * sinB * sinG * cosA) /
143 divisor;
144
145 this->toX3factorX1 = Sx2 * Sx3 * (-cosG * sinB * cosA + sinG * sinA) / divisor;
146 this->toX3factorX2 = Sx1 * Sx3 * (sinB * cosG * sinA + sinG * cosA) / divisor;
147 this->toX3factorX3 = Sx1 * Sx2 * cosB * cosG / divisor;
148 this->toX3delta =
149 (-Tx2 * Sx1 * Sx3 * sinG * cosA - Tx3 * Sx1 * Sx2 * cosG * cosB - Tx2 * Sx1 * Sx3 * cosG * sinA * sinB -
150 Tx1 * Sx2 * Sx3 * sinG * sinA + Tx1 * Sx2 * Sx3 * sinB * cosG * cosA) /
151 divisor;
152
153 // Matrix-Werte von T_invers (indizes: 12 = spalte 1 zeile 2)
154 this->fromX1factorX1 = cosB * cosA * Sx1;
155 this->fromX1factorX2 = (sinG * sinB * cosA + cosG * sinA) * Sx1;
156 this->fromX1factorX3 = (-cosG * sinB * cosA + sinG * sinA) * Sx1;
157 this->fromX1delta = Tx1;
158
159 this->fromX2factorX1 = -cosB * sinA * Sx2;
160 this->fromX2factorX2 = -(sinG * sinB * sinA - cosG * cosA) * Sx2;
161 this->fromX2factorX3 = (cosG * sinB * sinA + sinG * cosA) * Sx2;
162 this->fromX2delta = Tx2;
163
164 this->fromX3factorX1 = sinB * Sx3;
165 this->fromX3factorX2 = -sinG * cosB * Sx3;
166 this->fromX3factorX3 = cosG * cosB * Sx3;
167 this->fromX3delta = Tx3;
168
169 this->active = true;
170
171 this->transformation = true;
172}
173/*======================================================*/
179{
180 if (this->active == active)
181 return;
182 if (this->transformation)
183 this->active = active;
184}
185/*======================================================*/
192double CoordinateTransformation3D::transformForwardToX1Coordinate(const double &x1, const double &x2,
193 const double &x3) const
194{
195 if (this->active)
196 return this->toX1factorX1 * x1 + this->toX1factorX2 * x2 + this->toX1factorX3 * x3 + this->toX1delta;
197 else
198 return x1;
199}
200/*======================================================*/
201double CoordinateTransformation3D::transformForwardToX2Coordinate(const double &x1, const double &x2,
202 const double &x3) const
203{
204 if (this->active)
205 return this->toX2factorX1 * x1 + this->toX2factorX2 * x2 + this->toX2factorX3 * x3 + this->toX2delta;
206 else
207 return x2;
208}
209/*======================================================*/
210double CoordinateTransformation3D::transformForwardToX3Coordinate(const double &x1, const double &x2,
211 const double &x3) const
212{
213 if (this->active)
214 return this->toX3factorX1 * x1 + this->toX3factorX2 * x2 + this->toX3factorX3 * x3 + this->toX3delta;
215 else
216 return x3;
217}
218/*======================================================*/
224{
225 if (this->active)
226 return (x1 - this->Tx1) / this->Sx1;
227 else
228 return x1;
229}
230/*======================================================*/
232{
233 if (this->active)
234 return (x2 - this->Tx2) / this->Sx2;
235 else
236 return x2;
237}
238/*======================================================*/
240{
241 if (this->active)
242 return (x3 - this->Tx3) / this->Sx3;
243 else
244 return x3;
245}
246/*======================================================*/
253double CoordinateTransformation3D::transformBackwardToX1Coordinate(const double &x1, const double &x2,
254 const double &x3) const
255{
256 if (this->active)
257 return this->fromX1factorX1 * x1 + this->fromX1factorX2 * x2 + this->fromX1factorX3 * x3 + this->fromX1delta;
258 else
259 return x1;
260}
261/*======================================================*/
262double CoordinateTransformation3D::transformBackwardToX2Coordinate(const double &x1, const double &x2,
263 const double &x3) const
264{
265 if (this->active)
266 return this->fromX2factorX1 * x1 + this->fromX2factorX2 * x2 + this->fromX2factorX3 * x3 + this->fromX2delta;
267 else
268 return x2;
269}
270/*======================================================*/
271double CoordinateTransformation3D::transformBackwardToX3Coordinate(const double &x1, const double &x2,
272 const double &x3) const
273{
274 if (this->active)
275 return this->fromX3factorX1 * x1 + this->fromX3factorX2 * x2 + this->fromX3factorX3 * x3 + this->fromX3delta;
276 else
277 return x3;
278}
279/*======================================================*/
285{
286 if (this->active)
287 return x1 * this->Sx1 + this->Tx1;
288 else
289 return x1;
290}
291/*======================================================*/
293{
294 if (this->active)
295 return x2 * this->Sx2 + this->Tx2;
296 else
297 return x2;
298}
299/*======================================================*/
301{
302 if (this->active)
303 return x3 * this->Sx3 + this->Tx3;
304 else
305 return x3;
306}
307/*======================================================*/
313{
315 ss << " CoordinateTransformation3D\n";
316 // ss<<"[isTransformation="<<this->transformation;
317 // ss<<", isActive="<<this->active<<endl;
318 ss << " ,a=" << this->Tx1 << ", b=" << this->Tx2 << ", c=" << this->Tx3 << endl;
319 ss << " , dx1=" << this->Sx1 << ", dx2=" << this->Sx2 << ", dx2=" << this->Sx3 << endl;
320 // ss<<" , alpha="<<this->alpha<<", beta="<<this->beta<endl;
321 // ss<<"]";
322 // ss<<"[to11="<<this->to11<<", to12="<<this->to12<<", to13="<<this->to13;
323 // ss<<", to21="<<this->to21<<", to22="<<this->to22<<", to23="<<this->to23;
324 // ss<<", to31="<<this->to31<<", to32="<<this->to32<<", to33="<<this->to33;
325 // ss<<", toA="<<this->toA<<", toB="<<this->toB<<", toC="<<this->toC;
326 // ss<<", from11="<<this->from11<<", from12="<<this->from12<<", from13="<<this->from13;
327 // ss<<", from21="<<this->from21<<", from22="<<this->from22<<", from23="<<this->from23;
328 // ss<<", from31="<<this->from31<<", from32="<<this->from32<<", from33="<<this->from33;
329 // ss<<", fromA="<<this->fromA; ss<<", fromB="<<this->fromB; ss<<", fromC="<<this->fromC;
330 // ss<<"]}";
331 return ss.str();
332}
333
A class provides 3d coordinate transformation.
std::shared_ptr< T > SPtr
double transformForwardToX3Coordinate(const double &x1, const double &x2, const double &x3) const
double transformBackwardToX2CoordinateIgnoringRotation(const double &x2) const
double transformForwardToX2CoordinateIgnoringRotation(const double &x2) const
double transformBackwardToX2Coordinate(const double &x1, const double &x2, const double &x3) const
double transformBackwardToX3Coordinate(const double &x1, const double &x2, const double &x3) const
double transformBackwardToX1Coordinate(const double &x1, const double &x2, const double &x3) const
double transformForwardToX3CoordinateIgnoringRotation(const double &x3) const
double transformBackwardToX1CoordinateIgnoringRotation(const double &x1) const
double transformBackwardToX3CoordinateIgnoringRotation(const double &x3) const
double transformForwardToX1Coordinate(const double &x1, const double &x2, const double &x3) const
double transformForwardToX2Coordinate(const double &x1, const double &x2, const double &x3) const
void setTransformationValues(const double &originX1, const double &originX2, const double &originX3, const double &dx1, const double &dx2, const double &dx3, const double &alpha, const double &beta, const double &gamma)
Set transformation values.
double transformForwardToX1CoordinateIgnoringRotation(const double &x1) const
#define UB_EXARGS
Definition UbException.h:73
const double PI
bool zero(const T &value)
Definition UbMath.h:139