void ApproximateEllipseByArcs (Real a, Real b, int numArcs, Vector2<Real>*& points, Vector2<Real>*& centers, Real*& radii) { // Allocate arrays. assertion(numArcs >= 2, "Must specify at least two arcs\n"); if (numArcs < 2) { points = 0; centers = 0; radii = 0; return; } points = new1<Vector2<Real> >(numArcs + 1); centers = new1<Vector2<Real> >(numArcs); radii = new1<Real>(numArcs); // Intermediate ellipse quantities. Real a2 = a*a, b2 = b*b, ab = a*b; Real invB2mA2 = ((Real)1)/(b2 - a2); // End points of ellipse in first quadrant. Points are generated in // counterclockwise order. points[0] = Vector2<Real>(a, (Real)0); points[numArcs] = Vector2<Real>((Real)0, b); // Curvature at end points, store curvature for computing arcs. Real curv0 = a/b2; Real curv1 = b/a2; // Select ellipse points based on curvature properties. Real invNumArcs = ((Real)1)/numArcs; int i; for (i = 1; i < numArcs; ++i) { // Curvature at new point is weighted average of curvature at ends. Real weight1 = i*invNumArcs; Real weight0 = (Real)1 - weight1; Real curv = weight0*curv0 + weight1*curv1; // Compute point having this curvature. Real tmp = Math<Real>::Pow(ab/curv, (Real)2/(Real)3); points[i][0] = a*Math<Real>::Sqrt( Math<Real>::FAbs((tmp - a2)*invB2mA2)); points[i][1] = b*Math<Real>::Sqrt( Math<Real>::FAbs((tmp - b2)*invB2mA2)); } // Compute arc at (a,0). Circle2<Real> circle; Circumscribe<Real>(Vector2<Real>(points[1][0], -points[1][1]), points[0], points[1], circle); centers[0] = circle.Center; radii[0] = circle.Radius; // Compute arc at (0,b). int last = numArcs - 1; Circumscribe(Vector2<Real>(-points[last][0], points[last][1]), points[numArcs], points[last], circle); centers[last] = circle.Center; radii[last] = circle.Radius; // Compute arcs at intermediate points between (a,0) and (0,b). int iM, iP; for (iM = 0, i = 1, iP = 2; i < last; ++iM, ++i, ++iP) { Circumscribe<Real>(points[iM], points[i], points[iP], circle); centers[i] = circle.Center; radii[i] = circle.Radius; } }
Real EigenDecomposition<Real>::GetEigenvalue (int i) const { assertion(0 <= i && i < mSize, "Invalid index in GetEigenvalue\n"); return mDiagonal[i]; }
void peano::applications::poisson::multigrid::records::RegularGridStatePacked::setMeshWidth(int elementIndex, const double& meshWidth) { assertion(elementIndex>=0); assertion(elementIndex<DIMENSIONS); _persistentRecords._meshWidth[elementIndex]= meshWidth; }
void XMLTag:: parse ( XMLTag::XMLReader* xmlReader ) { preciceTrace1("parse()", _fullName); try { resetAttributes(); if (xmlReader->getNodeType() == tarch::irr::io::EXN_ELEMENT){ assertion(xmlReader->getNodeName() != NULL); preciceDebug("reading attributes of tag " << xmlReader->getNodeName()); readAttributes(xmlReader); _listener.xmlTagCallback(*this); } if (_subtags.size() > 0){ while (xmlReader->read()){ if (xmlReader->getNodeType() == tarch::irr::io::EXN_ELEMENT){ assertion(xmlReader->getNodeName() != NULL); preciceDebug("reading subtag " << xmlReader->getNodeName() << " of tag " << _fullName); parseSubtag(xmlReader); } else if (xmlReader->getNodeType() == tarch::irr::io::EXN_ELEMENT_END){ assertion(xmlReader->getNodeName() != NULL); if (std::string(xmlReader->getNodeName()) == _fullName){ preciceDebug("end of tag " << xmlReader->getNodeName()); areAllSubtagsConfigured(); _configured = true; _listener.xmlEndTagCallback(*this); //resetAttributes(); return; } else { std::ostringstream stream; if (not _fullName.empty()){ stream << "Invalid closing tag </" << xmlReader->getNodeName() << ">"; throw stream.str(); } //else { // stream << "Invalid closing tag </" << xmlReader->getNodeName() // << ">, expected closing of tag <" << _fullName << "> instead"; //} } } } if (not _name.empty()){ std::ostringstream error; error << "Missing closing tag </" << _fullName << ">"; throw error.str(); } } else { _configured = true; } } catch (std::string errorMsg){ if (not _name.empty()){ errorMsg += "\n in tag <" + _fullName + ">"; } throw errorMsg; } }
peano::applications::poisson::multigrid::records::RegularGridStatePacked::RegularGridStatePacked(const double& omega, const tarch::la::Vector<DIMENSIONS,double>& meshWidth, const double& numberOfInnerVertices, const double& numberOfBoundaryVertices, const double& numberOfOuterVertices, const double& numberOfInnerCells, const double& numberOfOuterCells, const bool& gridIsStationary): _persistentRecords(omega, meshWidth, numberOfInnerVertices, numberOfBoundaryVertices, numberOfOuterVertices, numberOfInnerCells, numberOfOuterCells, gridIsStationary) { assertion((1 < (8 * sizeof(short int)))); }
double peano::applications::poisson::multigrid::records::RegularGridStatePacked::getMeshWidth(int elementIndex) const { assertion(elementIndex>=0); assertion(elementIndex<DIMENSIONS); return _persistentRecords._meshWidth[elementIndex]; }
peano::applications::poisson::multigrid::records::RegularGridStatePacked::RegularGridStatePacked() { assertion((1 < (8 * sizeof(short int)))); }
peano::applications::poisson::multigrid::records::RegularGridStatePacked::RegularGridStatePacked(const PersistentRecords& persistentRecords): _persistentRecords(persistentRecords._omega, persistentRecords._meshWidth, persistentRecords._numberOfInnerVertices, persistentRecords._numberOfBoundaryVertices, persistentRecords._numberOfOuterVertices, persistentRecords._numberOfInnerCells, persistentRecords._numberOfOuterCells, persistentRecords.getGridIsStationary()) { assertion((1 < (8 * sizeof(short int)))); }
int peano::applications::poisson::multigrid::records::RegularGridState::getSenderRank() const { assertion( _senderRank!=-1 ); return _senderRank; }
bool start_ndfsm(int argc, char** argv, ndfsm* test) { NDFSM_TestEngineData ndfsm_state; bool tracing_was_started_here = false; bool was_accidental_transition_traced; AssertionExit prev_assert = NULL; TestSystemParameters* pars; bool verdict; bool verdict_init; // Initialize test engine data init_NDFSM_TestEngineData( &ndfsm_state, test ); // Process standard parameters pars = processStandardParameters(test->name,test->actions,argc,argv); assertion( pars != NULL, "start_ndfsm: standard parameters processing fails"); // Start tracing if it has not been started yet if (!isInTrace()) { tracing_was_started_here = true; prev_assert = ts_setup_assert_function(); startTrace(); } START_EXCEPTION_PROTECTED_SECTION(ts_default_exception_handler); setCurrentTestScenarioName(test->name); traceScenarioStart(test->name); traceScenarioParameters(pars->argc,pars->argv); // Scenario initialization verdict = true; if (test->init != NULL) { // Trace pseudo transition start was_accidental_transition_traced = setTraceAccidental(true); traceState("start"); traceScenarioValue ("state", "", "", "start"); traceTransitionStart("initialize"); traceScenarioValue ("scenario method", "", "", "initialize"); // Call 'init' function clearOracleVerdict(); verdict_init = test->init(pars->argc, pars->argv); verdict = verdict_init && getOracleVerdict(); // Frame end verdict = onFrameEnd( &ndfsm_state.executor.model_state, verdict ); // Trace initialization failed message if (!verdict_init) { traceException(SCENARIO_INITIALIZATION_FAILED_MESSAGE); testVerdict = TD_faulted; } // Trace pseudo transition end traceTransitionEnd(); setTraceAccidental(was_accidental_transition_traced); } // FSM traversing if (verdict) {if (check_consistency_NDFSM(test)) { traceProperties_NDFSM( &ndfsm_state ); traverse_NDFSM( &ndfsm_state ); // Evaluate historical test verdict if (ndfsm_state.fatal_failure) { verdict = false; testVerdict = TD_faulted; } else if (ndfsm_state.failure_number > 0) { verdict = false; testVerdict = TD_bad_verdict; } else testVerdict = TD_ok; } if (test->finish != NULL) { // Trace pseudo transition start was_accidental_transition_traced = setTraceAccidental(true); traceTransitionStart("finalize"); traceScenarioValue ("scenario method", "", "", "finalize"); // Call 'finish' function clearOracleVerdict(); test->finish(); verdict = verdict && getOracleVerdict(); // Frame end verdict = onFrameEnd( &ndfsm_state.executor.model_state, verdict ); // Trace pseudo transition end traceTransitionEnd(); traceState("end"); traceScenarioValue ("state", "", "", "end"); setTraceAccidental(was_accidental_transition_traced); } } traceScenarioEnd(); setCurrentTestScenarioName(NULL); // Deallocate resources destroy_NDFSM_TestEngineData( &ndfsm_state ); END_EXCEPTION_PROTECTED_SECTION(); // Stop tracing if it was started here if (tracing_was_started_here) { endTrace(); ts_restore_assert_function(prev_assert); } // Disable standard parameters disableStandardParameters(pars); return verdict; }
static void destroy_NDFSM_Arc( NDFSM_Arc* arc ) { assertion( (arc != NULL), "destroy_NDFSM_Arc: arc is NULL" ); destroy_ArcSymbol( &arc->symbol ); }
int IntrLine3Cylinder3<Real>::Find (const Vector3<Real>& origin, const Vector3<Real>& dir, const Cylinder3<Real>& cylinder, Real t[2]) { // Create a coordinate system for the cylinder. In this system, the // cylinder segment center C is the origin and the cylinder axis direction // W is the z-axis. U and V are the other coordinate axis directions. // If P = x*U+y*V+z*W, the cylinder is x^2 + y^2 = r^2, where r is the // cylinder radius. The end caps are |z| = h/2, where h is the cylinder // height. Vector3<Real> U, V, W = cylinder.Axis.Direction; Vector3<Real>::GenerateComplementBasis(U, V, W); Real halfHeight = ((Real)0.5)*cylinder.Height; Real rSqr = cylinder.Radius*cylinder.Radius; // convert incoming line origin to cylinder coordinates Vector3<Real> diff = origin - cylinder.Axis.Origin; Vector3<Real> P(U.Dot(diff), V.Dot(diff), W.Dot(diff)); // Get the z-value, in cylinder coordinates, of the incoming line's // unit-length direction. Real dz = W.Dot(dir); if (Math<Real>::FAbs(dz) >= (Real)1 - Math<Real>::ZERO_TOLERANCE) { // The line is parallel to the cylinder axis. Determine if the line // intersects the cylinder end disks. Real radialSqrDist = rSqr - P.X()*P.X() - P.Y()*P.Y(); if (radialSqrDist < (Real)0) { // Line outside the cylinder, no intersection. return 0; } // Line intersects the cylinder end disks. if (dz > (Real)0) { t[0] = -P.Z() - halfHeight; t[1] = -P.Z() + halfHeight; } else { t[0] = P.Z() - halfHeight; t[1] = P.Z() + halfHeight; } return 2; } // convert incoming line unit-length direction to cylinder coordinates Vector3<Real> D(U.Dot(dir),V.Dot(dir),dz); Real a0, a1, a2, discr, root, inv, tValue; if (Math<Real>::FAbs(D.Z()) <= Math<Real>::ZERO_TOLERANCE) { // The line is perpendicular to the cylinder axis. if (Math<Real>::FAbs(P.Z()) > halfHeight) { // Line is outside the planes of the cylinder end disks. return 0; } // Test intersection of line P+t*D with infinite cylinder // x^2+y^2 = r^2. This reduces to computing the roots of a // quadratic equation. If P = (px,py,pz) and D = (dx,dy,dz), // then the quadratic equation is // (dx^2+dy^2)*t^2 + 2*(px*dx+py*dy)*t + (px^2+py^2-r^2) = 0 a0 = P.X()*P.X() + P.Y()*P.Y() - rSqr; a1 = P.X()*D.X() + P.Y()*D.Y(); a2 = D.X()*D.X() + D.Y()*D.Y(); discr = a1*a1 - a0*a2; if (discr < (Real)0) { // Line does not intersect cylinder. return 0; } else if (discr > Math<Real>::ZERO_TOLERANCE) { // Line intersects cylinder in two places. root = Math<Real>::Sqrt(discr); inv = ((Real)1)/a2; t[0] = (-a1 - root)*inv; t[1] = (-a1 + root)*inv; return 2; } else { // Line is tangent to the cylinder. t[0] = -a1/a2; return 1; } } // Test plane intersections first. int quantity = 0; inv = ((Real)1.0)/D.Z(); Real t0 = (-halfHeight - P.Z())*inv; Real xTmp = P.X() + t0*D.X(); Real yTmp = P.Y() + t0*D.Y(); if (xTmp*xTmp + yTmp*yTmp <= rSqr) { // Planar intersection inside the top cylinder end disk. t[quantity++] = t0; } Real t1 = (+halfHeight - P.Z())*inv; xTmp = P.X() + t1*D.X(); yTmp = P.Y() + t1*D.Y(); if (xTmp*xTmp + yTmp*yTmp <= rSqr) { // Planar intersection inside the bottom cylinder end disk. t[quantity++] = t1; } if (quantity == 2) { // Line intersects both top and bottom cylinder end disks. if (t[0] > t[1]) { Real save = t[0]; t[0] = t[1]; t[1] = save; } return 2; } // If quantity == 1, then the line must intersect cylinder wall in a // single point somewhere between the end disks. This case is detected // in the following code that tests for intersection between line and // cylinder wall. a0 = P.X()*P.X() + P.Y()*P.Y() - rSqr; a1 = P.X()*D.X() + P.Y()*D.Y(); a2 = D.X()*D.X() + D.Y()*D.Y(); discr = a1*a1 - a0*a2; if (discr < (Real)0) { // Line does not intersect cylinder wall. assertion(quantity == 0, "Unexpected condition\n"); return 0; } else if (discr > Math<Real>::ZERO_TOLERANCE) { root = Math<Real>::Sqrt(discr); inv = ((Real)1)/a2; tValue = (-a1 - root)*inv; if (t0 <= t1) { if (t0 <= tValue && tValue <= t1) { t[quantity++] = tValue; } } else { if (t1 <= tValue && tValue <= t0) { t[quantity++] = tValue; } } if (quantity == 2) { // Line intersects one of the cylinder end disks and once on the // cylinder wall. if (t[0] > t[1]) { Real save = t[0]; t[0] = t[1]; t[1] = save; } return 2; } tValue = (-a1 + root)*inv; if (t0 <= t1) { if (t0 <= tValue && tValue <= t1) { t[quantity++] = tValue; } } else { if (t1 <= tValue && tValue <= t0) { t[quantity++] = tValue; } } } else { tValue = -a1/a2; if (t0 <= t1) { if (t0 <= tValue && tValue <= t1) { t[quantity++] = tValue; } } else { if (t1 <= tValue && tValue <= t0) { t[quantity++] = tValue; } } } if (quantity == 2) { if (t[0] > t[1]) { Real save = t[0]; t[0] = t[1]; t[1] = save; } } return quantity; }
peano::applications::pic::demo::repositories::PICBatchJobRepositoryForSpacetreeGridArrayStackImplementation::~PICBatchJobRepositoryForSpacetreeGridArrayStackImplementation() { assertion( _repositoryState.getAction() == PICBatchJobRepositoryState::Terminate ); }