Beispiel #1
0
 def test_actual_to_renate_idl(self):
     for test_case in self.test_cases:
         path = os.path.join('test_dataset', 'crm_systemtests', 'archive',
                             'renate_idl', test_case + '.xml')
         reference = Beamlet(data_path=path, solver='disregard')
         actual_source = reference.copy(object_copy='without-results')
         actual = Beamlet(param=actual_source.param,
                          profiles=actual_source.profiles,
                          components=actual_source.components,
                          atomic_db=actual_source.atomic_db,
                          solver='numerical')
         msg = 'Failure for following test case: ' + test_case + '\n'
         self.assertAlmostEqualRateEvolution(
             actual, reference, precision=self.EXPECTED_PRECISION, msg=msg)
Beispiel #2
0
 def _compute_all_benchmarks(self):
     for test_case in self.test_cases:
         test_path = self.test_path + '/' + self.actual_folder + '/' + test_case + '.xml'
         reference = Beamlet(data_path=test_path, solver='disregard')
         actual_source = reference.copy(object_copy='without-results')
         actual = Beamlet(param=actual_source.param,
                          profiles=actual_source.profiles,
                          components=actual_source.components,
                          atomic_db=actual_source.atomic_db,
                          solver='numerical')
         actual.compute_linear_density_attenuation()
         actual.compute_linear_emission_density()
         actual.compute_relative_populations()
         self.write.write_beamlet_profiles(actual,
                                           subdir=self.release_folder + '/')
Beispiel #3
0
 def test_profiles(self):
     actual = Beamlet(solver='disregard')
     self.assertIsInstance(
         actual.profiles,
         pandas.core.frame.DataFrame,
         msg='Expected data type of profiles is: pandas DataFrame.')
     self.assertEqual(
         len(actual.profiles),
         self.EXPECTED_PROFILES_LENGTH,
         msg='Expected profile length for test case does not match.')
     self.assertTupleEqual(
         actual.profiles.shape,
         (self.EXPECTED_PROFILES_LENGTH,
          2 * len(self.EXPECTED_COMPONENTS_KEYS) + 1),
         msg='Plasma description lacks necessary'
         ' density and/or temperature profiles for all components.')
     self.assertIsInstance(
         actual.profiles.axes[0],
         pandas.Int64Index,
         msg='Expected data type of X - axis for profiles is Int64Index.')
     self.assertIsInstance(
         actual.profiles.axes[1],
         pandas.MultiIndex,
         msg='Expected data type of Y - axis for profiles is MultiIndex.')
     for key in range(len(actual.profiles.keys())):
         self.assertTupleEqual(
             actual.profiles.keys()[key],
             self.EXPECTED_PROFILES_KEYS[key],
             msg='Profiles key description fails for test case.')
Beispiel #4
0
 def test_actual_to_previous_release(self):
     for test_case in self.test_cases:
         path = os.path.join('test_dataset', 'crm_systemtests', 'actual',
                             test_case + '.xml')
         reference = Beamlet(data_path=path, solver='disregard')
         actual_source = reference.copy(object_copy='without-results')
         actual = Beamlet(param=actual_source.param,
                          profiles=actual_source.profiles,
                          components=actual_source.components,
                          atomic_db=actual_source.atomic_db,
                          solver='numerical')
         msg = 'Failure for following test case: ' + test_case + '\n'
         self.assertAlmostEqualRateEvolution(
             actual, reference, precision=self.EXPECTED_PRECISION, msg=msg)
         actual.compute_linear_density_attenuation()
         self.assertAlmostEqualBeamAttenuation(
             actual, reference, precision=self.EXPECTED_PRECISION, msg=msg)
         actual.compute_linear_emission_density()
         self.assertAlmostEqualEmissionDensity(
             actual, reference, precision=self.EXPECTED_PRECISION, msg=msg)
         actual.compute_relative_populations()
         self.assertAlmostEqualRelativePopulation(
             actual, reference, precision=self.EXPECTED_PRECISION, msg=msg)
