CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Pre-Processing (https://www.cfd-online.com/Forums/openfoam-pre-processing/)
-   -   codedFixedValue boundary condition (https://www.cfd-online.com/Forums/openfoam-pre-processing/91859-codedfixedvalue-boundary-condition.html)

Goutam March 20, 2012 12:41

[CODE]

inlet
{
type codedFixedValue;
value $internalField;
redirectType ramp;
code
#{
scalar U_0 = 0.003,
scalar r = 0.025;
fixedValueFvPatchField<vector> myPatch(
this->Cf().size());
forAll(this->Cf(), i)
{
myPatch[i] = vector( 2*U_0*(1 - Foam::pow(this->Cf()[i].x(), 2) / r / r )),0,0);
}
(*this)== myPatch;
#};
}

I got the following error:

Using dynamicCode for patch inlet on field U at line 25 in "/home/thermo/gsaha/OpenFOAM/gsaha-2.1.0/run/tutorials/incompressible/simpleFoam/parabolicflow/0/U::boundaryField::inlet"
Creating new library in "dynamicCode/ramp/platforms/linux64GccDPOpt/lib/libramp_33868748d21fc6c5f633c2f3604861e34d0d7dc7.s o"
Invoking "wmake -s libso /home/thermo/gsaha/OpenFOAM/gsaha-2.1.0/run/tutorials/incompressible/simpleFoam/parabolicflow/dynamicCode/ramp"
wmakeLnInclude: linking include files to ./lnInclude
Making dependency list for source file fixedValueFvPatchFieldTemplate.C
/home/thermo/gsaha/OpenFOAM/gsaha-2.1.0/run/tutorials/incompressible/simpleFoam/parabolicflow/0/U::boundaryField::inlet: In member function ‘virtual void Foam::rampFixedValueFvPatchVectorField::updateCoef fs()’:
/home/thermo/gsaha/OpenFOAM/gsaha-2.1.0/run/tutorials/incompressible/simpleFoam/parabolicflow/0/U::boundaryField::inlet:32: error: ‘class Foam::rampFixedValueFvPatchVectorField’ has no member named ‘Cf’
/home/thermo/gsaha/OpenFOAM/gsaha-2.1.0/run/tutorials/incompressible/simpleFoam/parabolicflow/0/U::boundaryField::inlet:32: error: expected primary-expression before ‘)’ token
/home/thermo/gsaha/OpenFOAM/gsaha-2.1.0/run/tutorials/incompressible/simpleFoam/parabolicflow/0/U::boundaryField::inlet:32: error: expected ‘;’ before ‘)’ token
/home/thermo/gsaha/OpenFOAM/gsaha-2.1.0/run/tutorials/incompressible/simpleFoam/parabolicflow/0/U::boundaryField::inlet:33: error: ‘class Foam::rampFixedValueFvPatchVectorField’ has no member named ‘Cf’
/home/thermo/gsaha/OpenFOAM/gsaha-2.1.0/run/tutorials/incompressible/simpleFoam/parabolicflow/0/U::boundaryField::inlet:33: error: ‘class Foam::rampFixedValueFvPatchVectorField’ has no member named ‘Cf’
/home/thermo/gsaha/OpenFOAM/gsaha-2.1.0/run/tutorials/incompressible/simpleFoam/parabolicflow/0/U::boundaryField::inlet:33: error: expected ‘;’ before ‘)’ token
make: *** [Make/linux64GccDPOpt/fixedValueFvPatchFieldTemplate.o] Error 1


--> FOAM FATAL IO ERROR:
Failed wmake "dynamicCode/ramp/platforms/linux64GccDPOpt/lib/libramp_33868748d21fc6c5f633c2f3604861e34d0d7dc7.s o"


file: /home/thermo/gsaha/OpenFOAM/gsaha-2.1.0/run/tutorials/incompressible/simpleFoam/parabolicflow/0/U::boundaryField::inlet from line 25 to line 30.

From function codedBase::createLibrary(..)
in file db/dynamicLibrary/codedBase/codedBase.C at line 202.

FOAM exiting

wouter March 20, 2012 17:40

hello,

there is a , instead of ;
scalar U_0 = 0.003,

But you probably found that already.

all the best,
Wouter

Goutam March 21, 2012 04:28

Error code: has no member named ‘Cf’
 
[CODE]

inlet
{
type codedFixedValue;
value $internalField;
redirectType ramp;
code
#{
scalar U_0 = 0.003;
scalar r = 0.025;
fixedValueFvPatchField<vector> myPatch(
this->Cf().size());
forAll(this->Cf(), i)
{ myPatch[i] = vector( 2*U_0*(1 - Foam:pow(this->Cf()[i].x(), 2) / pow(r,2)),0,0); }
(*this)== myPatch;
#};
}

