Example #1
0
 public Dispensary(IExecutive executive, Mixture mixture)
 {
     m_executive                 = executive;
     m_getProcessor              = s_dummyIdec;
     m_waiters                   = new List <IDetachableEventController>();
     PeekMixture                 = mixture;
     executive.ExecutiveStarted += delegate { m_waiters.Clear(); PeekMixture.Clear(); };
 }
Example #2
0
 /// <summary>
 /// Performs a reset operation on this instance.
 /// </summary>
 public void Reset()
 {
     m_mixture.Clear();
     m_pressure = m_initialPressure;
     m_mixtureVolume.Reset();
     m_mixtureMass.Reset();
     m_mixtureMass.Register(m_mixture.Mass);
     m_mixtureVolume.Register(m_mixture.Volume);
 }
 public void Reset(double mH2O, double mNANO2)
 {
     m_mixture.Clear();
     m_mixture.AddMaterial(m_brs.MyMaterialCatalog["Water"].CreateMass(mH2O, 20));            // Add 250 kg.
     m_mixture.AddMaterial(m_brs.MyMaterialCatalog["Sodium Nitrite"].CreateMass(mNANO2, 20)); // Add 100 kg NaNO2.
 }
Example #4
0
        /// <summary>
        /// Performs the inflow/outflow cycle analysis. After this runs, consult the Mass, Volume and Temperature history members.
        /// </summary>
        public void Process()
        {
            m_massHistory.Reset();
            m_volumeHistory.Reset();

            Mixture contents = (Mixture)m_initial.Clone();

            if (m_reactionProcessor != null)
            {
                m_reactionProcessor.Watch(contents);
            }

            Mixture inflow  = m_inflow == null?new Mixture():(Mixture)m_inflow.Clone();
            Mixture outflow = m_outflow == null ? new Mixture() : (Mixture)m_outflow.Clone();

            double tiv = inflow.Volume;
            double tim = inflow.Mass;
            double tov = outflow.Volume;
            double tom = outflow.Mass;

            bool useMinidumps = true;

            //bool useMinidumps = false;
            //if ( ( tiv + contents.Volume - tov > m_capacity ) ) useMinidumps = true;

            RecordMvt(contents);
            if (m_cyclical)
            {
                if (m_inflowFirst)
                {
                    if (s_diagnostics)
                    {
                        Console.WriteLine("Initial - total volume = " + contents.Volume + ", mixture is " + contents);
                    }
                    while (inflow.Mass > 0.0 || outflow.Mass > 0.0)
                    {
                        // Perform charge
                        if (inflow.Mass > 0.0)
                        {
                            double chgMass     = Math.Min((m_capacity - contents.Volume) * (tim / tiv), inflow.Mass);
                            double pctOfInFlow = chgMass / inflow.Mass;
                            contents.AddMaterial(inflow.RemoveMaterial(chgMass));
                            if (s_diagnostics)
                            {
                                Console.WriteLine("After charge - total volume = " + contents.Volume + ", mixture is " + contents);
                            }
                            RecordMvt(contents);
                        }

                        // Perform discharge
                        if (outflow.Mass > 0.0)
                        {
                            double  dischgMass = Math.Min((m_capacity - contents.Volume) * (tom / tov), outflow.Mass);
                            Mixture extract    = (Mixture)outflow.RemoveMaterial(dischgMass);
                            foreach (Substance substance in extract.Constituents)
                            {
                                contents.RemoveMaterial(substance.MaterialType, extract.Mass);
                            }
                            if (s_diagnostics)
                            {
                                Console.WriteLine("After discharge - total volume = " + contents.Volume + ", mixture is " + contents);
                            }
                            RecordMvt(contents);
                        }

                        if (useMinidumps)
                        {
                            contents.Clear();
                        }
                    }
                }
                else
                {
                    throw new NotImplementedException("Only able to model inflow-first, cyclical behavior.");
                }
            }
            else
            {
                throw new NotImplementedException("Only able to model inflow-first, cyclical behavior.");
            }
            if (m_reactionProcessor != null)
            {
                m_reactionProcessor.Ignore(contents);
            }
        }