1
0
Fork 0
mirror of https://github.com/gwm17/catima.git synced 2024-11-26 20:18:51 -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 self.total[key]
return None 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): class z_eff_type(IntEnum):
none = 0, none = 0,
atima = 1 atima = 1
@ -287,7 +298,15 @@ cdef class Config:
default_config = 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): if(not energy is None):
projectile.T(energy) projectile.T(energy)
cdef catimac.Result cres = catimac.calculate(projectile.cbase,material.cbase,config.cbase) 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) res.setc(cres)
return res 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 get_clayers(Layers layers):
cdef catimac.Layers res cdef catimac.Layers res
cdef catimac.Material m cdef catimac.Material m
@ -308,17 +338,6 @@ cdef catimac.Material get_cmaterial(Material material):
res = material.cbase res = material.cbase
return res 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): def range(Projectile projectile, Material material, energy = None, Config config = default_config):
if(isinstance(energy,numpy.ndarray)): if(isinstance(energy,numpy.ndarray)):
res = numpy.empty(energy.size) res = numpy.empty(energy.size)

View File

@ -4,17 +4,7 @@ using namespace std;
#include "catima/catima.h" #include "catima/catima.h"
#include "catima/storage.h" #include "catima/storage.h"
#include "catima/material_database.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;
}
}
const lest::test specification[] = const lest::test specification[] =
{ {
@ -71,6 +61,11 @@ const lest::test specification[] =
catima::_storage.Add(p,graphite); catima::_storage.Add(p,graphite);
EXPECT(catima::_storage.get_index()==2); 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"){ CASE("energy table"){
double step = (catima::logEmax - catima::logEmin)/(catima::max_datapoints-1); double step = (catima::logEmax - catima::logEmin)/(catima::max_datapoints-1);
EXPECT(catima::energy_table.step==step); EXPECT(catima::energy_table.step==step);