I got the following error:

/home/thermo/gsaha/OpenFOAM/gsaha-2.1.0/run/tutorials/incompressible/simpleFoam/parabolicflow/0/U::boundaryField::inlet:32: error: ‘class Foam::rampFixedValueFvPatchVectorField’ has no member named ‘Cf’
/home/thermo/gsaha/OpenFOAM/gsaha-2.1.0/run/tutorials/incompressible/simpleFoam/parabolicflow/0/U::boundaryField::inlet:33: error: ‘class Foam::rampFixedValueFvPatchVectorField’ has no member named ‘Cf’
/home/thermo/gsaha/OpenFOAM/gsaha-2.1.0/run/tutorials/incompressible/simpleFoam/parabolicflow/0/U::boundaryField::inlet:33: error: ‘class Foam::rampFixedValueFvPatchVectorField’ has no member named ‘Cf’
make: *** [Make/linux64GccDPOpt/fixedValueFvPatchFieldTemplate.o] Error 1

Thanks All

November March 22, 2012 02:15

Greetings guys...
I want to apply a codedFixedValue to a 0/p for the inlet of an oscillatory flow... according to NS equation that p value should have something like p=-2*pi*f*U_m*cos(2*pi*f*t)x, so at left boundary x=-20 therefore this equation becomes p=-2*pi*f*U_m*cos(2*pi*f*t)*(-20).

I want to realize that p BC by codedFixedValue as following:
inlet
{
type codedFixedValue;
value uniform 0;
redirectType rampedFixedValue;
code
#{

operator==40*3.141*1*cos(3.141*0.5*this->db().time().value());

#};
}

However I keep getting the following error msg:

Quote:

--> FOAM FATAL IO ERROR:
Loading a shared library using case-supplied code is not enabled by default
because of security issues. If you trust the code you can enable this
facility be adding to the InfoSwitches setting in the system controlDict:

allowSystemOperations 1

The system controlDict is either

~/.OpenFOAM/$WM_PROJECT_VERSION/controlDict

or

$WM_PROJECT_DIR/etc/controlDict



file: /home/kyang/OpenFOAM/OpenFOAM-2.1.0/icoFoam-t/3DCylinder/0/p::boundaryField::inlet from line 35 to line 39.

From function codedBase::updateLibrary()
in file db/dynamicLibrary/dynamicCode/dynamicCode.C at line 81.

FOAM exiting
I wonder if in order to use the codedFixedValue, one has to do something like in the msg: "adding to the InfoSwitches setting in the system controlDict: allowSystemOperations 1"?? But I'm not sure how exactly to do that?? What is the InfoSwitches setting in controlDict?? I copied "allowSystemOperations 1" to controlDict and it didnt work....

wyldckat March 22, 2012 15:45

Greetings November,

Quote:

Originally Posted by November (Post 350820)
I wonder if in order to use the codedFixedValue, one has to do something like in the msg: "adding to the InfoSwitches setting in the system controlDict: allowSystemOperations 1"?? But I'm not sure how exactly to do that?? What is the InfoSwitches setting in controlDict?? I copied "allowSystemOperations 1" to controlDict and it didnt work....

I've written about this some time ago... read this section: 2.1 Additional tuning

Best regards,
Bruno

November March 23, 2012 00:16

Quote:

Originally Posted by wyldckat (Post 350996)
Greetings November,


I written about this some time ago... read this section: 2.1 Additional tuning

Best regards,
Bruno

Thanks a lot Bruno!!! I can apply the coded BC now however...

I am trying to simulate a very easy problem - oscillatory flow around a circular cylinder (3D), however I got stuck for the inlet and outlet boundary conditions here... and have been searching the web for solutions but without luck..
so, I want a inlet velocity at u_x=U_m*sin(2*pi*f*t), U_m=1m/s, u_y=0, u_z=0. Therefore I have specified for the inlet and outlet BC in 0/u as followings:

code:
Quote:

