コード例 #1
0
void ensightParticlePositions
(
    const Foam::fvMesh& mesh,
    const Foam::fileName& postProcPath,
    const Foam::word& timeFile,
    const Foam::word& cloudName,
    const bool dataExists
)
{
    if (dataExists)
    {
        Info<< "Converting cloud " << cloudName << " positions" <<  endl;
    }
    else
    {
        Info<< "Creating empty cloud " << cloudName << " positions" << endl;
    }

    const Time& runTime = mesh.time();

    fileName ensightFileName(timeFile + "." + cloudName);
    OFstream ensightFile
    (
        postProcPath/ensightFileName,
        ios_base::out|ios_base::trunc,
        runTime.writeFormat(),
        runTime.writeVersion(),
        runTime.writeCompression()
    );

    // Output header
    ensightFile
        << cloudName.c_str() << nl
        << "particle coordinates" << nl;

    if (dataExists)
    {
        Cloud<passiveParticle> parcels(mesh, cloudName, false);

        // Set Format
        ensightFile.setf(ios_base::scientific, ios_base::floatfield);
        ensightFile.precision(5);

        ensightFile<< setw(8) << parcels.size() << nl;

        label nParcels = 0;

        // Output positions
        forAllConstIter(Cloud<passiveParticle>, parcels, elmnt)
        {
            const vector& p = elmnt().position();

            ensightFile
                << setw(8) << ++nParcels
                << setw(12) << p.x() << setw(12) << p.y() << setw(12) << p.z()
                << nl;
        }
    }
    else
    {
コード例 #2
0
void ensightCloudField
(
    const Foam::IOobject& fieldObject,
    const Foam::fileName& postProcPath,
    const Foam::word& prepend,
    const Foam::label timeIndex,
    const Foam::word& cloudName,
    Foam::Ostream& ensightCaseFile,
    const bool dataExists
)
{
    if (dataExists)
    {
        Info<< "Converting cloud " << cloudName
            << " field " << fieldObject.name() << endl;
    }
    else
    {
        Info<< "Creating empty cloud " << cloudName
            << " field "  << fieldObject.name() << endl;
    }

    word timeFile = prepend + itoa(timeIndex);

    const Time& runTime = fieldObject.time();

    if (timeIndex == 0 && Pstream::master())
    {
        ensightCaseFile
            << pTraits<Type>::typeName << " per measured node:      1       ";
        ensightCaseFile.width(15);
        ensightCaseFile.setf(ios_base::left);
        ensightCaseFile
            << ("c" + fieldObject.name()).c_str()
            << (' ' + prepend + "***." + cloudName
              + "." + fieldObject.name()).c_str()
            << nl;
    }

    fileName ensightFileName
    (
        timeFile + "." + cloudName +"." + fieldObject.name()
    );

    OFstream ensightFile
    (
        postProcPath/ensightFileName,
        runTime.writeFormat(),
        runTime.writeVersion(),
        runTime.writeCompression()
    );

    ensightFile<< pTraits<Type>::typeName << " values" << nl;

    if (dataExists)
    {
        IOField<Type> vf(fieldObject);

        ensightFile.setf(ios_base::scientific, ios_base::floatfield);
        ensightFile.precision(5);

        label count = 0;
        forAll(vf, i)
        {
            Type v = vf[i];

            if (mag(v) < 1.0e-90)
            {
                v = pTraits<Type>::zero;
            }

            for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
            {
                ensightFile << setw(12) << component(v, cmpt);
                if (++count % 6 == 0)
                {
                    ensightFile << nl;
                }
            }
        }

        if ((count % 6 != 0) || (count==0))
        {
            ensightFile << nl;
        }
    }