//<Summary> //get value from a simulation //</Summary> public override void recvFromSim(sinter_Sim o_sim) { //this reads back the inputs // It's handy for default generation. // try // { if (!isSetting) { if (type == sinter_IOType.si_DY_DOUBLE) { o_value = o_sim.recvValueFromSim <double>(addressStrings[0]); ((double[])o_TimeSeriesValues)[o_TimeSeriesIndex] = (double)o_value; //Store it properly in the timevalues } else if (type == sinter_IOType.si_DY_INTEGER) { o_value = o_sim.recvValueFromSim <int>(addressStrings[0]); ((int[])o_TimeSeriesValues)[o_TimeSeriesIndex] = (int)o_value; //Store it properly in the timevalues } else if (type == sinter_IOType.si_DY_STRING) { o_value = o_sim.recvValueFromSim <String>(addressStrings[0]); ((string[])o_TimeSeriesValues)[o_TimeSeriesIndex] = (string)o_value; //Store it properly in the timevalues } } }
public virtual string getVariableName(sinter_Sim o_sim, string path) { //Get the simulator's name suggestion String returnName = o_sim.getCurrentName(path); return(returnName); /* * IList<String> parsedPath = o_sim.parsePath(path); * //If the name that comes back is just the path, try to make it the last part of the path, which is usually the most useful bit. * if (returnName == path) * { * if (parsedPath.Count <= 1) //If the path is only one segment long, just return it. We have no useful guess. * { * return returnName; * } else { * returnName = parsedPath[parsedPath.Count - 1]; * } * } * * if (String.Compare(returnName, "Value", true) != 0) * {//If the last element in the path is not "Value" (often appears in ACM Vectors) return it. * returnName = parsedPath[parsedPath.Count - 1]; * } * else * { //If the last element in the path IS "Value" get the second to last value, which is more useful usually. * return parsedPath[parsedPath.Count - 2]; * } * * return returnName; */ }
//--------------------------------------- // Comunication with Simulation Program //--------------------------------------- public void sendSetting(sinter_Sim o_sim) { if (isSetting) { o_sim.setSetting(o_settingName, Value); } }
public static sinter_Variable makeNewVariable(sinter_Sim sim, string path) { sinter_Variable retVar = null; sinter.sinter_Variable.sinter_IOType vartype = sim.guessTypeFromSim(path); if (vartype == sinter.sinter_Variable.sinter_IOType.si_DOUBLE || vartype == sinter.sinter_Variable.sinter_IOType.si_INTEGER || vartype == sinter.sinter_Variable.sinter_IOType.si_STRING) { sinter_Variable previewVar = new sinter_Variable(); string[] addressString = new string[1] { path }; previewVar.init(sim, vartype, addressString); previewVar.initializeUnits(sim); previewVar.initializeDescription(sim); retVar = previewVar; } else if (vartype == sinter.sinter_Variable.sinter_IOType.si_DOUBLE_VEC || vartype == sinter.sinter_Variable.sinter_IOType.si_INTEGER_VEC || vartype == sinter.sinter_Variable.sinter_IOType.si_STRING_VEC) { sinter_Vector previewVar = new sinter_Vector(); string[] addressString = new string[1] { path }; previewVar.init(sim, vartype, addressString); previewVar.initializeUnits(sim); previewVar.initializeDescription(sim); retVar = previewVar; } return(retVar); }
public override void initializeUnits(sinter_Sim o_sim) { if (!isSetting) { o_units = o_sim.getCurrentUnits(addressStrings[0], get_vectorIndicies(o_sim)); o_defaultUnits = o_units; } }
public int[] get_vectorIndicies(sinter_Sim sim) { if (o_vectorindicies == null) { o_vectorindicies = sim.getVectorIndicies(o_addressStrings[0], size); } return(o_vectorindicies); }
public void initializeUnits(sinter_Sim o_sim) { for (int ii = 0; ii <= rowStringCount - 1; ii++) { for (int jj = 0; jj <= colStringCount - 1; jj++) { o_value[ii, jj].initializeUnits(o_sim); } } }
//This is for querying the simulation for the current units in the simulation. So it sets both units and default units. //This isn't for use during a normal simulation, it's mostly part of the sinter config generation process. public virtual void initializeDescription(sinter_Sim o_sim) { if (!isSetting) { if (o_description == null || o_description == "") //If the user as already set some units, we want to keep those { o_description = o_sim.getCurrentDescription(addressStrings[0]); } } }
//This is for querying the simulation for the current units in the simulation. So it sets both units and default units. //This isn't for use during a normal simulation, it's mostly part of the sinter config generation process. public virtual void initializeUnits(sinter_Sim o_sim) { if (!isSetting) { if (o_units == null || o_units == "") //If the user as already set some units, we want to keep those { o_units = o_sim.getCurrentUnits(addressStrings[0]); o_defaultUnits = o_units; } } }
/** * createSinter parses part of the setup file passed in (as a string) to discover the * extension of the simulation file provided. * From that extension it creates the correct class for running that type of simulation. **/ public static ISimulation createSinter(string setupFileString) { sinter_SetupFile thisSetupFile = sinter_SetupFile.determineFileTypeAndParse(setupFileString); string extension = System.IO.Path.GetExtension(thisSetupFile.aspenFilename); sinter_Sim thisAspen = null; if (extension == ".bkp" || extension == ".apw") { thisAspen = new sinter_SimAspen(); thisAspen.setupFile = thisSetupFile; } else if (extension == ".acmf") { thisAspen = new sinter_SimACM(); thisAspen.setupFile = thisSetupFile; } else if (extension == ".xlsm" || extension == ".xls" || extension == ".xlsx") { thisAspen = new sinter_SimExcel(); thisAspen.setupFile = thisSetupFile; } else if (extension != null && extension.ToLower() == ".gencrypt") { thisAspen = new sinter.PSE.sinter_simGPROMS(); thisAspen.setupFile = thisSetupFile; } else if (extension != null && extension.ToLower() == ".gPJ") { throw new System.IO.IOException(String.Format( "gPJ is not an allowed extension for sinter simulation run. SimSinter requires a .gENCRYPT file. filename: {1}.", setupFileString)); } else { throw new System.IO.IOException(String.Format( "Unknown Aspen File extension {0} on filename: {1}. Expecting either .bkp or .apw for Aspen+, .acmf for ACM, .xlsm .xls .xlsx for Excel, or .gencrypt for GPROMS", extension, setupFileString)); } if (thisAspen == null) { throw new System.IO.IOException("Failed to create sinter object, reason unknown."); } if (thisAspen is sinter_InteractiveSim) { sinter_InteractiveSim sSim = (sinter_InteractiveSim)thisAspen; sSim.makeIOTree(); } return(thisAspen); }
//<Summary> //get value from a simulation //</Summary> public void recvFromSim(sinter_Sim o_sim) { if (mode != sinter_Variable.sinter_IOMode.si_IN) { //This allows one to pass in simulation settings as a sinter varaible if it has a path of the form: setting(blah) = value //So, setting( is a "reserved word" in sinter variable pathes (Maybe a special character would be better? for (int ii = 0; ii <= rowStringCount - 1; ii++) { for (int jj = 0; jj <= colStringCount - 1; jj++) { o_value[ii, jj].recvFromSim(o_sim); } } } }
/** * This version of init attempts to discover as much as possible about the variable automatically. * This is useful for the GUI, when the user selects a variable off the tree we need to try to figure out all about it. **/ public virtual void init(sinter_Sim sim, sinter.sinter_Variable.sinter_IOType type, string[] addStrings) { o_addressStrings = addStrings; IList <string> splitPath = sim.parsePath(o_addressStrings[0]); o_name = getVariableName(sim, addStrings[0]); o_mode = sinter_IOMode.si_IN; //Default to input o_type = type; o_description = null; o_table = null; o_tableName = null; o_tableCol = 0; o_tableRow = 0; makeValue(); recvFromSim(sim); setDefaultToValue(); }
//<Summary> //get value from a simulation //</Summary> public override void recvFromSim(sinter_Sim o_sim) { if (!isSetting) { if (type == sinter_IOType.si_DOUBLE_VEC) { o_sim.recvVectorFromSim <double>(addressStrings[0], get_vectorIndicies(o_sim), (double[])o_value); } else if (type == sinter_IOType.si_INTEGER_VEC) { o_sim.recvVectorFromSim <int>(addressStrings[0], get_vectorIndicies(o_sim), (int[])o_value); } else { o_sim.recvVectorFromSim <string>(addressStrings[0], get_vectorIndicies(o_sim), (string[])o_value); } } }
//<Summary> //get value from a simulation //</Summary> public virtual void recvFromSim(sinter_Sim o_sim) { //this reads back the inputs // It's handy for default generation. // try // { if (!isSetting) { if (type == sinter_IOType.si_DOUBLE) { o_value = o_sim.recvValueFromSim <double>(addressStrings[0]); } else if (type == sinter_IOType.si_INTEGER) { o_value = o_sim.recvValueFromSim <int>(addressStrings[0]); } else if (type == sinter_IOType.si_STRING) { o_value = o_sim.recvValueFromSim <String>(addressStrings[0]); } } }
public override void init(sinter_Sim sim, sinter_IOType type, string[] addStrings) { throw new NotImplementedException("Dynamic Scalar does not implement init with no time series"); }