vectorField fieldOperations:: getWallPointMotion ( const fvMesh& mesh, const volScalarField& C, const label movingPatchID ) { // interpolate the concentration from cells to wall faces coupledPatchInterpolation patchInterpolator ( mesh.boundaryMesh()[movingPatchID], mesh ); // concentration and normals on the faces scalarField pointCface = -C.boundaryField()[movingPatchID].snGrad(); vectorField pointNface = mesh.boundaryMesh()[movingPatchID].faceNormals(); scalarField motionC = patchInterpolator.faceToPointInterpolate(pointCface); vectorField motionN = patchInterpolator.faceToPointInterpolate(pointNface); // normalize point normals to 1 forAll(motionN, ii) motionN[ii]/=mag(motionN[ii]); return motionC*motionN; }
// Construct from components Foam::contactPatchPair::contactPatchPair ( const fvMesh& m, const label master, const label slave, const scalar tolerance ) : mesh_(m), masterPatchIndex_(master), slavePatchIndex_(slave), masterInterpolate_(m.boundaryMesh()[masterPatchIndex_]), slaveInterpolate_(m.boundaryMesh()[slavePatchIndex_]), patchToPatchInterpolate_ ( m.boundaryMesh()[masterPatchIndex_], m.boundaryMesh()[slavePatchIndex_], intersection::FULL_RAY, intersection::CONTACT_SPHERE ), tol_(tolerance), touchFraction_ ( mesh_.boundaryMesh()[slavePatchIndex_].size(), pTraits<scalar>::zero ), slaveDisplacement_ ( mesh_.boundaryMesh()[slavePatchIndex_].size(), pTraits<vector>::zero ) {}
void replaceBoundaryType ( const fvMesh& mesh, const word& fieldName, const word& boundaryType, const string& boundaryValue ) { IOobject header ( fieldName, mesh.time().timeName(), mesh, IOobject::MUST_READ, IOobject::NO_WRITE ); if (!header.headerOk()) { return; } Info<< "Updating boundary types for field " << header.name() << endl; const word oldTypeName = IOdictionary::typeName; const_cast<word&>(IOdictionary::typeName) = word::null; IOdictionary dict(header); const_cast<word&>(IOdictionary::typeName) = oldTypeName; const_cast<word&>(dict.type()) = dict.headerClassName(); // Make a backup of the old file if (mvBak(dict.objectPath(), "old")) { Info<< " Backup original file to " << (dict.objectPath() + ".old") << endl; } // Loop through boundary patches and update const polyBoundaryMesh& bMesh = mesh.boundaryMesh(); dictionary& boundaryDict = dict.subDict("boundaryField"); forAll(bMesh, patchI) { if (isA<wallPolyPatch>(bMesh[patchI])) { word patchName = bMesh[patchI].name(); dictionary& oldPatch = boundaryDict.subDict(patchName); dictionary newPatch(dictionary::null); newPatch.add("type", boundaryType); newPatch.add("value", ("uniform " + boundaryValue).c_str()); oldPatch = newPatch; } } Info<< " writing updated " << dict.name() << nl << endl; dict.regIOobject::write(); }
// Conversion is a two step process: // - from original (fine) patch faces to agglomerations (aggloms might not // be in correct patch order) // - from agglomerations to coarse patch faces void Foam::singleCellFvMesh::agglomerateMesh ( const fvMesh& mesh, const labelListList& agglom ) { const polyBoundaryMesh& oldPatches = mesh.boundaryMesh(); // Check agglomeration within patch face range and continuous labelList nAgglom(oldPatches.size(), 0); forAll(oldPatches, patchI) { const polyPatch& pp = oldPatches[patchI]; if (pp.size() > 0) { nAgglom[patchI] = max(agglom[patchI])+1; forAll(pp, i) { if (agglom[patchI][i] < 0 || agglom[patchI][i] >= pp.size()) { FatalErrorIn ( "singleCellFvMesh::agglomerateMesh(..)" ) << "agglomeration on patch " << patchI << " is out of range 0.." << pp.size()-1 << exit(FatalError); } } } }
// Inplace add mesh1 to mesh0 Foam::autoPtr<Foam::mapAddedPolyMesh> Foam::fvMeshAdder::add ( fvMesh& mesh0, const fvMesh& mesh1, const faceCoupleInfo& coupleInfo, const bool validBoundary ) { mesh0.clearOut(); // Resulting merged mesh (polyMesh only!) autoPtr<mapAddedPolyMesh> mapPtr ( polyMeshAdder::add ( mesh0, mesh1, coupleInfo, validBoundary ) ); // Adjust the fvMesh part. const polyBoundaryMesh& patches = mesh0.boundaryMesh(); fvBoundaryMesh& fvPatches = const_cast<fvBoundaryMesh&>(mesh0.boundary()); fvPatches.setSize(patches.size()); forAll(patches, patchI) { fvPatches.set(patchI, fvPatch::New(patches[patchI], fvPatches)); }
void Foam::patchProbes::findElements(const fvMesh& mesh) { (void)mesh.tetBasePtIs(); const polyBoundaryMesh& bm = mesh.boundaryMesh(); label patchi = bm.findPatchID(patchName_); if (patchi == -1) { FatalErrorInFunction << " Unknown patch name " << patchName_ << endl << exit(FatalError); } // All the info for nearest. Construct to miss List<mappedPatchBase::nearInfo> nearest(this->size()); const polyPatch& pp = bm[patchi]; if (pp.size() > 0) { labelList bndFaces(pp.size()); forAll(bndFaces, i) { bndFaces[i] = pp.start() + i; }
Foam::fv::patchMeanVelocityForce::patchMeanVelocityForce ( const word& sourceName, const word& modelType, const dictionary& dict, const fvMesh& mesh ) : meanVelocityForce(sourceName, modelType, dict, mesh), patch_(coeffs_.lookup("patch")), patchi_(mesh.boundaryMesh().findPatchID(patch_)) { if (patchi_ < 0) { FatalErrorInFunction << "Cannot find patch " << patch_ << exit(FatalError); } }
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; //} }
forAll(p, patchi) { p[patchi] = patches[patchi].clone(fMesh.boundaryMesh()).ptr(); }
conservativeMeshToMesh::conservativeMeshToMesh ( const fvMesh& srcMesh, const fvMesh& tgtMesh, const label nThreads, const bool forceRecalculation, const bool writeAddressing ) : meshSrc_(srcMesh), meshTgt_(tgtMesh), addressing_ ( IOobject ( "addressing", tgtMesh.time().timeName(), tgtMesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE ), tgtMesh.nCells() ), weights_ ( IOobject ( "weights", tgtMesh.time().timeName(), tgtMesh, IOobject::NO_READ, IOobject::NO_WRITE ), tgtMesh.nCells() ), centres_ ( IOobject ( "centres", tgtMesh.time().timeName(), tgtMesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE ), tgtMesh.nCells() ), cellAddressing_(tgtMesh.nCells()), counter_(0), boundaryAddressing_(tgtMesh.boundaryMesh().size()) { if (addressing_.headerOk() && weights_.headerOk() && centres_.headerOk()) { // Check if sizes match. Otherwise, re-calculate. if ( addressing_.size() == tgtMesh.nCells() && weights_.size() == tgtMesh.nCells() && centres_.size() == tgtMesh.nCells() && !forceRecalculation ) { Info<< " Reading addressing from file." << endl; return; } Info<< " Recalculating addressing." << endl; } else { Info<< " Calculating addressing." << endl; } // Check if the source mesh has a calculated addressing // If yes, try and invert that. IOobject srcHeader ( "addressing", srcMesh.time().timeName(), srcMesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE ); if (srcHeader.headerOk() && !addressing_.headerOk()) { Info<< " Found addressing in source directory." << " Checking for compatibility." << endl; if (invertAddressing()) { Info<< " Inversion successful. " << endl; return; } } // Track calculation time clockTime calcTimer; // Compute nearest cell addressing calcCellAddressing(); if (nThreads == 1) { calcAddressingAndWeights(0, tgtMesh.nCells(), true); } else { // Prior to multi-threaded operation, // force calculation of demand-driven data tgtMesh.cells(); srcMesh.cells(); srcMesh.cellCentres(); srcMesh.cellCells(); multiThreader threader(nThreads); // Set one handler per thread PtrList<handler> hdl(threader.getNumThreads()); forAll(hdl, i) { hdl.set(i, new handler(*this, threader)); } // Simple, but inefficient load-balancing scheme labelList tStarts(threader.getNumThreads(), 0); labelList tSizes(threader.getNumThreads(), 0); label index = tgtMesh.nCells(), j = 0; while (index--) { tSizes[(j = tSizes.fcIndex(j))]++; } label total = 0; for (label i = 1; i < tStarts.size(); i++) { tStarts[i] = tSizes[i-1] + total; total += tSizes[i-1]; } if (debug) { Info<< " Load starts: " << tStarts << endl; Info<< " Load sizes: " << tSizes << endl; } // Set the argument list for each thread forAll(hdl, i) { // Size up the argument list hdl[i].setSize(2); // Set the start/end cell indices hdl[i].set(0, &tStarts[i]); hdl[i].set(1, &tSizes[i]); // Lock the slave thread first hdl[i].lock(handler::START); hdl[i].unsetPredicate(handler::START); hdl[i].lock(handler::STOP); hdl[i].unsetPredicate(handler::STOP); }
Foam::dbse::dbse ( Time& runTime, fvMesh& mesh, const dictionary& snapEdgeDict ) : runTime_(runTime), mesh_(mesh), dict_(snapEdgeDict), patches_(mesh.boundaryMesh()), zones_(mesh.faceZones()), points_(mesh.points()), snapPatches_(dict_.lookup("snapPatches")), snapZones_(dict_.lookup("snapZones")), stlFileNames_(dict_.lookup("stlFileNames")), tolerance_(readScalar(dict_.lookup("tolerance"))), relaxation_(readScalar(dict_.lookup("relaxation"))), featureAngle_(readScalar(dict_.lookup("featureAngle"))), excludeAngle_(readScalar(dict_.lookup("excludeEdgeAngle"))), parallelAngle_(readScalar(dict_.lookup("parallelAngle"))), includeInterior_(readBool(dict_.lookup("includeInterior"))), nIterations_(readLabel(dict_.lookup("nIterations"))), fitFactor_(readScalar(dict_.lookup("fitFactor"))), minFit_(-mag(fitFactor_)), maxFit_(1.0 + mag(fitFactor_)), newPoints_(points_), edgePoints_(0), nSTL_(stlFileNames_.size()), stlFeatures_(nSTL_), globalSTLPoints_(nSTL_), nEdgePoints_(nSTL_), cosFeature_(::cos(featureAngle_*deg2rad_)), cosFeature2_(::cos(featureAngle_*0.5*deg2rad_)), cosExclude_(::cos(excludeAngle_*deg2rad_)), cosParAngle_(::cos(parallelAngle_*deg2rad_)), smallestEdgeLength_(GREAT) { forAll(stlFileNames_, is) { word stlFileName(stlFileNames_[is]); fileName stlFile("constant/triSurface/"+stlFileName); triSurface stlSurface(stlFile); const edgeList& stlEdges = stlSurface.edges(); const labelListList& stlEdgeFaces = stlSurface.edgeFaces(); const vectorField& stlSf = stlSurface.faceNormals(); const vectorField& stlPoints = stlSurface.localPoints(); addToList(globalSTLPoints_[is], stlPoints); nEdgePoints_[is].setSize(stlPoints.size()); Info << "Finding features for stl : " << stlFileName << endl; forAll(stlEdgeFaces, i) { if(!stlSurface.isInternalEdge(i)) { addToList(stlFeatures_[is], stlEdges[i]); nEdgePoints_[is][stlEdges[i][0]]++; nEdgePoints_[is][stlEdges[i][1]]++; } else { label fi0 = stlEdgeFaces[i][0]; label fi1 = stlEdgeFaces[i][1]; scalar magF0 = mag(stlSf[fi0]); scalar magF1 = mag(stlSf[fi1]); if ( (magF0 < 1.0e-5) || (magF1 < 1.0e-5)) { Info << "Warning:: face normals are zero!?!" << endl; } vector f0 = stlSf[fi0]/magF0; vector f1 = stlSf[fi1]/magF1; scalar cosa = f0 & f1; if (cosa < cosFeature_) { addToList(stlFeatures_[is], stlEdges[i]); nEdgePoints_[is][stlEdges[i][0]]++; nEdgePoints_[is][stlEdges[i][1]]++; } } } if (stlFeatures_[is].size() == 0) { Info << "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *" << endl; Info << "WARNING!!! Your stl does not contain any feature lines." << endl; Info << "* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *" << endl; } }