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/)
-   -   Problem in the calculation of function (https://www.cfd-online.com/Forums/openfoam-solving/64679-problem-calculation-function.html)

titio May 19, 2009 14:43

Problem in the calculation of function
 
Hi all,

I have a problem where I have to calculate the value of a scalar function func, in the form

func=1+A*tr(tensor1)

where A is a scalar constant, tensor is a volume tensorial field, and func is scalar field.

In the createFields.h file I included the following line

volScalarField trac_tensor
(
IOobject
(
"trac_tensor",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
tr(tensor)
);

volScalarField func
(
IOobject
(
"func",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
1.0 + A*trac_tensor
);

I have considered that the trace of tensor generates a scalar field. Although it compiles fine and the code runs, when I check the values given by func_lin, I noted that it is always returning one. The value of A is defined and the components of the tensor change, but, func_lin never changes.

Am i doing something wrong? How I should do the calculation of func?

Antonio Martins

psosnows May 20, 2009 09:18

the code looks fine

one question though- are you updating the values during the simulation?

the createFields.h is called once at the beginning of the simulation before the main loop. It initiates the values, sets them for automatic reading/writing but does not set any automatic refreshment of the values.

maybe if you put something like:
Code:

trac_tensor=tr(tensor);
func=1.0 + A*trac_tensor;

inside the main loop you will get your results

otherwise it will be always only the ones which were initiated :)

Pawel


All times are GMT -4. The time now is 17:36.