Skip to content

Commit

Permalink
bucket search serial all works, test refactored to test timing betwee…
Browse files Browse the repository at this point in the history
…n methods
  • Loading branch information
martinjrobins committed Sep 12, 2016
1 parent d37ca6e commit dd4d773
Show file tree
Hide file tree
Showing 12 changed files with 203 additions and 53 deletions.
22 changes: 15 additions & 7 deletions src/NeighbourSearchBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,23 @@ class neighbour_search_base {
LOG(2,"neighbour_search_base: add_points_at_end: embedding "<<dist<<" new points. Total number = "<<end-begin);
cast().add_points_at_end_impl(dist);
}
ASSERT(m_particles_begin==begin, "did not update m_particles_begin correctly");
ASSERT(m_particles_end==end, "did not update m_particles_end correctly");
}

void copy_points(iterator copy_from_iterator, iterator copy_to_iterator) {
ASSERT((copy_to_iterator-m_particles_begin>=0) &&
(m_particles_end-copy_to_iterator>0),"invalid copy to iterator");
ASSERT((copy_from_iterator-m_particles_begin>=0) &&
(m_particles_end-copy_from_iterator>0),"invalid copy from iterator");
if (copy_to_iterator==copy_from_iterator) return;
cast().copy_points_impl(copy_from_iterator,copy_from_iterator);
/*
std::cout <<"copy_to = "<<get<position>(*copy_to_iterator)<<std::endl;
std::cout <<" begin = "<<get<position>(*m_particles_begin)<<std::endl;
std::cout <<"copy_to = "<<get<position>(*copy_to_iterator)<<" begin = "<<get<position>(*m_particles_begin)<<std::endl;
std::cout <<"1st:"<< copy_to_iterator-m_particles_begin <<" 2nd: "<< m_particles_end-copy_to_iterator<<std::endl;
*/
ASSERT((copy_to_iterator-m_particles_begin>=0) &&
(m_particles_end-copy_to_iterator>0),"invalid copy to iterator");
ASSERT((copy_from_iterator-m_particles_begin>=0) &&
(m_particles_end-copy_from_iterator>0),"invalid copy from iterator");
if (copy_to_iterator==copy_from_iterator) return;
cast().copy_points_impl(copy_from_iterator,copy_from_iterator);
}


