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/)
-   -   fvPatchField<Type>::operator== (https://www.cfd-online.com/Forums/openfoam-programming-development/228830-fvpatchfield-type-operator.html)

Gerry Kan July 16, 2020 10:02

fvPatchField<Type>::operator==
 
Howdy Foamers:

Browsing through the uniformFixedValue fvPatchField implementation there is a call to an operator like this in the member function updateCoeffs():

Code:

fvPatchField<Type>::operator == ( uniformValue_->value(t) );
Digging into fvPatchField.C, the function is implemented as follows:

Code:

template<class Type>
void Foam::fvPatchField<Type>::operator ==  ( const Type& t )  {
    Field<Type>::operator = (t);
}

I am familiar with operator overloading C++, but I have never seen operators to be called like this before. I could guess that the == ends up being some kind of assignment. It would be great if someone could provide a more accurate description of what both lines do.

Thanks in advance, Gerry.

Gerry Kan July 17, 2020 05:57

Howdy Foamers:

I think it is simply used as an assignment, and based on this OpenFOAM will somehow update the solver coefficients. I didn't dig so deep to see if this is the case but my results seems to tell me something is happening in the right direction.

Gerry.

hjasak July 17, 2020 13:28

Hi,

We use operator== to indicate forced assignment, in contrast with normal assignment of an fvPatchField.

Normal assignment is a virtual overload depending on type, where for example it does nothing for a fixedValue derives class.

What the code says is “when forcing assignment, use the op= of the base class for the Field. This is not a virtual hierarchy and it will do the actual assignment job.

Hope this helps,

Hrv

Gerry Kan July 20, 2020 02:38

Dear Professor Jasak:

Thank you very much for taking your time to explain this. In the end I went (just a little) deeper to the definition of the overloaded Field assignment operator and it confirmed your comments and my observation.

In the end I would like to use this to assign a Field to the fvPatchField using this variant of the forced assignment operator, that is:

Code:

void Foam::fvPatchField<Type>::operator == ( const Field<Type>& tf )
instead of:

Code:

void Foam::fvPatchField<Type>::operator == ( const Type& t )
I am still in the process of trying to get it to work, as I am still having some problems with referencing my incoming Field. However I think your input has made this much more clear and I believe I know how to proceed.

Thank you again, Gerry.


All times are GMT -4. The time now is 19:11.