CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (https://www.cfd-online.com/Forums/openfoam-solving/)
-   -   Specifying nonuniform boundary condition (https://www.cfd-online.com/Forums/openfoam-solving/57782-specifying-nonuniform-boundary-condition.html)

Schag June 2, 2009 09:41

Hi,

Looking for a way to implement non uniform BC, I found part of the answer here, thanks!

Now, I'm looking for something more specific: I want to implement an inletOutlet condition. With the help provided here, I managed to modify the value argument of my BC. Now I want to modify also the inletValue argument, but I don't know how to write it.

Does anyone can help me? Thank you for your help!

Julien

ngj June 3, 2009 02:21

Hi Julien

There is already implemented an inletOutlet boundary condition. See the User-/Programming-guides.
For the use of these look into "/tutorials/interFoam/damBreak/0".

Best regards,

Niels

Schag June 3, 2009 03:16

Thank you for answering Niels,

but sorry, I wanted to say non uniform inletOutlet boundary condition.
I already used inletOutlet conditions, but only with uniform values at inletValue. I would like to know the syntax to modify the inletValue argument instead of the value one.

Best Regards
Julien

ngj June 3, 2009 03:34

So what you need is to be able to read a list of values in stead of on single value?
If that is the case, I would look into

A_("A", coeffDict_, N_)

where A_ in this case is a scalarField, "A" the name of the valuelist in the dictionary seen by coeffDict_ and N_ is the number of elements. The above is used in a constructor. See also the last constructor in the Doxygen-files:

http://foam.sourceforge.net/doc/Doxy...b6d65dfbddd227

Good luck,

Niels

P.S. I would start with the single-value inletOutlet and modify it where needed.

Schag July 27, 2009 12:00

Hi,
I come back to this topic because I'm using what was explained in the first page, and I want to go further for an industrial use (so I have to create applications that would make my work faster after...)

I want to change the type of boundaryfield with an application, so I'm looking for syntax to do it.
For the moment, after the line

fvPatchScalarField& targetPatch = gamma.boundaryField()[inletPatchID];

when I write

targetPatch.type();

I get

type generic;

and targetPatch is

type fixedValue;
value uniform 0;



and I don't find the way to change type fixedValue.
I want to change from fixedValue to inletOutlet for example, and then implement the arguments of my type (here inletValue and Value). I looked around the declarations of fvPatchField, boundaryField... but I'm a beginner in C++ and didn't find what I wanted.

Can anyone help me please?

Best regards,

Julien

heavy_user January 11, 2010 10:08

Quote:

Originally Posted by rres (Post 192875)
Hi guys,

I'm trying to create a custom bc as told here, but I'm stuck. I want to set the values of U, k and epsilon at the inlet, but when I try to compile, it throws the folowing errors:


I don't know what libraries are required. I've searched the manuals, internet, forums and nothing. For God's sake, someone help me! It's driving me crazy!!! http://www.cfd-online.com/OpenFOAM_D...part/happy.gif

Ravi

Quote:

Originally Posted by rres (Post 192875)
'k' was not declared in this scope
'epsilon' was not declared in this scope
'faceCentreshub' was not declared in this scope


Ravi

Hi Ravi,

I hope you did not go crazy on the prob :-P , waiting for the answer over one year...but here we go...

I had the exact same problem and I think i came up with an answer.
Since I could not find anything regarding an answer to "our" prob here a post:


the creatfields.h file needs to contain an entry for every variable you want to use (otherwise he complains obout unknown things)

so you need to do:

Info << "Reading field VARIABLE\n" << endl;
vol-insertTYPE-Field VARIABLE
(
IOobject
(
"VARIABLE",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
mesh
);


regards

heavy_user January 11, 2010 13:30

Hey There,

I have been trying to create my own nonuniform profile for different variables.

I ran into a prob (suprise, surprise...).

I used the executable that is made once you type "wmake" to change the first boundary patch successfully.
then I was going to add a second patch, which did not work out.
I tried different things and figured that I can only assign the first patch defined in Blockmesh (right ??).

i came up with this theory since I have this code:
....
volVectorField::GeometricBoundaryField& Upatches = U.boundaryField();
volScalarField::GeometricBoundaryField& kpatches = k.boundaryField();
volScalarField::GeometricBoundaryField& epsilonpatches = epsilon.boundaryField();

forAll(Upatches, patchI)
{
if
(
(typeid(Upatches[patchI]) == typeid(fixedValueFvPatchVectorField))
&&
(mesh.boundaryMesh()[patchI].name() == "inlet-air" || "sidewall" ||
"inlet-gas" || "sackgesicht!" )
)
{
fixedValueFvPatchVectorField& Upatch =
refCast<fixedValueFvPatchVectorField>(Upatches[patchI]);

fixedValueFvPatchScalarField& kpatch =
refCast<fixedValueFvPatchScalarField>(kpatches[patchI]);

fixedValueFvPatchScalarField& epsilonpatch =
refCast<fixedValueFvPatchScalarField>(epsilonpatch es[patchI]);

const vectorField& faceCentres =
mesh.Cf().boundaryField()[patchI];


forAll(faceCentres, facei)
{

{
Upatch[facei] = vector (0,0,56789);
kpatch[facei] = 666;
epsilonpatch[facei] = 666;
}


}
};

Info<< "Writing nonsence\n" << endl;
U.write();
k.write();
epsilon.write();

Info<< "End\n" << endl;

return 0;


}

}

and he writes only new entrys for the first patch defined by blockmesh.
I changed patch-orders in Blockmesh.
When I changed first and second patch he assigned values to the new first patch.
When I tried having the patch originally assigned third on first place, i ended up with error messages->:confused: .

so what the bleeep is going on and how can I assigne non-uniform values to several patches at once??
-----------
One veery noobish question:
I was forced to copy the executable, which is created by typing wmake, to the case-folder and execute it using ./filename..
Since rehash seems not to work on suse 11.
How can I rehash easy, so that I can use it like the other tools (such as setHotRoom, or paraFoam) just by typing its name??
-----------



thx&regards

gschaider January 11, 2010 14:01

Quote:

Originally Posted by heavy_user (Post 242207)
Hey There,

(mesh.boundaryMesh()[patchI].name() == "inlet-air" || "sidewall" ||
"inlet-gas" || "sackgesicht!" )
)

That was not what you wanted to write. You wanted something like
Code:

(mesh.boundaryMesh()[patchI].name() ==  "inlet-air" || mesh.boundaryMesh()[patchI].name() == "sidewall" ||
          mesh.boundaryMesh()[patchI].name() == "inlet-gas"  || mesh.boundaryMesh()[patchI].name() == "sackgesicht!" )
  )

