/* 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 //#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 <1dmod> " << 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::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::IncompleteLUT > >::NewSP(); //auto EM3D = EMSchur3D< Eigen::BiCGSTAB > >::NewSP(); // LS CG //auto EM3D = EMSchur3D< Eigen::LeastSquaresConjugateGradient > >::NewSP(); // CG...dangerous //auto EM3D = EMSchur3D< Eigen::ConjugateGradient, Eigen::Lower > >::NewSP(); //auto EM3D = EMSchur3D< Eigen::ConjugateGradient, Eigen::Lower, Eigen::IncompleteCholesky > >::NewSP(); // LU direct //auto EM3D = EMSchur3D< Eigen::SparseLU, Eigen::COLAMDOrdering > >::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); }