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()); } }
void Foam::sampledIsoSurface::getIsoFields() const { const fvMesh& fvm = static_cast<const fvMesh&>(mesh()); // Get volField // ~~~~~~~~~~~~ if (fvm.foundObject<volScalarField>(isoField_)) { if (debug) { Info<< "sampledIsoSurface::getIsoFields() : lookup volField " << isoField_ << endl; } storedVolFieldPtr_.clear(); volFieldPtr_ = &fvm.lookupObject<volScalarField>(isoField_); } else { // Bit of a hack. Read field and store. if (debug) { Info<< "sampledIsoSurface::getIsoFields() : checking " << isoField_ << " for same time " << fvm.time().timeName() << endl; } if ( storedVolFieldPtr_.empty() || (fvm.time().timeName() != storedVolFieldPtr_().instance()) ) { if (debug) { Info<< "sampledIsoSurface::getIsoFields() : reading volField " << isoField_ << " from time " << fvm.time().timeName() << endl; } IOobject vfHeader ( isoField_, fvm.time().timeName(), fvm, IOobject::MUST_READ, IOobject::NO_WRITE, false ); if (vfHeader.headerOk()) { storedVolFieldPtr_.reset ( new volScalarField ( vfHeader, fvm ) ); volFieldPtr_ = storedVolFieldPtr_.operator->(); } else { FatalErrorIn("sampledIsoSurface::getIsoFields()") << "Cannot find isosurface field " << isoField_ << " in database or directory " << vfHeader.path() << exit(FatalError); } } } // Get pointField // ~~~~~~~~~~~~~~ if (!subMeshPtr_.valid()) { word pointFldName = "volPointInterpolate(" + isoField_ + ')'; if (fvm.foundObject<pointScalarField>(pointFldName)) { if (debug) { Info<< "sampledIsoSurface::getIsoFields() : lookup pointField " << pointFldName << endl; } pointFieldPtr_ = &fvm.lookupObject<pointScalarField>(pointFldName); } else { // Not in registry. Interpolate. if (debug) { Info<< "sampledIsoSurface::getIsoFields() : " << "checking pointField " << pointFldName << " for same time " << fvm.time().timeName() << endl; } if ( storedPointFieldPtr_.empty() || (fvm.time().timeName() != storedPointFieldPtr_().instance()) ) { if (debug) { Info<< "sampledIsoSurface::getIsoFields() :" << " interpolating volField " << volFieldPtr_->name() << " to get pointField " << pointFldName << endl; } storedPointFieldPtr_.reset ( volPointInterpolation::New(fvm) .interpolate(*volFieldPtr_).ptr() ); storedPointFieldPtr_->checkOut(); pointFieldPtr_ = storedPointFieldPtr_.operator->(); } } // If averaging redo the volField. Can only be done now since needs the // point field. if (average_) { storedVolFieldPtr_.reset ( pointAverage(*pointFieldPtr_).ptr() ); volFieldPtr_ = storedVolFieldPtr_.operator->(); } if (debug) { Info<< "sampledIsoSurface::getIsoFields() : volField " << volFieldPtr_->name() << " min:" << min(*volFieldPtr_).value() << " max:" << max(*volFieldPtr_).value() << endl; Info<< "sampledIsoSurface::getIsoFields() : pointField " << pointFieldPtr_->name() << " min:" << gMin(pointFieldPtr_->internalField()) << " max:" << gMax(pointFieldPtr_->internalField()) << endl; } } else { // Get subMesh variants const fvMesh& subFvm = subMeshPtr_().subMesh(); // Either lookup on the submesh or subset the whole-mesh volField if (subFvm.foundObject<volScalarField>(isoField_)) { if (debug) { Info<< "sampledIsoSurface::getIsoFields() :" << " submesh lookup volField " << isoField_ << endl; } storedVolSubFieldPtr_.clear(); volSubFieldPtr_ = &subFvm.lookupObject<volScalarField>(isoField_); } else { if (debug) { Info<< "sampledIsoSurface::getIsoFields() : " << "subsetting volField " << isoField_ << endl; } storedVolSubFieldPtr_.reset ( subMeshPtr_().interpolate ( *volFieldPtr_ ).ptr() ); storedVolSubFieldPtr_->checkOut(); volSubFieldPtr_ = storedVolSubFieldPtr_.operator->(); } // Pointfield on submesh word pointFldName = "volPointInterpolate(" + volSubFieldPtr_->name() + ')'; if (subFvm.foundObject<pointScalarField>(pointFldName)) { if (debug) { Info<< "sampledIsoSurface::getIsoFields() :" << " submesh lookup pointField " << pointFldName << endl; } storedPointSubFieldPtr_.clear(); pointSubFieldPtr_ = &subFvm.lookupObject<pointScalarField> ( pointFldName ); } else { if (debug) { Info<< "sampledIsoSurface::getIsoFields() :" << " interpolating submesh volField " << volSubFieldPtr_->name() << " to get submesh pointField " << pointFldName << endl; } storedPointSubFieldPtr_.reset ( volPointInterpolation::New ( subFvm ).interpolate(*volSubFieldPtr_).ptr() ); storedPointSubFieldPtr_->checkOut(); pointSubFieldPtr_ = storedPointSubFieldPtr_.operator->(); } // If averaging redo the volField. Can only be done now since needs the // point field. if (average_) { storedVolSubFieldPtr_.reset ( pointAverage(*pointSubFieldPtr_).ptr() ); volSubFieldPtr_ = storedVolSubFieldPtr_.operator->(); } if (debug) { Info<< "sampledIsoSurface::getIsoFields() : volSubField " << volSubFieldPtr_->name() << " min:" << min(*volSubFieldPtr_).value() << " max:" << max(*volSubFieldPtr_).value() << endl; Info<< "sampledIsoSurface::getIsoFields() : pointSubField " << pointSubFieldPtr_->name() << " min:" << gMin(pointSubFieldPtr_->internalField()) << " max:" << gMax(pointSubFieldPtr_->internalField()) << endl; } } }
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; } } }
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; } }
void Foam::sampledIsoSurface::getIsoFields() const { const fvMesh& fvm = static_cast<const fvMesh&>(mesh()); // Get volField // ~~~~~~~~~~~~ if (fvm.foundObject<volScalarField>(isoField_)) { if (debug) { InfoInFunction << "Lookup volField " << isoField_ << endl; } storedVolFieldPtr_.clear(); volFieldPtr_ = &fvm.lookupObject<volScalarField>(isoField_); } else { // Bit of a hack. Read field and store. if (debug) { InfoInFunction << "Checking " << isoField_ << " for same time " << fvm.time().timeName() << endl; } if ( storedVolFieldPtr_.empty() || (fvm.time().timeName() != storedVolFieldPtr_().instance()) ) { if (debug) { InfoInFunction << "Reading volField " << isoField_ << " from time " << fvm.time().timeName() << endl; } IOobject vfHeader ( isoField_, fvm.time().timeName(), fvm, IOobject::MUST_READ, IOobject::NO_WRITE, false ); if (vfHeader.typeHeaderOk<volScalarField>(true)) { storedVolFieldPtr_.reset ( new volScalarField ( vfHeader, fvm ) ); volFieldPtr_ = storedVolFieldPtr_.operator->(); } else { FatalErrorInFunction << "Cannot find isosurface field " << isoField_ << " in database or directory " << vfHeader.path() << exit(FatalError); } } } // Get pointField // ~~~~~~~~~~~~~~ // In case of multiple iso values we don't want to calculate multiple e.g. // "volPointInterpolate(p)" so register it and re-use it. This is the // same as the 'cache' functionality from volPointInterpolate but // unfortunately that one does not guarantee that the field pointer // remain: e.g. some other functionObject might delete the cached version. // (volPointInterpolation::interpolate with cache=false deletes any // registered one or if mesh.changing()) if (!subMeshPtr_.valid()) { const word pointFldName = "volPointInterpolate_" + type() + "(" + isoField_ + ')'; if (fvm.foundObject<pointScalarField>(pointFldName)) { if (debug) { InfoInFunction << "lookup pointField " << pointFldName << endl; } const pointScalarField& pfld = fvm.lookupObject<pointScalarField> ( pointFldName ); if (!pfld.upToDate(*volFieldPtr_)) { if (debug) { InfoInFunction << "updating pointField " << pointFldName << endl; } // Update the interpolated value volPointInterpolation::New(fvm).interpolate ( *volFieldPtr_, const_cast<pointScalarField&>(pfld) ); } pointFieldPtr_ = &pfld; } else { // Not in registry. Interpolate. if (debug) { InfoInFunction << "Checking pointField " << pointFldName << " for same time " << fvm.time().timeName() << endl; } // Interpolate without cache. Note that we're registering it // below so next time round it goes into the condition // above. tmp<pointScalarField> tpfld ( volPointInterpolation::New(fvm).interpolate ( *volFieldPtr_, pointFldName, false ) ); pointFieldPtr_ = tpfld.ptr(); const_cast<pointScalarField*>(pointFieldPtr_)->store(); } // If averaging redo the volField. Can only be done now since needs the // point field. if (average_) { storedVolFieldPtr_.reset ( pointAverage(*pointFieldPtr_).ptr() ); volFieldPtr_ = storedVolFieldPtr_.operator->(); } if (debug) { InfoInFunction << "volField " << volFieldPtr_->name() << " min:" << min(*volFieldPtr_).value() << " max:" << max(*volFieldPtr_).value() << endl; InfoInFunction << "pointField " << pointFieldPtr_->name() << " min:" << gMin(pointFieldPtr_->primitiveField()) << " max:" << gMax(pointFieldPtr_->primitiveField()) << endl; } } else { // Get subMesh variants const fvMesh& subFvm = subMeshPtr_().subMesh(); // Either lookup on the submesh or subset the whole-mesh volField if (subFvm.foundObject<volScalarField>(isoField_)) { if (debug) { InfoInFunction << "Sub-mesh lookup volField " << isoField_ << endl; } storedVolSubFieldPtr_.clear(); volSubFieldPtr_ = &subFvm.lookupObject<volScalarField>(isoField_); } else { if (debug) { InfoInFunction << "Sub-setting volField " << isoField_ << endl; } storedVolSubFieldPtr_.reset ( subMeshPtr_().interpolate ( *volFieldPtr_ ).ptr() ); storedVolSubFieldPtr_->checkOut(); volSubFieldPtr_ = storedVolSubFieldPtr_.operator->(); } // Pointfield on submesh word pointFldName = "volPointInterpolate(" + volSubFieldPtr_->name() + ')'; if (subFvm.foundObject<pointScalarField>(pointFldName)) { if (debug) { InfoInFunction << "Sub-mesh lookup pointField " << pointFldName << endl; } storedPointSubFieldPtr_.clear(); pointSubFieldPtr_ = &subFvm.lookupObject<pointScalarField> ( pointFldName ); } else { if (debug) { InfoInFunction << "Interpolating submesh volField " << volSubFieldPtr_->name() << " to get submesh pointField " << pointFldName << endl; } storedPointSubFieldPtr_.reset ( volPointInterpolation::New ( subFvm ).interpolate(*volSubFieldPtr_).ptr() ); storedPointSubFieldPtr_->checkOut(); pointSubFieldPtr_ = storedPointSubFieldPtr_.operator->(); } // If averaging redo the volField. Can only be done now since needs the // point field. if (average_) { storedVolSubFieldPtr_.reset ( pointAverage(*pointSubFieldPtr_).ptr() ); volSubFieldPtr_ = storedVolSubFieldPtr_.operator->(); } if (debug) { InfoInFunction << "volSubField " << volSubFieldPtr_->name() << " min:" << min(*volSubFieldPtr_).value() << " max:" << max(*volSubFieldPtr_).value() << endl; InfoInFunction << "pointSubField " << pointSubFieldPtr_->name() << " min:" << gMin(pointSubFieldPtr_->primitiveField()) << " max:" << gMax(pointSubFieldPtr_->primitiveField()) << endl; } } }