CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

Rotating a vector in OpenFOAM

Register Blogs Community New Posts Updated Threads Search

Like Tree5Likes
  • 1 Post By msaravia
  • 4 Post By olesen

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 29, 2018, 14:42
Default Rotating a vector in OpenFOAM
  #1
Senior Member
 
Join Date: Mar 2018
Posts: 115
Rep Power: 8
anon_q is on a distinguished road
In mathematics, to rotate a vector \vec{V}(x, y, z) about the Z-axis by an angle of \theta, we do the the matrix multiplication:


\vec{W} = R\vec{V}
\vec{W}: is the new vector obtained by rotation.
R is the rotation matrix. [R] is given by:

R = \begin{pmatrix}\cos\theta  & -\sin\theta & 0 \\
  \sin\theta  & \cos\theta  & 0 \\
  0 & 0 & 1  \end{pmatrix} .

My question is: Is there any builtin function in OpenFOAM to rotate a vector without doing that manually? something like:
Code:
vector V(5.0, 1.0, 3.0);
vector axis(0.0, 0.0, 1.0);
vector W = vector::rotate(V, axis);
???
anon_q is offline   Reply With Quote

Old   October 29, 2018, 16:22
Default
  #2
Member
 
Martin
Join Date: Dec 2011
Posts: 40
Rep Power: 14
msaravia is on a distinguished road
Hi again... I don't know if it can help you, but it may help others searching for the same thing.

First of all, rotations in 3D are very different from rotations in 2D. 3D rotations belong to SO3 group, which is not a vector space, but a manifold. 3D rotations can be parametrized in different ways; a set of 3 or 4 parameters is needed to build the rotational operator. Then, in contrast to the 2D case, 3D rotations are not commutative, and the parameters are often not additive.

I know that OpenFOAM can use quaternions to rotate a vector field (I dont know if another set of parameters can be used, the quaternions play the role of your angles). Quaternions are a set a of 4 parameters that parametrize a 3D rotation globally. Since OF is thought to be 3D, you would probably have to use a 3D function and feed it with a 2D rotation parameters.

As far as I know, that may not be enough, there is a function called transform such that, passing the quaternion as a parameter you obtain the rotated vector field.

This is:

Code:
 Foam::tmp<Foam::vectorField> Foam::transform
 (
     const quaternion& q,
     const vectorField& tf
 )
Hughtong likes this.

Last edited by msaravia; October 29, 2018 at 18:09.
msaravia is offline   Reply With Quote

Old   October 29, 2018, 17:56
Default
  #3
Senior Member
 
Join Date: Mar 2018
Posts: 115
Rep Power: 8
anon_q is on a distinguished road
Thank you very much dear Martin for your answer
anon_q is offline   Reply With Quote

Old   November 15, 2018, 10:42
Default
  #4
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,714
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Quote:
Originally Posted by Evren Linda View Post
In mathematics, to rotate a vector \vec{V}(x, y, z) about the Z-axis by an angle of \theta, we do the the matrix multiplication:


\vec{W} = R\vec{V}
\vec{W}: is the new vector obtained by rotation.
R is the rotation matrix. [R] is given by:

R = \begin{pmatrix}\cos\theta  & -\sin\theta & 0 \\
  \sin\theta  & \cos\theta  & 0 \\
  0 & 0 & 1  \end{pmatrix} .

My question is: Is there any builtin function in OpenFOAM to rotate a vector without doing that manually? something like:
Code:
vector V(5.0, 1.0, 3.0);
vector axis(0.0, 0.0, 1.0);
vector W = vector::rotate(V, axis);
???

If you have the rotation matrix, you can just do that directly. Eg
Code:
tensor rot
(
    cos(theta), -sin(theta), 0,
    sin(theta), cos(theta), 0,
    0, 0, 1
);.


vector vec(someX, someY, somZ);


vector  vec1 = transform(rot, vec);
vector  vec2 = invTransform(rot, vec);  // probably doesn't yet work, but does in1812


... or manually:


vector  vec1 = rot & vec;
vector  vec2 = vec & rot;
Instead of defining the rotation matrix yourself, the coordinateRotation classes can be more useful. Eg,


Code:
tensor rot = axesRotation(axis1, axis2).R();
vector vec1 = rot & vec;
Could also just use a coordinateSystem directly. The additional overhead of an origin that you don't use is quite minimal.


/mark
olesen is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
OpenFOAM v3.0+ ?? SBusch OpenFOAM 22 December 26, 2016 15:24
OpenFOAM Training, London, Chicago, Munich, Houston 2016-2017 cfd.direct OpenFOAM Announcements from Other Sources 0 September 14, 2016 04:19
Superlinear speedup in OpenFOAM 13 msrinath80 OpenFOAM Running, Solving & CFD 18 March 3, 2015 06:36
[Other] OpenFOAM 2.1.0/x: rotating devices. ebah6 OpenFOAM Meshing & Mesh Conversion 3 January 31, 2012 11:54
Adventure of fisrst openfoam installation on Ubuntu 710 jussi OpenFOAM Installation 0 April 24, 2008 15:25


All times are GMT -4. The time now is 03:58.