// 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; }
Foam::labelList Foam::backgroundMeshDecomposition::processorPosition ( const List<PointType>& pts ) const { DynamicList<label> toCandidateProc; DynamicList<point> testPoints; labelList ptBlockStart(pts.size(), -1); labelList ptBlockSize(pts.size(), -1); label nTotalCandidates = 0; forAll(pts, pI) { const pointFromPoint pt = topoint(pts[pI]); label nCandidates = 0; forAll(allBackgroundMeshBounds_, procI) { if (allBackgroundMeshBounds_[procI].contains(pt)) { toCandidateProc.append(procI); testPoints.append(pt); nCandidates++; } } ptBlockStart[pI] = nTotalCandidates; ptBlockSize[pI] = nCandidates; nTotalCandidates += nCandidates; } // Needed for reverseDistribute label preDistributionToCandidateProcSize = toCandidateProc.size(); autoPtr<mapDistribute> map(buildMap(toCandidateProc)); map().distribute(testPoints); List<bool> pointOnCandidate(testPoints.size(), false); // Test candidate points on candidate processors forAll(testPoints, tPI) { pointOnCandidate[tPI] = positionOnThisProcessor(testPoints[tPI]); }
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; }
void Foam::CSV<Type>::read() { fileName expandedFile(fName_); IFstream is(expandedFile.expand()); if (!is.good()) { FatalIOErrorIn("CSV<Type>::read()", is) << "Cannot open CSV file for reading." << exit(FatalIOError); } DynamicList<Tuple2<scalar, Type> > values; // skip header if (headerLine_) { string line; is.getLine(line); } // read data while (is.good()) { string line; is.getLine(line); DynamicList<string> splitted; std::size_t pos = 0; while (pos != std::string::npos) { std::size_t nPos = line.find(separator_, pos); if (nPos == std::string::npos) { splitted.append(line.substr(pos)); pos = nPos; } else { splitted.append(line.substr(pos, nPos - pos)); pos = nPos + 1; } } if (splitted.size() <= 1) { break; } scalar x = readScalar(IStringStream(splitted[refColumn_])()); Type value = readValue(splitted); values.append(Tuple2<scalar,Type>(x, value)); } this->table_.transfer(values); }
void Foam::csvTableReader<Type>::operator() ( const fileName& fName, List<Tuple2<scalar, Type>>& data ) { // IFstream in(fName); autoPtr<ISstream> inPtr(fileHandler().NewIFstream(fName)); ISstream& in = inPtr(); DynamicList<Tuple2<scalar, Type>> values; // Skip header if (headerLine_) { string line; in.getLine(line); } while (in.good()) { string line; in.getLine(line); DynamicList<string> split; std::size_t pos = 0; while (pos != std::string::npos) { std::size_t nPos = line.find(separator_, pos); if (nPos == std::string::npos) { split.append(line.substr(pos)); pos=nPos; } else { split.append(line.substr(pos, nPos-pos)); pos=nPos+1; } } if (split.size() <= 1) { break; } scalar time = readScalar(IStringStream(split[timeColumn_])()); Type value = readValue(split); values.append(Tuple2<scalar,Type>(time, value)); } data.transfer(values); }
Foam::patchInteractionDataList::patchInteractionDataList ( const polyMesh& mesh, const dictionary& dict ) : List<patchInteractionData>(dict.lookup("patches")), patchGroupIDs_(this->size()) { const polyBoundaryMesh& bMesh = mesh.boundaryMesh(); const wordList allPatchNames = bMesh.names(); const List<patchInteractionData>& items = *this; forAllReverse(items, i) { const word& patchName = items[i].patchName(); labelList patchIDs = findStrings(patchName, allPatchNames); if (patchIDs.empty()) { WarningInFunction << "Cannot find any patch names matching " << patchName << endl; } patchGroupIDs_[i].transfer(patchIDs); } // Check that all patches are specified DynamicList<word> badPatches; forAll(bMesh, patchI) { const polyPatch& pp = bMesh[patchI]; if ( !pp.coupled() && !isA<emptyPolyPatch>(pp) && !isA<cyclicAMIPolyPatch>(pp) && applyToPatch(pp.index()) < 0 ) { badPatches.append(pp.name()); } } if (badPatches.size() > 0) { FatalErrorInFunction << "All patches must be specified when employing local patch " << "interaction. Please specify data for patches:" << nl << badPatches << nl << exit(FatalError); } }
Foam::fileNameList Foam::dlLoaded() { DynamicList<fileName> libs; dl_iterate_phdr(collectLibsCallback, &libs); if (POSIX::debug) { std::cout << "dlLoaded()" << " : determined loaded libraries :" << libs.size() << std::endl; } return libs; }
void refine ( cellShapeControlMesh& mesh, const conformationSurfaces& geometryToConformTo, const label maxRefinementIterations, const scalar defaultCellSize ) { for (label iter = 0; iter < maxRefinementIterations; ++iter) { DynamicList<point> ptsToInsert; for ( CellSizeDelaunay::Finite_cells_iterator cit = mesh.finite_cells_begin(); cit != mesh.finite_cells_end(); ++cit ) { const point newPoint = topoint ( CGAL::centroid ( cit->vertex(0)->point(), cit->vertex(1)->point(), cit->vertex(2)->point(), cit->vertex(3)->point() ) ); if (geometryToConformTo.inside(newPoint)) { ptsToInsert.append(newPoint); } } Info<< " Adding " << returnReduce(ptsToInsert.size(), sumOp<label>()) << endl; forAll(ptsToInsert, ptI) { mesh.insert ( ptsToInsert[ptI], defaultCellSize, triad::unset, Vb::vtInternal ); } }
void addAndExtend ( DynamicList<label>& indizes, label celli, label val ) { if (indizes.size() < (celli+1)) { indizes.setSize(celli+1,-1); } indizes[celli] = val; }
bool Foam::functionEntries::ifeqEntry::execute ( DynamicList<filePos>& stack, dictionary& parentDict, Istream& is ) { const label nNested = stack.size(); stack.append(filePos(is.name(), is.lineNumber())); // Read first token and expand any string token cond1(is); cond1 = expand(parentDict, cond1); // Read second token and expand any string token cond2(is); cond2 = expand(parentDict, cond2); const bool equal = equalToken(cond1, cond2); // Info<< "Using #" << typeName << " " << cond1 // << " == " << cond2 // << " at line " << stack.last().second() // << " in file " << stack.last().first() << endl; bool ok = ifeqEntry::execute(equal, stack, parentDict, is); if (stack.size() != nNested) { FatalIOErrorInFunction(parentDict) << "Did not find matching #endif for condition starting" << " at line " << stack.last().second() << " in file " << stack.last().first() << exit(FatalIOError); } return ok; }
Foam::label Foam::face::triangles ( const pointField& points, DynamicList<face, SizeInc, SizeMult, SizeDiv>& triFaces ) const { label triI = triFaces.size(); label quadI = 0; faceList quadFaces; // adjust the addressable size (and allocate space if needed) triFaces.setSize(triI + nTriangles()); return split(SPLITTRIANGLE, points, triI, quadI, triFaces, quadFaces); }
void SwakSetValue<T>::setValue ( fvMatrix<T>& eqn, const label fieldI ) { this->driver().clearVariables(); this->driver().parse(this->expressions_[fieldI]); if( !this->driver(). FieldValueExpressionDriver::resultIsTyp<typename SwakSetValue<T>::resultField>() ) { FatalErrorIn("SwakSetValue<"+word(pTraits<T>::typeName)+">::setValue()") << "Result of " << this->expressions_[fieldI] << " is not a " << pTraits<T>::typeName << endl << exit(FatalError); } typename SwakSetValue<T>::resultField result( this->driver(). FieldValueExpressionDriver::getResult<typename SwakSetValue<T>::resultField>() ); DynamicList<label> cellIDs; if(useMaskExpression_) { if(!getMask(cellIDs,eqn.psi().name())) { return; } } else { cellIDs=this->cells_; } List<T> values(cellIDs.size()); // UIndirectList<Type>(values, cells_) = injectionRate_[fieldI]; forAll(cellIDs,i) { label cellI=cellIDs[i]; values[i]=result[cellI]; }
void faForceEquation<vector>::operator()(faMatrix<vector> &eq) { clearVariables(); DynamicList<label> cellIDs; if(!getMask(cellIDs,eq.psi().name())) { return; } Field<vector> values(cellIDs.size()); parse(valueExpression_); const areaVectorField &calculated=getVector(); forAll(cellIDs,i) { values[i]=calculated[cellIDs[i]]; } eq.setValues(cellIDs,values); }
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; }
void forceEquation<T>::operator()(fvMatrix<T> &eq) { typedef GeometricField<T,fvPatchField,volMesh> resultField; clearVariables(); DynamicList<label> cellIDs; if(!getMask(cellIDs,eq.psi().name())) { return; } Field<T> values(cellIDs.size()); parse(valueExpression_); const resultField &calculated=getResult<resultField>(); forAll(cellIDs,i) { values[i]=calculated[cellIDs[i]]; } eq.setValues(cellIDs,values); }
int main(int argc, char *argv[]) { argList::validOptions.insert("readLevel", ""); # 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; 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[lowerLimits.size()-1]); forAll(sortedVols, i) { if (sortedVols[i] > upperLimits[upperLimits.size()-1]) { // New value outside of current bin // Shrink old bin. DynamicList<label>& bin = bins[bins.size()-1]; bin.shrink(); Info<< "Collected " << bin.size() << " elements in bin " << lowerLimits[lowerLimits.size()-1] << " .. " << upperLimits[upperLimits.size()-1] << endl; // Create new bin. bins.append(DynamicList<label>()); lowerLimits.append(sortedVols[i]); upperLimits.append(1.1*lowerLimits[lowerLimits.size()-1]); Info<< "Creating new bin " << lowerLimits[lowerLimits.size()-1] << " .. " << upperLimits[upperLimits.size()-1] << endl; } // Append to current bin. DynamicList<label>& bin = bins[bins.size()-1]; bin.append(sortedVols.indices()[i]); } Info<< endl; bins[bins.size()-1].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::STLsurfaceFormatCore::readBINARY ( istream& is, const off_t dataFileSize ) { sorted_ = true; // Read the STL header char header[headerSize]; is.read(header, headerSize); // Check that stream is OK, if not this may be an ASCII file if (!is.good()) { FatalErrorIn ( "fileFormats::STLsurfaceFormatCore::readBINARY(IFstream&)" ) << "problem reading header, perhaps file is not binary " << exit(FatalError); } // Read the number of triangles in the STl file // (note: read as int so we can check whether >2^31) int nTris; is.read(reinterpret_cast<char*>(&nTris), sizeof(unsigned int)); // Check that stream is OK and number of triangles is positive, // if not this maybe an ASCII file // // Also compare the file size with that expected from the number of tris // If the comparison is not sensible then it may be an ASCII file if ( !is || nTris < 0 || nTris < (dataFileSize - headerSize)/50 || nTris > (dataFileSize - headerSize)/25 ) { FatalErrorIn ( "fileFormats::STLsurfaceFormatCore::readBINARY(istream&)" ) << "problem reading number of triangles, perhaps file is not binary" << exit(FatalError); } #ifdef DEBUG_STLBINARY Info<< "# " << nTris << " facets" << endl; label prevZone = -1; #endif points_.setSize(3*nTris); zoneIds_.setSize(nTris); Map<label> lookup; DynamicList<label> dynSizes; label ptI = 0; label zoneI = -1; forAll(zoneIds_, faceI) { // Read an STL triangle STLtriangle stlTri(is); // transcribe the vertices of the STL triangle -> points points_[ptI++] = stlTri.a(); points_[ptI++] = stlTri.b(); points_[ptI++] = stlTri.c(); // interprete stl attribute as a zone const label origId = stlTri.attrib(); Map<label>::const_iterator fnd = lookup.find(origId); if (fnd != lookup.end()) { if (zoneI != fnd()) { // group appeared out of order sorted_ = false; } zoneI = fnd(); } else { zoneI = dynSizes.size(); lookup.insert(origId, zoneI); dynSizes.append(0); } zoneIds_[faceI] = zoneI; dynSizes[zoneI]++; #ifdef DEBUG_STLBINARY if (prevZone != zoneI) { if (prevZone != -1) { Info<< "endsolid zone" << prevZone << nl; } prevZone = zoneI; Info<< "solid zone" << prevZone << nl; } Info<< " facet normal " << stlTri.normal() << nl << " outer loop" << nl << " vertex " << stlTri.a() << nl << " vertex " << stlTri.b() << nl << " vertex " << stlTri.c() << nl << " outer loop" << nl << " endfacet" << endl; #endif }
int main(int argc, char *argv[]) { List<DynamicList<label, 1, 0> > ldl(2); ldl[0](0) = 0; ldl[0](2) = 2; ldl[0](3) = 3; ldl[0](1) = 1; ldl[0].setCapacity(5); // increase allocated size ldl[1].setCapacity(10); // increase allocated size ldl[0].reserve(15); // should increase allocated size ldl[1].reserve(5); // should not decrease allocated size ldl[1](3) = 2; // allocates space and sets value // this works without a segfault, but doesn't change the list size ldl[0][4] = 4; ldl[1] = 3; Info<< "<ldl>" << ldl << "</ldl>" << nl << "sizes: "; forAll(ldl, i) { Info<< " " << ldl[i].size() << "/" << ldl[i].capacity(); } Info<< endl; List<List<label> > ll(2); ll[0].transfer(ldl[0]); ll[1].transfer(ldl[1].shrink()); Info<< "<ldl>" << ldl << "</ldl>" << nl << "sizes: "; forAll(ldl, i) { Info<< " " << ldl[i].size() << "/" << ldl[i].capacity(); } Info<< endl; Info<< "<ll>" << ll << "</ll>" << nl << endl; // test the transfer between DynamicLists DynamicList<label, 1, 0> dlA; DynamicList<label, 1, 0> dlB; for (label i = 0; i < 5; i++) { dlA.append(i); } dlA.setCapacity(10); Info<< "<dlA>" << dlA << "</dlA>" << nl << "sizes: " << " " << dlA.size() << "/" << dlA.capacity() << endl; dlB.transfer(dlA); // provokes memory error if previous transfer did not maintain // the correct allocated space dlB[6] = 6; Info<< "Transferred to dlB" << endl; Info<< "<dlA>" << dlA << "</dlA>" << nl << "sizes: " << " " << dlA.size() << "/" << dlA.capacity() << endl; Info<< "<dlB>" << dlB << "</dlB>" << nl << "sizes: " << " " << dlB.size() << "/" << dlB.capacity() << endl; // try with a normal list: List<label> lstA; lstA.transfer(dlB); Info<< "Transferred to normal list" << endl; Info<< "<lstA>" << lstA << "</lstA>" << nl << "sizes: " << " " << lstA.size() << endl; Info<< "<dlB>" << dlB << "</dlB>" << nl << "sizes: " << " " << dlB.size() << "/" << dlB.capacity() << endl; // Copy back and append a few time for (label i=0; i < 3; i++) { dlB.append(lstA); } Info<< "appended list a few times" << endl; Info<< "<dlB>" << dlB << "</dlB>" << nl << "sizes: " << " " << dlB.size() << "/" << dlB.capacity() << endl; // assign the list (should maintain allocated space) dlB = lstA; Info<< "assigned list" << endl; Info<< "<dlB>" << dlB << "</dlB>" << nl << "sizes: " << " " << dlB.size() << "/" << dlB.capacity() << endl; // Copy back and append a few time for (label i=0; i < 3; i++) { dlB.append(lstA); } // check allocation granularity DynamicList<label, 6, 0> dlC; Info<< "<dlC>" << dlC << "</dlC>" << nl << "sizes: " << " " << dlC.size() << "/" << dlC.capacity() << endl; dlC.reserve(dlB.size()); dlC = dlB; Info<< "<dlC>" << dlC << "</dlC>" << nl << "sizes: " << " " << dlC.size() << "/" << dlC.capacity() << endl; List<label> lstB(dlC.xfer()); Info<< "Transferred to normal list via the xfer() method" << endl; Info<< "<lstB>" << lstB << "</lstB>" << nl << "sizes: " << " " << lstB.size() << endl; Info<< "<dlC>" << dlC << "</dlC>" << nl << "sizes: " << " " << dlC.size() << "/" << dlC.capacity() << endl; DynamicList<label> dlD(lstB.xfer()); Info<< "Transfer construct from normal list" << endl; Info<< "<lstB>" << lstB << "</lstB>" << nl << "sizes: " << " " << lstB.size() << endl; Info<< "<dlD>" << dlD << "</dlD>" << nl << "sizes: " << " " << dlD.size() << "/" << dlD.capacity() << endl; DynamicList<label,10> dlE1(10); DynamicList<label> dlE2(dlE1); // construct dissimilar Info<< "<dlE1>" << dlE1 << "</dlE1>" << nl << "sizes: " << " " << dlE1.size() << "/" << dlE1.capacity() << endl; Info<< "<dlE2>" << dlE2 << "</dlE2>" << nl << "sizes: " << " " << dlE2.size() << "/" << dlE2.capacity() << endl; for (label elemI=0; elemI < 5; ++elemI) { dlE1.append(4 - elemI); dlE2.append(elemI); } Info<< "<dlE2>" << dlE2 << "</dlE2>" << endl; DynamicList<label> dlE3(dlE2); // construct identical Info<< "<dlE3>" << dlE3 << "</dlE3>" << endl; dlE3 = dlE1; // assign dissimilar Info<< "<dlE3>" << dlE3 << "</dlE3>" << endl; dlE3 = dlE2; // assign identical Info<< "<dlE3>" << dlE3 << "</dlE3>" << endl; Info<< "\nEnd\n"; return 0; }
void Foam::faceOnlySet::calcSamples ( DynamicList<point>& samplingPts, DynamicList<label>& samplingCells, DynamicList<label>& samplingFaces, DynamicList<label>& samplingSegments, DynamicList<scalar>& samplingCurveDist ) const { // distance vector between sampling points if (mag(end_ - start_) < SMALL) { FatalErrorIn("faceOnlySet::calcSamples()") << "Incorrect sample specification :" << " start equals end point." << endl << " start:" << start_ << " end:" << end_ << exit(FatalError); } const vector offset = (end_ - start_); const vector normOffset = offset/mag(offset); const vector smallVec = tol*offset; const scalar smallDist = mag(smallVec); // Force calculation of minimum-tet decomposition. (void) mesh().tetBasePtIs(); // Get all boundary intersections List<pointIndexHit> bHits = searchEngine().intersections ( start_ - smallVec, end_ + smallVec ); point bPoint(GREAT, GREAT, GREAT); label bFaceI = -1; if (bHits.size()) { bPoint = bHits[0].hitPoint(); bFaceI = bHits[0].index(); } // Get first tracking point. Use bPoint, bFaceI if provided. point trackPt; label trackCellI = -1; label trackFaceI = -1; //Info<< "before getTrackingPoint : bPoint:" << bPoint // << " bFaceI:" << bFaceI << endl; getTrackingPoint ( offset, start_, bPoint, bFaceI, trackPt, trackCellI, trackFaceI ); //Info<< "after getTrackingPoint : " // << " trackPt:" << trackPt // << " trackCellI:" << trackCellI // << " trackFaceI:" << trackFaceI // << endl; if (trackCellI == -1) { // Line start_ - end_ does not intersect domain at all. // (or is along edge) // Set points and cell/face labels to empty lists //Info<< "calcSamples : Both start_ and end_ outside domain" // << endl; return; } if (trackFaceI == -1) { // No boundary face. Check for nearish internal face trackFaceI = findNearFace(trackCellI, trackPt, smallDist); } //Info<< "calcSamples : got first point to track from :" // << " trackPt:" << trackPt // << " trackCell:" << trackCellI // << " trackFace:" << trackFaceI // << endl; // // Track until hit end of all boundary intersections // // current segment number label segmentI = 0; // starting index of current segment in samplePts label startSegmentI = 0; // index in bHits; current boundary intersection label bHitI = 1; while(true) { if (trackFaceI != -1) { //Info<< "trackPt:" << trackPt << " on face so use." << endl; samplingPts.append(trackPt); samplingCells.append(trackCellI); samplingFaces.append(trackFaceI); samplingCurveDist.append(mag(trackPt - start_)); } // Initialize tracking starting from trackPt passiveParticle singleParticle ( mesh(), trackPt, trackCellI ); bool reachedBoundary = trackToBoundary ( singleParticle, samplingPts, samplingCells, samplingFaces, samplingCurveDist ); // fill sampleSegments for (label i = samplingPts.size() - 1; i >= startSegmentI; --i) { samplingSegments.append(segmentI); } if (!reachedBoundary) { //Info<< "calcSamples : Reached end of samples: " // << " samplePt now:" << singleParticle.position() // << endl; break; } // Go past boundary intersection where tracking stopped // Use coordinate comparison instead of face comparison for // accuracy reasons bool foundValidB = false; while (bHitI < bHits.size()) { scalar dist = (bHits[bHitI].hitPoint() - singleParticle.position()) & normOffset; //Info<< "Finding next boundary : " // << "bPoint:" << bHits[bHitI].hitPoint() // << " tracking:" << singleParticle.position() // << " dist:" << dist // << endl; if (dist > smallDist) { // hitpoint is past tracking position foundValidB = true; break; } else { bHitI++; } } if (!foundValidB) { // No valid boundary intersection found beyond tracking position break; } // Update starting point for tracking trackFaceI = bHits[bHitI].index(); trackPt = pushIn(bHits[bHitI].hitPoint(), trackFaceI); trackCellI = getBoundaryCell(trackFaceI); segmentI++; startSegmentI = samplingPts.size(); } }
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(); }
void Foam::polyLineSet::calcSamples ( DynamicList<point>& samplingPts, DynamicList<label>& samplingCells, DynamicList<label>& samplingFaces, DynamicList<label>& samplingSegments, DynamicList<scalar>& samplingCurveDist ) const { // Check sampling points if (sampleCoords_.size() < 2) { FatalErrorInFunction << "Incorrect sample specification. Too few points:" << sampleCoords_ << exit(FatalError); } point oldPoint = sampleCoords_[0]; for (label sampleI = 1; sampleI < sampleCoords_.size(); sampleI++) { if (mag(sampleCoords_[sampleI] - oldPoint) < SMALL) { FatalErrorInFunction << "Incorrect sample specification." << " Point " << sampleCoords_[sampleI-1] << " at position " << sampleI-1 << " and point " << sampleCoords_[sampleI] << " at position " << sampleI << " are too close" << exit(FatalError); } oldPoint = sampleCoords_[sampleI]; } // Force calculation of cloud addressing on all processors const bool oldMoving = const_cast<polyMesh&>(mesh()).moving(false); passiveParticleCloud particleCloud(mesh()); // current segment number label segmentI = 0; // starting index of current segment in samplePts label startSegmentI = 0; label sampleI = 0; point lastSample(GREAT, GREAT, GREAT); while (true) { // Get boundary intersection point trackPt; label trackCelli = -1; label trackFacei = -1; do { const vector offset = sampleCoords_[sampleI+1] - sampleCoords_[sampleI]; const scalar smallDist = mag(tol*offset); // Get all boundary intersections List<pointIndexHit> bHits = searchEngine().intersections ( sampleCoords_[sampleI], sampleCoords_[sampleI+1] ); point bPoint(GREAT, GREAT, GREAT); label bFacei = -1; if (bHits.size()) { bPoint = bHits[0].hitPoint(); bFacei = bHits[0].index(); } // Get tracking point bool isSample = getTrackingPoint ( sampleCoords_[sampleI], bPoint, bFacei, smallDist, trackPt, trackCelli, trackFacei ); if (isSample && (mag(lastSample - trackPt) > smallDist)) { //Info<< "calcSamples : getTrackingPoint returned valid sample " // << " trackPt:" << trackPt // << " trackFacei:" << trackFacei // << " trackCelli:" << trackCelli // << " sampleI:" << sampleI // << " dist:" << dist // << endl; samplingPts.append(trackPt); samplingCells.append(trackCelli); samplingFaces.append(trackFacei); // Convert sampling position to unique curve parameter. Get // fraction of distance between sampleI and sampleI+1. scalar dist = mag(trackPt - sampleCoords_[sampleI]) / mag(sampleCoords_[sampleI+1] - sampleCoords_[sampleI]); samplingCurveDist.append(sampleI + dist); lastSample = trackPt; } if (trackCelli == -1) { // No intersection found. Go to next point sampleI++; } } while ((trackCelli == -1) && (sampleI < sampleCoords_.size() - 1)); if (sampleI == sampleCoords_.size() - 1) { //Info<< "calcSamples : Reached end of samples: " // << " sampleI now:" << sampleI // << endl; break; } // // Segment sampleI .. sampleI+1 intersected by domain // // Initialize tracking starting from sampleI passiveParticle singleParticle ( mesh(), trackPt, trackCelli ); bool bReached = trackToBoundary ( particleCloud, singleParticle, sampleI, samplingPts, samplingCells, samplingFaces, samplingCurveDist ); // fill sampleSegments for (label i = samplingPts.size() - 1; i >= startSegmentI; --i) { samplingSegments.append(segmentI); } if (!bReached) { //Info<< "calcSamples : Reached end of samples: " // << " sampleI now:" << sampleI // << endl; break; } lastSample = singleParticle.position(); // Find next boundary. sampleI++; if (sampleI == sampleCoords_.size() - 1) { //Info<< "calcSamples : Reached end of samples: " // << " sampleI now:" << sampleI // << endl; break; } segmentI++; startSegmentI = samplingPts.size(); } const_cast<polyMesh&>(mesh()).moving(oldMoving); }
Foam::WallLocalSpringSliderDashpot<CloudType>::WallLocalSpringSliderDashpot ( const dictionary& dict, CloudType& cloud ) : WallModel<CloudType>(dict, cloud, typeName), Estar_(), Gstar_(), alpha_(), b_(), mu_(), patchMap_(), maxEstarIndex_(-1), collisionResolutionSteps_ ( readScalar ( this->coeffDict().lookup("collisionResolutionSteps") ) ), volumeFactor_(1.0), useEquivalentSize_(Switch(this->coeffDict().lookup("useEquivalentSize"))) { if (useEquivalentSize_) { volumeFactor_ = readScalar(this->coeffDict().lookup("volumeFactor")); } scalar pNu = this->owner().constProps().poissonsRatio(); scalar pE = this->owner().constProps().youngsModulus(); const polyMesh& mesh = cloud.mesh(); const polyBoundaryMesh& bMesh = mesh.boundaryMesh(); patchMap_.setSize(bMesh.size(), -1); DynamicList<label> wallPatchIndices; forAll(bMesh, patchI) { if (isA<wallPolyPatch>(bMesh[patchI])) { wallPatchIndices.append(bMesh[patchI].index()); } } label nWallPatches = wallPatchIndices.size(); Estar_.setSize(nWallPatches); Gstar_.setSize(nWallPatches); alpha_.setSize(nWallPatches); b_.setSize(nWallPatches); mu_.setSize(nWallPatches); scalar maxEstar = -GREAT; forAll(wallPatchIndices, wPI) { const dictionary& patchCoeffDict ( this->coeffDict().subDict(bMesh[wallPatchIndices[wPI]].name()) ); patchMap_[wallPatchIndices[wPI]] = wPI; scalar nu = readScalar(patchCoeffDict.lookup("poissonsRatio")); scalar E = readScalar(patchCoeffDict.lookup("youngsModulus")); Estar_[wPI] = 1/((1 - sqr(pNu))/pE + (1 - sqr(nu))/E); Gstar_[wPI] = 1/(2*((2 + pNu - sqr(pNu))/pE + (2 + nu - sqr(nu))/E)); alpha_[wPI] = readScalar(patchCoeffDict.lookup("alpha")); b_[wPI] = readScalar(patchCoeffDict.lookup("b")); mu_[wPI] = readScalar(patchCoeffDict.lookup("mu")); if (Estar_[wPI] > maxEstar) { maxEstarIndex_ = wPI; maxEstar = Estar_[wPI]; } } }
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::uniformSet::calcSamples ( DynamicList<point>& samplingPts, dynamicLabelList& samplingCells, dynamicLabelList& samplingFaces, dynamicLabelList& samplingSegments, DynamicList<scalar>& samplingCurveDist ) const { // distance vector between sampling points if ((nPoints_ < 2) || (mag(end_ - start_) < SMALL)) { FatalErrorIn("uniformSet::calcSamples()") << "Incorrect sample specification. Either too few points or" << " start equals end point." << endl << "nPoints:" << nPoints_ << " start:" << start_ << " end:" << end_ << exit(FatalError); } const vector offset = (end_ - start_)/(nPoints_ - 1); const vector normOffset = offset/mag(offset); const vector smallVec = tol*offset; const scalar smallDist = mag(smallVec); // Get all boundary intersections List<pointIndexHit> bHits = searchEngine().intersections ( start_ - smallVec, end_ + smallVec ); point bPoint(GREAT, GREAT, GREAT); label bFaceI = -1; if (bHits.size()) { bPoint = bHits[0].hitPoint(); bFaceI = bHits[0].index(); } // Get first tracking point. Use bPoint, bFaceI if provided. point trackPt; label trackCellI = -1; label trackFaceI = -1; bool isSample = getTrackingPoint ( offset, start_, bPoint, bFaceI, trackPt, trackCellI, trackFaceI ); if (trackCellI == -1) { // Line start_ - end_ does not intersect domain at all. // (or is along edge) // Set points and cell/face labels to empty lists return; } if (isSample) { samplingPts.append(start_); samplingCells.append(trackCellI); samplingFaces.append(trackFaceI); samplingCurveDist.append(0.0); } // // Track until hit end of all boundary intersections // // current segment number label segmentI = 0; // starting index of current segment in samplePts label startSegmentI = 0; label sampleI = 0; point samplePt = start_; // index in bHits; current boundary intersection label bHitI = 1; while(true) { // Initialize tracking starting from trackPt Cloud<passiveParticle> particles(mesh(), IDLList<passiveParticle>()); passiveParticle singleParticle ( particles, trackPt, trackCellI ); bool reachedBoundary = trackToBoundary ( singleParticle, samplePt, sampleI, samplingPts, samplingCells, samplingFaces, samplingCurveDist ); // fill sampleSegments for(label i = samplingPts.size() - 1; i >= startSegmentI; --i) { samplingSegments.append(segmentI); } if (!reachedBoundary) { if (debug) { Info<< "calcSamples : Reached end of samples: " << " samplePt now:" << samplePt << " sampleI now:" << sampleI << endl; } break; } bool foundValidB = false; while (bHitI < bHits.size()) { scalar dist = (bHits[bHitI].hitPoint() - singleParticle.position()) & normOffset; if (debug) { Info<< "Finding next boundary : " << "bPoint:" << bHits[bHitI].hitPoint() << " tracking:" << singleParticle.position() << " dist:" << dist << endl; } if (dist > smallDist) { // hitpoint is past tracking position foundValidB = true; break; } else { bHitI++; } } if (!foundValidB) { // No valid boundary intersection found beyond tracking position break; } // Update starting point for tracking trackFaceI = bFaceI; trackPt = pushIn(bPoint, trackFaceI); trackCellI = getBoundaryCell(trackFaceI); segmentI++; startSegmentI = samplingPts.size(); } }
bool Foam::fileFormats::NASsurfaceFormat<Face>::read ( const fileName& filename ) { const bool mustTriangulate = this->isTri(); this->clear(); IFstream is(filename); if (!is.good()) { FatalErrorIn ( "fileFormats::NASsurfaceFormat::read(const fileName&)" ) << "Cannot read file " << filename << exit(FatalError); } // Nastran index of points DynamicList<label> pointId; DynamicList<point> dynPoints; DynamicList<Face> dynFaces; DynamicList<label> dynZones; DynamicList<label> dynSizes; Map<label> lookup; // assume the types are not intermixed // leave faces that didn't have a group in 0 bool sorted = true; label zoneI = 0; // Name for face group Map<word> nameLookup; // Ansa tags. Denoted by $ANSA_NAME. // These will appear just before the first use of a type. // We read them and store the PSHELL types which are used to name // the zones. label ansaId = -1; word ansaType, ansaName; // A single warning per unrecognized command HashSet<word> unhandledCmd; while (is.good()) { string line; is.getLine(line); // Ansa extension if (line.substr(0, 10) == "$ANSA_NAME") { string::size_type sem0 = line.find (';', 0); string::size_type sem1 = line.find (';', sem0+1); string::size_type sem2 = line.find (';', sem1+1); if ( sem0 != string::npos && sem1 != string::npos && sem2 != string::npos ) { ansaId = readLabel ( IStringStream(line.substr(sem0+1, sem1-sem0-1))() ); ansaType = line.substr(sem1+1, sem2-sem1-1); string rawName; is.getLine(rawName); if (rawName[rawName.size()-1] == '\r') { rawName = rawName.substr(1, rawName.size()-2); } else { rawName = rawName.substr(1, rawName.size()-1); } string::stripInvalid<word>(rawName); ansaName = rawName; // Info<< "ANSA tag for NastranID:" << ansaId // << " of type " << ansaType // << " name " << ansaName << endl; } } // Hypermesh extension // $HMNAME COMP 1"partName" if ( line.substr(0, 12) == "$HMNAME COMP" && line.find ('"') != string::npos ) { label groupId = readLabel ( IStringStream(line.substr(16, 16))() ); IStringStream lineStream(line.substr(32)); string rawName; lineStream >> rawName; string::stripInvalid<word>(rawName); word groupName(rawName); nameLookup.insert(groupId, groupName); // Info<< "group " << groupId << " => " << groupName << endl; } // 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 == "CTRIA3") { triFace fTri; label groupId = readLabel(IStringStream(line.substr(16,8))()); fTri[0] = readLabel(IStringStream(line.substr(24,8))()); fTri[1] = readLabel(IStringStream(line.substr(32,8))()); fTri[2] = readLabel(IStringStream(line.substr(40,8))()); // Convert groupID into zoneId Map<label>::const_iterator fnd = lookup.find(groupId); if (fnd != lookup.end()) { if (zoneI != fnd()) { // pshell types are intermixed sorted = false; } zoneI = fnd(); } else { zoneI = dynSizes.size(); lookup.insert(groupId, zoneI); dynSizes.append(0); // Info<< "zone" << zoneI << " => group " << groupId <<endl; } dynFaces.append(fTri); dynZones.append(zoneI); dynSizes[zoneI]++; } else if (cmd == "CQUAD4") { face fQuad(4); UList<label>& f = static_cast<UList<label>&>(fQuad); label groupId = readLabel(IStringStream(line.substr(16,8))()); fQuad[0] = readLabel(IStringStream(line.substr(24,8))()); fQuad[1] = readLabel(IStringStream(line.substr(32,8))()); fQuad[2] = readLabel(IStringStream(line.substr(40,8))()); fQuad[3] = readLabel(IStringStream(line.substr(48,8))()); // Convert groupID into zoneId Map<label>::const_iterator fnd = lookup.find(groupId); if (fnd != lookup.end()) { if (zoneI != fnd()) { // pshell types are intermixed sorted = false; } zoneI = fnd(); } else { zoneI = dynSizes.size(); lookup.insert(groupId, zoneI); dynSizes.append(0); // Info<< "zone" << zoneI << " => group " << groupId <<endl; } if (mustTriangulate) { dynFaces.append(triFace(f[0], f[1], f[2])); dynFaces.append(triFace(f[0], f[2], f[3])); dynZones.append(zoneI); dynZones.append(zoneI); dynSizes[zoneI] += 2; } else { dynFaces.append(Face(f)); dynZones.append(zoneI); dynSizes[zoneI]++; } } 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] != '*') { FatalErrorIn ( "fileFormats::NASsurfaceFormat::read(const fileName&)" ) << "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)); } else if (cmd == "PSHELL") { // pshell type for zone names with the Ansa extension label groupId = readLabel(IStringStream(line.substr(8,8))()); if (groupId == ansaId && ansaType == "PSHELL") { nameLookup.insert(ansaId, ansaName); // Info<< "group " << groupId << " => " << ansaName << endl; } } else if (unhandledCmd.insert(cmd)) { Info<< "Unhandled Nastran command " << line << nl << "File:" << is.name() << " line:" << is.lineNumber() << endl; } }
void Foam::featurePointConformer::createMasterAndSlavePoints ( const extendedFeatureEdgeMesh& feMesh, const label ptI, DynamicList<Vb>& pts ) const { typedef DynamicList<autoPtr<plane> > planeDynList; typedef indexedVertexEnum::vertexType vertexType; typedef extendedFeatureEdgeMesh::edgeStatus edgeStatus; const Foam::point& featPt = feMesh.points()[ptI]; if ( ( Pstream::parRun() && !foamyHexMesh_.decomposition().positionOnThisProcessor(featPt) ) || geometryToConformTo_.outside(featPt) ) { return; } const scalar ppDist = foamyHexMesh_.pointPairDistance(featPt); // Maintain a list of master points and the planes to relect them in DynamicList<Foam::point> masterPoints; DynamicList<vertexType> masterPointsTypes; Map<planeDynList> masterPointReflections; const labelList& featPtEdges = feMesh.featurePointEdges()[ptI]; pointFeatureEdgesTypes pointEdgeTypes(feMesh, ptI); const List<extendedFeatureEdgeMesh::edgeStatus> allEdStat = pointEdgeTypes.calcPointFeatureEdgesTypes(); // Info<< nl << featPt << " " << pointEdgeTypes; const_circulator<labelList> circ(featPtEdges); // Loop around the edges of the feature point if (circ.size()) do { // const edgeStatus eStatusPrev = feMesh.getEdgeStatus(circ.prev()); const edgeStatus eStatusCurr = feMesh.getEdgeStatus(circ()); // const edgeStatus eStatusNext = feMesh.getEdgeStatus(circ.next()); // Info<< " Prev = " // << extendedFeatureEdgeMesh::edgeStatusNames_[eStatusPrev] // << " Curr = " // << extendedFeatureEdgeMesh::edgeStatusNames_[eStatusCurr] //// << " Next = " //// << extendedFeatureEdgeMesh::edgeStatusNames_[eStatusNext] // << endl; // Get the direction in which to move the point in relation to the // feature point label sign = getSign(eStatusCurr); const vector n = sharedFaceNormal(feMesh, circ(), circ.next()); const vector pointMotionDirection = sign*0.5*ppDist*n; // Info<< " Shared face normal = " << n << endl; // Info<< " Direction to move point = " << pointMotionDirection // << endl; if (masterPoints.empty()) { // Initialise with the first master point Foam::point pt = featPt + pointMotionDirection; planeDynList firstPlane; firstPlane.append(autoPtr<plane>(new plane(featPt, n))); masterPoints.append(pt); masterPointsTypes.append ( sign == 1 ? Vb::vtExternalFeaturePoint // true : Vb::vtInternalFeaturePoint // false ); //Info<< " " << " " << firstPlane << endl; // const Foam::point reflectedPoint = reflectPointInPlane // ( // masterPoints.last(), // firstPlane.last()() // ); masterPointReflections.insert ( masterPoints.size() - 1, firstPlane ); } // else if // ( // eStatusPrev == extendedFeatureEdgeMesh::INTERNAL // && eStatusCurr == extendedFeatureEdgeMesh::EXTERNAL // ) // { // // Insert a new master point. // Foam::point pt = featPt + pointMotionDirection; // // planeDynList firstPlane; // firstPlane.append(autoPtr<plane>(new plane(featPt, n))); // // masterPoints.append(pt); // // masterPointsTypes.append // ( // sign == 1 // ? Vb::vtExternalFeaturePoint // true // : Vb::vtInternalFeaturePoint // false // ); // // masterPointReflections.insert // ( // masterPoints.size() - 1, // firstPlane // ); // } // else if // ( // eStatusPrev == extendedFeatureEdgeMesh::EXTERNAL // && eStatusCurr == extendedFeatureEdgeMesh::INTERNAL // ) // { // // } else { // Just add this face contribution to the latest master point masterPoints.last() += pointMotionDirection; masterPointReflections[masterPoints.size() - 1].append ( autoPtr<plane>(new plane(featPt, n)) ); } } while (circ.circulate(CirculatorBase::CLOCKWISE)); addMasterAndSlavePoints ( masterPoints, masterPointsTypes, masterPointReflections, pts, ptI ); }
void Foam::CSV<Type>::read() { fileName expandedFile(fName_); IFstream is(expandedFile.expand()); if (!is.good()) { FatalIOErrorIn("CSV<Type>::read()", is) << "Cannot open CSV file for reading." << exit(FatalIOError); } DynamicList<Tuple2<scalar, Type> > values; // skip header for (label i = 0; i < nHeaderLine_; i++) { string line; is.getLine(line); } label nEntries = max(componentColumns_); // read data while (is.good()) { string line; is.getLine(line); label n = 0; std::size_t pos = 0; DynamicList<string> splitted; if (mergeSeparators_) { std::size_t nPos = 0; while ((pos != std::string::npos) && (n <= nEntries)) { bool found = false; while (!found) { nPos = line.find(separator_, pos); if ((nPos != std::string::npos) && (nPos - pos == 0)) { pos = nPos + 1; } else { found = true; } } nPos = line.find(separator_, pos); if (nPos == std::string::npos) { splitted.append(line.substr(pos)); pos = nPos; n++; } else { splitted.append(line.substr(pos, nPos - pos)); pos = nPos + 1; n++; } } } else { while ((pos != std::string::npos) && (n <= nEntries)) { std::size_t nPos = line.find(separator_, pos); if (nPos == std::string::npos) { splitted.append(line.substr(pos)); pos = nPos; n++; } else { splitted.append(line.substr(pos, nPos - pos)); pos = nPos + 1; n++; } } } if (splitted.size() <= 1) { break; } scalar x = readScalar(IStringStream(splitted[refColumn_])()); Type value = readValue(splitted); values.append(Tuple2<scalar,Type>(x, value)); } this->table_.transfer(values); }
bool Foam::fileFormats::TRIsurfaceFormatCore::read ( const fileName& filename ) { this->clear(); sorted_ = true; IFstream is(filename); if (!is.good()) { FatalErrorIn ( "fileFormats::TRIsurfaceFormatCore::read(const fileName&)" ) << "Cannot read file " << filename << exit(FatalError); } // uses similar structure as STL, just some points // the rest of the reader resembles the STL binary reader DynamicList<point> dynPoints; DynamicList<label> dynZones; DynamicList<label> dynSizes; HashTable<label> lookup; // place faces without a group in zone0 label zoneI = 0; dynSizes.append(zoneI); lookup.insert("zoneI", zoneI); while (is.good()) { string line = this->getLineNoComment(is); // handle continuations ? // if (line[line.size()-1] == '\\') // { // line.substr(0, line.size()-1); // line += this->getLineNoComment(is); // } IStringStream lineStream(line); point p ( readScalar(lineStream), readScalar(lineStream), readScalar(lineStream) ); if (!lineStream) break; dynPoints.append(p); dynPoints.append ( point ( readScalar(lineStream), readScalar(lineStream), readScalar(lineStream) ) ); dynPoints.append ( point ( readScalar(lineStream), readScalar(lineStream), readScalar(lineStream) ) ); // zone/colour in .tri file starts with 0x. Skip. // ie, instead of having 0xFF, skip 0 and leave xFF to // get read as a word and name it "zoneFF" char zero; lineStream >> zero; word rawName(lineStream); word name("zone" + rawName(1, rawName.size()-1)); HashTable<label>::const_iterator fnd = lookup.find(name); if (fnd != lookup.end()) { if (zoneI != fnd()) { // group appeared out of order sorted_ = false; } zoneI = fnd(); } else { zoneI = dynSizes.size(); lookup.insert(name, zoneI); dynSizes.append(0); } dynZones.append(zoneI); dynSizes[zoneI]++; } // skip empty groups label nZone = 0; forAll(dynSizes, zoneI) { if (dynSizes[zoneI]) { if (nZone != zoneI) { dynSizes[nZone] = dynSizes[zoneI]; } nZone++; } } // truncate addressed size dynSizes.setCapacity(nZone); // transfer to normal lists points_.transfer(dynPoints); zoneIds_.transfer(dynZones); sizes_.transfer(dynSizes); return true; }
bool Foam::featurePointConformer::createSpecialisedFeaturePoint ( const extendedFeatureEdgeMesh& feMesh, const labelList& pEds, const pointFeatureEdgesTypes& pFEdgesTypes, const List<extendedFeatureEdgeMesh::edgeStatus>& allEdStat, const label ptI, DynamicList<Vb>& pts ) const { if ( !pFEdgesTypes.found(extendedFeatureEdgeMesh::EXTERNAL) || !pFEdgesTypes.found(extendedFeatureEdgeMesh::INTERNAL) ) { return false; } if ( pFEdgesTypes[extendedFeatureEdgeMesh::EXTERNAL] == 2 && pFEdgesTypes[extendedFeatureEdgeMesh::INTERNAL] == 1 && pEds.size() == 3 ) { if (debug) Info<< "nExternal == 2 && nInternal == 1" << endl; const Foam::point& featPt = feMesh.points()[ptI]; if ( Pstream::parRun() && !foamyHexMesh_.decomposition().positionOnThisProcessor(featPt) ) { return false; } label nVert = foamyHexMesh_.number_of_vertices(); const label initialNumOfPoints = pts.size(); const scalar ppDist = foamyHexMesh_.pointPairDistance(featPt); const vectorField& normals = feMesh.normals(); const labelListList& edgeNormals = feMesh.edgeNormals(); label concaveEdgeI = -1; labelList convexEdgesI(2, label(-1)); label nConvex = 0; forAll(pEds, i) { const extendedFeatureEdgeMesh::edgeStatus& eS = allEdStat[i]; if (eS == extendedFeatureEdgeMesh::INTERNAL) { concaveEdgeI = pEds[i]; } else if (eS == extendedFeatureEdgeMesh::EXTERNAL) { convexEdgesI[nConvex++] = pEds[i]; } else if (eS == extendedFeatureEdgeMesh::FLAT) { WarningIn("Foam::conformalVoronoiMesh::" "createSpecialisedFeaturePoint") << "Edge " << eS << " is flat" << endl; } else { FatalErrorIn("Foam::conformalVoronoiMesh::" "createSpecialisedFeaturePoint") << "Edge " << eS << " not concave/convex" << exit(FatalError); } } const vector& concaveEdgePlaneANormal = normals[edgeNormals[concaveEdgeI][0]]; const vector& concaveEdgePlaneBNormal = normals[edgeNormals[concaveEdgeI][1]]; // Intersect planes parallel to the concave edge planes offset // by ppDist and the plane defined by featPt and the edge vector. plane planeA ( featPt + ppDist*concaveEdgePlaneANormal, concaveEdgePlaneANormal ); plane planeB ( featPt + ppDist*concaveEdgePlaneBNormal, concaveEdgePlaneBNormal ); const vector& concaveEdgeDir = feMesh.edgeDirection ( concaveEdgeI, ptI ); // Todo,needed later but want to get rid of this. const Foam::point concaveEdgeLocalFeatPt = featPt + ppDist*concaveEdgeDir; // Finding the nearest point on the intersecting line to the edge // point. Floating point errors often occur using planePlaneIntersect plane planeF(concaveEdgeLocalFeatPt, concaveEdgeDir); const Foam::point concaveEdgeExternalPt = planeF.planePlaneIntersect ( planeA, planeB ); // Redefine planes to be on the feature surfaces to project through planeA = plane(featPt, concaveEdgePlaneANormal); planeB = plane(featPt, concaveEdgePlaneBNormal); const Foam::point internalPtA = concaveEdgeExternalPt - 2.0*planeA.distance(concaveEdgeExternalPt) *concaveEdgePlaneANormal; pts.append ( Vb ( internalPtA, foamyHexMesh_.vertexCount() + pts.size(), Vb::vtInternalFeaturePoint, Pstream::myProcNo() ) ); const label internalPtAIndex(pts.last().index()); const Foam::point internalPtB = concaveEdgeExternalPt - 2.0*planeB.distance(concaveEdgeExternalPt) *concaveEdgePlaneBNormal; pts.append ( Vb ( internalPtB, foamyHexMesh_.vertexCount() + pts.size(), Vb::vtInternalFeaturePoint, Pstream::myProcNo() ) ); const label internalPtBIndex(pts.last().index()); // Add the external points Foam::point externalPtD; Foam::point externalPtE; vector convexEdgePlaneCNormal(vector::zero); vector convexEdgePlaneDNormal(vector::zero); const labelList& concaveEdgeNormals = edgeNormals[concaveEdgeI]; const labelList& convexEdgeANormals = edgeNormals[convexEdgesI[0]]; const labelList& convexEdgeBNormals = edgeNormals[convexEdgesI[1]]; forAll(concaveEdgeNormals, edgeNormalI) { bool convexEdgeA = false; bool convexEdgeB = false; forAll(convexEdgeANormals, edgeAnormalI) { const vector& concaveNormal = normals[concaveEdgeNormals[edgeNormalI]]; const vector& convexNormal = normals[convexEdgeANormals[edgeAnormalI]]; if (debug) { Info<< "Angle between vectors = " << degAngleBetween(concaveNormal, convexNormal) << endl; } // Need a looser tolerance, because sometimes adjacent triangles // on the same surface will be slightly out of alignment. if (areParallel(concaveNormal, convexNormal, tolParallel)) { convexEdgeA = true; } } forAll(convexEdgeBNormals, edgeBnormalI) { const vector& concaveNormal = normals[concaveEdgeNormals[edgeNormalI]]; const vector& convexNormal = normals[convexEdgeBNormals[edgeBnormalI]]; if (debug) { Info<< "Angle between vectors = " << degAngleBetween(concaveNormal, convexNormal) << endl; } // Need a looser tolerance, because sometimes adjacent triangles // on the same surface will be slightly out of alignment. if (areParallel(concaveNormal, convexNormal, tolParallel)) { convexEdgeB = true; } } if ((convexEdgeA && convexEdgeB) || (!convexEdgeA && !convexEdgeB)) { WarningIn ( "Foam::conformalVoronoiMesh" "::createSpecialisedFeaturePoint" ) << "Both or neither of the convex edges share the concave " << "edge's normal." << " convexEdgeA = " << convexEdgeA << " convexEdgeB = " << convexEdgeB << endl; // Remove points that have just been added before returning for (label i = 0; i < 2; ++i) { pts.remove(); nVert--; } return false; } if (convexEdgeA) { forAll(convexEdgeANormals, edgeAnormalI) { const vector& concaveNormal = normals[concaveEdgeNormals[edgeNormalI]]; const vector& convexNormal = normals[convexEdgeANormals[edgeAnormalI]]; if ( !areParallel(concaveNormal, convexNormal, tolParallel) ) { convexEdgePlaneCNormal = convexNormal; plane planeC(featPt, convexEdgePlaneCNormal); externalPtD = internalPtA + 2.0*planeC.distance(internalPtA) *convexEdgePlaneCNormal; pts.append ( Vb ( externalPtD, foamyHexMesh_.vertexCount() + pts.size(), Vb::vtExternalFeaturePoint, Pstream::myProcNo() ) ); ftPtPairs_.addPointPair ( internalPtAIndex, pts.last().index() ); } } } if (convexEdgeB) { forAll(convexEdgeBNormals, edgeBnormalI) { const vector& concaveNormal = normals[concaveEdgeNormals[edgeNormalI]]; const vector& convexNormal = normals[convexEdgeBNormals[edgeBnormalI]]; if ( !areParallel(concaveNormal, convexNormal, tolParallel) ) { convexEdgePlaneDNormal = convexNormal; plane planeD(featPt, convexEdgePlaneDNormal); externalPtE = internalPtB + 2.0*planeD.distance(internalPtB) *convexEdgePlaneDNormal; pts.append ( Vb ( externalPtE, foamyHexMesh_.vertexCount() + pts.size(), Vb::vtExternalFeaturePoint, Pstream::myProcNo() ) ); ftPtPairs_.addPointPair ( internalPtBIndex, pts.last().index() ); } } } } pts.append ( Vb ( concaveEdgeExternalPt, foamyHexMesh_.vertexCount() + pts.size(), Vb::vtExternalFeaturePoint, Pstream::myProcNo() ) ); ftPtPairs_.addPointPair ( internalPtBIndex, pts.last().index() ); ftPtPairs_.addPointPair ( internalPtAIndex, pts.last().index() ); const label concaveEdgeExternalPtIndex(pts.last().index()); const scalar totalAngle = radToDeg ( constant::mathematical::pi + radAngleBetween(concaveEdgePlaneANormal, concaveEdgePlaneBNormal) ); if (totalAngle > foamyHexMeshControls_.maxQuadAngle()) { // Add additional mitreing points //scalar angleSign = 1.0; vector convexEdgesPlaneNormal = 0.5*(convexEdgePlaneCNormal + convexEdgePlaneDNormal); plane planeM(featPt, convexEdgesPlaneNormal); // if // ( // geometryToConformTo_.outside // ( // featPt - convexEdgesPlaneNormal*ppDist // ) // ) // { // angleSign = -1.0; // } // scalar phi = // angleSign*acos(concaveEdgeDir & -convexEdgesPlaneNormal); // // scalar guard = // ( // 1.0 + sin(phi)*ppDist/mag // ( // concaveEdgeLocalFeatPt - concaveEdgeExternalPt // ) // )/cos(phi) - 1.0; const Foam::point internalPtF = concaveEdgeExternalPt //+ (2.0 + guard)*(concaveEdgeLocalFeatPt - concaveEdgeExternalPt); + 2.0*(concaveEdgeLocalFeatPt - concaveEdgeExternalPt); pts.append ( Vb ( internalPtF, foamyHexMesh_.vertexCount() + pts.size(), Vb::vtInternalFeaturePoint, Pstream::myProcNo() ) ); const label internalPtFIndex(pts.last().index()); ftPtPairs_.addPointPair ( concaveEdgeExternalPtIndex, pts.last().index() ); const Foam::point externalPtG = internalPtF + 2.0*planeM.distance(internalPtF)*convexEdgesPlaneNormal; pts.append ( Vb ( externalPtG, foamyHexMesh_.vertexCount() + pts.size(), Vb::vtExternalFeaturePoint, Pstream::myProcNo() ) ); ftPtPairs_.addPointPair ( internalPtFIndex, pts.last().index() ); } if (debug) { for (label ptI = initialNumOfPoints; ptI < pts.size(); ++ptI) { Info<< "Point " << ptI << " : "; meshTools::writeOBJ(Info, topoint(pts[ptI].point())); } } return true; }
void Foam::featurePointConformer::addMasterAndSlavePoints ( const DynamicList<Foam::point>& masterPoints, const DynamicList<Foam::indexedVertexEnum::vertexType>& masterPointsTypes, const Map<DynamicList<autoPtr<plane> > >& masterPointReflections, DynamicList<Vb>& pts, const label ptI ) const { typedef DynamicList<autoPtr<plane> > planeDynList; typedef Foam::indexedVertexEnum::vertexType vertexType; forAll(masterPoints, pI) { // Append master to the list of points const Foam::point& masterPt = masterPoints[pI]; const vertexType masterType = masterPointsTypes[pI]; // Info<< " Master = " << masterPt << endl; pts.append ( Vb ( masterPt, foamyHexMesh_.vertexCount() + pts.size(), masterType, Pstream::myProcNo() ) ); const label masterIndex = pts.last().index(); //meshTools::writeOBJ(strMasters, masterPt); const planeDynList& masterPointPlanes = masterPointReflections[pI]; forAll(masterPointPlanes, planeI) { // Reflect master points in the planes and insert the slave points const plane& reflPlane = masterPointPlanes[planeI](); const Foam::point slavePt = reflPlane.mirror(masterPt); // Info<< " Slave " << planeI << " = " << slavePt << endl; const vertexType slaveType = ( masterType == Vb::vtInternalFeaturePoint ? Vb::vtExternalFeaturePoint // true : Vb::vtInternalFeaturePoint // false ); pts.append ( Vb ( slavePt, foamyHexMesh_.vertexCount() + pts.size(), slaveType, Pstream::myProcNo() ) ); ftPtPairs_.addPointPair ( masterIndex, pts.last().index() ); //meshTools::writeOBJ(strSlaves, slavePt); } } }