CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Community Contributions (https://www.cfd-online.com/Forums/openfoam-community-contributions/)
-   -   [swak4Foam] a script for changing variables in groovyBC in 0 folder (https://www.cfd-online.com/Forums/openfoam-community-contributions/118313-script-changing-variables-groovybc-0-folder.html)

immortality May 24, 2013 17:36

a script for changing variables in groovyBC in 0 folder
 
Hi I have some variables(theta0,theta1,...,theta8)in various variable files(p,T,U,k,omega) in 0 folder.I'm wondering if its possible to write a script to change each of these variables I want before a run starts without a need to look into each files separately.
thanks for helps.
Code:

right
    {
        type groovyBC;

        variables (

                  "r=0.02325;"
                  "rpm=32151;"
                  "omega=rpm*pi/30;"
                  "v_r=r*omega;"
                  "w_cell=.004;"
                  "n=1;"
                  "theta0=0;"
                  "theta4=180;"
                  "theta5=23.72685186;"
                  "theta6=57.87037038;"
                  "theta7=104;"
                  "theta8=139;"
                  "p0_2=1023382.5;"
                  "T0_2=907;"
                  "p0_4=374902.5;"
                  "T0_4=973;"
                  "gamma=1.4;"
                  "R=287.14;"

                  "w_w0=n*w_cell;"
                  "w_w3=(theta5-theta0)*r*pi/180;"
                  "w_p2=(theta6-theta5)*r*pi/180;"
                  "w_w4=(theta7-theta6)*r*pi/180;"
                  "w_p4=(theta8-theta7)*r*pi/180;"
                  "w_w5=(theta4-theta8)*r*pi/180;"
               
                  "c1=(w_w3)/v_r;"
                  "c2=(w_w3+w_p2)/v_r;"
                  "c3=(w_w3+w_p2+w_w4)/v_r;"
                  "c4=(w_w3+w_p2+w_w4+w_p4)/v_r;"
                  "c5=(w_w3+w_p2+w_w4+w_p4+w_w5)/v_r;"
                  "t1=(w_w0-pos().y)/v_r;"
                  "t_mapped=(time()>t1) ? ((time()-t1)%(c5)+t1) : time();"

      );


gschaider May 24, 2013 18:31

Quote:

Originally Posted by immortality (Post 429876)
Hi I have some variables(theta0,theta1,...,theta8)in various variable files(p,T,U,k,omega) in 0 folder.I'm wondering if its possible to write a script to change each of these variables I want before a run starts without a need to look into each files separately.
thanks for helps.

One possibility would be to declare them as global variables in the controlDict and then add the appropriate globalScopes in the boundary conditions. Have a look at the examples how it is done there

immortality May 25, 2013 05:37

Hi Bernhard
which examples do you talking about?

ngj May 25, 2013 05:48

Hi Ehsan,

If you go to the location of your swak4Foam installation and type the following in the command line:

Code:

find ./Examples | xargs grep globalScope
then you will be given a nice list of all the occurrences of "globalScope" in the installation. In total 5-10 cases is present, where globalScope is used.

Good luck,

Niels

gschaider May 25, 2013 05:51

Quote:

Originally Posted by ngj (Post 429943)
Hi Ehsan,

If you go to the location of your swak4Foam installation and type the following in the command line:

Code:

find ./Examples | xargs grep globalScope
then you will be given a nice list of all the occurrences of "globalScope" in the installation. In total 5-10 cases is present, where globalScope is used.

Good luck,

Niels

Thanks Niels for helping me keep my Karma clean. I was just going to write something similar ... but more unfriendly

ngj May 25, 2013 05:53

You are welcome, Bernhard. Have a nice weekend.

/ Niels

immortality May 25, 2013 06:00

@Niels:thanks Niels,I thought Bernhard is poiting to OF examples in tutorial!
@Bernhard: wow! really?! Bernhard you should be more patient.:D I can't imagine what did you do if you were in place and position of me.;)

immortality May 25, 2013 06:37

thanks Both Niels and Bernhard
in an example I found this in controlDict:
Code:

defineState {
        type addGlobalVariable;
        outputControl timeStep;
        outputInterval 1;

        globalScope outletState;
        globalVariables {
            closed {
                valueType scalar;
                value 0;
            }
            airReachedOutletTime {
                valueType scalar;
                value -1;
            }
            shutdownTime {
                valueType scalar;
                value 1;
            }
        }
    }

then it suffices to add something like this in controlDict and
Code:

globalScopes (
            outletState
        );

in BC's as dear Bernhard said,right? the name of function that here is "defineState"isn't important,is?

immortality May 25, 2013 06:48

separate header of variables
 
I also found a brilliant idea for storing many variables I have in a separate file,
then I should delete theta variables in variable file and only bring them in global variable function,true?
but could anyone say what does this part of variables do?I think maybe i will need it in next time.
Code:

delayedVariables (
    {
        name outflow;
        delay 15;
        //        delay 1;
        storeInterval 0.1;
        startupValue "0";
    }
);


wyldckat May 25, 2013 07:55

Greetings to all!

@Ehsan:
Quote:

Originally Posted by immortality (Post 429955)
but could anyone say what does this part of variables do?I think maybe i will need it in next time.

I did a quick search on "swak4Foam delay" and got a hint from the main README file:
Code:

**** delayed-t-junction
    - Solver :: pimpleFoam
    - Demonstrates :: Delayed variables to simulate an inflow that
                      depends on the value of the outflow

Then I looked at the case in question, in particular the file "Examples/groovyBC/delayed-t-junction/0/U" and saw this:
Code:

    inlet1
    {
        type groovyBC;
        valueExpression "-inVel*normal()"
        value uniform (0 0 0);
        variables (
            "A=sum(area());"
            "outFlow{outlet}=sum((U&normal())*area());"
            "myFlow=0.5*outFlow;"
            "inVel=myFlow/sum(area());"
        );
        delayedVariables (
            {
                name outFlow;
                startupValue "0";
                storeInterval 0.001;
                delay 0.1;
            }
        );
    }

So Ehsan, I ask you: what does it seem that this "delayedVariables" feature look like it does? :)

Best regards,
Bruno

immortality May 25, 2013 08:09

don't you know such a simple thing Bruno?:mad:
I knew that I should explain you that!
It takes some the value in outlet and put it in inlet after a while each .001s !:D
after joking! but whats the role of delay there?

wyldckat May 25, 2013 08:35

Quote:

Originally Posted by immortality (Post 429970)
It takes some the value in outlet and put it in inlet after a while each .001s !:D
after joking! but whats the role of delay there?

It's exactly that! :)
This is a simple case, where the delay can help in reach a better convergence (I think, I'm not sure here), since it's giving a time offset to a boundary condition. This BC acts similarly to OpenFOAM's "directMapped" (or something "mapped" something).
The difference is that the original "mapped" will teleport the patch fields in the same time iteration or between consecutive iterations (I'm not sure on this one). The "delay" can give you more control on when the transfer is made.

Another possibility - which doesn't have much to do with convergence - is the ability to emulate a longer pipe, without the need to simulate it. For example, if you're simulating a 12 meter pipe that repeats itself with a protuberance of some kind (e.g. convergent or divergence nozzle or a simple obstacle), you can simulate only 2 meters that have the protuberance and calculate the delay it takes to go through the remaining 10 meters, before repeating the flow on the other side!

immortality May 25, 2013 11:49

so it takes and saves the data in output each .001s but waits and after .1s starts exerting them on inlet.right?
I didn't grasp your example exactly.could you clarify how this feature can be applicable in such situation you mentioned?
thanks.

wyldckat May 25, 2013 12:38

Quote:

Originally Posted by immortality (Post 429990)
so it takes and saves the data in output each .001s but waits and after .1s starts exerting them on inlet.right?

I think so, but I have not tested this to confirm.

Quote:

Originally Posted by immortality (Post 429990)
I didn't grasp your example exactly.could you clarify how this feature can be applicable in such situation you mentioned?
thanks.

OK, so we have a repeating pipe structure, with water flowing at around 1.0m/s. At every 12m, there is cluster of non-symmetrical bumps in the pipe, to cause some mixing turbulence. And we're only interested about the cumulative aspect of this turbulence and not an exact accurate answer... and/or because we have some equations that predict how the turbulent flow behaves for 10m of pipe at 1m/s.

Now, for example, we can either have a mesh with around 12 million cells, or trim it down to just 2-3 million cells and simulate only 2m worth of pipe.
To fill in the gap of the missing 10m, we need to delay the outlet back into the inlet for about: 10 (m) / 1 (m/s) = 10s.

With the "mapped" feature that OpenFOAM has got, you could only map after the full 12m pipe... or you could create a variant of OpenFOAM's "mapped" BC and implement the options and equations directly. But with this groovyBC's feature, there is no need for coding!

immortality May 25, 2013 13:15

Thank you so much.I figured out what you mean!
what a brilliant idea of using this feature in the example!
maybe i need to use it in future.

immortality May 25, 2013 16:07

2 Attachment(s)
I moved all variables to a file named variables(does it have any problem?)
and this error on wall_right occurred:
Code:

Selecting turbulence model type RASModel
Selecting RAS turbulence model kOmegaSST
kOmegaSSTCoeffs
{
alphaK1        0.85034;
alphaK2        1;
alphaOmega1    0.5;
alphaOmega2    0.85616;
Prt            1;
gamma1          0.5532;
gamma2          0.4403;
beta1          0.075;
beta2          0.0828;
betaStar        0.09;
a1              0.31;
b1              1;
c1              10;
F3              false;
}

fluxScheme: Kurganov

Starting time loop

swak4Foam: Setting default mesh
faceSource Average_left:
total faces  = 20
total area  = 4e-06


Mean and max Courant Numbers = 0.9922503451 4.611736676
deltaT = 2.127659574e-08
Time = 2.12766e-08

diagonal:  Solving for rho, Initial residual = 0, Final residual = 0, No Iterations 0
diagonal:  Solving for rhoUx, Initial residual = 0, Final residual = 0, No Iterations 0
diagonal:  Solving for rhoUy, Initial residual = 0, Final residual = 0, No Iterations 0
--> FOAM Warning :
From function CommonValueExpressionDriver::evaluateVariable
in file CommonValueExpressionDriver.C at line 924
There is a field named omega of type IOobject found which may be shadowed by the variable of the same name.
This may lead to trouble
If this is OK set 'variableNameIdenticalToField' in the relevant parser

[0] swak4Foam: Allocating new repository for sampledGlobalVariables
[1] swak4Foam: Allocating new repository for sampledGlobalVariables
[3] swak4Foam: Allocating new repository for sampledGlobalVariables
[2] swak4Foam: Allocating new repository for sampledGlobalVariables
--> FOAM Warning :
From function ConcretePluginFunction<DriverType>::exists
in file lnInclude/ConcretePluginFunction.C at line 111
Constructor table of plugin functions for PatchValueExpressionDriver is not initialized
[1] [3] [0]
[0]
[0] --> FOAM FATAL ERROR:
[0]  Parser Error for driver PatchValueExpressionDriver at "1.1-10" :"field wall_right not existing or of wrong type"
"wall_right ? vector(0,-v_r,0) : vector(300,0,0)"
^^^^^^^^^^
--|

Context of the error:


- From dictionary: /home/ehsan/Desktop/Central/nonUniformMesh/WR_Main_Central_100*10_nonMesh/processor0/0/U.boundaryField.right
Evaluating expression "wall_right ? vector(0,-v_r,0) : vector(300,0,0)"
[0]
[0]

[0]    From function parsingValue
[0]    in file lnInclude/CommonValueExpressionDriverI.H at line 1039.
[0]
FOAM parallel run exiting
[1]
[1] --> FOAM FATAL ERROR:
[1]  Parser Error for driver PatchValueExpressionDriver at "1.1-10" :"field wall_right not existing or of wrong type"
"wall_right ? vector(0,-v_r,0) : vector(300,0,0)"
^^^^^^^^^^
--|

Context of the error:


- From dictionary: /home/ehsan/Desktop/Central/nonUniformMesh/WR_Main_Central_100*10_nonMesh/processor1/0/U.boundaryField.right
Evaluating expression "wall_right ? vector(0,-v_r,0) : vector(300,0,0)"
[0]
[1]
[1]
[1]    From function parsingValue
[1]    in file lnInclude/CommonValueExpressionDriverI.H at line 1039.
[1]
FOAM parallel run exiting
[1]

[3] --------------------------------------------------------------------------
MPI_ABORT was invoked on rank 0 in communicator MPI_COMM_WORLD
with errorcode 1.

NOTE: invoking MPI_ABORT causes Open MPI to kill all MPI processes.
You may or may not see output from other processes, depending on
exactly when Open MPI kills them.
--------------------------------------------------------------------------

[3] --> FOAM FATAL ERROR:
[3]  Parser Error for driver PatchValueExpressionDriver at "1.1-10" :"field wall_right not existing or of wrong type"
"wall_right ? vector(0,-v_r,0) : vector(300,0,0)"
^^^^^^^^^^
--|

Context of the error:


- From dictionary: /home/ehsan/Desktop/Central/nonUniformMesh/WR_Main_Central_100*10_nonMesh/processor3/0/U.boundaryField.right
Evaluating expression "wall_right ? vector(0,-v_r,0) : vector(300,0,0)"
[3]
[3]
[3]    From function parsingValue
[3]    in file lnInclude/CommonValueExpressionDriverI.H at line 1039.
[3]
FOAM parallel run exiting
[3]
[2]
[2]
[2] --> FOAM FATAL ERROR:
[2]  Parser Error for driver PatchValueExpressionDriver at "1.1-10" :"field wall_right not existing or of wrong type"
"wall_right ? vector(0,-v_r,0) : vector(300,0,0)"
^^^^^^^^^^
--|

Context of the error:


- From dictionary: /home/ehsan/Desktop/Central/nonUniformMesh/WR_Main_Central_100*10_nonMesh/processor2/0/U.boundaryField.right
Evaluating expression "wall_right ? vector(0,-v_r,0) : vector(300,0,0)"
[2]
[2]
[2]    From function parsingValue
[2]    in file lnInclude/CommonValueExpressionDriverI.H at line 1039.
[2]
FOAM parallel run exiting
[2]
--------------------------------------------------------------------------
mpirun has exited due to process rank 0 with PID 19407 on
node Ehsan-com exiting without calling "finalize". This may
have caused other processes in the application to be
terminated by signals sent by mpirun (as reported here).
--------------------------------------------------------------------------
[Ehsan-com:19403] 3 more processes have sent help message help-mpi-api.txt / mpi-abort
[Ehsan-com:19403] Set MCA parameter "orte_base_help_aggregate" to 0 to see all help / error messages
Killing PID 19401
 PyFoam WARNING on line 232 of file /usr/local/lib/python2.7/dist-packages/PyFoam/Execution/FoamThread.py : Process 19401 was already dead
Getting LinuxMem: [Errno 2] No such file or directory: '/proc/19401/status'

whats wrong with this variable?I have defined it too!
----------------------------------------------------------------
I have defined the variable wall_right to be a Boolean variable according to values of time,maybe this is the source of the error?

wyldckat May 25, 2013 16:22

(edit: CAUTION - this post was guessing something that apparently isn't true. The problem seems to be something else.)

I haven't tested this yet, but my guess is this: the OpenFOAM feature "#include" does not work in the same way as in C++. It (probably) does not copy-paste the contents of the mentioned file into where we tell it to place. What it (probably) does is load it into memory and process the defined variables within the file.

So, I think the correct way to use this would be:
  1. In the file "variables", define it like:
    Code:

    myVariables (
    //... all of your variables...
    );

  2. Then in the "U" file, use it like this:
    Code:

    variables $myVariables;
  3. Still in the "U" file, use "#include" only once for the "variables" file.

immortality May 25, 2013 16:33

I saw it this morning in this example of swak4Foam:Examples/other/OSCFD_cleaningtank2D/0.orig
in its U file it has come these functions:
Code:

wall
    {
        type            fixedValue;
        value          uniform (0 0 0);
    }
    inlet
    {
        //        type fixedValue;
        type            groovyBC;
        //      value          uniform (0.1 0 0);
        value          uniform (1 0 0);
        valueExpression "-velIn*normal()";
        //        valueExpression "-0.1*normal()";

#include "commonVariables"
    }

and its the commonVariables file:
Code:

// -*- C++ -*-

variables (
    "outflow{outlet}=sum(normal()&U*alpha1*area());"
    "targetVelIn=0.2;"
    "minFrac=outflow>1e-15 ? 0.25 : 0;"
    "minHeight=min(pts().y);"
    "maxHeight=max(pts().y);"
    "volFlow=sum(targetVelIn*area());"
    "volFlow=mag(volFlow)<1e-15 ? 1e-15 : volFlow;"
    "flowFraction=outflow>1e-15 ? outflow/volFlow : 0;"
    "fraction=max(minFrac,flowFraction);"
    "fillHeight=minHeight+fraction*(maxHeight-minHeight);"
    "filled=pos().y<=fillHeight ? 1 : 0;"
    "filledArea=sum(filled*area());"
    "velIn=filled>0.5 ? outflow/max(filledArea,1e-15) : 0;"
);

delayedVariables (
    {
        name outflow;
        delay 15;
        //        delay 1;
        storeInterval 0.1;
        startupValue "0";
    }
);

then how this example has put there.maybe its because of Boolean!

wyldckat May 25, 2013 17:30

Hi Ehsan,

As I said, I was only guessing. Without a test case, that's all I can do :rolleyes:

Right before copying the variables list into the "variables" file, did you confirm if everything was working as intended?

Best regards,
Bruno

immortality May 25, 2013 17:53

I emailed you the case.one time before Bernhard told me something related to Boolean I don't remember,mabe its due to that.


All times are GMT -4. The time now is 00:23.