Bladeren bron

Tweaks for looking at padding cells

master
Trevor Irons 5 jaren geleden
bovenliggende
commit
bbf9f90125
4 gewijzigde bestanden met toevoegingen van 63 en 57 verwijderingen
  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 Bestand weergeven

@@ -29,7 +29,7 @@ using namespace Lemma;
29 29
 int main( int argc, char** argv ) {
30 30
 
31 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 34
     //auto EM3D = EMSchur3D< Eigen::BiCGSTAB<Eigen::SparseMatrix<Complex, SPARSEMAJOR> > >::NewSP();
35 35
 
@@ -43,7 +43,7 @@ int main( int argc, char** argv ) {
43 43
     //auto EM3D = EMSchur3D< Eigen::SparseLU<Eigen::SparseMatrix<Complex, SPARSEMAJOR> > >::NewSP();
44 44
 
45 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 48
     // PaStiX
49 49
     //auto EM3D = EMSchur3D< Eigen::PastixLU<Eigen::SparseMatrix<Complex, SPARSEMAJOR>, true > >::NewSP();

+ 37
- 35
examples/block.py Bestand weergeven

@@ -3,25 +3,28 @@ import pprint
3 3
 
4 4
 def calcH( oxx, nxx, dxx, pad ):
5 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 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 10
         return hx, px 
11 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 29
         return hx, px
27 30
 
@@ -44,30 +47,29 @@ def writeH(fout, h, p):
44 47
             fout.write(" ")
45 48
 
46 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 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 61
     fout.write("\n// hy\n")
56
-    hy,py = calcH( args.oy[0], args.ny[0], args.dy[0], args.pad )
57 62
     writeH(fout, hy, py)
58
-    
59 63
     fout.write("\n// hz\n")
60
-    hz,pz = calcH( args.oz[0], args.nz[0], args.dz[0], args.pad )
61 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 67
     fout.write( "// vim: set filetype=cpp:\n")
66 68
 
67 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 73
     sigma[:,:,pz[1:]>0] = 0.05
72 74
     xlo = np.where( px[0:-1] >= args.bxlo[0] )[0][0] 
73 75
     xhi = np.where( px[1:] <= args.bxhi[0] )[0][-1] + 1
@@ -94,22 +96,22 @@ PAD = 0
94 96
 parser = argparse.ArgumentParser(description='Set up test EMSchur3D block problem.')
95 97
 
96 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 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 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 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 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 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 116
 parser.add_argument('dx', metavar='dx', type=int, nargs=1, 
115 117
                    help='minimum spacing in x')
@@ -149,7 +151,7 @@ px,py,pz = writeGRD(fout, args)
149 151
 fout.close()
150 152
 
151 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 156
 #print(args.nx)
155 157
 #print(args.accumulate(args.nx))

+ 10
- 7
include/EMSchur3D.h Bestand weergeven

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

+ 14
- 13
include/EMSchur3DBase.h Bestand weergeven

@@ -84,8 +84,9 @@
84 84
 
85 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 90
 #define LOWER 1  // 1=true, 0=false
90 91
 
91 92
 enum SOLVER{ SPARSELU, SimplicialLLT, SimplicialLDLT, BiCGStab, SparseQR };
@@ -443,23 +444,23 @@ class EMSchur3DBase : public LemmaObject {
443 444
     std::vector<int> idx;
444 445
 
445 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 462
     bool DirichletZHI = true;
462
-//    bool DirichletZHI = false;
463
+    //bool DirichletZHI = false;
463 464
 
464 465
     private:
465 466
 

Laden…
Annuleren
Opslaan