From 876961ff53eaa3bab442abfa3bdeeaf8c5e859f0 Mon Sep 17 00:00:00 2001 From: hrocho Date: Thu, 19 Oct 2017 01:36:54 +0200 Subject: [PATCH] minor changes for server --- catima.pyx | 14 ++++++++++++++ catimac.pxd | 14 ++++++++++++-- storage.cpp | 2 +- storage.h | 1 + tests/test.py | 19 ++++++++++++++----- 5 files changed, 42 insertions(+), 8 deletions(-) diff --git a/catima.pyx b/catima.pyx index 738242a..64c33df 100644 --- a/catima.pyx +++ b/catima.pyx @@ -406,7 +406,9 @@ def get_data(Projectile projectile, Material material, Config config = default_c data = catimac.get_data(projectile.cbase, material.cbase, config.cbase) return [data.range,data.range_straggling,data.angular_variance] +# constants max_datapoints = catimac.max_datapoints +max_storage_data = catimac.max_storage_data def energy_table(unsigned int i): if(i0 and data.p.Z>0 and data.m.ncomponents()>0): + matter = [] + for j in range(data.m.ncomponents()): + e = data.m.get_element(j) + matter.append([e.first.A,e.first.Z,e.second]) + res.append({"projectile":[data.p.A,data.p.Z],"matter":matter}) + return res diff --git a/catimac.pxd b/catimac.pxd index 2e916f6..d6fc3ac 100644 --- a/catimac.pxd +++ b/catimac.pxd @@ -87,6 +87,7 @@ cdef extern from "catima/calculations.h" namespace "catima": cdef extern from "catima/constants.h" namespace "catima": int max_datapoints "catima::max_datapoints" + int max_storage_data "catima::max_storage_data" int logEmin "catima::logEmin" int logEmax "catima::logEmax" @@ -97,14 +98,23 @@ cdef extern from "catima/storage.h" namespace "catima": double derivative(double) cdef cppclass DataPoint: + Projectile p + Material m + Config config vector[double] range vector[double] range_straggling vector[double] angular_variance + cdef cppclass Data: + Data() except + + DataPoint& Get(unsigned int i) + int GetN() + + cdef cppclass EnergyTableType "catima::EnergyTable[max_datapoints]": size_t num; double operator()(int i) - - cdef EnergyTableType energy_table; + cdef EnergyTableType energy_table; + cdef Data _storage; cdef DataPoint& get_data(const Projectile &p, const Material &t, Config c); diff --git a/storage.cpp b/storage.cpp index 5bea454..07de1d7 100644 --- a/storage.cpp +++ b/storage.cpp @@ -19,7 +19,7 @@ namespace catima { } Data::Data(){ - //storage.reserve(max_storage_data); + //storage.reserve(max_storage_data); // disabled because of "circular" storage storage.resize(max_storage_data); index = storage.begin(); } diff --git a/storage.h b/storage.h index 3495604..789eff4 100644 --- a/storage.h +++ b/storage.h @@ -124,6 +124,7 @@ namespace catima{ int GetN() const {return storage.size();}; void Reset(){storage.clear();storage.resize(max_storage_data);index=storage.begin();}; DataPoint& Get(const Projectile &p, const Material &t, Config c=default_config); + DataPoint& Get(unsigned int i){return storage[i];}; int get_index() {return std::distance(storage.begin(),index);} private: std::vector storage; diff --git a/tests/test.py b/tests/test.py index 34e20c7..8f69f34 100644 --- a/tests/test.py +++ b/tests/test.py @@ -214,7 +214,6 @@ class TestStructures(unittest.TestCase): graphite.thickness(1.0) data = catima.get_data(p, water) - print(data[1]) et = catima.get_energy_table() self.assertEqual(len(data),3) @@ -223,24 +222,34 @@ class TestStructures(unittest.TestCase): res = catima.calculate(p(et[10]),water) self.assertAlmostEqual(res.range,data[0][10],6) self.assertAlmostEqual(catima.projectile_range(p,water),data[0][10],6) - self.assertAlmostEqual(catima.domega2de(p,water),data[1][10],6) + #self.assertAlmostEqual(catima.domega2de(p,water),data[1][10],6) res = catima.calculate(p(et[100]),water) self.assertAlmostEqual(res.range,data[0][100],6) self.assertAlmostEqual(catima.projectile_range(p,water),data[0][100],6) - self.assertAlmostEqual(catima.domega2de(p,water),data[1][100],6) + #self.assertAlmostEqual(catima.domega2de(p,water),data[1][100],6) res = catima.calculate(p(et[200]),water) self.assertAlmostEqual(res.range,data[0][200],6) self.assertAlmostEqual(catima.projectile_range(p,water),data[0][200],6) - self.assertAlmostEqual(catima.domega2de(p,water),data[1][200],6) + #self.assertAlmostEqual(catima.domega2de(p,water),data[1][200],6) res = catima.calculate(p(et[401]),water) self.assertAlmostEqual(res.range,data[0][401],6) self.assertAlmostEqual(catima.projectile_range(p,water),data[0][401],6) - self.assertAlmostEqual(catima.domega2de(p,water),data[1][401],6) + #self.assertAlmostEqual(catima.domega2de(p,water),data[1][401],6) + def test_python_storage_access(self): + p = catima.Projectile(12,6) + water = catima.get_material(catima.material.WATER) + water.thickness(10.0) + graphite = catima.get_material(6) + graphite.thickness(1.0) + data = catima.get_data(p, water) + self.assertEqual(catima.max_storage_data,50) # assuming 50, this has to be changed manually + r = catima.print_storage() + print(r) #self.assertAlmostEqual(catima.da2de(p,water,et[100]),data[2][100],6) #self.assertAlmostEqual(catima.da2de(p,water,et[400]),data[2][400],6)