/// <summary>
        /// Do measurements which depend on plant.
        ///
        /// used by Norg, TKN, Ntot sensors.
        ///
        /// 5th type
        ///
        /// example sensor:
        /// at the end called by biogas_chp_plant
        /// d.h.: energyProduction_sensor
        /// </summary>
        /// <param name="time">current simulation time</param>
        /// <param name="id">id of sensor</param>
        /// <param name="myPlant"></param>
        /// <param name="u">could be biogas stream or state vector</param>
        /// <exception cref="exception">Unknown sensor id</exception>
        public void measure(double time, string id, //double deltatime,
                            biogas.plant myPlant, double[] u)
        {
            double value;

            measure(time, id, myPlant, u, out value);
        }
        /// <summary>
        /// Do measurements which depend on plant.
        ///
        /// 4th type
        ///
        /// example sensor:
        /// used by pumpEnergy_sensor
        /// </summary>
        /// <param name="time">current simulation time</param>
        /// <param name="id">id of sensor</param>
        /// <param name="myPlant"></param>
        /// <param name="u">could be biogas stream or state vector</param>
        /// <param name="par">some doubles</param>
        /// <param name="value">first measured value</param>
        /// <exception cref="exception">Unknown sensor id</exception>
        public void measure(double time, string id, //double deltatime,
                            biogas.plant myPlant, double u, double[] par, out double value)
        {
            physValue[] vals = measureVec(time, id, myPlant, u, par);

            value = vals[0].Value;
        }
        // -------------------------------------------------------------------------------------
        //                              !!! PRIVATE METHODS !!!
        // -------------------------------------------------------------------------------------

        /// <summary>
        /// Calculates the volumeflow of each substrate going into the given digester digester_id.
        /// The substrate flows are returned as a vector.
        ///
        /// TODO: ist nicht mehr private
        /// </summary>
        /// <param name="t">current simulation time</param>
        /// <param name="mySubstrates"></param>
        /// <param name="myPlant"></param>
        /// <param name="mySensors"></param>
        /// <param name="substrate_network"></param>
        /// <param name="digester_id">id of the digester which is fed</param>
        /// <returns>
        /// always a vector with as many elements as there are substrates on the plant
        /// </returns>
        public static physValue[] getSubstrateMixFlowForFermenter(double t, biogas.substrates mySubstrates,
                                                                  biogas.plant myPlant, sensors mySensors, double[,] substrate_network,
                                                                  string digester_id)
        {
            int digester_index = myPlant.getDigesterIndex(digester_id) - 1;

            // get recorded substrate feeds in m³/d
            physValue[] Q = mySensors.getMeasurementsAt("Q", "Q", t, mySubstrates);

            // make the sum over the 2nd dimension, the digesters
            double[] norm_vec = math.sum(substrate_network, 1);

            double[] substrate_digester = new double[substrate_network.GetLength(0)];

            for (int isubstrate = 0; isubstrate < substrate_network.GetLength(0); isubstrate++)
            {
                // what is if norm_vec is 0 for an element
                // then we have 0/0.
                if (norm_vec[isubstrate] != 0)
                {
                    substrate_digester[isubstrate] =
                        substrate_network[isubstrate, digester_index] /
                        norm_vec[isubstrate];
                }
                else
                {
                    substrate_digester[isubstrate] = 0;
                }
            }

            // this is the amount of each substrate going into the given digester
            Q = physValue.times(Q, substrate_digester);

            return(Q);
        }
Exemple #4
0
        /// <summary>
        /// Do measurements which depend on fitness_params.
        ///
        /// 8th type
        ///
        /// example sensor:
        /// used by all fitness sensors
        /// </summary>
        /// <param name="time">current simulation time</param>
        /// <param name="id">id of sensor</param>
        /// <param name="myPlant"></param>
        /// <param name="myFitnessParams"></param>
        /// <param name="par">some doubles</param>
        /// <param name="value">first measured value</param>
        /// <exception cref="exception">Unknown sensor id</exception>
        public void measure(double time, string id, biogas.plant myPlant, //double deltatime,
                            biooptim.fitness_params myFitnessParams, double[] par, out double value)
        {
            physValue[] vals = measureVec(time, id, myPlant, myFitnessParams, par);

            value = vals[0].Value;
        }
        /// <summary>
        /// Do measurements which depend on plant.
        ///
        /// 4th type
        ///
        /// example sensor:
        /// used by pumpEnergy_sensor
        /// </summary>
        /// <param name="time">current simulation time</param>
        /// <param name="id">id of sensor</param>
        /// <param name="myPlant"></param>
        /// <param name="u">could be biogas stream or state vector</param>
        /// <param name="par">some doubles</param>
        /// <returns>measured values</returns>
        /// <exception cref="exception">Unknown sensor id</exception>
        public physValue[] measureVec(double time, string id, //double deltatime,
                                      biogas.plant myPlant, double u, params double[] par)
        {
            sensor mySensor = get(id);

            return(mySensor.measure(time, sampling_time, myPlant, u, par));
        }
