CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Multiple volScalarFields using List<volScalarField> (http://www.cfd-online.com/Forums/openfoam-programming-development/113261-multiple-volscalarfields-using-list-volscalarfield.html)

vbchris February 15, 2013 17:47

Multiple volScalarFields using List<volScalarField>
 
I would like to initialize a list of volScalarFields. This will be used for the calculation of concentrations of multiple species.

I used the following code to initialize the volScalarFields in createFields.h
I also thought about using ptrlist<volScalarField>.

What I thought the code would do is create a list size 3 (to be size n) of volScalarField objects called T. T[1] was used in the solver code by using the intermediate Ti.



Code:

    volScalarField Temp_field
    (
        IOobject
        (
            "T",
            runTime.timeName(),
            mesh,
            IOobject::MUST_READ,
            IOobject::AUTO_WRITE
        ),
        mesh
    );
   

    List<volScalarField> T;

    T.setSize(3);

    for (label i=0; i<3; i++)
    {     
        T[i] = Temp_field;
    }

And implemented it into the scalarTransportFoam solver with
Code:

    while (simple.loop())
    {
        Info<< "Time = " << runTime.timeName() << nl << endl;

        while (simple.correctNonOrthogonal())
        {
        volScalarField& Ti = T[1];
            solve
            (
                fvm::ddt(Ti) ///HERE
              + fvm::div(phi, Ti) ///HERE
              - fvm::laplacian(DT, Ti) ///HERE
            );

However, the code won't compile. From the debug it looks like I'm not passing a volScalarField to the solve() function. Here is the debug output on OpenFoam 2.1.1:

Code:

Making dependency list for source file myScalarTransportFoam.C
SOURCE=myScalarTransportFoam.C ;  g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor -O3  -DNoRepository -ftemplate-depth-100 -I/opt/openfoam211/src/finiteVolume/lnInclude -I/opt/openfoam211/src/lnInclude -IlnInclude -I. -I/opt/openfoam211/src/OpenFOAM/lnInclude -I/opt/openfoam211/src/OSspecific/POSIX/lnInclude  -fPIC -c $SOURCE -o Make/linux64GccDPOpt/myScalarTransportFoam.o
myScalarTransportFoam.C: In function ‘int main(int, char**)’:
myScalarTransportFoam.C:67:27: error: no matching function for call to ‘ddt(Foam::List<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> >&)’
myScalarTransportFoam.C:67:27: note: candidates are:
/opt/openfoam211/src/finiteVolume/lnInclude/fvmDdt.C:45:1: note: template<class Type> Foam::tmp<Foam::fvMatrix<Type> > Foam::fvm::ddt(const Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>&)
/opt/openfoam211/src/finiteVolume/lnInclude/fvmDdt.C:60:1: note: template<class Type> Foam::tmp<Foam::fvMatrix<Type> > Foam::fvm::ddt(const Foam::one&, const Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>&)
/opt/openfoam211/src/finiteVolume/lnInclude/fvmDdt.C:72:1: note: template<class Type> Foam::tmp<Foam::fvMatrix<Type> > Foam::fvm::ddt(const dimensionedScalar&, const Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>&)
/opt/openfoam211/src/finiteVolume/lnInclude/fvmDdt.C:88:1: note: template<class Type> Foam::tmp<Foam::fvMatrix<Type> > Foam::fvm::ddt(const volScalarField&, const Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>&)
myScalarTransportFoam.C:68:32: error: no matching function for call to ‘div(Foam::surfaceScalarField&, Foam::List<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> >&)’
myScalarTransportFoam.C:68:32: note: candidates are:
/opt/openfoam211/src/finiteVolume/lnInclude/fvmDiv.C:45:1: note: template<class Type> Foam::tmp<Foam::fvMatrix<Type> > Foam::fvm::div(const surfaceScalarField&, const Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>&, const Foam::word&)
/opt/openfoam211/src/finiteVolume/lnInclude/fvmDiv.C:62:1: note: template<class Type> Foam::tmp<Foam::fvMatrix<Type> > Foam::fvm::div(const Foam::tmp<Foam::GeometricField<double, Foam::fvsPatchField, Foam::surfaceMesh> >&, const Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>&, const Foam::word&)
/opt/openfoam211/src/finiteVolume/lnInclude/fvmDiv.C:77:1: note: template<class Type> Foam::tmp<Foam::fvMatrix<Type> > Foam::fvm::div(const surfaceScalarField&, const Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>&)
/opt/openfoam211/src/finiteVolume/lnInclude/fvmDiv.C:88:1: note: template<class Type> Foam::tmp<Foam::fvMatrix<Type> > Foam::fvm::div(const Foam::tmp<Foam::GeometricField<double, Foam::fvsPatchField, Foam::surfaceMesh> >&, const Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>&)
myScalarTransportFoam.C:69:37: error: no matching function for call to ‘laplacian(Foam::dimensionedScalar&, Foam::List<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> >&)’
myScalarTransportFoam.C:69:37: note: candidates are:
/opt/openfoam211/src/finiteVolume/lnInclude/fvmLaplacian.C:45:1: note: template<class Type> Foam::tmp<Foam::fvMatrix<Type> > Foam::fvm::laplacian(const Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>&, const Foam::word&)
/opt/openfoam211/src/finiteVolume/lnInclude/fvmLaplacian.C:70:1: note: template<class Type> Foam::tmp<Foam::fvMatrix<Type> > Foam::fvm::laplacian(const Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>&)
/opt/openfoam211/src/finiteVolume/lnInclude/fvmLaplacian.C:99:1: note: template<class Type> Foam::tmp<Foam::fvMatrix<Type> > Foam::fvm::laplacian(const Foam::zero&, const Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>&, const Foam::word&)
/opt/openfoam211/src/finiteVolume/lnInclude/fvmLaplacian.C:115:1: note: template<class Type> Foam::tmp<Foam::fvMatrix<Type> > Foam::fvm::laplacian(const Foam::zero&, const Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>&)
/opt/openfoam211/src/finiteVolume/lnInclude/fvmLaplacian.C:130:1: note: template<class Type> Foam::tmp<Foam::fvMatrix<Type> > Foam::fvm::laplacian(const Foam::one&, const Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>&, const Foam::word&)
/opt/openfoam211/src/finiteVolume/lnInclude/fvmLaplacian.C:143:1: note: template<class Type> Foam::tmp<Foam::fvMatrix<Type> > Foam::fvm::laplacian(const Foam::one&, const Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>&)
/opt/openfoam211/src/finiteVolume/lnInclude/fvmLaplacian.C:155:1: note: template<class Type, class GType> Foam::tmp<Foam::fvMatrix<Type> > Foam::fvm::laplacian(const Foam::dimensioned<Type2>&, const Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>&, const Foam::word&)
/opt/openfoam211/src/finiteVolume/lnInclude/fvmLaplacian.C:181:1: note: template<class Type, class GType> Foam::tmp<Foam::fvMatrix<Type> > Foam::fvm::laplacian(const Foam::dimensioned<Type2>&, const Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>&)
/opt/openfoam211/src/finiteVolume/lnInclude/fvmLaplacian.C:208:1: note: template<class Type, class GType> Foam::tmp<Foam::fvMatrix<Type> > Foam::fvm::laplacian(const Foam::GeometricField<GType, Foam::fvPatchField, Foam::volMesh>&, const Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>&, const Foam::word&)
/opt/openfoam211/src/finiteVolume/lnInclude/fvmLaplacian.C:240:1: note: template<class Type, class GType> Foam::tmp<Foam::fvMatrix<Type> > Foam::fvm::laplacian(const Foam::GeometricField<GType, Foam::fvPatchField, Foam::volMesh>&, const Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>&)
/opt/openfoam211/src/finiteVolume/lnInclude/fvmLaplacian.C:225:1: note: template<class Type, class GType> Foam::tmp<Foam::fvMatrix<Type> > Foam::fvm::laplacian(const Foam::tmp<Foam::GeometricField<GType, Foam::fvPatchField, Foam::volMesh> >&, const Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>&, const Foam::word&)
/opt/openfoam211/src/finiteVolume/lnInclude/fvmLaplacian.C:257:1: note: template<class Type, class GType> Foam::tmp<Foam::fvMatrix<Type> > Foam::fvm::laplacian(const Foam::tmp<Foam::GeometricField<GType, Foam::fvPatchField, Foam::volMesh> >&, const Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>&)
/opt/openfoam211/src/finiteVolume/lnInclude/fvmLaplacian.C:273:1: note: template<class Type, class GType> Foam::tmp<Foam::fvMatrix<Type> > Foam::fvm::laplacian(const Foam::GeometricField<GType, Foam::fvsPatchField, Foam::surfaceMesh>&, const Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>&, const Foam::word&)
/opt/openfoam211/src/finiteVolume/lnInclude/fvmLaplacian.C:290:1: note: template<class Type, class GType> Foam::tmp<Foam::fvMatrix<Type> > Foam::fvm::laplacian(const Foam::tmp<Foam::GeometricField<GType, Foam::fvsPatchField, Foam::surfaceMesh> >&, const Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>&, const Foam::word&)
/opt/openfoam211/src/finiteVolume/lnInclude/fvmLaplacian.C:305:1: note: template<class Type, class GType> Foam::tmp<Foam::fvMatrix<Type> > Foam::fvm::laplacian(const Foam::GeometricField<GType, Foam::fvsPatchField, Foam::surfaceMesh>&, const Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>&)
/opt/openfoam211/src/finiteVolume/lnInclude/fvmLaplacian.C:322:1: note: template<class Type, class GType> Foam::tmp<Foam::fvMatrix<Type> > Foam::fvm::laplacian(const Foam::tmp<Foam::GeometricField<GType, Foam::fvsPatchField, Foam::surfaceMesh> >&, const Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>&)
myScalarTransportFoam.C:80:68: error: ‘class Foam::List<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> >’ has no member named ‘boundaryField’
In file included from /opt/openfoam211/src/OpenFOAM/lnInclude/List.H:259:0,
                from /opt/openfoam211/src/OpenFOAM/lnInclude/labelList.H:48,
                from /opt/openfoam211/src/OpenFOAM/lnInclude/UPstream.H:43,
                from /opt/openfoam211/src/OpenFOAM/lnInclude/Pstream.H:42,
                from /opt/openfoam211/src/OpenFOAM/lnInclude/parRun.H:35,
                from /opt/openfoam211/src/finiteVolume/lnInclude/fvCFD.H:4,
                from myScalarTransportFoam.C:32:
/opt/openfoam211/src/OpenFOAM/lnInclude/List.C: In member function ‘void Foam::List<T>::setSize(Foam::label) [with T = Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>, Foam::label = int]’:
createFields.H:21:16:  instantiated from here
/opt/openfoam211/src/OpenFOAM/lnInclude/List.C:331:41: error: no matching function for call to ‘Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>::GeometricField()’
/opt/openfoam211/src/OpenFOAM/lnInclude/List.C:331:41: note: candidates are:
/opt/openfoam211/src/OpenFOAM/lnInclude/GeometricField.C:625:1: note: Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField(const Foam::IOobject&, const Foam::GeometricField<Type, PatchField, GeoMesh>&, const wordList&, const wordList&) [with Type = double, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh, Foam::wordList = Foam::List<Foam::word>]
/opt/openfoam211/src/OpenFOAM/lnInclude/GeometricField.C:625:1: note:  candidate expects 4 arguments, 0 provided
/opt/openfoam211/src/OpenFOAM/lnInclude/GeometricField.C:590:1: note: Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField(const Foam::IOobject&, const Foam::GeometricField<Type, PatchField, GeoMesh>&, const Foam::word&) [with Type = double, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh]
/opt/openfoam211/src/OpenFOAM/lnInclude/GeometricField.C:590:1: note:  candidate expects 3 arguments, 0 provided
/opt/openfoam211/src/OpenFOAM/lnInclude/GeometricField.C:560:1: note: Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField(const Foam::word&, const Foam::tmp<Foam::GeometricField<Type, PatchField, GeoMesh> >&) [with Type = double, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh]
/opt/openfoam211/src/OpenFOAM/lnInclude/GeometricField.C:560:1: note:  candidate expects 2 arguments, 0 provided
/opt/openfoam211/src/OpenFOAM/lnInclude/GeometricField.C:527:1: note: Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField(const Foam::word&, const Foam::GeometricField<Type, PatchField, GeoMesh>&) [with Type = double, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh]
/opt/openfoam211/src/OpenFOAM/lnInclude/GeometricField.C:527:1: note:  candidate expects 2 arguments, 0 provided
/opt/openfoam211/src/OpenFOAM/lnInclude/GeometricField.C:495:1: note: Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField(const Foam::IOobject&, const Foam::GeometricField<Type, PatchField, GeoMesh>&) [with Type = double, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh]
/opt/openfoam211/src/OpenFOAM/lnInclude/GeometricField.C:495:1: note:  candidate expects 2 arguments, 0 provided
/opt/openfoam211/src/OpenFOAM/lnInclude/GeometricField.C:464:1: note: Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField(const Foam::tmp<Foam::GeometricField<Type, PatchField, GeoMesh> >&) [with Type = double, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh]
/opt/openfoam211/src/OpenFOAM/lnInclude/GeometricField.C:464:1: note:  candidate expects 1 argument, 0 provided
/opt/openfoam211/src/OpenFOAM/lnInclude/GeometricField.C:432:1: note: Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField(const Foam::GeometricField<Type, PatchField, GeoMesh>&) [with Type = double, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh]
/opt/openfoam211/src/OpenFOAM/lnInclude/GeometricField.C:432:1: note:  candidate expects 1 argument, 0 provided
/opt/openfoam211/src/OpenFOAM/lnInclude/GeometricField.C:393:1: note: Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField(const Foam::IOobject&, const Mesh&, const Foam::dictionary&) [with Type = double, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh, Foam::GeometricField<Type, PatchField, GeoMesh>::Mesh = Foam::fvMesh]
/opt/openfoam211/src/OpenFOAM/lnInclude/GeometricField.C:393:1: note:  candidate expects 3 arguments, 0 provided
/opt/openfoam211/src/OpenFOAM/lnInclude/GeometricField.C:353:1: note: Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField(const Foam::IOobject&, const Mesh&) [with Type = double, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh, Foam::GeometricField<Type, PatchField, GeoMesh>::Mesh = Foam::fvMesh]
/opt/openfoam211/src/OpenFOAM/lnInclude/GeometricField.C:353:1: note:  candidate expects 2 arguments, 0 provided
/opt/openfoam211/src/OpenFOAM/lnInclude/GeometricField.C:326:1: note: Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField(const Foam::IOobject&, const Mesh&, const Foam::dimensionSet&, const Foam::Field<TypeR>&, const Foam::PtrList<PatchField<Type> >&) [with Type = double, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh, Foam::GeometricField<Type, PatchField, GeoMesh>::Mesh = Foam::fvMesh]
/opt/openfoam211/src/OpenFOAM/lnInclude/GeometricField.C:326:1: note:  candidate expects 5 arguments, 0 provided
/opt/openfoam211/src/OpenFOAM/lnInclude/GeometricField.C:296:1: note: Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField(const Foam::IOobject&, const Mesh&, const Foam::dimensioned<Form>&, const wordList&, const wordList&) [with Type = double, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh, Foam::GeometricField<Type, PatchField, GeoMesh>::Mesh = Foam::fvMesh, Foam::wordList = Foam::List<Foam::word>]
/opt/openfoam211/src/OpenFOAM/lnInclude/GeometricField.C:296:1: note:  candidate expects 5 arguments, 0 provided
/opt/openfoam211/src/OpenFOAM/lnInclude/GeometricField.C:267:1: note: Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField(const Foam::IOobject&, const Mesh&, const Foam::dimensioned<Form>&, const Foam::word&) [with Type = double, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh, Foam::GeometricField<Type, PatchField, GeoMesh>::Mesh = Foam::fvMesh]
/opt/openfoam211/src/OpenFOAM/lnInclude/GeometricField.C:267:1: note:  candidate expects 4 arguments, 0 provided
/opt/openfoam211/src/OpenFOAM/lnInclude/GeometricField.C:239:1: note: Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField(const Foam::IOobject&, const Mesh&, const Foam::dimensionSet&, const wordList&, const wordList&) [with Type = double, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh, Foam::GeometricField<Type, PatchField, GeoMesh>::Mesh = Foam::fvMesh, Foam::wordList = Foam::List<Foam::word>]
/opt/openfoam211/src/OpenFOAM/lnInclude/GeometricField.C:239:1: note:  candidate expects 5 arguments, 0 provided
/opt/openfoam211/src/OpenFOAM/lnInclude/GeometricField.C:209:1: note: Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField(const Foam::IOobject&, const Mesh&, const Foam::dimensionSet&, const Foam::word&) [with Type = double, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh, Foam::GeometricField<Type, PatchField, GeoMesh>::Mesh = Foam::fvMesh]
/opt/openfoam211/src/OpenFOAM/lnInclude/GeometricField.C:209:1: note:  candidate expects 4 arguments, 0 provided
make: *** [Make/linux64GccDPOpt/myScalarTransportFoam.o] Error 1

Any assistance would be greatly appreciated!

mkraposhin February 16, 2013 12:54

1 Attachment(s)
Hello, You made some mistakes:

1) You declared array of volScalarField - but List<template A> of A-template needs default constructor for A class, which is forbidden for volScalarField (A == volScalarField)
2) In the init and solution loop You are using reference assignment - wall variables will reference only to "T" field

Solution - List of Pointers - List<autoPtr<volScalarField> >, i made easy example for laplacianFoam, You can use it to change Your own solver:

createFields.H:
Code:

    Info<< "Reading field T\n" << endl;
   
    label N = 2;
   
    List<autoPtr<volScalarField> > TiPtr (N);
   
    forAll (TiPtr, iField)
    {

        word nameTi ("T" + name(iField));

        TiPtr[iField].reset
        (
            new volScalarField
            (
                IOobject
                (
                    nameTi,
                    runTime.timeName(),
                    mesh,
                    IOobject::MUST_READ,
                    IOobject::AUTO_WRITE
                ),
                mesh
            )
        );

    }


    volScalarField T
    (
        IOobject
        (
            "T",
            runTime.timeName(),
            mesh,
            IOobject::MUST_READ,
            IOobject::AUTO_WRITE
        ),
        mesh
    );


    Info<< "Reading transportProperties\n" << endl;

    IOdictionary transportProperties
    (
        IOobject
        (
            "transportProperties",
            runTime.constant(),
            mesh,
            IOobject::MUST_READ_IF_MODIFIED,
            IOobject::NO_WRITE
        )
    );


    Info<< "Reading diffusivity DT\n" << endl;

    dimensionedScalar DT
    (
        transportProperties.lookup("DT")
    );

myLaplacianFoam.C
Code:


#include "fvCFD.H"
#include "simpleControl.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

int main(int argc, char *argv[])
{
    #include "setRootCase.H"

    #include "createTime.H"
    #include "createMesh.H"
    #include "createFields.H"

    simpleControl simple(mesh);

    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

    Info<< "\nCalculating temperature distribution\n" << endl;

    while (simple.loop())
    {
        Info<< "Time = " << runTime.timeName() << nl << endl;

        while (simple.correctNonOrthogonal())
        {
            solve
            (
                fvm::ddt(T) - fvm::laplacian(DT, T)
            );
           
            forAll(TiPtr, iField)
            {
                volScalarField& Ti = TiPtr[iField]();
                solve
                (
                    fvm::ddt(Ti) - fvm::laplacian(DT,Ti)
                );
            }

        }

        #include "write.H"

        Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
            << "  ClockTime = " << runTime.elapsedClockTime() << " s"
            << nl << endl;
    }

    Info<< "End\n" << endl;

    return 0;
}

And here you can find code example, tutorial you can take from flange example (don't forget to create field T0 and T1)

vbchris February 16, 2013 16:57

Thanks,

I modified your solution a bit and used ptrlist<>.
Do you have any comments on this method?
Compiles fine, I will modify it later to read in from multiple files.

Code:

PtrList<volScalarField> PopBal(bin_count);

for(count = 0; count < bin_count; count++)
{
    PopBal.set
    (
        count,
        new volScalarField
    (
            IOobject
            (
                "T",
                runTime.timeName(),
                mesh,
                IOobject::MUST_READ,
                IOobject::AUTO_WRITE
            ),
            mesh
        )
    );
}


mkraposhin February 17, 2013 05:24

PtrList is the same as List<volScalarField* >, which holds pure (hardware) pointers,
List<autoPtr<volScalarField> > holds list of software pointers (autoPtr<>), which is safer, for me,

for different filenames, you can substitute string:
word nameTi ("fieldName" + name(fieldCounter))

l_r_mcglashan February 18, 2013 05:34

Quote:

Originally Posted by mkraposhin (Post 408259)
PtrList is the same as List<volScalarField* >, which holds pure (hardware) pointers,
List<autoPtr<volScalarField> > holds list of software pointers (autoPtr<>), which is safer, for me

You cannot use copy or assignment on a List of autoPtr though.

bubbleToes June 5, 2013 10:13

question about creating a list
 
Hello,

I am writing here because it is one of the only threads where Lists are mentioned.

I want to create a List out of a class I made, ie. I want every object that I add or remove in my main program to be sorted out in a list in order to be able to apply the methods I have created on every single object.

To be more specific, my class is called "Vessels" and one of the methods I use calculates the value of blood flow in a given vessel.

My main program calculates pressure distribution and blood flow in my computational domain, and I want to be able to add as much arteries & veins as I like without having to calculate for everyone single one of them the corresponding blood flow.


I'm new to OF & C++ and would really appreciate your help. Thanks!


All times are GMT -4. The time now is 18:57.