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

OF 1.6 extend. GGI - rotation around two axis - C++ newbie needs help

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 5, 2013, 01:31
Default OF 1.6 extend. GGI - rotation around two axis - C++ newbie needs help
  #1
Member
 
Andreas Wendy
Join Date: Aug 2012
Posts: 73
Rep Power: 13
A.Wendy is on a distinguished road
Hi everybody,

i have a problem and i hope you can help me.
i am planing to simulate an gyro-copter including the auto rotation.
i was able to implement some rigid body movement into the mixerggi library and can simulate a rotation around one fixed axis. but i also want to simulate the flapping hinge. for that i need to make a rotation around a second axis.
i know what i have to implement but i dont know how.

the plan is the following:
reading out he forces using forces library <- works
recalculate an ne rpm for rotation <- works
rotate the rotor around z-axis <- works
change the rotation axis for flapping hinge <- does not work (see below)
rotate rotor for flapping hinge <- should work
change rotation axis back to z-axis and start to next time step.


here to the problem with the rotation for the flapping hinge:
when the rotor is rotating around the z-axis the coordinate system for the flapping hinge will change by each time step. so i have to compute this axis manually. i think i can do this. but i can not store these data in the variable of the mixerGgi script.
the variables (classes) are:
csPtr_().axis()
csPtr_().origin()

i am able to change the origin but not the axis. has anyone an idea to solve this problem?

here is the declaration:
//- Return coordinate system
const coordinateSystem& cs() const
{
return csPtr_();
}

how can i change it? why can i change the origin but not the axis? both have the same declaration or?

i added the c-file and header.


Best wishes


Andreas
Attached Files
File Type: c mixerGgiFvMesh_modified.C (17.7 KB, 5 views)
File Type: h mixerGgiFvMesh_modified.H (5.4 KB, 1 views)
A.Wendy is offline   Reply With Quote

Old   February 5, 2013, 02:14
Default
  #2
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,900
Rep Power: 37
ngj will become famous soon enoughngj will become famous soon enough
Hi Andreas,

You can only change the origin, as this is the only variable (besides the name), which has an edit-option in the coordinateSystem-class. You can find the details here:

Code:
<some path>/src/OpenFOAM/coordinateSystems/coordinateSystem.H
What you would need to do is to modify the construction of the coordinateSystem, so it is based on varying axes and not a fixed axis defined at the beginning of the run.

Another option is that if you have defined the axis in a dictionary, then you can change that particular input in the dictionary every time the axis is updated. This way you do not need to change the mixer*** classes.

Kind regards,

Niels
ngj is offline   Reply With Quote

Old   February 6, 2013, 03:43
Default
  #3
Member
 
Andreas Wendy
Join Date: Aug 2012
Posts: 73
Rep Power: 13
A.Wendy is on a distinguished road
Quote:
Originally Posted by ngj View Post
Hi Andreas,

You can only change the origin, as this is the only variable (besides the name), which has an edit-option in the coordinateSystem-class. You can find the details here:

Code:
<some path>/src/OpenFOAM/coordinateSystems/coordinateSystem.H
What you would need to do is to modify the construction of the coordinateSystem, so it is based on varying axes and not a fixed axis defined at the beginning of the run.

Another option is that if you have defined the axis in a dictionary, then you can change that particular input in the dictionary every time the axis is updated. This way you do not need to change the mixer*** classes.

Kind regards,

Niels
hi niels,

thanks for the info so far.

the second option means, that i have to change the entries in the dynamicMeshDict after every iteration an reload it afterwards right? This includes the selecting of the cells or? Would be a lot calculation time wich is needed... but the fastest programming method. i will give it a try.

the first option looks lets say more professional i will try this afterwards

best wishes

Andy
A.Wendy is offline   Reply With Quote

Old   February 6, 2013, 04:00
Default
  #4
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,900
Rep Power: 37
ngj will become famous soon enoughngj will become famous soon enough
Hi Andreas,

