|
[Sponsors] |
Problem with writeIntegratedHeader functionObject in parallel processing |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
May 16, 2021, 07:12 |
Problem with writeIntegratedHeader functionObject in parallel processing
|
#1 |
Member
Join Date: Feb 2020
Posts: 90
Rep Power: 6 |
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: 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 // ************************************************************************* // 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; } Code:
writeIntegratedHeader("Coefficients", coeffFilePtr_()) How really appreciate some help! Best Regards |
|
May 16, 2021, 15:44 |
|
#2 |
Member
Join Date: Feb 2020
Posts: 90
Rep Power: 6 |
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_()); } } } |
|
Thread Tools | Search this Thread |
Display Modes | |
|
|
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 |