123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- /* This file is part of Lemma, a geophysical modelling and inversion API.
- * More information is available at http://lemmasoftware.org
- */
-
- /* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- */
-
- /**
- * @file
- * @date 01/04/2018 04:34:54 PM
- * @version $Id$
- * @author Trevor Irons (ti)
- * @email tirons@egi.utah.edu
- * @copyright Copyright (c) 2018, University of Utah
- * @copyright Copyright (c) 2018, Lemma Software, LLC
- */
-
- #include <LemmaCore>
- //#include "RectilinearGridReader.h"
- //#include "AEMSurveyReader.h"
- #include "EMSchur3D.h"
- //#include "LayeredEarthEMReader.h"
- //#include "CSymSimplicialCholesky.h"
-
- #include "vtkRectilinearGridReader.h"
-
- using namespace Lemma;
-
- int main( int argc, char** argv ) {
-
- if (argc < 3) {
- std::cout << "EMSchur3D <rgrid.vtr> <1dmod> <source> " << std::endl;
- std::cout << "\trgrid.vtr - VTK Rectilinear grid file containing 3D conductivity structure.\n";
- exit( EXIT_SUCCESS );
- }
-
- #ifdef LEMMAUSEOMP
- std::cout << "Eigen is using OpenMP.\n";
- Eigen::initParallel();
- #endif
-
- ///////////////////////////////////////////////////
- // Read in VTK Grid
- auto vtr = vtkSmartPointer<vtkRectilinearGridReader>::New();
- vtr->SetFileName( argv[1] );
- if (!vtr->OpenVTKFile()) {
- std::cout << "Failed to open VTK file " << argv[1] << std::endl;
- return EXIT_FAILURE;
- }
- vtr->Update();
- //std::cout << *vtr->GetOutput() << std::endl;
- auto gimp = RectilinearGridVTKImporter::NewSP();
- gimp->SetVTKInput( vtr->GetOutput() );
- gimp->ConvertGrid( 0, 0, 2150 );
-
- //////////////////////////////////////////////////
- // Read in Layered earth, for backgound model
- auto layeredEarth = LayeredEarthEM::DeSerialize( YAML::LoadFile(argv[2]) );
-
- /*
-
- ///////////////////////////////////////////////////
- // Read in Grid
- auto GridRead = RectilinearGridReader::NewSP();
- try {
- GridRead->ReadASCIIGridFile( argv[1] );
- } catch (std::exception& e) {
- std::cout << "Caught an error opening ASCII Grid file: ";
- std::cout << e.what() << std::endl;
- std::cout << "enter filename or 0 to exit programme\n";
- std::string inp;
- std::cin >> inp;
- if (inp != "0")
- GridRead->ReadASCIIGridFile( inp.c_str() );
- else exit(EXIT_FAILURE);
- }
-
- //////////////////////////////////////////////////
- // Read in Layered earth, for backgound model
- auto LayEarthRead = LayeredEarthEMReader::NewSP();
- try {
- LayEarthRead->ReadASCIIInputFile( argv[2] );
- } catch (std::exception& e) {
- std::cout << "Caught an error opening ASCII Layered Earth file: ";
- std::cout << e.what() << std::endl;
- std::cout << "enter filename or 0 to exit programme\n";
- std::string inp;
- std::cin >> inp;
- if (inp != "0")
- LayEarthRead->ReadASCIIGridFile( inp.c_str() );
- else exit(EXIT_FAILURE);
- }
- */
-
- //////////////////////////////////////////////////
- // Read in source specification
- auto AEMRead = AEMSurveyReader::NewSP();
- try{
- AEMRead->ReadASCIIAEMFile(argv[4]);
- } catch (std::exception& e) {
- std::cout << "Caught an error opening ASCII AEM file: ";
- std::cout << e.what() << std::endl;
- std::cout << "enter filename or 0 to exit programme\n";
- std::string inp;
- std::cin >> inp;
- if (inp != "0")
- AEMRead->ReadASCIIAEMFile( inp.c_str() );
- else exit(EXIT_FAILURE);
- }
-
- //////////////////////////////////////////////////
- // And solve
-
- // Use BiCGSTAB Diagonal preconditioner
- auto EM3D = EMSchur3D< Eigen::BiCGSTAB<Eigen::SparseMatrix<Complex, Eigen::ColMajor>, Eigen::IncompleteLUT<Complex> > >::NewSP();
- //auto EM3D = EMSchur3D< Eigen::BiCGSTAB<Eigen::SparseMatrix<Complex, Eigen::ColMajor> > >::NewSP();
-
- //auto EM3D = EMSchur3D< Eigen::PardisoLU<Eigen::SparseMatrix<Complex, Eigen::ColMajor> > >::NewSP();
- //auto EM3D = EMSchur3D< Eigen::PardisoLDLT<Eigen::SparseMatrix<Complex, Eigen::ColMajor>, Eigen::Symmetric > >::NewSP();
-
- // LS CG
- //auto EM3D = EMSchur3D< Eigen::LeastSquaresConjugateGradient<Eigen::SparseMatrix<Complex, Eigen::ColMajor> > >::NewSP();
-
- // CG...dangerous
- //auto EM3D = EMSchur3D< Eigen::ConjugateGradient<Eigen::SparseMatrix<Complex, Eigen::ColMajor>, Eigen::Lower > >::NewSP();
- //auto EM3D = EMSchur3D< Eigen::ConjugateGradient<Eigen::SparseMatrix<Complex, Eigen::ColMajor>, Eigen::Lower, Eigen::IncompleteCholesky<Complex> > >::NewSP();
-
- // LU direct
- //auto EM3D = EMSchur3D< Eigen::SparseLU<Eigen::SparseMatrix<Complex, Eigen::ColMajor>, Eigen::COLAMDOrdering<int> > >::NewSP();
-
- EM3D->SetRectilinearGrid( gimp->GetGrid() );
-
- EM3D->SetLayeredEarthEM( layeredEarth );
- EM3D->SetAEMSurvey( AEMRead->GetSurvey() );
- EM3D->LoadMeshToolsConductivityModel( argv[3] );
- EM3D->SetResFileName(argv[5]);
-
- //EM3D->SetCSolver( Lemma::SPARSELU ); // Lemma::BiCGSTAB );
- EM3D->Solve();
-
- exit(EXIT_SUCCESS);
- }
|