ukaea/neutronics_material_maker

making Material and MultiMaterial objects JSON serializable

Closed this issue · 1 comments

When using different materials in parameter studies it is useful to be able to dump the Material or MultiMaterial to a json file which means they must be JSON serializable.

This does not currently work

import json
from neutronics_material_maker import Materail

a = Material('H2O',temperature_in_C=30, pressure_in_Pa=101325)   

json.dumps(a)

I think this is due to the a.dict including the openmc_material object that does not look JSON serializable.

We should be able to overwrite the methods that convert this into a JSON dictionary so that it skips the ones that don't work and skips the ones starting with _

Currently a.__dict__ outputs

{'_material_name': 'H2O',
 '_material_tag': None,
 '_temperature_in_C': 30,
 '_temperature_in_K': 303.15,
 '_pressure_in_Pa': 101325,
 '_packing_fraction': 1.0,
 '_elements': 'H2O',
 '_isotopes': None,
 '_density': 0.9956494539376417,
 '_density_equation': "PropsSI('D', 'T', temperature_in_K, 'P', pressure_in_Pa, 'Water')/1000.",
 '_atoms_per_unit_cell': None,
 '_volume_of_unit_cell_cm3': None,
 '_density_unit': 'g/cm3',
 '_percent_type': 'ao',
 '_enrichment': None,
 '_enrichment_target': None,
 '_enrichment_type': None,
 '_reference': 'CoolProp python package',
 'enrichment_element': None,
 'density_packed': None,
 'openmc_material': Material
 	ID             =	4
 	Name           =	H2O
 	Temperature    =	None
 	Density        =	0.9956494539376417 [g/cm3]
 	S(a,b) Tables  
 	Nuclides       
 	H1             =	0.66656284   [ao]
 	H2             =	0.00010382666666666666 [ao]
 	O16            =	0.333207     [ao]
 	O17            =	0.00012633333333333333 [ao],
 'list_of_fractions': None,
 'chemical_equation': 'H2O',
 'element_numbers': None,
 'element_symbols': None}

fixed by PR #49