== operator
Hi foamers,
I know the "==" operator as an equality operator in C, i.e. (a==b) suppose to return true or false. But then I can't understand following lines of interFoam: Code:
rho == alpha1*rho1 + (scalar(1) - alpha1)*rho2; Code:
solve Code:
rho = alpha1*rho1 + (scalar(1) - alpha1)*rho2; Best regards, Ilya |
I think...
= only does stuff to the internalField() == does stuff to the internalField() AND the boundaryField() |
And how OF knows, if it has to use the C/C++ standard boolean or the OF-redefined "==" operator?
|
Hi, '=' is the usual operator used to replace the content of LHS with RHS. '==' is overloaded in fvMatrix class in order to write equations. It's only dividing sides.
Regards. |
Even in this case: rho == alpha1*rho1 + (scalar(1) - alpha1)*rho2; ?
I thought in this line the volScalar rho is being computed, but if I understand you correctly an equation for rho is being defined? :eek: regards, Ilya |
No Ilya, in your example it is an assignment just like Laurence already stated further up. Santiago was explaining the case when having an "==" within a solve().
|
Illya, from what source file did you take this line?:
Code:
rho = alpha1*rho1 + (scalar(1) - alpha1)*rho2; |
Quote:
Quote:
|
Aha, it's true I never paid attention in this particular '==' operator. Checking GeometricField.C, operator== and operator= copies both internal and boundary fields. The difference seems to be in another characteristic, operator= uses transfer method and operator== does not. But I don't realize the necessity of this operator in this case.
Regards. |
Quote:
Regards. |
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 |
Aha, that explains the part I couldn't understand at all (GeometricField.C:01103):
Code:
01090 template<class Type, template<class> class PatchField, class GeoMesh> Code:
00437 // Force an assignment, overriding fixedValue status Regards. P.S. fvPatchField class don't have a 'fixed value flag' to avoid overriding? |
Greetings,
I am developing a timeVaryingMapped BC for tractionDisplacement based on the timeV..M..FixedValue and the tractionDisplacement BCs. In the first (timeV..M..FixedValues) I find that values are assigned by the "==" operator: Quote:
However, in the tractionDisplacement BC, the gradient() is calculated via a "=" operator. I would like to know: 1. What is the meaning of "this->operator==(someField);" for a fixedGradient BC? 2. To assign gradient() for the custom BC I seek, should I use "gradient() == someVectorField;" or "gradient() = someVectorField;" I appreciate your help/answer! Thanks Hisham |
Quote:
operators are like other functions in C++. Although you don't see it, they look like, for example: Code:
left operand == (right operand) From fvMatrix.C: Code:
template<class Type> Since it returns A - B (both coeff matrices), it seems to me that it just makes the entire algebraic system implicit (put B on the left side, or in your case, the field you get by fvc::reconstruct). operator = ... from fvMatrix.C: Code:
template<class Type> There seems to be no difference between rho = something and rho == something If rho is a vol*Field, == will copy both the boundary and the internal field: 01154 template<class Type, template<class> class PatchField, class GeoMesh> 01155 void Foam::GeometricField<Type, PatchField, GeoMesh>::operator== 01156 ( 01157 const tmp<GeometricField<Type, PatchField, GeoMesh> >& tgf 01158 ) 01159 { 01160 const GeometricField<Type, PatchField, GeoMesh>& gf = tgf(); 01161 01162 checkField(*this, gf, "=="); 01163 01164 // only equate field contents not ID 01165 01166 dimensionedInternalField() = gf.dimensionedInternalField(); 01167 boundaryField() == gf.boundaryField(); 01168 01169 tgf.clear(); 01170 } and "=" seems to be doing the same thing: 01082 template<class Type, template<class> class PatchField, class GeoMesh> 01083 void Foam::GeometricField<Type, PatchField, GeoMesh>::operator= 01084 ( 01085 const GeometricField<Type, PatchField, GeoMesh>& gf 01086 ) 01087 { 01088 if (this == &gf) 01089 { 01090 FatalErrorIn 01091 ( 01092 "GeometricField<Type, PatchField, GeoMesh>::operator=" 01093 "(const GeometricField<Type, PatchField, GeoMesh>&)" 01094 ) << "attempted assignment to self" 01095 << abort(FatalError); 01096 } 01097 01098 checkField(*this, gf, "="); 01099 01100 // only equate field contents not ID 01101 01102 dimensionedInternalField() = gf.dimensionedInternalField(); 01103 boundaryField() = gf.boundaryField(); 01104 } Both operators, work on GeometricField<Type, PatchField, GeoMesh> ( example: vol*Field) from both sides. Hope this helps, Tomislav |
Ah, but == will force an overwrite of all the boundary conditions, whereas = will not.
|
Quote:
I didn't notice that double "==" in the operator == of the GeometricField<blah ... and when I look in the BoundaryField, this operator is defined to do: Code:
void operator== ( const GeometricBoundaryField & Code:
// Forced assignments The only question is, what does this button do: "this->operator[](patchI) == bf[patchI]" |
All times are GMT -4. The time now is 11:55. |