changeset 2557:57fcdc5bc098

app/pitot: made Pitot's eq mode work with CO2 based gases Historically, I had used a pg-eq mode in the past, where the fill state was set pg and I made the other states work in eq as they are generally higher temperature. The current solution sets the state 1 state using only the fill species (i.e. say CO2 and N2) instead of all possible states, and it works much better. This causes an issue with the calculation of Ht at the end of the pitot run due to states 8 (an eq state) and state 1 (a pg state) not being referenced to the same enthalpy reference temperature. This required mainly changes to pitot_input_utils.py where the input states are calculated using the function state_builder, and some small changes to some of the flow functions in pitot_flow_functions.py changes were also made to the function acceleration_tube_calculation so that the composition of the accelerator gas is printed after running, as this was seen to be useful as well...
author Chris James <c.james4@uq.edu.au>
date Thu, 04 Jan 2018 18:46:02 +1000
parents a0c37d3355d0
children 34f1dcd1363e
files app/pitot/pitot.py app/pitot/pitot_flow_functions.py app/pitot/pitot_input_utils.py
diffstat 3 files changed, 65 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/app/pitot/pitot.py	Sun Dec 03 12:16:08 2017 +1000
+++ b/app/pitot/pitot.py	Thu Jan 04 18:46:02 2018 +1000
@@ -314,7 +314,7 @@
 from pitot_output_utils import *
 from pitot_area_ratio_check import *
 
-VERSION_STRING = "31-Jul-2017"
+VERSION_STRING = "04-Jan-2018"
 
 DEBUG_PITOT = False
 
--- a/app/pitot/pitot_flow_functions.py	Sun Dec 03 12:16:08 2017 +1000
+++ b/app/pitot/pitot_flow_functions.py	Thu Jan 04 18:46:02 2018 +1000
@@ -425,7 +425,18 @@
         
         # do a clone of state 1 here so we don't get a lot of floating point jumping around
         # if the pressure is too low...
-        state1 = state1.clone()
+        # we need to do some weird stuff here if we are in eq mode with CO2 in the test gas,
+        # (which is made even worse by being in a function, I chose to check if it has a reactants
+        # dict to check if it is eq, and then if CO2 is in that dict...)
+        # but this is simple otherwise...
+        if hasattr(state1, 'reactants') and 'CO2' in state1.reactants:
+            state1.onlyList = state1.reactants
+            state1.with_ions = False
+            state1 = state1.clone()
+            state1.onlyList = []
+            state1.with_ions = True
+        else:
+            state1 = state1.clone()
 
         print "Performing normal shock calculation on state 1."         
         
@@ -1214,9 +1225,9 @@
             # the unsteady expansion work (as state 2 is expanding into state 7)
             states[cfg['at_entry_state']].with_ions = False 
         if cfg['Vs1'] > 2000.0 and 'Vs2_lower' not in cfg and 'Vs2_upper' not in cfg:
-            cfg['Vs2_lower'] = cfg['Vs1'] + 2000.0; cfg['Vs2_upper'] = 34750.0
+            cfg['Vs2_lower'] = cfg['Vs1'] + 1000.0; cfg['Vs2_upper'] = 34750.0
         elif cfg['Vs1'] <= 2000.0 and 'Vs2_lower' not in cfg and 'Vs2_upper' not in cfg:
-            cfg['Vs2_lower'] = cfg['Vs1'] + 1000.0; cfg['Vs2_upper'] = 34750.0
+            cfg['Vs2_lower'] = cfg['Vs1'] + 500.0; cfg['Vs2_upper'] = 34750.0
         else:
             print "Using custom limits for Vs2 secant solver."
             print "('Vs2_lower' = {0} m/s and 'Vs2_upper' = {1} m/s)".\
@@ -1417,6 +1428,13 @@
                         raise Exception, "pitot_flow_functions.nozzle_expansion(): Acceleration tube function failed trying to make the mass fraction based object ('s7_mf')."
                 else:
                     raise Exception, "pitot_flow_functions.nozzle_expansion(): Acceleration tube function failed trying to make the mass fraction based object ('s7_mf')."
+
+            print "Creating a version of state 6 with mass fractions ('s6_mf') in the states dict as the user has asked for this."
+            try:
+                states['s6_mf'] = states['s6'].clone(newOutputUnits='massf')
+            except Exception as e:
+                print "{0}: {1}".format(type(e).__name__, e.message)
+                raise Exception, "pitot_flow_functions.nozzle_expansion(): Acceleration tube function failed trying to make the mass fraction based object ('s6_mf')."
     elif cfg['expand_to'] == 'p7':
         print "State 7 is being expanded to a specified p7 value of {0} Pa.".format(cfg['p7'])
         try:
@@ -1475,8 +1493,6 @@
                 
     if PRINT_STATUS:
         print '-'*60
-        if not cfg['expand_to'] == 'p7': #no Vs2 or state 6 if we expand to a pressure to find state 7
-            print "state 6: p = {0:.2f} Pa, T = {1:.2f} K, V = {2:.2f} m/s.".format(states['s6'].p, states['s6'].T,  V['s6']) 
         print "state 7: p = {0:.2f} Pa, T = {1:.2f} K. V = {2:.2f} m/s.".format(states['s7'].p, states['s7'].T,  V['s7'])
         if isinstance(states['s7'], Gas):
             # print the species if it is an eq gas object...
