CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Pre-Processing (https://www.cfd-online.com/Forums/openfoam-pre-processing/)
-   -   Including run time as variable in dynamicMeshDict (https://www.cfd-online.com/Forums/openfoam-pre-processing/192965-including-run-time-variable-dynamicmeshdict.html)

RKyle September 14, 2017 09:04

Including run time as variable in dynamicMeshDict
 
Hi there,

I'm looking to include a dynamic motion as a function of time in my dynamicMeshDict but now sure how to. I basically need to change the rotation axis depending on the run time. Does anyone have any idea or has done this before?

I saw one post using "scalar t=runTime.value();" but I'm probably using it wrongly (I've been fiddling with a simple case to see if it works). I get an error message saying '$t was not declared in this scope'. I've attached a snippet of my dynamicMeshDict to show how I've used it mainly to see if it can work first.



/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 2.3.0 |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
location "constant";
object dynamicMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dynamicFvMesh solidBodyMotionFvMesh;

motionSolverLibs ( "libfvMotionSolvers.so" );


scalar t=runTime.value();

solidBodyMotionFvMeshCoeffs
{

solidBodyMotionFunction multiMotion;
multiMotionCoeffs

{

Rotation
{
cellZone RotorCylinder;
solidBodyMotionFunction rotatingMotion;
rotatingMotionCoeffs
{

origin (0 0 0);
axis (1 0 0);
omega #calc "3.5*$t"; // rad/s
}
}

.....

Any tips and pointers would be greatly appreciated!


Kind regards,

Ryan

JonW September 27, 2017 15:50

rotation as a function of time
 
cd $HOME/OpenFOAM/OpenFOAM-2.3.1/src/dynamicFvMesh/solidBodyMotionFvMesh/solidBodyMotionFunctions/

cd rotatingMotion

gedit rotatingMotion.C

in the function (line 73)
Foam::septernion
Foam::solidBodyMotionFunctions::rotatingMotion::tr ansformation() const
you can do your stuff

I added ...

const scalar PI = constant::mathematical::pi;

// scalar angle = omega_->integrate(0, t);
scalar angle = Foam::sin(1.0*PI*t)*omega_->integrate(0, t);

Now you have sinus type of rotation. You can add other functions, like atan if you want a steady increase and then steady state rotation.
---------------------------------------------------------------------------

In ./constant/dynamicMeshDict

dynamicFvMesh solidBodyMotionFvMesh;

solidBodyMotionFvMeshCoeffs
{
cellZone none; // none => the whole mesh rotates.
// if you want only part of it to rotate, you have to define
// that region. see examples in openfoam wiki
solidBodyMotionFunction rotatingMotion;

rotatingMotionCoeffs
{
origin ( 0 0 0 );
axis ( 0 0 1 );
omega 1.4451; // rad/s // omega = 2*pi*(0.23 rps)
}
}

RKyle October 4, 2017 06:59

Thanks for the reply, JonW! This is helpful, it seems relatively straightforward to tweak the code to do something like this.

However (and this is my fault) I should have given the example code more in line with that I am aiming to do; there I was trying to change omega as a way of playing around with the time value but that's not what my goal is. What I actually need to do is move the origin (centre of rotation) with time. Imagine a pendulum moving, I'm trying to keep the centre of rotation at the tip of it.

I've discovered the tabulated6DoFMotion option, which seems good. It reads the rotation/translation in the form of a table so that there's a rotation/translation in terms of degrees and metres for each time step. If I could do the same with the CofG (origin) that would be ideal! It's like this in the dynamicMeshDict:


Pitching
{
cellZone "Rotor.*";
solidBodyMotionFunction tabulated6DoFMotion;
tabulated6DoFMotionCoeffs
{
CofG (-0.2 -0.2818 0);
timeDataFileName "$FOAM_CASE/constant/6DoF.dat";
}
}


The rotation/translation table listed in the 6DoF.dat file within the /constant folder looks like this, for example:


//(time ((x trans, y trans, z trans) (x rot y rot z rot))) about CofG
5001 //number of entries
(
(0.0 ((0 0 0) (0.144977489506 0 0)))
(0.002 ((0 0 0) (0.289958382958 0 0)))
(0.004 ((0 0 0) (0.434942669873 0 0)))
(0.006 ((0 0 0) (0.579930339763 0 0)))
(0.008 ((0 0 0) (0.724921382128 0 0)))
(0.01 ((0 0 0) (0.869915786463 0 0)))
(0.012 ((0 0 0) (1.01491354225 0 0)))
(0.014 ((0 0 0) (1.15991463898 0 0)))
...

Again, any help in doing the same with the CofG would be great! In the mean time, I'm doing my C++ homework..


Thanks again,

Ryan

JonW October 4, 2017 12:07

Hi Ryan
This is very interesting what you are trying to do. Unfortunately, I don't have an answer. I have been reading (when I have time) about the dynamicMesh thingi for the past weeks, when I have time (which is not much). But I am not where you are now in this. Hopefully, I will be there soon enough. If I come across ideas, I will let you know.
Good luck (to both of us)
J.

Bakhshi March 26, 2023 00:39

Quote:

Originally Posted by RKyle (Post 666535)
Thanks for the reply, JonW! This is helpful, it seems relatively straightforward to tweak the code to do something like this.

However (and this is my fault) I should have given the example code more in line with that I am aiming to do; there I was trying to change omega as a way of playing around with the time value but that's not what my goal is. What I actually need to do is move the origin (centre of rotation) with time. Imagine a pendulum moving, I'm trying to keep the centre of rotation at the tip of it.

I've discovered the tabulated6DoFMotion option, which seems good. It reads the rotation/translation in the form of a table so that there's a rotation/translation in terms of degrees and metres for each time step. If I could do the same with the CofG (origin) that would be ideal! It's like this in the dynamicMeshDict:


Pitching
{
cellZone "Rotor.*";
solidBodyMotionFunction tabulated6DoFMotion;
tabulated6DoFMotionCoeffs
{
CofG (-0.2 -0.2818 0);
timeDataFileName "$FOAM_CASE/constant/6DoF.dat";
}
}


The rotation/translation table listed in the 6DoF.dat file within the /constant folder looks like this, for example:


//(time ((x trans, y trans, z trans) (x rot y rot z rot))) about CofG
5001 //number of entries
(
(0.0 ((0 0 0) (0.144977489506 0 0)))
(0.002 ((0 0 0) (0.289958382958 0 0)))
(0.004 ((0 0 0) (0.434942669873 0 0)))
(0.006 ((0 0 0) (0.579930339763 0 0)))
(0.008 ((0 0 0) (0.724921382128 0 0)))
(0.01 ((0 0 0) (0.869915786463 0 0)))
(0.012 ((0 0 0) (1.01491354225 0 0)))
(0.014 ((0 0 0) (1.15991463898 0 0)))
...

Again, any help in doing the same with the CofG would be great! In the mean time, I'm doing my C++ homework..


Thanks again,

Ryan

Hey RKyle!

Were you able to figure out how to move origin with time? I am working on a similar case where I have to rotate a cylindrical domain in dynamicMeshDict file whose's origin is changing with time.


All times are GMT -4. The time now is 11:19.