CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   OF 1.6 extend. GGI - rotation around two axis - C++ newbie needs help (http://www.cfd-online.com/Forums/openfoam-programming-development/112765-1-6-extend-ggi-rotation-around-two-axis-c-newbie-needs-help.html)

A.Wendy February 5, 2013 02:31

OF 1.6 extend. GGI - rotation around two axis - C++ newbie needs help
 
2 Attachment(s)
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

ngj February 5, 2013 03:14

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

A.Wendy February 6, 2013 04:43

Quote:

Originally Posted by ngj (Post 406055)
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

ngj February 6, 2013 05:00

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

A.Wendy February 6, 2013 06:13

Quote:

Originally Posted by ngj (Post 406270)
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 (Post 406270)
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

ngj February 6, 2013 06:29

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

A.Wendy February 6, 2013 06:38

Quote:

Originally Posted by ngj (Post 406285)
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!

ngj February 6, 2013 06:52

Yes, that is exactly what I would try :)

/ Niels

A.Wendy February 7, 2013 03:35

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

ngj February 7, 2013 04:07

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

A.Wendy February 7, 2013 06:08

2 Attachment(s)
Quote:

Originally Posted by ngj (Post 406474)
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

ngj February 7, 2013 06:57

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

A.Wendy February 7, 2013 08:07

Quote:

Originally Posted by ngj (Post 406505)
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 February 8, 2013 03:35

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

ngj February 8, 2013 08:21

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

A.Wendy February 8, 2013 08:47

Quote:

Originally Posted by ngj (Post 406724)
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

ngj February 8, 2013 08:52

And the same to you. Please upload a video, when you wing is rotating freely :)

A.Wendy February 18, 2013 04:22

and the next problem has occured....
maybe you got an idea:

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

best wishes

andy


All times are GMT -4. The time now is 06:05.