예제 #1
0
void ExporterEnsight<MeshType>::caseVariableSection (std::ofstream& casef)
{
    ASSERT (casef.good(), "There is an error while writing to file" );
    casef << "VARIABLE\n";
    std::string aux, str;
    for (typename super::dataVectorIterator_Type i = this->M_dataVector.begin(); i != this->M_dataVector.end(); ++i)
    {
        if ( i->regime() == exporterData_Type::SteadyRegime )
        {
            str = "";
        }
        else
        {
            std::string stars (".");
            for (UInt cc (0); cc < this->M_timeIndexWidth; ++cc)
            {
                stars += "*";
            }

            str = stars;
        }
        aux = i->variableName() + " " + super::M_prefix + "_" + i->variableName();
        switch ( i->fieldType() )
        {
            case exporterData_Type::ScalarField:
                ASSERT (casef.good(), "There is an error while writing to file" );
                casef << "scalar per node: 1 " +  aux + str << this->M_me << ".scl\n";
                break;
            case exporterData_Type::VectorField:
                ASSERT (casef.good(), "There is an error while writing to file" );
                casef << "vector per node: 1 " +  aux +  str << this->M_me << ".vct\n";
                break;
        }
    }
}
예제 #2
0
ExporterVTK<MeshType>::~ExporterVTK()
{
    // Right before dying, the exporter will write a VTK collection in a pvd file
    // This allows ParaView to load a single file for the entire time series,
    // and each frame will be associated to the correct time value.
    // This will happen only if at least one time step was actually post-processed
    if ( this->M_timeSteps.size() )
    {
        std::stringstream buffer ("");

        // a unique time collection is produced by the leader process
        if (this->M_procId == 0)
        {
            for (typename super::dataVectorIterator_Type iData = this->M_dataVector.begin();
                    iData != this->M_dataVector.end(); ++iData)
            {
                composeVTKCollection ( iData->variableName(), buffer );

                std::string filename ( this->M_postDir + this->M_prefix + "_" + iData->variableName() + ".pvd" );
                std::ofstream vtkCollectionFile;
                vtkCollectionFile.open ( filename.c_str() );
                ASSERT (vtkCollectionFile.is_open(), "There is an error while opening " + filename );
                ASSERT (vtkCollectionFile.good(), "There is an error while writing to " + filename );
                vtkCollectionFile << buffer.str();
                vtkCollectionFile.close();

                buffer.str ("");
            }
        }
    }

}
예제 #3
0
void ExporterEnsight<MeshType>::postProcess (const Real& time)
{
    // writing the geo file and the list of global IDs, but only upon the first instance
    if ( M_firstTimeStep )
    {
        if (!this->M_multimesh)
        {
            writeAsciiGeometry ( this->M_postDir + this->M_prefix + this->M_me + ".geo" );
        }

        writeGlobalIDs ( this->M_postDir + super::M_prefix + "_globalIDs" +
                         this->M_me + ".scl" );

        M_firstTimeStep = false;
    }
    // prepare the file postfix
    this->computePostfix();

    // the postfix will be full of stars, if this time step is not going to generate a snapshot
    std::size_t found ( this->M_postfix.find ( "*" ) );
    if ( found == std::string::npos )
    {
        if (!this->M_procId)
        {
            std::cout << "  X-  ExporterEnsight post-processing ...        " << std::flush;
        }
        LifeChrono chrono;
        chrono.start();
        for (typename super::dataVectorIterator_Type i = this->M_dataVector.begin();
                i != this->M_dataVector.end(); ++i)
        {
            // the "regime" attribute needs to be valid
            if ( i->regime() != exporterData_Type::NullRegime )
            {
                writeAscii (*i);
            }
            // if the solution is steady, we do not need to export it at each time step
            if (i->regime() == exporterData_Type::SteadyRegime)
            {
                i->setRegime ( exporterData_Type::NullRegime );
            }
        }
        // write an updated case file
        writeCase (time);

        // write an updated geo file, if needed
        if (this->M_multimesh)
        {
            writeAsciiGeometry ( this->M_postDir + this->M_prefix + this->M_postfix + this->M_me + ".geo" );
        }
        chrono.stop();
        if (!this->M_procId)
        {
            std::cout << "      done in " << chrono.diff() << " s." << std::endl;
        }
    }

}
예제 #4
0
void ExporterVTK<MeshType>::postProcess (const Real& time)
{
    // typedef std::list< ExporterData >::iterator Iterator;

    this->computePostfix();

    std::size_t found ( this->M_postfix.find ( "*" ) );
    if ( found == string::npos )
    {
        if (this->M_procId == 0)
        {
            std::cout << "  X-  ExporterVTK post-processing" << std::flush;
        }

        LifeChrono chrono;
        chrono.start();

        this->M_timeSteps.push_back (time);

        for (typename super::dataVectorIterator_Type iData = this->M_dataVector.begin();
                iData != this->M_dataVector.end(); ++iData)
        {
            std::ofstream vtkFile;
            std::stringstream buffer ("");

            // a unique PVTU file + a time collection is produced by the leader process
            if (this->M_procId == 0)
            {
                composePVTUStream (*iData, buffer);

                std::string vtkPFileName ( this->M_prefix + "_" + iData->variableName() +
                                           this->M_postfix + ".pvtu" );
                std::string vtkPFileNameWithDir (this->M_postDir + vtkPFileName);

                std::ofstream vtkPFile;
                vtkPFile.open ( vtkPFileNameWithDir.c_str() );
                ASSERT (vtkPFile.is_open(), "There is an error while opening " + vtkPFileName );
                ASSERT (vtkPFile.good(), "There is an error while writing to " + vtkPFileName );
                vtkPFile << buffer.str();
                vtkPFile.close();

                buffer.str ("");

                this->M_pvtuFiles[iData->variableName()].push_back (vtkPFileName);

            }


            // redundant. should be done just the first time
            std::map<UInt, UInt> ltgPointsMap, gtlPointsMap;
            std::vector<Vector> pointsCoords;
            createPointsMaps ( iData->feSpacePtr(), gtlPointsMap, ltgPointsMap, pointsCoords );

            composeVTUHeaderStream ( gtlPointsMap.size(), buffer );
            composeVTUGeoStream ( iData->feSpacePtr(), gtlPointsMap, pointsCoords, buffer );

            composeTypeDataHeaderStream (iData->where(), buffer);
            composeDataArrayStream (*iData, ltgPointsMap, buffer);
            composeTypeDataFooterStream (iData->where(), buffer);

            composeVTUFooterStream ( buffer );

            // each process writes its own file
            std::string filename ( this->M_postDir + this->M_prefix + "_" + iData->variableName() +
                                   this->M_postfix + "." + this->M_procId + ".vtu" );
            vtkFile.open ( filename.c_str() );
            ASSERT (vtkFile.is_open(), "There is an error while opening " + filename );
            ASSERT (vtkFile.good(), "There is an error while writing to " + filename );
            vtkFile << buffer.str();
            vtkFile.close();

            buffer.str ("");

        }
        chrono.stop();
        if (!this->M_procId)
        {
            std::cout << "...done in " << chrono.diff() << " s." << std::endl;
        }
    }
}