def curvesSimilar(t1, y1, t2, y2, tol): """ This function returns True if the two given curves are similar enough within tol. Otherwise returns False. t1: time/domain of standard curve we assume to be correct y1: values of standard curve, usually either temperature in (K) or log of a mol fraction t2: time/domain of test curve y2: values of test curve, usually either temperature in (K) or log of a mol fraction The test curve is first synchronized to the standard curve using geatNearestTime function. We then calculate the value of abs((y1-y2')/y1), giving us a normalized difference for every point. If the average value of these differences is less than tol, we say the curves are similar. We choose this criteria because it is compatible with step functions we expect to see in ignition systems. """ # Make synchornized version of t2,y2 called t2sync,y2sync. t2sync = numpy.zeros_like(t1) y2sync = numpy.zeros_like(t1) for i, timepoint1 in enumerate(t1): time_index = findNearest(t2, timepoint1) t2sync[i] = t2[time_index] y2sync[i] = y2[time_index] # Get R^2 value equivalent: normalizedError = abs((y1 - y2sync) / y1) normalizedError = sum(normalizedError) / len(y1) if normalizedError > tol: return False else: return True
def curvesSimilar(t1, y1, t2, y2, tol): """ This function returns True if the two given curves are similar enough within tol. Otherwise returns False. t1: time/domain of standard curve we assume to be correct y1: values of standard curve, usually either temperature in (K) or log of a mol fraction t2: time/domain of test curve y2: values of test curve, usually either temperature in (K) or log of a mol fraction The test curve is first synchronized to the standard curve using geatNearestTime function. We then calculate the value of abs((y1-y2')/y1), giving us a normalized difference for every point. If the average value of these differences is less than tol, we say the curves are similar. We choose this criteria because it is compatible with step functions we expect to see in ignition systems. """ # Make synchornized version of t2,y2 called t2sync,y2sync. t2sync=numpy.zeros_like(t1) y2sync=numpy.zeros_like(t1) for i, timepoint1 in enumerate(t1): time_index = findNearest(t2, timepoint1) t2sync[i]=t2[time_index] y2sync[i]=y2[time_index] # Get R^2 value equivalent: normalizedError=abs((y1-y2sync)/y1) normalizedError=sum(normalizedError)/len(y1) if normalizedError > tol: return False else: return True
def getExample1Data(conditionData, conditions, shockTubeEffectiveHeatingTimes, smilesInExperiments): """ Parses the simulation's data to make generic data objects to compare with shock tube data taken from figure 1 of #Y. Hiadka, K. Sato, H. Hoshikawa, T. Nishimori, H. Tanaka, K. Inami, N. Ito. Combust. Flame, 120 3 (2000), pp. 245-264 """ #First get the time points close to allResults=[] for T, timepoint in shockTubeEffectiveHeatingTimes.iteritems(): for smiles in smilesInExperiments: temperatureResults=GenericData(label=label='Temperature', data = [] units = 'K') for conIndex, data in conditionData: if conditions[conIndex].T0==T: #index1 is the index of time from the simulation closest to timepoint #data is organized as (timeArray, rest of data) index1=findNearest(data[0], timepoint) for speciesData in data[1]: if smiles==speciesData.species: if smiles not in exptCompDict1: exptCompDict1[smiles]=[] #need to multiply by 20, in the experiment, they don't seem to count the Ar in the mole fraction exptCompDict1[smiles].append(resultsDictionary[T][1][index1][index2+1]*20) (index1, timepoint2)=rt.getNearestTime(timepoint1, resultsDictionary[T][2]) for index2, smiles in enumerate(majorSpecies[0:4]): if smiles not in exptCompDict2: exptCompDict2[smiles]=[] exptCompDict2[smiles].append(resultsDictionary[T][3][index1][index2+1]*20)