CFD Online Logo CFD Online URL
Home > Forums > Software User Forums > OpenFOAM

Instruction if

Register Blogs Members List Search Today's Posts Mark Forums Read

LinkBack Thread Tools Display Modes
Old   April 27, 2012, 06:48
Default Instruction if
New Member
Nabil MEAH
Join Date: Apr 2012
Posts: 8
Rep Power: 7
bluemind is on a distinguished road

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>:perator== [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 ?

bluemind is offline   Reply With Quote

Old   April 27, 2012, 08:07
New Member
Nabil MEAH
Join Date: Apr 2012
Posts: 8
Rep Power: 7
bluemind is on a distinguished road
I found the command :

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

bluemind is offline   Reply With Quote

Old   April 29, 2012, 04:25
Senior Member
Join Date: Sep 2009
Location: Delft
Posts: 790
Rep Power: 15
Bernhard is on a distinguished road
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.
Bernhard is offline   Reply With Quote

Old   April 29, 2012, 13:28
Senior Member
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 15
marupio is on a distinguished road
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.
Follow me on twitter @DavidGaden
marupio is offline   Reply With Quote

Old   June 14, 2016, 14:14
Exclamation Problem with if Loop in interFoam
New Member
Join Date: Jan 2016
Posts: 25
Rep Power: 4
block is on a distinguished road
Hi guys i am trying to implement a if loop in one of the libraries of interFoam where a variable called "kappaf" is depend on the alpha1f value, where i want to impose a condition where kappaf is alpha1f * DI for alpha1f >0.5 or zero if alphaf < 0.5.

I have written the loop


I am getting this error


I am new to openfoam and C++ coding so not familiar with how to write this.

Kind Regards

block is offline   Reply With Quote



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Instalation on ubuntu 710 basilwatson OpenFOAM Installation 17 March 16, 2012 21:16
Pls help last problem to be solved for installing OPENfoam daydayuper OpenFOAM Installation 5 November 9, 2008 05:59
Who help to give a instruction how to install paraFoam correctly liugx212 OpenFOAM Paraview & paraFoam 0 April 17, 2006 15:32
64-bit processors for home computing Ananda Himansu Main CFD Forum 2 March 16, 2004 13:48
Web-based CFD/HT instruction Graham de Vahl Davis Main CFD Forum 0 April 2, 1999 16:49

All times are GMT -4. The time now is 18:35.