7 if (test) {
SPI::printf(
"\x1b[32m"+name+
" test passed"+
"\x1b[0m"); }
8 else{ std::cout<<
"\x1b[31m"+name+
" test failed"+
"\x1b[0m"<<std::endl;}
11 void test_if_close(PetscScalar value,PetscScalar golden, std::string name, PetscReal tol){
12 PetscReal valuer=PetscRealPart(value);
13 PetscReal goldenr=PetscRealPart(golden);
14 if ((goldenr-tol<=valuer) && (valuer<=goldenr+tol)) {
SPI::printf(
"\x1b[32m"+name+
" test passed"+
"\x1b[0m"); }
18 SPI::printf(
"\x1b[31m"+name+
" test failed"+
"\x1b[0m");
19 SPI::printf(
"\x1b[31m goldenr=%.20f \x1b[0m",goldenr);
20 SPI::printf(
"\x1b[31m valuer =%.20f \x1b[0m",valuer );
26 PetscBool alltests=PETSC_FALSE;
29 SPI::printf(
"------------ Vec tests start-------------");
37 X1.set(3,1.+1.*PETSC_i);
57 test_if_close(X3(2,PETSC_TRUE),4.,
"SPIVec.axpy(PetscScalar,SPIVec)");
67 X6 = (X1*(0.+1.*PETSC_i));
81 SPI::printf(
"------------ Mat tests start ---------------");
90 for (
int i=0; i<m; i++){
95 test_if_close(PetscImaginaryPart(A2(2,2,PETSC_TRUE)),1.,
"SPIMat(PetscInt,PetscInt,PETSC_TRUE)");
98 test_if_close(B(0,1,PETSC_TRUE),1.,
"SPIMat(PetscInt,PetscInt,PetscInt)");
99 B=(3.4+PETSC_i*4.2)*A2+4.*A2;
100 test_if_close(B(1,1,PETSC_TRUE),3.2,
"PetscScalar*SPIMat+double*SPIMat");
104 test_if_close(E(1,1,PETSC_TRUE),1.,
"SPIMat(PetscInt,PetscInt,SPIMat) 1");
105 test_if_close(E(4,7,PETSC_TRUE),3.182,
"SPIMat(PetscInt,PetscInt,SPIMat) 2");
110 test_if_close(A2T(3,0,PETSC_TRUE),3.612,
"SPIMat.T(SPIMat)");
114 test_if_close(D(0,3,PETSC_TRUE),4.*-9.3912,
"SPIMat*=PetscScalar");
117 test_if_close(A2(0,3,PETSC_TRUE),3.612,
"SPIMat*eye(SPIMat)");
124 test_if_close(E(7,8,PETSC_TRUE),3.182,
"SPIMat(PetscInt,PetscInt,SPIMat) 3");
125 test_if_close(PetscImaginaryPart(E(6,10,PETSC_TRUE)),11.6,
"SPIMat(PetscInt,PetscInt,SPIMat) 4");
127 test_if_close(PetscImaginaryPart(E(10,6,PETSC_TRUE)),-11.6,
"SPIMat.H()");
129 test_if_close(PetscImaginaryPart(E(10,6,PETSC_TRUE)),11.6,
"SPIMat.conj()");
131 test_if_close(PetscImaginaryPart(E(6,10,PETSC_TRUE)),11.6,
"SPIMat.T()");
133 test_if_close(PetscImaginaryPart(F(6,10,PETSC_TRUE)),11.6,
"SPIMat(SPIMat)");
136 SPI::printf(
"------------ Mat tests end ---------------");
139 SPI::printf(
"------------ A*x tests start ---------------");
143 for(
int i=0; i<4; i++){
161 SPI::printf(
"------------ A*x tests end ---------------");
165 SPI::printf(
"------------ A*x=b tests start ---------------");
169 for(
int i=0; i<4; i++){
177 SPI::printf(
"------------ A*x=b tests end ---------------");
180 SPI::printf(
"------------ Mat func tests start-------------");
185 for (
int i=0; i<3; i++) two(i,2.);
197 D(0,0,1.); D(0,1,2.);
198 D(1,0,3.); D(1,1,4.);
202 SPI::printf(
"------------ Mat func tests end -------------");
205 SPI::printf(
"------------ Mat eig tests start-------------");
215 std::tie(alpha,
eig,eig2) =
SPI::eig(A,B,1.0+PETSC_i*0.5);
217 test_if_close(alpha,1.,
"eig(SPIMat,SPIMat,PetscScalar) 1",1.E-8);
219 std::tie(alpha2,eig2,
eig) =
SPI::eig(A,B,-1.0+PETSC_i*0.00005,1.E-19,10);
221 test_if_close(alpha2,1.,
"eig(SPIMat,SPIMat,PetscScalar) 2",1.E-7);
224 test_if_close(alpha,1.,
"eig_right(SPIMat,SPIMat,PetscScalar) 1",1.E-8);
226 test_if_close(alpha2,1.,
"eig_right(SPIMat,SPIMat,PetscScalar) 2",1.E-7);
229 test_if_close(alpha,1.,
"eig_init(SPIMat,SPIMat,PetscScalar,SPIVec) 1",1.E-8);
231 test_if_close(alpha2,1.,
"eig_init(SPIMat,SPIMat,PetscScalar,SPIVec,PetscReal,PetscInt) 2",1.E-7);
234 test_if_close(alpha,1.,
"eig_init_right(SPIMat,SPIMat,PetscScalar,SPIVec) 1",1.E-8);
236 test_if_close(alpha2,1.,
"eig_init_right(SPIMat,SPIMat,PetscScalar,SPIVec,PetscReal,PetscInt) 2",1.E-7);
251 C(0,0,0.4); C(0,2,-0.3);
253 C(2,0,-0.3); C(2,2,0.5); C(2,3,-0.2);
254 C(3,2,-0.2);C(3,3,0.2);
256 K(0,0,-7.); K(0,1,2.); K(0,2,4);
257 K(1,0,2); K(1,1,-4); K(1,2,2);
258 K(2,0,4); K(2,1,2); K(2,2,-9); K(2,3,3);
266 std::tie(alpha4,eig4) =
SPI::polyeig({K,C,M},-2.5+0.5*PETSC_i);
267 test_if_close(alpha4,-2.44985,
"polyeig(std::vector<SPIMat>,PetscScalar) 1",1.E-5);
268 std::tie(alpha4,eig4) =
SPI::polyeig({K,C,M},0.33+0.005*PETSC_i);
269 test_if_close(alpha4,0.3353,
"polyeig(std::vector<SPIMat>,PetscScalar) 2",1.E-5);
276 test_if_close(alpha4,-2.44985,
"polyeig_init(std::vector<SPIMat>,PetscScalar) 1",1.E-5);
278 test_if_close(alpha4,0.3353,
"polyeig_init(std::vector<SPIMat>,PetscScalar) 2",1.E-5);
280 SPI::printf(
"------------ Mat eig tests end -------------");
284 SPI::printf(
"------------ I/O tests start -------------");
295 SPI::printf(
"------------ I/O tests end -------------");
298 SPI::printf(
"------------ I/O tests2 start -------------");
301 test_if_close(A_read(0,PETSC_TRUE),1.,
"load(SPIVec,std::string) 1");
302 test_if_close(A_read(1,PETSC_TRUE),2.,
"load(SPIVec,std::string) 2");
305 test_if_close(PetscImaginaryPart(B_read(0,PETSC_TRUE)),0.5,
"load(SPIVec,std::string) 3");
306 test_if_close(B_read(1,PETSC_TRUE),0.,
"load(SPIVec,std::string) 4");
307 SPI::printf(
"------------ I/O tests2 end -------------");
310 SPI::printf(
"------------ I/O tests3 start -------------");
314 A(1,1,3.+4.59*PETSC_i);
320 B(1,1,5.+4.89*PETSC_i);
323 SPI::printf(
"------------ I/O tests3 end -------------");
326 SPI::printf(
"------------ I/O tests4 start -------------");
329 test_if_close(A_read(0,0,PETSC_TRUE),1.,
"load(SPIMat,std::string) 1");
330 test_if_close(A_read(1,0,PETSC_TRUE),2.,
"load(SPIMat,std::string) 2");
331 test_if_close(A_read(1,1,PETSC_TRUE),3.,
"load(SPIMat,std::string) 3");
332 test_if_close(PetscImaginaryPart(A_read(1,1,PETSC_TRUE)),4.59,
"load(SPIMat,std::string) 4");
333 std::vector<SPI::SPIMat> AB(2,
SPI::eye(2)*0.);
335 test_if_close(AB[0](0,0,PETSC_TRUE),1.,
"load(std::vector<SPIMat>,std::string) 1");
336 test_if_close(AB[0](1,0,PETSC_TRUE),2.,
"load(std::vector<SPIMat>,std::string) 2");
337 test_if_close(AB[0](1,1,PETSC_TRUE),3.,
"load(std::vector<SPIMat>,std::string) 3");
338 test_if_close(PetscImaginaryPart(AB[0](1,1,PETSC_TRUE)),4.59,
"load(std::vector<SPIMat>,std::string) 4");
339 test_if_close(AB[1](0,0,PETSC_TRUE),3.,
"load(std::vector<SPIMat>,std::string) 5");
340 test_if_close(AB[1](1,0,PETSC_TRUE),4.,
"load(std::vector<SPIMat>,std::string) 6");
341 test_if_close(AB[1](1,1,PETSC_TRUE),5.,
"load(std::vector<SPIMat>,std::string) 7");
342 test_if_close(PetscImaginaryPart(AB[1](1,1,PETSC_TRUE)),4.89,
"load(std::vector<SPIMat>,std::string) 8");
346 SPI::printf(
"------------ I/O tests4 end -------------");
349 SPI::printf(
"------------ block test start -------------");
363 SPI::printf(
"------------ block test end -------------");
366 SPI::printf(
"------------ LST_temporal test start -------------");
376 SPI::SPIbaseflow channel(U.
diag(),o,o,o,Uy.
diag(),o,o,o,o,o,o,o,o,o);
379 PetscScalar Re=2000.0;
380 PetscScalar alpha=1.0;
381 PetscScalar beta=0.0;
386 params.
omega = 0.3121002078-0.0197986590*PETSC_i;
387 params.
alpha = alpha;
392 PetscScalar eigenvalue;
393 eigenfunction.
name =
"eigenfunction";
397 test_if_close(eigenvalue,0.3121002979-0.0197986590*PETSC_i,
"LST_temporal 1",1e-9);
400 test_if_close(eigenvalue,0.3121002979-0.0197986590*PETSC_i,
"LST_temporal 2",1e-9);
401 SPI::printf(
"------------ LST_temporal test end -------------");
404 SPI::printf(
"------------ LST_spatial test start -------------");
416 params.
alpha = 0.97875+0.044394*PETSC_i;
420 PetscScalar eigenvalue;
421 eigenfunction.
name =
"eigenfunction";
424 SPI::SPIbaseflow channel(U.
diag(),o,o,o,Uy.
diag(),o,o,o,o,o,o,o,o,o);
427 test_if_close(eigenvalue,0.97875+0.044394*PETSC_i,
"LST_spatial 1",1e-5);
430 test_if_close(eigenvalue,0.97875+0.044394*PETSC_i,
"LST_spatial 1",1e-5);
432 params.
alpha = 0.34312+0.049677*PETSC_i;
434 test_if_close(eigenvalue,0.34312+0.049677*PETSC_i,
"LST_spatial 2",1e-5);
436 params.
alpha = 0.61+0.1*PETSC_i;
438 test_if_close(eigenvalue,0.61167+0.140492*PETSC_i,
"LST_spatial 3",1e-5);
440 SPI::printf(
"------------ LST_spatial test end -------------");
443 SPI::printf(
"------------ LSTNP_spatial test start -------------");
455 params.
alpha = 0.97875+0.044394*PETSC_i;
461 PetscScalar eigenvalue;
462 eigenfunction.
name =
"eigenfunction";
465 SPI::SPIbaseflow channel(U,o,o,o,Uy,o,o,o,o,o,o,o,o,o);
470 test_if_close(eigenvalue,0.978748+0.04439397*PETSC_i,
"LSTNP_spatial 1",1e-5);
476 params.
alpha = 0.978748+0.04439397*PETSC_i;
479 test_if_close(eigenvalue,0.978748+0.04439397*PETSC_i,
"LSTNP_spatial 2",1e-5);
484 params.
alpha = 0.34305+0.0498376872*PETSC_i;
485 std::tie(eigenvalue,cg,leigenfunction,eigenfunction) =
SPI::LSTNP_spatial(params,grid,
channel,leigenfunction,eigenfunction);
487 test_if_close(eigenvalue,0.34305+0.049837*PETSC_i,
"LSTNP_spatial 3",1e-5);
489 test_if_close(eigenvalue,0.34305+0.049837*PETSC_i,
"LSTNP_spatial_right 3",1e-5);
492 params.
alpha = 0.6116672+0.140493*PETSC_i;
493 std::tie(eigenvalue,cg,leigenfunction,eigenfunction) =
SPI::LSTNP_spatial(params,grid,
channel,leigenfunction,eigenfunction);
495 test_if_close(eigenvalue,0.6116672+0.140493*PETSC_i,
"LSTNP_spatial 4",1e-5);
497 test_if_close(eigenvalue,0.6116672+0.140493*PETSC_i,
"LSTNP_spatial_right 4",1e-5);
500 SPI::printf(
"------------ LSTNP_spatial test end -------------");
503 SPI::printf(
"------------ Chebyshev derivatives start -----------");
509 SPI::printf(
"------------ Chebyshev derivatives end -----------");
512 SPI::printf(
"------------ LSTNP Blasius boundary layer start -----------");
525 params.
omega = 86.*params.
Re/(1000000.);
526 params.
nu = 1./params.
Re;
527 params.
x = params.
Re;
529 params.
alpha = 0.094966+0.004564*PETSC_i;
537 PetscScalar eigenvalue;
538 eigenfunction.
name =
"eigenfunction";
551 std::tie(eigenvalue,cg,leigenfunction,eigenfunction) =
SPI::LSTNP_spatial(params,grid,bl_flow);
554 test_if_close(eigenvalue,0.094966+0.004564*PETSC_i,
"LSTNP_spatial 1",1e-5);
560 std::tie(eigenvalue,cg,leigenfunction,eigenfunction) =
SPI::LSTNP_spatial(params,grid,bl_flow,leigenfunction,eigenfunction);
562 test_if_close(eigenvalue,0.094966+0.004564*PETSC_i,
"LSTNP_spatial 2",1e-5);
564 test_if_close(eigenvalue,0.094966+0.004564*PETSC_i,
"LSTNP_spatial_right 2",1e-5);
567 params.
alpha = 0.1067+0.001898*PETSC_i;
568 std::tie(eigenvalue,cg,leigenfunction,eigenfunction) =
SPI::LSTNP_spatial(params,grid,bl_flow);
570 test_if_close(eigenvalue,0.10665+0.0018979*PETSC_i,
"LSTNP_spatial 3",1e-5);
572 test_if_close(eigenvalue,0.10665+0.0018979*PETSC_i,
"LSTNP_spatial_right 3",1e-5);
574 std::tie(eigenvalue,cg,leigenfunction,eigenfunction) =
SPI::LSTNP_spatial(params,grid,bl_flow,leigenfunction,eigenfunction);
576 test_if_close(eigenvalue,0.10665+0.0018979*PETSC_i,
"LSTNP_spatial 4",1e-5);
577 SPI::printfc(
"eigenvalue is %.10f + %.10fi",eigenvalue);
579 test_if_close(eigenvalue,0.10665+0.0018979*PETSC_i,
"LSTNP_spatial_right 4",1e-5);
581 SPI::printf(
"------------ LSTNP Blasius boundary layer end -----------");
584 SPI::printf(
"------------ LSTNP Blasius boundary layer start -----------");
597 params.
omega = 86.*params.
Re/(1000000.);
598 params.
nu = 1./params.
Re;
599 params.
x = params.
Re;
601 params.
alpha = 0.094966+0.004564*PETSC_i;
609 PetscScalar eigenvalue;
610 eigenfunction.
name =
"eigenfunction";
623 std::tie(eigenvalue,cg,leigenfunction,eigenfunction) =
SPI::LSTNP_spatial(params,grid,bl_flow);
626 test_if_close(eigenvalue,0.094966+0.004564*PETSC_i,
"LSTNP_spatial 1",1e-5);
632 std::tie(eigenvalue,cg,leigenfunction,eigenfunction) =
SPI::LSTNP_spatial(params,grid,bl_flow,leigenfunction,eigenfunction);
634 test_if_close(eigenvalue,0.094966+0.004564*PETSC_i,
"LSTNP_spatial 2",1e-5);
639 params.
alpha = 0.1067+0.001898*PETSC_i;
640 std::tie(eigenvalue,cg,leigenfunction,eigenfunction) =
SPI::LSTNP_spatial(params,grid,bl_flow);
642 test_if_close(eigenvalue,0.10665+0.0018979*PETSC_i,
"LSTNP_spatial 3",1e-5);
646 std::tie(eigenvalue,cg,leigenfunction,eigenfunction) =
SPI::LSTNP_spatial(params,grid,bl_flow,leigenfunction,eigenfunction);
648 test_if_close(eigenvalue,0.10665+0.0018979*PETSC_i,
"LSTNP_spatial 4",1e-5);
649 SPI::printfc(
"eigenvalue is %.10f + %.10fi",eigenvalue);
653 SPI::printf(
"------------ LSTNP Blasius boundary layer end -----------");
656 SPI::printf(
"------------ LST Blasius boundary layer start -----------");
668 params.
Re = 1000.0/1.7208;
669 params.
omega = 0.26/1.7208;
670 params.
nu = 1./params.
Re;
671 params.
x = params.
Re;
673 params.
alpha = (0.74155+0.345132*PETSC_i)/1.7208;
677 PetscScalar eigenvalue;
678 eigenfunction.
name =
"eigenfunction";
691 test_if_close(eigenvalue*1.7208,(0.74155+0.345132*PETSC_i),
"LST_spatial 1",1e-5);
693 SPI::printfc(
"eigenvalue is %.10f + %.10fi",eigenvalue*1.7208);
695 params.
alpha = (0.54213+0.083968*PETSC_i)/1.7208;
697 test_if_close(eigenvalue*1.7208,(0.54213+0.083968*PETSC_i),
"LST_spatial 2",1e-5);
698 SPI::printfc(
"eigenvalue is %.10f + %.10fi",eigenvalue*1.7208);
700 params.
alpha = (0.29967+0.230773*PETSC_i)/1.7208;
702 test_if_close(eigenvalue*1.7208,(0.29967+0.083968*PETSC_i),
"LST_spatial 3",1e-5);
703 SPI::printfc(
"eigenvalue is %.10f + %.10fi",eigenvalue*1.7208);
705 SPI::printf(
"------------ LST Blasius boundary layer end -----------");
708 SPI::printf(
"------------ LSTNP parallel Blasius boundary layer start -----------");
720 params.
Re = 1000.0/1.7208;
721 params.
omega = 0.26/1.7208;
722 params.
nu = 1./params.
Re;
723 params.
x = params.
Re;
725 params.
alpha = (0.74155+0.345132*PETSC_i)/1.7208;
729 PetscScalar eigenvalue;
730 eigenfunction.
name =
"eigenfunction";
743 test_if_close(eigenvalue*1.7208,(0.74155+0.345132*PETSC_i),
"LSTNP_spatial_right 1",1e-5);
744 test_if_close(params.
alpha*1.7208,(0.74155+0.345132*PETSC_i),
"LSTNP_spatial_right 1",1e-5);
745 SPI::printfc(
"eigenvalue is %.10f + %.10fi",eigenvalue*1.7208);
747 params.
alpha = (0.54213+0.083968*PETSC_i)/1.7208;
749 test_if_close(eigenvalue*1.7208,(0.54213+0.083968*PETSC_i),
"LSTNP_spatial_right 2",1e-5);
750 SPI::printfc(
"eigenvalue is %.10f + %.10fi",eigenvalue*1.7208);
752 params.
alpha = (0.29967+0.230773*PETSC_i)/1.7208;
754 test_if_close(eigenvalue*1.7208,(0.29967+0.083968*PETSC_i),
"LSTNP_spatial_right 3",1e-5);
755 SPI::printfc(
"eigenvalue is %.10f + %.10fi",eigenvalue*1.7208);
757 SPI::printf(
"------------ LSTNP parallel Blasius boundary layer end -----------");
760 SPI::printf(
"------------ Fourier Collocated derivative operator start -----------");
766 test_if_close((Dt*y)(2,PETSC_TRUE),yp(2,PETSC_TRUE),
"set_D_Fourier 1",1e-12);
769 SPI::printf(
"------------ Fourier Collocated derivative operator end -----------");
772 SPI::printf(
"------------ BV Orthogonalize start -----------");
781 A1(0,1.0+0.5*PETSC_i); A2(0,1.);
782 A1(1,2.0+0.5*PETSC_i); A2(1,1.);
784 Vec As[]={A1.vec,A2.
vec};
789 ierr = BVCreate(PETSC_COMM_WORLD,&bv); CHKERRXX(ierr);
791 BVSetSizesFromVec(bv,A1.vec,m);
792 ierr = BVSetFromOptions(bv);CHKERRXX(ierr);
793 ierr = BVInsertVecs(bv,0,&m,As,PETSC_TRUE);
795 ierr = BVCreateMat(bv,&AorthH.
mat); CHKERRXX(ierr);
799 ierr = BVDestroy(&bv); CHKERRXX(ierr);
802 test_if_close(Aorth(1,0,PETSC_TRUE),0.85280286542244166,
"orthogonalize 1",1e-12);
807 test_if_close(Aorth2(1,0,PETSC_TRUE),0.85280286542244166,
"orthogonalize 2",1e-12);
816 SPI::printf(
"------------ BV Orthogonalize end -----------");
819 SPI::printf(
"------------ Gram-Schmidt Orthogonalize start -----------");
824 std::vector<SPI::SPIVec> A={A1,A2};
829 test_if_close(Aorth[0](2,PETSC_TRUE),-0.484122918275927,
"orthogonalize 1",1e-12);
830 test_if_close(Aorth[1](2,PETSC_TRUE),1.082531754730548,
"orthogonalize 2",1e-12);
832 SPI::printf(
"------------ Gram-Schmidt Orthogonalize end -----------");
835 SPI::printf(
"------------ Gram-Schmidt Orthogonalize start -----------");
840 std::vector<SPI::SPIVec> A={A1,A2};
845 test_if_close(Aorth[0](2,PETSC_TRUE),-0.484122918275927,
"orthogonalize 1",1e-12);
846 test_if_close(Aorth[1](2,PETSC_TRUE),1.082531754730548,
"orthogonalize 2",1e-12);
859 std::vector<SPI::SPIVec> Al = {A1l,A2l};
861 test_if_close(Alorth[0](2,PETSC_TRUE),-0.228217732293819,
"orthogonalize 3",1e-12);
862 test_if_close(Alorth[0](10,PETSC_TRUE),0.228217732293819,
"orthogonalize 4",1e-12);
863 test_if_close(Alorth[1](0,PETSC_TRUE),0.714434508311760,
"orthogonalize 5",1e-12);
864 test_if_close(Alorth[1](8,PETSC_TRUE),-0.306186217847897,
"orthogonalize 6",1e-12);
879 std::vector<SPI::SPIVec> All = {A1ll,A2ll};
881 test_if_close(Allorth[0](2,PETSC_TRUE),-0.161374306091976,
"orthogonalize 7",1e-12);
882 test_if_close(Allorth[0](8,PETSC_TRUE),0.484122918275927,
"orthogonalize 8",1e-12);
883 test_if_close(Allorth[0](10,PETSC_TRUE),0.161374306091976,
"orthogonalize 9",1e-12);
884 test_if_close(Allorth[0](18,PETSC_TRUE),-0.161374306091976,
"orthogonalize 10",1e-12);
885 test_if_close(Allorth[0](24,PETSC_TRUE),0.484122918275927,
"orthogonalize 11",1e-12);
886 test_if_close(Allorth[0](26,PETSC_TRUE),0.161374306091976,
"orthogonalize 12",1e-12);
887 test_if_close(Allorth[1](2,PETSC_TRUE),0.360843918243516,
"orthogonalize 13",1e-12);
888 test_if_close(Allorth[1](8,PETSC_TRUE),-0.216506350946110,
"orthogonalize 14",1e-12);
889 test_if_close(Allorth[1](10,PETSC_TRUE),-0.360843918243516,
"orthogonalize 15",1e-12);
890 test_if_close(Allorth[1](18,PETSC_TRUE),0.360843918243516,
"orthogonalize 16",1e-12);
891 test_if_close(Allorth[1](24,PETSC_TRUE),-0.216506350946110,
"orthogonalize 17",1e-12);
892 test_if_close(Allorth[1](26,PETSC_TRUE),-0.360843918243516,
"orthogonalize 18",1e-12);
894 SPI::printf(
"------------ Gram-Schmidt Orthogonalize end -----------");
897 SPI::printf(
"------------ Gram-Schmidt Orthogonalize 2D start -----------");
933 std::vector<SPI::SPIVec> A12ls = {A1l,A2l};
934 std::vector<SPI::SPIVec> A12lso;
998 SPI::printf(
"------------ Gram-Schmidt Orthogonalize 2D end -----------");
1001 SPI::printf(
"------------ SPIMat.H(SPIVec) start -----------");
1003 A(0,0,4.); A(0,1,3.);
1004 A(1,0,3.+4.0*PETSC_i); A(1,1,3.);
1005 A(2,0,2.); A(2,1,3.);
1006 A(3,0,1.); A(3,1,3.);
1010 test_if_close(AHq(0,PETSC_TRUE),10.0,
"SPIMat.H(SPIVec) 1",1e-12);
1011 test_if_close(PetscImaginaryPart(AHq(0,PETSC_TRUE)),-4.0,
"SPIMat.H(SPIVec) 2",1e-12);
1012 test_if_close(AHq(1,PETSC_TRUE),12.0,
"SPIMat.H(SPIVec) 3",1e-12);
1013 test_if_close(PetscImaginaryPart(AHq(1,PETSC_TRUE)),0.0,
"SPIMat.H(SPIVec) 3",1e-12);
1014 SPI::printf(
"------------ SPIMat.H(SPIVec) end -----------");
1017 SPI::printf(
"------------ long skinny mat * short vec SPIMat*SPIVec start -----------");
1020 for(PetscInt i=0; i<ny; ++i){
1021 A(i,0,(PetscScalar)i);
1022 A(i,1,(PetscScalar)(2*i));
1028 SPI::printf(
"------------ long skinny mat * short vec SPIMat*SPIVec start -----------");
1031 SPI::printf(
"------------ abs(SPIMat) start -----------");
1034 for(PetscInt i=0; i<ny; ++i){
1035 A(i,0,-(PetscScalar)i+0.0*PETSC_i);
1036 A(i,1,-(PetscScalar)(2*i) - 2.0*PETSC_i);
1043 SPI::printf(
"------------ abs(SPIMat) end -----------");
1046 SPI::printf(
"------------ inv(SPIMat) start -----------");
1048 A(0,0, 0.0); A(0,1,-3.0); A(0,2,-2.0);
1049 A(1,0, 1.0); A(1,1,-4.0); A(1,2,-2.0);
1050 A(2,0,-3.0); A(2,1, 4.0); A(2,2, 1.0);
1053 MatGetColumnVector(A.
mat,yy.
vec,1);
1055 test_if_close(Ainv(2,1,PETSC_TRUE),9.0,
"inv(SPIMat) 1",1e-12);
1056 SPI::printf(
"------------ inv(SPIMat) end -----------");
1059 SPI::printf(
"------------ UltraSpherical ops start -----------");
1074 test_if_close((S1*D1)(1,2,PETSC_TRUE),0.2,
"set_D_UltraS(SPIMat) 1",1e-12);
1075 test_if_close((S1*D1)(1,4,PETSC_TRUE),-0.2,
"set_D_UltraS(SPIMat) 2",1e-12);
1076 test_if_close(D2(1,3,PETSC_TRUE),0.24,
"set_D_UltraS(SPIMat) 3",1e-12);
1077 test_if_close((T*
inv(S0)*D1*That)(1,2,PETSC_TRUE),0.282842712,
"set_D_UltraS(SPIMat) 4",1e-7);
1078 test_if_close((T*
inv(S0)*
inv(S1)*D2*That)(1,3,PETSC_TRUE),-0.08,
"set_D_UltraS(SPIMat) 4",1e-7);
1085 SPI::printf(
"------------ UltraSpherical ops end -----------");
1088 SPI::printf(
"------------ LST_temporal channel UltraS start -----------");
1101 params.
omega = 0.3121-0.01978*PETSC_i;
1102 params.
nu = 1./params.
Re;
1110 PetscScalar eigenvalue;
1111 eigenfunction.
name =
"eigenfunction";
1117 SPI::SPIbaseflow channel(U,o,o,o,Uy,o,o,o,o,o,o,o,o,o);
1131 test_if_close(eigenvalue,0.3121-0.01978*PETSC_i,
"LST_temporal UltraS 1",1e-5);
1158 SPI::printf(
"------------ LST_temporal channel UltraS end -----------");
1161 SPI::printf(
"------------ LST_spatial channel flow UltraS start -----------");
1180 params.
nu = 1./params.
Re;
1181 params.
x = params.
Re;
1184 params.
alpha = 0.97875+0.044394*PETSC_i;
1190 PetscScalar eigenvalue;
1191 eigenfunction.
name =
"eigenfunction";
1203 std::tie(eigenvalue,eigenfunction) =
SPI::LST_spatial(params,grid,bl_flow);
1206 params.
alpha = 0.34312+0.049677*PETSC_i;
1207 std::tie(eigenvalue,eigenfunction) =
SPI::LST_spatial(params,grid,bl_flow);
1210 params.
alpha = 0.61167+0.140492*PETSC_i;
1211 std::tie(eigenvalue,eigenfunction) =
SPI::LST_spatial(params,grid,bl_flow);
1214 SPI::printf(
"------------ LST_spatial channel flow UltraS end -----------");
1217 SPI::printf(
"------------ LST_spatial Blasius boundary layer UltraS start -----------");
1232 params.
Re = 1000.0/1.7208;
1233 params.
omega = 0.26/1.7208;
1234 params.
nu = 1./params.
Re;
1235 params.
x = params.
Re;
1237 params.
alpha = (0.74155+0.345132*PETSC_i)/1.7208;
1244 PetscScalar eigenvalue;
1245 eigenfunction.
name =
"eigenfunction";
1259 std::tie(eigenvalue,eigenfunction) =
SPI::LST_spatial(params,grid,bl_flow);
1262 params.
alpha = (0.54213+0.083968*PETSC_i)/1.7208;
1263 std::tie(eigenvalue,eigenfunction) =
SPI::LST_spatial(params,grid,bl_flow);
1266 params.
alpha = (0.29967+0.230773*PETSC_i)/1.7208;
1267 std::tie(eigenvalue,eigenfunction) =
SPI::LST_spatial(params,grid,bl_flow);
1270 SPI::printf(
"------------ LST_spatial Blasius boundary layer UltraS end -----------");
1274 SPI::printf(
"------------ eye and block timings start -----------");
1278 std::cout<<
"created I and O"<<std::endl;
1284 std::cout<<
"created block"<<std::endl;
1290 std::cout<<
"created block P"<<std::endl;
1295 std::cout<<
"created block one kron"<<std::endl;
1301 std::cout<<
"created block using 2 kron"<<std::endl;
1303 SPI::printf(
"------------ eye and block timings end -----------");
1306 SPI::printf(
"------------ LSTNP_spatial_right Blasius boundary layer UltraS start -----------");
1321 params.
Re = 1000.0/1.7208;
1322 params.
omega = 0.26/1.7208;
1323 params.
nu = 1./params.
Re;
1324 params.
x = params.
Re;
1326 params.
alpha = (0.74155+0.345132*PETSC_i)/1.7208;
1333 PetscScalar eigenvalue;
1334 eigenfunction.
name =
"eigenfunction";
1349 test_if_close(params.
alpha*1.7208,(0.74155+0.345132*PETSC_i),
"LSTNP_spatial_right 1",1e-5);
1351 params.
alpha = (0.54213+0.083968*PETSC_i)/1.7208;
1353 test_if_close(params.
alpha*1.7208,(0.54213+0.083968*PETSC_i),
"LSTNP_spatial_right 2",1e-5);
1355 params.
alpha = (0.29967+0.230773*PETSC_i)/1.7208;
1357 test_if_close(params.
alpha*1.7208,(0.29967+0.230773*PETSC_i),
"LSTNP_spatial_right 3",1e-5);
1359 SPI::printf(
"------------ LSTNP_spatial_right Blasius boundary layer UltraS end -----------");
1362 SPI::printf(
"------------ LST_spatial_cg Blasius boundary layer physical vs UltraS start -----------");
1378 params.
Re = 1000.0/1.7208;
1379 params.
omega = 0.26/1.7208;
1380 params.
nu = 1./params.
Re;
1381 params.
x = params.
Re;
1383 params.
alpha = (0.74155+0.345132*PETSC_i)/1.7208;
1391 PetscScalar eigenvalue;
1392 eigenfunction.
name =
"eigenfunction";
1407 std::tie(eigenvalue,cg,leigenfunction,eigenfunction) =
SPI::LST_spatial_cg(params,grid,bl_flow);
1410 test_if_close(params.
alpha*1.7208,(0.74155+0.345132*PETSC_i),
"LST_spatial_cg UltraS 1",1e-5);
1413 {grid.
T,O,O,O,O,O,O,O},
1414 {O,grid.
T,O,O,O,O,O,O},
1415 {O,O,grid.
T,O,O,O,O,O},
1416 {O,O,O,grid.
T,O,O,O,O},
1417 {O,O,O,O,grid.
T,O,O,O},
1418 {O,O,O,O,O,grid.
T,O,O},
1419 {O,O,O,O,O,O,grid.
T,O},
1420 {O,O,O,O,O,O,O,grid.
T},
1422 SPI::SPIVec eigenfunctionout(T*eigenfunction,
"UltraS");
1423 SPI::SPIVec leigenfunctionout(T*leigenfunction,
"UltraSl");
1425 eigenfunctionout /=
SPI::L2(eigenfunctionout);
1426 leigenfunctionout /=
SPI::L2(leigenfunctionout);
1427 SPI::save(eigenfunctionout,
"eigenfunction.h5");
1428 SPI::save(leigenfunctionout,
"eigenfunction.h5");
1432 std::tie(eigenvalue,cg,leigenfunction8,eigenfunction8) =
SPI::LST_spatial_cg(params,grid2,bl_flow);
1434 test_if_close(params.
alpha*1.7208,(0.74155+0.345132*PETSC_i),
"LST_spatial_cg physical 1",1e-5);
1435 SPI::save(eigenfunction8,
"eigenfunction.h5");
1436 SPI::save(leigenfunction8,
"eigenfunction.h5");
1439 PetscScalar deltaOmega = 1e-2;
1440 params.
omega += deltaOmega;
1441 PetscScalar deltaeigenvalue;
1442 std::tie(deltaeigenvalue,cg,leigenfunction8,eigenfunction8) =
SPI::LST_spatial_cg(params,grid2,bl_flow);
1443 SPI::printfc(
"with delta_omega cg = %.10f + %.10fi",cg);
1444 cg = deltaOmega/(deltaeigenvalue-eigenvalue);
1445 SPI::printfc(
"with finite diff delta_omega cg = %.10f + %.10fi",cg);
1446 params.
omega -= 2.0*deltaOmega;
1447 PetscScalar deltaeigenvaluem;
1448 std::tie(deltaeigenvaluem,cg,leigenfunction8,eigenfunction8) =
SPI::LST_spatial_cg(params,grid,bl_flow);
1449 cg = (2.0*deltaOmega)/(deltaeigenvalue-deltaeigenvaluem);
1450 SPI::printfc(
"with finite diff delta_omega2 cg = %.10f + %.10fi",cg);
1473 SPI::printf(
"------------ LST_spatial_cg Blasius boundary layer UltraS end -----------");
1476 SPI::printf(
"------------ LSTNP_spatial Blasius boundary layer UltraS start -----------");
1492 params.
Re = 1000.0/1.7208;
1493 params.
omega = 0.26/1.7208;
1494 params.
nu = 1./params.
Re;
1495 params.
x = params.
Re;
1497 params.
alpha = (0.74155+0.345132*PETSC_i)/1.7208;
1505 PetscScalar eigenvalue;
1506 eigenfunction.
name =
"eigenfunction";
1520 std::tie(eigenvalue,cg,leigenfunction,eigenfunction) =
SPI::LSTNP_spatial(params,grid,bl_flow);
1523 test_if_close(params.
alpha*1.7208,(0.74155+0.345132*PETSC_i),
"LSTNP_spatial UltraS 1",1e-4);
1527 {t,O,O,O,O,O,O,O,O,O,O,O,O,O,O,O},
1528 {O,t,O,O,O,O,O,O,O,O,O,O,O,O,O,O},
1529 {O,O,t,O,O,O,O,O,O,O,O,O,O,O,O,O},
1530 {O,O,O,t,O,O,O,O,O,O,O,O,O,O,O,O},
1531 {O,O,O,O,t,O,O,O,O,O,O,O,O,O,O,O},
1532 {O,O,O,O,O,t,O,O,O,O,O,O,O,O,O,O},
1533 {O,O,O,O,O,O,t,O,O,O,O,O,O,O,O,O},
1534 {O,O,O,O,O,O,O,t,O,O,O,O,O,O,O,O},
1535 {O,O,O,O,O,O,O,O,t,O,O,O,O,O,O,O},
1536 {O,O,O,O,O,O,O,O,O,t,O,O,O,O,O,O},
1537 {O,O,O,O,O,O,O,O,O,O,t,O,O,O,O,O},
1538 {O,O,O,O,O,O,O,O,O,O,O,t,O,O,O,O},
1539 {O,O,O,O,O,O,O,O,O,O,O,O,t,O,O,O},
1540 {O,O,O,O,O,O,O,O,O,O,O,O,O,t,O,O},
1541 {O,O,O,O,O,O,O,O,O,O,O,O,O,O,t,O},
1542 {O,O,O,O,O,O,O,O,O,O,O,O,O,O,O,t},
1544 SPI::SPIVec eigenfunctionout(T*eigenfunction,
"UltraS");
1545 SPI::SPIVec leigenfunctionout(T*leigenfunction,
"UltraSl");
1552 std::tie(eigenvalue,cg,leigenfunction16,eigenfunction16) =
SPI::LSTNP_spatial(params,grid2,bl_flow);
1554 test_if_close(params.
alpha*1.7208,(0.74155+0.345132*PETSC_i),
"LSTNP_spatial physical 1",1e-4);
1556 std::tie(eigenvalue,cg,leigenfunction,eigenfunction) =
SPI::LSTNP_spatial(params,grid2,bl_flow);
1558 test_if_close(params.
alpha*1.7208,(0.74155+0.345132*PETSC_i),
"LSTNP_spatial physical 1",1e-4);
1560 params.
alpha = (0.54213+0.083968*PETSC_i)/1.7208;
1561 std::tie(eigenvalue,cg,leigenfunction,eigenfunction) =
SPI::LSTNP_spatial(params,grid,bl_flow);
1563 test_if_close(params.
alpha*1.7208,(0.54213+0.083968*PETSC_i),
"LSTNP_spatial UltraS 2",1e-5);
1565 params.
alpha = (0.29967+0.230773*PETSC_i)/1.7208;
1566 std::tie(eigenvalue,cg,leigenfunction,eigenfunction) =
SPI::LSTNP_spatial(params,grid,bl_flow);
1568 test_if_close(params.
alpha*1.7208,(0.29967+0.230773*PETSC_i),
"LSTNP_spatial UltraS 3",1e-5);
1570 SPI::printf(
"------------ LSTNP_spatial Blasius boundary layer UltraS end -----------");
1573 SPI::printf(
"------------ LSTNP_spatial_right Blasius boundary layer UltraS start -----------");
1589 params.
Re = 1000.0/1.7208;
1590 params.
omega = 0.26/1.7208;
1591 params.
nu = 1./params.
Re;
1592 params.
x = params.
Re;
1594 params.
alpha = (0.74155+0.345132*PETSC_i)/1.7208;
1601 PetscScalar eigenvalue;
1602 eigenfunction.
name =
"eigenfunction";
1617 test_if_close(params.
alpha*1.7208,(0.74155+0.345132*PETSC_i),
"LSTNP_spatial_right UltraS 1",1e-4);
1621 {t,O,O,O,O,O,O,O,O,O,O,O,O,O,O,O},
1622 {O,t,O,O,O,O,O,O,O,O,O,O,O,O,O,O},
1623 {O,O,t,O,O,O,O,O,O,O,O,O,O,O,O,O},
1624 {O,O,O,t,O,O,O,O,O,O,O,O,O,O,O,O},
1625 {O,O,O,O,t,O,O,O,O,O,O,O,O,O,O,O},
1626 {O,O,O,O,O,t,O,O,O,O,O,O,O,O,O,O},
1627 {O,O,O,O,O,O,t,O,O,O,O,O,O,O,O,O},
1628 {O,O,O,O,O,O,O,t,O,O,O,O,O,O,O,O},
1629 {O,O,O,O,O,O,O,O,t,O,O,O,O,O,O,O},
1630 {O,O,O,O,O,O,O,O,O,t,O,O,O,O,O,O},
1631 {O,O,O,O,O,O,O,O,O,O,t,O,O,O,O,O},
1632 {O,O,O,O,O,O,O,O,O,O,O,t,O,O,O,O},
1633 {O,O,O,O,O,O,O,O,O,O,O,O,t,O,O,O},
1634 {O,O,O,O,O,O,O,O,O,O,O,O,O,t,O,O},
1635 {O,O,O,O,O,O,O,O,O,O,O,O,O,O,t,O},
1636 {O,O,O,O,O,O,O,O,O,O,O,O,O,O,O,t},
1638 SPI::SPIVec eigenfunctionout(T*eigenfunction,
"UltraS");
1645 test_if_close(params.
alpha*1.7208,(0.74155+0.345132*PETSC_i),
"LSTNP_spatial_right physical 1",1e-4);
1648 test_if_close(params.
alpha*1.7208,(0.74155+0.345132*PETSC_i),
"LSTNP_spatial_right physical 1",1e-4);
1650 params.
alpha = (0.54213+0.083968*PETSC_i)/1.7208;
1652 test_if_close(params.
alpha*1.7208,(0.54213+0.083968*PETSC_i),
"LSTNP_spatial_right UltraS 2",1e-5);
1654 params.
alpha = (0.29967+0.230773*PETSC_i)/1.7208;
1656 test_if_close(params.
alpha*1.7208,(0.29967+0.230773*PETSC_i),
"LSTNP_spatial_right UltraS 3",1e-5);
1658 SPI::printf(
"------------ LSTNP_spatial_right Blasius boundary layer UltraS end -----------");
1661 SPI::printf(
"------------ LSTNP_spatials_right Blasius boundary layer UltraS start -----------");
1677 params.
Re = 1000.0/1.7208;
1678 params.
omega = 0.26/1.7208;
1679 params.
nu = 1./params.
Re;
1680 params.
x = params.
Re;
1682 params.
alpha = (0.74155+0.345132*PETSC_i)/1.7208;
1686 std::vector<SPI::SPIVec> eigenfunction(1);
1689 std::vector<PetscScalar> eigenvalue(1);
1690 std::vector<PetscScalar> eigenvalues;
1691 std::vector<SPI::SPIVec> eigenfunctions;
1692 eigenvalue[0] = params.
alpha;
1707 eigenvalues.push_back(params.
alpha);
1708 eigenfunctions.push_back(eigenfunction[0]);
1710 test_if_close(eigenvalue[0]*1.7208,(0.74155+0.345132*PETSC_i),
"LSTNP_spatials_right UltraS 1",1e-4);
1715 {t,O,O,O,O,O,O,O,O,O,O,O,O,O,O,O},
1716 {O,t,O,O,O,O,O,O,O,O,O,O,O,O,O,O},
1717 {O,O,t,O,O,O,O,O,O,O,O,O,O,O,O,O},
1718 {O,O,O,t,O,O,O,O,O,O,O,O,O,O,O,O},
1719 {O,O,O,O,t,O,O,O,O,O,O,O,O,O,O,O},
1720 {O,O,O,O,O,t,O,O,O,O,O,O,O,O,O,O},
1721 {O,O,O,O,O,O,t,O,O,O,O,O,O,O,O,O},
1722 {O,O,O,O,O,O,O,t,O,O,O,O,O,O,O,O},
1723 {O,O,O,O,O,O,O,O,t,O,O,O,O,O,O,O},
1724 {O,O,O,O,O,O,O,O,O,t,O,O,O,O,O,O},
1725 {O,O,O,O,O,O,O,O,O,O,t,O,O,O,O,O},
1726 {O,O,O,O,O,O,O,O,O,O,O,t,O,O,O,O},
1727 {O,O,O,O,O,O,O,O,O,O,O,O,t,O,O,O},
1728 {O,O,O,O,O,O,O,O,O,O,O,O,O,t,O,O},
1729 {O,O,O,O,O,O,O,O,O,O,O,O,O,O,t,O},
1730 {O,O,O,O,O,O,O,O,O,O,O,O,O,O,O,t},
1732 SPI::SPIVec eigenfunctionout(T*eigenfunction[0],
"UltraS");
1733 SPI::save(eigenfunctionout,
"eigenfunctionNP.h5");
1745 params.
alpha = (0.54213+0.083968*PETSC_i)/1.7208;
1746 eigenvalue[0] = params.
alpha;
1748 eigenvalues.push_back(params.
alpha);
1749 eigenfunctions.push_back(eigenfunction[0]);
1750 test_if_close(eigenvalue[0]*1.7208,(0.54213+0.083968*PETSC_i),
"LSTNP_spatials_right UltraS 2",1e-5);
1753 params.
alpha = (0.29967+0.230773*PETSC_i)/1.7208;
1754 eigenvalue[0] = params.
alpha;
1756 eigenvalues.push_back(params.
alpha);
1757 eigenfunctions.push_back(eigenfunction[0]);
1758 test_if_close(eigenvalue[0]*1.7208,(0.29967+0.230773*PETSC_i),
"LSTNP_spatials_right UltraS 3",1e-4);
1764 std::vector<PetscScalar> eigenvalues2;
1765 std::vector<SPI::SPIVec> eigenfunctions2;
1767 test_if_close(eigenvalues2[0]*1.7208,(0.74155+0.345132*PETSC_i),
"LSTNP_spatials_right UltraS 1",1e-4);
1768 test_if_close(eigenvalues2[1]*1.7208,(0.54213+0.083968*PETSC_i),
"LSTNP_spatials_right UltraS 2",1e-5);
1769 test_if_close(eigenvalues2[2]*1.7208,(0.29967+0.230773*PETSC_i),
"LSTNP_spatials_right UltraS 3",1e-5);
1771 SPI::printf(
"------------ LSTNP_spatials_right Blasius boundary layer UltraS end -----------");
1774 SPI::printf(
"------------ UltraS int start -----------");
1783 a = (grid.
That*((y^2)+(4.0*y)+1.0));
1785 a = (grid.
That*((y^2)+(4.0*y)));
1787 a = (grid.
That*(4.0*(y^2)+(y)+10.0));
1792 a = grid2.
That*(4.0*(y2^2)+(y2)+10.0);
1797 a = grid3.
That*(4.0*(y3^2)+(y3)+10.0);
1802 a = grid4.
That*(4.0*(y4^2)+(y4)+10.0);
1808 a = grid5.
That*(4.0*(y5^2)+(y5)+10.0);
1809 a2 = (4.0*(y5^2)+(y5)+10.0);
1815 a2 = (4.0*(y6^2)+(y6)+10.0);
1823 for(PetscInt i=0; i<4; ++i){
1824 for(PetscInt j=0; j<41; ++j){
1825 a7(i*41+j,tmp(j,PETSC_TRUE));
1832 SPI::printf(
"------------ UltraS int end -----------");
1835 SPI::printf(
"------------ LSTNP_spatials_right Blasius boundary layer UltraS start -----------");
1850 params.
Re = 1000.0/1.7208;
1851 params.
omega = 0.26/1.7208;
1852 params.
nu = 1./params.
Re;
1853 params.
x = params.
Re;
1855 params.
alpha = (0.74155+0.345132*PETSC_i)/1.7208;
1862 PetscScalar eigenvalue;
1863 eigenfunction.
name =
"eigenfunction";
1876 time_t timer1,timer2,timer3;
1880 std::vector<PetscScalar> alphas_guess(3);
1881 std::vector<SPI::SPIVec> eigenfunction_guess(3);
1883 alphas_guess[0] = eigenvalue;
1884 eigenfunction_guess[0] = eigenfunction;
1886 test_if_close(params.
alpha*1.7208,(0.74155+0.345132*PETSC_i),
"LSTNP_spatial_right 1",1e-4);
1888 params.
alpha = (0.54213+0.083968*PETSC_i)/1.7208;
1890 alphas_guess[1] = eigenvalue;
1891 eigenfunction_guess[1] = eigenfunction;
1892 test_if_close(params.
alpha*1.7208,(0.54213+0.083968*PETSC_i),
"LSTNP_spatial_right 2",1e-5);
1894 params.
alpha = (0.29967+0.230773*PETSC_i)/1.7208;
1896 alphas_guess[2] = eigenvalue;
1897 eigenfunction_guess[2] = eigenfunction;
1898 test_if_close(params.
alpha*1.7208,(0.29967+0.230773*PETSC_i),
"LSTNP_spatial_right 3",1e-3);
1901 std::vector<PetscScalar> alpha_spatials_right;
1902 std::vector<SPI::SPIVec> eig_vecs_spatials_right;
1903 std::tie(alpha_spatials_right,eig_vecs_spatials_right) =
SPI::LSTNP_spatials_right(params,grid,bl_flow,alphas_guess,eigenfunction_guess);
1904 test_if_close(alpha_spatials_right[0]*1.7208,(0.74155+0.345132*PETSC_i),
"LSTNP_spatials_right 1",1e-4);
1905 test_if_close(alpha_spatials_right[1]*1.7208,(0.54213+0.083968*PETSC_i),
"LSTNP_spatials_right 2",1e-5);
1906 test_if_close(alpha_spatials_right[2]*1.7208,(0.29967+0.230773*PETSC_i),
"LSTNP_spatials_right 3",1e-3);
1914 seconds = difftime(timer2,timer1);
1915 SPI::printf(
"%.10f seconds for LSTNP_spatial_right 3 solves on Blasius boundary layer",seconds);
1916 seconds = difftime(timer3,timer2);
1917 SPI::printf(
"%.10f seconds for LSTNP_spatials_right 3 solves on Blasius boundary layer",seconds);
1919 SPI::printf(
"------------ LSTNP_spatials_right Blasius boundary layer UltraS end -----------");
1922 SPI::printf(
"------------ A*x=b grid UltraS start -----------");
1929 A = grid.
Dyy + grid.
Dy + grid.
I;
1931 std::vector<PetscInt> rowBCs = {0*n,n-1};
1942 PetscScalar i=PETSC_i;
1947 std::cout<<
"error physical = "<<
SPI::L2(x-xexact)<<std::endl;
1952 A2 = grid2.
Dyy + grid2.
Dy + grid2.
I;
1957 MatSetOption(A2.
mat,MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE);
1958 for(PetscInt j=0; j<n; ++j){
1959 A2(rowBCs[0],j,grid.
T(0,j,PETSC_TRUE));
1960 A2(rowBCs[1],j,grid.
T(n-1,j,PETSC_TRUE));
1967 std::cout<<
"error UltraS = "<<
SPI::L2((grid.
T*x)-xexact)<<std::endl;
1969 std::cout<<
"error UltraS = "<<
SPI::L2((grid.
T*x)-xexact)<<std::endl;
1978 b = (4.0*y + 17.0) *
SPI::exp(4.0*y);
1989 std::cout<<
"error non-const = "<<
SPI::L2(x - xexact)<<std::endl;
1996 MatSetOption(A.
mat,MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE);
1997 for(PetscInt j=0; j<n; ++j){
1998 A(rowBCs[0],j,grid.
T(0,j,PETSC_TRUE));
1999 A(rowBCs[1],j,grid.
T(n-1,j,PETSC_TRUE));
2007 std::cout<<
"error non-const UltraS = "<<
SPI::L2(grid.
T*x - xexact)<<std::endl;
2009 SPI::printf(
"------------ A*x=b grid UltraS end -----------");
2012 SPI::printf(
"------------ LSTNP_spatials_right non-Parallel Blasius boundary layer UltraS start -----------");
2026 params.
omega = 86.*params.
Re/(1000000.);
2027 params.
nu = 1./params.
Re;
2028 params.
x = params.
Re;
2030 params.
alpha = (0.094966+0.004564*PETSC_i);
2037 PetscScalar eigenvalue,cg;
2038 eigenfunction.
name =
"eigenfunction";
2051 time_t timer1,timer2;
2057 seconds = difftime(timer2,timer1);
2058 SPI::printf(
"%.10f seconds for LSTNP_spatial_right 1 solves on Blasius boundary layer",seconds);
2059 test_if_close(params.
alpha,(0.094966355495876+0.004564261943353*PETSC_i),
"LSTNP_spatial_right 1",1e-8);
2061 std::vector<PetscScalar> alphas_guess(2);
2062 std::vector<SPI::SPIVec> eigenfunction_guess(2);
2066 seconds = difftime(timer2,timer1);
2067 SPI::printf(
"%.10f seconds for LSTNP_spatial_right 1 solves on Blasius boundary layer",seconds);
2068 alphas_guess[0] = eigenvalue;
2069 eigenfunction_guess[0] = eigenfunction;
2071 test_if_close(params.
alpha,(0.094966355495876+0.004564261943353*PETSC_i),
"LSTNP_spatial_right 1",1e-8);
2075 std::tie(eigenvalue,cg,leigenfunction,eigenfunction) =
SPI::LSTNP_spatial(params,grid,bl_flow);
2077 seconds = difftime(timer2,timer1);
2078 SPI::printf(
"%.10f seconds for LSTNP_spatial 2 solves on Blasius boundary layer",seconds);
2079 test_if_close(params.
alpha,(0.094966355495876+0.004564261943353*PETSC_i),
"LSTNP_spatial 2",1e-8);
2081 params.
alpha = (0.10665444+0.00189793*PETSC_i);
2085 seconds = difftime(timer2,timer1);
2086 SPI::printf(
"%.10f seconds for LSTNP_spatial_right 3 solves on Blasius boundary layer",seconds);
2087 alphas_guess[1] = eigenvalue;
2088 eigenfunction_guess[1] = eigenfunction;
2089 test_if_close(params.
alpha,(0.106654447306241+0.001897936897103*PETSC_i),
"LSTNP_spatial_right 3",1e-8);
2093 std::tie(eigenvalue,cg,leigenfunction,eigenfunction) =
SPI::LSTNP_spatial(params,grid,bl_flow);
2095 seconds = difftime(timer2,timer1);
2096 SPI::printf(
"%.10f seconds for LSTNP_spatial 4 solves on Blasius boundary layer",seconds);
2097 test_if_close(params.
alpha,(0.106654447306241+0.001897936897103*PETSC_i),
"LSTNP_spatial 4",1e-8);
2099 std::vector<PetscScalar> eigenvalues(2);
2100 std::vector<SPI::SPIVec> eigenfunctions(2);
2104 seconds = difftime(timer2,timer1);
2105 SPI::printf(
"%.10f seconds for LSTNP_spatials_right 5,6 solves on Blasius boundary layer",seconds);
2106 test_if_close(eigenvalues[0],(0.094966355495876+0.004564261943353*PETSC_i),
"LSTNP_spatials_right 5",1e-8);
2107 test_if_close(eigenvalues[1],(0.106654447306241+0.001897936897103*PETSC_i),
"LSTNP_spatials_right 6",1e-8);
2109 SPI::printf(
"------------ LSTNP_spatials_right non-Parallel Blasius boundary layer UltraS end -----------");
2112 SPI::printf(
"------------ LSTNP_spatials_right non-Parallel Blasius boundary layer UltraS start -----------");
2126 params.
omega = 86.*params.
Re/(1000000.);
2127 params.
nu = 1./params.
Re;
2128 params.
x = params.
Re;
2130 params.
alpha = (0.094966+0.004564*PETSC_i);
2137 PetscScalar eigenvalue,cg;
2138 eigenfunction.
name =
"eigenfunction";
2151 time_t timer1,timer2;
2157 seconds = difftime(timer2,timer1);
2158 SPI::printf(
"%.10f seconds for LSTNP_spatial_right 1 solves on Blasius boundary layer",seconds);
2159 test_if_close(params.
alpha,(0.094966355495876+0.004564261943353*PETSC_i),
"LSTNP_spatial_right 1",1e-8);
2160 SPI::printf(
"------------ LSTNP_spatials_right non-Parallel Blasius boundary layer UltraS end -----------");
2163 SPI::printf(
"------------ LSTNP_spatials_right non-Parallel Blasius boundary layer UltraS start -----------");
2242 params.
omega = 86.*params.
Re/(1000000.);
2243 params.
nu = 1./params.
Re;
2244 params.
x = params.
Re;
2246 params.
alpha = (0.094966+0.004564*PETSC_i);
2254 PetscScalar eigenvalue,eigenvalue2,cg;
2255 eigenfunction.
name =
"eigenfunction";
2268 time_t timer1,timer2;
2281 std::tie(eigenvalue2,eigenfunction2) =
SPI::LST_spatial(params,grid,bl_flow);
2283 seconds = difftime(timer2,timer1);
2284 SPI::printf(
"%.10f seconds for LSTNP_spatial_right 1 solves on Blasius boundary layer",seconds);
2285 test_if_close(eigenvalue,(0.094966355495876+0.004564261943353*PETSC_i),
"LSTNP_spatial_right 1",1e-8);
2286 SPI::printf(
"------------ LSTNP_spatials_right non-Parallel Blasius boundary layer UltraS end -----------");
2289 M(0,0,3.0); M(1,1,1.0); M(2,2,3.0); M(3,3,1.0); M();
2290 C(0,0,0.4); C(0,2,-0.3);
2291 C(2,0,-0.3); C(2,2,0.5); C(2,3,-0.2);
2292 C(3,2,-0.2); C(3,3,0.2);
2294 K(0,0,-7.0); K(0,1, 2.0); K(0,2, 4.0);
2295 K(1,0, 2.0); K(1,1,-4.0); K(1,2, 2.0);
2296 K(2,0, 4.0); K(2,1, 2.0); K(2,2,-9.0); K(2,3, 3.0);
2297 K(3,2, 3.0); K(3,3,-3.0);
2300 std::tie(eigenvalue,eigenfunction_4) =
SPI::polyeig({K,C,M},-2.4498);
2310 SPI::printf(
"------------ SVD start -----------");
2312 x(0,0.0); x(1,1.0); x(2,2.0); x(3,3.0);
2315 y(0,-1.0); y(1,0.2); y(2,0.9); y(3,2.1);
2319 A(0,0,0); A(0,1,1.0);
2320 A(1,0,1); A(1,1,1.0);
2321 A(2,0,2); A(2,1,1.0);
2322 A(3,0,3); A(3,1,1.0);
2325 std::vector<PetscReal> sigma;
2326 std::vector<SPI::SPIVec> u;
2327 std::vector<SPI::SPIVec> v;
2335 for(PetscInt j=0; j<2; ++j){
2336 xi += ((y.
dot(u[j]))/sigma[j]) * v[j];
2352 SPI::printf(
"------------ least squares start -----------");
2358 y(0,-1.0); y(1,0.2); y(2,0.9); y(3,2.1);
2361 A(0,0,0); A(0,1,1.0);
2362 A(1,0,1); A(1,1,1.0);
2363 A(2,0,2); A(2,1,1.0);
2364 A(3,0,3); A(3,1,1.0);
2372 SPI::printf(
"------------ least squares end -----------");
2375 SPI::printf(
"------------ set_col start -----------");
2377 x1(0,0.0); x1(1,1.0); x1(2,2.0); x1(3,3.0);
2381 x2(0,1.0); x2(1,1.0); x2(2,1.0); x2(3,1.0);
2391 SPI::printf(
"------------ set_col end -----------");
2394 SPI::printf(
"------------ SPIMat(std::vector<SPIVec>) and lstsq(std::vector<SPIVec>,SPIVec) start -----------");
2396 y(0,-1.0); y(1,0.2); y(2,0.9); y(3,2.1);
2399 x1(0,0.0); x1(1,1.0); x1(2,2.0); x1(3,3.0);
2402 x2(0,1.0); x2(1,1.0); x2(2,1.0); x2(3,1.0);
2404 std::vector<SPI::SPIVec> x = {x1,x2};
2411 test_if_close(xi(0,PETSC_TRUE),1.0,
"lstsq(std::vector<SPIVec>,SPIVec) 1",1e-14);
2412 test_if_close(xi(1,PETSC_TRUE),-0.95,
"lstsq(std::vector<SPIVec>,SPIVec) 2",1e-14);
2413 SPI::printf(
"------------ SPIMat(std::vector<SPIVec>) and lstsq(std::vector<SPIVec>,SPIVec) end -----------");
2416 SPI::printf(
"------------ SPIMat save start -----------");
2418 A(0,0,0.2+3.1*PETSC_i); A(0,1,1.0+4.0*PETSC_i);
2419 A(1,0,1.0+4.2*PETSC_i); A(1,1,2.0+3.0*PETSC_i);
2420 A(2,0,2.0+3.3*PETSC_i); A(2,1,3.0+2.0*PETSC_i);
2421 A(3,0,3.0+4.4*PETSC_i); A(3,1,4.0+1.0*PETSC_i);
2427 SPI::printf(
"------------ SPIMat save end -----------");
2430 SPI::printf(
"------------ SPIgrid2D.avgt start -----------");
2439 SPI::printf(
"------------ SPIgrid2D.avgt end -----------");
2442 SPI::printf(
"------------ SPIgrid interp1D_Mat start -----------");
2443 PetscInt n1=8,n2=11;
2451 std::cout<<
"L2(y2-interp*y1) = "<<
SPI::L2(grid2.
y,interp*grid1.
y)<<std::endl;
2457 SPI::printf(
"------------ SPIgrid interp1D_Mat end -----------");
2460 SPI::printf(
"------------ SPIgrid set_D_periodic start -----------");
2464 (0.5*PETSC_PI*
SPI::cos(0.5*PETSC_PI*t)).print();
2465 (Dt*(
SPI::sin(0.5*PETSC_PI*t))).print();
2466 SPI::printf(
"------------ SPIgrid set_D_periodic end -----------");
2469 SPI::printf(
"------------ SPIgrid dft and dft_dftinv_Ihalf_Ihalfn start -----------");
2475 test_if_close(FT(5,7,PETSC_TRUE),-0.0883883-0.0883883*PETSC_i,
"dft 1",1e-7);
2476 test_if_close(FT(6,7,PETSC_TRUE),0.-0.125*PETSC_i,
"dft 2",1e-7);
2478 test_if_close(FT(5,7,PETSC_TRUE),-0.0883883-0.0883883*PETSC_i,
"dft_dftinv_Ihalf_Ihalfn 1",1e-7);
2479 test_if_close(FT(6,7,PETSC_TRUE),0.-0.125*PETSC_i,
"dft_dftinv_Ihalf_Ihalfn 2",1e-7);
2480 test_if_close(FTinv(5,7,PETSC_TRUE),-0.707106781+0.0707106781*PETSC_i,
"dft_dftinv_Ihalf_Ihalfn 3",1e-7);
2481 test_if_close(FTinv(6,7,PETSC_TRUE),0.+1.*PETSC_i,
"dft_dftinv_Ihalf_Ihalfn 4",1e-7);
2482 test_if_close(Ihalf(6,6,PETSC_TRUE),0.,
"dft_dftinv_Ihalf_Ihalfn 5",1e-7);
2483 test_if_close(Ihalf(1,1,PETSC_TRUE),1.,
"dft_dftinv_Ihalf_Ihalfn 6",1e-7);
2484 test_if_close(Ihalfn(6,6,PETSC_TRUE),1.,
"dft_dftinv_Ihalf_Ihalfn 7",1e-7);
2485 test_if_close(Ihalfn(1,1,PETSC_TRUE),0.,
"dft_dftinv_Ihalf_Ihalfn 8",1e-7);
2486 SPI::printf(
"------------ SPIgrid dft and dft_dftinv_Ihalf_Ihalfn end -----------");