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)

wolfindark August 24, 2011 17:18

codedFixedValue boundary condition
 
Dear All;

I am trying to define a moving wall boundary condition, X component velocity will change with a function of sin().

the block below does not take calculated ux value. How can I get calculated value as a boundary condition like (ux 0 0) ?.

movingWall_1
{
type codedFixedValue;
value uniform (0 0 0);
redirectType rampedFixedValue;
code
#{

double ux=(0.5*sin(3.14*this->db().time().value())/2);

#};
}

best regards.:confused:

flowman August 24, 2011 21:29

I think it might be something like

Code:

movingWall_1
{
type codedFixedValue;
value uniform (0 0 0);
redirectType rampedFixedValue;
code
#{

 vector ((0.5*sin(3.14*this->db().time().value())/2), 0, 0);

#};
}


LarsPT August 25, 2011 01:16

That looks like something oscillating! Do you know the oscillatingFixedValue BC? It comes naturally with OpenFOAM. Check out the article in the Wiki.

http://openfoamwiki.net/index.php/Ma...tingFixedValue

wolfindark August 25, 2011 03:14

flowman: thank you for the reply but it does not work.

LarsPT : thank you too, yes this is oscilating. However, I also need different step or oscilating functions, I should imlement in this way.

any help aprreciated.

thank you.

gschaider August 25, 2011 07:13

Quote:

Originally Posted by wolfindark (Post 321460)
Dear All;

I am trying to define a moving wall boundary condition, X component velocity will change with a function of sin().

the block below does not take calculated ux value. How can I get calculated value as a boundary condition like (ux 0 0) ?.

movingWall_1
{
type codedFixedValue;
value uniform (0 0 0);
redirectType rampedFixedValue;
code
#{

double ux=(0.5*sin(3.14*this->db().time().value())/2);

#};
}

best regards.:confused:

I think the line
Code:

            (*this)==vector(0.5*sin(3.14*this->db().time().value())/2,0,0);
will do what you want to. Have a look in doxygen why it does that (should take you at most an hour).

I personally still prefer to write such simple boundary conditions as
Code:

type groovyBC;
valueExpression "vector(0.5*sin(3.1414*time())/2,0,0)";