Exemple #6
0
        /// <summary>
        /// Calc mix of substrates for all digesters
        ///
        /// TODO: s. auch in funktion unten
        /// </summary>
        /// <param name="t">current simulation time in days</param>
        /// <param name="mySubstrates"></param>
        /// <param name="myPlant"></param>
        /// <param name="substrate_network"></param>
        /// <param name="mySensors"></param>
        /// <param name="Q">only used if datasource_type == extern</param>
        /// <param name="dilution_rates">double vector with the wanted dilution rates for each digester.
        /// Could be given by a dilution rate control. The size of the vector must
        /// be equal to number of digesters.</param>
        /// <returns>[34dim stream for digester1; 34dim stream for digester2; ...]</returns>
        public static double[] calcADMstreamMix(double t, biogas.substrates mySubstrates,
                                                biogas.plant myPlant, double[,] substrate_network,
                                                biogas.sensors mySensors, double[] Q, //double deltatime,
                                                double[] dilution_rates)
        {
            double[,] myStreams = new double[biogas.ADMstate._dim_stream, myPlant.getNumDigesters()];

            for (int idigester = 0; idigester < myPlant.getNumDigesters(); idigester++)
            {
                double Vliq = myPlant.getDigesterParam(idigester + 1, "Vliq");

                // D ist < 0, wenn Anlage nicht geregelt wird
                double D = dilution_rates[idigester];

                double Q_new = D * Vliq;

                myStreams = math.insertColumn(myStreams,
                                              calcADMstreamMixForDigester(t, mySubstrates, substrate_network, mySensors,
                                                                          idigester, Q, Q_new),
                                              0, idigester);

                // measure energy needed to transport substrates
                biogas.substrate_transport.run(t, mySensors,
                                               "substratemix", myPlant.getDigesterID(idigester + 1), myPlant, mySubstrates,
                                               substrate_network);
            }

            double[] myStream = math.concat(myStreams);

            return(myStream);
        }
Exemple #7
0
        /// <summary>
        /// Do measurements which depend on fitness_params.
        ///
        /// 8th type
        ///
        /// example sensor:
        /// used by all fitness sensors
        /// </summary>
        /// <param name="time">current simulation time</param>
        /// <param name="id">id of sensor</param>
        /// <param name="myPlant"></param>
        /// <param name="myFitnessParams"></param>
        /// <param name="par">some doubles</param>
        /// <returns>measured values</returns>
        /// <exception cref="exception">Unknown sensor id</exception>
        public physValue[] measureVec(double time, string id, biogas.plant myPlant, //double deltatime,
                                      biooptim.fitness_params myFitnessParams, params double[] par)
        {
            sensor mySensor = get(id);

            return(mySensor.measure(time, sampling_time, myPlant, myFitnessParams, this, par));
        }
        /// <summary>
        /// Do measurements which depend on plant.
        ///
        /// used by Norg, TKN, Ntot sensors.
        ///
        /// 5th type
        ///
        /// example sensor:
        /// at the end called by biogas_chp_plant
        /// d.h.: energyProduction_sensor
        ///
        /// called by chps.run(), former biogas2bhkw
        /// </summary>
        /// <param name="time">current simulation time</param>
        /// <param name="id">id of sensor</param>
        /// <param name="myPlant"></param>
        /// <param name="u">could be biogas stream or state vector</param>
        /// <param name="param">some string</param>
        /// <param name="values">measured valuse</param>
        /// <exception cref="exception">Unknown sensor id</exception>
        public void measureVec(double time, string id, //double deltatime,
                               biogas.plant myPlant, double[] u, string param, out double[] values)
        {
            physValue[] vals = measureVec(time, id, myPlant, u, param);

            values = physValue.getValues(vals);
        }
