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

interesting assignment operator "==" and "="

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 2 Post By bieshuxuhe

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 15, 2014, 01:13
Post interesting assignment operator "==" and "="
  #1
Member
 
xuhe-openfoam
Join Date: Aug 2013
Location: DaLian,china
Posts: 82
Rep Power: 13
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, 11:02
Default
  #2
Senior Member
 
kmooney's Avatar
 
Kyle Mooney
Join Date: Jul 2009
Location: San Francisco, CA USA
Posts: 323
Rep Power: 18
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, 11:34
Default
  #3
Member
 
xuhe-openfoam
Join Date: Aug 2013
Location: DaLian,china
Posts: 82
Rep Power: 13
bieshuxuhe is on a distinguished road
thanks for your reply!
bieshuxuhe is offline   Reply With Quote

Old   April 15, 2014, 12:14
Smile
  #4
Member
 
xuhe-openfoam
Join Date: Aug 2013
Location: DaLian,china
Posts: 82
Rep Power: 13
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 and serles like this.
bieshuxuhe is offline   Reply With Quote

Reply

Tags
assignment operator


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



All times are GMT -4. The time now is 06:31.