3D EM based on Schur decomposition
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

EMSchur3D-vtk.cpp 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /* This file is part of Lemma, a geophysical modelling and inversion API.
  2. * More information is available at http://lemmasoftware.org
  3. */
  4. /* This Source Code Form is subject to the terms of the Mozilla Public
  5. * License, v. 2.0. If a copy of the MPL was not distributed with this
  6. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  7. */
  8. /**
  9. * @file
  10. * @date 01/04/2018 04:34:54 PM
  11. * @version $Id$
  12. * @author Trevor Irons (ti)
  13. * @email tirons@egi.utah.edu
  14. * @copyright Copyright (c) 2018, University of Utah
  15. * @copyright Copyright (c) 2018, Lemma Software, LLC
  16. */
  17. #include <LemmaCore>
  18. //#include "RectilinearGridReader.h"
  19. //#include "AEMSurveyReader.h"
  20. #include "EMSchur3D.h"
  21. //#include "LayeredEarthEMReader.h"
  22. //#include "CSymSimplicialCholesky.h"
  23. #include "vtkRectilinearGridReader.h"
  24. using namespace Lemma;
  25. int main( int argc, char** argv ) {
  26. if (argc < 3) {
  27. std::cout << "EMSchur3D <rgrid.vtr> <1dmod> <source> " << std::endl;
  28. std::cout << "\trgrid.vtr - VTK Rectilinear grid file containing 3D conductivity structure.\n";
  29. exit( EXIT_SUCCESS );
  30. }
  31. #ifdef LEMMAUSEOMP
  32. std::cout << "Eigen is using OpenMP.\n";
  33. Eigen::initParallel();
  34. #endif
  35. ///////////////////////////////////////////////////
  36. // Read in VTK Grid
  37. auto vtr = vtkSmartPointer<vtkRectilinearGridReader>::New();
  38. vtr->SetFileName( argv[1] );
  39. if (!vtr->OpenVTKFile()) {
  40. std::cout << "Failed to open VTK file " << argv[1] << std::endl;
  41. return EXIT_FAILURE;
  42. }
  43. vtr->Update();
  44. //std::cout << *vtr->GetOutput() << std::endl;
  45. auto gimp = RectilinearGridVTKImporter::NewSP();
  46. gimp->SetVTKInput( vtr->GetOutput() );
  47. gimp->ConvertGrid( 0, 0, 2150 );
  48. //////////////////////////////////////////////////
  49. // Read in Layered earth, for backgound model
  50. auto layeredEarth = LayeredEarthEM::DeSerialize( YAML::LoadFile(argv[2]) );
  51. /*
  52. ///////////////////////////////////////////////////
  53. // Read in Grid
  54. auto GridRead = RectilinearGridReader::NewSP();
  55. try {
  56. GridRead->ReadASCIIGridFile( argv[1] );
  57. } catch (std::exception& e) {
  58. std::cout << "Caught an error opening ASCII Grid file: ";
  59. std::cout << e.what() << std::endl;
  60. std::cout << "enter filename or 0 to exit programme\n";
  61. std::string inp;
  62. std::cin >> inp;
  63. if (inp != "0")
  64. GridRead->ReadASCIIGridFile( inp.c_str() );
  65. else exit(EXIT_FAILURE);
  66. }
  67. //////////////////////////////////////////////////
  68. // Read in Layered earth, for backgound model
  69. auto LayEarthRead = LayeredEarthEMReader::NewSP();
  70. try {
  71. LayEarthRead->ReadASCIIInputFile( argv[2] );
  72. } catch (std::exception& e) {
  73. std::cout << "Caught an error opening ASCII Layered Earth file: ";
  74. std::cout << e.what() << std::endl;
  75. std::cout << "enter filename or 0 to exit programme\n";
  76. std::string inp;
  77. std::cin >> inp;
  78. if (inp != "0")
  79. LayEarthRead->ReadASCIIGridFile( inp.c_str() );
  80. else exit(EXIT_FAILURE);
  81. }
  82. */
  83. //////////////////////////////////////////////////
  84. // Read in source specification
  85. auto AEMRead = AEMSurveyReader::NewSP();
  86. try{
  87. AEMRead->ReadASCIIAEMFile(argv[4]);
  88. } catch (std::exception& e) {
  89. std::cout << "Caught an error opening ASCII AEM file: ";
  90. std::cout << e.what() << std::endl;
  91. std::cout << "enter filename or 0 to exit programme\n";
  92. std::string inp;
  93. std::cin >> inp;
  94. if (inp != "0")
  95. AEMRead->ReadASCIIAEMFile( inp.c_str() );
  96. else exit(EXIT_FAILURE);
  97. }
  98. //////////////////////////////////////////////////
  99. // And solve
  100. // Use BiCGSTAB Diagonal preconditioner
  101. auto EM3D = EMSchur3D< Eigen::BiCGSTAB<Eigen::SparseMatrix<Complex, Eigen::ColMajor>, Eigen::IncompleteLUT<Complex> > >::NewSP();
  102. //auto EM3D = EMSchur3D< Eigen::BiCGSTAB<Eigen::SparseMatrix<Complex, Eigen::ColMajor> > >::NewSP();
  103. //auto EM3D = EMSchur3D< Eigen::PardisoLU<Eigen::SparseMatrix<Complex, Eigen::ColMajor> > >::NewSP();
  104. //auto EM3D = EMSchur3D< Eigen::PardisoLDLT<Eigen::SparseMatrix<Complex, Eigen::ColMajor>, Eigen::Symmetric > >::NewSP();
  105. // LS CG
  106. //auto EM3D = EMSchur3D< Eigen::LeastSquaresConjugateGradient<Eigen::SparseMatrix<Complex, Eigen::ColMajor> > >::NewSP();
  107. // CG...dangerous
  108. //auto EM3D = EMSchur3D< Eigen::ConjugateGradient<Eigen::SparseMatrix<Complex, Eigen::ColMajor>, Eigen::Lower > >::NewSP();
  109. //auto EM3D = EMSchur3D< Eigen::ConjugateGradient<Eigen::SparseMatrix<Complex, Eigen::ColMajor>, Eigen::Lower, Eigen::IncompleteCholesky<Complex> > >::NewSP();
  110. // LU direct
  111. //auto EM3D = EMSchur3D< Eigen::SparseLU<Eigen::SparseMatrix<Complex, Eigen::ColMajor>, Eigen::COLAMDOrdering<int> > >::NewSP();
  112. EM3D->SetRectilinearGrid( gimp->GetGrid() );
  113. EM3D->SetLayeredEarthEM( layeredEarth );
  114. EM3D->SetAEMSurvey( AEMRead->GetSurvey() );
  115. EM3D->LoadMeshToolsConductivityModel( argv[3] );
  116. EM3D->SetResFileName(argv[5]);
  117. //EM3D->SetCSolver( Lemma::SPARSELU ); // Lemma::BiCGSTAB );
  118. EM3D->Solve();
  119. exit(EXIT_SUCCESS);
  120. }