-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge commit 'a96f4be1e31bf296a18eff2eac583f959ea77406'
- Loading branch information
Showing
150 changed files
with
20,118 additions
and
2,658 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
x0 = 0 | ||
y0 = 0 | ||
v0 = 30 | ||
angle = 45 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
# 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. | ||
#*************************************** | ||
#* Simple analytic test ExternalModule * | ||
#*************************************** | ||
# | ||
# Simulates time-dependent track of a projectile through the air from start to 0, | ||
# assuming no air resistance. | ||
# Inputs: | ||
# (x0,y0) - initial position | ||
# v0 - initial total velocity | ||
# ang - angle of initial motion, in degrees, with respect to flat ground | ||
# Outputs: | ||
# (x,y) - vector positions of projectile in time | ||
# t - corresponding time steps | ||
# | ||
import numpy as np | ||
|
||
def prange(v,th,y0=0,g=9.8): | ||
""" | ||
Calculates the analytic range. | ||
@ In, v, float, velocity of the projectile | ||
@ In, th, float, angle to the ground for initial projectile motion | ||
@ In, y0, float, optional, initial height of projectile | ||
@ In, g, float, optional, gravitational constant (m/s/s) | ||
@ Out, prange, float, range | ||
""" | ||
return v*np.cos(th)/g * (v*np.sin(th) + np.sqrt(v*v*np.sin(th)**2+2.*g*y0)) | ||
|
||
def timeToGround(v,th,y0=0,g=9.8): | ||
""" | ||
Calculates the analytic time of flight | ||
@ In, v, float, velocity of the projectile | ||
@ In, th, float, angle to the ground for initial projectile motion | ||
@ In, y0, float, optional, initial height of projectile | ||
@ In, g, float, optional, gravitational constant (m/s/s) | ||
@ Out, timeToGround, float, time projectile is above the ground | ||
""" | ||
return v*np.sin(th)/g + np.sqrt(v*v*np.sin(th)**2+2.*g*y0)/g | ||
|
||
def xPosition(x0,v,t): | ||
""" | ||
Calculates the x position in time | ||
@ In, x0, float, initial horizontal position | ||
@ In, v, float, velocity of the projectile | ||
@ In, t, float, time of flight | ||
@ Out, xPosition, float, horizontal position | ||
""" | ||
return x0 + v*t | ||
|
||
def yPosition(y0,v,t): | ||
""" | ||
Calculates the analytic vertical position in time | ||
@ In, y0, float, initial vertical position | ||
@ In, v, float, velocity of the projectile | ||
@ In, t, float, time of flight | ||
@ Out, yPosition, float, vertical position | ||
""" | ||
return y0 + v*t - 4.9*t*t | ||
|
||
def run(self,Input): | ||
""" | ||
Method require by RAVEN to run this as an external model. | ||
@ In, self, object, object to store members on | ||
@ In, Input, dict, dictionary containing inputs from RAVEN | ||
@ Out, None | ||
""" | ||
x0 = Input.get('x0',0.0) | ||
y0 = Input.get('y0',0.0) | ||
v0 = Input.get('v0',1.0) | ||
ang = Input.get('angle',45.)*np.pi/180. | ||
timeOption = Input.get('timeOption', 1) | ||
self.x0 = x0 | ||
self.y0 = y0 | ||
self.v0 = v0 | ||
self.ang = ang | ||
if timeOption == 0: | ||
ts = np.linspace(0,1,10) | ||
else: | ||
ts = np.linspace(0,timeToGround(v0,ang,y0),20) | ||
|
||
vx0 = np.cos(ang)*v0 | ||
vy0 = np.sin(ang)*v0 | ||
r = prange(v0,ang,y0) | ||
|
||
self.x = np.zeros(len(ts)) | ||
self.y = np.zeros(len(ts)) | ||
self.r = np.zeros(len(ts)) | ||
for i,t in enumerate(ts): | ||
self.x[i] = xPosition(x0,vx0,t) | ||
self.y[i] = yPosition(y0,vy0,t) | ||
self.r[i] = r | ||
self.t = ts | ||
|
||
#can be used as a code as well | ||
if __name__=="__main__": | ||
import sys | ||
print 'Welcome to RAVEN\'s Simple Projectile Motion Simulator!' | ||
inFile = sys.argv[sys.argv.index('-i')+1] | ||
print 'Reading input from',inFile,'...' | ||
outFile = sys.argv[sys.argv.index('-o')+1] | ||
#construct the input | ||
Input = {} | ||
for line in open(inFile,'r'): | ||
if line.startswith('#'): | ||
continue | ||
arg,val = (a.strip() for a in line.split('=')) | ||
Input[arg] = float(val) | ||
#make a dummy class to hold values | ||
class IO: | ||
""" | ||
Dummy class to hold values like RAVEN does | ||
""" | ||
pass | ||
io = IO() | ||
#run the code | ||
print 'Simulating ...' | ||
run(io,Input) | ||
#write output | ||
print 'Writing output to',outFile+'.txt','...' | ||
outFile = open(outFile+'.txt','w') | ||
header = ' '.join("{:8s}".format(i) for i in ('x0','y0','v0','ang','r','x','y','t'))+ '\n' | ||
outFile.writelines(header.strip()+'\n') | ||
inpstr = ' '.join("{:8.4f}".format(i) for i in (io.x0,io.y0,io.v0,io.ang)) | ||
for i in range(len(io.t)): | ||
outFile.writelines( (inpstr+" " + ' '.join("{:8.4f}".format(i) for i in (io.r[i],io.x[i],io.y[i],io.t[i]))).strip() +"\n") | ||
outFile.writelines('-'*(8*8+4)+'\n') | ||
outFile.writelines('SUCCESS'+'\n') | ||
outFile.close() | ||
print 'Done!' | ||
print '' |
127 changes: 127 additions & 0 deletions
127
doc/workshop/advancedReliability/exercises/Inputs/1_adaptive_sampling.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
<?xml version="1.0" ?> | ||
<Simulation> | ||
<TestInfo> | ||
<name>doc/workshop/advancedReliability/exercises/Inputs.Adapt</name> | ||
<author>wangc</author> | ||
<created>2018-09-21</created> | ||
<classesTested>Sampler.LimitSurfaceSearch</classesTested> | ||
<description>Workshop test: advanced reliability test using Limit Surface Search</description> | ||
</TestInfo> | ||
|
||
<RunInfo> | ||
<WorkingDir>Results</WorkingDir> | ||
<Sequence>adaptive_sampling,plot</Sequence> | ||
<batchSize>10</batchSize> | ||
</RunInfo> | ||
|
||
<Steps> | ||
<MultiRun name="adaptive_sampling"> | ||
<!-- For hands-on, remove the following subnodes execept the SolutionExport --> | ||
<Sampler class="Samplers" type="LimitSurfaceSearch">adaptiveSearch</Sampler> | ||
<SolutionExport class="DataObjects" type="PointSet">limitSurface</SolutionExport> | ||
<Input class="DataObjects" type="PointSet">placeholder</Input> | ||
<Model class="Models" type="ExternalModel">projectile</Model> | ||
<Output class="DataObjects" type="PointSet">results</Output> | ||
<Output class="OutStreams" type="Print">to_file</Output> | ||
</MultiRun> | ||
<IOStep name="plot" pauseAtEnd="True"> | ||
<Input class="DataObjects" type="PointSet">results</Input> | ||
<Input class="DataObjects" type="PointSet">limitSurface</Input> | ||
<Output class="OutStreams" type="Print">to_file</Output> | ||
<Output class="OutStreams" type="Print">ls_to_file</Output> | ||
<Output class="OutStreams" type="Plot">to_plot</Output> | ||
</IOStep> | ||
</Steps> | ||
|
||
<Functions> | ||
<External file="adaptive_test_goal" name="decision"> | ||
<variable>r</variable> | ||
</External> | ||
</Functions> | ||
|
||
<Models> | ||
<ExternalModel ModuleToLoad="../../../../ExternalModels/projectile.py" name="projectile" subType=""> | ||
<variables>v0,angle,r,t</variables> | ||
</ExternalModel> | ||
<ROM name="acceleration_ROM" subType="SciKitLearn"> | ||
<Features>v0,angle</Features> | ||
<Target>decision</Target> | ||
<SKLtype>svm|SVC</SKLtype> | ||
<kernel>rbf</kernel> | ||
<gamma>10</gamma> | ||
<tol>1e-5</tol> | ||
<C>50</C> | ||
</ROM> | ||
</Models> | ||
|
||
<Samplers> | ||
<LimitSurfaceSearch name="adaptiveSearch"> | ||
<ROM class="Models" type="ROM">acceleration_ROM</ROM> | ||
<Function class="Functions" type="External">decision</Function> | ||
<TargetEvaluation class="DataObjects" type="PointSet">results</TargetEvaluation> | ||
<Convergence forceIteration="False" limit="3000" persistence="20" weight="CDF">5e-4</Convergence> | ||
<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> | ||
</LimitSurfaceSearch> | ||
</Samplers> | ||
|
||
<Distributions> | ||
<Normal name="vel_dist"> | ||
<mean>30</mean> | ||
<sigma>5</sigma> | ||
<lowerBound>1</lowerBound> | ||
<upperBound>60</upperBound> | ||
</Normal> | ||
<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> | ||
<PointSet name="limitSurface"> | ||
<Input>v0,angle</Input> | ||
<Output>decision</Output> | ||
</PointSet> | ||
</DataObjects> | ||
|
||
<OutStreams> | ||
<Print name="to_file"> | ||
<type>csv</type> | ||
<source>results</source> | ||
</Print> | ||
<Print name="ls_to_file"> | ||
<type>csv</type> | ||
<source>limitSurface</source> | ||
</Print> | ||
<Plot name="to_plot"> | ||
<plotSettings> | ||
<plot> | ||
<type>scatter</type> | ||
<x>limitSurface|Input|v0</x> | ||
<y>limitSurface|Input|angle</y> | ||
<colorMap>limitSurface|Output|decision</colorMap> | ||
</plot> | ||
<xlabel>v0</xlabel> | ||
<ylabel>angle</ylabel> | ||
</plotSettings> | ||
<actions> | ||
<how>png</how> | ||
</actions> | ||
</Plot> | ||
</OutStreams> | ||
|
||
</Simulation> |
Oops, something went wrong.