Esempio n. 1
0
bool Foam::objectRegistry::checkIn(regIOobject& io) const
{
    if (objectRegistry::debug)
    {
        Pout<< "objectRegistry::checkIn(regIOobject&) : "
            << name() << " : checking in " << io.name()
            << endl;
    }

    return const_cast<objectRegistry&>(*this).insert(io.name(), &io);
}
Esempio n. 2
0
bool Foam::objectRegistry::checkOut(regIOobject& io) const
{
    iterator iter = const_cast<objectRegistry&>(*this).find(io.name());

    if (iter != end())
    {
        if (objectRegistry::debug)
        {
            Pout<< "objectRegistry::checkOut(regIOobject&) : "
                << name() << " : checking out " << iter.key()
                << endl;
        }

        if (iter() != &io)
        {
            if (objectRegistry::debug)
            {
                WarningInFunction
                    << name() << " : attempt to checkOut copy of "
                    << iter.key()
                    << endl;
            }

            return false;
        }
        else
        {
            regIOobject* object = iter();

            bool hasErased = const_cast<objectRegistry&>(*this).erase(iter);

            if (io.ownedByRegistry())
            {
                delete object;
            }

            return hasErased;
        }
    }
    else
    {
        if (objectRegistry::debug)
        {
            Pout<< "objectRegistry::checkOut(regIOobject&) : "
                << name() << " : could not find " << io.name()
                << " in registry " << name()
                << endl;
        }
    }

    return false;
}
bool Foam::passiveParticleStreamReconstructor::reconstruct
(
    const parUnallocatedFvFieldReconstructor& reconstructor,
    const regIOobject& thisIO,
    const bool,
    IOstream::streamFormat fmt,
    IOstream::versionNumber ver,
    IOstream::compressionType cmp
) const
{
    Pout<< "*** LAGRANGIAN reconstructin " << thisIO.objectPath() << endl;
    Pout<< "** LAGRANGIAN reconstruct " << thisIO.objectPath() << endl;
    return true;
}
bool Foam::fileOperations::masterFileOperation::writeObject
(
    const regIOobject& io,
    IOstream::streamFormat fmt,
    IOstream::versionNumber ver,
    IOstream::compressionType cmp
) const
{
    mkDir(io.path());
    fileName pathName(io.objectPath());

    autoPtr<Ostream> osPtr
    (
        NewOFstream
        (
            pathName,
            fmt,
            ver,
            cmp
        )
    );
    Ostream& os = osPtr();

    // If any of these fail, return (leave error handling to Ostream class)
    if (!os.good())
    {
        return false;
    }

    if (!io.writeHeader(os))
    {
        return false;
    }

    // Write the data to the Ostream
    if (!io.writeData(os))
    {
        return false;
    }

    IOobject::writeEndDivider(os);

    return true;
}
Esempio n. 5
0
bool Foam::regIOobject::upToDate
(
    const regIOobject& a,
    const regIOobject& b
) const
{
    if
    (
        a.eventNo() >= eventNo_
     || b.eventNo() >= eventNo_
    )
    {
        return false;
    }
    else
    {
        return true;
    }
}
Esempio n. 6
0
Foam::regIOobject::regIOobject
(
    const word& newName,
    const regIOobject& rio,
    bool registerCopy
)
:
    IOobject(newName, rio.instance(), rio.local(), rio.db()),
    registered_(false),
    ownedByRegistry_(false),
    watchIndex_(-1),
    eventNo_(db().getEvent()),
    isPtr_(NULL)
{
    if (registerCopy)
    {
        checkIn();
    }
}
bool Foam::fileOperations::autoParallelFileOperation::writeObject
(
    const regIOobject& io,
    IOstream::streamFormat fmt,
    IOstream::versionNumber ver,
    IOstream::compressionType cmp,
    const bool valid
) const
{
    bool ok = true;

    if (Pstream::parRun())
    {
        if (debug)
        {
            Pout<< indent
                << "autoParallelFileOperation::writeObject :"
                << " Searching for handler for type:" << io.type()
                << " of object: " << io.objectPath() << endl;
        }

        autoPtr<streamReconstructor> typeReconstructor
        (
            streamReconstructor::New(io.type())
        );

        if (typeReconstructor.valid())
        {
            const Time& runTime = io.time();

            Pout<< incrIndent;

            // Install basic file handler
            storeFileHandler defaultOp(basicFileHandler_);

            // Mapping engine from mesh to baseMesh (demand loads various)
            const parUnallocatedFvFieldReconstructor& mapper
                 = reconstructor(runTime);

            if (debug)
            {
                Pout<< indent
                    << "autoParallelFileOperation::writeObject :"
                    << " reconstructing and writing:" << io.name()
                    << " with handler for type:" << io.type()
                    << endl;
            }

            Pout<< decrIndent;

            typeReconstructor().reconstruct
            (
                mapper,
                io,
                false,          // no face flips. Tbd.
                fmt,
                ver,
                cmp
            );
        }
        else if
        (
            io.instance() == io.time().timeName()
         && io.local() == "uniform"
        )
        {
            if (valid)
            {
                // Copy of fileOperation::writeObject but with parent path

                fileName pathName
                (
                    io.rootPath()
                   /io.time().globalCaseName()
                   /io.instance()
                   /io.db().dbDir()
                   /io.local()
                   /io.name()
                );

                mkDir(pathName.path());

                autoPtr<Ostream> osPtr
                (
                    NewOFstream
                    (
                        pathName,
                        fmt,
                        ver,
                        cmp
                    )
                );

                if (!osPtr.valid())
                {
                    return false;
                }

                Ostream& os = osPtr();

                // If any of these fail, return (leave error handling to
                // Ostream class)
                if (!os.good())
                {
                    return false;
                }

                if (!io.writeHeader(os))
                {
                    return false;
                }

                // Write the data to the Ostream
                if (!io.writeData(os))
                {
                    return false;
                }

                IOobject::writeEndDivider(os);
            }
            return true;
        }
        else
        {
            ok = uncollatedFileOperation::writeObject
            (
                io,
                fmt,
                ver,
                cmp,
                valid
            );
        }
    }
    else
    {
        ok = uncollatedFileOperation::writeObject
        (
            io,
            fmt,
            ver,
            cmp,
            valid
        );
    }
    return ok;
}
bool Foam::fileOperations::autoParallelFileOperation::read
(
    regIOobject& io,
    const bool masterOnly,
    const IOstream::streamFormat format,
    const word& type
) const
{
    bool ok = true;

    if (Pstream::parRun())
    {
        if (debug)
        {
            Pout<< indent
                << "autoParallelFileOperation::read :"
                << " Searching for handler for type:" << type
                << " global:" << io.globalObject()
                << " masterOnly:" << masterOnly
                << " of object: " << io.objectPath() << endl;
        }
        autoPtr<streamReconstructor> typeReconstructor
        (
            streamReconstructor::New(type)
        );

        if (typeReconstructor.valid())
        {
            // Set flag for e.g. codeStream
            const bool oldGlobal = io.globalObject();
            io.globalObject() = masterOnly;
            // If codeStream originates from dictionary which is
            // not IOdictionary we have a problem so use global
            //const bool oldFlag = regIOobject::masterOnlyReading;
            //regIOobject::masterOnlyReading = masterOnly;


            // Find file, check in parent directory
            fileName objPath = filePath(oldGlobal, io, type);

            // Check if the file comes from the parent path
            fileName parentObjectPath =
                io.rootPath()/io.time().globalCaseName()
               /io.instance()/io.db().dbDir()/io.local()/io.name();

            if (debug)
            {
                Pout<< indent
                    << "io.objectPath   :" << io.objectPath() << nl
                    << indent
                    << "filePath        :" << objPath << nl
                    << indent
                    << "parentObjectPath:" << parentObjectPath << endl;
            }

            if (io.objectPath() != objPath && objPath == parentObjectPath)
            {
                const Time& runTime = io.time();

                // Install basic file handler
                storeFileHandler defaultOp(basicFileHandler_);

                Pout<< incrIndent;

                // Read local mesh
                const unallocatedFvMesh& procMesh = mesh(runTime);
                // Read undecomposed mesh. Read procAddressing files
                // (from runTime).
                const unallocatedFvMesh& baseUMesh = baseMesh(runTime);
                // Mapping engine from mesh to baseMesh
                const parUnallocatedFvFieldReconstructor& mapper
                     = reconstructor(runTime);

                IOobject baseIO
                (
                    io.name(),
                    io.instance(),
                    io.local(),
                    baseUMesh.thisDb(),
                    IOobject::MUST_READ,
                    IOobject::NO_WRITE,
                    false
                );

                OStringStream os(IOstream::BINARY);

                if (debug)
                {
                    Pout<< "autoParallelFileOperation::read :"
                        << " decompose and writing:" << baseIO.objectPath()
                        << endl;
                }
                bool ok = typeReconstructor().decompose
                (
                    mapper,
                    baseUMesh,
                    baseIO,
                    procMesh,
                    io,
                    false,              // no face flips. Tbd.
                    os
                );

                Pout<< decrIndent;

                if (ok)
                {
                    IStringStream is(os.str(), IOstream::BINARY);

                    // Read field from stream
                    ok = io.readData(is);
                    io.close();

                    if (debug)
                    {
                        const word oldName(io.name());
                        io.rename(oldName + '_' + typeName_());
                        io.write();
                        Pout<< indent
                            << "autoParallelFileOperation::read :"
                            << " sucessfully decomposed " << io.objectPath()
                            << " into " << io.objectPath()
                            << endl;
                        io.rename(oldName);
                    }
                }
                else
                {
                    if (debug)
                    {
                        Pout<< indent
                            << "autoParallelFileOperation::read :"
                            << " ** failed decomposing " << io.objectPath()
                            << endl;
                    }
                    return false;
                }
            }
            else
            {
                ok = io.readData(io.readStream(type));
                io.close();
            }

            // Restore flags
            io.globalObject() = oldGlobal;
            //regIOobject::masterOnlyReading = oldFlag;
        }
        else
        {
            ok = io.readData(io.readStream(type));
            io.close();
        }
    }
    else
    {
        ok = uncollatedFileOperation::read
        (
            io,
            masterOnly,
            format,
            type
        );
    }

    return ok;
}
Foam::autoPtr<Foam::Istream>
Foam::fileOperations::masterFileOperation::readStream
(
    regIOobject& io,
    const fileName& fName
) const
{
    if (!fName.size())
    {
        FatalErrorInFunction
            << "empty file name" << exit(FatalError);
    }

    fileNameList filePaths(Pstream::nProcs());
    filePaths[Pstream::myProcNo()] = fName;
    Pstream::gatherList(filePaths);

    PstreamBuffers pBufs(Pstream::nonBlocking);

    autoPtr<Istream> isPtr;

    if (Pstream::master())
    {
        //const bool uniform = uniformFile(filePaths);

        autoPtr<IFstream> ifsPtr(new IFstream(fName));
        IFstream& is = ifsPtr();

        // Read header
        if (!io.readHeader(is))
        {
            FatalIOErrorInFunction(is)
                << "problem while reading header for object " << io.name()
                << exit(FatalIOError);
        }

        // Open master (steal from ifsPtr)
        isPtr.reset(ifsPtr.ptr());

        // Read slave files
        for (label proci = 1; proci < Pstream::nProcs(); proci++)
        {
            if (IFstream::debug)
            {
                Pout<< "For processor " << proci
                    << " opening " << filePaths[proci] << endl;
            }

            std::ifstream is(filePaths[proci]);
            // Get length of file
            is.seekg(0, ios_base::end);
            std::streamoff count = is.tellg();
            is.seekg(0, ios_base::beg);

            if (IFstream::debug)
            {
                Pout<< "From " << filePaths[proci]
                    <<  " reading " << label(count) << " bytes" << endl;
            }
            List<char> buf(static_cast<label>(count));
            is.read(buf.begin(), count);

            UOPstream os(proci, pBufs);
            os.write(buf.begin(), count);
        }
    }

    labelList recvSizes;
    pBufs.finishedSends(recvSizes);

    // isPtr will be valid on master. Else the information is in the
    // PstreamBuffers

    if (!isPtr.valid())
    {
        UIPstream is(Pstream::masterNo(), pBufs);
        string buf(recvSizes[Pstream::masterNo()], '\0');
        is.read(&buf[0], recvSizes[Pstream::masterNo()]);

        if (IFstream::debug)
        {
            Pout<< "Done reading " << buf.size() << " bytes" << endl;
        }
        isPtr.reset(new IStringStream(buf));

        if (!io.readHeader(isPtr()))
        {
            FatalIOErrorInFunction(isPtr())
                << "problem while reading header for object " << io.name()
                << exit(FatalIOError);
        }
    }
    return isPtr;
}