CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Programming & Development (
-   -   Problem in defining patch deformation (

paul b April 21, 2010 04:54

Problem in defining patch deformation
2 Attachment(s)
Hello Forum,

i'm not new to OpenFOAM but I just started changing code a few days ago, so please excuse if my question may seem trivial...

I am trying to set up a library which performs a fish-like undulatory deformation of a given patch. I have had a look at the stuff in OpenFoam-1.6.x/src/fvMotionSolver/pointPatchFields/derived/ and also at the library that can be found here:

I then took the code that can be found in the link and changed it according to my needs.
What I do in my code is take a patch and shift it to a given origin:


// Patch relative to the given origin is created.
    vectorField p0Rel = p0_ - origin_;

I rotate it onto the xy-plane:


// The patch is rotated using the rotation matrix.
    vectorField p0RelRot = p0Rel & Rrot;

Then I change the z-values according to a given function (a simple oscillation to start with). This is done in a loop for every single point:


// Vectors for an individual point of the rotated Patch are declared.
    //vector pointRotOld;
    vector pointRotNew;

    // The new deformed patch is declared using the undeformed patch.
    vectorField p0RelRotNew = p0RelRot;


        // The new z-Value of the current point is calculated from its x- and y-values.
        pointRotNew=vector(0, 0, (s_*sin(omega_*t.value())));    //- pointRotOld[2]);    //-phi_*p0RotOrig[0])*(a_*pow(p0RotOrig[0],2)+b_*p0RotOrig[0]+c_)); 
    // THe current point is written into the patch.

Then the whole thing is rotated it back and moved back into its original position.


// The new patch is rotated back into its original position
    vectorField p0RelNew = p0RelRotNew & RrotInv;
    // The patch is moved back to its original position
    vectorField p0New=p0RelNew + origin_;

After this comes what seems to be an essential part whos function I don't quite understand:



The problem is: The new positions of the points are somehow not just taken from my function but added to the ones from the previous timestep. So I don't end up with a nice sinus-like oscillation around z=0, but with half an oscillation into one direction and back.
I don't really understand how this can be. I think the problem lies in the part of the loop where the individual points are written into the patch. It seems to me that


does not assign the value on the right to pointRotNew, but add it. Since pointRotNew contains the value (0,0,someZValue) the patch p0RelRotNew would have to end up with all its points having x- and y-values of 0, but it does not, which is a good thing in this case. But in the same manner the z-values of pointRotNew are just added to the points of the patch which is not what i want.

What am I getting wrong here? May be I don't understand the function of "="?

I would appreciate any help!
Thanks in advance and best regards,


P.S.: a case using PimplyDyFoam and the code of my library is attached...

paul b April 26, 2010 10:54

Ok, in case this is too special or maybe just too stupid, lets start with some simple questions that may lead me to finding my mistake:

1: What is the purpose of


2: Sounds very stupid but just to make sure: Does the velocityLaplacian motion solver require the velocities of the moved points or does the term "velocity" in its name refer to something else?

3: Is there an overview of the different motion solvers?

Hope someone could comment on this!
Thanks and best regards,


paul b April 26, 2010 11:59

@ mods: if this is not the appropriate subforum for this question, please be so kind as to move the thread.

cwang5 April 27, 2010 00:31

Hi Paul,

Just a quick question. I'm trying to get the rotation working for my code (I'm still fairly clueless with C++ programming, even though I've been using OpenFOAM for a year now). I defined the initial position of the points using the following code


label patchi = iter.key();
vectorField oldCell = mesh.C().boundaryField()[patchi];
pointField oldPoint = mesh.boundaryMesh()[patchi].localPoints();

and the rotation tensor using the quaternion function


quaternion Rotation(angle, axis);
tensor R = Rotation.R();

and proceed with the rotation using


vectorField newCell = oldCell & R;
pointField newPoint = oldPoint & R;

I'm not sure what I did wrong, but when I tried to compile the code I got the error:

'oldCell' was not declared in this scope
'oldPoint' was not declared in this scope

Do you have any idea what might have lead to the error? Thanks.


EDIT: Nevermind, I messed up the patchi loop. It's working now.

All times are GMT -4. The time now is 16:08.