Exemple #9
0
        /// <summary>
        /// calculates ADMstream mix of substrates for each digester
        /// and measures in the mix of all digesters together the COD SS and VS
        /// content.
        /// </summary>
        /// <param name="t">current simulation time in days</param>
        /// <param name="mySubstrates"></param>
        /// <param name="myPlant"></param>
        /// <param name="substrate_network"></param>
        /// <param name="mySensors"></param>
        /// <param name="dilution_rates">double vector with the wanted dilution rates for each digester.
        /// Could be given by a dilution rate control. The size of the vector must
        /// be equal to number of digesters.</param>
        /// <returns></returns>
        public static double[] calc_measureADMstreamMix(double t, biogas.substrates mySubstrates,
                                                        biogas.plant myPlant, double[,] substrate_network,
                                                        biogas.sensors mySensors, //double deltatime,
                                                        double[] dilution_rates)
        {
            double[] mystream = calcADMstreamMix(t, mySubstrates, myPlant, substrate_network,
                                                 mySensors, dilution_rates);

            //

            double[] mixed_stream = mixADMstreams(mystream);

            // measure COD SS and VS of mixed stream

            // TODO : evtl. von total_mix in substratemix umbenennen
            // muss dann auch überall anders gemacht werden. bsp: objectives und
            // sensors: create_sensor_network

            mySensors.measure(t, "SS_COD_total_mix_2", mixed_stream);

            mySensors.measure(t, "VS_COD_total_mix_2", mixed_stream);

            mySensors.measure(t, "Q_total_mix_2", mixed_stream);

            // messe VS in Substratzufuhr
            mySensors.measure(t, "VS_total_mix_2", mixed_stream, mySubstrates);

            return(mystream);
        }
        /// <summary>
        /// Do measurements which depend on plant.
        ///
        /// used by Norg, TKN, Ntot sensors.
        ///
        /// 5th type
        ///
        /// example sensor:
        /// at the end called by biogas_chp_plant
        /// d.h.: energyProduction_sensor
        /// </summary>
        /// <param name="time">current simulation time</param>
        /// <param name="id">id of sensor</param>
        /// <param name="myPlant"></param>
        /// <param name="u">could be biogas stream or state vector</param>
        /// <param name="values">measured values</param>
        /// <exception cref="exception">Unknown sensor id</exception>
        public void measureVec(double time, string id, //double deltatime,
                               biogas.plant myPlant, double[] u, out double[] values)
        {
            string param = "";

            measureVec(time, id, myPlant, u, param, out values);
        }
Exemple #11
0
 /// <summary>
 /// called by TS sensor, OLR sensor, density sensor and heatConsumption_sensor
 ///
 /// type 7
 /// </summary>
 /// <param name="x">stream vector</param>
 /// <param name="myPlant"></param>
 /// <param name="mySubstrates"></param>
 /// <param name="mySensors"></param>
 /// <param name="Q">substrate feed and recirculation sludge going into the digester</param>
 /// <param name="par">some doubles</param>
 /// <returns>measured values</returns>
 /// <exception cref="exception">Not implemented</exception>
 virtual protected physValue[] doMeasurement(double[] x, biogas.plant myPlant,
                                             biogas.substrates mySubstrates,
                                             biogas.sensors mySensors,
                                             double[] Q, params double[] par)
 {
     throw new exception("Not implemented!");
 }
Exemple #12
0
        // -------------------------------------------------------------------------------------
        //                              !!! CONSTRUCTOR METHODS !!!
        // -------------------------------------------------------------------------------------



        // -------------------------------------------------------------------------------------
        //                              !!! PUBLIC METHODS !!!
        // -------------------------------------------------------------------------------------

        /// <summary>
        /// simulates all chps of the plant
        /// </summary>
        /// <param name="t"></param>
        /// <param name="u">
        /// number of digesters times n_gases dimensional vector
        /// with the biogas streams for each digester measured in m^3/d</param>
        /// <param name="mySensors"></param>
        /// <param name="myPlant"></param>
        /// <returns>
        /// produced electrical power for each chp in kW and the biogas excess in m³/d
        /// dimension: number of digesters + 1
        /// </returns>
        public static double[] run(double t, double[] u, //double deltatime,
                                   biogas.sensors mySensors, biogas.plant myPlant)
        {
            // TODO - Parameter aus plant bekommen
            string gas2chpsplittype = "threshold";

            return(run(t, u, mySensors, myPlant, gas2chpsplittype));
        }
