Skip to content
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

Added MOOSE interface Generic File perturbation #1141

Merged
merged 2 commits into from
Jan 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 42 additions & 4 deletions doc/user_manual/existing_interfaces.tex
Original file line number Diff line number Diff line change
Expand Up @@ -892,18 +892,27 @@ \subsubsection{Files}
%
In the case of any MooseBasedApp, the files typically needed are the following:
\begin{itemize}
\item MooseBasedApp YAML input file
\item MooseBasedApp GetPot input file
\item Restart Files (if the calculation is instantiated from a restart point)
\item Mesh Files (in case the mesh is externally specified)
\item Any other generic input file (CSVs with Power histories, boundary conditions files, etc.)
\end{itemize}
Example:
\begin{lstlisting}[style=XML]
<Files>
<Input name='mooseBasedApp.i' type=''>mooseBasedApp.i</Input>
<Input name='0020_mesh.cpr' type=''>0020_mesh.cpr</Input>
<Input name='0020.xdr.0000'>0020.xdr.0000</Input>
<Input name='0020.rd-0'>0020.rd-0</Input>
<Input name='0020.xdr.0000' type="">0020.xdr.0000</Input>
<Input name='0020.rd-0' type="">0020.rd-0</Input>
<Input name='exodus_mesh.e' type="">exodus_mesh.e</Input>
<Input name='a_generic_additional_input_file.csv' type="Generic">a_generic_additional_input_file.csv</Input>
</Files>
\end{lstlisting}
If any file is tagged with the type \texttt{Generic}, it will be perturbable with the approach (wildcards)
explained in the generic code interface (see \ref{subsec:genericInterface}).



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsubsection{Models}
In the \xmlNode{Models} block particular MooseBasedApp executable needs to be specified.
Expand Down Expand Up @@ -994,8 +1003,30 @@ \subsubsection{Samplers}
...
\end{lstlisting}
%
In this example, we proceed to do so for both the Grid sampling and the Monte-Carlo sampling.
In case some variables in external (\texttt{Generic} input files) need to be perturbed,
the wildcard approach can be used (for those variables):
\begin{lstlisting}[style=XML]
...
<Samplers>
<aSampler name='aUserDefinedName' >
<variable name='aWildCard1'>
...
</variable>
<variable name='aWildCard2'>
...
</variable>
<variable name='Materials|heatStructure|thermal_conductivity'>
...
</variable>
</aSampler>
</Samplers>
...
\end{lstlisting}
In this case the tagged file (\texttt{Generic}) will be parsed to find the variables
\texttt{\$RAVEN-aWildCard1\$} and \texttt{\$RAVEN-aWildCard1\$} and to replace their values
with the corresponding sampled variables (for more details, see \ref{subsec:genericInterface})

In this example, we proceed to do so for both the Grid sampling and the Monte-Carlo sampling.
\begin{lstlisting}[style=XML,morekeywords={name,type,construction,lowerBound,steps,limit,initialSeed}]
<Samplers verbosity='debug'>
<Grid name='myGrid'>
Expand All @@ -1011,6 +1042,10 @@ \subsubsection{Samplers}
<distribution >ThermalConductivity2</distribution>
<grid type='value' upperBound='4' construction='equal' steps='1'>0.5</grid>
</variable>
<variable name='aWildCard1'>
<distribution >ThermalConductivity2</distribution>
<grid type='value' upperBound='4' construction='equal' steps='1'>0.5</grid>
</variable>
</Grid>
<MonteCarlo name='MC_Sampler' limit='1000'>
<variable name='Materials|heatStructure1|thermal_conductivity' >
Expand All @@ -1022,6 +1057,9 @@ \subsubsection{Samplers}
<variable name='Materials|heatStructure2|thermal_conductivity'>
<distribution >ThermalConductivity2</distribution>
</variable>
<variable name='aWildCard1'>
<distribution >ThermalConductivity2</distribution>
</variable>
</MonteCarlo>
</Samplers>
\end{lstlisting}
Expand Down
20 changes: 15 additions & 5 deletions framework/CodeInterfaces/MooseBasedApp/MooseBasedAppInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import os
import copy
from CodeInterfaceBaseClass import CodeInterfaceBase
import GenericParser
import MooseData
import csvUtilities

Expand Down Expand Up @@ -78,11 +79,15 @@ def createNewInput(self,currentInputFiles,oriInputFiles,samplerType,**Kwargs):
self._samplersDictionary[samplerType] = self.pointSamplerForMooseBasedApp

found = False
for index, inputFile in enumerate(currentInputFiles):
inputFile = inputFile.getAbsFile()
if inputFile.endswith(self.getInputExtension()):
genericInput, genericOriInput = [], []
for i, inputFile in enumerate(currentInputFiles):
inFile = inputFile.getAbsFile()
if inFile.endswith(self.getInputExtension()):
index = i
found = True
break
if inputFile.getType().lower() == "generic":
genericInput.append(inputFile)
genericOriInput.append(oriInputFiles[i])
if not found:
raise IOError('None of the input files has one of the following extensions: ' + ' '.join(self.getInputExtension()))
outName = self.outputPrefix+currentInputFiles[index].getBase()
Expand All @@ -98,6 +103,12 @@ def createNewInput(self,currentInputFiles,oriInputFiles,samplerType,**Kwargs):
#make input
parser.printInput(currentInputFiles[index].getAbsFile())
self.vectorPPFound, self.vectorPPDict = parser.vectorPostProcessor()

if genericInput:
parser = GenericParser.GenericParser(genericInput)
parser.modifyInternalDictionary(**Kwargs)
parser.writeNewInput(genericInput,genericOriInput)

return currentInputFiles