inlet
{
type oscillatingFixedValue;
refValue uniform (0 0 0);
//offset (0 -1 0);
amplitude constant 1;
frequency constant 0.5;
value uniform (0 0 0);//dummy OF

outlet
{
type zeroGradient;
}
and for the 0/p, I first tried to put for inlet the "fixedValue=0" but the results are not good. So I guessed according to NS, dp/dx=-du/dt at inlet, therefore dp/dx can bu calculated according to u_x, and do an intergral one gets the p=-2*pi*f*U_m*cos(2*pi*f*t)*x....So I decided to use the codedFixedValue for that p:

Quote:

inlet
{
type codedFixedValue;
value uniform 0;
redirectType rampedFixedValue; // what does this mean??
code
#{

(*this)==40*3.141*1*cos(3.141*0.5*this->db().time().value()); // 40 because x=-20 at inlet

#};
}
outlet
{
type fixedValue;
value 0;
}
But the results gets non-convergent after sometime...

Specifying the BC of inlet and outlet for an oscillatory flow around a circular cylinder... It looks easy however I couldnt find an example as how people did it... I am really confused now...Could you give me some hints??? Thanks in advance!!

Hisham April 11, 2012 11:18

Quote:

Originally Posted by Goutam (Post 350596)
[CODE]

I got the following error:

/home/thermo/gsaha/OpenFOAM/gsaha-2.1.0/run/tutorials/incompressible/simpleFoam/parabolicflow/0/U::boundaryField::inlet:32: error: ‘class Foam::rampFixedValueFvPatchVectorField’ has no member named ‘Cf’
/home/thermo/gsaha/OpenFOAM/gsaha-2.1.0/run/tutorials/incompressible/simpleFoam/parabolicflow/0/U::boundaryField::inlet:33: error: ‘class Foam::rampFixedValueFvPatchVectorField’ has no member named ‘Cf’
/home/thermo/gsaha/OpenFOAM/gsaha-2.1.0/run/tutorials/incompressible/simpleFoam/parabolicflow/0/U::boundaryField::inlet:33: error: ‘class Foam::rampFixedValueFvPatchVectorField’ has no member named ‘Cf’
make: *** [Make/linux64GccDPOpt/fixedValueFvPatchFieldTemplate.o] Error 1

Thanks All

Hi Goutam,

Had you any luck applying your BC????

Anyways, this works with me:
Code:

this->patch().Cf()
Best regards,
Hisham

Goutam April 12, 2012 05:22

I wrote the following code and now its working:

inlet
{
type codedFixedValue;
value $internalField;
redirectType ramp;

code
#{
scalar U_0=0.001934;
scalar r=0.02595;
fixedValueFvPatchVectorField myPatch(*this);
forAll(this->patch().Cf(),i)
{
myPatch[i]=vector(2*U_0*(1-Foam::pow(this->patch().Cf()[i].x(),2)/r/r),0,0);
}
operator==(myPatch);
#};
}

aabbasi59 September 6, 2012 08:12

Hi Friends,
I want to use codedFixedValue boundaryfield for boundary condition in Inlet for U. If I used constant value for equation it works but when I want to put values from another file it doesn't work. How can I force this patch-type for reading a constant from another file(e.g., include/initials)??
My code is:
inlet
{
type codedFixedValue;
redirectType velocity_inlet;
code
#{
scalar Ustar=$Ustar;;
scalar k=0.42;
scalar z0=2.25e-4;
fixedValueFvPatchVectorField myPatch(*this);
forAll(this->patch().Cf(),i)
{
myPatch[i]=vector(Ustar/k*(Foam::log((this->patch().Cf()[i].y()+z0)/z0)),0,0);
}
operator==(myPatch);
#};

value $internalField;
}


and I get the error below:
‘Ustar’ was not declared in this scope

Thanks a lot in advance.
Ali

aevub September 14, 2012 09:28

Hi
I am trying to make a ramped BC as mentioned above (Tomasso Lucchini's rampedFixedValue BC).

It compiles, but when using it in the cavitycase I get this error:


Foam::error:rintStack(Foam::Ostream&) in "/home/mvdtempe/OpenFOAM/OpenFOAM-2.1.x/platforms/linuxGccDPOpt/lib/libOpenFOAM.so"
Foam::sigSegv::sigHandler(int) in "/home/mvdtempe/OpenFOAM/OpenFOAM-2.1.x/platforms/linuxGccDPOpt/lib/libOpenFOAM.so"
Uninterpreted:
void Foam::dot<Foam::Vector<double>, Foam::Vector<double>, Foam::fvsPatchField, Foam::surfaceMesh>(Foam::GeometricField<Foam::inne rProduct<Foam::Vector<double>, Foam::Vector<double> >::type, Foam::fvsPatchField, Foam::surfaceMesh>&, Foam::GeometricField<Foam::Vector<double>, Foam::fvsPatchField, Foam::surfaceMesh> const&, Foam::GeometricField<Foam::Vector<double>, Foam::fvsPatchField, Foam::surfaceMesh> const&) in "/home/mvdtempe/OpenFOAM/OpenFOAM-2.1.x/platforms/linuxGccDPOpt/bin/icoFoam"

at icoFoam.C:0

in "/home/mvdtempe/OpenFOAM/OpenFOAM-2.1.x/platforms/linuxGccDPOpt/bin/icoFoam"
__libc_start_main in "/lib/i386-linux-gnu/libc.so.6"
in "/home/mvdtempe/OpenFOAM/OpenFOAM-2.1.x/platforms/linuxGccDPOpt/bin/icoFoam"
Segmentation fault (core dumped)


...?
I use 2.1.x

hesong December 12, 2014 05:43

I am trying to define a boundary condition, T(Temperature) will change with a Z(coordinates). But I don’t know ,which boundary should I user ,movingwall or front,etc;
I NEED HELP

myPatch
{
type codedFixedValue;
value uniform 0;
redirectType myFixedValue; // name of generated BC

code
#{
forAll(*this, i)
{
scalar z = patch().Cf()[i][2];
if (z > 0 && z < 32)
(*this)[i] = 0.0075 * z -1.58;
else if (...)
...;
else
...;
}
#};

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

codeOptions
#{
-I$(LIB_SRC)/finiteVolume/lnInclude
#};

aabbasi59 December 12, 2014 05:49

@hesong
Why don't you use groovyBC!? For your B.C the groovyBC could be the best choice.

hesong December 12, 2014 06:00

Quote:

Originally Posted by aabbasi59 (Post 523616)
@hesong
Why don't you use groovyBC!? For your B.C the groovyBC could be the best choice.

thank you !
could you provide some detailed information
I just learn this software for several months.

aabbasi59 December 12, 2014 06:08

Using groovyBC for complex BCs is straightforward. You can search it in the forum and find a lot of resources on working with groovyBC and swak4FOAM:
https://openfoamwiki.net/index.php/Contrib/groovyBC
https://openfoamwiki.net/index.php/Contrib/swak4Foam
http://www.cfd-online.com/Forums/tags/groovybc.html
http://www.cfd-online.com/Forums/ope...locity-bc.html
I hope you can find your solution.

mehtab April 23, 2015 11:50

Hi Foamers,

I want to implement a boundary condition at inlet.

𝑇_𝑠=𝑇_0+1/𝐶_𝑝 [𝑄_𝑓/(𝑚*̇ " )*̇ −𝐻_𝑣𝑎𝑝 ]


In this equation Q_f and 𝑚*̇ " need to be taken from inlet at previous time step.

Is it possible to do it using grovyBC or codedFixedValue in Openfoam? Which one be easier to implement?

Thanks in advance.....

usv001 April 14, 2016 02:51

Hello everybody,

I am experimenting with #codestream and codedFixedValue boundary conditions. I was able to implement #codeStream successfully for the internalField. But I am having a lot of trouble with codedFixedValue. I can't even get the example code given in the documentation to work. The code is compiling without mistakes but when I view it in Paraview it is applying the value (uniform 0) that is specified for 'value'. Any idea why codedFixedValue does not work for me?

By the way, I am using OF 2.1.1. Thank you very much.

usv001 April 14, 2016 06:08

I want to try something advanced but I am not sure of OF syntax and such.I just want to clarify if this code is supposed to work. It is just setting some fixed value.

Code:

NOZZLE_INLET
    {
        type                codedFixedValue;
        value                uniform 400000;
        redirectType        random;

    code
    #{
        operator == (200000);
    #};


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

    codeOptions
    #{
        -I$(LIB_SRC)/finiteVolume/lnInclude
    #};

    }

I know this doesn't require codedFixedValue but just wondering if it should work. Like I said in my previous post, the codedFixedValue does not show any errors when I run Paraview but it shows 400000 for the patch instead of 200000.

Once again, thanks everyone.

wyldckat April 15, 2016 18:10

Quote:

Originally Posted by usv001 (Post 594981)
Like I said in my previous post, the codedFixedValue does not show any errors when I run Paraview but it shows 400000 for the patch instead of 200000.

Quick answer: Given how you coded it, the value is only updated in the first time step of the solver or at least when you run decomposePar.

usv001 April 16, 2016 08:53

Hi Bruno,

Thank you very much for replying me. Really appreciate you taking your time to help others.

I used decomposePar and then reconstructPar to see if the changes take effect but there seems to be no change at all. The #code section is still being ignored.

wyldckat April 16, 2016 16:27

Hi usv001,

Something very strange is going on here... at least in my machine. I would have to rebuild OpenFOAM 2.1.1 from source code to fix the problem on my side and I don't feel like it right now.

There are two things I need to you test/check:
  1. Run the tutorial case "incompressible/simpleFoam/pipeCyclic". To run it:
    Code:

    ./Allrun
    Then inspect the contents of the file "log.simpleFoam". I ask this because this tutorial should work as intended.
  2. The code you're using has a flaw... this:
    Code:

    operator == (200000);
    should be at least like this:
    Code:

    operator==(200000);
Because I suspect that the boundary condition isn't even being built in your case, because you should see a pretty glaring error message when trying to use decomposePar.


In addition to this, which Linux Distribution and version are you using?

Best regards,
Bruno


All times are GMT -4. The time now is 20:01.