Ejemplo n.º 1
0
    def get_errorr(self, **fileOptions):
        mydir = os.path.join(self.folder, fileOptions["FILENAME"])
        os.makedirs(mydir, exist_ok=True)

        utils.force_symlink(fileOptions["TAPE"], os.path.join(mydir, "tape20"))
        text = self._moder_input(20, -21, **fileOptions)

#        if "GENDFTAPE" in fileOptions:
#            force_symlink(fileOptions["GENDFTAPE"], os.path.join(mydir, "tape29"))
#            text += self.moder_input(29, 25, **fileOptions)
#            p = 0; g = 25
#        elif "PENDFTAPE" in kwargs:
        utils.force_symlink(fileOptions["PENDFTAPE"], os.path.join(mydir, "tape29"))
        text += self._moder_input(29, -25, **fileOptions)
        p = -25; g = 0

        errorrs = []; er = 30
        for tmp in self.TEMPS:
            text += self._errorr_input(-21, p, g, er, TMP=tmp, **fileOptions)
            errorrs.append(er)
            er += 1
        text += "stop"

        DfOutputs = OutputFiles()
        inputfile = os.path.join(mydir, "input_errorr.{}".format(fileOptions["TAG"]))
        DfOutputs = DfOutputs.append({"id" : "input_errorr", "format" : "TEXT", "file" : inputfile}, ignore_index=True)
        with open(inputfile,'w') as f: f.write(text)
        print(" --- run errorr for {} ---".format(fileOptions["TAG"]))
        returncode, stdout, stderr = run_process("{} < {}".format(self.exe, inputfile), cwd=mydir)

        newfile = os.path.join(mydir, "{}.errorr".format(fileOptions["TAG"]))
        if os.path.isfile(newfile): os.remove(newfile)
        with open(newfile, "a") as f:
            for er in errorrs:
                oldfile = os.path.join(mydir, "tape{}".format(er))
                if not os.path.isfile(oldfile): continue
                with open(oldfile) as g:
                    lines = g.readlines()
                    if er != errorrs[0]:
                        lines = lines[1:]
                    if er != errorrs[-1]:
                        lines = lines[:-1]
                    f.writelines(lines)
        if os.path.getsize(newfile) == 0: os.remove(newfile)
        if os.path.isfile(newfile): DfOutputs = DfOutputs.append({"id" : "errorr", "format" : "ERRORR", "file" : newfile}, ignore_index=True)

        oldfile = os.path.join(mydir, "output")
        newfile = os.path.join(mydir, "output_errorr.{}".format(fileOptions["TAG"]))
        shutil.move(oldfile, newfile)
        DfOutputs = DfOutputs.append({"id" : "output_errorr", "format" : "TEXT", "file" : newfile}, ignore_index=True)
        DfMessages = NjoyOutput.from_file(newfile).get_messages()

        for filename in os.listdir(mydir):
            if filename[:4] == 'tape': os.remove(os.path.join(mydir, filename))
        return DfOutputs, DfMessages
Ejemplo n.º 2
0
    def get_gendf(self, **fileOptions):
        mydir = os.path.join(self.folder, fileOptions["FILENAME"])
        os.makedirs(mydir, exist_ok=True)

        utils.force_symlink(fileOptions["TAPE"], os.path.join(mydir, "tape20"))
        text = self._moder_input(20, -21, **fileOptions)

        utils.force_symlink(fileOptions["PENDFTAPE"], os.path.join(mydir, "tape29"))
        text += self._moder_input(29, -25, **fileOptions)

        text += self._groupr_input(-21, -25, 0, -26, **fileOptions)
        text += self._moder_input(-26, 30, **fileOptions)
        text += "stop"

        DfOutputs = OutputFiles()
        inputfile = os.path.join(mydir, "input_gendf.{}".format(fileOptions["TAG"]))
        DfOutputs = DfOutputs.append({"id" : "input_gendf", "format" : "TEXT", "file" : inputfile}, ignore_index=True)
        with open(inputfile,'w') as f: f.write(text)
        print(" --- run gendf for {} ---".format(fileOptions["TAG"]))
        returncode, stdout, stderr = run_process("{} < {}".format(self.exe, inputfile), cwd=mydir)

        oldfile = os.path.join(mydir, "tape30")
        newfile = os.path.join(mydir, "{}.gendf".format(fileOptions["TAG"]))
        if os.path.isfile(oldfile):
            if os.path.getsize(oldfile) > 0:
                shutil.move(oldfile, newfile)
                DfOutputs = DfOutputs.append({"id" : "gendf", "format" : "GENDF", "file" : newfile}, ignore_index=True)

        oldfile = os.path.join(mydir, "output")
        newfile = os.path.join(mydir, "output_gendf.{}".format(fileOptions["TAG"]))
        shutil.move(oldfile, newfile)
        DfOutputs = DfOutputs.append({"id" : "output_gendf", "format" : "TEXT", "file" : newfile}, ignore_index=True)
        DfMessages = NjoyOutput.from_file(newfile).get_messages()

        for filename in os.listdir(mydir):
            if filename[:4] == 'tape': os.remove(os.path.join(mydir, filename))
        return DfOutputs, DfMessages
