Esempio n. 1
0
        public void addVariable(sinter_IVariable var)
        {
            o_AllIVariable.Add(var, var.name);
            if (var.isTable)
            {
                o_Tables.Add(var, var.name);
                return;
            }

            sinter_Variable vVar = (sinter_Variable)var;

            addVariablePath(vVar);
            o_VariablesAndSettings.Add(vVar, var.name);

            if (vVar.isDynamicVariable)
            {
                o_DynamicVariables.Add(vVar, vVar.name);
            }

            if (vVar.isSetting)
            {
                o_Settings.Add(vVar, var.name);
            }
            else
            {
                o_Variables.Add(vVar, vVar.name); //o_Variables doesn't include settings or tables
            }
        }
Esempio n. 2
0
        /// <summary>
        /// In text setup files the IO Variables in a table need to be generated, as they don't exist independently in the
        /// file.  In a JSON file they do exist independently, so this function is unnecessary.
        /// </summary>

        public void fixupTable(sinter_SetupFile setupFile)
        {
            //First make sure the variable array is the right size
            int nn = rowStringCount;
            int mm = colStringCount;

            o_value = new sinter_Variable[nn, mm];

            for (int addressIndex = 0; addressIndex <= (addressStrings.Length - 1); addressIndex++)
            {
                for (int i = 0; i <= rowStringCount - 1; i++)
                {
                    for (int j = 0; j <= colStringCount - 1; j++)
                    {
                        string aString = addressStrings[addressIndex].Replace("%r", getRowString(i));
                        aString = aString.Replace("%c", getColString(j));
                        //Now create and init vars
                        sinter_Variable thisVar = new sinter_Variable();
                        //We don't have a real name, so just use table[i,j]
                        String   thisName = String.Format("{0}[{1},{2}]", o_name, i, j);
                        String   desc     = String.Format("{0}[{1},{2}] (Table Description : {3} )", name, getRowLabel(i), getColLabel(j), description);
                        String[] aStrings = new String[1] {
                            aString
                        };
                        thisVar.init(thisName, mode, sinter_Variable.sinter_IOType.si_DOUBLE, desc, aStrings);
                        thisVar.tableRow  = i;
                        thisVar.tableCol  = j;
                        thisVar.tableName = name;
                        thisVar.table     = this;
                        setVariable(i, j, thisVar);
                        setupFile.addVariable(thisVar);
                    }
                }
            }
        }
Esempio n. 3
0
 public void addSetting(sinter_Variable var)
 {
     o_AllIVariable.Add(var, var.name);
     o_Settings.Add(var, var.name);
     o_VariablesAndSettings.Add(var, var.name);
     addVariablePath(var);
 }
Esempio n. 4
0
 private void addVariablePath(sinter_Variable thisVar)
 {
     foreach (string path in thisVar.addressStrings)
     {
         o_pathToVariable[path] = thisVar;
     }
 }
        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);
        }
Esempio n. 6
0
        //Put together the output file from Sinter
        public virtual JObject getOutputs()
        {
            JObject toplevelJObject = new JObject();

            toplevelJObject.Add("title", String.Format("Outputs from {0}", this.setupFile.title));
            toplevelJObject.Add("description", String.Format("Outputs from {0}", this.setupFile.title));
            toplevelJObject.Add(this.setupfileKey, this.setupFile.aspenFilename);
            toplevelJObject.Add("author", this.setupFile.author);
            toplevelJObject.Add("date", DateTime.Now.ToString("yyyy'-'MM'-'dd"));
            toplevelJObject.Add("filetype", "sinteroutputs");
            toplevelJObject.Add("version", 0.2);

            JObject inputs  = new JObject();
            JObject outputs = new JObject();


            for (int ii = 1; ii <= this.countIO; ++ii)
            {
                sinter_Variable outputVar = (sinter_Variable)this.getIOByIndex(ii);
                string          varname   = outputVar.name;
                JObject         jsonVar   = new JObject();
                jsonVar.Add("value", outputVar.getOutput());
                if (outputVar.units == null || outputVar.units == "") //If units were not specified by the input file, use the default units.  (Note, may still be "")
                {
                    jsonVar.Add("units", outputVar.defaultUnits);
                }
                else
                {
                    jsonVar.Add("units", outputVar.units);
                }

                // If it's an output, add it to outputs, otherwise to inputs
                if (outputVar.isOutput)
                {
                    outputs.Add(varname, jsonVar);
                }
                else
                {
                    inputs.Add(varname, jsonVar);
                }
            }

            //Special case, Always put the run Status put the status in the outputs as "status".
            {
                JObject jsonVar = new JObject();
                jsonVar.Add("units", "");
                jsonVar.Add("value", (int)runStatus);
                outputs.Add("status", jsonVar);
            }

            toplevelJObject.Add("inputs", inputs);
            toplevelJObject.Add("outputs", outputs);

            return(toplevelJObject);
        }
