def convert_flux(input_flux, group, by_energy=False): output_group_bounds = list(reversed(pp.ALL_GROUPS[group])) values = getattr(pp.groupconvert, "by_energy" if by_energy else "by_lethargy")( input_flux.boundaries, input_flux.values, output_group_bounds) output_flux = pp.FluxesFile() output_flux.setGroup(group) output_flux.values = values return output_flux
def createflux(): # set monoenergetic flux at 14 MeV for group 709 flux = pp.FluxesFile(name="14 MeV (almost) monoenergetic", norm=1.0) flux.setGroup(group) flux.setValue(12.0e6, 0.1) flux.setValue(13.0e6, 0.4) flux.setValue(14.0e6, 1.0) flux.validate() return flux
#!/usr/bin/env python3 import os import pypact as pp # fluxes file # set monoenergetic flux at 14 MeV for group 709 flux = pp.FluxesFile(name="14 MeV (almost) monoenergetic", norm=1.0) flux.setGroup(709) # set values at energies 12, 13 and 14 MeV flux.setValue(12.0e6, 0.1) flux.setValue(13.0e6, 0.4) flux.setValue(14.0e6, 1.0) # validate the data flux.validate() pp.to_file(flux, os.path.join('files', 'fluxes'))
import json import pypact as pp flux_file = "/Volumes/Pegasus2/Code/FISPACT-II/system_tests/Tst_prot_he/fluxes" ff = pp.FluxesFile() pp.from_file(ff, flux_file) data = { "name": ff.name.strip('\n').rstrip(), "group": len(ff.values), "energies": ff.boundaries, "values": ff.values, "normalisation": ff.norm } with open('fluxdata.json', 'w') as f: json.dump(data, f)
import os import math import matplotlib.pyplot as plt import pypact as pp iflux = 'fluxes66.in' oflux1 = os.path.join('ref', 'fluxes709_ref.out') oflux2 = os.path.join('ref', 'fluxes709_2_ref.out') iff = pp.ArbFluxesFile() off1 = pp.FluxesFile() off2 = pp.FluxesFile() pp.from_file(iff, iflux) pp.from_file(off1, oflux1) pp.from_file(off2, oflux2) def getraw(fluxes): x = [] y = [] norm = 1.0/sum(fluxes.values) for i in range(len(fluxes)): x.append(fluxes.boundaries[i]) y.append(fluxes.values[i]*norm) x.append(fluxes.boundaries[i+1]) y.append(fluxes.values[i]*norm) return x, y # scale the values by bin width def getscaled(fluxes): x = []
return ipt def getinventory(output): fuel = [] # get the last entry only for n in output[-1].nuclides: fuel.append(("{}{}{}".format(n.element, n.isotope, n.state), n.atoms)) return fuel ipt1 = makeinput(inventory=[("W", 100.0)], usemass=True, irradschedule=[(0.0, 1.1e14), (300., 1.1e14)]) fluxes = pp.FluxesFile() files = pp.FilesFile() pp.from_file(fluxes, 'fluxes.1') pp.from_file(files, 'files.1') opt1 = pp.compute(ipt1, files, fluxes, cleanup=False) print(opt1.run_data.run_name) irradschedule = [(0.0, 1.3e14), (600.0, 1.3e14)] for i in range(10): irradschedule.extend((1.0 * YEAR_IN_SECS, 0.0)) ipt2 = makeinput(inventory=getinventory(opt1), irradschedule=irradschedule) pp.from_file(fluxes, 'fluxes.1') pp.from_file(files, 'files.1') opt2 = pp.compute(ipt2, files, fluxes)
import os import pypact as pp fluxes = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'fluxes') ff1 = pp.FluxesFile() pp.from_file(ff1, fluxes) # normalise values sum1 = sum(ff1.values) ff1.values = [v/sum1 for v in ff1.values] import matplotlib.pyplot as plt plt.loglog(ff1.midPointEnergies, ff1.values, 'k', alpha=0.7, label='80 MeV proton beam') plt.xlabel("Energy (eV)", fontsize=18) plt.ylabel("Normalised units", fontsize=18) plt.grid() plt.legend() plt.show()
import os import pypact as pp import matplotlib.pyplot as plt fluxes1 = 'fluxes.162' fluxes2 = 'fluxes.162.convert' fluxes3 = 'fluxes.616' ff1 = pp.FluxesFile() ff2 = pp.FluxesFile() ff3 = pp.FluxesFile() pp.from_file(ff1, fluxes1) pp.from_file(ff2, fluxes2) pp.from_file(ff3, fluxes3) ff1.values = [f / sum(ff1.values) for f in ff1.values] ff2.values = [f / sum(ff2.values) for f in ff2.values] ff3.values = [f / sum(ff3.values) for f in ff3.values] plt.plot(ff1.midPointEnergies, ff1.values, 'k', alpha=0.7, label='162 original') plt.plot(ff2.midPointEnergies, ff2.values, 'r', alpha=0.5, label='162 group convert') plt.plot(ff3.midPointEnergies,
import pypact as pp ffin = pp.FluxesFile() pp.from_file(ffin, 'fluxes.616') assert ffin.boundaries == list(reversed(pp.ALL_GROUPS[616])) ffout = pp.ArbFluxesFile("arb flux 616") ffout.setGroup(ffin.boundaries) ffout.values = ffin.values pp.to_file(ffout, 'fluxes.616.arb')