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

Multiple volScalarFields using List<volScalarField>

Register Blogs Community New Posts Updated Threads Search

Like Tree19Likes
  • 15 Post By mkraposhin
  • 1 Post By vbchris
  • 1 Post By mkraposhin
  • 1 Post By l_r_mcglashan
  • 1 Post By atoof

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 15, 2013, 18:47
Default Multiple volScalarFields using List<volScalarField>
  #1
Member
 
Chris L
Join Date: Sep 2012
Posts: 53
Rep Power: 14
vbchris is on a distinguished road
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!
vbchris is offline   Reply With Quote

Old   February 16, 2013, 13:54
Default
  #2
Senior Member
 
mkraposhin's Avatar
 
Matvey Kraposhin
Join Date: Mar 2009
Location: Moscow, Russian Federation
Posts: 355
Rep Power: 21
mkraposhin is on a distinguished road
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)
Attached Files
File Type: gz myLaplacianFoam.tar.gz (1.8 KB, 101 views)
mkraposhin is offline   Reply With Quote

Old   February 16, 2013, 17:57
Default
  #3
Member
 
Chris L
Join Date: Sep 2012
Posts: 53
Rep Power: 14
vbchris is on a distinguished road
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
        )
    );
}
charryzzz likes this.
vbchris is offline   Reply With Quote

Old   February 17, 2013, 06:24
Default
  #4
Senior Member
 
mkraposhin's Avatar
 
Matvey Kraposhin
Join Date: Mar 2009
Location: Moscow, Russian Federation
Posts: 355
Rep Power: 21
mkraposhin is on a distinguished road
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))
Ramzy1990 likes this.
mkraposhin is offline   Reply With Quote

Old   February 18, 2013, 06:34
Default
  #5
Senior Member
 
Laurence R. McGlashan
Join Date: Mar 2009
Posts: 370
Rep Power: 23
l_r_mcglashan will become famous soon enough
Quote:
Originally Posted by mkraposhin View Post
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.
Ramzy1990 likes this.
__________________
Laurence R. McGlashan :: Website
l_r_mcglashan is offline   Reply With Quote

Old   June 5, 2013, 11:13
Default question about creating a list
  #6
New Member
 
Farah Yasmina
Join Date: Mar 2013
Location: France
Posts: 2
Rep Power: 0
bubbleToes is on a distinguished road
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!
bubbleToes is offline   Reply With Quote

Old   September 14, 2014, 07:38
Default
  #7
Member
 
Hossein
Join Date: Apr 2010
Posts: 65
Rep Power: 16
atoof is on a distinguished road
Send a message via Yahoo to atoof
Quote:
Originally Posted by mkraposhin View Post
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
            )
        );

    }
Hi,
I used the following code in my new solver that based on reactingFoam OF2.1.x.
Code:
    forAll(spNames, specieI)
    { 
        word namemuIi ("muI" + name(specieI));
        muI.set
        (
        specieI,
        new volScalarField 
        (
            IOobject
            (
                namemuIi,
                runTime.timeName(),
                mesh,
                IOobject::NO_READ,
                IOobject::NO_WRITE
            ),
            dimensionedScalar("muI", dimensionSet(1, -1, -1, 0, 0, 0, 0), 2.6693E-05 * Foam::pow(composition.W(specieI) * T, 0.5)/ Foam::pow(sigmaI,2)/ om22)
        )
        );
    }
Where
Code:
PtrList<volScalarField> muI(Y.size());
, T is a volScalarField with dimension of temperature, Y is the list of species value in the domain and sigmaI is a scalar. Indeed I'm going to generate n volScalarFields, where n in the number of species.
After compiling the solver, I encounter the following error:
Code:
...
error: no matching function for call to ‘Foam::dimensioned<double>::dimensioned(const char [7], const Foam::dimensionSet&, Foam::volScalarField&)’
...
/home/mohammad/OpenFOAM/OpenFOAM-2.1.x/src/OpenFOAM/lnInclude/dimensionedType.C:68:1: note:   no known conversion for argument 3 from ‘Foam::volScalarField {aka Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>}’ to ‘double’
In file included from /home/mohammad/OpenFOAM/OpenFOAM-2.1.x/src/OpenFOAM/lnInclude/dimensionedScalar.H:38:0,
...
How can I remove the error?

Regards,

Hossein
charryzzz likes this.
atoof is offline   Reply With Quote

Reply


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
how to set periodic boundary conditions Ganesh FLUENT 15 November 18, 2020 07:09
[ICEM] Multiple edges asal ANSYS Meshing & Geometry 2 March 22, 2013 11:10
OpenFOAM static build on Cray XT5 asaijo OpenFOAM Installation 9 April 6, 2011 13:21
Multiple domain/Multiple material problems... possible or not? Amiga500 OpenFOAM 1 April 14, 2010 16:32
Multiple reference frames? Moon Siemens 0 March 4, 2003 07:32


All times are GMT -4. The time now is 06:05.