I just had a quick look at the code again, and it occurred to me that the coordinateSystem is only created in the constructor, which means that my comment on changing the input in the dictionary has become redundant.

Thus: Only solutions are to change the mixer class as already discussed OR make a new coordinate system class. This class should, whenever the runTime.timeIndex() differs from a local variable, read the axis of rotation from somewhere and update the rotation matrix.

Kind regards,

Niels
ngj is offline   Reply With Quote

Old   February 6, 2013, 05:13
Default
  #5
Member
 
Andreas Wendy
Join Date: Aug 2012
Posts: 73
Rep Power: 13
A.Wendy is on a distinguished road
Quote:
Originally Posted by ngj View Post
Hi Andreas,

I just had a quick look at the code again, and it occurred to me that the coordinateSystem is only created in the constructor, which means that my comment on changing the input in the dictionary has become redundant.
this means the coordination system is once set i cant change it without restarting (stopp and start at next time step) the calculation right?

Quote:
Originally Posted by ngj View Post
Thus: Only solutions are to change the mixer class as already discussed OR make a new coordinate system class. This class should, whenever the runTime.timeIndex() differs from a local variable, read the axis of rotation from somewhere and update the rotation matrix.

Kind regards,

Niels
what dou you mean by changing the mixer class?

best wishes

Andy
A.Wendy is offline   Reply With Quote

Old   February 6, 2013, 05:29
Default
  #6
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,900
Rep Power: 37
ngj will become famous soon enoughngj will become famous soon enough
Quote:
this means the coordination system is once set i cant change it without restarting (stopp and start at next time step) the calculation right?
Yes, it looks so.

Quote:
what dou you mean by changing the mixer class?
Everytime you need to update the coordinates you would need to construct a new coordinate system based on the newly computed axis. Therefore, you will need to modify the mixerggi, such that the coordinateSystem is not constructed in the beginning, but rather a fresh coordinateSystem is constructed every time you need it, i.e. at least once per time step.

Kind regards

Niels
ngj is offline   Reply With Quote

Old   February 6, 2013, 05:38
Default
  #7
Member
 
Andreas Wendy
Join Date: Aug 2012
Posts: 73
Rep Power: 13
A.Wendy is on a distinguished road
Quote:
Originally Posted by ngj View Post
Yes, it looks so.

Everytime you need to update the coordinates you would need to construct a new coordinate system based on the newly computed axis. Therefore, you will need to modify the mixerggi, such that the coordinateSystem is not constructed in the beginning, but rather a fresh coordinateSystem is constructed every time you need it, i.e. at least once per time step.

Kind regards

Niels
ok.
so i have to "delete" the cobnstruction of the cooardinate system by moving it a later position and modify it a little bit - or maybe more^^

thanks!
A.Wendy is offline   Reply With Quote

Old   February 6, 2013, 05:52
Default
  #8
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,900
Rep Power: 37
ngj will become famous soon enoughngj will become famous soon enough
Yes, that is exactly what I would try

/ Niels
ngj is offline   Reply With Quote

Old   February 7, 2013, 02:35
Default
  #9
Member
 
Andreas Wendy
Join Date: Aug 2012
Posts: 73
Rep Power: 13
A.Wendy is on a distinguished road
hi niels,

somehow i am not able to compile the mixxer class.

i tried the following:

