|
@@ -0,0 +1,133 @@
|
|
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 01/04/2018 04:34:54 PM
|
|
13
|
+ * @version $Id$
|
|
14
|
+ * @author Trevor Irons (ti)
|
|
15
|
+ * @email tirons@egi.utah.edu
|
|
16
|
+ * @copyright Copyright (c) 2018, University of Utah
|
|
17
|
+ * @copyright Copyright (c) 2018, Lemma Software, LLC
|
|
18
|
+ */
|
|
19
|
+
|
|
20
|
+#include <LemmaCore>
|
|
21
|
+//#include "RectilinearGridReader.h"
|
|
22
|
+//#include "AEMSurveyReader.h"
|
|
23
|
+#include "EMSchur3D.h"
|
|
24
|
+//#include "LayeredEarthEMReader.h"
|
|
25
|
+//#include "CSymSimplicialCholesky.h"
|
|
26
|
+
|
|
27
|
+#include "vtkRectilinearGridReader.h"
|
|
28
|
+
|
|
29
|
+using namespace Lemma;
|
|
30
|
+
|
|
31
|
+int main( int argc, char** argv ) {
|
|
32
|
+
|
|
33
|
+ if (argc < 3) {
|
|
34
|
+ std::cout << "EMSchur3D <rgrid.vtr> <1dmod> <source> " << std::endl;
|
|
35
|
+ std::cout << "\trgrid.vtr - VTK Rectilinear grid file containing 3D conductivity structure.\n";
|
|
36
|
+ exit( EXIT_SUCCESS );
|
|
37
|
+ }
|
|
38
|
+
|
|
39
|
+ #ifdef LEMMAUSEOMP
|
|
40
|
+ std::cout << "Eigen is using OpenMP.\n";
|
|
41
|
+ Eigen::initParallel();
|
|
42
|
+ #endif
|
|
43
|
+
|
|
44
|
+ ///////////////////////////////////////////////////
|
|
45
|
+ // Read in VTK Grid
|
|
46
|
+ auto vtr = vtkSmartPointer<vtkRectilinearGridReader>::New();
|
|
47
|
+ vtr->SetFileName( argv[1] );
|
|
48
|
+ if (!vtr->OpenVTKFile()) {
|
|
49
|
+ std::cout << "Failed to open VTK file " << argv[1] << std::endl;
|
|
50
|
+ return EXIT_FAILURE;
|
|
51
|
+ }
|
|
52
|
+ vtr->Update();
|
|
53
|
+ //std::cout << *vtr->GetOutput() << std::endl;
|
|
54
|
+ auto gimp = RectilinearGridVTKImporter::NewSP();
|
|
55
|
+ gimp->SetVTKInput( vtr->GetOutput() );
|
|
56
|
+ gimp->ConvertGrid( 0, 0, 2150 );
|
|
57
|
+
|
|
58
|
+ //////////////////////////////////////////////////
|
|
59
|
+ // Read in Layered earth, for backgound model
|
|
60
|
+ auto layeredEarth = LayeredEarthEM::DeSerialize( YAML::LoadFile(argv[2]) );
|
|
61
|
+
|
|
62
|
+ /*
|
|
63
|
+
|
|
64
|
+ ///////////////////////////////////////////////////
|
|
65
|
+ // Read in Grid
|
|
66
|
+ auto GridRead = RectilinearGridReader::NewSP();
|
|
67
|
+ try {
|
|
68
|
+ GridRead->ReadASCIIGridFile( argv[1] );
|
|
69
|
+ } catch (std::exception& e) {
|
|
70
|
+ std::cout << "Caught an error opening ASCII Grid file: ";
|
|
71
|
+ std::cout << e.what() << std::endl;
|
|
72
|
+ std::cout << "enter filename or 0 to exit programme\n";
|
|
73
|
+ std::string inp;
|
|
74
|
+ std::cin >> inp;
|
|
75
|
+ if (inp != "0")
|
|
76
|
+ GridRead->ReadASCIIGridFile( inp.c_str() );
|
|
77
|
+ else exit(EXIT_FAILURE);
|
|
78
|
+ }
|
|
79
|
+
|
|
80
|
+ //////////////////////////////////////////////////
|
|
81
|
+ // Read in Layered earth, for backgound model
|
|
82
|
+ auto LayEarthRead = LayeredEarthEMReader::NewSP();
|
|
83
|
+ try {
|
|
84
|
+ LayEarthRead->ReadASCIIInputFile( argv[2] );
|
|
85
|
+ } catch (std::exception& e) {
|
|
86
|
+ std::cout << "Caught an error opening ASCII Layered Earth file: ";
|
|
87
|
+ std::cout << e.what() << std::endl;
|
|
88
|
+ std::cout << "enter filename or 0 to exit programme\n";
|
|
89
|
+ std::string inp;
|
|
90
|
+ std::cin >> inp;
|
|
91
|
+ if (inp != "0")
|
|
92
|
+ LayEarthRead->ReadASCIIGridFile( inp.c_str() );
|
|
93
|
+ else exit(EXIT_FAILURE);
|
|
94
|
+ }
|
|
95
|
+ */
|
|
96
|
+
|
|
97
|
+ //////////////////////////////////////////////////
|
|
98
|
+ // Read in source specification
|
|
99
|
+ auto AEMRead = AEMSurveyReader::NewSP();
|
|
100
|
+ try{
|
|
101
|
+ AEMRead->ReadASCIIAEMFile(argv[4]);
|
|
102
|
+ } catch (std::exception& e) {
|
|
103
|
+ std::cout << "Caught an error opening ASCII AEM file: ";
|
|
104
|
+ std::cout << e.what() << std::endl;
|
|
105
|
+ std::cout << "enter filename or 0 to exit programme\n";
|
|
106
|
+ std::string inp;
|
|
107
|
+ std::cin >> inp;
|
|
108
|
+ if (inp != "0")
|
|
109
|
+ AEMRead->ReadASCIIAEMFile( inp.c_str() );
|
|
110
|
+ else exit(EXIT_FAILURE);
|
|
111
|
+ }
|
|
112
|
+
|
|
113
|
+ //////////////////////////////////////////////////
|
|
114
|
+ // And solve
|
|
115
|
+ // Use BiCGSTAB Diagonal preconditioner
|
|
116
|
+ //auto EM3D = EMSchur3D< Eigen::BiCGSTAB<Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::IncompleteLUT<Complex> > >::NewSP();
|
|
117
|
+ //auto EM3D = EMSchur3D< Eigen::BiCGSTAB<Eigen::SparseMatrix<Complex, Eigen::RowMajor> > >::NewSP();
|
|
118
|
+ auto EM3D = EMSchur3D< Eigen::LeastSquaresConjugateGradient<Eigen::SparseMatrix<Complex, Eigen::RowMajor> > >::NewSP();
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+ EM3D->SetRectilinearGrid( gimp->GetGrid() );
|
|
122
|
+
|
|
123
|
+ EM3D->SetLayeredEarthEM( layeredEarth );
|
|
124
|
+ EM3D->SetAEMSurvey( AEMRead->GetSurvey() );
|
|
125
|
+ EM3D->LoadMeshToolsConductivityModel( argv[3] );
|
|
126
|
+ EM3D->SetResFileName(argv[5]);
|
|
127
|
+
|
|
128
|
+ //EM3D->SetCSolver( Lemma::SPARSELU ); // Lemma::BiCGSTAB );
|
|
129
|
+ EM3D->Solve();
|
|
130
|
+
|
|
131
|
+ exit(EXIT_SUCCESS);
|
|
132
|
+}
|
|
133
|
+
|