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

Access pointDisplacement field from within pimpleDyMFoam

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 2, 2016, 03:16
Default Access pointDisplacement field from within pimpleDyMFoam
  #1
New Member
 
Paul Bomke
Join Date: Mar 2010
Location: Bremen, Germany
Posts: 16
Rep Power: 16
paul b is on a distinguished road
Dear Foamers,

I am currently modifying pimplyDyMFoam (from foam-extend-3.2) to communicate with an external python program via socket connection.

My aim is to send pressure and shear force distribution of a patch to my python app, do some stuff there and send a displacement for the patch back to pimpleDyMFoam. The idea is to have a machine learning algorithm find the appropriate patch deformations to react to disturbances in the flow.

The socket connection sending and receiving part works nicely. However, I'm having trouble accessing the pointDisplacement field of the patch from within pimpleDyMFoam to pass the displacement values into it before calling mesh.update(). My main problem is that a): I'm not really sure in which object registry the pointDisplacement field is in, and b): I'm probably using the wrong methods to fetch it and write to it.

I tried the code from here: http://www.cfd-online.com/Forums/ope...tml#post447552 which shows that the pointDisplacement field should be in the mesh db.

Below you see my pimpleDyMFoam up to mesh.update().
The relevant part is at the end.

Code:
// Socket communication library and stuff needed for converting fields to strings.
#include <zmqpp/zmqpp.hpp>
#include <sstream>
#include <string>
#include <iostream>

// Foam stuff.
#include "fvCFD.H"
#include "singlePhaseTransportModel.H"
#include "turbulenceModel.H"
#include "dynamicFvMesh.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

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

#   include "createTime.H"
#   include "createDynamicFvMesh.H"
#   include "readPIMPLEControls.H"
#   include "initContinuityErrs.H"
#   include "createFields.H"
#   include "readTimeControls.H"

    // Read the force dict where the patch name is stored.
#   include "readForceControls.H"

    // Create and init the socket connection to python.
#   include "socketSetup.H"


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

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


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

        // Make the fluxes absolute
        fvc::makeAbsolute(phi, U);

        runTime++;

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



        // Get the surface force distribution, send via socket and wait for response with pointDisplacement field.
#       include "forceCalc.H"

//########################### THIS IS WHERE THE PROBLEM IS #####################
        // Set patch displacement for motion solver.
        //Find the reference to the pointDisplacement field
        pointVectorField& PointDisplacement = const_cast<pointVectorField&>
        (
            mesh.objectRegistry::lookupObject<pointVectorField>
            (
            "pointDisplacement"
            )
        );
// #############################################################################

        // Move the mesh.
        bool meshChanged = mesh.update();
However, this gives me the following error (which might be due to the fact that the code above comes from OF-2.2):

Code:
In file included from /home/paul/foam/foam-extend-3.2/src/finiteVolume/lnInclude/fvMesh.H:55:0,
                 from /home/paul/foam/foam-extend-3.2/src/finiteVolume/lnInclude/fvCFD.H:8,
                 from optimizerFoam.C:42:
/home/paul/foam/foam-extend-3.2/src/foam/lnInclude/DimensionedField.H: In instantiation of ‘class Foam::DimensionedField<Foam::Vector<double>, Foam::pointMesh>’:
/home/paul/foam/foam-extend-3.2/src/foam/lnInclude/GeometricField.H:81:7:   required from ‘class Foam::GeometricField<Foam::Vector<double>, Foam::pointPatchField, Foam::pointMesh>’
/home/paul/foam/foam-extend-3.2/src/foam/lnInclude/objectRegistryTemplates.C:113:64:   required from ‘const Type& Foam::objectRegistry::lookupObject(const Foam::word&) const [with Type = Foam::GeometricField<Foam::Vector<double>, Foam::pointPatchField, Foam::pointMesh>]’
optimizerFoam.C:101:4:   required from here
/home/paul/foam/foam-extend-3.2/src/foam/lnInclude/DimensionedField.H:82:40: error: invalid use of incomplete type ‘class Foam::pointMesh’
         typedef typename GeoMesh::Mesh Mesh;
                                        ^
I'm think the compiler complains about the lookup method returning or requesting a wrong type:
Code:
Type = Foam::GeometricField<Foam::Vector<double>, Foam::pointPatchField, Foam::pointMesh>
Could someone please explain to me what's going wrong and how to use the lookup method properly?

I recon that this could also be solved by a modified pointDisplacement boundary condition or dynamicFvMesh which reads directly from the socket, but I'd like to keep the number of socket connections low and restrict the code modifications to pimpleDyMFoam if possible.

I would be happy if someone could shed some light on how to access the pointDisplacement or point me into the right direction.

Thanks a lot in advance,
Paul
paul b is offline   Reply With Quote

Reply

Tags
field acces, mesh motion, mesh movement, object registry, prescribed motion


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
New Solver error Foam::error::printStack upuli OpenFOAM Running, Solving & CFD 4 May 11, 2018 01:43
Is good initial guess field is neccessary ? mmkr825 OpenFOAM 5 October 17, 2012 12:58
Access raw field data (scalars, vectors) on mesh haakon OpenFOAM Programming & Development 3 September 25, 2012 10:01
Modify pointDisplacement field from within solver? nowhere OpenFOAM Programming & Development 2 October 13, 2011 13:53
ACCESS VIOLATION MHDWill FLUENT 1 September 23, 2007 02:51


All times are GMT -4. The time now is 11:40.