CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

conditional operator in source term

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 2, 2018, 03:52
Default conditional operator in source term
  #1
New Member
 
Join Date: Aug 2018
Posts: 18
Rep Power: 8
nago is on a distinguished road
Hi,all

I use OF2.3.1, coding wall condensation model of H2O gas, in rhoReactingBuoyantFoam.
In YEqn.H, I add Mass source term in YiEqnMatrix.
But compile does'nt pass.
I intend to reduce H2O Mass from near wall cell, not considering water liquid phase.

In Yeqn.H, judgeing species H2O or Others, decide mass source term field value "Mass_source" or Zero value.
but zero value does not recieved.

"Mass_source" is volScalarField.

<< Yeqn.H source Code >>
fvScalarMatrix YiEqn
(
fvm::ddt(rho, Yi)
+ mvConvection->fvmDiv(phi, Yi)
- fvm::laplacian(turbulence->muEff(), Yi)
==
reaction->R(Yi)
+ fvOptions(rho, Yi)
+ (Yi.name() == "H2O" ? Mass_source :0.0 )
);

<< Compile Error >>
YEqn.H:32:48: error: no match for ternary ‘operator?:’ (operand types are ‘bool’, ‘Foam::volScalarField {aka Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>}’, and ‘double’)
+ (Yi.name() == "H2O" ? Mass_sou :0.0 )


So I'm programing beginner, I don't know what I shoud do.
Can anyone help me?

best regard.

(sorry for bad english ...)
nago is offline   Reply With Quote

Old   August 7, 2018, 21:53
Default
  #2
Senior Member
 
shinji nakagawa
Join Date: Mar 2009
Location: Japan
Posts: 113
Blog Entries: 1
Rep Power: 18
snak is on a distinguished road
Hi,


"Mass_source" is volScalarField, but 0.0 is just a double.

The operator "?" needs two values with the same type (or implicit type conversion exists).


OpenFOAM have zero class. I'm not sure it works here or not.


Defining volScalarField with zero value or using if statement before the creation of fvScalarMatrix YiEqn may work, i guess...
It may not be elegant code...
snak is offline   Reply With Quote

Old   August 8, 2018, 02:45
Default
  #3
New Member
 
Join Date: Aug 2018
Posts: 18
Rep Power: 8
nago is on a distinguished road
Hello,snak.

Thank you for reply.

I thought there was a simpler way, but I know there wasn't.
it was nice to know that.
So I write if statement before YiEqn, and it works.

OF is so complex...

nago
nago is offline   Reply With Quote

Old   May 30, 2019, 02:13
Exclamation
  #4
Member
 
Vivek
Join Date: Mar 2018
Location: India
Posts: 54
Rep Power: 8
vivek05 is on a distinguished road
Quote:
Originally Posted by nago View Post
Hello,snak.

Thank you for reply.

I thought there was a simpler way, but I know there wasn't.
it was nice to know that.
So I write if statement before YiEqn, and it works.

OF is so complex...

nago
Hi,
I am also getting the same error when using the ternary operator. Can you share us how did you implement if statement before fvSclarMatrix to achieve mass_source condition

Thanks,
Vivek S
vivek05 is offline   Reply With Quote

Reply

Tags
openfoam 2.3.1


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 Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Source Term due to evaporation in energy transport equation styleworker OpenFOAM Programming & Development 3 September 7, 2022 04:09
[OpenFOAM.org] Patches to compile OpenFOAM 2.2 on Mac OS X gschaider OpenFOAM Installation 136 October 10, 2017 18:25
polynomial BC srv537 OpenFOAM Pre-Processing 4 December 3, 2016 10:07
"parabolicVelocity" in OpenFoam 2.1.0 ? sawyer86 OpenFOAM Running, Solving & CFD 21 February 7, 2012 12:44
DxFoam reader update hjasak OpenFOAM Post-Processing 69 April 24, 2008 02:24


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