void Foam::lagrangianFieldDecomposer::readFields ( const label cloudI, const IOobjectList& lagrangianObjects, PtrList<PtrList<IOField<Type> > >& lagrangianFields ) { // Search list of objects for lagrangian fields IOobjectList lagrangianTypeObjects ( lagrangianObjects.lookupClass(IOField<Type>::typeName) ); lagrangianFields.set ( cloudI, new PtrList<IOField<Type> > ( lagrangianTypeObjects.size() ) ); label lagrangianFieldi = 0; forAllIter(IOobjectList, lagrangianTypeObjects, iter) { lagrangianFields[cloudI].set ( lagrangianFieldi++, new IOField<Type>(*iter()) ); }
void readFields ( PtrList<List<Type> >& values, const List<word>& fieldNames, const IOobjectList& cloudObjs ) { IOobjectList objects(cloudObjs.lookupClass(IOField<Type>::typeName)); forAll(fieldNames, j) { const IOobject* obj = objects.lookup(fieldNames[j]); if (obj != NULL) { Info<< " reading field " << fieldNames[j] << endl; IOField<Type> newField(*obj); values.set(j, new List<Type>(newField.xfer())); } else { FatalErrorIn ( "template<class Type>" "void readFields" "(" "PtrList<List<Type> >&, " "const List<word>&, " "const IOobjectList&" ")" ) << "Unable to read field " << fieldNames[j] << abort(FatalError); } } }
tmp<Field<Type> > readParticleField ( const word& name, const IOobjectList cloudObjs ) { IOobjectList objects(cloudObjs.lookupClass(IOField<Type>::typeName)); const IOobject* obj = objects.lookup(name); if (obj != NULL) { IOField<Type> newField(*obj); return tmp<Field<Type> >(new Field<Type>(newField.xfer())); } FatalErrorIn ( "template<class Type>" "void readParticleField" "(" "const word&, " "const IOobjectList" ")" ) << "error: cloud field name " << name << " not found" << abort(FatalError); return Field<Type>::null(); }
wordList ReadUniformFields ( const IOobjectList& objects, PtrList<GeoField>& fields, const bool syncPar ) { // Search list of objects for wanted type IOobjectList fieldObjects(objects.lookupClass(GeoField::typeName)); wordList masterNames(fieldObjects.names()); if (syncPar && Pstream::parRun()) { // Check that I have the same fields as the master const wordList localNames(masterNames); Pstream::scatter(masterNames); HashSet<word> localNamesSet(localNames); forAll(masterNames, i) { const word& masterFld = masterNames[i]; HashSet<word>::iterator iter = localNamesSet.find(masterFld); if (iter == localNamesSet.end()) { FatalErrorIn ( "ReadFields<class GeoField>" "(const IOobjectList&, PtrList<GeoField>&" ", const bool)" ) << "Fields not synchronised across processors." << endl << "Master has fields " << masterNames << " processor " << Pstream::myProcNo() << " has fields " << localNames << exit(FatalError); } else { localNamesSet.erase(iter); } } forAllConstIter(HashSet<word>, localNamesSet, iter) { FatalErrorIn ( "ReadFields<class GeoField>" "(const IOobjectList&, PtrList<GeoField>&" ", const bool)" ) << "Fields not synchronised across processors." << endl << "Master has fields " << masterNames << " processor " << Pstream::myProcNo() << " has fields " << localNames << exit(FatalError); } }
void processField ( const fvMesh& mesh, const IOobjectList& objects, const word& fieldName, label& processed ) { if (processed != -1) { return; } typedef GeometricField<Type, fvPatchField, volMesh> fieldType; const word timeName(mesh.time().timeName()); IOobjectList fieldObjbjects(objects.lookupClass(fieldType::typeName)); if (fieldObjbjects.lookup(fieldName) != NULL) { fieldType vtf(*fieldObjbjects.lookup(fieldName), mesh); const typename fieldType::GeometricBoundaryField& bf = vtf.boundaryField(); forAll(bf, patchI) { if (isA<externalCoupledMixedFvPatchField<Type> >(bf[patchI])) { Info<< "Generating external coupled geometry for field " << fieldName << endl; const externalCoupledMixedFvPatchField<Type>& pf = refCast<const externalCoupledMixedFvPatchField<Type> > ( bf[patchI] ); pf.writeGeometry(); processed = 1; break; } } if (processed != 1) { processed = 0; Info<< "Field " << fieldName << " found, but does not have any " << externalCoupledMixedFvPatchField<Type>::typeName << " boundary conditions" << endl; } }
bool checkFields ( const fvMesh& mesh, const IOobjectList& objects, GeoField* dummy ) { // Search list of objects for volScalarFields IOobjectList fieldObjects(objects.lookupClass(GeoField::typeName)); for ( IOobjectList::iterator iter = fieldObjects.begin(); iter != fieldObjects.end(); ++iter ) { GeoField current(*iter(), mesh); GeoField ref ( IOobject ( "reference"/mesh.time().timeName()/current.name(), mesh, IOobject::MUST_READ ), mesh ); dimensionedScalar small("small", ref.dimensions(), SMALL); volScalarField error = mag(current - ref)/stabilise(mag(ref), small); dimensionedScalar maxError = max(error); Info << ref.name() << tab << maxError.value() << endl; if ( maxError.value() > 0.001 ) { return true; } } return false; }
void RotateFields ( const fvMesh& mesh, const IOobjectList& objects, const tensor& T ) { // Search list of objects for volScalarFields IOobjectList fields(objects.lookupClass(GeometricField::typeName)); forAllIter(IOobjectList, fields, fieldIter) { Info<< " Rotating " << fieldIter()->name() << endl; GeometricField theta(*fieldIter(), mesh); transform(theta, dimensionedTensor(T), theta); theta.write(); }
void readFields ( const vtkMesh& vMesh, const typename GeoField::Mesh& mesh, const IOobjectList& objects, const HashSet<word>& selectedFields, PtrList<GeoField>& fields ) { // Search list of objects for volScalarFields IOobjectList fieldObjects(objects.lookupClass(GeoField::typeName)); // Construct the vol scalar fields label nFields = fields.size(); fields.setSize(nFields + fieldObjects.size()); for ( IOobjectList::iterator iter = fieldObjects.begin(); iter != fieldObjects.end(); ++iter ) { if (selectedFields.empty() || selectedFields.found(iter()->name())) { fields.set ( nFields, vMesh.interpolate ( GeoField ( *iter(), mesh ) ) ); nFields++; } } fields.setSize(nFields); }
void Foam::readFields ( const Mesh& mesh, const IOobjectList& objects, PtrList<GeoField>& fields ) { // Search list of objects for volScalarFields IOobjectList fieldObjects(objects.lookupClass(GeoField::typeName)); // Remove the cellDist field IOobjectList::iterator celDistIter = fieldObjects.find("cellDist"); if (celDistIter != fieldObjects.end()) { fieldObjects.erase(celDistIter); } // Construct the vol scalar fields fields.setSize(fieldObjects.size()); label fieldi=0; for ( IOobjectList::iterator iter = fieldObjects.begin(); iter != fieldObjects.end(); ++iter ) { fields.set ( fieldi++, new GeoField ( *iter(), mesh ) ); } }
void ReadAndMapFields ( const fvMesh& mesh, const IOobjectList& objects, const fvMesh& tetDualMesh, const labelList& map, const typename MappedGeoField::value_type& nullValue, PtrList<MappedGeoField>& tetFields ) { typedef typename MappedGeoField::value_type Type; // Search list of objects for wanted type IOobjectList fieldObjects(objects.lookupClass(ReadGeoField::typeName)); tetFields.setSize(fieldObjects.size()); label i = 0; forAllConstIter(IOobjectList, fieldObjects, iter) { Info<< "Converting " << ReadGeoField::typeName << ' ' << iter.key() << endl; ReadGeoField readField(*iter(), mesh); tetFields.set ( i, new MappedGeoField ( IOobject ( readField.name(), readField.instance(), readField.local(), tetDualMesh, IOobject::NO_READ, IOobject::AUTO_WRITE, readField.registerObject() ), pointMesh::New(tetDualMesh), dimensioned<Type> ( "zero", readField.dimensions(), pTraits<Type>::zero ) ) ); Field<Type>& fld = tetFields[i].internalField(); // Map from read field. Set unmapped entries to nullValue. fld.setSize(map.size(), nullValue); forAll(map, pointI) { label index = map[pointI]; if (index > 0) { label cellI = index-1; fld[pointI] = readField[cellI]; } else if (index < 0) { label faceI = -index-1; label bFaceI = faceI - mesh.nInternalFaces(); if (bFaceI >= 0) { label patchI = mesh.boundaryMesh().patchID()[bFaceI]; label localFaceI = mesh.boundaryMesh()[patchI].whichFace ( faceI ); fld[pointI] = readField.boundaryField()[patchI][localFaceI]; } //else //{ // FatalErrorIn("ReadAndMapFields(..)") // << "Face " << faceI << " from index " << index // << " is not a boundary face." << abort(FatalError); //} } //else //{ // WarningIn("ReadAndMapFields(..)") // << "Point " << pointI << " at " // << tetDualMesh.points()[pointI] // << " has no dual correspondence." << endl; //} }
void setUpdater::updateSets(const mapPolyMesh& morphMap) const { // // Update all sets in memory. // HashTable<const Type*> memSets = morphMap.mesh().objectRegistry::lookupClass<Type>(); for ( typename HashTable<const Type*>::iterator iter = memSets.begin(); iter != memSets.end(); ++iter ) { Type& set = const_cast<Type&>(*iter()); if (debug) { Pout<< "Set:" << set.name() << " size:" << set.size() << " updated in memory" << endl; } set.updateMesh(morphMap); // Write or not? Debatable. set.write(); } // // Update all sets on disk // // Get last valid mesh (discard points-only change) IOobjectList Objects ( morphMap.mesh().time(), morphMap.mesh().time().findInstance ( morphMap.mesh().meshDir(), "faces" ), "polyMesh/sets" ); IOobjectList fileSets(Objects.lookupClass(Type::typeName)); for ( IOobjectList::const_iterator iter = fileSets.begin(); iter != fileSets.end(); ++iter ) { if (!memSets.found(iter.key())) { // Not in memory. Load it. Type set(*iter()); if (debug) { Pout<< "Set:" << set.name() << " size:" << set.size() << " updated on disk" << endl; } set.updateMesh(morphMap); set.write(); } else { if (debug) { Pout<< "Set:" << iter.key() << " already updated from memory" << endl; } } } }
int main(int argc, char *argv[]) { argList::validOptions.insert("noFlipMap", ""); # include "addRegionOption.H" # include "addTimeOptions.H" # include "setRootCase.H" # include "createTime.H" bool noFlipMap = args.optionFound("noFlipMap"); // Get times list instantList Times = runTime.times(); label startTime = Times.size()-1; label endTime = Times.size(); // check -time and -latestTime options # include "checkTimeOption.H" runTime.setTime(Times[startTime], startTime); # include "createNamedPolyMesh.H" // Search for list of objects for the time of the mesh IOobjectList objects ( mesh, mesh.pointsInstance(), polyMesh::meshSubDir/"sets" ); Info<< "Searched : " << mesh.pointsInstance()/polyMesh::meshSubDir/"sets" << nl << "Found : " << objects.names() << nl << endl; IOobjectList pointObjects(objects.lookupClass(pointSet::typeName)); //Pout<< "pointSets:" << pointObjects.names() << endl; for ( IOobjectList::const_iterator iter = pointObjects.begin(); iter != pointObjects.end(); ++iter ) { // Not in memory. Load it. pointSet set(*iter()); SortableList<label> pointLabels(set.toc()); label zoneID = mesh.pointZones().findZoneID(set.name()); if (zoneID == -1) { Info<< "Adding set " << set.name() << " as a pointZone." << endl; label sz = mesh.pointZones().size(); mesh.pointZones().setSize(sz+1); mesh.pointZones().set ( sz, new pointZone ( set.name(), //name pointLabels, //addressing sz, //index mesh.pointZones() //pointZoneMesh ) ); mesh.pointZones().writeOpt() = IOobject::AUTO_WRITE; mesh.pointZones().instance() = mesh.facesInstance(); } else { Info<< "Overwriting contents of existing pointZone " << zoneID << " with that of set " << set.name() << "." << endl; mesh.pointZones()[zoneID] = pointLabels; mesh.pointZones().writeOpt() = IOobject::AUTO_WRITE; mesh.pointZones().instance() = mesh.facesInstance(); } } IOobjectList faceObjects(objects.lookupClass(faceSet::typeName)); HashSet<word> slaveCellSets; //Pout<< "faceSets:" << faceObjects.names() << endl; for ( IOobjectList::const_iterator iter = faceObjects.begin(); iter != faceObjects.end(); ++iter ) { // Not in memory. Load it. faceSet set(*iter()); SortableList<label> faceLabels(set.toc()); DynamicList<label> addressing(set.size()); DynamicList<bool> flipMap(set.size()); if (!noFlipMap) { word setName(set.name() + "SlaveCells"); Info<< "Trying to load cellSet " << setName << " to find out the slave side of the zone." << nl << "If you do not care about the flipMap" << " (i.e. do not use the sideness)" << nl << "use the -noFlipMap command line option." << endl; // Load corresponding cells cellSet cells(mesh, setName); // Store setName to exclude from cellZones further on slaveCellSets.insert(setName); forAll(faceLabels, i) { label faceI = faceLabels[i]; bool flip = false; if (mesh.isInternalFace(faceI)) { if ( cells.found(mesh.faceOwner()[faceI]) && !cells.found(mesh.faceNeighbour()[faceI]) ) { flip = false; } else if ( !cells.found(mesh.faceOwner()[faceI]) && cells.found(mesh.faceNeighbour()[faceI]) ) { flip = true; } else { FatalErrorIn(args.executable()) << "One of owner or neighbour of internal face " << faceI << " should be in cellSet " << cells.name() << " to be able to determine orientation." << endl << "Face:" << faceI << " own:" << mesh.faceOwner()[faceI] << " OwnInCellSet:" << cells.found(mesh.faceOwner()[faceI]) << " nei:" << mesh.faceNeighbour()[faceI] << " NeiInCellSet:" << cells.found(mesh.faceNeighbour()[faceI]) << abort(FatalError); } } else { if (cells.found(mesh.faceOwner()[faceI])) { flip = false; } else { flip = true; } } addressing.append(faceI); flipMap.append(flip); } }
bool fieldOk(const IOobjectList& cloudObjs, const word& name) { IOobjectList objects(cloudObjs.lookupClass(IOField<Type>::typeName)); return (objects.lookup(name) != NULL); }