1. copy the constructur for reading in the dynmaicmesh dict and modified like this:
Quote:
// Read dynamicMeshDict!
Foam::mixerGgiFvMesh_modified3D::updateCS
(
const IOobject& io
)
:
dynamicFvMesh(io),
dict_
(
IOdictionary
(
IOobject
(
"dynamicMeshDict",
time().constant(),
*this,
IOobject::MUST_READ,
IOobject::NO_WRITE
)
).subDict(typeName + "Coeffs")
),
csPtr_
(
coordinateSystem::New
(
"coordinateSystem",
dict_.subDict("coordinateSystem")
)
),
rpm_(readScalar(dict_.lookup("rpm"))),
IXX_(readScalar(dict_.lookup("IXX"))),
IXY_(readScalar(dict_.lookup("IXY"))),
IXZ_(readScalar(dict_.lookup("IXZ"))),
IYY_(readScalar(dict_.lookup("IYY"))),
IYZ_(readScalar(dict_.lookup("IYZ"))),
IZZ_(readScalar(dict_.lookup("IZZ"))),
MXX_(readScalar(dict_.lookup("MXX"))),
MYY_(readScalar(dict_.lookup("MYY"))),
MZZ_(readScalar(dict_.lookup("MZZ"))),
MaxMXX(readScalar(dict_.lookup("MaxMXX"))),
MaxMYY(readScalar(dict_.lookup("MaxMYY"))),
MaxMZZ(readScalar(dict_.lookup("MaxMZZ"))),
movingPointsMaskPtr_(NULL)

{


Info<< "Mixer mesh:" << nl
<< " origin: " << cs().origin() << nl
<< " axis : " << cs().axis() << nl
<< " rpm : " << rpm_ << nl

<< "moment of inertia tensor" << nl
<< "\t\t" << IXX_ << "\t\t" << IXY_ << "\t\t" << IXZ_ << nl
<< "\t\t" << IXY_ << "\t\t" << IYY_ << "\t\t" << IYZ_ << nl
<< "\t\t" << IXZ_ << "\t\t" << IYZ_ << "\t\t" << IZZ_ << endl;

}
i declared the fuction as follows in the .h file:
Quote:
//- update coordinate system
explicit updateCS(const IOobject& io);
under public dynamicFvMesh

when i try to compile i get this error:
Quote:
mixerGgiFvMesh_modified3D/mixerGgiFvMesh_modified3D.H:187:45: error: ISO C++ forbids declaration of 'updateCS' with no type [-fpermissive]
mixerGgiFvMesh_modified3D/mixerGgiFvMesh_modified3D.H:187:45: error: only declarations of constructors can be 'explicit'
mixerGgiFvMesh_modified3D/mixerGgiFvMesh_modified3D.C:240:1: error: ISO C++ forbids declaration of 'updateCS' with no type [-fpermissive]
when i declare as void instead of explicit i got this error:

Quote:
mixerGgiFvMesh_modified3D/mixerGgiFvMesh_modified3D.C:240:1: error: ISO C++ forbids declaration of 'updateCS' with no type [-fpermissive]
mixerGgiFvMesh_modified3D/mixerGgiFvMesh_modified3D.C:237:1: error: prototype for 'int Foam::mixerGgiFvMesh_modified3D::updateCS(const Foam::IOobject&)' does not match any in class 'Foam::mixerGgiFvMesh_modified3D'
mixerGgiFvMesh_modified3D/mixerGgiFvMesh_modified3D.H:187:14: error: candidate is: void Foam::mixerGgiFvMesh_modified3D::updateCS(const Foam::IOobject&)
do you got any idea?


best wishes

Andy
A.Wendy is offline   Reply With Quote

Old   February 7, 2013, 03:07
Default
  #10
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,900
Rep Power: 37
ngj will become famous soon enoughngj will become famous soon enough
Good morning,

Yes, your simple updateCS(io) method has some constructor-behaviour to it, because all the stuff, which is defined after ":" and before the scope "{" is part of the constructor. I do not believe

1. That you are allowed to do that in a simple class method - have never tried.

2. When you are updating the coordinate system, you do not need to set all the other class-variables againl; which is what is happening after ":"

Have you declared void in both H and C files?

Furthermore, you are using the "new" memory allocation for your coordinate sytem. If you do not clean up after yourself, you will come to a point, where you run out of memory, since you continue to allocate more and more memory.

Kind regards

Niels
ngj is offline   Reply With Quote

Old   February 7, 2013, 05:08
Default
  #11
Member
 