Maybe there are other problems, but this was the most obvious one

Bernhard

heavy_user January 12, 2010 05:46

Hi Bernhard,

thanks for your answer!

But I am afraid it has to be something else...

when I do:

volVectorField::GeometricBoundaryField& Upatches = U.boundaryField();
volScalarField::GeometricBoundaryField& kpatches = k.boundaryField();
volScalarField::GeometricBoundaryField& epsilonpatches = epsilon.boundaryField();

forAll(Upatches, patchI)
{
if
(
(typeid(Upatches[patchI]) == typeid(fixedValueFvPatchVectorField))
&&
(mesh.boundaryMesh()[patchI].name() == "inlet-air" )
)

{
fixedValueFvPatchVectorField& Upatch =
refCast<fixedValueFvPatchVectorField>(Upatches[patchI]);

fixedValueFvPatchScalarField& kpatch =
refCast<fixedValueFvPatchScalarField>(kpatches[patchI]);

fixedValueFvPatchScalarField& epsilonpatch =
refCast<fixedValueFvPatchScalarField>(epsilonpatch es[patchI]);

const vectorField& faceCentres =
mesh.Cf().boundaryField()[patchI];

forAll(faceCentres, facei)
{

{
Upatch[facei] = vector (0,0,777);
kpatch[facei] = 666;
epsilonpatch[facei] = 666;
}




}
};
Info<< "Writing nonsence\n" << endl;
U.write();
k.write();
epsilon.write();
Info<< "End\n" << endl;
return 0;
}

