def test_1Darray_write(self): my_comp = VarComponent() sb = Namelist(my_comp) my_comp.arrayvar = zeros(3, dtype=numpy_float32) my_comp.arrayvar[2] = 3.7 my_comp.single = array(['a', 'b', 'c']) my_comp.singleint = array([1, 2, 3]) my_comp.singlebool = array([False, True, False]) sb.set_filename(self.filename) sb.add_group('Test') sb.add_var("arrayvar") # This should be ignored because it is zero-D sb.add_var("arrayvarzerod") sb.add_var("single") sb.add_var("singleint") sb.add_var("singlebool") sb.generate() f = open(self.filename, 'r') contents = f.read() compare = "\n" + \ "&Test\n" + \ " arrayvar = 0.0, 0.0, 3.700000047683716\n" + \ " single = 'a', 'b', 'c'\n" + \ " singleint = 1, 2, 3\n" + \ " singlebool = F, T, F\n" + \ "/\n" self.assertEqual(contents, compare)
def test_2Darray_write(self): my_comp = VarComponent() sb = Namelist(my_comp) my_comp.arrayvar = zeros([3, 2], dtype=numpy_float32) my_comp.arrayvar[0, 1] = 3.7 my_comp.arrayvar[2, 0] = 7.88 sb.set_filename(self.filename) sb.add_group('Test') sb.add_var("arrayvar") sb.generate() f = open(self.filename, 'r') contents = f.read() compare = "\n" + \ "&Test\n" + \ " arrayvar(1,1) = 0.0, 3.700000047683716, \n" + \ "arrayvar(1,2) = 0.0, 0.0, \n" + \ "arrayvar(1,3) = 7.880000114440918, 0.0, \n" + \ "/\n" self.assertEqual(contents, compare)
def test_unsupported_array(self): top = Problem() top.root = Group() top.root.add('my_comp', VarComponent()) top.setup(check=False) top.run() sb = Namelist(top.root.my_comp) top['my_comp.arrayvar'] = zeros([2, 2, 2], dtype=numpy_float32) sb.set_filename(self.filename) sb.add_group('Test') sb.add_var("arrayvar") try: sb.generate() except RuntimeError as err: self.assertEqual(str(err), "Don't know how to handle array of" + \ " 3 dimensions") else: self.fail('RuntimeError expected')
def test_2Darray_write(self): top = Problem() top.root = Group() top.root.add('my_comp', VarComponent()) top.setup(check=False) top.run() sb = Namelist(top.root.my_comp) top['my_comp.arrayvar'] = zeros([3, 2], dtype=numpy_float32) top['my_comp.arrayvar'][0, 1] = 3.7 top['my_comp.arrayvar'][2, 0] = 7.88 sb.set_filename(self.filename) sb.add_group('Test') sb.add_var("arrayvar") sb.generate() f = open(self.filename, 'r') contents = f.read() compare = "\n" + \ "&Test\n" + \ " arrayvar(1,1) = 0.0, 3.700000047683716, \n" + \ "arrayvar(1,2) = 0.0, 0.0, \n" + \ "arrayvar(1,3) = 7.880000114440918, 0.0, \n" + \ "/\n" self.assertEqual(contents, compare)
def test_unsupported_traits(self): my_comp = VarComponent() my_comp.add('unsupported', File(iotype='in')) sb = Namelist(my_comp) sb.set_filename(self.filename) sb.add_group('Test') sb.add_var("unsupported") try: sb.generate() except RuntimeError, err: self.assertEqual(str(err), "Error generating input file. Don't" + \ " know how to handle data in variable" + \ " unsupported in group Test.")
def test_unsupported_array(self): my_comp = VarComponent() sb = Namelist(my_comp) my_comp.arrayvar = zeros([2, 2, 2], dtype=numpy_float32) sb.set_filename(self.filename) sb.add_group('Test') sb.add_var("arrayvar") try: sb.generate() except RuntimeError, err: self.assertEqual(str(err), "Don't know how to handle array of" + \ " 3 dimensions")
def test_1Darray_write(self): top = Problem() top.root = Group() top.root.add('my_comp', VarComponent()) top.setup(check=False) top.run() sb = Namelist(top.root.my_comp) top['my_comp.arrayvar'] = zeros(3, dtype=numpy_float32) top['my_comp.arrayvar'][2] = 3.7 top['my_comp.single'] = array(['a', 'b', 'c']) top['my_comp.singleint'] = array([1, 2, 3]) top['my_comp.singlebool'] = array([False, True, False]) sb.set_filename(self.filename) sb.add_group('Test') sb.add_var("arrayvar") # This should be ignored because it is zero-D sb.add_var("arrayvarzerod") sb.add_var("single") sb.add_var("singleint") sb.add_var("singlebool") sb.generate() f = open(self.filename, 'r') contents = f.read() compare = "\n" + \ "&Test\n" + \ " arrayvar = 0.0, 0.0, 3.700000047683716\n" + \ " single = 'a', 'b', 'c'\n" + \ " singleint = 1, 2, 3\n" + \ " singlebool = F, T, F\n" + \ "/\n" self.assertEqual(contents, compare)
def test_writes(self): top = Problem() top.root = Group() top.root.add('my_comp', VarComponent()) top.setup(check=False) top.run() sb = Namelist(top.root.my_comp) sb.set_filename(self.filename) sb.set_title("Testing") sb.add_group('FREEFORM') sb.add_group('OPTION') sb.add_comment("This is a comment") sb.add_var("boolvar") sb.add_var("intvar") sb.add_var("floatvar") sb.add_var("textvar") sb.add_newvar("newcard", "new value") sb.generate() f = open(self.filename, 'r') contents = f.read() compare = "Testing\n" + \ "FREEFORM\n" + \ "&OPTION\n" + \ " This is a comment\n" + \ " boolvar = F\n" + \ " intvar = 333\n" + \ " floatvar = -16.54\n" + \ " textvar = 'This'\n" + \ " newcard = 'new value'\n" + \ "/\n" self.assertEqual(contents, compare)
def test_writes(self): my_comp = VarComponent() my_comp.listenumvar = [1, 2, 1, 3] my_comp.listenumvar2 = [1.5, 1.5] my_comp.listenumvar3 = ['b'] my_comp.listenumvar4 = [False, False, False] sb = Namelist(my_comp) sb.set_filename(self.filename) sb.set_title("Testing") sb.add_group('FREEFORM') sb.add_group('OPTION') sb.add_comment("This is a comment") sb.add_var("boolvar") sb.add_var("intvar") sb.add_var("floatvar") sb.add_var("textvar") sb.add_var("listenumvar") sb.add_var("listenumvar2") sb.add_var("listenumvar3") sb.add_var("listenumvar4") sb.add_newvar("newcard", "new value") sb.generate() f = open(self.filename, 'r') contents = f.read() compare = "Testing\n" + \ "FREEFORM\n" + \ "&OPTION\n" + \ " This is a comment\n" + \ " boolvar = F\n" + \ " intvar = 333\n" + \ " floatvar = -16.54\n" + \ " textvar = 'This'\n" + \ " listenumvar = 1, 2, 1, 3\n" + \ " listenumvar2 = 1.5, 1.5\n" + \ " listenumvar3 = 'b'\n" + \ " listenumvar4 = F, F, F\n" + \ " newcard = 'new value'\n" + \ "/\n" self.assertEqual(contents, compare)
def generate_input(self, FabriOrSub): """Creates the DREA input files.""" # Determine ist, ifab and geometry parameters # ------------------------- if FabriOrSub == 'Fabri': self.ist = 1 self.ifab = 1 if FabriOrSub == 'Subsonic': self.ist = 0 self.ifab = 0 self.geom[-1, 0] = self.geo_in.length self.geom[0, 1] = (self.geo_in.Apri / 2 + self.geo_in.Asec / 2) / self.geo_in.width self.geom[-1, 1] = self.geo_in.Aexit / 2 / self.geo_in.width # Create control.in # ------------------------- crt = Namelist(self) crt.set_filename("control.in") crt.add_group('cntrl') crt.add_var("icnvl") crt.add_var("ieject") crt.add_var("ist") crt.add_var("ifab") crt.add_var("ispm") crt.add_var("iprnt") crt.add_var("ipw") crt.add_var("nmax") crt.generate() # Create flocond.in # ------------------------- flw = Namelist(self) flw.set_filename("flocond.in") flw.add_group('floc') flw.add_newvar("p01d", self.flow_in.pri.Pt) flw.add_newvar("p02d", self.flow_in.sec.Pt) flw.add_newvar("t01d", self.flow_in.pri.Tt) flw.add_newvar("t02d", self.flow_in.sec.Tt) flw.add_newvar("rm1", self.flow_in.pri.Mach) flw.add_newvar("rm2", self.flow_in.sec.Mach) flw.add_var("a1d") flw.add_var("a2d") flw.add_var("a3d") flw.add_var("rg") flw.add_newvar("gam", self.flow_in.gamma) flw.add_newvar("pinf", self.flow_in.Pstatic) flw.add_var("rec1") flw.add_var("rec2") flw.generate() # Create expnd.in # ------------------------- exd = Namelist(self) exd.set_filename("expnd.in") exd.add_group('exd') exd.add_var("rm1s") exd.add_var("rm2s") exd.add_var("dxe") exd.add_var("relx"), exd.add_var("errm") exd.add_var("nmx") exd.add_var("intt") exd.generate() # Create zrdmix.in # ------------------------- zrd = Namelist(self) zrd.set_filename("zrdmix.in") zrd.add_group('zrd') zrd.add_var("BWID") zrd.add_newvar("RLD", self.geo_in.length) zrd.add_var("RLPRNT") zrd.add_var("PR") zrd.add_var("CGR") zrd.add_var("REVRT") zrd.add_newvar("H0LM", self.geo_in.LhWave) zrd.add_newvar("H0HY", self.geo_in.LhMh) zrd.add_newvar("ALP1", self.geo_in.ChuteAngles) zrd.add_newvar("ALP2", self.geo_in.ChuteAngles) zrd.add_var("IMAX") zrd.add_var("JMAX") zrd.generate() # Create hwall.in # ------------------------- geom_data = [] form = "%.15f, %.15f, \n" geom_data.append("%d\n" % self.geom.shape[0]) for element in self.geom: geom_data.append(form % (element[0], element[1])) outfile = open("hwall.in", 'w') outfile.writelines(geom_data) outfile.close()
def generate_input(self, FabriOrSub): """Creates the DREA input files.""" # Determine ist, ifab and geometry parameters # ------------------------- if FabriOrSub == 'Fabri': self.ist = 1 self.ifab = 1 elif FabriOrSub == 'Subsonic': self.ist = 0 self.ifab = 0 else: msg = 'FabriOrSub should be Fabri or Subsonic' raise RuntimeError(msg) self.geom[-1,0] = self.geo_in.length self.geom[0,1] = (self.geo_in.Apri/2+self.geo_in.Asec/2)/self.geo_in.width self.geom[-1,1] = self.geo_in.Aexit/2/self.geo_in.width # Create control.in # ------------------------- crt = Namelist(self) crt.set_filename("control.in") crt.add_group('cntrl') crt.add_var("icnvl") crt.add_var("ieject") crt.add_newvar("ist", self.ist) crt.add_newvar("ifab", self.ifab) crt.add_var("ispm") crt.add_var("iprnt") crt.add_var("ipw") crt.add_var("nmax") crt.generate() # Create flocond.in # ------------------------- flw = Namelist(self) flw.set_filename("flocond.in") flw.add_group('floc') flw.add_newvar("p01d", self.flow_in.pri.Pt) flw.add_newvar("p02d", self.flow_in.sec.Pt) flw.add_newvar("t01d", self.flow_in.pri.Tt) flw.add_newvar("t02d", self.flow_in.sec.Tt) flw.add_newvar("rm1", self.flow_in.pri.Mach) flw.add_newvar("rm2", self.flow_in.sec.Mach) flw.add_var("a1d") flw.add_var("a2d") flw.add_var("a3d") flw.add_var("rg") flw.add_newvar("gam", self.flow_in.gamma) flw.add_newvar("pinf", self.flow_in.Pstatic) flw.add_var("rec1") flw.add_var("rec2") flw.generate() # Create expnd.in # ------------------------- exd = Namelist(self) exd.set_filename("expnd.in") exd.add_group('exd') exd.add_var("rm1s") exd.add_var("rm2s") exd.add_var("dxe") exd.add_var("relx"), exd.add_var("errm") exd.add_var("nmx") exd.add_var("intt") exd.generate() # Create zrdmix.in # ------------------------- zrd = Namelist(self) zrd.set_filename("zrdmix.in") zrd.add_group('zrd') zrd.add_var("BWID") zrd.add_newvar("RLD", self.geo_in.length) zrd.add_var("RLPRNT") zrd.add_var("PR") zrd.add_var("CGR") zrd.add_var("REVRT") zrd.add_newvar("H0LM", self.geo_in.LhWave) zrd.add_newvar("H0HY", self.geo_in.LhMh) zrd.add_newvar("ALP1", self.geo_in.ChuteAngles) zrd.add_newvar("ALP2", self.geo_in.ChuteAngles) zrd.add_var("IMAX") zrd.add_var("JMAX") zrd.generate() # Create hwall.in # ------------------------- geom_data = [] form = "%.15f, %.15f, \n" geom_data.append("%d\n" % self.geom.shape[0]) for element in self.geom: geom_data.append(form % (element[0], element[1])) outfile = open("hwall.in", 'w') outfile.writelines(geom_data) outfile.close()