2017-12-15 23:48 GMT

View Issue Details Jump to Notes ]
IDProjectCategoryView StatusLast Update
0002656OpenFOAMFeaturepublic2017-09-09 19:06
Reporterhandrake0724 
Assigned Tohenry 
PrioritynormalSeverityfeatureReproducibilityhave not tried
StatusresolvedResolutionfixed 
Platformx86_64OSArchOS Version(please specify)
Product Version4.x 
Target VersionFixed in Version 
Summary0002656: request a functionObject for reporting motion state of sixDoFRigidBodyMotionsolver
DescriptionI am working on 6 DoF motion in two-phase flow.
sixDoFRigidBodyMotionSolver works fine, but what I am missing is a function to report motion state such as center of mass, rotation angle, etc.
Current sixDoFRigidBodyMotionSolver only print out to stdout.
So I made a functionObject for motion state. To do that, I have to access to motionPtr_ in dynamicMotionSolverFvMesh and motion_ in sixDoFRigidBodyMotionSolver.

So I added following code to two sources as follows:

  dynamicMotionSolverFvMesh.H
  public:
  const motionSolver& motionPtr() const { return motionPtr_(); }

  sixDoFRigidBodyMotionSolver.H
  public:
  const sixDoFRigidBodyMotion& motion() const { return motion_; }

based on these modification, I could make a functionObject as attached.

It would be good if a simular function reporting body motion is added to OpenFOAM.
TagsNo tags attached.
Attached Files

-Relationships
+Relationships

-Notes

~0008544

henry (manager)

in dynamicMotionSolverFvMesh.H

Why name the function motionPtr:

  const motionSolver& motionPtr() const { return motionPtr_(); }

it returns a reference to the motionSolver, not a pointer.

~0008545

handrake0724 (reporter)

I just name the function after the variable name.
just motion will be fine.

~0008547

henry (manager)

> I just name the function after the variable name.

But you de-reference the pointer with '()':

    return motionPtr_()

so it returns the reference rather than the pointer the variable is named after.

> just motion will be fine.

This would be more logical.

~0008548

handrake0724 (reporter)

Is there a way to write initial time and state to the stream?
current code starts writing from initial + timeStep instead of initial.

~0008549

henry (manager)

> Is there a way to write initial time and state to the stream?

Not in a standard way. This issue has been discussed before and a general solution would require some major work on the functionObject base classes and special handling for the functionObjects which do not have a logical initial state because they depend on values not available at the initial time.

~0008564

handrake0724 (reporter)

for now, it's find without writting the initial state.

~0008616

henry (manager)

The code is rather specifically written and seems unnecessarily complex, for example what is the advantage of

        centreOfRotation_.x() = motion_.centreOfRotation().x();
        centreOfRotation_.y() = motion_.centreOfRotation().y();
        centreOfRotation_.z() = motion_.centreOfRotation().z();

over

        centreOfRotation_ = motion_.centreOfRotation();

Also the format of the output would be difficult to read back into OpenFOAM because the vectors do not have brackets

        << centreOfRotation_[0] << setw(1) << tab
        << centreOfRotation_[1] << setw(1) << tab
        << centreOfRotation_[2] << setw(1) << tab

should be
        << centreOfRotation_ << setw(1) << tab

Other problem relate to deviations from the style guidelines, in particular the line length should be limited to 80 characters see

https://openfoam.org/dev/coding-style-guide

I could rewrite it to be consistent with the rest of OpenFOAM but this would need funding. Alternatively if you could improve the code following convensions in the rest of the code and the style guidelines it would help.

~0008617

henry (manager)

What is the purpose of the if-else in

        if(degree_)
        {
            writeHeaderValue(file(0), "Rotation Angle Unit:", "degree");
            writeCommented(file(0), "Time");
        }
        else
        {
            writeHeaderValue(file(0), "Rotation Angle Unit:", "degree");
            writeCommented(file(0), "Time");
        }

The two clauses appear to do the same thing.

~0008618

henry (manager)

Why store the state in the class? Why not just lookup and write the state in the write function?

Incidentally this layout

        //- file names
        wordList names_;
        //- centre of rotation
        vector centreOfRotation_;
        //- center of mass
        vector centreOfMass_;
        //- angular position
        vector rotationAngle_;
        //- linear velocity
        vector linearVelocity_;
        //- angular velocity
        vector angularVelocity_;
        //- quaternion
        vector rotAxis_;
        scalar rotAngle_;

will cause Doxygen to fail to generate correct documentation for the class; please see the style guideline for the details of the correct layout.

~0008621

handrake0724 (reporter)

for the ~0008616, you are right about calcState function. It is unnecessarily complex.
                  the reason of missing brackets is to be easily plotted with gnuplot.
                  it would be helpful if a way is possible to make the output fit to the gnuplot format without OpenFOAM's philosophy.

for the ~0008617, it is a typo, one of them should be radian instead of degree.

for the ~0008618, I splitted functions into calcState and writeState. so member variables to store the results were needed. I think those two functions can be made into a function.

~0008622

handrake0724 (reporter)

Updated codes are attached.
current output format is raw format so vector types are written with brackets.

~0008737

henry (manager)

Resolved by commit 7dc61879a676c6e6c56b94580873d888c26dfbbd
+Notes

-Issue History
Date Modified Username Field Change
2017-08-09 05:04 handrake0724 New Issue
2017-08-09 05:04 handrake0724 File Added: rigidBodyState.tar.bz2
2017-08-09 18:41 henry Note Added: 0008544
2017-08-10 00:54 handrake0724 Note Added: 0008545
2017-08-10 08:49 henry Note Added: 0008547
2017-08-10 09:04 handrake0724 Note Added: 0008548
2017-08-10 09:45 henry Note Added: 0008549
2017-08-13 03:39 handrake0724 Note Added: 0008564
2017-08-22 16:24 henry Note Added: 0008616
2017-08-22 16:27 henry Note Added: 0008617
2017-08-22 16:35 henry Note Added: 0008618
2017-08-23 01:20 handrake0724 Note Added: 0008621
2017-08-23 02:17 handrake0724 File Added: rigidBodyState.tar-2.bz2
2017-08-23 02:17 handrake0724 Note Added: 0008622
2017-09-09 19:06 henry Assigned To => henry
2017-09-09 19:06 henry Status new => resolved
2017-09-09 19:06 henry Resolution open => fixed
2017-09-09 19:06 henry Note Added: 0008737
+Issue History