Expand All @@ -176,7 +184,7 @@ class neighbour_search_base {
const size_t dist = oldn-(end-begin);
if (dist > 0) {
LOG(2,"neighbour_search_base: delete_points_at_end: deleting "<<dist<<" points. Total number = "<<end-begin);
cast().add_points_at_end_impl(dist);
cast().delete_points_at_end_impl(dist);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Particles.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ class Particles {
iterator erase (iterator i, bool update_neighbour_search = true) {
if (i != end()-1) {
*i = *(end()-1);
if (search.unordered()) {
if (search.unordered() && searchable) {
search.copy_points(end()-1,i);
}
traits_type::pop_back(data);
Expand Down
66 changes: 64 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ macro(aboria_cxx_test target target_file)
add_custom_command(
OUTPUT "${CPP_FULL_NAME}"
COMMAND ${CXXTESTGEN} --runner=ErrorPrinter --output "${CPP_FULL_NAME}" ${test_files}
DEPENDS "${source}"
DEPENDS ${test_files}
VERBATIM
)
if (${target_file} MATCHES .cu$)
Expand All @@ -29,7 +29,7 @@ set(test_files
neighbours.h
#geometry
diffusion_around_spheres.h
assemble.h
#assemble.h
symbolic.h
rbf_pde.h
rbf_interpolation.h
Expand All @@ -41,13 +41,75 @@ set(test_files
)
set(test_suites
NeighboursTest
BDTest
SPHTest
MDTest
RbfInterpolationTest
RbfPdeTest
DiffusionAroundSpheres
ParticleContainerTest
SymbolicTest
VariablesTest
#AssembleTest
ConstructorsTest
OperatorsTest
)

set(SymbolicTest
test_default
)

set(VariablesTest
test_std_vector
)

set(OperatorsTest
test_Eigen
)

set(ConstructorsTest
test_std_vector
)

set(NeighboursTest
test_std_vector_bucket_search_serial
test_std_vector_bucket_search_parallel
)

set(ParticleContainerTest
test_std_vector_bucket_search_serial
test_std_vector_bucket_search_parallel
)

set(BDTest
test_bucket_search_serial
test_bucket_search_parallel
)

set(SPHTest
test_bucket_search_serial
test_bucket_search_parallel
)

set(MDTest
test_bucket_search_serial
test_bucket_search_parallel
)

set(RbfInterpolationTest
test_bucket_search_serial
test_bucket_search_parallel
)

set(RbfPdeTest
test_bucket_search_serial
test_bucket_search_parallel
)

set(DiffusionAroundSpheres
test_bucket_search_serial
test_bucket_search_parallel
)

aboria_cxx_test(tests tests.cpp ${test_files})
target_link_libraries(tests ${VTK_LIBRARIES} ${Boost_LIBRARIES})
Expand Down
15 changes: 12 additions & 3 deletions tests/bd.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ class BDTest : public CxxTest::TestSuite {
typedef std::mt19937 generator_type;
generator_type generator;

void test_bd(void) {
template<template <typename> class SearchMethod>
void helper_bd(void) {
//->
//=int main() {
ABORIA_VARIABLE(radius,double,"radius")

typedef Particles<std::tuple<radius>> spheres_type;
typedef Particles<> points_type;
typedef Particles<std::tuple<radius>,3,std::vector,SearchMethod> spheres_type;
typedef Particles<std::tuple<>,3,std::vector,SearchMethod> points_type;
typedef position_d<3> position;
spheres_type spheres;

Expand Down Expand Up @@ -110,6 +111,14 @@ class BDTest : public CxxTest::TestSuite {
}
//]

void test_bucket_search_parallel() {
helper_bd<bucket_search_parallel>();
}

void test_bucket_search_serial() {
helper_bd<bucket_search_serial>();
}

};

#endif /* BD_TEST_H_ */
Expand Down
16 changes: 14 additions & 2 deletions tests/diffusion_around_spheres.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,13 @@ class DiffusionAroundSpheres : public CxxTest::TestSuite {
generator_type generator;


void test_diffusion_around_spheres(void) {
template<template <typename> class SearchMethod>
void helper_diffusion_around_spheres(void) {
//const double tol = GEOMETRY_TOLERANCE;

ABORIA_VARIABLE(radius,double,"radius")

typedef Particles<std::tuple<radius>> spheres_type;
typedef Particles<std::tuple<radius>,3,std::vector,SearchMethod> spheres_type;
typedef Particles<> points_type;
typedef position_d<3> position;
spheres_type spheres;
Expand Down Expand Up @@ -189,6 +190,17 @@ class DiffusionAroundSpheres : public CxxTest::TestSuite {
TS_ASSERT_RELATION(std::greater<double>, (get<position>(i) - double3(0,0,5)).norm(), 1.0);
}
}


void test_bucket_search_parallel() {
helper_diffusion_around_spheres<bucket_search_parallel>();
}

void test_bucket_search_serial() {
helper_diffusion_around_spheres<bucket_search_serial>();
}


};

#endif /* DIFFUSION_AROUND_SPHERES_H_ */
20 changes: 15 additions & 5 deletions tests/md.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class MDTest : public CxxTest::TestSuite {
typedef std::mt19937 generator_type;
generator_type generator;

void test_md(void) {
template<template <typename> class SearchMethod>
void helper_md(void) {
//->
//=int main() {
const double PI = boost::math::constants::pi<double>();
Expand All @@ -35,8 +36,8 @@ class MDTest : public CxxTest::TestSuite {
* "velocity", represented by a 2d double vector
*/
ABORIA_VARIABLE(velocity,double2,"velocity")
typedef Particles<std::tuple<velocity>,2> container_type;
typedef container_type::position position;
typedef Particles<std::tuple<velocity>,2,std::vector,SearchMethod> container_type;
typedef typename container_type::position position;
container_type particles;

/*
Expand Down Expand Up @@ -72,7 +73,7 @@ class MDTest : public CxxTest::TestSuite {
/*
* create new particle
*/
container_type::value_type p;
typename container_type::value_type p;

/*
* set a random direction, and initialise velocity
Expand Down Expand Up @@ -101,7 +102,7 @@ class MDTest : public CxxTest::TestSuite {
* from query point
*/
const double2& dx = std::get<1>(tpl);
const container_type::value_type& j = std::get<0>(tpl);
const typename container_type::value_type& j = std::get<0>(tpl);
if (dx.norm() < diameter) {
free_position = false;
break;
Expand Down Expand Up @@ -161,6 +162,15 @@ class MDTest : public CxxTest::TestSuite {
}
//]

void test_bucket_search_parallel() {
helper_md<bucket_search_parallel>();
}

void test_bucket_search_serial() {
helper_md<bucket_search_serial>();
}


};

#endif /* MD_TEST_H_ */
Expand Down
4 changes: 2 additions & 2 deletions tests/metafunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/


#ifndef SYMBOLICTEST_H_
#define SYMBOLICTEST_H_
#ifndef METAFUNCTIONSTEST_H_
#define METAFUNCTIONSTEST_H_


#include <cxxtest/TestSuite.h>
Expand Down
33 changes: 20 additions & 13 deletions tests/particle_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,31 +46,31 @@ using namespace Aboria;

class ParticleContainerTest : public CxxTest::TestSuite {
public:
template<template <typename,typename> class V>
template<template <typename,typename> class V, template <typename> class SearchMethod>
void helper_add_particle1(void) {
typedef Particles<std::tuple<>,3,V> Test_type;
typedef Particles<std::tuple<>,3,V,SearchMethod> Test_type;
Test_type test;
typename Test_type::value_type p;
test.push_back(p);
TS_ASSERT_EQUALS(test.size(),1);
}

template<template <typename,typename> class V>
template<template <typename,typename> class V, template <typename> class SearchMethod>
void helper_add_particle2(void) {
ABORIA_VARIABLE(scalar,double,"scalar")
typedef std::tuple<scalar> variables_type;
typedef Particles<variables_type,3,V> Test_type;
typedef Particles<variables_type,3,V,SearchMethod> Test_type;
Test_type test;
typename Test_type::value_type p;
test.push_back(p);
TS_ASSERT_EQUALS(test.size(),1);
}

template<template <typename,typename> class V>
template<template <typename,typename> class V, template <typename> class SearchMethod>
void helper_add_particle2_dimensions(void) {
ABORIA_VARIABLE(scalar,double,"scalar")
typedef std::tuple<scalar> variables_type;
typedef Particles<variables_type,6,V> Test_type;
typedef Particles<variables_type,6,V,SearchMethod> Test_type;
Test_type test;
typename Test_type::value_type p;
typedef Vector<double,6> double6;
Expand All @@ -81,11 +81,11 @@ class ParticleContainerTest : public CxxTest::TestSuite {
TS_ASSERT(((double6)get<position>(test[0])==double6(2.0)).all());
}

template<template <typename,typename> class V>
template<template <typename,typename> class V, template <typename> class SearchMethod>
void helper_add_delete_particle(void) {
ABORIA_VARIABLE(scalar,double,"scalar")
typedef std::tuple<scalar> variables_type;
typedef Particles<variables_type,3,V> Test_type;
typedef Particles<variables_type,3,V,SearchMethod> Test_type;
Test_type test;
typename Test_type::value_type p;
test.push_back(p);
Expand All @@ -101,11 +101,18 @@ class ParticleContainerTest : public CxxTest::TestSuite {
TS_ASSERT_EQUALS(test.size(),0);
}

void test_std_vector(void) {
helper_add_particle1<std::vector>();
helper_add_particle2<std::vector>();
helper_add_particle2_dimensions<std::vector>();
helper_add_delete_particle<std::vector>();
void test_std_vector_bucket_search_serial(void) {
helper_add_particle1<std::vector,bucket_search_serial>();
helper_add_particle2<std::vector,bucket_search_serial>();
helper_add_particle2_dimensions<std::vector,bucket_search_serial>();
helper_add_delete_particle<std::vector,bucket_search_serial>();
}

void test_std_vector_bucket_search_parallel(void) {
helper_add_particle1<std::vector,bucket_search_parallel>();
helper_add_particle2<std::vector,bucket_search_parallel>();
helper_add_particle2_dimensions<std::vector,bucket_search_parallel>();
helper_add_delete_particle<std::vector,bucket_search_parallel>();
}

void test_thrust_vector(void) {
Expand Down
Loading

0 comments on commit dd4d773

Please sign in to comment.