10 for(
int i=1; i<=n; ++i) value *= i;
24 for(PetscInt i=0; i<N; i++){
32 for(PetscInt j=0; j<N; j++){
34 A(i,j,spow(j,PETSC_TRUE));
69 SPIVec dxidy(1./(D1*y),
"dxidy");
70 SPIVec d2xidy2(-1.*(D*y)*(dxidy^3),
"d2xidy2");
76 SPI::printf(
"--------------Something wrong with map_D call -------------");
94 PetscScalar h = xi(1,PETSC_TRUE)-xi(0,PETSC_TRUE);
99 PetscErrorCode ierr=1;
103 if ((d%2) != 0) Nm1 += 1;
105 PetscInt smax = s(s.
rows-1,PETSC_TRUE).
real();
111 for(PetscInt i=0; i<s.
rows; i++){
113 PetscInt k=(PetscInt)s(i,PETSC_TRUE).
real();
115 D +=
diag(Coeffs(i,PETSC_TRUE)*
ones(nmk),k);
121 D.
ierr = MatSetOption(D.
mat,MAT_NEW_NONZERO_LOCATIONS,PETSC_TRUE);CHKERRXX(D.
ierr);
122 for(PetscInt i=0; i<smax; i++){
134 for(PetscInt j=0; j<s.
rows; j++){
135 PetscInt sj=s(j,PETSC_TRUE).
real();
137 D(i,sj+i,Coeffs(j,PETSC_TRUE));
151 for(PetscInt j=0; j<s.
rows; j++){
152 PetscInt sj=s(j,PETSC_TRUE).
real();
154 D(D.
rows-1-i,D.
cols-1+sj-i,Coeffs(j,PETSC_TRUE));
158 D.
ierr = MatSetOption(D.
mat,MAT_NEW_NONZERO_LOCATIONS,PETSC_FALSE);CHKERRXX(D.
ierr);
162 if(uniform==PETSC_FALSE){
178 PetscScalar h = y(1,PETSC_TRUE)-y(0,PETSC_TRUE);
181 PetscInt N = order+d;
183 PetscErrorCode ierr=1;
187 if ((d%2) != 0) Nm1 += 1;
189 PetscInt smax = s(s.
rows-1,PETSC_TRUE).
real();
195 for(PetscInt i=0; i<s.
rows; i++){
197 PetscInt k=(PetscInt)s(i,PETSC_TRUE).
real();
199 D +=
diag(Coeffs(i,PETSC_TRUE)*
ones(nmk),k);
201 D +=
diag(Coeffs(i,PETSC_TRUE)*
ones(k),-nmk);
204 D +=
diag(Coeffs(i,PETSC_TRUE)*
ones(-k),k+n);
241 for(PetscInt j=0; j<N+1; j++){
242 PetscScalar cj=c(j,PETSC_TRUE);
243 PetscScalar xj=x(j,PETSC_TRUE);
244 for(PetscInt k=0; k<N+1; k++){
245 PetscScalar ck=c(k,PETSC_TRUE);
246 PetscScalar xk=x(k,PETSC_TRUE);
248 D(j,k,cj*
pow(-1.,(PetscScalar)((
double)(j+k)+0.0*PETSC_i)) / (ck*(xj-xk)));
250 else if((j==k) && ((j!=0) && (j!=N))){
251 D(j,k,-xj/(2.*(1.-(
pow(xj,2)))));
253 else if((j==k) && (j==0)){
254 D(j,k,-1.0*(2.*
pow((PetscScalar)((
double)N+0.0*PETSC_i),2.)+1.)/6.);
256 else if((j==k) && (j==N)){
257 D(j,k,1.0*(2.*
pow((PetscScalar)((
double)N+0.0*PETSC_i),2.)+1.)/6.);
260 std::cout<<
"you messed up in set_D_Chebyshev"<<std::endl;
294 SPIVec d2xidx2(-1.*(D2*x)*(dxidx^3));
299 std::cout<<
"order of derivative is not implemented in map_D_Chebyshev"<<std::endl;
311 PetscScalar a=yi*y_max/(y_max-2.*yi);
312 PetscScalar b=1.+2.*a/y_max;
313 SPIVec y(a*(1.+xi)/(b-xi),
"y");
324 SPIVec y(b*(xi+1.0)/2.0+a*(1.0-xi)/2.0,
"y");
333 SPIVec y(
cos(PETSC_PI*
arange((PetscScalar)ny-1.,-1.,-1.)/((PetscScalar)ny-1.)),
"y");
343 PetscScalar a=x(0,PETSC_TRUE);
344 PetscScalar b=x(n-1,PETSC_TRUE);
354 return std::make_tuple(S0,D1);
359 return std::make_tuple(S1,D2);
362 SPI::printf(
"Warning: d>2 not implemented in set_D_UltraS function");
371 SPIVec xi(
cos(PETSC_PI*
arange((PetscScalar)n-1.,-1.,-1.)/((PetscScalar)n-1.)),
"y");
380 for(PetscInt i=0; i<n; ++i) That(i,0,Thatcopy(i,0,PETSC_TRUE)/2.0);
381 for(PetscInt i=0; i<n; ++i) That(i,n-1,Thatcopy(i,n-1,PETSC_TRUE)/2.0);
384 for(PetscInt i=0; i<n; ++i) That(0,i,Thatcopy(0,i,PETSC_TRUE)/2.0);
385 for(PetscInt i=0; i<n; ++i) That(n-1,i,Thatcopy(n-1,i,PETSC_TRUE)/2.0);
387 That *= (2.0/((PetscScalar)N));
388 return std::make_tuple(T,That);
396 PetscScalar step = T/(PetscScalar)nt;
398 PetscScalar value=0.;
399 for(PetscInt i=0; i<nt; ++i){
412 PetscScalar dt = t(1,PETSC_TRUE)-t(0,PETSC_TRUE);
413 PetscInt npts=t.
rows;
415 PetscScalar nptss = (PetscScalar)npts;
416 PetscScalar T = t(npts-1,PETSC_TRUE) + dt;
423 D = ((PETSC_PI/T)*((-1.0)^(NmJ)))/
tan((PETSC_PI/nptss)*(NmJ));
435 D.
ierr = MatDiagonalSet(D.
mat,
zeros(npts).vec,INSERT_VALUES);CHKERRXX(D.
ierr);
457 this->
ytype = _ytype;
469 SPI::printf(
"---------------- "+this->
name+
" start --------------------------");
489 SPI::printf(
"---------------- "+this->
name+
" done ---------------------------");
497 this->y.
name=std::string(
"y");
508 this->
Dy.
name=std::string(
"Dy");
510 this->
Dyy.
name=std::string(
"Dyy");
517 this->
Dy.
name=std::string(
"Dy");
519 this->
Dyy.
name=std::string(
"Dyy");
527 this->
Dy.
name=std::string(
"Dy");
529 this->
Dyy.
name=std::string(
"Dyy");
536 this->
Dy.
name=std::string(
"Dy");
538 this->
Dyy.
name=std::string(
"Dyy");
557 this->Dy.name=std::string(
"Dy");
558 this->S0.name=std::string(
"S0");
559 this->
S1.
name=std::string(
"S1");
560 this->
Dyy.
name=std::string(
"Dyy");
561 this->
T.
name=std::string(
"T");
562 this->That.name=std::string(
"That");
569 SPI::printf(
"Warning this type of ytype grid is not implemented in SPIgrid1D.set_derivatives");
578 this->
O.
name =
"zero";
642 this->
ytype = y_gridtype;
643 this->
ttype = t_gridtype;
655 SPI::printf(
"---------------- "+this->
name+
" start --------------------------");
672 SPI::printf(
"---------------- "+this->
name+
" done ---------------------------");
681 this->y.
name=std::string(
"y");
684 this->t.
name=std::string(
"t");
775 PetscInt n=(this->
ny)*(this->
nt);
782 PetscScalar val = 1.0/(PetscScalar)(this->
nt);
784 for(PetscInt ti=0; ti<
nt; ++ti){
785 for(PetscInt yi=0; yi<
ny; ++yi){
786 PetscInt ii = ti*
ny + yi;
787 for(PetscInt jj=yi; jj<n; jj+=this->
ny){
788 this->
avgt(ii,jj,val);
855 PetscInt ny=grid2D.
ny;
857 PetscInt nt=grid2D.
nt;
859 std::vector<PetscScalar> utmp(ny);
860 for(PetscInt j=0; j<ny; ++j){
861 utmp[j] = u(j,PETSC_TRUE);
863 for(PetscInt i=0; i<nt; ++i){
864 for(PetscInt j=0; j<ny; ++j){
878 PetscInt ny=grid.
y.
rows;
883 for(PetscInt i=0; i<ni; ++i){
884 for(PetscInt j=0; j<ny; ++j){
885 atmp(j,a(ny*i + j,PETSC_TRUE));
893 PetscInt ny=grid.
y.
rows;
899 for(PetscInt i=0; i<ni; ++i){
900 for(PetscInt j=0; j<ny; ++j){
901 atmp(j,a(ny*i + j,PETSC_TRUE));
905 atmp2 = ((grid.
That)*atmp);
911 PetscInt ny=grid.
y.
rows;
916 for(PetscInt i=0; i<ni; ++i){
917 for(PetscInt j=0; j<ny; ++j){
918 atmp(j,a(ny*i + j,PETSC_TRUE));
921 val +=
trapz(atmp,grid.
y);
934 PetscInt nytx=a.
rows;
935 PetscInt ni=nytx/(ny*nt);
937 PetscScalar val2=0.0;
942 for(PetscInt i=0; i<ni; ++i){
943 for(PetscInt j=0; j<nt; ++j){
944 for(PetscInt k=0; k<ny; ++k){
945 atmp(k,a(ny*nt*i + ny*j + k,PETSC_TRUE));
955 val2 =
trapz(atmpt,grid.
t);
963 PetscInt nytx=a.
rows;
964 PetscInt ni=nytx/(ny*nt);
966 PetscScalar val2=0.0;
970 SPIVec atmpt2(nt,
"atmpt2");
971 for(PetscInt i=0; i<ni; ++i){
972 for(PetscInt j=0; j<nt; ++j){
973 for(PetscInt k=0; k<ny; ++k){
974 atmp(k,a(ny*nt*i + ny*j + k,PETSC_TRUE));
993 PetscInt nytx=a.
rows;
994 PetscInt ni=nytx/(ny*nt);
996 PetscScalar val2=0.0;
1000 SPIVec atmpt2(nt,
"atmpt2");
1001 for(PetscInt i=0; i<ni; ++i){
1002 for(PetscInt j=0; j<nt; ++j){
1003 for(PetscInt k=0; k<ny; ++k){
1004 atmp(k,a(ny*nt*i + ny*j + k,PETSC_TRUE));
1022 PetscInt ny=grid.
ny;
1023 PetscInt nt=grid.
nt;
1024 PetscInt nytx=a.
rows;
1025 PetscInt ni=nytx/(ny*nt);
1026 PetscScalar val=0.0;
1027 PetscScalar val2=0.0;
1032 SPIVec atmpt(nt+1,
"atmpt");
1034 for(PetscInt i=0; i<nt; ++i){
1035 t(i,grid.
t(i,PETSC_TRUE));
1037 PetscScalar dt = grid.
t(1,PETSC_TRUE) - grid.
t(0,PETSC_TRUE);
1038 t(nt,grid.
t(nt-1,PETSC_TRUE)+dt);
1040 for(PetscInt i=0; i<ni; ++i){
1041 for(PetscInt j=0; j<nt; ++j){
1042 for(PetscInt k=0; k<ny; ++k){
1043 atmp(k,a(ny*nt*i + ny*j + k,PETSC_TRUE));
1051 if(j==0){ atmpt(nt,val2); }
1056 val2 =
trapz(atmpt,t);
1059 std::cout<<
"integrate val = "<<val<<std::endl;
1063 PetscInt ny=grid.
ny;
1064 PetscInt nt=grid.
nt;
1065 PetscInt nytx=a.
rows;
1066 PetscInt ni=nytx/(ny*nt);
1067 PetscScalar val=0.0;
1068 PetscScalar val2=0.0;
1070 SPIVec atmp2(ny,
"atmp2");
1073 SPIVec atmpt(nt+1,
"atmpt");
1075 for(PetscInt i=0; i<nt; ++i){
1076 t(i,grid.
t(i,PETSC_TRUE));
1078 PetscScalar dt = grid.
t(1,PETSC_TRUE) - grid.
t(0,PETSC_TRUE);
1079 t(nt,grid.
t(nt-1,PETSC_TRUE)+dt);
1081 for(PetscInt i=0; i<ni; ++i){
1082 for(PetscInt j=0; j<nt; ++j){
1083 for(PetscInt k=0; k<ny; ++k){
1084 atmp(k,a(ny*nt*i + ny*j + k,PETSC_TRUE));
1092 if(j==0){ atmpt(nt,val2); }
1097 val2 =
trapz(atmpt,t);
1100 std::cout<<
"integrate val = "<<val<<std::endl;
1104 PetscInt ny=grid.
ny;
1105 PetscInt nt=grid.
nt;
1106 PetscInt nytx=a.
rows;
1107 PetscInt ni=nytx/(ny*nt);
1108 PetscScalar val=0.0;
1109 PetscScalar val2=0.0;
1112 SPIVec atmpt(nt,
"atmpt");
1114 for(PetscInt i=0; i<ni; ++i){
1115 for(PetscInt j=0; j<nt; ++j){
1116 for(PetscInt k=0; k<ny; ++k){
1117 atmp(k,a(ny*nt*i + ny*j + k,PETSC_TRUE));
1122 val2 =
trapz(atmp,grid.
y);
1128 val2 =
trapz(atmpt,grid.
t);
1136 PetscInt ny=grid.
ny;
1137 PetscInt nt=grid.
nt;
1138 PetscInt nytx=a.
rows;
1139 PetscInt ni=nytx/(ny*nt);
1140 PetscScalar val=0.0;
1141 PetscScalar val2=0.0;
1144 SPIVec atmpt(nt+1,
"atmpt");
1146 for(PetscInt i=0; i<nt; ++i){
1147 t(i,grid.
t(i,PETSC_TRUE));
1149 PetscScalar dt = grid.
t(1,PETSC_TRUE) - grid.
t(0,PETSC_TRUE);
1150 t(nt,grid.
t(nt-1,PETSC_TRUE)+dt);
1153 for(PetscInt i=0; i<ni; ++i){
1154 for(PetscInt j=0; j<nt; ++j){
1155 for(PetscInt k=0; k<ny; ++k){
1156 atmp(k,a(ny*nt*i + ny*j + k,PETSC_TRUE));
1161 val2 =
trapz(atmp,grid.
y);
1164 if(j==0){ atmpt(nt,val2); }
1168 val2 =
trapz(atmpt,t);
1175 PetscInt ny=grid.
ny;
1176 PetscInt nt=grid.
nt;
1177 PetscInt nytx=a.
rows;
1178 PetscInt ni=nytx/(ny*nt);
1179 PetscScalar val=0.0;
1180 PetscScalar val2=0.0;
1183 SPIVec atmpt(nt+1,
"atmpt");
1185 for(PetscInt i=0; i<nt; ++i){
1186 t(i,grid.
t(i,PETSC_TRUE));
1188 PetscScalar dt = grid.
t(1,PETSC_TRUE) - grid.
t(0,PETSC_TRUE);
1189 t(nt,grid.
t(nt-1,PETSC_TRUE)+dt);
1192 for(PetscInt i=0; i<ni; ++i){
1193 for(PetscInt j=0; j<nt; ++j){
1194 for(PetscInt k=0; k<ny; ++k){
1195 atmp(k,a(ny*nt*i + ny*j + k,PETSC_TRUE));
1200 val2 =
trapz(atmp,grid.
y);
1203 if(j==0){ atmpt(nt,val2); }
1207 val2 =
trapz(atmpt,t);
1214 std::cout<<
"integrate mixed types not available"<<std::endl;
1247 {grid.
T,grid.
O,grid.
O,grid.
O},
1248 {grid.
O,grid.
T,grid.
O,grid.
O},
1249 {grid.
O,grid.
O,grid.
T,grid.
O},
1250 {grid.
O,grid.
O,grid.
O,grid.
T},
1253 {grid.
That,grid.
O,grid.
O,grid.
O},
1254 {grid.
O,grid.
That,grid.
O,grid.
O},
1255 {grid.
O,grid.
O,grid.
That,grid.
O},
1256 {grid.
O,grid.
O,grid.
O,grid.
That},
1273 std::cout<<
"in proj 1"<<std::endl;
1278 std::cout<<
"in proj 2"<<std::endl;
1284 std::cout<<
"in proj 3"<<std::endl;
1296 std::cout<<
"in proj 4"<<std::endl;
1298 {grid.
T,grid.
O,grid.
O,grid.
O},
1299 {grid.
O,grid.
T,grid.
O,grid.
O},
1300 {grid.
O,grid.
O,grid.
T,grid.
O},
1301 {grid.
O,grid.
O,grid.
O,grid.
T},
1303 std::cout<<
"in proj 5"<<std::endl;
1305 {grid.
That,grid.
O,grid.
O,grid.
O},
1306 {grid.
O,grid.
That,grid.
O,grid.
O},
1307 {grid.
O,grid.
O,grid.
That,grid.
O},
1308 {grid.
O,grid.
O,grid.
O,grid.
That},
1310 std::cout<<
"in proj 6"<<std::endl;
1312 std::cout<<
"in proj 7"<<std::endl;
1314 std::cout<<
"in proj 8"<<std::endl;
1316 std::cout<<
"in proj 9"<<std::endl;
1324 std::vector<SPIVec> &x,
1328 PetscInt n=x.size();
1330 std::vector<SPIVec> qi(n);
1332 for(PetscInt i=0; i<n; ++i){
1336 for(PetscInt i=0; i<n; ++i){
1338 for(PetscInt j=1; j<=i; ++j){
1340 qi[i] -=
proj(qi[j-1],qi[i],grid);
1348 PetscInt ni = qi[0].rows/(grid.
y.
rows);
1350 for(PetscInt i=0; i<n; ++i){
1353 qtmp = grid.
That*(qtmp*qtmp);
1366 for(PetscInt i=0; i<n; ++i){
1369 qtmp = That*(qtmp*qtmp);
1375 {grid.
T,grid.
O,grid.
O,grid.
O},
1376 {grid.
O,grid.
T,grid.
O,grid.
O},
1377 {grid.
O,grid.
O,grid.
T,grid.
O},
1378 {grid.
O,grid.
O,grid.
O,grid.
T},
1381 {grid.
That,grid.
O,grid.
O,grid.
O},
1382 {grid.
O,grid.
That,grid.
O,grid.
O},
1383 {grid.
O,grid.
O,grid.
That,grid.
O},
1384 {grid.
O,grid.
O,grid.
O,grid.
That},
1386 for(PetscInt i=0; i<n; ++i){
1389 qtmp = That*(qtmp*qtmp);
1399 for(PetscInt i=0; i<n; ++i){
1407 std::vector<SPIVec> &x,
1412 PetscInt n=x.size();
1414 std::vector<SPIVec> qi(n);
1416 for(PetscInt i=0; i<n; ++i){
1421 for(PetscInt i=0; i<n; ++i){
1423 for(PetscInt j=1; j<=i; ++j){
1426 qi[i] -=
proj(qi[j-1],qi[i],grid);
1435 PetscInt ni = qi[0].rows/(grid.
y.
rows*grid.
t.
rows);
1437 for(PetscInt i=0; i<n; ++i){
1440 qtmp = grid.
That*(qtmp*qtmp);
1453 for(PetscInt i=0; i<n; ++i){
1456 qtmp = That*(qtmp*qtmp);
1463 {grid.
T,grid.
O,grid.
O,grid.
O},
1464 {grid.
O,grid.
T,grid.
O,grid.
O},
1465 {grid.
O,grid.
O,grid.
T,grid.
O},
1466 {grid.
O,grid.
O,grid.
O,grid.
T},
1470 {grid.
That,grid.
O,grid.
O,grid.
O},
1471 {grid.
O,grid.
That,grid.
O,grid.
O},
1472 {grid.
O,grid.
O,grid.
That,grid.
O},
1473 {grid.
O,grid.
O,grid.
O,grid.
That},
1476 for(PetscInt i=0; i<n; ++i){
1479 qtmp = That*(qtmp*qtmp);
1490 for(PetscInt i=0; i<n; ++i){
1510 PetscInt n1=grid1.
ny;
1511 PetscInt n2=grid2.
ny;
1512 SPIMat I_n2Xn1(n2,n1,
"I");
1513 for(PetscInt i=0; i<n2; i++){
1514 PetscScalar y2i = grid2.
y(i,PETSC_TRUE);
1515 PetscBool flag=PETSC_TRUE;
1516 for(PetscInt j=0; j<n1; j++){
1517 PetscScalar y1j = grid1.
y(j,PETSC_TRUE);
1518 if(y1j.real()>y2i.real()){
1533 SPIMat Deltay(
diag(grid2.
y - (I_n2Xn1*grid1.
y)),
"Deltay");
1534 SPIMat interp_n1_to_n2(I_n2Xn1 + (Deltay*(I_n2Xn1*grid1.
Dy)) + 0.5*(Deltay*Deltay*(I_n2Xn1*grid1.
Dyy)),
"interp");
1535 return interp_n1_to_n2;
1542 PetscInt n1=y1.
rows;
1543 PetscInt n2=y2.
rows;
1546 SPIMat I_n2Xn1(n2,n1,
"I");
1548 for(PetscInt i=0; i<n2; i++){
1549 PetscScalar y2i = y2(i,PETSC_TRUE);
1550 PetscBool flag=PETSC_TRUE;
1551 for(PetscInt j=0; j<n1; j++){
1552 PetscScalar y1j = y1(j,PETSC_TRUE);
1553 if(y1j.real()>y2i.real()){
1568 SPIMat Deltay(
diag(y2 - (I_n2Xn1*y1)),
"Deltay");
1569 SPIMat interp_n1_to_n2(I_n2Xn1 + (Deltay*(I_n2Xn1*Dy1)) + 0.5*(Deltay*Deltay*(I_n2Xn1*Dyy1)),
"interp");
1570 return interp_n1_to_n2;
1576 PetscScalar Nt = (PetscScalar)nt;
1577 PetscScalar e = (PetscExpScalar(-2.0*PETSC_PI*PETSC_i/Nt));
1579 for(PetscInt i=0; i<nt; ++i){
1580 for(PetscInt j=0; j<nt; ++j){
1581 W(i,j,PetscPowScalar(e,i*j));
1592 PetscScalar Nt = (PetscScalar)nt;
1594 SPIMat FTinv(nt,nt,
"inv(FT)");
1597 SPIMat Ihalf(nt,nt,
"Ihalf");
1598 SPIMat Ihalfn(nt,nt,
"Ihalf");
1599 PetscInt Nthalf = nt/2;
1604 for(PetscInt i=0; i<nt; ++i){
1609 else if(i < Nthalf){
1612 else if(i >= Nthalf){
1620 return std::make_tuple(FT,FTinv,Ihalf,Ihalfn);