blob: 2f2d691abd2bc4dda046bc4ebf910621b25767fe (
plain)
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
|
#include <kel/lbm/lbm.hpp>
#include <AdaptiveCpp/sycl/sycl.hpp>
#include <kel/lbm/particle/geometry/circle.hpp>
#include <iostream>
namespace kel{
namespace lbm {
namespace sch {
using namespace saw::schema;
}
}
saw::error_or<void> lbm_main(int argc, char** argv){
(void) argc;
(void) argv;
using namespace lbm;
using namespace acpp;
saw::data<sch::Array<sch::Particle<sch::Float32,2u>>> particles{1024u};
for(saw::data<sch::UInt64> i{0u}; i < saw::data<sch::UInt64>{32u}; ++i){
for(saw::data<sch::UInt64> j{0u}; j < saw::data<sch::UInt64>{32u}; ++j){
auto& part = particles.at(i*32ul+j);
auto& body = part.template get<"rigid_body">();
auto& pos = body.template get<"position">();
auto& old_pos = body.template get<"position_old">();
auto& acceleration = body.template get<"acceleration">();
auto& p_size = part.template get<"size">();
p_size = {0.5f};
if(j.get() % 2u == 0) acceleration.at({{1u}}) = {9.81};
pos.at({{0u}}) = {i.template cast_to<sch::Float32>()};
pos.at({{1u}}) = {j.template cast_to<sch::Float32>()};
old_pos = pos;
}
}
for(saw::data<sch::UInt64> dt{0u}; dt < saw::data<sch::UInt64>{32ul}; ++dt){
for(saw::data<sch::UInt64> i{0u}; i < particles.size(); ++i){
auto& part_i = particles.at(i);
verlet_step_lambda<sch::Float32,2u>(part_i,{0.05f});
}
for(saw::data<sch::UInt64> i{0u}; i < particles.size(); ++i){
auto& part_i = particles.at(i);
for(saw::data<sch::UInt64> j{i+1ul}; j < particles.size(); ++j){
auto& part_j = particles.at(j);
auto res = broadphase_collision_distance<sch::Float32,2u>(part_i, part_j);
if(res.first){
std::cout<<"Collision"<<std::endl;
}
}
}
auto& pos = particles.at({0u}).template get<"rigid_body">().template get<"position">();
std::cout<<pos.at({{0u}}).get()<<" "<<pos.at({{1u}}).get()<<std::endl;
saw::codec<sch::Array<sch::Particle<sch::Float32,2u>>, saw::encode::Json> j_codec;
}
return saw::make_void();
}
}
int main(int argc, char** argv){
auto eov = kel::lbm_main(argc, argv);
if(eov.is_error()){
auto& err = eov.get_error();
std::cerr<<"[Error] "<<err.get_category();
auto err_msg = err.get_message();
if(err_msg.size() > 0u){
std::cerr<<" - "<<err_msg;
}
std::cerr<<std::endl;
return err.get_id();
}
return 0;
}
|