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

How to access to the solid body motion state from a custom interDyMFoam.C ?

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   June 24, 2015, 16:07
Default How to access to the solid body motion state from a custom interDyMFoam.C ?
  #1
jmf
Member
 
Jean-Michel FONTAINE
Join Date: Aug 2009
Location: Orleans - France
Posts: 50
Rep Power: 9
jmf is on a distinguished road
Hi every body


I'm stuck on this coding problem since weeks

My target is to expose the solid body motion caracteristics to the solver, for instance v() or a().
I tried many ways, without success. Here is the current state of my attempts.
The idea is to expose motionPtr_ via a public function.

This is the modified dynamicMotionSolverFvMesh.H :
Code:
#ifndef dynamicMotionSolverFvMesh_H
#define dynamicMotionSolverFvMesh_H
#include "dynamicFvMesh.H"

namespace Foam
{
class motionSolver;
class dynamicMotionSolverFvMesh: public dynamicFvMesh
{
    // Private data
    autoPtr<motionSolver> motionPtr_; 

    // Private Member Functions

    //- Disallow default bitwise copy construct
    dynamicMotionSolverFvMesh(const dynamicMotionSolverFvMesh&);

    //- Disallow default bitwise assignment
    void operator=(const dynamicMotionSolverFvMesh&);

public:
    //- Runtime type information
    TypeName("dynamicMotionSolverFvMesh");

    // Constructors
        //- Construct from IOobject
        dynamicMotionSolverFvMesh(const IOobject& io);

    //- Destructor
    ~dynamicMotionSolverFvMesh();

    // Member Functions

        //- Update the mesh for both mesh motion and topology change
        virtual bool update();

        // this is the additionnal public function <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        Foam::motionSolver* motionSolverPtr() { return motionPtr_.ptr(); };  
};
#endif
This is myInterDyMFoam.C:

Code:
Application
    interDyMFoam

#include "fvCFD.H"
#include "dynamicFvMesh.H"
#include "CMULES.H"
#include "subCycle.H"
#include "immiscibleIncompressibleTwoPhaseMixture.H"
#include "turbulenceModel.H"
#include "pimpleControl.H"
#include "fvIOoptionList.H"
#include "fixedFluxPressureFvPatchScalarField.H"
#include "dynamicMotionSolverFvMesh.H" // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

int main(int argc, char *argv[])
{
    #include "setRootCase.H"
    #include "createTime.H"
    #include "createDynamicFvMesh.H"
    #include "initContinuityErrs.H"

    // this is the attempt to call motionSolverPtr() <<<<<<<<<<<<<<<<<<<<<<<
    Foam::motionSolver* motionPtr; //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    motionPtr = Foam::dynamicMotionSolverFvMesh::motionSolverPtr(); //<<<<<<
    Info<< "motionPtr->v() = " << motionPtr->v() << nl << endl; //<<<<<<<<<<

    pimpleControl pimple(mesh);

    #include "createFields.H"
    #include "readTimeControls.H"
    #include "createPrghCorrTypes.H"

    volScalarField rAU
    (
        IOobject
        (
            "rAU",
            runTime.timeName(),
            mesh,
            IOobject::READ_IF_PRESENT,
            IOobject::AUTO_WRITE
        ),
        mesh,
        dimensionedScalar("rAUf", dimTime/rho.dimensions(), 1.0)
    );

    #include "correctPhi.H"
    #include "createUf.H"
    #include "CourantNo.H"
    #include "setInitialDeltaT.H"

    Info<< "\nStarting time loop\n" << endl;

    while (runTime.run())
    {
        #include "readControls.H"
        #include "alphaCourantNo.H"
        #include "CourantNo.H"

        #include "setDeltaT.H"

        runTime++;

        Info<< "Time = " << runTime.timeName() << nl << endl;

        // --- Pressure-velocity PIMPLE corrector loop
        while (pimple.loop())
        {
            if (pimple.firstIter() || moveMeshOuterCorrectors)
            {
                scalar timeBeforeMeshUpdate = runTime.elapsedCpuTime();

                mesh.update();

                if (mesh.changing())
                {
                    Info<< "Execution time for mesh.update() = "
                        << runTime.elapsedCpuTime() - timeBeforeMeshUpdate
                        << " s" << endl;

                    gh = g & mesh.C();
                    ghf = g & mesh.Cf();
                }

                if (mesh.changing() && correctPhi)
                {
                    // Calculate absolute flux from the mapped surface velocity
                    phi = mesh.Sf() & Uf;

                    #include "correctPhi.H"

                    // Make the flux relative to the mesh motion
                    fvc::makeRelative(phi, U);

                    mixture.correct();
                }

                if (mesh.changing() && checkMeshCourantNo)
                {
                    #include "meshCourantNo.H"
                }
            }

            #include "alphaControls.H"
            #include "alphaEqnSubCycle.H"

            mixture.correct();

            #include "UEqn.H"

            // --- Pressure corrector loop
            while (pimple.correct())
            {
                #include "pEqn.H"
            }

            if (pimple.turbCorr())
            {
                turbulence->correct();
            }
        }

        runTime.write();

        Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
            << "  ClockTime = " << runTime.elapsedClockTime() << " s"
            << nl << endl;
    }

    Info<< "End\n" << endl;

    return 0;
}
Result : this does not compile. The compilation error are :
Code:
interDyMFoam.C: In function ‘int main(int, char**)’:
interDyMFoam.C:57:17: error: ‘motionSolverPtr’ is not a member of ‘Foam::dynamicMotionSolverFvMesh’
interDyMFoam.C:58:54: error: invalid use of incomplete type ‘class Foam::motionSolver’
In file included from interDyMFoam.C:44:0:
/home/nous/OpenFOAM/OpenFOAM-2.3.x/src/dynamicFvMesh/lnInclude/dynamicMotionSolverFvMesh.H:45:7: error: forward declaration of ‘class Foam::motionSolver’
I can't find a solution, I don't understand this.

And furthermore the next question is : would motionPtr->v() give something ?

I would appreciate any help

Best regards

Jean-Michel
jmf is offline   Reply With Quote

Old   November 19, 2016, 08:09
Default [Solved] How to access to the solid body motion state from interDyMFoam.C ?
  #2
jmf
Member
 
Jean-Michel FONTAINE
Join Date: Aug 2009
Location: Orleans - France
Posts: 50
Rep Power: 9
jmf is on a distinguished road
Hi

The solution for me was to use dictionaries in the object registry. Some example here after.

Create the dictionary and write something:
Code:
   /* interDyMFoam.C
    */

