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

Making a PtrList<PtrList<volScalarField> > or making a square matrix volScalarField

Register Blogs Community New Posts Updated Threads Search

Like Tree4Likes
  • 1 Post By marupio
  • 3 Post By ChasingNeutrons

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 29, 2016, 13:10
Default Making a PtrList<PtrList<volScalarField> > or making a square matrix volScalarField
  #1
New Member
 
Paul
Join Date: Jun 2016
Posts: 21
Rep Power: 10
ChasingNeutrons is on a distinguished road
Hi guys, I'm trying to create a volScalarField for a square matrix of values. Specifically, in a nuclear reactor physics context, I'm trying to make some convenient data structure to hold the scattering cross-section matrix which is a property of a given material and for g energy groups will have g^2 entries.

Having had great success and finding much convenience in storing other properties in the form of PtrList<volScalarField> my first inclination is to attempt to extend this method to a second dimension. For example, for the property sigmaT I've written in createFields.H:

Code:
PtrList<volScalarField> sigmaT(energyGroups);
forAll(sigmaT, i)
{
    sigmaT.set
    (
        i,
        new volScalarField
        (
            IOobject
            (
                "sigmaT"+i,
                runTime.timeName(),
                mesh,
                IOobject::NO_READ,
                IOobject::NO_WRITE
            ),
            mesh,
            dimensionedScalar("", dimensionSet(0,-1,0,0,0,0,0), 0.0),
            zeroGradientFvPatchScalarField::typeName
        )
    );
}
For my matrix of scattering values therefore I've tried:

Code:
PtrList<volScalarField> sigmaTo(energyGroups);
forAll(sigmaTo, energyJ)
{
    sigmaTo.set
    (
        energyJ,
        new volScalarField
        (
            IOobject
            (
                "sigmaTo"+Foam::name(energyJ),
                runTime.timeName(),
                mesh,
                IOobject::NO_READ,
                IOobject::NO_WRITE
            ),
            mesh,
            dimensionedScalar("", dimensionSet(0,-1,0,0,0,0,0), 0.0),
            zeroGradientFvPatchScalarField::typeName
        )
    );
}


PtrList<PtrList<volScalarField> > sigmaFrom(energyGroups);
forAll(sigmaFrom,energyI)
{    
    sigmaFrom.set(energyI,sigmaTo);
}
Unfortunately, this results in the following error:

Code:
In file included from /opt/openfoam30/src/OpenFOAM/lnInclude/tmp.H:139:0,
                 from /opt/openfoam30/src/OpenFOAM/lnInclude/PtrListI.H:27,
                 from /opt/openfoam30/src/OpenFOAM/lnInclude/PtrList.H:436,
                 from /opt/openfoam30/src/OpenFOAM/lnInclude/List.C:30,
                 from /opt/openfoam30/src/OpenFOAM/lnInclude/List.H:259,
                 from /opt/openfoam30/src/OpenFOAM/lnInclude/labelList.H:48,
                 from /opt/openfoam30/src/OpenFOAM/lnInclude/UPstream.H:42,
                 from /opt/openfoam30/src/OpenFOAM/lnInclude/Pstream.H:42,
                 from /opt/openfoam30/src/OpenFOAM/lnInclude/parRun.H:35,
                 from /opt/openfoam30/src/finiteVolume/lnInclude/fvCFD.H:4,
                 from MOCMEMRsolver.C:35:
/opt/openfoam30/src/OpenFOAM/lnInclude/tmpI.H: In instantiation of ‘Foam::tmp<T>::~tmp() [with T = Foam::PtrList<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> >]’:
createFields.H:241:31:   required from here
/opt/openfoam30/src/OpenFOAM/lnInclude/tmpI.H:111:9: error: ‘class Foam::PtrList<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> >’ has no member named ‘okToDelete’
         if (ptr_->okToDelete())
         ^
/opt/openfoam30/src/OpenFOAM/lnInclude/tmpI.H:118:13: error: ‘class Foam::PtrList<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> >’ has no member named ‘operator--’
             ptr_->operator--();
             ^
