Exemplo n.º 1
0
        public void AddDA_variable(SmOutput.OutputType outputType, string nodeOrOutlet, string toNode, string name, string additionalParams)
        {
            if (DA_Points == null)
            {
                DA_Points = new List <EnsembleValuesForPoint>();
                E         = DenseMatrix.Create(models[0].state.values.Length, models.Length, 0);
                //Updater = new EnKFsmartInflation();
                Updater = new EnKF();
            }

            EnsembleValuesForPoint DApoint;

            switch (outputType)
            {
            case SmOutput.OutputType.outletFlowTimeSeries:
            case SmOutput.OutputType.nodeWaterLevel:
                DApoint = new EnsembleValuesForPoint(models, outputType, nodeOrOutlet, additionalParams);
                break;

            default:
                throw new NotImplementedException();
            }
            DA_Points.Add(DApoint);
            p_DA_obs++;
        }
Exemplo n.º 2
0
      public bool addOutputVariable(string nodeName, SmOutput.OutputType type)
      {
          bool bsuccess = false;

          if (type != SmOutput.OutputType.nodeVolume)
          {
              throw new Exception("Unsupported output type for node " + nodeName);
          }

          foreach (Node _node in nodes)
          {
              if (_node.name == nodeName)
              {
                  SmOutput xout = new SmOutput();
                  xout.type  = SmOutput.OutputType.nodeVolume;
                  xout.name  = "Volume in " + nodeName;
                  xout.nodex = _node;

                  output.addNewDataSeries(xout);
                  bsuccess = true;
              }
          }

          if (!bsuccess)
          {
              throw new Exception("could not find output variable " + nodeName);
          }

          return(bsuccess);
      }
Exemplo n.º 3
0
        //to make it easy to interface from matlab etc.
        public bool Mat_AddOutputVariable(SmOutput.OutputType hydraulicType, string name, bool mean, bool std, bool min, bool max, bool median)
        {
            EnsembleStatistics stats = new EnsembleStatistics();

            stats.SetStats(mean, std, min, max, median);
            AddOutputVariable(hydraulicType, stats, name);
            return(true);
        }
Exemplo n.º 4
0
        public EnsembleValuesForPoint(MainModel[] models, SmOutput.OutputType type, string name, string additionalParams)
        {
            Models = models;
            Values = new double[Models.Length];
            _type  = type;
            switch (_type)
            {
            case SmOutput.OutputType.linkFlowTimeSeries:
                throw new NotImplementedException();
                for (int i = 0; i < Models.Length; i++)
                {
                    //cons[i] = models[i].get
                }
                break;

            case SmOutput.OutputType.nodeVolume:
                nodex = Models[0].getNode(name);
                break;

            case SmOutput.OutputType.nodeWaterLevel:
                nodex    = Models[0].getNode(name);
                _type    = SmOutput.OutputType.nodeWaterLevel;
                _derived = new DerivedValue(additionalParams);

                break;

            case SmOutput.OutputType.outletFlowTimeSeries:

                outlets = new Outlet[Models.Length];

                int outletIndexInNodeArray = int.MaxValue;
                foreach (int i in Models[0].iOutlets)
                {
                    if (Models[0].Nodes[i].name == name)
                    {
                        outletIndexInNodeArray = i;
                    }
                }
                if (outletIndexInNodeArray == int.MaxValue)
                {
                    throw new Exception("could not find outlet");
                }

                for (int i = 0; i < Models.Length; i++)
                {
                    outlets[i] = (Outlet)models[i].Nodes[outletIndexInNodeArray];
                }

                break;

            default:
                break;
            }
        }
Exemplo n.º 5
0
      public bool addOutputVariable(SmOutput.OutputType type)
      {
          bool bsuccess = false;

          SmOutput xout = new SmOutput();

          xout.type = type;
          xout.name = type.ToString();
          output.addNewDataSeries(xout);
          bsuccess = true;
          return(bsuccess);
      }
