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

interesting assignment operator "==" and "="

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

Like Tree1Likes
  • 1 Post By bieshuxuhe

Reply
 
LinkBack Thread Tools Display Modes
Old   April 15, 2014, 00:13
Post interesting assignment operator "==" and "="
  #1
Member
 
xuhe-openfoam
Join Date: Aug 2013
Location: DaLian,china
Posts: 82
Rep Power: 6
bieshuxuhe is on a distinguished road
hi!
look down the piece of code of "pEqn.H" in interFoam (openfoam 2.2.0):
Code:
00049     #include "continuityErrs.H"
00050 
00051     p == p_rgh + rho*gh;
00052 
00053     if (p_rgh.needReference())
00054     {
00055         p += dimensionedScalar
00056         (
00057             "p",
00058             p.dimensions(),
00059             pRefValue - getRefCellValue(p, pRefCell)
00060         );
00061         p_rgh = p - rho*gh;
00062     }
00063 }
the red code "p == p_rgh + rho*gh;" use the operator "==" , and the green code "p_rgh = p - rho*gh;" use the operator "=" !
Then I look up the source guide .
I could only understand from the source guide that the difference between "=" and "==" is that:
operator "=" will check first to make sure the variable couldn't be assigned to itself , while "==" won't check that ! ;
I wonder is there any other difference between "==" and "=" ?

could you help me ?
thanks!
bieshuxuhe is offline   Reply With Quote

Old   April 15, 2014, 10:02
Default
  #2
Senior Member
 
kmooney's Avatar
 
Kyle Mooney
Join Date: Jul 2009
Location: Amherst, MA USA - San Diego, CA USA
Posts: 321
Rep Power: 11
kmooney is on a distinguished road
I "think" that the == will force an overwrite of the current boundary values even if they are set to a non-Dirichlet type. This is done in addition to altering the internalField values. I recall seeing a discussion on this somewhere in this forum but I can't seem to find it.

I might be wrong about this so don't hold me accountable!
kmooney is offline   Reply With Quote

Old   April 15, 2014, 10:34
Default
  #3
Member
 
xuhe-openfoam
Join Date: Aug 2013
Location: DaLian,china
Posts: 82
Rep Power: 6
bieshuxuhe is on a distinguished road
thanks for your reply!
bieshuxuhe is offline   Reply With Quote

Old   April 15, 2014, 11:14
Smile
  #4
Member
 
xuhe-openfoam
Join Date: Aug 2013
Location: DaLian,china
Posts: 82
Rep Power: 6
bieshuxuhe is on a distinguished road
it is there:
HTML Code:
http://www.cfd-online.com/Forums/openfoam-programming-development/85013-operator.html
Nope: operator== will FORCE assignment, even if patch field type says it should not be so. For example for a fixedValue patch, operator== will change its value and operator= will do nothing.

Hrv
__________________
Hrvoje Jasak
hua1015 likes this.
bieshuxuhe is offline   Reply With Quote

Reply

Tags
assignment operator

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



All times are GMT -4. The time now is 07:52.