source: src/Fragmentation/Exporters/unittests/SphericalPointDistributionUnitTest_assistant.hpp@ 2d8c4e

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
Last change on this file since 2d8c4e was 6393ff, checked in by Frederik Heber <heber@…>, 9 years ago

Added getConnections() to SphericalPointDistribution.

  • we use tesselation in order to extract the connection information between nearest neighboring points from the BoundaryLines of the tesselation. The triangles are ideal as they assure that no point lies within a triangle, hence all these points may be safely combined.
  • functions reside in extra module as with get().
  • added extensive unit tests.
  • Property mode set to 100644
File size: 3.8 KB
Line 
1/*
2 * SphericalPointDistribution_assistant.hpp
3 *
4 * Created on: Jul 12, 2014
5 * Author: heber
6 */
7
8#ifndef SPHERICALPOINTDISTRIBUTION_ASSISTANT_HPP_
9#define SPHERICALPOINTDISTRIBUTION_ASSISTANT_HPP_
10
11// include config.h
12#ifdef HAVE_CONFIG_H
13#include <config.h>
14#endif
15
16#include "SphericalPointDistributionUnitTest.hpp"
17
18#include "CodePatterns/Log.hpp"
19
20#include "Atom/TesselPoint.hpp"
21#include "Fragmentation/Exporters/SphericalPointDistribution.hpp"
22#include "LinkedCell/linkedcell.hpp"
23#include "LinkedCell/PointCloudAdaptor.hpp"
24#include "Tesselation/BoundaryLineSet.hpp"
25#include "Tesselation/tesselation.hpp"
26
27
28// class generator: taken from www.cplusplus.com example std::generate
29struct c_unique {
30 unsigned int current;
31 c_unique() {current=0;}
32 unsigned int operator()() {return current++;}
33} UniqueNumber;
34
35struct VectorToTesselPoint
36{
37 TesselPoint * operator()(const Vector &_v, const unsigned int _index) {
38 TesselPoint *t = new TesselPoint();
39 t->setPosition(_v);
40 t->setNr(_index);
41 return t;
42 }
43};
44
45/** UnitTest for getConnections()
46 */
47template <int N>
48void SphericalPointDistributionTest_assistant::getConnectionTest()
49{
50 SphericalPointDistribution SPD(1.);
51 // get the points and convert into TesselPoint list
52 SphericalPointDistribution::Polygon_t newpolygon = SPD.get<N>();
53 TesselPointSTLList Corners;
54 SphericalPointDistribution::IndexList_t indices(N);
55 std::generate(indices.begin(), indices.end(), UniqueNumber);
56 std::transform(
57 newpolygon.begin(), newpolygon.end(),
58 indices.begin(),
59 std::back_inserter(Corners),
60 VectorToTesselPoint());
61
62 // create the tesselation
63 const double SPHERERADIUS = 1.5;
64 Tesselation TesselStruct;
65 PointCloudAdaptor<TesselPointSTLList> cloud(&Corners, "TesselPointSTLList");
66 TesselStruct(cloud, SPHERERADIUS);
67
68 // create a adjacency list from a tesselation of the (convex set of) points
69 SphericalPointDistribution::adjacency_t adjacency;
70 for (LineMap::const_iterator iter = TesselStruct.LinesOnBoundary.begin();
71 iter != TesselStruct.LinesOnBoundary.end(); ++iter) {
72 const BoundaryLineSet * const line = iter->second;
73 {
74 std::pair< SphericalPointDistribution::adjacency_t::iterator, bool > inserter =
75 adjacency.insert(
76 std::make_pair(
77 line->endpoints[0]->Nr,
78 SphericalPointDistribution::IndexSet_t() ));
79 inserter.first->second.insert(line->endpoints[1]->Nr);
80 LOG(6, "DEBUG: Inserting " << line->endpoints[0]->Nr << "," << line->endpoints[1]->Nr);
81 }
82 {
83 std::pair< SphericalPointDistribution::adjacency_t::iterator, bool > inserter =
84 adjacency.insert(
85 std::make_pair(
86 line->endpoints[1]->Nr,
87 SphericalPointDistribution::IndexSet_t() ));
88 inserter.first->second.insert(line->endpoints[0]->Nr);
89 LOG(6, "DEBUG: Inserting " << line->endpoints[1]->Nr << "," << line->endpoints[0]->Nr);
90 }
91 }
92
93 // get the implemented connections
94 SphericalPointDistribution::adjacency_t expected =
95 SPD.getConnections<N>();
96
97// // print the map: for debugging and extracting the edges for getConnections()
98// std::cout << "\tadjacency_t adjacency;" << std::endl;
99// for (SphericalPointDistribution::adjacency_t::const_iterator iter = adjacency.begin();
100// iter != adjacency.end(); ++iter) {
101// std::cout << "\tadjacency += make_pair<unsigned int, IndexSet_t >( "
102// << iter->first << ", list_of<unsigned int>";
103// for (SphericalPointDistribution::IndexSet_t::const_iterator indexiter = iter->second.begin();
104// indexiter != iter->second.end(); ++indexiter)
105// std::cout << "(" << *indexiter << ")";
106// std::cout << " );" << std::endl;
107// }
108
109 // and compare the two
110 CPPUNIT_ASSERT_EQUAL( expected, adjacency );
111}
112
113
114#endif /* SPHERICALPOINTDISTRIBUTION_ASSISTANT_HPP_ */
Note: See TracBrowser for help on using the repository browser.