Changeset 196a5a


Ignore:
Timestamp:
Dec 23, 2008, 11:21:29 AM (16 years ago)
Author:
Christian Neuen <neuen@…>
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:
02bfde
Parents:
7c6712
Message:

BallAngel enhanced, added new alternative direction for issues with right angles

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/boundary.cpp

    r7c6712 r196a5a  
    14221422 * @param c vector third point of triangle
    14231423 * @param Direction vector indicates up/down
     1424 * @param AlternativeDirection vecotr, needed in case the triangles have 90 deg angle
    14241425 * @param Halfplaneindicator double indicates whether Direction is up or down
     1426 * @param AlternativeIndicator doube indicates in case of orthogonal triangles which direction of AlternativeDirection is suitable
    14251427 * @param alpha double angle at a
    14261428 * @param beta double, angle at b
     
    14301432 */
    14311433
    1432   void Get_center_of_sphere(Vector* Center, Vector a, Vector b, Vector c, Vector* Direction, double HalfplaneIndicator,
    1433       double alpha, double beta, double gamma, double RADIUS, double Umkreisradius)
     1434  void Get_center_of_sphere(Vector* Center, Vector a, Vector b, Vector c, Vector* Direction, Vector* AlternativeDirection,
     1435      double HalfplaneIndicator, double AlternativeIndicator, double alpha, double beta, double gamma, double RADIUS, double Umkreisradius)
    14341436  {
    14351437    Vector TempNormal, helper;
     
    14371439
    14381440    *Center = a * sin(2.*alpha) + b * sin(2.*beta) + c * sin(2.*gamma) ;
    1439     Center->Scale(1/(sin(2*alpha) + sin(2*beta) + sin(2*gamma)));
     1441    Center->Scale(1./(sin(2.*alpha) + sin(2.*beta) + sin(2.*gamma)));
    14401442    // Here we calculated center of circumscribing circle, using barycentric coordinates
    14411443
     
    14451447    helper.SubtractVector(&c);
    14461448    TempNormal.VectorProduct(&helper);
    1447     if (TempNormal.ScalarProduct(Direction)<0 && HalfplaneIndicator >0 || TempNormal.ScalarProduct(Direction)>0 && HalfplaneIndicator<0)
     1449    if (fabs(HalfplaneIndicator) < MYEPSILON)
    14481450      {
    1449         TempNormal.Scale(-1);
     1451        if ((TempNormal.ScalarProduct(AlternativeDirection) <0 and AlternativeIndicator >0) or (TempNormal.ScalarProduct(AlternativeDirection) >0 and AlternativeIndicator <0))
     1452          {
     1453            TempNormal.Scale(-1);
     1454          }
     1455      }
     1456    else
     1457      {
     1458        if (TempNormal.ScalarProduct(Direction)<0 && HalfplaneIndicator >0 || TempNormal.ScalarProduct(Direction)>0 && HalfplaneIndicator<0)
     1459          {
     1460            TempNormal.Scale(-1);
     1461          }
    14501462      }
    14511463
     
    14691481 * @param a first point
    14701482 * @param b second point
     1483 * *param c atom old third point of old triangle
    14711484 * @param Candidate base point along whose bonds to start looking from
    14721485 * @param Parent point to avoid during search as its wrong direction
     
    14821495 */
    14831496
    1484 void Find_next_suitable_point_via_Angle_of_Sphere(atom* a, atom* b, atom* Candidate, atom* Parent,
     1497void Find_next_suitable_point_via_Angle_of_Sphere(atom* a, atom* b, atom* c, atom* Candidate, atom* Parent,
    14851498    int RecursionLevel, Vector *Chord, Vector *direction1, Vector *OldNormal, Vector ReferencePoint,
    14861499    atom*& Opt_Candidate, double *Storage, const double RADIUS, molecule* mol)
    14871500{
    1488 
    1489   cout << Verbose(1) << "Candidate is "<< Candidate->nr << endl;
    1490   cout << "ReferencePoint is " << ReferencePoint.x[0] << " "<< ReferencePoint.x[1] << " "<< ReferencePoint.x[2] << " "<< endl;
     1501  //cout << "ReferencePoint is " << ReferencePoint.x[0] << " "<< ReferencePoint.x[1] << " "<< ReferencePoint.x[2] << " "<< endl;
    14911502  /* OldNormal is normal vector on the old triangle
    14921503   * direction1 is normal on the triangle line, from which we come, as well as on OldNormal.
     
    15011512  double CurrentEpsilon = 0.1;
    15021513  double alpha, beta, gamma, SideA, SideB, SideC, sign, Umkreisradius, Restradius, Distance;
    1503   double BallAngle;
     1514  double BallAngle, AlternativeSign;
    15041515  atom *Walker; // variable atom point
    15051516
     
    15221533  gamma = dif_a.Angle(&dif_b);
    15231534
    1524   if (a != Candidate and b != Candidate)
     1535
     1536  if (a != Candidate and b != Candidate and c != Candidate)
    15251537    {
    15261538
     
    15321544      if (Umkreisradius < RADIUS) //Checking whether ball will at least rest on points.
    15331545        {
     1546          cout << Verbose(1) << "Candidate is "<< *Candidate << endl;
    15341547          sign = AngleCheck.ScalarProduct(direction1);
    1535           sign /= fabs(sign); // +1 if in direction of triangle plane, -1 if in other direction...
    1536 
    1537           Get_center_of_sphere(&Mittelpunkt, (a->x), (b->x), (Candidate->x), OldNormal, sign, alpha, beta, gamma, RADIUS, Umkreisradius);
     1548          if (fabs(sign)<MYEPSILON)
     1549            {
     1550              if (AngleCheck.ScalarProduct(OldNormal)<0)
     1551                {
     1552                  sign =0;
     1553                  AlternativeSign=1;
     1554                }
     1555              else
     1556                {
     1557                  sign =0;
     1558                  AlternativeSign=-1;
     1559                }
     1560            }
     1561          else
     1562            {
     1563              sign /= fabs(sign);
     1564            }
     1565
     1566
     1567
     1568          Get_center_of_sphere(&Mittelpunkt, (a->x), (b->x), (Candidate->x), OldNormal, direction1, sign, AlternativeSign, alpha, beta, gamma, RADIUS, Umkreisradius);
    15381569
    15391570          AngleCheck.CopyVector(&ReferencePoint);
    15401571          AngleCheck.Scale(-1);
    1541           cout << "AngleCheck is " << AngleCheck.x[0] << " "<< AngleCheck.x[1] << " "<< AngleCheck.x[2] << " "<< endl;
     1572          //cout << "AngleCheck is " << AngleCheck.x[0] << " "<< AngleCheck.x[1] << " "<< AngleCheck.x[2] << " "<< endl;
    15421573          AngleCheck.AddVector(&Mittelpunkt);
    1543           cout << "AngleCheck is " << AngleCheck.x[0] << " "<< AngleCheck.x[1] << " "<< AngleCheck.x[2] << " "<< endl;
     1574          //cout << "AngleCheck is " << AngleCheck.x[0] << " "<< AngleCheck.x[1] << " "<< AngleCheck.x[2] << " "<< endl;
    15441575
    15451576          BallAngle = AngleCheck.Angle(OldNormal);
    1546           cout << "direction1 is " << direction1->x[0] <<" "<< direction1->x[1] <<" "<< direction1->x[2] <<" " << endl;
    1547           cout << "AngleCheck is " << AngleCheck.x[0] << " "<< AngleCheck.x[1] << " "<< AngleCheck.x[2] << " "<< endl;
    1548           sign = AngleCheck.ScalarProduct(direction1);
    1549           sign /= fabs(sign);
    1550 
    1551 
    1552           if (sign >0)
     1577
     1578          //cout << "direction1 is " << direction1->x[0] <<" "<< direction1->x[1] <<" "<< direction1->x[2] <<" " << endl;
     1579          //cout << "AngleCheck is " << AngleCheck.x[0] << " "<< AngleCheck.x[1] << " "<< AngleCheck.x[2] << " "<< endl;
     1580
     1581          cout << Verbose(1) << "BallAngle is " << BallAngle << " Sign is " << sign << endl;
     1582
     1583          if (AngleCheck.ScalarProduct(direction1) >=0)
    15531584            {
    15541585              if (Storage[0]< -1.5) // first Candidate at all
     
    15581589                  Opt_Candidate = Candidate;
    15591590                  Storage[0] = sign;
    1560                   Storage[1] = BallAngle;
    1561                   cout << "Angle is " << Storage[1] << ", Halbraum ist "
     1591                  Storage[1] = AlternativeSign;
     1592                  Storage[2] = BallAngle;
     1593                  cout << "Angle is " << Storage[2] << ", Halbraum ist "
    15621594                    << Storage[0] << endl;
    15631595
     
    15661598              else
    15671599                {
    1568                   if ( Storage[1] > BallAngle)
     1600                  if ( Storage[2] > BallAngle)
    15691601                    {
    15701602                      cout << "Next better candidate is " << *Candidate << " with ";
    15711603                      Opt_Candidate = Candidate;
    15721604                      Storage[0] = sign;
    1573                       Storage[1] = BallAngle;
    1574                       cout << "Angle is " << Storage[1] << ", Halbraum ist "
     1605                      Storage[1] = AlternativeSign;
     1606                      Storage[2] = BallAngle;
     1607                      cout << "Angle is " << Storage[2] << ", Halbraum ist "
    15751608                        << Storage[0] << endl;
    15761609                    }
    15771610                  else
    15781611                    {
    1579                       if (DEBUG)
    1580                         {
    1581                           cout << "Looses to better candidate" << endl;
    1582                         }
     1612                      //if (DEBUG)
     1613                        cout << "Looses to better candidate" << endl;
     1614
    15831615                    }
    15841616                }
     
    15861618            else
    15871619              {
    1588                 cout << "Refused due to sign which is " << sign << endl;
     1620                //if (DEBUG)
     1621                  cout << "Refused due to bad direction of ball centre." << endl;
    15891622              }
    15901623          }
    15911624        else
    15921625          {
    1593             if (DEBUG)
    1594               {
    1595                 cout << "Doesn't satisfy requirements for circumscribing circle" << endl;
    1596               }
     1626            //if (DEBUG)
     1627              cout << "Doesn't satisfy requirements for circumscribing circle" << endl;
    15971628          }
    15981629      }
    15991630    else
    16001631      {
    1601         if (DEBUG)
    1602           {
    1603             cout << "identisch mit Ursprungslinie" << endl;
    1604           }
     1632        //if (DEBUG)
     1633          cout << "identisch mit Ursprungslinie" << endl;
     1634
    16051635      }
    16061636
    16071637
    16081638
    1609   if (RecursionLevel < 7) // Five is the recursion level threshold.
     1639  if (RecursionLevel < 9) // Seven is the recursion level threshold.
    16101640    {
    16111641      for (int i = 0; i < mol->NumberOfBondsPerAtom[Candidate->nr]; i++) // go through all bond
     
    16191649          else
    16201650            {
    1621               Find_next_suitable_point_via_Angle_of_Sphere(a, b, Walker, Candidate, RecursionLevel
     1651              Find_next_suitable_point_via_Angle_of_Sphere(a, b, c, Walker, Candidate, RecursionLevel
    16221652                  + 1, Chord, direction1, OldNormal, ReferencePoint, Opt_Candidate, Storage, RADIUS,
    16231653                  mol); //call function again
     
    19101940  ofstream *tempstream = NULL;
    19111941  char filename[255];
    1912   //atom* Walker;
    1913 
    1914   double Storage[2];
     1942  atom* OldThirdPoint;
     1943
     1944  double Storage[3];
    19151945  Storage[0] = -2.; // This direction is either +1 or -1 one, so any result will take precedence over initial values
    1916   Storage[1] = 9999999.; // This is also lower then any value produced by an eligible atom, which are all positive
     1946  Storage[1] = -2.; // This is also lower then any value produced by an eligible atom, which are all positive
     1947  Storage[2] = 9999999.;
    19171948  atom* Opt_Candidate = NULL;
    19181949  Vector Opt_Mittelpunkt;
     
    19251956          && T.endpoints[i]->node->nr != Line.endpoints[1]->node->nr)
    19261957        {
     1958          OldThirdPoint = T.endpoints[i]->node;
    19271959          helper.SubtractVector(&T.endpoints[i]->node->x);
    19281960          break;
     
    19571989
    19581990    Umkreismittelpunkt = (T.endpoints[0]->node->x) * sin(2.*alpha) + T.endpoints[1]->node->x * sin(2.*beta) + (T.endpoints[2]->node->x) * sin(2.*gamma) ;
    1959     cout << "UmkreisMittelpunkt is " << Umkreismittelpunkt.x[0] << " "<< Umkreismittelpunkt.x[1] << " "<< Umkreismittelpunkt.x[2] << " "<< endl;
     1991    //cout << "UmkreisMittelpunkt is " << Umkreismittelpunkt.x[0] << " "<< Umkreismittelpunkt.x[1] << " "<< Umkreismittelpunkt.x[2] << " "<< endl;
    19601992    Umkreismittelpunkt.Scale(1/(sin(2*alpha) + sin(2*beta) + sin(2*gamma)));
    19611993    cout << "UmkreisMittelpunkt is " << Umkreismittelpunkt.x[0] << " "<< Umkreismittelpunkt.x[1] << " "<< Umkreismittelpunkt.x[2] << " "<< endl;
     1994    cout << " We look over line " << Line << " in direction " << direction1.x[0] << " " << direction1.x[1] << " " << direction1.x[2] << " " << endl;
     1995    cout << " Old Normal is " <<  (T.NormalVector.x)[0] << " " << T.NormalVector.x[1] << " " << (T.NormalVector.x)[2] << " " << endl;
    19621996
    19631997
    19641998  cout << Verbose(1) << "Looking for third point candidates for triangle ... " << endl;
    19651999
    1966   Find_next_suitable_point_via_Angle_of_Sphere(Line.endpoints[0]->node, Line.endpoints[1]->node,
     2000  Find_next_suitable_point_via_Angle_of_Sphere(Line.endpoints[0]->node, Line.endpoints[1]->node, OldThirdPoint,
    19672001      Line.endpoints[0]->node, Line.endpoints[1]->node, 0, &Chord, &direction1,
    19682002      &(T.NormalVector), Umkreismittelpunkt, Opt_Candidate, Storage, RADIUS, mol);
    1969   Find_next_suitable_point_via_Angle_of_Sphere(Line.endpoints[0]->node, Line.endpoints[1]->node,
     2003  Find_next_suitable_point_via_Angle_of_Sphere(Line.endpoints[0]->node, Line.endpoints[1]->node, OldThirdPoint,
    19702004      Line.endpoints[1]->node, Line.endpoints[0]->node, 0, &Chord, &direction1,
    19712005      &(T.NormalVector), Umkreismittelpunkt, Opt_Candidate, Storage, RADIUS, mol);
    19722006
    19732007
    1974   if ((TrianglesOnBoundaryCount % 10) == 0)
     2008      cout << "Letzter Winkel bei " << TrianglesOnBoundaryCount << " Winkel ist " << Storage[2] << endl;
     2009
     2010
     2011  if ((TrianglesOnBoundaryCount % 1) == 0)
    19752012    {
    19762013    sprintf(filename, "testEnvelope-%d.dat", TriangleFilesWritten);
     
    19822019  }
    19832020
    1984   if (TrianglesOnBoundaryCount >1000 )
     2021  if (TrianglesOnBoundaryCount >189 and TrianglesOnBoundaryCount < 200 )
    19852022    {
    19862023      cout << Verbose(1)
     
    20102047
    20112048  if ((BTS->NormalVector.ScalarProduct(&(T.NormalVector)) < 0 && Storage[0] > 0)  ||
    2012       (BTS->NormalVector.ScalarProduct(&(T.NormalVector)) > 0 && Storage[0] < 0))
     2049      (BTS->NormalVector.ScalarProduct(&(T.NormalVector)) > 0 && Storage[0] < 0) ||
     2050      (fabs(Storage[0]) < MYEPSILON && Storage[1]*BTS->NormalVector.ScalarProduct(&direction1) < 0) )
     2051
    20132052    {
    20142053      BTS->NormalVector.Scale(-1);
     
    20192058
    20202059void Find_second_point_for_Tesselation(atom* a, atom* Candidate, atom* Parent,
    2021     int RecursionLevel, Vector Oben, atom*& Opt_Candidate, double Storage[2],
     2060    int RecursionLevel, Vector Oben, atom*& Opt_Candidate, double Storage[3],
    20222061    molecule* mol, double RADIUS)
    20232062{
     
    20412080          if (AngleCheck.Angle(&Oben) < Storage[0])
    20422081            {
    2043               //cout << Verbose(1) << "Old values of Storage: %lf %lf \n", Storage[0], Storage[1]);
     2082              //cout << Verbose(1) << "Old values of Storage: %lf %lf \n", Storage[0], Storage[2]);
    20442083              cout << "Next better candidate is " << *Candidate
    20452084                  << " with distance " << norm << ".\n";
    20462085              Opt_Candidate = Candidate;
    20472086              Storage[0] = AngleCheck.Angle(&Oben);
    2048               //cout << Verbose(1) << "Changing something in Storage: %lf %lf. \n", Storage[0], Storage[1]);
     2087              //cout << Verbose(1) << "Changing something in Storage: %lf %lf. \n", Storage[0], Storage[2]);
    20492088            }
    20502089          else
     
    21252164  cout << Verbose(1) << "Coordinates of start atom " << *FirstPoint << ": "
    21262165      << FirstPoint->x.x[0] << endl;
    2127   double Storage[2];
     2166  double Storage[3];
    21282167  atom* Opt_Candidate = NULL;
    21292168  Storage[0] = 999999.; // This will contain the angle, which will be always positive (when looking for second point), when looking for third point this will be the quadrant.
    21302169  Storage[1] = 999999.; // This will be an angle looking for the third point.
     2170  Storage[2] = 999999.;
    21312171  cout << Verbose(1) << "Number of Bonds: "
    21322172      << mol->NumberOfBondsPerAtom[FirstPoint->nr] << endl;
     
    21452185  Storage[0] = -2.; // This will indicate the quadrant.
    21462186  Storage[1] = 9999999.; // This will be an angle looking for the third point.
     2187  Storage[2] = 9999999.;
    21472188
    21482189  Chord.CopyVector(&(FirstPoint->x)); // bring into calling function
     
    21512192
    21522193  cout << Verbose(1) << "Looking for third point candidates \n";
     2194  cout << Verbose(1) << " In direction " << helper.x[0] << " " << helper.x[1] << " " << helper.x[2] << " " << endl;
    21532195  // look in one direction of baseline for initial candidate
    21542196  Opt_Candidate = NULL;
    21552197  CenterOfFirstLine.CopyVector(&Chord);
    2156   CenterOfFirstLine.Scale(-0.5);
     2198  CenterOfFirstLine.Scale(0.5);
    21572199  CenterOfFirstLine.AddVector(&(SecondPoint->x));
    21582200
    2159   Find_next_suitable_point_via_Angle_of_Sphere(FirstPoint, SecondPoint, SecondPoint, FirstPoint, 0,
     2201  Find_next_suitable_point_via_Angle_of_Sphere(FirstPoint, SecondPoint, SecondPoint, SecondPoint, FirstPoint, 0,
    21602202      &Chord, &helper, &Oben, CenterOfFirstLine,  Opt_Candidate, Storage, RADIUS, mol);
    21612203  // look in other direction of baseline for possible better candidate
    2162   Find_next_suitable_point_via_Angle_of_Sphere(FirstPoint, SecondPoint, FirstPoint, SecondPoint, 0,
     2204  Find_next_suitable_point_via_Angle_of_Sphere(FirstPoint, SecondPoint, SecondPoint, FirstPoint, SecondPoint, 0,
    21632205      &Chord, &helper, &Oben, CenterOfFirstLine, Opt_Candidate, Storage, RADIUS, mol);
    21642206  cout << Verbose(1) << "Third Point is " << *Opt_Candidate << endl;
Note: See TracChangeset for help on using the changeset viewer.