Esempio n. 7
0
        /* Get a list of all availible settings for this simulation as sinter_Variables */
        public virtual IList <sinter_Variable> getSettings()
        {
            List <sinter_Variable> settings = new List <sinter_Variable>();

            foreach (KeyValuePair <string, Tuple <set_setting, get_setting, sinter_Variable.sinter_IOType> > entry in o_availibleSettings)
            {
                sinter_Variable thisSetting   = sinter_Factory.createVariable(entry.Value.Item3);
                string[]        addressString = { "setting(" + entry.Key + ")" };
                thisSetting.init(entry.Key, sinter_Variable.sinter_IOMode.si_IN, entry.Value.Item3, "Simulation specific setting: " + entry.Key, addressString);
                thisSetting.Value  = entry.Value.Item2();
                thisSetting.dfault = thisSetting.Value;
                settings.Add(thisSetting);
            }
            return(settings);
        }
 private void addIO(sinter_Variable.sinter_IOMode iomode, sinter_Variable.sinter_IOType type, string name, string desc, string[] addStrings, int[] bounds)
 {
     if (type == sinter_Variable.sinter_IOType.si_TABLE)
     {
         sinter_Table thisTable = new sinter_Table();
         if (bounds == null || bounds.Length < 2)
         {
             thisTable.init(name, iomode, desc, addStrings, 0, 0);
         }
         else
         {
             thisTable.init(name, iomode, desc, addStrings, bounds[0], bounds[1]);
         }
         addTable(thisTable);
     }
     else if (type == sinter_Variable.sinter_IOType.si_DOUBLE_VEC ||
              type == sinter_Variable.sinter_IOType.si_INTEGER_VEC ||
              type == sinter_Variable.sinter_IOType.si_STRING_VEC)
     {
         sinter_Vector o = new sinter_Vector();
         if (bounds == null || bounds.Length < 1)
         {
             o.init(name, iomode, type, desc, addStrings, 0);
         }
         else
         {
             o.init(name, iomode, type, desc, addStrings, bounds[0]);
         }
         addVariable(o);
     }
     else
     {
         sinter_Variable o = new sinter_Variable();
         o.init(name, iomode, type, desc, addStrings);
         if (o.isSetting)
         {
             addSetting(o);
         }
         else
         {
             addVariable(o);
         }
     }
 }
Esempio n. 9
0
        //old fashioned output, deprecated.
        public JObject getOutputsToJSON_1()
        {
            JObject outputDict = new JObject();

            for (int ii = 1; ii <= this.countIO; ++ii)
            {
                sinter_IVariable outputVal = this.getIOByIndex(ii);
                string           varname   = outputVal.name;
                if (outputVal.isTable)
                {
                    sinter_Table outputTable = (sinter_Table)outputVal;
                    int          nrows       = (int)outputTable.MNRows;
                    int          ncols       = (int)outputTable.MNCols;
                    for (int irow = 0; irow <= nrows; ++irow)
                    {
                        for (int icol = 0; icol <= ncols; ++icol)
                        {
                            outputDict.Add(varname + "[" + irow + "," + icol + "]", sinter_HelperFunctions.convertSinterValueToJToken(outputTable.getVariable(irow, icol)));
                        }
                    }
                }
                else if (outputVal.isVec)
                {
                    sinter_Variable             outputVar = (sinter_Variable)outputVal;
                    Newtonsoft.Json.Linq.JArray jsonArray = new Newtonsoft.Json.Linq.JArray(outputVar.Value);
                    outputDict.Add(varname, jsonArray);
                }
                else
                {
                    sinter_Variable outputVar = (sinter_Variable)outputVal;
                    outputDict.Add(varname, sinter_HelperFunctions.convertSinterValueToJToken(outputVar));
                }
            }

            //Special case, Always put the run Status put the status in the outputs as "status".
            outputDict.Add("status", (int)runStatus);

            return(outputDict);
        }
        public static JToken convertSinterValueToJToken(sinter_Variable sVar)
        {
            JToken jtok = null;

            if (sVar.isVec)
            {
                Newtonsoft.Json.Linq.JArray jsonArray = new Newtonsoft.Json.Linq.JArray(sVar.Value);
                jtok = (JToken)jsonArray;
            }
            else if (sVar.isScalar)
            {
                if (sVar.type == sinter_Variable.sinter_IOType.si_DOUBLE)
                {
                    double val = Convert.ToDouble(sVar.Value);
                    jtok = (JToken)val;
                }
                else if (sVar.type == sinter_Variable.sinter_IOType.si_INTEGER)
                {
                    int val = Convert.ToInt32(sVar.Value);
                    jtok = (JToken)val;
                }
                else if (sVar.type == sinter_Variable.sinter_IOType.si_STRING)
                {
                    String val = (String)sVar.Value;
                    jtok = (JToken)val;
                }
                else
                {
                    throw new System.IO.IOException(String.Format("Sinter Variable {0} has unknown type {1}", sVar.name, sVar.type));
                }
            }
            else
            {
                throw new System.IO.IOException(String.Format("Sinter Variable {0} has unknown type {1}", sVar.name, sVar.type));
            }
            return(jtok);
        }
