VTK output in kernel calulation as an option
[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<3) {
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") {
39 Kern->CalculateK0( tx, rx, true ); // 3rd argument is vtk output
40 } else {
41 std::cout << "not using VTK" << std::endl;
42 Kern->CalculateK0( tx, rx, false ); // 3rd argument is vtk output
43 }
44
45 // TODO fix python post-processing so this is not necessary
46 // Save in simplified format for easy python plotting
47 std::ofstream dout = std::ofstream(std::string("Tx")+std::string(argv[2])+std::string("Rx-")+std::string(argv[3])+std::string(".dat"));
48 dout << "# Transmitters: ";
49 for (auto lp : tx) {
50 dout << lp << "\t";
51 }
52 dout << "\n# Receivers: ";
53 for (auto lp : rx) {
54 dout << lp << "\t";
55 }
56 dout << "\n# Tolerance: " << Kern->GetTolerance() << std::endl;
57 dout << Kern->GetInterfaces().transpose() << std::endl;
58 dout << Kern->GetPulseDuration()*Kern->GetPulseCurrent().transpose() << std::endl;
59 dout << "#real\n";
60 dout << Kern->GetKernel().real() << std::endl;
61 dout << "#imag\n";
62 dout << Kern->GetKernel().imag() << std::endl;
63 dout.close();
64
65 // Save YAML kernel
66 std::ofstream out = std::ofstream(std::string("Tx")+std::string(argv[2])+std::string("Rx-")+std::string(argv[3])+std::string(".yaml"));
67 out << *Kern;
68 out.close();
69
70 }
71
72