12 #include <emscripten.h>
13 #include <emscripten/bind.h>
14 using namespace emscripten ;
16 #ifndef JS_CONVERT_ARRAYS
17 #define JS_CONVERT_ARRAYS
22 emscripten::val
to_js_array(
const std::vector<std::vector<T>>& data) {
23 using namespace emscripten;
24 val outer = val::array();
25 for (
size_t i = 0; i < data.size(); ++i) {
26 val inner = val::array();
27 for (
size_t j = 0; j < data[i].size(); ++j) {
28 inner.set(j, data[i][j]);
35 emscripten::val
to_js_array(
const std::vector<T>& data) {
36 using namespace emscripten;
37 val outer = val::array();
38 for (
size_t i = 0; i < data.size(); ++i) {
39 outer.set(i, data[i]);
47 template <
typename T> std::vector<std::vector<T>>
to_js_array(std::vector<std::vector<T>>& data) {
return data ; }
48 template <
typename T> std::vector<T>
to_js_array(std::vector<T>& data) {
return data ; }
53 #include <boost/iostreams/filtering_streambuf.hpp>
54 #include <boost/iostreams/stream.hpp>
76 int process_timestep (
int ts,
bool hasdonefirstpass=
false) ;
77 int process_fluct_from_avg() ;
80 Vector1Djs get_result(
int ts, std::string field,
int component) ;
89 void debug () {printf(
"BLAAAA\n") ; }
116 C =
new Coarsing (P.dim, P.boxes, P.boundaries, P.maxT) ;
117 for (
auto i : P.extrafields)
118 C->add_extra_field(i.name, i.order, i.type) ;
120 C->setWindow(P.window, P.windowsize, P.periodicity, P.boxes, P.delta) ;
122 C->setWindow(P.window,P.windowsize) ;
123 pipeline = C->set_flags(P.flags) ;
124 auto extrafieldmap = C->grid_setfields() ;
125 C->grid_neighbour() ;
132 int ts = ts_abs - P.skipT ;
136 P.read_timestep(ts+P.skipT) ;
138 P.set_data (C->data) ;
140 if (!hasdonefirstpass)
if (pipeline &
Pass::Pass1) C->pass_1() ;
152 for (
int ts=0 ; ts<P.maxT ; ts++)
154 P.read_timestep(ts+P.skipT,
true) ;
156 P.set_data (C->data) ;
168 bool hasdonefirstpass = false ;
172 process_fluct_from_avg() ;
173 hasdonefirstpass = true ;
176 for (
int ts=0 ; ts<P.maxT ; ts++)
178 printf(
"\rProcessing %d ", ts) ; fflush(stdout) ;
179 process_timestep(ts+P.skipT, hasdonefirstpass) ;
182 C->mean_time(
false) ;
187 if (std::find(P.saveformat.begin(), P.saveformat.end(),
"netCDF")!=P.saveformat.end()) C->write_netCDF(P.save) ;
188 if (std::find(P.saveformat.begin(), P.saveformat.end(),
"vtk")!=P.saveformat.end()) C->write_vtk (P.save) ;
189 if (std::find(P.saveformat.begin(), P.saveformat.end(),
"mat")!=P.saveformat.end()) C->write_matlab(P.save,
true) ;
190 if (std::find(P.saveformat.begin(), P.saveformat.end(),
"numpy")!=P.saveformat.end()) C->write_numpy(P.save,
true) ;
195 int ts = ts_abs - P.skipT ;
196 if (ts != C->cT) {printf(
"The requested timestep has not been processed.\n");
return {} ; }
197 int idx = C->get_id(field) ;
199 std::vector <double> res ;
200 res.resize(C->CGP.size()) ;
201 for (
size_t i = 0 ; i<res.size() ; i++)
202 res[i]=C->CGP[C->idx_FastFirst2SlowFirst(i)].fields[C->cT][idx] ;
208 std::vector<double> res ;
210 res.push_back(C->CGP[0].location[0]) ;
211 res.push_back(C->CGP[0].location[1]) ;
212 res.push_back(C->CGP[0].location[2]) ;
214 res.push_back(C->dx[0]) ;
215 res.push_back(C->dx[1]) ;
216 res.push_back(C->dx[2]) ;
218 res.push_back(C->npt[0]) ;
219 res.push_back(C->npt[1]) ;
220 res.push_back(C->npt[2]) ;
226 std::vector<std::vector<double>> res ; res.resize(4) ;
227 int ts = ts_abs - P.skipT ;
228 P.read_timestep(ts+P.skipT) ;
230 int n = P.get_num_particles() ;
231 for (
int i=0 ; i<4 ; i++) res[i].resize(n) ;
234 for (
int i=0 ; i<3 ; i++)
237 for (
int j=0 ; j<n ; j++)
241 for (
int j=0 ; j<n ; j++)
std::vector< std::vector< T > > to_js_array(std::vector< std::vector< T >> &data)
Definition: CoarseGraining.h:47
std::vector< std::vector< double > > Vector2Djs
Definition: DEMND.h:78
std::vector< double > Vector1Djs
Definition: DEMND.h:79
Definition: CoarseGraining.h:67
Param P
Definition: CoarseGraining.h:70
CoarseGraining()
Definition: CoarseGraining.h:69
void process_all()
Definition: CoarseGraining.h:166
Vector1Djs get_result(int ts, std::string field, int component)
Definition: CoarseGraining.h:193
Vector2Djs param_get_bounds(int file=0)
Definition: CoarseGraining.h:86
int process_timestep(int ts, bool hasdonefirstpass=false)
Definition: CoarseGraining.h:130
void param_post_init()
Definition: CoarseGraining.h:91
Vector1Djs param_get_minmaxradius(int file=0)
Definition: CoarseGraining.h:87
int param_get_numts(int file=0)
Definition: CoarseGraining.h:88
int process_fluct_from_avg()
Definition: CoarseGraining.h:150
Pass pipeline
Definition: CoarseGraining.h:72
Vector2Djs get_spheres(int ts_abs)
Definition: CoarseGraining.h:224
void param_from_json_string(std::string param)
Definition: CoarseGraining.h:85
Vector1Djs get_gridinfo()
Definition: CoarseGraining.h:206
int param_read_timestep(int n)
Definition: CoarseGraining.h:90
void setup_CG()
Definition: CoarseGraining.h:110
void debug()
Definition: CoarseGraining.h:89
void write()
Definition: CoarseGraining.h:185
Main Coarse graining class.
Definition: Coarsing.h:141
namespace for Niels Lohmann
Definition: json.hpp:20203
Pass
Definition: Coarsing.h:61
@ Final
Definition: Coarsing.h:60
@ Both
Definition: Coarsing.h:60
@ Intermediate
Definition: Coarsing.h:60
@ Pass1
Definition: Coarsing.h:61
@ Pass3
Definition: Coarsing.h:61
@ Pass4
Definition: Coarsing.h:61
@ Pass2
Definition: Coarsing.h:61
@ VelFluct
Definition: Coarsing.h:62
@ RotFluct
Definition: Coarsing.h:62
@ Pass5
Definition: Coarsing.h:61
@ pos
Definition: Typedefs.h:19
@ radius
Definition: Typedefs.h:19
Contains the parameters of the simulation & CG.
Definition: IOLiggghts.h:67
int read_timestep(int ts, bool particleonly=false)
Definition: Parameters.h:116
std::vector< File > files
Definition: Parameters.h:41
void from_json(json &j)
Definition: IOLiggghts.h:107
void post_init()
Definition: IOLiggghts.h:188