void Foam::coordinateRotationOFext::operator=(const dictionary& rhs)
{
    if (debug)
    {
        Pout<< "coordinateRotation::operator=(const dictionary&) : "
            << "assign from " << rhs << endl;
    }

    // allow as embedded sub-dictionary "coordinateRotation"
    const dictionary& dict =
    (
        rhs.found(typeName_())
      ? rhs.subDict(typeName_())
      : rhs
    );

    vector axis1, axis2;
    axisOrder order = e3e1;

    if (dict.readIfPresent("e1", axis1) && dict.readIfPresent("e2", axis2))
    {
        order = e1e2;
    }
    else if
    (
        dict.readIfPresent("e2", axis1)
     && dict.readIfPresent("e3", axis2)
    )
    {
        order = e2e3;
    }
    else if
    (
        dict.readIfPresent("e3", axis1)
     && dict.readIfPresent("e1", axis2)
    )
    {
        order = e3e1;
    }
    else if (dict.found("axis") || dict.found("direction"))
    {
        // let it bomb if only one of axis/direction is defined
        order = e3e1;
        axis1 = vector(dict.lookup("axis"));
        axis2 = vector(dict.lookup("direction"));
    }
    else
    {
        // unspecified axes revert to the global system
        tensor::operator=(sphericalTensor::I);
        return;
    }

    calcTransform(axis1, axis2, order);
}
Foam::coordinateSystem::coordinateSystem
(
    const dictionary& dict,
    const objectRegistry& obr
)
:
    name_(type()),
    note_(),
    origin_(point::zero),
    R_(),
    Rtr_(sphericalTensor::I)
{
    const entry* entryPtr = dict.lookupEntryPtr(typeName_(), false, false);

    // non-dictionary entry is a lookup into global coordinateSystems
    if (entryPtr && !entryPtr->isDict())
    {
        keyType key(entryPtr->stream());

        const coordinateSystems& lst = coordinateSystems::New(obr);
        const label index = lst.findIndex(key);

        if (debug)
        {
            Info<< "coordinateSystem::coordinateSystem"
                "(const dictionary&, const objectRegistry&):"
                << nl << "using global coordinate system: "
                << key << "=" << index << endl;
        }

        if (index < 0)
        {
            FatalErrorIn
            (
                "coordinateSystem::coordinateSystem"
                "(const dictionary&, const objectRegistry&)"
            )   << "could not find coordinate system: " << key << nl
                << "available coordinate systems: " << lst.toc() << nl << nl
                << exit(FatalError);
        }

        // copy coordinateSystem, but assign the name as the typeName
        // to avoid strange things in writeDict()
        operator=(lst[index]);
        name_ = typeName_();
    }
    else
    {
        operator=(dict);
    }
}
void lineRefinement::operator=(const dictionary& d)
{
    // allow as embedded sub-dictionary "coordinateSystem"
    const dictionary& dict =
    (
        d.found(typeName_())
      ? d.subDict(typeName_())
      : d
    );

    // unspecified centre is (0 0 0)
    if( dict.found("p0") )
    {
        dict.lookup("p0") >> p0_;
    }
void lineRefinement::writeDict(Ostream& os, bool subDict) const
{
    if( subDict )
    {
        os << indent << token::BEGIN_BLOCK << incrIndent << nl;
    }

    if( additionalRefinementLevels() == 0 && cellSize() >= 0.0 )
    {
        os.writeKeyword("cellSize") << cellSize() << token::END_STATEMENT << nl;
    }
    else
    {
        os.writeKeyword("additionalRefinementLevels")
                << additionalRefinementLevels()
                << token::END_STATEMENT << nl;
    }

    // only write type for derived types
    if( type() != typeName_() )
    {
        os.writeKeyword("type") << type() << token::END_STATEMENT << nl;
    }

    os.writeKeyword("p0") << p0_ << token::END_STATEMENT << nl;
    os.writeKeyword("p1") << p1_ << token::END_STATEMENT << nl;

    if( subDict )
    {
        os << decrIndent << indent << token::END_BLOCK << endl;
    }
}
void Foam::coordinateSystem::writeDict(Ostream& os, bool subDict) const
{
    if (subDict)
    {
        os  << indent << name_ << nl
            << indent << token::BEGIN_BLOCK << incrIndent << nl;
    }

    // only write type for derived types
    if (type() != typeName_())
    {
        os.writeKeyword("type") << type() << token::END_STATEMENT << nl;
    }

    // The note entry is optional
    if (note_.size())
    {
        os.writeKeyword("note") << note_ << token::END_STATEMENT << nl;
    }

    os.writeKeyword("origin") << origin_ << token::END_STATEMENT << nl;
    os.writeKeyword("e1") << e1() << token::END_STATEMENT << nl;
    os.writeKeyword("e3") << e3() << token::END_STATEMENT << nl;

    if (subDict)
    {
        os  << decrIndent << indent << token::END_BLOCK << endl;
    }
}
Example #6
0
Foam::coordinateSystem::coordinateSystem
(
    const dictionary& dict,
    const objectRegistry& obr
)
:
    name_(type()),
    note_(),
    origin_(point::zero),
    R_(),
    Rtr_(sphericalTensor::I)
{
    const entry* entryPtr = dict.lookupEntryPtr(typeName_(), false, false);

    // a simple entry is a lookup into global coordinateSystems
    if (entryPtr && !entryPtr->isDict())
    {
        word csName;
        entryPtr->stream() >> csName;

        const coordinateSystems& csLst = coordinateSystems::New(obr);

        label csId = csLst.find(csName);
        if (debug)
        {
            Info<< "coordinateSystem::coordinateSystem"
                "(const dictionary&, const objectRegistry&):"
                << nl << "using global coordinate system: "
                << csName << "=" << csId << endl;
        }

        if (csId < 0)
        {
            FatalErrorIn
            (
                "coordinateSystem::coordinateSystem"
                "(const dictionary&, const objectRegistry&)"
            )   << "could not find coordinate system: " << csName << nl
                << "available coordinate systems: " << csLst.toc() << nl << nl
                << exit(FatalError);
        }

        // copy coordinateSystem, but assign the name as the typeName
        // to avoid strange things in writeDict()
        operator=(csLst[csId]);
        name_ = typeName_();
    }
Example #7
0
Foam::autoPtr<Foam::coordinateSystem> Foam::coordinateSystem::New
(
    const word& name,
    const dictionary& dict
)
{
    if (debug)
    {
        Pout<< "coordinateSystem::New(const word&, const dictionary&) : "
            << "constructing coordinateSystem"
            << endl;
    }

    // construct base class directly, also allow 'cartesian' as an alias
    word coordType(typeName_());
    if
    (
        !dict.readIfPresent("type", coordType)
     || coordType == typeName_()
     || coordType == "cartesian"
    )
    {
        return autoPtr<coordinateSystem>(new coordinateSystem(name, dict));
    }

    dictionaryConstructorTable::iterator cstrIter =
        dictionaryConstructorTablePtr_->find(coordType);

    if (cstrIter == dictionaryConstructorTablePtr_->end())
    {
        FatalIOErrorIn
        (
            "coordinateSystem::New(const word&, const dictionary&)",
            dict
        )   << "Unknown coordinateSystem type " << coordType << nl << nl
            << "Valid coordinateSystem types are :" << nl
            << "[default: " << typeName_() << "]"
            << dictionaryConstructorTablePtr_->toc()
            << exit(FatalIOError);
    }

    return autoPtr<coordinateSystem>(cstrIter()(name, dict));
}
Foam::autoPtr<Foam::coordinateRotationOFext> Foam::coordinateRotationOFext::New
(
    const dictionary& dict
)
{
    if (debug)
    {
        Pout<< "coordinateRotation::New(const dictionary&) : "
            << "constructing coordinateRotation"
            << endl;
    }

    // default type is self (alias: "axes")
    word rotType(typeName_());
    dict.readIfPresent("type", rotType);

    // can (must) construct base class directly
    if (rotType == typeName_() || rotType == "axes")
    {
        return autoPtr<coordinateRotationOFext>(new coordinateRotationOFext(dict));
    }


    dictionaryConstructorTable::iterator cstrIter =
        dictionaryConstructorTablePtr_->find(rotType);

    if (cstrIter == dictionaryConstructorTablePtr_->end())
    {
        FatalIOErrorIn
        (
            "coordinateRotation::New(const dictionary&)",
            dict
        )   << "Unknown coordinateRotation type "
            << rotType << nl << nl
            << "Valid coordinateRotation types are :" <<  nl
            << "[default: axes " << typeName_() << "]"
            << dictionaryConstructorTablePtr_->toc()
            << exit(FatalIOError);
    }

    return autoPtr<coordinateRotationOFext>(cstrIter()(dict));
}
void Foam::coordinateSystem::operator=(const dictionary& rhs)
{
    if (debug)
    {
        Pout<< "coordinateSystem::operator=(const dictionary&) : "
            << "assign from " << rhs << endl;
    }

    // allow as embedded sub-dictionary "coordinateSystem"
    const dictionary& dict =
    (
        rhs.found(typeName_())
      ? rhs.subDict(typeName_())
      : rhs
    );

    // unspecified origin is (0 0 0)
    origin_ = point::zero;
    dict.readIfPresent("origin", origin_);

    // The note entry is optional
    note_.clear();
    rhs.readIfPresent("note", note_);

    // specify via coordinateRotation sub-dictionary
    if (dict.found("coordinateRotation"))
    {
        R_  = coordinateRotation::New(dict.subDict("coordinateRotation"))();
    }
    else
    {
        // let coordinateRotation constructor extract the axes specification
        R_ = coordinateRotation(dict);
    }

    Rtr_ = R_.T();
}
Foam::autoPtr<Foam::coordinateSystem> Foam::coordinateSystem::New
(
    const word& name,
    const dictionary& dict
)
{
    if (debug)
    {
        Pout<< "coordinateSystem::New(const word&, const dictionary&) : "
            << "constructing coordinateSystem"
            << endl;
    }

    // default type is self
    word coordType(typeName_());
    if (dict.found("type"))
    {
	dict.lookup("type") >> coordType;
    }
Foam::dictionary Foam::coordinateSystem::dict(bool ignoreType) const
{
    dictionary dict;

    dict.add("name", name_);

    // only write type for derived types
    if (!ignoreType && type() != typeName_())
    {
        dict.add("type", type());
    }

    // The note entry is optional
    if (note_.size())
    {
        dict.add("note", note_);
    }

    dict.add("origin", origin_);
    dict.add("e1", e1());
    dict.add("e3", e3());

    return dict;
}
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;
}