Esempio n. 11
0
        //Convert from a steady state variable to a dynamic one
        public sinter_DynamicScalar(sinter_Variable rhs)
        {
            o_TimeSeriesLength = 1;
            o_TimeSeriesValues = new double[1];
            addressStrings     = rhs.addressStrings;
            name        = rhs.name;
            mode        = rhs.mode;
            description = rhs.description;
            table       = rhs.table;
            tableName   = rhs.tableName;
            tableCol    = rhs.tableCol;
            tableRow    = rhs.tableRow;

            switch (rhs.type)
            {
            case sinter_Variable.sinter_IOType.si_DOUBLE:
                type = sinter_Variable.sinter_IOType.si_DY_DOUBLE;
                break;

            case sinter_Variable.sinter_IOType.si_INTEGER:
                type = sinter_Variable.sinter_IOType.si_DY_INTEGER;
                break;

            case sinter_Variable.sinter_IOType.si_STRING:
                type = sinter_Variable.sinter_IOType.si_DY_STRING;
                break;
            }

            units        = rhs.units;
            defaultUnits = rhs.defaultUnits;

            Value   = rhs.Value;
            maximum = rhs.maximum;
            minimum = rhs.minimum;
            dfault  = rhs.dfault;
        }
Esempio n. 12
0
 public void setVariable(int ii, int jj, sinter_Variable value)
 {
     o_value[ii, jj] = value;
 }
