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

PROBLEMS DEFINING A LIST USING #CODESTREAM !! Help please !!

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 18, 2020, 09:07
Default PROBLEMS DEFINING A LIST USING #CODESTREAM !! Help please !!
  #1
New Member
 
Angel Garcia
Join Date: Apr 2020
Posts: 4
Rep Power: 6
angatri_14 is on a distinguished road
Dear foamers,
I'm trying to change the initial condition of my case using #codeStream procedure after some time steps. The idea is to add a modelled vortex after some iterations. However, I'm not able to overlap both fields, the vortex and the solution from the last time step. The problem is that I'm not a C++ user, so I don't know how to define a list (scalarField or vectorField) inside the #codeStream directive using the results from the last time step.

I have tried to use the #include directive creating a file with the list for both pressure and velocity results from the last time step, but it did not work. Also, I have seen the different list constructors but I think that anyone fits with my case (using the list presented in p and U file for the last time step).

This is my code for the initial conditions using #codeStream :
Code:
/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  v1912                                 |
|   \\  /    A nd           | Website:  www.openfoam.com                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       volScalarField;
    location    "0.22";
    object      p;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions      [0 2 -2 0 0 0 0];

internalField #codeStream
{

    codeInclude
    #{
        #include "fvMesh.H"
         #include "fvCFD.H"
	
    #};

    codeOptions
    #{
        -I$(LIB_SRC)/finiteVolume/lnInclude \
        -I$(LIB_SRC)/meshTools/lnInclude
    #};
    codeLibs
    #{
        -lmeshTools \
        -lfiniteVolume
    #};


    code
    #{
        const IOdictionary& d = static_cast<const IOdictionary&>(dict);
        const fvMesh& mesh = refCast<const fvMesh>(d.db());

        scalarField p(mesh.nCells(), 0.);

        scalar Cv = 0.0412; // Vortex strenght
        scalar Rv = 0.05; // Vortex core radius
	scalar rho_inf = 1.225; //Ambient density [kg/m^3]

        scalar x_v =0.1; // X vortex-centre position [m]
        scalar y_v = 0; // Y vortex-centre position [m]

        forAll(p, i)
        {
	     const scalar x = mesh.C()[i][0];
	     const scalar y = mesh.C()[i][1];
	     
	   //Here I want to define a scalarFied with the pressure values from the last time step called list_pressure

	     p[i] = -rho_inf/2*pow(Cv/Rv, 2)*exp(-((pow(x-x_v,2))+(pow(y-y_v,2)))/(pow(Rv,2)))+list_pressure[i];

            
        }

        //void Foam::Field<Type>::writeEntry(const word& keyword, Ostream& os) const

        p.writeEntry("", os);

     #};

}; 



boundaryField
{
    inlet
    {
        type            zeroGradient;
    }
    outlet
    {
        type            fixedValue;
        value           uniform 0;
    }
    upperWall
    {
        type            zeroGradient;
    }
    lowerWall
    {
        type            zeroGradient;
    }
    frontAndBack
    {
        type            empty;
    }
}


// ************************************************************************* //
and the file "initialConditions" with the pressure field for the last time step (the list I have to use in #codeStream)
Code:
/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  v1912                                 |
|   \\  /    A nd           | Website:  www.openfoam.com                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       volScalarField;
    location    "0.22";
    object      p;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions      [0 2 -2 0 0 0 0];

internalField #codeStream
{

    codeInclude
    #{
        #include "fvMesh.H"
         #include "fvCFD.H"
	
    #};

    codeOptions
    #{
        -I$(LIB_SRC)/finiteVolume/lnInclude \
        -I$(LIB_SRC)/meshTools/lnInclude
    #};
    codeLibs
    #{
        -lmeshTools \
        -lfiniteVolume
    #};


    code
    #{
        const IOdictionary& d = static_cast<const IOdictionary&>(dict);
        const fvMesh& mesh = refCast<const fvMesh>(d.db());

        scalarField p(mesh.nCells(), 0.);

        scalar Cv = 0.0412; // Vortex strenght
        scalar Rv = 0.05; // Vortex core radius
	scalar rho_inf = 1.225; //Ambient density [kg/m^3]

        scalar x_v =0.1; // X vortex-centre position [m]
        scalar y_v = 0; // Y vortex-centre position [m]

        forAll(p, i)
        {
	     const scalar x = mesh.C()[i][0];
	     const scalar y = mesh.C()[i][1];
	     
	   

	     p[i] = -rho_inf/2*pow(Cv/Rv, 2)*exp(-((pow(x-x_v,2))+(pow(y-y_v,2)))/(pow(Rv,2)));

            
        }

        //void Foam::Field<Type>::writeEntry(const word& keyword, Ostream& os) const

        p.writeEntry("", os);

     #};

}; 



boundaryField
{
    inlet
    {
        type            zeroGradient;
    }
    outlet
    {
        type            fixedValue;
        value           uniform 0;
    }
    upperWall
    {
        type            zeroGradient;
    }
    lowerWall
    {
        type            zeroGradient;
    }
    frontAndBack
    {
        type            empty;
    }
}


// ************************************************************************* //
Any help is useful and really appreciated !! Thanks you all.
angatri_14 is offline   Reply With Quote

Old   August 21, 2020, 18:16
Default
  #2
Senior Member
 
joegi
Join Date: Nov 2009
Location: genoa
Posts: 104
Rep Power: 17
joegi.geo is on a distinguished road
Well, you cannot add initial conditions after the solution have been computed.
It is an initial condition, just used to get your solver started, then your field will be whatever the solver computes.



In your case, I guess it is better to add a source term to the equations. You can do it using fvOptons or a programmable source term using codeStream.



You don't need tables, you need to program the mathematical function that describes that source term. Accessing tables with codeStream is not very easy, or even not possible at all (I don't recall).
joegi.geo 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
[OpenFOAM.com] swak4foam compiling issues on a cluster saj216 OpenFOAM Installation 5 January 17, 2023 17:05
Problems with volume defining Tudor_M ANSA 29 December 29, 2015 09:59
[Other] How to use finite area method in official OpenFOAM 2.2.0? Detian Liu OpenFOAM Meshing & Mesh Conversion 4 November 3, 2015 04:04
OpenFOAM on MinGW crosscompiler hosted on Linux allenzhao OpenFOAM Installation 127 January 30, 2009 20:08
DxFoam reader update hjasak OpenFOAM Post-Processing 69 April 24, 2008 02:24


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