Пример #1
0
 public override void SetOverallPropList(string propName, PropertyBasis basis, IEnumerable <double> value)
 {
     CasterLogger.Debug($"Set property {propName} for overall: {value}");
     double[] temp = value as double[] ?? value.ToArray();
     _capeThermoMaterial.SetOverallProp(propName, basis.ToString(), value);
     //_alreadyFlashed = false;
     CasterLogger.Debug($"Set property complete");
 }
Пример #2
0
 /// <summary>
 /// set single phase composition, eg.set V or L in RadFrac
 /// </summary>
 public void SetSinglePhaseComposition(Phases phase, PropertyBasis basis, Dictionary <string, double> composition)
 {
     double[] temp = new double[CompoundNum];
     for (int i = 0; i < CompoundNum; i++)
     {
         temp[i] = composition[Compounds[i]];
     }
     SetSinglePhaseComposition(phase, PropertyBasis.Mole, temp);
 }
Пример #3
0
        public override double[] GetOverallPropList(string propName, PropertyBasis basis, bool calculate = false)
        {
            CasterLogger.Debug($"Get property {propName} for overall");
            object value = null;

            _capeThermoMaterial.GetOverallProp(propName, basis.ToString(), ref value);
            CasterLogger.Debug($"Property {propName} result: {value}");
            return(value as double[]);
        }
Пример #4
0
 public override void SetSinglePhasePropList(string propName, Phases phase, PropertyBasis basis, IEnumerable <double> value)
 {
     CasterLogger.Debug($"Set property {propName} for phase {phase}: {value}");
     if (PresentPhases.All(p => p.Value != phase.Value))
     {
         PresentPhases = AllowedPhases;
     }
     double[] temp = value as double[] ?? value.ToArray();
     _capeThermoMaterial.SetSinglePhaseProp(propName, phase.Value, basis.ToString(), temp);
     //_alreadyFlashed = false;
     CasterLogger.Debug($"Set property complete");
 }
Пример #5
0
        /// <summary>
        /// get the vapor or liquid part composition of the material, must be flashed first!
        /// </summary>
        public Dictionary <string, double> GetSinglePhaseComposition(Phases phase, PropertyBasis basis)
        {
            var composition  = new Dictionary <string, double>();
            var compoundList = Compounds;

            double[] compositionList = GetSinglePhasePropList("fraction", phase, basis);
            for (int i = 0; i < compoundList.Length; i++)
            {
                composition.Add(compoundList[i], compositionList[i]);
            }
            return(composition);
        }
Пример #6
0
        /// <summary>
        /// get single phase property, return a double number, will try to calculate property first, if not present, return 0; if property is an array, throw exception
        /// </summary>
        public double GetSinglePhasePropDouble(string propName, Phases phase, PropertyBasis basis, bool calculate = true)
        {
            CasterLogger.Debug($"GetSinglePhasePropDouble for {propName} in {phase} Calculate: {calculate}");
            if (PresentPhases.All(p => p.Value != phase.Value))
            {
                return(0);
            }
            var result = GetSinglePhasePropList(propName, phase, basis, calculate).SingleOrDefault();

            CasterLogger.Debug($"GetSinglePhasePropDouble result: {result}");
            return(result);
        }