Andreas Wendy
Join Date: Aug 2012
Posts: 73
Rep Power: 13
A.Wendy is on a distinguished road
Quote:
Originally Posted by ngj View Post
Good morning,

Yes, your simple updateCS(io) method has some constructor-behaviour to it, because all the stuff, which is defined after ":" and before the scope "{" is part of the constructor. I do not believe

1. That you are allowed to do that in a simple class method - have never tried.

2. When you are updating the coordinate system, you do not need to set all the other class-variables againl; which is what is happening after ":"

Have you declared void in both H and C files?

Furthermore, you are using the "new" memory allocation for your coordinate sytem. If you do not clean up after yourself, you will come to a point, where you run out of memory, since you continue to allocate more and more memory.

Kind regards

Niels
hi niels,

by setting the variables again do you ment the readscalar part? aren't they overwritten by the data inside the dynamicmeshdict?

what other option do i have instead of ::New? ::Update or what would the right expression?

cause i do not want the constructor behaviour i have to move the part after ":" into this range: { ....... }

i added the .c and .h file for further "investigations"
i am very sorry for being so helpless but i never worked with c++ before....

best wishes

Andy
Attached Files
File Type: c mixerGgiFvMesh_modified3D.C (17.5 KB, 3 views)
File Type: h mixerGgiFvMesh_modified3D.H (5.5 KB, 3 views)
A.Wendy is offline   Reply With Quote

Old   February 7, 2013, 05:57
Default
  #12
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,900
Rep Power: 37
ngj will become famous soon enoughngj will become famous soon enough
Hi Andy,

It is a bit difficult to give advice based on your code, since you have made a lot of modifications, though, here are my immediate recommendations, which will give you a first go on a working code:

1. Remove entirely the updateCS method. This will not work.

2. In each of the methods (in the C-file), where you use the coordinateSystem, you construct your own local coordinate system, say csLocal (see <somePath>/OpenFoam/src/OpenFOAM/coordinateSystems/coordinateSystem.H to find your preferred way of constructing the coordinate system).
Use this local coordinate system instead of cs() and csPtr_.
This approach is a bit cumbersome and might not be terribly effective, but it is the first step toward a working code.

3. Please note that until you actually clean up the code, you still need to construct csPtr_ in the constructor of mixerGgiFvMesh. I know csPtr_ becomes redundant, but just take one single step at the time.

Hope this helps,

Niels

P.S. Here is a link to a quite big book on C++ programming. Otherwise, I can recommend using Google, even though I understand that it is hard to find answers, if you are unsure of which questions to pose.

http://www-cs-faculty.stanford.edu/~...6BX-Reader.pdf
ngj is offline   Reply With Quote

Old   February 7, 2013, 07:07
Default
  #13
Member
 
Andreas Wendy
Join Date: Aug 2012
Posts: 73
Rep Power: 13
A.Wendy is on a distinguished road
Quote:
Originally Posted by ngj View Post
1. Remove entirely the updateCS method. This will not work.

2. In each of the methods (in the C-file), where you use the coordinateSystem, you construct your own local coordinate system, say csLocal (see <somePath>/OpenFoam/src/OpenFOAM/coordinateSystems/coordinateSystem.H to find your preferred way of constructing the coordinate system).


3. Please note that until you actually clean up the code, you still need to construct csPtr_ in the constructor of mixerGgiFvMesh. I know csPtr_ becomes redundant, but just take one single step at the time.
find answers, if you are unsure of which questions to pose.
Hi Niels,

1) done

2) i am going to have a look at that. so i recalculate my vector for the origin, direction and axis use them as input and calculate/update the local CS right? That sounds good and is exactly what i was locking for

3) i will have a fixed axis which coordinate system will never change. so i can stay at this pointer to the coordinate system in the mesh dict and only have to update my second local cs right?


Thanks so far

Andy
A.Wendy is offline   Reply With Quote

Old   February 8, 2013, 02:35
Default
  #14
