Changeset 474961 for src


Ignore:
Timestamp:
Apr 16, 2010, 12:26:16 PM (15 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:
d5fea7
Parents:
ebb50e
Message:

New approach to degenerated triangles: Recognize on creation and add both sides at once.

Location:
src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/boundary.cpp

    rebb50e r474961  
    10141014    double ShortestAngle = 4.*M_PI;
    10151015    for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++) {
    1016       if (Runner->second->T->AngleFromTop < Runner->second->ShortestAngle) {
    1017         Log() << Verbose(1) << "INFO: Checking candidate is " << *Runner->second->BaseLine << " with point " << *(*Runner->second->pointlist.begin()) << " and angle " << Runner->second->ShortestAngle << endl;
    1018         if (Runner->second->ShortestAngle < ShortestAngle) {
    1019           baseline = Runner->second;
    1020           ShortestAngle = baseline->ShortestAngle;
    1021           Log() << Verbose(1) << "New best candidate is " << *baseline->BaseLine << " with point " << *(*baseline->pointlist.begin()) << " and angle " << baseline->ShortestAngle << endl;
    1022         }
    1023       } else {
    1024         Log() << Verbose(1) << "Rejecting openline " << *Runner->second->BaseLine << " with point " << *(*Runner->second->pointlist.begin()) << " and angle " << Runner->second->ShortestAngle << " against angle from top " << Runner->second->T->AngleFromTop << "." << endl;
     1016      if (Runner->second->ShortestAngle < ShortestAngle) {
     1017        baseline = Runner->second;
     1018        ShortestAngle = baseline->ShortestAngle;
     1019        Log() << Verbose(1) << "New best candidate is " << *baseline->BaseLine << " with point " << *(*baseline->pointlist.begin()) << " and angle " << baseline->ShortestAngle << endl;
    10251020      }
    10261021    }
    1027     if ((ShortestAngle == 4.*M_PI) || (baseline->pointlist.empty()))
    1028       for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++) {
    1029         if (Runner->second->ShortestAngle < ShortestAngle) {
    1030           baseline = Runner->second;
    1031           ShortestAngle = baseline->ShortestAngle;
    1032           Log() << Verbose(1) << "New best candidate is " << *baseline->BaseLine << " with point " << *(*baseline->pointlist.begin()) << " and angle " << baseline->ShortestAngle << endl;
    1033         }
    1034       }
    10351022    // 2e. if we found one, add candidate
    10361023    if ((ShortestAngle == 4.*M_PI) || (baseline->pointlist.empty()))
    10371024      OneLoopWithoutSuccessFlag = false;
    10381025    else {
    1039       TesselStruct->AddCandidatePolygon(*baseline);
     1026      TesselStruct->AddCandidatePolygon(*baseline, RADIUS, LCList);
    10401027    }
    10411028
  • src/tesselation.cpp

    rebb50e r474961  
    654654};
    655655
     656/** Checks validity of a given sphere of a candidate line.
     657 * \sa CandidateForTesselation::CheckValidity(), which is more evolved.
     658 * \param *OtherOptCenter center of the other triangle
     659 * \param RADIUS radius of sphere
     660 * \param *LC LinkedCell structure with other atoms
     661 * \return true - candidate triangle is degenerated, false - candidate triangle is not degenerated
     662 */
     663bool BoundaryTriangleSet::CheckDegeneracy(Vector *OtherOptCenter, const double RADIUS, const LinkedCell *LC) const
     664{
     665  Info FunctionInfo(__func__);
     666
     667  DoLog(1) && (Log() << Verbose(1) << "INFO: Checking whether sphere contains no others points ..." << endl);
     668  bool flag = true;
     669
     670  // get all points inside the sphere
     671  TesselPointList *ListofPoints = LC->GetPointsInsideSphere(RADIUS, OtherOptCenter);
     672
     673  // remove triangles's endpoints
     674  for (int i=0;i<3;i++)
     675    ListofPoints->remove(endpoints[i]->node);
     676
     677  // check for other points
     678  if (!ListofPoints->empty()) {
     679    Log() << Verbose(1) << "CheckValidity: There are still " << ListofPoints->size() << " points inside the sphere." << endl;
     680    flag = false;
     681    Log() << Verbose(1) << "External atoms inside of sphere at " << *OtherOptCenter << ":" << endl;
     682    for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner)
     683      Log() << Verbose(1) << "  " << *(*Runner) << " with distance " << (*Runner)->node->Distance(OtherOptCenter) << "." << endl;
     684  }
     685  delete(ListofPoints);
     686
     687  return flag;
     688};
     689
     690
     691
    656692/** Returns the endpoint which is not contained in the given \a *line.
    657693 * \param *line baseline defining two endpoints
     
    11041140  return flag;
    11051141};
    1106 
    1107 
    11081142
    11091143/** output operator for CandidateForTesselation.
     
    18111845      if (FindLine->second->triangles.size() < 2) {
    18121846        insertNewLine = false;
    1813         Log() << Verbose(0) << "Using existing line " << *FindLine->second << endl;
    1814 
    1815         BPS[0] = FindLine->second->endpoints[0];
    1816         BPS[1] = FindLine->second->endpoints[1];
    1817         BLS[n] = FindLine->second;
    1818 
    1819         // remove existing line from OpenLines
    1820         CandidateMap::iterator CandidateLine = OpenLines.find(BLS[n]);
    1821         if (CandidateLine != OpenLines.end()) {
    1822           Log() << Verbose(1) << " Removing line from OpenLines." << endl;
    1823           delete(CandidateLine->second);
    1824           OpenLines.erase(CandidateLine);
    1825         } else {
    1826           DoeLog(1) && (eLog()<< Verbose(1) << "Line exists and is attached to less than two triangles, but not in OpenLines!" << endl);
    1827         }
    1828 
     1847        AddExistingTesselationTriangleLine(FindLine->second, n);
    18291848        break;
    18301849      }
     
    18331852
    18341853  if (insertNewLine) {
    1835     AlwaysAddTesselationTriangleLine(a, b, n);
     1854    AddNewTesselationTriangleLine(a, b, n);
    18361855  }
    18371856}
     
    18461865 * @param n index of Tesselation::BLS giving the line with both endpoints
    18471866 */
    1848 void Tesselation::AlwaysAddTesselationTriangleLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n)
     1867void Tesselation::AddNewTesselationTriangleLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n)
    18491868{
    18501869        Info FunctionInfo(__func__);
     
    18601879  CandidateForTesselation *CFT = new CandidateForTesselation(BLS[n]);
    18611880  OpenLines.insert(pair< BoundaryLineSet *, CandidateForTesselation *> (BLS[n], CFT));
     1881};
     1882
     1883/** Uses an existing line for a new triangle.
     1884 * Sets Tesselation::BLS[\a n] and removes the lines from Tesselation::OpenLines.
     1885 * \param *FindLine the line to add
     1886 * \param n index of the line to set in Tesselation::BLS
     1887 */
     1888void Tesselation::AddExistingTesselationTriangleLine(class BoundaryLineSet *Line, int n)
     1889{
     1890  Info FunctionInfo(__func__);
     1891  Log() << Verbose(0) << "Using existing line " << *Line << endl;
     1892
     1893  // set endpoints and line
     1894  BPS[0] = Line->endpoints[0];
     1895  BPS[1] = Line->endpoints[1];
     1896  BLS[n] = Line;
     1897
     1898  // remove existing line from OpenLines
     1899  CandidateMap::iterator CandidateLine = OpenLines.find(BLS[n]);
     1900  if (CandidateLine != OpenLines.end()) {
     1901    Log() << Verbose(1) << " Removing line from OpenLines." << endl;
     1902    delete(CandidateLine->second);
     1903    OpenLines.erase(CandidateLine);
     1904  } else {
     1905    DoeLog(1) && (eLog()<< Verbose(1) << "Line exists and is attached to less than two triangles, but not in OpenLines!" << endl);
     1906  }
    18621907};
    18631908
     
    22222267
    22232268    BTS = NULL;
    2224     AddCandidatePolygon(OptCandidates);
     2269    AddCandidatePolygon(OptCandidates, RADIUS, LC);
    22252270//    delete(BaseLine.endpoints[0]);
    22262271//    delete(BaseLine.endpoints[1]);
     
    25442589/** Adds the present line and candidate point from \a &CandidateLine to the Tesselation.
    25452590 * \param CandidateLine triangle to add
    2546  * \NOTE we need the copy operator here as the original CandidateForTesselation is removed in AddTesselationLine()
    2547  */
    2548 void Tesselation::AddCandidatePolygon(CandidateForTesselation CandidateLine)
     2591 * \param RADIUS Radius of sphere
     2592 * \param *LC LinkedCell structure
     2593 * \NOTE we need the copy operator here as the original CandidateForTesselation is removed in
     2594 * AddTesselationLine() in AddCandidateTriangle()
     2595 */
     2596void Tesselation::AddCandidatePolygon(CandidateForTesselation CandidateLine, const double RADIUS, const LinkedCell *LC)
    25492597{
    25502598  Info FunctionInfo(__func__);
     
    25702618  Sprinter++;
    25712619  while(Sprinter != connectedClosestPoints->end()) {
    2572     // add the points
    2573     AddTesselationPoint(TurningPoint, 0);
    2574     AddTesselationPoint((*Runner), 1);
    2575     AddTesselationPoint((*Sprinter), 2);
    2576 
    2577     // add the lines
    2578     AddTesselationLine(TPS[0], TPS[1], 0);
    2579     AddTesselationLine(TPS[0], TPS[2], 1);
    2580     AddTesselationLine(TPS[1], TPS[2], 2);
    2581 
    2582     // add the triangles
    2583     BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
    2584     AddTesselationTriangle();
    2585     BTS->GetCenter(&Center);
     2620    // add this triangle
     2621    AddCandidateTriangle(TurningPoint, *Runner, *Sprinter);
     2622
     2623    // store values from tesselation procedure therein
    25862624    BTS->SetTopNode(CandidateLine.T);
    25872625    if (CandidateLine.T != NULL)  // start triangle has angle from top of -1
     
    25892627    else
    25902628      BTS->AngleFromTop = -1.;
     2629
     2630    // create normal vector
     2631    BTS->GetCenter(&Center);
    25912632    Center.SubtractVector(&CandidateLine.OptCenter);
    25922633    BTS->SphereCenter.CopyVector(&CandidateLine.OptCenter);
    25932634    BTS->GetNormalVector(Center);
    25942635
     2636    // give some verbose output about the whole procedure
    25952637    if (CandidateLine.T != NULL)
    25962638      Log() << Verbose(0) << "--> New triangle with " << *BTS << " and normal vector " << BTS->NormalVector << ", from " << *CandidateLine.T << " and angle " << CandidateLine.ShortestAngle << "." << endl;
    25972639    else
    25982640      Log() << Verbose(0) << "--> New starting triangle with " << *BTS << " and normal vector " << BTS->NormalVector << " and no top triangle." << endl;
     2641
     2642    // check whether its degenerate and if so, add the other side triangle as well
     2643    if (BTS->CheckDegeneracy(&CandidateLine.OtherOptCenter, RADIUS, LC)) {
     2644      Log() << Verbose(1) << "Triangle " << *BTS << " is degenerated, adding other side." << endl;
     2645      BoundaryTriangleSet * const triangle = BTS;
     2646      AddDegeneratedTriangle(BTS, &CandidateLine.OtherOptCenter, RADIUS, LC);
     2647      // check whether other side triangle has been created
     2648      if (BTS != NULL) {
     2649        BTS->SetTopNode(CandidateLine.T);
     2650        if (CandidateLine.T != NULL)  // start triangle has angle from top of -1
     2651          BTS->AngleFromTop = CandidateLine.ShortestAngle;
     2652        else
     2653          BTS->AngleFromTop = -1.;
     2654        BTS->SphereCenter.CopyVector(&CandidateLine.OtherOptCenter);
     2655        // normal vector points other way round
     2656        BTS->NormalVector.CopyVector(&triangle->NormalVector);
     2657        BTS->NormalVector.Scale(-1.);
     2658
     2659        // give some verbose output about the whole procedure
     2660        if (CandidateLine.T != NULL)
     2661          Log() << Verbose(0) << "--> New degenerate triangle with " << *BTS << " and normal vector " << BTS->NormalVector << ", from " << *CandidateLine.T << " and angle " << CandidateLine.ShortestAngle << "." << endl;
     2662        else
     2663          Log() << Verbose(0) << "--> New degenerate starting triangle with " << *BTS << " and normal vector " << BTS->NormalVector << " and no top triangle." << endl;
     2664      }
     2665    }
     2666
    25992667    Runner = Sprinter;
    26002668    Sprinter++;
     
    26042672  }
    26052673  delete(connectedClosestPoints);
     2674};
     2675
     2676/** If a given \a *triangle is degenerated, this adds the "other side".
     2677 * i.e. the triangle with same BoundaryPointSet's but NormalVector in opposite direction.
     2678 * \param *triangle degenerated triangle
     2679 * \param *OtherOptCenter center of the sphere for the other triangle
     2680 * \param RADIUS radius of sphere
     2681 * \param *LC pointer to LinkedCell structure
     2682 * \return pointer to created other triangle
     2683 */
     2684void Tesselation::AddDegeneratedTriangle(BoundaryTriangleSet *&triangle, Vector *OtherOptCenter, const double RADIUS, const LinkedCell *LC)
     2685{
     2686  Info FunctionInfo(__func__);
     2687  TesselPoint *ThirdNode = NULL;
     2688  BoundaryTriangleSet *otherTriangle = NULL;
     2689  /// 1. For each of the open sides of \a *triangle find best candidate
     2690  for (int i=0;i<3;i++) {
     2691    BLS[i] = NULL;
     2692    // go through all possible lines (also degenerate ones)
     2693    pair<LineMap::iterator,LineMap::iterator> FindPair = triangle->lines[i]->endpoints[0]->lines.equal_range(triangle->lines[i]->endpoints[1]->Nr);
     2694    for (LineMap::iterator FindLine = FindPair.first; FindLine != FindPair.second; FindLine++) {
     2695      if ((*FindLine).second->triangles.size() == 1) {
     2696        // check whether best Candidate for this line from the degenerate triangle is the third endpoint
     2697        CandidateForTesselation CandidateLine((*FindLine).second);
     2698        otherTriangle = ((*FindLine).second->triangles.begin())->second;  // this is unique and present, above we check that there is exactly one
     2699        ThirdNode = otherTriangle->GetThirdEndpoint((*FindLine).second)->node;
     2700        FindNextSuitableTriangle(CandidateLine, *triangle, RADIUS, LC);
     2701
     2702        /// 2. If best candidate is third endpoint,
     2703        for (TesselPointList::const_iterator Runner = CandidateLine.pointlist.begin(); Runner != CandidateLine.pointlist.end(); ++Runner) {
     2704          Log() << Verbose(1) << "Found candidate " << *(*Runner) << endl;
     2705          if ((*Runner) == ThirdNode) { // seems like we found a line to connect to
     2706            /// sets Tesselation::BLS[i] accordingly and removes the line from Tesselation::OpenLines
     2707            AddExistingTesselationTriangleLine((*FindLine).second,i);
     2708            break;
     2709          }
     2710        }
     2711      }
     2712    }
     2713    /// otherwise we create a new BoundaryLineSet for this Tesselation::BLS[i] and add it to OpenLines
     2714  }
     2715  if ((BLS[0] == NULL) && (BLS[1] == NULL) && (BLS[2] == NULL)) {
     2716    Log() << Verbose(0) << "This degenerate triangle would not share any line with its other side, rejecting." << endl;
     2717    BTS = NULL;
     2718  } else {
     2719    for (int i=0;i<3;i++) {
     2720      if (BLS[i] == NULL) {
     2721        AddNewTesselationTriangleLine(triangle->lines[i]->endpoints[0],triangle->lines[i]->endpoints[1],i);
     2722      }
     2723    }
     2724    /// 3. Create the triangle with opposite NormalVector and other center
     2725    BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
     2726    AddTesselationTriangle();
     2727  }
     2728};
     2729
     2730/** Adds a triangle to the Tesselation structure from three given TesselPoint's.
     2731 * \param *first first TesselPoint
     2732 * \param *second second TesselPoint
     2733 * \param *third third TesselPoint
     2734 */
     2735void Tesselation::AddCandidateTriangle(TesselPoint *first, TesselPoint *second, TesselPoint *third)
     2736{
     2737  Info FunctionInfo(__func__);
     2738  // add the points
     2739  AddTesselationPoint(first, 0);
     2740  AddTesselationPoint(second, 1);
     2741  AddTesselationPoint(third, 2);
     2742
     2743  // add the lines
     2744  AddTesselationLine(TPS[0], TPS[1], 0);
     2745  AddTesselationLine(TPS[0], TPS[2], 1);
     2746  AddTesselationLine(TPS[1], TPS[2], 2);
     2747
     2748  // add the triangles
     2749  BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
     2750  AddTesselationTriangle();
    26062751};
    26072752
  • src/tesselation.hpp

    rebb50e r474961  
    163163    bool IsPresentTupel(const BoundaryPointSet * const Points[3]) const;
    164164    bool IsPresentTupel(const BoundaryTriangleSet * const T) const;
     165    bool CheckDegeneracy(Vector *OtherOptCenter, const double RADIUS, const LinkedCell *LC) const;
    165166    void SetTopNode(const BoundaryTriangleSet * const topnode);
    166167
     
    283284    void SetTesselationPoint(TesselPoint* Candidate, const int n) const;
    284285    void AddTesselationLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n);
    285     void AlwaysAddTesselationTriangleLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n);
     286    void AddNewTesselationTriangleLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n);
     287    void AddExistingTesselationTriangleLine(class BoundaryLineSet *FindLine, int n);
    286288    void AddTesselationTriangle();
    287289    void AddTesselationTriangle(const int nr);
    288     void AddCandidatePolygon(CandidateForTesselation CandidateLine);
     290    void AddCandidateTriangle(TesselPoint *first, TesselPoint *second, TesselPoint *third);
     291    void AddDegeneratedTriangle(BoundaryTriangleSet *&triangle, Vector *OtherOptCenter, const double RADIUS, const LinkedCell *LC);
     292    void AddCandidatePolygon(CandidateForTesselation CandidateLine, const double RADIUS, const LinkedCell *LC);
    289293    void RemoveTesselationTriangle(class BoundaryTriangleSet *triangle);
    290294    void RemoveTesselationLine(class BoundaryLineSet *line);
  • src/unittests/tesselation_insideoutsideunittest.cpp

    rebb50e r474961  
    123123      OneLoopWithoutSuccessFlag = false;
    124124    else {
    125       TesselStruct->AddCandidatePolygon(*baseline);
     125      TesselStruct->AddCandidatePolygon(*baseline, SPHERERADIUS, LinkedList);
    126126    }
    127127  }
  • src/unittests/tesselationunittest.cpp

    rebb50e r474961  
    9191      OneLoopWithoutSuccessFlag = false;
    9292    else {
    93       TesselStruct->AddCandidatePolygon(*baseline);
     93      TesselStruct->AddCandidatePolygon(*baseline, SPHERERADIUS, LinkedList);
    9494    }
    9595  }
Note: See TracChangeset for help on using the changeset viewer.