CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   For loops in OpenFoam (https://www.cfd-online.com/Forums/openfoam-programming-development/79839-loops-openfoam.html)

balkrishna September 6, 2010 07:44

For loops in OpenFoam
 
I am generalising the twoPhase Euler Foam to handle n Phases . In the file pEqn.H I want to sum up the phase fraction of all the dispersed phases to get the dispersed phase . To do so I programmed the following :
Code:

PtrList<surfaceScalarField>alphaf(nPhases);                                                                                             
                                                                                                                                             
    //just an initialization                                                                                                                 
    surfaceScalarField af ;                                                                                                                 
    surfaceScalarField betaf = scalar(1) - af;                                                                                               
                                                                                                                                             
    forAll(alphaf,aPh)                                                                                                                       
    {                                                                                                                                       
        alphaf.set(aPh,fvc::interpolate(phases[aPh].alpha()));                                                                               
        af= af + alphaf[aPh];                                                                                                               
    }                                                                                                                                       
    betaf = scalar(1) - af ;

On compilation I got the following error :
Code:

error: no matching function for call to ‘Foam::GeometricField<double, Foam::fvsPatchField, Foam::surfaceMesh>::GeometricField()’
/home/ifmg/OpenFOAM/OpenFOAM-1.7.0/src/OpenFOAM/lnInclude/GeometricField.C:652: note: candidates are: Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField(const Foam::IOobject&, const Foam::GeometricField<Type, PatchField, GeoMesh>&, const Foam::wordList&) [with Type = double, PatchField = Foam::fvsPatchField, GeoMesh = Foam::surfaceMesh]


marupio September 6, 2010 16:46

The problem isn't the for loop, it's your PtrList .set command:

Code:

alphaf.set(aPh,fvc::interpolate(phases[aPh].alpha()));
You have to create a GeometricField on the freestore for this pointer list... and you have to use a proper GeometricField constructor.

Code:

alphaf.set
(
    aPh,
    new surfaceScalarField
    (
        IOobject
        (
            // IOobject constructor parameters - you decide
        ),
        mesh,
        fvc::interpolate(phases[aPh].alpha())
    )
);

Hope that helps!

balkrishna September 7, 2010 00:37

The error wasnt for the alphaf.set line . It was for the "surfaceScalarField alphaf ; " line

akidess September 7, 2010 04:06

Duplicate: http://www.cfd-online.com/Forums/ope...-openfoam.html

niklas September 7, 2010 11:54

there is no default constructor for the surfaceScalarField.

it needs to know about its size, take any available surfaceScalarField available and use that.
For instance phi and

surfaceScalarField alphaf(phi.size());

balkrishna September 7, 2010 12:01

Thanks evry1 .... my problem was solved ... i initialized af in createFields.H and that solved the problem as suggested by alberto here ...


All times are GMT -4. The time now is 23:35.