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

How to exchange information within coded fvpatchfield between different fields

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 16, 2022, 05:25
Default How to exchange information within coded fvpatchfield between different fields
  #1
New Member
 
Join Date: May 2020
Posts: 14
Rep Power: 5
ruanyg968tf is on a distinguished road
Dear foamers,
I want to define a field within a volScalarField called psi and access it within another volVectorField named psiVector. I have followed the thread objectRegistry::lookupObject<scalar>. I defined an IOdictionary within createField.H, and tried to modify it within psi field. However, when I tried to access the IOdictionary object within psiVector, the IOdictionary I accessed from the registry was empty.
In order to illustrate it more clearly, there are the codes and output.
1. Define an IOobject within createFields.H file.
Code:
IOdictionary regedDictionary
(
    IOobject
    (
        "regedDictionary",
        runTime.constant(),
        mesh,
        IOobject::NO_READ,
        IOobject::NO_WRITE
    )
);
2. Modify the IOobject within volScalarField psi.
Code:
left
    {
        type            codedFixedValue;
        name            leftCodedVal;
        value           uniform 0.2;
        code
        #{
            const Time &runTime = this->db().time();
            const fvMesh &mesh = this->patch().boundaryMesh().mesh();
            Info << "time = " << runTime.value() << endl;

            IOdictionary &regedDict = mesh.lookupObjectRef<IOdictionary>("regedDictionary");
            dictionary scalardict;
            scalardict.set("value",2 * runTime.value());
            regedDict.set("scalardict",scalardict);
            dictionary vectordict;
            vectordict.set("value",3 * runTime.value());
            regedDict.set("vectordict", vectordict);
            const IOdictionary &searchRegDict = this->db().lookupObject<IOdictionary>("regedDictionary");
            Info << "IOdictionary regedDictionary from psi:" << endl << searchRegDict << endl;
        #};
    }
3. Access the IOobject within volVectorField psiVector.
Code:
left
    {
        type            codedFixedValue;
        value           uniform (0.2 0.2 0.2);
        name            leftVecCodedVal;
        code
        #{
            const IOdictionary &regedDict = this->db().lookupObject<IOobject>("regedDictionary");
            Info << "IOdictionary regedDictionary from psiVector: " << endl << regedDict << endl;
        #};
    }
There are the outputs.
Code:
IOdictionary regedDictionary from psi:

{
    scalardict
    {
        value           4;
    }
    vectordict
    {
        value           6;
    }
}

IOdictionary regedDictionary from psiVector:

{
}
It can be seen that the IOdictionary regedDictionary was truly modified within psi boundary. But it seemed that the modification vanished whthin psiVector. Do you know what's the reason. And do you know how to access the value (or variables) from psiVector defined within the variable psi? Thanks in advance.
ruanyg968tf is offline   Reply With Quote

Old   May 16, 2022, 06:05
Default
  #2
New Member
 
Join Date: May 2020
Posts: 14
Rep Power: 5
ruanyg968tf is on a distinguished road
The problem has been solved. Sorry for my foolish error. The error came from the definition of the IOdictionary within createFields.H. The definition should be like this:
Code:
IOdictionary regedDictionary
(
    IOobject
    (
        "regedDictionary",
        runTime.constant(),
        mesh,
        IOobject::READ_IF_PRESENT,
        IOobject::NO_WRITE
    )
);
.
So the value of dictionary could be updated within psiVector.

By the way, is it possible to define a new variable or dictionary within psi that can be accessed within psiVector. So the modification of the original solver can be avoided. Do you have any ideals?
I have tried the following:
psi:
Code:
left
    {
        type            codedFixedValue;
        name            leftCodedVal;
        value           uniform 0.2;
        code
        #{
            this->operator == (0.2);
            const Time &runTime = this->db().time();
            const fvMesh &mesh = this->patch().boundaryMesh().mesh();
            Info << "time = " << runTime.value() << endl;

            vectorIOField regVectorField
            (
                IOobject
                (
                    "regVectorField",
                    runTime.timeName(),
                    mesh,
                    IOobject::NO_READ,
                    IOobject::NO_WRITE
                ),
                vectorField(this->size(),vector(0,0,0))
            );

            IOdictionary testDict
            (
                IOobject
                (
                    "testDict",
                    runTime.timeName(),
                    mesh,
                    IOobject::NO_READ,
                    IOobject::NO_WRITE
                )
            );

            Info << "db().name() = " << this->db().names() << endl;
        #};
    }
.
psiVector:
Code:
left
    {
        type            codedFixedValue;
        value           uniform (0.2 0.2 0.2);
        name            leftVecCodedVal;
        code
        #{
            Info << "psiVector Fields " << endl << this->db().names() << endl;
        #};
    }
.
I got the following output:
Code:
time = 2
db().name() = 
18
(
solutionControl
points
neighbour
psi
faces
psiVector
fvSchemes
fvOptions
faceZones
fvSolution
owner
data
regedDictionary
cellZones
boundary
regVectorField
testDict
pointZones
)

psiVector Fields 

16
(
solutionControl
points
neighbour
psi
faces
psiVector
fvSchemes
fvOptions
faceZones
fvSolution
owner
data
regedDictionary
cellZones
boundary
pointZones
)
.
Neither the IOdictionary testDict nor the vectorIOField regVectorField could be accessed from psiVectoer. Any suggestions would be appreciated.
ruanyg968tf is offline   Reply With Quote

Reply


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
[General] Extracting ParaView Data into Python Arrays Jeffzda ParaView 30 November 6, 2023 21:00
ERROR #001100279 has occurred in subroutine ErrAction. smnaryal CFX 11 December 20, 2017 16:32
OpenFOAM 2D simulation - Freelancer Job- Information will be provided sanjar CFD Freelancers 0 March 7, 2017 09:45
libz.so.1: no version information available dmaz OpenFOAM Running, Solving & CFD 3 January 4, 2015 16:54
Terrible Mistake In Fluid Dynamics History Abhi Main CFD Forum 12 July 8, 2002 09:11


All times are GMT -4. The time now is 07:06.