Changeset f5bca2


Ignore:
Timestamp:
Dec 4, 2010, 11:56:28 PM (14 years ago)
Author:
Frederik Heber <heber@…>
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:
9c5296
Parents:
742371
git-author:
Frederik Heber <heber@…> (11/22/10 11:10:57)
git-committer:
Frederik Heber <heber@…> (12/04/10 23:56:28)
Message:

SubspaceFactorizer now has the matrix dimension as an enum.

Location:
src/unittests
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/unittests/SubspaceFactorizerUnittest.cpp

    r742371 rf5bca2  
    4545
    4646void SubspaceFactorizerUnittest::setUp(){
    47   fourbyfour = new MatrixContent(4,4);
    48   fourbyfour->setZero();
    49   for (int i=0; i<4 ; i++) {
    50     fourbyfour->set(i,i, 2.);
    51     if (i < (4-1)) {
    52       fourbyfour->set(i+1,i, 1.);
    53       fourbyfour->set(i,i+1, 1.);
    54     }
    55   }
    56   transformation = new MatrixContent**[3];
    57 
    58   // 1d subspace
    59   transformation[0] = new MatrixContent*[4];
    60   for(size_t i=0; i<4;++i) {
    61     transformation[0][i] = new MatrixContent(4,4);
    62     transformation[0][i]->setZero();
    63     for (size_t j=0; j<1; ++j)
    64       transformation[0][i]->set(i+j,i+j, 1.);
    65 //    std::cout << i << "th transformation matrix, " << 1 << "d subspace is "
    66 //        << *transformation[0][i] << std::endl;
    67   }
    68 
    69   // 2d subspace
    70   transformation[1] = new MatrixContent*[3];
    71   for(size_t i=0; i<3;++i) {
    72     transformation[1][i] = new MatrixContent(4,4);
    73     transformation[1][i]->setZero();
    74     for (size_t j=0; j<2; ++j)
    75       transformation[1][i]->set(i+j,i+j, 1.);
    76 //    std::cout << i << "th transformation matrix, " << 2 << "d subspace is "
    77 //        << *transformation[1][i] << std::endl;
    78   }
    79 
    80   // 3d subspace
    81   transformation[2] = new MatrixContent*[2];
    82   for(size_t i=0; i<2;++i) {
    83     transformation[2][i] = new MatrixContent(4,4);
    84     transformation[2][i]->setZero();
    85     for (size_t j=0; j<3; ++j)
    86       transformation[2][i]->set(i+j,i+j, 1.);
    87 //    std::cout << i << "th transformation matrix, " << 3 << "d subspace is "
    88 //        << *transformation[2][i] << std::endl;
    89   }
    90 }
     47  matrix = new MatrixContent(matrixdimension,matrixdimension);
     48  matrix->setZero();
     49  for (int i=0; i<matrixdimension ; i++) {
     50    matrix->set(i,i, 2.);
     51    if (i < (matrixdimension-1)) {
     52      matrix->set(i+1,i, 1.);
     53      matrix->set(i,i+1, 1.);
     54    }
     55  }
     56}
     57
    9158void SubspaceFactorizerUnittest::tearDown(){
    9259  // delete test matrix
    93   delete fourbyfour;
    94 
    95   // delete all transformations
    96   for(size_t i=0; i<3;++i)
    97     delete transformation[0][i];
    98   delete[] transformation[0];
    99   for(size_t i=0; i<3;++i)
    100     delete transformation[1][i];
    101   delete[] transformation[1];
    102   for(size_t i=0; i<2;++i)
    103     delete transformation[2][i];
    104   delete[] transformation[2];
    105   delete[] transformation;
     60  delete matrix;
    10661}
    10762
    10863void SubspaceFactorizerUnittest::BlockTest()
    10964{
    110   MatrixContent temp((*fourbyfour)&(*transformation[0][0]));
    111   std::cout << "Our matrix is " << *fourbyfour << "." << std::endl;
    112 
    113   std::cout << "Hadamard product of " << *fourbyfour << " with " << *transformation[0][0] << " is: " << std::endl;
     65  MatrixContent *transformation = new MatrixContent(matrixdimension,matrixdimension);
     66  transformation->setZero();
     67  for (size_t j=0; j<1; ++j)
     68    transformation->set(j,j, 1.);
     69
     70  MatrixContent temp((*matrix)&(*transformation));
     71  std::cout << "Our matrix is " << *matrix << "." << std::endl;
     72
     73  std::cout << "Hadamard product of " << *matrix << " with " << *transformation << " is: " << std::endl;
    11474  std::cout << temp << std::endl;
    11575
     
    12080  delete eigenvaluesView;
    12181  gsl_vector_free(eigenvalues);
     82  delete (transformation);
    12283
    12384
     
    329290
    330291  // (for now settle with the one we are most parallel to)
    331   size_t mostparallel_index = 4;
     292  size_t mostparallel_index = SubspaceFactorizerUnittest::matrixdimension;
    332293  double mostparallel_scalarproduct = 0.;
    333294  BOOST_FOREACH( size_t indexiter, CorrespondenceList) {
     
    340301    }
    341302  }
    342   if (mostparallel_index != 4) {
     303  if (mostparallel_index != SubspaceFactorizerUnittest::matrixdimension) {
    343304    // put into std::list for later use
    344305    // invert if pointing in negative direction
     
    358319  VectorArray CurrentEigenvectors;
    359320  ValueArray CurrentEigenvalues;
    360   VectorValueList *ParallelEigenvectorList = new VectorValueList[4];
     321  VectorValueList *ParallelEigenvectorList = new VectorValueList[matrixdimension];
    361322  IndexSet AllIndices;
    362323
    363324  // create the total index set
    364   for (size_t i=0;i<4;++i)
     325  for (size_t i=0;i<matrixdimension;++i)
    365326    AllIndices.insert(i);
    366327
     
    368329  IndexMap Dimension_to_Indexset;
    369330  for (size_t dim = 0; dim<3;++dim) {
    370     for (size_t i=0;i<4-dim;++i) {
     331    for (size_t i=0;i<matrixdimension;++i) {
    371332      IndexSet *indexset = new IndexSet;
    372       for (size_t j=0;j<=dim;++j) {
    373         //std::cout << "Putting " << i+j << " into " << i << "th map " << dim << std::endl;
    374         CPPUNIT_ASSERT_MESSAGE("index "+toString(i+j)+" already present in "+toString(dim)+"-dim "+toString(i)+"th indexset.", indexset->count(i+j) == 0);
    375         indexset->insert(i+j);
     333      for (size_t j=0;j<dim+1;++j) {
     334        const int value = (i+j) % matrixdimension;
     335        //std::cout << "Putting " << value << " into " << i << "th map " << dim << std::endl;
     336        CPPUNIT_ASSERT_MESSAGE("index "+toString(value)+" already present in "+toString(dim)+"-dim "+toString(i)+"th indexset.", indexset->count(value) == 0);
     337        indexset->insert(value);
    376338      }
    377339      Dimension_to_Indexset.insert( make_pair(dim, boost::shared_ptr<IndexSet>(indexset)) );
     
    381343  }
    382344
    383   // set to first guess, i.e. the unit vectors of R^4
     345  // set to first guess, i.e. the unit vectors of R^matrixdimension
    384346  BOOST_FOREACH( size_t index, AllIndices) {
    385     boost::shared_ptr<VectorContent> EV(new VectorContent(4));
     347    boost::shared_ptr<VectorContent> EV(new VectorContent(matrixdimension));
    386348    EV->setZero();
    387349    EV->at(index) = 1.;
     
    392354  size_t run=1; // counting iterations
    393355  double threshold = 1.;  // containing threshold value
    394   while ((threshold > 1e-6) && (run < 200)) {
     356  while ((threshold > 1e-10) && (run < 200)) {
    395357    // for every dimension
    396     for (size_t dim = 0; dim<3;++dim) {
     358    for (size_t dim = 0; dim<4;++dim) {
    397359      // for every index set of this dimension
    398360      Log() << Verbose(0) << std::endl << std::endl;
     
    407369
    408370        // create transformation matrices from these
    409         MatrixContent *subsystem = getSubspaceMatrix(*fourbyfour, CurrentEigenvectors, *(IndexsetIter->second));
     371        MatrixContent *subsystem = getSubspaceMatrix(*matrix, CurrentEigenvectors, *(IndexsetIter->second));
    410372        Log() << Verbose(2) << "Subsystem matrix is " << *subsystem << std::endl;
    411373
     
    415377        Log() << Verbose(2) << "Eigenvalues are " << *Eigenvalues << std::endl;
    416378
    417         // blow up eigenvectors to 4dim column vector again
     379        // blow up eigenvectors to matrixdimensiondim column vector again
    418380        MatrixContent *Eigenvectors = embedSubspaceMatrix(CurrentEigenvectors, *subsystem, *(IndexsetIter->second));
    419         Log() << Verbose(1) << "4x4 Eigenvector matrix is " << *Eigenvectors << std::endl;
     381        Log() << Verbose(1) << matrixdimension << "x" << matrixdimension << " Eigenvector matrix is " << *Eigenvectors << std::endl;
    420382
    421383        // we don't need the subsystem anymore
     
    488450    }
    489451
    490     // check orthonormality again
    491     checkOrthogonality(AllIndices, CurrentEigenvectors);
     452//    // check orthonormality again
     453//    checkOrthogonality(AllIndices, CurrentEigenvectors);
    492454
    493455    // show new ones
  • src/unittests/SubspaceFactorizerUnittest.hpp

    r742371 rf5bca2  
    3434  void EigenvectorTest();
    3535
    36   MatrixContent *fourbyfour;
     36  enum { matrixdimension = 3 };
     37private:
     38
     39  MatrixContent *matrix;
    3740
    3841  MatrixContent ***transformation;
Note: See TracChangeset for help on using the changeset viewer.