View Issue Details

IDProjectCategoryView StatusLast Update
0002656OpenFOAMFeaturepublic2017-09-09 19:06
Reporterhandrake0724 Assigned Tohenry  
PrioritynormalSeverityfeatureReproducibilityhave not tried
Status resolvedResolutionfixed 
Platformx86_64OSArchOS Version(please specify)
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.

Activities

handrake0724

2017-08-09 05:04

viewer  

rigidBodyState.tar.bz2 (3,066 bytes)

henry

2017-08-09 18:41

manager   ~0008544

in dynamicMotionSolverFvMesh.H

Why name the function motionPtr:

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

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

handrake0724

2017-08-10 00:54

viewer   ~0008545

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

henry

2017-08-10 08:49

manager   ~0008547

> 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.

handrake0724

2017-08-10 09:04

viewer   ~0008548

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

henry

2017-08-10 09:45

manager   ~0008549

> 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.

handrake0724

2017-08-13 03:39

viewer   ~0008564

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

henry

2017-08-22 16:24

manager   ~0008616

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.

henry

2017-08-22 16:27

manager   ~0008617

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.

henry

2017-08-22 16:35

manager   ~0008618

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.

handrake0724

2017-08-23 01:20

viewer   ~0008621

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.

handrake0724

2017-08-23 02:17

viewer   ~0008622

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

henry

2017-09-09 19:06

manager   ~0008737

Resolved by commit 7dc61879a676c6e6c56b94580873d888c26dfbbd

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