Ejemplo n.º 1
0
 def loadInput(self,argv):
   print argv,type(argv)
   cl = GetPot(argv)
   if cl.search('-i'):
     self.unc_inp_file=cl.next('')
     print 'Selected uncertainty input',self.unc_inp_file,'...'
     #check desired file exists
     if not os.path.isfile(self.unc_inp_file):
       raise IOError('Uncertainty input not found: '+self.unc_inp_file)
     print '  ...found uncertainty input file.'
   else:
     raise IOError('Requires and input file using -i.')
   self.input_file = GetPot(Filename=self.unc_inp_file)
Ejemplo n.º 2
0
 def loadInput(self, argv):
     print argv, type(argv)
     cl = GetPot(argv)
     if cl.search('-i'):
         self.unc_inp_file = cl.next('')
         print 'Selected uncertainty input', self.unc_inp_file, '...'
         #check desired file exists
         if not os.path.isfile(self.unc_inp_file):
             raise IOError('Uncertainty input not found: ' +
                           self.unc_inp_file)
         print '  ...found uncertainty input file.'
     else:
         raise IOError('Requires and input file using -i.')
     self.input_file = GetPot(Filename=self.unc_inp_file)
Ejemplo n.º 3
0
def readInputFile(file_name):
    ifpot = GetPot(Filename=file_name)
    print ifpot.comments
    root_node = GPNode('root', None)
    buildSectionTree(ifpot, root_node)
    populateParams(ifpot, root_node)
#  root_node.Print()
    return root_node
Ejemplo n.º 4
0
 def createROMLevel(self, lvl, ie):
     ROMs = {}
     runs = self.getRunSet(lvl)
     for run, vrs in runs.iteritems():
         print '\nStarting run:', run
         chlist, ident = self.makeCase(run)
         runfile = ie.writeInput(self.unc_inp_file, chlist, ident)
         inp_file = GetPot(Filename=runfile)
         exdict = {}
         for i in range(len(run)):
             exdict[run[i]] = vrs[i]
         ex = Executor.ExecutorFactory('SC', exdict, inp_file)
         ex.run()
         os.system('rm ' + runfile)
         ROMs[ident] = ex.ROM
     return ROMs
Ejemplo n.º 5
0
 def createROMs(self):
     self.ROMs = {}
     ident = self.todo.keys()[0]
     print '\nStarting run:', ident
     inp_file = GetPot(Filename=self.unc_inp_file)
     ex_type = inp_file('Problem/executor', '')
     print 'ex type:', ex_type
     ex = Executor.ExecutorFactory(ex_type, self.varDict, inp_file)
     ex.run(verbose=self.verbose)
     try:
         self.ROMs[ident] = ex.ROM
         print 'sampled mean:', ex.ROM.moment(1)
     except AttributeError:
         pass  #MC doesn't store a rom at this point
     self.ex = ex
     #xs={}
     #for key,value in self.varDict.iteritems():
     #  xs[key]=1
     #print 'sampled:',ex.ROM.sample(xs,verbose=False)
     return ex
Ejemplo n.º 6
0
import sys
import time

def g(xa=0.75,loc=2.0,D=0.5,S=1.0):
  #S = 1.0 #source strength
  #D = 0.5 #diffusion coefficient
  #loc = 2.0 #depth in cm
  cof = S/xa
  #print '...in source.py...'
  #print 'D,xa:',D,xa
  L = np.sqrt(D/xa)
  flux = cof*(1.0-np.exp(-loc/L))
  return flux

if __name__=='__main__':
  cl = GetPot(sys.argv)
  if cl.search('-i'):
    inpFileName = ''
    inpFileName = cl.next(inpFileName)
    input_file=GetPot(Filename=inpFileName)
  else: raise IOError('Requires an input file using -i.')

  xa = input_file('Problem/xa' ,1.0)
  D  = input_file('Problem/D'  ,1.0)
  loc= input_file('Problem/loc',1.0)
  S  = input_file('Problem/S'  ,1.0)

  outFileName = input_file('Output/file','test.out')
  print 'outFileName:',outFileName

  result = g(xa,D,loc,S)
Ejemplo n.º 7
0
            prefix_less_token_name = token_name[len(TokenPrefix):]
            # NOTE: The line number might be wrong, because of the comment deletion
            lexer_mode.token_id_db[prefix_less_token_name] = \
                    TokenInfo(prefix_less_token_name, None, None, fh.name, line_n) 
        
        # find "#include" statements
        include_file_list = include_re_obj.findall(content)
        include_file_list = filter(lambda file: file not in done_list,    include_file_list)
        include_file_list = filter(lambda file: os.access(file, os.F_OK), include_file_list)
        work_list.extend(include_file_list)

if __name__ == "__main__":
    if len(sys.argv) < 2:
        print "error: missing command line parameter: input 'token file'"
        sys.exit(-1)

    cl = GetPot(sys.argv)
    input_file       = cl.follow("", "-i")
    token_class_file = cl.follow("", "-t")
    token_class      = cl.follow("token", "--token-class-name")
    token_counter_offset = cl.follow(1000, "--offset")
    output_file          = cl.follow("", "-o")
    token_prefix         = cl.follow("TKN_", "--tp")
    
    if "" in [input_file, output_file]:
        print "error: please specify input (option '-i') and output file (option '-o')"
        sys.exit(-1)
        
    do(Setup(input_file, output_file, token_class_file, token_class, token_prefix, token_counter_offset))

