Example #1
0
        public void Compute(ITime targetTime)
        {
            ITime lastTime = DetermineCurrentTime(null);

            if (lastTime == null)
            {
                throw new Exception("Could not find time/space output item to check model's current time");
            }

            while (lastTime.EndTime.MJD < targetTime.MJD &&
                   _openMIComponent.Status != LinkableComponentStatus.Failed &&
                   _openMIComponent.Status != LinkableComponentStatus.Done)
            {
                try
                {
                    _openMIComponent.Update();
                }
                catch (Exception e)
                {
                    ModelFactory.AppendLogMessage("Exception in Update()" + e);
                    throw e;
                }
                foreach (KeyValuePair <string, ExchangeItem> output in _outputs)
                {
                    output.Value.AddNewOpenMIOutputValuesToBuffer();
                }
                lastTime = DetermineCurrentTime(null);
            }
        }
Example #2
0
        private ITime DetermineFinalTime(ITime currentTime)
        {
            foreach (KeyValuePair <string, ExchangeItem> output in _outputs)
            {
                if (output.Value.Times != null && output.Value.Times.Length > 0)
                {
                    double timeAsMJD = output.Value.Times[output.Value.Times.Length - 1];

                    currentTime = new DotNet.Bridge.Time(timeAsMJD);
                    break;
                }
            }
            foreach (KeyValuePair <string, ExchangeItem> inout in _inout)
            {
                if (inout.Value.Times != null && inout.Value.Times.Length > 0)
                {
                    double timeAsMJD = inout.Value.Times[inout.Value.Times.Length - 1];
                    currentTime = new DotNet.Bridge.Time(timeAsMJD);
                    break;
                }
            }

            if (currentTime == null)
            {
                currentTime = TimeHorizon.BeginTime;
            }
            return(currentTime);
        }
Example #3
0
        public void Compute(ITime targetTime)
        {
            ITime lastTime = DetermineCurrentTime(null);
            //double FinalSimTime = TimeHorizon.MJD ;
            double FinalSimTime = TimeHorizon.EndTime.MJD;

            // Get the precision for comparing times as specified by the user.
            double timePrecisionMJD = org.openda.utils.performance.OdaGlobSettings.getTimePrecision();


            ITime current = lastTime;

            if (lastTime == null)
            {
                throw new Exception("Could not find time/space output item to check model's current time");
            }

            // Note: we are absolutely not sure why we have the second part in the while check!!!!
            while (lastTime.EndTime.MJD + timePrecisionMJD < targetTime.MJD && FinalSimTime - timePrecisionMJD > lastTime.EndTime.MJD)
            {
                current = lastTime;
                try
                {
                    _openMIComponent.Update();
                }
                catch (Exception e)
                {
                    FileStream   fileStream   = File.Open("MShe_Exceptions.txt", FileMode.Append);
                    StreamWriter streamWriter = new StreamWriter(fileStream);
                    streamWriter.WriteLine("Exception in Update()" + e);
                    streamWriter.Close();
                }

                // Get the timeStamp of the Model. This is used in case time information is missing in the exhangeItems of the Model
                ITime timeStampModel = DetermineCurrentTime(null);

                foreach (KeyValuePair <string, ExchangeItem> output in _outputs)
                {
                    output.Value.AddNewOpenMIOutputValuesToBuffer(timeStampModel.MJD);
                    output.Value.UpdatetstepCount();
                }
                foreach (KeyValuePair <string, ExchangeItem> inout in _inout)
                {
                    inout.Value.AddNewOpenMIOutputValuesToBuffer(timeStampModel.MJD);
                    inout.Value.UpdatetstepCount();
                }
                foreach (KeyValuePair <string, ExchangeItem> input in _inputs)
                {
                    input.Value.UpdatetstepCount();
                }
                lastTime = DetermineCurrentTime(null);
                _mSheTstep++;
            }
        }
Example #4
0
        private ITime DetermineCurrentTime(ITime currentTime)
        {
            /* In case the component implements some extensions, use them */
            if (_openMIComponent is ITimeSpaceComponentExtensions)
            {
                ITimeSpaceComponentExtensions extendedComponent = (ITimeSpaceComponentExtensions)_openMIComponent;
                double now = extendedComponent.currentTime().StampAsModifiedJulianDay;
                return(new DotNet.Bridge.Time(now));
            }
            /* We have to fall back on a proper time administration in the exhange items */

            foreach (KeyValuePair <string, ExchangeItem> output in _outputs)
            {
                if (output.Value.Times != null && output.Value.Times.Length > 0)
                {
                    double timeAsMJD = output.Value.Times[output.Value.Times.Length - 1];
                    currentTime = new DotNet.Bridge.Time(timeAsMJD);
                    if (currentTime != null)
                    {
                        return(currentTime);
                    }
                }
            }

            foreach (KeyValuePair <string, ExchangeItem> inout in _inout)
            {
                if (inout.Value.Times != null && inout.Value.Times.Length > 0)
                {
                    double timeAsMJD = inout.Value.Times[inout.Value.Times.Length - 1];
                    currentTime = new DotNet.Bridge.Time(timeAsMJD);

                    break;
                }
                break;
            }

            if (currentTime == null)
            {
                currentTime = TimeHorizon.BeginTime;
            }
            return(currentTime);
            // }
        }