Kernel calculation can now align with Akvo data from the YAML.
[Merlin.git] / examples / KernelV0-2.cpp
1 /* This file is part of Lemma, a geophysical modelling and inversion API.
2 * More information is available at http://lemmasoftware.org
3 */
4
5 /* This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
9
10 /**
11 * @file
12 * @date 11/11/2016 02:44:37 PM
13 * @version $Id$
14 * @author Trevor Irons (ti)
15 * @email tirons@egi.utah.edu
16 * @copyright Copyright (c) 2016, University of Utah
17 * @copyright Copyright (c) 2016, Lemma Software, LLC
18 */
19
20 #include <Merlin>
21 using namespace Lemma;
22
23
24 int main(int argc, char** argv) {
25
26 if (argc<5) {
27 std::cout << "./KernelV0-2 Kernel.yaml TxString RxString vtkoutput<true/false> \n";
28 return(EXIT_SUCCESS);
29 }
30
31 std::cout << "Using kernel paramaters: " << argv[1] << std::endl;
32 auto Kern = KernelV0::DeSerialize( YAML::LoadFile(argv[1]) );
33
34 std::vector<std::string> tx = {std::string(argv[2])};
35 std::vector<std::string> rx = {std::string(argv[3])};
36
37 std::cout << "argv[4]\t" << argv[4] << std::endl;
38 if( std::string(argv[4]) == "true" || std::string(argv[4]) == "True") {
39 std::cout << "Using VTK, output files may be very large" << std::endl;
40 Kern->CalculateK0( tx, rx, true ); // 3rd argument is vtk output
41 } else {
42 std::cout << "not using VTK" << std::endl;
43 Kern->CalculateK0( tx, rx, false ); // 3rd argument is vtk output
44 }
45
46 // TODO fix python post-processing so this is not necessary
47 // Save in simplified format for easy python plotting
48 std::ofstream dout = std::ofstream(std::string("Tx")+std::string(argv[2])+std::string("Rx-")+std::string(argv[3])+std::string(".dat"));
49 dout << "# Transmitters: ";
50 for (auto lp : tx) {
51 dout << lp << "\t";
52 }
53 dout << "\n# Receivers: ";
54 for (auto lp : rx) {
55 dout << lp << "\t";
56 }
57 dout << "\n# Tolerance: " << Kern->GetTolerance() << std::endl;
58 dout << Kern->GetInterfaces().transpose() << std::endl;
59 dout << Kern->GetPulseDuration()*Kern->GetPulseCurrent().transpose() << std::endl;
60 dout << "#real\n";
61 dout << Kern->GetKernel().real() << std::endl;
62 dout << "#imag\n";
63 dout << Kern->GetKernel().imag() << std::endl;
64 dout.close();
65
66 // Save YAML kernel
67 std::ofstream out = std::ofstream(std::string("Tx")+std::string(argv[2])+std::string("Rx-")+std::string(argv[3])+std::string(".yaml"));
68 out << *Kern;
69 out.close();
70
71 }
72
73