|
[Sponsors] |
February 22, 2016, 05:35 |
Difference between = and ==
|
#1 |
Senior Member
Manu Chakkingal
Join Date: Feb 2016
Location: Delft, Netherlands
Posts: 129
Rep Power: 10 |
Hello
I came across the usage of = and ==. Does = implies at calculating and assigning value of RHS to the LHS == (initially assumed to be equality check operator), but found in cases where equations are solved and assigned similar to = What is the exact difference /w the two and where it should be used in specific |
|
February 22, 2016, 12:27 |
|
#2 |
Senior Member
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 22 |
C++ allows operator overloading, which means that these operators could mean anything. A good design would be to keep it logical and consistent.
In OpenFOAM, we can use mathematical operators on GeometricFields, such as the velocity field. It makes sense that = means assignment, but OpenFOAM is very clever, and will apply the correct meaning to each of the boundary conditions on the field. In the case of fixedValue, OpenFOAM will assume that you are doing routine physics calculations on your field... in these cases, we don't want to overwrite the fixedValue assigned at the start. So, U = A + B would do nothing to any of U's fixed value boundary conditions. But there are situations where you do want to override the fixedValue. For instance, some boundary conditions use fixedValue as a base, but calculate a new value at every timestep. They need to override the value. The design decision that was made is to use operator== for that. Kind of like a 'super assignment'. So for field variables, and the associated math, == is not a test... it is assignment. In general, use operator= unless you are really certain you need to override any of the fixedValue.
__________________
~~~ Follow me on twitter @DavidGaden |
|
February 23, 2016, 06:57 |
|
#3 | |
Senior Member
Manu Chakkingal
Join Date: Feb 2016
Location: Delft, Netherlands
Posts: 129
Rep Power: 10 |
Quote:
In short == is a forceful assignment at boundaries..while = leaves out the boundaries during assignment |
||
October 11, 2017, 11:07 |
|
#4 | |
Member
sibo
Join Date: Oct 2016
Location: Chicago
Posts: 55
Rep Power: 10 |
Quote:
Thanks for your detailed explanation. I want to create a dynamic mesh solver and the situation in my case is exactly the same as you mentioned. I want to use fixedValue as a base for the wall's boundary condition and then give it a calculated displacement value to make it move every time step. Therefore, I use this "==" operator. want to assign the calculated "dispVals" to "PointDisplacement". Code:
PointDisplacement.boundaryField()[patchID] == dispVals; Code:
error: no match for ‘operator==’ (operand types are ‘const Foam::pointPatchField<Foam::Vector<double> >’ and ‘Foam::vectorField {aka Foam::Field<Foam::Vector<double> >}’) PointDisplacement.boundaryField()[patchID] == dispVals; ^ Any suggestion would be greatly appreciated! Thanks! |
||
January 18, 2018, 11:46 |
|
#5 | |
Member
Lennart
Join Date: Feb 2016
Posts: 46
Rep Power: 10 |
Quote:
Code:
PointDisplacement.boundaryFieldRef()[patchID] == dispVals; |
||
|
|