示例#1
0
 static bool shouldOutputMinMax(sinter_Variable ioobj)
 {
     //Strings don't have min/max, so skip.  Vectors need to have every entry checked
     if (ioobj.type == sinter_Variable.sinter_IOType.si_DOUBLE || ioobj.type == sinter_Variable.sinter_IOType.si_INTEGER)
     {
         if (ioobj.minimum != ioobj.maximum && Convert.ToDouble(ioobj.minimum) != 0.0)  //The default values are 0.0 for both
         {
             return(true);
         }
     }
     else if (ioobj.type == sinter_Variable.sinter_IOType.si_DOUBLE_VEC || ioobj.type == sinter_Variable.sinter_IOType.si_INTEGER_VEC)
     {
         sinter_Vector thisVec       = (sinter_Vector)ioobj;
         bool          hasDifference = false;
         for (int ii = 0; ii < thisVec.size; ++ii)
         {
             if (thisVec.getElementMin(ii) != thisVec.getElementMax(ii) && ((double)thisVec.getElementMin(ii)) != 0)  //The default values are 0.0 for both
             {
                 hasDifference = true;
                 break;
             }
         }
         if (hasDifference)  //JSON should be able to figure out these are arrays.
         {
             return(true);
         }
     }
     return(false);
 }
示例#2
0
        /**
         * The input file to gORUN_XML contains all the output variable to report back
         * named as "ReportVariable."  For arrays you have to request every value in the array.
         **/
        private void writeReportVariable(XmlTextWriter xw, sinter_Variable var)
        {
            string basePath = snipProcessNameFromPath(getSettingWithDefault("ProcessName", ""), var.addressStrings[0]);

            switch (var.type)
            {
            case sinter_Variable.sinter_IOType.si_DOUBLE:
            case sinter_Variable.sinter_IOType.si_INTEGER:
            case sinter_Variable.sinter_IOType.si_STRING:
                xw.WriteStartElement("ReportVariable");
                xw.WriteAttributeString("pathName", basePath);
                xw.WriteEndElement();
                break;

            case sinter_Variable.sinter_IOType.si_DOUBLE_VEC:
            case sinter_Variable.sinter_IOType.si_INTEGER_VEC:
            case sinter_Variable.sinter_IOType.si_STRING_VEC:
                sinter_Vector vec      = (sinter_Vector)var;
                int[]         indicies = vec.get_vectorIndicies(this);
                foreach (int idx in indicies)
                {
                    xw.WriteStartElement("ReportVariable");
                    xw.WriteAttributeString("pathName", addVecIndex(basePath, idx));
                    xw.WriteEndElement();
                }
                break;

            default:
                throw new NotImplementedException(string.Format("Only static types are currently allowed with gPROMS, unknown type: {0}", var.type));
            }
        }
示例#3
0
 //Used to write setting values, would be better to do as a set automatically
 private string getSettingWithDefault(string key, string def)
 {
     if (o_setupFile.Settings.Contains(key))
     {
         sinter_IVariable ivar = (sinter_IVariable)o_setupFile.Settings[key];
         if (sinter_Variable.sinter_IOType.si_STRING == ivar.type)
         {
             sinter_Variable svar = (sinter_Variable)ivar;
             return(svar.Value.ToString());
         }
     }
     return(def);
 }
示例#4
0
        private void writeVarValues(XmlTextWriter xw, sinter_Variable var)
        {
            switch (var.type)
            {
            case sinter_Variable.sinter_IOType.si_DOUBLE:
                xw.WriteElementString("RealValue", var.Value.ToString());
                break;

            case sinter_Variable.sinter_IOType.si_INTEGER:
                xw.WriteElementString("IntegerValue", var.Value.ToString());
                break;

            case sinter_Variable.sinter_IOType.si_STRING:
                xw.WriteElementString("StringValue", var.Value.ToString());
                break;

            case sinter_Variable.sinter_IOType.si_DOUBLE_VEC:
                sinter_Vector dvect = (sinter_Vector)var;
                for (int i = 0; i < dvect.size; ++i)
                {
                    xw.WriteElementString("RealValue", dvect.getElement(i).ToString());
                }
                break;

            case sinter_Variable.sinter_IOType.si_INTEGER_VEC:
                sinter_Vector ivect = (sinter_Vector)var;
                for (int i = 0; i < ivect.size; ++i)
                {
                    xw.WriteElementString("IntegerValue", ivect.getElement(i).ToString());
                }
                break;

            case sinter_Variable.sinter_IOType.si_STRING_VEC:
                sinter_Vector svect = (sinter_Vector)var;
                for (int i = 0; i < svect.size; ++i)
                {
                    xw.WriteElementString("StringValue", svect.getElement(i).ToString());
                }
                break;

            default:
                throw new sinter_SimulationException(String.Format("gPROMS input variable, {0}, does not have a type that is supported by gPROMS sinter.",
                                                                   var.name));
            }
        }
示例#5
0
        public void DataTreeTest()
        {
            String sinterconf              = Properties.Settings.Default.ExcelSinterJson;
            String defaultsfile            = null;
            String infilename              = Properties.Settings.Default.ExcelSinterInputs;
            String outfilename             = Properties.Settings.Default.ExcelSinterOutputs;
            String canonicalOutputFilename = Properties.Settings.Default.ExcelSinterCanonicalOutputs;

            ISimulation           sim   = startupSim(sinterconf, defaultsfile, infilename);
            sinter_InteractiveSim a_sim = (sinter_InteractiveSim)sim; //Only works on Interactive sims

            {
                String nodePath = "height$C$2";

                VariableTreeNode testNode = sim.dataTree.resolveNode(nodePath);
                Assert.IsTrue(nodePath == testNode.path);
                Assert.IsTrue(testNode.name == "C");

                sinter_Variable tmp = new sinter_Variable();
                tmp.init(a_sim, sinter_Variable.sinter_IOType.si_DOUBLE, new String[] { nodePath });

                Assert.IsTrue((double)tmp.dfault == 74);
                Assert.IsTrue(tmp.type == sinter_Variable.sinter_IOType.si_DOUBLE);
            }

            {
                String nodePath = "height$B$2";

                VariableTreeNode testNode = sim.dataTree.resolveNode(nodePath);
                Assert.IsTrue(nodePath == testNode.path);
                Assert.IsTrue(testNode.name == "B");

                sinter_Variable tmp = new sinter_Variable();
                tmp.init(a_sim, sinter_Variable.sinter_IOType.si_STRING, new String[] { nodePath });

                Assert.IsTrue((String)tmp.dfault == "Leek");
                Assert.IsTrue(tmp.type == sinter_Variable.sinter_IOType.si_STRING);
            }
            sim.closeSim();
        }
示例#6
0
        static public Dictionary <String, Object> getDefaultsFromAspen()
        {
            Dictionary <String, Object> outputDict = new Dictionary <String, Object>();

            for (int ii = 1; ii <= stest.setupFile.countIO; ++ii)
            {
                sinter_Variable outputVal = (sinter_Variable)stest.setupFile.getIOByIndex(ii);
                if (outputVal.isInput)
                {
                    string varname = outputVal.name;
                    outputDict.Add(varname, outputVal.Value);
                    try
                    {
                        Console.WriteLine(outputVal.Value);   //DELETE, just debugging output
                    }
                    catch
                    {
                        Console.WriteLine("Something went wrong with the outputfile....");
                    }
                }
            }
            return(outputDict);
        }
示例#7
0
 public VariableViewModel(sinter_Variable variable)
 {
     o_variable = variable;
 }