|
[Sponsors] |
September 29, 2011, 16:27 |
openFoam syntax
|
#1 |
Senior Member
Nima Samkhaniani
Join Date: Sep 2009
Location: Tehran, Iran
Posts: 1,267
Blog Entries: 1
Rep Power: 25 |
hi openFoamer
in compressibleInterFoam and in pEqn.H there are following syntax: Code:
dgdt = (pos(alpha2)*(psi2/rho2) - pos(alpha1)*(psi1/rho1)) *(pEqnComp & p); pEqnComp : fvScalarMatrix p : volScalarField so whats "&" here ? |
|
September 29, 2011, 21:30 |
|
#2 |
Senior Member
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 22 |
I think it's the inner product.
__________________
~~~ Follow me on twitter @DavidGaden |
|
September 29, 2011, 22:57 |
|
#3 |
Senior Member
Nima Samkhaniani
Join Date: Sep 2009
Location: Tehran, Iran
Posts: 1,267
Blog Entries: 1
Rep Power: 25 |
im confused how we can inner product fvScalarMatrix with volScalarField?
what is the output and how this calculation can be done? give me a mathematical concept please |
|
September 29, 2011, 23:39 |
|
#4 |
Senior Member
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 22 |
fvMatrix.C implements operator& around line 2270. The result is a GeometricField. I'm not exactly sure what it does, but it looks like it affects the matrix. I don't have my Foaming computer in front of me at the moment.
__________________
~~~ Follow me on twitter @DavidGaden |
|
September 30, 2011, 06:45 |
|
#5 |
Senior Member
Nima Samkhaniani
Join Date: Sep 2009
Location: Tehran, Iran
Posts: 1,267
Blog Entries: 1
Rep Power: 25 |
& operator is defined in fvMatrix.C like below:
Code:
template<class Type> Foam::tmp<Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh> > Foam::operator& ( const fvMatrix<Type>& M, const DimensionedField<Type, volMesh>& psi ) { tmp<GeometricField<Type, fvPatchField, volMesh> > tMphi ( new GeometricField<Type, fvPatchField, volMesh> ( IOobject ( "M&" + psi.name(), psi.instance(), psi.mesh(), IOobject::NO_READ, IOobject::NO_WRITE ), psi.mesh(), M.dimensions()/dimVol, zeroGradientFvPatchScalarField::typeName ) ); GeometricField<Type, fvPatchField, volMesh>& Mphi = tMphi(); // Loop over field components for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++) { scalarField psiCmpt = psi.field().component(cmpt); scalarField boundaryDiagCmpt(M.diag()); M.addBoundaryDiag(boundaryDiagCmpt, cmpt); Mphi.internalField().replace(cmpt, -boundaryDiagCmpt*psiCmpt); } Mphi.internalField() += M.lduMatrix::H(psi.field()) + M.source(); M.addBoundarySource(Mphi.internalField()); Mphi.internalField() /= -psi.mesh().V(); Mphi.correctBoundaryConditions(); return tMphi; } it seems it loops over the field to make it diagonal predominate, but its confusing! 2)why it returns tMphi while it does all operation on Mphi? i feel it should be Mphi |
|
September 30, 2011, 07:02 |
|
#6 |
Senior Member
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,903
Rep Power: 37 |
add 2) tMphi is a tmp<Type>, whereas Mphi (of type Type) is a reference to tMphi. Hence all changes to Mphi is directly a change to tMphi.
tMphi is returned, as the tmp class is included in OpenFOAM to optimise the memory handling. Since volFieldsType> can potentially be very large, the return of a tmp<volField<Type> > speeds up the run-time. Kind regards, Niels |
|
September 30, 2011, 10:33 |
|
#7 |
Senior Member
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 22 |
It's probably the inner product. When it involves a fvMatrix, it apparently does something to the Matrix's diagonal. I'm not going to try to decode it because I agree: it is confusing.
__________________
~~~ Follow me on twitter @DavidGaden |
|
September 30, 2011, 13:26 |
|
#8 |
Senior Member
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 22 |
Hi Nima, sorry for being dismissive in the last response. If you want to go into detail about what the & operator does, I've added some comments in blue that might help you out. It looks like it doesn't actually affect the matrix. It looks like it is the inner product between the field associated with the matirx, with the field p you mention. Since a matrix is involved, it has to account for boundary conditions, and I think that's where it gets confusing, especially when it comes to boundary patches that have out-of-core multiplication (cyclic, processor, etc). Also see below for links to useful pages that might help further explain things.
Code:
template<class Type> Foam::tmp<Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh> > Foam::operator& ( const fvMatrix<Type>& M, const DimensionedField<Type, volMesh>& psi ) { // Here we create the return object tmp<GeometricField<Type, fvPatchField, volMesh> > tMphi ( new GeometricField<Type, fvPatchField, volMesh> ( IOobject ( "M&" + psi.name(), psi.instance(), psi.mesh(), IOobject::NO_READ, IOobject::NO_WRITE ), psi.mesh(), M.dimensions()/dimVol, zeroGradientFvPatchScalarField::typeName ) ); // This is for convenience, because it is awkward dealing directly with tmp<> // See link below. GeometricField<Type, fvPatchField, volMesh>& Mphi = tMphi(); // Loop over field components for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++) { // psiCmpt is your "p" scalarField psiCmpt = psi.field().component(cmpt); // Here we're grabbing a copy of the matrix diagonal of your "pEqnComp" scalarField boundaryDiagCmpt(M.diag()); // This function brings in out-of-core multiplication effects from the boundary // (e.g. cyclic patches) and puts it into our copy of the diagonal M.addBoundaryDiag(boundaryDiagCmpt, cmpt); // Multiplying p by the modified diagonal, store result in output object Mphi.internalField().replace(cmpt, -boundaryDiagCmpt*psiCmpt); } // H operator stuff. Shorthand operation built into the matrix that I never // remember what it does... see link below Mphi.internalField() += M.lduMatrix::H(psi.field()) + M.source(); M.addBoundarySource(Mphi.internalField()); // Per unit volume - the matrix is integrated over the volume; a field is not Mphi.internalField() /= -psi.mesh().V(); Mphi.correctBoundaryConditions(); return tMphi; } http://openfoamwiki.net/index.php/Op...ide/H_operator For what tmp<> is all about, see here: http://openfoamwiki.net/index.php/OpenFOAM_guide/tmp
__________________
~~~ Follow me on twitter @DavidGaden |
|
Tags |
equation, operator, syntax |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Cross-compiling OpenFOAM 1.7.0 on Linux for Windows 32 and 64bits with Mingw-w64 | wyldckat | OpenFOAM Announcements from Other Sources | 3 | September 8, 2010 07:25 |
OpenFOAM file syntax | amtri | OpenFOAM | 5 | August 28, 2010 08:19 |
Modified OpenFOAM Forum Structure and New Mailing-List | pete | Site News & Announcements | 0 | June 29, 2009 06:56 |
OpenFOAM Debian packaging current status problems and TODOs | oseen | OpenFOAM Installation | 9 | August 26, 2007 14:50 |
error while compiling the USER Sub routine | CFD user | CFX | 3 | November 25, 2002 16:16 |