Swarm-NG  1.1
types.hpp
Go to the documentation of this file.
1 /*************************************************************************
2  * Copyright (C) 2010 by Mario Juric and the Swarm-NG Development Team *
3  * *
4  * This program is free software; you can redistribute it and/or modify *
5  * it under the terms of the GNU General Public License as published by *
6  * the Free Software Foundation; either version 3 of the License. *
7  * *
8  * This program is distributed in the hope that it will be useful, *
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
11  * GNU General Public License for more details. *
12  * *
13  * You should have received a copy of the GNU General Public License *
14  * along with this program; if not, write to the *
15  * Free Software Foundation, Inc., *
16  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
17  ************************************************************************/
18 
25 #pragma once
26 #include "../types/ensemble.hpp"
27 
28 namespace swarm { namespace log {
29 
37 struct ALIGN(8) body
38 {
39  double x, y, z;
40  double vx, vy, vz;
41  double mass;
42  int body_id; // EBF added
43 
45  GENERIC void set(const int& i,const ensemble::Body& b)
46  {
47  mass = b.mass();
48  x = b[0].pos();
49  y = b[1].pos();
50  z = b[2].pos();
51  vx = b[0].vel();
52  vy = b[1].vel();
53  vz = b[2].vel();
54  body_id = i;
55  }
56 };
57 
64 template<int N>
65 struct body_set
66 {
67  const ensemble &ens;
68  int sys, bod[N];
69 
70  GENERIC body_set(const ensemble &ens_, int sys_) : ens(ens_), sys(sys_) { }
71 };
72 
74 GENERIC const body_set<1> make_body_set(const ensemble &ens, int sys, int bod0)
75 {
76  body_set<1> br(ens, sys);
77  br.bod[0] = bod0;
78  return br;
79 }
80 
82 GENERIC const body_set<2> make_body_set(const ensemble &ens, int sys, int bod0, int bod1)
83 {
84  body_set<2> br(ens, sys);
85  br.bod[0] = bod0;
86  br.bod[1] = bod1;
87  return br;
88 }
89 
91 GENERIC const body_set<3> make_body_set(const ensemble &ens, int sys, int bod0, int bod1, int bod2)
92 {
93  body_set<3> br(ens, sys);
94  br.bod[0] = bod0;
95  br.bod[1] = bod1;
96  br.bod[2] = bod2;
97  return br;
98 }
99 
100 } }
101 
102 
103 
104 namespace gpulog { namespace internal {
105 
106 
107 using namespace swarm::log;
108 
112 template<int N> struct alignment<body_set<N> > : public alignment<body[N]> { };
114 template<int N> struct ttrait<body_set<N> > : public ttrait<body[N]> { };
115 
122 template<int N> struct argio<body_set<N> >
123 {
124  GENERIC static void put(char *ptr, const body_set<N> &br, int start, int datalen)
125  {
126  DHOST( std::cerr << "Writing [" << br << "] start=" << start << " len=" << datalen << "\n" );
127  DGPU( printf("Writing start=%d len=%d\n", start, datalen); );
128  dev_assert(sizeof(body)*N == datalen);
129 
130  // write out N bodies
131  body *bodies = (body *)(ptr + start);
132  for(int i=0; i < N; i++)
133  {
134  bodies[i].set(i,br.ens[br.sys][br.bod[i]]);
135  }
136  }
137 };
138 
139 } }
140