forAll (ffe, ffeI) { // Get addressing const labelList& mo = ffe[ffeI].masterObjects(); label faceI = ffe[ffeI].index(); if (addr[faceI].size()) { FatalErrorIn("void faceMapper::calcAddressing() const") << "Master face " << faceI << " mapped from edge faces " << mo << " already destination of mapping." << abort(FatalError); } // Map from masters, uniform weights addr[faceI] = mo; w[faceI] = scalarList(mo.size(), 1.0/mo.size()); }
forAll (cfp, cfpI) { // Get addressing const labelList& mo = cfp[cfpI].masterObjects(); label cellI = cfp[cfpI].index(); if (addr[cellI].size()) { FatalErrorIn("void cellMapper::calcAddressing() const") << "Master cell " << cellI << " mapped from point cells " << mo << " already destination of mapping." << abort(FatalError); } // Map from masters, uniform weights addr[cellI] = mo; w[cellI] = scalarList(mo.size(), 1.0/mo.size()); }
forAll(cff, cffI) { // Get addressing const labelList& mo = cff[cffI].masterObjects(); label cellI = cff[cffI].index(); if (addr[cellI].size()) { FatalErrorInFunction << "Master cell " << cellI << " mapped from face cells " << mo << " already destination of mapping." << abort(FatalError); } // Map from masters, uniform weights addr[cellI] = mo; w[cellI] = scalarList(mo.size(), 1.0/mo.size()); }
TerrainManager::TerrainManager( const Time & runTime, const dictionary & dict, const searchableSurface * const stl_ ): BlockMeshManager(runTime), stl_(stl_), blockNrs_(dict.lookup("blocks")), cellNrs_(dict.lookup("cells")), domainBox_ ( CoordinateSystem ( point(dict.lookup("p_corner")), List< Foam::vector >(dict.subDict("coordinates").lookup("baseVectors")) ), scalarList(dict.lookup("dimensions")), dict.lookupOrDefault< scalar >("boxResolution",0.0001) ), stlBox_(domainBox_), splineNormalDist_(0), mode_upwardSplines_(0), zeroLevel_(0), gradingFactors_(dict.lookup("gradingFactors")), cylinderModule_(this), modificationModule_(this), gradingModule_(this), blendingFunction_ ( new ScalarBlendingFunction() ){ // Read dictionary: p_above_ = point(dict.lookup("p_above")); maxDistProj_ = readScalar(dict.lookup("maxDistProj")); // option for stl_ inside the domain box: if(dict.found("stlInsideBox")){ if(dict.subDict("stlInsideBox").found("zeroLevel")){ zeroLevel_ = readScalar(dict.subDict("stlInsideBox").lookup("zeroLevel")); } stlBox_ = Box ( CoordinateSystem ( point(dict.subDict("stlInsideBox").lookup("p_corner_inside_stl")), coordinateSystem().axes() ), scalarList(dict.subDict("stlInsideBox").lookup("dimensions_inside_stl")), dict.subDict("stlInsideBox").lookupOrDefault< scalar >("boxResolution",0.0001) ); blendingFunction_ = ScalarBlendingFunction::New ( dict.subDict("stlInsideBox").subDict("blendingFunction") ); if(dict.subDict("stlInsideBox").subDict("blendingFunction").found("writePDF")){ const dictionary & writeDict = dict.subDict("stlInsideBox").subDict("blendingFunction").subDict("writePDF"); blendingFunction_().writePDFs ( word(writeDict.lookup("baseName")), fileName(writeDict.lookup("resultsFolder")), point(writeDict.lookup("probePoint0")), point(writeDict.lookup("probePoint1")), 0,1, readLabel(writeDict.lookup("steps")), readLabel(writeDict.lookup("plotPoints")), readLabel(writeDict.lookup("interpolOrder")) ); } else { Info << "TerrainManager: keyword 'writePDF' not found in sub dictionary 'blendingFunction'." << endl; } } // module orography modifications: if(dict.found("terrainModification")){ Info << " loading orography modification module" << endl; if(!modificationModule_.load(dict.subDict("terrainModification"))){ Info << "\n TerrainManager: Error while loading orography modification module." << endl; throw; } } // module block grading: if(dict.found("blockGrading")){ Info << " loading block grading module" << endl; if(!gradingModule_.load(dict.subDict("blockGrading"))){ Info << "\n TerrainManager: Error while loading block grading module." << endl; throw; } } // module outer cylinder: if(dict.found("outerCylinder")){ Info << " loading cylinder module" << endl; if(!cylinderModule_.load(dict.subDict("outerCylinder"))){ Info << "\n TerrainManager: Error while loading cylinder module." << endl; throw; } } // option for othogonalization of upward splines: if(dict.found("orthogonalizeUpwardSplines")){ dictionary upsDict = dict.subDict("orthogonalizeUpwardSplines"); splineNormalDist_ = readScalar(upsDict.lookup("splineNormalDist")); if(upsDict.found("ignoreBoundary")) mode_upwardSplines_ = 2; else mode_upwardSplines_ = 1; } // add patches: patchesRef().resize(6); patchesRef().set ( Block::WEST, new BlockMeshPatch ( *this, word(dict.lookup("patch_name_west")), word(dict.lookup("patch_type_west")) ) ); patchesRef().set ( Block::EAST, new BlockMeshPatch ( *this, word(dict.lookup("patch_name_east")), word(dict.lookup("patch_type_east")) ) ); patchesRef().set ( Block::SOUTH, new BlockMeshPatch ( *this, word(dict.lookup("patch_name_south")), word(dict.lookup("patch_type_south")) ) ); patchesRef().set ( Block::NORTH, new BlockMeshPatch ( *this, word(dict.lookup("patch_name_north")), word(dict.lookup("patch_type_north")) ) ); patchesRef().set ( Block::GROUND, new BlockMeshPatch ( *this, word(dict.lookup("patch_name_ground")), word(dict.lookup("patch_type_ground")) ) ); patchesRef().set ( Block::SKY, new BlockMeshPatch ( *this, word(dict.lookup("patch_name_sky")), word(dict.lookup("patch_type_sky")) ) ); // only one block in up direction: blockNrs_[UP] = 1; // set spline point numbers: splinePointNrs_.resize(3); splinePointNrs_[0] = cellNrs_[0] - 1; splinePointNrs_[1] = cellNrs_[1] - 1; splinePointNrs_[2] = cellNrs_[2] - 1; // init landscape_: if(stl_){ landscape_.set ( new STLLandscape ( stl_, &(blendingFunction_()), &domainBox_, &stlBox_, zeroLevel_ ) ); } // output boxes: domainBox_.writeSTL("domainBox.stl"); stlBox_.writeSTL("stlBox.stl"); }
//- Calculate inverse-distance weights for interpolative mapping void topoCellMapper::calcInverseDistanceWeights() const { if (weightsPtr_) { FatalErrorIn ( "void topoCellMapper::calcInverseDistanceWeights() const" ) << "Weights already calculated." << abort(FatalError); } // Fetch interpolative addressing const labelListList& addr = addressing(); // Allocate memory weightsPtr_ = new scalarListList(size()); scalarListList& w = *weightsPtr_; // Obtain cell-centre information from old/new meshes const vectorField& oldCentres = tMapper_.internalCentres(); const vectorField& newCentres = mesh_.cellCentres(); forAll(addr, cellI) { const labelList& mo = addr[cellI]; // Do mapped cells if (mo.size() == 1) { w[cellI] = scalarList(1, 1.0); } else { // Map from masters, inverse-distance weights scalar totalWeight = 0.0; w[cellI] = scalarList(mo.size(), 0.0); forAll (mo, oldCellI) { w[cellI][oldCellI] = ( 1.0/stabilise ( magSqr ( newCentres[cellI] - oldCentres[mo[oldCellI]] ), VSMALL ) ); totalWeight += w[cellI][oldCellI]; } // Normalize weights scalar normFactor = (1.0/totalWeight); forAll (mo, oldCellI) { w[cellI][oldCellI] *= normFactor; } } }
forAll(tgtToSrcCellAddr, i) { tgtToSrcCellWght[i] = scalarList(tgtToSrc[i].size(), tgtVc[i]); tgtToSrcCellAddr[i].transfer(tgtToSrc[i]); }
void Foam::mapNearestMethod::calculateAddressing ( labelListList& srcToTgtCellAddr, scalarListList& srcToTgtCellWght, labelListList& tgtToSrcCellAddr, scalarListList& tgtToSrcCellWght, const label srcSeedI, const label tgtSeedI, const labelList& srcCellIDs, boolList& mapFlag, label& startSeedI ) { List<DynamicList<label>> srcToTgt(src_.nCells()); List<DynamicList<label>> tgtToSrc(tgt_.nCells()); const scalarField& srcVc = src_.cellVolumes(); const scalarField& tgtVc = tgt_.cellVolumes(); { label srcCelli = srcSeedI; label tgtCelli = tgtSeedI; do { // find nearest tgt cell findNearestCell(src_, tgt_, srcCelli, tgtCelli); // store src/tgt cell pair srcToTgt[srcCelli].append(tgtCelli); tgtToSrc[tgtCelli].append(srcCelli); // mark source cell srcCelli and tgtCelli as matched mapFlag[srcCelli] = false; // accumulate intersection volume V_ += srcVc[srcCelli]; // find new source cell setNextNearestCells ( startSeedI, srcCelli, tgtCelli, mapFlag, srcCellIDs ); } while (srcCelli >= 0); } // for the case of multiple source cells per target cell, select the // nearest source cell only and discard the others const vectorField& srcCc = src_.cellCentres(); const vectorField& tgtCc = tgt_.cellCentres(); forAll(tgtToSrc, targetCelli) { if (tgtToSrc[targetCelli].size() > 1) { const vector& tgtC = tgtCc[targetCelli]; DynamicList<label>& srcCells = tgtToSrc[targetCelli]; label srcCelli = srcCells[0]; scalar d = magSqr(tgtC - srcCc[srcCelli]); for (label i = 1; i < srcCells.size(); i++) { label srcI = srcCells[i]; scalar dNew = magSqr(tgtC - srcCc[srcI]); if (dNew < d) { d = dNew; srcCelli = srcI; } } srcCells.clear(); srcCells.append(srcCelli); } } // If there are more target cells than source cells, some target cells // might not yet be mapped forAll(tgtToSrc, tgtCelli) { if (tgtToSrc[tgtCelli].empty()) { label srcCelli = findMappedSrcCell(tgtCelli, tgtToSrc); findNearestCell(tgt_, src_, tgtCelli, srcCelli); tgtToSrc[tgtCelli].append(srcCelli); } } // transfer addressing into persistent storage forAll(srcToTgtCellAddr, i) { srcToTgtCellWght[i] = scalarList(srcToTgt[i].size(), srcVc[i]); srcToTgtCellAddr[i].transfer(srcToTgt[i]); }