Browse Source

Updating for CWC-CSEM

master
Trevor Irons 6 years ago
parent
commit
ba007bdb5f

+ 10
- 2
CMakeLists.txt View File

5
 set(EMSCHUR3D_VERSION "\"${EMSCHUR3D_VERSION_MAJOR}.${EMSCHUR3D_VERSION_MINOR}.${EMSCHUR3D_VERSION_PATCH}\"")
5
 set(EMSCHUR3D_VERSION "\"${EMSCHUR3D_VERSION_MAJOR}.${EMSCHUR3D_VERSION_MINOR}.${EMSCHUR3D_VERSION_PATCH}\"")
6
 set(EMSCHUR3D_VERSION_NOQUOTES "${EMSCHUR3D_VERSION_MAJOR}.${EMSCHUR3D_VERSION_MINOR}.${EMSCHUR3D_VERSION_PATCH}")
6
 set(EMSCHUR3D_VERSION_NOQUOTES "${EMSCHUR3D_VERSION_MAJOR}.${EMSCHUR3D_VERSION_MINOR}.${EMSCHUR3D_VERSION_PATCH}")
7
 
7
 
8
-if ( LEMMA_VTK6_SUPPORT OR LEMMA_VTK7_SUPPORT ) 
8
+option ( LEMMA_MODULE_EMSCHUR3D TRUE )
9
+
10
+if ( LEMMA_VTK6_SUPPORT OR LEMMA_VTK7_SUPPORT OR LEMMA_VTK8_SUPPORT AND LEMMA_MODULE_EMSCHUR3D ) 
9
 
11
 