@@ -1487,6 +1503,19 @@
             print 'species in state7 at equilibrium (by mass):'               
             print '{0}'.format(states['s7_mf'].species)
         print 'state 7 gamma = {0}, state 7 R = {1}.'.format(states['s7'].gam,states['s7'].R)
+
+        print '-' * 60
+        if not cfg['expand_to'] == 'p7': #no Vs2 or state 6 if we expand to a pressure to find state 7
+            print "state 6: p = {0:.2f} Pa, T = {1:.2f} K, V = {2:.2f} m/s.".format(states['s6'].p, states['s6'].T,  V['s6'])
+        if isinstance(states['s6'], Gas):
+            # print the species if it is an eq gas object...
+            print 'species in state6 (the accelerator gas) at equilibrium (by moles):'
+            print '{0}'.format(states['s6'].species)
+        if cfg['store_mass_fractions'] and isinstance(states['s6_mf'], Gas):
+            # print the species if it is an eq gas object...
+            print 'species in state6 (the accelerator gas) at equilibrium (by mass):'
+            print '{0}'.format(states['s7_mf'].species)
+        print 'state 6 gamma = {0}, state 6 R = {1}.'.format(states['s6'].gam,states['s6'].R)
     
     if PRINT_STATUS: print '-'*60
     
--- a/app/pitot/pitot_input_utils.py	Sun Dec 03 12:16:08 2017 +1000
+++ b/app/pitot/pitot_input_utils.py	Thu Jan 04 18:46:02 2018 +1000
@@ -1324,14 +1324,28 @@
         states['s1'].set_pT(float(cfg['p1']),cfg['T0'])
         cfg['gas_guess'] = None
     else:
-        if cfg['test_gas'] == 'mars' or cfg['test_gas'] == 'co2' or cfg['test_gas'] == 'venus':
-            states['s1'], cfg['gas_guess'], test_gas_gam, test_gas_Mmass = make_test_gas(cfg['test_gas'])   
+        # ------------------------ eq test gas stuff ----------------------------
+        if cfg['test_gas'] in ['mars', 'co2', 'venus']:
+            states['s1'], cfg['gas_guess'], test_gas_gam, test_gas_Mmass = make_test_gas(cfg['test_gas'])
+            if cfg['solver'] == 'eq':
+                print "As CO2 is in the test gas state 1 will be set using only the reactants in state 1."
+                print "({0})".format(states['s1'].reactants)
+                print "This will be turned off for other states based on this one so that they work normally."
+                states['s1'].onlyList = states['s1'].reactants
+                states['s1'].with_ions = False
+                states['s1'].set_pT(float(cfg['p1']), cfg['T1'])
+                print "The ideal gas guess for the gas will also be removed as it will cause issues in the normal shock function"
+                cfg['gas_guess'] = None
+            # the onlyList and with_ions stuff will be turned off below after states 2 and 7 have been cloned
+            # from state 1...
         else: #need to split this up as the function returns 4 values if CO2 is in the test gas
               # and trying to set the state of the co2 gas object at room temp will break it
             states['s1'], cfg['gas_guess'] = make_test_gas(cfg['test_gas'])
             if 'p1' not in cfg: #set atmospheric state if a pressure was not specified
                 cfg['p1'] = cfg['p0']
             states['s1'].set_pT(float(cfg['p1']),cfg['T1'])
+
+        #--------------- extra perfect gas or perfect gas eq stuff -------------
         if cfg['solver'] == 'pg' or cfg['solver'] == 'pg-eq': #make perfect gas object if asked to do so, then re-set the gas state
             if cfg['solver'] == 'pg-eq': #store the eq gas object as we'll want to come back to it later...      
                 states['s1-eq'] = states['s1'].clone()        
@@ -1386,7 +1400,7 @@
         states['s3'] = states['sd2'].clone() #s3 will be sd2 after unsteady expansion
     else:
         states['s3'] = states['s3s'].clone() #s3 will be s3s after unsteady expansion
-            
+
     states['s2'] = states['s1'].clone() #s2 is s1 shock heated
     
     if cfg['tunnel_mode'] == 'expansion-tube':
@@ -1407,6 +1421,19 @@
             #states['s7'].set_pT(states['s2'].p, states['s2'].T)
             states['s7'].with_ions = False
 
+    if cfg['solver'] == 'eq' and cfg['test_gas'] in ['mars', 'co2', 'venus']:
+        # now remove onlyList and with ions so that the calculation works fine
+        states['s1'].onlyList = []
+        states['s1'].with_ions = True
+
+        states['s2'].onlyList = []
+        states['s2'].with_ions = True
+
+        if cfg['tunnel_mode'] == 'expansion-tube':
+            states['s7'].onlyList = []
+            states['s7'].with_ions = True
+
+
     if PRINT_STATUS: print '-'*60               
     
     return cfg, states, V, M