    // Creates the exchange dictionary in the registry
    dictionary dataDict;
    mesh.thisDb().store
    (   
        new IOdictionary
        (   
            IOobject
            (   
                "motion",
                runTime.timeName(),
                mesh,
                IOobject::NO_READ,
                IOobject::AUTO_WRITE
            ),
            dataDict
        )
    );

   // Open and write
    const dictionary& motionDict = 
            mesh.thisDb().lookupObject<IOdictionary>("motion");

    // Update for the motion solver
    dictionary updateDbDictionary = &motionDict;
    updateDbDictionary.set("centreOfRotation", initalCentreOfMass_);
    const_cast<dictionary& > (motionDict) = updateDbDictionary ;
Read something:
Code:
/* sixDoFRigidBodyMotionSolver.C
 */
    
    if ( mesh().thisDb().foundObject<IOdictionary >("motion"))
    {
        const dictionary& dbDictionary = 
                  mesh().thisDb().lookupObject <IOdictionary >("motion");
        point centreOfRotation 
            = dbDictionary.lookupOrDefault("centreOfRotation", point(0, 0, 0));
    }
This works everywhere one has access to mesh or time.

The const_cast trick allows overwriting everywhere. It come from the post #14 of this thread:
http://www.cfd-online.com/Forums/ope...rfield-bc.html

Without an access to time or mesh, for instance in sixDoFRigidBodyMotion.C, I did not found better solution than adding setter and getter functions, which is hassle. It a pity that not all the classes have access to registry.

Hope this will be useful

Jean-Michel

Last edited by jmf; November 19, 2016 at 08:52. Reason: Added [Solved]
jmf is offline   Reply With Quote

Reply

Tags
custom solver, motion, state

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculation of the Governing Equations Mihail CFX 7 September 7, 2014 06:27
[DesignModeler] Question about converting surface body to solid body in DesignModeler lnk ANSYS Meshing & Geometry 2 November 24, 2013 01:02
[DesignModeler] how to subtract a surface body from a solid body? yahya ANSYS Meshing & Geometry 4 January 7, 2013 12:00
cooling a solid body Ralf Schmidt FLUENT 1 April 16, 2007 10:54
Two-Phase Buoyant Flow Issue Miguel Baritto CFX 4 August 31, 2006 12:02


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