def generate_input(self): """Creates the HSRNOISE input file.""" self.EJLIN = self.LinFrac*self.geo_in.length parser = InputFileGenerator() parser.set_template_file('test_temp.input') parser.set_generated_file('test.input') # Set Geometry and Flight Conditions # -------------------------------------- parser.mark_anchor("$GEOM") parser.transfer_var(self.HMIC, 1, 3) parser.transfer_var(self.SL, 2, 3) parser.mark_anchor("$FLIPATH") parser.transfer_var(self.ALTEVO, 1, 3) parser.mark_anchor("JETMETHOD") parser.transfer_var(self.JETMETHOD, 0,3) # Replace JET1IN variables in test.input # -------------------------------------- parser.mark_anchor("$JET1IN") parser.transfer_var(self.geo_in.Apri, 1, 3) #APRI parser.transfer_var(self.geo_in.Asec, 2, 3) #ASEC parser.transfer_var(self.ATHP, 3, 3) parser.transfer_var(self.CFG, 4, 3) parser.transfer_var(self.DELMIX, 5, 3) parser.transfer_var(self.DELPE, 6, 3) parser.transfer_var(self.DELPI, 7, 3) parser.transfer_var(self.geo_in.ChuteAngles, 8, 3) #DIVANG parser.transfer_var(self.geo_in.AR, 9, 3) #EJASP parser.transfer_var(self.EJD, 10, 3) parser.transfer_var(self.geo_in.length, 11, 3) # EJL parser.transfer_var(self.EJLIN, 12, 3) parser.transfer_var(self.FLIN, 13, 3) parser.transfer_var(self.geo_in.LhMh, 14, 3) #PEN parser.transfer_var(self.PLUGD, 15, 3) parser.transfer_var(self.PSI0, 16, 3) parser.transfer_var(self.SPOKE, 17, 3) parser.transfer_var(self.flow_in.pri.Tt, 18, 3) #TPRI parser.transfer_var(self.flow_in.sec.Tt, 19, 3) #TSEC parser.transfer_var(self.flow_in.pri.Vel, 20, 3) #VPRI parser.transfer_var(self.flow_in.sec.Vel, 21, 3) #VSEC parser.transfer_var(self.flow_in.pri.W, 22, 3) #WPRI parser.transfer_var(self.flow_in.sec.W, 23, 3) #WSEC parser.transfer_var(self.geo_in.AeAt, 24, 3) #XMAR # Replace JET2IN variables in test.input # -------------------------------------- parser.mark_anchor("$JET2IN") parser.transfer_var(self.APT, 1, 3) parser.transfer_var(self.AS, 2, 3) parser.transfer_var(self.CER, 3, 3) parser.transfer_var(self.DHP, 4, 3) parser.transfer_var(self.DL, 5, 3) parser.transfer_var(self.DM, 6, 3) parser.transfer_var(self.FPK, 7, 3) parser.transfer_var(self.GAMMAC, 8, 3) parser.transfer_var(self.HEX, 9, 3) parser.transfer_var(self.IEX, 10, 3) parser.transfer_var(self.ISUPPR, 11, 3) parser.transfer_var(self.LBE, 12, 3) parser.transfer_var(self.LBS, 13, 3) parser.transfer_var(self.LE, 14, 3) parser.transfer_var(self.LPE, 15, 3) parser.transfer_var(self.LPS, 16, 3) parser.transfer_var(self.MMC, 17, 3) parser.transfer_var(self.MPD, 18, 3) parser.transfer_var(self.PC, 19, 3) parser.transfer_var(self.PEN, 20, 3) parser.transfer_var(self.SAR, 21, 3) parser.transfer_var(self.SUPPK, 22, 3) parser.transfer_var(self.TC, 23, 3) parser.transfer_var(self.TEX, 24, 3) parser.transfer_var(self.VEX, 25, 3) parser.transfer_var(self.WEX, 26, 3) parser.transfer_var(self.WSWP, 27, 3) parser.generate()
def test_templated_input(self): template = "Junk\n" + \ "Anchor\n" + \ " A 1, 2 34, Test 1e65\n" + \ " B 4 Stuff\n" + \ "Anchor\n" + \ " C 77 False Inf 333.444\n" outfile = open(self.templatename, 'w') outfile.write(template) outfile.close() gen = InputFileGenerator() gen.set_template_file(self.templatename) gen.set_generated_file(self.filename) gen.set_delimiters(', ') gen.mark_anchor('Anchor') gen.transfer_var('CC', 2, 0) gen.transfer_var(3.0, 1, 3) gen.reset_anchor() gen.mark_anchor('Anchor', 2) gen.transfer_var('NaN', 1, 4) gen.reset_anchor() gen.transfer_var('55', 3, 2) gen.mark_anchor('C 77') gen.transfer_var(1.3e-37, -3, 6) gen.clearline(-5) gen.mark_anchor('Anchor', -1) gen.transfer_var('8.7', 1, 5) gen.generate() infile = open(self.filename, 'r') result = infile.read() infile.close() answer = "\n" + \ "Anchor\n" + \ " A 1, 3.0 34, Test 1.3e-37\n" + \ " B 55 Stuff\n" + \ "Anchor\n" + \ " C 77 False NaN 8.7\n" self.assertEqual(answer, result) # Test some errors try: gen.mark_anchor('C 77', 3.14) except ValueError, err: msg = "The value for occurrence must be an integer" self.assertEqual(str(err), msg)
def generate_input(self): """Creates the HSRNOISE input file.""" self.EJLIN = self.LinFrac * self.geo_in.length parser = InputFileGenerator() parser.set_template_file('test_temp.input') parser.set_generated_file('test.input') # Set Geometry and Flight Conditions # -------------------------------------- parser.mark_anchor("$GEOM") parser.transfer_var(self.HMIC, 1, 3) parser.transfer_var(self.SL, 2, 3) parser.mark_anchor("$FLIPATH") parser.transfer_var(self.ALTEVO, 1, 3) parser.mark_anchor("JETMETHOD") parser.transfer_var(self.JETMETHOD, 0, 3) # Replace JET1IN variables in test.input # -------------------------------------- parser.mark_anchor("$JET1IN") parser.transfer_var(self.geo_in.Apri, 1, 3) #APRI parser.transfer_var(self.geo_in.Asec, 2, 3) #ASEC parser.transfer_var(self.ATHP, 3, 3) parser.transfer_var(self.CFG, 4, 3) parser.transfer_var(self.DELMIX, 5, 3) parser.transfer_var(self.DELPE, 6, 3) parser.transfer_var(self.DELPI, 7, 3) parser.transfer_var(self.geo_in.ChuteAngles, 8, 3) #DIVANG parser.transfer_var(self.geo_in.AR, 9, 3) #EJASP parser.transfer_var(self.EJD, 10, 3) parser.transfer_var(self.geo_in.length, 11, 3) # EJL parser.transfer_var(self.EJLIN, 12, 3) parser.transfer_var(self.FLIN, 13, 3) parser.transfer_var(self.geo_in.LhMh, 14, 3) #PEN parser.transfer_var(self.PLUGD, 15, 3) parser.transfer_var(self.PSI0, 16, 3) parser.transfer_var(self.SPOKE, 17, 3) parser.transfer_var(self.flow_in.pri.Tt, 18, 3) #TPRI parser.transfer_var(self.flow_in.sec.Tt, 19, 3) #TSEC parser.transfer_var(self.flow_in.pri.Vel, 20, 3) #VPRI parser.transfer_var(self.flow_in.sec.Vel, 21, 3) #VSEC parser.transfer_var(self.flow_in.pri.W, 22, 3) #WPRI parser.transfer_var(self.flow_in.sec.W, 23, 3) #WSEC parser.transfer_var(self.geo_in.AeAt, 24, 3) #XMAR # Replace JET2IN variables in test.input # -------------------------------------- parser.mark_anchor("$JET2IN") parser.transfer_var(self.APT, 1, 3) parser.transfer_var(self.AS, 2, 3) parser.transfer_var(self.CER, 3, 3) parser.transfer_var(self.DHP, 4, 3) parser.transfer_var(self.DL, 5, 3) parser.transfer_var(self.DM, 6, 3) parser.transfer_var(self.FPK, 7, 3) parser.transfer_var(self.GAMMAC, 8, 3) parser.transfer_var(self.HEX, 9, 3) parser.transfer_var(self.IEX, 10, 3) parser.transfer_var(self.ISUPPR, 11, 3) parser.transfer_var(self.LBE, 12, 3) parser.transfer_var(self.LBS, 13, 3) parser.transfer_var(self.LE, 14, 3) parser.transfer_var(self.LPE, 15, 3) parser.transfer_var(self.LPS, 16, 3) parser.transfer_var(self.MMC, 17, 3) parser.transfer_var(self.MPD, 18, 3) parser.transfer_var(self.PC, 19, 3) parser.transfer_var(self.PEN, 20, 3) parser.transfer_var(self.SAR, 21, 3) parser.transfer_var(self.SUPPK, 22, 3) parser.transfer_var(self.TC, 23, 3) parser.transfer_var(self.TEX, 24, 3) parser.transfer_var(self.VEX, 25, 3) parser.transfer_var(self.WEX, 26, 3) parser.transfer_var(self.WSWP, 27, 3) parser.generate()
def test_templated_input_2Darrays(self): template = "Anchor\n" + \ "0 0 0 0 0\n" + \ "0 0 0 0 0\n" outfile = open(self.templatename, 'w') outfile.write(template) outfile.close() gen = InputFileGenerator() gen.set_template_file(self.templatename) gen.set_generated_file(self.filename) gen.mark_anchor('Anchor') var = array([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]]) gen.transfer_2Darray(var, 1, 2, 1, 5) gen.generate() infile = open(self.filename, 'r') result = infile.read() infile.close() answer = "Anchor\n" + \ "1 2 3 4 5\n" + \ "6 7 8 9 10\n" self.assertEqual(answer, result)
def test_templated_input_arrays(self): template = "Anchor\n" + \ "0 0 0 0 0\n" outfile = open(self.templatename, 'w') outfile.write(template) outfile.close() gen = InputFileGenerator() gen.set_template_file(self.templatename) gen.set_generated_file(self.filename) gen.mark_anchor('Anchor') gen.transfer_array(array([1, 2, 3, 4.75, 5.0]), 1, 3, 5, sep=' ') gen.generate() infile = open(self.filename, 'r') result = infile.read() infile.close() answer = "Anchor\n" + \ "0 0 1.0 2.0 3.0 4.75 5.0\n" self.assertEqual(answer, result)
def test_templated_input_same_anchors(self): template = "CQUAD4 1 3.456\n" + \ "CQUAD4 2 4.123\n" + \ "CQUAD4 3 7.222\n" + \ "CQUAD4 4\n" outfile = open(self.templatename, 'w') outfile.write(template) outfile.close() gen = InputFileGenerator() gen.set_template_file(self.templatename) gen.set_generated_file(self.filename) gen.set_delimiters(', ') gen.mark_anchor('CQUAD4') gen.transfer_var('x', 0, 2) gen.mark_anchor('CQUAD4') gen.transfer_var('y', 0, 3) gen.mark_anchor('CQUAD4', 2) gen.transfer_var('z', 0, 2) gen.generate() infile = open(self.filename, 'r') result = infile.read() infile.close() answer = "CQUAD4 x 3.456\n" + \ "CQUAD4 2 y\n" + \ "CQUAD4 3 7.222\n" + \ "CQUAD4 z\n" self.assertEqual(answer, result) print result
def execute(self): lenght = self.lenght radius_2 = self.radius_2 radius_4 = self.radius_4 alpha = self.alpha beta = self.beta # Prepare the input file system("del ark_stent.py") # deletes previous input file parser = InputFileGenerator() parser.set_template_file("template.py") parser.set_generated_file("ark_stent.py") parser.reset_anchor() parser.mark_anchor("lenght") parser.transfer_var(lenght, 0, 2) parser.reset_anchor() parser.mark_anchor("radius_2") parser.transfer_var(radius_2, 0, 2) parser.reset_anchor() parser.mark_anchor("radius_4") parser.transfer_var(radius_4, 0, 2) parser.reset_anchor() parser.mark_anchor("alpha") parser.transfer_var(alpha, 0, 2) parser.reset_anchor() parser.mark_anchor("beta") parser.transfer_var(beta, 0, 2) parser.generate() # Run Abaqus vi External's code execute function super(WrapAbaqus_stent, self).execute() # Parse the output files from abaqus parser = FileParser() parser.set_file("output.txt") parser.reset_anchor() parser.mark_anchor("max_mises") var = parser.transfer_var(1, 1) self.max_mises = var parser.reset_anchor() parser.mark_anchor("minus_max_displacement") var = parser.transfer_var(1, 1) self.minus_max_displacement = var print self.return_code
def execute(self): lenght = self.lenght radius_2 = self.radius_2 radius_4 = self.radius_4 alpha = self.alpha beta = self.beta # Prepare the input file system('del ark_stent.py') # deletes previous input file parser = InputFileGenerator() parser.set_template_file('template.py') parser.set_generated_file('ark_stent.py') parser.reset_anchor() parser.mark_anchor("lenght") parser.transfer_var(lenght, 0, 2) parser.reset_anchor() parser.mark_anchor("radius_2") parser.transfer_var(radius_2, 0, 2) parser.reset_anchor() parser.mark_anchor("radius_4") parser.transfer_var(radius_4, 0, 2) parser.reset_anchor() parser.mark_anchor("alpha") parser.transfer_var(alpha, 0, 2) parser.reset_anchor() parser.mark_anchor("beta") parser.transfer_var(beta, 0, 2) parser.generate() #Run Abaqus vi External's code execute function super(WrapAbaqus_stent, self).execute() #Parse the output files from abaqus parser = FileParser() parser.set_file('output.txt') parser.reset_anchor() parser.mark_anchor("max_mises") var = parser.transfer_var(1, 1) self.max_mises = var parser.reset_anchor() parser.mark_anchor("minus_max_displacement") var = parser.transfer_var(1, 1) self.minus_max_displacement = var print self.return_code