public void GetValuesOnTimeExtrapolator() { // create the component // connect query and output item // take care that component becomes valid and produces initial output for connected items ITimeSpaceComponent cf = RainRrCfComponents.CreateChannelFlowInstance("CF-2"); ITimeSpaceOutput selectedOutput = RainRrCfCompositions.FindOutputItem(cf, "node-2.waterlevel"); cf.Validate(); ITimeSpaceAdaptedOutput timeExtrapolator = (ITimeSpaceAdaptedOutput)RainRrCfCompositions.ConnectItemsUsingAdaptedOutput(cf, selectedOutput, _waterlevQueryItem, RainRrCfCompositions.timeExtrapolatorId); // set query time for getting values _dischargeQueryItem.TimeSet.SetSingleTimeStamp(new DateTime(2009, 3, 28, 12, 0, 0)); ITimeSpaceValueSet values = timeExtrapolator.GetValues(_dischargeQueryItem); Assert.IsNotNull(values, "values != null"); Assert.AreEqual(4001.5, (double)values.Values2D[0][0], "value[0] from GetValues 1"); _dischargeQueryItem.TimeSet.SetSingleTimeStamp(new DateTime(2009, 3, 29, 0, 0, 0)); values = timeExtrapolator.GetValues(_dischargeQueryItem); Assert.IsNotNull(values, "values != null"); Assert.AreEqual(4002.0, (double)values.Values2D[0][0], "value[0] from GetValues 1"); _dischargeQueryItem.TimeSet.SetSingleTimeStamp(new DateTime(2009, 3, 30, 0, 0, 0)); timeExtrapolator.GetValues(_dischargeQueryItem); Assert.AreEqual(4002.0, (double)values.Values2D[0][0], "value[0] from GetValues 1"); }
public static ITimeSpaceComponent OmiDeserializeAndInitialize(LinkableComponentComplexType omi, DirectoryInfo relativePath) { if (_assemblyLoader == null) { _assemblyLoader = new AssemblyLoader(); } object obj = _assemblyLoader.Load(omi.Assembly, omi.Type, relativePath); if (!(obj is ITimeSpaceComponent)) { throw new InvalidCastException("ILinkableComponent"); } ITimeSpaceComponent iLC = (ITimeSpaceComponent)obj; Dictionary <string, IArgument> args = new Dictionary <string, IArgument>(); if (iLC.Arguments != null) { foreach (IArgument iArg in iLC.Arguments) { args.Add(iArg.Id, iArg); } } if (omi.Arguments != null) { foreach (LinkableComponentComplexTypeArgument omiArg in omi.Arguments) { if (args.ContainsKey(omiArg.Key)) { if (args[omiArg.Key].ValueType == typeof(FileInfo) && !Path.IsPathRooted(omiArg.Value)) { omiArg.Value = Path.Combine(relativePath.FullName, omiArg.Value); } else if (args[omiArg.Key].ValueType == typeof(DirectoryInfo) && !Path.IsPathRooted(omiArg.Value)) { omiArg.Value = Path.Combine(relativePath.FullName, omiArg.Value); } args[omiArg.Key].ValueAsString = omiArg.Value; } else {// add anyway as string args.Add(omiArg.Key, new ArgumentString(omiArg.Key, omiArg.Value)); } } } // Suspect this could come in handy, so added // args.Add("OMI_PATH", new ArgumentDirectoryInfo("OMI_PATH", relativePath)); iLC.Initialize(new List <IArgument>(args.Values)); return(iLC); }
public void TestDummyModelFactoryGetInstances() { IOpenDaModelProvider linkableComponentFactory = new SimpleLinkableComponentFactory(); linkableComponentFactory.Initialize(".", "factory-arg1-value"); ITimeSpaceComponent modelInstance = linkableComponentFactory.CreateInstance(); modelInstance.Arguments[0].Value = "instance-arg1-value"; modelInstance.Initialize(); modelInstance.Validate(); modelInstance.Prepare(); IList <IBaseInput> inputs = modelInstance.Inputs; Assert.IsTrue(inputs.Count > 0, "At least one input"); IBaseInput input = inputs[0]; Assert.IsTrue(input != null, "Inputs[0] is IBaseInput"); IList <IBaseOutput> outputs = modelInstance.Outputs; Assert.IsTrue(outputs.Count > 0, "At least one output"); ITimeSpaceOutput output = outputs[0] as ITimeSpaceOutput; Assert.IsTrue(output != null, "Outputs[0] is ITimeSpaceOutput"); while (modelInstance.Status == LinkableComponentStatus.Updated) { modelInstance.Update(); } Assert.AreEqual(LinkableComponentStatus.Done, modelInstance.Status, "Status == Done"); modelInstance.Finish(); }
public void Init() { simpleRiver = new SimpleRiverEngineWrapper(); IArgument[] arguments = new IArgument[1]; arguments[0] = Argument.Create("FilePath", @"..\..\..\..\Data", true, "description"); simpleRiver.Initialize(arguments); }
public ModelInstance(ModelFactory myModelFactory, ITimeSpaceComponent openMIComponent) { _mSheTstep = 0; _openDaModelFactory = myModelFactory; _openMIComponent = openMIComponent; GetExchangeItemsFromOpenMIComponent(); _openMIComponent.Update(); }
private static void ConnectItems(ITimeSpaceComponent sourceComponentInstance, string outputItemId, ITimeSpaceComponent targetComponentInstance, string inputItemId) { ITimeSpaceOutput output = FindOutputItem(sourceComponentInstance, outputItemId); ITimeSpaceInput input = FindInputItem(targetComponentInstance, inputItemId); output.AddConsumer(input); }
public void InitialiseAs3rdParty(Type type, ITimeSpaceComponent source) { FileInfo assembly = new FileInfo(System.Reflection.Assembly.GetAssembly(type).Location); InitialiseAs3rdParty(assembly, type.FullName); _modelCaption = source.Caption; }
public void TreePopulate(TreeOptions options) { _linkableComponent = null; _treeOptions = options; _items.Clear(); TreeCreate(null); }
public IModelInstance GetInstance(string[] arguments, int outputLevel) { ITimeSpaceComponent timeSpaceComponent = _openMIModelFactory.CreateInstance(); //timeSpaceComponent.Initialize(); //timeSpaceComponent.Validate(); //timeSpaceComponent.Prepare(); return(new ModelInstance(this, timeSpaceComponent)); }
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 void Initialise(ITimeSpaceComponent iLC, IValueDefinition iVD, IElementSet iES) { _iValueDefinition = iVD; _iElementSet = iES; _iComponent = iLC; _iDescribable = new Describable( string.Format("{0}, {1}", _iValueDefinition.Caption, _iElementSet.Caption), string.Format("{0}, {1}", _iValueDefinition.Description, _iElementSet.Description)); }
//private static void RunLoopDriven(IEnumerable<ITimeSpaceComponent> components) //{ // bool atLeastOneComponentFinished = false; // foreach (ITimeSpaceComponent component in components) // { // component.CascadingUpdateCallsDisabled = true; // } // const int maxNumLoopCalls = 10000; // int numLoopCalls = 0; // while (!atLeastOneComponentFinished && numLoopCalls < maxNumLoopCalls) // { // foreach (ITimeSpaceComponent component in components) // { // component.Update(); // } // // check if components are finished // atLeastOneComponentFinished = CheckIfComponentsAreFinished(components); // numLoopCalls++; // } // if (numLoopCalls == maxNumLoopCalls) // { // throw new Exception(_MaxLoopCallsExceeded); // } //} private static void RunPullDriven(IEnumerable <ITimeSpaceComponent> components) { ITimeSpaceComponent componentAtEndOfChain = RainRrCfCompositions.FindComponent(components, RainRrCfCompositions.channelFlowId); while (!(componentAtEndOfChain.Status == LinkableComponentStatus.Done || componentAtEndOfChain.Status == LinkableComponentStatus.Failed)) { componentAtEndOfChain.Update(); } }
public void GetValues1A() { LinkableEngine riverModelLE = CreateRiverModel(); ITimeSpaceComponent riverModelLC = riverModelLE; // initialize model List <IArgument> riverArguments = CreateRiverModelArguments(riverModelLC); riverArguments.Add(Argument.Create("ModelID", "RiverModel", true, "argument")); riverArguments.Add(Argument.Create("TimeStepLength", 3600)); riverModelLC.Arguments.ApplyArguments(riverArguments); riverModelLC.Initialize(); // Link output and trigger with a time buffer ITimeSpaceOutput output = (ITimeSpaceOutput)riverModelLC.Outputs[2]; IAdaptedOutputFactory adaptedOutputFactory = riverModelLC.AdaptedOutputFactories[0]; IIdentifiable[] adaptedOutputIds = adaptedOutputFactory.GetAvailableAdaptedOutputIds(output, _queryItem1); ITimeSpaceAdaptedOutput adaptedOutput = (ITimeSpaceAdaptedOutput) adaptedOutputFactory.CreateAdaptedOutput(adaptedOutputIds[0], output, _queryItem1); adaptedOutput.AddConsumer(_queryItem1); riverModelLC.Validate(); Assert.IsTrue(riverModelLC.Status == LinkableComponentStatus.Valid); riverModelLC.Prepare(); Assert.IsTrue(riverModelLC.Status == LinkableComponentStatus.Updated); // specify query times double firstTriggerGetValuesTime = riverModelLE.CurrentTime.StampAsModifiedJulianDay; double secondTriggerGetValuesTime = firstTriggerGetValuesTime + 2; double thirdTriggerGetValuesTime = firstTriggerGetValuesTime + 4.3; // check initial values Assert.AreEqual(1, output.Values.Values2D[0].Count, "#values for " + output.Id); Assert.AreEqual(7.0, (double)output.Values.GetValue(0, 0), "Value[0] as property"); // get values for specified query times _queryItem1.TimeSet.SetSingleTimeStamp(firstTriggerGetValuesTime); ITimeSpaceValueSet values = adaptedOutput.GetValues(_queryItem1); Assert.AreEqual(7.0, values.GetValue(0, 0), "value for first query time"); // only runoff inflow, 10 L/s _queryItem1.TimeSet.SetSingleTimeStamp(secondTriggerGetValuesTime); values = adaptedOutput.GetValues(_queryItem1); Assert.AreEqual(35.0 / 4.0, values.GetValue(0, 0), "value for second query time"); // still only runoff inflow, 10 L/s _queryItem1.TimeSet.SetSingleTimeStamp(thirdTriggerGetValuesTime); values = adaptedOutput.GetValues(_queryItem1); Assert.AreEqual(35.0 / 4.0, values.GetValue(0, 0), "value for third query time"); riverModelLC.Finish(); }
public void TreePopulate(ITimeSpaceComponent linkableComponent, TreeOptions options) { _linkableComponent = linkableComponent; _treeOptions = options; _items = _treeOptions.IsSource ? Sources(linkableComponent) : Targets(linkableComponent); TreeCreate(null); }
public List <IArgument> CreateRiverModelArguments(ITimeSpaceComponent model) { if (model is SimpleRiverEngineWrapper) { var arguments = new List <IArgument>(); arguments.Add(Argument.Create("FilePath", @"..\..\..\..\..\Examples\SimpleFortranRiver\Data", false, "FilePath")); arguments.Add(Argument.Create("SimFileName", @"SimpleRiverUT.sim", false, "FilePath")); return(arguments); } return(_netFactory.CreateRiverModelArguments(model)); }
public static ITimeSpaceInput FindInputItem(ITimeSpaceComponent componentInstance, string inputItemId) { foreach (ITimeSpaceInput inputItem in componentInstance.Inputs) { if (inputItem.Id.Equals(inputItemId)) { return(inputItem); } } throw new Exception("Input item \"" + inputItemId + "\" not found in component " + componentInstance.Id); }
public static ITimeSpaceOutput FindOutputItem(ITimeSpaceComponent 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); }
private static void ConnectItemsWithTimeInterpolator(ITimeSpaceComponent sourceComponentInstance, string outputItemId, ITimeSpaceComponent targetComponentInstance, string inputItemId) { ITimeSpaceOutput output = FindOutputItem(sourceComponentInstance, outputItemId); ITimeSpaceInput input = FindInputItem(targetComponentInstance, inputItemId); IAdaptedOutputFactory derivedOutputFactory = sourceComponentInstance.AdaptedOutputFactories[0]; IIdentifiable[] derivedOutputIdentifiers = derivedOutputFactory.GetAvailableAdaptedOutputIds(output, input); IBaseAdaptedOutput timeInterpolator = derivedOutputFactory.CreateAdaptedOutput(derivedOutputIdentifiers[0], output, input); }
public static void ConnectItemsUsingAdaptedOutput(ITimeSpaceComponent sourceComponentInstance, string outputItemId, ITimeSpaceComponent targetComponentInstance, string inputItemId, string derivedOutputName) { ITimeSpaceOutput output = FindOutputItem(sourceComponentInstance, outputItemId); ITimeSpaceInput input = FindInputItem(targetComponentInstance, inputItemId); ConnectItemsUsingAdaptedOutput(sourceComponentInstance, output, input, derivedOutputName); }
public void CreateInitializeTest() { ITimeSpaceComponent riverModel = CreateRiverModel(); Assert.IsTrue(riverModel.Status == LinkableComponentStatus.Created); List <IArgument> arguments = CreateRiverModelArguments(riverModel); arguments.Add(new ArgumentBool("flowItemsAsSpan", _flowItemsAsSpan)); riverModel.Arguments.ApplyArguments(arguments); riverModel.Initialize(); Assert.IsTrue(riverModel.Status == LinkableComponentStatus.Initialized); Assert.AreEqual("RiverModel Default Model ID", riverModel.Id); }
public void CreateModels() { _riverModel = new RiverModelLC(); Assert.IsTrue(_riverModel.Status == LinkableComponentStatus.Created); _riverModel.Initialize(); Assert.IsTrue(_riverModel.Status == LinkableComponentStatus.Initialized); Assert.AreEqual("RiverModel Default Model ID", _riverModel.Id); _gwModel = new GWModelLC(); Assert.IsTrue(_gwModel.Status == LinkableComponentStatus.Created); _gwModel.Initialize(); Assert.IsTrue(_gwModel.Status == LinkableComponentStatus.Initialized); Assert.AreEqual("GWModelLC", _gwModel.Id); }
private static IDictionary <string, ITimeSpaceComponent> CreateComponentInstances() { // create the involved components (rainfall measurements, rainfall runoff, 1D channel flow IDictionary <string, ITimeSpaceComponent> components = new Dictionary <string, ITimeSpaceComponent>(); ITimeSpaceComponent rainfallMeasurementsInstance = RainRrCfComponents.CreateRainfallMeasurementsInstance(rainfallMeasurementsId); ITimeSpaceComponent rainfallRunoffInstance = RainRrCfComponents.CreateRainfallRunoffInstance(rainfallRunoffId); ITimeSpaceComponent channelFlowLC = RainRrCfComponents.CreateChannelFlowInstance(channelFlowId); components.Add(rainfallMeasurementsId, rainfallMeasurementsInstance); components.Add(rainfallRunoffId, rainfallRunoffInstance); components.Add(channelFlowId, channelFlowLC); return(components); }
/// <summary> /// Find the adaptor with the provided id. /// </summary> /// <param name="component">Component to find adaptor in</param> /// <param name="adaptorId">Id of adaptor to search for</param> /// <param name="output">Output item to find adaptor for.</param> /// <param name="input">Input item to find adaptor for. Can be null</param> /// <returns>Returns adaptor with id, or null if not found</returns> public static ITimeSpaceAdaptedOutput FindAdaptor(this ITimeSpaceComponent component, string adaptorId, ITimeSpaceOutput output, ITimeSpaceInput input) { foreach (IAdaptedOutputFactory adaptorFactory in component.AdaptedOutputFactories) { foreach (IIdentifiable availId in adaptorFactory.GetAvailableAdaptedOutputIds(output, input)) { if (string.Equals(availId.Id, adaptorId, StringComparison.OrdinalIgnoreCase)) { IBaseAdaptedOutput adaptor = adaptorFactory.CreateAdaptedOutput(availId, output, input); return(adaptor as ITimeSpaceAdaptedOutput); } } } return(null); //throw new Exception("Could not find adaptor with id = '" + id + "'"); }
static List <UIExchangeItem> Targets(ITimeSpaceComponent target) { if (target == null) { return(new List <UIExchangeItem>()); } List <UIExchangeItem> targets = new List <UIExchangeItem>(target.Inputs.Count); foreach (ITimeSpaceInput item in target.Inputs) { targets.Add(new UIInputItem(item)); } return(targets); }
static List <UIExchangeItem> Sources(ITimeSpaceComponent source) { if (source == null) { return(new List <UIExchangeItem>()); } List <UIExchangeItem> sources = new List <UIExchangeItem>(source.Outputs.Count); foreach (ITimeSpaceOutput item in source.Outputs) { sources.Add(new UIOutputItem(item)); } return(sources); }
/// <summary> /// Find the output item with the provided id. /// </summary> /// <param name="component">Component to find output item in</param> /// <param name="id">Id of output item to search for</param> /// <returns>Returns output item with id, or null if not found</returns> public static ITimeSpaceOutput FindOutputItem(this ITimeSpaceComponent component, string id) { foreach (IBaseOutput input in component.Outputs) { if (string.Equals(input.Id, id, StringComparison.OrdinalIgnoreCase)) { ITimeSpaceOutput timeSpaceInput = input as ITimeSpaceOutput; if (timeSpaceInput == null) { throw new Exception("Found exchange item, but it was not a TimeSpaceOutput, id = '" + id + "'"); } return(timeSpaceInput); } } return(null); //throw new Exception("Could not find output item with id = '" + id + "'"); }
/// <summary> /// This method is called in <see cref="Run">Run</see> method. /// </summary> private void RunThreadFunction() { ITimeSpaceComponent triggered = GetTrigger(); //Debug.Assert(trigger != null); //Thread.Sleep(0); try { foreach (UIModel iComponent in _models) { iComponent.LinkableComponent.Initialize(); iComponent.LinkableComponent.Prepare(); } // See comment on WaitingForFinish additional state while (triggered.Status != LinkableComponentStatus.Finishing && triggered.Status != LinkableComponentStatus.Failed) { triggered.Update(); } foreach (UIModel iComponent in _models) { iComponent.LinkableComponent.Finish(); if (iComponent.LinkableComponent is IDisposable) { ((IDisposable)iComponent.LinkableComponent).Dispose(); } } } catch (Exception e) { log.Error("Error while running components", e); } finally { _running = false; } }
public void TreePopulate(UIConnection connection, TreeOptions options) { ITimeSpaceComponent source = connection.SourceModel.LinkableComponent; ITimeSpaceComponent target = connection.TargetModel.LinkableComponent; List <UIOutputItem> extraSources = new List <UIOutputItem>(); UIOutputItem src; foreach (Link pair in connection.Links) { src = pair.Source; //while (src.Parent != null) // decorator //{ // extraSources.Add(src); // src = src.Parent; //} } TreePopulate(source, target, extraSources, options); }
public void TreePopulate(ITimeSpaceComponent source, ITimeSpaceComponent target, List <UIOutputItem> extraSources, TreeOptions options) { _treeOptions = options; List <UIExchangeItem> sources = Sources(source); List <UIExchangeItem> targets = Targets(target); UIExchangeItem toCheck = null; if (extraSources != null) { sources.AddRange(extraSources.ToArray()); if (extraSources.Count > 0) { toCheck = extraSources[0]; } } Filter(sources, targets); if (_treeOptions.IsSource) { _linkableComponent = source; _items = sources; } else if (_treeOptions.IsTarget) { _linkableComponent = target; _items = targets; } else { _linkableComponent = null; _items = new List <UIExchangeItem>(); } TreeCreate(toCheck); }
public static IBaseAdaptedOutput ConnectItemsUsingAdaptedOutput(ITimeSpaceComponent sourceComponentInstance, ITimeSpaceOutput output, ITimeSpaceInput input, string adaptedOutputId) { IAdaptedOutputFactory adaptedOutputFactory = sourceComponentInstance.AdaptedOutputFactories[0]; IIdentifiable[] adaptedOutputIds = adaptedOutputFactory.GetAvailableAdaptedOutputIds(output, input); IIdentifiable adaptedOutputIdentifier = null; foreach (IIdentifiable identifier in adaptedOutputIds) { if (identifier.Id.StartsWith(adaptedOutputId)) { adaptedOutputIdentifier = identifier; } } if (adaptedOutputIdentifier == null) { throw new Exception("AdaptedOutput with name \"" + adaptedOutputId + "\" not found"); } IBaseAdaptedOutput timeExtrapolator = adaptedOutputFactory.CreateAdaptedOutput(adaptedOutputIdentifier, output, input); return(timeExtrapolator); }