Exemple #13
0
        /// <summary>
        /// Constructor creating the sensors by reading from the given xml file.
        /// </summary>
        /// <param name="XMLfile"></param>
        /// <param name="myPlant"></param>
        public sensors(string XMLfile, biogas.plant myPlant)
        {
            XmlTextReader reader = new System.Xml.XmlTextReader(XMLfile);

            getParamsFromXMLReader(ref reader, myPlant);

            reader.Close();
        }
        /// <summary>
        /// Do measurements which depend on plant and substrates.
        ///
        /// 6th type
        ///
        /// example sensor:
        /// wird von heatConsumption_sensor genutzt
        ///
        /// heatConsumption_sensor benötigt call mit substrate_network,
        /// damit getSubstrateMixFlowForFermenter
        /// aufgerufen werden kann, den haben wir direkt hier drüber
        /// </summary>
        /// <param name="time">current simulation time</param>
        /// <param name="id">id of sensor</param>
        /// <param name="myPlant"></param>
        /// <param name="mySubstrates"></param>
        /// <param name="values">measured values</param>
        /// <exception cref="exception">Unknown sensor id</exception>
        public void measureVec(double time, string id, //double deltatime,
                               biogas.plant myPlant, biogas.substrates mySubstrates,
                               out double[] values)
        {
            physValue[] vals = measureVec(time, id, myPlant, mySubstrates);

            values = physValue.getValues(vals);
        }
        /// <summary>
        /// Do measurements which depend on plant.
        ///
        /// used by Norg, TKN, Ntot sensors.
        ///
        /// 5th type
        ///
        /// example sensor:
        /// at the end called by biogas_chp_plant
        /// d.h.: energyProduction_sensor
        /// </summary>
        /// <param name="time">current simulation time</param>
        /// <param name="id">id of sensor</param>
        /// <param name="myPlant"></param>
        /// <param name="u">could be biogas stream or state vector</param>
        /// <param name="param">some string</param>
        /// <returns>measured values</returns>
        /// <exception cref="exception">Unknown sensor id</exception>
        public physValue[] measureVec(double time, string id, //double deltatime,
                                      biogas.plant myPlant,
                                      double[] u, string param)
        {
            double[] par = new double[1];

            return(measureVec(time, id, myPlant, u, param, par));
        }
        /// <summary>
        /// Do measurements which depend on plant.
        ///
        /// used by Norg, TKN, Ntot sensors.
        ///
        /// 5th type
        ///
        /// example sensor:
        /// at the end called by biogas_chp_plant
        /// d.h.: energyProduction_sensor
        /// </summary>
        /// <param name="time">current simulation time</param>
        /// <param name="id">id of sensor</param>
        /// <param name="myPlant"></param>
        /// <param name="u">could be biogas stream or state vector</param>
        /// <param name="value">measured value</param>
        /// <exception cref="exception">Unknown sensor id</exception>
        public void measure(double time, string id, //double deltatime,
                            biogas.plant myPlant, double[] u, out double value)
        {
            double[] vals;

            measureVec(time, id, myPlant, u, out vals);

            value = vals[0];
        }
        /// <summary>
        /// Do measurements which depend on plant and substrates.
        ///
        /// 6th type
        ///
        /// example sensor:
        /// wird von heatConsumption_sensor genutzt
        /// </summary>
        /// <param name="time">current simulation time</param>
        /// <param name="id">id of sensor</param>
        /// <param name="myPlant"></param>
        /// <param name="mySubstrates"></param>
        /// <param name="Q">zufuhr aller substrate in anlage, nicht in fermenter
        /// TODO: es wäre vermutlich besser wenn es nur in fermenter wäre,
        /// da heatConsumption_sensor am fermenter angebracht ist</param>
        /// <returns>measured values</returns>
        /// <exception cref="exception">Unknown sensor id</exception>
        public physValue[] measureVec(double time, string id, //double deltatime,
                                      biogas.plant myPlant, biogas.substrates mySubstrates,
                                      double[] Q)
        {
            double[] par = new double[1];

            return(measureVec(time, id, myPlant, mySubstrates,
                              Q, par));
        }
Exemple #18
0
        /// <summary>
        /// Do measurements which depend on plant and substrates and other measurements.
        ///
        /// 7th type
        ///
        /// example sensors:
        /// called by TS sensor
        /// OLR_sensor
        /// density_sensor
        /// </summary>
        /// <param name="time">current simulation time</param>
        /// <param name="id">id of sensor</param>
        /// <param name="x">could be statevector</param>
        /// <param name="myPlant"></param>
        /// <param name="mySubstrates"></param>
        /// <param name="mySensors"></param>
        /// <param name="Q">
        /// first values are Q for substrates, then pumped sludge going into digester
        /// </param>
        /// <param name="par">some doubles</param>
        /// <returns>measured values</returns>
        /// <exception cref="exception">Unknown sensor id</exception>
        public physValue[] measureVec(double time, string id, //double deltatime,
                                      double[] x, biogas.plant myPlant, biogas.substrates mySubstrates,
                                      biogas.sensors mySensors,
                                      double[] Q, params double[] par)
        {
            sensor mySensor = get(id);

            return(mySensor.measure(time, sampling_time, x, myPlant, mySubstrates, mySensors, Q, par));
        }