It only writes new values when I change the patch-entry in blockmesh to first position, otherwise it seems not to be doing anything ...

any further Ideas?

regards!

p.s. can anyone also give me a hint how to quickly rehash on suse 11. ?

heavy_user January 13, 2010 12:47

nonuniform internal Field
 
Hi All,

if I want to have a nonuniform InternalField and I would like to have a similar code like postet above for the inlet...what do I have to change?
Can anyone give me a hint?

I have been trying stuff like this, but it does not work...

fvPatchField::internalField& Upatches = U.internalField();
GeometricField::internalField& Upatches = U.internalField();

I have also been trying to find a hint how to do it in the doxygen-"documentation"...but without success...has anyone a hint how to takle the problem, when I have a file setting the boundary (like postet before) and I want to rewrite it to set a nonuniform INternalfield ??

Thx&Regards !

gschaider January 13, 2010 14:10

Quote:

Originally Posted by heavy_user (Post 242459)
Hi All,

if I want to have a nonuniform InternalField and I would like to have a similar code like postet above for the inlet...what do I have to change?
Can anyone give me a hint?

I have been trying stuff like this, but it does not work...

fvPatchField::internalField& Upatches = U.internalField();
GeometricField::internalField& Upatches = U.internalField();

I have also been trying to find a hint how to do it in the doxygen-"documentation"...but without success...has anyone a hint how to takle the problem, when I have a file setting the boundary (like postet before) and I want to rewrite it to set a nonuniform INternalfield ??

The best strategy is usually "which utility does something like this and can inspire me". Have a look at the code of the engineSwirl-utility (found in $FOAM_UTILITIES/preprocessing). Basically a cell value for U can be accessed via U[cellI].

Bernhard

heavy_user January 14, 2010 09:08

Hi Bernhard,

thx for your answer..
It is kind of inspiring, but I am lacking the knowledge to do anything with this inspiration...

For example:

I have the lines:

const vectorField& faceCentres =
mesh.Cf().boundaryField()[patchI];

and

scalar test = cellCentres.y() /R;

For the boundary-profile.
I suppose the first line assigns the position-information to the variable "face centers".
The secont line uses part of this info.

Since i want to fit it to my cause (the internal-field) i have been trying things like this:

const vectorField& position =
mesh.Cf().internalField()[cellI];

scalar test = position.y() /R;

which obviously causes the compiler (and i guess also you) to do: :rolleyes: !

I could not find a axample in files (like funkysetfields, setfields...) which i was able to transfer.

So I started looking in the doxygen-files..I think they are hiding the answer somewhere...

So my question:

----------How do I start looking for the answer (in this case of bottom to top engineering) ??



I have been trying to find the syntax in the classes that regard my prob.. For example in :

src » finiteVolume » fields » fvPatchFields » fvPatchField

But the source code contains no information about finding a position in the field.

Or I have been staring at:
Foam::globalMeshData

I can see with which variables the classes exchange data...but i cant find a solution for my prob(or any service of the class i can call and which classes i have to include for him to work)..


I know that this is quite a "large" question, but I think the only way to really "learn" how to deal with Openfoam is to understand how I get information about the structure (otherwise i keep on guessing ).

regards&thx ( again) !

gschaider January 14, 2010 15:24

Quote:

Originally Posted by heavy_user (Post 242601)
For example:

I have the lines:

const vectorField& faceCentres =
mesh.Cf().boundaryField()[patchI];

and

scalar test = cellCentres.y() /R;

For the boundary-profile.
I suppose the first line assigns the position-information to the variable "face centers".

