1
0
Fork 0
mirror of https://github.com/gwm17/catima.git synced 2024-11-26 12:08:52 -05:00

python module

This commit is contained in:
hrocho 2017-08-02 12:17:34 +02:00
parent c0a97d2536
commit 66b97e2caf
2 changed files with 37 additions and 23 deletions

View File

@ -243,6 +243,17 @@ cdef class MultiResult:
return self.total[key]
return None
def getJSON(self):
res = {}
res["total"] = self.total
res["partial"] = []
for r in self.results:
#print(r)
#temp = Result()
#temp.setc(r)
res["partial"].append(r)
return res
class z_eff_type(IntEnum):
none = 0,
atima = 1
@ -287,7 +298,15 @@ cdef class Config:
default_config = Config()
def calculate(Projectile projectile, Material material, energy = None, Config config = default_config):
def calculate(Projectile projectile, material, energy = None, config=default_config):
if(not energy is None):
projectile.T(energy)
if(isinstance(material,Material)):
return calculate_material(projectile, material, config = config)
if(isinstance(material,Layers)):
return calculate_layers(projectile, material, config = config)
def calculate_material(Projectile projectile, Material material, energy = None, Config config = default_config):
if(not energy is None):
projectile.T(energy)
cdef catimac.Result cres = catimac.calculate(projectile.cbase,material.cbase,config.cbase)
@ -295,6 +314,17 @@ def calculate(Projectile projectile, Material material, energy = None, Config co
res.setc(cres)
return res
def calculate_layers(Projectile projectile, Layers layers, energy = None, Config config = default_config):
cdef catimac.Layers clayers
clayers = catimac.Layers()
clayers = get_clayers(layers)
if(not energy is None):
projectile.T(energy)
cdef catimac.MultiResult cres = catimac.calculate(projectile.cbase, clayers, config.cbase)
res = MultiResult()
res.setc(cres)
return res
cdef catimac.Layers get_clayers(Layers layers):
cdef catimac.Layers res
cdef catimac.Material m
@ -308,17 +338,6 @@ cdef catimac.Material get_cmaterial(Material material):
res = material.cbase
return res
def calculate_layers(Projectile projectile, Layers layers, energy = None, Config config = default_config):
cdef catimac.Layers clayers
clayers = catimac.Layers()
clayers = get_clayers(layers)
if(not energy is None):
projectile.T(energy)
cdef catimac.MultiResult cres = catimac.calculate(projectile.cbase, clayers, config.cbase)
res = MultiResult()
res.setc(cres)
return res
def range(Projectile projectile, Material material, energy = None, Config config = default_config):
if(isinstance(energy,numpy.ndarray)):
res = numpy.empty(energy.size)

View File

@ -4,17 +4,7 @@ using namespace std;
#include "catima/catima.h"
#include "catima/storage.h"
bool rcompare(double a, double b,double eps){
if(fabs((a-b)/fabs(b))<eps){
return true;
}
else{
std::cout<<"\033[1;31m"<<a<<" == "<<b<<"\033[0m"<<std::endl;
return false;
}
}
#include "catima/material_database.h"
const lest::test specification[] =
{
@ -71,6 +61,11 @@ const lest::test specification[] =
catima::_storage.Add(p,graphite);
EXPECT(catima::_storage.get_index()==2);
},
CASE("storage limit"){
for(int i=0;i<100;i++){
auto m = catima::get_material(i);
}
},
CASE("energy table"){
double step = (catima::logEmax - catima::logEmin)/(catima::max_datapoints-1);
EXPECT(catima::energy_table.step==step);