int main() { D4 od4; chkVal(__LINE__, "od4.vf1()", od4.vf1(), 101); chkVal(__LINE__, "od4.vf2()", od4.vf2(), 201); chkVal(__LINE__, "od4.vf3()", od4.vf3(), 301); chkVal(__LINE__, "od4.vf4()", od4.vf4(), 401); // Check access through pointer to right "diamond" lattice // R1* rptr = new D4; chkVal(__LINE__, "rptr->vf1()", rptr->vf1(), 101); // should call R1::vf1 chkVal(__LINE__, "rptr->vf2()", rptr->vf2(), 201); // should call L2::vf2 chkVal(__LINE__, "rptr->vf3()", rptr->vf3(), 301); // should call L3::vf3 chkVal(__LINE__, "rptr->vf4()", rptr->vf4(), 401); // should call R4::vf4 // Check access through pointer to left "diamond" lattice // L3* lptr = new D1; chkVal(__LINE__, "lptr->vf1()", lptr->vf1(), 101); // should call R1::vf1 chkVal(__LINE__, "lptr->vf2()", lptr->vf2(), 201); // should call L2::vf2 chkVal(__LINE__, "lptr->vf3()", lptr->vf3(), 301); // should call L3::vf3 chkVal(__LINE__, "lptr->vf4()", lptr->vf4(), 401); // should call R4::vf4 _PASS; }
template <typename R1, typename R2> inline bool is_ci_equal(R1 const &var, R2 const &target) { //BOOST_STATIC_ASSERT((boost::is_same<typename R1::value_type, typename R2::value_type>::value)); BOOST_STATIC_ASSERT((sizeof(typename R1::value_type) == sizeof(typename R2::value_type))); if (var.size() == target.size()) { return std::equal(var.begin(), var.end(), target.begin(), ci_equal<typename R1::value_type>()); } return false; }
void TypeOfFE_P1Lagrange1d::FB(const What_d whatd,const Mesh & ,const Element & K,const R1 & P,RNMK_ & val) const { // const Triangle & K(FE.T); R l[]={1.-P.sum(),P.x}; assert(val.N() >=Element::nv); assert(val.M()==1 ); val=0; RN_ f0(val('.',0,op_id)); if (whatd & Fop_D0) { f0[0] = l[0]; f0[1] = l[1]; } if (whatd & Fop_D1) { R1 Dl[3]; K.Gradlambda(Dl); if (whatd & Fop_dx) { RN_ f0x(val('.',0,op_dx)); f0x[0] = Dl[0].x; f0x[1] = Dl[1].x; } } }
void check_equal_ranges(const std::string& string1, const R1& range1, const std::string& string2, const R2& range2) { auto r1_it = range1.begin(); auto r2_it = range2.begin(); auto r1_end = range1.end(); auto r2_end = range2.end(); for (; r1_it != r1_end && r2_it != r2_end; ++r1_it, ++r2_it) { BOOST_CHECK_MESSAGE( *r1_it == *r2_it, string1 << " (" << *r1_it << ") == " << string2 << " ("<< *r2_it << ")"); } BOOST_CHECK_MESSAGE(r1_it == r1_end, "Reached end of " << string1); BOOST_CHECK_MESSAGE(r2_it == r2_end, "Reached end of " << string2); }
void TypeOfFE_P2Lagrange1d::FB(const What_d whatd,const Mesh & ,const Element & K,const R1 & P,RNMK_ & val) const { // const Triangle & K(FE.T); R l[]={1.-P.sum(),P.x}; assert(val.N() >=E::nv+E::ne); assert(val.M()==1 ); val=0; RN_ f0(val('.',0,op_id)); // if (whatd & Fop_D0) { int k=0; for(int i=0;i<E::nv;++i) f0[k++] = l[i]*(2*l[i]-1.); for(int i=0;i<E::ne;++i) f0[k++] = 4.*l[E::nvedge[i][0]]*l[E::nvedge[i][1]]; } if (whatd & (Fop_D1|Fop_D2)) { R1 Dl[2]; R l4[2]={ (4*l[0]-1),(4*l[1]-1)}; K.Gradlambda(Dl); RN_ f0x(val('.',0,op_dx)); int k=0; for(int i=0;i<E::nv;++i,++k) { f0x[k] = Dl[i].x*l4[i]; } for(int i=0;i<E::ne;++i,++k) { int i0=E::nvedge[i][0],i1=E::nvedge[i][1]; f0x[k] = 4*(Dl[i1].x*l[i0] + Dl[i0].x*l[i1]) ; } assert(k==1); //cout << " D2 " << whatd << endl; if (whatd & Fop_D2) { //cout << " D2 " << endl; RN_ f0xx(val('.',0,op_dxx)); k=0; for(int i=0;i<E::nv;++i,++k) { f0xx[k] = 4.*Dl[i].x*Dl[i].x; } for(int i=0;i<E::ne;++i,++k) { int i0=E::nvedge[i][0],i1=E::nvedge[i][1]; f0xx[k] = 8.*Dl[i0].x*Dl[i1].x; } } } }
template <typename R1, typename R2> inline bool is_ci_less(R1 const &var, R2 const &target) { BOOST_STATIC_ASSERT((boost::is_same<typename R1::value_type, typename R2::value_type>::value)); return std::lexicographical_compare(var.begin(), var.end(), target.begin(), target.end(), ci_less<typename R1::value_type>()); }
template < class Q1, class R1> BOOST_FORCEINLINE void do_it(A0& a0, const char& orient, Q1 & q1, R1 & r1) const { BOOST_AUTO_TPL(q, boost::proto::child_c<0>(a0)); BOOST_AUTO_TPL(r, boost::proto::child_c<1>(a0)); size_t j = boost::proto::child_c<2>(a0); BOOST_AUTO_TPL(x, boost::proto::child_c<3>(a0)); table<value_t, nt2::of_size_<2, 2> > g; size_t n = size(r, 2); size_t m = size(r, 1); if (orient == 'c') { // Make room and insert x before j-th column. r1.resize(nt2::of_size(m, n+1)); q1 = q; r1(nt2::_,nt2::_(1, j-1)) = r(nt2::_,nt2::_(1, j-1)); r1(nt2::_,nt2::_(j+1, n+1)) = r(nt2::_,nt2::_(j, n)); r1(nt2::_,j) = nt2::mtimes(nt2::ct(q), x); ++n; // now r has nonzeros below the diagonal in the j-th column, // and "extra" zeros on the diagonal in later columns. // r = [x x x x x [x x x x x // 0 x x x x g 0 x x x x // 0 0 + x x ---> 0 0 * * * // 0 0 + 0 x 0 0 0 * * // 0 0 + 0 0] 0 0 0 0 *] // use givens rotations to zero the +'s, one at a time, from bottom to top. // // q is treated to (the transpose of) the same rotations. // q = [x x x x x g' [x x * * * // x x x x x ---> x x * * * // x x x x x x x * * * // x x x x x x x * * * // x x x x x] x x * * *] for(size_t k = m-1; k >= j; --k) { BOOST_AUTO_TPL(p, nt2::cons(k, k+1)); nt2::tie(g,r1(p,j)) = nt2::planerot(r1(p,j)); if (k < n) { r1(p,nt2::_(k+1, n)) = nt2::mtimes(g, r1(p,nt2::_(k+1, n))); } q1(nt2::_,p) = nt2::mtimes(q1(nt2::_,p), nt2::ct(g)); } } else { r1 = catv(x, r); q1 = catv(cath(nt2::One<value_t>(), nt2::zeros(1,m,meta::as_<value_t>())), cath(nt2::zeros(m,1,meta::as_<value_t>()),q)); // now r is upper hessenberg. // r = [x x x x [* * * * // + x x x g * * * // + x x ---> * * // + x * // + 0 0 0 0 // 0 0 0 0 0 0 0 0 // 0 0 0 0] 0 0 0 0] // use givens rotations to zero the +'s, one at a time, from top to bottom. // // q is treated to (the transpose of) the same rotations and then a row // permutation, p, to shuffle row 1 down to row j. // q = [1 | 0 0 0 0 0 [# # # # # # [* * * * * * // --|---------- ----------- ----------- // 0 | x x x x x g' * * * * * * p * * * * * * // 0 | x x x x x ---> * * * * * * ---> # # # # # # // 0 | x x x x x * * * * * * * * * * * * // 0 | x x x x x * * * * * * * * * * * * // 0 | x x x x x] * * * * * *] * * * * * *] for(size_t i = 1; i <= nt2::min(m,n); ++i) { BOOST_AUTO_TPL(p, nt2::cons(i, i+1)); nt2::tie(g,r1(p,i)) = nt2::planerot(r1(p,i)); r1(p,nt2::_(i+1, n)) = nt2::mtimes(g, r1(p,nt2::_(i+1, n))); q1(nt2::_,p) = nt2::mtimes(q1(nt2::_,p), nt2::ct(g)); } // this permutes row 1 of q*r to row j of q(p,:)*r if (j != 1) { BOOST_AUTO_TPL(p, nt2::cath(nt2::cath(nt2::_(size_t(2), j), size_t(1)), nt2::_(j+1, m+1))); table<value_t> qq = q1(p,nt2::_); q1 = qq; } } }
QList<char> start(QVector<double> params) { return r1.productionRules({params[0] + 3,0 }) + r2.productionRules({params[0] + 2,0}) + r3.productionRules({params[0] + 3, 0}) + T1().symbol({0,0}) + T2().symbol({0,0}); }