Yes. Have a look at Table 2.1 in the Programmer's guide for the meaning of Cf(). What you'll also find is the method C() for cell centers which you'll propably need for non-uniform internal fields

heavy_user January 15, 2010 06:59

Quote:

Originally Posted by gschaider (Post 242659)
Yes. Have a look at Table 2.1 in the Programmer's guide for the meaning of Cf(). What you'll also find is the method C() for cell centers which you'll propably need for non-uniform internal fields

Hi Bernhard,

thx a lot, was quite usefull..

have a nice weekend!

regards

heavy_user January 15, 2010 07:02

nonuniform internalField, Volumeprofile, profile, Volume
 
Hi Folks,

since I was not able to find something like this and I just finished it (and it is working :D ) here a post for the archive:
(This file is writing a non uniform internal-field for k, epsilon, velocity)

#include "fvCFD.H"
#include "OSspecific.H"
#include "fixedValueFvPatchFields.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

int main(int argc, char *argv[])
{

# include "setRootCase.H"

# include "createTime.H"
# include "createMesh.H"
# include "createFields.H"


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

volVectorField::InternalField& Upatches = U.internalField();
volScalarField::InternalField& kpatches = k.internalField();
volScalarField::InternalField& epspatches = epsilon.internalField();


forAll(Upatches, cellI)
{
scalar R = 0.0026;
//for 3d geometries only!?
/*scalar rR = sqr(faceCentres[facei].y *faceCentres[facei].y() +
faceCentres[facei].x() *faceCentres[facei].x() )/R; */

scalar test = mesh.Cf().internalField()[cellI].y() /R;


if
(
(test > 0) &&
(test < 1.00)
)

{
scalar MEAN_vel1 = 53;
scalar FACT1 = 0.03;


scalar VEL1 = MEAN_vel1 * (1.1758 + 0.27651 * test - 4.034 * pow(test,2) +
21.211*pow(test,3) - 50.888 * pow(test,4) + 57.595 * pow(test,5) - 25.343 * pow(test,6));

scalar k_1 = (3*VEL1*VEL1*FACT1*FACT1)/2;
scalar sucker_1 = VEL1*VEL1*VEL1;
scalar eps_1 = ( (Foam::sqrt(sucker_1>0 ? sucker_1 : -sucker_1) ) / (0.1 * 2*
0.0026));



Upatches[cellI] = vector (0,0,VEL1);
kpatches[cellI] =k_1 ;
epspatches[cellI]= eps_1;

}


if
(
(test > 1.00) &&
(test < 5)

)
{
scalar MEAN_vel2 = 9.2;
scalar FACT2 = -0.60736 + 1.2393 * test - 0.82277 * pow(test,2) + 0.2596 * pow(test,3) - 0.042878 * pow(test,4) + 0.0035864 *pow(test,5) -
0.00012003 * pow(test,6);
scalar VEL2 = MEAN_vel2 * ( -8.5665 + 19.253 * test - 16.531 *pow(test,2)
+ 7.6006* pow(test,3) - 2.0045 * pow(test,4) + 0.30352 * pow(test,5) - 0.024522 * pow(test,6) + 0.00081898 * pow(test,7) ) ;


scalar k_2 = (3*FACT2*FACT2*VEL2*VEL2)/2);

scalar eps_2 = ( (Foam::sqrt(VEL2*VEL2*VEL2) ) / (0.1 * 2* 0.0026));


Upatches[cellI] = vector (0,0,VEL2);
kpatches[cellI] = k_2;
epspatches[cellI]= eps_2;
}



if
(
(test > 5) &&
(test < 6.5)

)
{
scalar MEAN_vel3 = 9.2;
scalar FACT3 = -2.2207 + 1.4684 * test - 0.3617 * pow(test,2) + 0.039378 * pow(test,3) - 0.0016 * pow(test,4);
scalar VEL3 = MEAN_vel3 * 1 ;
scalar k_3 = (3*( pow(FACT3, 2) * pow(VEL3,2) )/2;

scalar eps_3 = ((Foam::sqrt(pow(VEL3,3))) / (0.1 * 2* R));


Upatches[cellI] = vector (0,0, VEL3);
kpatches[cellI] = k_3;
epspatches[cellI]= eps_3;
}


if
(
(test > 6.5)
)
{
scalar MEAN_vel4 = 9.2;
scalar FACT4 = 0.001;
scalar VEL4 = MEAN_vel4 * 1 ;
scalar k_4 = (3 * (pow(FACT4, 2) * pow(VEL4,2))/2;
scalar eps_4 = ((Foam::sqrt(pow(VEL4,3))) / (0.1 * 2* R));

Upatches[cellI] = vector (0,0, VEL4);
kpatches[cellI] = k_4;
epspatches[cellI]= eps_4;
}
}
Info<< "Writing stuff\n" << endl;
U.write();
k.write();
epsilon.write();

Info<< "End\n" << endl;

return 0;
}


regards!

heavy_user January 18, 2010 13:41

nonuniform profile with library
 
Hi There,

i have managed to make an executable (by using wmake) that patches the folder "0" with the desired non-uniform Values (see postings before if interested) ...

So I tried to do the same using the library I can create out of my BC-files by using "wmake libso"..

So I do:
"wmake libso" and he says : "'libNULL.so' is up to date."

I added the library entry to controldict
( like shown here: http://openfoamwiki.net/index.php/Si...ry_/_Tutorials )
libs ("setProfiles_oneInlet.so");I also added an entry to the k or U or epsilon file in 0 :
Like for using groovyBC...

inlet
{
type setProfiles_oneInlet;
value uniform 0.000138;
}



when i start the calculation he says:

gradientInternalCoeffs cannot be called for a genericFvPatchField (actual type setProfiles_oneInlet)
on patch inlet of field k in file "/home/itvns/OpenFOAM/OpenFOAM-1.6/!!_OWN/sandia_nonpremixed_turb_jetflame/V5_profiles_byLIB/0/k"
You are probably trying to solve for a field with a generic boundary condition.

From function genericFvPatchField<Type>::gradientInternalCoeffs( ) const
in file fields/fvPatchFields/basic/generic/genericFvPatchField.C at line 782.


so what did I miss, how do I use the boundary-conditionst this way (or is it not possible??)

thx in advance!

regards!

heavy_user January 20, 2010 07:24

3 Attachment(s)
Hi All,

i thougth I managed to create a profile for the BC and the internal-field..unfortunatelly I failed for reasons I dont understand.

The Profiles (for U, epsilon, k, CH4 and O2) should be independent of Z-direction, BUT they are NOT !

I attached pictures of CH4 over y (for different heights (Z)).
And also a graph for the z-velocity over y (for different heights (Z)).
Those were made for time 0 after patching the profile.
CH4 is the easyest example of the profile i am trying to use.
It should be 1 for 0<y<0.0026& 0<z<2 and 0 elsewhere.

(I am also assigning values to U,eps, k, CH4, O2, thats why i dont use setFields)


:confused: So 2 PRROBS :confused: :

1. why is the distribution depending on z, eventhough it should not be?
2. The patched file "0/CH4" has the values 0 and 1 ONLY (i checked on that ;)
), the values I get out of "sample-utility" and the picture from
paraFoam show values unequal to 0 or 1 ...similar things happen to U_z(see picture "vel_distribution.."):confused: ???

So why is the distribution depending on z and why does he alter my (peak) values ???

thx in advance&regards!!

More Info:
I have an INLET along the y-axes(CH4 entering for y< 0.0026, O2 for y>0.0026), x-Direction is"empty" since i am doing 2d..Direction of flow is along z-axis.

The Complete code for patching the BC and internal field is attached, parts of it can be seen further down...
(here i deleted eveything not necessary for CH4, to keep it simple)


Code:


volVectorField::InternalField& Upatches2 = U.internalField();
volScalarField::InternalField& kpatches2 = k.internalField();
volScalarField::InternalField& epspatches2 = epsilon.internalField();
volScalarField::InternalField& CH4patches2 = CH4.internalField();
volScalarField::InternalField& O2patches2 = O2.internalField();

  forAll(Upatches2, cellI)
  {
    scalar R              =  0.0026;

   
    scalar test            =  mesh.Cf().internalField()[cellI].y() /R;
       
       
      if
      (
        (test > 0) &&
        (test < 1.00)
      )
       
      {   

        CH4patches2[cellI] =  1;
        O2patches2[cellI]  =  0;   
         
      }
       

      if
      (
      (test > 1.00) &&
      (test < 5) 
     
      )
      {

      CH4patches2[cellI] =  0;
      O2patches2[cellI]  =  1; 
      }   



      if
      (
      (test > 5) &&
      (test < 6.5)     
      )     
      {

      CH4patches2[cellI] =  0;
      O2patches2[cellI]  =  1;
      }   


      if
      (
    (test > 6.5) 
      )
      {
        CH4patches2[cellI]=  0;
        O2patches2[cellI] =  1;
      }
    }

    Info<< "Writing stuff\n" << endl;

    U.write(); 
    k.write();
    epsilon.write();
    CH4.write();
    O2.write();

    Info<< "End\n" << endl;

    return 0;


  }

}

