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.

EMSchur3D.h 29KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  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::ColMajor> > > >( 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(750);
  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. << "\tInital solution error="<< Error.norm() // Iteritive info
  181. << "\tSolver reported error="<< CSolver[iw].error() // Iteritive info
  182. << "\ttime " << timer.end() / 60. << " [m] "
  183. << CSolver[iw].iterations() << " iterations"
  184. << std::endl;
  185. //VectorXcr ADivMAC = ADiv.array() * MAC.array().cast<Complex>();
  186. //logio << "|| Div(A) || on MAC grid " << ADivMAC.norm() << std::endl;
  187. /////////////////////
  188. // Solve for Phi
  189. logio << "Solving for Phi " << std::flush;
  190. timer.begin();
  191. tol = 1e-18;
  192. int success(2);
  193. success = implicitbicgstab(D, idx, ms, ADiv, Phi, CSolver[iw], max_it, tol, errorn, iter_done, logio);
  194. //Phi.array() *= MAC.array().cast<Complex>(); // remove phi from air regions
  195. /* Restart if necessary */
  196. /*
  197. int nrestart(1);
  198. // TODO send MAC to implicitbicgstab?
  199. while (success == 2 && nrestart < 18 && iter_done > 1) {
  200. success = implicitbicgstab(D, idx, ms, ADiv, Phi, CSolver[iw], max_it, tol, errorn, iter_done, logio);
  201. //Phi.array() *= MAC.array().cast<Complex>(); // remove phi from air regions
  202. nrestart += 1;
  203. }
  204. */
  205. logio << "Implicit BiCGStab solution in " << iter_done << " iterations."
  206. << " with error " << std::setprecision(8) << std::scientific << errorn << std::endl;
  207. logio << "time "<< timer.end()/60. << " [m]" << std::endl;
  208. E = ms.array()*(D.transpose()*Phi).array(); // Temp, field due to charge
  209. /////////////////////////////////////
  210. // Compute A
  211. /////////////////////////////////////
  212. logio << "Solving for A using phi" << std::endl;
  213. std::cout << "Solving for A" << std::endl;
  214. max_it = nx*ny*nz;
  215. tol = 5e-16;
  216. errorn = 0;
  217. iter_done = 0;
  218. timer.begin();
  219. A = CSolver[iw].solve( (Se-E).eval() ); // UmfPack requires eval?
  220. VectorXcr ADiv2 = D*A;
  221. //logio << "|| Div(A) || = " << ADiv2.norm() ;
  222. //" in " << iter_done << " iterations"
  223. //<< " with error " << errorn << "\t";
  224. // Report error of solutions
  225. Error = ((Cc.selfadjointView<Eigen::Lower>()*A).array() + E.array() - Se.array());
  226. //logio << "\tsolution error " << Error.norm()
  227. // << std::fixed << std::setprecision(2) << "\ttime " << timer.end()/60. << "\ttotal time " << timer2.end()/60. << std::endl;
  228. // << "\tSolver reported error="<< CSolver[iw].error() // Iteritive info
  229. // << "\ttime " << timer.end() / 60. << " [m] "
  230. // << CSolver[iw].iterations() << " iterations"
  231. logio << "|| Div(A) || = " << ADiv2.norm()
  232. << "\tInital solution error="<< Error.norm() // Iteritive info
  233. << "\tSolver reported error="<< CSolver[iw].error() // Iteritive info
  234. << "\ttime " << timer.end() / 60. << " [m] "
  235. << CSolver[iw].iterations() << " iterations"
  236. << std::endl;
  237. logio.close();
  238. //////////////////////////////////////
  239. // Update Fields and report
  240. E.array() = Complex(0,-Omegas[iw])*A.array() - (D.transpose()*Phi).array(); // Secondary Field Only
  241. VectorXcr B = StaggeredGridCurl(A);
  242. WriteVTKResults( ResFile+ to_string(isource), A, Se, E0, E , Phi, ADiv, ADiv2, B);
  243. //dpoint->Delete();
  244. return ;
  245. } // ----- end of method EMSchur3D::SolveSource -----
  246. //--------------------------------------------------------------------------------------
  247. // Class: EMSchur3DBase
  248. // Method: BuildCDirectSolver
  249. //--------------------------------------------------------------------------------------
  250. template < class Solver >
  251. void EMSchur3D<Solver>::BuildCDirectSolver ( ) {
  252. CSolver = new Solver[Omegas.size()];
  253. for (int iw=0; iw<Omegas.size(); ++iw) {
  254. jsw_timer timer;
  255. timer.begin();
  256. /* Complex system */
  257. /*
  258. std::cout << "Generic solver pattern analyzing C_" << iw << ",";
  259. std::cout.flush();
  260. CSolver[iw].analyzePattern( Cvec[iw].selfadjointView< Eigen::Lower>() );
  261. std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  262. // factorize
  263. timer.begin();
  264. std::cout << "Generic solver factorising C_" << iw << ", ";
  265. std::cout.flush();
  266. CSolver[iw].factorize( Cvec[iw].selfadjointView< Eigen::Lower>() );
  267. */
  268. std::cerr << "No solver Specified!" << iw << ",";
  269. exit(EXIT_FAILURE);
  270. //CSolver[iw].compute( Cvec[iw].selfadjointView< Eigen::Lower>() );
  271. std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  272. }
  273. }
  274. #ifdef HAVE_SUPERLUMT
  275. template<>
  276. void EMSchur3D< Eigen::SuperLU<Eigen::SparseMatrix<Complex, Eigen::ColMajor> > >::BuildCDirectSolver() {
  277. CSolver = new Eigen::SuperLU<Eigen::SparseMatrix<Complex, Eigen::ColMajor> > [Omegas.size()];
  278. for (int iw=0; iw<Omegas.size(); ++iw) {
  279. jsw_timer timer;
  280. timer.begin();
  281. /* SuperLU */
  282. //CSolver[iw].options().DiagPivotThresh = 0.01;
  283. //CSolver[iw].options().SymmetricMode = YES;
  284. //CSolver[iw].options().ColPerm = MMD_AT_PLUS_A;
  285. //CSolver[iw].options().Trans = NOTRANS;
  286. //CSolver[iw].options().ConditionNumber = NO;
  287. //std::cout << "SuperLU options:\n";
  288. //std::cout << "\tPivot Threshold: " << CSolver[iw].options().DiagPivotThresh << std::endl;
  289. //std::cout << "\tSymmetric mode: " << CSolver[iw].options().SymmetricMode << std::endl;
  290. //std::cout << "\tEquilibrate: " << CSolver[iw].options().Equil << std::endl;
  291. //std::cout << "\tCol Permutation: " << CSolver[iw].options().ColPerm << std::endl;
  292. //std::cout << "\tTrans: " << CSolver[iw].options().Trans << std::endl;
  293. //std::cout << "\tCondition Number: " << CSolver[iw].options().ConditionNumber << std::endl;
  294. /* Complex system */
  295. std::cout << "SuperLU_MT pattern analyzing C_" << iw << ",";
  296. std::cout.flush();
  297. CSolver[iw].analyzePattern( Cvec[iw].selfadjointView< Eigen::Lower>() );
  298. std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  299. // factorize
  300. timer.begin();
  301. std::cout << "SuperLU_MT factorising C_" << iw << ", ";
  302. std::cout.flush();
  303. CSolver[iw].factorize( Cvec[iw].selfadjointView< Eigen::Lower>() );
  304. std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  305. }
  306. }
  307. #endif
  308. template<>
  309. void EMSchur3D< Eigen::SparseLU<Eigen::SparseMatrix<Complex, Eigen::ColMajor>, Eigen::COLAMDOrdering<int> > >::BuildCDirectSolver() {
  310. CSolver = new Eigen::SparseLU<Eigen::SparseMatrix<Complex, Eigen::ColMajor>, Eigen::COLAMDOrdering<int> > [Omegas.size()];
  311. for (int iw=0; iw<Omegas.size(); ++iw) {
  312. jsw_timer timer;
  313. timer.begin();
  314. CSolver[iw].isSymmetric(true);
  315. //CSolver[iw].setPivotThreshold(0.0); // OK for symmetric complex systems with real and imaginary positive definite parts.
  316. // // but our imaginary part is negative definite
  317. //http://www.ams.org/journals/mcom/1998-67-224/S0025-5718-98-00978-8/S0025-5718-98-00978-8.pdf
  318. /* Complex system */
  319. std::cout << "SparseLU pattern analyzing C_" << iw << ",";
  320. std::cout.flush();
  321. CSolver[iw].analyzePattern( Cvec[iw].selfadjointView< Eigen::Lower>() );
  322. std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  323. // factorize
  324. timer.begin();
  325. std::cout << "SparseLU factorising C_" << iw << ", ";
  326. std::cout.flush();
  327. CSolver[iw].factorize( Cvec[iw].selfadjointView< Eigen::Lower>() );
  328. std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  329. }
  330. }
  331. // template<>
  332. // void EMSchur3D< Eigen::CholmodSupernodalLLT< Eigen::SparseMatrix<Complex, Eigen::ColMajor>, Eigen::Lower > > ::BuildCDirectSolver() {
  333. // CSolver = new Eigen::CholmodSupernodalLLT< Eigen::SparseMatrix<Complex, Eigen::ColMajor>, Eigen::Lower > [Omegas.size()];
  334. // for (int iw=0; iw<Omegas.size(); ++iw) {
  335. // Csym = Cvec[iw].selfadjointView<Eigen::Lower>();
  336. // jsw_timer timer;
  337. // timer.begin();
  338. // /* Complex system */
  339. // std::cout << "CholmodSupernodalLLT pattern analyzing C_" << iw << ",";
  340. // std::cout.flush();
  341. // CSolver[iw].analyzePattern( Csym );
  342. // std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  343. // /* factorize */
  344. // timer.begin();
  345. // std::cout << "CholmodSupernodalLLT factorising C_" << iw << ", ";
  346. // std::cout.flush();
  347. // CSolver[iw].factorize( Csym );
  348. // std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  349. // }
  350. // }
  351. // template<>
  352. // void EMSchur3D< Eigen::CSymSimplicialLLT< Eigen::SparseMatrix<Complex, Eigen::ColMajor>, Eigen::Lower, Eigen::NaturalOrdering<int> > > ::BuildCDirectSolver() {
  353. // CSolver = new Eigen::CSymSimplicialLLT< Eigen::SparseMatrix<Complex, Eigen::ColMajor>, Eigen::Lower, Eigen::NaturalOrdering<int> > [Omegas.size()];
  354. // for (int iw=0; iw<Omegas.size(); ++iw) {
  355. // Csym = Cvec[iw].selfadjointView<Eigen::Lower>();
  356. // jsw_timer timer;
  357. // timer.begin();
  358. // /* Complex system */
  359. // std::cout << "CSymSimplicialLLT<NaturalOrdering> pattern analyzing C_" << iw << ",";
  360. // std::cout.flush();
  361. // CSolver[iw].analyzePattern( Csym );
  362. // std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  363. // /* factorize */
  364. // timer.begin();
  365. // std::cout << "CSymSimplicialLLT<NaturalOrdering> factorising C_" << iw << ", ";
  366. // std::cout.flush();
  367. // CSolver[iw].factorize( Csym );
  368. // std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  369. // }
  370. // }
  371. //
  372. // template<>
  373. // void EMSchur3D< Eigen::CSymSimplicialLLT< Eigen::SparseMatrix<Complex, Eigen::ColMajor>, Eigen::Lower, Eigen::AMDOrdering<int> > > ::BuildCDirectSolver() {
  374. // CSolver = new Eigen::CSymSimplicialLLT< Eigen::SparseMatrix<Complex, Eigen::ColMajor>, Eigen::Lower, Eigen::AMDOrdering<int> > [Omegas.size()];
  375. // for (int iw=0; iw<Omegas.size(); ++iw) {
  376. // //Csym = Cvec[iw].selfadjointView<Eigen::Lower>();
  377. // jsw_timer timer;
  378. // timer.begin();
  379. // /* Complex system */
  380. // std::cout << "CSymSimplicialLLT<AMDOrdering> pattern analyzing C_" << iw << ",";
  381. // std::cout.flush();
  382. // CSolver[iw].analyzePattern( Cvec[iw] );
  383. // std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  384. // /* factorize */
  385. // timer.begin();
  386. // std::cout << "CSymSimplicialLLT<AMDOrdering> factorising C_" << iw << ", ";
  387. // std::cout.flush();
  388. // CSolver[iw].factorize( Cvec[iw] );
  389. // std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  390. // }
  391. // }
  392. //
  393. // template<>
  394. // void EMSchur3D< Eigen::CSymSimplicialLDLT< Eigen::SparseMatrix<Complex, Eigen::ColMajor>, Eigen::Lower, Eigen::AMDOrdering<int> > > ::BuildCDirectSolver() {
  395. // CSolver = new Eigen::CSymSimplicialLDLT< Eigen::SparseMatrix<Complex, Eigen::ColMajor>, Eigen::Lower, Eigen::AMDOrdering<int> > [Omegas.size()];
  396. // for (int iw=0; iw<Omegas.size(); ++iw) {
  397. // Csym = Cvec[iw].selfadjointView<Eigen::Lower>();
  398. // jsw_timer timer;
  399. // timer.begin();
  400. // /* Complex system */
  401. // std::cout << "CSymSimplicialLDLT<AMDOrdering> pattern analyzing C_" << iw << ",";
  402. // std::cout.flush();
  403. // CSolver[iw].analyzePattern( Csym );
  404. // std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  405. // /* factorize */
  406. // timer.begin();
  407. // std::cout << "CSymSimplicialLDLT<AMDOrdering> factorising C_" << iw << ", ";
  408. // std::cout.flush();
  409. // CSolver[iw].factorize( Csym );
  410. // std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  411. // }
  412. // }
  413. template<>
  414. void EMSchur3D< Eigen::BiCGSTAB<Eigen::SparseMatrix<Complex, Eigen::ColMajor>, Eigen::IncompleteLUT<Complex> > > ::BuildCDirectSolver() {
  415. CSolver = new Eigen::BiCGSTAB<Eigen::SparseMatrix<Complex, Eigen::ColMajor>, Eigen::IncompleteLUT<Complex> > [Omegas.size()];
  416. for (int iw=0; iw<Omegas.size(); ++iw) {
  417. Csym = Cvec[iw].selfadjointView<Eigen::Lower>();
  418. CSolver[iw].preconditioner().setDroptol(1e-5); // 1e-12
  419. //CSolver[iw].preconditioner().setFillfactor(5e1); // 1e2
  420. jsw_timer timer;
  421. timer.begin();
  422. /* Complex system */
  423. std::cout << "BiCGSTAB(ILU) pattern analyzing C_" << iw << ",";
  424. std::cout.flush();
  425. CSolver[iw].analyzePattern( Csym );
  426. std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  427. /* factorize */
  428. timer.begin();
  429. std::cout << "BiCGSTAB(ILU) factorising C_" << iw << ", ";
  430. std::cout.flush();
  431. CSolver[iw].factorize( Csym );
  432. std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  433. }
  434. }
  435. template<>
  436. void EMSchur3D< Eigen::BiCGSTAB< Eigen::SparseMatrix<Complex, Eigen::ColMajor> > > ::BuildCDirectSolver() {
  437. CSolver = new Eigen::BiCGSTAB< Eigen::SparseMatrix<Complex, Eigen::ColMajor> > [Omegas.size()];
  438. for (int iw=0; iw<Omegas.size(); ++iw) {
  439. Csym = Cvec[iw].selfadjointView<Eigen::Lower>();
  440. jsw_timer timer;
  441. timer.begin();
  442. /* Complex system */
  443. std::cout << "BiCGSTAB pattern analyzing C_" << iw << ",";
  444. std::cout.flush();
  445. CSolver[iw].analyzePattern( Csym );
  446. std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  447. // factorize
  448. timer.begin();
  449. std::cout << "BiCGSTAB factorising C_" << iw << ", ";
  450. std::cout.flush();
  451. CSolver[iw].factorize( Csym );
  452. std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  453. }
  454. }
  455. template<>
  456. void EMSchur3D< Eigen::LeastSquaresConjugateGradient< Eigen::SparseMatrix<Complex, Eigen::ColMajor> > > ::BuildCDirectSolver() {
  457. CSolver = new Eigen::LeastSquaresConjugateGradient< Eigen::SparseMatrix<Complex, Eigen::ColMajor> > [Omegas.size()];
  458. for (int iw=0; iw<Omegas.size(); ++iw) {
  459. Csym = Cvec[iw].selfadjointView<Eigen::Lower>();
  460. jsw_timer timer;
  461. timer.begin();
  462. /* Complex system */
  463. std::cout << "LeastSquaresConjugateGradient pattern analyzing C_" << iw << ",";
  464. std::cout.flush();
  465. CSolver[iw].analyzePattern( Csym );
  466. std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  467. // factorize
  468. timer.begin();
  469. std::cout << "LeastSquaresConjugateGradient factorising C_" << iw << ", ";
  470. std::cout.flush();
  471. CSolver[iw].factorize( Csym );
  472. std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  473. }
  474. }
  475. template<>
  476. void EMSchur3D< Eigen::ConjugateGradient<Eigen::SparseMatrix<Complex, Eigen::ColMajor>, Eigen::Lower > > ::BuildCDirectSolver() {
  477. CSolver = new Eigen::ConjugateGradient<Eigen::SparseMatrix<Complex, Eigen::ColMajor>, Eigen::Lower > [Omegas.size()];
  478. for (int iw=0; iw<Omegas.size(); ++iw) {
  479. //Csym = Cvec[iw].selfadjointView<Eigen::Lower>();
  480. jsw_timer timer;
  481. timer.begin();
  482. /* Complex system */
  483. std::cout << "ConjugateGradient pattern analyzing C_" << iw << ",";
  484. std::cout.flush();
  485. CSolver[iw].analyzePattern( Cvec[iw] );
  486. std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  487. // factorize
  488. timer.begin();
  489. std::cout << "ConjugateGradient factorising C_" << iw << ", ";
  490. std::cout.flush();
  491. CSolver[iw].factorize( Cvec[iw] );
  492. std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  493. }
  494. }
  495. template<>
  496. void EMSchur3D< Eigen::ConjugateGradient<Eigen::SparseMatrix<Complex, Eigen::ColMajor>, Eigen::Lower, Eigen::IncompleteCholesky<Complex> > > ::BuildCDirectSolver() {
  497. CSolver = new Eigen::ConjugateGradient<Eigen::SparseMatrix<Complex, Eigen::ColMajor>, Eigen::Lower, Eigen::IncompleteCholesky<Complex> > [Omegas.size()];
  498. for (int iw=0; iw<Omegas.size(); ++iw) {
  499. //Csym = Cvec[iw].selfadjointView<Eigen::Lower>();
  500. jsw_timer timer;
  501. timer.begin();
  502. /* Complex system */
  503. std::cout << "ConjugateGradient<IncompleteCholesky> pattern analyzing C_" << iw << ",";
  504. std::cout.flush();
  505. CSolver[iw].analyzePattern( Cvec[iw] );
  506. std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  507. // factorize
  508. timer.begin();
  509. std::cout << "ConjugateGradient<IncompleteCholesky> factorising C_" << iw << ", ";
  510. std::cout.flush();
  511. CSolver[iw].factorize( Cvec[iw] );
  512. std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  513. }
  514. }
  515. // template<>
  516. // void EMSchur3D< Eigen::PastixLLT<Eigen::SparseMatrix<Complex, Eigen::ColMajor>, Eigen::Lower > > ::BuildCDirectSolver() {
  517. // CSolver = new Eigen::PastixLLT<Eigen::SparseMatrix<Complex, Eigen::ColMajor>, Eigen::Lower > [Omegas.size()];
  518. // //MPI_Init(NULL, NULL);
  519. // for (int iw=0; iw<Omegas.size(); ++iw) {
  520. // //Csym = Cvec[iw].selfadjointView<Eigen::Lower>();
  521. // jsw_timer timer;
  522. // timer.begin();
  523. // /* Complex system */
  524. // std::cout << "PaStiX LLT pattern analyzing C_" << iw << ",";
  525. // std::cout.flush();
  526. // CSolver[iw].analyzePattern( Cvec[iw] );
  527. // std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  528. // // factorize
  529. // timer.begin();
  530. // std::cout << "PaStiX LLT factorising C_" << iw << ", ";
  531. // std::cout.flush();
  532. // CSolver[iw].factorize( Cvec[iw] );
  533. // std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  534. // }
  535. // }
  536. //
  537. // template<>
  538. // void EMSchur3D< Eigen::PastixLDLT<Eigen::SparseMatrix<Complex, Eigen::ColMajor>, Eigen::Lower > > ::BuildCDirectSolver() {
  539. // CSolver = new Eigen::PastixLDLT<Eigen::SparseMatrix<Complex, Eigen::ColMajor>, Eigen::Lower > [Omegas.size()];
  540. // //MPI_Init(NULL, NULL);
  541. // for (int iw=0; iw<Omegas.size(); ++iw) {
  542. // //Csym = Cvec[iw].selfadjointView<Eigen::Lower>();
  543. // jsw_timer timer;
  544. // timer.begin();
  545. // /* Complex system */
  546. // std::cout << "PaStiX LDLT pattern analyzing C_" << iw << ",";
  547. // std::cout.flush();
  548. // CSolver[iw].analyzePattern( Cvec[iw] );
  549. // std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  550. // // factorize
  551. // timer.begin();
  552. // std::cout << "PaStiX LDLT factorising C_" << iw << ", ";
  553. // std::cout.flush();
  554. // CSolver[iw].factorize( Cvec[iw] );
  555. // std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  556. // std::cout << "INFO " << CSolver[iw].info( ) << std::endl;
  557. // }
  558. // }
  559. //
  560. // template<>
  561. // void EMSchur3D< Eigen::PastixLU<Eigen::SparseMatrix<Complex, Eigen::ColMajor>, true > > ::BuildCDirectSolver() {
  562. // CSolver = new Eigen::PastixLU<Eigen::SparseMatrix<Complex, Eigen::ColMajor>, true > [Omegas.size()];
  563. // //MPI_Init(NULL, NULL);
  564. // for (int iw=0; iw<Omegas.size(); ++iw) {
  565. // Csym = Cvec[iw].selfadjointView<Eigen::Lower>();
  566. // jsw_timer timer;
  567. // timer.begin();
  568. // /* Complex system */
  569. // std::cout << "PaStiX LU pattern analyzing C_" << iw << ",";
  570. // std::cout.flush();
  571. // CSolver[iw].compute( Csym );
  572. // std::cout << "PaStiX LU Done C_" << iw << std::endl;;
  573. // // std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  574. // // // factorize
  575. // // timer.begin();
  576. // // std::cout << "PaStiX LU factorising C_" << iw << ", ";
  577. // // std::cout.flush();
  578. // // CSolver[iw].factorize( Csym );
  579. // // std::cout << " done in " << timer.end() / 60. << " [m]" << std::endl;
  580. // }
  581. // }
  582. } // ----- end of Lemma name -----
  583. #endif // ----- #ifndef EMSCHUR3D_INC -----