/// <summary> /// Retrieves data from the providing LinkableComponent as defined /// in the Link and sets this data in the engine /// </summary> public virtual void UpdateInput() { ITime inputTime = this._engine.GetInputTime(link.TargetQuantity.ID, link.TargetElementSet.ID); if (inputTime != null) { SendEvent(EventType.TargetBeforeGetValuesCall, this.link.TargetComponent); IScalarSet sourceValueSet = (IScalarSet)link.SourceComponent.GetValues(inputTime, link.ID); //The input values set is copied in ordet to avoid the risk that it is changed be the provider. double targetMissValDef = this._engine.GetMissingValueDefinition(); ScalarSet targetValueSet = new ScalarSet(sourceValueSet); for (int i = 0; i < sourceValueSet.Count; i++) { if (!sourceValueSet.IsValid(i)) { targetValueSet.data[i] = targetMissValDef; } } targetValueSet.MissingValueDefinition = targetMissValDef; targetValueSet.CompareDoublesEpsilon = targetMissValDef / 1.0e+10; SendEvent(EventType.TargetAfterGetValuesReturn, this.link.TargetComponent); this.Engine.SetValues(link.TargetQuantity.ID, link.TargetElementSet.ID, targetValueSet); } }
public void PerformTimeStep() { Debug.WriteLine("\n\n---------------------------------------------------"); Debug.WriteLine("Running the 'PerformTimeStep' Test"); Debug.WriteLine("---------------------------------------------------"); //---- put data into IValueSets IValueSet temp = new ScalarSet(new double[1] { 19 }); IValueSet mintemp = new ScalarSet(new double[1] { 17 }); IValueSet maxtemp = new ScalarSet(new double[1] { 21 }); //---- set values hargreaves.SetValues("Temp", "Climate Station 01", temp); hargreaves.SetValues("Min Temp", "Climate Station 01", mintemp); hargreaves.SetValues("Max Temp", "Climate Station 01", maxtemp); //---- call perform time step hargreaves.PerformTimeStep(); //---- read calculated results double[] pet = ((ScalarSet)hargreaves.GetValues("PET", "Coweeta")).data; double chk = Math.Round(pet[0], 2); Assert.IsTrue(chk == 1.16, "The calculated value of " + chk.ToString() + " does not equal the known value of 1.16"); }
public IValueSet GetValues(ITime time, string linkID) { var values = MsheOrg.GetValues(time, linkID); var link = AlteredLinks[linkID]; if (link.SourceElementSet.ID == "BaseGrid") { ScalarSet scinner = new ScalarSet(values as IScalarSet); List <double> InnerValues = new List <double>(); foreach (int i in InnerIdeces) { InnerValues.Add(((ScalarSet)values).data[i]); } scinner.data = InnerValues.ToArray(); if (mappers.ContainsKey(linkID)) { return(mappers[linkID].MapValues(scinner)); } return(scinner); } return(values); }
public void CopyConstructorSpeed() { var random = new Random(); var values = new double[5000000]; for (var i = 0; i < 5000000; i++) { values[i] = random.Next(); } var scalarSet = new ScalarSet(values); // copying values var stopwatch = new Stopwatch(); stopwatch.Start(); values.Clone(); stopwatch.Stop(); var copyArrayTime = stopwatch.ElapsedMilliseconds; Trace.WriteLine("Copying array with 1M values took: " + copyArrayTime + " ms"); stopwatch.Reset(); stopwatch.Start(); new ScalarSet(scalarSet); stopwatch.Stop(); Trace.WriteLine("Copying scalar set with 1M values took: " + stopwatch.ElapsedMilliseconds + " ms"); var fraction = stopwatch.ElapsedMilliseconds / copyArrayTime; Assert.IsTrue(fraction < 1.1); }
public override bool PerformTimeStep() { //Get input values from another component ScalarSet invals = (ScalarSet)this.GetValues(_input_quantity, _output_elementset); double[] indata = invals.data; //create something to hold output double[] outdata = new double[indata.Length]; //do some computation... for (int i = 0; i < _seeds.Count; i++) { _seeds[i] += Convert.ToInt32(indata[i]); _rndNum = new Random(_seeds[i]); double r_number = Convert.ToDouble(_rndNum.Next()); //save values locally outdata[i] = r_number; //save the value for output _randomNumbers.Add(r_number); } //set output values for another component this.SetValues(_output_quantity, _output_elementset, new ScalarSet(outdata)); //advance time by one time step this.AdvanceTime(); return(true); }
public void TestPerformTimeStep() { PT_Evapotranspiration.PT_PET component = new PT_PET(); //Initialize Component System.Collections.Hashtable args = new System.Collections.Hashtable(); args.Add("ConfigFile", "../../../Source/PT_PETconfig.xml"); args.Add("DataFolder", "../../../data"); args.Add("OutDir", "../../../"); component.Initialize(args); //Define Inputs double[] NetRadiation = { 4, 17.28, 6, 7 }; component.SetValues("NSR", "NetRadiation", new ScalarSet(NetRadiation)); double[] temp = { 4.3, 25, 6.5, 7.6 }; component.SetValues("Temp", "T", new ScalarSet(temp)); double[] elevation = { 14, 0, 16, 17 }; component.SetValues("Elevation", "Z", new ScalarSet(elevation)); //Call perform timestep in the component class component.PerformTimeStep(); //retrieve values from the compenent class ScalarSet OutputValues = (ScalarSet)component.GetValues("PET", "pet"); ScalarSet OutputValues2 = (ScalarSet)component.GetValues("StandardizedET", "ETsz"); double[] PET = OutputValues.data; double[] ETsz = OutputValues2.data; //Call finish component.Finish(); }
/// <summary> /// Set values for: /// water level at outlet /// discharges /// property concentrations /// </summary> public void SetValues(string QuantityID, string ElementSetID, global::OpenMI.Standard.IValueSet values) { setValuesWatch.Start(); if (QuantityID == qtdOutletLevel.ID) { double waterLevel = ((ScalarSet)values).data[0]; mohidLandEngine.SetDownstreamWaterLevel(drainageNetworkInstanceID, waterLevel); } else if (QuantityID == qtdDischarges.ID) { ScalarSet flow = (ScalarSet)values; double[] flowValues = flow.data; mohidLandEngine.SetStormWaterModelFlow(runoffInstanceID, flow.Count, ref flowValues); } else if (QuantityID == qtdFlowFromStrom.ID) { ScalarSet flow = (ScalarSet)values; double[] flowvalues = flow.data; mohidLandEngine.SetStormWaterInflow(drainageNetworkInstanceID, flow.Count, ref flowvalues); } else //Concentration of properties { double concentration = ((ScalarSet)values).data[0]; int propertyID = Convert.ToInt32(QuantityID); mohidLandEngine.SetDownStreamConcentration(drainageNetworkInstanceID, propertyID, concentration); } setValuesWatch.Stop(); }
public IValueSet GetValues(ITime time, string linkID) { // covert time to a DateTime data type TimeStamp timestamp = (TimeStamp)time; DateTime dt = CalendarConverter.ModifiedJulian2Gregorian( (double)timestamp.ModifiedJulianDay); // write datetime to log file StreamWriter sr = new StreamWriter("hydrolink_log.txt", true); sr.WriteLine("get values request for time: " + dt.ToLongDateString() + " " + dt.ToLongTimeString()); sr.Flush(); //get scalar set IValueSet values = _buffervalues[linkID].GetValues(time); // write value set to log file ScalarSet ss = (ScalarSet)values; sr.Write("values set: "); sr.Flush(); for (int i = 0; i < ss.Count; ++i) { sr.Write(" " + ss.GetScalar(i).ToString() + " "); sr.Flush(); } sr.Write("\n"); sr.Close(); return(values); }
public void PerformTimeStepTest() { Evptrnsprtion.eT component = new eT(); //Initialize Component System.Collections.Hashtable args = new System.Collections.Hashtable(); args.Add("ConfigFile", "../../../Source/config.xml"); component.Initialize(args); //Define Inputs double[] NetRadiation = { 4, 5, 6, 7 }; component.SetValues("NSR", "NetRadiation", new ScalarSet(NetRadiation)); //Call perform timestep in the component class component.PerformTimeStep(); //retrieve values from the compenent class ScalarSet OutputValues = (ScalarSet)component.GetValues("PET", "pet"); ScalarSet OutputValues3 = (ScalarSet)component.GetValues("StandardizedET", "ETsz"); double[] PET = OutputValues.data; double[] ETsz = OutputValues3.data; }
public void PTS() { Console.WriteLine("\n ----- Beginning Perform-Time-Step -----"); System.Collections.Hashtable args = new System.Collections.Hashtable(); args.Add("ConfigFile", "./configTest.xml"); engine.Initialize(args); //Precipitation values in mm/hr, on 10 min intervals double[] p = new double[6] { 10, 20, 80, 100, 80, 10 }; Console.WriteLine("F \t\t\t dt \t\t i \t\t\t i*dt \t Cumulative_Storage \t Runoff"); for (int j = 0; j <= p.Length - 1; j++) { double[] P = new double[1] { p[j] }; IValueSet Precip = new ScalarSet(P); engine.SetValues("Rainfall", "Test", Precip); engine.PerformTimeStep(); ScalarSet Excess = (ScalarSet)engine.GetValues("Excess Rainfall", "Test"); } Console.WriteLine("\n ----- Perform-Time-Step finished Sucessfully -----"); }
/// <summary> /// Implementation of the same method in /// OpenMI.Standard.ILInkableComponent /// </summary> /// <param name="time">Time (ITimeSpan or ITimeStamp) for which values are requested</param> /// <param name="LinkID">LinkID associated to the requested values</param> /// <returns>The values</returns> public override IValueSet GetValues(ITime time, string LinkID) { try { CheckTimeArgumentInGetvaluesMethod(time); SendSourceAfterGetValuesCallEvent(time, LinkID); IValueSet engineResult = new ScalarSet(); int outputLinkIndex = -999; for (int i = 0; i < _smartOutputLinks.Count; i++) { if (((SmartOutputLink)_smartOutputLinks[i]).link.ID == LinkID) { outputLinkIndex = i; break; } } RunToTime(time, outputLinkIndex); engineResult = ((SmartOutputLink)_smartOutputLinks[outputLinkIndex]).GetValue(time); SendEvent(EventType.SourceBeforeGetValuesReturn); return(engineResult); } catch (System.Exception e) { string message = "Exception in LinkableComponent. ComponentID: "; message += this.ComponentID; throw new System.Exception(message, e); } }
public void Test_TimeStepping() { Debug.WriteLine("\n\n---------------------------------------------------"); Debug.WriteLine("Testing the Perform Time Step Method for Timestepping error"); Debug.WriteLine("---------------------------------------------------"); //initialize the component edu.SC.Models.Routing.Muskingum Routing = new edu.SC.Models.Routing.Muskingum(); System.Collections.Hashtable args = new System.Collections.Hashtable(); args.Add("ConfigFile", "ConfigTest_2reaches.xml"); Routing.Initialize(args); //Begin Perform Time Step Procedures //define the input hydrograph. //double[,] p = new double[16, 2] {{0.0,0},{800.0,0},{2000.0,0},{4200.0,0},{5200.0,0}, // {4400.0,0},{3200.0,0},{2500.0,0},{2000.0,0},{1500.0,0}, // {1000.0,0},{700.0,0},{400.0,0},{0.0,0},{0.0,0},{0.0,0}}; //define known muskingum routed vals, from example 9.3.2 //double[] vals = new double[16] { 0, 272, 1178, 2701, 4455, 4886, 4020, 3009, 2359, 1851, 1350, 918, 610, 276, 16, 1 }; //Queue<double> KnownAnswers = new Queue<double>(vals); //loop over all hydrograph values for (int j = 0; j <= 10000 - 1; j++) { Console.WriteLine("TimeStep " + Convert.ToString(j + 1)); double[] Array = new double[2]; //for (int k = 0; k <= p.GetLength(1) - 1; k++) //{ // //create array to hold the input hydrograph values for this timestep // Array[k] = p[j, k]; //} Array[0] = 1; Array[1] = 1; //Save input values to the Simple Model Wrappers DataTable using "SetValues" IValueSet Precip = new ScalarSet(Array); Routing.SetValues("Excess Rainfall", "Smith Branch", Precip); //Call Perform Time Step within the Muskingum routing component. Routing.PerformTimeStep(); //Retrieve the calculated outflow from the Simple Model Wrappers DataTable, by calling GetValues() ScalarSet Outflow = (ScalarSet)Routing.GetValues("Streamflow", "Smith Branch"); //Write the output results to the screen for (int i = 0; i <= Outflow.Count - 1; i++) { Console.WriteLine("Outlet: " + i.ToString() + "\t Outflow [cfs]: " + Outflow.data[i].ToString() + "\n"); } //Check to see if the computed values equal the known ones //Assert.IsTrue(Math.Round(Outflow.data[1], 0) == KnownAnswers.Dequeue()); } //Teardown the component Routing.Finish(); }
public void Process() { Console.WriteLine("\n ----- Beginning Perform-Time-Step -----"); //temperature values, celcius, on 60 min intervals double[] t = new double[6] { 8.17, 33.0, 32.6, 32.2, 27.5, 29.8 }; //Use the engine Console.WriteLine("Precipitable Water for Different Surface Temperature"); for (int j = 0; j < t.Count(); j++) { double[] T = new double[1] { t[j] }; IValueSet temp = new ScalarSet(T); engine.SetValues("T", "Temperature", temp); engine.PerformTimeStep(); ScalarSet Excess = (ScalarSet)engine.GetValues("P", "Precipitable Water"); } Console.WriteLine("\n ----- Perform-Time-Step finished Sucessfully -----"); }
/// <summary> /// Implementation of the same method in /// OpenMI.Standard.ILInkableComponent /// </summary> /// <param name="time">Time (ITimeSpan or ITimeStamp) for which values are requested</param> /// <param name="LinkID">LinkID associated to the requested values</param> /// <returns>The values</returns> public override IValueSet GetValues(ITime time, string LinkID) { try { CheckTimeArgumentInGetvaluesMethod(time); SendSourceAfterGetValuesCallEvent(time, LinkID); IValueSet engineResult = new ScalarSet(); int outputLinkIndex = -999; for (int i = 0; i < _smartOutputLinks.Count; i++) { if (((SmartOutputLink)_smartOutputLinks[i]).link.ID == LinkID) { outputLinkIndex = i; break; } } if (_isBusy == false) { //while(IsLater(time,_engineApiAccess.GetCurrentTime())) while (IsLater(time, ((SmartOutputLink)_smartOutputLinks[outputLinkIndex]).GetLastBufferedTime())) { _isBusy = true; //Update input links foreach (SmartInputLink smartInputLink in _smartInputLinks) { smartInputLink.UpdateInput(); } _isBusy = false; //Perform Timestep if (_engineApiAccess.PerformTimeStep()) { //Update buffer with engine values, Time is timestamp foreach (SmartOutputLink smartOutputLink in _smartOutputLinks) { smartOutputLink.UpdateBuffer(); } SendEvent(EventType.DataChanged); } } } engineResult = ((SmartOutputLink)_smartOutputLinks[outputLinkIndex]).GetValue(time); SendEvent(EventType.SourceBeforeGetValuesReturn); return(engineResult); } catch (System.Exception e) { string message = "Exception in LinkableComponent. ComponentID: "; message += this.ComponentID; throw new System.Exception(message, e); } }
public void Run(ITimeStamp time) { //IScalarSet scalarSet = new ScalarSet(); ScalarSet scalarSet = new ScalarSet((IScalarSet)_link.SourceComponent.GetValues(time, _link.ID)); _earliestInputTime.ModifiedJulianDay = time.ModifiedJulianDay; _resultsBuffer.AddValues(time, scalarSet); }
public void Equals() { double[] values = { 1.0, 2.0, 3.0 }; ScalarSet scalarSet2 = new ScalarSet(values); Assert.IsTrue(scalarSet.Equals(scalarSet2)); scalarSet2.data[1] = 2.5; Assert.IsFalse(scalarSet.Equals(scalarSet2)); }
public void RunSimulationWithInputAndOutput() { ITimeSpan modelSpan = mohidWaterEngineWrapper.GetTimeHorizon(); double now = modelSpan.Start.ModifiedJulianDay; Stopwatch win = new Stopwatch(); Stopwatch wout = new Stopwatch(); Stopwatch wengine = new Stopwatch(); while (now < modelSpan.End.ModifiedJulianDay) { DateTime currentTime = CalendarConverter.ModifiedJulian2Gregorian(now); DateTime intitalTime = CalendarConverter.ModifiedJulian2Gregorian( mohidWaterEngineWrapper.GetTimeHorizon().Start.ModifiedJulianDay); Console.WriteLine(currentTime.ToString()); wengine.Start(); mohidWaterEngineWrapper.PerformTimeStep(); wengine.Stop(); wout.Start(); //Gets outputs Items for (int i = 0; i < mohidWaterEngineWrapper.GetOutputExchangeItemCount(); i++) { OutputExchangeItem ouputItem = mohidWaterEngineWrapper.GetOutputExchangeItem(i); IValueSet values = mohidWaterEngineWrapper.GetValues(ouputItem.Quantity.ID, ouputItem.ElementSet.ID); } wout.Stop(); //Sets Input Items win.Start(); for (int i = 0; i < mohidWaterEngineWrapper.GetInputExchangeItemCount(); i++) { InputExchangeItem inputItem = mohidWaterEngineWrapper.GetInputExchangeItem(i); double[] aux = new double[inputItem.ElementSet.ElementCount]; for (int j = 0; j < inputItem.ElementSet.ElementCount; j++) { aux[j] = 0; } IValueSet values = new ScalarSet(aux); //mohidLandEngineWrapper.SetValues(inputItem.Quantity.ID, inputItem.ElementSet.ID, values); } win.Stop(); now = mohidWaterEngineWrapper.GetEarliestNeededTime().ModifiedJulianDay; } Console.WriteLine("Input Exchange: " + win.ElapsedMilliseconds.ToString()); Console.WriteLine("Output Exchange: " + wout.ElapsedMilliseconds.ToString()); Console.WriteLine("Engine: " + wengine.ElapsedMilliseconds.ToString()); }
public global::OpenMI.Standard.IValueSet GetValues(string QuantityID, string ElementSetID) { ScalarSet scalarSet = new ScalarSet(nx * ny, 0); for (int i = 0; i < nx * ny; i++) { scalarSet.data[i] = ((TimestampSeries)groundwaterHeads.Items[i]).Items[currentTimestep].Value; } return(scalarSet); }
public void PTS_inputexchangeitem() { Console.WriteLine("\n ----- Beginning Perform-Time-Step -----"); System.Collections.Hashtable args = new System.Collections.Hashtable(); args.Add("ConfigFile", "../../data/configTest.xml"); args.Add("TI", "../../Data/TI.csv"); args.Add("Weather", "../../Data/Weather.csv"); engine.Initialize(args); //passing the daily precip and ET (mm/hr) double[] p = new double[5] { 10.5, 0, 0, 0, 5.613 }; double[] pet = new double[5] { 1.355, 1.665, 1.665, 1.815, 1.665 }; double R = 9.66; //Known Runoff results double[] Known_runoff = new double[5] { 12.02, 9.35, 8.80, 8.30, 9.84 }; Queue <double> Known_runoff_Answers = new Queue <double>(Known_runoff); Console.WriteLine("Day \t\t\t Runoff "); for (int j = 0; j <= p.Length - 1; j++) { double[] P = new double[1] { p[j] }; IValueSet Precip = new ScalarSet(P); engine.SetValues("PPT", "TopModel Testing", Precip); double[] Pet = new double[1] { pet[j] }; IValueSet pett = new ScalarSet(Pet); engine.SetValues("PET", "TopModel", pett); engine.PerformTimeStep(); double[] pe = ((ScalarSet)engine.GetValues("Runoff", "TopModel")).data; Console.WriteLine("{0:D}\t\t\t {1:F}", j, pe[j], Known_runoff[j]); //Check to see if the computed values equal the known ones Assert.IsTrue(Math.Round(pe[j], 2) == Known_runoff_Answers.Dequeue()); } Console.WriteLine("\n ----- Perform-Time-Step finished Sucessfully -----"); }
public override bool PerformTimeStep() { //Defie current time step and the row of water component TimeStamp SedTime = (TimeStamp)this.GetCurrentTime(); ScalarSet aa = (ScalarSet)this.GetValues("Concentration", "water"); //set adv_prev to the imported values for (int i = 0; i <= cw.GetLength(1) - 1; i++) { adv_prev[0, i] = aa.data[i]; } // specifies if the values should be saved. bool SaveValues = true; TimeStamp t = (TimeStamp)this.GetCurrentTime(); DateTime time = CalendarConverter.ModifiedJulian2Gregorian(t.ModifiedJulianDay); // calculate concentration in sediment using diffusion mechanism from water cs = Calculate_concentration(); //setup the value of diff_prev= upper row of cs since cs contain 9 rows for (int i = 0; i <= cs.GetLength(1) - 1; i++) { diff_prev[i] = cs[cs.GetUpperBound(0), i]; } //save results for output during Finish() double[,] z = new double[rows_S, cols_S]; if (SaveValues) { for (int i = 0; i <= cs.GetLength(0) - 1; i++) { for (int j = 0; j <= cs.GetLength(1) - 1; j++) { z[i, j] = cs[i, j]; } } //save results for output during Finish() outputValues.Add(time, z); outv.Add(z); } //setting boundary conditions so that they are available to water component. double[] outvals = new double[cs.GetLength(1)]; for (int i = 0; i <= cs.GetLength(1) - 1; i++) { outvals[i] = cs[8, i]; } this.SetValues("Concentration", "sed", new ScalarSet(outvals)); this.AdvanceTime(); return(true); }
//In case the PET inputs are from txt file. need to uncomment the Pet reading input in TopModel.cs public void PTS_readingfrominputfile() { Console.WriteLine("\n ----- Beginning Perform-Time-Step -----"); System.Collections.Hashtable args = new System.Collections.Hashtable(); args.Add("ConfigFile", "../../data/configTest.xml"); args.Add("TI", "../../Data/TI_raster.txt"); args.Add("m", "180"); args.Add("Tmax", "250000"); args.Add("Interception", "3"); args.Add("R", "9.66"); engine.Initialize(args); //passing the daily precip and ET (mm/hr) double[] p = new double[5] { 10.5, 0, 0, 0, 5.613 }; double [] pet = new double[5] { 1.355, 1.665, 1.665, 1.815, 1.665 }; //Known Runoff results double [] Known_pe = new double[5] { 12.02, 9.35, 8.80, 8.30, 9.84 }; Queue <double> Known_pe_Answers = new Queue <double>(Known_pe); Console.WriteLine("Day \t\t\t Runoff "); for (int j = 0; j <= p.Length - 1; j++) { double[] P = new double[1] { p[j] }; IValueSet Precip = new ScalarSet(P); engine.SetValues("Precip", "TopModel", Precip); double[] Pet = new double[1] { pet[j] }; IValueSet pett = new ScalarSet(Pet); engine.SetValues("PET", "TopModel", pett); engine.PerformTimeStep(); double[] pe = ((ScalarSet)engine.GetValues("Runoff", "TopModel")).data; Console.WriteLine("{0:D}\t\t\t {1:F}", j, pe[0], Known_pe[j]); } Console.WriteLine("\n ----- Perform-Time-Step finished Sucessfully -----"); }
public override void SetEngineValues(EngineInputItem inputItem, ITimeSpaceValueSet values) { int elementCount = ValueSet.GetElementCount(values); double[] avalues = new double[elementCount]; for (int i = 0; i < elementCount; i++) { avalues[i] = (double)values.GetValue(0, i); } ScalarSet scalarSet = new ScalarSet(avalues); _engineApiAccess.SetValues(inputItem.ValueDefinition.Caption, inputItem.SpatialDefinition.Caption, scalarSet); }
public void GetValues() { Console.Write("Begin Get Values Test..."); //create the his component DbReader his = new DbReader(); IArgument[] arguments = new IArgument[2]; arguments[0] = new Argument("DbPath", @"..\data\cuahsi-his\demo.db", true, "Database"); arguments[1] = new Argument("Relaxation", "1", true, "Time interpolation factor, btwn 0(linear inter.) and 1(nearest neigbor)"); his.Initialize(arguments); //create a trigger component Trigger trigger = new Trigger(); trigger.Initialize(null); //link the two components Link link = new Link(); link.ID = "link-1"; link.TargetElementSet = trigger.GetInputExchangeItem(0).ElementSet; link.TargetQuantity = trigger.GetInputExchangeItem(0).Quantity; link.TargetComponent = trigger; link.SourceElementSet = his.GetOutputExchangeItem(0).ElementSet; link.SourceQuantity = his.GetOutputExchangeItem(0).Quantity; link.TargetComponent = his; //run configuration his.AddLink(link); //prepare his.Prepare(); DateTime dt = Convert.ToDateTime("2009-08-20"); while (dt <= Convert.ToDateTime("2009-09-20")) { ITimeStamp time_stmp = new TimeStamp(CalendarConverter.Gregorian2ModifiedJulian(dt)); Application.DoEvents(); ScalarSet scalarset = (ScalarSet)his.GetValues(time_stmp, "link-1"); Console.WriteLine("GetValues: " + dt.ToString("s")); int i = 0; foreach (double d in scalarset.data) { Console.WriteLine(link.SourceElementSet.GetElementID(i).ToString() + " " + d.ToString()); ++i; } dt = dt.AddMinutes(5); } Console.Write("done. \n"); }
public IValueSet GetValues(ITime time, string linkID) { Random random = new Random(); double[] output = new double[_numElements]; for (int i = 0; i < _numElements; i++) { output[i] = random.Next(20); } IValueSet vals = new ScalarSet(output); return(vals); }
public override bool PerformTimeStep() { //Define time step and get lowest row from the Sediment component grid(lowest row of matrix= actual top row) TimeStamp WaterTime = (TimeStamp)this.GetCurrentTime(); ScalarSet ss = (ScalarSet)this.GetValues("Concentration", "sed"); //set diff_prev = the imported values for (int i = 0; i <= cs.GetLength(1) - 1; i++) { diff_prev[i] = ss.data[i]; } //specifies if values should be saved. bool SaveValues = true; TimeStamp t = (TimeStamp)this.GetCurrentTime(); DateTime time = CalendarConverter.ModifiedJulian2Gregorian(t.ModifiedJulianDay); // calculate concentration in water using advection mechanismin water and diffusion from sediment cw = Calculate_concentration(); //store these c values in adv_prev, for next timestep adv_prev = cw; //save results for output during Finish() double[,] z = new double[rows_W, cols_W]; if (SaveValues) { for (int i = 0; i <= cw.GetLength(0) - 1; i++) { for (int j = 0; j <= cw.GetLength(1) - 1; j++) { z[i, j] = adv_prev[i, j]; } } outputValues.Add(time, z); } double[] outvals = new double[cw.GetLength(1)]; for (int i = 0; i <= cw.GetLength(1) - 1; i++) { outvals[i] = cw[cw.GetLength(0) - 1, i]; } this.SetValues("Concentration", "water", new ScalarSet(outvals)); this.AdvanceTime(); return(true); }
public void PerformTimeStepTest() { N_SolarRadiation.N_SR component = new N_SR(); //Initialize Component System.Collections.Hashtable args = new System.Collections.Hashtable(); args.Add("ConfigFile", "../../../source/config.xml"); args.Add("wtmpFolder", "../../../data/wtmp"); component.Initialize(args); //Call perform timestep in the component class component.PerformTimeStep(); //retrieve values from the compenent class ScalarSet _NSR = (ScalarSet)component.GetValues("NSR", "NetRad"); double[] NSR = _NSR.data; }
public override IValueSet GetValues(ITime time, string LinkID) { Link l = (Link)_links[LinkID]; if (l.TargetComponent.ModelID != "Oatc.OpenMI.Gui.Trigger") { string quantity = l.SourceQuantity.ID; string elementset = l.SourceElementSet.ID; ScalarSet ss = (ScalarSet)EngineApiAccess.GetValues(quantity, elementset); return(ss); } else { return(base.GetValues(time, LinkID)); } }
public void PerformTimeStepTest() { csvfileReader.WR component = new WR(); //Initialize Component System.Collections.Hashtable args = new System.Collections.Hashtable(); args.Add("ConfigFile", "C:/research/code/HydroDesktopHG/Source/Plugins/HydroModeler/Components/wtmpReader/Source/config.xml"); args.Add("DataFolder", "C:/research/code/HydroDesktopHG/Source/Plugins/HydroModeler/Components/wtmpReader/data"); component.Initialize(args); //Call perform timestep in the component class component.PerformTimeStep(); //retrieve values from the compenent class ScalarSet OutputValues = (ScalarSet)component.GetValues("Temperature", "Temp"); double[] T = OutputValues.data; }
/// <summary> /// Retrieves data from the providing LinkableComponent as defined /// in the Link and sets this data in the engine /// </summary> public virtual void UpdateInput() { ITime inputTime = this._engine.GetInputTime(link.TargetQuantity.ID, link.TargetElementSet.ID); if (inputTime != null) { SendEvent(EventType.TargetBeforeGetValuesCall, this.link.TargetComponent); IScalarSet sourceValueSet = (IScalarSet)link.SourceComponent.GetValues(inputTime, link.ID); //The input values set is copied in ordet to avoid the risk that it is changed be the provider. double targetMissValDef = this._engine.GetMissingValueDefinition(); ScalarSet targetValueSet = new ScalarSet(sourceValueSet); for (int i = 0; i < sourceValueSet.Count; i++) { if (!sourceValueSet.IsValid(i)) { targetValueSet.data[i] = targetMissValDef; } } targetValueSet.MissingValueDefinition = targetMissValDef; targetValueSet.CompareDoublesEpsilon = targetMissValDef / 1.0e+10; if (link.TargetComponent is LinkableRunEngine && ((LinkableRunEngine)link.TargetComponent).SendExtendedEventInfo) { string msg = " Quantity: " + link.TargetQuantity.ID + " Recieved values:"; if (sourceValueSet is IScalarSet) { for (int i = 0; i < ((IScalarSet)sourceValueSet).Count; i++) { msg += (((IScalarSet)sourceValueSet).GetScalar(i).ToString() + ", "); } } SendEvent(EventType.TargetAfterGetValuesReturn, this.link.TargetComponent, msg); } else { SendEvent(EventType.TargetAfterGetValuesReturn, this.link.TargetComponent); } this.Engine.SetValues(link.TargetQuantity.ID, link.TargetElementSet.ID, targetValueSet); } }
public void PTS() { SCSAbstractionMethod CN = new SCSAbstractionMethod(); System.Collections.Hashtable args = new System.Collections.Hashtable(); args.Add("ConfigFile", "./configTest.xml"); CN.Initialize(args); //Precipitation values from Precip Reader Component [based on 30 Min rainfall] double[,] p = new double[8, 1] { { 0.00 }, { 0.20 }, { 0.70 }, { 0.37 }, { 1.04 }, { 2.34 }, { 0.64 }, { 0.07 } }; for (int j = 0; j <= p.GetLength(0) - 1; j++) { Console.WriteLine("TimeStep " + Convert.ToString(j + 1)); double[] precipArray = new double[p.GetLength(1)]; for (int k = 0; k <= p.GetLength(1) - 1; k++) { //create double array precipArray[k] = p[j, k]; } IValueSet Precip = new ScalarSet(precipArray); CN.SetValues("Rainfall", "SmithBranch", Precip); CN.PerformTimeStep(); ScalarSet Excess = (ScalarSet)CN.GetValues("Excess Rainfall", "Smith Branch"); for (int i = 0; i <= Excess.Count - 1; i++) { Console.WriteLine("Watershed: " + i.ToString() + "\t Excess Rainfall: " + Excess.data[i].ToString()); } } CN.Finish(); }
public IValueSet GetValues(ITime time, string linkID) { var values = MsheOrg.GetValues(time, linkID); var link = AlteredLinks[linkID]; if (link.SourceElementSet.ID == "BaseGrid") { ScalarSet scinner = new ScalarSet(values as IScalarSet); List<double> InnerValues = new List<double>(); foreach (int i in InnerIdeces) InnerValues.Add(((ScalarSet)values).data[i]); scinner.data = InnerValues.ToArray(); if (mappers.ContainsKey(linkID)) { return mappers[linkID].MapValues(scinner); } return scinner; } return values; }