sampleDict:

Code:


interpolationScheme cellPoint;

setFormat    raw;

sets
(
  /*
    z=0
    {
        name            test123;
    type        uniform;
        axis            y;
        start          (0 0.00001 0);
        end            (0 0.15 0);
        nPoints        100;
    }

    z=0.1
    {
        name            test123;
    type        uniform;
        axis            y;
        start          (0 0 0.1);
        end            (0 0.15 0.1);
        nPoints        100;
    }


    z=0.2

    {
        name            test123;
    type        uniform;
        axis            y;
        start          (0 0.00001 0.2);
        end            (0 0.15 0.2);
        nPoints        100;
    }

    z=0.5
    {
        name            test123;
    type        uniform;
        axis            y;
        start          (0 0.00001 0.5);
        end            (0 0.15 0.5);
        nPoints        100;
    }
/*
    z=1
    {
        name            test123;
    type        uniform;
        axis            y;
        start          (0 0.00001 1);
        end            (0 0.15 1);
        nPoints        100;
    }

    z=1.5
    {
        name            test123;
    type        uniform;
        axis            y;
        start          (0 0.00001 1.5);
        end            (0 0.15 1.5);
        nPoints        100;
    }
*/
);

surfaces
();

fields
(
CH4



);


heavy_user January 22, 2010 11:01

