CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Post-Processing (https://www.cfd-online.com/Forums/openfoam-post-processing/)
-   -   FoamCalc writing a new function wakeField (https://www.cfd-online.com/Forums/openfoam-post-processing/61339-foamcalc-writing-new-function-wakefield.html)

markc December 15, 2008 08:27

Dear All, I am in need of s
 
Dear All,

I am in need of some help regarding writing a new add on for foamCalc, called "wakeField". The function is to perform a very simple calculation:

wakeField = 1 - Ux / U(farfield).

I used the folder "components" as a starting point and modified step by step until I ran into problems.

I was able to perform : wakeField = Ux / U(farfield). However, next is that I do 1- Ux/U(farfield) by adding the following in the writeWakeField.C:
>>>
scalar(1) - (field.component(i) / scalar(5))
<<<

wmake libso works well but running the utility (foamCalc wakeField U) gives the next error:
>>>
LHS and RHS of - have different dimensions
dimensions : [0 0 0 0 0 0 0] - [0 1 -1 0 0 0 0]
<<<
Well, this is a very clear error message: the "1" has no dimensions while a U field has. But I do not know how to solve this problem.

Furthermore: so far I assumed for simplicity that my farfield velocity is 5. However this should be read from the time directory/U file under the head belonging to the inlet patch.
So as extra input I would ask the user for "inletPatchName". The utility should search in this inlet patch for the correct U value. How to program this?

I hope I made myself clear enough and anyone is able to comment,

Brgds,

Mark

silva December 15, 2008 09:06

Hi Mark, You should use a d
 
Hi Mark,

You should use a dimensioned variable to define U(farfield) (after all, it has velocity units, right?). Then, the Ux/U(farfield) division will be dimensionless as the subtracting operation.

At this time, define it in your code as:

dimensionedScalar Ufarfield
(
"Ufarfield", // the name
[0 1 -1 0 0 0 0], // its dimensions (L / T)
5.0 // the value
);

I suppose you will have to change or create a code for the boundary condition if you want to read Ufarfield from the 'time/U' file. If not, probably, there is an easy way to read this variable, but I don't know it (and it would take some time for me to dig it out). Let's see if someone out there knows it better.

On the other hand, if 'Ufarfield' is a variable that does not change in time, you could store it in a file in the constant directory...

Hope it helped,
Luiz F.

markc December 15, 2008 10:25

Hi Luiz, Thanks for your ef
 
Hi Luiz,

Thanks for your effort. Unfortunately it did not work for me, I probably have not enough knowledge about C++ qualifiers etc. However your comments brought me a step further again.
And yes, you're right: the value 5 shall be read from the time directory.
I should incorporate something like:
>>>
surfaceScalarField Ufarfield
(
IOobject
(
"Ufarfield",
mesh.time().timeName(),
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
),
dimensionedscalar("Ufarfield", [0 1 -1 0 0 0 0], 5.0)
);
<<<
in the main .C file (wakeField.C). But so far I did not succeed. I have to tell the utility that has to read the value from the entry:
>>>
Inlet
{
type pressureInletVelocity;
value uniform (5 0 0);
}
<<<

Any help would be greatly appreciated.

Brgds,

Mark

cedric_duprat December 16, 2008 07:12

Hi Mark, Maybe you can hav
 
Hi Mark,

Maybe you can have a look at the channelOodles solver (solvers/DNSandLES/channelOodles).
In this solver at each time step a scalar (gradP) is written in runTime.path()/runTime.timeName()/

And when you start your calculation, the solver read this file.

So you can adapt it to your case, write it every time step and read it not only when you start the calculation but at each time step.

I hope I've got well understand your problem and that it will help


Cedric

markc December 16, 2008 08:57

Cedric, All little pieces h
 
Cedric,

All little pieces help, thanks for your advice. However, channelOodles reads a datafile (gradP.raw), which works a little different from reading a BC file.
Well, for the experienced C programmers here it will surely be something simple, but I get stuck here.

Thanks anyway,

Mark

markc December 24, 2008 04:09

Hello All, The utility is f
 
Hello All,

The utility is finished. I made a simple stand-alone though, so it is not available via foamCalc.
For reference the files are attached here:

http://www.cfd-online.com/OpenFOAM_D...s/mime_zip.gif wakeField.zip

Thanks for the assistance,

Mark


All times are GMT -4. The time now is 03:46.