Foam::binaryOperationSearchableSurface::binaryOperationSearchableSurface
(
    const IOobject& io,
    const dictionary& dict
)
:
    searchableSurface(io),
    aName_(dict.lookupOrDefault<word>("aName","A")),
    bName_(dict.lookupOrDefault<word>("bName","B")),
    a_(
        searchableSurface::New
        (
            word(dict.subDict("a").lookup("type")),
            IOobject(
                name()+"_"+word(dict.lookup("type"))+"_"+aName_,
                io.instance(),
                io.db(),
                io.readOpt(),
                io.writeOpt()
            ),
            dict.subDict("a")
        )
    ),
    b_(
        searchableSurface::New
        (
            word(dict.subDict("b").lookup("type")),
            IOobject(
                name()+"_"+word(dict.lookup("type"))+"_"+bName_,
                io.instance(),
                io.db(),
                io.readOpt(),
                io.writeOpt()
            ),
            dict.subDict("b")
        )
    ),
    nrARegions_(
        a().regions().size()
    ),
    nrBRegions_(
        b().regions().size()
    )
{
    if(aName_==bName_) {
        FatalErrorIn("binaryOperationSearchableSurface::binaryOperationSearchableSurface")
            << "'aName' and 'bName' have the same value " << aName_
                << " for " << name()
                << endl
                << exit(FatalError);
    }
    if(regions().size()!=size()) {
        FatalErrorIn("binaryOperationSearchableSurface::binaryOperationSearchableSurface")
            << "Number of regions " << regions().size() << " not equal to size "
                << size() << nl << "Regions: " << regions()
                << endl
                << exit(FatalError);

    }
}
示例#2
0
Foam::surfMesh::surfMesh
(
    const IOobject& io,
    const Xfer<MeshedSurface<face> >& surf,
    const word& surfName
)
:
    surfaceRegistry(io.db(), (surfName.size() ? surfName : io.name())),
    Allocator
    (
        IOobject
        (
            "points",
            instance(),
            meshSubDir,
            *this,
            IOobject::NO_READ,
            IOobject::AUTO_WRITE
        ),
        pointField(),
        IOobject
        (
            "faces",
            instance(),
            meshSubDir,
            *this,
            IOobject::NO_READ,
            IOobject::AUTO_WRITE
        ),
        faceList(),
        IOobject
        (
            "surfZones",
            instance(),
            meshSubDir,
            *this,
            IOobject::NO_READ,
            IOobject::AUTO_WRITE
        ),
        surfZoneList()
    ),
    MeshReference(this->storedIOFaces(), this->storedIOPoints())
{
    if (debug)
    {
        Info<<"IOobject: " << io.path() << nl
            <<" name: " << io.name()
            <<" instance: " << io.instance()
            <<" local: " << io.local()
            <<" dbDir: " << io.db().dbDir() << endl;
        Info<<"creating surfMesh at instance " << instance() << endl;
        Info<<"timeName: " << instance() << endl;
    }

    // We can also send Xfer<..>::null just to initialize without allocating
    if (notNull(surf))
    {
        transfer(surf());
    }
}
Foam::fileName Foam::fileOperations::autoParallelFileOperation::filePath
(
    const bool checkGlobal,
    const IOobject& io,
    const word& typeName
) const
{
    if (debug)
    {
        Pout<< indent
            << "autoParallelFileOperation::filePath :"
            << " objectPath:" << io.objectPath()
            << " checkGlobal:" << checkGlobal << endl;
    }

    // Try uncollated searching
    fileName objPath = uncollatedFileOperation::filePath
    (
        checkGlobal,
        io,
        typeName
    );

    // If not found and parallel check parent
    if (objPath.empty() && io.time().processorCase()) // && checkGlobal)
    {
        fileName parentObjectPath =
            io.rootPath()/io.time().globalCaseName()
           /io.instance()/io.db().dbDir()/io.local()/io.name();

        if (isFile(parentObjectPath))
        {
            objPath = parentObjectPath;
        }
    }

    if (debug)
    {
        Pout<< indent
            << "autoParallelFileOperation::filePath :"
            << " Returning from file searching:" << endl
            << "    objectPath:" << io.objectPath() << endl
            << "    filePath  :" << objPath << endl << endl;
    }
    return objPath;
}
Foam::binaryOperationSearchableSurface::binaryOperationSearchableSurface
(
    const IOobject& io,
    const dictionary& dict
)
:
    searchableSurface(io),
    aName_(dict.lookupOrDefault<word>("aName","A")),
    bName_(dict.lookupOrDefault<word>("bName","B")),
    a_(
        searchableSurface::New
        (
            word(dict.subDict("a").lookup("type")),
            IOobject(
                name()+"_"+word(dict.lookup("type"))+"_"+aName_,
                io.instance(),
                io.db(),
                io.readOpt(),
                io.writeOpt()
            ),
            dict.subDict("a")
        )
    ),
    b_(
        searchableSurface::New
        (
            word(dict.subDict("b").lookup("type")),
            IOobject(
                name()+"_"+word(dict.lookup("type"))+"_"+bName_,
                io.instance(),
                io.db(),
                io.readOpt(),
                io.writeOpt()
            ),
            dict.subDict("b")
        )
    ),
    nrARegions_(
        a().regions().size()
    ),
    nrBRegions_(
        b().regions().size()
    )
{
    if(aName_==bName_) {
        FatalErrorIn("binaryOperationSearchableSurface::binaryOperationSearchableSurface")
            << "'aName' and 'bName' have the same value " << aName_
                << " for " << name()
                << endl
                << exit(FatalError);
    }
    if(regions().size()!=size()) {
        FatalErrorIn("binaryOperationSearchableSurface::binaryOperationSearchableSurface")
            << "Number of regions " << regions().size() << " not equal to size "
                << size() << nl << "Regions: " << regions()
                << endl
                << exit(FatalError);

    }

#ifdef FOAM_SEARCHABLE_SURF_HAS_BOUND_METHOD
    pointField pts(4);
    pts[0]=a().bounds().min();
    pts[1]=a().bounds().max();
    pts[2]=b().bounds().min();
    pts[3]=b().bounds().max();
    bounds()=boundBox(pts);
#endif
}
bool Foam::passiveParticleStreamReconstructor::reconstruct
(
    const IOobject& io,
    const bool,
    Ostream& os
) const
{
    // io.db()                   = Cloud<passiveParticle>
    // io.db().parent()          = polyMesh
    // io.db().parent().parent() = Time

    // Retrieve from polyMesh
    const uFieldReconstructor& reconstructor =
        uFieldReconstructor::New(io.db().parent());

    const PtrList<unallocatedFvMesh>& procMeshes = reconstructor.procMeshes();

    Info<< "Reconstructing " << io.objectPath() << endl;

    // Read field on proc meshes
    PtrList<cloud> procClouds(procMeshes.size());
    PtrList<unallocatedIOPosition> procFields(procMeshes.size());
    forAll(procFields, proci)
    {
        const unallocatedFvMesh& procMesh = procMeshes[proci];

        Pout<< incrIndent;

        // Construct empty cloud
        procClouds.set
        (
            proci,
            new cloud
            (
                procMesh.thisDb(),
                "kinematicCloud"
            )
        );

        procFields.set
        (
            proci,
            new unallocatedIOPosition
            (
                IOobject
                (
                    io.name(),
                    io.instance(),
                    io.local(),
                    procClouds[proci],
                    IOobject::MUST_READ,    //IOobject::READ_IF_PRESENT,
                    IOobject::NO_WRITE
                )
            )
        );

        Pout<< decrIndent;
    }

    unallocatedIOPosition particles
    (
        IOobject
        (
            io.name(),
            io.instance(),
            io.local(),
            io.db(),
            IOobject::NO_READ,
            IOobject::NO_WRITE,
            false
        )
    );

    const faceList* facesPtr = nullptr;
    if (isA<polyMesh>(io.db().parent()))
    {
        facesPtr = &dynamic_cast<const polyMesh&>(io.db().parent()).faces();
    }

    forAll(procFields, proci)
    {
        const unallocatedIOPosition& procCloud = procFields[proci];
        const labelList& cellMap = reconstructor.cellProcAddressing()[proci];
        const labelList& faceMap = reconstructor.faceProcAddressing()[proci];

        forAllConstIter(typename IDLList<basicParticle>, procCloud, iter)
        {
            const basicParticle& p = iter();

            const label mappedCell = cellMap[p.cell()];

            const label mapi = faceMap[p.tetFace()];

            label mappedTetFace = -1;
            label tetPti = p.tetPt();
            if (mapi == 0)
            {
                FatalErrorInFunction << "problem" << exit(FatalError);
            }
            else if (mapi > 0)
            {
                mappedTetFace = mapi - 1;
            }
            else
            {
                mappedTetFace = -mapi - 1;

                if (facesPtr)
                {
                    // Flipping face

                    const face& f = (*facesPtr)[mappedTetFace];
                    tetPti = f.size() - 1 - tetPti;
                }
            }

            particles.append
            (
                new basicParticle
                (
                    p,
                    mappedCell,
                    mappedTetFace,
                    tetPti
                )
            );
        }
    }
    particles.writeData(os);

    return os.good();
}
int main(int argc, char *argv[])
{
    argList::addNote
    (
        "redistribute a triSurface"
    );

    argList::validArgs.append("triSurfaceMesh");
    argList::validArgs.append("distributionType");
    argList::addBoolOption
    (
        "keepNonMapped",
        "preserve surface outside of mesh bounds"
    );

    #include "setRootCase.H"
    #include "createTime.H"
    runTime.functionObjects().off();

    const fileName surfFileName = args[1];
    const word distType = args[2];

    Info<< "Reading surface from " << surfFileName << nl << nl
        << "Using distribution method "
        << distributedTriSurfaceMesh::distributionTypeNames_[distType]
        << " " << distType << nl << endl;

    const bool keepNonMapped = args.options().found("keepNonMapped");

    if (keepNonMapped)
    {
        Info<< "Preserving surface outside of mesh bounds." << nl << endl;
    }
    else
    {
        Info<< "Removing surface outside of mesh bounds." << nl << endl;
    }


    if (!Pstream::parRun())
    {
        FatalErrorIn(args.executable())
            << "Please run this program on the decomposed case."
            << " It will read surface " << surfFileName
            << " and decompose it such that it overlaps the mesh bounding box."
            << exit(FatalError);
    }


    #include "createPolyMesh.H"

    Random rndGen(653213);

    // Determine mesh bounding boxes:
    List<List<treeBoundBox> > meshBb(Pstream::nProcs());
    {
        meshBb[Pstream::myProcNo()] = List<treeBoundBox>
        (
            1,
            treeBoundBox
            (
                boundBox(mesh.points(), false)
            ).extend(rndGen, 1E-3)
        );
        Pstream::gatherList(meshBb);
        Pstream::scatterList(meshBb);
    }

    IOobject io
    (
        surfFileName,         // name
        //runTime.findInstance("triSurface", surfFileName),   // instance
        runTime.constant(),   // instance
        "triSurface",         // local
        runTime,              // registry
        IOobject::MUST_READ,
        IOobject::NO_WRITE
    );

    const fileName actualPath(io.filePath());
    fileName localPath(actualPath);
    localPath.replace(runTime.rootPath() + '/', "");

    if (actualPath == io.objectPath())
    {
        Info<< "Loading local (decomposed) surface " << localPath << nl <<endl;
    }
    else
    {
        Info<< "Loading undecomposed surface " << localPath << nl << endl;
    }


    // Create dummy dictionary for bounding boxes if does not exist.
    if (!isFile(actualPath / "Dict"))
    {
        dictionary dict;
        dict.add("bounds", meshBb[Pstream::myProcNo()]);
        dict.add("distributionType", distType);
        dict.add("mergeDistance", SMALL);

        IOdictionary ioDict
        (
            IOobject
            (
                io.name() + "Dict",
                io.instance(),
                io.local(),
                io.db(),
                IOobject::NO_READ,
                IOobject::NO_WRITE,
                false
            ),
            dict
        );

        Info<< "Writing dummy bounds dictionary to " << ioDict.name()
            << nl << endl;

        ioDict.regIOobject::writeObject
        (
            IOstream::ASCII,
            IOstream::currentVersion,
            ioDict.time().writeCompression()
        );
    }


    // Load surface
    distributedTriSurfaceMesh surfMesh(io);
    Info<< "Loaded surface" << nl << endl;


    // Generate a test field
    {
        const triSurface& s = static_cast<const triSurface&>(surfMesh);

        autoPtr<triSurfaceVectorField> fcPtr
        (
            new triSurfaceVectorField
            (
                IOobject
                (
                    surfMesh.searchableSurface::name(),     // name
                    surfMesh.searchableSurface::instance(), // instance
                    surfMesh.searchableSurface::local(),    // local
                    surfMesh,
                    IOobject::NO_READ,
                    IOobject::AUTO_WRITE
                ),
                surfMesh,
                dimLength
            )
        );
        triSurfaceVectorField& fc = fcPtr();

        forAll(fc, triI)
        {
            fc[triI] = s[triI].centre(s.points());
        }

        // Steal pointer and store object on surfMesh
        fcPtr.ptr()->store();
    }
Foam::fileName Foam::fileOperations::masterFileOperation::filePath
(
    const bool checkGlobal,
    const IOobject& io,
    pathType& searchType,
    word& newInstancePath
)
{
    newInstancePath = word::null;

    if (io.instance().isAbsolute())
    {
        fileName objectPath = io.instance()/io.name();
        if (Foam::isFile(objectPath))
        {
            searchType = fileOperation::ABSOLUTE;
            return objectPath;
        }
        else
        {
            searchType = fileOperation::NOTFOUND;
            return fileName::null;
        }
    }
    else
    {
        fileName path = io.path();
        fileName objectPath = path/io.name();

        if (Foam::isFile(objectPath))
        {
            searchType = fileOperation::OBJECT;
            return objectPath;
        }
        else
        {
            if
            (
                checkGlobal
             && io.time().processorCase()
             && (
                    io.instance() == io.time().system()
                 || io.instance() == io.time().constant()
                )
            )
            {
                fileName parentObjectPath =
                    io.rootPath()/io.time().globalCaseName()
                   /io.instance()/io.db().dbDir()/io.local()/io.name();

                if (Foam::isFile(parentObjectPath))
                {
                    searchType = fileOperation::PARENTOBJECT;
                    return parentObjectPath;
                }
            }

//- The big problem with findInstance is that it itself needs file
//  access through the fileHandler. Since this routine is only called on the
//  master we'll get a deadlock.
//            if (!Foam::isDir(path))
//            {
//                newInstancePath = io.time().findInstancePath
//                (
//                    instant(io.instance())
//                );
//
//                if (newInstancePath.size())
//                {
//                    fileName fName
//                    (
//                        io.rootPath()/io.caseName()
//                       /newInstancePath/io.db().dbDir()/io.local()/io.name()
//                    );
//
//                    if (Foam::isFile(fName))
//                    {
//                        searchType = fileOperation::FINDINSTANCE;
//                        return fName;
//                    }
//                }
//            }

            // Try constant & local
            {
                newInstancePath = io.time().constant();
                fileName fName
                (
                    io.rootPath()
                   /io.caseName()
                   /newInstancePath
                   /io.db().dbDir()
                   /io.local()
                   /io.name()
                );
                //DebugVar(fName);

                if (Foam::isFile(fName))
                {
                    searchType = fileOperation::FINDINSTANCE;
                    return fName;
                }
            }

        }

        return fileName::null;
    }
}
Foam::fileName Foam::fileOperations::masterFileOperation::objectPath
(
    const IOobject& io,
    const pathType& searchType,
    const word& instancePath
)
{
    // Replacement for IOobject::objectPath()

    switch (searchType)
    {
        case fileOperation::ABSOLUTE:
        {
            return io.instance()/io.name();
        }
        break;

        case fileOperation::OBJECT:
        {
            return io.path()/io.name();
        }
        break;

        case fileOperation::PROCESSORSOBJECT:
        {
            return processorsPath(io, io.instance())/io.name();
        }
        break;

        case fileOperation::PARENTOBJECT:
        {
            return
                io.rootPath()/io.time().globalCaseName()
               /io.instance()/io.db().dbDir()/io.local()/io.name();
        }
        break;

        case fileOperation::FINDINSTANCE:
        {
            return
                io.rootPath()/io.caseName()
               /instancePath/io.db().dbDir()/io.local()/io.name();
        }
        break;

        case fileOperation::PROCESSORSFINDINSTANCE:
        {
            return processorsPath(io, instancePath)/io.name();
        }
        break;

        case fileOperation::NOTFOUND:
        {
            return fileName::null;
        }
        break;

        default:
        {
            NotImplemented;
            return fileName::null;
        }
    }
}
bool Foam::volFieldStreamReconstructor<Type>::reconstruct
(
    const IOobject& io,
    const bool,
    Ostream& os
) const
{
    typedef GeometricField<Type, unallocatedFvPatchField, unallocatedVolMesh>
        GeoField;

    // Retrieve from polyMesh
    const uFieldReconstructor& reconstructor =
        uFieldReconstructor::New(io.db());

    const PtrList<unallocatedFvMesh>& procMeshes = reconstructor.procMeshes();

    Info<< "Reconstructing " << io.objectPath() << endl;

    // Read field on proc meshes
    PtrList<GeoField> procFields(procMeshes.size());
    forAll(procFields, proci)
    {
        const unallocatedFvMesh& procMesh = procMeshes[proci];

        Pout<< incrIndent;
        procFields.set
        (
            proci,
            new GeoField
            (
                IOobject
                (
                    io.name(),
                    io.instance(),
                    io.local(),
                    procMesh.thisDb(),
                    IOobject::MUST_READ,
                    IOobject::NO_WRITE,
                    false
                ),
                procMesh
            )
        );
        Pout<< decrIndent;
    }

    // Fix filtering of empty nonuniform entries
    reconstructor.reconstructor().fixGenericNonuniform
    <
        GeoField,
        unallocatedGenericFvPatchField<Type>
    >(procFields);

    // Map local field onto baseMesh
    const unallocatedFvMesh& baseMesh = reconstructor.baseMesh();

    tmp<GeoField> tfld
    (
        reconstructor.reconstructor().reconstructFvVolumeField
        (
            IOobject
            (
                io.name(),
                io.instance(),
                io.local(),
                baseMesh.thisDb(),
                IOobject::NO_READ,
                IOobject::AUTO_WRITE,
                false
            ),
            procFields
        )
    );

    Pout<< incrIndent;
    os << tfld();
    Pout<< decrIndent;

    return os.good();
}