Parcourir la source

kernel plotting and working on spacing bug, may have just been an illusion.

master
Trevor Irons il y a 8 ans
Parent
révision
6e5f0f3651
3 fichiers modifiés avec 55 ajouts et 9 suppressions
  1. 18
    7
      examples/KernelV0.cpp
  2. 33
    1
      examples/plotkernel.py
  3. 4
    1
      src/KernelV0.cpp

+ 18
- 7
examples/KernelV0.cpp Voir le fichier

@@ -44,10 +44,11 @@ int main() {
44 44
 
45 45
         Kern->SetIntegrationSize( (Vector3r() << 200,200,200).finished() );
46 46
         Kern->SetIntegrationOrigin( (Vector3r() << 0,0,0).finished() );
47
-        Kern->SetTolerance( 1e-10 );
47
+        Kern->SetTolerance( 1e-9 );
48 48
 
49 49
         Kern->SetPulseDuration(0.020);
50 50
         VectorXr I(36);
51
+        // Pulses from Wyoming Red Buttes exp 0
51 52
         I << 397.4208916184016, 352.364477036168, 313.0112765842783, 278.37896394065376, 247.81424224324982,
52 53
              220.77925043190442, 196.76493264105017, 175.31662279234038, 156.0044839325404, 138.73983004230124,
53 54
              123.42064612625474, 109.82713394836259, 97.76534468972267, 87.06061858367781, 77.56000002944572, 69.1280780096311,
@@ -59,20 +60,30 @@ int main() {
59 60
         Kern->SetPulseCurrent( I ); // nbins, low, high
60 61
 
61 62
         //Kern->SetDepthLayerInterfaces( VectorXr::LinSpaced( 30, 3, 45.5 ) ); // nlay, low, high
62
-        //10**np.linspace(np.log10(10),np.log10(19),10)
63
-        VectorXr interfaces = VectorXr::LinSpaced(21, std::log10(2), std::log10(50)); // 30 log spaced
64
-        for (int i=0; i<interfaces.size(); ++i) {
65
-            interfaces(i) = std::pow(10, interfaces(i));
63
+        VectorXr interfaces = VectorXr::LinSpaced( 31, 1, 45.5 ); // nlay, low, high
64
+        Real thick = .5;
65
+        for (int ilay=1; ilay<interfaces.size(); ++ilay) {
66
+            interfaces(ilay) = interfaces(ilay-1) + thick;
67
+            thick *= 1.1;
66 68
         }
69
+        // TODO log spacing results in a strange transposition of the matrix? Difficult to understand
70
+        //10**np.linspace(np.log10(10),np.log10(19),10)
71
+//         VectorXr interfaces2 = VectorXr::LinSpaced(31, std::log10(2), std::log10(150)); // 30 log spaced
72
+//         for (int i=0; i<interfaces2.size(); ++i) {
73
+//             interfaces(i) = std::pow(10, interfaces2(i));
74
+//         }
75
+//         std::cout << interfaces << std::endl;
76
+
67 77
         Kern->SetDepthLayerInterfaces( interfaces ); // nlay, low, high
68 78
 
69 79
     // We could, I suppose, take the earth model in here? For non-linear that
70 80
     // may be more natural to work with?
71
-    std::vector<std::string> tx = {std::string("Coil 1"), std::string("Coil 2") };
81
+    //std::vector<std::string> tx = {std::string("Coil 1"), std::string("Coil 2") };
82
+    std::vector<std::string> tx = {std::string("Coil 1")};
72 83
     std::vector<std::string> rx = {std::string("Coil 1")};
73 84
     Kern->CalculateK0( tx, rx, true );
74 85
 
75
-    ofstream out = ofstream("k.yaml");
86
+    std::ofstream out = std::ofstream("k.yaml");
76 87
     out << *Kern;
77 88
     out.close();
78 89
 }

+ 33
- 1
examples/plotkernel.py Voir le fichier

@@ -1,10 +1,42 @@
1 1
 import numpy as np
2 2
 import matplotlib.pyplot as plt
3 3
 import sys
4
+from pylab import meshgrid
4 5
 
5
-K = np.loadtxt(sys.argv[1], comments="#")
6
+kf = open(sys.argv[1])
7
+ifaces = np.array( kf.readline().split(), dtype=np.float ) 
8
+q = np.array( kf.readline().split(), dtype=np.float ) 
9
+q = np.append( q, (q[-1]+q[-2]) ) # for pcolor mesh
10
+Y,X = meshgrid( ifaces, q )   
11
+
12
+K = np.loadtxt(sys.argv[1], comments="#", skiprows=2)
6 13
 nx, ny = np.shape(K)
7 14
 
15
+fig = plt.figure( )
16
+ax1 = fig.add_axes( [.10,.10,.35,.80] )
17
+ax2 = fig.add_axes( [.5,.10,.35,.80], sharex=ax1, sharey=ax1 )
18
+axcb = fig.add_axes( [.9,.10,.05,.80] )
19
+
20
+# Real plot
21
+ax1.pcolormesh(X, Y, K[0:nx//2].T , cmap="RdBu", vmin=-np.max(np.abs(K)), vmax=np.max(np.abs(K)) )
22
+ax1.set_ylim( ifaces[-1], ifaces[0] )
23
+ax1.set_xlim( q[-1], q[0] )
24
+ax1.set_xscale("log", nonposx='clip')
25
+#plt.colorbar()
26
+
27
+# imaginary 
28
+im = ax2.pcolormesh(X, Y, K[nx//2:].T , cmap="RdBu", vmin=-np.max(np.abs(K)), vmax=np.max(np.abs(K)) )
29
+plt.setp(ax2.get_yticklabels(), visible=False)
30
+plt.colorbar(im, axcb)
31
+
32
+ax1.set_ylabel("Depth (m)")
33
+ax1.set_xlabel("Pulse moment (A$\cdot$s)")
34
+ax2.set_xlabel("Pulse moment (A$\cdot$s)")
35
+
36
+plt.show()
37
+exit()
38
+
39
+
8 40
 plt.matshow(K[0:nx//2])
9 41
 plt.colorbar()
10 42
 

+ 4
- 1
src/KernelV0.cpp Voir le fichier

@@ -160,7 +160,10 @@ namespace Lemma {
160 160
             IntegrateOnOctreeGrid( vtkOutput );
161 161
         }
162 162
         std::cout << "\rFinished KERNEL\n";
163
-        ofstream out = ofstream("k.dat");
163
+
164
+        std::ofstream out = std::ofstream("k.dat");
165
+        out << Interfaces.transpose() << std::endl;
166
+        out << PulseI.transpose() << std::endl;
164 167
         out << "#real\n";
165 168
         out << Kern.real() << std::endl;
166 169
         out << "#imag\n";

Chargement…
Annuler
Enregistrer