- Timestamp:
- Dec 4, 2010, 11:56:27 PM (14 years ago)
- Branches:
- Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
- Children:
- 041462
- Parents:
- 5eec98
- git-author:
- Frederik Heber <heber@…> (11/16/10 11:42:47)
- git-committer:
- Frederik Heber <heber@…> (12/04/10 23:56:27)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/LinearAlgebra/MatrixContent.cpp
r5eec98 r17fa81 215 215 const MatrixContent MatrixContent::operator*(const MatrixContent &rhs) const 216 216 { 217 ASSERT (columns == rhs.rows, 218 "MatrixContent::operator*() - dimensions not match for matrix product (a,b)*(b,c) = (a,c):" 219 "("+toString(rows)+","+toString(columns)+")*("+toString(rhs.rows)+","+toString(rhs.columns)+")"); 217 220 gsl_matrix *res = gsl_matrix_alloc(rows, rhs.columns); 218 221 gsl_blas_dgemm(CblasNoTrans, CblasNoTrans, 1.0, content, rhs.content, 0.0, res); … … 358 361 } 359 362 360 /** Transform the matrix to its eigenbasis an sreturn resulting eigenvalues.363 /** Transform the matrix to its eigenbasis and return resulting eigenvalues. 361 364 * Note that we only return real-space part in case of non-symmetric matrix. 362 365 * \warn return vector has to be freed'd … … 376 379 return eval; 377 380 } else { // non-symmetric 378 //ASSERT(false, "MatrixContent::transformToEigenbasis() - only implemented for square matrices: "+toString(rows)+"!="+toString(columns)+"!");379 380 381 // blow up gsl_matrix in content to square matrix, fill other components with zero 381 382 const size_t greaterDimension = rows > columns ? rows : columns; … … 388 389 } 389 390 390 // show squared matrix 391 MatrixContent *ContentSquare = new MatrixViewContent(gsl_matrix_submatrix(content ,0,0,content->size1, content->size2));391 // show squared matrix by putting it into a MatrixViewContent 392 MatrixContent *ContentSquare = new MatrixViewContent(gsl_matrix_submatrix(content_square,0,0,content_square->size1, content_square->size2)); 392 393 std::cout << "The squared matrix is " << *ContentSquare << std::endl; 393 delete ContentSquare;394 394 395 395 // solve eigenvalue problem … … 401 401 402 402 // copy eigenvectors real-parts into content_square and ... 403 for (size_t i=0; i<greaterDimension; i++) 404 for (size_t j=0; j<greaterDimension; j++) 405 gsl_matrix_set(content_square, i,j, GSL_REAL(gsl_matrix_complex_get(evec,i,j))); 406 403 407 // ... show complex-valued eigenvector matrix 404 std::cout << " Resulting eigenvector matrix is [";405 for (size_t i=0; i<greaterDimension; i++) { 406 for (size_t j=0; j<greaterDimension; j++) {407 std::cout << "(" << GSL_REAL(gsl_matrix_complex_get(evec,i,j)) 408 << "," << GSL_IMAG(gsl_matrix_complex_get(evec,i,j)) << ")"; 409 if (j < greaterDimension-1) 410 std::cout << " "; 411 gsl_matrix_set(content_square, i,j, GSL_REAL(gsl_matrix_complex_get(evec,i,j)));412 }413 if (i < greaterDimension-1)414 std::cout << "; ";415 }416 std::cout << "]" << std::endl;417 418 // scan for zero rows and columns to drop419 std::set<size_t> RowDropList;420 s td::set<size_t> ColumnDropList;408 std::cout << "The real-value eigenvector matrix is " << *ContentSquare << std::endl; 409 // std::cout << "Resulting eigenvector matrix is ["; 410 // for (size_t i=0; i<greaterDimension; i++) { 411 // for (size_t j=0; j<greaterDimension; j++) { 412 // std::cout << "(" << GSL_REAL(gsl_matrix_complex_get(evec,i,j)) 413 // << "," << GSL_IMAG(gsl_matrix_complex_get(evec,i,j)) << ")"; 414 // if (j < greaterDimension-1) 415 // std::cout << " "; 416 // } 417 // if (i < greaterDimension-1) 418 // std::cout << "; "; 419 // } 420 // std::cout << "]" << std::endl; 421 422 // copy real-parts of complex eigenvalues and eigenvectors (column-wise orientation) 423 gsl_vector *eval_real = gsl_vector_alloc(columns); 424 size_t I=0; 421 425 for (size_t i=0; i<greaterDimension; i++) { // only copy real space part 422 double Rsum = 0.; 423 double Csum = 0.; 424 for (size_t j=0; j<greaterDimension; j++) { 425 Rsum += fabs(GSL_REAL(gsl_matrix_complex_get(evec,i,j))); 426 Csum += fabs(GSL_REAL(gsl_matrix_complex_get(evec,j,i))); 427 } 428 Rsum /= (double)greaterDimension; 429 Csum /= (double)greaterDimension; 430 if (Rsum < MYEPSILON) 431 RowDropList.insert(i); 432 if (Csum < MYEPSILON) 433 ColumnDropList.insert(i); 434 } 435 436 // copy real-parts of complex eigenvalues and eigenvectors 437 gsl_vector *eval_real = gsl_vector_alloc(greaterDimension); 438 size_t I=0; 439 size_t J=0; 440 for (size_t i=0; i<greaterDimension; i++) { // only copy real space part 441 if (RowDropList.find(i) == RowDropList.end()) { 426 if (fabs(GSL_REAL(gsl_vector_complex_get(eval,i))) > MYEPSILON) { // only take eigenvectors with value > 0 427 std::cout << i << "th eigenvalue is (" << GSL_REAL(gsl_vector_complex_get(eval,i)) << "," << GSL_IMAG(gsl_vector_complex_get(eval,i)) << ")" << std::endl; 442 428 for (size_t j=0; j<greaterDimension; j++) { 443 if (ColumnDropList.find(j) == ColumnDropList.end()) { 444 if (fabs(GSL_IMAG(gsl_matrix_complex_get(evec,i,j))) > MYEPSILON) 445 std::cerr << "MatrixContent::transformToEigenbasis() - WARNING: eigenvectors are complex-valued!" << std::endl; 446 gsl_matrix_set(content, I,J, GSL_REAL(gsl_matrix_complex_get(evec,i,j))); 447 J++; 448 } 429 if (fabs(GSL_IMAG(gsl_matrix_complex_get(evec,j,i))) > MYEPSILON) 430 std::cerr << "MatrixContent::transformToEigenbasis() - WARNING: eigenvectors are complex-valued!" << std::endl; 431 gsl_matrix_set(content, j,I, GSL_REAL(gsl_matrix_complex_get(evec,j,i))); 449 432 } 450 433 if (fabs(GSL_IMAG(gsl_vector_complex_get(eval,I))) > MYEPSILON) … … 456 439 gsl_matrix_complex_free(evec); 457 440 gsl_vector_complex_free(eval); 441 delete ContentSquare; 442 458 443 return eval_real; 459 444 }
Note:
See TracChangeset
for help on using the changeset viewer.