def pointSamplerForMooseBasedApp(self,**Kwargs):
Expand All @@ -124,7 +135,6 @@ def dynamicEventTreeForMooseBasedApp(self,**Kwargs):
"""
listDict = []
raise IOError('dynamicEventTreeForMooseBasedApp not yet implemented')
return listDict

def finalizeCodeOutput(self,command,output,workingDir):
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
[Mesh]
type = GeneratedMesh
dim = 2
xmin = 0
xmax = 1
ymin = 0
ymax = 1
nx = 10
ny = 10
elem_type = QUAD4
[]

[Functions]
# ODEs
[./exact_x_fn]
type = ParsedFunction
value = (-1/3)*exp(-t)+(4/3)*exp(5*t)
[../]
[./exact_y_fn]
type = ParsedFunction
value = (2/3)*exp(-t)+(4/3)*exp(5*t)
[../]
[]

[Variables]
[./diffused]
order = FIRST
family = LAGRANGE
[../]

# ODE variables
[./x]
family = SCALAR
order = FIRST
initial_condition = 1
[../]
[./y]
family = SCALAR
order = FIRST
initial_condition = 2
[../]

[]

[Kernels]
[./td]
type = TimeDerivative
variable = diffused
[../]
[./diff]
type = Diffusion
variable = diffused
[../]
[]

[ScalarKernels]
[./td1]
type = ODETimeDerivative
variable = x
[../]
[./ode1]
type = ImplicitODEx
variable = x
y = y
[../]

[./td2]
type = ODETimeDerivative
variable = y
[../]
[./ode2]
type = ImplicitODEy
variable = y
x = x
[../]
[]


[BCs]
[./right]
type = ScalarDirichletBC
variable = diffused
boundary = 1
scalar_var = x
[../]

[./left]
type = ScalarDirichletBC
variable = diffused
boundary = 3
scalar_var = y
[../]
[]

[Postprocessors]
# to print the values of x, y into a file so we can plot it
[./x]
type = ScalarVariable
variable = x
execute_on = timestep_end
[../]

[./y]
type = ScalarVariable
variable = y
execute_on = timestep_end
[../]

[./exact_x]
type = FunctionValuePostprocessor
function = exact_x_fn
execute_on = timestep_end
point = '0 0 0'
[../]

[./exact_y]
type = FunctionValuePostprocessor
function = exact_y_fn
execute_on = timestep_end
point = '0 0 0'
[../]

# Measure the error in ODE solution for 'x'.
[./l2err_x]
type = ScalarL2Error
variable = x
function = exact_x_fn
[../]

# Measure the error in ODE solution for 'y'.
[./l2err_y]
type = ScalarL2Error
variable = y
function = exact_y_fn
[../]
[]


[Executioner]
type = Transient
start_time = 0
dt = 0.01
num_steps = 10

#Preconditioned JFNK (default)
solve_type = 'PJFNK'
[]

[Outputs]
exodus = true
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
time,power
0.,10
1.0,20
2.0,$RAVEN-p2.0$
3.0,$RAVEN-p3.0$
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
time,exact_x,exact_y,l2err_x,l2err_y,x,y
0,0,0,0,0,1,2
0.01,1.0716781839183,2.0617280176675,0.0017975847110658,0.0018467608635113,1.0734757686294,2.063574778531
0.02,1.1468283329986,2.1270270063054,0.0037839718620896,0.0038813479623196,1.1506123048607,2.1309083542677
0.03,1.2256304791215,2.19607601267,0.0059738448989899,0.0061184592775807,1.2316043240205,2.2021944719476
0.04,1.3082738644961,2.2690633036484,0.008382904883361,0.0085738102126549,1.3166567693795,2.2776371138611
0.05,1.3949574140834,2.3461868385841,0.011027936581653,0.011264199685733,1.4059853506651,2.3574510382699
0.06,1.4858902322399,2.4276547658242,0.013926878676188,0.014207580343858,1.4998171109161,2.441862346168
0.07,1.5812921248224,2.5136859447283,0.017098898346571,0.017423133144702,1.5983910231689,2.531109077873
0.08,1.6813941480595,2.6045104944461,0.020564470486559,0.020931346578875,1.701958618546,2.625441841025
0.09,1.7864391855631,2.7003703708344,0.024345461837806,0.024754100802847,1.810784647401,2.7251244716372
0.1,1.8966825549215,2.8015199729575,0.028465220336359,0.028914756989218,1.9251477752579,2.8304347299467
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
time,exact_x,exact_y,l2err_x,l2err_y,x,y
0,0,0,0,0,1,2
0.01,1.0716781839183,2.0617280176675,0.0017975847110658,0.0018467608635113,1.0734757686294,2.063574778531
0.02,1.1468283329986,2.1270270063054,0.0037839718620896,0.0038813479623196,1.1506123048607,2.1309083542677
0.03,1.2256304791215,2.19607601267,0.0059738448989899,0.0061184592775807,1.2316043240205,2.2021944719476
0.04,1.3082738644961,2.2690633036484,0.008382904883361,0.0085738102126549,1.3166567693795,2.2776371138611
0.05,1.3949574140834,2.3461868385841,0.011027936581653,0.011264199685733,1.4059853506651,2.3574510382699
0.06,1.4858902322399,2.4276547658242,0.013926878676188,0.014207580343858,1.4998171109161,2.441862346168
0.07,1.5812921248224,2.5136859447283,0.017098898346571,0.017423133144702,1.5983910231689,2.531109077873
0.08,1.6813941480595,2.6045104944461,0.020564470486559,0.020931346578875,1.701958618546,2.625441841025
0.09,1.7864391855631,2.7003703708344,0.024345461837806,0.024754100802847,1.810784647401,2.7251244716372
0.1,1.8966825549215,2.8015199729575,0.028465220336359,0.028914756989218,1.9251477752579,2.8304347299467
Loading