def parse_material(values):
    material = geometry.Material()

    for i in range(4):
        material.diffuse[i] = float(values[2 + i])
        material.ambient[i] = float(values[7 + i])
        material.specular[i] = float(values[12 + i])

    return material
示例#2
0
    def read(self, filename, model, params):
        xmldoc = minidom.parse(filename)

        # parse materials
        materials_xml = xmldoc.getElementsByTagName('library_materials')[0]
        materials = {}

        for material_xml in materials_xml.getElementsByTagName('material'):
            material = geometry.Material()

            material_name = material_xml.getAttribute('name')
            material_id = material_xml.getElementsByTagName(
                'instance_effect')[0].getAttribute('url')[1:]

            # finding proper effects tag
            # effect_xml = None

            # for effect in xmldoc.getElementsByTagName('effect'):
            # if effect.getAttribute('id') == material_id:
            # effect_xml = effect

            material.texture = params['texture']

            # end of material definition
            materials[material_name] = material

        # parse vertex data
        mesh_xml = xmldoc.getElementsByTagName('mesh')[0]

        # vertex arrays
        vertex_arrays = {}

        for source_xml in xmldoc.getElementsByTagName('source'):
            source_id = source_xml.getAttribute('id')
            float_array = source_xml.getElementsByTagName('float_array')

            if len(float_array) < 1:
                continue

            text = ''.join(t.nodeValue for t in float_array[0].childNodes)

            print(source_id)
            print(text)
            print(' ')

        return True
def read_mtl_file(filename):
    materials = {}

    input_file = open(filename, 'r')

    while True:
        line = input_file.readline()

        if len(line) == 0:
            break

        if line[len(line) - 1] == '\n':
            line = line[:len(line) - 1]

        parts = line.split(' ')

        if parts[0] == 'newmtl':
            current_material = geometry.Material()

            match = state_pattern.match(parts[1])

            if match is not None:
                current_material.state = geometry.encode_state(match.group(2))

            materials[parts[1]] = current_material
        elif parts[0] == 'Ka':
            for i in range(3):
                current_material.ambient[i] = float(parts[i + 1])
        elif parts[0] == 'Kd':
            for i in range(3):
                current_material.diffuse[i] = float(parts[i + 1])
        elif parts[0] == 'Ks':
            for i in range(3):
                current_material.specular[i] = float(parts[i + 1])
        elif parts[0] == 'map_Kd':
            current_material.texture = parts[1]

    input_file.close()

    return materials
示例#4
0
#microscopic XS, in barns
xs_scatter_238 = 11.29
xs_scatter_o = 3.888
xs_scatter_h = 20.47
xs_absorption_h = 1.0

barns = 1e-24  #cm; conversion factor

#macroscopic XS, cm^-1
sigma_fuel = (xs_scatter_238 + 2 * xs_scatter_o) * num_density_uo2 * barns
sigma_mod = (2 * xs_absorption_h + xs_scatter_o +
             2 * xs_scatter_h) * num_density_h2o * barns
sigma_mod_scatter = (xs_scatter_o + 2 * xs_scatter_h) * num_density_h2o * barns

#set material objects
fuel = geometry.Material('fuel', q_fuel, sigma_fuel, sigma_fuel)
moderator = geometry.Material('moderator', q_mod, sigma_mod, sigma_mod_scatter)

#########################################
############ RESULTS STORAGE ############
#########################################
#create directory to store plots, results in
timestr = time.strftime("%Y-%m-%d_%H-%M")
pathname = 'plots/' + timestr
plotter.mkdir_p(pathname)
savepath = pathname
resultsfile = pathname + '/' + timestr + '_results'

f = open('%s.txt' % resultsfile, 'w+')

f.write("********PROBLEM SETUP********\n")
示例#5
0
f.write("converge tol \t %g\nnum_azim \t %g\nnum_polar \t %g\n" %
        (tol, num_azim, n_p))
f.write("track spacing \t %g\nmesh spacing \t %g\n" % (t, spacing))
f.write("fuel total xs \t %g\nfuel scatter \t %g\nfuel absorp \t %g\n"
        "mod total xs \t %g\nmod scatter \t %g\nmod absorp \t%g\n"
        "*****************************\n\n" %
        (sigma_fuel_tot, sigma_fuel_scatter, sigma_fuel_abs, sigma_mod_tot,
         sigma_mod_scatter, sigma_mod_abs))

f.close()

###############################################
########## SETUP FLAT SOURCE REGIONS ##########
###############################################
#set material objects
fuelmat = geom.Material('fuel', q_fuel, sigma_fuel_tot, sigma_fuel_scatter,
                        sigma_fuel_abs)
moderator = geom.Material('moderator', q_mod, sigma_mod_tot, sigma_mod_scatter,
                          sigma_mod_abs)

fuel = geom.FlatSourceRegion(q_fuel, sigma_fuel_tot)
mod = geom.FlatSourceRegion(q_mod, sigma_mod_tot)
fsr = [fuel, mod]


def solveMOC(num_azim, spacing, t, savepath):
    #resultfilename = '/' + resultsfile + ''
    f = open('%s.txt' % resultsfile, 'a+')
    print "\nSolving MOC, n_azim %d, track spacing %g, mesh spacing %g" % (
        num_azim, t, spacing)
    f.write("\nSolving MOC, n_azim %d, track spacing %g, mesh spacing %g" %
            (num_azim, t, spacing))