1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
#include <forstio/test/suite.hpp>
#include <iostream>
//#include "../c++/particle/geometry/circle.hpp"
#include "../c++/particle/particle.hpp"
#include <forstio/codec/data.hpp>
namespace {
namespace sch {
using namespace kel::lbm::sch;
using T = Float64;
}
SAW_TEST("Verlet step 2D - Planar"){
using namespace kel;
saw::data<sch::Particle<sch::T,2u>> particle;
auto& body = particle.template get<"rigid_body">();
auto& pos = body.template get<"position">();
auto& pos_old = body.template get<"position_old">();
// auto& rot = body.template get<"rotation">();
auto& acc = body.template get<"acceleration">();
acc.at({{0}}).set({1.0});
lbm::verlet_step_lambda<sch::T,2u>(particle,{0.5});
SAW_EXPECT(pos.at({{0}}).get() == 0.25, std::string{"Incorrect Pos X: "} + std::to_string(pos.at({{0}}).get()));
SAW_EXPECT(pos.at({{1}}).get() == 0.0, std::string{"Incorrect Pos Y: "} + std::to_string(pos.at({{1}}).get()));
}
SAW_TEST("No Collision Spheroid 2D"){
using namespace kel;
saw::data<sch::Particle<sch::T,2u>> part_a;
{
auto& body = part_a.template get<"rigid_body">();
auto& pos = body.template get<"position">();
auto& coll = part_a.template get<"collision">();
auto& radius = coll.template get<"radius">();
radius.set(1.0);
pos.at({{0u}}) = 0.1;
pos.at({{1u}}) = 0.2;
}
saw::data<sch::Particle<sch::T,2u>> part_b;
{
auto& body = part_b.template get<"rigid_body">();
auto& pos = body.template get<"position">();
auto& coll = part_b.template get<"collision">();
auto& radius = coll.template get<"radius">();
radius.set(1.0);
pos.at({{0u}}) = -2.1;
pos.at({{1u}}) = 0.0;
}
bool have_collided = lbm::broadphase_collision_check<sch::T,2u>(part_a,part_b);
SAW_EXPECT(not have_collided, "Particles shouldn't collide");
}
SAW_TEST("Collision Spheroid 2D"){
using namespace kel;
saw::data<sch::Particle<sch::T,2u>> part_a;
{
auto& body = part_a.template get<"rigid_body">();
auto& pos = body.template get<"position">();
auto& coll = part_a.template get<"collision">();
auto& radius = coll.template get<"radius">();
radius.set(1.0);
pos.at({{0u}}) = 0.1;
pos.at({{1u}}) = 0.2;
}
saw::data<sch::Particle<sch::T,2u>> part_b;
{
auto& body = part_b.template get<"rigid_body">();
auto& pos = body.template get<"position">();
auto& coll = part_b.template get<"collision">();
auto& radius = coll.template get<"radius">();
radius.set(1.0);
pos.at({{0u}}) = -1.5;
pos.at({{1u}}) = 0.0;
}
bool have_collided = lbm::broadphase_collision_check<sch::T,2u>(part_a,part_b);
SAW_EXPECT(have_collided, "Particles should collide");
}
/*
SAW_TEST("Minor Test for mask"){
using namespace kel;
lbm::particle_circle_geometry<sch::T> geo;
auto mask = geo.generate_mask<sch::T>(9u,1u);
auto& grid = mask.template get<"grid">();
for(saw::data<sch::UInt64> i{0u}; i < grid.template get_dim_size<0>(); ++i){
for(saw::data<sch::UInt64> j{0u}; j < grid.template get_dim_size<1>(); ++j){
std::cout<<grid.at({{i,j}}).get()<<" ";
}
std::cout<<"\n";
}
std::cout<<std::endl;
//saw::data<sch::Array<sch::T,2>> reference_mask{{{4+2,4+2}}};
//reference_mask.at({{0,0}});
}
*/
/*
SAW_TEST("Verlet integration test 2D"){
using namespace kel;
lbm::particle_system<sch::T,2,sch::Particle<sch::T,2>> system;
{
saw::data<sch::Particle<sch::T,2>> particle;
auto& rb = particle.template get<"rigid_body">();
auto& acc = rb.template get<"acceleration">();
auto& pos = rb.template get<"position">();
auto& pos_old = rb.template get<"position_old">();
pos = {{1e-1,1e-1}};
pos_old = {{0.0, 0.0}};
acc = {{0.0,-1e1}};
auto eov = system.add_particle(std::move(particle));
SAW_EXPECT(eov.is_value(), "Expected no error :)");
}
{
auto& p = system.at({0u});
auto& rb = p.template get<"rigid_body">();
auto& pos = rb.template get<"position">();
for(saw::data<sch::UInt64> i{0u}; i < saw::data<sch::UInt64>{2u}; ++i){
std::cout<<pos.at(i).get()<<" ";
}
std::cout<<std::endl;
}
for(uint64_t i = 0u; i < 36u; ++i){
system.step(saw::data<sch::T>{1e-1});
{
auto& p = system.at({0u});
auto& rb = p.template get<"rigid_body">();
auto& pos = rb.template get<"position">();
for(saw::data<sch::UInt64> i{0u}; i < saw::data<sch::UInt64>{2u}; ++i){
std::cout<<pos.at(i).get()<<" ";
}
std::cout<<"\n";
if(pos.at({1u}).get() < 0.0){
break;
}
}
}
}
*/
}
|