From 14b52c424885515a5df260b58c5e8009d8b33a10 Mon Sep 17 00:00:00 2001 From: Guilhem Lavaux Date: Thu, 28 Feb 2013 17:09:27 -0600 Subject: [PATCH] Finished subsubsampling on regeneration --- c_tools/mock/generateMock.cpp | 49 ++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/c_tools/mock/generateMock.cpp b/c_tools/mock/generateMock.cpp index cb42eae..209fb4c 100644 --- a/c_tools/mock/generateMock.cpp +++ b/c_tools/mock/generateMock.cpp @@ -222,17 +222,12 @@ void generateOutput(SimuData *data, int axis, // cleared. That way new particles can be appended if this is a multi-file snapshot. void selectBox(SimuData *simu, std::vector& targets, generateMock_info& args_info, SimulationPreprocessor *preselect) { - float subsample; - if (args_info.subsample_given) { - subsample = args_info.subsample_arg; - } else { - subsample = 1.0; - } double ranges[3][2] = { { args_info.rangeX_min_arg, args_info.rangeX_max_arg }, { args_info.rangeY_min_arg, args_info.rangeY_max_arg }, { args_info.rangeZ_min_arg, args_info.rangeZ_max_arg } }; + long numAccepted =0; for (uint32_t i = 0; i < simu->NumPart; i++) { @@ -252,9 +247,12 @@ void selectBox(SimuData *simu, std::vector& targets, generateMock_info& ar if (preselect != 0) acceptance = acceptance && preselect->accept(p); - if (acceptance) + if (acceptance) { targets.push_back(i); + numAccepted++; + } } + cout << "Num accepted here = " << numAccepted << " / input = " << simu->NumPart << endl; } class PreselectParticles: public SimulationPreprocessor @@ -490,6 +488,40 @@ void makeBoxFromParameter(SimuData *simu, SimuData* &boxed, generateMock_info& a uniqueID[i] |= (unsigned long)(tmp_int[i]) << 32; delete[] tmp_int; + + PreselectParticles *preselect = 0; + + if (args_info.resubsample_given) + { + preselect = new PreselectParticles(args_info.resubsample_arg, args_info.resubsample_seed_arg); + preselect->reset(); + } + + if (preselect == 0) + return; + + long pid_read = 0, pid_write = 0; + for (int s_id = 0; s_id < *num_snapshots; s_id++) + { + long previous_write = pid_write; + for (long q = 0; q < snapshot_split[s_id]; q++) + { + SingleParticle p; + p.ID = -1; + assert(pid_read < boxed->NumPart); + if (preselect->accept(p)) + { + particle_id[pid_write] = particle_id[pid_read]; + uniqueID[pid_write] = uniqueID[pid_read]; + expansion_fac[pid_write] = uniqueID[pid_read]; + pid_write++; + } + pid_read++; + } + snapshot_split[s_id] = pid_write - previous_write; + } + boxed->NumPart = pid_write; + delete preselect; } void makeBoxFromSimulation(SimulationLoader *loader, SimuData* &boxed, MetricFunctor metric, generateMock_info& args_info) @@ -522,6 +554,9 @@ void makeBoxFromSimulation(SimulationLoader *loader, SimuData* &boxed, MetricFun } createBox(loader->getHeader(), targets, split, boxed, args_info); + + if (preselect) + delete preselect; } int main(int argc, char **argv)