but then machines get polluted with groovyBC/swak4Foam as soon as I touch them (and I prefer not to do C++ if I don't have to)

Bernhard

wolfindark August 25, 2011 08:40

gschaider thank you! it works.

anlj October 9, 2011 16:51

Dear all,
I can not get this boundary condition to work (see below), has anyone else gotten this error and have a solution?

Many thanks, Anders

Create time
Create mesh for time = 0
Selecting dynamicFvMesh dynamicMotionSolverFvMesh
Selecting motion solver: displacementLaplacian
[0] [2] [1]
[1]
[1] --> FOAM FATAL IO ERROR:
[1] Unknown patchField type codedFixedValue for patch type wall
Valid patchField types are :
25
(
angularOscillatingDisplacement
angularOscillatingVelocity
calculated
cyclic
cyclicSlip
empty
fixedNormalSlip
fixedValue
mixed
nonuniformTransformCyclic
oscillatingDisplacement
oscillatingVelocity
processor
processorCyclic
sixDoFRigidBodyDisplacement
slip
surfaceDisplacement
surfaceSlipDisplacement
symmetryPlane
timeVaryingUniformFixedValue
uncoupledSixDoFRigidBodyDisplacement
uniformFixedValue
value
wedge
zeroGradient
)
[1] [3]
[0] --------------------------------------------------------------------------

gschaider October 10, 2011 04:30

Quote:

Originally Posted by anlj (Post 327228)
Dear all,
I can not get this boundary condition to work (see below), has anyone else gotten this error and have a solution?

Many thanks, Anders

Create time
Create mesh for time = 0
Selecting dynamicFvMesh dynamicMotionSolverFvMesh
Selecting motion solver: displacementLaplacian
[0] [2] [1]
[1]
[1] --> FOAM FATAL IO ERROR:
[1] Unknown patchField type codedFixedValue for patch type wall
Valid patchField types are :
25
(
angularOscillatingDisplacement
angularOscillatingVelocity
calculated
cyclic
cyclicSlip
empty
fixedNormalSlip
fixedValue
mixed
nonuniformTransformCyclic
oscillatingDisplacement
oscillatingVelocity
processor
processorCyclic
sixDoFRigidBodyDisplacement
slip
surfaceDisplacement
surfaceSlipDisplacement
symmetryPlane
timeVaryingUniformFixedValue
uncoupledSixDoFRigidBodyDisplacement
uniformFixedValue
value
wedge
zeroGradient
)
[1] [3]
[0] --------------------------------------------------------------------------

Should be there .... if you're using OF 2.0

anlj October 10, 2011 05:39

Hello Bernhard,

Yes it is OF 2.0, and I have allowed the use of dynamic code in the "global" controlDict.

gschaider October 11, 2011 04:55

Quote:

Originally Posted by anlj (Post 327290)
Hello Bernhard,

Yes it is OF 2.0, and I have allowed the use of dynamic code in the "global" controlDict.

It is compiled into finiteVolume, so it should be in that list. Maybe the problem is that your patch is a wall (not a patch). But I'm not an expert on the codedBC (only used it once out of curiosity)

anlj October 11, 2011 15:37

Ok, I tried codedFixedValue on the inlet (which is a patch and not a wall) in the wingMotion tutorial and it works! But if it does not work for walls, why is there an example of a codedFixedValue boundary condition for a movingWall in the C++ documentation of the codedFixedValue?

Still speaking of the wingMotion tutorial; if I want the wing (patch type wall) to move according to user supplied code, I have to find some other way than the codedFixedValue BC? I am confused :S

Inlet BC (U file):

inlet
{
type codedFixedValue;
value $internalField;
redirectType ramp;
code
#{
(*this)==vector(min(100, 0.1*this->db().time().value()),0,0);
#};
}

Output:

/*---------------------------------------------------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 2.0.1 |
| \\ / A nd | Web: www.OpenFOAM.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
Build : 2.0.1-51f1de99a4bc
Exec : pimpleDyMFoam
Date : Oct 11 2011
Time : 20:56:33
Host : anlj-laptop
PID : 3089
Case : /home/anlj/OpenFOAM/anlj-2.0.1/run/tutorials/wingMotion/wingMotion2D_pimpleDyMFoam
nProcs : 1
sigFpe : Enabling floating point exception trapping (FOAM_SIGFPE).
fileModificationChecking : Monitoring run-time modified files using timeStampMaster
allowSystemOperations : Allowing user-supplied system call operations

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Create time

Create mesh for time = 0

Selecting dynamicFvMesh dynamicMotionSolverFvMesh
Selecting motion solver: displacementLaplacian
Selecting motion diffusion: inverseDistance
Reading field p

Reading field U

Using dynamicCode for patch inlet on field U
at line 12593 in "/home/anlj/OpenFOAM/anlj-2.0.1/run/tutorials/wingMotion/wingMotion2D_pimpleDyMFoam/0/U::boundaryField::inlet"
Reading/calculating face flux field phi

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

Reading field rAU if present


PIMPLE: no residual control data found.
Calculations will employ 2 corrector loops


Starting time loop
....

Best regards, Anders

gschaider October 11, 2011 17:05

Quote:

Originally Posted by anlj (Post 327528)
Ok, I tried codedFixedValue on the inlet (which is a patch and not a wall) in the wingMotion tutorial and it works! But if it does not work for walls, why is there an example of a codedFixedValue boundary condition for a movingWall in the C++ documentation of the codedFixedValue?

I don't know. The guys from OpenCFD don't answer on the message board any more, so if you really want an answer you'll have to make a bug-report.

Quote:

Originally Posted by anlj (Post 327528)
Still speaking of the wingMotion tutorial; if I want the wing (patch type wall) to move according to user supplied code, I have to find some other way than the codedFixedValue BC? I am confused :S

I personally (but I'm biased) use groovyBC for that kind of stuff. There are cases whee groovyBC has its limits, but not in this case (and it doesn't care whether the patch is a wall)

Quote:

Originally Posted by anlj (Post 327528)
Inlet BC (U file):

inlet
{
type codedFixedValue;
value $internalField;
redirectType ramp;
code
#{
(*this)==vector(min(100, 0.1*this->db().time().value()),0,0);
#};
}

That would be the same BC in groovyBC:
Code:

inlet {
    type groovyBC;
    value          $internalField;
    valueExpression "vector(min(100,time()),0,0)";
}

Quote:

Originally Posted by anlj (Post 327528)
Output:

Starting time loop

That looks alright, doesn't it?

wyldckat October 11, 2011 19:51

Greetings to all!

Quote:

Originally Posted by anlj (Post 327528)
But if it does not work for walls, why is there an example of a codedFixedValue boundary condition for a movingWall in the C++ documentation of the codedFixedValue?

Just my 2 cents here (since I don't much experience on this particular subject), but my guess is that:
  • a wall BC is like a house;
  • a movingWall BC is like a trailer;
  • but a trailer is not a house ;) both can be homes, but only one is a true house :D
In other words, they probably designate the movingWall BC to be a special type of patch, similarly to a wedge or a symmetryPlane (if I'm not mistaken).

As for the moving wing, shouldn't it be a mesh motion, not a field motion!?
But if it is meant to be a field motion, then why not set it as a movingWall instead of just wall?

Best regards,
Bruno

anlj October 12, 2011 08:28

Gents,
Thanks for your replies.

My goal here is to implement a quite advanced control algorithm for the movement of a wall in my simulation (which is not the wingMotion tutorial, I just use that one as a test case) so groovyBC is not an option.

Previously (OF 1.7) I used the timeVaryingUniformFixedValue BC on my moving wall (in the pointDisplacment file) and had the wall moving in a prescribed matter, i.e. a passiv solution. Now I want to switch to the codedFixedValue and have the wall move according to instructions from a control algorithm, i.e. an active solution.

The patch type in the constant/polyMesh/boundary file must be set to WALL, otherwise I can not use turbulnce wall functions on my moving wall since wall functions are made for patch type wall only, and not for patch type patch as well?

When a wall moves, the movingWall BC must be applied on that wall in the U-file as I understand it?

Then in the pointDisplacment file, instead of the sixDOF BC (as in wingMotion tutorial) I want to write my own C++ code. I thought codedFixedValue would let me do that.....

Bruno; did you mean that that codedFixedValue BC is only for fields and can not be used for mesh motion? Is that why it does not work?

Best regards, Anders

wyldckat October 12, 2011 16:17

Hi Anders,

Quote:

Originally Posted by anlj (Post 327653)
Bruno; did you mean that that codedFixedValue BC is only for fields and can not be used for mesh motion? Is that why it does not work?

According to the error message, that's exactly it! codedFixedValue hasn't been implemented on the point displacement solver. It's even a bit ironic, trying to define a dynamic fixed value...

OK, basically said motion solver is explicitly specified in the file "constant/dynamicMeshDict" which states the following interesting code:
Code:

dynamicFvMesh      dynamicMotionSolverFvMesh;

motionSolverLibs ("libfvMotionSolvers.so");

solver            displacementLaplacian;

diffusivity      inverseDistance (wing);

The output you showed us before indicates the same:
Code:

Selecting dynamicFvMesh dynamicMotionSolverFvMesh
Selecting motion solver: displacementLaplacian

If you check the folder "OpenFOAM-2.0.x/src/fvMotionSolver/fvMotionSolvers/displacement", you'll find these:
Code:

componentLaplacian
displacementFvMotionSolver
interpolation
laplacian
layeredSolver
SBRStress

Sooo... this pretty much reinforces the idea that the codedFixedValue doesn't exist yet for point displacement.

Now you have (at least) two options:
  1. Try to (re)make the library yourself, using copy-paste-change/adapt ;).
  2. Or innocently report this as a bug here: http://www.openfoam.com/mantisbt/my_view_page.php :rolleyes:

edit: here's another possibility, shown in the folder "tutorials/basic/potentialFoam/cylinder/constant/polyMesh/blockMeshDict", where it shows how to code the desired text on-the-fly... but I don't know its limitations.
All I know is that OpenFOAM 2.0 keeps blowing my mind... this "#codeStream" business seems pretty powerful!


Best regards,
Bruno

Hisham October 17, 2011 19:49

Dear all,

Thanks a lot for the rich info.

I would like to do something similar. I guess from what I've read, and for my case, I will base a point (motionSolver) BC on the timeVaryingUniformFixedValue. Apart from that comes my ignorance-rich question:

In both fvPatch and pointPatch, what is the difference between a fixedValue and a uniformFixedValue BC?

Best regards
Hisham

Goutam March 20, 2012 10:38

Dear Hisham

How can I write the codedFixedValue boundary condition for

U(x) = 2 U_0 (1 - x^2 / r^2 ) where U_0 and r are known.

Thanks

Hisham March 20, 2012 11:39

Quote:

Originally Posted by Goutam (Post 350438)
Dear Hisham

How can I write the codedFixedValue boundary condition for

U(x) = 2 U_0 (1 - x^2 / r^2 ) where U_0 and r are known.

Thanks

I guess you should use the groovyBC .... There are many posts about it and a nice Wiki

Nevertheless, it should go something like:

Code:

inlet
{
    type            codedFixedValue;
    value          $internalField;
    redirectType    ramp;
    code
    #{
      scalar U_0 = 5, r = 10; // Values you need
  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 would appreciate it if anyone can confirm/edit :rolleyes: this code

Goutam March 20, 2012 13:06

Dear Hisham,

Thanks for your quick reply. I am using of-2.1.0. Is it possible to use groovyBC in this version? I have checked this but i am confused.

I will try to implement your suggession about the codedFixedValue.

Thanks for your help.

gschaider March 20, 2012 13:17

Quote:

Originally Posted by Goutam (Post 350481)
Dear Hisham,

Thanks for your quick reply. I am using of-2.1.0. Is it possible to use groovyBC in this version? I have checked this but i am confused.

I will try to implement your suggession about the codedFixedValue.

Thanks for your help.

Not the "standalone/oldSchool" groovyBC but the groovyBC that comes with swak4Foam (the 2.x-variant): http://openfoamwiki.net/index.php/Co...am#Downloading


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