Foam::tmp<Foam::scalarField> Foam::primitiveMesh::movePoints ( const pointField& newPoints, const pointField& oldPoints ) { if (newPoints.size() < nPoints() || oldPoints.size() < nPoints()) { FatalErrorIn ( "primitiveMesh::movePoints(const pointField& newPoints, " "const pointField& oldPoints)" ) << "Cannot move points: size of given point list smaller " << "than the number of active points" << nl << "newPoints: " << newPoints.size() << " oldPoints: " << oldPoints.size() << " nPoints(): " << nPoints() << nl << abort(FatalError); } // Create swept volumes const faceList& f = faces(); tmp<scalarField> tsweptVols(new scalarField(f.size())); scalarField& sweptVols = tsweptVols(); forAll(f, faceI) { sweptVols[faceI] = f[faceI].sweptVol(oldPoints, newPoints); }
Foam::List<Foam::objectHit> Foam::PrimitivePatch<Face, FaceList, PointField, PointType>:: projectPoints ( const ToPatch& targetPatch, const Field<PointType>& projectionDirection, const intersection::algorithm alg, const intersection::direction dir ) const { // The current patch is slave, i.e. it is being projected onto the target if (projectionDirection.size() != nPoints()) { FatalErrorIn ( "PrimitivePatch<Face, FaceList, PointField, PointType>::" "projectPoints(const PrimitivePatch& " ", const Field<PointType>&) const" ) << "Projection direction field does not correspond to " << "patch points." << endl << "Size: " << projectionDirection.size() << " Number of points: " << nPoints() << abort(FatalError); } const labelList& slavePointOrder = localPointOrder(); const labelList& slaveMeshPoints = meshPoints(); // Result List<objectHit> result(nPoints()); // If there are no faces in the master patch, return: all misses if (targetPatch.size() == 0) { // Null-constructed object hit is a miss return result; } const labelListList& masterFaceFaces = targetPatch.faceFaces(); const ToPatch& masterFaces = targetPatch; const Field<PointType>& masterPoints = targetPatch.points(); // Estimate face centre of target side Field<PointType> masterFaceCentres(targetPatch.size()); forAll (masterFaceCentres, faceI) { masterFaceCentres[faceI] = average(masterFaces[faceI].points(masterPoints)); }
/*! * \brief Load data from specified file */ bool Data2D::load(const char* fileName) { // Open file and check that we're OK to proceed reading from it LineParser parser(fileName); if (!parser.ready()) { msg.print("Couldn't open file '%s' for reading.\n", fileName); return false; } int success; double oldZ = z_; clear(); while (!parser.atEnd()) { success = parser.getArgs(LineParser::SkipBlanks); if (!success) { parser.closeFiles(); msg.print("Error reading from file '%s'.\n", fileName); return false; } addPoint(parser.argd(0), parser.argd(1)); } parser.closeFiles(); msg.print("Loaded %i points from file '%s'.\n", nPoints(), fileName); z_ = oldZ; return true; }
const Foam::labelListList& Foam::primitiveMesh::pointFaces() const { if (!pfPtr_) { if (debug) { Pout<< "primitiveMesh::pointFaces() : " << "calculating pointFaces" << endl; } // Invert faces() pfPtr_ = new labelListList(nPoints()); invertManyToMany(nPoints(), faces(), *pfPtr_); } return *pfPtr_; }
void Foam::primitiveMesh::calcPointCells() const { // Loop through cells and mark up points if (debug) { Pout<< "primitiveMesh::calcPointCells() : " << "calculating pointCells" << endl; if (debug == -1) { // For checking calls:abort so we can quickly hunt down // origin of call FatalErrorIn("primitiveMesh::calcPointCells()") << abort(FatalError); } } // It is an error to attempt to recalculate pointCells // if the pointer is already set if (pcPtr_) { FatalErrorIn("primitiveMesh::calcPointCells() const") << "pointCells already calculated" << abort(FatalError); } else { const cellList& cf = cells(); // Count number of cells per point labelList npc(nPoints(), 0); forAll (cf, cellI) { const labelList curPoints = cf[cellI].labels(faces()); forAll (curPoints, pointI) { label ptI = curPoints[pointI]; npc[ptI]++; } } // Size and fill cells per point pcPtr_ = new labelListList(npc.size()); labelListList& pointCellAddr = *pcPtr_; forAll (pointCellAddr, pointI) { pointCellAddr[pointI].setSize(npc[pointI]); }
void Foam::h5Write::meshWritePoints() { Info<< " meshWritePoints" << endl; const pointField& points = mesh_.points(); // Find out how many points each process has List<label> nPoints(Pstream::nProcs()); nPoints[Pstream::myProcNo()] = points.size(); Pstream::gatherList(nPoints); Pstream::scatterList(nPoints); // Create the different datasets (needs to be done collectively) char datasetName[80]; hsize_t dimsf[2]; hid_t fileSpace; hid_t dsetID; hid_t plistID; forAll(nPoints, proc) { // Create the dataspace for the dataset dimsf[0] = nPoints[proc]; dimsf[1] = 3; fileSpace = H5Screate_simple(2, dimsf, NULL); // Set property to create parent groups as neccesary plistID = H5Pcreate(H5P_LINK_CREATE); H5Pset_create_intermediate_group(plistID, 1); // Create the dataset for points sprintf ( datasetName, "MESH/%s/processor%i/POINTS", mesh_.time().timeName().c_str(), proc ); dsetID = H5Dcreate2 ( fileID_, datasetName, H5T_SCALAR, fileSpace, plistID, H5P_DEFAULT, H5P_DEFAULT ); H5Dclose(dsetID); H5Pclose(plistID); H5Sclose(fileSpace); }
void CompositeDataset::print() const { std::cout << "Composite dataset:" << std::endl; std::cout << "Name: " << getName() << std::endl; std::cout << "N points: " << nPoints() << std::endl; std::cout << "dataset includes:" << std::endl; std::list< Dataset* >::const_iterator itrDat; for ( itrDat = _datasets.begin(); itrDat != _datasets.end(); ++itrDat ) { (*itrDat)->print(); } }
XML_Node& Domain1D::save(XML_Node& o, const doublereal* const sol) { XML_Node& d = o.addChild("domain"); d.addAttribute("points", nPoints()); d.addAttribute("components", nComponents()); d.addAttribute("id", id()); addFloatArray(d, "abstol_transient", nComponents(), &m_atol_ts[0]); addFloatArray(d, "reltol_transient", nComponents(), &m_rtol_ts[0]); addFloatArray(d, "abstol_steady", nComponents(), &m_atol_ss[0]); addFloatArray(d, "reltol_steady", nComponents(), &m_rtol_ss[0]); return d; }
/*! * \brief Convolute this data with the supplied data, by products */ bool Data2D::convoluteProduct(Data2D& data) { // Check compatibility of datasets if (data.nPoints() != nPoints()) { msg.print("Refusing to convolute by product two datasets of different sizes.\n"); return false; } for (int n=0; n<nPoints(); ++n) { if (fabs(data.x(n) - x_[n]) > 1.0e-5) { msg.print("Refusing to convolute by product two datasets with different x-values.\n"); return false; } } // Ready to go... for (int n=0; n<nPoints(); ++n) y_[n] *= data.y(n); return true; }
/*! * \brief Compute absolute integral of the data * \details Compute the absolute integral of the current data using the Trapezium method */ double Data2D::absIntegral() { if (nPoints() < 2) return 0.0; double total = 0.0, y0 = y_.first(), y1, x0 = x_.first(), x1; for (int n=1; n<x_.nItems(); ++n) { x1 = x_[n]; y1 = y_[n]; total += fabs((x1 - x0) * (y0 + y1) * 0.5); x0 = x1; y0 = y1; } return total; }
void GeoMapper::mapData() { const std::vector<GeoLib::Point*> *points (this->_geo_objects.getPointVec(this->_geo_name)); GeoLib::Station* stn_test = dynamic_cast<GeoLib::Station*>((*points)[0]); bool is_borehole(false); if (stn_test != nullptr && static_cast<GeoLib::StationBorehole*>((*points)[0])->type() == GeoLib::Station::StationType::BOREHOLE) is_borehole = true; double min_val(0), max_val(0); if (_mesh) { GeoLib::AABB<GeoLib::Point> bounding_box (_mesh->getNodes().begin(), _mesh->getNodes().end()); min_val = bounding_box.getMinPoint()[2]; max_val = bounding_box.getMaxPoint()[2]; } size_t nPoints (points->size()); if (!is_borehole) { for (unsigned j=0; j<nPoints; ++j) { GeoLib::Point* pnt ((*points)[j]); (*pnt)[2] = (_grid) ? this->getMeshElevation((*pnt)[0],(*pnt)[1], min_val, max_val) : this->getDemElevation((*pnt)[0],(*pnt)[1]); } } else { for (unsigned j=0; j<nPoints; ++j) { GeoLib::Point* pnt ((*points)[j]); double offset = (_grid) ? (this->getMeshElevation((*pnt)[0],(*pnt)[1], min_val, max_val) - (*pnt)[2]) : (this->getDemElevation((*pnt)[0],(*pnt)[1]) - (*pnt)[2]); GeoLib::StationBorehole* borehole = static_cast<GeoLib::StationBorehole*>(pnt); const std::vector<GeoLib::Point*> layers = borehole->getProfile(); size_t nLayers = layers.size(); for (unsigned k=0; k<nLayers; ++k) { GeoLib::Point* layer_pnt = layers[k]; (*layer_pnt)[2] = (*layer_pnt)[2] + offset; } } } }
void Foam::polyMesh::updateMesh(const mapPolyMesh& mpm) { // Update zones. Since boundary depends on zones, they need to be // updated first. HJ, 20/May/2014 pointZones_.updateMesh(); faceZones_.updateMesh(); cellZones_.updateMesh(); // Update boundaryMesh (note that patches themselves are already ok) boundary_.updateMesh(); // Clear out parallel data. HJ, 27/Nov/2009 deleteDemandDrivenData(globalMeshDataPtr_); setInstance(time().timeName()); // Map the old motion points if present if (oldAllPointsPtr_) { // Make a copy of the original points pointField oldMotionPoints = *oldAllPointsPtr_; pointField& newMotionPoints = *oldAllPointsPtr_; // Resize the list to new size newMotionPoints.setSize(allPoints_.size()); // Map the list newMotionPoints.map(oldMotionPoints, mpm.pointMap()); // Reset old points if present if (oldPointsPtr_) { oldPointsPtr_->reset(*oldAllPointsPtr_, nPoints()); } } // Reset valid directions (could change by faces put into empty patches) geometricD_ = Vector<label>::zero; solutionD_ = Vector<label>::zero; // Update all function objects // Moved from fvMesh.C in 1.6.x merge. HJ, 29/Aug/2010 meshObjectBase::allUpdateTopology<polyMesh>(*this, mpm); }
void LinearEditDialog::setupDialog(const std::vector<size_t> &dis_nodes, const std::vector<double> &dis_values) { size_t nPoints(_line.getNumberOfPoints()); this->tableWidget->setRowCount(nPoints); QList<QString> indexlist; for (size_t i=0; i<nPoints; i++) { indexlist.push_back(QString::number(i)); QTableWidgetItem *newItem = new QTableWidgetItem(""); tableWidget->setItem(i, 0, newItem); } QStringList vHeaders(indexlist); tableWidget->setVerticalHeaderLabels(vHeaders); size_t nValues (dis_values.size()); for (size_t i=0; i<nValues; i++) tableWidget->item(dis_nodes[i],0)->setText(QString::number(dis_values[i])); }
void CCurve::Serialize(CArchive& ar) { CElement::Serialize(ar); // Call the base class function // Serialize the vector of points if (ar.IsStoring()) { ar << m_Points.size(); // Store the point count // Now store the points for (size_t i = 0 ; i < m_Points.size() ; ++i) ar << m_Points[i]; } else { size_t nPoints(0); // Stores number of points ar >> nPoints; // Retrieve the number of points // Now retrieve the points CPoint point; for (size_t i = 0 ; i < nPoints ; ++i) { ar >> point; m_Points.push_back(point); } } }
void GeoMapper::mapData(MeshLib::Mesh const*const mesh) { const std::vector<GeoLib::Point*> *points (this->_geo_objects.getPointVec(this->_geo_name)); GeoLib::Station* stn_test = dynamic_cast<GeoLib::Station*>((*points)[0]); bool is_borehole(false); if (stn_test != NULL && static_cast<GeoLib::StationBorehole*>((*points)[0])->type() == GeoLib::Station::BOREHOLE) is_borehole = true; size_t nPoints (points->size()); if (!is_borehole) { for (unsigned j=0; j<nPoints; ++j) { GeoLib::Point* pnt ((*points)[j]); (*pnt)[2] = (_grid) ? this->getMeshElevation((*pnt)[0],(*pnt)[1], mesh) : this->getDemElevation((*pnt)[0],(*pnt)[1]); } } else { for (unsigned j=0; j<nPoints; ++j) { GeoLib::Point* pnt ((*points)[j]); double offset = (_grid) ? (this->getMeshElevation((*pnt)[0],(*pnt)[1], mesh) - (*pnt)[2]) : (this->getDemElevation((*pnt)[0],(*pnt)[1]) - (*pnt)[2]); GeoLib::StationBorehole* borehole = static_cast<GeoLib::StationBorehole*>(pnt); const std::vector<GeoLib::Point*> layers = borehole->getProfile(); size_t nLayers = layers.size(); for (unsigned k=0; k<nLayers; ++k) { GeoLib::Point* layer_pnt = layers[k]; (*layer_pnt)[2] = (*layer_pnt)[2] + offset; } } } }
GeoLib::Grid<GeoLib::PointWithID>* GeoMapper::getFlatGrid(MeshLib::Mesh const*const mesh, std::vector<GeoLib::PointWithID*> sfc_pnts) const { if (mesh->getDimension()<3) //much faster { size_t nNodes (mesh->getNNodes()); sfc_pnts.resize(nNodes); const std::vector<MeshLib::Node*> nodes (mesh->getNodes()); for (unsigned i(0); i<nNodes; ++i) sfc_pnts[i] = new GeoLib::PointWithID(nodes[i]->getCoords(), nodes[i]->getID()); } else { double dir[3] = {1,0,0}; sfc_pnts = MeshLib::MshEditor::getSurfaceNodes(*mesh, dir); } size_t nPoints (sfc_pnts.size()); for (unsigned i=0; i<nPoints; ++i) { GeoLib::PointWithID* pnt (sfc_pnts[i]); (*pnt)[2] = 0; } return new GeoLib::Grid<GeoLib::PointWithID>(sfc_pnts.begin(), sfc_pnts.end()); }
bool Foam::twoStrokeEngine::update() { // Detaching the interface if (attached()) { Info << "Decoupling sliding interfaces" << endl; makeSlidersLive(); // Changing topology by hand autoPtr<mapPolyMesh> topoChangeMap5 = topoChanger_.changeMesh(); if (topoChangeMap5->hasMotionPoints() && topoChangeMap5->morphing()) { Info << "Topology change; executing pre-motion after " << "sliding detach" << endl; movePoints(topoChangeMap5->preMotionPoints()); } Info << "sliding interfaces successfully decoupled!!!" << endl; } else { Info << "Sliding interfaces decoupled" << endl; } Info << "Executing layer action" << endl; // Piston Layering makeLayersLive(); // Changing topology by hand // /* Tommaso, 23/5/2008 // Find piston mesh modifier const label pistonLayerID = topoChanger_.findModifierID("pistonLayer"); if (pistonLayerID < 0) { FatalErrorIn("void engineFvMesh::moveAndMorph()") << "Piston modifier not found." << abort(FatalError); } scalar minLayerThickness = piston().minLayer(); scalar deltaZ = engTime().pistonDisplacement().value(); virtualPistonPosition() += deltaZ; Info << "virtualPistonPosition = " << virtualPistonPosition() << ", deckHeight = " << deckHeight() << ", pistonPosition = " << pistonPosition() << endl; if (realDeformation()) { // Dectivate piston layer Info << "Mesh deformation mode" << endl; topoChanger_[pistonLayerID].disable(); } else { // Activate piston layer Info << "Piston layering mode" << endl; topoChanger_[pistonLayerID].enable(); } // Changing topology by hand autoPtr<mapPolyMesh> topoChangeMap = topoChanger_.changeMesh(); // Work array for new points position. pointField newPoints = allPoints(); const pointField& refPoints = allPoints(); if (topoChangeMap->morphing()) { if (topoChangeMap->hasMotionPoints()) { Info<< "Topology change; executing pre-motion after " << "dynamic layering" << endl; movePoints(topoChangeMap->preMotionPoints()); newPoints = topoChangeMap->preMotionPoints(); } setV0(); resetMotion(); } // Reset the position of layered interfaces boolList scaleDisp(nPoints(), true); boolList pistonPoint(newPoints.size(), false); boolList headPoint(newPoints.size(), false); // Make a list of piston and head points. HJ, 2/Dec/2009 labelList pistonPoints; labelList headPoints; { label pistonCellIndex = cellZones().findZoneID("pistonCells"); if (pistonCellIndex < 0) { FatalErrorIn("bool twoStrokeEngine::update()") << "Cannot find cell zone pistonCells" << abort(FatalError); } const labelList& pistonCells = cellZones()[pistonCellIndex]; label headCellIndex = cellZones().findZoneID("headCells"); if (headCellIndex < 0) { FatalErrorIn("bool twoStrokeEngine::update()") << "Cannot find cell zone headCells" << abort(FatalError); } const labelList& headCells = cellZones()[headCellIndex]; const labelListList& cp = cellPoints(); boolList count(newPoints.size(), false); forAll (pistonCells, cellI) { const labelList& curCellPoints = cp[pistonCells[cellI]]; forAll (curCellPoints, i) { count[curCellPoints[i]] = true; } } // Count the points label nCounted = 0; forAll (count, pointI) { if (count[pointI] == true) { nCounted++; } } pistonPoints.setSize(nCounted); // Collect the points nCounted = 0; forAll (count, pointI) { if (count[pointI] == true) { pistonPoints[nCounted] = pointI; nCounted++; } } // Repeat for head points count = false; forAll (headCells, cellI) { const labelList& curCellPoints = cp[pistonCells[cellI]]; forAll (curCellPoints, i) { count[curCellPoints[i]] = true; } } // Count the points nCounted = 0; forAll (count, pointI) { if (count[pointI] == true) { nCounted++; } } headPoints.setSize(nCounted); // Collect the points nCounted = 0; forAll (count, pointI) { if (count[pointI] == true) { headPoints[nCounted] = pointI; nCounted++; } } } label nScaled = nPoints(); // label pistonPtsIndex = pointZones().findZoneID("pistonPoints"); // const labelList& pistonPoints = pointZones()[pistonPtsIndex]; // label headPtsIndex = pointZones().findZoneID("headPoints"); // const labelList& headPoints = pointZones()[headPtsIndex]; const scalarField& movingPointsM = movingPointsMask(); forAll(pistonPoints, i) { label pointI = pistonPoints[i]; pistonPoint[pointI] = true; point& p = newPoints[pointI]; if (p.z() < pistonPosition() - 1.0e-6) { scaleDisp[pointI] = false; nScaled--; } }
AABB::AABB(const std::vector<GEOLIB::Point*>* points) { size_t nPoints(points->size()); for (size_t i = 0; i < nPoints; i++) this->update((*(*points)[i])[0], (*(*points)[i])[1], (*(*points)[i])[2]); }
void Foam::block::createPoints() const { // set local variables for mesh specification const label ni = meshDensity().x(); const label nj = meshDensity().y(); const label nk = meshDensity().z(); const point& p000 = blockPoint(0); const point& p100 = blockPoint(1); const point& p110 = blockPoint(2); const point& p010 = blockPoint(3); const point& p001 = blockPoint(4); const point& p101 = blockPoint(5); const point& p111 = blockPoint(6); const point& p011 = blockPoint(7); // list of edge point and weighting factors const List< List<point> >& p = blockEdgePoints(); const scalarListList& w = blockEdgeWeights(); // // generate vertices // vertices_.clear(); vertices_.setSize(nPoints()); for (label k = 0; k <= nk; k++) { for (label j = 0; j <= nj; j++) { for (label i = 0; i <= ni; i++) { const label vertexNo = vtxLabel(i, j, k); // points on edges vector edgex1 = p000 + (p100 - p000)*w[0][i]; vector edgex2 = p010 + (p110 - p010)*w[1][i]; vector edgex3 = p011 + (p111 - p011)*w[2][i]; vector edgex4 = p001 + (p101 - p001)*w[3][i]; vector edgey1 = p000 + (p010 - p000)*w[4][j]; vector edgey2 = p100 + (p110 - p100)*w[5][j]; vector edgey3 = p101 + (p111 - p101)*w[6][j]; vector edgey4 = p001 + (p011 - p001)*w[7][j]; vector edgez1 = p000 + (p001 - p000)*w[8][k]; vector edgez2 = p100 + (p101 - p100)*w[9][k]; vector edgez3 = p110 + (p111 - p110)*w[10][k]; vector edgez4 = p010 + (p011 - p010)*w[11][k]; // calculate the importance factors for all edges // x-direction scalar impx1 = ( (1.0 - w[0][i])*(1.0 - w[4][j])*(1.0 - w[8][k]) + w[0][i]*(1.0 - w[5][j])*(1.0 - w[9][k]) ); scalar impx2 = ( (1.0 - w[1][i])*w[4][j]*(1.0 - w[11][k]) + w[1][i]*w[5][j]*(1.0 - w[10][k]) ); scalar impx3 = ( (1.0 - w[2][i])*w[7][j]*w[11][k] + w[2][i]*w[6][j]*w[10][k] ); scalar impx4 = ( (1.0 - w[3][i])*(1.0 - w[7][j])*w[8][k] + w[3][i]*(1.0 - w[6][j])*w[9][k] ); scalar magImpx = impx1 + impx2 + impx3 + impx4; impx1 /= magImpx; impx2 /= magImpx; impx3 /= magImpx; impx4 /= magImpx; // y-direction scalar impy1 = ( (1.0 - w[4][j])*(1.0 - w[0][i])*(1.0 - w[8][k]) + w[4][j]*(1.0 - w[1][i])*(1.0 - w[11][k]) ); scalar impy2 = ( (1.0 - w[5][j])*w[0][i]*(1.0 - w[9][k]) + w[5][j]*w[1][i]*(1.0 - w[10][k]) ); scalar impy3 = ( (1.0 - w[6][j])*w[3][i]*w[9][k] + w[6][j]*w[2][i]*w[10][k] ); scalar impy4 = ( (1.0 - w[7][j])*(1.0 - w[3][i])*w[8][k] + w[7][j]*(1.0 - w[2][i])*w[11][k] ); scalar magImpy = impy1 + impy2 + impy3 + impy4; impy1 /= magImpy; impy2 /= magImpy; impy3 /= magImpy; impy4 /= magImpy; // z-direction scalar impz1 = ( (1.0 - w[8][k])*(1.0 - w[0][i])*(1.0 - w[4][j]) + w[8][k]*(1.0 - w[3][i])*(1.0 - w[7][j]) ); scalar impz2 = ( (1.0 - w[9][k])*w[0][i]*(1.0 - w[5][j]) + w[9][k]*w[3][i]*(1.0 - w[6][j]) ); scalar impz3 = ( (1.0 - w[10][k])*w[1][i]*w[5][j] + w[10][k]*w[2][i]*w[6][j] ); scalar impz4 = ( (1.0 - w[11][k])*(1.0 - w[1][i])*w[4][j] + w[11][k]*(1.0 - w[2][i])*w[7][j] ); scalar magImpz = impz1 + impz2 + impz3 + impz4; impz1 /= magImpz; impz2 /= magImpz; impz3 /= magImpz; impz4 /= magImpz; // calculate the correction vectors vector corx1 = impx1*(p[0][i] - edgex1); vector corx2 = impx2*(p[1][i] - edgex2); vector corx3 = impx3*(p[2][i] - edgex3); vector corx4 = impx4*(p[3][i] - edgex4); vector cory1 = impy1*(p[4][j] - edgey1); vector cory2 = impy2*(p[5][j] - edgey2); vector cory3 = impy3*(p[6][j] - edgey3); vector cory4 = impy4*(p[7][j] - edgey4); vector corz1 = impz1*(p[8][k] - edgez1); vector corz2 = impz2*(p[9][k] - edgez2); vector corz3 = impz3*(p[10][k] - edgez3); vector corz4 = impz4*(p[11][k] - edgez4); // multiply by the importance factor // x-direction edgex1 *= impx1; edgex2 *= impx2; edgex3 *= impx3; edgex4 *= impx4; // y-direction edgey1 *= impy1; edgey2 *= impy2; edgey3 *= impy3; edgey4 *= impy4; // z-direction edgez1 *= impz1; edgez2 *= impz2; edgez3 *= impz3; edgez4 *= impz4; // add the contributions vertices_[vertexNo] = ( edgex1 + edgex2 + edgex3 + edgex4 + edgey1 + edgey2 + edgey3 + edgey4 + edgez1 + edgez2 + edgez3 + edgez4 ) / 3.0; vertices_[vertexNo] += ( corx1 + corx2 + corx3 + corx4 + cory1 + cory2 + cory3 + cory4 + corz1 + corz2 + corz3 + corz4 ); } } } }
nCells = max(nCells, neighbour_[facei]); } nCells++; // Reset the primitiveMesh with the sizes of the primitive arrays primitiveMesh::reset ( points_.size(), neighbour_.size(), owner_.size(), nCells ); string meshInfo = "nPoints:" + Foam::name(nPoints()) + " nCells:" + Foam::name(this->nCells()) + " nFaces:" + Foam::name(nFaces()) + " nInternalFaces:" + Foam::name(nInternalFaces()); owner_.note() = meshInfo; neighbour_.note() = meshInfo; } void Foam::polyMesh::initMesh(cellList& c) { if (debug) { Info<< "void polyMesh::initMesh(cellList& c) : " << "calculating owner-neighbour arrays" << endl;
void Foam::block::createPoints() { // Set local variables for mesh specification const label ni = density().x(); const label nj = density().y(); const label nk = density().z(); const point& p000 = blockPoint(0); const point& p100 = blockPoint(1); const point& p110 = blockPoint(2); const point& p010 = blockPoint(3); const point& p001 = blockPoint(4); const point& p101 = blockPoint(5); const point& p111 = blockPoint(6); const point& p011 = blockPoint(7); // List of edge point and weighting factors pointField p[12]; scalarList w[12]; label nCurvedEdges = edgesPointsWeights(p, w); points_.setSize(nPoints()); points_[pointLabel(0, 0, 0)] = p000; points_[pointLabel(ni, 0, 0)] = p100; points_[pointLabel(ni, nj, 0)] = p110; points_[pointLabel(0, nj, 0)] = p010; points_[pointLabel(0, 0, nk)] = p001; points_[pointLabel(ni, 0, nk)] = p101; points_[pointLabel(ni, nj, nk)] = p111; points_[pointLabel(0, nj, nk)] = p011; for (label k=0; k<=nk; k++) { for (label j=0; j<=nj; j++) { for (label i=0; i<=ni; i++) { // Skip block vertices if (vertex(i, j, k)) continue; const label vijk = pointLabel(i, j, k); // Calculate the weighting factors for all edges // x-direction scalar wx1 = (1 - w0)*(1 - w4)*(1 - w8) + w0*(1 - w5)*(1 - w9); scalar wx2 = (1 - w1)*w4*(1 - w11) + w1*w5*(1 - w10); scalar wx3 = (1 - w2)*w7*w11 + w2*w6*w10; scalar wx4 = (1 - w3)*(1 - w7)*w8 + w3*(1 - w6)*w9; const scalar sumWx = wx1 + wx2 + wx3 + wx4; wx1 /= sumWx; wx2 /= sumWx; wx3 /= sumWx; wx4 /= sumWx; // y-direction scalar wy1 = (1 - w4)*(1 - w0)*(1 - w8) + w4*(1 - w1)*(1 - w11); scalar wy2 = (1 - w5)*w0*(1 - w9) + w5*w1*(1 - w10); scalar wy3 = (1 - w6)*w3*w9 + w6*w2*w10; scalar wy4 = (1 - w7)*(1 - w3)*w8 + w7*(1 - w2)*w11; const scalar sumWy = wy1 + wy2 + wy3 + wy4; wy1 /= sumWy; wy2 /= sumWy; wy3 /= sumWy; wy4 /= sumWy; // z-direction scalar wz1 = (1 - w8)*(1 - w0)*(1 - w4) + w8*(1 - w3)*(1 - w7); scalar wz2 = (1 - w9)*w0*(1 - w5) + w9*w3*(1 - w6); scalar wz3 = (1 - w10)*w1*w5 + w10*w2*w6; scalar wz4 = (1 - w11)*(1 - w1)*w4 + w11*(1 - w2)*w7; const scalar sumWz = wz1 + wz2 + wz3 + wz4; wz1 /= sumWz; wz2 /= sumWz; wz3 /= sumWz; wz4 /= sumWz; // Points on straight edges const vector edgex1 = p000 + (p100 - p000)*w0; const vector edgex2 = p010 + (p110 - p010)*w1; const vector edgex3 = p011 + (p111 - p011)*w2; const vector edgex4 = p001 + (p101 - p001)*w3; const vector edgey1 = p000 + (p010 - p000)*w4; const vector edgey2 = p100 + (p110 - p100)*w5; const vector edgey3 = p101 + (p111 - p101)*w6; const vector edgey4 = p001 + (p011 - p001)*w7; const vector edgez1 = p000 + (p001 - p000)*w8; const vector edgez2 = p100 + (p101 - p100)*w9; const vector edgez3 = p110 + (p111 - p110)*w10; const vector edgez4 = p010 + (p011 - p010)*w11; // Add the contributions points_[vijk] = ( wx1*edgex1 + wx2*edgex2 + wx3*edgex3 + wx4*edgex4 + wy1*edgey1 + wy2*edgey2 + wy3*edgey3 + wy4*edgey4 + wz1*edgez1 + wz2*edgez2 + wz3*edgez3 + wz4*edgez4 )/3; // Apply curved-edge correction if block has curved edges if (nCurvedEdges) { // Calculate the correction vectors const vector corx1 = wx1*(p[0][i] - edgex1); const vector corx2 = wx2*(p[1][i] - edgex2); const vector corx3 = wx3*(p[2][i] - edgex3); const vector corx4 = wx4*(p[3][i] - edgex4); const vector cory1 = wy1*(p[4][j] - edgey1); const vector cory2 = wy2*(p[5][j] - edgey2); const vector cory3 = wy3*(p[6][j] - edgey3); const vector cory4 = wy4*(p[7][j] - edgey4); const vector corz1 = wz1*(p[8][k] - edgez1); const vector corz2 = wz2*(p[9][k] - edgez2); const vector corz3 = wz3*(p[10][k] - edgez3); const vector corz4 = wz4*(p[11][k] - edgez4); points_[vijk] += ( corx1 + corx2 + corx3 + corx4 + cory1 + cory2 + cory3 + cory4 + corz1 + corz2 + corz3 + corz4 ); } } } } if (!nCurvedFaces()) return; // Apply curvature correction to face points FixedList<pointField, 6> facePoints(this->facePoints(points_)); correctFacePoints(facePoints); // Loop over points and apply the correction from the from the i-faces for (label ii=0; ii<=ni; ii++) { // Process the points on the curved faces last label i = (ii + 1)%(ni + 1); for (label j=0; j<=nj; j++) { for (label k=0; k<=nk; k++) { // Skip non-curved faces and edges if (flatFaceOrEdge(i, j, k)) continue; const label vijk = pointLabel(i, j, k); scalar wf0 = ( (1 - w0)*(1 - w4)*(1 - w8) + (1 - w1)*w4*(1 - w11) + (1 - w2)*w7*w11 + (1 - w3)*(1 - w7)*w8 ); scalar wf1 = ( w0*(1 - w5)*(1 - w9) + w1*w5*(1 - w10) + w2*w5*w10 + w3*(1 - w6)*w9 ); const scalar sumWf = wf0 + wf1; wf0 /= sumWf; wf1 /= sumWf; points_[vijk] += ( wf0 *( facePoints[0][facePointLabel(0, j, k)] - points_[pointLabel(0, j, k)] ) + wf1 *( facePoints[1][facePointLabel(1, j, k)] - points_[pointLabel(ni, j, k)] ) ); } } } // Loop over points and apply the correction from the from the j-faces for (label jj=0; jj<=nj; jj++) { // Process the points on the curved faces last label j = (jj + 1)%(nj + 1); for (label i=0; i<=ni; i++) { for (label k=0; k<=nk; k++) { // Skip flat faces and edges if (flatFaceOrEdge(i, j, k)) continue; const label vijk = pointLabel(i, j, k); scalar wf2 = ( (1 - w4)*(1 - w1)*(1 - w8) + (1 - w5)*w0*(1 - w9) + (1 - w6)*w3*w9 + (1 - w7)*(1 - w3)*w8 ); scalar wf3 = ( w4*(1 - w1)*(1 - w11) + w5*w1*(1 - w10) + w6*w2*w10 + w7*(1 - w2)*w11 ); const scalar sumWf = wf2 + wf3; wf2 /= sumWf; wf3 /= sumWf; points_[vijk] += ( wf2 *( facePoints[2][facePointLabel(2, i, k)] - points_[pointLabel(i, 0, k)] ) + wf3 *( facePoints[3][facePointLabel(3, i, k)] - points_[pointLabel(i, nj, k)] ) ); } } } // Loop over points and apply the correction from the from the k-faces for (label kk=0; kk<=nk; kk++) { // Process the points on the curved faces last label k = (kk + 1)%(nk + 1); for (label i=0; i<=ni; i++) { for (label j=0; j<=nj; j++) { // Skip flat faces and edges if (flatFaceOrEdge(i, j, k)) continue; const label vijk = pointLabel(i, j, k); scalar wf4 = ( (1 - w8)*(1 - w0)*(1 - w4) + (1 - w9)*w0*(1 - w5) + (1 - w10)*w1*w5 + (1 - w11)*(1 - w1)*w4 ); scalar wf5 = ( w8*(1 - w3)*(1 - w7) + w9*w3*(1 - w6) + w10*w2*w6 + w11*(1 - w2)*w7 ); const scalar sumWf = wf4 + wf5; wf4 /= sumWf; wf5 /= sumWf; points_[vijk] += ( wf4 *( facePoints[4][facePointLabel(4, i, j)] - points_[pointLabel(i, j, 0)] ) + wf5 *( facePoints[5][facePointLabel(5, i, j)] - points_[pointLabel(i, j, nk)] ) ); } } } }
Foam::multiSolidBodyMotionFvMesh::multiSolidBodyMotionFvMesh(const IOobject& io) : dynamicFvMesh(io), dynamicMeshCoeffs_ ( IOdictionary ( IOobject ( "dynamicMeshDict", io.time().constant(), *this, IOobject::MUST_READ_IF_MODIFIED, IOobject::NO_WRITE, false ) ).subDict(typeName + "Coeffs") ), undisplacedPoints_ ( IOobject ( "points", io.time().constant(), meshSubDir, *this, IOobject::MUST_READ, IOobject::NO_WRITE, false ) ) { if (undisplacedPoints_.size() != nPoints()) { FatalIOErrorInFunction ( dynamicMeshCoeffs_ ) << "Read " << undisplacedPoints_.size() << " undisplaced points from " << undisplacedPoints_.objectPath() << " but the current mesh has " << nPoints() << exit(FatalIOError); } zoneIDs_.setSize(dynamicMeshCoeffs_.size()); SBMFs_.setSize(dynamicMeshCoeffs_.size()); pointIDs_.setSize(dynamicMeshCoeffs_.size()); label zoneI = 0; forAllConstIter(dictionary, dynamicMeshCoeffs_, iter) { if (iter().isDict()) { zoneIDs_[zoneI] = cellZones().findZoneID(iter().keyword()); if (zoneIDs_[zoneI] == -1) { FatalIOErrorInFunction ( dynamicMeshCoeffs_ ) << "Cannot find cellZone named " << iter().keyword() << ". Valid zones are " << cellZones().names() << exit(FatalIOError); } const dictionary& subDict = iter().dict(); SBMFs_.set ( zoneI, solidBodyMotionFunction::New(subDict, io.time()) ); // Collect points of cell zone. const cellZone& cz = cellZones()[zoneIDs_[zoneI]]; boolList movePts(nPoints(), false); forAll(cz, i) { label celli = cz[i]; const cell& c = cells()[celli]; forAll(c, j) { const face& f = faces()[c[j]]; forAll(f, k) { label pointi = f[k]; movePts[pointi] = true; } } }
Polyline* Polyline::constructPolylineFromSegments(const std::vector<Polyline*>& ply_vec, double prox) { size_t nLines = ply_vec.size(); Polyline* new_ply = new Polyline(*ply_vec[0]); std::vector<GEOLIB::Point*> pnt_vec(new_ply->getPointsVec()); std::vector<Polyline*> local_ply_vec; for (size_t i = 1; i < nLines; i++) local_ply_vec.push_back(ply_vec[i]); while (!local_ply_vec.empty()) { bool ply_found(false); prox *= prox; // square distance once to save time later for (std::vector<Polyline*>::iterator it = local_ply_vec.begin(); it != local_ply_vec.end(); ++it) { if (pnt_vec == (*it)->getPointsVec()) { size_t nPoints((*it)->getNumberOfPoints()); // if (new_ply->getPointID(0) == (*it)->getPointID(0)) if (pointsAreIdentical(pnt_vec, new_ply->getPointID(0), (*it)->getPointID(0), prox)) { Polyline* tmp = new Polyline((*it)->getPointsVec()); for (size_t k = 0; k < nPoints; k++) tmp->addPoint((*it)->getPointID(nPoints - k - 1)); size_t new_ply_size(new_ply->getNumberOfPoints()); for (size_t k = 1; k < new_ply_size; k++) tmp->addPoint(new_ply->getPointID(k)); delete new_ply; new_ply = tmp; ply_found = true; } // else if (new_ply->getPointID(0) == (*it)->getPointID(nPoints-1)) else if (pointsAreIdentical(pnt_vec, new_ply->getPointID(0), (*it)->getPointID(nPoints - 1), prox)) { Polyline* tmp = new Polyline(**it); size_t new_ply_size(new_ply->getNumberOfPoints()); for (size_t k = 1; k < new_ply_size; k++) tmp->addPoint(new_ply->getPointID(k)); delete new_ply; new_ply = tmp; ply_found = true; } // else if (new_ply->getPointID(new_ply->getNumberOfPoints()-1) == (*it)->getPointID(0)) else if (pointsAreIdentical(pnt_vec, new_ply->getPointID(new_ply->getNumberOfPoints() - 1), (*it)->getPointID(0), prox)) { for (size_t k = 1; k < nPoints; k++) new_ply->addPoint((*it)->getPointID(k)); ply_found = true; } // else if (new_ply->getPointID(new_ply->getNumberOfPoints()-1) == (*it)->getPointID(nPoints-1)) else if (pointsAreIdentical(pnt_vec, new_ply->getPointID(new_ply->getNumberOfPoints() - 1), (*it)->getPointID(nPoints - 1), prox)) { for (size_t k = 1; k < nPoints; k++) new_ply->addPoint((*it)->getPointID(nPoints - k - 1)); ply_found = true; } if (ply_found) { local_ply_vec.erase(it); break; } } else std::cout << "Error in Polyline::contructPolylineFromSegments() - Line segments use different point " "vectors..." << "\n"; } if (!ply_found) { std::cout << "Error in Polyline::contructPolylineFromSegments() - Not all segments are connected..." << "\n"; new_ply = NULL; break; } } return new_ply; }
void toPython() { RefElem RefConv; std::ostringstream ostr; ostr << getName() << "_" << getPointsInfo() << ".py"; std::ofstream ofs( ostr.str().c_str() ); ofs << "from pyx import *\n"; ofs << "p=path.path("; for ( uint16_type i = 0; i < Convex::numEdges; ++i ) { for ( uint16_type j = 0; j < 2; ++j ) { node_type x( 2 ); if ( Convex::nRealDim == 1 ) { x( 0 ) = RefConv.edgeVertex( i,j )( 0 ); x( 1 ) = value_type( 0 ); } if ( Convex::nRealDim == 2 ) { x = RefConv.edgeVertex( i, j ); } if ( Convex::nRealDim == 3 ) { x( 0 ) = RefConv.edgeVertex( i, j )( 0 )+RefConv.edgeVertex( i, j )( 1 )*std::cos( M_PI/4 ); x( 1 ) = RefConv.edgeVertex( i, j )( 2 )+RefConv.edgeVertex( i, j )( 1 )*std::sin( M_PI/4 ); } if ( j == 0 ) ofs << "path.moveto(" << double( x( 0 ) )<< "," << double( x( 1 ) ) << "),\n"; else if ( j == 1 ) ofs << "path.lineto(" << double( x( 0 ) )<< "," << double( x( 1 ) ) << "),\n"; } } ofs << "path.closepath() )\n"; ofs << "text.set(mode=\"latex\")\n" << "c = canvas.canvas()\n" << "c.stroke(p, [style.linewidth.Thin])\n"; for ( uint16_type i = 0; i < nPoints(); ++i ) { node_type x( 2 ); if ( Convex::nRealDim == 1 ) { x( 0 ) = this->point( i )( 0 ); x( 1 ) = value_type( 0 ); } if ( Convex::nRealDim == 2 ) { x = this->point( i ); } if ( Convex::nRealDim == 3 ) { x( 0 ) = this->point( i )( 0 ) + this->point( i )( 1 )*std::cos( M_PI/4 ); x( 1 ) = this->point( i )( 2 ) + this->point( i )( 1 )*std::sin( M_PI/4 ); } ofs << "c.fill ( path.circle(" << double( x( 0 ) ) << "," << double( x( 1 ) )<< ", 0.02 ),[deco.filled([color.rgb.red])])\n"; ofs << "c.text( " << double( x( 0 )+0.025 ) << "," << double( x( 1 )+0.025 )<< ", r\"{\\scriptsize " << i << "}\")\n"; } ofs << "c.writeEPSfile(\"" << getName() << "_" << getPointsInfo() << "\", document.paperformat.A4)\n"; }
{ nonGlobalPatchPointsPtr_ = new labelList(nPoints()); labelList& ngpp = *nonGlobalPatchPointsPtr_; forAll(ngpp, i) { ngpp[i] = i; } } else { // Get reference to shared points const labelList& sharedPoints = boundaryMesh().mesh()().globalData().sharedPointLabels(); nonGlobalPatchPointsPtr_ = new labelList(nPoints()); labelList& ngpp = *nonGlobalPatchPointsPtr_; const labelList& faMeshPatchPoints = pointLabels(); const labelList& meshPoints = boundaryMesh().mesh().patch().meshPoints(); label noFiltPoints = 0; forAll (faMeshPatchPoints, pointI) { label curP = meshPoints[faMeshPatchPoints[pointI]]; bool found = false;
int main() { typedef double scalar_type; typedef numeric::vector <scalar_type> vector_type; typedef numeric::matrix <scalar_type> matrix_type; typedef scalar_type (*function_type )( vector_type const & ); typedef vector_type (*function_grad_type )( vector_type const & ); typedef matrix_type (*function_inv_hessian_type)( vector_type const & ); typedef scalar_type (*scalar_norm_type )( scalar_type ); typedef scalar_type (*vector_norm_type )( numeric::ublas::vector_expression<vector_type> const & ); typedef numeric::barrier_method::PointDebugInfo<scalar_type> points_debug_info_type; function_type const f = &function::function<vector_type>; function_grad_type const df = &function::functionGrad<vector_type>; scalar_type const preferredPrecision = function::preferredPrecision; scalar_norm_type const sNorm = &xmath::abs<scalar_type>; vector_norm_type const vNorm = &numeric::ublas::norm_2<vector_type>; vector_type startPoint(2); startPoint(0) = function::startX; startPoint(1) = function::startY; scalar_type const startMu = function::startMu; scalar_type const beta = function::beta; std::vector<function_type> constraints; std::vector<function_grad_type> constraintsGrads; constraints. push_back(&function::limitFunc1<scalar_type>); constraints. push_back(&function::limitFunc2<scalar_type>); constraintsGrads.push_back(&function::limitFuncGrad1<scalar_type>); constraintsGrads.push_back(&function::limitFuncGrad2<scalar_type>); // TODO: Separate this constants. scalar_type const gradientDescentPrecision = 1e-8; scalar_type const gradientDescentStep = 1.0; { // // Calculating Lipschitz constant. // vector_type x(2); x(0) = function::loLipschitzX; x(1) = function::loLipschitzY; vector_type y(2); y(0) = function::hiLipschitzX; y(1) = function::hiLipschitzY; vector_type step(2); step(0) = function::lipschitzStepX; step(1) = function::lipschitzStepY; scalar_type const R = numeric::lipschitz_constant<function_type, scalar_type, scalar_norm_type, vector_type, vector_norm_type>( f, sNorm, x, y, vNorm, step); { // Saving Lipschitz constant. char const *dataFileName = "../output/lipschitz_const.tex"; boost::scoped_ptr<std::ofstream> ofs(new std::ofstream(dataFileName)); if (ofs->fail()) { std::cerr << "Failed to open data file '" << dataFileName << "'.\n"; return 1; } *ofs << boost::format("%1$15.8f") % R; } } { // // Barrier method. // std::vector<points_debug_info_type> points; vector_type const xMin = numeric::barrier_method::find_min <function_type, function_grad_type, scalar_type>( f, df, constraints.begin(), constraints.end(), constraintsGrads.begin(), constraintsGrads.end(), startPoint, startMu, beta, preferredPrecision, gradientDescentPrecision, gradientDescentStep, std::back_inserter(points)); { // Saving passed spots. char const *dataFileName = "../output/ne_points.dat"; // TODO: Correct file name. boost::scoped_ptr<std::ofstream> ofs(new std::ofstream(dataFileName)); if (ofs->fail()) { std::cerr << "Failed to open data file '" << dataFileName << "'.\n"; return 1; } for (size_t i = 0; i < points.size(); ++i) { points_debug_info_type const &pdi = points[i]; numeric::output_vector_coordinates<std::ofstream, vector_type>(*ofs, pdi.x, " ", "\n", "%1$15.8f"); } } { // Saving detail report. char const *dataFileName = "../output/bm_points.tex"; boost::scoped_ptr<std::ofstream> ofs(new std::ofstream(dataFileName)); if (ofs->fail()) { std::cerr << "Failed to open data file '" << dataFileName << "'.\n"; return 1; } for (size_t i = 0; i < points.size(); ++i) { points_debug_info_type const &pdi = points[i]; *ofs << i + 1 << " & "; // TODO: There is space between brackets and numbers! *ofs << "( "; numeric::output_vector_coordinates(*ofs, pdi.x, ", ", "", "%1$15.8f"); *ofs << " ) & "; *ofs << boost::format("%1$15.8f") % (pdi.fx) << " & "; *ofs << boost::format("%1$15.8f") % (pdi.mu) << " & "; *ofs << boost::format("%1$15.8f") % (pdi.Bx) << " & "; *ofs << boost::format("%1$15.8f") % (pdi.mu * pdi.Bx) << " & "; *ofs << boost::format("%1$15.8f") % (pdi.fx + pdi.mu * pdi.Bx) << " \\\\ " << std::endl; } } if (points.begin() != points.end()) { // Saving passed spots function values (for contours). char const *dataFileName = "../output/ne_contours.gp"; // TODO: Correct file name. boost::scoped_ptr<std::ofstream> ofs(new std::ofstream(dataFileName)); if (ofs->fail()) { std::cerr << "Failed to open data file '" << dataFileName << "'.\n"; return 1; } *ofs << "set cntrparam levels discrete "; for (size_t i = 1; i < points.size(); ++i) *ofs << points[i].fx << ","; *ofs << points[0].fx; *ofs << std::endl; } } { // Generating report data. char const *dataFileName = "../output/ne_points.tex"; boost::scoped_ptr<std::ofstream> ofs(new std::ofstream(dataFileName)); if (ofs->fail()) { std::cerr << "Failed to open data file '" << dataFileName << "'.\n"; return 1; } boost::optional<scalar_type> prevFMinVal; for (size_t p = 0; p < numeric::array_size(function::precisions); ++p) { scalar_type const precision = function::precisions[p]; size_t nPoints(0); numeric::CountingOutputIterator outputIterator(nPoints); vector_type const xMin = numeric::barrier_method::find_min <function_type, function_grad_type, scalar_type>( f, df, constraints.begin(), constraints.end(), constraintsGrads.begin(), constraintsGrads.end(), startPoint, startMu, beta, precision, gradientDescentPrecision, gradientDescentStep, outputIterator); // Outputting: precision, number of iterations, xMin, f(xMin), f(xMin) - f(xPrevMin), grad f, g1(xMin), g2(xMin). *ofs << boost::format("%1$1.0e") % precision << " & " << nPoints << " & ("; numeric::output_vector_coordinates(*ofs, xMin, ", ", ""); *ofs << ") & "; scalar_type const curFMinVal = f(xMin); *ofs << boost::format("%1$15.8f") % curFMinVal << " & "; if (prevFMinVal) *ofs << boost::format("%1e") % (curFMinVal - *prevFMinVal); prevFMinVal = curFMinVal; vector_type const curGrad = df(xMin); *ofs << " & ("; numeric::output_vector_coordinates(*ofs, curGrad, ", ", "", "%1e"); *ofs << ")"; *ofs << " & " << constraints[0](xMin); *ofs << " & " << constraints[1](xMin); *ofs << " \\\\\n"; } } }
Foam::polyMesh::polyMesh(const IOobject& io) : objectRegistry(io), primitiveMesh(), points_ ( IOobject ( "points", time().findInstance(meshDir(), "points"), meshSubDir, *this, IOobject::MUST_READ, IOobject::NO_WRITE ) ), faces_ ( IOobject ( "faces", time().findInstance(meshDir(), "faces"), meshSubDir, *this, IOobject::MUST_READ, IOobject::NO_WRITE ) ), owner_ ( IOobject ( "owner", faces_.instance(), meshSubDir, *this, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE ) ), neighbour_ ( IOobject ( "neighbour", faces_.instance(), meshSubDir, *this, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE ) ), clearedPrimitives_(false), boundary_ ( IOobject ( "boundary", time().findInstance(meshDir(), "boundary"), meshSubDir, *this, IOobject::MUST_READ, IOobject::NO_WRITE ), *this ), bounds_(points_), comm_(UPstream::worldComm), geometricD_(Vector<label>::zero), solutionD_(Vector<label>::zero), tetBasePtIsPtr_(NULL), cellTreePtr_(NULL), pointZones_ ( IOobject ( "pointZones", time().findInstance ( meshDir(), "pointZones", IOobject::READ_IF_PRESENT ), meshSubDir, *this, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE ), *this ), faceZones_ ( IOobject ( "faceZones", time().findInstance ( meshDir(), "faceZones", IOobject::READ_IF_PRESENT ), meshSubDir, *this, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE ), *this ), cellZones_ ( IOobject ( "cellZones", time().findInstance ( meshDir(), "cellZones", IOobject::READ_IF_PRESENT ), meshSubDir, *this, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE ), *this ), globalMeshDataPtr_(NULL), moving_(false), topoChanging_(false), curMotionTimeIndex_(time().timeIndex()), oldPointsPtr_(NULL) { if (exists(owner_.objectPath())) { initMesh(); } else { cellCompactIOList cLst ( IOobject ( "cells", time().findInstance(meshDir(), "cells"), meshSubDir, *this, IOobject::MUST_READ, IOobject::NO_WRITE ) ); // Set the primitive mesh initMesh(cLst); owner_.write(); neighbour_.write(); } // Calculate topology for the patches (processor-processor comms etc.) boundary_.updateMesh(); // Calculate the geometry for the patches (transformation tensors etc.) boundary_.calcGeometry(); // Warn if global empty mesh if (returnReduce(nPoints(), sumOp<label>()) == 0) { WarningIn("polyMesh(const IOobject&)") << "no points in mesh" << endl; } if (returnReduce(nCells(), sumOp<label>()) == 0) { WarningIn("polyMesh(const IOobject&)") << "no cells in mesh" << endl; } // Initialise demand-driven data calcDirections(); }
Foam::solidBodyMotionFvMesh::solidBodyMotionFvMesh(const IOobject& io) : dynamicFvMesh(io), dynamicMeshCoeffs_ ( IOdictionary ( IOobject ( "dynamicMeshDict", io.time().constant(), *this, IOobject::MUST_READ_IF_MODIFIED, IOobject::NO_WRITE, false ) ).subDict(typeName + "Coeffs") ), SBMFPtr_(solidBodyMotionFunction::New(dynamicMeshCoeffs_, io.time())), undisplacedPoints_ ( IOobject ( "points", io.time().constant(), meshSubDir, *this, IOobject::MUST_READ, IOobject::NO_WRITE, false ) ), zoneID_(-1), pointIDs_() { if (undisplacedPoints_.size() != nPoints()) { FatalIOErrorIn ( "solidBodyMotionFvMesh::solidBodyMotionFvMesh(const IOobject&)", dynamicMeshCoeffs_ ) << "Read " << undisplacedPoints_.size() << " undisplaced points from " << undisplacedPoints_.objectPath() << " but the current mesh has " << nPoints() << exit(FatalError); } word cellZoneName = dynamicMeshCoeffs_.lookupOrDefault<word>("cellZone", "none"); if (cellZoneName != "none") { zoneID_ = cellZones().findZoneID(cellZoneName); Info<< "Applying solid body motion to cellZone " << cellZoneName << endl; const cellZone& cz = cellZones()[zoneID_]; // collect point IDs of points in cell zone boolList movePts(nPoints(), false); forAll(cz, i) { label cellI = cz[i]; const cell& c = cells()[cellI]; forAll(c, j) { const face& f = faces()[c[j]]; forAll(f, k) { label pointI = f[k]; movePts[pointI] = true; } }
Foam::solidBodyMotionFvMesh::solidBodyMotionFvMesh(const IOobject& io) : dynamicFvMesh(io), dynamicMeshCoeffs_ ( IOdictionary ( IOobject ( "dynamicMeshDict", io.time().constant(), *this, IOobject::MUST_READ_IF_MODIFIED, IOobject::NO_WRITE, false ) ).subDict(typeName + "Coeffs") ), SBMFPtr_(solidBodyMotionFunction::New(dynamicMeshCoeffs_, io.time())), undisplacedPoints_ ( IOobject ( "points", io.time().constant(), meshSubDir, *this, IOobject::MUST_READ, IOobject::NO_WRITE, false ) ), pointIDs_(), moveAllCells_(false), UName_(dynamicMeshCoeffs_.lookupOrDefault<word>("UName", "U")) { if (undisplacedPoints_.size() != nPoints()) { FatalIOErrorIn ( "solidBodyMotionFvMesh::solidBodyMotionFvMesh(const IOobject&)", dynamicMeshCoeffs_ ) << "Read " << undisplacedPoints_.size() << " undisplaced points from " << undisplacedPoints_.objectPath() << " but the current mesh has " << nPoints() << exit(FatalIOError); } word cellZoneName = dynamicMeshCoeffs_.lookupOrDefault<word>("cellZone", "none"); word cellSetName = dynamicMeshCoeffs_.lookupOrDefault<word>("cellSet", "none"); if ((cellZoneName != "none") && (cellSetName != "none")) { FatalIOErrorIn ( "solidBodyMotionFvMesh::solidBodyMotionFvMesh(const IOobject&)", dynamicMeshCoeffs_ ) << "Either cellZone OR cellSet can be supplied, but not both. " << "If neither is supplied, all cells will be included" << exit(FatalIOError); } labelList cellIDs; if (cellZoneName != "none") { Info<< "Applying solid body motion to cellZone " << cellZoneName << endl; label zoneID = cellZones().findZoneID(cellZoneName); if (zoneID == -1) { FatalErrorIn ( "solidBodyMotionFvMesh::solidBodyMotionFvMesh(const IOobject&)" ) << "Unable to find cellZone " << cellZoneName << ". Valid celLZones are:" << cellZones().names() << exit(FatalError); } cellIDs = cellZones()[zoneID]; } if (cellSetName != "none") { Info<< "Applying solid body motion to cellSet " << cellSetName << endl; cellSet set(*this, cellSetName); cellIDs = set.toc(); } label nCells = returnReduce(cellIDs.size(), sumOp<label>()); moveAllCells_ = nCells == 0; if (moveAllCells_) { Info<< "Applying solid body motion to entire mesh" << endl; } else { // collect point IDs of points in cell zone boolList movePts(nPoints(), false); forAll(cellIDs, i) { label cellI = cellIDs[i]; const cell& c = cells()[cellI]; forAll(c, j) { const face& f = faces()[c[j]]; forAll(f, k) { label pointI = f[k]; movePts[pointI] = true; } } }
void SetupAxis(int nm, GLuint &vao, GLuint &vbo, GLuint &ibo) { std::vector<gmtl::Point3f>start; std::vector<gmtl::Point3f> verts; std::vector<unsigned int> indices; std::vector<gmtl::Point3f> color; std::vector<gmtl::Point2f> uvs; std::vector<gmtl::Point3f> normals; int np = 5; gmtl::Point3f p0(.0f, .0f, .0f); gmtl::Point3f p1(.025f, .0f, .0f); gmtl::Point3f p2(.025f, .85f, .0f); gmtl::Point3f p3(.055f, .85f, .0f); gmtl::Point3f p4(.0f, 1.0f, .0f); start.push_back(p0); start.push_back(p1); start.push_back(p2); start.push_back(p3); start.push_back(p4); verts = rPoints(start, nm, np, 'y'); color = cPoints(verts, 'o'); normals = nPoints(verts, 'a'); uvs = uvPoints(nm, np); GenerateIndices(nm, np, indices); axisIndexSize = indices.size(); int vertOffset = verts.size() * sizeof(gmtl::Point3f); int uvOffset = uvs.size() * sizeof(gmtl::Point2f); int colorOffset = color.size() * sizeof(gmtl::Point3f); int indexOffset = indices.size() * sizeof(GLuint); int normalOffset = normals.size() * sizeof(gmtl::Point3f); glGenVertexArrays(1, &vao); glBindVertexArray(vao); glGenBuffers(1, &ibo); //Setup 1 buffer name and store the generated buffer object name their glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo); //bind the buffer name to the target glBufferData(GL_ELEMENT_ARRAY_BUFFER, //target buffer object indexOffset, //size of buffer object &indices[0], //pointer to the data GL_STATIC_DRAW); glGenBuffers(1, &vbo); glBindBuffer(GL_ARRAY_BUFFER, vbo); //Set the size and data of the Vertex Buffer Object and set it to STATIC_DRAW glBufferData(GL_ARRAY_BUFFER, //this is the target we are buffering to vertOffset + colorOffset + normalOffset + uvOffset, //this is the total size of the buffer NULL, //address of the content to be updated nothing because we are setting it in the subData buffers GL_STATIC_DRAW);//+ uvOffset + normalOffset glBufferSubData(GL_ARRAY_BUFFER, 0, //offset where data replacement will begin vertOffset, //size &verts[0]);//address of the content to be updated glBufferSubData(GL_ARRAY_BUFFER, vertOffset, //offset where data replacement will begin colorOffset, //size &color[0]);//data glBufferSubData(GL_ARRAY_BUFFER, vertOffset + colorOffset, normalOffset, &normals[0]); glBufferSubData(GL_ARRAY_BUFFER, vertOffset + colorOffset + normalOffset, uvOffset, &uvs[0]); //verts|uv|color|normals //layout(location = 0) in vec4 VertexPosition; //layout(location = 1) in vec4 VertexColor; //layout(location = 2) in vec3 VertexNormal; //layout(location = 3) in vec2 VertexUV; //This is the layout in the shader for the attribute variables //that will be binded to the different geometry buffers glEnableVertexAttribArray(0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)(0)); glEnableVertexAttribArray(1); glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (void*)(vertOffset)); // vertex buffer object glEnableVertexAttribArray(2); glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, (void*)(vertOffset + colorOffset)); // vertex buffer object glEnableVertexAttribArray(3); glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, 0, (void*)(vertOffset + colorOffset + normalOffset)); glBindVertexArray(0); //Bind the index buffer for the object glBindBuffer(GL_ARRAY_BUFFER, 0); // Bind the index buffer for the object glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); }