10
 	configure_file (
12
 	configure_file (
11
 		"${CMAKE_CURRENT_SOURCE_DIR}/config/EMSchur3DConfig.h.in"
13
 		"${CMAKE_CURRENT_SOURCE_DIR}/config/EMSchur3DConfig.h.in"
49
 	if (	LEMMA_BUILD_EXAMPLES)
51
 	if (	LEMMA_BUILD_EXAMPLES)
50
 		add_subdirectory(examples)
52
 		add_subdirectory(examples)
51
 	endif()
53
 	endif()
52
-
54
+else()
55
+	if ( LEMMA_MODULE_EMSCHUR3D )
56
+        message ( FATAL_ERROR
57
+	          "EMSChur3D requires VTK 6, 7, or 8"	
58
+		)
59
+	endif()
60
+       
53
 endif()
61
 endif()

+ 3
- 0
examples/CMakeLists.txt View File

1
 add_executable( EMSchur3D  EMSchur3D.cpp  )
1
 add_executable( EMSchur3D  EMSchur3D.cpp  )
2
+add_executable( EMSchur3D-vtk  EMSchur3D-vtk.cpp  )
2
 target_link_libraries(  EMSchur3D  "lemmacore" "fdem1d" "emschur3d")
3
 target_link_libraries(  EMSchur3D  "lemmacore" "fdem1d" "emschur3d")
4
+target_link_libraries(  EMSchur3D-vtk  "lemmacore" "fdem1d" "emschur3d")
3
 
5
 
4
 # Linking
6
 # Linking
5
 #if ( LEMMA_VTK6_SUPPORT OR LEMMA_VTK7_SUPPORT )
7
 #if ( LEMMA_VTK6_SUPPORT OR LEMMA_VTK7_SUPPORT )
16
 
18
 
17
 INSTALL_TARGETS( "/share/EMSchur3D/"
19
 INSTALL_TARGETS( "/share/EMSchur3D/"
18
     EMSchur3D
20
     EMSchur3D
21
+    EMSchur3D-vtk
19
 )
22
 )

+ 133
- 0
examples/EMSchur3D-vtk.cpp View File

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
+

+ 1
- 1
examples/EMSchur3D.cpp View File

32
     auto EM3D = EMSchur3D< Eigen::BiCGSTAB<Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::IncompleteLUT<Complex> > >::NewSP();
32
     auto EM3D = EMSchur3D< Eigen::BiCGSTAB<Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::IncompleteLUT<Complex> > >::NewSP();
33
 
33
 
34
     if (argc < 3) {
34
     if (argc < 3) {
35
-        std::cout << "EMSchur3D  <rgrid>  <1dmod>  <aemsurvey> " << std::endl;
35
+        std::cout << "EMSchur3D  <rgrid>  <1dmod> <3dmod>  <aemsurvey> " << std::endl;
36
         exit( EXIT_SUCCESS );
36
         exit( EXIT_SUCCESS );
37
     }
37
     }
38
 
38
 

+ 28
- 4
include/EMSchur3D.h View File

193
         logfile += to_string(isource) + std::string(".log");
193
         logfile += to_string(isource) + std::string(".log");
194
         ofstream logio(logfile.c_str());
194
         ofstream logio(logfile.c_str());
195
 
195
 
196
-        std::cout << "just logging" << std::endl;
196
+        std::cout << "just logging, TODO fix source" << std::endl;
197
 //        logio << *Source << std::endl;
197
 //        logio << *Source << std::endl;
198
         logio << *Grid << std::endl;
198
         logio << *Grid << std::endl;
199
         logio << *LayModel << std::endl;
199
         logio << *LayModel << std::endl;
215
 
215
 
216
         /////////////////////////////////////////
216
         /////////////////////////////////////////
217
         // Solve for RHS
217
         // Solve for RHS
218
+        CSolver[iw].setMaxIterations(10000);
218
         VectorXcr A = CSolver[iw].solve(Se);
219
         VectorXcr A = CSolver[iw].solve(Se);
219
 
220
 
220
 //         // Solve Real system instead
221
 //         // Solve Real system instead
236
                 // << " in " << iter_done << " iterations"
237
                 // << " in " << iter_done << " iterations"
237
               //<<  " with error " << errorn << "\t"
238
               //<<  " with error " << errorn << "\t"
238
               << "\tInital solution error "<<   Error.norm()  // Iteritive info
239
               << "\tInital solution error "<<   Error.norm()  // Iteritive info
239
-              << "\ttime " << timer.end() << std::endl;
240
+              << "\ttime " << timer.end() / 60. << " [m]" << std::endl;
240
 
241
 
241
         //VectorXcr ADivMAC = ADiv.array() * MAC.array().cast<Complex>();
242
         //VectorXcr ADivMAC = ADiv.array() * MAC.array().cast<Complex>();
242
         //logio << "|| Div(A) || on MAC grid " << ADivMAC.norm() << std::endl;
243
         //logio << "|| Div(A) || on MAC grid " << ADivMAC.norm() << std::endl;
252
         //Phi.array() *= MAC.array().cast<Complex>(); // remove phi from air regions
253
         //Phi.array() *= MAC.array().cast<Complex>(); // remove phi from air regions
253
 
254
 
254
         /* Restart if necessary */
255
         /* Restart if necessary */
256
+/*
255
         int nrestart(1);
257
         int nrestart(1);
256
         // TODO send MAC to implicitbicgstab?
258
         // TODO send MAC to implicitbicgstab?
257
         while (success == 2 && nrestart < 18 && iter_done > 1) {
259
         while (success == 2 && nrestart < 18 && iter_done > 1) {
259
             //Phi.array() *= MAC.array().cast<Complex>(); // remove phi from air regions
261
             //Phi.array() *= MAC.array().cast<Complex>(); // remove phi from air regions
260
             nrestart += 1;
262
             nrestart += 1;
261
         }
263
         }
264
+*/
262
 
265
 
263
         logio << "Implicit BiCGStab solution in " << iter_done << " iterations."
266
         logio << "Implicit BiCGStab solution in " << iter_done << " iterations."
264
                 << " with error " << std::setprecision(8) << std::scientific << errorn << std::endl;
267
                 << " with error " << std::setprecision(8) << std::scientific << errorn << std::endl;
265
-        logio << "time "<< timer.end() << " [s]" << std::endl;
268
+        logio << "time "<< timer.end()/60. << " [m]" << std::endl;
266
 
269
 
267
 
270
 
268
         E = ms.array()*(D.transpose()*Phi).array(); // Temp, field due to charge
271
         E = ms.array()*(D.transpose()*Phi).array(); // Temp, field due to charge
289
         // Report error of solutions
292
         // Report error of solutions
290
         Error = ((Cc.selfadjointView<Eigen::Lower>()*A).array() + E.array() - Se.array());
293
         Error = ((Cc.selfadjointView<Eigen::Lower>()*A).array() + E.array() - Se.array());
291
         logio << "\tsolution error " << Error.norm()
294
         logio << "\tsolution error " << Error.norm()
292
-              << std::fixed << std::setprecision(2) << "\ttime " << timer.end() << "\ttotal time " << timer2.end() << std::endl;
295
+              << std::fixed << std::setprecision(2) << "\ttime " << timer.end()/60. << "\ttotal time " << timer2.end()/60. << std::endl;
293
         logio.close();
296
         logio.close();
294
 
297
 
295
         //////////////////////////////////////
298
         //////////////////////////////////////
535
         }
538
         }
