def test_Hsrnoise_wrapper(self): comp = HSRNOISE() dirname = os.path.abspath(os.path.dirname(__file__)) basename = os.getcwd() os.chdir(dirname) try: # Check input file generation comp.load_model(filename='base.input') comp.setup() comp.generate_input() with open('base.input', 'r') as inp: result1 = inp.read() with open('test.input', 'r') as inp: result2 = inp.read() lnum = 1 for line1, line2 in zip(result1, result2): # Omit lines with objects, because memory location differs if 'object at' not in line1: try: self.assertEqual(line1, line2) except AssertionError as err: raise AssertionError("line %d doesn't match file %s: %s" % (lnum, 'base.input', err)) lnum += 1 # Check output file parsing shutil.copyfile('base.output', 'test.output') print comp.SPL comp.parse_output() print comp.SPL with open('hsr.dump', 'w') as out: dump(comp, stream=out, recurse=True) with open('base_hsr.dump', 'r') as inp: result1 = inp.readlines() with open('hsr.dump', 'r') as inp: result2 = inp.readlines() lnum = 1 for line1, line2 in zip(result1, result2): # Omit lines with objects, because memory location differs if 'object at' not in line1: try: self.assertEqual(line1, line2) except AssertionError as err: raise AssertionError("line %d doesn't match file %s: %s" % (lnum, 'base_hsr.dump', err)) lnum += 1 finally: os.chdir(basename)
def test_PDCYL_case(self): comp = PdcylComp() dirname = os.path.abspath(os.path.dirname(__file__)) basename = os.getcwd() os.chdir(dirname) try: # Check input file generation comp.load_model("transport.in") comp.generate_input() file1 = open("transport.in", "r") result1 = file1.read() file1.close() file2 = open("PDCYL.in", "r") result2 = file2.read() file2.close() self.assertEqual(result1, result2) # Check output file parsing shutil.copyfile("transport.out", "PDCYL.out") comp.parse_output() file1 = open("pdcyl.dump", "w") dump(comp, stream=file1, recurse=True) file1.close() file1 = open("transport.dump", "r") result1 = file1.readlines() file1.close() file2 = open("pdcyl.dump", "r") result2 = file2.readlines() file2.close() for line1, line2 in zip(result1, result2): # Omit lines with objects, because memory location differs if "object at" not in line1: self.assertEqual(line1, line2) finally: os.chdir(basename)
def test_PDCYL_case(self): comp = PdcylComp() dirname = os.path.abspath(os.path.dirname(__file__)) basename = os.getcwd() os.chdir(dirname) try: # Check input file generation comp.load_model('transport.in') comp.generate_input() file1 = open('transport.in', 'r') result1 = file1.read() file1.close() file2 = open('PDCYL.in', 'r') result2 = file2.read() file2.close() self.assertEqual(result1, result2) # Check output file parsing shutil.copyfile('transport.out', 'PDCYL.out') comp.parse_output() file1 = open('pdcyl.dump', 'w') dump(comp, stream=file1, recurse=True) file1.close() file1 = open('transport.dump', 'r') result1 = file1.readlines() file1.close() file2 = open('pdcyl.dump', 'r') result2 = file2.readlines() file2.close() for line1, line2 in zip(result1, result2): # Omit lines with objects, because memory location differs if 'object at' not in line1: self.assertEqual(line1, line2) finally: os.chdir(basename)
def test_FLOPS_cases(self): dirname = os.path.abspath(os.path.dirname(__file__)) basename = os.getcwd() os.chdir(dirname) try: for num in range(1, 7): startfile_name = 'xflp%s.in' % num infile_name = 'xflp%s_openmdao.in' % num outfile_name = 'xflp%s_openmdao.out' % num dumpfile_name = 'xflp%s_openmdao.dump' % num flops_comp = FlopsWrapper() # Check input file generation flops_comp.load_model(startfile_name) flops_comp.generate_input() with open(infile_name, 'r') as inp: result1 = inp.readlines() with open('flops.inp', 'r') as inp: result2 = inp.readlines() lnum = 1 for line1, line2 in zip(result1, result2): try: self.assertEqual(line1, line2) except AssertionError as err: raise AssertionError( "line %d doesn't match file %s: %s" % (lnum, infile_name, err)) lnum += 1 # Check output file parsing shutil.copyfile(outfile_name, 'flops.out') flops_comp.parse_output() with open('flops.dump', 'w') as out: dump(flops_comp, stream=out, recurse=True) with open(dumpfile_name, 'r') as inp: result1 = inp.readlines() with open('flops.dump', 'r') as inp: result2 = inp.readlines() lnum = 1 for line1, line2 in zip(result1, result2): # Omit lines with objects, because memory location differs if 'object at' not in line1: try: self.assertEqual(line1, line2) except AssertionError as err: raise AssertionError( "line %d doesn't match file %s: %s" % (lnum, dumpfile_name, err)) lnum += 1 finally: os.chdir(basename)
def test_FLOPS_cases(self): dirname = os.path.abspath(os.path.dirname(__file__)) basename = os.getcwd() os.chdir(dirname) try: for num in range(1, 7): startfile_name = 'xflp%s.in' % num infile_name = 'xflp%s_openmdao.in' % num outfile_name = 'xflp%s_openmdao.out' % num dumpfile_name = 'xflp%s_openmdao.dump' % num flops_comp = FlopsWrapper() # Check input file generation flops_comp.load_model(startfile_name) flops_comp.generate_input() with open(infile_name, 'r') as inp: result1 = inp.readlines() with open('flops.inp', 'r') as inp: result2 = inp.readlines() lnum = 1 for line1, line2 in zip(result1, result2): try: self.assertEqual(line1, line2) except AssertionError as err: raise AssertionError("line %d doesn't match file %s: %s" % (lnum, infile_name, err)) lnum += 1 # Check output file parsing shutil.copyfile(outfile_name, 'flops.out') flops_comp.parse_output() with open('flops.dump', 'w') as out: dump(flops_comp, stream=out, recurse=True) with open(dumpfile_name, 'r') as inp: result1 = inp.readlines() with open('flops.dump', 'r') as inp: result2 = inp.readlines() lnum = 1 for line1, line2 in zip(result1, result2): # Omit lines with objects, because memory location differs if 'object at' not in line1: try: self.assertEqual(line1, line2) except AssertionError as err: raise AssertionError("line %d doesn't match file %s: %s" % (lnum, dumpfile_name, err)) lnum += 1 finally: os.chdir(basename)
def test_Drea_wrapper(self): comp = DREA() dirname = os.path.abspath(os.path.dirname(__file__)) basename = os.getcwd() os.chdir(dirname) try: # Check input file generation comp.load_model(control_input='base_control.in', flocond_input='base_flocond.in', expnd_input='base_expnd.in', zrdmix_input='base_zrdmix.in', hwall_input='base_hwall.in') comp.setup() comp.generate_input('Subsonic') for item in ['control', 'flocond', 'expnd', 'zrdmix', 'hwall']: infile_name = 'base_%s.in' % item with open(infile_name, 'r') as inp: result1 = inp.read() with open('%s.in' % item, 'r') as inp: result2 = inp.read() lnum = 1 for line1, line2 in zip(result1, result2): try: self.assertEqual(line1, line2) except AssertionError as err: raise AssertionError( "line %d doesn't match file %s: %s" % (lnum, infile_name, err)) lnum += 1 self.assertEqual(result1, result2) # Check output file parsing shutil.copyfile('base_ejectd.out', 'ejectd.out') comp.parse_output('Subsonic') with open('drea.dump', 'w') as out: dump(comp, stream=out, recurse=True) with open('base_drea.dump', 'r') as inp: result1 = inp.readlines() with open('drea.dump', 'r') as inp: result2 = inp.readlines() lnum = 1 for line1, line2 in zip(result1, result2): # Omit lines with objects, because memory location differs if 'object at' not in line1: try: self.assertEqual(line1, line2) except AssertionError as err: raise AssertionError( "line %d doesn't match file %s: %s" % (lnum, 'base_drea.dump', err)) lnum += 1 finally: os.chdir(basename)
def test_Drea_wrapper(self): comp = DREA() dirname = os.path.abspath(os.path.dirname(__file__)) basename = os.getcwd() os.chdir(dirname) try: # Check input file generation comp.load_model(control_input='base_control.in', flocond_input='base_flocond.in', expnd_input='base_expnd.in', zrdmix_input='base_zrdmix.in', hwall_input='base_hwall.in') comp.setup() comp.generate_input('Subsonic') for item in ['control', 'flocond', 'expnd', 'zrdmix', 'hwall']: infile_name = 'base_%s.in' % item with open(infile_name, 'r') as inp: result1 = inp.read() with open('%s.in' % item, 'r') as inp: result2 = inp.read() lnum = 1 for line1, line2 in zip(result1, result2): try: self.assertEqual(line1, line2) except AssertionError as err: raise AssertionError("line %d doesn't match file %s: %s" % (lnum, infile_name, err)) lnum += 1 self.assertEqual(result1, result2) # Check output file parsing shutil.copyfile('base_ejectd.out', 'ejectd.out') comp.parse_output('Subsonic') with open('drea.dump', 'w') as out: dump(comp, stream=out, recurse=True) with open('base_drea.dump', 'r') as inp: result1 = inp.readlines() with open('drea.dump', 'r') as inp: result2 = inp.readlines() lnum = 1 for line1, line2 in zip(result1, result2): # Omit lines with objects, because memory location differs if 'object at' not in line1: try: self.assertEqual(line1, line2) except AssertionError as err: raise AssertionError("line %d doesn't match file %s: %s" % (lnum, 'base_drea.dump', err)) lnum += 1 finally: os.chdir(basename)
from pdcyl_comp import PdcylComp if __name__ == "__main__": # pragma: no cover from openmdao.main.api import set_as_top from numpy import array my_comp = set_as_top(PdcylComp()) # Note, change command to point to where your copy of pdcyl resides my_comp.command = '/home/ktmoore1/work/PDCYL/pdcyl' my_comp.load_model('transport.in') my_comp.run() from openmdao.main.container import dump dump(my_comp, recurse=True)
from pdcyl_comp import PdcylComp if __name__ == "__main__": # pragma: no cover from numpy import array my_comp = PdcylComp() # Note, change command to point to where your copy of pdcyl resides my_comp.command = ['/home/ktmoore1/work/PDCYL/pdcyl'] my_comp.load_model('transport.in') my_comp.run() from openmdao.main.container import dump dump(my_comp, recurse=True)