Exemplo n.º 6
0
        public bool AddOutputVariable(SmOutput.OutputType hydraulicType, EnsembleStatistics stats, string name)
        {
            EnsOutput xouts = new EnsOutput(stats);

            xouts.name          = name;
            xouts.hydraulicType = hydraulicType;
            MainModel model = models[0];

            switch (hydraulicType)
            {
            case SmOutput.OutputType.linkFlowTimeSeries:
                break;

            case SmOutput.OutputType.nodeVolume:
                xouts.nodex = models[0].getNode(name);
                break;

            case SmOutput.OutputType.GlobalVolumen:
                break;

            case SmOutput.OutputType.outletFlowTimeSeries:

                bool bsuccess = false;
                foreach (int i in model.iOutlets)
                {
                    if (model.Nodes[i].name == name)
                    {
                        xouts.outletx = new Outlet[models.Length];


                        for (int j = 0; j < models.Length; j++)
                        {
                            xouts.outletx[j] = (Outlet)models[j].Nodes[i];
                        }
                        bsuccess = true;
                    }
                }
                if (!bsuccess)
                {
                    throw new Exception("could not find output variable " + name);
                }
                break;

            default:
                break;
            }

            outputCollection.addNewDataSeries(xouts);
            return(true);
        }
Exemplo n.º 7
0
        public bool Mat_AddOutputVariableLinkFlow(string fromNode, string toNode, string name, bool mean, bool std, bool min, bool max, bool median)
        {
            SmOutput.OutputType hydraulicType = SmOutput.OutputType.linkFlowTimeSeries;
            EnsembleStatistics  stats         = new EnsembleStatistics();

            stats.SetStats(mean, std, min, max, median);
            EnsOutput xouts = new EnsOutput(stats);

            xouts.name          = name;
            xouts.hydraulicType = hydraulicType;
            MainModel         model = models[0];
            List <Connection> cons  = model.getConnections();
            int fromIndex           = model.getNode(fromNode).index;
            int toIndex             = model.getNode(toNode).index;

            bool bsuccess = false;

            for (int i = 0; i < cons.Count; i++)
            {
                if (cons[i].from == fromIndex && cons[i].to == toIndex)
                {
                    SmOutput xout = new SmOutput();
                    xout.name = name;
                    xouts.con = new Connection[models.Length];


                    for (int j = 0; j < models.Length; j++)
                    {
                        xouts.con[j] = models[j].Connections[i];
                    }
                }

                bsuccess = true;
            }
            if (!bsuccess)
            {
                throw new Exception("could not find output variable " + name);
            }

            outputCollection.addNewDataSeries(xouts);
            return(true);
        }
Exemplo n.º 8
0
        private void AddEnsembleOutputFromParameterTable(string[,] paramTable, int ix)
        {
            bool[] ensStats = new bool[5];

            for (int i = ix; i < paramTable.Length; i++)
            {
                if (paramTable[i, 0] == "[EndSect]")
                {
                    return;
                }
                if (paramTable[i, 0] == "<Stats>")
                {
                    string[] split = paramTable[i, 1].Split(new Char[] { ' ', '\t', '=', ',', '(', ')', ';' }, StringSplitOptions.RemoveEmptyEntries);
                    ensStats = new bool[split.Length];
                    for (int j = 0; j < split.Length; j++)
                    {
                        ensStats[j] = (split[j] == "1");
                    }
                }
                if (paramTable[i, 0] == "<output>")
                {
                    switch (paramTable[i, 1])
                    {
                    case "Flow":
                        Mat_AddOutputVariableLinkFlow(paramTable[i, 2], paramTable[i, 3], paramTable[i, 4], ensStats[0], ensStats[1], ensStats[2], ensStats[3], ensStats[4]);
                        break;

                    case "Vol":
                        Mat_AddOutputVariable(SmOutput.OutputType.nodeVolume, paramTable[i, 2], ensStats[0], ensStats[1], ensStats[2], ensStats[3], ensStats[4]);
                        break;

                    case "outletFlow":
                        Mat_AddOutputVariable(SmOutput.OutputType.outletFlowTimeSeries, paramTable[i, 2], ensStats[0], ensStats[1], ensStats[2], ensStats[3], ensStats[4]);
                        break;

                    case "GlobalVolume":
                        // addOutputVariable(SmOutput.OutputType.GlobalVolumen);
                        throw new NotImplementedException("Unknown connection type: " + paramTable[i, 1]);
                        break;

                    case "NodeWL":
                        SmOutput.OutputType hydraulicType = SmOutput.OutputType.nodeWaterLevel;
                        EnsembleStatistics  stats         = new EnsembleStatistics();
                        stats.SetStats(ensStats[0], ensStats[1], ensStats[2], ensStats[3], ensStats[4]);
                        EnsOutput xouts = new EnsOutput(stats);
                        xouts.name          = paramTable[i, 4];
                        xouts.hydraulicType = hydraulicType;
                        MainModel model = models[0];
                        xouts.nodex   = model.getNode((paramTable[i, 2]));
                        xouts.derived = new DerivedValue(paramTable[i, 5]);

                        for (int j = 0; j < models.Length; j++)
                        {
                            SmOutput xout = new SmOutput();
                            xout.name = paramTable[i, 4];
                        }
                        outputCollection.addNewDataSeries(xouts);
                        break;

                    default:
                        throw new NotImplementedException("Unknown connection type: " + paramTable[i, 1]);
                    }
                }
            }
        }