Beispiel #5
0
    def __init__(self, plasma, beam):

        # TODO - input variable validation

        # build species specifications, starting with electrons
        charges = [-1]
        charges.extend(
            [s.charge for s in plasma.composition if not s.charge == 0])
        nuclear_charges = [0]
        nuclear_charges.extend([
            s.element.atomic_number for s in plasma.composition
            if not s.charge == 0
        ])
        atomic_weights = [0]
        atomic_weights.extend([
            int(s.element.atomic_weight) for s in plasma.composition
            if not s.charge == 0
        ])
        index = ['electron']
        index.extend(
            ['ion{}'.format(i + 1) for i in range(len(atomic_weights) - 1)])
        components = pd.DataFrame(data={
            'q': charges,
            'Z': nuclear_charges,
            'A': atomic_weights
        },
                                  index=index)

        # sample plasma parameters along the beam axis
        beam_axis = np.linspace(0, beam.length, num=500)
        beam_to_world = beam.to_root()

        num_params = 1 + 2 + len(
            plasma.composition
        ) * 2  # *2 since every species has density and temperature
        profiles = np.zeros((num_params, 500))
        type_labels = []
        property_labels = []
        unit_labels = []
        profiles[0, :] = beam_axis
        type_labels.append('beamlet grid')
        property_labels.append('distance')
        unit_labels.append('m')
        profiles[1, :] = _sample_along_beam_axis(
            plasma.electron_distribution.density,
            beam_axis,
            beam_to_world,
            debug=True)
        type_labels.append('electron')
        property_labels.append('density')
        unit_labels.append('m-3')
        profiles[2, :] = _sample_along_beam_axis(
            plasma.electron_distribution.effective_temperature, beam_axis,
            beam_to_world)
        type_labels.append('electron')
        property_labels.append('temperature')
        unit_labels.append('eV')
        for i, species in enumerate(plasma.composition):
            profiles[i * 2 + 3, :] = _sample_along_beam_axis(
                species.distribution.density, beam_axis, beam_to_world)
            type_labels.append('ion{}'.format(i))
            property_labels.append('density')
            unit_labels.append('m-3')
            profiles[i * 2 + 4, :] = _sample_along_beam_axis(
                species.distribution.effective_temperature, beam_axis,
                beam_to_world)
            type_labels.append('ion{}'.format(i))
            property_labels.append('temperature')
            unit_labels.append('eV')

        profiles = np.swapaxes(profiles, 0, 1)
        row_index = [i for i in range(500)]
        column_index = pd.MultiIndex.from_arrays(
            [type_labels, property_labels, unit_labels],
            names=['type', 'property', 'unit'])

        profiles = pd.DataFrame(data=profiles,
                                columns=column_index,
                                index=row_index)

        # construct beam param specification
        xml = etree.Element('xml')
        head = etree.SubElement(xml, 'head')
        id_tag = etree.SubElement(head, 'id')
        id_tag.text = 'beamlet_test'
        body_tag = etree.SubElement(xml, 'body')
        beamlet_energy = etree.SubElement(body_tag, 'beamlet_energy',
                                          {'unit': 'keV'})
        beamlet_energy.text = str(int(beam.energy / 1000))
        beamlet_species = etree.SubElement(body_tag, 'beamlet_species')
        beamlet_species.text = beam.element.symbol
        beamlet_source = etree.SubElement(body_tag, 'beamlet_source')
        beamlet_source.text = 'beamlet/test_impurity.h5'
        beamlet_current = etree.SubElement(body_tag, 'beamlet_current',
                                           {'unit': 'A'})
        beamlet_current.text = '0.001'
        beamlet_mass = etree.SubElement(body_tag, 'beamlet_mass',
                                        {'unit': 'kg'})
        beamlet_mass.text = '1.15258e-026'
        beamlet_velocity = etree.SubElement(body_tag, 'beamlet_velocity',
                                            {'unit': 'm/s'})
        beamlet_velocity.text = '1291547.1348855693'
        beamlet_profiles = etree.SubElement(body_tag, 'beamlet_profiles', {})
        beamlet_profiles.text = './beamlet_test.h5'
        param = etree.ElementTree(element=xml)

        # move this outside
        # from crm_solver.atomic_db import AtomicDB
        # renata_ad = AtomicDB(param=param)

        b = Beamlet(param=param, profiles=profiles, components=components)
        b.compute_linear_density_attenuation()
        b.compute_relative_populations()

        self.renate_beamlet = b
xml = etree.Element('xml')
head = etree.SubElement(xml, 'head')
id_tag = etree.SubElement(head, 'id')
id_tag.text = 'beamlet_test'
body_tag = etree.SubElement(xml, 'body')
beamlet_energy = etree.SubElement(body_tag, 'beamlet_energy', {'unit': 'keV'})
beamlet_energy.text = '100'
beamlet_species = etree.SubElement(body_tag, 'beamlet_species')
beamlet_species.text = 'H'  # Li
beamlet_source = etree.SubElement(body_tag, 'beamlet_source')
beamlet_source.text = 'beamlet/test_impurity.h5'
beamlet_current = etree.SubElement(body_tag, 'beamlet_current', {'unit': 'A'})
beamlet_current.text = '0.001'
beamlet_mass = etree.SubElement(body_tag, 'beamlet_mass', {'unit': 'kg'})
beamlet_mass.text = '1.15258e-026'
beamlet_velocity = etree.SubElement(body_tag, 'beamlet_velocity',
                                    {'unit': 'm/s'})
beamlet_velocity.text = '1291547.1348855693'
beamlet_profiles = etree.SubElement(body_tag, 'beamlet_profiles', {})
beamlet_profiles.text = './beamlet_test.h5'
param = etree.ElementTree(element=xml)

b = Beamlet(param=param, profiles=profiles, components=components)

b.compute_linear_emission_density()
b.compute_linear_density_attenuation()
b.compute_relative_populations()

plt.plot(b.profiles['beamlet grid'], b.profiles['linear_emission_density'])
Beispiel #7
0
 def setUp(self):
     self.beamlet = Beamlet()
Beispiel #8
0
 def test_not_supported_solver(self):
     with self.assertRaises(Exception):
         actual = Beamlet(solver='not-supported')
Beispiel #9
0
 def test_analytical_solver(self):
     with self.assertRaises(NotImplementedError):
         actual = Beamlet(solver='analytical')