|
[Sponsors] | |||||
|
|
|
#1 |
|
Senior Member
Illya Shevchuk
Join Date: Aug 2009
Location: Darmstadt, Germany
Posts: 176
Rep Power: 18 ![]() |
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 |
|
|
|
|
|
|
|
|
#3 |
|
Senior Member
Illya Shevchuk
Join Date: Aug 2009
Location: Darmstadt, Germany
Posts: 176
Rep Power: 18 ![]() |
And how OF knows, if it has to use the C/C++ standard boolean or the OF-redefined "==" operator?
|
|
|
|
|
|
|
|
|
#4 |
|
Senior Member
Santiago Marquez Damian
Join Date: Aug 2009
Location: Santa Fe, Santa Fe, Argentina
Posts: 452
Rep Power: 25 ![]() |
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 |
|
|
|
|
|
|
|
|
#5 |
|
Senior Member
Illya Shevchuk
Join Date: Aug 2009
Location: Darmstadt, Germany
Posts: 176
Rep Power: 18 ![]() |
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 |
|
|
|
|
|
|
|
|
#6 |
|
Senior Member
Anton Kidess
Join Date: May 2009
Location: Germany
Posts: 1,377
Rep Power: 31 ![]() |
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 |
|
|
|
|
|
|
|
|
#7 |
|
Senior Member
Santiago Marquez Damian
Join Date: Aug 2009
Location: Santa Fe, Santa Fe, Argentina
Posts: 452
Rep Power: 25 ![]() |
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 |
|
|
|
|
|
|
|
|
#8 |
|
Senior Member
Illya Shevchuk
Join Date: Aug 2009
Location: Darmstadt, Germany
Posts: 176
Rep Power: 18 ![]() |
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? |
|
|
|
|
|
|
|
|
#9 |
|
Senior Member
Santiago Marquez Damian
Join Date: Aug 2009
Location: Santa Fe, Santa Fe, Argentina
Posts: 452
Rep Power: 25 ![]() |
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. |
|
|
|
|
|
|
|
|
#10 |
|
Senior Member
Illya Shevchuk
Join Date: Aug 2009
Location: Darmstadt, Germany
Posts: 176
Rep Power: 18 ![]() |
||
|
|
|
|
|
|
|
#11 |
|
Senior Member
Hrvoje Jasak
Join Date: Mar 2009
Location: London, England
Posts: 1,908
Rep Power: 34 ![]() |
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 |
|
|
|
|
|
|
|
|
#12 |
|
Senior Member
Santiago Marquez Damian
Join Date: Aug 2009
Location: Santa Fe, Santa Fe, Argentina
Posts: 452
Rep Power: 25 ![]() |
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 |
|
|
|
|
|
|
|
|
#13 | |
|
Senior Member
Hisham Elsafti
Join Date: Apr 2011
Location: Braunschweig, Germany
Posts: 257
Blog Entries: 10
Rep Power: 18 ![]() |
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 |
||
|
|
|
||
|
|
|
#14 | |
|
Senior Member
Tomislav Maric
Join Date: Mar 2009
Location: Darmstadt, Germany
Posts: 284
Blog Entries: 5
Rep Power: 22 ![]() |
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_);
}
}
perator= because it inherits from it, this guy goes over lower, upper and diagonal part and executes the data copy. The other part copies the rest of the data that is stored in the fvMatrix.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 |
||
|
|
|
||
|
|
|
#16 | |
|
Senior Member
Tomislav Maric
Join Date: Mar 2009
Location: Darmstadt, Germany
Posts: 284
Blog Entries: 5
Rep Power: 22 ![]() |
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];
}
}
It's all in the GeometricField.C and GeometricBoundaryField.C (GeometricBoundaryField is composited into GeometricField). The only question is, what does this button do: "this->operator[](patchI) == bf[patchI]" |
||
|
|
|
||
![]() |
| Tags |
| equality operator, openfoam operators |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
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 |