CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM

openFoam syntax

Register Blogs Community New Posts Updated Threads Search

Like Tree5Likes
  • 1 Post By nimasam
  • 4 Post By marupio

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 29, 2011, 16:27
Default openFoam syntax
  #1
Senior Member
 
Nima Samkhaniani
Join Date: Sep 2009
Location: Tehran, Iran
Posts: 1,267
Blog Entries: 1
Rep Power: 25
nimasam is on a distinguished road
hi openFoamer

in compressibleInterFoam and in pEqn.H there are following syntax:
Code:
 dgdt =
                (pos(alpha2)*(psi2/rho2) - pos(alpha1)*(psi1/rho1))
               *(pEqnComp & p);
can any body tell me whats the meaning of "pEqnComp & p" ?

pEqnComp : fvScalarMatrix
p : volScalarField

so whats "&" here ?
alia likes this.
nimasam is offline   Reply With Quote

Old   September 29, 2011, 21:30
Default
  #2
Senior Member
 
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 22
marupio is on a distinguished road
I think it's the inner product.
__________________
~~~
Follow me on twitter @DavidGaden
marupio is offline   Reply With Quote

Old   September 29, 2011, 22:57
Default
  #3
Senior Member
 
Nima Samkhaniani
Join Date: Sep 2009
Location: Tehran, Iran
Posts: 1,267
Blog Entries: 1
Rep Power: 25
nimasam is on a distinguished road
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
nimasam is offline   Reply With Quote

Old   September 29, 2011, 23:39
Default
  #4
Senior Member
 
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 22
marupio is on a distinguished road
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
marupio is offline   Reply With Quote

Old   September 30, 2011, 06:45
Default
  #5
Senior Member
 
Nima Samkhaniani
Join Date: Sep 2009
Location: Tehran, Iran
Posts: 1,267
Blog Entries: 1
Rep Power: 25
nimasam is on a distinguished road
& 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;
}
1) could you please tell me what does this piece of code do?

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
nimasam is offline   Reply With Quote

Old   September 30, 2011, 07:02
Default
  #6
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,903
Rep Power: 37
ngj will become famous soon enoughngj will become famous soon enough
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
ngj is offline   Reply With Quote

Old   September 30, 2011, 10:33
Default
  #7
Senior Member
 
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 22
marupio is on a distinguished road
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
marupio is offline   Reply With Quote

Old   September 30, 2011, 13:26
Default
  #8
Senior Member
 
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 22
marupio is on a distinguished road
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;
}
For H operator stuff, see this page:
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
nlc, nimasam, alia and 1 others like this.
__________________
~~~
Follow me on twitter @DavidGaden
marupio is offline   Reply With Quote

Reply

Tags
equation, operator, syntax


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


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


All times are GMT -4. The time now is 09:00.