lib/io/writer.cc
/**
 ********************************************************************************************************************************************
 * \brief   Function to write solution file in HDF5 format in parallel
 *
 *          It opens a file in the output folder and all the processors write in parallel into the file
 *          Before writing however, all the data is interpolated into the cell centers for ease of post-processing.
 *
 * \param   time is a real value containing the time to be used for naming the file
 ********************************************************************************************************************************************
 */
\brief   Function to write solution file in HDF5 format in parallel
It opens a file in the output folder and all the processors write in parallel into the file
Before writing however, all the data is interpolated into the cell centers for ease of post-processing.

\param   time is a real value containing the time to be used for naming the file
\ brief Function to write solution file in HDF5 format in parallel It opens a file in the output folder and all the processors write in parallel into the file Before writing however all the data is interpolated into the cell centers for ease of post - processing . \ param time is a real value containing the time to be used for naming the file
void writer::writeSolution(real time) {
    hid_t plist_id;
    hid_t fileHandle;
    hid_t dataSet;
    herr_t status;
    std::ostringstream constFile;
    char* fileName;
    int pIndex = wFields.size() - 1;
    plist_id = H5Pcreate(H5P_FILE_ACCESS);
    H5Pset_fapl_mpio(plist_id, MPI_COMM_WORLD, MPI_INFO_NULL);
    fileName = new char[100];
    constFile.str(std::string());
    constFile << "output/Soln_" << std::fixed << std::setfill('0') << std::setw(9) << std::setprecision(4) << time << ".h5";
    strcpy(fileName, constFile.str().c_str());
    fileHandle = H5Fcreate(fileName, H5F_ACC_TRUNC, H5P_DEFAULT, plist_id);
    H5Pclose(plist_id);
    plist_id = H5Pcreate(H5P_DATASET_XFER);
    H5Pset_dxpl_mpio(plist_id, H5FD_MPIO_COLLECTIVE);
    for (unsigned int i=0; i < wFields.size(); i++) {
#ifdef PLANAR
        fieldData.resize(blitz::TinyVector<int, 2>(localSize[pIndex](0), localSize[pIndex](2)));
#else
        fieldData.resize(localSize[pIndex]);
#endif
        interpolateData(wFields[i]);
        dataSet = H5Dcreate2(fileHandle, wFields[i].fieldName.c_str(), H5T_NATIVE_REAL, targetDSpace[pIndex], H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
        status = H5Dwrite(dataSet, H5T_NATIVE_REAL, sourceDSpace[pIndex], targetDSpace[pIndex], plist_id, fieldData.dataFirst());
        if (status) {
            if (mesh.rankData.rank == 0) {
                std::cout << "Error in writing output to HDF file. Aborting" << std::endl;
            }
            MPI_Finalize();
            exit(0);
        }
        H5Dclose(dataSet);
    }
    H5Pclose(plist_id);
    H5Fclose(fileHandle);
    delete fileName;
}
void writer :: writeSolution ( real time ) { hid_t plist_id ; hid_t fileHandle ; hid_t dataSet ; herr_t status ; std :: ostringstream constFile ; char * fileName ; int pIndex = wFields . size ( ) - 1 ; plist_id = H5Pcreate ( H5P_FILE_ACCESS ) ; H5Pset_fapl_mpio ( plist_id , MPI_COMM_WORLD , MPI_INFO_NULL ) ; fileName = new char [ 100 ] ; constFile . str ( std :: string ( ) ) ; constFile << " " << std :: fixed << std :: setfill ( ' ' ) << std :: setw ( 9 ) << std :: setprecision ( 4 ) << time << " " ; strcpy ( fileName , constFile . str ( ) . c_str ( ) ) ; fileHandle = H5Fcreate ( fileName , H5F_ACC_TRUNC , H5P_DEFAULT , plist_id ) ; H5Pclose ( plist_id ) ; plist_id = H5Pcreate ( H5P_DATASET_XFER ) ; H5Pset_dxpl_mpio ( plist_id , H5FD_MPIO_COLLECTIVE ) ; for ( unsigned int i = 0 ; i < wFields . size ( ) ; i ++ ) { #ifdef PLANAR fieldData . resize ( blitz :: TinyVector < int , 2 > ( localSize [ pIndex ] ( 0 ) , localSize [ pIndex ] ( 2 ) ) ) ; #else fieldData . resize ( localSize [ pIndex ] ) ; #endif interpolateData ( wFields [ i ] ) ; dataSet = H5Dcreate2 ( fileHandle , wFields [ i ] . fieldName . c_str ( ) , H5T_NATIVE_REAL , targetDSpace [ pIndex ] , H5P_DEFAULT , H5P_DEFAULT , H5P_DEFAULT ) ; status = H5Dwrite ( dataSet , H5T_NATIVE_REAL , sourceDSpace [ pIndex ] , targetDSpace [ pIndex ] , plist_id , fieldData . dataFirst ( ) ) ; if ( status ) { if ( mesh . rankData . rank == 0 ) { std :: cout << " " << std :: endl ; } MPI_Finalize ( ) ; exit ( 0 ) ; } H5Dclose ( dataSet ) ; } H5Pclose ( plist_id ) ; H5Fclose ( fileHandle ) ; delete fileName ; }
\brief   Function to write solution file in HDF5 format in parallel
          It opens a file in the output folder and all the processors write in parallel into the file
          Before writing however, all the data is interpolated into the cell centers for ease of post-processing.
\ brief Function to write solution file in HDF5 format in parallel It opens a file in the output folder and all the processors write in parallel into the file Before writing however all the data is interpolated into the cell centers for ease of post - processing .
// The last entry in wFields is P, which is cell centered. Hence the MPI-IO data-structures associated with this index is used for file writing // Create a property list for collectively opening a file by all processors // Generate the filename corresponding to the solution file // First create a file handle with the path to the output file // Close the property list for later reuse // Create a property list to use collective data write //Write data after first interpolating them to cell centers // Create the dataset *for the file*, linking it to the file handle. // Correspondingly, it will use the *core* dataspace, as only the core has to be written excluding the pads // Write the dataset. Most important thing to note is that the 3rd and 4th arguments represent the *source* and *destination* dataspaces. // The source here is the sourceDSpace pointing to the memory buffer. Note that its view has been adjusted using hyperslab. // The destination is the targetDSpace. Though the targetDSpace is smaller than the sourceDSpace, // only the appropriate hyperslab within the sourceDSpace is transferred to the destination. // Close dataset for reuse // CLOSE/RELEASE RESOURCES