HI Folks,

i updated the last post to make the prob clearer..

regards& a nice weekend!!

gschaider January 27, 2010 09:54

Quote:

Originally Posted by heavy_user (Post 243151)
Hi All,

i thougth I managed to create a profile for the BC and the internal-field..unfortunatelly I failed for reasons I dont understand.

The Profiles (for U, epsilon, k, CH4 and O2) should be independent of Z-direction, BUT they are NOT !



Code:


volVectorField::InternalField& Upatches2 = U.internalField();

  forAll(Upatches2, cellI)
  {
    scalar R              =  0.0026;

   
    scalar test            =  mesh.Cf().internalField()[cellI].y() /R;
       
       
      if
      (
        (test > 0) &&
        (test < 1.00)
      )


OK. Now I get it. You're mixing cells with faces. What you'll want is
Code:

scalar test            =  mesh.C()[cellI].y() /R;
But your code gives the more interesting (not completely random) patterns

heavy_user January 29, 2010 04:50

Quote:

Originally Posted by gschaider (Post 243911)
OK. Now I get it. You're mixing cells with faces. What you'll want is
Code:

scalar test            =  mesh.C()[cellI].y() /R;
But your code gives the more interesting (not completely random) patterns

Thank you so much, again!! :o


All times are GMT -4. The time now is 19:16.