void PreviousSolutionFunction::values(FieldContainer<double> &values, BasisCachePtr basisCache) { int rank = Teuchos::GlobalMPISession::getRank(); if (_overrideMeshCheck) { _solnExpression->evaluate(values, _soln, basisCache); return; } if (!basisCache.get()) cout << "basisCache is nil!\n"; if (!_soln.get()) cout << "_soln is nil!\n"; // values are stored in (C,P,D) order if (basisCache->mesh().get() == _soln->mesh().get()) { _solnExpression->evaluate(values, _soln, basisCache); } else { static bool warningIssued = false; if (!warningIssued) { if (rank==0) cout << "NOTE: In PreviousSolutionFunction, basisCache's mesh doesn't match solution's. If this is not what you intended, it would be a good idea to make sure that the mesh is passed in on BasisCache construction; the evaluation will be a lot slower without it...\n"; warningIssued = true; } // get the physicalPoints, and make a basisCache for each... FieldContainer<double> physicalPoints = basisCache->getPhysicalCubaturePoints(); FieldContainer<double> value(1,1); // assumes scalar-valued solution function. int numCells = physicalPoints.dimension(0); int numPoints = physicalPoints.dimension(1); int spaceDim = physicalPoints.dimension(2); physicalPoints.resize(numCells*numPoints,spaceDim); vector< ElementPtr > elements = _soln->mesh()->elementsForPoints(physicalPoints, false); // false: don't make elements null just because they're off-rank. FieldContainer<double> point(1,spaceDim); FieldContainer<double> refPoint(1,spaceDim); int combinedIndex = 0; vector<GlobalIndexType> cellID; cellID.push_back(-1); BasisCachePtr basisCacheOnePoint; for (int cellIndex=0; cellIndex<numCells; cellIndex++) { for (int ptIndex=0; ptIndex<numPoints; ptIndex++, combinedIndex++) { if (elements[combinedIndex].get()==NULL) continue; // no element found for point; skip it… ElementTypePtr elemType = elements[combinedIndex]->elementType(); for (int d=0; d<spaceDim; d++) { point(0,d) = physicalPoints(combinedIndex,d); } if (elements[combinedIndex]->cellID() != cellID[0]) { cellID[0] = elements[combinedIndex]->cellID(); basisCacheOnePoint = Teuchos::rcp( new BasisCache(elemType, _soln->mesh()) ); basisCacheOnePoint->setPhysicalCellNodes(_soln->mesh()->physicalCellNodesForCell(cellID[0]),cellID,false); // false: don't createSideCacheToo } // compute the refPoint: typedef CellTools<double> CellTools; int whichCell = 0; CellTools::mapToReferenceFrame(refPoint,point,_soln->mesh()->physicalCellNodesForCell(cellID[0]), *(elemType->cellTopoPtr),whichCell); basisCacheOnePoint->setRefCellPoints(refPoint); // cout << "refCellPoints:\n " << refPoint; // cout << "physicalCubaturePoints:\n " << basisCacheOnePoint->getPhysicalCubaturePoints(); _solnExpression->evaluate(value, _soln, basisCacheOnePoint); // cout << "value at point (" << point(0,0) << ", " << point(0,1) << ") = " << value(0,0) << endl; values(cellIndex,ptIndex) = value(0,0); } } } }
void Foam::sampledPlane::print(Ostream& os) const { os << "sampledPlane: " << name() << " :" << " base:" << refPoint() << " normal:" << normal() << " faces:" << faces().size() << " points:" << points().size(); }
void DXF2BRD_CONVERTER::addText( const DRW_Text& aData ) { BOARD_ITEM* brdItem; EDA_TEXT* textItem; if( m_useModuleItems ) { TEXTE_MODULE* modText = new TEXTE_MODULE( NULL ); brdItem = static_cast< BOARD_ITEM* >( modText ); textItem = static_cast< EDA_TEXT* >( modText ); } else { TEXTE_PCB* pcbText = new TEXTE_PCB( NULL ); brdItem = static_cast< BOARD_ITEM* >( pcbText ); textItem = static_cast< EDA_TEXT* >( pcbText ); } brdItem->SetLayer( ToLAYER_ID( m_brdLayer ) ); wxPoint refPoint( mapX( aData.basePoint.x ), mapY( aData.basePoint.y ) ); wxPoint secPoint( mapX( aData.secPoint.x ), mapY( aData.secPoint.y ) ); if( aData.alignV != 0 || aData.alignH != 0 || aData.alignH == DRW_Text::HMiddle ) { if( aData.alignH != DRW_Text::HAligned && aData.alignH != DRW_Text::HFit ) { wxPoint tmp = secPoint; secPoint = refPoint; refPoint = tmp; } } switch( aData.alignV ) { case DRW_Text::VBaseLine: textItem->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM ); break; case DRW_Text::VBottom: textItem->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM ); break; case DRW_Text::VMiddle: textItem->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER ); break; case DRW_Text::VTop: textItem->SetVertJustify( GR_TEXT_VJUSTIFY_TOP ); break; } switch( aData.alignH ) { case DRW_Text::HLeft: textItem->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT ); break; case DRW_Text::HCenter: textItem->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER ); break; case DRW_Text::HRight: textItem->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT ); break; case DRW_Text::HAligned: // no equivalent options in text pcb. textItem->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT ); break; case DRW_Text::HMiddle: // no equivalent options in text pcb. textItem->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER ); break; case DRW_Text::HFit: // no equivalent options in text pcb. textItem->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT ); break; } #if 0 wxString sty = wxString::FromUTF8( aData.style.c_str() ); sty = sty.ToLower(); if( aData.textgen == 2 ) { // Text dir = left to right; } else if( aData.textgen == 4 ) { // Text dir = top to bottom; } else { } #endif wxString text = toNativeString( wxString::FromUTF8( aData.text.c_str() ) ); textItem->SetTextPos( refPoint ); textItem->SetTextAngle( aData.angle * 10 ); // The 0.8 factor gives a better height/width ratio with our font textItem->SetTextWidth( mapDim( aData.height * 0.8 ) ); textItem->SetTextHeight( mapDim( aData.height ) ); textItem->SetThickness( mapDim( aData.thickness == 0 ? m_defaultThickness : aData.thickness ) ); textItem->SetText( text ); m_newItemsList.push_back( static_cast< BOARD_ITEM* >( brdItem ) ); }
/** * Import texts (TEXT). */ void DXF2BRD_CONVERTER::addText(const DRW_Text& data) { TEXTE_PCB* pcb_text = new TEXTE_PCB( m_brd ); pcb_text->SetLayer( m_brdLayer ); wxPoint refPoint( mapX(data.basePoint.x), mapY(data.basePoint.y) ); wxPoint secPoint( mapX(data.secPoint.x), mapY(data.secPoint.y) ); if (data.alignV !=0 || data.alignH !=0 ||data.alignH ==DRW_Text::HMiddle) { if (data.alignH !=DRW_Text::HAligned && data.alignH !=DRW_Text::HFit) { wxPoint tmp = secPoint; secPoint = refPoint; refPoint = tmp; } } switch( data.alignV ) { case DRW_Text::VBaseLine: pcb_text->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM ); break; case DRW_Text::VBottom: pcb_text->SetVertJustify( GR_TEXT_VJUSTIFY_BOTTOM ); break; case DRW_Text::VMiddle: pcb_text->SetVertJustify( GR_TEXT_VJUSTIFY_CENTER ); break; case DRW_Text::VTop: pcb_text->SetVertJustify( GR_TEXT_VJUSTIFY_TOP ); break; } switch( data.alignH ) { case DRW_Text::HLeft: pcb_text->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT ); break; case DRW_Text::HCenter: pcb_text->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER ); break; case DRW_Text::HRight: pcb_text->SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT ); break; case DRW_Text::HAligned: // no equivalent options in text pcb. pcb_text->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT ); break; case DRW_Text::HMiddle: // no equivalent options in text pcb. pcb_text->SetHorizJustify( GR_TEXT_HJUSTIFY_CENTER ); break; case DRW_Text::HFit: // no equivalent options in text pcb. pcb_text->SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT ); break; } #if 0 wxString sty = wxString::FromUTF8(data.style.c_str()); sty=sty.ToLower(); if (data.textgen==2) { // Text dir = left to right; } else if (data.textgen==4) { / Text dir = top to bottom; } else { }
// Cutting line of two planes Foam::plane::ray Foam::plane::planeIntersect(const plane& plane2) const { // Mathworld plane-plane intersection. Assume there is a point on the // intersection line with z=0 and solve the two plane equations // for that (now 2x2 equation in x and y) // Better: use either z=0 or x=0 or y=0. const vector& n1 = normal(); const vector& n2 = plane2.normal(); const point& p1 = refPoint(); const point& p2 = plane2.refPoint(); scalar n1p1 = n1&p1; scalar n2p2 = n2&p2; vector dir = n1 ^ n2; // Determine zeroed out direction (can be x,y or z) by looking at which // has the largest component in dir. scalar magX = mag(dir.x()); scalar magY = mag(dir.y()); scalar magZ = mag(dir.z()); direction iZero, i1, i2; if (magX > magY) { if (magX > magZ) { iZero = 0; i1 = 1; i2 = 2; } else { iZero = 2; i1 = 0; i2 = 1; } } else { if (magY > magZ) { iZero = 1; i1 = 2; i2 = 0; } else { iZero = 2; i1 = 0; i2 = 1; } } vector pt; pt[iZero] = 0; pt[i1] = (n2[i2]*n1p1 - n1[i2]*n2p2) / (n1[i1]*n2[i2] - n2[i1]*n1[i2]); pt[i2] = (n2[i1]*n1p1 - n1[i1]*n2p2) / (n1[i2]*n2[i1] - n1[i1]*n2[i2]); return ray(pt, dir); }