CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Pre-Processing (http://www.cfd-online.com/Forums/openfoam-pre-processing/)
-   -   ScalarField division (http://www.cfd-online.com/Forums/openfoam-pre-processing/62115-scalarfield-division.html)

maka August 26, 2007 17:57

I do the following operation b
 
I do the following operation but it gives wrong result (1.22005e-312):

const scalarField& ry = patch().deltaCoeffs();
// magnitude of patch-normal distance from face to cell centers:
const scalarField& yn= 1.0/ry;

but if I make a loop and use:

const scalarField& yn= 1.0/ry[facei];

it gives correct result. How can I do mathematical operations that contain scalarFields and scalars without looping? Thanks.

Best regards,
Maka

hjasak August 26, 2007 18:16

Classic mistake: reference to
 
Classic mistake: reference to a temporary: if you do:

scalarField yn= 1.0/ry;

all will be well. Operation 1/ry will return a COPY, i.e. a new field. You took a reference to it, which is a memory error - that's the little & bit after the scalarField.

I bet you already know this - if not, time for a careful look at a good C++ book.

Got it?

Hrv

maka August 27, 2007 05:10

Thanks Hrv for the explanation
 
Thanks Hrv for the explanation.
Best regards,
Maka.


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