CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Running, Solving & CFD (
-   -   User defined bc (

anja March 29, 2006 08:28

Hi, I've written an applica

I've written an application ("vprofil") which defines a 3D velocity profile for an inlet patch (or at least I hope it will turn out like that).

The application is situated in: ~OpenFOAM/Anja-1.2/applications/vprofil

I've also created a new case in FoamX and have already choosen the solver I want to use.

Afterwards I've typed:
vprofil <root> <case>

But the error message is:
vprofil cannot open root directory

Can someone please help me?

gschaider March 29, 2006 10:30

What where your concrete value
What where your concrete values for root and case. I mean: do they exist? (usually root is ".": that should exist)
I would guess that the problem is a typo with the root-directory.

anja March 30, 2006 05:30

Hi, and now the error meass

and now the error meassage is:
keyword inlet is undefined in dictionary ..../run/test/sbogen1/0/U::boundaryField

But I thought this would be done automatically with my application for the velocity profil??

gschaider March 30, 2006 07:01

What this means is: your appli
What this means is: your application is trying to access a patch named "inlet" but in mesh there is no such patch. Check the file sbogen1/0/U and the files sbogen1/constant/polyMesh/boundary

My guess (but I can't tell without looking at the code) is that in your application the patch name "inlet" is hardcoded while in the mesh the patch that should be the inlet has another name ("einlasz" ?)

anja March 30, 2006 07:12

The problem is more, that I do
The problem is more, that I don't what to write in /0/U to define a velocity for the inlet, because I want it to come from the application.

If I just fill out something in /0/U like:
{ type fixedValue;
value uniform (0 0 0); }

I can reach a next problem:
FOAM FATAL ERROR : LHS and RHS of - have different dimensions
dimensions : [0 1 0 0 0 0 0] - [0 0 0 0 0 0 0]

gschaider March 30, 2006 09:06

OK. I assume that the 0/U file
OK. I assume that the 0/U file wasn't in tune with the boundary file.

The second problem is (I'm extrapolating this from the C()-discussion in another thread) that somewhere in the program you try to subract from a value with the dimension [m] a value with dimension [1]. Propably this happens during the calculation involving the face/cell-Centers (which have dimension [m]) and a scalar (which is I think converted to a dimensioned scalar [1]).

Try using the .value()-method for the dimensioned value (or give the non-dimensioned value a dimension)

anja March 30, 2006 12:01

Hi again, but I still have
Hi again,

but I still have the first mentioned problem. What do I have to do so that the application for my velocity profil is taken into acount?

Thanks Bernhard, you really help me alot!

gschaider March 30, 2006 19:26

Short answer: if your utility
Short answer: if your utility changes the velocity profile in the initial time step and the boundary condition is "fixed value", then you're in business.

Your vproile-application sets a value for every face in inlet (I hope). So instead of something like "uniform (0,0,1)" there is a whole list of values in the 0/U file (for the inlet). The solver starts with these values, and because it is a fixedValue-BC doesn't see no reason to change these values (and should therefor happily keep calculating with your profile).

ziemowitzima March 31, 2006 07:00

Hello All! I want to set up t
Hello All!
I want to set up transient boundary conditions which values are calculated and based on the solution (velocities field) from previous time step. Is the "calculated" bc type a good choice and how exactly use it?
Thank you for any information!

anja March 31, 2006 07:02

But the utility does not chang
But the utility does not change the velocity in the initial time step it seems.

I do have:
the application "vprofil"
started a new case in FoamX
already choosen the solver "simpleFoam" for that

But how can I actually use my utility??
With that: vprofil <profil><case> [-parallel]
it says this is one command too much??

gschaider March 31, 2006 07:14

Anja: a) Which time-step doe
a) Which time-step does the utility say it is reading?
b) if it is the initial time-step, are you actually writing the modified velocity field?
c) if you are writing: there is still the possibilty of a bug in your calculation (I can't help you with that, but "Info <<" for outputing intermediate results is your friend)

anja March 31, 2006 07:22

What I'm doing is: vprofil
What I'm doing is: vprofil <root> case

but then it says:
keyword inlet is undefined in dictionary ..../0/U::boundary field
(but this I do not want to fill out, because this should be the velocity profil coming from the application "vprofil", the whole list of values you were talking about)

gschaider March 31, 2006 09:54

You'll have too, because OpenF
You'll have too, because OpenFOAM needs that information to create the field (but fixedValue/uniform is sufficient) to make it possible to manipulate it. After your utility ran it will be something fixedValue/non-uniform.

anja March 31, 2006 11:06

Thanks, very nice to know.
Thanks, very nice to know.

But now about the dimension problem. I've tried to change my velocity profile, and can't compile it any more.
Could you please check the source code??

Here it is:
#include "fvCFD.H"
#include "incompressible/singlePhaseTransportModel/singlePhaseTransportModel.H"
#include "incompressible/turbulenceModel/turbulenceModel.H"

int main(int argc, char *argv[])
# include "setRootCase.H"
# include "createTime.H"
# include "createMesh.H"
# include "createFields.H"
# include "initContinuityErrs.H"

Info<< "\nStarting time loop\n" << endl;

// Change bc:

// Get index of patch
label inletPatchID = mesh.boundaryMesh().findPatchID("inlet");
// Get reference to boundary field value
fvPatchVectorField& inletu = U.boundaryField()[inletPatchID];
// get coordinate for cell centres
const fvPatchVectorField& centre = mesh.C().boundaryField()[inletPatchID];

scalarField x = centre.component(vector::X);
scalarField y = centre.component(vector::Y);
scalarField z = centre.component(vector::Z);

scalar n_1 = 0.159159;
scalar n_2 = -0.030791;

dimensionedScalar a
dimensionSet(0, -1, -1, 0, 0, 0, 0),

dimensionedScalar s
dimensionSet(0, 1, -1, 0, 0, 0, 0),

vector Cp = vector::zero;

dimensionedScalar d
dimensionSet(0, 1, 0, 0, 0, 0, 0),
scalarField(mag(mesh.C() - Cp)),

scalarField Ux = sqrt((s-d*d*a)*(s-d*d*a)/(n_1*n_1 + n_2*n_2))* n_1;
scalarField Uy = sqrt((s-d*d*a)*(s-d*d*a)/(n_1*n_1 + n_2*n_2))* n_2;
scalar Uz = 0.0;

inletu = vector(Ux, Uy, Uz);


Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s\n\n" << endl;

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


and here are the error messages:

(concerning last line of each dimensionSet)
error: expected primary-expression before ')' token

(concerning line for Ux)
error: conversion from 'Foam::dimensionedScalar' to non-scalar type 'Foam::Field<foam::scalar>' requested

(concerning line inletu= )
error: no matching function for call to 'Foam::Vector<foam::scalar>::Vector(Foam::scalarFi eld&, Foam::scalarField&, Foam::scalar&)'

Bernhard, I hope you keep answering

Thanks alot

gschaider April 3, 2006 08:26

- first error message: think a
- first error message: think about the third ',' and whether it is necessary?

- second error: I'm amazed it didn't fail at the construction of d (using a field to construct a scalar)

- third error: I wouldn't do it like this, but by doing
scalarField &Ux=inletu.component(0);
Ux= .... ;
(but I'm not sure whether this works (references to component ..). Usually I do these calculations for every face separatly: Drop me a mail and I'll send you a copy of an old program of mine that does something similar)

anja April 5, 2006 07:07

Hi, okay, I've channged my

okay, I've channged my application so far that I can compile it.
And also the command: vprofil <root> <case> does not bring an error message.
"vprofil" is in the folder ...OpenFOAM/Anja-1.2/applications/vprofil and the calculation is in...OpenFOAM/Anja-1.2/run/test

But still the values in .../0/U were not changed!
How come??


mayank June 21, 2007 10:00

hello, I am trying to write

I am trying to write a code for inlet radial velocity for multiple inlets on the face of cylinder.
when i use the following command to write to file:
inletu[facei] = vector(0,vely,velz);

i get the following error:
vprofile.C: In function 'int main(int, char**)':
vprofile.C:136: error: no matching function for call to 'Foam::Vector<double>::Vector(int, Foam::dimensionedScalar&, Foam::dimensionedScalar&)'
/home/mgo/OpenFOAM/OpenFOAM-1.4/src/OpenFOAM/lnInclude/VectorI.H:60: note: candidates are: Foam::Vector<cmpt>::Vector(Foam::Istream&) [with Cmpt = double]
/home/mgo/OpenFOAM/OpenFOAM-1.4/src/OpenFOAM/lnInclude/VectorI.H:50: note: Foam::Vector<cmpt>::Vector(const Cmpt&, const Cmpt&, const Cmpt&) [with Cmpt = double]
/home/mgo/OpenFOAM/OpenFOAM-1.4/src/OpenFOAM/lnInclude/VectorI.H:42: note: Foam::Vector<cmpt>::Vector(const Foam::VectorSpace<foam::vector<cmpt>, Cmpt, 3>&) [with Cmpt = double]
/home/mgo/OpenFOAM/OpenFOAM-1.4/src/OpenFOAM/lnInclude/VectorI.H:36: note: Foam::Vector<cmpt>::Vector() [with Cmpt = double]
/home/mgo/OpenFOAM/OpenFOAM-1.4/src/OpenFOAM/lnInclude/Vector.H:62: note: Foam::Vector<double>::Vector(const Foam::Vector<double>&)
make: *** [Make/linux64Gcc4DPOpt/vprofile.o] Error 1

The solution proposed by Bernhard also doesnt work as i'm using dimensionedscalar to define Ux and Uy .This is necessary for using cos and sin functions on velocity.

How to write the components of U to the file. But when i only print the components output is visible.
I need some urgent help.


rafal June 21, 2007 12:34

try inletu = vector(0,
inletu[facei] = vector(0,vely.value(),velz.value());
hope that helps,

mayank June 22, 2007 05:32

hello rafal, thanks for you
hello rafal,

thanks for your worked but i still have one more query. Values of vely,velz seem to be correct when i print the values . But i am not able to write these values to the file 0/U on the desired inlet patch. I tried U.write() after including <fstream> but it just clears out the mesh and i again have to set all the initial values in FoamX.


mayank June 22, 2007 07:31

hello all, i got the soluti
hello all,

i got the solution.basically i was placing U.write() in the wrong place.It has to be written after all the loops.


All times are GMT -4. The time now is 10:31.