CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM (http://www.cfd-online.com/Forums/openfoam/)
-   -   Instruction if (http://www.cfd-online.com/Forums/openfoam/100599-instruction-if.html)

bluemind April 27, 2012 06:48

Instruction if
 
Hello,

I'm a student and new user of OpenFOAM, I am currently trying to modify the solver twoLiquidMixingFoam by adding the energy equation. Since I haven't use C++ so far, I'm having some trouble when I use the instruction if, for example in my case I just want to implement these simple lines :

if ( alpha1 == 0 ) // l : 34
{

...

}
I have the following error :

energyEqn.H:34: error: could not convert ‘alpha1.Foam::GeometricField<Type, PatchField, GeoMesh>::operator== [with Type = double, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh](((const Foam::dimensioned<double>&)(& Foam::dimensioned<double>(((const double&)((const double*)(&0.0)))))))’ to ‘bool’

Since alpha1 is an object, I don't think this is the appropriated way to do this. Is it possible to have some help ?

Thanks,

bluemind April 27, 2012 08:07

I found the command :

forAll( alpha1,celli){
if ( alpha1[celli] < 1.e-5 )
{
...

}
}

Bernhard April 29, 2012 04:25

Hi Nabil,

Welcome to CFD-online!

The method you found should work fine, but it really depends on what you want to obtain. If you can explain a bit more on what you want exactly, there may be a nicer way.

marupio April 29, 2012 13:28

Seconded. What you've got now is an indexed for loop over all elements in the mesh. These types of loops should be avoided whenever possible as they can be 10x slower than OpenFOAM's built-in field operations, which use optimised pointer loops.


All times are GMT -4. The time now is 04:58.