Exemple #19
0
        // -------------------------------------------------------------------------------------
        //                              !!! PUBLIC METHODS !!!
        // -------------------------------------------------------------------------------------

        /// <summary>
        /// Do measurements which depend on plant and substrates and other measurements.
        ///
        /// 7th type
        ///
        /// example sensors:
        /// called by TS sensor
        /// OLR_sensor
        /// density_sensor
        /// </summary>
        /// <param name="time">current simulation time</param>
        /// <param name="id">id of sensor</param>
        /// <param name="x">could be statevector</param>
        /// <param name="myPlant"></param>
        /// <param name="mySubstrates"></param>
        /// <param name="mySensors"></param>
        /// <param name="Q">could be substrate feed</param>
        /// <param name="value">first measured value</param>
        /// <exception cref="exception">Unknown sensor id</exception>
        public void measure(double time, string id, //double deltatime,
                            double[] x, biogas.plant myPlant, biogas.substrates mySubstrates,
                            biogas.sensors mySensors,
                            double[] Q, out double value)
        {
            physValue[] vals = measureVec(time, id, x, myPlant, mySubstrates, mySensors, Q);

            value = vals[0].Value;
        }
Exemple #20
0
        /// <summary>
        /// TODO
        /// </summary>
        /// <param name="t">current simulation time in days</param>
        /// <param name="mySensors"></param>
        /// <param name="u">stream going into the pump measured in m^3/d</param>
        /// <param name="Q_pump">to be pumped amount in m^3/d</param>
        /// <param name="unit_start"></param>
        /// <param name="unit_destiny"></param>
        /// <param name="myPlant"></param>
        /// <returns></returns>
        public static double run(double t, //double deltatime,
                                 biogas.sensors mySensors, double u, double Q_pump,
                                 string unit_start, string unit_destiny,
                                 biogas.plant myPlant /*, biogas.substrates mySubstrates,
                                                       * double[,] substrate_network*/)
        {
            string pump_id = getid(unit_start, unit_destiny);

            // determine rho - default value for digester or storagetank
            //physValue density = new physValue("rho", 1000, "kg/m^3", "density");

            if (unit_start == "substratemix")
            {
                throw new exception("pumps may not pump the substratemix");

                // get mean rho out of substrates and double[] Q
                // nutze hier getSubstrateMixFlowForFermenter

                //double[] Q;

                // TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                // id_in_array einführen und durch "Q" ersetzen
                // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                //mySensors.getCurrentMeasurements("Q", "Q", mySubstrates, out Q);
                //getMeasurementsAt("Q", "Q", time, mySubstrates, out Q);

                // unit_destiny here must be a digester_id, because you cannot
                // pump substratemix directly into final storage tank
                //physValue[] Q_digester =
                //  sensors.getSubstrateMixFlowForFermenter(t, mySubstrates, myPlant,
                //                          mySensors, substrate_network, unit_destiny);

                //// values are Q for all substrates
                //double[] Q = physValue.getValues(Q_digester);

                //mySubstrates.get_weighted_mean_of(Q, "rho", out density);
            }


            // measure energy needed to pump stuff

            double P_kWh_d;

            // es ist wichtig, dass hier rho nicht mit übergeben wird
            // wird genutzt als erkennungsmerkmal in pumpEnergy_sensor
            // im unterschied zu substrate_transport
            double[] parvec = { Q_pump };//, density.Value };

            mySensors.measure(t, "pumpEnergy_" + pump_id,
                              myPlant, u, parvec, out P_kWh_d);

            // TODO - DEFINE WHAT SHOULD be returned
            //double[] retvals = { P_kWh_d, Q_pump };

            return(P_kWh_d);// retvals;
        }
        /// <summary>
        /// Call measure of all type 8 sensors
        ///
        /// type 8
        ///
        /// used by fitness sensors
        /// </summary>
        /// <param name="time">current simulation time in days</param>
        /// <param name="myPlant"></param>
        /// <param name="myFitnessParams"></param>
        /// <param name="par"></param>
        public void measure_type8(double time, //double deltatime,
                                  biogas.plant myPlant, biooptim.fitness_params myFitnessParams, double par)
        {
            double value;

            foreach (string id in ids_type8)
            {
                measure(time, id, myPlant, myFitnessParams, par, out value);
            }
        }
