CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   groovyBC controlled by scalar (http://www.cfd-online.com/Forums/openfoam-programming-development/100090-groovybc-controlled-scalar.html)

Jaroslav April 20, 2012 04:13

groovyBC controlled by scalar
 
Hi all,

could somebody help me? I'm trying to implement thermostat function in OpenFOAM. I'm using groovyBC.
I want something like this (in the 0/T file):
Code:

hotWall
    {
          type        groovyBC;
          variables    "Thot=Burner*373.15 + (1-Burner)*293.15;";
          valueExpression "Thot";
    }

where Burner is parameter defining the state of burner (1-on,0-off) and its value is determined in the solver code (controlled by algorithm).
If I declare Burner as volScalarField in the solver and change the value on the corresponding patch (hotWall), it works fine.
But this is quite complicated and IMHO nasty way how to do it.

So my question is: Is there any way how to achieve this using variable Burner only as a scalar?

I tried this (and many other variation):
Code:

dimensionedScalar Burner
    (
      "Burner",
      scalar(1)
    );

but it ended with parser error (Burner was not recognized).

Do you have any idea how to use only scalar in the groovyBC?
Thank very much for your help

regards
Jaroslav

gschaider April 20, 2012 20:23

Quote:

Originally Posted by Jaroslav (Post 355760)
Hi all,

could somebody help me? I'm trying to implement thermostat function in OpenFOAM. I'm using groovyBC.
I want something like this (in the 0/T file):
Code:

hotWall
    {
          type        groovyBC;
          variables    "Thot=Burner*373.15 + (1-Burner)*293.15;";
          valueExpression "Thot";
    }

where Burner is parameter defining the state of burner (1-on,0-off) and its value is determined in the solver code (controlled by algorithm).
If I declare Burner as volScalarField in the solver and change the value on the corresponding patch (hotWall), it works fine.
But this is quite complicated and IMHO nasty way how to do it.

So my question is: Is there any way how to achieve this using variable Burner only as a scalar?

I tried this (and many other variation):
Code:

dimensionedScalar Burner
    (
      "Burner",
      scalar(1)
    );

but it ended with parser error (Burner was not recognized).

Do you have any idea how to use only scalar in the groovyBC?
Thank very much for your help

regards
Jaroslav

Unfortunately there is no way to register a single scalar value with an objectRegistry (which would be the requirement for this to work). But there is a way using the global variables mechanism in swak4Foam. The problem is that you'll have to link it to the swak4FoamParsers-library (with -lswak4FoamParsers). If you can live with chaining your solver to that monster: fine ;)

You'll have to make the place were global variables are stored known to the solver with
Code:

#include "GlobalVariablesRepository.C"
then where it is appropriate you can store your variable in a global scope (I assume you have a variable called "burner")
Code:

GlobalVariablesRepository::getGlobalVariables().addValue(
  "Burner",
  "BurnerControl",
  ExpressionResult(dimensionedScalar("burner",dimless,burner))
);

(the interface to GlobalVariablesRepository was not really designed to be used by end-users)

Now in the boundary condition you've got to make the global scope known with
Code:

globalScopes ( BurnerControl );
and the variable Burner should be known and have the last value that has been set.

If you want to keep your solver "swak-free" then an alternative would be to implement the burner algorithm in a functionObject and set the global variable there. This is possible with the swakCoded-functionObject (which basically is the usual coded-FO with the possibility to set globals) or the pythonIntegration-functionObject.

Jaroslav April 25, 2012 12:16

Hi Bernhard,

thank you very much for your help! It works. My monster code is alive! ;) (thunder in background :) )

Jaroslav

gschaider April 25, 2012 12:56

Quote:

Originally Posted by Jaroslav (Post 356959)
Hi Bernhard,

thank you very much for your help! It works. My monster code is alive! ;) (thunder in background :) )

You mean: like this http://www.youtube.com/watch?v=9AFf0ysgNiM (that's me on the right, BTW)

argonaut May 28, 2012 07:05

Quote:

Originally Posted by gschaider (Post 355927)
Code:

GlobalVariablesRepository::getGlobalVariables().addValue(
  "Burner",
  "BurnerControl",
  ExpressionResult(dimensionedScalar("burner",dimless,burner))
);


Can the ExpressionResult contain other type of a variable except dimensionedScalar, e.g. scalar or int?

gschaider May 28, 2012 10:24

Quote:

Originally Posted by argonaut (Post 363421)
Can the ExpressionResult contain other type of a variable except dimensionedScalar, e.g. scalar or int?

int (or how us Foamers call it: label) is definitely not supported (reason is that there is no such thing as a volLabelField). But if you don't count too high a scalar might serve this purpose too.

Currently the constructor only supports dimensioned values. But as you see above (dimless) this is no problem. The constructor is templated to accept any dimensioned-thing, but the internals (ugly, but serves its purpose) of ExpressionResult only accept scalar, vector, tensor, symmTensor and sphericalThensor


All times are GMT -4. The time now is 17:09.