public MultiInputAdaptorFactory(IBaseLinkableComponent component) { _component = component; Id = "MultiInputAdaptorFactory"; Caption = "MultiInputAdaptorFactory"; Description = "A factory for creating adapted outputs, when connecting more than one output to a single input"; }
public Component(IBaseLinkableComponent component) : base(component) { _id = component.Id; _component = component; _timeExtent = new TimeSet(component.TimeExtent()); }
public Output(IIdentifiable identity, IValueDefinition valueDefinition, IBaseLinkableComponent component, IValueSetConverter valueSetConverter) : base(identity, valueDefinition, component) { _valueSetConverter = valueSetConverter; if (_valueSetConverter != null) _valueSetConverter.ExchangeItem = this; }
public InputSpace(IValueDefinition valueDefinition, ISpatialDefinition spatialDefinition, IBaseLinkableComponent component, IValueSetConverter valueSetConverter) : base(valueDefinition, spatialDefinition, component) { _valueSetConverter = valueSetConverter; if (_valueSetConverter != null) _valueSetConverter.ExchangeItem = this; }
/// <summary> /// Creates new instance of <see cref="TriggerExchangeItem">TriggerExchangeItem</see> /// </summary> public TriggerExchangeItem(IBaseLinkableComponent trigger) : base("Trigger") { Caption = "Trigger"; ValueDefinition = new Quantity("Trigger"); SpatialDefinition = new ElementSet("Trigger"); Component = trigger; }
public InputSpaceTime(IIdentifiable identity, IValueDefinition valueDefinition, ISpatialDefinition spatialDefinition, IBaseLinkableComponent component, IValueSetConverterTime valueSetConverterTime) : base(identity, valueDefinition, spatialDefinition, component) { _valueSetConverterTime = valueSetConverterTime; if (_valueSetConverterTime != null) _valueSetConverterTime.ExchangeItem = this; }
public void CreateInitializeTest() { ITimeSpaceComponent gwModel = new GWModelLC(); IBaseLinkableComponent lc = gwModel; Assert.IsTrue(gwModel.Status == LinkableComponentStatus.Created); List<IArgument> gwArguments = CreateTestArguments(); gwModel.Arguments.ApplyArguments(gwArguments); gwModel.Initialize(); Assert.IsTrue(gwModel.Status == LinkableComponentStatus.Initialized); Assert.AreEqual("GWModelLC", gwModel.Id); Assert.AreEqual(3, gwModel.Inputs.Count); Assert.AreEqual(3, gwModel.Outputs.Count); { // Check the ground water level output ITimeSpaceOutput gwLevel = lc.Outputs[2] as ITimeSpaceOutput; Assert.IsNotNull(gwLevel); Assert.AreEqual("Grid.gwLevel", gwLevel.Id); // Check quantity IQuantity quantity = gwLevel.ValueDefinition as IQuantity; Assert.IsNotNull(quantity); Assert.AreEqual("Ground water level", quantity.Caption); Assert.AreEqual("gw level", quantity.Unit.Caption); Assert.AreEqual(1, quantity.Unit.Dimension.GetPower(DimensionBase.Length)); Assert.AreEqual(0, quantity.Unit.Dimension.GetPower(DimensionBase.Time)); Assert.AreEqual(1, quantity.Unit.ConversionFactorToSI); // Check element set IElementSet gridSet = gwLevel.ElementSet(); CheckRegularGridElmtSet(gridSet); } { // Check the ground water inflow input ITimeSpaceInput gwInput = lc.Inputs[2] as ITimeSpaceInput; Assert.IsNotNull(gwInput); Assert.AreEqual("Grid.Inflow", gwInput.Id); // Check quantity IQuantity quantity = gwInput.ValueDefinition as IQuantity; Assert.IsNotNull(quantity); Assert.AreEqual("Inflow", quantity.Caption); Assert.AreEqual("Discharge", quantity.Unit.Caption); Assert.AreEqual(3, quantity.Unit.Dimension.GetPower(DimensionBase.Length)); Assert.AreEqual(-1, quantity.Unit.Dimension.GetPower(DimensionBase.Time)); Assert.AreEqual(0.001, quantity.Unit.ConversionFactorToSI); // Check element set IElementSet gridSet = gwInput.ElementSet(); CheckRegularGridElmtSet(gridSet); } }
public static ITimeSet TimeExtent(this IBaseLinkableComponent component) { ITimeSpaceComponent tsComponent = component as ITimeSpaceComponent; if (tsComponent != null) { return(tsComponent.TimeExtent); } throw new NotSupportedException("The component needs to be an ITimeSpaceComponent"); }
public BaseExchangeItem(IIdentifiable identity, IBaseLinkableComponent component, IValueDefinition iValueDefinition, IValueSetConverter iValueSetConverter) : base(identity, component, iValueDefinition) { // _componentId = _component != null ? _component.Id : string.Empty; _valueSetConverter = iValueSetConverter; if (_valueSetConverter != null) _valueSetConverter.ExchangeItem = this; }
public static ITimeSpaceOutput FindOutputItem(IBaseLinkableComponent componentInstance, string outputItemId) { foreach (ITimeSpaceOutput outputItem in componentInstance.Outputs) { if (outputItem.Id.Equals(outputItemId)) { return(outputItem); } } throw new Exception("Output item \"" + outputItemId + "\" not found in component " + componentInstance.Id); }
public static bool Update(ITimeSpaceOutput output, IBaseExchangeItem basequerySpecifier) { ITimeSpaceExchangeItem querySpecifier = basequerySpecifier as ITimeSpaceExchangeItem; if (querySpecifier == null) { throw new ArgumentException("querySpecifier must be an ITimeSpaceExchangeItem - add an adaptor"); } // Time set of query must be defined and have at least 1 time if (querySpecifier.TimeSet == null || querySpecifier.TimeSet.Times == null || querySpecifier.TimeSet.Times.Count == 0) { throw new Exception("Given the TimeSet of output item \"" + output.Id + "\", it can not produce one set of values for \"" + querySpecifier.Id + "\""); } // Output time set must be defined if (output.TimeSet == null || output.TimeSet.Times == null) { throw new Exception("Invalid time specifier in output item \"" + output.Id + "\" for in updating according to a time specification" + querySpecifier.Id); } // Compute until this time is available double queryTimeMjd = querySpecifier.TimeSet.Times[0].End().StampAsModifiedJulianDay; // The current available time from the output item double availableTimeMjd = Double.NegativeInfinity; if (output.TimeSet.Times.Count > 0) { availableTimeMjd = output.TimeSet.Times[output.TimeSet.Times.Count - 1].End().StampAsModifiedJulianDay; } // Update component until querytime is available // If component is "busy" (LinkableComponentStatus.Updating), the // component will not be updated. IBaseLinkableComponent component = output.Component; while ((component.Status == LinkableComponentStatus.Valid || component.Status == LinkableComponentStatus.Updated) && availableTimeMjd + Time.EpsilonForTimeCompare < queryTimeMjd) { component.Update(); availableTimeMjd = output.TimeSet.Times[output.TimeSet.Times.Count - 1].End().StampAsModifiedJulianDay; } // Return true if component was updated up until queryTimeMjd return(availableTimeMjd + Time.EpsilonForTimeCompare >= queryTimeMjd); }
void RunProgress(object sender, ProgressChangedEventArgs e) { if (e.UserState != null && (e.UserState is CompositionRun.State)) { CompositionRun.State state = (CompositionRun.State)e.UserState; ProgressStatus currStatus = status[state.OprIndex]; int?progress = state.Progress; if (progress != null && progress.Value > currStatus.Progress) { IBaseLinkableComponent iLC = state.StatusArgs != null ? state.StatusArgs.LinkableComponent : state.ExchangeArgs.ExchangeItem.Component; currStatus.ComponentStatus = iLC != null?iLC.Status.ToString() : ""; currStatus.LastUpdated = state.LastEventUpdate; currStatus.Progress = progress.Value; if (state.OprIndex == _nOprIndexTrigger && progressBarRun.Value != progress.Value) { progressBarRun.Value = progress.Value; UpdateTitleText(progress); _timeSpan = DateTime.Now - _startTime; string elapsed = string.Format("{0},{1},{2}.{3}", _timeSpan.Hours, _timeSpan.Minutes, _timeSpan.Seconds, _timeSpan.Milliseconds); labelMessage.Text = string.Format("Running [{0}%]\r\nElapsed {1}", progress.Value, elapsed); } dataGridViewStatus.InvalidateRow(state.OprIndex); } _logCache.Add(state); } }
public BaseExchangeItem(IBaseLinkableComponent component, XElement xElement, IDocumentAccessor accessor) : base(Persistence.Identity.Parse(xElement.Elements(Persistence.Identity.XName).Single(), accessor)) { Contract35.Requires(xElement.Name == BaseExchangeItem.XName); Component = component; // _componentId = Utilities.Xml.GetAttribute(xElement, "componentId"); if (xElement.Elements(Persistence.ValueDefinition.XName).SingleOrDefault() != null) ValueDefinition = Persistence.ValueDefinition.Parse( xElement.Element(Persistence.ValueDefinition.XName), accessor); _valueSetConverter = null; foreach (XElement xUserVariable in xElement.Elements("UserVariable")) _userVariables.Add( Utilities.Xml.GetAttribute(xUserVariable, "key"), Utilities.Xml.GetAttribute(xUserVariable, "value")); }
public void InitialiseAsNative(string id, IBaseLinkableComponent source) { _id = id; _modelCaption = source.Caption; _is3rdParty = false; foreach (IAdaptedOutputFactory factory in source.AdaptedOutputFactories) { if (factory.Id == id) { _type = factory.GetType(); _assembly = new FileInfo(_type.Assembly.Location); _factory = factory; return; } } throw new ArgumentException(string.Format( "Cannot find adapter factory \"{0}\" in model \"{1}\"", id, source.Caption)); }
public void Initialise(oprConnectionDecoratorFactory opr, IBaseLinkableComponent source, DirectoryInfo oprPath) { if (opr.id != string.Empty || opr.assembly == "SourceComponent") { InitialiseAsNative(opr.id, source); } else // 3rd party { FileInfo assembly; if (!Path.IsPathRooted(opr.assembly)) { assembly = new FileInfo( Path.Combine(oprPath.FullName, opr.assembly)); } else { assembly = new FileInfo(opr.assembly); } InitialiseAs3rdParty(assembly, opr.type); } }
public static XElement Persist( IBaseLinkableComponent component, SupportedPlatforms platforms, IDocumentAccessor accessor) { // Original intention was to filter out arguments that were read only or // set explicitly to their default values to simplify what user sees by reducing // verbosity. However, components that aggregate other components might need to process // all the aggregated component arguments before those aggregated components ever get // instantiated (when defaults etc. would normally become visible). // Hence, welcome verbosity my DEAR old friend. Contract.Requires(component != null, "component != null"); var args = component .Arguments .Select(a => ArgumentValueGet(a, accessor)); return Persist(component, platforms, args, accessor); }
public static bool OmiArgumentValuesSet( IBaseLinkableComponent component, List<Argument> arguments, IDocumentAccessor accessor, List<IReport> reports) { foreach (var argument in arguments) { var arg = component.Arguments .Where(a => a.Id == argument.Key) .SingleOrDefault(); if (arg == null) arg = component.Arguments .Where(a => a.Caption == argument.Key) .SingleOrDefault(); if (arg != null) ArgumentValueSet(arg, argument, reports, accessor); else reports.Add(Report.Warning(Report.ResourceIds.InvalidOmiArgumentKey, "Cannot find component argument from OMI Key", argument.Key)); } return !reports.Any(r => r.Severity == ReportSeverity.Error); }
public static bool Instantiate( ExternalType componentType, SupportedPlatforms platforms, List<IReport> reports, out IBaseLinkableComponent component) { Contract.Requires(componentType != null, "componentType != null"); Contract.Requires(reports != null, "reports != null"); component = null; Type type; try { component = componentType .CreateInstance(out type) as IBaseLinkableComponent; } catch (System.Exception e) { reports.Add(Report.Error(Report.ResourceIds.Instantiation, "Cannot instantiate IBaseLinkableComponent", e.Message)); return false; } if (component == null) { reports.Add(Report.Error(Report.ResourceIds.Instantiation, "Cannot instantiate IBaseLinkableComponent", type.ToString())); return false; } return true; }
public void InputOutputTests() { GWModelLC gwlc = new GWModelLC(); IBaseLinkableComponent lc = gwlc; List<IArgument> arguments = CreateTestArguments(); lc.Initialize(arguments); IElementSet elementSet = ((ITimeSpaceExchangeItem)lc.Inputs[2]).ElementSet(); Quantity dischargeQuantity = new Quantity(new Unit(PredefinedUnits.CubicMeterPerSecond), null, "Discharge"); Quantity waterlevelQuantity = new Quantity(new Unit(PredefinedUnits.Meter), null, "Water Level"); ElementSet idBasedElementSetA = new ElementSet(null, "ElmSet-A", ElementType.IdBased); idBasedElementSetA.AddElement(new Element("elm-1")); Input waterLevelTriggerInput = new Input("Water level, to be retrieved from some output item", waterlevelQuantity, elementSet); waterLevelTriggerInput.TimeSet = new TimeSet(); SimpleOutput dischargeOutput = new SimpleOutput("Discharge, to be sent to GW model", dischargeQuantity, elementSet); dischargeOutput.ConstOutput = 6; dischargeOutput.TimeSet = new TimeSet(); ITimeSpaceInput gwInflow = UTHelper.FindInputItem(lc, "Grid.Inflow"); ITimeSpaceOutput gwLevel = UTHelper.FindOutputItem(lc, "Grid.gwLevel"); // Connect discharge gwInflow.Provider = dischargeOutput; dischargeOutput.AddConsumer(gwInflow); // Connect triggering input gwLevel.AddConsumer(waterLevelTriggerInput); lc.Validate(); lc.Prepare(); // specify query times double firstTriggerGetValuesTime = gwLevel.TimeSet.Times[0].StampAsModifiedJulianDay; double secondTriggerGetValuesTime = firstTriggerGetValuesTime + 3; double thirdTriggerGetValuesTime = firstTriggerGetValuesTime + 5; // check initial values Assert.AreEqual(8, gwLevel.Values.Values2D[0].Count); Assert.AreEqual(-10, (double)gwLevel.Values.GetValue(0, 0)); ITimeSpaceValueSet values; // get values for initial time, therefor intial values waterLevelTriggerInput.TimeSet.SetSingleTime(new Time(firstTriggerGetValuesTime)); values = gwLevel.GetValues(waterLevelTriggerInput); Assert.AreEqual(-10, values.GetValue(0, 0), "value for first query time"); // get values for second query time: -10 : base gw level. // 10 : storageHeight is multiplied by a factor of 10 // 3 days, 6 constant inflow, 3600*24 seconds in a day, 1000 L/M3, (100 x 200) grid cell size waterLevelTriggerInput.TimeSet.SetSingleTime(new Time(secondTriggerGetValuesTime)); values = gwLevel.GetValues(waterLevelTriggerInput); Assert.AreEqual(-10.0 + 10 * 3 * 6.0 * 60 * 60 * 24 / 1000 / (100 * 200), values.GetValue(0, 0), "value for first query time"); // get values for second query time: // 10 : storageHeight is multiplied by a factor of 10 // 5 days, 6 constant inflow, 3600*24 seconds in a day, 1000 L/M3, (100 x 200) grid cell size waterLevelTriggerInput.TimeSet.SetSingleTime(new Time(thirdTriggerGetValuesTime)); values = gwLevel.GetValues(waterLevelTriggerInput); Assert.AreEqual(-10.0 + 10 * 5 * 6.0 * 60 * 60 * 24 / 1000 / (100 * 200), values.GetValue(0, 0), "value for first query time"); lc.Finish(); }
public override ITimeSpaceValueSet GetValues(IBaseExchangeItem querySpecifier) { ITimeSpaceExchangeItem timeSpaceQuery = querySpecifier as ITimeSpaceExchangeItem; if (timeSpaceQuery == null) { throw new ArgumentException("querySpecifier must be an ITimeSpaceExchangeItem - add an adaptor"); } if (timeSpaceQuery.TimeSet == null || timeSpaceQuery.TimeSet.Times == null || timeSpaceQuery.TimeSet.Times.Count == 0) { throw new Exception("Invalid query specifier \"" + timeSpaceQuery.Id + "\" for in GetValues() call to time decorater " + Id); } // Determinee query time and currently available time double queryTimeAsMJD = timeSpaceQuery.TimeSet.Times[timeSpaceQuery.TimeSet.Times.Count - 1].StampAsModifiedJulianDay + timeSpaceQuery.TimeSet.Times[timeSpaceQuery.TimeSet.Times.Count - 1].DurationInDays; double availableTimeAsMJD = Double.NegativeInfinity; IList <ITime> currentTimes = TimeSet.Times; if (currentTimes.Count > 0) { availableTimeAsMJD = currentTimes[currentTimes.Count - 1].StampAsModifiedJulianDay + currentTimes[currentTimes.Count - 1].DurationInDays; } // Check if we need to update if (availableTimeAsMJD < queryTimeAsMJD) { // TODO (JGr): output item should not do the actual update of the component? if (Adaptee == null) { throw new Exception("Can not update, no parent output defined, calling GetValues() of time bufferer " + Id); } if (_adaptee.TimeSet == null || _adaptee.TimeSet.Times == null) { throw new Exception("Invalid time specifier in decorated output item \"" + Adaptee.Id + "\" for in GetValues() call to time decorater " + Id); } // Update as far as needed. IBaseLinkableComponent linkableComponent = Adaptee.Component; while ((linkableComponent.Status == LinkableComponentStatus.Valid || linkableComponent.Status == LinkableComponentStatus.Updated) && availableTimeAsMJD < queryTimeAsMJD) { linkableComponent.Update(); // Determine newly available time IList <ITime> parentTimes = _adaptee.TimeSet.Times; availableTimeAsMJD = parentTimes[parentTimes.Count - 1].StampAsModifiedJulianDay + parentTimes[parentTimes.Count - 1].DurationInDays; } } // Return the values for the required time(s) IList <IList <double> > resultValues = new List <IList <double> >(); if (timeSpaceQuery.TimeSet != null && timeSpaceQuery.TimeSet.Times != null) { for (int t = 0; t < timeSpaceQuery.TimeSet.Times.Count; t++) { resultValues.Add(new List <double>()); ITime queryTime = timeSpaceQuery.TimeSet.Times[t]; List <double> valuesForTimeStep = _buffer.GetValues(queryTime); foreach (double d in valuesForTimeStep) { resultValues[t].Add(d); } } } return(new TimeSpaceValueSet <double>(resultValues)); }
public InputSpaceTimeUserVariables(IIdentifiable identity, IBaseLinkableComponent component, IValueDefinition iValueDefinition, ISpatialDefinition iSpatialDefinition, string engineVariable, double missingValue, int elementCount) : base(identity, iValueDefinition, iSpatialDefinition, component, new ValueSetConverterTimeEngineDouble(engineVariable, missingValue, elementCount, ValueSetConverterTimeRecordBase<double>.InterpolationTemporal.Linear)) { UserVariables = new Dictionary<string, string>(); }
public static XElement Persist( IBaseLinkableComponent component, SupportedPlatforms platforms, IEnumerable<Argument> argumentsOmi, IDocumentAccessor accessor) { Contract.Requires(component != null, "component != null"); Contract.Requires(argumentsOmi != null, "arguments != null"); var location = new Uri(component.GetType().Assembly.Location); if (accessor != null && accessor.Uri != null) location = accessor.Uri.MakeRelativeUri(location); return new XElement(NamespaceOpenMIv2 + "LinkableComponent", new XAttribute("Type", component.GetType().ToString()), new XAttribute("Assembly", location.ToString()), new XElement(NamespaceOpenMIv2 + "Arguments", argumentsOmi.Select(a => a.Persist(accessor))), Platforms.Persist(platforms, accessor)); }
/// <summary> /// Apply the arguments in the <paramref name="arguments"/> list to the <paramref name="component"/>. /// <para> /// It searches through all the <see cref="IBaseLinkableComponent.Arguments"/> of the /// <paramref name="component"/> and sets the value for those with id's from the /// <paramref name="arguments"/>. /// </para> /// <para> /// If an argument in the <paramref name="arguments"/> list comes with an id that does not /// exist in the arguments of the component, an exception is thrown. /// </para> /// </summary> /// <param name="component">Component to set arguments to</param> /// <param name="arguments">Arguments to set</param> public static void ApplyArguments(this IBaseLinkableComponent component, IList <IArgument> arguments) { component.Arguments.ApplyArguments(arguments); }
/// <summary> /// Similar to the "old"/deprecated initialise method for an <see cref="IBaseLinkableComponent"/>. /// <para> /// It will call first <see cref="ApplyArguments"/>, and then call <see cref="IBaseLinkableComponent.Initialize()"/> /// </para> /// </summary> /// <param name="component">Component to initialise</param> /// <param name="arguments">Arguments to set to the component</param> public static void Initialize(this IBaseLinkableComponent component, IList <IArgument> arguments) { component.ApplyArguments(arguments); component.Initialize(); }
public static void ParseCachedComponent( IBaseLinkableComponent component, XElement xCachedComponent, IDocumentAccessor accessor, out IIdentifiable identity, out IEnumerable<IArgument> arguments, out IEnumerable<IBaseInput> inputs, out IEnumerable<IBaseOutput> outputs) { ValidElement(xCachedComponent, "Cache"); identity = Persistence.Identity.Parse( xCachedComponent.Element(Persistence.Identity.XName), accessor); arguments = Persistence.Arguments.Parse(xCachedComponent, accessor); inputs = xCachedComponent .Elements("IBaseInput") .Select(e => Persistence.Parse<IBaseInput>("IBaseInput", e, accessor)); outputs = xCachedComponent .Elements("IBaseOutput") .Select(e => Persistence.Parse<IBaseOutput>("IBaseOutput", e, accessor)); }
public OutputSpaceTimeComponent1(IIdentifiable identity, IBaseLinkableComponent component, IValueDefinition iValueDefinition, ISpatialDefinition iSpatialDefinition, string engineVariable, Vector3d<double> missingValue, int elementCount) : base(identity, iValueDefinition, iSpatialDefinition, component, new ValueSetConverterTimeEngineDoubleVector3dStandard1(engineVariable, missingValue, elementCount)) { }
public OutputSpaceTimeUserVariables(IIdentifiable identity, IBaseLinkableComponent component, IValueDefinition iValueDefinition, ISpatialDefinition iSpatialDefinition, string engineVariable, Vector3d<double> missingValue, int elementCount) : base(identity, iValueDefinition, iSpatialDefinition, component, new ValueSetConverterTimeEngineDoubleVector3d(engineVariable, missingValue, elementCount, ValueSetConverterTimeRecordBase<Vector3d<double>>.InterpolationTemporal.Linear)) { }
public ProgressStatus(IBaseLinkableComponent component) { this.component = component; }
public ValidationComponent(IBaseLinkableComponent component) : base(component) { _component = component; }