bool Foam::functionObjects::regionFunctionObject::store ( word& fieldName, const tmp<ObjectType>& tfield, bool cacheable ) { if (cacheable && fieldName == tfield().name()) { WarningInFunction << "Cannot store cache-able field with the named used in the cache." << nl << " Either choose a different name or cache the field" << " and use the 'writeObjects' functionObject." << endl; return false; } if ( fieldName.size() && obr_.foundObject<ObjectType>(fieldName) ) { const ObjectType& field = ( obr_.lookupObject<ObjectType>(fieldName) ); // If there is a result field already registered assign to the new // result field otherwise transfer ownership of the new result field to // the object registry if (&field != &tfield()) { const_cast<ObjectType&>(field) = tfield; } else { obr_.objectRegistry::store(tfield.ptr()); } } else { if (fieldName.size() && fieldName != tfield().name()) { tfield.ref().rename(fieldName); } else { fieldName = tfield().name(); } obr_.objectRegistry::store(tfield.ptr()); } return true; }
Foam::surfMesh::surfMesh(const IOobject& io, const word& surfName) : surfaceRegistry(io.db(), (surfName.size() ? surfName : io.name())), Allocator ( IOobject ( "points", time().findInstance(meshDir(), "points"), meshSubDir, *this, IOobject::MUST_READ, IOobject::NO_WRITE ), IOobject ( "faces", time().findInstance(meshDir(), "faces"), meshSubDir, *this, IOobject::MUST_READ, IOobject::NO_WRITE ), IOobject ( "surfZones", time().findInstance(meshDir(), "surfZones"), meshSubDir, *this, IOobject::MUST_READ, IOobject::NO_WRITE ) ), MeshReference(this->storedIOFaces(), this->storedIOPoints()) {}
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::home(const word& userName) { struct passwd* pw; if (userName.size()) { pw = getpwnam(userName.c_str()); } else { char* env = getenv("HOME"); if (env != NULL) { return fileName(env); } pw = getpwuid(getuid()); } if (pw != NULL) { return pw->pw_dir; } else { return fileName::null; } }
// Construct from components Foam::vtkMesh::vtkMesh ( const IOobject& io, const word& setName ) : fvMesh(io), subsetMesh_ ( IOobject ( "subset", io.time().constant(), *this, IOobject::NO_READ, IOobject::NO_WRITE ), *this ), setName_(setName) { if (setName.size()) { // Read cellSet using whole mesh cellSet currentSet(*this, setName_); // Set current subset subsetMesh_.setLargeCellSubset(currentSet); } }
Foam::cloud::cloud(const objectRegistry& obr, const word& cloudName) : objectRegistry ( IOobject ( (cloudName.size() ? cloudName : defaultName), obr.time().timeName(), prefix, obr, IOobject::NO_READ, IOobject::AUTO_WRITE ) ) { if (isA<polyMesh>(obr)) { if (debug) { Pout<< "cloud: Initialising polyMesh nGeometricD" << endl; } // initialise mesh dimensions - needed for parallel runs // due to lazy evaluation of valid mesh dimensions const polyMesh& mesh = dynamic_cast<const polyMesh&>(obr); const_cast<polyMesh&>(mesh).nGeometricD(); } }
bool Foam::primitiveEntry::expandFunction ( const word& keyword, const dictionary& parentDict, Istream& is ) { word functionName = keyword(1, keyword.size()-1); return functionEntry::execute(functionName, parentDict, *this, is); }
Foam::fileName Foam::fileFormats::surfaceFormatsCore::localMeshFileName ( const word& surfName ) { const word name(surfName.size() ? surfName : surfaceRegistry::defaultName); return fileName ( surfaceRegistry::prefix/name/surfMesh::meshSubDir / name + "." + nativeExt ); }
Foam::cloud::cloud(const objectRegistry& obr, const word& cloudName) : objectRegistry ( IOobject ( ( cloudName.size() ? cloudName : defaultName ), obr.time().timeName(), prefix, obr, IOobject::NO_READ, IOobject::AUTO_WRITE ) ) {}
Foam::surfMesh::surfMesh ( const IOobject& io, const Xfer<pointField>& pointLst, const Xfer<faceList>& faceLst, const word& surfName ) : surfaceRegistry(io.db(), (surfName.size() ? surfName : io.name())), Allocator ( IOobject ( "points", instance(), meshSubDir, *this, IOobject::NO_READ, IOobject::AUTO_WRITE ), pointLst, IOobject ( "faces", instance(), meshSubDir, *this, IOobject::NO_READ, IOobject::AUTO_WRITE ), faceLst, IOobject ( "surfZones", instance(), meshSubDir, *this, IOobject::NO_READ, IOobject::AUTO_WRITE ), Xfer<surfZoneList>() ), MeshReference(this->storedIOFaces(), this->storedIOPoints()) {}
Foam::surfaceRegistry::surfaceRegistry ( const objectRegistry& obr, const word& surfName ) : objectRegistry ( IOobject ( ( surfName.size() ? surfName : defaultName ), obr.time().timeName(), prefix, obr, IOobject::NO_READ, IOobject::NO_WRITE ) ) {}
// Construct from components Foam::vtkMesh::vtkMesh ( fvMesh& baseMesh, const word& setName ) : baseMesh_(baseMesh), subsetter_(baseMesh), setName_(setName) { if (setName.size()) { // Read cellSet using whole mesh cellSet currentSet(baseMesh_, setName_); // Set current subset subsetter_.setLargeCellSubset(currentSet); } }
void Foam::hierarchGeomDecomp::setDecompOrder() { const word order(geomDecomDict_.lookup("order")); if (order.size() != 3) { FatalIOErrorIn ( "hierarchGeomDecomp::hierarchGeomDecomp" "(const dictionary& decompositionDict)", decompositionDict_ ) << "number of characters in order (" << order << ") != 3" << exit(FatalIOError); } for (label i = 0; i < 3; ++i) { if (order[i] == 'x') { decompOrder_[i] = 0; } else if (order[i] == 'y') { decompOrder_[i] = 1; } else if (order[i] == 'z') { decompOrder_[i] = 2; } else { FatalIOErrorIn ( "hierarchGeomDecomp::hierarchGeomDecomp" "(const dictionary& decompositionDict)", decompositionDict_ ) << "Illegal decomposition order " << order << endl << "It should only contain x, y or z" << exit(FatalError); } } }
void Foam::MeshedSurfaceProxy<Face>::write ( const Time& t, const word& surfName ) const { // the surface name to be used word name(surfName.size() ? surfName : surfaceRegistry::defaultName); if (debug) { Info<< "MeshedSurfaceProxy::write" "(const Time&, const word&) : " "writing to " << name << endl; } // the local location const fileName objectDir ( t.timePath()/surfaceRegistry::prefix/name/surfMesh::meshSubDir ); if (!isDir(objectDir)) { mkDir(objectDir); } // write surfMesh/points { pointIOField io ( IOobject ( "points", t.timeName(), surfMesh::meshSubDir, t, IOobject::NO_READ, IOobject::NO_WRITE, false ) ); OFstream os ( objectDir/io.name(), t.writeFormat(), IOstream::currentVersion, t.writeCompression() ); io.writeHeader(os); os << this->points(); io.writeEndDivider(os); } // write surfMesh/faces { faceCompactIOList io ( IOobject ( "faces", t.timeName(), surfMesh::meshSubDir, t, IOobject::NO_READ, IOobject::NO_WRITE, false ) ); OFstream os ( objectDir/io.name(), t.writeFormat(), IOstream::currentVersion, t.writeCompression() ); io.writeHeader(os); if (this->useFaceMap()) { // this is really a bit annoying (and wasteful) but no other way os << reorder(this->faceMap(), this->faces()); } else { os << this->faces(); } io.writeEndDivider(os); } // write surfMesh/surfZones { surfZoneIOList io ( IOobject ( "surfZones", t.timeName(), surfMesh::meshSubDir, t, IOobject::NO_READ, IOobject::NO_WRITE, false ) ); // write as ascii OFstream os(objectDir/io.name()); io.writeHeader(os); os << this->surfZones(); io.writeEndDivider(os); } }
Foam::string& Foam::stringOps::inplaceExpand ( string& s, const dictionary& dict, const bool allowEnvVars, const bool allowEmpty, const char sigil ) { string::size_type begVar = 0; // Expand $VAR or ${VAR} // Repeat until nothing more is found while ( (begVar = s.find(sigil, begVar)) != string::npos && begVar < s.size()-1 ) { if (begVar == 0 || s[begVar-1] != '\\') { if (s[begVar+1] == '{') { // Recursive variable expansion mode label stringStart = begVar; begVar += 2; string varValue ( expand ( s, begVar, dict, allowEnvVars, allowEmpty ) ); s.std::string::replace ( stringStart, begVar - stringStart + 1, varValue ); begVar = stringStart+varValue.size(); } else { string::iterator iter = s.begin() + begVar + 1; // more generous in accepting keywords than for env variables string::size_type endVar = begVar; while ( iter != s.end() && ( isalnum(*iter) || *iter == '.' || *iter == ':' || *iter == '_' ) ) { ++iter; ++endVar; } const word varName ( s.substr ( begVar + 1, endVar - begVar ), false ); string varValue ( getVariable ( varName, dict, allowEnvVars, allowEmpty ) ); s.std::string::replace ( begVar, varName.size()+1, varValue ); begVar += varValue.size(); } } else { ++begVar; } } if (!s.empty()) { if (s[0] == '~') { // Expand initial ~ // ~/ => home directory // ~OpenFOAM => site/user OpenFOAM configuration directory // ~user => home directory for specified user string user; fileName file; if ((begVar = s.find('/')) != string::npos) { user = s.substr(1, begVar - 1); file = s.substr(begVar + 1); } else { user = s.substr(1); } // NB: be a bit lazy and expand ~unknownUser as an // empty string rather than leaving it untouched. // otherwise add extra test if (user == "OpenFOAM") { s = findEtcFile(file); } else { s = home(user)/file; } } else if (s[0] == '.') { // Expand a lone '.' and an initial './' into cwd if (s.size() == 1) { s = cwd(); } else if (s[1] == '/') { s.std::string::replace(0, 1, cwd()); } } } return s; }
void setScoped ( dictionary& dict, const word& keyword, const bool overwrite, entry* d ) { if (keyword[0] == ':') { // Go up to top level and recurse to find entries setScoped ( const_cast<dictionary&>(dict.topDict()), keyword.substr(1, keyword.size()-1), overwrite, d ); return; } else { string::size_type dotPos = keyword.find('.'); if (dotPos == string::npos) { // Non-scoped lookup if (overwrite) { dict.set(d); } else { dict.add(d, false); } return; } else { if (dotPos == 0) { // Starting with a '.'. Go up for every 2nd '.' found const dictionary* dictPtr = &dict; string::size_type begVar = dotPos + 1; string::const_iterator iter = keyword.begin() + begVar; string::size_type endVar = begVar; while ( iter != keyword.end() && *iter == '.' ) { ++iter; ++endVar; // Go to parent if (&dictPtr->parent() == &dictionary::null) { FatalIOErrorInFunction(dict) << "No parent of current dictionary" << " when searching for " << keyword.substr ( begVar, keyword.size() - begVar ) << exit(FatalIOError); } dictPtr = &dictPtr->parent(); } setScoped ( const_cast<dictionary&>(*dictPtr), keyword.substr(endVar), overwrite, d ); return; } else { // Extract the first word word firstWord = keyword.substr(0, dotPos); const entry* entPtr = dict.lookupScopedEntryPtr ( firstWord, false, // Recursive false ); if (!entPtr || !entPtr->isDict()) { FatalIOErrorInFunction(dict) << "keyword " << firstWord << " is undefined in dictionary " << dict.name() << " or is not a dictionary" << endl << "Valid keywords are " << dict.keys() << exit(FatalIOError); } const dictionary& firstDict = entPtr->dict(); setScoped ( const_cast<dictionary&>(firstDict), keyword.substr(dotPos, keyword.size()-dotPos), overwrite, d ); return; } } } }