forked from FreeFem/FreeFem-sources
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproblem.hpp
1399 lines (1183 loc) · 50.5 KB
/
problem.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// -*- Mode : c++ -*-
//
// SUMMARY :
// USAGE :
// ORG :
// AUTHOR : Frederic Hecht
// E-MAIL : hecht@ann.jussieu.fr
//
/*
This file is part of Freefem++
Freefem++ is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
Freefem++ is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with Freefem++; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef PROBLEM_HPP_
#define PROBLEM_HPP_
extern Block *currentblock;
template<class K> class Matrice_Creuse;
template<class K> class MatriceCreuse;
namespace Fem2D {
template<class K> class SolveGCPrecon;
template<class K> class SolveGMRESPrecon;
template<class K> class SolveGMRESDiag;
// int IsoLineK(double *f,R2 *Q,double eps);
}
#include "P1IsoValue.hpp"
template<class K> class SolveGCDiag;
class Plot;
class v_fes; // [[file:lgfem.hpp::v_fes]]
// real [[file:lgfem.hpp::FEbase]] using [[file:lgfem.hpp::v_fes]]
typedef FEbase<double,v_fes> * pferbase ; // <<pferbase>>
typedef FEbaseArray<double,v_fes> * pferbasearray ; // <<pferbasearray>>
typedef pair<pferbase,int> pfer ; // <<pfer>>
typedef pair<pferbasearray,int> pferarray ; // <<pferarray>>
// complex [[file:lgfem.hpp::FEbase]] using [[file:lgfem.hpp::v_fes]]
typedef FEbase<Complex,v_fes> * pfecbase ; // <<pfecbase>>
typedef FEbaseArray<Complex,v_fes> * pfecbasearray ; // <<pfecbasearray>>
typedef pair<pfecbase,int> pfec ; // <<pfec>>
typedef pair<pfecbasearray,int> pfecarray ; // <<pfecarray>>
//typedef pair<pmesh *,int> pmesharray ;
typedef LinearComb<MGauche,C_F0> Finconnue;
typedef LinearComb<MDroit,C_F0> Ftest;
typedef LinearComb<pair<MGauche,MDroit>,C_F0> Foperator;
inline int intOp(const MGauche &i) {return i.second;}
inline int intOp(const MDroit &i) {return i.second;}
inline int intOp(pair<MGauche,MDroit> & p) {return Max(intOp(p.first),intOp(p.second));}
inline void SetOp(KN_<bool> & d,const MGauche &i)
{ d[i.second% last_operatortype]=true;}
inline void SetOp(KN_<bool> & d,const MDroit &i)
{ d[(int) i.second % last_operatortype]=true;}
inline void SetOp(KN_<bool> & d,const pair<MGauche,MDroit> & p)
{SetOp(d,p.first);SetOp(d,p.second);}
inline unsigned int GetDiffOp(const MGauche &i, int& lastop)
{int op=(i.second% last_operatortype);
lastop=max(lastop,op) ;
return 1<<op;}
inline unsigned int GetDiffOp(const MDroit &i, int& lastop)
{int op=(i.second% last_operatortype);
lastop=max(lastop,op) ;
return 1<<op;}
inline unsigned int GetDiffOp(const pair<MGauche,MDroit> &p, int& lastop)
{ return GetDiffOp(p.first,lastop)|GetDiffOp(p.second,lastop);}
typedef const Finconnue finconnue;
typedef const Ftest ftest;
typedef const Foperator foperator;
Expression IsFebaseArray(Expression f);
void SetArgsFormLinear(const ListOfId *lid,int ordre);
inline ostream & operator<<(ostream & f,const TypeSolveMat & tm)
{
switch(tm.t) {
case TypeSolveMat::NONESQUARE: f << "No Square (Sparse Morse)"; break;
case TypeSolveMat::LU: f << "LU (Skyline)"; break;
case TypeSolveMat::CROUT: f << "CROUT (Skyline)"; break;
case TypeSolveMat::CHOLESKY: f << "CHOLESKY (Skyline)"; break;
case TypeSolveMat::GC: f << "CG (Sparse Morse)"; break;
case TypeSolveMat::GMRES: f << "GMRES (Sparse Morse)"; break;
case TypeSolveMat::SparseSolver: f << "SparseSolver (Sparse Morse)"; break;
default: f << "Unknown bug???";
}
return f;
}
class C_args: public E_F0mps {public:
typedef const C_args * Result;
list<C_F0> largs;
typedef list<C_F0> ::const_iterator const_iterator ;
// il faut expendre
C_args() :largs(){}
C_args(C_F0 c) : largs() { if(!c.Zero() )largs.push_back(c);}
C_args( const basicAC_F0 & args) :largs(){
int n=args.size();
for (int i=0;i< n;i++)
{
if(args[i].Zero()) ; // skip zero term ...
else if (args[i].left() == atype<const C_args *>())
{
const C_args * a = dynamic_cast<const C_args *>(args[i].LeftValue());
for (list<C_F0>::const_iterator i=a->largs.begin();i!=a->largs.end();i++)
if( ! i->Zero()) // skip Zero term
largs.push_back(*i);
}
else
largs.push_back(args[i]);
};}
static ArrayOfaType typeargs() { return ArrayOfaType(true);}
AnyType operator()(Stack ) const { return SetAny<const C_args *>(this);}
operator aType () const { return atype<const C_args *>();}
static E_F0 * f(const basicAC_F0 & args) { return new C_args(args);}
bool Zero() const { return largs.empty();} // BIG WARNING April and wrong functon FH v 3.60 .......
bool IsLinearOperator() const;
bool IsBilinearOperator() const;
};
class C_args_minus: public C_args {public:
C_args_minus( const basicAC_F0 & args) {
int n=args.size();
ffassert(n==2);
if (args[0].left() == atype<const C_args *>())
{
const C_args * a = dynamic_cast<const C_args *>(args[0].LeftValue());
ffassert(a);
for (list<C_F0>::const_iterator i=a->largs.begin();i!=a->largs.end();i++)
largs.push_back(*i);
}
else
largs.push_back(args[0]);
largs.push_back(C_F0(TheOperators,"-",args[1]));
}
static ArrayOfaType typeargs() { return ArrayOfaType(atype<const C_args *>(),true);}
static E_F0 * f(const basicAC_F0 & args) { return new C_args_minus(args);}
};
bool isVF(const list<C_F0> & largs);
template<typename F>
class Minus_Form: public E_F0mps {public:
typedef const F * Result;
static ArrayOfaType typeargs() { return ArrayOfaType(atype<const F *>());}
static E_F0 * f(const basicAC_F0 & args) {
int n=args.size();
ffassert(n==1);
aType tF=atype<Result>();
ffassert(args[0].left() == tF);
Result f = dynamic_cast<Result>(args[0].LeftValue());
ffassert(f);
// F mf = -*f;
F * rf=new F(-*f);
return rf;
}
operator aType () const { return atype<Result>();}
};
//template<class RR=double>
class BC_set : public E_F0mps { public:
bool complextype;
typedef const BC_set* Result;
vector<Expression> on;
vector<int> onis;
vector<pair<int,Expression> > bc; // n¡ de l'inconnue+ valeur
BC_set( const basicAC_F0 & args)
:on(args.size()),onis(args.size())
{
int n = args.size();
ffassert(args.named_parameter);
AC_F0::const_iterator ii=args.named_parameter->begin();
AC_F0::const_iterator ie=args.named_parameter->end();
bc.resize(args.named_parameter->size());
complextype=false;
for (int kk=0;ii!=ie;kk++,ii++)
{
if( ! BCastTo<double>(ii->second))
complextype = true;
}
ii=args.named_parameter->begin();
for (int kk=0;ii!=ie;kk++,ii++)
{ //
C_F0 x=Find(ii->first);
if (x.left() != atype<const finconnue *>())
CompileError("We expected an unkown u=... of the problem");
const finconnue * uu = dynamic_cast<const finconnue *>(x.LeftValue());
ffassert(uu);
const MGauche *ui=uu->simple();
ffassert(ui && ui->second == op_id);
if(verbosity>9)
cout << " on : " << ii->first << " n " << ui->first << " = ? " << endl;
if (complextype)
bc[kk]= make_pair(ui->first,CastTo<Complex>(ii->second));
else
bc[kk]= make_pair(ui->first,CastTo<double>(ii->second));
//ii->second;
}
// sort bc / num de composante
std::sort(bc.begin(),bc.end());
if(verbosity>9)
for (vector<pair<int,Expression> >::iterator i=bc.begin(); i !=bc.end();++i)
cout <<" on " << i->first << " " << i->second << endl;
for (int i=0;i<n;i++)
if( ! BCastTo<KN_<long> >(args[i]))
{
on[i]=CastTo<long>(args[i]);
onis[i]=0;
}
else
{
on[i]=CastTo<KN_<long> >(args[i]);
onis[i]=1;
}
}
template<class K>
void CastToK()
{
aType rr = complextype ? atype<Complex>() : atype<double>();
if (rr == atype<Complex>()) complextype= true;
if(verbosity > 10) cout << " CastToK => " << complextype <<endl;
for ( vector<pair<int,Expression> >::iterator k=bc.begin();k!=bc.end();k++)
k->second=CastTo<K>(C_F0(k->second,rr)) ;
}
/* De
// ajout modif FH mai 2007 XXXXXXXXXXXXX....
void mappingC(C_F0 (*f)(const C_F0 &)) {
for ( vector<pair<int,Expression> >::iterator k=bc.begin();k!=bc.end();k++)
k->second=CastTo<Complex>(C_F0(k->second,rr)) ;}
// fin ajout
*/
static ArrayOfaType typeargs() { return ArrayOfaType(/*atype<long>(),*/true);} // change frev 2011 FH...
AnyType operator()(Stack ) const { return SetAny<Result>(this);}
operator aType () const { return atype<Result>();}
static E_F0 * f(const basicAC_F0 & args) { return new BC_set(args);}
// void init(Stack stack) const {}
};
class CDomainOfIntegration: public E_F0mps {
public:
static const int n_name_param =12;
static basicAC_F0::name_and_type name_param[] ;
Expression nargs[n_name_param];
enum typeofkind { int2d=0, int1d=1, intalledges=2,intallVFedges=3, int3d = 4, intallfaces= 5,intallVFfaces=6 } ; //3d
typeofkind kind; // 0
int d; // 3d
typedef const CDomainOfIntegration* Result;
Expression Th;
Expression mapt[3],mapu[3];
vector<Expression> what;
vector<int> whatis; // 0 -> long , 1 -> array ???
CDomainOfIntegration( const basicAC_F0 & args,typeofkind b=int2d,int ddim=2) // 3d
:kind(b),d(ddim), Th(0), what(args.size()-1),whatis(args.size()-1)
{
mapt[0]=mapt[1]=mapt[2]=0; // no map of intergration points for test function
mapu[0]=mapu[1]=mapu[2]=0; // no map of intergration points for unknows function
args.SetNameParam(n_name_param,name_param,nargs);
if(d==2) // 3d
Th=CastTo<pmesh>(args[0]);
else if(d==3)
Th=CastTo<pmesh3>(args[0]);
else ffassert(0); // a faire
int n=args.size();
for (int i=1;i<n;i++)
if(!BCastTo<KN_<long> >(args[i]) )
{
whatis[i-1]=0;
what[i-1]=CastTo<long>(args[i]);
}
else
{
whatis[i-1]=1;
what[i-1]=CastTo<KN_<long> >(args[i]);
}
const E_Array *pmapt = dynamic_cast<E_Array *>(nargs[10]);
const E_Array *pmapu = dynamic_cast<E_Array *>(nargs[11]);
if(pmapt )
{
if( pmapt->size() != d ) ErrorCompile("mapt bad arry size ",1);
for(int i=0; i<d; ++i)
mapt[i]=CastTo<double >((*pmapt)[i]);
}
if(pmapu )
{
if( pmapu->size() != d ) ErrorCompile("mapu bad arry size ",1);
for(int i=0; i<d; ++i)
mapu[i]=CastTo<double >((*pmapu)[i]);
}
// cout << " CDomainOfIntegration " << this << endl;
}
static ArrayOfaType typeargs() { return ArrayOfaType(atype<pmesh>(), true);} // all type
AnyType operator()(Stack ) const { return SetAny<const CDomainOfIntegration *>(this);}
operator aType () const { return atype<const CDomainOfIntegration *>();}
static E_F0 * f(const basicAC_F0 & args) { return new CDomainOfIntegration(args);}
const Fem2D::QuadratureFormular & FIT(Stack) const ;
const Fem2D::QuadratureFormular1d & FIE(Stack) const ;
const Fem2D::GQuadratureFormular<R3> & FIV(Stack) const ; // 3d
long UseOpt(Stack s) const { return nargs[5] ? GetAny<long>( (*(nargs[5]))(s) ) : 1;}
double binside(Stack s) const { return nargs[6] ? GetAny<double>( (*(nargs[6]))(s) ) : 0;} // truc pour FH
bool intmortar(Stack s) const { return nargs[7] ? GetAny<bool>( (*(nargs[7])) (s) ) : 1;} // truc pour
double levelset(Stack s) const { return nargs[9] ? GetAny<double>( (*(nargs[9]))(s) ) : 0;}
bool islevelset() const { return nargs[9] != 0; }
bool withmap() const {return mapu[0] || mapt[0]; }
};
class CDomainOfIntegrationBorder: public CDomainOfIntegration {
public:
CDomainOfIntegrationBorder( const basicAC_F0 & args) :CDomainOfIntegration(args,int1d) {}
static E_F0 * f(const basicAC_F0 & args) { return new CDomainOfIntegration(args,int1d);}
};
class CDomainOfIntegrationAllEdges: public CDomainOfIntegration {
public:
CDomainOfIntegrationAllEdges( const basicAC_F0 & args) :CDomainOfIntegration(args,intalledges) {}
static E_F0 * f(const basicAC_F0 & args) { return new CDomainOfIntegration(args,intalledges);}
};
class CDomainOfIntegrationVFEdges: public CDomainOfIntegration {
public:
CDomainOfIntegrationVFEdges( const basicAC_F0 & args) :CDomainOfIntegration(args,intallVFedges) {}
static E_F0 * f(const basicAC_F0 & args) { return new CDomainOfIntegration(args,intallVFedges);}
};
// add for the 3d case .. // 3d
class CDomainOfIntegration3d: public CDomainOfIntegration {
public:
CDomainOfIntegration3d( const basicAC_F0 & args) :CDomainOfIntegration(args,int3d,3) {}
static E_F0 * f(const basicAC_F0 & args) { return new CDomainOfIntegration(args,int3d,3);}
static ArrayOfaType typeargs() { return ArrayOfaType(atype<pmesh3>(), true);} // all type
};
class CDomainOfIntegrationBorder3d: public CDomainOfIntegration {
public:
CDomainOfIntegrationBorder3d( const basicAC_F0 & args) :CDomainOfIntegration(args,int2d,3) {}
static E_F0 * f(const basicAC_F0 & args) { return new CDomainOfIntegration(args,int2d,3);}
static ArrayOfaType typeargs() { return ArrayOfaType(atype<pmesh3>(), true);} // all type
};
class CDomainOfIntegrationAllFaces: public CDomainOfIntegration {
public:
CDomainOfIntegrationAllFaces( const basicAC_F0 & args) :CDomainOfIntegration(args,intallfaces,3) {}
static E_F0 * f(const basicAC_F0 & args) { return new CDomainOfIntegration(args,intallfaces,3);}
static ArrayOfaType typeargs() { return ArrayOfaType(atype<pmesh3>(), true);} // all type
};
// end add
// hack build template
template<class T> struct CadnaType{
typedef T Scalaire;
};
#ifdef HAVE_CADNA
#include <cadnafree.h>
// specialisation
template<> struct CadnaType<complex<double> >{
typedef complex<double_st> Scalaire;
};
template<> struct CadnaType<double> {
typedef double_st Scalaire;
};
inline double_st conj(const double_st &x){ return x;};
inline complex<double_st> conj(const complex<double_st> &x){ return complex<double_st>(x.real(),-x.imag());}
inline double norm(complex<double_st> x){return x.real()*x.real()+x.imag()*x.imag();}
inline double norm(double_st x){return x*x;}
inline int cestac(const complex<double_st> & z)
{return min(cestac(z.real()),cestac(z.imag()));}
#endif
class Problem : public Polymorphic {
// typedef double R;
static basicAC_F0::name_and_type name_param[] ;
static const int n_name_param =3+NB_NAME_PARM_MAT; // modi FH oct 2005 add tol_pivot 02/ 2007 add nbiter
int Nitem,Mitem;
const int dim;
public:
template<class FESpace>
struct Data {
typedef typename FESpace::Mesh Mesh;
const Mesh * pTh;
CountPointer<const FESpace> Uh;
CountPointer<const FESpace> Vh;
CountPointer<MatriceCreuse<double> > AR;
CountPointer<MatriceCreuse<Complex> > AC;
typedef CadnaType<double>::Scalaire double_st;
typedef CadnaType<complex<double> >::Scalaire cmplx_st;
MatriceCreuse<double_st> * AcadnaR;
MatriceCreuse<cmplx_st> * AcadnaC;
void init() {pTh=0; AcadnaR=0;AcadnaC=0; Uh.init(),Vh.init();AR.init();AC.init();}
void destroy() {
pTh=0;
Uh.destroy();
Vh.destroy();
AR.destroy();
AC.destroy();
if(AcadnaR) AcadnaR->destroy();
if(AcadnaC) AcadnaC->destroy();
}
} ;
const OneOperator *precon;
C_args *op; // the list of all operator
mutable vector<Expression> var; // list des var pour les solutions et test
bool complextype,VF;
// Expression noinit,type,epsilon;
Expression nargs[n_name_param];
const size_t offset;
Problem(const C_args * ca,const ListOfId &l,size_t & top) ;
static ArrayOfaType typeargs() { return ArrayOfaType(true);}// all type
Data<FESpace> * dataptr (Stack stack) const {return (Data<FESpace> *) (void *) (((char *) stack)+offset);}
Data<FESpace3> * dataptr3 (Stack stack) const {return (Data<FESpace3> *) (void *) (((char *) stack)+offset);}
void init(Stack stack) const {
// cout << " init " << (char *) dataptr(stack) - (char*) stack << " " << offset << endl;
if(dim==2)
dataptr(stack)->init();
else
dataptr3(stack)->init();
}
void destroy(Stack stack) const {
if(dim==2) dataptr(stack)->destroy();
else dataptr3(stack)->destroy();
}
template<class R,class FESpace,class v_fes>
AnyType eval(Stack stack,Data<FESpace> * data,CountPointer<MatriceCreuse<R> > & dataA,
MatriceCreuse< typename CadnaType<R>::Scalaire > * & dataCadna) const;
AnyType operator()(Stack stack) const
{
if(dim==2)
{
Data<FESpace> *data= dataptr(stack);
if (complextype)
return eval<Complex,FESpace,v_fes>(stack,data,data->AC,data->AcadnaC);
else
return eval<double,FESpace,v_fes>(stack,data,data->AR,data->AcadnaR);
}
else if(dim==3)
{
Data<FESpace3> *data= dataptr3(stack);
if (complextype)
return eval<Complex,FESpace3,v_fes3>(stack,data,data->AC,data->AcadnaC);
else
return eval<double,FESpace3,v_fes3>(stack,data,data->AR,data->AcadnaR);
}
else ffassert(0);
}
bool Empty() const {return false;}
size_t nbitem() const { return Nitem;}
};
class Solve : public Problem { public:
// just a problem with implicit solve
Solve(const C_args * ca,const ListOfId &l,size_t & top)
: Problem(new C_args(*ca),l,top) {}
};
class FormBilinear : public E_F0mps { public:
typedef const FormBilinear* Result;
typedef const CDomainOfIntegration * A;
typedef const foperator * B;
A di;
Foperator * b;
FormBilinear(const basicAC_F0 & args) {
di= dynamic_cast<A>(CastTo<A>(args[0]));
B bb= dynamic_cast<B>(CastTo<B>(args[1]));
// b = bb->Optimize(currentblock); // FH1004
b=new Foperator(*bb); // FH1004 no optimisation here because we don't the type of the bilinear form here.
// the opimisation is done after in FieldOfForm routine
// to find if the form is real or complex
// delete bb; il ne faut pas detruire .. car bb peut etre dans une variable
ffassert(di && b); }
static ArrayOfaType typeargs() { return ArrayOfaType(atype<A>(),atype<B>());}// all type
AnyType operator()(Stack ) const { return SetAny<Result>(this);}
operator aType () const { return atype<Result>();}
static E_F0 * f(const basicAC_F0 & args) { return new FormBilinear(args);}
FormBilinear(A a,Expression bb) : di(a),b(new Foperator(*dynamic_cast<B>(bb))/*->Optimize(currentblock) FH1004 */)
{ffassert(b);}
FormBilinear operator-() const { return FormBilinear(di,C_F0(TheOperators,"-",C_F0(b,atype<B>())));}
bool VF() const { return MaxOp(b) >= last_operatortype;}
int dim() const {return di->d;}
FormBilinear(const FormBilinear & fb) : di(fb.di),b(new Foperator(*fb.b) ) {}
// void init(Stack stack) const {}
};
//template<class v_fes>
class FormLinear : public E_F0mps { public:
typedef const FormLinear* Result;
typedef const CDomainOfIntegration * A;
typedef const ftest * B;
A di;
Ftest * l;
FormLinear(const basicAC_F0 & args) {
di= dynamic_cast<A>(CastTo<A>(args[0]));
assert(di);
Expression a1=CastTo<B>(args[1]);
assert(a1);
// cout << " ---FormLinear: "<< a1 << " " << typeid(*a1).name() << *a1 <<endl;
B ll= dynamic_cast<B>(a1);
assert(ll);
l = new Ftest(*ll); // FH1004 ->Optimize(currentblock); same as bilinear
// delete ll; // il ne faut pas detruire car ll peut etre dans une variable
assert(l);
ffassert(di && l);
}
bool VF() const { return MaxOp(l) >= last_operatortype;}
static ArrayOfaType typeargs() { return ArrayOfaType(atype<A>(),atype<B>());}// all type
AnyType operator()(Stack ) const { return SetAny<Result>(this);}
operator aType () const { return atype<Result>();}
int dim() const {return di->d;}
static E_F0 * f(const basicAC_F0 & args) { return new FormLinear(args);}
FormLinear(A a,Expression bb) : di(a),l(new Ftest(*dynamic_cast<B>(bb))/*->Optimize(currentblock) FH1004 */) {ffassert(l);}
FormLinear operator-() const { return FormLinear(di,C_F0(TheOperators,"-",C_F0(l,atype<B>())));}
// void init(Stack stack) const {}
FormLinear(const FormLinear & fb) : di(fb.di),l(new Ftest(*fb.l) ) {}
};
template<class VFES>
class Call_FormLinear: public E_F0mps
{
public:
const int d;
list<C_F0> largs;
Expression *nargs;
typedef list<C_F0>::const_iterator const_iterator;
const int N;
Expression ppfes;
Call_FormLinear(int dd,Expression * na,Expression LL, Expression ft) ;
AnyType operator()(Stack stack) const
{ InternalError(" bug: no eval of Call_FormLinear ");}
operator aType () const { return atype<void>();}
};
template<class VFES>
class Call_FormBilinear: public E_F0mps
{
public:
const int d;
Expression *nargs;
list<C_F0> largs;
typedef list<C_F0>::const_iterator const_iterator;
const int N,M;
Expression euh,evh;
Call_FormBilinear(int dd,Expression * na,Expression LL, Expression fi,Expression fj) ;
AnyType operator()(Stack stack) const
{ InternalError(" bug: no eval of Call_FormBilinear ");}
operator aType () const { return atype<void>();}
};
struct OpCall_FormLinear_np {
static basicAC_F0::name_and_type name_param[] ;
static const int n_name_param =1;
};
struct OpCall_FormBilinear_np {
static basicAC_F0::name_and_type name_param[] ;
static const int n_name_param =1+NB_NAME_PARM_MAT; // 9-> 11 FH 31/10/2005 11->12 nbiter 02/2007 // 12->22 MUMPS+ Autre Solveur 02/08
};
template<class T,class v_fes>
struct OpCall_FormLinear
: public OneOperator,
public OpCall_FormLinear_np
{
typedef v_fes *pfes;
E_F0 * code(const basicAC_F0 & args) const
{
Expression * nargs = new Expression[n_name_param];
args.SetNameParam(n_name_param,name_param,nargs);
return new Call_FormLinear<v_fes>(v_fes::d,nargs,to<const C_args*>(args[0]),to<pfes*>(args[1]));}
OpCall_FormLinear() :
OneOperator(atype<const Call_FormLinear<v_fes>*>(),atype<const T*>(),atype<pfes*>()) {}
};
template<class T,class v_fes>
struct OpCall_FormLinear2
: public OneOperator,
public OpCall_FormLinear_np
{
static const int d=v_fes::d;
typedef v_fes *pfes;
E_F0 * code(const basicAC_F0 & args) const
{
Expression * nargs = new Expression[this->n_name_param];
args.SetNameParam(this->n_name_param,this->name_param,nargs);
Expression p=args[1];
if ( ! p->EvaluableWithOutStack() )
{ CompileError(" a(long,Vh) , The long must be a constant, and = 0, sorry");}
long pv = GetAny<long>((*p)(NullStack));
if ( pv )
{ CompileError(" a(long,Vh) , The long must be a constant == 0, sorry");}
return new Call_FormLinear<v_fes>(v_fes::d,nargs,to<const C_args*>(args[0]),to<pfes*>(args[2]));}
OpCall_FormLinear2() :
OneOperator(atype<const Call_FormLinear<v_fes>*>(),atype<const T*>(),atype<long>(),atype<pfes*>()) {}
};
template<class T,class v_fes>
struct OpCall_FormBilinear
: public OneOperator ,
OpCall_FormBilinear_np
{
typedef v_fes *pfes;
static const int d=v_fes::d;
E_F0 * code(const basicAC_F0 & args) const
{ Expression * nargs = new Expression[n_name_param];
args.SetNameParam(n_name_param,name_param,nargs);
// cout << " OpCall_FormBilinear " << *args[0].left() << " " << args[0].LeftValue() << endl;
return new Call_FormBilinear<v_fes>(v_fes::d,nargs,to<const C_args*>(args[0]),to<pfes*>(args[1]),to<pfes*>(args[2]));}
OpCall_FormBilinear() :
OneOperator(atype<const Call_FormBilinear<v_fes>*>(),atype<const T *>(),atype<pfes*>(),atype<pfes*>()) {}
};
bool FieldOfForm( list<C_F0> & largs ,bool complextype);
template<class A> struct IsComplexType { static const bool value=false;};
template<> struct IsComplexType<Complex> { static const bool value=true;};
template<class R,class v_fes> // to make x=linearform(x)
struct OpArraytoLinearForm
: public OneOperator
{
typedef typename Call_FormLinear<v_fes>::const_iterator const_iterator;
const bool isptr;
const bool init;
const bool zero;
class Op : public E_F0mps
{
public:
Call_FormLinear<v_fes> *l;
Expression x;
const bool isptr;
const bool init;
const bool zero;
AnyType operator()(Stack s) const ;
Op(Expression xx,Expression ll,bool isptrr,bool initt,bool zzero)
: l(new Call_FormLinear<v_fes>(*dynamic_cast<const Call_FormLinear<v_fes> *>(ll))),
x(xx),
isptr(isptrr),init(initt),zero(zzero)
{assert(l);
bool iscmplx=FieldOfForm(l->largs,IsComplexType<R>::value);
//cout<< "FieldOfForm:iscmplx " << iscmplx << " " << IsComplexType<R>::value << " " <<( (iscmplx) == IsComplexType<R>::value) << endl;
ffassert( (iscmplx) == IsComplexType<R>::value);
}
operator aType () const { return atype<KN<R> *>();}
};
E_F0 * code(const basicAC_F0 & args) const
{ if(isptr) return new Op(to<KN<R> *>(args[0]),args[1],isptr,init,zero);
else return new Op(to<KN_<R> >(args[0]),args[1],isptr,init,zero);}
// OpArraytoLinearForm(const basicForEachType * tt) :
// OneOperator(atype<KN_<R> >(),tt,atype<const Call_FormLinear*>()),init(false),isptr(false) {}
OpArraytoLinearForm(const basicForEachType * tt,bool isptrr, bool initt,bool zzero=1) :
OneOperator(atype<KN_<R> >(),tt,atype<const Call_FormLinear<v_fes>*>()),
isptr(isptrr), init(initt),zero(zzero) {}
};
template<class R,class v_fes> // to make A=linearform(x)
struct OpMatrixtoBilinearForm
: public OneOperator
{
typedef typename Call_FormBilinear<v_fes>::const_iterator const_iterator;
int init;
class Op : public E_F0mps {
public:
Call_FormBilinear<v_fes> *b;
Expression a;
int init;
AnyType operator()(Stack s) const ;
Op(Expression aa,Expression bb,int initt)
: b(new Call_FormBilinear<v_fes>(* dynamic_cast<const Call_FormBilinear<v_fes> *>(bb))),a(aa),init(initt)
{ assert(b && b->nargs);
bool iscmplx=FieldOfForm(b->largs,IsComplexType<R>::value) ;
// cout<< "FieldOfForm:iscmplx " << iscmplx << " " << IsComplexType<R>::value << " " << ((iscmplx) == IsComplexType<R>::value) << endl;
ffassert( (iscmplx) == IsComplexType<R>::value);
}
operator aType () const { return atype<Matrice_Creuse<R> *>();}
};
E_F0 * code(const basicAC_F0 & args) const
{ return new Op(to<Matrice_Creuse<R>*>(args[0]),args[1],init);}
OpMatrixtoBilinearForm(int initt=0) :
OneOperator(atype<Matrice_Creuse<R>*>(),atype<Matrice_Creuse<R>*>(),atype<const Call_FormBilinear<v_fes>*>()),
init(initt)
{}
};
template<class R>
class IntFunction : public E_F0mps { public:
typedef R Result;
typedef const CDomainOfIntegration * A;
typedef R B;
A di;
Expression fonc;
IntFunction(const basicAC_F0 & args) {
di= dynamic_cast<A>(CastTo<A>(args[0]));
fonc= CastTo<B>(args[1]);
ffassert(di && fonc); }
static ArrayOfaType typeargs() { return ArrayOfaType(atype<A>(),atype<B>());}// all type
AnyType operator()(Stack ) const;
static E_F0 * f(const basicAC_F0 & args) { return new IntFunction(args);}
// IntFunction(A a,Expression bb) : di(a),fonc(bb) {}
operator aType () const { return atype<Result>();}
};
extern Block *currentblock;
class TypeFormOperator: public ForEachType<const C_args*> {
public:
TypeFormOperator() : ForEachType<const C_args*>(0,0) {}
void SetArgs(const ListOfId *lid) const {
SetArgsFormLinear(lid,2); }
Type_Expr SetParam(const C_F0 & c,const ListOfId *l,size_t & top) const
{ return Type_Expr(this,CastTo(c));}
inline C_F0 Initialization(const Type_Expr & e) const {return C_F0();}
};
class TypeFormBilinear: public ForEachType<const FormBilinear*> {
public:
TypeFormBilinear() : ForEachType<const FormBilinear*>(0,0) {}
void SetArgs(const ListOfId *lid) const {
SetArgsFormLinear(lid,2);
}
Type_Expr SetParam(const C_F0 & c,const ListOfId *l,size_t & top) const
{ return Type_Expr(this,CastTo(c));}
C_F0 Initialization(const Type_Expr & e) const
{
// cout << "Initialization " << *e.first << endl;
return C_F0(); } // nothing to initialize
Type_Expr construct(const Type_Expr & e) const
{
//cout << "construct " << *e.first << endl;
return e; }
};
template<bool exec_init,class Problem>
class TypeSolve : public ForEachType<const Problem*> {
public:
TypeSolve() : ForEachType<const Problem*>(0,0) {}
void SetArgs(const ListOfId *lid) const {
SetArgsFormLinear(lid,2);
}
Type_Expr SetParam(const C_F0 & c,const ListOfId *l,size_t & top) const
{ if (c.left() != atype<const C_args*>())
CompileError(" Problem a(...) = invalid type ",c.left());
const C_args * ca = dynamic_cast<const C_args *>(c.LeftValue());
Problem * pb=new Problem(ca,*l,top);
SHOWVERB(cout << "solve:SetParam " << ca << " pb=" << pb << endl);
return Type_Expr(this,pb);
}
class SolveInit: public E_F0 { public:
const Problem * a;
AnyType operator()(Stack s) const {
a->init(s);
return exec_init ? (*a)(s) : Nothing ;
}
SolveInit(const Type_Expr & te) : a(dynamic_cast<const Problem *>(te.second))
{ SHOWVERB(cout << "SolveInit " << te.second << endl);
ffassert(a);}
};
class SolveDel: public E_F0 { public:
const Problem * a;
SolveDel(const C_F0 & c) : a(dynamic_cast<const Problem *>(c.LeftValue()))
{
SHOWVERB(cout << "SolveDel " << c.left() << endl);
ffassert(a);}
AnyType operator()(Stack s) const {
a->destroy(s);
return Nothing;
}};
Expression Destroy(const C_F0 & c) const
{ return new SolveDel(c);}
bool ExistDestroy() const {return true;}
C_F0 Initialization(const Type_Expr & e) const
{ return C_F0( new SolveInit(e) ,atype<void>()); }
};
class TypeFormLinear: public ForEachType<const FormLinear*> {
public:
TypeFormLinear() : ForEachType<const FormLinear*>(0,0) {}
void SetArgs(const ListOfId *lid) const {
SetArgsFormLinear(lid,1); }
Type_Expr SetParam(const C_F0 & c,const ListOfId *l,size_t & top) const
{ return Type_Expr(this,CastTo(c));}
// { return Type_Expr(c.left(),c.LeftValue()); } //
C_F0 Initialization(const Type_Expr & e) const
{ return C_F0(); } // nothing to initialize
};
template<class K> class Matrice_Creuse {
// CountPointer<FESpace> Uh,Vh;
//pfes *pUh,*pVh; // pointeur sur la variable stockant FESpace;
public:
UniqueffId Uh,Vh; // pour la reconstruction
// const void * pUh,pVh; // pointeur pour la reconstruction
CountPointer<MatriceCreuse<K> > A;
TypeSolveMat typemat;
size_t count;
void init() {
count=0;
A.init();Uh.init();Vh.init();
typemat=TypeSolveMat(TypeSolveMat::NONESQUARE);}
Matrice_Creuse() { init();}
void destroy() {// Correct Oct 2015 FH (avant test a 'envert) !!!!
if(count--==0)
A.destroy();
//else count--;
// Uh.destroy();
//Vh.destroy();
}
Matrice_Creuse( MatriceCreuse<K> * aa)//,const pfes *ppUh,const pfes *ppVh)
:A(aa){}//,pUh(ppUh),pVh(ppVh),Uh(*ppUh),Vh(*ppVh) {}
Matrice_Creuse( MatriceCreuse<K> * aa,const UniqueffId *pUh,const UniqueffId *pVh)//,const pfes *ppUh,const pfes *ppVh)
:A(aa),Uh(*pUh),Vh(*pVh) {}//,pUh(ppUh),pVh(ppVh),Uh(*ppUh),Vh(*ppVh) {}
long N() const {return A ? A->n : 0;}
long M() const { return A ? A->m : 0;}
void resize(int n,int m) { if(A) A->resize(n,m);}
void increment(){ count++;}
};
template<class K> class Matrice_Creuse_Transpose;
template<class KA,class KB> class Matrix_Prod { public:
Matrice_Creuse<KA> *A;
Matrice_Creuse<KB> *B;
bool ta,tb;
Matrix_Prod(Matrice_Creuse<KA> *AA,Matrice_Creuse<KB> *BB) : A(AA),B(BB),ta(false),tb(false) {assert(AA && BB);}
Matrix_Prod(Matrice_Creuse_Transpose<KA> AA,Matrice_Creuse<KB> *BB) : A(AA),B(BB),ta(true),tb(false) {assert(AA && BB);}
Matrix_Prod(Matrice_Creuse<KA> *AA,Matrice_Creuse_Transpose<KB> BB) : A(AA),B(BB),ta(false),tb(true) {assert(AA && BB);}
Matrix_Prod(Matrice_Creuse_Transpose<KA> AA,Matrice_Creuse_Transpose<KB> BB) : A(AA),B(BB),ta(true),tb(true) {assert(AA && BB);}
};
template<class K> ostream & operator << (ostream & f,const Matrice_Creuse<K> & A)
{ if ( !A.A) f << " unset sparse matrix " << endl;
else f << *A.A ;
return f; }
template<class K> istream & operator >> (istream & f,Matrice_Creuse<K> & A)
{
if ( WhichMatrix(f)== 2 )
{
// A.pUh=0;
//A.pVh=0;
A.A.master(new MatriceMorse<K>(f));
A.typemat=(A.A->n == A.A->m) ? TypeSolveMat(TypeSolveMat::GMRES) : TypeSolveMat(TypeSolveMat::NONESQUARE); // none square matrice (morse)
}
else {
cerr << " unkwon type of matrix " << endl;
ExecError("Erreur read matrix ");
A.A =0; }
return f; }
template<class K> class Matrice_Creuse_Transpose { public:
Matrice_Creuse<K> * A;
Matrice_Creuse_Transpose(Matrice_Creuse<K> * AA) : A(AA) {assert(A);}
operator MatriceCreuse<K> & () const {return *A->A;}
operator Matrice_Creuse<K> * () const {return A;}
};
template<class K> class Matrice_Creuse_inv { public:
Matrice_Creuse<K> * A;
Matrice_Creuse_inv(Matrice_Creuse<K> * AA) : A(AA) {assert(A);}
operator MatriceCreuse<K> & () const {return *A->A;}
operator Matrice_Creuse<K> * () const {return A;}
};
namespace Fem2D {
inline void F_Pi_h(R* v, const R2 & P,const baseFElement & K,int i,const R2 & Phat,void * arg)
{
TabFuncArg &tabe(*(TabFuncArg*)arg);
//MeshPoint & mp = *MeshPointStack(tabe.s);
MeshPointStack(tabe.s)->set(P,Phat,K);
tabe.eval(v);
// if (Norme2_2(P-mp.P) > 1e-10)
// cout << " bug?? F_Pi_h " << endl;
}
inline void FoX_1_Pi_h(R* v, const R2 & P,const baseFElement & K,int i,const R2 & Phat,void * arg)
{
TabFuncArg &tabe(*(TabFuncArg*)arg);
MeshPointStack(tabe.s)->set(P,Phat,K);
R2 X=tabe.eval_X();
MeshPointStack(tabe.s)->set(X.x,X.y);