CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Community Contributions

[swak4Foam] access field variables in groovyBC

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

Like Tree1Likes
  • 1 Post By wyldckat

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 29, 2015, 08:17
Default access field variables in groovyBC
  #1
Member
 
Mehtab
Join Date: Jan 2015
Posts: 41
Rep Power: 11
mehtab is on a distinguished road
Hi,

I tried implementing temperature boundary condition at Inlet as:

T_s = T_0 + 1/C_p(Q_f/m" - Hv)


Here is my files

Code:
boundaryField
{
    outlet
    {
        type            inletOutlet;
        inletValue      uniform 298.15;
        value           uniform 298.15;
    }
    sides
    {
        type            inletOutlet;
        inletValue      uniform 298.15;
        value           uniform 298.15;
    }
    base
    {
        type            zeroGradient;
    }
    inlet
    {
    type                          groovyBC;
    valueExpression        "T0+((1/cpi)*((Qf/m)-Hv))";
    variables                  "T0=300;m{inlet}=phi;Hv=8500;Qf{inlet}=Qr;cpi{inlet}=cp;";
    value                        300;

    }
controlDict
Code:
application     fireFoam;

startFrom       startTime;

startTime       0.0;

stopAt          endTime;

endTime         1.0;

deltaT          1.0e-2;

writeControl    adjustableRunTime;

writeInterval   0.01;

purgeWrite      0;

writeFormat     ascii;

writePrecision  6;

writeCompression uncompressed;

timeFormat      general;

timePrecision   6;

graphFormat     raw;

runTimeModifiable yes;

adjustTimeStep  yes;

maxCo           0.6;

maxDeltaT       0.1;

functions
{
    fieldAverage
    {
        type            fieldAverage;
        functionObjectLibs ( "libfieldFunctionObjects.so" );
        enabled         true;
        outputControl   outputTime;

        fields
        (
              U
              {
                  mean on;
                  prime2Mean on;
                  base time;
              }
          T
              {
                  mean on;
                  prime2Mean on;
                  base time;
              }
          CH4
              {
                  mean on;
                  prime2Mean on;
                  base time;
              }
          CO2
              {
                  mean on;
                  prime2Mean on;
                  base time;
              }
          H2O
              {
                  mean on;
                  prime2Mean on;
                  base time;
              }
          O2
              {
                  mean on;
                  prime2Mean on;
                  base time;
              }
        );
    }

libs (
    "libOpenFOAM.so"
    "libgroovyBC.so"
    "libgroovyStandardBCs.so"
    "libsimpleFunctionObjects.so"
    "libsimpleSwakFunctionObjects.so"
    "libswakFunctionObjects.so"
    "libswakPythonIntegration.so"
    "libswakTransportTurbFunctionPlugin.so"
) ;
I also checked my solver fireFoam createFields.H to check how Cp is being used.

createFields.H
Code:
volScalarField cp
    (
        IOobject
        (
            "cp",
            runTime.timeName(),
            mesh,
            IOobject::MUST_READ,
            IOobject::AUTO_WRITE
        ),
        thermo.Cp()
    );
I am getting this error:
Code:
swak4Foam: Setting default mesh
swak4Foam: Allocating new repository for sampledGlobalVariables
--> FOAM Warning : 
    From function ConcretePluginFunction<DriverType>::exists
    in file lnInclude/ConcretePluginFunction.C at line 121
    Constructor table of plugin functions for PatchValueExpressionDriver is not initialized


--> FOAM FATAL ERROR: 
 Parser Error for driver PatchValueExpressionDriver at "1.1-2" :"field Qr not existing or of wrong type"
"Qr"
  ^^
--| 

Context of the error:


- Driver constructed from scratch
  Evaluating expression "Qr"


    From function parsingValue
    in file lnInclude/CommonValueExpressionDriverI.H at line 1189.

FOAM exiting
What should I modify in me expressions? Have I defined cp correctly or should I change to thermo.Cp? Here Qr is totat radiative flux being calculated through radiation model. I am not able to understand the error. Please help

Thanks in advance....

[ Moderator note: moved from http://www.cfd-online.com/Forums/ope...-values-2.html ]

Last edited by wyldckat; September 21, 2015 at 15:42. Reason: Added [CODE][/CODE] markers and moderator note
mehtab is offline   Reply With Quote

Old   May 5, 2015, 14:54
Default access field variables in groovyBC
  #2
Member
 
Mehtab
Join Date: Jan 2015
Posts: 41
Rep Power: 11
mehtab is on a distinguished road
Hi,

Is it possible to access field variables (mass flow, temperature, heat flux) in groovyBC? If yes then how?

Please help

Thanks
mehtab is offline   Reply With Quote

Old   September 21, 2015, 16:09
Default
  #3
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,974
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Greetings firefoam,

I've had your questions on my to-do list for quite sometime now and only today did I finally manage to come to it .

The first issue I'm not able to reproduce. I used the tutorial case "combustion/fireFoam/les/smallPoolFire2D" as a test case for this and tried this condition:
Code:
    inlet
    {
      type                          groovyBC;
      valueExpression            "T0+(Qf/m)";
      variables                  "T0=300;m=phi;Qf=Qr;";
      value                        300;
    }
It worked fine without any problems. For future reference, I used OpenFOAM 2.4.x and swak4Foam 0.3.2.

I'm guessing the second question is related to the same problem, therefore I would need more details in order to be able to answer better to your question, because access to the "T" field should be straight forward and the other calculations could perhaps be achieved by using what's shown here: http://www.cfd-online.com/Forums/ope...tml#post446085 - post #5.

Best regards,
Bruno
__________________
wyldckat is offline   Reply With Quote

Old   September 28, 2015, 14:12
Default
  #4
Member
 
Mehtab
Join Date: Jan 2015
Posts: 41
Rep Power: 11
mehtab is on a distinguished road
Dear Bruno,

Thank you very much for looking at my problem. I also checked with OF 2.4.0 and swak4Foam 0.3.2. I took smallpoolfire3D tutorial case in OpenFoam.

First I defined my boundary condition exactly same as you and it was working fine. Then I added Cp term into my equation as below.

Code:
inlet
    {
        type                          groovyBC;
        valueExpression            "T0+1/Cp*(Qf/m)";
      	variables                  "T0=300;m=phi;Qf=Qr;";
      	value                        300;
    }
But in this case the solver does not recognise Cp as mentioned in the valueExpression and gives error.

I referred to the link provided by you : http://www.cfd-online.com/Forums/ope...tml#post446085

I have added the following piece of code into my controlDict and try to run the tutorial.

Code:
loadThermo {
    type loadPsiThermoModel;
    correctModel false;
    //        correctModel true;
    allowReload false;
    failIfModelTypeExists false;
    outputControl timeStep;
    outputInterval 1;
}

cvField {
    type expressionField;
    autowrite false;
    outputControl timeStep;
    outputInterval 1;
    expression "thermo_Cv()";
    fieldName CRRv;
}

cpField {
    type expressionField;
    autowrite false;
    outputControl timeStep;
    outputInterval 1;
    expression "thermo_Cp()";
    fieldName CRRp;
}
My error is below:
Quote:
--> FOAM FATAL ERROR:
Parser Error for driver PatchValueExpressionDriver at "1.6-9" :"field CRRp not existing or of wrong type"
"T0+1/CRRp*(Qf/m)"
^^^^
-------|

Context of the error:


- From dictionary: /home/maqsood/OpenFOAM/maqsood-2.4.0/tutorials/combustion/fireFoam/les/smallPoolFire3D/0/T.boundaryField.inlet
Evaluating expression "T0+1/CRRp*(Qf/m)"


From function parsingValue
in file lnInclude/CommonValueExpressionDriverI.H at line 1189.

FOAM exiting
Please suggest where I am doing it wrong.

Thanks
mehtab is offline   Reply With Quote

Old   October 2, 2015, 08:26
Default
  #5
Member
 
Mehtab
Join Date: Jan 2015
Posts: 41
Rep Power: 11
mehtab is on a distinguished road
Dear Bruno and Ehsan,

I am facing the same problem from quite a long time. But after reading this thread, I realized that I might be missing some functions in my controlDict file.

I am attaching my controlDict file and Temperature Boundary condition file where I am using groovyBC.

PS: Bruno, I have referred to your post http://www.cfd-online.com/Forums/ope...-groovybc.html #3 and http://www.cfd-online.com/Forums/ope...-values-2.html #39. I read the full post and think that I must be missing some functions in my controlDict file That is why I am attaching it to have a look for you. Please look at the files. Your guidance will be really helpful.
My error message reads as below:
Quote:
--> FOAM FATAL ERROR:
Parser Error for driver PatchValueExpressionDriver at "1.1-6" :"field thermo not existing or of wrong type"
"thermo:cp()"
^^^^^^
--|

Context of the error:


- From dictionary: /home/maqsood/OpenFOAM/maqsood-2.4.0/tutorials/combustion/fireFoam/les/smallPoolFire3D/0/T.boundaryField.inlet
Evaluating expression "thermo:cp()"


From function parsingValue
in file lnInclude/CommonValueExpressionDriverI.H at line 1189.

FOAM exiting
For the information I am using OF2.4.0 with swak4Foam0.3.2 and I am trying to solve the tutorial case of fireFoam :smallpoolfire3D.

Thanks in advance.


[ Moderator note: Moved from http://www.cfd-online.com/Forums/ope...-values-2.html ]
Attached Files
File Type: txt T.txt (1.5 KB, 41 views)
File Type: txt controlDict.txt (2.2 KB, 30 views)

Last edited by wyldckat; October 10, 2015 at 11:59. Reason: see "Moderator note:"
mehtab is offline   Reply With Quote

Old   October 4, 2015, 16:50
Default
  #6
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,974
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Quick answer: Please provide the complete "system/controlDict" file. I suspect something might be out-of-place and I can't guess what it is without seeing the full contents of the file.
wyldckat is offline   Reply With Quote

Old   October 5, 2015, 06:40
Default
  #7
Member
 
Mehtab
Join Date: Jan 2015
Posts: 41
Rep Power: 11
mehtab is on a distinguished road
Dear Bruno,

Please find attached my system/controlDict file and Temperature boundary condition file where I am using groovyBC.



Thanks in advance
Maqs
Attached Files
File Type: txt controlDict.txt (2.2 KB, 44 views)
File Type: txt T.txt (1.5 KB, 35 views)

Last edited by mehtab; October 9, 2015 at 11:32.
mehtab is offline   Reply With Quote

Old   October 10, 2015, 11:55
Default
  #8
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,974
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Quick answer: My guess was right, you defined the function objects in the wrong place. In theory, the correct content for "controlDict" is this:
Code:
/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  2.4.0                                 |
|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version         2.0;
    format          ascii;
    class           dictionary;
    object          controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

application     fireFoam;

startFrom       startTime;

startTime       0.0;

stopAt          endTime;

endTime         4.0;

deltaT          0.001;

writeControl    adjustableRunTime;

writeInterval   0.1;

purgeWrite      0;

writeFormat     ascii;

writePrecision  6;

writeCompression uncompressed;

timeFormat      general;

timePrecision   6;

graphFormat     raw;

runTimeModifiable yes;

adjustTimeStep  yes;

maxCo           0.6;

maxDeltaT       0.1;



libs (
    "libgroovyBC.so"
    "libsimpleFunctionObjects.so"
    "libsimpleSwakFunctionObjects.so"
    "libswakFunctionObjects.so"
    "libgroovyStandardBCs.so"
    "libswakThermoTurbFunctionPlugin.so"
);

functions
{

    loadThermo
    {
        type loadpsiThermoModel;
        correctModel false;
        //correctModel true;
        allowReload false;
        failIfModelTypeExists false;
        outputControl timeStep;
        outputInterval 1;
    }

    CvField
    {
            type expressionField;
            dimension [0 2 -2 -1 0 0 0];
            autowrite false;//false;
            outputControl timeStep;
            outputInterval 1;
            expression "thermo:Cv()";
            fieldName CRRv;
    }

    CpField
    {
            type expressionField;
            dimension [0 2 -2 -1 0 0 0];
            autowrite false;//false;
            outputControl timeStep;
            outputInterval 1;
            expression "thermo:Cp()";
            fieldName CRRp;
    }
  
}

// ************************************************************************* //
It feels like you didn't take good look into the tutorial cases that OpenFOAM has got for function objects. This is also explained in the OpenFOAM User Guide, section 6.2: http://cfd.direct/openfoam/user-guide/function-objects/
wyldckat is offline   Reply With Quote

Old   October 13, 2015, 11:27
Default
  #9
Member
 
Mehtab
Join Date: Jan 2015
Posts: 41
Rep Power: 11
mehtab is on a distinguished road
Dear Bruno,

Thank you very much for your support and guidance. I understood from this discussion that "loadPsiThermoModel" will provide all the fields which are defined in createField as thermo.p or thermo.T or thermo.psi etc. (mentioned in below code RoyalBlue color)

createFields.H
Code:
Info<< "Creating combustion model\n" << endl;

autoPtr<combustionModels::psiCombustionModel> combustion
(
    combustionModels::psiCombustionModel::New
    (
        mesh
    )
);

Info<< "Reading thermophysical properties\n" << endl;

psiReactionThermo& thermo = combustion->thermo();
thermo.validate(args.executable(), "h", "e");

SLGThermo slgThermo(mesh, thermo);

basicMultiComponentMixture& composition = thermo.composition();
PtrList<volScalarField>& Y = composition.Y();

const word inertSpecie(thermo.lookup("inertSpecie"));

Info<< "Creating field rho\n" << endl;
volScalarField rho
(
    IOobject
    (
        "rho",
        runTime.timeName(),
        mesh,
        IOobject::NO_READ,
        IOobject::AUTO_WRITE
    ),
    thermo.rho()
);

volScalarField& p = thermo.p();
const volScalarField& T = thermo.T();
const volScalarField& psi = thermo.psi();
However if I want to access the value of mass concentration of a particular species eg CH4 in this tutorial case for modifying velocity BC, I cannot get it from this function "loadPsiThermoModel". I think the reason is that this multicomponent specie fraction is defined in a different way as shown below.

Code:
Info<< "Creating combustion model\n" << endl;

autoPtr<combustionModels::psiCombustionModel> combustion
(
    combustionModels::psiCombustionModel::New
    (
        mesh
    )
);

Info<< "Reading thermophysical properties\n" << endl;

psiReactionThermo& thermo = combustion->thermo();
thermo.validate(args.executable(), "h", "e");

SLGThermo slgThermo(mesh, thermo);

basicMultiComponentMixture& composition = thermo.composition();
PtrList<volScalarField>& Y = composition.Y();

Is there any way to access mass concentration of a particular specie in groovyBC using swak4Foam?

Code:
CH4Field
    {
            type expressionField;
            dimension [0 0 0 0 0 0 0];
            autowrite false;//false;
            outputControl timeStep;
            outputInterval 1;
            expression "thermo_composition()";
            fieldName Ych4;
    }
I tried this but did not succeed and getting errors. I tried loading other functions as well but no success. I think I am not using the correct function to load species mass concentration.

Please suggest.

Thanks
Maqs
mehtab is offline   Reply With Quote

Old   October 17, 2015, 12:04
Default
  #10
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,974
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Quick answer: If the CH4 field is registered in memory and accessible from the outside, it will show up when you test this function object: http://openfoamwiki.net/index.php/Ti...gisteredObject
Kummi likes this.
wyldckat is offline   Reply With Quote

Old   October 23, 2015, 20:59
Default
  #11
Member
 
Mehtab
Join Date: Jan 2015
Posts: 41
Rep Power: 11
mehtab is on a distinguished road
Dear Bruno,

Thanks a lot for you help and suggestions. With your help, my temperature boundary condition is working now.

But I tried to implement groovyBC for velocity BC using CH4 field only and this is not running and shows error. It is not calculating the velocity in first iteration only and stops just after rho calculations.

My controlDict file looks fine now. I think the problem is in U file only while defining groovyBC. I have attached the file for your reference. Please suggest, if you point out any error or mistake in files.

Thanks
Maqs
Attached Files
File Type: txt controlDict.txt (4.8 KB, 46 views)
File Type: txt U.txt (2.5 KB, 51 views)
mehtab is offline   Reply With Quote

Old   February 4, 2019, 13:08
Default
  #12
Member
 
Join Date: Oct 2015
Posts: 63
Rep Power: 10
Scram_1 is on a distinguished road
Hi Mehtab,
Did you manage to fix your issue? If yes, then can you share your solution?
I'm facing a similar problem where my variable is not getting updated with time if I use groovyBC.

Best,
Scram_1
Scram_1 is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to access the alpha.water field when coding a velocity boundary. zhxter OpenFOAM Programming & Development 4 December 24, 2021 08:57
[Other] dynamicTopoFVMesh and pointDisplacement RandomUser OpenFOAM Meshing & Mesh Conversion 6 April 26, 2018 08:30
[swak4Foam] groovyBC and access to fields of other Regions ancolli OpenFOAM Community Contributions 0 July 29, 2017 09:41
[swak4Foam] groovyBC issue - k and epsilon sagnikmazumdar OpenFOAM Community Contributions 24 March 1, 2015 08:16


All times are GMT -4. The time now is 02:36.