Esempio n. 13
0
        private sinter.sinter_AppError processLine(string l)
        {
            string[] fields = null;
            sinter_Variable.sinter_IOType type = default(sinter_Variable.sinter_IOType);
            sinter_Variable.sinter_IOMode mode = default(sinter_Variable.sinter_IOMode);
            //
            // Split line using a bar
            //
            if (l.Length < 1)
            {
                return(sinter.sinter_AppError.si_OKAY);
            }

            fields = l.Split('|');
            if (fields.Length == 0)
            {
                return(sinter.sinter_AppError.si_OKAY);
            }
            for (int i = 0; i <= fields.Length - 1; i++)
            {
                fields[i] = fields[i].Trim();//  Strings.Trim(fields[i]);
                char tab = '\u0009';
                fields[i] = fields[i].Replace(tab.ToString(), "");
            }
            //
            // Check for special key words
            //
            if (fields[0].Length == 0)
            {
                return(sinter.sinter_AppError.si_OKAY);
                //Blank or invalid line, ignore it
            }
            if (fields[0][0] == '#')  //If first char in line is a #
            {
                return(sinter.sinter_AppError.si_OKAY);
                //it is a comment ignore line
            }
            else if (fields[0] == "file" & fields.Length == 2)
            {
                o_aspenFilename = fields[1];
                //e = sim.openSim();
                //open sim so can inspect IO
                //return e;
                return(sinter.sinter_AppError.si_OKAY);
            }
            else if (fields[0] == "dir" & fields.Length == 2)
            {
//                o_workingDir = fields[1];
                return(sinter.sinter_AppError.si_UNKNOWN_FIELD);
            }
            else if (fields[0] == "title" & fields.Length == 2)
            {
                o_title = fields[1];
                return(sinter.sinter_AppError.si_OKAY);
            }
            else if (fields[0] == "author" & fields.Length == 2)
            {
                o_author = fields[1];
                return(sinter.sinter_AppError.si_OKAY);
            }
            else if (fields[0] == "date" & fields.Length == 2)
            {
                o_dateString = fields[1];
                return(sinter.sinter_AppError.si_OKAY);
            }
            else if (fields[0] == "description" & fields.Length == 2)
            {
                o_simDesc = fields[1];
                return(sinter.sinter_AppError.si_OKAY);
            }
            else if (fields[0] == "min")
            {
                processMin(fields);
                return(sinter.sinter_AppError.si_OKAY);
            }
            else if (fields[0] == "max")
            {
                processMax(fields);
                return(sinter.sinter_AppError.si_OKAY);
            }
            else if (fields[0] == "default")
            {
                processDefault(fields);
                return(sinter.sinter_AppError.si_OKAY);
            }
            else if (fields[0] == "limits")
            {
                if (getIOByName(fields[1]) == null)
                {
                    throw new System.IO.IOException("Cannot apply labels, Object " + fields[1] + " not found.  (Settings not allowed)");
                    //return sinter.sinter_AppError.si_OKAY;
                }
                else if (!(getIOByName(fields[1]).isScalar))
                {
                    throw new System.IO.IOException("Cannot use limits on non scalar");
                    //return sinter.sinter_AppError.si_OKAY;
                }
                else if (fields.Length != 4)
                {
                    throw new System.IO.IOException("Limits on " + fields[1] + " too few arguments");
                    //return sinter.sinter_AppError.si_OKAY;
                }
                if (getIOByName(fields[1]).type == sinter_Variable.sinter_IOType.si_DOUBLE)
                {
                    sinter_Variable thisVar = (sinter_Variable)getIOByName(fields[1]);
                    thisVar.minimum = Convert.ToDouble(fields[2]);
                    thisVar.maximum = Convert.ToDouble(fields[3]);
                }
                else if (getIOByName(fields[1]).type == sinter_Variable.sinter_IOType.si_INTEGER)
                {
                    sinter_Variable thisVar = (sinter_Variable)getIOByName(fields[1]);
                    thisVar.minimum = Convert.ToInt32(fields[2]);
                    thisVar.maximum = Convert.ToInt32(fields[3]);
                }
                return(sinter.sinter_AppError.si_OKAY);
            }
            else if (fields[0] == "cLabels" | fields[0] == "clabels")
            {
                if (getIOByName(fields[1]) == null)
                {
                    throw new System.IO.IOException("Cannot apply labels, Object " + fields[1] + " not found");
                }
                processLabels("c", fields, getIOByName(fields[1]));
                return(sinter.sinter_AppError.si_OKAY);
            }
            else if (fields[0] == "rLabels" | fields[0] == "rlabels")
            {
                if (getIOByName(fields[1]) == null)
                {
                    throw new System.IO.IOException("Cannot apply labels, Object " + fields[1] + " not found");
                }
                processLabels("r", fields, getIOByName(fields[1]));
                return(sinter.sinter_AppError.si_OKAY);
            }
            else if (fields[0] == "cStrings" | fields[0] == "cstrings")
            {
                if (getIOByName(fields[1]) == null)
                {
                    throw new System.IO.IOException("Cannot apply strings, Object " + fields[1] + " not found");
                }
                processLabels("cs", fields, getIOByName(fields[1]));
                sinter_IVariable io = getIOByName(fields[1]);
                return(sinter.sinter_AppError.si_OKAY);
            }
            else if (fields[0] == "rStrings" | fields[0] == "rstrings")
            {
                if (getIOByName(fields[1]) == null)
                {
                    throw new System.IO.IOException("Cannot apply strings, Object " + fields[1] + " not found");
                }
                processLabels("rs", fields, getIOByName(fields[1]));
                return(sinter.sinter_AppError.si_OKAY);
            }
            else if (fields[0] == "rStrings_ForEach" | fields[0] == "rstrings_ForEach")
            {
                throw new System.IO.IOException("No Foreach allowed with this version of sinter.");
            }
            //
            // Check lines that add input and output
            //
            if (fields.Length >= 5)
            {
                //assume if a line isn't a keyword line and it has 5 or more fields
                // it is adding an input or output
                //
                // 0-name | 1-iomode | 2-iotype | 3-description | 4-addess-string ... (There may be multiple address strings)

                if ((fields[1] == "input"))
                {
                    mode = sinter_Variable.sinter_IOMode.si_IN;
                }
                else
                {
                    mode = sinter_Variable.sinter_IOMode.si_OUT;
                }
                int[] bounds = null;
                sinter_Variable.string2Type(fields[2], ref type, ref bounds);
                string[] addresses = new string[fields.Length - 4];
                Array.Copy(fields, 4, addresses, 0, fields.Length - 4);
                //Copy all address strings for this line
                addIO(mode, type, fields[0], fields[3], addresses, bounds);
                return(sinter.sinter_AppError.si_OKAY);
            }

            throw new System.IO.IOException(String.Format("Sinter Config Line unknown: {0}", l));
        }