Exemple #22
0
        // -------------------------------------------------------------------------------------
        //                              !!! PUBLIC METHODS !!!
        // -------------------------------------------------------------------------------------

        /// <summary>
        /// TODO
        /// </summary>
        /// <param name="t">current simulation time in days</param>
        /// <param name="mySensors"></param>
        /// <param name="unit_start"></param>
        /// <param name="unit_destiny"></param>
        /// <param name="myPlant"></param>
        /// <param name="mySubstrates"></param>
        /// <param name="substrate_network"></param>
        /// <returns></returns>
        public static double run(double t, //double deltatime,
                                 biogas.sensors mySensors,
                                 string unit_start, string unit_destiny,
                                 biogas.plant myPlant, biogas.substrates mySubstrates,
                                 double[,] substrate_network)
        {
            double Q_pump, Q_solids;

            return(run(t, mySensors, unit_start, unit_destiny,
                       myPlant, mySubstrates, substrate_network, out Q_pump, out Q_solids));
        }
Exemple #23
0
        // -------------------------------------------------------------------------------------
        //                              !!! PRIVATE METHODS !!!
        // -------------------------------------------------------------------------------------

        /// <summary>
        /// Calc loss in €/d due to in excess produced biogas
        /// </summary>
        /// <param name="biogas_v">measured biogas vector gotten out of sensors</param>
        /// <param name="substrate_costs">costs for substrates in [€/d]</param>
        /// <param name="myPlant"></param>
        /// <param name="myFitnessParams"></param>
        /// <param name="biogasExcess">in excess produced biogas [m^3/d]</param>
        /// <returns></returns>
        private static double calcLossDueToBiogasExcess(physValue[] biogas_v, double substrate_costs,
                                                        biogas.plant myPlant, biooptim.fitness_params myFitnessParams, out double biogasExcess)
        {
            double H2Concentration      = biogas_v[1].Value; // ppm
            double methaneConcentration = biogas_v[2].Value; // %
            double CO2Concentration     = biogas_v[3].Value; // %

            // in excess produced biogas in [m^3/d]
            biogasExcess = biogas_v[biogas_v.Length - 1].Value;

            //

            double[] u = new double[3];

            // biogas excess in m³/d
            u[0] = biogasExcess * H2Concentration / 1000000;
            u[1] = biogasExcess * methaneConcentration / 100;
            u[2] = biogasExcess * CO2Concentration / 100;


            // €/d : get monetary value of in excess produced biogas. which amount of
            // money would we earn when we had sell the energy produced by the in excess
            // produced biogas?
            double valueMethaneExcess = calcValueOfMethaneExcess(u, myPlant, myFitnessParams);


            // m³/d : total biogas production
            double total_biogas_prod = biogas_v[0].Value;


            // costs of substrates needed to produce the excess methane amount in €/d
            double substrateCostsMethaneExcess =
                calcSubstrateCostsForMethaneExcess(biogasExcess, methaneConcentration,
                                                   substrate_costs, total_biogas_prod);


            // since complete substrate costs are already included in fitness function.
            // therefore we only may add the difference of the value of the methane and
            // the substrate costs needed to produce it. this value is always positive,
            // because methane is more worse then the substates needed to produce it.
            double lossBiogasExcess = valueMethaneExcess - substrateCostsMethaneExcess;

            //

            if (lossBiogasExcess < 0)
            {
                // TODO - throw error
                //error('loss: %f < 0, value: %f, costs: %f', ...
                //lossBiogasExcess, valueMethaneExcess, substrateCostsMethaneExcess);
                //throw new toolbox.exception(String.Format("lossBiogasExcess < 0: {0}", lossBiogasExcess));
            }

            return(lossBiogasExcess);
        }
        /// <summary>
        /// Do measurements which depend on plant and substrates.
        ///
        /// 6th type
        ///
        /// example sensor:
        /// wird von heatConsumption_sensor genutzt
        /// </summary>
        /// <param name="time">current simulation time</param>
        /// <param name="id">id of sensor</param>
        /// <param name="myPlant"></param>
        /// <param name="mySubstrates"></param>
        /// <param name="substrate_network"></param>
        /// <param name="digester_id">ID of digester</param>
        /// <returns>measured values</returns>
        /// <exception cref="exception">Unknown sensor id</exception>
        public physValue[] measureVec(double time, string id, //double deltatime,
                                      biogas.plant myPlant, biogas.substrates mySubstrates,
                                      double[,] substrate_network, string digester_id)
        {
            physValue[] Q_digester = getSubstrateMixFlowForFermenter(time, mySubstrates, myPlant,
                                                                     this, substrate_network, digester_id);

            // values are Q for all substrates
            double[] Q = physValue.getValues(Q_digester);

            return(measureVec(time, id, myPlant, mySubstrates, Q));
        }
