Foam::refinementParameters::refinementParameters(const dictionary& dict) : maxGlobalCells_(readLabel(dict.lookup("maxGlobalCells"))), maxLocalCells_(readLabel(dict.lookup("maxLocalCells"))), minRefineCells_(readLabel(dict.lookup("minRefinementCells"))), nBufferLayers_(readLabel(dict.lookup("nCellsBetweenLevels"))), keepPoints_(pointField(1, dict.lookup("locationInMesh"))), allowFreeStandingZoneFaces_ ( dict.lookupOrDefault<Switch> ( "allowFreeStandingZoneFaces", true ) ), maxLoadUnbalance_(dict.lookupOrDefault<scalar>("maxLoadUnbalance",0)) { scalar featAngle(readScalar(dict.lookup("resolveFeatureAngle"))); if (featAngle < 0 || featAngle > 180) { curvature_ = -GREAT; } else { curvature_ = Foam::cos(featAngle*mathematicalConstant::pi/180.0); } }
void Foam::projectEdge::findNearest ( const point& pt, point& near, pointConstraint& constraint ) const { if (surfaces_.size()) { const scalar distSqr = magSqr(points_[end_]-points_[start_]); pointField boundaryNear(1); List<pointConstraint> boundaryConstraint(1); searchableSurfacesQueries::findNearest ( geometry_, surfaces_, pointField(1, pt), scalarField(1, distSqr), boundaryNear, boundaryConstraint ); near = boundaryNear[0]; constraint = boundaryConstraint[0]; } else { near = pt; constraint = pointConstraint(); } }
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::pointField Foam::treeDataPoint::shapePoints() const { if (useSubset_) { return pointField(points_, pointLabels_); } else { return points_; } }
void shiftFieldGeneralPluginFunction<Type,Order>::doEvaluation() { const fvMesh &origMesh=this->mesh(); fvMesh shiftMesh( IOobject( origMesh.name()+"Shifted", origMesh.polyMesh::instance(), origMesh.polyMesh::db() ), #ifdef FOAM_LIST_HAS_MOVABLE_CONSTRUCT pointField(origMesh.points()), faceList(origMesh.faces()), labelList(origMesh.faceOwner()), labelList(origMesh.faceNeighbour()) #else Xfer<pointField>(origMesh.points()), Xfer<faceList>(origMesh.faces()), Xfer<labelList>(origMesh.faceOwner()), Xfer<labelList>(origMesh.faceNeighbour()) #endif ); { const polyBoundaryMesh &origBound=origMesh.boundaryMesh(); List<polyPatch*> newBound(origBound.size(),NULL); forAll(origBound,patchI) { newBound[patchI]=origBound[patchI].clone(shiftMesh.boundaryMesh()).ptr(); } shiftMesh.removeFvBoundary(); #ifdef FOAM_MESHTOMESH_OLD_STYLE shiftMesh.addFvPatches(newBound); #else shiftMesh.addPatches(newBound); #endif #ifdef FOAM_MESHTOMESH_HAS_CORRECTEDCELLVOLUMEWEIGHT shiftMesh.fvSchemes::merge( origMesh.schemesDict() ); shiftMesh.fvSchemes::readOpt()=IOobject::READ_IF_PRESENT; shiftMesh.fvSchemes::read(); // const_cast<dictionary&>(shiftMesh.schemesDict())=origMesh.schemesDict(); // Info << origMesh.schemesDict() << endl; // Info << shiftMesh.schemesDict().name() << endl; // Info << shiftMesh.schemesDict() << endl; // Info << shiftMesh.gradScheme("valsShift") << endl; #endif }
Foam::featureEdgeMesh::featureEdgeMesh(const IOobject& io) : regIOobject(io), edgeMesh(pointField(0), edgeList(0)) { if ( io.readOpt() == IOobject::MUST_READ || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk()) ) { readStream(typeName) >> *this; close(); }
Foam::splineEdge::splineEdge(const pointField& points, Istream& is) : curvedEdge(points, is), CatmullRomSpline(appendEndPoints(points, start_, end_, pointField(is))) { token t(is); is.putBack(t); // compatibility - might also have start/end tangents - discard them if (t == token::BEGIN_LIST) { vector tangent0Ignored(is); vector tangent1Ignored(is); } }
void topoSet::writeDebug ( Ostream& os, const pointField& coords, const label maxLen ) const { // Bounding box of contents. boundBox bb(pointField(coords, toc()), true); os << "Set bounding box: min = " << bb.min() << " max = " << bb.max() << " meters. " << endl << endl; label n = 0; topoSet::const_iterator iter = begin(); if (size() <= maxLen) { writeDebug(os, coords, maxLen, iter, n); } else { label halfLen = maxLen/2; os << "Size larger than " << maxLen << ". Printing first and last " << halfLen << " elements:" << endl << endl; writeDebug(os, coords, halfLen, iter, n); os<< endl << " .." << endl << endl; for (; n < size() - halfLen; ++n) { ++iter; } writeDebug(os, coords, halfLen, iter, n); } }
Foam::polySplineEdge::polySplineEdge ( const pointField& points, Istream& is ) : curvedEdge(points, is), polyLine(pointField(0)), otherKnots_(is) { label nInterKnots(20); vector fstend(is); vector sndend(is); controlPoints_.setSize(nsize(otherKnots_.size(), nInterKnots)); distances_.setSize(controlPoints_.size()); controlPoints_ = intervening(otherKnots_, nInterKnots, fstend, sndend); calcDistances(); }
Foam::refinementParameters::refinementParameters(const dictionary& dict) : maxGlobalCells_(readLabel(dict.lookup("maxGlobalCells"))), maxLocalCells_(readLabel(dict.lookup("maxLocalCells"))), minRefineCells_(readLabel(dict.lookup("minRefinementCells"))), planarAngle_ ( dict.lookupOrDefault ( "planarAngle", readScalar(dict.lookup("resolveFeatureAngle")) ) ), nBufferLayers_(readLabel(dict.lookup("nCellsBetweenLevels"))), keepPoints_(pointField(1, dict.lookup("locationInMesh"))), allowFreeStandingZoneFaces_(dict.lookup("allowFreeStandingZoneFaces")), useTopologicalSnapDetection_ ( dict.lookupOrDefault<bool>("useTopologicalSnapDetection", true) ), maxLoadUnbalance_(dict.lookupOrDefault<scalar>("maxLoadUnbalance", 0)), handleSnapProblems_ ( dict.lookupOrDefault<Switch>("handleSnapProblems", true) ) { scalar featAngle(readScalar(dict.lookup("resolveFeatureAngle"))); if (featAngle < 0 || featAngle > 180) { curvature_ = -GREAT; } else { curvature_ = Foam::cos(degToRad(featAngle)); } }
bool surfaceOffsetLinearDistance::cellSize ( const point& pt, scalar& size ) const { size = 0; List<pointIndexHit> hits; surface_.findNearest ( pointField(1, pt), scalarField(1, totalDistanceSqr_), regionIndices_, hits ); const pointIndexHit& hitInfo = hits[0]; if (hitInfo.hit()) { const point& hitPt = hitInfo.hitPoint(); const label hitIndex = hitInfo.index(); const scalar dist = mag(pt - hitPt); if (sideMode_ == rmBothsides) { size = sizeFunction(hitPt, dist, hitIndex); return true; } // If the nearest point is essentially on the surface, do not do a // getVolumeType calculation, as it will be prone to error. if (mag(pt - hitInfo.hitPoint()) < snapToSurfaceTol_) { size = sizeFunction(hitPt, 0, hitIndex); return true; } pointField ptF(1, pt); List<volumeType> vTL; surface_.getVolumeType(ptF, vTL); bool functionApplied = false; if ( sideMode_ == smInside && vTL[0] == volumeType::INSIDE ) { size = sizeFunction(hitPt, dist, hitIndex); functionApplied = true; } else if ( sideMode_ == smOutside && vTL[0] == volumeType::OUTSIDE ) { size = sizeFunction(hitPt, dist, hitIndex); functionApplied = true; } return functionApplied; } return false; }
void Foam::timeVaryingMappedFixedValuePointPatchField<Type>::checkTable() { // Initialise if (startSampleTime_ == -1 && endSampleTime_ == -1) { const polyMesh& pMesh = this->patch().boundaryMesh().mesh()(); // Read the initial point position pointField meshPts; if (pMesh.pointsInstance() == pMesh.facesInstance()) { meshPts = pointField(pMesh.points(), this->patch().meshPoints()); } else { // Load points from facesInstance if (debug) { Info<< "Reloading points0 from " << pMesh.facesInstance() << endl; } pointIOField points0 ( IOobject ( "points", pMesh.facesInstance(), polyMesh::meshSubDir, pMesh, IOobject::MUST_READ, IOobject::NO_WRITE, false ) ); meshPts = pointField(points0, this->patch().meshPoints()); } pointIOField samplePoints ( IOobject ( "points", this->db().time().constant(), "boundaryData"/this->patch().name(), this->db(), IOobject::MUST_READ, IOobject::AUTO_WRITE, false ) ); // tbd: run-time selection bool nearestOnly = ( !mapMethod_.empty() && mapMethod_ != "planarInterpolation" ); // Allocate the interpolator mapperPtr_.reset ( new pointToPointPlanarInterpolation ( samplePoints, meshPts, perturb_, nearestOnly ) ); // Read the times for which data is available const fileName samplePointsFile = samplePoints.filePath(); const fileName samplePointsDir = samplePointsFile.path(); sampleTimes_ = Time::findTimes(samplePointsDir); if (debug) { Info<< "timeVaryingMappedFixedValuePointPatchField : In directory " << samplePointsDir << " found times " << pointToPointPlanarInterpolation::timeNames(sampleTimes_) << endl; } } // Find current time in sampleTimes label lo = -1; label hi = -1; bool foundTime = mapperPtr_().findTime ( sampleTimes_, startSampleTime_, this->db().time().value(), lo, hi ); if (!foundTime) { FatalErrorIn ( "timeVaryingMappedFixedValuePointPatchField<Type>::checkTable" ) << "Cannot find starting sampling values for current time " << this->db().time().value() << nl << "Have sampling values for times " << pointToPointPlanarInterpolation::timeNames(sampleTimes_) << nl << "In directory " << this->db().time().constant()/"boundaryData"/this->patch().name() << "\n on patch " << this->patch().name() << " of field " << fieldTableName_ << exit(FatalError); } // Update sampled data fields. if (lo != startSampleTime_) { startSampleTime_ = lo; if (startSampleTime_ == endSampleTime_) { // No need to reread since are end values if (debug) { Pout<< "checkTable : Setting startValues to (already read) " << "boundaryData" /this->patch().name() /sampleTimes_[startSampleTime_].name() << endl; } startSampledValues_ = endSampledValues_; startAverage_ = endAverage_; } else { if (debug) { Pout<< "checkTable : Reading startValues from " << "boundaryData" /this->patch().name() /sampleTimes_[lo].name() << endl; } // Reread values and interpolate AverageIOField<Type> vals ( IOobject ( fieldTableName_, this->db().time().constant(), "boundaryData" /this->patch().name() /sampleTimes_[startSampleTime_].name(), this->db(), IOobject::MUST_READ, IOobject::AUTO_WRITE, false ) ); if (vals.size() != mapperPtr_().sourceSize()) { FatalErrorIn ( "timeVaryingMappedFixedValuePointPatchField<Type>::" "checkTable()" ) << "Number of values (" << vals.size() << ") differs from the number of points (" << mapperPtr_().sourceSize() << ") in file " << vals.objectPath() << exit(FatalError); } startAverage_ = vals.average(); startSampledValues_ = mapperPtr_().interpolate(vals); } } if (hi != endSampleTime_) { endSampleTime_ = hi; if (endSampleTime_ == -1) { // endTime no longer valid. Might as well clear endValues. if (debug) { Pout<< "checkTable : Clearing endValues" << endl; } endSampledValues_.clear(); } else { if (debug) { Pout<< "checkTable : Reading endValues from " << "boundaryData" /this->patch().name() /sampleTimes_[endSampleTime_].name() << endl; } // Reread values and interpolate AverageIOField<Type> vals ( IOobject ( fieldTableName_, this->db().time().constant(), "boundaryData" /this->patch().name() /sampleTimes_[endSampleTime_].name(), this->db(), IOobject::MUST_READ, IOobject::AUTO_WRITE, false ) ); if (vals.size() != mapperPtr_().sourceSize()) { FatalErrorIn ( "timeVaryingMappedFixedValuePointPatchField<Type>::" "checkTable()" ) << "Number of values (" << vals.size() << ") differs from the number of points (" << mapperPtr_().sourceSize() << ") in file " << vals.objectPath() << exit(FatalError); } endAverage_ = vals.average(); endSampledValues_ = mapperPtr_().interpolate(vals); } } }
bool linearSpatial::cellSize ( const point& pt, scalar& size ) const { if (sideMode_ == rmBothsides) { size = sizeFunction(pt); return true; } size = 0; List<pointIndexHit> hits; surface_.findNearest ( pointField(1, pt), scalarField(1, sqr(snapToSurfaceTol_)), regionIndices_, hits ); const pointIndexHit& hitInfo = hits[0]; // If the nearest point is essentially on the surface, do not do a // getVolumeType calculation, as it will be prone to error. if (hitInfo.hit()) { size = sizeFunction(pt); return true; } pointField ptF(1, pt); List<volumeType> vTL; surface_.getVolumeType(ptF, vTL); bool functionApplied = false; if ( sideMode_ == smInside && vTL[0] == volumeType::INSIDE ) { size = sizeFunction(pt); functionApplied = true; } else if ( sideMode_ == smOutside && vTL[0] == volumeType::OUTSIDE ) { size = sizeFunction(pt); functionApplied = true; } return functionApplied; }
// Read mesh if available. Otherwise create empty mesh with same non-proc // patches as proc0 mesh. Requires all processors to have all patches // (and in same order). autoPtr<fvMesh> createMesh ( const Time& runTime, const word& regionName, const fileName& instDir, const bool haveMesh ) { //Pout<< "Create mesh for time = " // << runTime.timeName() << nl << endl; IOobject io ( regionName, instDir, runTime, IOobject::MUST_READ ); if (!haveMesh) { // Create dummy mesh. Only used on procs that don't have mesh. IOobject noReadIO(io); noReadIO.readOpt() = IOobject::NO_READ; fvMesh dummyMesh ( noReadIO, xferCopy(pointField()), xferCopy(faceList()), xferCopy(labelList()), xferCopy(labelList()), false ); // Add some dummy zones so upon reading it does not read them // from the undecomposed case. Should be done as extra argument to // regIOobject::readStream? List<pointZone*> pz ( 1, new pointZone ( "dummyPointZone", labelList(0), 0, dummyMesh.pointZones() ) ); List<faceZone*> fz ( 1, new faceZone ( "dummyFaceZone", labelList(0), boolList(0), 0, dummyMesh.faceZones() ) ); List<cellZone*> cz ( 1, new cellZone ( "dummyCellZone", labelList(0), 0, dummyMesh.cellZones() ) ); dummyMesh.addZones(pz, fz, cz); //Pout<< "Writing dummy mesh to " << dummyMesh.polyMesh::objectPath() // << endl; dummyMesh.write(); } //Pout<< "Reading mesh from " << io.objectPath() << endl; autoPtr<fvMesh> meshPtr(new fvMesh(io)); fvMesh& mesh = meshPtr(); // Sync patches // ~~~~~~~~~~~~ if (Pstream::master()) { // Send patches for ( int slave=Pstream::firstSlave(); slave<=Pstream::lastSlave(); slave++ ) { OPstream toSlave(Pstream::scheduled, slave); toSlave << mesh.boundaryMesh(); } } else { // Receive patches IPstream fromMaster(Pstream::scheduled, Pstream::masterNo()); PtrList<entry> patchEntries(fromMaster); if (haveMesh) { // Check master names against mine const polyBoundaryMesh& patches = mesh.boundaryMesh(); forAll(patchEntries, patchI) { const entry& e = patchEntries[patchI]; const word type(e.dict().lookup("type")); const word& name = e.keyword(); if (type == processorPolyPatch::typeName) { break; } if (patchI >= patches.size()) { FatalErrorIn ( "createMesh(const Time&, const fileName&, const bool)" ) << "Non-processor patches not synchronised." << endl << "Processor " << Pstream::myProcNo() << " has only " << patches.size() << " patches, master has " << patchI << exit(FatalError); } if ( type != patches[patchI].type() || name != patches[patchI].name() ) { FatalErrorIn ( "createMesh(const Time&, const fileName&, const bool)" ) << "Non-processor patches not synchronised." << endl << "Master patch " << patchI << " name:" << type << " type:" << type << endl << "Processor " << Pstream::myProcNo() << " patch " << patchI << " has name:" << patches[patchI].name() << " type:" << patches[patchI].type() << exit(FatalError); } } } else { // Add patch List<polyPatch*> patches(patchEntries.size()); label nPatches = 0; forAll(patchEntries, patchI) { const entry& e = patchEntries[patchI]; const word type(e.dict().lookup("type")); const word& name = e.keyword(); if (type == processorPolyPatch::typeName) { break; } //Pout<< "Adding patch:" << nPatches // << " name:" << name << " type:" << type << endl; dictionary patchDict(e.dict()); patchDict.remove("nFaces"); patchDict.add("nFaces", 0); patchDict.remove("startFace"); patchDict.add("startFace", 0); patches[patchI] = polyPatch::New ( name, patchDict, nPatches++, mesh.boundaryMesh() ).ptr(); } patches.setSize(nPatches); mesh.addFvPatches(patches, false); // no parallel comms //// Write empty mesh now we have correct patches //meshPtr().write(); } }
// Read mesh if available. Otherwise create empty mesh with same non-proc // patches as proc0 mesh. Requires all processors to have all patches // (and in same order). autoPtr<fvMesh> createMesh ( const Time& runTime, const word& regionName, const fileName& instDir, const bool haveMesh ) { Pout<< "Create mesh for time = " << runTime.timeName() << nl << endl; IOobject io ( regionName, instDir, runTime, IOobject::MUST_READ ); if (!haveMesh) { // Create dummy mesh. Only used on procs that don't have mesh. fvMesh dummyMesh ( io, xferCopy(pointField()), xferCopy(faceList()), xferCopy(labelList()), xferCopy(labelList()), false ); Pout<< "Writing dummy mesh to " << dummyMesh.polyMesh::objectPath() << endl; dummyMesh.write(); } Pout<< "Reading mesh from " << io.objectPath() << endl; autoPtr<fvMesh> meshPtr(new fvMesh(io)); fvMesh& mesh = meshPtr(); // Determine patches. if (Pstream::master()) { // Send patches for ( int slave=Pstream::firstSlave(); slave<=Pstream::lastSlave(); slave++ ) { OPstream toSlave(Pstream::blocking, slave); toSlave << mesh.boundaryMesh(); } } else { // Receive patches IPstream fromMaster(Pstream::blocking, Pstream::masterNo()); PtrList<entry> patchEntries(fromMaster); if (haveMesh) { // Check master names against mine const polyBoundaryMesh& patches = mesh.boundaryMesh(); forAll(patchEntries, patchI) { const entry& e = patchEntries[patchI]; const word type(e.dict().lookup("type")); const word& name = e.keyword(); if (type == processorPolyPatch::typeName) { break; } if (patchI >= patches.size()) { FatalErrorIn ( "createMesh(const Time&, const fileName&, const bool)" ) << "Non-processor patches not synchronised." << endl << "Processor " << Pstream::myProcNo() << " has only " << patches.size() << " patches, master has " << patchI << exit(FatalError); } if ( type != patches[patchI].type() || name != patches[patchI].name() ) { FatalErrorIn ( "createMesh(const Time&, const fileName&, const bool)" ) << "Non-processor patches not synchronised." << endl << "Master patch " << patchI << " name:" << type << " type:" << type << endl << "Processor " << Pstream::myProcNo() << " patch " << patchI << " has name:" << patches[patchI].name() << " type:" << patches[patchI].type() << exit(FatalError); } } } else { // Add patch List<polyPatch*> patches(patchEntries.size()); label nPatches = 0; forAll(patchEntries, patchI) { const entry& e = patchEntries[patchI]; const word type(e.dict().lookup("type")); const word& name = e.keyword(); if (type == processorPolyPatch::typeName) { break; } Pout<< "Adding patch:" << nPatches << " name:" << name << " type:" << type << endl; dictionary patchDict(e.dict()); patchDict.remove("nFaces"); patchDict.add("nFaces", 0); patchDict.remove("startFace"); patchDict.add("startFace", 0); patches[patchI] = polyPatch::New ( name, patchDict, nPatches++, mesh.boundaryMesh() ).ptr(); } patches.setSize(nPatches); mesh.addFvPatches(patches, false); // no parallel comms //// Write empty mesh now we have correct patches //meshPtr().write(); } }
Foam::extendedFeatureEdgeMesh::extendedFeatureEdgeMesh(const IOobject& io) : regIOobject(io), edgeMesh(pointField(0), edgeList(0)), concaveStart_(0), mixedStart_(0), nonFeatureStart_(0), internalStart_(0), flatStart_(0), openStart_(0), multipleStart_(0), normals_(0), edgeDirections_(0), edgeNormals_(0), featurePointNormals_(0), featurePointEdges_(0), regionEdges_(0), pointTree_(), edgeTree_(), edgeTreesByType_() { if ( io.readOpt() == IOobject::MUST_READ || io.readOpt() == IOobject::MUST_READ_IF_MODIFIED || (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk()) ) { if (readOpt() == IOobject::MUST_READ_IF_MODIFIED) { WarningIn ( "extendedFeatureEdgeMesh::extendedFeatureEdgeMesh" "(const IOobject&)" ) << "Specified IOobject::MUST_READ_IF_MODIFIED but class" << " does not support automatic rereading." << endl; } Istream& is = readStream(typeName); is >> *this >> concaveStart_ >> mixedStart_ >> nonFeatureStart_ >> internalStart_ >> flatStart_ >> openStart_ >> multipleStart_ >> normals_ >> edgeNormals_ >> featurePointNormals_ >> featurePointEdges_ >> regionEdges_; close(); { // Calculate edgeDirections const edgeList& eds(edges()); const pointField& pts(points()); edgeDirections_.setSize(eds.size()); forAll(eds, eI) { edgeDirections_[eI] = eds[eI].vec(pts); } edgeDirections_ /= mag(edgeDirections_); } }
// Construct from Istream simpleSplineEdge::simpleSplineEdge(const pointField& points, Istream& is) : curvedEdge(points, is), BSpline(knotlist(points, start_, end_, pointField(is))) {}
Foam::polyLineEdge::polyLineEdge(const pointField& ps, Istream& is) : curvedEdge(ps, is), polyLine(appendEndPoints(ps, start_, end_, pointField(is))) {}