Ejemplo n.º 3
0
 def get_ace(self, tape, mat=None, pendftape=None, tag=None, 
             **fileOptions):
     """ Run the NJOY sequence to produce a ACE file.
     """
     if mat is None: mat = mat_from_endf(tape)
     fname = os.path.split(tape)[1]
     if tag is None: tag = fname
     mydir = os.path.join(self.wdir, fname)
     os.makedirs(mydir, exist_ok=True)
     if pendftape is None:
         dfout, dferr = self.get_pendf(tape, mat=mat, pendftape=pendftape, tag=tag)
         pendftape = dfout.query("id==\"pendf\"").file.iloc[0]
     else:
         dfout = OutputFiles()
         dferr = NjoyMessages()
     # Build njoy input text
     utils.force_symlink(tape, os.path.join(mydir, "tape20"))
     text = self._moder_input(20, -21)
     utils.force_symlink(pendftape, os.path.join(mydir, "tape29"))
     text += self._moder_input(29, -25)
     aces = []; xsdirs = []
     e = -21; p = -25; a = 40; x = 50
     for tmp,suff in zip(self.temps, self.suffixes):
         text += self._acer_input(e, p, a, x, mat, tmp, suff)
         aces.append(a); xsdirs.append(x)
         a += 1; x += 1
     text += "stop"
     # Run NJOY and process outputs
     inputfile = os.path.join(mydir, "input_acer.{}".format(tag))
     dfout = OutputFiles()
     dfout = dfout.append({"id" : "input_acer", "format" : "ACE", "file" : inputfile}, ignore_index=True)
     with open(inputfile,'w') as f: f.write(text)
     returncode, stdout, stderr = utils.run_process(
             "{} < {}".format(self.exe, inputfile),
             cwd=mydir,
             verbose=True,
             )
     # Process NJOY outputs
     newfile = os.path.join(mydir, "{}.ace".format(tag))
     if os.path.isfile(newfile): os.remove(newfile)
     for a in aces:
         oldfile = os.path.join(mydir, "tape{}".format(a))
         if not os.path.isfile(oldfile): continue
         with open(newfile, "a") as f, open(oldfile) as g: f.write(g.read())
     if (os.path.isfile(newfile) and os.path.getsize(newfile) > 0):
             dfout = dfout.append({"id" : "ace", "format" : "ACE", "file" : newfile}, ignore_index=True)
     newfile = os.path.join(mydir, "{}.xsdir".format(tag))
     if os.path.isfile(newfile): os.remove(newfile)
     with open(newfile, "a") as f:
         lines = []
         for x in xsdirs:
             oldfile = os.path.join(mydir, "tape{}".format(x))
             if not os.path.isfile(oldfile): continue
             with open(oldfile) as g:
                 xargs = g.read().split()
                 xargs[2] = "{}.ace".format(tag)
                 xargs[3] = "0"
                 lines.append(" ".join(xargs))
         f.write("\n".join(lines))
     if (os.path.isfile(newfile) and os.path.getsize(newfile) > 0):
         dfout = dfout.append({"id" : "xsdir", "format" : "TEXT", "file" : newfile}, ignore_index=True)
     oldfile = os.path.join(mydir, "output")
     newfile = os.path.join(mydir, "output_acer.{}".format(tag))
     if (os.path.isfile(oldfile) and os.path.getsize(oldfile) > 0):
         shutil.move(oldfile, newfile)
         dfout = dfout.append({"id" : "output_acer", "format" : "TEXT", "file" : newfile}, ignore_index=True)
         dferr = NjoyOutput.from_file(newfile).get_messages()
     for filename in os.listdir(mydir):
         if filename[:4] == 'tape': os.remove(os.path.join(mydir, filename))
     return dfout, dferr
