Browse Source

Tweaks for looking at padding cells

master
Trevor Irons 5 years ago
parent
commit
bbf9f90125
4 changed files with 63 additions and 57 deletions
  1. 2
    2
      examples/EMSchur3D.cpp
  2. 37
    35
      examples/block.py
  3. 10
    7
      include/EMSchur3D.h
  4. 14
    13
      include/EMSchur3DBase.h

+ 2
- 2
examples/EMSchur3D.cpp View File

29
 int main( int argc, char** argv ) {
29
 int main( int argc, char** argv ) {
30
 
30
 
31
     // BiCGSTAB Diagonal preconditioner
31
     // BiCGSTAB Diagonal preconditioner
32
-    //auto EM3D = EMSchur3D< Eigen::BiCGSTAB<Eigen::SparseMatrix<Complex, SPARSEMAJOR>, Eigen::IncompleteLUT<Complex> > >::NewSP();
32
+    auto EM3D = EMSchur3D< Eigen::BiCGSTAB<Eigen::SparseMatrix<Complex, SPARSEMAJOR>, Eigen::IncompleteLUT<Complex> > >::NewSP();
33
 
33
 
34
     //auto EM3D = EMSchur3D< Eigen::BiCGSTAB<Eigen::SparseMatrix<Complex, SPARSEMAJOR> > >::NewSP();
34
     //auto EM3D = EMSchur3D< Eigen::BiCGSTAB<Eigen::SparseMatrix<Complex, SPARSEMAJOR> > >::NewSP();
35
 
35
 
43
     //auto EM3D = EMSchur3D< Eigen::SparseLU<Eigen::SparseMatrix<Complex, SPARSEMAJOR> > >::NewSP();
43
     //auto EM3D = EMSchur3D< Eigen::SparseLU<Eigen::SparseMatrix<Complex, SPARSEMAJOR> > >::NewSP();
44
 
44
 
45
     // UmfPack
45
     // UmfPack
46
-    auto EM3D = EMSchur3D< Eigen::UmfPackLU<Eigen::SparseMatrix<Complex, SPARSEMAJOR> > >::NewSP();
46
+    //auto EM3D = EMSchur3D< Eigen::UmfPackLU<Eigen::SparseMatrix<Complex, SPARSEMAJOR> > >::NewSP();
47
 
47
 
48
     // PaStiX
48
     // PaStiX
49
     //auto EM3D = EMSchur3D< Eigen::PastixLU<Eigen::SparseMatrix<Complex, SPARSEMAJOR>, true > >::NewSP();
49
     //auto EM3D = EMSchur3D< Eigen::PastixLU<Eigen::SparseMatrix<Complex, SPARSEMAJOR>, true > >::NewSP();

+ 37
- 35
examples/block.py View File

3
 
3
 
4
 def calcH( oxx, nxx, dxx, pad ):
4
 def calcH( oxx, nxx, dxx, pad ):
5
     """Calculates grid spacing along a dimension, if padding cells are requested those are incorporated too"""
5
     """Calculates grid spacing along a dimension, if padding cells are requested those are incorporated too"""
6
-    pp = 1.1 # fixed padding expansion factor 
6
+    px = np.arange(oxx, oxx+(nxx+1)*dxx, dxx)
7
+    hx = dxx*np.ones(nxx)
7
     if not pad:
8
     if not pad:
8
-        px = np.arange(oxx-dxx/2, oxx-dxx/2+(nxx+1)*dxx, dxx)
9
-        hx = dxx*np.ones(nxx)
9
+        #px = np.arange(oxx-dxx/2, oxx-dxx/2+(nxx+1)*dxx, dxx)
10
         return hx, px 
10
         return hx, px 
11
     else:
11
     else:
12
-        hx = np.zeros( nxx )
13
-        for ip in range(0,pad):
14
-            hx[ip] = dxx*pp**(pad-ip)      
15
-        hx[pad:nxx-pad] = dxx
16
-        ip = 1 
17
-        for ii in range (nxx-pad, nxx):
18
-            hx[ii] = dxx*pp**ip
19
-            ip += 1  
20
-
21
-        px = np.zeros( nxx + 1 )  # interfaces 
22
-        px[0] = oxx - (dxx*pp**pad)/2
23
-        for i, h in enumerate(hx):
24
-            px[i+1] = px[i]+h
12
+        pp = 1.1 # fixed padding expansion factor 
13
+        px_padhi = np.zeros( pad+1 )
14
+        px_padlo = np.zeros( pad+1 )
15
+        hx_pad = np.zeros( pad )
16
+        hx_pad[0] = dxx*pp
17
+        px_padhi[0] = px[-1] # hi end 
18
+        px_padlo[0] = px[0]  # lo end 
19
+        for ip in range(1,pad):
20
+            px_padhi[ip] = px_padhi[ip-1] + hx_pad[ip-1]    
21
+            px_padlo[ip] = px_padlo[ip-1] - hx_pad[ip-1]    
22
+            hx_pad[ip] = pp*hx_pad[ip-1]   
23
+        px_padhi[-1] = px_padhi[-2] + hx_pad[-1]    
24
+        px_padlo[-1] = px_padlo[-2] - hx_pad[-1]    
25
+
26
+        hx = np.concatenate((hx_pad[::-1],hx, hx_pad))
27
+        px = np.concatenate((px_padlo[1::][::-1], px, px_padhi[1::]))
25
 
28
 
26
         return hx, px
29
         return hx, px
27
 
30
 
44
             fout.write(" ")
47
             fout.write(" ")
45
 
48
 
46
 def writeGRD(fout, args):
49
 def writeGRD(fout, args):
47
-    
48
-    fout.write( "%i\t%i\t%i\t// nx ny nz\n" %(args.nx[0],args.ny[0],args.nz[0]) )
49
-    fout.write( "%f\t%f\t%f\t// ox oy oz\n" %(args.ox[0],args.oy[0],args.oz[0]) )
50
 
50
 
51
-    fout.write("\n// hx\n")
52
     hx,px = calcH( args.ox[0], args.nx[0], args.dx[0], args.pad )
51
     hx,px = calcH( args.ox[0], args.nx[0], args.dx[0], args.pad )
53
-    writeH(fout, hx, px)
52
+    hy,py = calcH( args.oy[0], args.ny[0], args.dy[0], args.pad )
53
+    hz,pz = calcH( args.oz[0], args.nz[0], args.dz[0], args.pad )
54
+    
55
+    fout.write( "%i %i %i // nx ny nz\n" %(args.nx[0]+2*args.pad,args.ny[0]+2*args.pad,args.nz[0]+2*args.pad) )
56
+    #fout.write( "%f %f %f // ox oy oz (cell centres)\n" %(args.ox[0]+args.dx[0]/2, args.oy[0]+args.dy[0]/2, args.oz[0]+args.dz[0]/2))
57
+    fout.write( "%f %f %f // ox oy oz (cell centres)\n" %(px[0]+.5*hx[0], py[0]+.5*hy[0], pz[0]+.5*hz[0]))
54
     
58
     
59
+    fout.write("\n// hx\n")
60
+    writeH(fout, hx, px)
55
     fout.write("\n// hy\n")
61
     fout.write("\n// hy\n")
56
-    hy,py = calcH( args.oy[0], args.ny[0], args.dy[0], args.pad )
57
     writeH(fout, hy, py)
62
     writeH(fout, hy, py)
58
-    
59
     fout.write("\n// hz\n")
63
     fout.write("\n// hz\n")
60
-    hz,pz = calcH( args.oz[0], args.nz[0], args.dz[0], args.pad )
61
     writeH(fout, hz, pz)
64
     writeH(fout, hz, pz)
62
 
65
 
63
-    fout.write("\n\n")
64
-    #fout.write( "// vim: set tabstop=4 expandtab:\n")
66
+    fout.write("\n")
65
     fout.write( "// vim: set filetype=cpp:\n")
67
     fout.write( "// vim: set filetype=cpp:\n")
66
 
68
 
67
     return px,py,pz
69
     return px,py,pz
68
 
70
 
69
-def writeMOD(fout, args, px, py, pz):
70
-    sigma = np.zeros( (args.nx[0], args.ny[0], args.nz[0]) )  
71
+def writeMOD(fout, args, px, py, pz, pad=0):
72
+    sigma = np.zeros( (args.nx[0]+2*pad, args.ny[0]+2*pad, args.nz[0]+2*pad) )  
71
     sigma[:,:,pz[1:]>0] = 0.05
73
     sigma[:,:,pz[1:]>0] = 0.05
72
     xlo = np.where( px[0:-1] >= args.bxlo[0] )[0][0] 
74
     xlo = np.where( px[0:-1] >= args.bxlo[0] )[0][0] 
73
     xhi = np.where( px[1:] <= args.bxhi[0] )[0][-1] + 1
75
     xhi = np.where( px[1:] <= args.bxhi[0] )[0][-1] + 1
94
 parser = argparse.ArgumentParser(description='Set up test EMSchur3D block problem.')
96
 parser = argparse.ArgumentParser(description='Set up test EMSchur3D block problem.')
95
 
97
 
96
 parser.add_argument('nx', metavar='nx', type=int, nargs=1, 
98
 parser.add_argument('nx', metavar='nx', type=int, nargs=1, 
97
-                   help='number of cells in x')
99
+                   help='number of cells in x, does NOT include padding cells')
98
 
100
 
99
 parser.add_argument('ny', metavar='ny', type=int, nargs=1, 
101
 parser.add_argument('ny', metavar='ny', type=int, nargs=1, 
100
-                   help='number of cells in y')
102
+                   help='number of cells in y, does NOT include padding cells')
101
 
103
 
102
 parser.add_argument('nz', metavar='nz', type=int, nargs=1, 
104
 parser.add_argument('nz', metavar='nz', type=int, nargs=1, 
103
-                   help='number of cells in z')
105
+                   help='number of cells in z, does NOT include padding cells')
104
 
106
 
105
 parser.add_argument('ox', metavar='ox', type=float, nargs=1, 
107
 parser.add_argument('ox', metavar='ox', type=float, nargs=1, 
106
-                   help='offset of grid in x')
108
+                   help='offset of grid in x (low edge of cell not centre), if pad is true ox should NOT include padding')
107
 
109
 
108
 parser.add_argument('oy', metavar='oy', type=float, nargs=1, 
110
 parser.add_argument('oy', metavar='oy', type=float, nargs=1, 
109
-                   help='offset of grid in y')
111
+                   help='offset of grid in y (low edge of cell not centre), if pad is true oy should NOT include padding')
110
 
112
 
111
 parser.add_argument('oz', metavar='oz', type=float, nargs=1, 
113
 parser.add_argument('oz', metavar='oz', type=float, nargs=1, 
112
-                   help='offset of grid in z')
114
+                   help='offset of grid in z (low edge of cell not centre), if pad is true oz should NOT include padding')
113
 
115
 
114
 parser.add_argument('dx', metavar='dx', type=int, nargs=1, 
116
 parser.add_argument('dx', metavar='dx', type=int, nargs=1, 
115
                    help='minimum spacing in x')
117
                    help='minimum spacing in x')
149
 fout.close()
151
 fout.close()
150
 
152
 
151
 mout = open("example.mod", 'w')
153
 mout = open("example.mod", 'w')
152
-writeMOD(mout, args, px, py, pz)
154
+writeMOD(mout, args, px, py, pz, args.pad)
153
 
155
 
154
 #print(args.nx)
156
 #print(args.nx)
155
 #print(args.accumulate(args.nx))
157
 #print(args.accumulate(args.nx))

+ 10
- 7
include/EMSchur3D.h View File

280
         success = implicitbicgstab(D, idx, ms, ADiv, Phi, CSolver[iw], max_it, tol, errorn, iter_done, logio);
280
         success = implicitbicgstab(D, idx, ms, ADiv, Phi, CSolver[iw], max_it, tol, errorn, iter_done, logio);
281
         //Phi.array() *= MAC.array().cast<Complex>(); // remove phi from air regions
281
         //Phi.array() *= MAC.array().cast<Complex>(); // remove phi from air regions
282
 
282
 
283
+
283
         /* Restart if necessary */
284
         /* Restart if necessary */
285
+/*
284
         int nrestart(1);
286
         int nrestart(1);
285
         // TODO send MAC to implicitbicgstab?
287
         // TODO send MAC to implicitbicgstab?
286
         while (success == 2 && nrestart < 18 && iter_done > 1) {
288
         while (success == 2 && nrestart < 18 && iter_done > 1) {
288
             //Phi.array() *= MAC.array().cast<Complex>(); // remove phi from air regions
290
             //Phi.array() *= MAC.array().cast<Complex>(); // remove phi from air regions
289
             nrestart += 1;
291
             nrestart += 1;
290
         }
292
         }
293
+*/
291
 
294
 
292
         logio << "Implicit BiCGStab solution in " << iter_done << " iterations."
295
         logio << "Implicit BiCGStab solution in " << iter_done << " iterations."
293
                 << " with error " << std::setprecision(8) << std::scientific << errorn << std::endl;
296
                 << " with error " << std::setprecision(8) << std::scientific << errorn << std::endl;
637
     void EMSchur3D< Eigen::BiCGSTAB<Eigen::SparseMatrix<Complex, SPARSEMAJOR>, Eigen::IncompleteLUT<Complex> > > ::BuildCDirectSolver() {
640
     void EMSchur3D< Eigen::BiCGSTAB<Eigen::SparseMatrix<Complex, SPARSEMAJOR>, Eigen::IncompleteLUT<Complex> > > ::BuildCDirectSolver() {
638
         CSolver = new Eigen::BiCGSTAB<Eigen::SparseMatrix<Complex, SPARSEMAJOR>, Eigen::IncompleteLUT<Complex> > [Omegas.size()];
641
         CSolver = new Eigen::BiCGSTAB<Eigen::SparseMatrix<Complex, SPARSEMAJOR>, Eigen::IncompleteLUT<Complex> > [Omegas.size()];
639
         for (int iw=0; iw<Omegas.size(); ++iw) {
642
         for (int iw=0; iw<Omegas.size(); ++iw) {
640
-            Csym = Cvec[iw].selfadjointView<Eigen::Lower>();
641
-            CSolver[iw].preconditioner().setDroptol(1e-6);       //1e-5);      // 1e-12
642
-            CSolver[iw].preconditioner().setFillfactor(5e1);     // 1e2
643
+            //Csym = Cvec[iw].selfadjointView<Eigen::Lower>();
644
+            CSolver[iw].preconditioner().setDroptol(1e-5);       //1e-5);      // 1e-12
645
+            CSolver[iw].preconditioner().setFillfactor(1e1);     // 1e2
643
             jsw_timer timer;
646
             jsw_timer timer;
644
             timer.begin();
647
             timer.begin();
645
             /*  Complex system */
648
             /*  Complex system */
646
             std::cout << "BiCGSTAB(ILU) pattern analyzing C_" << iw << ",";
649
             std::cout << "BiCGSTAB(ILU) pattern analyzing C_" << iw << ",";
647
             std::cout.flush();
650
             std::cout.flush();
648
-            CSolver[iw].analyzePattern( Csym );
649
-            //CSolver[iw].analyzePattern( Cvec[iw]);
651
+            //CSolver[iw].analyzePattern( Csym );
652
+            CSolver[iw].analyzePattern( Cvec[iw]);
650
             std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
653
             std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
651
             /* factorize */
654
             /* factorize */
652
             timer.begin();
655
             timer.begin();
653
             std::cout << "BiCGSTAB(ILU) factorising C_" << iw << ", ";
656
             std::cout << "BiCGSTAB(ILU) factorising C_" << iw << ", ";
654
             std::cout.flush();
657
             std::cout.flush();
655
-            CSolver[iw].factorize( Csym );
656
-            //CSolver[iw].factorize( Cvec[iw] );
658
+            //CSolver[iw].factorize( Csym );
659
+            CSolver[iw].factorize( Cvec[iw] );
657
             std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
660
             std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
658
         }
661
         }
659
     }
662
     }

+ 14
- 13
include/EMSchur3DBase.h View File

84
 
84
 
85
 namespace Lemma {
85
 namespace Lemma {
86
 
86
 
87
-// Pardiso likes LOWER for Sym problem
88
-#define UPPER 1  // LOWER WAS 0
87
+// Pardiso likes LOWER for Sym problem,
88
+//         for non-symmetric, set both to 1
89
+#define UPPER 1  // 1=true, 0=false
89
 #define LOWER 1  // 1=true, 0=false
90
 #define LOWER 1  // 1=true, 0=false
90
 
91
 
91
 enum SOLVER{ SPARSELU, SimplicialLLT, SimplicialLDLT, BiCGStab, SparseQR };
92
 enum SOLVER{ SPARSELU, SimplicialLLT, SimplicialLDLT, BiCGStab, SparseQR };
443
     std::vector<int> idx;
444
     std::vector<int> idx;
444
 
445
 
445
     /** Dirichlet on low X */
446
     /** Dirichlet on low X */
446
-    //bool DirichletXLO = true;
447
-    bool DirichletXLO = false;
447
+    bool DirichletXLO = true;
448
+    //bool DirichletXLO = false;
448
 
449
 
449
-    //bool DirichletXHI = true;
450
-    bool DirichletXHI = false;
450
+    bool DirichletXHI = true;
451
+    //bool DirichletXHI = false;
451
 
452
 
452
-    //bool DirichletYLO = true;
453
-    bool DirichletYLO = false;
453
+    bool DirichletYLO = true;
454
+    //bool DirichletYLO = false;
454
 
455
 
455
-    //bool DirichletYHI = true;
456
-    bool DirichletYHI = false;
456
+    bool DirichletYHI = true;
457
+    //bool DirichletYHI = false;
457
 
458
 
458
-//    bool DirichletZLO = true;
459
-    bool DirichletZLO = false;
459
+    bool DirichletZLO = true;
460
+    //bool DirichletZLO = false;
460
 
461
 
461
     bool DirichletZHI = true;
462
     bool DirichletZHI = true;
462
-//    bool DirichletZHI = false;
463
+    //bool DirichletZHI = false;
463
 
464
 
464
     private:
465
     private:
465
 
466
 

Loading…
Cancel
Save