Exemple #25
0
        /// <summary>
        /// Do measurements which depend on plant and substrates and other measurements.
        ///
        /// 7th type
        ///
        /// example sensors:
        /// called by TS sensor
        /// OLR_sensor
        /// density_sensor
        /// </summary>
        /// <param name="time">current simulation time</param>
        /// <param name="id">id of sensor</param>
        /// <param name="x">could be statevector</param>
        /// <param name="myPlant"></param>
        /// <param name="mySubstrates"></param>
        /// <param name="mySensors"></param>
        /// <param name="substrate_network"></param>
        /// <param name="plant_network"></param>
        /// <param name="digester_id">digester ID</param>
        /// <param name="value">first measured value</param>
        /// <exception cref="exception">Unknown sensor id</exception>
        public void measure(double time, string id, //double deltatime,
                            double[] x, biogas.plant myPlant, biogas.substrates mySubstrates,
                            biogas.sensors mySensors,
                            double[,] substrate_network, double[,] plant_network,
                            string digester_id, out double value)
        {
            physValue[] vals = measureVec(time, id, x, myPlant,
                                          mySubstrates, mySensors,
                                          substrate_network, plant_network, digester_id);

            value = vals[0].Value;
        }
Exemple #26
0
        /// <summary>
        /// Calc mix of substrates for all digesters
        ///
        /// Q is gotten out of sensor
        /// </summary>
        /// <param name="t">current simulation time in days</param>
        /// <param name="mySubstrates"></param>
        /// <param name="myPlant"></param>
        /// <param name="substrate_network"></param>
        /// <param name="mySensors"></param>
        /// <param name="dilution_rates">double vector with the wanted dilution rates for each digester.
        /// Could be given by a dilution rate control. The size of the vector must
        /// be equal to number of digesters.</param>
        /// <returns>a column vector with dimension equal to dim_stream * n_digester</returns>
        public static double[] calcADMstreamMix(double t, biogas.substrates mySubstrates,
                                                biogas.plant myPlant, double[,] substrate_network,
                                                biogas.sensors mySensors, //double deltatime,
                                                double[] dilution_rates)
        {
            double[] Q;

            mySensors.getMeasurementsAt("Q", "Q", t, mySubstrates, out Q);

            return(calcADMstreamMix(t, mySubstrates, myPlant, substrate_network, mySensors,
                                    Q, dilution_rates));
        }
        /// <summary>
        /// Calculation of total thermal energy consumption
        ///
        /// returns thermal energy consumption of
        /// - heating
        /// - microbiology (production)
        /// - mixer (production)
        ///
        /// in kWh/d
        /// </summary>
        /// <param name="myPlant"></param>
        /// <param name="mySensors"></param>
        /// <param name="energyConsumptionHeat">thermal energy consumption of heat losses [kWh/d]</param>
        /// <param name="energyProdMixer">th. energy prod. of stirrer [kWh/d]</param>
        /// <param name="energyProdMicro">th. energy prod. by micros [kWh/d]</param>
        /// <returns></returns>
        private static double getThermalEnergyConsumption(biogas.plant myPlant, biogas.sensors mySensors,
                                                          out double energyConsumptionHeat,
                                                          out double energyProdMixer, out double energyProdMicro)
        {
            double energyConsumption = 0;

            energyConsumptionHeat = 0;
            energyProdMixer       = 0; // heat energy dissipated to digester in kWh/d
            energyProdMicro       = 0;

            //

            int n_digester = myPlant.getNumDigesters();

            for (int idigester = 0; idigester < n_digester; idigester++)
            {
                string digester_id = myPlant.getDigesterID(idigester + 1);

                biogas.digester myDigester = myPlant.getDigester(idigester + 1);

                // heating

                physValue[] heat_v = mySensors.getCurrentMeasurementVector("heatConsumption_" + digester_id);

                // inflow heating
                // thermal Energie welche benötigt wird um das Substrat aufzuheizen
                // \frac{kWh}{d}
                energyConsumptionHeat += heat_v[0].Value;

                // radiation loss energy
                // thermal Energie, welche die Heizungen benötigen um die
                // Wärmeverluste auszugleichen
                // \frac{kWh}{d}
                energyConsumptionHeat += heat_v[1].Value;

                // produced heat by bacteria in digester [kWh/d]
                // das ist eine thermische, keine elektrische energie
                energyProdMicro += heat_v[2].Value;

                // thermal energy production by stirrer through dissipation
                // \frac{kWh}{d}
                energyProdMixer += heat_v[3].Value;
            }

            // sum in kWh/d
            // Vorsicht: energy von bakterien wird als produktion nicht als verbrauch
            // angesehen, deshalb hier neg. VZ
            energyConsumption = energyConsumptionHeat - energyProdMicro - energyProdMixer;

            return(energyConsumption);
        }
        /// <summary>
        /// Do measurements which depend on plant and substrates.
        ///
        /// 6th type
        ///
        /// example sensor:
        /// wird von heatConsumption_sensor genutzt
        /// </summary>
        /// <param name="time">current simulation time</param>
        /// <param name="id">id of sensor</param>
        /// <param name="myPlant"></param>
        /// <param name="mySubstrates"></param>
        /// <returns>measured values</returns>
        /// <exception cref="exception">Unknown sensor id</exception>
        public physValue[] measureVec(double time, string id, //double deltatime,
                                      biogas.plant myPlant, biogas.substrates mySubstrates)
        {
            double[] Q;

            // TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            // id_in_array einführen und durch "Q" ersetzen
            // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            //getCurrentMeasurements("Q", "Q", mySubstrates, out Q);
            getMeasurementsAt("Q", "Q", time, mySubstrates, out Q);

            return(measureVec(time, id, myPlant, mySubstrates,
                              Q));
        }
