void Foam::polyLineSet::genSamples() { // Storage for sample points DynamicList<point> samplingPts; DynamicList<label> samplingCells; DynamicList<label> samplingFaces; DynamicList<label> samplingSegments; DynamicList<scalar> samplingCurveDist; calcSamples ( samplingPts, samplingCells, samplingFaces, samplingSegments, samplingCurveDist ); samplingPts.shrink(); samplingCells.shrink(); samplingFaces.shrink(); samplingSegments.shrink(); samplingCurveDist.shrink(); setSamples ( samplingPts, samplingCells, samplingFaces, samplingSegments, samplingCurveDist ); }
// Reads points section. Read region as well? void readPoints ( IFstream& is, DynamicList<point>& points, // coordinates DynamicList<label>& unvPointID // unv index ) { Sout<< "Starting reading points at line " << is.lineNumber() << '.' << endl; static bool hasWarned = false; while (true) { string line; is.getLine(line); label pointI = readLabel(IStringStream(line.substr(0, 10))()); if (pointI == -1) { break; } else if (pointI != points.size()+1 && !hasWarned) { hasWarned = true; IOWarningIn ( "readPoints(IFstream&, label&, DynamicList<point>" ", DynamicList<label>&)", is ) << "Points not in order starting at point " << pointI //<< " at line " << is.lineNumber() //<< abort(FatalError); << endl; } point pt; is.getLine(line); pt[0] = readUnvScalar(line.substr(0, 25)); pt[1] = readUnvScalar(line.substr(25, 25)); pt[2] = readUnvScalar(line.substr(50, 25)); unvPointID.append(pointI); points.append(pt); } points.shrink(); unvPointID.shrink(); Sout<< "Read " << points.size() << " points." << endl; }
bool faForceEquation<T>::getMask(DynamicList<label> &cellIDs,const word &psi) { parse(maskExpression_); if(!resultIsLogical()) { FatalErrorIn("faForceEquation<scalar>::operator()(faMatrix<T> &)") << "Result of " << maskExpression_ << " is not a logical expression" << endl << abort(FatalError); } const areaScalarField &cond=getScalar(); forAll(cond,cellI) { if(cond[cellI]!=0) { cellIDs.append(cellI); } } cellIDs.shrink(); label size=cellIDs.size(); reduce(size,plusOp<label>()); if(size==0) { if(verbose_) { Info << "No cells fixed for field " << psi << endl; } return false; } if(verbose_) { Info << size << " cells fixed for field " << psi << endl; } return true; }
scalarList splitValuesString ( const string &values ) { DynamicList<scalar> result; std::string::size_type start=0; std::string::size_type end=0; while(start<values.length()) { end=values.find(',',start); if(end==std::string::npos) { end=values.length(); } result.append( readScalar( IStringStream( values.substr( start,end-start ) )() ) ); start=end+1; } result.shrink(); return result; }
bool SwakSetValue<T>::getMask(DynamicList<label> &cellIDs,const word &psi) { this->driver().parse(maskExpression_); if( !this->driver(). FieldValueExpressionDriver::resultIsTyp<volScalarField>(true) ) { FatalErrorIn("SwakSetValue<scalar>::getMask") << "Result of " << maskExpression_ << " is not a logical expression" << endl << exit(FatalError); } const volScalarField &cond=this->driver(). FieldValueExpressionDriver::getResult<volScalarField>(); forAll(cond,cellI) { if(cond[cellI]!=0) { cellIDs.append(cellI); } } cellIDs.shrink(); label size=cellIDs.size(); reduce(size,plusOp<label>()); if(size==0) { if(this->verbose_) { Info << "No cells fixed for field " << psi << endl; } return false; } if(this->verbose_) { Info << size << " cells fixed for field " << psi << endl; } return true; }
triSurface triangulate ( const polyBoundaryMesh& bMesh, const labelHashSet& includePatches, const labelListIOList& finalAgglom, labelList& triSurfaceToAgglom, const globalIndex& globalNumbering, const polyBoundaryMesh& coarsePatches ) { const polyMesh& mesh = bMesh.mesh(); // Storage for surfaceMesh. Size estimate. DynamicList<labelledTri> triangles ( mesh.nFaces() - mesh.nInternalFaces() ); label newPatchI = 0; label localTriFaceI = 0; forAllConstIter(labelHashSet, includePatches, iter) { const label patchI = iter.key(); const polyPatch& patch = bMesh[patchI]; const pointField& points = patch.points(); label nTriTotal = 0; forAll(patch, patchFaceI) { const face& f = patch[patchFaceI]; faceList triFaces(f.nTriangles(points)); label nTri = 0; f.triangles(points, nTri, triFaces); forAll(triFaces, triFaceI) { const face& f = triFaces[triFaceI]; triangles.append(labelledTri(f[0], f[1], f[2], newPatchI)); nTriTotal++; triSurfaceToAgglom[localTriFaceI++] = globalNumbering.toGlobal ( Pstream::myProcNo(), finalAgglom[patchI][patchFaceI] + coarsePatches[patchI].start() ); } } newPatchI++; } triSurfaceToAgglom.resize(localTriFaceI-1); triangles.shrink(); // Create globally numbered tri surface triSurface rawSurface(triangles, mesh.points()); // Create locally numbered tri surface triSurface surface ( rawSurface.localFaces(), rawSurface.localPoints() ); // Add patch names to surface surface.patches().setSize(newPatchI); newPatchI = 0; forAllConstIter(labelHashSet, includePatches, iter) { const label patchI = iter.key(); const polyPatch& patch = bMesh[patchI]; surface.patches()[newPatchI].index() = patchI; surface.patches()[newPatchI].name() = patch.name(); surface.patches()[newPatchI].geometricType() = patch.type(); newPatchI++; } return surface; }
int main(int argc, char *argv[]) { argList::addBoolOption ( "readLevel", "read level from refinementLevel file" ); #include "setRootCase.H" #include "createTime.H" #include "createPolyMesh.H" Info<< "Dividing cells into bins depending on cell volume.\nThis will" << " correspond to refinement levels for a mesh with only 2x2x2" << " refinement\n" << "The upper range for every bin is always 1.1 times the lower range" << " to allow for some truncation error." << nl << endl; const bool readLevel = args.optionFound("readLevel"); const scalarField& vols = mesh.cellVolumes(); SortableList<scalar> sortedVols(vols); // All cell labels, sorted per bin. DynamicList<DynamicList<label>> bins; // Lower/upper limits DynamicList<scalar> lowerLimits; DynamicList<scalar> upperLimits; // Create bin0. Have upperlimit as factor times lowerlimit. bins.append(DynamicList<label>()); lowerLimits.append(sortedVols[0]); upperLimits.append(1.1 * lowerLimits.last()); forAll(sortedVols, i) { if (sortedVols[i] > upperLimits.last()) { // New value outside of current bin // Shrink old bin. DynamicList<label>& bin = bins.last(); bin.shrink(); Info<< "Collected " << bin.size() << " elements in bin " << lowerLimits.last() << " .. " << upperLimits.last() << endl; // Create new bin. bins.append(DynamicList<label>()); lowerLimits.append(sortedVols[i]); upperLimits.append(1.1 * lowerLimits.last()); Info<< "Creating new bin " << lowerLimits.last() << " .. " << upperLimits.last() << endl; } // Append to current bin. DynamicList<label>& bin = bins.last(); bin.append(sortedVols.indices()[i]); } Info<< endl; bins.last().shrink(); bins.shrink(); lowerLimits.shrink(); upperLimits.shrink(); // // Write to cellSets. // Info<< "Volume bins:" << nl; forAll(bins, binI) { const DynamicList<label>& bin = bins[binI]; cellSet cells(mesh, "vol" + name(binI), bin.size()); forAll(bin, i) { cells.insert(bin[i]); } Info<< " " << lowerLimits[binI] << " .. " << upperLimits[binI] << " : writing " << bin.size() << " cells to cellSet " << cells.name() << endl; cells.write(); }
bool Foam::fileFormats::NASedgeFormat::read ( const fileName& filename ) { clear(); IFstream is(filename); if (!is.good()) { FatalErrorInFunction << "Cannot read file " << filename << exit(FatalError); } DynamicList<point> dynPoints; DynamicList<edge> dynEdges; DynamicList<label> pointId; // Nastran index of points while (is.good()) { string line; is.getLine(line); // Skip empty or comment if (line.empty() || line[0] == '$') { continue; } // Check if character 72 is continuation if (line.size() > 72 && line[72] == '+') { line = line.substr(0, 72); while (true) { string buf; is.getLine(buf); if (buf.size() > 72 && buf[72] == '+') { line += buf.substr(8, 64); } else { line += buf.substr(8, buf.size()-8); break; } } } // Read first word IStringStream lineStream(line); word cmd; lineStream >> cmd; if (cmd == "CBEAM" || cmd == "CROD") { edge e; // label groupId = readLabel(IStringStream(line.substr(16,8))()); e[0] = readLabel(IStringStream(line.substr(24,8))()); e[1] = readLabel(IStringStream(line.substr(32,8))()); // discard groupID dynEdges.append(e); } else if (cmd == "PLOTEL") { edge e; // label groupId = readLabel(IStringStream(line.substr(16,8))()); e[0] = readLabel(IStringStream(line.substr(16,8))()); e[1] = readLabel(IStringStream(line.substr(24,8))()); // discard groupID dynEdges.append(e); } else if (cmd == "GRID") { label index = readLabel(IStringStream(line.substr(8,8))()); scalar x = parseNASCoord(line.substr(24, 8)); scalar y = parseNASCoord(line.substr(32, 8)); scalar z = parseNASCoord(line.substr(40, 8)); pointId.append(index); dynPoints.append(point(x, y, z)); } else if (cmd == "GRID*") { // Long format is on two lines with '*' continuation symbol // on start of second line. // Typical line (spaces compacted) // GRID* 126 0 -5.55999875E+02 -5.68730474E+02 // * 2.14897901E+02 label index = readLabel(IStringStream(line.substr(8,16))()); scalar x = parseNASCoord(line.substr(40, 16)); scalar y = parseNASCoord(line.substr(56, 16)); is.getLine(line); if (line[0] != '*') { FatalErrorInFunction << "Expected continuation symbol '*' when reading GRID*" << " (double precision coordinate) format" << nl << "Read:" << line << nl << "File:" << is.name() << " line:" << is.lineNumber() << exit(FatalError); } scalar z = parseNASCoord(line.substr(8, 16)); pointId.append(index); dynPoints.append(point(x, y, z)); } } // transfer to normal lists storedPoints().transfer(dynPoints); pointId.shrink(); dynEdges.shrink(); // Build inverse mapping (NASTRAN pointId -> index) Map<label> mapPointId(2*pointId.size()); forAll(pointId, i) { mapPointId.insert(pointId[i], i); }
void Foam::interactionLists::buildCellReferralLists() { Info<< nl << "Determining molecule referring schedule" << endl; const referredCellList& refIntL(ril()); DynamicList<label> referralProcs; // Run through all referredCells to build list of interacting processors forAll(refIntL, rIL) { const referredCell& rC(refIntL[rIL]); if (findIndex(referralProcs, rC.sourceProc()) == -1) { referralProcs.append(rC.sourceProc()); } } referralProcs.shrink(); // Pout << "referralProcs: " << nl << referralProcs << endl; List<DynamicList<label> > cellSendingReferralLists(referralProcs.size()); List<DynamicList<DynamicList<label> > > cellReceivingReferralLists(referralProcs.size()); // Run through all referredCells again building up send and receive info forAll(refIntL, rIL) { const referredCell& rC(refIntL[rIL]); label rPI = findIndex(referralProcs, rC.sourceProc()); DynamicList<DynamicList<label> >& rRL(cellReceivingReferralLists[rPI]); DynamicList<label>& sRL(cellSendingReferralLists[rPI]); label existingSource = findIndex(sRL, rC.sourceCell()); // Check to see if this source cell has already been allocated to // come to this processor. If not, add the source cell to the sending // list and add the current referred cell to the receiving list. // It shouldn't be possible for the sending and receiving lists to be // different lengths, because their append operations happen at the // same time. if (existingSource == -1) { sRL.append(rC.sourceCell()); rRL.append ( DynamicList<label> (labelList(1,rIL)) ); } else { rRL[existingSource].append(rIL); rRL[existingSource].shrink(); } } forAll(referralProcs, rPI) { DynamicList<DynamicList<label> >& rRL(cellReceivingReferralLists[rPI]); DynamicList<label>& sRL(cellSendingReferralLists[rPI]); sRL.shrink(); rRL.shrink(); }