Changeset 2d8c4e for src/Fragmentation


Ignore:
Timestamp:
Sep 12, 2016, 11:58:11 PM (8 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_StructOpt_integration_tests, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, 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_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, GeometryObjects, Gui_displays_atomic_force_velocity, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, Ubuntu_1604_changes, stable
Children:
2ccdf4
Parents:
6393ff
git-author:
Frederik Heber <heber@…> (07/12/14 16:19:46)
git-committer:
Frederik Heber <heber@…> (09/12/16 23:58:11)
Message:

Removed all IsZero() checking and special cases for the triangle idea.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Fragmentation/Exporters/SphericalPointDistribution.cpp

    r6393ff r2d8c4e  
    699699      _referencepositions, _currentpositions);
    700700
    701   if ((!oldCenter.IsZero()) && (!newCenter.IsZero())) {
    702     LOG(4, "DEBUG: oldCenter is " << oldCenter << ", newCenter is " << newCenter);
    703     oldCenter.Normalize();
    704     newCenter.Normalize();
    705     if (!oldCenter.IsEqualTo(newCenter)) {
    706       // calculate rotation axis and angle
    707       Rotation.first = oldCenter;
    708       Rotation.first.VectorProduct(newCenter);
    709       Rotation.second = oldCenter.Angle(newCenter); // /(M_PI/2.);
    710     } else {
    711       // no rotation required anymore
    712     }
     701  ASSERT( !oldCenter.IsZero() && !newCenter.IsZero(),
     702      "findPlaneAligningRotation() - either old "+toString(oldCenter)
     703      +" or new center "+toString(newCenter)+" are zero.");
     704  LOG(4, "DEBUG: oldCenter is " << oldCenter << ", newCenter is " << newCenter);
     705  if (!oldCenter.IsEqualTo(newCenter)) {
     706    // calculate rotation axis and angle
     707    Rotation.first = oldCenter;
     708    Rotation.first.VectorProduct(newCenter);
     709    Rotation.first.Normalize();
     710    // construct reference vector to determine direction of rotation
     711    const double sign = determineSignOfRotation(newCenter, oldCenter, Rotation.first);
     712    Rotation.second = sign * oldCenter.Angle(newCenter);
    713713  } else {
    714     LOG(4, "DEBUG: oldCenter is " << oldCenter << ", newCenter is " << newCenter);
    715     if ((oldCenter.IsZero()) && (newCenter.IsZero())) {
    716       // either oldCenter or newCenter (or both) is directly at origin
    717       if (_currentpositions.indices.size() == 2) {
    718         // line case
    719         Vector oldPosition = _currentpositions.polygon[*_currentpositions.indices.begin()];
    720         Vector newPosition = _referencepositions.polygon[0];
    721         // check whether we need to rotate at all
    722         if (!oldPosition.IsEqualTo(newPosition)) {
    723           Rotation.first = oldPosition;
    724           Rotation.first.VectorProduct(newPosition);
    725           // orientation will fix the sign here eventually
    726           Rotation.second = oldPosition.Angle(newPosition);
    727         } else {
    728           // no rotation required anymore
    729         }
    730       } else {
    731         // triangle case
    732         // both triangles/planes have same center, hence get axis by
    733         // VectorProduct of Normals
    734         Plane newplane(_referencepositions.polygon[0], _referencepositions.polygon[1], _referencepositions.polygon[2]);
    735         VectorArray_t vectors;
    736         for (IndexList_t::const_iterator iter = _currentpositions.indices.begin();
    737             iter != _currentpositions.indices.end(); ++iter)
    738           vectors.push_back(_currentpositions.polygon[*iter]);
    739         Plane oldplane(vectors[0], vectors[1], vectors[2]);
    740         Vector oldPosition = oldplane.getNormal();
    741         Vector newPosition = newplane.getNormal();
    742         // check whether we need to rotate at all
    743         if (!oldPosition.IsEqualTo(newPosition)) {
    744           Rotation.first = oldPosition;
    745           Rotation.first.VectorProduct(newPosition);
    746           Rotation.first.Normalize();
    747 
    748           // construct reference vector to determine direction of rotation
    749           const double sign = determineSignOfRotation(oldPosition, newPosition, Rotation.first);
    750           Rotation.second = sign * oldPosition.Angle(newPosition);
    751           LOG(5, "DEBUG: Rotating plane normals by " << Rotation.second
    752               << " around axis " << Rotation.first);
    753         } else {
    754           // else do nothing
    755         }
    756       }
    757     } else {
    758       // TODO: we can't do anything here, but this case needs to be dealt with when
    759       // we have no ideal geometries anymore
    760       if ((oldCenter-newCenter).Norm() > warn_amplitude)
    761         ELOG(2, "oldCenter is " << oldCenter << ", yet newCenter is " << newCenter);
    762 #ifndef NDEBUG
    763       // else they are considered close enough
    764       dontcheck = true;
    765 #endif
    766     }
     714    // no rotation required anymore
    767715  }
    768716
     
    805753      << oldPosition.Norm() << ") and newPosition is " << newPosition << " length(: "
    806754      << newPosition.Norm() << ")");
     755
    807756  if (!oldPosition.IsEqualTo(newPosition)) {
    808     if ((!oldCenter.IsZero()) && (!newCenter.IsZero())) {
    809       // we rotate at oldCenter and around the radial direction, which is again given
    810       // by oldCenter.
    811       Rotation.first = oldCenter;
    812       Rotation.first.Normalize();  // note weighted sum of normalized weight is not normalized
    813       LOG(6, "DEBUG: Using oldCenter " << oldCenter << " as rotation center and "
    814           << Rotation.first << " as axis.");
    815       oldPosition -= oldCenter;
    816       newPosition -= oldCenter;
    817       oldPosition = (oldPosition - oldPosition.Projection(Rotation.first));
    818       newPosition = (newPosition - newPosition.Projection(Rotation.first));
    819       LOG(6, "DEBUG: Positions after projection are " << oldPosition << " and " << newPosition);
    820     } else {
    821       if (remainingnew.indices.size() == 2) {
    822         // line situation
    823         try {
    824           Plane oldplane(oldPosition, oldCenter, newPosition);
    825           Rotation.first = oldplane.getNormal();
    826           LOG(6, "DEBUG: Plane is " << oldplane << " and normal is " << Rotation.first);
    827         } catch (LinearDependenceException &e) {
    828           LOG(6, "DEBUG: Vectors defining plane are linearly dependent.");
    829           // oldPosition and newPosition are on a line, just flip when not equal
    830           if (!oldPosition.IsEqualTo(newPosition)) {
    831             Rotation.first.Zero();
    832             Rotation.first.GetOneNormalVector(oldPosition);
    833             LOG(6, "DEBUG: For flipping we use Rotation.first " << Rotation.first);
    834             assert( Rotation.first.ScalarProduct(oldPosition) < std::numeric_limits<double>::epsilon()*1e4);
    835   //              Rotation.second = M_PI;
    836           } else {
    837             LOG(6, "DEBUG: oldPosition and newPosition are equivalent.");
    838           }
    839         }
    840       } else {
    841         // triangle situation
    842         Plane oldplane(remainingold.polygon[0], remainingold.polygon[1], remainingold.polygon[2]);
    843         Rotation.first = oldplane.getNormal();
    844         LOG(6, "DEBUG: oldPlane is " << oldplane << " and normal is " << Rotation.first);
    845         oldPosition.ProjectOntoPlane(Rotation.first);
    846         LOG(6, "DEBUG: Positions after projection are " << oldPosition << " and " << newPosition);
    847       }
    848     }
     757    // we rotate at oldCenter and around the radial direction, which is again given
     758    // by oldCenter.
     759    Rotation.first = oldCenter;
     760    Rotation.first.Normalize();  // note weighted sum of normalized weight is not normalized
     761    LOG(6, "DEBUG: Using oldCenter " << oldCenter << " as rotation center and "
     762        << Rotation.first << " as axis.");
     763    oldPosition -= oldCenter;
     764    newPosition -= oldCenter;
     765    oldPosition = (oldPosition - oldPosition.Projection(Rotation.first));
     766    newPosition = (newPosition - newPosition.Projection(Rotation.first));
     767    LOG(6, "DEBUG: Positions after projection are " << oldPosition << " and " << newPosition);
     768
    849769    // construct reference vector to determine direction of rotation
    850770    const double sign = determineSignOfRotation(oldPosition, newPosition, Rotation.first);
     
    919839#ifndef NDEBUG
    920840      // check: rotated "newCenter" should now equal oldCenter
    921       {
     841      // we don't check in case of two points as these lie on a great circle
     842      // and the center cannot stably be recalculated. We may reactivate this
     843      // when we calculate centers only once
     844      if (oldSet.indices.size() > 2) {
    922845        Vector oldCenter;
    923846        Vector rotatednewCenter;
Note: See TracChangeset for help on using the changeset viewer.