Exemplo n.º 9
0
        private void CollectOutputData()
        {
            outputCollection.timeInSeconds.Add(models[0].t);
            foreach (EnsOutput ensOut in outputCollection.hydraulicOutput)
            {
                SmOutput.OutputType hydraulicType = ensOut.hydraulicType;

                double[] ensValues = new double[m_ensembleMembers];

                switch (hydraulicType)
                {
                case SmOutput.OutputType.linkFlowTimeSeries:
                    for (int i = 0; i < m_ensembleMembers; i++)
                    {
                        ensValues[i] = ensOut.con[i].retrieveMeanFlow();
                    }
                    break;

                case SmOutput.OutputType.nodeVolume:
                    for (int i = 0; i < m_ensembleMembers; i++)
                    {
                        ensValues[i] = models[i].state.values[ensOut.nodex.index];
                    }
                    break;

                case SmOutput.OutputType.GlobalVolumen:

                    for (int i = 0; i < m_ensembleMembers; i++)
                    {
                        ensValues[i] = models[i].state.values.Sum();
                    }

                    break;

                case SmOutput.OutputType.outletFlowTimeSeries:
                    for (int i = 0; i < m_ensembleMembers; i++)
                    {
                        ensValues[i] = ensOut.outletx[i].flow;
                    }

                    break;

                case SmOutput.OutputType.nodeWaterLevel:
                    try
                    {
                        for (int i = 0; i < m_ensembleMembers; i++)
                        {
                            ensValues[i] = ensOut.derived.calculate(models[i].state.values[ensOut.nodex.index]);
                        }
                    }
                    catch (Exception e)
                    {
                        throw new Exception("Error collecting derived WL output for node " + ensOut.name + ": " + e.Message);
                    }

                    break;

                default:
                    break;
                }


                int j = 0;
                foreach (SmOutput.StatType statType in ensOut.stats.types)
                {
                    switch (statType)
                    {
                    case SmOutput.StatType.deterministic:
                        throw new Exception("Error collecting output");
                        break;

                    case SmOutput.StatType.mean:
                        ensOut.dataSeries[j].updateData(ensValues.Average());
                        break;

                    case SmOutput.StatType.std:
                        double average = ensValues.Average();
                        double sumOfSquaresOfDifferences = ensValues.Select(val => (val - average) * (val - average)).Sum();
                        double std = Math.Sqrt(sumOfSquaresOfDifferences / ensValues.Length);
                        ensOut.dataSeries[j].updateData(std);
                        break;

                    case SmOutput.StatType.min:
                        ensOut.dataSeries[j].updateData(ensValues.Min());
                        break;

                    case SmOutput.StatType.max:
                        ensOut.dataSeries[j].updateData(ensValues.Max());
                        break;

                    case SmOutput.StatType.median:
                        ensOut.dataSeries[j].updateData(ensValues.Median());
                        break;

                    case SmOutput.StatType.accumulated:
                        throw new Exception("Error collecting output");
                        break;

                    default:
                        throw new Exception("Error collecting output");
                        break;
                    }
                    j++;
                }
            }
        }