CellModules
SchemeSQL.hpp
Go to the documentation of this file.
1//'''
2#pragma once
3
4#include <string>
5#include <sstream>
6
7/*isigen:eval@utilityDeclarations'''
8 attributesToIgnore = ['type', 'state']
9 correctAttribute = [a for a in builderData['CellAttributesRecorded'] if a['value'] not in attributesToIgnore]
10 def convert(type) :
11 conversion = "DOUBLE PRECISION"
12 if (type == "int") | ((type in builderData['enums']) if 'enums' in builderData else False):
13 conversion = "INTEGER"
14 return conversion
15
16 def cast_enum(a):
17 if a['type'] not in builderData['enums']:
18 return 'c->'+a['value']
19 else:
20 return 'static_cast<unsigned int>(c->'+a['value']+')'
21 '''*/
22
23namespace PluginSQL {
24
25 struct Scheme {
26
27 public:
28 const std::string WorldTable;
29 const std::string CellTable;
30
33
34 const std::string WorldTableDataLayout;
35 const std::string CellTableDataLayout;
36
37
38 Scheme(const std::string &simulation_id) :
39 WorldTable(simulation_id + "_world"),
40 CellTable(simulation_id + "_cells"),
41 WorldTableCreationStatement("CREATE TABLE " + simulation_id + "_world (" +
42 "step integer NOT NULL," +
43 "num_cells integer NOT NULL," +
44 "hours real NOT NULL" +
45 "); "),
46 CellTableCreationStatement("CREATE TABLE " + simulation_id + "_cells (" +
47 /*isigen:insert@CreateTableCells'''
48 print('\n'.join(['"{value}\t{type}\t\tNOT NULL," +'.format(value=a['value'], type=convert(a['type'])) for a in correctAttribute]))
49 '''*/
50 "step integer NOT NULL," +
51 "cell_id integer NOT NULL," +
52 "type integer NOT NULL," +
53 "state integer NOT NULL," +
54 "x real NOT NULL," +
55 "y real NOT NULL," +
56 "z real NOT NULL," +
57 "radius real NOT NULL);"),
58 CellTableDataLayout(std::string("(")+
59 /*isigen:insert@CellTableDataLayout'''
60 print('"'+', '.join([a['value'] for a in correctAttribute])+'," +')
61 '''*/
62 "step, cell_id, type, state, x, y, z, radius)"),
63 WorldTableDataLayout("(step, num_cells, hours)")
64 {}
65
66 template<typename cell_t, typename world_t>
67 void CellValueStatement(std::stringstream& ss, cell_t *c, world_t *w) {
68 auto pos = c->getBody().getPosition();
69 ss << "(";
70 /*isigen:insert@CellValueStatement'''
71 print('\n'.join(['ss << "CAST(" << {value} << " AS {type})" << ", ";'.format(value=cast_enum(a), type=convert(a['type'])) for a in correctAttribute]))
72 '''*/
73 ss << w->getNbUpdates() << ", ";
74 ss << c->getId() << ", ";
75 ss << static_cast<unsigned int>(c->getType()) << ",";
76 ss << static_cast<unsigned int>(c->getState()) << ",";
77 ss << pos.x() << ", ";
78 ss << pos.y() << ", ";
79 ss << pos.z() << ", ";
80 ss << c->getBody().getBoundingBoxRadius();
81 ss << " )";
82 }
83
84 template<typename world_t>
85 std::string WorldValueStatement(world_t *w) {
86 std::stringstream ss;
87 ss << "(";
88 ss << w->getNbUpdates() << ", ";
89 ss << w->cells.size() << ", ";
90 ss << w->getNbUpdates() * w->dt / 3600;
91 ss << " )";
92
93 return ss.str();
94 }
95
96 };
97}
98//'''
MecaCell::Vec pos
Definition: CellBody.hpp:34
double x() const
Definition: vector3D.h:94
double y() const
Definition: vector3D.h:100
double z() const
Definition: vector3D.h:106
Provides common mathematical functions and vector operations.
Definition: std.hpp:4
void CellValueStatement(std::stringstream &ss, cell_t *c, world_t *w)
Definition: SchemeSQL.hpp:67
const std::string WorldTable
Definition: SchemeSQL.hpp:28
const std::string WorldTableDataLayout
Definition: SchemeSQL.hpp:34
const std::string CellTable
Definition: SchemeSQL.hpp:29
const std::string CellTableDataLayout
Definition: SchemeSQL.hpp:35
std::string WorldTableCreationStatement
Definition: SchemeSQL.hpp:31
std::string CellTableCreationStatement
Definition: SchemeSQL.hpp:32
Scheme(const std::string &simulation_id)
Definition: SchemeSQL.hpp:38
std::string WorldValueStatement(world_t *w)
Definition: SchemeSQL.hpp:85