Skip to content
Open
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
94 changes: 94 additions & 0 deletions ravenframework/CodeInterfaceClasses/Barracuda/BarracudaParser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Copyright 2017 Battelle Energy Alliance, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Created on Mar 10, 2015

@author: talbpaul
"""
from __future__ import division, print_function, unicode_literals, absolute_import

import os
import sys
import numpy as np
from ravenframework.utils import mathUtils
# numpy with version 1.14.0 and upper will change the floating point type and print
# https://docs.scipy.org/doc/numpy-1.14.0/release.html
if int(np.__version__.split('.')[1]) > 13:
np.set_printoptions(**{'legacy':'1.13'})

def _reprIfFloat(value):
"""
Uses repr if the value is a float
@ In, value, any, the value to convert to a string
@ Out, _reprIfFloat, string, a string conversion of this
"""
if mathUtils.isAFloat(value):
return repr(value)
else:
return str(value)

class BarracudaParser():
"""
import the user-edited input file, build list of strings with replaceable parts
"""
def __init__(self,inputFiles,**Kwargs):
"""
Accept the input file and parse it by the prefix-postfix breaks. Someday might be able to change prefix,postfix,defaultDelim from input file, but not yet.
@ In, inputFiles, list, string list of input filenames that might need parsing.
@ In, perturbVarDict, dictionary of perturbed variables
@ Out, None
"""
self.inputFiles = inputFiles
self.lines = self.inputFile.readlines()
self.inputFiles.close()
self.distributedPerturbedVars = Kwargs['SampledVars']

# Iterate through self.distributedPerturbedVars and call updates to self.inputFiles
for perturbedParam in self.distributedPerturbedVars.keys():
if perturbedParam == 'temperature':
self.updateTemperature(self.distributedPerturbedVars['temperature'])

self.writeNewInput()


def updateTemperature(self, newTemperature):
"""
Edits self.lines to modify the temperature.
@ In, newTemperature, float, value of the perturbed temperature.
@ Out, None
"""
# Perform math on perturbed variable

# Iterate through file to find specific text
for lineNo, line in enumerate(self.lines):
if "isothermalT" in line:
lineUpdateNo = lineNo
break

# Updaate lines with perturbed variable
self.lines[lineUpdateNo] = "isothermalT %8.6e\n" % (newTemperature)

return


def writeNewInput(self):
"""
Generates a new input file with the existing parsed dictionary.
@ In, None
@ Out, None
"""
outfile = self.inputFiles
outfile.open('w')
outfile.writelines(self.lines)
outfile.close()
Empty file.
98 changes: 98 additions & 0 deletions ravenframework/CodeInterfaceClasses/Barracuda/barracuda.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?xml version="1.0" ?>
<Simulation>
<RunInfo>
<WorkingDir>r1</WorkingDir>
</RunInfo>

<Files>
<Input name="prj_file">Model_2in_60deg.prj</Input>
<Input name="stl_file">2in_retort_curve_bottom.stl</Input>
<Input name="Ar_sff">Ar_viscosity_data_interpltn.sff</Input>
<Input name="lay_file">volfracfilter.lay</Input>
<Input name="grid_file">grid.i</Input>
</Files>

<Steps>
<MultiRun name="generate_data">
<Sampler class="Samplers" type="MonteCarlo">my_mc</Sampler>
<Input class="DataObjects" type="PointSet">placeholder</Input>
<Model class="Models" type="ExternalModel">projectile</Model>
<Output class="DataObjects" type="PointSet">results</Output>
</MultiRun>
<IOStep name="plot" pauseAtEnd="True">
<Input class="DataObjects" type="PointSet">results</Input>
<Output class="OutStreams" type="Print">to_file</Output>
<Output class="OutStreams" type="Plot">to_plot</Output>
</IOStep>
</Steps>

<Models>
<ExternalModel ModuleToLoad="../../../ExternalModels/projectile.py" name="projectile" subType="">
<variables>v0,angle,r,t,timeOption</variables>
</ExternalModel>
</Models>

<Samplers>
<MonteCarlo name="my_mc">
<samplerInit>
<limit>1000</limit>
<initialSeed>42</initialSeed>
</samplerInit>
<variable name="v0">
<distribution>vel_dist</distribution>
</variable>
<variable name="angle">
<distribution>angle_dist</distribution>
</variable>
<constant name="x0">0</constant>
<constant name="y0">0</constant>
<constant name="timeOption">1</constant>
</MonteCarlo>
</Samplers>

<Distributions>
<Uniform name="vel_dist">
<lowerBound>1</lowerBound>
<upperBound>60</upperBound>
</Uniform>
<Uniform name="angle_dist">
<lowerBound>5</lowerBound>
<upperBound>85</upperBound>
</Uniform>
</Distributions>

<DataObjects>
<PointSet name="placeholder">
<Input>v0,angle</Input>
</PointSet>
<PointSet name="results">
<Input>v0,angle</Input>
<Output>r,t</Output>
</PointSet>
</DataObjects>

<OutStreams>
<Print name="to_file">
<type>csv</type>
<source>results</source>
</Print>
<Plot name="to_plot">
<plotSettings>
<plot>
<type>scatter</type>
<x>results|Input|v0</x>
<y>results|Input|angle</y>
<z>results|Output|r</z>
<colorMap>results|Output|t</colorMap>
</plot>
<xlabel>v0</xlabel>
<ylabel>angle</ylabel>
<zlabel>r</zlabel>
</plotSettings>
<actions>
<how>screen, png</how>
</actions>
</Plot>
</OutStreams>

</Simulation>
Loading