-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Basic Event Scheduler Model #37
base: devel
Are you sure you want to change the base?
Changes from all commits
6fab7d1
53b7eaf
512eaf6
27dcbba
571c36c
7eb7c07
a5cb574
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
\section{Basic Event Scheduler Model} | ||
\label{sec:basicEventScheduler} | ||
|
||
This model is designed to read the initial and final time under which a set of basic events | ||
are set to True, and then it generates an HistorySet with the full temporal profile of all | ||
basic events. | ||
|
||
This HistorySet is generated by colleting all the initial and final time values, by ordering | ||
them in ascending order, and by setting the corresponding logical values for each basic event | ||
along the time axis. | ||
Note that this model performs a conversion from interval-based data to instant-based data | ||
(i.e., the history set). The convention is that a logical value set to 1 at a specific time | ||
instant implies that the basic event is actually True from the previous time instant. | ||
|
||
All the specifications of the Basic Event Scheduler model are given in the \xmlNode{ExternalModel} block. | ||
Inside the \xmlNode{ExternalModel} block, the XML | ||
nodes that belong to this models are: | ||
\begin{itemize} | ||
\item \xmlNode{variables}, \xmlDesc{string, required parameter}, a list containing the names of both the input and output variables of the model | ||
\item \xmlNode{BE}, \xmlDesc{string, required parameter}, the name ID of all basic events | ||
\begin{itemize} | ||
\item \xmlAttr{tin}, \xmlDesc{required string attribute}, name ID of the variable describing the initial time of the BE | ||
\item \xmlAttr{tfin}, \xmlDesc{required string attribute}, name ID of the variable describing the final time of the BE | ||
\end{itemize} | ||
\end{itemize} | ||
|
||
The example of \textbf{basicEventScheduler} model is provided below: | ||
\begin{lstlisting}[style=XML] | ||
<Models> | ||
<ExternalModel name="basicEventScheduler" subType="SR2ML.basicEventScheduler"> | ||
<variables>BE1_tin, BE2_tin, BE3_tin, | ||
BE1_tfin,BE2_tfin,BE3_tfin, | ||
BE1,BE2,BE3,time</variables> | ||
<BE tin='BE1_tin' tfin='BE1_tfin'>BE1</BE> | ||
<BE tin='BE2_tin' tfin='BE2_tfin'>BE2</BE> | ||
<BE tin='BE3_tin' tfin='BE3_tfin'>BE3</BE> | ||
<timeID>time</timeID> | ||
</ExternalModel> | ||
</Models> | ||
\end{lstlisting} | ||
|
||
\subsection{basicEventScheduler Reference Tests} | ||
\begin{itemize} | ||
\item SR2ML/tests/test\_basicEventScheduler.xml | ||
\end{itemize} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
# Copyright 2020, Battelle Energy Alliance, LLC | ||
# ALL RIGHTS RESERVED | ||
|
||
""" | ||
Created on June 24, 2020 | ||
|
||
@author: mandd | ||
""" | ||
|
||
#External Modules--------------------------------------------------------------- | ||
import numpy as np | ||
import xarray as xr | ||
import pandas as pd | ||
#External Modules End----------------------------------------------------------- | ||
|
||
#Internal Modules--------------------------------------------------------------- | ||
from PluginBaseClasses.ExternalModelPluginBase import ExternalModelPluginBase | ||
#Internal Modules End----------------------------------------------------------- | ||
|
||
class BasicEventScheduler(ExternalModelPluginBase): | ||
""" | ||
This class is designed to create a Maintenance Scheduler model | ||
""" | ||
def __init__(self): | ||
""" | ||
Constructor | ||
@ In, None | ||
@ Out, None | ||
""" | ||
ExternalModelPluginBase.__init__(self) | ||
|
||
def initialize(self, container, runInfoDict, inputFiles): | ||
""" | ||
Method to initialize the Basic Event Scheduler model | ||
@ In, container, object, self-like object where all the variables can be stored | ||
@ In, runInfoDict, dict, dictionary containing all the RunInfo parameters (XML node <RunInfo>) | ||
@ In, inputFiles, list, list of input files (if any) | ||
@ Out, None | ||
""" | ||
|
||
def _readMoreXML(self, container, xmlNode): | ||
""" | ||
Method to read the portion of the XML that belongs to the Basic Event Scheduler model | ||
@ In, container, object, self-like object where all the variables can be stored | ||
@ In, xmlNode, xml.etree.ElementTree.Element, XML node that needs to be read | ||
@ Out, None | ||
""" | ||
container.basicEvents = {} | ||
|
||
for child in xmlNode: | ||
if child.tag == 'BE': | ||
container.basicEvents[child.text.strip()] = [child.get('tin'),child.get('tfin')] | ||
elif child.tag == 'timeID': | ||
container.timeID = child.text.strip() | ||
elif child.tag == 'variables': | ||
variables = [str(var.strip()) for var in child.text.split(",")] | ||
else: | ||
raise IOError("basicEventScheduler: xml node " + str(child.tag) + " is not allowed") | ||
|
||
def run(self, container, inputs): | ||
""" | ||
This method generate an historySet from the a pointSet which contains initial and final time of the | ||
basic events. This method is generating the time series variable basicEventHistorySet which is passed | ||
to RAVEN through the container.__dict__ container | ||
@ In, inputs, dict, dictionary of inputs from RAVEN | ||
@ In, container, object, self-like object where all the variables can be stored | ||
""" | ||
dataDict = {} | ||
for key in container.basicEvents.keys(): | ||
dataDict[key] = [] | ||
dataDict[key].append(inputs[container.basicEvents[key][0]][0]) | ||
dataDict[key].append(inputs[container.basicEvents[key][1]][0]) | ||
|
||
inputDataset = pd.DataFrame.from_dict(dataDict, orient='index',columns=['tin', 'tfin']) | ||
|
||
timeArray = np.concatenate([inputDataset['tin'],inputDataset['tfin']]) | ||
timeArraySorted = np.sort(timeArray,axis=0) | ||
timeArrayCleaned = np.unique(timeArraySorted) | ||
|
||
keys = list(container.basicEvents.keys()) | ||
dataVars={} | ||
for key in keys: | ||
dataVars[key]=(['RAVEN_sample_ID',container.timeID],np.zeros((1,timeArrayCleaned.shape[0]))) | ||
|
||
basicEventHistorySet = xr.Dataset(data_vars = dataVars, | ||
coords = dict(time=timeArrayCleaned, | ||
RAVEN_sample_ID=np.zeros(1))) | ||
|
||
for key in container.basicEvents.keys(): | ||
tin = inputs[container.basicEvents[key][0]][0] | ||
tend = inputs[container.basicEvents[key][1]][0] | ||
indexes = np.where(np.logical_and(timeArrayCleaned>tin,timeArrayCleaned<=tend)) | ||
basicEventHistorySet[key][0][indexes] = 1.0 | ||
|
||
container.__dict__[key] = basicEventHistorySet[key].values[0] | ||
|
||
container.__dict__[container.timeID] = timeArrayCleaned | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
time,BE1,BE2,BE3 | ||
0.2246649631356506,0.0,0.0,0.0 | ||
2.6344256060278104,1.0,0.0,0.0 | ||
2.8543678209777847,0.0,0.0,0.0 | ||
2.914493040161788,0.0,1.0,0.0 | ||
4.562087161131689,0.0,1.0,1.0 | ||
4.785268305285197,0.0,0.0,1.0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
<Simulation verbosity="debug"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no gold files for this test There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's weird, i wonder why the regression test was green There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see issue #38 |
||
<TestInfo> | ||
<name>SR2ML/basicEventScheduler</name> | ||
<author>mandd</author> | ||
<created>2021-07-14</created> | ||
<classesTested>SR2ML/basicEventScheduler</classesTested> | ||
<description> | ||
This model provided the schedule of a set of basic events create an history set containing | ||
basic event temporal profiles. Each basic event is represented by the initial and final time | ||
where basic event is set to True (i.e., with probability=1.0) | ||
</description> | ||
</TestInfo> | ||
|
||
<RunInfo> | ||
<WorkingDir>basicEventScheduler</WorkingDir> | ||
<Sequence>simRun</Sequence> | ||
<batchSize>1</batchSize> | ||
</RunInfo> | ||
|
||
<Models> | ||
<ExternalModel name="basicEventScheduler" subType="SR2ML.BasicEventScheduler"> | ||
<variables>BE1_tin, BE2_tin, BE3_tin, | ||
BE1_tfin,BE2_tfin,BE3_tfin, | ||
BE1,BE2,BE3,time</variables> | ||
<BE tin='BE1_tin' tfin='BE1_tfin'>BE1</BE> | ||
<BE tin='BE2_tin' tfin='BE2_tfin'>BE2</BE> | ||
<BE tin='BE3_tin' tfin='BE3_tfin'>BE3</BE> | ||
<timeID>time</timeID> | ||
</ExternalModel> | ||
</Models> | ||
|
||
<Distributions> | ||
<Uniform name='BE1_tin_dist'> | ||
<lowerBound>0.</lowerBound> | ||
<upperBound>1.</upperBound> | ||
</Uniform> | ||
<Uniform name='BE2_tin_dist'> | ||
<lowerBound>2.</lowerBound> | ||
<upperBound>3.</upperBound> | ||
</Uniform> | ||
<Uniform name='BE3_tin_dist'> | ||
<lowerBound>1.</lowerBound> | ||
<upperBound>3.</upperBound> | ||
</Uniform> | ||
<Uniform name='BE1_tfin_dist'> | ||
<lowerBound>2.</lowerBound> | ||
<upperBound>3.</upperBound> | ||
</Uniform> | ||
<Uniform name='BE2_tfin_dist'> | ||
<lowerBound>4.</lowerBound> | ||
<upperBound>5.</upperBound> | ||
</Uniform> | ||
<Uniform name='BE3_tfin_dist'> | ||
<lowerBound>3.</lowerBound> | ||
<upperBound>5.</upperBound> | ||
</Uniform> | ||
</Distributions> | ||
|
||
<Samplers> | ||
<MonteCarlo name="MC_external"> | ||
<samplerInit> | ||
<limit>1</limit> | ||
</samplerInit> | ||
<variable name="BE1_tin"> | ||
<distribution>BE1_tin_dist</distribution> | ||
</variable> | ||
<variable name="BE2_tin"> | ||
<distribution>BE2_tin_dist</distribution> | ||
</variable> | ||
<variable name="BE3_tin"> | ||
<distribution>BE3_tin_dist</distribution> | ||
</variable> | ||
<variable name="BE1_tfin"> | ||
<distribution>BE1_tfin_dist</distribution> | ||
</variable> | ||
<variable name="BE2_tfin"> | ||
<distribution>BE2_tfin_dist</distribution> | ||
</variable> | ||
<variable name="BE3_tfin"> | ||
<distribution>BE3_tfin_dist</distribution> | ||
</variable> | ||
</MonteCarlo> | ||
</Samplers> | ||
|
||
<Steps> | ||
<MultiRun name="simRun"> | ||
<Input class="DataObjects" type="PointSet" >inputPlaceHolder</Input> | ||
<Model class="Models" type="ExternalModel" >basicEventScheduler</Model> | ||
<Sampler class="Samplers" type="MonteCarlo" >MC_external</Sampler> | ||
<Output class="DataObjects" type="HistorySet" >sim_HS</Output> | ||
<Output class="OutStreams" type="Print" >Print_sim_HS</Output> | ||
</MultiRun> | ||
</Steps> | ||
|
||
<OutStreams> | ||
<Print name="Print_sim_HS"> | ||
<type>csv</type> | ||
<source>sim_HS</source> | ||
<what>input,output</what> | ||
</Print> | ||
</OutStreams> | ||
|
||
<DataObjects> | ||
<PointSet name="inputPlaceHolder"> | ||
<Input>BE1_tin, BE2_tin, BE3_tin, | ||
BE1_tfin,BE2_tfin,BE3_tfin</Input> | ||
<Output>OutputPlaceHolder</Output> | ||
</PointSet> | ||
<HistorySet name="sim_HS"> | ||
<Input>BE1_tin, BE2_tin, BE3_tin, | ||
BE1_tfin,BE2_tfin,BE3_tfin</Input> | ||
<Output>BE1,BE2,BE3</Output> | ||
<options> | ||
<pivotParameter>time</pivotParameter> | ||
</options> | ||
</HistorySet> | ||
</DataObjects> | ||
|
||
</Simulation> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend to add another paragraph to explain the structure of generated history set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added