Esempio n. 14
0
        private void processDefault(string[] fields)
        {
            int    i    = 0;
            string line = null;

            string[]         n        = null;
            int              j        = 0;
            sinter_IVariable thisIVar = (sinter_IVariable)getIOByName(fields[1]);

            if (thisIVar == null)
            {
                throw new System.IO.IOException("Cannot apply labels, Object " + fields[1] + " not found");
            }
            if (thisIVar.isScalar)
            {
                sinter_Variable thisVar = (sinter_Variable)thisIVar;
                if (thisVar.type == sinter_Variable.sinter_IOType.si_DOUBLE)
                {
                    thisVar.dfault = Convert.ToDouble(fields[2]);
                }
                else if (thisVar.type == sinter_Variable.sinter_IOType.si_INTEGER)
                {
                    thisVar.dfault = Convert.ToInt32(fields[2]);
                }
                else if (thisVar.type == sinter_Variable.sinter_IOType.si_STRING)
                {
                    thisVar.dfault = Convert.ToString(fields[2]);
                }
            }
            else if (thisIVar.isVec)
            {
                sinter_Vector thisVar = (sinter_Vector)thisIVar;
                if (thisVar.type == sinter_Variable.sinter_IOType.si_DOUBLE_VEC)
                {
                    thisVar.setElementDefault(0, Convert.ToDouble(fields[2]));
                }
                else if (thisVar.type == sinter_Variable.sinter_IOType.si_INTEGER_VEC)
                {
                    thisVar.setElementDefault(0, Convert.ToInt32(fields[2]));
                }
                for (i = 1; i <= thisVar.size - 1; i++)
                {
                    line = inFileStream.ReadLine();
                    n    = line.Split('|');
                    if (n.Length == 0)
                    {
                        return;
                    }
                    for (j = 0; j <= n.Length - 1; j++)
                    {
                        n[j] = n[j].Trim();
                    }
                    if (thisVar.type == sinter_Variable.sinter_IOType.si_DOUBLE_VEC)
                    {
                        thisVar.setElementDefault(i, Convert.ToDouble(n[0]));
                    }
                    else if (thisVar.type == sinter_Variable.sinter_IOType.si_INTEGER_VEC)
                    {
                        thisVar.setElementDefault(i, Convert.ToInt32(n[0]));
                    }
                }
            }
            else if (thisIVar.isTable)
            {
                sinter_Table thisTable = (sinter_Table)thisIVar;
                for (j = 2; j <= fields.Length - 1; j++)
                {
                    sinter_Variable thisVar = (sinter_Variable)thisTable.getElement(0, j - 2);
                    if (thisVar.type == sinter_Variable.sinter_IOType.si_DOUBLE)
                    {
                        thisVar.dfault = Convert.ToDouble(fields[j]);
                    }
                    else if (thisVar.type == sinter_Variable.sinter_IOType.si_INTEGER)
                    {
                        thisVar.dfault = Convert.ToInt32(fields[j]);
                    }
                    else
                    {
                        throw new System.IO.IOException("Cannot apply minimum on " + thisVar.name + ".  Bad type");
                    }
                }
                for (i = 1; i <= thisTable.MNRows; i++)
                {
                    line = inFileStream.ReadLine();
                    n    = line.Split('|');
                    if (n.Length == 0)
                    {
                        return;
                    }
                    for (j = 0; j <= n.Length - 1; j++)
                    {
                        n[j] = n[j].Trim();
                    }
                    for (j = 0; j <= n.Length - 1; j++)
                    {
                        sinter_Variable thisVar = (sinter_Variable)thisTable.getElement(0, j);
                        if (thisVar.type == sinter_Variable.sinter_IOType.si_DOUBLE)
                        {
                            thisVar.dfault = Convert.ToDouble(fields[j]);
                        }
                        else if (thisVar.type == sinter_Variable.sinter_IOType.si_INTEGER)
                        {
                            thisVar.dfault = Convert.ToInt32(fields[j]);
                        }
                        else
                        {
                            throw new System.IO.IOException("Cannot apply maximum on " + thisVar.name + ".  Bad type");
                        }
                    }
                }
            }
            ////////////////////////////////////////////////////////////////
            //Now that we've set all the defaults, make them the basic value
            ////////////////////////////////////////////////////////////////
            thisIVar.resetToDefault();
        }