Пример #7
0
        /// <summary>
        /// Calculate or get property
        /// </summary>
        /// <param name="propName">property name, defined in CO reference</param>
        /// <param name="phases">empty means </param>
        /// <param name="basis"></param>
        /// <param name="calculate"></param>
        /// <returns></returns>
        protected double[] GetPropList(string propName, PropertyBasis basis, Phases[] phases = null, bool calculate = true)
        {
            object value = null;

            try
            {
                // overall don't need calculate
                if (calculate && phases != null && phases.Length != 0)
                {
                    CasterLogger.Debug($"Calculate property {propName} for {phases}");
                    _capeThermoMaterialObject.CalcProp(new[] { propName }, phases, "mixture");
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("Calculate single phase prop {0} fails. {1}", propName, e.Message);
            }
            if (phases == null || phases.Length == 0) // overall
            {
                CasterLogger.Debug($"Get property {propName} for overall phase");
                value = _capeThermoMaterialObject.GetProp(propName, "Overall", null, "mixture", basis.ToString());
            }
            else if (phases.Length == 1)  // one phase
            {
                CasterLogger.Debug($"Get property {propName} for {phases[0]}");
                value = _capeThermoMaterialObject.GetProp(propName, phases[0].Value, null, "mixture", basis.ToString());
            }
            else if (phases.Length == 2)  // two phases, example: kvalues
            {
                CasterLogger.Debug($"Get property {propName} for {phases[0]} and {phases[1]}");
                string phaseName = null;
                if (phases.Contains(Phases.Vapor) && phases.Contains(Phases.Liquid))
                {
                    phaseName = Phases.Vapor.Value + Phases.Liquid.Value;   // vapor in front
                }
                else
                {
                    phaseName = phases[0].Value + phases[1].Value;
                }
                value = _capeThermoMaterialObject.GetProp(propName, phaseName, null, "mixture", basis.ToString());
            }
            else
            {
                CasterLogger.Error($"Only support overall, 1 phase or 2 phases");
                throw new ArgumentOutOfRangeException($"Only support overall, 1 phase or 2 phases");
            }
            CasterLogger.Debug($"Get property {propName}: {value}");
            return(value as double[]);
        }
Пример #8
0
 /// <summary>
 /// set property
 /// </summary>
 /// <param name="propName">property name, defined in CO reference</param>
 /// <param name="phases">empty means overall, if it's vapor and liquid, will be combined to "vaporliquid", otherwise, just add the names</param>
 /// <returns></returns>
 protected void SetPropList(string propName, PropertyBasis basis, IEnumerable <double> value, Phases[] phases = null)
 {
     CasterLogger.Debug($"Set property for {propName}: {value}");
     double[] temp = value as double[] ?? value.ToArray();
     if (phases == null || phases.Length == 0) // overall
     {
         CasterLogger.Debug($"Set property {propName} for overall phase");
         _capeThermoMaterialObject.SetProp(propName, "Overall", null, "mixture", basis.ToString(), temp);
     }
     else if (phases.Length == 1)  // one phase
     {
         CasterLogger.Debug($"Set property {propName} for {phases[0]}");
         _capeThermoMaterialObject.SetProp(propName, phases[0].Value, null, null, basis.ToString(), temp);
     }
     else if (phases.Length == 2)  // two phases
     {
         CasterLogger.Debug($"Set property {propName} for {phases[0]} and {phases[1]}");
         string phaseName = null;
         if (phases.Contains(Phases.Vapor) && phases.Contains(Phases.Liquid))
         {
             phaseName = Phases.Vapor.Value + Phases.Liquid.Value;   // vapor in front
         }
         else
         {
             phaseName = phases[0].Value + phases[1].Value;
         }
         _capeThermoMaterialObject.SetProp(propName, phaseName, null, "mixture", basis.ToString(), temp);
     }
     else
     {
         CasterLogger.Error($"Only support overall, 1 phase or 2 phases");
         throw new ArgumentOutOfRangeException($"Only support overall, 1 phase or 2 phases");
     }
     //_alreadyFlashed = false;
     CasterLogger.Debug($"Set property completed");
 }
Пример #9
0
 /// <summary>
 /// set two phase property
 /// </summary>
 public void SetTwoPhasePropDouble(string propName, Phases phase1, Phases phase2, PropertyBasis basis, double value)
 {
     CasterLogger.Debug($"SetTwoPhasePropDouble {propName} for {phase1} and {phase2}, {value}");
     SetTwoPhasePropList(propName, phase1, phase2, basis, new[] { value });
     CasterLogger.Debug($"SetTwoPhasePropDouble completed");
 }
Пример #10
0
 /// <summary>
 /// set two phase property,
 /// </summary>
 /// <paramCollection name="value">the value to be set, MUST be IEnumerable double, if you want to set other data structure, use the raw interface</paramCollection>
 public abstract void SetTwoPhasePropList(string propName, Phases phase1, Phases phase2, PropertyBasis basis, IEnumerable <double> value);
Пример #11
0
 /// <summary>
 /// Get two phase property, if a phase is not present, will return new double[CompoundNum]
 /// </summary>
 public abstract double[] GetTwoPhasePropList(string propName, Phases phase1, Phases phase2, PropertyBasis basis, bool calculate = true);
Пример #12
0
 /// <summary>
 /// get overall property, return a double array, if result is a single number, will return a single element array
 /// </summary>
 public abstract double[] GetOverallPropList(string propName, PropertyBasis basis, bool calculate = false);
Пример #13
0
 public override double[] GetTwoPhasePropList(string propName, Phases phase1, Phases phase2, PropertyBasis basis, bool calculate = true)
 {
     return(GetPropList(propName, basis, new[] { phase1, phase2 }, calculate));
 }
Пример #14
0
        public override double[] GetTwoPhasePropList(string propName, Phases phase1, Phases phase2, PropertyBasis basis, bool calculate = true)
        {
            CasterLogger.Debug($"Get property {propName} for phase {phase1} and {phase2}");

            object value = null;

            if (PresentPhases.All(p => p.Value != phase1.Value) ||
                PresentPhases.All(p => p.Value != phase2.Value))
            {
                return(new double[CompoundNum]);
            }

            string[] phaseList = { phase1.Value, phase2.Value };
            try
            {
                _capeThermoPropertyRoutine.CalcTwoPhaseProp(new[] { propName }, phaseList);
            }
            catch (Exception e)
            {
                Debug.WriteLine("Calculate two phase prop {0} fails. {1}", propName, e.Message);
            }
            _capeThermoMaterial.GetTwoPhaseProp(propName, phaseList, basis.ToString(), ref value);
            CasterLogger.Debug($"Property {propName} result: {value}");
            return(value as double[]);
        }
Пример #15
0
 /// <summary>
 /// get single phase flow
 /// </summary>
 public double GetSinglePhaseFlow(Phases phase, PropertyBasis basis)
 {
     return(GetSinglePhasePropDouble("phaseFraction", phase, basis, false) * TotalFlow);
 }
Пример #16
0
 /// <summary>
 /// set single pahse property
 /// </summary>
 public void SetSinglePhasePropDouble(string propName, Phases phase, PropertyBasis basis, double value)
 {
     CasterLogger.Debug($"SetSinglePhasePropDouble for {propName} in {phase}: {value}");
     SetSinglePhasePropList(propName, phase, basis, new[] { value });
     CasterLogger.Debug($"SetSinglePhasePropDouble completed.");
 }
Пример #17
0
 /// <summary>
 /// set overall property
 /// </summary>
 /// <paramCollection name="value">the value to be set, MUST be IEnumerable double, if you want to set other data structure, use the raw interface</paramCollection>
 public abstract void SetOverallPropList(string propName, PropertyBasis basis, IEnumerable <double> value);
Пример #18
0
 /// <summary>
 /// set overall property
 /// </summary>
 public void SetOverallPropDouble(string propName, PropertyBasis basis, double value)
 {
     CasterLogger.Debug($"SetOverallPropDouble for {propName}, value is {value}");
     SetOverallPropList(propName, basis, new[] { value });
     CasterLogger.Debug($"SetOverallPropDouble completed.");
 }
Пример #19
0
 public override double[] GetOverallPropList(string propName, PropertyBasis basis, bool calculate = false)
 {
     return(GetPropList(propName, basis));
 }
Пример #20
0
        public override double[] GetSinglePhasePropList(string propName, Phases phase, PropertyBasis basis, bool calculate = true)
        {
            CasterLogger.Debug($"Get property {propName} for phase {phase}");
            object value = null;

            if (PresentPhases.All(p => p.Value != phase.Value))
            {
                return(new double[CompoundNum]);     //default is 0 for every element
            }
            try
            {
                if (calculate)
                {
                    _capeThermoPropertyRoutine.CalcSinglePhaseProp(new[] { propName }, phase.Value);
                }
            }
            catch (Exception e)
            {
                CasterLogger.ErrorFormatted("Calculate single phase prop {0} fails. {1}", propName, e.Message);
                Debug.WriteLine("Calculate single phase prop {0} fails. {1}", propName, e.Message);
            }
            _capeThermoMaterial.GetSinglePhaseProp(propName, phase.Value, basis.ToString(), ref value);
            CasterLogger.Debug($"Property {propName} result: {value}");
            return(value as double[]);
        }
Пример #21
0
 public override void SetOverallPropList(string propName, PropertyBasis basis, IEnumerable <double> value)
 {
     SetPropList(propName, basis, value);
 }
Пример #22
0
        /// <summary>
        /// Set composition of single phase, the composition is ordered by Compounds
        /// </summary>
        public void SetSinglePhaseComposition(Phases phase, PropertyBasis basis, IEnumerable <double> composition)
        {
            var enumerable = composition as double[] ?? composition.ToArray();

            SetSinglePhasePropList("fraction", phase, PropertyBasis.Mole, enumerable);
        }
Пример #23
0
 public override void SetTwoPhasePropList(string propName, Phases phase1, Phases phase2, PropertyBasis basis, IEnumerable <double> value)
 {
     SetPropList(propName, basis, value, new[] { phase1, phase2 });
 }
Пример #24
0
 /// <summary>
 /// get overall property, return a double number, if not present, return 0; if result is an array, throw an exception
 /// </summary>
 public double GetOverallPropDouble(string propName, PropertyBasis basis)
 {
     CasterLogger.Debug($"GetOverallPropDouble for {propName}");
     return(GetOverallPropList(propName, basis).Single());
 }