Changeset 7c6712 for src/boundary.cpp


Ignore:
Timestamp:
Dec 19, 2008, 4:21:11 PM (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:
196a5a, 44fd95
Parents:
e9fa06f
Message:

Switched choice process to Ball angle completely.
Problem remains.
Same position?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/boundary.cpp

    re9fa06f r7c6712  
    14151415;
    14161416
     1417/**
     1418 * Function returns center of sphere with RADIUS, which rests on points a, b, c
     1419 * @param Center this vector will be used for return
     1420 * @param a vector first point of triangle
     1421 * @param b vector second point of triangle
     1422 * @param c vector third point of triangle
     1423 * @param Direction vector indicates up/down
     1424 * @param Halfplaneindicator double indicates whether Direction is up or down
     1425 * @param alpha double angle at a
     1426 * @param beta double, angle at b
     1427 * @param gamma, double, angle at c
     1428 * @param Radius, double
     1429 * @param Umkreisradius double radius of circumscribing circle
     1430 */
     1431
     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  {
     1435    Vector TempNormal, helper;
     1436    double Restradius;
     1437
     1438    *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)));
     1440    // Here we calculated center of circumscribing circle, using barycentric coordinates
     1441
     1442    TempNormal.CopyVector(&a);
     1443    TempNormal.SubtractVector(&b);
     1444    helper.CopyVector(&a);
     1445    helper.SubtractVector(&c);
     1446    TempNormal.VectorProduct(&helper);
     1447    if (TempNormal.ScalarProduct(Direction)<0 && HalfplaneIndicator >0 || TempNormal.ScalarProduct(Direction)>0 && HalfplaneIndicator<0)
     1448      {
     1449        TempNormal.Scale(-1);
     1450      }
     1451
     1452    TempNormal.Normalize();
     1453    Restradius = sqrt(RADIUS*RADIUS - Umkreisradius*Umkreisradius);
     1454    TempNormal.Scale(Restradius);
     1455
     1456    Center->AddVector(&TempNormal);
     1457  }
     1458  ;
     1459
     1460
    14171461/** This recursive function finds a third point, to form a triangle with two given ones.
    14181462 * Two atoms are fixed, a candidate is supplied, additionally two vectors for direction distinction, a Storage area to \
     
    14291473 * @param RecursionLevel contains current recursion depth
    14301474 * @param Chord baseline vector of first and second point
    1431  * @param d1 second in plane vector (along with \a Chord) of the triangle the baseline belongs to
     1475 * @param direction1 second in plane vector (along with \a Chord) of the triangle the baseline belongs to
    14321476 * @param OldNormal normal of the triangle which the baseline belongs to
     1477 * @param ReferencePoint Vector of center of circumscribing circle from which we look towards center of sphere
    14331478 * @param Opt_Candidate candidate reference to return
    1434  * @param Opt_Mittelpunkt Centerpoint of ball, when resting on Opt_Candidate
    14351479 * @param Storage array containing two angles of current Opt_Candidate
    14361480 * @param RADIUS radius of ball
    14371481 * @param mol molecule structure with atoms and bonds
    14381482 */
     1483
     1484void Find_next_suitable_point_via_Angle_of_Sphere(atom* a, atom* b, atom* Candidate, atom* Parent,
     1485    int RecursionLevel, Vector *Chord, Vector *direction1, Vector *OldNormal, Vector ReferencePoint,
     1486    atom*& Opt_Candidate, double *Storage, const double RADIUS, molecule* mol)
     1487{
     1488
     1489  cout << Verbose(1) << "Candidate is "<< Candidate->nr << endl;
     1490  cout << "ReferencePoint is " << ReferencePoint.x[0] << " "<< ReferencePoint.x[1] << " "<< ReferencePoint.x[2] << " "<< endl;
     1491  /* OldNormal is normal vector on the old triangle
     1492   * direction1 is normal on the triangle line, from which we come, as well as on OldNormal.
     1493   * Chord points from b to a!!!
     1494   */
     1495  Vector dif_a; //Vector from a to candidate
     1496  Vector dif_b; //Vector from b to candidate
     1497  Vector AngleCheck;
     1498  Vector TempNormal, Umkreismittelpunkt;
     1499  Vector Mittelpunkt;
     1500
     1501  double CurrentEpsilon = 0.1;
     1502  double alpha, beta, gamma, SideA, SideB, SideC, sign, Umkreisradius, Restradius, Distance;
     1503  double BallAngle;
     1504  atom *Walker; // variable atom point
     1505
     1506
     1507  dif_a.CopyVector(&(a->x));
     1508  dif_a.SubtractVector(&(Candidate->x));
     1509  dif_b.CopyVector(&(b->x));
     1510  dif_b.SubtractVector(&(Candidate->x));
     1511  AngleCheck.CopyVector(&(Candidate->x));
     1512  AngleCheck.SubtractVector(&(a->x));
     1513  AngleCheck.ProjectOntoPlane(Chord);
     1514
     1515  SideA = dif_b.Norm();
     1516  SideB = dif_a.Norm();
     1517  SideC = Chord->Norm();
     1518  //Chord->Scale(-1);
     1519
     1520  alpha = Chord->Angle(&dif_a);
     1521  beta = M_PI - Chord->Angle(&dif_b);
     1522  gamma = dif_a.Angle(&dif_b);
     1523
     1524  if (a != Candidate and b != Candidate)
     1525    {
     1526
     1527      Umkreisradius = SideA / 2.0 / sin(alpha);
     1528      //cout << Umkreisradius << endl;
     1529      //cout << SideB / 2.0 / sin(beta) << endl;
     1530      //cout << SideC / 2.0 / sin(gamma) << endl;
     1531
     1532      if (Umkreisradius < RADIUS) //Checking whether ball will at least rest on points.
     1533        {
     1534          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);
     1538
     1539          AngleCheck.CopyVector(&ReferencePoint);
     1540          AngleCheck.Scale(-1);
     1541          cout << "AngleCheck is " << AngleCheck.x[0] << " "<< AngleCheck.x[1] << " "<< AngleCheck.x[2] << " "<< endl;
     1542          AngleCheck.AddVector(&Mittelpunkt);
     1543          cout << "AngleCheck is " << AngleCheck.x[0] << " "<< AngleCheck.x[1] << " "<< AngleCheck.x[2] << " "<< endl;
     1544
     1545          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)
     1553            {
     1554              if (Storage[0]< -1.5) // first Candidate at all
     1555                {
     1556
     1557                  cout << "Next better candidate is " << *Candidate << " with ";
     1558                  Opt_Candidate = Candidate;
     1559                  Storage[0] = sign;
     1560                  Storage[1] = BallAngle;
     1561                  cout << "Angle is " << Storage[1] << ", Halbraum ist "
     1562                    << Storage[0] << endl;
     1563
     1564
     1565                }
     1566              else
     1567                {
     1568                  if ( Storage[1] > BallAngle)
     1569                    {
     1570                      cout << "Next better candidate is " << *Candidate << " with ";
     1571                      Opt_Candidate = Candidate;
     1572                      Storage[0] = sign;
     1573                      Storage[1] = BallAngle;
     1574                      cout << "Angle is " << Storage[1] << ", Halbraum ist "
     1575                        << Storage[0] << endl;
     1576                    }
     1577                  else
     1578                    {
     1579                      if (DEBUG)
     1580                        {
     1581                          cout << "Looses to better candidate" << endl;
     1582                        }
     1583                    }
     1584                }
     1585              }
     1586            else
     1587              {
     1588                cout << "Refused due to sign which is " << sign << endl;
     1589              }
     1590          }
     1591        else
     1592          {
     1593            if (DEBUG)
     1594              {
     1595                cout << "Doesn't satisfy requirements for circumscribing circle" << endl;
     1596              }
     1597          }
     1598      }
     1599    else
     1600      {
     1601        if (DEBUG)
     1602          {
     1603            cout << "identisch mit Ursprungslinie" << endl;
     1604          }
     1605      }
     1606
     1607
     1608
     1609  if (RecursionLevel < 7) // Five is the recursion level threshold.
     1610    {
     1611      for (int i = 0; i < mol->NumberOfBondsPerAtom[Candidate->nr]; i++) // go through all bond
     1612        {
     1613          Walker = mol->ListOfBondsPerAtom[Candidate->nr][i]->GetOtherAtom(
     1614              Candidate);
     1615          if (Walker == Parent)
     1616            { // don't go back the same bond
     1617              continue;
     1618            }
     1619          else
     1620            {
     1621              Find_next_suitable_point_via_Angle_of_Sphere(a, b, Walker, Candidate, RecursionLevel
     1622                  + 1, Chord, direction1, OldNormal, ReferencePoint, Opt_Candidate, Storage, RADIUS,
     1623                  mol); //call function again
     1624            }
     1625        }
     1626    }
     1627}
     1628;
     1629
     1630
     1631  /** This recursive function finds a third point, to form a triangle with two given ones.
     1632   * Two atoms are fixed, a candidate is supplied, additionally two vectors for direction distinction, a Storage area to \
     1633   *  supply results to the calling function, the radius of the sphere which the triangle shall support and the molecule \
     1634   *  upon which we operate.
     1635   *  If the candidate is more fitting to support the sphere than the already stored atom is, then we write its general \
     1636   *  direction and angle into Storage.
     1637   *  We the determine the recursive level we have reached and if this is not on the threshold yet, call this function again, \
     1638   *  with all neighbours of the candidate.
     1639   * @param a first point
     1640   * @param b second point
     1641   * @param Candidate base point along whose bonds to start looking from
     1642   * @param Parent point to avoid during search as its wrong direction
     1643   * @param RecursionLevel contains current recursion depth
     1644   * @param Chord baseline vector of first and second point
     1645   * @param d1 second in plane vector (along with \a Chord) of the triangle the baseline belongs to
     1646   * @param OldNormal normal of the triangle which the baseline belongs to
     1647   * @param Opt_Candidate candidate reference to return
     1648   * @param Opt_Mittelpunkt Centerpoint of ball, when resting on Opt_Candidate
     1649   * @param Storage array containing two angles of current Opt_Candidate
     1650   * @param RADIUS radius of ball
     1651   * @param mol molecule structure with atoms and bonds
     1652   */
     1653
    14391654void Find_next_suitable_point(atom* a, atom* b, atom* Candidate, atom* Parent,
    14401655    int RecursionLevel, Vector *Chord, Vector *d1, Vector *OldNormal,
     
    16691884                  + 1, Chord, d1, OldNormal, Opt_Candidate, Opt_Mittelpunkt, Storage, RADIUS,
    16701885                  mol); //call function again
     1886
    16711887            }
    16721888        }
     
    16841900 * @param N number of found triangles
    16851901 */
    1686 void
    1687 Tesselation::Find_next_suitable_triangle(ofstream *out, ofstream *tecplot,
     1902void Tesselation::Find_next_suitable_triangle(ofstream *out, ofstream *tecplot,
    16881903    molecule* mol, BoundaryLineSet &Line, BoundaryTriangleSet &T,
    16891904    const double& RADIUS, int N)
     
    17271942  Chord.SubtractVector(&(Line.endpoints[1]->node->x));
    17281943
    1729   {
    1730     Vector TempNormal, Umkreismittelpunkt, Mittelpunkt;
    1731     double alpha, beta, gamma, SideA, SideB, SideC, sign, Umkreisradius, Restradius, Distance;
    1732 
    1733     SideA = dif_b.Norm();
    1734       SideB = dif_a.Norm();
    1735       SideC = Chord->Norm();
    1736       //Chord->Scale(-1);
    1737 
    1738       alpha = Chord->Angle(&dif_a);
    1739       beta = M_PI - Chord->Angle(&dif_b);
    1740       gamma = dif_a.Angle(&dif_b);
    1741 
    1742       Umkreismittelpunkt = (a->x) * sin(2.*alpha) + b->x * sin(2.*beta) + (Candidate->x) * sin(2.*gamma) ;
    1743       Umkreismittelpunkt.Scale(1/(sin(2*alpha) + sin(2*beta) + sin(2*gamma)));
    1744   }
     1944
     1945    Vector Umkreismittelpunkt, a, b, c;
     1946    double alpha, beta, gamma;
     1947    a.CopyVector(&(T.endpoints[0]->node->x));
     1948    b.CopyVector(&(T.endpoints[1]->node->x));
     1949    c.CopyVector(&(T.endpoints[2]->node->x));
     1950    a.SubtractVector(&(T.endpoints[1]->node->x));
     1951    b.SubtractVector(&(T.endpoints[2]->node->x));
     1952    c.SubtractVector(&(T.endpoints[0]->node->x));
     1953
     1954    alpha = M_PI - a.Angle(&c);
     1955    beta = M_PI - b.Angle(&a);
     1956    gamma = M_PI - c.Angle(&b);
     1957
     1958    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;
     1960    Umkreismittelpunkt.Scale(1/(sin(2*alpha) + sin(2*beta) + sin(2*gamma)));
     1961    cout << "UmkreisMittelpunkt is " << Umkreismittelpunkt.x[0] << " "<< Umkreismittelpunkt.x[1] << " "<< Umkreismittelpunkt.x[2] << " "<< endl;
     1962
     1963
    17451964  cout << Verbose(1) << "Looking for third point candidates for triangle ... " << endl;
    17461965
    1747   Find_next_suitable_point(Line.endpoints[0]->node, Line.endpoints[1]->node,
     1966  Find_next_suitable_point_via_Angle_of_Sphere(Line.endpoints[0]->node, Line.endpoints[1]->node,
    17481967      Line.endpoints[0]->node, Line.endpoints[1]->node, 0, &Chord, &direction1,
    1749       &(T.NormalVector), Opt_Candidate, &Opt_Mittelpunkt, Storage, RADIUS, mol);
    1750   Find_next_suitable_point(Line.endpoints[0]->node, Line.endpoints[1]->node,
     1968      &(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,
    17511970      Line.endpoints[1]->node, Line.endpoints[0]->node, 0, &Chord, &direction1,
    1752       &(T.NormalVector), Opt_Candidate, &Opt_Mittelpunkt, Storage, RADIUS, mol);
     1971      &(T.NormalVector), Umkreismittelpunkt, Opt_Candidate, Storage, RADIUS, mol);
    17531972
    17541973
     
    17992018;
    18002019
    1801 void
    1802 Find_second_point_for_Tesselation(atom* a, atom* Candidate, atom* Parent,
     2020void Find_second_point_for_Tesselation(atom* a, atom* Candidate, atom* Parent,
    18032021    int RecursionLevel, Vector Oben, atom*& Opt_Candidate, double Storage[2],
    18042022    molecule* mol, double RADIUS)
     
    18602078;
    18612079
    1862 void
    1863 Tesselation::Find_starting_triangle(molecule* mol, const double RADIUS)
     2080void Tesselation::Find_starting_triangle(molecule* mol, const double RADIUS)
    18642081{
    18652082  cout << Verbose(1) << "Looking for starting triangle \n";
     
    18732090  Vector helper;
    18742091  Vector Chord;
    1875   Vector Opt_Mittelpunkt;
     2092  Vector CenterOfFirstLine;
    18762093
    18772094  Oben.Zero();
     
    19362153  // look in one direction of baseline for initial candidate
    19372154  Opt_Candidate = NULL;
    1938   Opt_Mittelpunkt;
    1939   Find_next_suitable_point(FirstPoint, SecondPoint, SecondPoint, FirstPoint, 0,
    1940       &Chord, &helper, &Oben, Opt_Candidate, &Opt_Mittelpunkt, Storage, RADIUS, mol);
     2155  CenterOfFirstLine.CopyVector(&Chord);
     2156  CenterOfFirstLine.Scale(-0.5);
     2157  CenterOfFirstLine.AddVector(&(SecondPoint->x));
     2158
     2159  Find_next_suitable_point_via_Angle_of_Sphere(FirstPoint, SecondPoint, SecondPoint, FirstPoint, 0,
     2160      &Chord, &helper, &Oben, CenterOfFirstLine,  Opt_Candidate, Storage, RADIUS, mol);
    19412161  // look in other direction of baseline for possible better candidate
    1942   Find_next_suitable_point(FirstPoint, SecondPoint, FirstPoint, SecondPoint, 0,
    1943       &Chord, &helper, &Oben, Opt_Candidate, &Opt_Mittelpunkt, Storage, RADIUS, mol);
     2162  Find_next_suitable_point_via_Angle_of_Sphere(FirstPoint, SecondPoint, FirstPoint, SecondPoint, 0,
     2163      &Chord, &helper, &Oben, CenterOfFirstLine, Opt_Candidate, Storage, RADIUS, mol);
    19442164  cout << Verbose(1) << "Third Point is " << *Opt_Candidate << endl;
    19452165
     
    19672187;
    19682188
    1969 void
    1970 Find_non_convex_border(ofstream *out, ofstream *tecplot, molecule* mol)
     2189void Find_non_convex_border(ofstream *out, ofstream *tecplot, molecule* mol)
    19712190{
    19722191  int N = 0;
Note: See TracChangeset for help on using the changeset viewer.