Ejemplo n.º 8
0
import numpy as np
import scipy.stats as stt
import time
import os
from GetPot import GetPot
from sys import *
import InputEditor
import Variables
import Samplers as spr
import Backends as be
import matplotlib.pyplot as plt

starttime = time.time()

#load uncertainty input
cl = GetPot(argv)
if cl.search('-i'):
    inpFileName = ''
    inpFileName = cl.next(inpFileName)
    input_file = GetPot(Filename=inpFileName)
else:
    raise IOError('Requires an input file using -i.')

#load problem-specific information
templateFile = input_file('Problem/templateFile', '')
#maxSamples = input_file('Problem/totalSamples',0)
storeFlux = input_file('Problem/storeFlux', 0)
execDir = input_file('Problem/execDir', '')
inputDir = input_file('Problem/inputDir', '')
input_editor = input_file('Problem/input_editor', '')
Ejemplo n.º 9
0
        # find "#include" statements
        include_file_list = include_re_obj.findall(content)
        include_file_list = filter(lambda file: file not in done_list,
                                   include_file_list)
        include_file_list = filter(lambda file: os.access(file, os.F_OK),
                                   include_file_list)
        work_list.extend(include_file_list)


if __name__ == "__main__":
    if len(sys.argv) < 2:
        print "error: missing command line parameter: input 'token file'"
        sys.exit(-1)

    cl = GetPot(sys.argv)
    input_file = cl.follow("", "-i")
    token_class_file = cl.follow("", "-t")
    token_class = cl.follow("token", "--token-class-name")
    token_counter_offset = cl.follow(1000, "--offset")
    output_file = cl.follow("", "-o")
    token_prefix = cl.follow("TKN_", "--tp")

    if "" in [input_file, output_file]:
        print "error: please specify input (option '-i') and output file (option '-o')"
        sys.exit(-1)

    do(
        Setup(input_file, output_file, token_class_file, token_class,
              token_prefix, token_counter_offset))
Ejemplo n.º 10
0
 def createROMs(self):
     print ''
     print 'Beginning HDMR term calculations...'
     self.ROMs = {}
     ie = InputEditor.HDMR_IO()
     #reference run
     chlist, ident = self.makeCase({})
     runfile = ie.writeInput(self.unc_inp_file, chlist, ident)
     inp_file = GetPot(Filename=runfile)
     ex = Executor.ExecutorFactory('SC', {}, inp_file)
     ex.run(verbose=False)
     os.system('rm ' + runfile)
     self.ROMs[ident] = ex.ROM
     # rest of runs
     numruns = {}
     for i in range(1, self.hdmr_level + 1):
         nr = 0
         print '\n===================================='
         print '    STARTING %i-INPUT INTERACTIONS' % i
         print '====================================\n'
         new = self.createROMLevel(i, ie)
         for key, value in new.iteritems():
             nr += 1
             self.ROMs[key] = value
         print '\nnumber of order %i runs: %i' % (i, nr)
         numruns[i] = nr
     xs = {}
     for key, value in self.varDict.iteritems():
         xs[key] = 1
     #for key,value in self.ROMs.iteritems():
     #  print 'mean',key,':',value.moment(1)
     print '\nROMs per level:'
     for key, value in numruns.iteritems():
         print ' ', key, value
     #for rom in self.ROMs.values():
     #  pk.dump(rom.serializable(),file('hdmr_'+rom.case()+'.pk','w'))
     self.HDMR_ROM = ROM.HDMR_ROM(self.ROMs, self.varDict)
     print 'Total Det. Runs:', self.HDMR_ROM.numRunsToCreate()
     print 'HDMR sampled', self.HDMR_ROM.sample(xs, self.hdmr_level)[1]
     #store output
     case = 'hdmr'
     case += '_' + self.input_file('Sampler/SC/indexSet', '')
     case += '_N' + str(len(self.varDict))
     case += '_H' + str(self.hdmr_level)
     #case+= '_L'+self.input_file('Sampler/SC/expOrd','')
     mean = self.HDMR_ROM.moment(self.hdmr_level, r=1, verbose=False)
     if self.input_file('HDMR/anova', 0) > 0:
         secm, contribs = self.HDMR_ROM.moment(self.hdmr_level,
                                               r=2,
                                               anova=True)
         anovaFileName = case + '.anova'
         anovaFile = file(anovaFileName, 'w')
         anovaFile.writelines('Variables,Contribution,Percent\n')
         for i, j in contribs.iteritems():
             name = '-'.join(i.split('_')[1:])
             value = str(j**2 / secm)
             anovaFile.writelines(name + ',' + str(j**2) + ',' + value +
                                  '\n')
         anovaFile.close()
         print 'ANOVA analysis written to', anovaFileName
     else:
         secm = self.HDMR_ROM.moment(self.hdmr_level, r=2, verbose=False)
     outFile = file(case + '.out', 'a')
     outFile.writelines('\nRuns,SC Level,Mean\n')
     outFile.writelines(str(self.HDMR_ROM.numRunsToCreate()) + ',')
     outFile.writelines(self.input_file('Sampler/SC/expOrd', '') + ',')
     outFile.writelines('%1.15e,%1.15e \n' % (mean, secm - mean * mean))
     outFile.close()