Explorar el Código

working on file output a bit

master
T-bone hace 8 años
padre
commit
017dbd5310
Se han modificado 4 ficheros con 54 adiciones y 49 borrados
  1. 20
    16
      examples/KernelV0.cpp
  2. 25
    22
      examples/plotkernel.py
  3. 7
    0
      include/KernelV0.h
  4. 2
    11
      src/KernelV0.cpp

+ 20
- 16
examples/KernelV0.cpp Ver fichero

@@ -22,7 +22,10 @@ using namespace Lemma;
22 22
 
23 23
 std::shared_ptr<PolygonalWireAntenna> CircularLoop ( int nd, Real radius, Real Offsetx, Real Offsety ) ;
24 24
 
25
-int main() {
25
+int main(int argc, char** argv) {
26
+
27
+    Real offset = atof(argv[1]);
28
+        std::cout << offset << std::endl;
26 29
 
27 30
 	auto earth = LayeredEarthEM::NewSP();
28 31
 		earth->SetNumberOfLayers(3);
@@ -34,7 +37,7 @@ int main() {
34 37
 
35 38
     // Transmitter loops
36 39
     auto Tx1 = CircularLoop(21, 15, 100, 100);
37
-    auto Tx2 = CircularLoop(21, 15, 100, 124.8);
40
+    auto Tx2 = CircularLoop(21, 15, 100, 100 + offset); // 100, 115, 124.8, 130
38 41
     //auto Tx1 = CircularLoop(60, 15, 0, 0); // was 60
39 42
 
40 43
     auto Kern = KernelV0::NewSP();
@@ -44,7 +47,7 @@ int main() {
44 47
 
45 48
         Kern->SetIntegrationSize( (Vector3r() << 200,200,200).finished() );
46 49
         Kern->SetIntegrationOrigin( (Vector3r() << 0,0,0).finished() );
47
-        Kern->SetTolerance( 1e-9 );
50
+        Kern->SetTolerance( 1e-12 );
48 51
 
49 52
         Kern->SetPulseDuration(0.020);
50 53
         VectorXr I(36);
@@ -66,24 +69,25 @@ int main() {
66 69
             interfaces(ilay) = interfaces(ilay-1) + thick;
67 70
             thick *= 1.1;
68 71
         }
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
-
77 72
         Kern->SetDepthLayerInterfaces( interfaces ); // nlay, low, high
78 73
 
79 74
     // We could, I suppose, take the earth model in here? For non-linear that
80 75
     // may be more natural to work with?
81
-    //std::vector<std::string> tx = {std::string("Coil 1"), std::string("Coil 2") };
82
-    std::vector<std::string> tx = {std::string("Coil 1")};
76
+    std::vector<std::string> tx = {std::string("Coil 1"), std::string("Coil 2") };
77
+    //std::vector<std::string> tx = {std::string("Coil 1")};
83 78
     std::vector<std::string> rx = {std::string("Coil 1")};
84
-    Kern->CalculateK0( tx, rx, true );
85
-
86
-    std::ofstream out = std::ofstream("k.yaml");
79
+    Kern->CalculateK0( tx, rx, false );
80
+
81
+    std::ofstream dout = std::ofstream(std::string("k-")+ std::string(argv[1])+ std::string(".dat"));
82
+        dout << interfaces.transpose() << std::endl;
83
+        dout << I.transpose() << std::endl;
84
+        dout << "#real\n";
85
+        dout << Kern->GetKernel().real() << std::endl;
86
+        dout << "#imag\n";
87
+        dout << Kern->GetKernel().imag() << std::endl;
88
+        dout.close();
89
+
90
+    std::ofstream out = std::ofstream(std::string("k-")+std::string(argv[1])+std::string(".yaml"));
87 91
     out << *Kern;
88 92
     out.close();
89 93
 }

+ 25
- 22
examples/plotkernel.py Ver fichero

@@ -2,6 +2,11 @@ import numpy as np
2 2
 import matplotlib.pyplot as plt
3 3
 import sys
4 4
 from pylab import meshgrid
5
+from matplotlib.colors import LightSource
6
+from matplotlib.ticker import ScalarFormatter
7
+from matplotlib.ticker import MaxNLocator
8
+from matplotlib.ticker import AutoMinorLocator
9
+from matplotlib.ticker import LogLocator
5 10
 
6 11
 kf = open(sys.argv[1])
7 12
 ifaces = np.array( kf.readline().split(), dtype=np.float ) 
@@ -9,41 +14,39 @@ q = np.array( kf.readline().split(), dtype=np.float )
9 14
 q = np.append( q, (q[-1]+q[-2]) ) # for pcolor mesh
10 15
 Y,X = meshgrid( ifaces, q )   
11 16
 
12
-K = np.loadtxt(sys.argv[1], comments="#", skiprows=2)
17
+K = 1e9*np.loadtxt(sys.argv[1], comments="#", skiprows=2)
13 18
 nx, ny = np.shape(K)
14 19
 
15 20
 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] )
21
+ax1 =  fig.add_axes( [.100,.125,.335,.775] )
22
+ax2 =  fig.add_axes( [.465,.125,.335,.775] , sharex=ax1, sharey=ax1 )
23
+axcb = fig.add_axes( [.835,.125,.040,.775] )
24
+
25
+ccmap = "seismic" # RdBu
19 26
 
20 27
 # 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)) )
28
+ax1.pcolormesh(X, Y, K[0:nx//2].T, cmap=ccmap, vmin=-np.max(np.abs(K)), vmax=np.max(np.abs(K)))
22 29
 ax1.set_ylim( ifaces[-1], ifaces[0] )
23 30
 ax1.set_xlim( q[-1], q[0] )
24 31
 ax1.set_xscale("log", nonposx='clip')
25
-#plt.colorbar()
32
+ax1.minorticks_off()
33
+ax1.set_title(r"$\mathrm{Re} \left( \mathcal{K}_N^{1D} \right)$")
34
+
35
+ax1.xaxis.set_major_locator(LogLocator(base = 2.0))
36
+ax1.get_xaxis().set_major_formatter(ScalarFormatter())
26 37
 
27 38
 # 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)) )
39
+im = ax2.pcolormesh(X, Y, K[nx//2:].T, cmap=ccmap, vmin=-np.max(np.abs(K)), vmax=np.max(np.abs(K)))
29 40
 plt.setp(ax2.get_yticklabels(), visible=False)
30
-plt.colorbar(im, axcb)
41
+cb = plt.colorbar(im, axcb)
42
+cb.set_label(r"$\overline{V}^{\left(0\right)}_N$  (nV)")
31 43
 
32 44
 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
-
45
+ax1.set_xlabel(r"Pulse moment (A$\cdot$s)")
46
+ax2.set_xlabel(r"Pulse moment (A$\cdot$s)")
47
+ax2.set_title(r"$\mathrm{Im} \left( \mathcal{K}_N^{1D} \right)$")
39 48
 
40
-plt.matshow(K[0:nx//2])
41
-plt.colorbar()
49
+plt.suptitle("exp 0")
42 50
 
43
-plt.matshow(K[nx//2:])
44
-plt.colorbar()
45
-
46
-KA = np.abs(K[0:nx//2] + 1j*K[nx//2:])
47
-plt.matshow(1e9*KA, cmap='viridis')
48
-plt.colorbar()
49 51
 plt.show()
52
+exit()

+ 7
- 0
include/KernelV0.h Ver fichero

@@ -127,6 +127,13 @@ namespace Lemma {
127 127
         }		// -----  end of method KernelV0::get_SigmaModel  -----
128 128
 
129 129
         /**
130
+         * @return the kernel matrix
131
+         */
132
+        inline MatrixXcr GetKernel ( ) {
133
+            return Kern;
134
+        }
135
+
136
+        /**
130 137
          * @param[in] value the 1D-EM model used for calculations
131 138
          */
132 139
         inline void SetLayeredEarthEM ( std::shared_ptr< LayeredEarthEM > value ) {

+ 2
- 11
src/KernelV0.cpp Ver fichero

@@ -154,21 +154,12 @@ namespace Lemma {
154 154
         std::cout << "Calculating K0 kernel\n";
155 155
         Kern = MatrixXcr::Zero( Interfaces.size()-1, PulseI.size() );
156 156
         for (ilay=0; ilay<Interfaces.size()-1; ++ilay) {
157
-            std::cout << "Layer " << ilay << "\tfrom " << Interfaces(ilay) <<" to "<< Interfaces(ilay+1) << std::endl; //<< " q " << iq << std::endl;
157
+            std::cout << "Layer " << ilay << "\tfrom " << Interfaces(ilay) <<" to "<< Interfaces(ilay+1) << std::endl;
158 158
             Size(2) = Interfaces(ilay+1) - Interfaces(ilay);
159 159
             Origin(2) = Interfaces(ilay);
160 160
             IntegrateOnOctreeGrid( vtkOutput );
161 161
         }
162
-        std::cout << "\rFinished KERNEL\n";
163
-
164
-        std::ofstream out = std::ofstream("k.dat");
165
-        out << Interfaces.transpose() << std::endl;
166
-        out << PulseI.transpose() << std::endl;
167
-        out << "#real\n";
168
-        out << Kern.real() << std::endl;
169
-        out << "#imag\n";
170
-        out << Kern.imag() << std::endl;
171
-        out.close();
162
+        std::cout << "\nFinished KERNEL\n";
172 163
     }
173 164
 
174 165
     //--------------------------------------------------------------------------------------

Loading…
Cancelar
Guardar