Member
 
Andreas Wendy
Join Date: Aug 2012
Posts: 73
Rep Power: 13
A.Wendy is on a distinguished road
Hi,

the definition of an new axis coordinate system worked pretty well thank you

now i try the following:
1. step (for initialization only) get the cell index of clossest cell/node to given coordinates. for example 0, 1,0
2. after each iteration get new coordinates of this cell after rotation.
and so on...

i was trying this one: (http://www.cfd-online.com/Forums/ope...ordinates.html)

Quote:
#include "fvCFD.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
int main(int argc, char *argv[])
{
# include "setRootCase.H"
# include "createTime.H"
# include "createMesh.H"
 
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Info<< "\nindex of the closest cell to (0,0,0): " << mesh.findCell(point(0,0,0)) << "\n" << endl;
return(0);
}
 
//************************************************** ********** //
this should give me the cell id. but i get introuble with the "Info" declaration in the mixer-class and the createMesh Class.

i am still sea5rching for a way to get the coordinates for a given cell id.

best wishes

andy
A.Wendy is offline   Reply With Quote

Old   February 8, 2013, 07:21
Default
  #15
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,900
Rep Power: 37
ngj will become famous soon enoughngj will become famous soon enough
Hi Andreas,

Back in the office again I am glad that you got it working.

The discussion about the cellID, where are you heading with that? I am unsure what you want to obtain by that.

Furthermore, using GGI, you need to have matching surfaces between the stagnant and moving part, correct? In that case, are you rotating a sphere about its centre, or how will you system work, when change the axis of rotation?

Kind regards,

Niels
ngj is offline   Reply With Quote

Old   February 8, 2013, 07:47
Thumbs up
  #16
Member
 
Andreas Wendy
Join Date: Aug 2012
Posts: 73
Rep Power: 13
A.Wendy is on a distinguished road
Quote:
Originally Posted by ngj View Post
Hi Andreas,

Back in the office again I am glad that you got it working.

The discussion about the cellID, where are you heading with that? I am unsure what you want to obtain by that.

Furthermore, using GGI, you need to have matching surfaces between the stagnant and moving part, correct? In that case, are you rotating a sphere about its centre, or how will you system work, when change the axis of rotation?

Kind regards,

Niels
Hi Niels,

yes you are right. by using the ggi the surfaces between the moving and static part have to mach. that is why i am using o sphere in a reactangle surrounding.

now i have implemented a automatically update on a reference cell coordinates whch lies on the axis of rotation. furthermore i am trying to clean the code. that was pretty dirty^^

wish you a nice weekend

Andy
A.Wendy is offline   Reply With Quote

Old   February 8, 2013, 07:52
Default
  #17
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,900
Rep Power: 37
ngj will become famous soon enoughngj will become famous soon enough
And the same to you. Please upload a video, when you wing is rotating freely
ngj is offline   Reply With Quote

Old   February 18, 2013, 03:22
Default
  #18
Member
 
Andreas Wendy
Join Date: Aug 2012
Posts: 73
Rep Power: 13
A.Wendy is on a distinguished road
and the next problem has occured....
maybe you got an idea:

http://www.cfd-online.com/Forums/ope...ng-forces.html

best wishes

andy
A.Wendy 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
Create a GeometricField of a given type on given patch? philippose OpenFOAM Programming & Development 4 August 12, 2013 12:41
OF 1.6 extend. GGI - rotation around two axis - C++ newbie needs help A.Wendy OpenFOAM Running, Solving & CFD 1 February 4, 2013 08:05
Frozen Rotor 1:1 Mesh Connection pharley CFX 5 January 31, 2013 16:15
parallel computing with GGI (OF 1.6 extend) A.Wendy OpenFOAM Running, Solving & CFD 1 November 18, 2012 17:27
Axis of rotation for centrifugal compressor Mattia FLUENT 4 October 22, 2007 11:05


All times are GMT -4. The time now is 23:27.