mirror of
https://github.com/gwm17/catima.git
synced 2024-11-22 18:28:51 -05:00
minor changes for server
This commit is contained in:
parent
bd28a60d74
commit
876961ff53
14
catima.pyx
14
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(i<catimac.energy_table.num):
|
||||
|
@ -417,3 +419,15 @@ def energy_table(unsigned int i):
|
|||
def get_energy_table():
|
||||
r = [catimac.energy_table(x) for x in range(catimac.energy_table.num)]
|
||||
return r
|
||||
|
||||
def print_storage():
|
||||
res = []
|
||||
for i in range(catimac.max_storage_data):
|
||||
data = catimac._storage.Get(i)
|
||||
if(data.p.A>0 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
|
||||
|
|
14
catimac.pxd
14
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);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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<DataPoint> storage;
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user