536
     }
539
     }
537
 
540
 
541
+    template<>
542
+    void EMSchur3D< Eigen::LeastSquaresConjugateGradient< Eigen::SparseMatrix<Complex, Eigen::RowMajor> > > ::BuildCDirectSolver() {
543
+        CSolver = new Eigen::LeastSquaresConjugateGradient< Eigen::SparseMatrix<Complex, Eigen::RowMajor> > [Omegas.size()];
544
+        for (int iw=0; iw<Omegas.size(); ++iw) {
545
+            Csym = Cvec[iw].selfadjointView<Eigen::Lower>();
546
+            jsw_timer timer;
547
+            timer.begin();
548
+            /*  Complex system */
549
+            std::cout << "LeastSquaresConjugateGradient pattern analyzing C_" << iw << ",";
550
+            std::cout.flush();
551
+            CSolver[iw].analyzePattern( Csym );
552
+            std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
553
+            // factorize
554
+            timer.begin();
555
+            std::cout << "LeastSquaresConjugateGradient factorising C_" << iw << ", ";
556
+            std::cout.flush();
557
+            CSolver[iw].factorize( Csym );
558
+            std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
559
+        }
560
+    }
561
+
538
 //     template<>
562
 //     template<>
539
 //     void EMSchur3D<   Eigen::ConjugateGradient<Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::Lower > > ::BuildCDirectSolver() {
563
 //     void EMSchur3D<   Eigen::ConjugateGradient<Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::Lower > > ::BuildCDirectSolver() {
540
 //         CSolver = new Eigen::ConjugateGradient<Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::Lower > [Omegas.size()];
564
 //         CSolver = new Eigen::ConjugateGradient<Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::Lower > [Omegas.size()];

+ 6
- 1
include/EMSchur3DBase.h View File

11
 //                  Colorado School of Mines
11
 //                  Colorado School of Mines
12
 //                  US Geological Survey
12
 //                  US Geological Survey
13
 //
13
 //
14
-//          Email:  tirons@egi.utah.edu
14
+//          Email:  Trevor.Irons@utah.edu
15
 //
15
 //
16
 // ===========================================================================
16
 // ===========================================================================
17
 
17
 
199
     /** Sets the RectilinearGrid to use
199
     /** Sets the RectilinearGrid to use
200
      *  @param[in] Grid is a pointer to the Grid to be used.
200
      *  @param[in] Grid is a pointer to the Grid to be used.
201
      */
201
      */
202
+    void SetRectilinearGrid( vtkRectilinearGrid* vtkGrid );
203
+
204
+    /** Sets the RectilinearGrid to use
205
+     *  @param[in] Grid is a pointer to the Grid to be used.
206
+     */
202
     void SetAEMSurvey( std::shared_ptr<AEMSurvey> Survey);
207
     void SetAEMSurvey( std::shared_ptr<AEMSurvey> Survey);
203
 
208
 
204
     /** Sets the prefix for results files (.log and .vtr) the source fiducial is added as well
209
     /** Sets the prefix for results files (.log and .vtr) the source fiducial is added as well

+ 11
- 0
src/EMSchur3DBase.cpp View File

858
 
858
 
859
     //--------------------------------------------------------------------------------------
859
     //--------------------------------------------------------------------------------------
860
     //       Class:  EMSchur3DBase
860
     //       Class:  EMSchur3DBase
861
+    //      Method:  SetRectilinearGrid
862
+    //--------------------------------------------------------------------------------------
863
+    void EMSchur3DBase::SetRectilinearGrid ( vtkRectilinearGrid*  rGridPtr ) {
864
+
865
+        // Convert to Lemma here
866
+
867
+
868
+    }		// -----  end of method EMSchur3DBase::SetRectilinearGrid  -----
869
+
870
+    //--------------------------------------------------------------------------------------
871
+    //       Class:  EMSchur3DBase
861
     //      Method:  Setup
872
     //      Method:  Setup
862
     //--------------------------------------------------------------------------------------
873
     //--------------------------------------------------------------------------------------
863
     void EMSchur3DBase::Setup (  ) {
874
     void EMSchur3DBase::Setup (  ) {

Loading…
Cancel
Save