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

Problem with writeIntegratedHeader functionObject in parallel processing

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 16, 2021, 07:12
Default Problem with writeIntegratedHeader functionObject in parallel processing
  #1
Member
 
Join Date: Feb 2020
Posts: 90
Rep Power: 6
Shibi is on a distinguished road
Hello to all,

I am doing a functionObject (FO) for analyzing some data in OpenFoam . I took the forceCoeffs FO as a starting point.

However, I am facing one difficulty. When running the FO in serial it gives me no problems, but when running the simulation in parallel I get an error saying:
Code:
[1] 
[1] --> FOAM FATAL ERROR: (openfoam-2012)
[1] unallocated autoPtr of type N4Foam8OFstreamE
[1] 
[1]     From T& Foam::autoPtr<T>::operator*() [with T = Foam::OFstream]
[1]     in file /home/pc/OpenFOAM/OpenFOAM-v2012/src/OpenFOAM/lnInclude/autoPtrI.H at line 154.
[1] 
FOAM parallel run aborting
[1]
The script I am currently using, only writes a file called "coefficient.dat" to the post postProcessing folder.

The script:
myForceCoefs.H

Code:
#ifndef functionObjects_myForceCoeffs_H
#define functionObjects_myForceCoeffs_H

#include "fvMeshFunctionObject.H"
#include "writeFile.H"
#include "cartesianCS.H"
#include "volFieldsFwd.H"
#include "HashSet.H"
#include "Tuple2.H"
#include "OFstream.H"
#include "Switch.H"

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

namespace Foam
{
namespace functionObjects
{

/*---------------------------------------------------------------------------*\
                         Class myForceCoeffs Declaration
\*---------------------------------------------------------------------------*/

class myForceCoeffs
:
    public fvMeshFunctionObject,
    public writeFile
{
    // Private data

        // Free-stream conditions

        // File streams

            //- Integrated coefficients
            autoPtr<OFstream> coeffFilePtr_;

    // Private Member Functions

        //- No copy construct
        myForceCoeffs(const myForceCoeffs&) = delete;

        //- No copy assignment
        void operator=(const myForceCoeffs&) = delete;


protected:

    // Protected Member Functions

        //- Create the output files
        void createFiles();

        //- Write header for integrated data
        void writeIntegratedHeader(const word& header, Ostream& os) const;

        //- Write header for binned data
        void writeBinHeader(const word& header, Ostream& os) const;

        //- Write integrated data
        void writeIntegratedData
        (
            const word& title,
            const List<Field<scalar>>& coeff
        ) const;

        //- Write binned data
        void writeBinData(const List<Field<scalar>> coeffs, Ostream& os) const;


public:

    //- Runtime type information
    TypeName("myForceCoeffs");


    // Constructors

        //- Construct from Time and dictionary
        myForceCoeffs
        (
            const word& name,
            const Time& runTime,
            const dictionary&,
            const bool readFields = true
        );


    //- Destructor
    virtual ~myForceCoeffs() = default;


    // Member Functions

        //- Read the forces data
        virtual bool read(const dictionary&);

        //- Execute
        virtual bool execute();

        //- Write the forces
        virtual bool write();
};


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

} // End namespace functionObjects
} // End namespace Foam

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

#endif

// ************************************************************************* //
myForceCoefs.C
Code:
#include "myForceCoeffs.H"
#include "dictionary.H"
#include "Time.H"
#include "Pstream.H"
#include "IOmanip.H"
#include "fvMesh.H"
#include "dimensionedTypes.H"
#include "volFields.H"
#include "addToRunTimeSelectionTable.H"

// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

namespace Foam
{
namespace functionObjects
{
    defineTypeNameAndDebug(myForceCoeffs, 0);
    addToRunTimeSelectionTable(functionObject, myForceCoeffs, dictionary);
}
}


// * * * * * * * * * * * * Protected Member Functions  * * * * * * * * * * * //

void Foam::functionObjects::myForceCoeffs::createFiles()
{
    // Note: Only possible to create bin files after bins have been initialised

    if (writeToFile() && !coeffFilePtr_)
    {
        coeffFilePtr_ = createFile("coefficient");
        writeIntegratedHeader("Coefficients", coeffFilePtr_());
    }
}


void Foam::functionObjects::myForceCoeffs::writeIntegratedHeader
(
    const word& header,
    Ostream& os
) const
{
    writeHeader(os, "Force coefficients");
    writeHeader(os, "");
    writeCommented(os, "Time");
    writeTabbed(os, "Cd");
    os  << endl;
}


void Foam::functionObjects::myForceCoeffs::writeBinHeader
(
    const word& header,
    Ostream& os
) const
{

}


void Foam::functionObjects::myForceCoeffs::writeIntegratedData
(
    const word& title,
    const List<Field<scalar>>& coeff
) const
{
}


void Foam::functionObjects::myForceCoeffs::writeBinData
(
    const List<Field<scalar>> coeffs,
    Ostream& os
) const
{

}


// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //

Foam::functionObjects::myForceCoeffs::myForceCoeffs
(
    const word& name,
    const Time& runTime,
    const dictionary& dict,
    const bool readFields
)
:
    fvMeshFunctionObject(name, runTime, dict),
    writeFile(mesh_, name),
    coeffFilePtr_()
{
    if (readFields)
    {
        read(dict);
        Info<< endl;
    }
}


// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //

bool Foam::functionObjects::myForceCoeffs::read(const dictionary& dict)
{
    return true;
}


bool Foam::functionObjects::myForceCoeffs::execute()
{
    createFiles();

    Info << "I am being executed" << endl;
    return true;
}


bool Foam::functionObjects::myForceCoeffs::write()
{
    return true;
}
I was able to track the problem to the line
Code:
writeIntegratedHeader("Coefficients", coeffFilePtr_())
However, I cannot yet understand what pointer is not allocated.


How really appreciate some help!


Best Regards
Shibi is offline   Reply With Quote

Old   May 16, 2021, 15:44
Default
  #2
Member
 
Join Date: Feb 2020
Posts: 90
Rep Power: 6
Shibi is on a distinguished road
This is solved.

Had to change the createFiles function to be:

Code:
void Foam::functionObjects::myForceCoeffs::createFiles()
{
  if (Pstream::master())
  {
        if (writeToFile() && !coeffFilePtr_)
        {
            coeffFilePtr_ = createFile("coefficient");
            writeIntegratedHeader("Coefficients", coeffFilePtr_());
        }
  }
}
Shibi 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
Problem in parallel processing [Process affinity not being set] Roh FLUENT 4 October 26, 2023 03:42
simpleFoam parallel AndrewMortimer OpenFOAM Running, Solving & CFD 12 August 7, 2015 18:45
Temperature Problem in Parallel Processing pdp.aero SU2 9 July 27, 2014 22:11
problem with parallel processing keng FLUENT 4 June 14, 2013 23:34
problem parallel processing (meshSearch, openMPI) FabienF OpenFOAM 0 September 10, 2012 04:23


All times are GMT -4. The time now is 08:32.