Exemplo n.º 1
0
        /// <summary>
        /// Calculates the f-Factor: fLi_Xc, defining the fraction of lipids in
        /// composites Xc
        /// </summary>
        /// <param name="RL">must be measured in % TS</param>
        /// <param name="VS">must be measured in % TS</param>
        /// <returns>fLi_Xc</returns>
        /// <exception cref="exception">value out of bounds</exception>
        public static double calcfLi_Xc(double RL, double VS)
        {
            physValue pRL = new science.physValue("RL", RL, "% TS");
            physValue pVS = new science.physValue("VS", VS, "% TS");

            return(calcfLi_Xc(pRL, pVS));
        }
Exemplo n.º 2
0
        // -------------------------------------------------------------------------------------
        //                              !!! PRIVATE METHODS !!!
        // -------------------------------------------------------------------------------------

        /// <summary>
        /// Get a value out of the state vector x in the given unit.
        /// </summary>
        /// <param name="x">ADM state vector</param>
        /// <param name="symbol">element of the state vector as defined in the ADM state vector</param>
        /// <param name="unit"></param>
        /// <returns></returns>
        /// <exception cref="exception">Unknown symbol</exception>
        private static physValue getFromADMstate(double[] x, string symbol,
                                                 string unit)
        {
            physValue value;

            if (isofkind(symbol, "acid"))
            {
                string Acid;
                string Base;
                string Sum;

                biogas.ADMstate.defineAcidBasePairs(symbol, out Acid, out Base, out Sum);

                double conc_base;
                double conc_sum;

                biogas.ADMstate.getADMstatevariables(x, out conc_base, Base);
                biogas.ADMstate.getADMstatevariables(x, out conc_sum, Sum);

                value = new science.physValue(symbol, conc_sum - conc_base, unit);
            }
            else
            {
                double conc;

                biogas.ADMstate.getADMstatevariables(x, out conc, symbol);

                value = new science.physValue(symbol, conc, unit);
            }

            return(value);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Calculates the f-Factor: fPr_Xc, defining the fraction of proteins in
        /// composites Xc
        /// </summary>
        /// <param name="RP">must be measured in % TS</param>
        /// <param name="VS">must be measured in % TS</param>
        /// <returns>fPr_Xc</returns>
        /// <exception cref="exception">value out of bounds</exception>
        public static double calcfPr_Xc(double RP, double VS)
        {
            physValue pRP = new science.physValue("RP", RP, "% TS");
            physValue pVS = new science.physValue("VS", VS, "% TS");

            return(calcfPr_Xc(pRP, pVS));
        }
Exemplo n.º 4
0
        // -------------------------------------------------------------------------------------
        //                              !!! CONSTRUCTOR METHODS !!!
        // -------------------------------------------------------------------------------------

        /// <summary>
        /// constructor with all parameters
        /// </summary>
        /// <param name="symbol">
        /// symbol of the physical value, such as m for mass, T for temperature, ...
        /// </param>
        /// <param name="value">
        /// value of the physical value
        /// </param>
        /// <param name="unit">
        /// unit of the physical value, without rectangular brackets
        /// </param>
        /// <param name="label">
        /// label of the physical value, such as temperature, mass, ...
        /// </param>
        /// <param name="reference">
        /// reference for a physical value gotten out of literature, or from plants
        /// </param>
        /// <param name="lb">
        /// lower boundary of the physical value
        /// </param>
        /// <param name="ub">
        /// upper boundary of the physical value
        /// </param>
        public physValueBounded(string symbol, double value, string unit, string label,
                                string reference, physValue lb, physValue ub) :
            base(symbol, value, unit, label, reference)
        {
            _lb = lb;
            _ub = ub;
        }
Exemplo n.º 5
0
 /// <summary>
 /// constructor used to copy physValues, the returned physValue
 /// is identical to the template
 /// </summary>
 /// <param name="template"></param>
 public physValue(physValue template)
 {
     _symbol    = template.Symbol;
     _value     = template.Value;
     _unit      = template.Unit;
     _label     = template.Label;
     _reference = template.Reference;
 }
Exemplo n.º 6
0
        /// <summary>
        /// unary minus: Returns -v
        /// </summary>
        /// <param name="v">v</param>
        /// <returns>-v</returns>
        public static physValue operator-(physValue v)
        {
            physValue v_new = new physValue(v);

            v_new._value = -v.Value;

            return(v_new);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Calculates the f-Factor: fXI_Xc, defining the fraction of particulate inerts in
        /// composites Xc
        /// </summary>
        /// <param name="ADL">must be measured in % TS</param>
        /// <param name="NDF">must be measured in % TS</param>
        /// <param name="VS">must be measured in % TS</param>
        /// <param name="D_VS">must be measured in 100 %</param>
        /// <returns>fXI_Xc</returns>
        public static double calcfXI_Xc(double ADL, double NDF, double VS, double D_VS)
        {
            physValue pADL  = new science.physValue("ADL", ADL, "% TS");
            physValue pNDF  = new science.physValue("NDF", NDF, "% TS");
            physValue pVS   = new science.physValue("VS", VS, "% TS");
            physValue pD_VS = new science.physValue("D_VS", D_VS, "100 %");

            return(calcfXI_Xc(pADL, pNDF, pVS, pD_VS));
        }
Exemplo n.º 8
0
        /// <summary>
        /// Rounds the double Value of the given physValue to the given digits
        /// </summary>
        /// <param name="value">physValue</param>
        /// <param name="digits">number of digits</param>
        /// <returns>physValue the same as the given one, only value round to number of digits
        /// </returns>
        public static physValue round(physValue value, int digits)
        {
            physValue new_value = new physValue(value);

            // new_value.Value
            new_value._value = Math.Round(new_value.Value, digits);

            return(new_value);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Returns the arithemtic mean of the physical values in the given array
        /// </summary>
        /// <param name="inputs">physValue vector</param>
        /// <returns>arithmetic mean of the components of inputs</returns>
        /// <exception cref="exception">inputs is empty</exception>
        /// <exception cref="exception">unit mismatch</exception>
        public static physValue mean(physValue[] inputs) // const
        {
            physValue mean = sum(inputs);

            if (inputs.Length > 0)
            {
                mean /= inputs.Length;
            }

            return(mean);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Returns the arithmetic mean of the physical values given.
        /// Call: physValue.meanVar(v1, v2, v3), v1-v3: physValues
        /// </summary>
        /// <param name="inputs">physValue objects</param>
        /// <returns>arithmetic mean of given values</returns>
        /// <exception cref="exception">inputs is empty</exception>
        /// <exception cref="exception">unit mismatch</exception>
        public static physValue meanVar(params physValue[] inputs) // const
        {
            physValue[] input_array = new physValue[inputs.Length];

            for (int iValue = 0; iValue < inputs.Length; iValue++)
            {
                input_array[iValue] = inputs[iValue];
            }

            return(mean(input_array));
        }
Exemplo n.º 11
0
        /// <summary>
        /// Rounds the double Value of each element inside the given physValue
        /// array to the given digits
        /// </summary>
        /// <param name="values">array of physValue</param>
        /// <param name="digits">number of digits</param>
        /// <returns>vector of rounded physValues</returns>
        public static physValue[] round(physValue[] values, int digits)
        {
            physValue[] new_value = new physValue[values.Length];

            for (int ivalue = 0; ivalue < new_value.Length; ivalue++)
            {
                new_value[ivalue] = round(values[ivalue], digits);
            }

            return(new_value);
        }
Exemplo n.º 12
0
        // -------------------------------------------------------------------------------------
        //                       !!! PUBLIC METHODS: MATHEMATICAL STUFF !!!
        // -------------------------------------------------------------------------------------

        /// <summary>
        /// Multiply a physValue array with a double scalar.
        /// Each value inside the array is multiplied with the scalar
        /// </summary>
        /// <param name="v">physValue vector</param>
        /// <param name="scalar">double scalar</param>
        /// <returns>v multiplied with scalar, componentwise</returns>
        public static physValue[] times(physValue[] v, double scalar)
        {
            physValue[] v_result = new physValue[v.Length];

            for (int iel = 0; iel < v_result.Length; iel++)
            {
                v_result[iel] = v[iel] * scalar;
            }

            return(v_result);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Returns the object out of both objects v1 and v2, which has the smaller
        /// numerical value. If Unit of both are not the same, then an error is
        /// thrown.
        /// </summary>
        /// <param name="v1">first physValue</param>
        /// <param name="v2">2nd physValue</param>
        /// <returns>min(v1, v2)</returns>
        /// <exception cref="exception">unit mismatch</exception>
        public static physValue min(physValue v1, physValue v2) // const
        {
            if (v1.Unit != v2.Unit)
            {
                throw new exception(String.Format(
                                        "Cannot compare! The units of both physical values are not equal: {0} != {1}!",
                                        v1.Unit, v2.Unit));
            }

            return(new physValue(String.Format("Min({0}, {1})", v1.Symbol, v2.Symbol),
                                 Math.Min(v1.Value, v2.Value), v1.Unit));
        }
Exemplo n.º 14
0
        /// <summary>
        /// Calculate g C / kg substrate fresh matter
        /// </summary>
        /// <param name="RF">must be measured in % TS</param>
        /// <param name="RP">must be measured in % TS</param>
        /// <param name="RL">must be measured in % TS</param>
        /// <param name="NfE">must be measured in % TS</param>
        /// <param name="ADL">must be measured in % TS</param>
        /// <param name="TS">must be measured in % FM</param>
        /// <returns>g C / kg fresh matter</returns>
        private static physValue calcC(double RF, double RP, double RL,
                                       double NfE, double ADL, double TS)
        {
            physValue pRF  = new science.physValue("RF", RF, "% TS");
            physValue pRP  = new science.physValue("RP", RP, "% TS");
            physValue pRL  = new science.physValue("RL", RL, "% TS");
            physValue pNfE = new science.physValue("NfE", NfE, "% TS");
            physValue pADL = new science.physValue("ADL", ADL, "% TS");
            physValue pTS  = new science.physValue("TS", TS, "% FM");

            return(calcC(pRF, pRP, pRL, pNfE, pADL, pTS));
        }
Exemplo n.º 15
0
        /// <summary>
        /// Math.Pow for physValues: Math.Pow(value, numerator/denominator)
        /// </summary>
        /// <param name="value">physValue</param>
        /// <param name="numerator">Zähler</param>
        /// <param name="denominator">Nenner</param>
        /// <returns>value^(numerator/denominator)</returns>
        public static physValue Pow(physValue value, int numerator, int denominator)
        {
            physValue new_value = new physValue(value);

            // new_value.Value
            new_value._value  = Math.Pow(new_value.Value, ((double)numerator / (double)denominator));
            new_value._symbol = String.Format("{0}^({1}/{2})", new_value.Symbol, numerator, denominator);
            new_value._unit   = String.Format("({0})^({1}/{2})", new_value.Unit, numerator, denominator);
            new_value._label  = String.Format("({0})^({1}/{2})", new_value.Label, numerator, denominator);

            return(new_value);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Math.Pow for physValues: Math.Pow(value, power)
        /// </summary>
        /// <param name="value">physValue</param>
        /// <param name="power">power</param>
        /// <returns>value^power</returns>
        public static physValue Pow(physValue value, int power)
        {
            physValue new_value = new physValue(value);

            // new_value.Value
            new_value._value  = Math.Pow(new_value.Value, power);
            new_value._symbol = String.Format("{0}^{1}", new_value.Symbol, power);
            new_value._unit   = String.Format("({0})^{1}", new_value.Unit, power);
            new_value._label  = String.Format("({0})^{1}", new_value.Label, power);

            return(new_value);
        }
Exemplo n.º 17
0
        /// <summary>
        /// Creates a physValue vector containing 0s
        /// </summary>
        /// <param name="dim">dimension of zero vector</param>
        /// <returns>zero vector with no unit "-"</returns>
        /// <exception cref="exception">dim &lt; 1</exception>
        public static physValue[] zeros(int dim)
        {
            if (dim <= 0)
            {
                throw new exception(String.Format("dim must be >= 1, but is {0}!", dim));
            }

            physValue[] v = new physValue[dim];

            // TODO - what is the definition of no unit? 1 or -?
            for (int iel = 0; iel < v.Length; iel++)
            {
                v[iel] = new physValue(String.Format("v{0}", iel), 0, "-");
            }

            return(v);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Math.Sqrt for physValues: Math.Sqrt(value)
        /// </summary>
        /// <param name="value">physValue</param>
        /// <returns>sqrt(value)</returns>
        public static physValue Sqrt(physValue value)
        {
            physValue new_value = new physValue(value);

            // new_value.Value
            new_value._value = Math.Sqrt(new_value.Value);

            //if (new_value.Symbol.Length > 0)
            new_value._symbol = String.Format("{0}^(1/2)", new_value.Symbol);

            //if (new_value.Unit.Length > 0)
            new_value._unit = String.Format("({0})^(1/2)", new_value.Unit);

            //if (new_value.Label.Length > 0)
            new_value._label = String.Format("({0})^(1/2)", new_value.Label);

            return(new_value);
        }
Exemplo n.º 19
0
        /// <summary>
        /// concatenate both vectors v1 and v2 vertically
        /// </summary>
        /// <param name="v1">first vector</param>
        /// <param name="v2">2nd vector</param>
        /// <returns>[v1; v2]</returns>
        public static physValue[] concat(physValue[] v1, physValue[] v2)
        {
            physValue[] v = new physValue[v1.Length + v2.Length];

            for (int iel = 0; iel < v.Length; iel++)
            {
                if (iel < v1.Length)
                {
                    v[iel] = v1[iel];
                }
                else
                {
                    v[iel] = v2[iel - v1.Length];
                }
            }

            return(v);
        }
Exemplo n.º 20
0
        /// <summary>
        /// Returns the min of the physical values in the given array
        /// if array is empty, then negative infinity is returned, with no unit
        /// </summary>
        /// <param name="inputs">physValue vector</param>
        /// <returns>min(inputs)</returns>
        /// <exception cref="exception">unit mismatch</exception>
        public static physValue min(physValue[] inputs) // const
        {
            physValue minVal;

            if (inputs.Length > 0)
            {
                minVal = inputs[0];
            }
            else
            {
                minVal = new physValue(Double.NegativeInfinity, "");
            }

            for (int iel = 0; iel < inputs.Length - 1; iel++)
            {
                minVal = min(minVal, inputs[iel + 1]);
            }

            return(minVal);
        }
Exemplo n.º 21
0
        /// <summary>
        /// Calculates total alkalinity out of given ADM state vector
        ///
        /// the buffer consists out of:
        /// - acetate of VFAs, HCO3, aniona and cations
        /// </summary>
        /// <param name="x">ADM state vector</param>
        /// <param name="unit"></param>
        /// <returns></returns>
        public static physValueBounded calcTACOfADMstate(double[] x, string unit)
        {
            string unit_temp = "mol/l";

            // kmol/m³ = mol/l
            physValue San = new science.physValue("San", x[biogas.ADMstate.pos_San - 1], "mol/l");
            // mol/l
            physValue Shco3 = biogas.ADMstate.calcFromADMstate(x, "Shco3", unit_temp);
            // mol/l
            physValue Sac_ = biogas.ADMstate.calcFromADMstate(x, "Sac_", unit_temp);
            // mol/l
            physValue Spro_ = biogas.ADMstate.calcFromADMstate(x, "Spro_", unit_temp);
            // mol/l
            physValue Sbu_ = biogas.ADMstate.calcFromADMstate(x, "Sbu_", unit_temp);
            // mol/l
            physValue Sva_ = biogas.ADMstate.calcFromADMstate(x, "Sva_", unit_temp);
            // kmol/m³ = mol/l
            physValue Scat = new science.physValue("Scat", x[biogas.ADMstate.pos_Scat - 1], "mol/l");

            //

            // mol/l
            physValueBounded TAC = new physValueBounded(San + Shco3 + Sac_ + Spro_ + Sva_ + Sbu_ - Scat);

            //

            TAC = TAC.convertUnit(unit);

            TAC.Symbol = "TAC";

            //TAC.setLB(-double.Epsilon);

            TAC.printIsOutOfBounds();

            return(TAC);
        }
Exemplo n.º 22
0
        public static physValue[] mtimes(physValue[] v1, double[] v2)
        {
            if (v1.Length != v2.Length)
            {
                throw new exception(String.Format(
                                        "The length of both vectors is not the same: {0} != {1}!",
                                        v1.Length, v2.Length));
            }

            if (v1.Length <= 0)
            {
                throw new exception(String.Format(
                                        "The length of both vectors is <= 0: {0}!", v1.Length));
            }

            physValue[] v_result = new physValue[v1.Length];

            for (int iel = 0; iel < v_result.Length; iel++)
            {
                v_result[iel] = v1[iel] * v2[iel];
            }

            return(v_result);
        }
Exemplo n.º 23
0
 /// <summary>
 /// Sets upper bound to max and LB to -infinity.
 /// The unit is the one the object currently has.
 /// </summary>
 /// <param name="max">max value</param>
 public void setUB(double max)
 {
     _lb = new physValue(double.NegativeInfinity, Unit);
     _ub = new physValue(max, Unit);
 }
Exemplo n.º 24
0
 /// <summary>
 /// Sets lower bound to min and UB to infinity.
 /// The unit is the one the object currently has.
 /// </summary>
 /// <param name="min">min value</param>
 public void setLB(double min)
 {
     _lb = new physValue(min, Unit);
     _ub = new physValue(double.PositiveInfinity, Unit);
 }
Exemplo n.º 25
0
 /// <summary>
 /// Sets boundaries of physValueBounded to min and max.
 /// The unit is the one the object currently has.
 /// </summary>
 /// <param name="min">min value</param>
 /// <param name="max">max value</param>
 public void setBounds(double min, double max)
 {
     _lb = new physValue(min, Unit);
     _ub = new physValue(max, Unit);
 }
Exemplo n.º 26
0
 /// <summary>
 /// Rounds the double Value to 2 digits
 /// </summary>
 /// <param name="value">some value</param>
 /// <returns>same value round to 2 digits</returns>
 public static physValue round(physValue value)
 {
     return(round(value, 2));
 }
Exemplo n.º 27
0
 /// <summary>
 /// constructor used to copy physValus, the returned physValueBounded
 /// is identical to the template. Just adds boundaries at pos. and negative
 /// infinity.
 /// </summary>
 /// <param name="template">template</param>
 public physValueBounded(physValue template) : base(template)
 {
     _lb = new physValue(double.NegativeInfinity, Unit);
     _ub = new physValue(double.PositiveInfinity, Unit);
 }
Exemplo n.º 28
0
 /// <summary>
 /// constructor used to copy physValus, the returned physValueBounded
 /// is identical to the template. Just adds boundaries at lb and ub
 /// </summary>
 /// <param name="template">template</param>
 /// <param name="lb">lower boundary of the new physValueBounded</param>
 /// <param name="ub">upper boundary of the new physValueBounded</param>
 public physValueBounded(physValue template, double lb, double ub)
     : base(template)
 {
     _lb = new physValue(lb, Unit);
     _ub = new physValue(ub, Unit);
 }
Exemplo n.º 29
0
        /// <summary>
        /// Reads the params out of the XmlTextReader and writes them in the object.
        /// not const. Only reads one physValueBounded then returns. the 2nd parameter symbol
        /// is not read out of the xml file but must be read before out of the xml file.
        ///
        /// TODO: why not call it physValueBounded ???
        /// &lt;physValue symbol= "..."&gt;
        /// </summary>
        /// <param name="reader">an open xml textreader</param>
        /// <param name="symbol">symbol of the to be read physValueBounded</param>
        /// <returns>true, if physValue not empty</returns>
        override public bool getParamsFromXMLReader(ref XmlTextReader reader, string symbol)
        {
            string param = "";

            // if physValue is empty: "<physValue></physValue>", then false, else true
            bool notEmpty = false;

            _symbol = symbol;

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case System.Xml.XmlNodeType.Element: // this knot is an element
                    param = reader.Name;

                    break;

                case System.Xml.XmlNodeType.Text: // text, thus value, of each element

                    switch (param)
                    {
                    case "value":
                        _value   = System.Xml.XmlConvert.ToDouble(reader.Value);//Convert.ToDouble(reader.Value);
                        notEmpty = true;
                        break;

                    case "unit":
                        _unit    = reader.Value;
                        notEmpty = true;
                        break;

                    case "label":
                        _label   = reader.Value;
                        notEmpty = true;
                        break;

                    case "reference":
                        _reference = reader.Value;
                        notEmpty   = true;
                        break;

                    case "LB":
                        _lb      = new physValue(System.Xml.XmlConvert.ToDouble(reader.Value), Unit);
                        notEmpty = true;
                        break;

                    case "UB":
                        _ub      = new physValue(System.Xml.XmlConvert.ToDouble(reader.Value), Unit);
                        notEmpty = true;
                        break;
                    }
                    break;

                case System.Xml.XmlNodeType.EndElement:
                    if (reader.Name == "physValue")
                    {
                        return(notEmpty);
                    }

                    break;
                }
            }

            return(notEmpty);
        }
Exemplo n.º 30
0
 /// <summary>
 /// constructor with no upper boundary
 /// </summary>
 /// <param name="symbol">
 /// symbol of the physical value, such as m for mass, T for temperature, ...
 /// </param>
 /// <param name="value">
 /// value of the physical value
 /// </param>
 /// <param name="unit">
 /// unit of the physical value, without rectangular brackets
 /// </param>
 /// <param name="label">
 /// label of the physical value, such as temperature, mass, ...
 /// </param>
 /// <param name="reference">
 /// reference for a physical value gotten out of literature, or from plants
 /// </param>
 /// <param name="lb">
 /// lower boundary of the physical value
 /// </param>
 public physValueBounded(string symbol, double value, string unit, string label,
                         string reference, physValue lb) :
     this(symbol, value, unit, label, reference, lb,
          new physValue(double.PositiveInfinity, unit))
 {
 }