CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Difference between operator= and operator== (https://www.cfd-online.com/Forums/openfoam-programming-development/246453-difference-between-operator-operator.html)

peyman.havaej December 5, 2022 05:45

Difference between operator= and operator==
 
Dear all,

I have developed a boundary condition, which is very similar to the movingWallVelocity in foam extend.

In this code, the velocity of the wall is updated according to a rigid body motion. Hence, it is a time-dependent condition.

I tried two different ways to update the boundary values:

1-
Code:

vectorField::operator=(Up + n*(Un - (n & Up)) + UNew);
In the case of using the '=' sign, the boundary values in time solution folders are updated, while the solver converges slowly.

2-
Code:

vectorField::operator==(Up + n*(Un - (n & Up)) + UNew);
In the case of using the '==' sign, the boundary values in time solution folders are not updated, while the solver converges much faster.

Here, UNew is between 0-0.1 and it is varying by time.

There is a big difference between the transient simulations of these cases, and I don't know which one is correct.

According to this discussion, I know that:
Quote:

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
However, I am not sure which operator should be used in my simulation. Also, what is the cause of different numerical results when force assignment is used?

Any comments or further explanations would be appreciated.

Kind regards,
Peyman

hjasak December 28, 2022 21:51

On a vector field there is no difference - you are looking at the wrong place. For fvPatchField, a double - will force assignment for all types and single - will behave differently depending on type.

For example, on a fixedValue patch, op= does nothing and op== will force the new value onto a patch even though its type is Dec;armed as fixedValue. This is very important for the code to work correctly. However, your problem is somewhere else.

Hrv


All times are GMT -4. The time now is 09:48.