3D EM based on Schur decomposition
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  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 02/19/2015 01:10:39 PM
  11. * @version $Id$
  12. * @author Trevor Irons (ti)
  13. * @email Trevor.Irons@xri-geo.com
  14. * @copyright Copyright (c) 2015, XRI Geophysics, LLC
  15. * @copyright Copyright (c) 2015, Trevor Irons
  16. * @copyright Copyright (c) 2011, Trevor Irons
  17. * @copyright Copyright (c) 2011, Colorado School of Mines
  18. */
  19. #ifndef EMSCHUR3D_INC
  20. #define EMSCHUR3D_INC
  21. #include "EMSchur3DBase.h"
  22. #include "bicgstab.h"
  23. //#include "CSymSimplicialCholesky.h"
  24. namespace Lemma {
  25. /**
  26. \brief Templated concrete classes of EMSChur3DBase.
  27. \details
  28. */
  29. template < class Solver >
  30. class EMSchur3D : public EMSchur3DBase {
  31. friend std::ostream &operator << (std::ostream &stream, const EMSchur3D &ob) {
  32. stream << ob.Serialize() << "\n"; // End of doc
  33. return stream;
  34. }
  35. //friend std::ostream &operator<<(std::ostream &stream,
  36. // const EMSchur3D &ob);
  37. public:
  38. // ==================== LIFECYCLE =======================
  39. /**
  40. * @copybrief LemmaObject::New()
  41. * @copydetails LemmaObject::New()
  42. */
  43. static std::shared_ptr< EMSchur3D > NewSP() {
  44. return std::make_shared< EMSchur3D<Solver> >( ctor_key() );
  45. //return std::make_shared< EMSchur3D< Eigen::BiCGSTAB<Eigen::SparseMatrix<Complex, Eigen::RowMajor> > > >( ctor_key() ) ;
  46. }
  47. /** Default protected constructor, use New */
  48. explicit EMSchur3D ( const ctor_key& key ) : EMSchur3DBase( key ), CSolver( nullptr ) {
  49. }
  50. /** Locked DeDerializing constructor, use factory DeSerialize method*/
  51. EMSchur3D (const YAML::Node& node, const ctor_key& key): EMSchur3DBase(node, key), CSolver( nullptr ) {
  52. }
  53. /** Default protected destructor, use Delete */
  54. virtual ~EMSchur3D () {
  55. // TODO delete arrays
  56. }
  57. /**
  58. * Uses YAML to serialize this object.
  59. * @return a YAML::Node
  60. */
  61. YAML::Node Serialize() const {
  62. YAML::Node node = EMSchur3DBase::Serialize();
  63. //node["NumberOfLayers"] = NumberOfLayers;
  64. node.SetTag( this->GetName() );
  65. return node;
  66. }
  67. /**
  68. * Constructs an object from a YAML::Node.
  69. */
  70. static EMSchur3D* DeSerialize(const YAML::Node& node);
  71. // ==================== OPERATORS =======================
  72. // ==================== OPERATIONS =======================
  73. /** Solves a single source problem. This method is thread safe.
  74. * @param[in] Source is the source term for generating primary fields
  75. * @param[in] isource is the source index
  76. */
  77. void SolveSource( std::shared_ptr<DipoleSource> Source , const int& isource);
  78. /** Builds the solver for the C matrix */
  79. void BuildCDirectSolver( );
  80. // ==================== ACCESS =======================
  81. virtual std::string GetName() const {
  82. return this->CName;
  83. }
  84. // ==================== INQUIRY =======================
  85. protected:
  86. // ==================== LIFECYCLE =======================
  87. private:
  88. /** Copy constructor */
  89. EMSchur3D( const EMSchur3D& ) = delete;
  90. // ==================== DATA MEMBERS =========================
  91. /** The templated solver for C */
  92. Solver* CSolver;
  93. Eigen::SparseMatrix<Complex> Csym;
  94. static constexpr auto CName = "EMSchur3D";
  95. }; // ----- end of class EMSchur3D -----
  96. ////////////////////////////////////////////////////////////////////////////////////////
  97. // Implimentation and Specialisations //
  98. ////////////////////////////////////////////////////////////////////////////////////////
  99. //--------------------------------------------------------------------------------------
  100. // Class: EMSchur3D
  101. // Method: SolveSource
  102. //--------------------------------------------------------------------------------------
  103. template < class Solver >
  104. void EMSchur3D<Solver>::SolveSource ( std::shared_ptr<DipoleSource> Source, const int& isource ) {
  105. std::cout << "In vanilla SolveSource" << std::endl;
  106. // figure out which omega we are working with
  107. int iw = -1;
  108. for (int iiw=0; iiw<Omegas.size(); ++iiw) {
  109. if (Omegas[iiw] - Source->GetAngularFrequency(0) < 1e-3 ) {
  110. iw = iiw;
  111. }
  112. }
  113. if (iw == -1) {
  114. std::cerr << "FREQUENCY DOOM IN EMSchur3D::SolveSource \n";
  115. exit(EXIT_FAILURE);
  116. }
  117. ///////////////////////////////////
  118. // Set up primary fields
  119. // TODO, this is a little stupid as they all share the same points. We need to extend
  120. // EmEARTH to be able to input a grid so that points are not explicitly needed like
  121. // this. This requires some care as calcs are made on faces.
  122. // Alternatively, the bins function of ReceiverPoints could be extended quite easily.
  123. // This may be the way to do this.
  124. //Lemma::ReceiverPoints* dpoint = Lemma::ReceiverPoints::New();
  125. std::shared_ptr< FieldPoints > dpoint = FieldPoints::NewSP();
  126. FillPoints(dpoint);
  127. PrimaryField(Source, dpoint);
  128. std::cout << "Done with primary field" << std::endl;
  129. // Allocate a ton of memory
  130. VectorXcr Phi = VectorXcr::Zero(uns);
  131. VectorXcr ms(unx+uny+unz); // mu sigma
  132. // Vector potential (A) Vector and phi
  133. VectorXcr Se = VectorXcr::Zero(unx+uny+unz);
  134. //VectorXcr A = VectorXcr::Zero(unx+uny+unz);
  135. VectorXcr E = VectorXcr::Zero(unx+uny+unz);
  136. VectorXcr E0 = VectorXcr::Zero(unx+uny+unz);
  137. // Lets get cracking
  138. std::cout << "Filling source terms" << std::endl;
  139. FillSourceTerms(ms, Se, E0, dpoint, Omegas[iw]);
  140. std::cout << "Done source terms" << std::endl;
  141. /////////////////////////////////////////////////
  142. // LOG File
  143. std::string logfile (ResFile);
  144. logfile += to_string(isource) + std::string(".log");
  145. ofstream logio(logfile.c_str());
  146. std::cout << "just logging, TODO fix source" << std::endl;
  147. // logio << *Source << std::endl;
  148. logio << *Grid << std::endl;
  149. logio << *LayModel << std::endl;
  150. std::cout << "dun logging" << std::endl;
  151. // solve for RHS
  152. int max_it(nx*ny*nz), iter_done(0);
  153. Real tol(3e-16), errorn(0);
  154. logio << "solving RHS for source " << isource << std::endl;
  155. // TODO, this is stupid, try and get rid of this copy!
  156. Eigen::SparseMatrix<Complex> Cc = Cvec[iw];
  157. jsw_timer timer;
  158. jsw_timer timer2;
  159. timer.begin();
  160. timer2.begin();
  161. /////////////////////////////////////////
  162. // Solve for RHS
  163. CSolver[iw].setMaxIterations(10000);
  164. VectorXcr A = CSolver[iw].solve(Se);
  165. // // Solve Real system instead
  166. // The Real system is quasi-definite, though an LDLT decomposition exists, CHOLMOD doesn't find it.
  167. // An LU can be done on this, but compute performance is very similiar to the complex system, and diagonal pivoting
  168. // cannot be assumed to be best, hurting solve time.
  169. // /* EXPERIMENTAL */
  170. // VectorXr b2 = VectorXr::Zero(2*(unx+uny+unz));
  171. // b2.head(unx+uny+unz) = Se.real();
  172. // b2.tail(unx+uny+unz) = Se.imag();
  173. // VectorXr A2 = CReSolver[iw].solve(b2);
  174. // A.real() = A2.head( unx+uny+unz );
  175. // A.imag() = -A2.tail( unx+uny+unz ); // Due to decomp. negative!
  176. // /* END EXPERIMENTAL */
  177. VectorXcr ADiv = D*A; // ADiv == RHS == D C^I Se
  178. VectorXcr Error = ((Cc.selfadjointView<Eigen::Lower>()*A).array() - Se.array());
  179. logio << "|| Div(A) || = " << ADiv.norm()
  180. // << " in " << iter_done << " iterations"
  181. //<< " with error " << errorn << "\t"
  182. << "\tInital solution error "<< Error.norm() // Iteritive info
  183. << "\ttime " << timer.end() / 60. << " [m]" << std::endl;
  184. //VectorXcr ADivMAC = ADiv.array() * MAC.array().cast<Complex>();
  185. //logio << "|| Div(A) || on MAC grid " << ADivMAC.norm() << std::endl;
  186. /////////////////////
  187. // Solve for Phi
  188. logio << "Solving for Phi " << std::flush;
  189. timer.begin();
  190. tol = 1e-18;
  191. int success(2);
  192. success = implicitbicgstab(D, idx, ms, ADiv, Phi, CSolver[iw], max_it, tol, errorn, iter_done, logio);
  193. //Phi.array() *= MAC.array().cast<Complex>(); // remove phi from air regions
  194. /* Restart if necessary */
  195. /*
  196. int nrestart(1);
  197. // TODO send MAC to implicitbicgstab?
  198. while (success == 2 && nrestart < 18 && iter_done > 1) {
  199. success = implicitbicgstab(D, idx, ms, ADiv, Phi, CSolver[iw], max_it, tol, errorn, iter_done, logio);
  200. //Phi.array() *= MAC.array().cast<Complex>(); // remove phi from air regions
  201. nrestart += 1;
  202. }
  203. */
  204. logio << "Implicit BiCGStab solution in " << iter_done << " iterations."
  205. << " with error " << std::setprecision(8) << std::scientific << errorn << std::endl;
  206. logio << "time "<< timer.end()/60. << " [m]" << std::endl;
  207. E = ms.array()*(D.transpose()*Phi).array(); // Temp, field due to charge
  208. /////////////////////////////////////
  209. // Compute A
  210. /////////////////////////////////////
  211. logio << "Solving for A using phi" << std::endl;
  212. std::cout << "Solving for A" << std::endl;
  213. max_it = nx*ny*nz;
  214. tol = 5e-16;
  215. errorn = 0;
  216. iter_done = 0;
  217. timer.begin();
  218. A = CSolver[iw].solve( (Se-E).eval() ); // UmfPack requires eval?
  219. VectorXcr ADiv2 = D*A;
  220. logio << "|| Div(A) || = " << ADiv2.norm() ;
  221. //" in " << iter_done << " iterations"
  222. //<< " with error " << errorn << "\t";
  223. // Report error of solutions
  224. Error = ((Cc.selfadjointView<Eigen::Lower>()*A).array() + E.array() - Se.array());
  225. logio << "\tsolution error " << Error.norm()
  226. << std::fixed << std::setprecision(2) << "\ttime " << timer.end()/60. << "\ttotal time " << timer2.end()/60. << std::endl;
  227. logio.close();
  228. //////////////////////////////////////
  229. // Update Fields and report
  230. E.array() = Complex(0,-Omegas[iw])*A.array() - (D.transpose()*Phi).array(); // Secondary Field Only
  231. VectorXcr B = StaggeredGridCurl(A);
  232. WriteVTKResults( ResFile+ to_string(isource), A, Se, E0, E , Phi, ADiv, ADiv2, B);
  233. //dpoint->Delete();
  234. return ;
  235. } // ----- end of method EMSchur3D::SolveSource -----
  236. //--------------------------------------------------------------------------------------
  237. // Class: EMSchur3DBase
  238. // Method: BuildCDirectSolver
  239. //--------------------------------------------------------------------------------------
  240. template < class Solver >
  241. void EMSchur3D<Solver>::BuildCDirectSolver ( ) {
  242. CSolver = new Solver[Omegas.size()];
  243. for (int iw=0; iw<Omegas.size(); ++iw) {
  244. jsw_timer timer;
  245. timer.begin();
  246. /* Complex system */
  247. /*
  248. std::cout << "Generic solver pattern analyzing C_" << iw << ",";
  249. std::cout.flush();
  250. CSolver[iw].analyzePattern( Cvec[iw].selfadjointView< Eigen::Lower>() );
  251. std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  252. // factorize
  253. timer.begin();
  254. std::cout << "Generic solver factorising C_" << iw << ", ";
  255. std::cout.flush();
  256. CSolver[iw].factorize( Cvec[iw].selfadjointView< Eigen::Lower>() );
  257. */
  258. std::cerr << "No solver Specified!" << iw << ",";
  259. exit(EXIT_FAILURE);
  260. //CSolver[iw].compute( Cvec[iw].selfadjointView< Eigen::Lower>() );
  261. std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  262. }
  263. }
  264. #ifdef HAVE_SUPERLUMT
  265. template<>
  266. void EMSchur3D< Eigen::SuperLU<Eigen::SparseMatrix<Complex, Eigen::RowMajor> > >::BuildCDirectSolver() {
  267. CSolver = new Eigen::SuperLU<Eigen::SparseMatrix<Complex, Eigen::RowMajor> > [Omegas.size()];
  268. for (int iw=0; iw<Omegas.size(); ++iw) {
  269. jsw_timer timer;
  270. timer.begin();
  271. /* SuperLU */
  272. //CSolver[iw].options().DiagPivotThresh = 0.01;
  273. //CSolver[iw].options().SymmetricMode = YES;
  274. //CSolver[iw].options().ColPerm = MMD_AT_PLUS_A;
  275. //CSolver[iw].options().Trans = NOTRANS;
  276. //CSolver[iw].options().ConditionNumber = NO;
  277. //std::cout << "SuperLU options:\n";
  278. //std::cout << "\tPivot Threshold: " << CSolver[iw].options().DiagPivotThresh << std::endl;
  279. //std::cout << "\tSymmetric mode: " << CSolver[iw].options().SymmetricMode << std::endl;
  280. //std::cout << "\tEquilibrate: " << CSolver[iw].options().Equil << std::endl;
  281. //std::cout << "\tCol Permutation: " << CSolver[iw].options().ColPerm << std::endl;
  282. //std::cout << "\tTrans: " << CSolver[iw].options().Trans << std::endl;
  283. //std::cout << "\tCondition Number: " << CSolver[iw].options().ConditionNumber << std::endl;
  284. /* Complex system */
  285. std::cout << "SuperLU_MT pattern analyzing C_" << iw << ",";
  286. std::cout.flush();
  287. CSolver[iw].analyzePattern( Cvec[iw].selfadjointView< Eigen::Lower>() );
  288. std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  289. // factorize
  290. timer.begin();
  291. std::cout << "SuperLU_MT factorising C_" << iw << ", ";
  292. std::cout.flush();
  293. CSolver[iw].factorize( Cvec[iw].selfadjointView< Eigen::Lower>() );
  294. std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  295. }
  296. }
  297. #endif
  298. template<>
  299. void EMSchur3D< Eigen::SparseLU<Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::COLAMDOrdering<int> > >::BuildCDirectSolver() {
  300. CSolver = new Eigen::SparseLU<Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::COLAMDOrdering<int> > [Omegas.size()];
  301. for (int iw=0; iw<Omegas.size(); ++iw) {
  302. jsw_timer timer;
  303. timer.begin();
  304. CSolver[iw].isSymmetric(true);
  305. CSolver[iw].setPivotThreshold(0.0);
  306. /* Complex system */
  307. std::cout << "SparseLU pattern analyzing C_" << iw << ",";
  308. std::cout.flush();
  309. CSolver[iw].analyzePattern( Cvec[iw].selfadjointView< Eigen::Lower>() );
  310. std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  311. // factorize
  312. timer.begin();
  313. std::cout << "SparseLU factorising C_" << iw << ", ";
  314. std::cout.flush();
  315. CSolver[iw].factorize( Cvec[iw].selfadjointView< Eigen::Lower>() );
  316. std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  317. }
  318. }
  319. // template<>
  320. // void EMSchur3D< Eigen::CholmodSupernodalLLT< Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::Lower > > ::BuildCDirectSolver() {
  321. // CSolver = new Eigen::CholmodSupernodalLLT< Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::Lower > [Omegas.size()];
  322. // for (int iw=0; iw<Omegas.size(); ++iw) {
  323. // Csym = Cvec[iw].selfadjointView<Eigen::Lower>();
  324. // jsw_timer timer;
  325. // timer.begin();
  326. // /* Complex system */
  327. // std::cout << "CholmodSupernodalLLT pattern analyzing C_" << iw << ",";
  328. // std::cout.flush();
  329. // CSolver[iw].analyzePattern( Csym );
  330. // std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  331. // /* factorize */
  332. // timer.begin();
  333. // std::cout << "CholmodSupernodalLLT factorising C_" << iw << ", ";
  334. // std::cout.flush();
  335. // CSolver[iw].factorize( Csym );
  336. // std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  337. // }
  338. // }
  339. // template<>
  340. // void EMSchur3D< Eigen::CSymSimplicialLLT< Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::Lower, Eigen::NaturalOrdering<int> > > ::BuildCDirectSolver() {
  341. // CSolver = new Eigen::CSymSimplicialLLT< Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::Lower, Eigen::NaturalOrdering<int> > [Omegas.size()];
  342. // for (int iw=0; iw<Omegas.size(); ++iw) {
  343. // Csym = Cvec[iw].selfadjointView<Eigen::Lower>();
  344. // jsw_timer timer;
  345. // timer.begin();
  346. // /* Complex system */
  347. // std::cout << "CSymSimplicialLLT<NaturalOrdering> pattern analyzing C_" << iw << ",";
  348. // std::cout.flush();
  349. // CSolver[iw].analyzePattern( Csym );
  350. // std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  351. // /* factorize */
  352. // timer.begin();
  353. // std::cout << "CSymSimplicialLLT<NaturalOrdering> factorising C_" << iw << ", ";
  354. // std::cout.flush();
  355. // CSolver[iw].factorize( Csym );
  356. // std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  357. // }
  358. // }
  359. //
  360. // template<>
  361. // void EMSchur3D< Eigen::CSymSimplicialLLT< Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::Lower, Eigen::AMDOrdering<int> > > ::BuildCDirectSolver() {
  362. // CSolver = new Eigen::CSymSimplicialLLT< Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::Lower, Eigen::AMDOrdering<int> > [Omegas.size()];
  363. // for (int iw=0; iw<Omegas.size(); ++iw) {
  364. // //Csym = Cvec[iw].selfadjointView<Eigen::Lower>();
  365. // jsw_timer timer;
  366. // timer.begin();
  367. // /* Complex system */
  368. // std::cout << "CSymSimplicialLLT<AMDOrdering> pattern analyzing C_" << iw << ",";
  369. // std::cout.flush();
  370. // CSolver[iw].analyzePattern( Cvec[iw] );
  371. // std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  372. // /* factorize */
  373. // timer.begin();
  374. // std::cout << "CSymSimplicialLLT<AMDOrdering> factorising C_" << iw << ", ";
  375. // std::cout.flush();
  376. // CSolver[iw].factorize( Cvec[iw] );
  377. // std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  378. // }
  379. // }
  380. //
  381. // template<>
  382. // void EMSchur3D< Eigen::CSymSimplicialLDLT< Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::Lower, Eigen::AMDOrdering<int> > > ::BuildCDirectSolver() {
  383. // CSolver = new Eigen::CSymSimplicialLDLT< Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::Lower, Eigen::AMDOrdering<int> > [Omegas.size()];
  384. // for (int iw=0; iw<Omegas.size(); ++iw) {
  385. // Csym = Cvec[iw].selfadjointView<Eigen::Lower>();
  386. // jsw_timer timer;
  387. // timer.begin();
  388. // /* Complex system */
  389. // std::cout << "CSymSimplicialLDLT<AMDOrdering> pattern analyzing C_" << iw << ",";
  390. // std::cout.flush();
  391. // CSolver[iw].analyzePattern( Csym );
  392. // std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  393. // /* factorize */
  394. // timer.begin();
  395. // std::cout << "CSymSimplicialLDLT<AMDOrdering> factorising C_" << iw << ", ";
  396. // std::cout.flush();
  397. // CSolver[iw].factorize( Csym );
  398. // std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  399. // }
  400. // }
  401. template<>
  402. void EMSchur3D< Eigen::BiCGSTAB<Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::IncompleteLUT<Complex> > > ::BuildCDirectSolver() {
  403. CSolver = new Eigen::BiCGSTAB<Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::IncompleteLUT<Complex> > [Omegas.size()];
  404. for (int iw=0; iw<Omegas.size(); ++iw) {
  405. Csym = Cvec[iw].selfadjointView<Eigen::Lower>();
  406. CSolver[iw].preconditioner().setDroptol(1e-12);
  407. CSolver[iw].preconditioner().setFillfactor(1e2);
  408. jsw_timer timer;
  409. timer.begin();
  410. /* Complex system */
  411. std::cout << "BiCGSTAB(ILU) pattern analyzing C_" << iw << ",";
  412. std::cout.flush();
  413. CSolver[iw].analyzePattern( Csym );
  414. std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  415. /* factorize */
  416. timer.begin();
  417. std::cout << "BiCGSTAB(ILU) factorising C_" << iw << ", ";
  418. std::cout.flush();
  419. CSolver[iw].factorize( Csym );
  420. std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  421. }
  422. }
  423. template<>
  424. void EMSchur3D< Eigen::BiCGSTAB< Eigen::SparseMatrix<Complex, Eigen::RowMajor> > > ::BuildCDirectSolver() {
  425. CSolver = new Eigen::BiCGSTAB< Eigen::SparseMatrix<Complex, Eigen::RowMajor> > [Omegas.size()];
  426. for (int iw=0; iw<Omegas.size(); ++iw) {
  427. Csym = Cvec[iw].selfadjointView<Eigen::Lower>();
  428. jsw_timer timer;
  429. timer.begin();
  430. /* Complex system */
  431. std::cout << "BiCGSTAB pattern analyzing C_" << iw << ",";
  432. std::cout.flush();
  433. CSolver[iw].analyzePattern( Csym );
  434. std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  435. // factorize
  436. timer.begin();
  437. std::cout << "BiCGSTAB factorising C_" << iw << ", ";
  438. std::cout.flush();
  439. CSolver[iw].factorize( Csym );
  440. std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  441. }
  442. }
  443. template<>
  444. void EMSchur3D< Eigen::LeastSquaresConjugateGradient< Eigen::SparseMatrix<Complex, Eigen::RowMajor> > > ::BuildCDirectSolver() {
  445. CSolver = new Eigen::LeastSquaresConjugateGradient< Eigen::SparseMatrix<Complex, Eigen::RowMajor> > [Omegas.size()];
  446. for (int iw=0; iw<Omegas.size(); ++iw) {
  447. Csym = Cvec[iw].selfadjointView<Eigen::Lower>();
  448. jsw_timer timer;
  449. timer.begin();
  450. /* Complex system */
  451. std::cout << "LeastSquaresConjugateGradient pattern analyzing C_" << iw << ",";
  452. std::cout.flush();
  453. CSolver[iw].analyzePattern( Csym );
  454. std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  455. // factorize
  456. timer.begin();
  457. std::cout << "LeastSquaresConjugateGradient factorising C_" << iw << ", ";
  458. std::cout.flush();
  459. CSolver[iw].factorize( Csym );
  460. std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  461. }
  462. }
  463. // template<>
  464. // void EMSchur3D< Eigen::ConjugateGradient<Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::Lower > > ::BuildCDirectSolver() {
  465. // CSolver = new Eigen::ConjugateGradient<Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::Lower > [Omegas.size()];
  466. // for (int iw=0; iw<Omegas.size(); ++iw) {
  467. // //Csym = Cvec[iw].selfadjointView<Eigen::Lower>();
  468. // jsw_timer timer;
  469. // timer.begin();
  470. // /* Complex system */
  471. // std::cout << "ConjugateGradient pattern analyzing C_" << iw << ",";
  472. // std::cout.flush();
  473. // CSolver[iw].analyzePattern( Cvec[iw] );
  474. // std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  475. // // factorize
  476. // timer.begin();
  477. // std::cout << "ConjugateGradient factorising C_" << iw << ", ";
  478. // std::cout.flush();
  479. // CSolver[iw].factorize( Cvec[iw] );
  480. // std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  481. // }
  482. // }
  483. // template<>
  484. // void EMSchur3D< Eigen::PastixLLT<Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::Lower > > ::BuildCDirectSolver() {
  485. // CSolver = new Eigen::PastixLLT<Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::Lower > [Omegas.size()];
  486. // //MPI_Init(NULL, NULL);
  487. // for (int iw=0; iw<Omegas.size(); ++iw) {
  488. // //Csym = Cvec[iw].selfadjointView<Eigen::Lower>();
  489. // jsw_timer timer;
  490. // timer.begin();
  491. // /* Complex system */
  492. // std::cout << "PaStiX LLT pattern analyzing C_" << iw << ",";
  493. // std::cout.flush();
  494. // CSolver[iw].analyzePattern( Cvec[iw] );
  495. // std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  496. // // factorize
  497. // timer.begin();
  498. // std::cout << "PaStiX LLT factorising C_" << iw << ", ";
  499. // std::cout.flush();
  500. // CSolver[iw].factorize( Cvec[iw] );
  501. // std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  502. // }
  503. // }
  504. //
  505. // template<>
  506. // void EMSchur3D< Eigen::PastixLDLT<Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::Lower > > ::BuildCDirectSolver() {
  507. // CSolver = new Eigen::PastixLDLT<Eigen::SparseMatrix<Complex, Eigen::RowMajor>, Eigen::Lower > [Omegas.size()];
  508. // //MPI_Init(NULL, NULL);
  509. // for (int iw=0; iw<Omegas.size(); ++iw) {
  510. // //Csym = Cvec[iw].selfadjointView<Eigen::Lower>();
  511. // jsw_timer timer;
  512. // timer.begin();
  513. // /* Complex system */
  514. // std::cout << "PaStiX LDLT pattern analyzing C_" << iw << ",";
  515. // std::cout.flush();
  516. // CSolver[iw].analyzePattern( Cvec[iw] );
  517. // std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  518. // // factorize
  519. // timer.begin();
  520. // std::cout << "PaStiX LDLT factorising C_" << iw << ", ";
  521. // std::cout.flush();
  522. // CSolver[iw].factorize( Cvec[iw] );
  523. // std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  524. // std::cout << "INFO " << CSolver[iw].info( ) << std::endl;
  525. // }
  526. // }
  527. //
  528. // template<>
  529. // void EMSchur3D< Eigen::PastixLU<Eigen::SparseMatrix<Complex, Eigen::RowMajor>, true > > ::BuildCDirectSolver() {
  530. // CSolver = new Eigen::PastixLU<Eigen::SparseMatrix<Complex, Eigen::RowMajor>, true > [Omegas.size()];
  531. // //MPI_Init(NULL, NULL);
  532. // for (int iw=0; iw<Omegas.size(); ++iw) {
  533. // Csym = Cvec[iw].selfadjointView<Eigen::Lower>();
  534. // jsw_timer timer;
  535. // timer.begin();
  536. // /* Complex system */
  537. // std::cout << "PaStiX LU pattern analyzing C_" << iw << ",";
  538. // std::cout.flush();
  539. // CSolver[iw].compute( Csym );
  540. // std::cout << "PaStiX LU Done C_" << iw << std::endl;;
  541. // // std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  542. // // // factorize
  543. // // timer.begin();
  544. // // std::cout << "PaStiX LU factorising C_" << iw << ", ";
  545. // // std::cout.flush();
  546. // // CSolver[iw].factorize( Csym );
  547. // // std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  548. // }
  549. // }
  550. } // ----- end of Lemma name -----
  551. #endif // ----- #ifndef EMSCHUR3D_INC -----