#include // class for 1 linear form // just copy a array // Warning this class are use at compilating time // ---------------------------------------------- using Fem2D::operatortype; using Fem2D::op_id; using Fem2D::op_dx; using Fem2D::op_dy; using Fem2D::op_dz; using Fem2D::last_operatortype; template inline T * NewCopy(const T * const o,int n) { int m=n; T * c = new T [n]; for (int i=0;i inline T * NewCopy(const T * const o,int n,int m) { throwassert(m<=n); T * c = new T [n]; for (int i=0;i struct triplet { typedef T1 first_type; typedef T2 second_type; typedef T3 third_type; T1 first; T2 second; T3 third; triplet() : first(),second(),third() {} triplet(const T1& x, const T2& y, const T3& z) : first(x),second(y), third(z) {} template inline triplet(const triplet& p) : first(p.first),second(p.second),third(p.third) {} }; template inline triplet make_triplet(T1 x, T2 y, T3 z) { return triplet(x, y, z); } template class LinearComb : public E_F0mps { public: typedef I TI; typedef R TR; typedef size_t size_type; typedef pair K; typedef vector array; typedef typename array::const_iterator const_iterator; typedef typename array::iterator iterator; array v; vector where_in_stack_opt; vector mesh_indep_stack_opt; const E_F0_Optimize * optiexp0,*optiexpK; bool isoptimize; LinearComb(): v(), where_in_stack_opt(),mesh_indep_stack_opt(), optiexp0(nullptr),optiexpK(nullptr),isoptimize(false) {} LinearComb(const I& i,const R& r) :v(1), where_in_stack_opt(),mesh_indep_stack_opt(), optiexp0(nullptr),optiexpK(nullptr),isoptimize(false) { v[0]=make_pair((I)i,(R)r); } LinearComb(const LinearComb &l) :v(l.v), where_in_stack_opt(l.where_in_stack_opt), mesh_indep_stack_opt(l.mesh_indep_stack_opt), optiexp0(l.optiexp0),optiexpK(l.optiexpK),isoptimize(false){} int nbtrue(bool *ok) const { int k=0; for (size_t i=0;i &l) { v=l.v; where_in_stack_opt=l.where_in_stack_opt; mesh_indep_stack_opt=l.mesh_indep_stack_opt; optiexp0=l.optiexp0; optiexpK=l.optiexpK; isoptimize=l.isoptimize; } const I * simple() const { if (v.size()==1) return & v.begin()->first;else return nullptr;} void add(const I& i,const R &r) { for (iterator k=v.begin();k!=v.end();k++) if (k->first == i) {k->second += r;return ;} v.push_back(make_pair((I)i,(R)r)); } size_type size() const { return v.size();} const K & operator[](size_type i) const { return v[i];} void operator+=(const LinearComb & l) { for (const_iterator k=l.v.begin();k!=l.v.end();k++) { const K & kk(*k); add(kk.first,kk.second);} } void operator*=(const R & r) { for (iterator k=v.begin();k!=v.end();k++) {K & kk(*k); kk.second = kk.second*r;} } void operator/=(const R & r) { for (iterator k=v.begin();k!=v.end();k++) {K & kk(*k); kk.second = kk.second/r; } } AnyType operator()(Stack ) const { return SetAny * >(this);} operator aType () const { return atype();} bool mappable(bool (*f)(const R &)) const { for (const_iterator k=v.begin();k!=v.end();k++) if (!(*f)(k->second)) return false; return true;} void mapping(R (*f)(const R &)) { for (iterator k=v.begin();k!=v.end();k++) k->second=(*f)(k->second) ;} int MaxOp() const { int m=0; for (const_iterator k=v.begin();k!=v.end();k++) m= maxop(m,(k->first)) ; return m;} void DiffOp(KN_ &d) const { assert(d.N() >= last_operatortype); d=false; for (const_iterator k=v.begin();k!=v.end();k++) SetOp(d,k->first); } unsigned int DiffOp(int & lastop) const { unsigned int d=0; lastop=0; for (const_iterator k=v.begin();k!=v.end();k++) d |= GetDiffOp(k->first,lastop); assert(lastop > ll; MapOfE_F0 m; rr.where_in_stack_opt.resize(n); rr.mesh_indep_stack_opt.resize(n); size_type top = b->OffSet(0), topbb=top; // FH. bofbof ??? for (int i=0; iMeshIndependent(); rr.where_in_stack_opt[i]=ee->Optimize(ll, m, top); if (kdump) cout << "\n\t\t"<< i << " " << ri.first << ": " << rr.where_in_stack_opt[i] << endl; } b->OffSet(top-topbb); // int k=ll.size(),k0=0,k1=0; for (int i=0;iMeshIndependent()) k0++; deque > l0(k0),l1(k-k0); k0=0,k1=0; for (int i=0;iMeshIndependent()) { if (kdump) cout << " mi " << ll[i].second << " " << *(ll[i].first) << endl; l0[k0++]=ll[i]; } else { if (kdump) cout << " md " << ll[i].second << " " << *(ll[i].first) << endl; l1[k1++]=ll[i]; } if (k0) rr.optiexp0 = new E_F0_Optimize(l0,m,0); if (k1) rr.optiexpK = new E_F0_Optimize(l1,m,0); rr.isoptimize=true; if (kdump) cout << "LinearCom Optimize k0(mi) = " << k0 << " k1 = " << k1 << "\n\n"< LinearComb operator+(const LinearComb & a,const LinearComb & b) {LinearComb r(a);r+=b;return r;} template LinearComb operator*(const LinearComb & a,const R & b) {LinearComb r(a);r*=b;return r;} template LinearComb operator*(const R & b,const LinearComb & a) {LinearComb r(a);r*=b;return r;} class MGauche :public pair {public: MGauche() {} MGauche(int i,operatortype j) {first = i;second= j;} MGauche(const pair &p) : pair(p){} bool operator==(const MGauche& a) const { return static_cast(first == a.first && second == a.second);} int maxop(int op) const { return Max(op,(int) second);} }; class MDroit :public pair {public: MDroit(){} MDroit(int i,operatortype j) {first = i;second =j;} // first : number of unknow // second : number of operator ( 0 Id, 1 dx, 2 dy) MDroit(const pair &p) : pair(p){} bool operator==(const MDroit& a) const { return static_cast(first == a.first && second == a.second);} }; inline ostream & operator<<(ostream & f,const MDroit & p) { f << p.first <<','< inline ostream & operator<<(ostream & f,const pair &p) { f << p.first <<" "< LinearOperatorG; typedef LinearComb LinearOperatorD; typedef LinearComb,C_F0> BilinearOperator; inline int maxop(int op,const MGauche & v) { return Max(op,(int) v.second);} inline int maxop(int op,const MDroit & v) { return Max(op,(int) v.second);} inline int maxop(int op,const pair & b) { return Max(op,(int) b.first.second,(int) b.second.second );} // Add J. Morice :: 07/22 inline void changeIndexFunctionInconnue( BilinearOperator &Op, const KN &index_operator, const KN &new_index_funct){ // function to change the index of inconnue function in a BilinearOperator // first.first ==> the inconnue function ffassert( index_operator.size() == new_index_funct.size() ); // check the size of the vector int N = index_operator.size(); for( int j=0; j &index_operator, const KN &new_index_funct){ // function to change the index of test function in a BilinearOperator // first.second ==> the test function ffassert( index_operator.size() == new_index_funct.size() ); // check the size of the vector int N = index_operator.size(); for( int j=0; j,pair > i1(vi.first); const pair ii(i1.first),jj(i1.second); f << *(const E_F0 *) vi.second << char('u'+ii.first) << www[ii.second] << " " << char('u'+jj.first)<<"'" << www[jj.second] ; if ( (++k%5)==0) f << endl ; else f << " "; } return f; } typedef LinearOperatorD LOperaD; typedef LinearOperatorG LOperaG; typedef BilinearOperator Opera; inline LOperaG DiffG(int i,operatortype j) { return LOperaG(make_pair(i,j),*pOne);} inline LOperaD DiffD(int i,operatortype j) { return LOperaD(make_pair(i,j),*pOne);} inline LOperaG *newU_(int i) { LOperaG * r; r= new LOperaG(make_pair(i,op_id),*pOne); SHOWVERB( cout << "newU_ " << r << endl); return r; } inline LOperaG *newU_x(int i) { return new LOperaG(make_pair(i,op_dx),*pOne);} inline LOperaG *newU_y(int i) { return new LOperaG(make_pair(i,op_dy),*pOne);} inline LOperaD *newV_(int i) { return new LOperaD(make_pair(i,op_id),*pOne);} inline LOperaD *newV_x(int i) { return new LOperaD(make_pair(i,op_dx),*pOne);} inline LOperaD *newV_y(int i) { return new LOperaD(make_pair(i,op_dy),*pOne);} template L * Diff(const L * u,const operatortype & d) { throwassert(u); L * r= new L(*u); for (typename L::iterator i=r->v.begin();i!=r->v.end();i++) { operatortype & dd=i->first.second; if (dd != op_id) { ffassert(0); i->first.second = op_id; } // a faire else { ffassert(i->second.EvaluableWithOutStack());// a faire derivation des fonctions dd = d ; } } return r;} template L * CONJ_op(const L * u) { throwassert(u); L * r= new L(*u); for (typename L::iterator i=r->v.begin();i!=r->v.end();i++) { typename L::TR & cc=i->second; if( cc.right()==atype() ) i->second= C_F0(TheOperators,"\'",cc); } return r;} template int MaxOp(const L * u) { throwassert(u); int op=0; for (typename L::const_iterator i=u->v.begin();i!=u->v.end();i++) op = maxop(op,i->first); return op;} template class CODE_L1 { public: typedef L* Result; typedef L* (*func)(const basicAC_F0 & args) ; static L* f(const basicAC_F0 & args) { return ff(args);} // ff :A-> L* static ArrayOfaType typeargs() {return ArrayOfaType(atype);} }; template class CODE_L_Add { public: typedef const L* Result; static E_F0 * f(const basicAC_F0 & args) { const L * a(dynamic_cast((Expression) args[0])); const L * b(dynamic_cast((Expression) args[1])); throwassert(a && b ); return new L(*a+*b);} static ArrayOfaType typeargs() {return ArrayOfaType(atype(),atype());} }; template class CODE_L_Sub { public: typedef const L* Result; static E_F0 * f(const basicAC_F0 & args) { const L * a(dynamic_cast((Expression) args[0])); const L * b(dynamic_cast((Expression) args[1])); throwassert(a && b ); L * bb = new L(*pminusOne * *b); return new L(*a+*bb);} static ArrayOfaType typeargs() {return ArrayOfaType(atype(),atype());} }; template class CODE_L_Minus { public: typedef const L* Result; static E_F0 * f(const basicAC_F0 & args) { const L * a(dynamic_cast((Expression) args[0])); throwassert(a && pminusOne ); return new L(*pminusOne * *a);} static ArrayOfaType typeargs() {return ArrayOfaType(atype());} }; template class CODE_L_Plus { public: typedef const L* Result; static E_F0 * f(const basicAC_F0 & args) { const L * a(dynamic_cast((Expression) args[0])); throwassert(a ); return new L( *a);} static ArrayOfaType typeargs() {return ArrayOfaType(atype());} }; template class CODE_L_Mul { public: typedef const L* Result; static E_F0 * f(const basicAC_F0 & args) { const A * a(dynamic_cast((Expression) args[0])); const B * b(dynamic_cast((Expression) args[1])); SHOWVERB(cout << " CODE_L_Mul " << a << " " << b << endl); throwassert(a && b ); return new L(*a * *b);} static ArrayOfaType typeargs() {return ArrayOfaType(atype(),atype());} }; template class CODE_L_MulRL { public: typedef const L* Result; static E_F0 * f(const basicAC_F0 & args) { const L * b(dynamic_cast((Expression) args[1])); if (!b) { cout << " --- " << ((Expression) args[1]) << typeid((Expression) args[1]).name() << endl; throwassert( b ); } return new L(to(args[0]) * *b);} static ArrayOfaType typeargs() {return ArrayOfaType(atype(),atype());} }; template class CODE_L_MulLR { public: typedef const L* Result; static E_F0 * f(const basicAC_F0 & args) { const L * a(dynamic_cast((Expression) args[0])); throwassert( a ); return new L(to(args[1]) * *a);} static ArrayOfaType typeargs() {return ArrayOfaType(atype(),atype());} }; template class CODE_L_DivLR { public: typedef const L* Result; static E_F0 * f(const basicAC_F0 & args) { const L * a(dynamic_cast((Expression) args[0])); throwassert( a ); return new L(C_F0(TheOperators,"/",*pOne,args[1]) * *a);} static ArrayOfaType typeargs() {return ArrayOfaType(atype(),atype());} }; template class CODE_Diff { public: typedef const L* Result; static E_F0 * f(const basicAC_F0 & args) { const L * a=dynamic_cast((Expression) args[0]) ; throwassert( a ); return Diff(a,op);} static ArrayOfaType typeargs() {return ArrayOfaType(atype());} }; template class CODE_conj { public: typedef const L* Result; static E_F0 * f(const basicAC_F0 & args) { const L * a=dynamic_cast((Expression) args[0]) ; throwassert( a ); return CONJ_op(a);} static ArrayOfaType typeargs() {return ArrayOfaType(atype());} }; enum TheCode_VF { Code_Jump=1, Code_Mean=2, Code_OtherSide=3}; template class Code_VF { public: typedef const L* Result; static E_F0 * f(const basicAC_F0 & args) { const L * u=dynamic_cast((Expression) args[0]) ; assert( u ); L * r= new L(*u); for (typename L::iterator i=r->v.begin();i!=r->v.end();i++) { operatortype & dd=i->first.second; assert(dd());} };