mirror of
https://github.com/gwm17/catima.git
synced 2024-11-26 20:18:51 -05:00
added few python functions
This commit is contained in:
parent
7d458f0c98
commit
ae4e0674f3
19
catima.pyx
19
catima.pyx
|
@ -338,7 +338,7 @@ cdef catimac.Material get_cmaterial(Material material):
|
|||
res = material.cbase
|
||||
return res
|
||||
|
||||
def range(Projectile projectile, Material material, energy = None, Config config = default_config):
|
||||
def projectile_range(Projectile projectile, Material material, energy = None, Config config = default_config):
|
||||
if(isinstance(energy,numpy.ndarray)):
|
||||
res = numpy.empty(energy.size)
|
||||
for i,e in enumerate(energy):
|
||||
|
@ -403,3 +403,20 @@ def z_effective(Projectile p, Target t, Config c = default_config):
|
|||
|
||||
def z_eff_Pierce_Blann(double z, double beta):
|
||||
return catimac.z_eff_Pierce_Blann(z,beta)
|
||||
|
||||
|
||||
def get_data(Projectile projectile, Material material, Config config = default_config):
|
||||
data = catimac.get_data(projectile.cbase, material.cbase, config.cbase)
|
||||
return [data.range,data.range_straggling,data.angular_variance]
|
||||
|
||||
max_datapoints = catimac.max_datapoints
|
||||
|
||||
def energy_table(unsigned int i):
|
||||
if(i<catimac.energy_table.num):
|
||||
return catimac.energy_table(i)
|
||||
else:
|
||||
return -1.0
|
||||
|
||||
def get_energy_table():
|
||||
r = [catimac.energy_table(x) for x in range(catimac.energy_table.num)]
|
||||
return r
|
||||
|
|
18
catimac.pxd
18
catimac.pxd
|
@ -86,9 +86,25 @@ cdef extern from "catima/calculations.h" namespace "catima":
|
|||
cdef double z_eff_Pierce_Blann(double z, double beta);
|
||||
|
||||
cdef extern from "catima/constants.h" namespace "catima":
|
||||
cdef int max_datapoints;
|
||||
int max_datapoints "catima::max_datapoints"
|
||||
int logEmin "catima::logEmin"
|
||||
int logEmax "catima::logEmax"
|
||||
|
||||
cdef extern from "catima/storage.h" namespace "catima":
|
||||
cdef cppclass Interpolator:
|
||||
Interpolator(const double *x, const double *y, int num) except +
|
||||
double eval(double)
|
||||
double derivative(double)
|
||||
|
||||
cdef cppclass DataPoint:
|
||||
vector[double] range
|
||||
vector[double] range_straggling
|
||||
vector[double] angular_variance
|
||||
|
||||
cdef cppclass EnergyTableType "catima::EnergyTable[max_datapoints]":
|
||||
size_t num;
|
||||
double operator()(int i)
|
||||
|
||||
|
||||
cdef EnergyTableType energy_table;
|
||||
cdef DataPoint& get_data(const Projectile &p, const Material &t, Config c);
|
||||
|
|
|
@ -2,6 +2,7 @@ import sys
|
|||
sys.path.insert(0,"../build")
|
||||
import unittest
|
||||
import catima
|
||||
import math
|
||||
|
||||
class TestStructures(unittest.TestCase):
|
||||
|
||||
|
@ -153,6 +154,11 @@ class TestStructures(unittest.TestCase):
|
|||
res = catima.calculate(p(9),water)
|
||||
self.assertAlmostEqual(res.dEdxi,51.17,1)
|
||||
|
||||
p(900000)
|
||||
res = catima.calculate(p,water)
|
||||
res2 = catima.dedx_from_range(p,water)
|
||||
self.assertAlmostEqual(res.dEdxi,res2,3)
|
||||
|
||||
def test_eout(self):
|
||||
graphite = catima.get_material(6)
|
||||
graphite.thickness(0.5)
|
||||
|
@ -189,5 +195,50 @@ class TestStructures(unittest.TestCase):
|
|||
self.assertAlmostEqual(res[0]["range"],107.1,0)
|
||||
self.assertAlmostEqual(res[1]["range"],110.7,0)
|
||||
|
||||
def test_energy_table(self):
|
||||
table = catima.get_energy_table()
|
||||
self.assertEqual(table[0],catima.energy_table(0))
|
||||
self.assertEqual(table[10],catima.energy_table(10))
|
||||
self.assertEqual(len(table),catima.max_datapoints)
|
||||
|
||||
def test_storage(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)
|
||||
print(data[1])
|
||||
et = catima.get_energy_table()
|
||||
|
||||
self.assertEqual(len(data),3)
|
||||
self.assertEqual(len(data[0]),len(et))
|
||||
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
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.da2de(p,water,et[100]),data[2][100],6)
|
||||
#self.assertAlmostEqual(catima.da2de(p,water,et[400]),data[2][400],6)
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
Loading…
Reference in New Issue
Block a user