Ejemplo n.º 4
0
 def get_pendf(self, tape, mat=None, pendftape=None, tag=None, 
               **fileOptions):
     """ Run NJOY sequence to produce a PENDF file.
     """
     if mat is None: mat = mat_from_endf(tape)
     fname = os.path.split(tape)[1]
     if tag is None: tag = fname
     mydir = os.path.join(self.wdir, fname)
     os.makedirs(mydir, exist_ok=True)
     DfOutputs = OutputFiles()
     # Build njoy input text
     utils.force_symlink(tape, os.path.join(mydir, "tape20"))
     text = self._moder_input(20, -21)
     if pendftape is None:
         text += self._reconr_input(-21, -22, mat, self.err)
     else:
         utils.force_symlink(pendftape, os.path.join(mydir, "tape30"))
         text += self._moder_input(30, -22)
     e = -21; p = -22
     if hasattr(self, "_temps"):
         text += self._broadr_input(e, p, -23, mat, self.temps, self.err)
         p = -23
     if self.free_gas:
         text += self._thermr_input(0, p, -24, mat, self.temps)
         p = -24
     if hasattr(self, "_sig0"):
         text += self._unresr_input(e, p, -25, mat, self.temps, self.sig0)
         p = -25
     if self.ptable:
         text += self._purr_input(e, p, -26, mat, self.temps, self.sig0)
         p = -26
     if hasattr(self, "_kerma"):
         text += self._heatr_input(e, p, -27, **fileOptions)
         p = -27
     if self.gaspr:
         text += self._gaspr_input(e, p, -28)
         p = -28
     text += self._moder_input(p, 29)
     text += "stop"
     # Run NJOY
     inputfile = os.path.join(mydir, "input_pendf.{}".format(tag))
     DfOutputs = DfOutputs.append({"id" : "input_pendf", "format" : "TEXT", "file" : inputfile}, ignore_index=True)
     with open(inputfile,'w') as f: f.write(text)
     returncode, stdout, stderr = utils.run_process(
             "{} < {}".format(self.exe, inputfile),
             cwd=mydir,
             verbose=True,
             )
     # Process NJOY outputs
     oldfile = os.path.join(mydir, "tape29")
     newfile = os.path.join(mydir, "{}.pendf".format(tag))
     if (os.path.isfile(oldfile) and os.path.getsize(oldfile) > 0):
         shutil.move(oldfile, newfile)
         DfOutputs = DfOutputs.append({"id" : "pendf", "format" : "ENDF", "file" : newfile}, ignore_index=True)
     oldfile = os.path.join(mydir, "output")
     newfile = os.path.join(mydir, "output_pendf.{}".format(tag))
     if (os.path.isfile(oldfile) and os.path.getsize(oldfile) > 0):
         shutil.move(oldfile, newfile)
         DfOutputs = DfOutputs.append({"id" : "output_pendf", "format" : "TEXT", "file" : newfile}, ignore_index=True)
         DfMessages = NjoyOutput.from_file(newfile).get_messages()
     for filename in os.listdir(mydir):
         if filename[:4] == 'tape': os.remove(os.path.join(mydir, filename))
     return DfOutputs, DfMessages
Ejemplo n.º 5
0
def get_pendf(tape, mat=None, pendftape=None, tag=None,
              err=0.001, errmax=None,
			  temperatures=[293.6], dilutions = [1E10],
			  partial_kermas = [302, 303, 304, 318, 402, 442, 443, 444, 445, 446, 447]
              broadr=True, thermr=True, purr=True,
			  unresr=False, heatr=False, gaspr=False
			  **kwargs):
	""" Run NJOY sequence to produce a PENDF file.
	"""
	if mat is None: mat = mat_from_endf(tape)
	fname = os.path.split(tape)[1]
	if tag is None: tag = fname
	mydir = os.path.join(self.wdir, fname)
	os.makedirs(mydir, exist_ok=True)
	# Build njoy input text
	utils.force_symlink(tape, os.path.join(mydir, "tape20"))
	text = _moder_input(20, -21)
	e, p = 21, 22
	text += _reconr_input(-e, -p, mat, self.err)
	if broadr:
		o = p + 1
		text += _broadr_input(-e, -p, -o, mat, temperatures, err)
		p = o
	if thermr:
		o = p + 1 
		text += _thermr_input(0, -p, -o, mat, temperatures)
		p = o
	if unresr:
		o = p + 1
		text += _unresr_input(-e, -p, -o, mat, temperatures, dilutions)
		p = o