Exemple #29
0
        /// <summary>
        /// Do measurements which depend on plant and substrates and other measurements.
        ///
        /// 7th type
        ///
        /// example sensors:
        /// called by TS sensor
        /// OLR_sensor
        /// density_sensor
        /// </summary>
        /// <param name="time">current simulation time</param>
        /// <param name="id">id of sensor</param>
        /// <param name="x">could be statevector</param>
        /// <param name="myPlant"></param>
        /// <param name="mySubstrates"></param>
        /// <param name="mySensors"></param>
        /// <param name="substrate_network"></param>
        /// <param name="plant_network"></param>
        /// <param name="digester_id">ID of digester</param>
        /// <returns>measured values</returns>
        /// <exception cref="exception">Unknown sensor id</exception>
        public physValue[] measureVec(double time, string id, //double deltatime,
                                      double[] x, biogas.plant myPlant, biogas.substrates mySubstrates,
                                      biogas.sensors mySensors,
                                      double[,] substrate_network, double[,] plant_network,
                                      string digester_id)
        {
            physValue[] pQ = getInputVolumeflowForFermenter(time, mySubstrates, myPlant, mySensors,
                                                            substrate_network, plant_network, digester_id);

            // first values are Q for substrates, then pumped sludge going into digester
            double[] Q = physValue.getValues(pQ);

            return(measureVec(time, id, x, myPlant, mySubstrates, mySensors, Q));
        }
        ///// <summary>
        ///// Calculates electrical and thermal energy production in [kWh/d]
        ///// </summary>
        ///// <param name="myPlant"></param>
        ///// <param name="mySensors"></param>
        ///// <param name="energyThermProduction">thermal energy production [kWh/d]</param>
        ///// <returns>electrical energy production [kWh/d]</returns>
        //private static double getEnergyProduction(biogas.plant myPlant, biogas.sensors mySensors,
        //  out double energyThermProduction)
        //{
        //  // Calculation of overall electrical + thermal energy production

        //  double energyProduction= 0;

        //  energyThermProduction= 0;

        //  for (int ibhkw= 0; ibhkw < myPlant.getNumCHPs(); ibhkw++)
        //  {
        //    string bhkw_id= myPlant.getCHPID(ibhkw + 1);

        //    // electrical energy production

        //    physValue[] energy_v= mySensors.getCurrentMeasurementVector("energyProduction_" + bhkw_id);

        //    energyProduction += energy_v[0].Value;

        //    // thermal energy production

        //    energyThermProduction += energy_v[1].Value;
        //  }

        //  return energyProduction;
        //}

        /// <summary>
        /// Calc max electrical energy production possible on given plant
        /// </summary>
        /// <param name="myPlant"></param>
        /// <returns>max. el. energy production in [kWh/d]</returns>
        private static double getMaxElEnergyProduction(biogas.plant myPlant)
        {
            //double energyProductionMax = 0;

            //for (int ibhkw = 0; ibhkw < myPlant.getNumCHPs(); ibhkw++)
            //{
            //  string bhkw_id = myPlant.getCHPID(ibhkw + 1);

            //  energyProductionMax += myPlant.getCHPParam(bhkw_id, "Pel") * 24;
            //}

            //return energyProductionMax;

            return(myPlant.getMaxElEnergy().Value);
        }