/opt/openfoam30/src/OpenFOAM/lnInclude/tmpI.H: In instantiation of ‘T* Foam::tmp<T>::ptr() const [with T = Foam::PtrList<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> >]’:
/opt/openfoam30/src/OpenFOAM/lnInclude/PtrListI.H:140:47:   required from ‘Foam::autoPtr<T> Foam::PtrList<T>::set(Foam::label, const Foam::tmp<T>&) [with T = Foam::PtrList<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> >; Foam::label = int]’
createFields.H:241:31:   required from here
/opt/openfoam30/src/OpenFOAM/lnInclude/tmpI.H:162:10: error: ‘class Foam::PtrList<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> >’ has no member named ‘resetRefCount’
          ptr->resetRefCount();
          ^
My suspicion is that I've done something very silly by not generating energyGroup different instances of sigmaTo. I ask your patience as I'm still far from competent in either C++ or OpenFOAM! If anyone can suggest a relatively painless fix it would be very much appreciated.

Cheers.
ChasingNeutrons is offline   Reply With Quote

Old   June 29, 2016, 16:43
Default
  #2
Senior Member
 
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 22
marupio is on a distinguished road
Look at the VectorN library in foam-extend. It has been used specifically for nuclear reactions before. See Ivor Clifford's work.
hua1015 likes this.
__________________
~~~
Follow me on twitter @DavidGaden
marupio is offline   Reply With Quote

Old   June 30, 2016, 07:27
Default
  #3
New Member
 
Paul
Join Date: Jun 2016
Posts: 21
Rep Power: 10
ChasingNeutrons is on a distinguished road
Thanks David - I'm actually modifying and gutting one of the descendants of Ivor Clifford's work, a coupled thermal-hydraulics, neutronics, mechanics code called GeN-Foam (although I'm only interested in the neutronics at the moment). I'm trying to stick quite close to its format in the hope of potentially being able to replace its neutronics solver with my own in the future, hence the use of PtrLists.

Unfortunately, it seems to be the case that its implementation of scattering isn't entirely compatible with the method I'm using (or, at least, it would be quite inefficient to use it). If I don't have any luck soon, however, then I'll definitely take a look at foam-extend. Cheers.
ChasingNeutrons is offline   Reply With Quote

Old   June 30, 2016, 09:50
Default
  #4
New Member
 
Paul
Join Date: Jun 2016
Posts: 21
Rep Power: 10
ChasingNeutrons is on a distinguished road
Managed to get it working exactly as desired. More than anything the problem was getting the right syntax:

Code:
Info<<"sigmaS\n" << endl;
PtrList<PtrList<volScalarField> > sigmaS(energyGroups);
forAll(sigmaS, energyI)
{
    sigmaS.set(energyI, new PtrList<volScalarField>(energyGroups));
    forAll(sigmaS[energyI], energyJ)
    {
        sigmaS[energyI].set
        (
            energyJ,
            new volScalarField
            (
                IOobject
                (
                    "sigmaS"+Foam::name(energyI)+Foam::name(energyJ),
                    runTime.timeName(),
                    mesh,
                    IOobject::NO_READ,
                    IOobject::NO_WRITE
                ),
                mesh,
                dimensionedScalar("", dimensionSet(0,-1,0,0,0,0,0), 0.0),
                zeroGradientFvPatchScalarField::typeName
            )
        );
    }
}
I was helped along by a previous post here: http://www.cfd-online.com/Forums/ope...ist-usage.html
jherb, Ramzy1990 and parthigcar like this.
ChasingNeutrons is offline   Reply With Quote

Old   July 6, 2016, 20:45
Default
  #5
Member
 
Jerry
Join Date: Oct 2013
Location: Salt Lake City, UT, USA
Posts: 52
Rep Power: 13
Jerryfan is on a distinguished road
Hi,


This is a very good example of using PtrList. I have a simpler question in this case, why do you choose PtrList<PtrList<>> instead of ListList<>? Is there any reason that we cann't use the normal list?
Jerryfan 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
[swak4Foam] funkyDoCalc with OF2.3 massflow NiFl OpenFOAM Community Contributions 14 November 25, 2020 04:30
[Other] How to use finite area method in official OpenFOAM 2.2.0? Detian Liu OpenFOAM Meshing & Mesh Conversion 4 November 3, 2015 04:04
[foam-extend.org] problem when installing foam-extend-1.6 Thomas pan OpenFOAM Installation 7 September 9, 2015 22:53
writing execFlowFunctionObjects immortality OpenFOAM Post-Processing 30 September 15, 2013 07:16
DecomposePar links against liblamso0 with OpenMPI jens_klostermann OpenFOAM Bugs 11 June 28, 2007 18:51


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