void LRSplineEvalGrid::testCoefComputation() { std::vector<double> tmpCoefs(dim_*order_v_*order_v_); std::vector<double> coefs; std::vector<double> tmpPoints(dim_*order_v_*order_v_); double *p =&tmpPoints[0]; int i=0; // for(auto it=orig.elements_begin(); it!=orig.elements_end(); it++, i++) { for(auto it=elements_begin(); it!=elements_end(); it++, i++) { param_float_type ll_x, ll_y, ur_x, ur_y; low(*it, ll_x, ll_y); high(*it, ur_x, ur_y); double ll[2]; ll[0] = ll_x; ll[1] = ll_y; double ur[2]; ur[0] = ur_x; ur[1] = ur_y; int index = i; // knotIntervals.push_back(KnotInterval(ll, ur, index)); evaluateGrid(*it, &tmpPoints[0]); computeBezCoefs(dim_, &tmpPoints[0], order_u_, order_v_, &tmpCoefs[0]); // coefficients.insert(coefficients.end(), tmpCoefs.begin(), tmpCoefs.end()); coefs.insert(coefs.end(), tmpCoefs.begin(), tmpCoefs.end()); // element_boundaries.push_back(ll_x); // element_boundaries.push_back(ll_y); // element_boundaries.push_back(ur_x); // element_boundaries.push_back(ur_y); } // m_knotSearcher.reset(new KnotIntervalSearcher(knotIntervals, glm::ivec2(128, 128))); // m_patchesU = 10; // m_patchesV = 10; // init(&element_boundaries[0], &coefficients[0]); std::cout << "Done with testCoefComputation()." << std::endl; }
std::vector<int> getLogSpacedSamplingPoints ( const unsigned & riStartPoint, const unsigned & riEndPoint, const unsigned & rnPoints ) { assert( riStartPoint > 0 ); assert( riEndPoint > riStartPoint ); assert( rnPoints > 0 ); assert( rnPoints <= riEndPoint-riStartPoint+1 ); std::vector<float> naivePoints( rnPoints ); std::vector<int> tmpPoints( rnPoints ); std::vector<int> points( rnPoints ); /* Naively create logspaced points rounding float to int */ const float dx = ( logf(riEndPoint) - logf(riStartPoint) ) / rnPoints; const float factor = exp(dx); //std::cout << "dx = " << dx << ", factor = " << factor << "\n"; naivePoints[0] = riStartPoint; for ( unsigned i = 1; i < rnPoints; ++i ) naivePoints[i] = naivePoints[i-1]*factor; /* set last point manually because of rounding errors */ naivePoints[ naivePoints.size()-1 ] = riEndPoint; //std::cout << "naivePoints = "; //for ( const auto & elem : naivePoints ) // std::cout << elem << " "; //std::cout << "\n"; /* sift out values which appear twice */ tmpPoints[0] = (int) naivePoints[0]; unsigned iTarget = 1; for ( unsigned i = 1; i < rnPoints; ++i ) { assert( iTarget >= 1 && iTarget < tmpPoints.size() ); if ( tmpPoints[ iTarget-1 ] != (int) naivePoints[i] ) tmpPoints[ iTarget++ ] = (int) naivePoints[i]; } //std::cout << "tmpPoints = "; //for ( const auto & elem : tmpPoints ) // std::cout << elem << " "; //std::cout << "\n"; /* if converted to int and fill in as many values as deleted */ int nToInsert = rnPoints - iTarget; points[0] = tmpPoints[0]; iTarget = 1; //std::cout << "nToInsert = " << nToInsert << "\n"; for ( unsigned iSrc = 1; iSrc < rnPoints; ++iSrc ) { for ( ; nToInsert > 0 and points[iTarget-1] < tmpPoints[iSrc]-1; ++iTarget, --nToInsert ) { assert( iTarget >= 1 && iTarget < points.size() ); points[iTarget] = points[iTarget-1] + 1; } assert( iSrc < tmpPoints.size() ); //assert( iTarget < points.size() ); /* this condition being false should only happen very rarely, if * rnPoints == riEndPoint - riStartPoint + 1 */ if ( iTarget < points.size() ) points[iTarget++] = tmpPoints[iSrc]; } //std::cout << "points = "; //for ( const auto & elem : points ) // std::cout << elem << " "; //std::cout << "\n"; for ( unsigned i = 1; i < points.size(); ++i ) { assert( points[i-1] < points[i] ); } return points; }
void Basis_HGRAD_LINE_Cn_FEM_JACOBI<Scalar, ArrayScalar>::getValues(ArrayScalar & outputValues, const ArrayScalar & inputPoints, const EOperator operatorType) const { // Verify arguments #ifdef HAVE_INTREPID2_DEBUG Intrepid2::getValues_HGRAD_Args<Scalar, ArrayScalar>(outputValues, inputPoints, operatorType, this -> getBaseCellTopology(), this -> getCardinality() ); #endif // Number of evaluation points = dimension 0 of inputPoints int numPoints = inputPoints.dimension(0); Teuchos::Array<Scalar> tmpPoints(numPoints); Teuchos::Array<Scalar> jacobiPolyAtPoints(numPoints); // Copy inputPoints into tmpPoints, to prepare for call to jacobfd for (int i=0; i<numPoints; i++) { tmpPoints[i] = inputPoints(i, 0); } try { switch (operatorType) { case OPERATOR_VALUE: { for (int ord = 0; ord < this -> basisCardinality_; ord++) { IntrepidPolylib::jacobfd(numPoints, &tmpPoints[0], &jacobiPolyAtPoints[0], (Scalar*)0, ord, jacobiAlpha_, jacobiBeta_); for (int pt = 0; pt < numPoints; pt++) { // outputValues is a rank-2 array with dimensions (basisCardinality_, numPoints) outputValues(ord, pt) = jacobiPolyAtPoints[pt]; } } } break; case OPERATOR_GRAD: case OPERATOR_D1: { for (int ord = 0; ord < this -> basisCardinality_; ord++) { IntrepidPolylib::jacobd(numPoints, &tmpPoints[0], &jacobiPolyAtPoints[0], ord, jacobiAlpha_, jacobiBeta_); for (int pt = 0; pt < numPoints; pt++) { // outputValues is a rank-2 array with dimensions (basisCardinality_, numPoints) outputValues(ord, pt, 0) = jacobiPolyAtPoints[pt]; } } } break; case OPERATOR_D2: case OPERATOR_D3: case OPERATOR_D4: case OPERATOR_D5: case OPERATOR_D6: case OPERATOR_D7: case OPERATOR_D8: case OPERATOR_D9: case OPERATOR_D10: { int d_order = getOperatorOrder( operatorType ); // fill in derivatives of polynomials of degree 0 through d_order - 1 with 0 // e.g. D2 annhialates linears. int stop_order; if (d_order > this->getDegree()) { stop_order = this->getDegree(); } else { stop_order = d_order; } for (int p_order=0;p_order<stop_order;p_order++) { for (int pt=0;pt<numPoints;pt++) { outputValues(p_order,pt,0) = 0.0; } } // fill in rest of derivatives with the differentiation rule for Jacobi polynomials for (int p_order=d_order;p_order<=this->getDegree();p_order++) { // calculate the scaling factor with a little loop. Scalar scalefactor = 1.0; for (int d=1;d<=d_order;d++) { scalefactor *= 0.5 * ( p_order + jacobiAlpha_ + jacobiBeta_ + d ); } // put in the right call to IntrepidPolyLib IntrepidPolylib::jacobfd(numPoints, &tmpPoints[0], &jacobiPolyAtPoints[0], (Scalar*)0, p_order-d_order, jacobiAlpha_ + d_order, jacobiBeta_ + d_order); for (int pt = 0; pt < numPoints; pt++) { // outputValues is a rank-3 array with dimensions (basisCardinality_, numPoints) outputValues(p_order, pt,0) = scalefactor *jacobiPolyAtPoints[pt]; } } } break; case OPERATOR_DIV: case OPERATOR_CURL: TEUCHOS_TEST_FOR_EXCEPTION( !( Intrepid2::isValidOperator(operatorType) ), std::invalid_argument, ">>> ERROR (Basis_HGRAD_LINE_Cn_FEM_JACOBI): Invalid operator type."); break; default: TEUCHOS_TEST_FOR_EXCEPTION( !( Intrepid2::isValidOperator(operatorType) ), std::invalid_argument, ">>> ERROR (Basis_HGRAD_LINE_Cn_FEM_JACOBI): Invalid operator type."); break; } } catch (std::invalid_argument &exception){ TEUCHOS_TEST_FOR_EXCEPTION( true , std::invalid_argument, ">>> ERROR (Basis_HGRAD_LINE_Cn_FEM_JACOBI): Operator failed"); } }