|
[Sponsors] |
February 15, 2011, 07:57 |
== operator
|
#1 |
Senior Member
Illya Shevchuk
Join Date: Aug 2009
Location: Darmstadt, Germany
Posts: 176
Rep Power: 17 |
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 ( UEqn == fvc::reconstruct ( ( fvc::interpolate(interface.sigmaK())*fvc::snGrad(alpha1) - ghf*fvc::snGrad(rho) - fvc::snGrad(p_rgh) ) * mesh.magSf() ) ); Code:
rho = alpha1*rho1 + (scalar(1) - alpha1)*rho2; Best regards, Ilya |
|
February 15, 2011, 08:56 |
|
#3 |
Senior Member
Illya Shevchuk
Join Date: Aug 2009
Location: Darmstadt, Germany
Posts: 176
Rep Power: 17 |
And how OF knows, if it has to use the C/C++ standard boolean or the OF-redefined "==" operator?
|
|
February 16, 2011, 00:32 |
|
#4 |
Senior Member
Santiago Marquez Damian
Join Date: Aug 2009
Location: Santa Fe, Santa Fe, Argentina
Posts: 452
Rep Power: 24 |
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.
__________________
Santiago MÁRQUEZ DAMIÁN, Ph.D. Research Scientist Research Center for Computational Methods (CIMEC) - CONICET/UNL Tel: 54-342-4511594 Int. 7032 Colectora Ruta Nac. 168 / Paraje El Pozo (3000) Santa Fe - Argentina. http://www.cimec.org.ar |
|
February 16, 2011, 08:11 |
|
#5 |
Senior Member
Illya Shevchuk
Join Date: Aug 2009
Location: Darmstadt, Germany
Posts: 176
Rep Power: 17 |
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? regards, Ilya |
|
February 16, 2011, 09:00 |
|
#6 |
Senior Member
Anton Kidess
Join Date: May 2009
Location: Germany
Posts: 1,377
Rep Power: 30 |
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().
Last edited by akidess; February 16, 2011 at 09:01. Reason: extended answer |
|
February 16, 2011, 09:22 |
|
#7 |
Senior Member
Santiago Marquez Damian
Join Date: Aug 2009
Location: Santa Fe, Santa Fe, Argentina
Posts: 452
Rep Power: 24 |
Illya, from what source file did you take this line?:
Code:
rho = alpha1*rho1 + (scalar(1) - alpha1)*rho2;
__________________
Santiago MÁRQUEZ DAMIÁN, Ph.D. Research Scientist Research Center for Computational Methods (CIMEC) - CONICET/UNL Tel: 54-342-4511594 Int. 7032 Colectora Ruta Nac. 168 / Paraje El Pozo (3000) Santa Fe - Argentina. http://www.cimec.org.ar |
|
February 16, 2011, 12:47 |
|
#8 |
Senior Member
Illya Shevchuk
Join Date: Aug 2009
Location: Darmstadt, Germany
Posts: 176
Rep Power: 17 |
interFoam : alphaEqnSubCycle.H
Thanks, so for volFields it makes more sense to use == instead of =, if no boundary condition is prescribed for the LHS-field? |
|
February 16, 2011, 14:33 |
|
#9 |
Senior Member
Santiago Marquez Damian
Join Date: Aug 2009
Location: Santa Fe, Santa Fe, Argentina
Posts: 452
Rep Power: 24 |
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.
__________________
Santiago MÁRQUEZ DAMIÁN, Ph.D. Research Scientist Research Center for Computational Methods (CIMEC) - CONICET/UNL Tel: 54-342-4511594 Int. 7032 Colectora Ruta Nac. 168 / Paraje El Pozo (3000) Santa Fe - Argentina. http://www.cimec.org.ar Last edited by santiagomarquezd; February 18, 2011 at 08:31. |
|
February 18, 2011, 08:07 |
|
#10 |
Senior Member
Illya Shevchuk
Join Date: Aug 2009
Location: Darmstadt, Germany
Posts: 176
Rep Power: 17 |
||
February 19, 2011, 07:55 |
|
#11 |
Senior Member
Hrvoje Jasak
Join Date: Mar 2009
Location: London, England
Posts: 1,907
Rep Power: 33 |
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 Providing commercial FOAM/OpenFOAM and CFD Consulting: http://wikki.co.uk |
|
February 19, 2011, 12:27 |
|
#12 |
Senior Member
Santiago Marquez Damian
Join Date: Aug 2009
Location: Santa Fe, Santa Fe, Argentina
Posts: 452
Rep Power: 24 |
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> 01091 void Foam::GeometricField<Type, PatchField, GeoMesh>::operator== 01092 ( 01093 const tmp<GeometricField<Type, PatchField, GeoMesh> >& tgf 01094 ) 01095 { 01096 const GeometricField<Type, PatchField, GeoMesh>& gf = tgf(); 01097 01098 checkField(*this, gf, "=="); 01099 01100 // only equate field contents not ID 01101 01102 dimensionedInternalField() = gf.dimensionedInternalField(); 01103 boundaryField() == gf.boundaryField(); 01104 01105 tgf.clear(); 01106 } Code:
00437 // Force an assignment, overriding fixedValue status 00438 template<class Type> 00439 void Foam::fvPatchField<Type>::operator== 00440 ( 00441 const fvPatchField<Type>& ptf 00442 ) 00443 { 00444 Field<Type>::operator=(ptf); 00445 } Regards. P.S. fvPatchField class don't have a 'fixed value flag' to avoid overriding?
__________________
Santiago MÁRQUEZ DAMIÁN, Ph.D. Research Scientist Research Center for Computational Methods (CIMEC) - CONICET/UNL Tel: 54-342-4511594 Int. 7032 Colectora Ruta Nac. 168 / Paraje El Pozo (3000) Santa Fe - Argentina. http://www.cimec.org.ar |
|
September 26, 2011, 16:35 |
|
#13 | |
Senior Member
Hisham Elsafti
Join Date: Apr 2011
Location: Braunschweig, Germany
Posts: 257
Blog Entries: 10
Rep Power: 17 |
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 |
||
September 27, 2011, 04:12 |
|
#14 | |
Senior Member
Tomislav Maric
Join Date: Mar 2009
Location: Darmstadt, Germany
Posts: 284
Blog Entries: 5
Rep Power: 21 |
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> Foam::tmp<Foam::fvMatrix<Type> > Foam::operator== ( const fvMatrix<Type>& A, const fvMatrix<Type>& B ) { checkMethod(A, B, "=="); return (A - B); } 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> void Foam::fvMatrix<Type>::operator=(const fvMatrix<Type>& fvmv) { if (this == &fvmv) { FatalErrorIn("fvMatrix<Type>::operator=(const fvMatrix<Type>&)") << "attempted assignment to self" << abort(FatalError); } if (&psi_ != &(fvmv.psi_)) { FatalErrorIn("fvMatrix<Type>::operator=(const fvMatrix<Type>&)") << "different fields" << abort(FatalError); } lduMatrix::operator=(fvmv); source_ = fvmv.source_; internalCoeffs_ = fvmv.internalCoeffs_; boundaryCoeffs_ = fvmv.boundaryCoeffs_; if (faceFluxCorrectionPtr_ && fvmv.faceFluxCorrectionPtr_) { *faceFluxCorrectionPtr_ = *fvmv.faceFluxCorrectionPtr_; } else if (fvmv.faceFluxCorrectionPtr_) { faceFluxCorrectionPtr_ = new GeometricField<Type, fvsPatchField, surfaceMesh> (*fvmv.faceFluxCorrectionPtr_); } } 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>:perator== 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>:perator= 01084 ( 01085 const GeometricField<Type, PatchField, GeoMesh>& gf 01086 ) 01087 { 01088 if (this == &gf) 01089 { 01090 FatalErrorIn 01091 ( 01092 "GeometricField<Type, PatchField, GeoMesh>:perator=" 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 |
||
September 27, 2011, 06:06 |
|
#16 | |
Senior Member
Tomislav Maric
Join Date: Mar 2009
Location: Darmstadt, Germany
Posts: 284
Blog Entries: 5
Rep Power: 21 |
Quote:
Code:
01167 boundaryField() == gf.boundaryField(); Code:
void operator== ( const GeometricBoundaryField & ) Forced assignment to. BoundaryField<Type, PatchField, BoundaryMesh> Code:
// Forced assignments template<class Type, template<class> class PatchField, class GeoMesh> void Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField:: operator== ( const typename GeometricField<Type, PatchField, GeoMesh>:: GeometricBoundaryField& bf ) { forAll((*this), patchI) { this->operator[](patchI) == bf[patchI]; } } The only question is, what does this button do: "this->operator[](patchI) == bf[patchI]" |
||
Tags |
equality operator, openfoam operators |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Modifying the laplacian operator | mlawson | OpenFOAM Running, Solving & CFD | 22 | July 16, 2018 05:56 |
Create a biharmonic operator | Pascal_doran | OpenFOAM Programming & Development | 12 | May 22, 2016 07:02 |
Installation of OpenFOAM15dev | antonio_ing | OpenFOAM Installation | 34 | December 18, 2009 11:06 |
Laplacian operator and nuSgs for heat equation | Bedotto | OpenFOAM Programming & Development | 4 | September 7, 2009 16:08 |
Operator declaration in Thermophysical library | lena | OpenFOAM Running, Solving & CFD | 0 | March 12, 2009 10:47 |