|
|
|
<!DOCTYPE html
|
|
PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<html><head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
<!--
|
|
This HTML was auto-generated from MATLAB code.
|
|
To make changes, update the MATLAB code and republish this document.
|
|
--><title>paramSweepParallel</title><meta name="generator" content="MATLAB 8.2"><link rel="schema.DC" href="http://purl.org/dc/elements/1.1/"><meta name="DC.date" content="2014-01-09"><meta name="DC.source" content="paramSweepParallel.m"><style type="text/css">
|
|
html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,font,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td{margin:0;padding:0;border:0;outline:0;font-size:100%;vertical-align:baseline;background:transparent}body{line-height:1}ol,ul{list-style:none}blockquote,q{quotes:none}blockquote:before,blockquote:after,q:before,q:after{content:'';content:none}:focus{outine:0}ins{text-decoration:none}del{text-decoration:line-through}table{border-collapse:collapse;border-spacing:0}
|
|
|
|
html { min-height:100%; margin-bottom:1px; }
|
|
html body { height:100%; margin:0px; font-family:Arial, Helvetica, sans-serif; font-size:10px; color:#000; line-height:140%; background:#fff none; overflow-y:scroll; }
|
|
html body td { vertical-align:top; text-align:left; }
|
|
|
|
h1 { padding:0px; margin:0px 0px 25px; font-family:Arial, Helvetica, sans-serif; font-size:1.5em; color:#d55000; line-height:100%; font-weight:normal; }
|
|
h2 { padding:0px; margin:0px 0px 8px; font-family:Arial, Helvetica, sans-serif; font-size:1.2em; color:#000; font-weight:bold; line-height:140%; border-bottom:1px solid #d6d4d4; display:block; }
|
|
h3 { padding:0px; margin:0px 0px 5px; font-family:Arial, Helvetica, sans-serif; font-size:1.1em; color:#000; font-weight:bold; line-height:140%; }
|
|
|
|
a { color:#005fce; text-decoration:none; }
|
|
a:hover { color:#005fce; text-decoration:underline; }
|
|
a:visited { color:#004aa0; text-decoration:none; }
|
|
|
|
p { padding:0px; margin:0px 0px 20px; }
|
|
img { padding:0px; margin:0px 0px 20px; border:none; }
|
|
p img, pre img, tt img, li img { margin-bottom:0px; }
|
|
|
|
ul { padding:0px; margin:0px 0px 20px 23px; list-style:square; }
|
|
ul li { padding:0px; margin:0px 0px 7px 0px; }
|
|
ul li ul { padding:5px 0px 0px; margin:0px 0px 7px 23px; }
|
|
ul li ol li { list-style:decimal; }
|
|
ol { padding:0px; margin:0px 0px 20px 0px; list-style:decimal; }
|
|
ol li { padding:0px; margin:0px 0px 7px 23px; list-style-type:decimal; }
|
|
ol li ol { padding:5px 0px 0px; margin:0px 0px 7px 0px; }
|
|
ol li ol li { list-style-type:lower-alpha; }
|
|
ol li ul { padding-top:7px; }
|
|
ol li ul li { list-style:square; }
|
|
|
|
.content { font-size:1.2em; line-height:140%; padding: 20px; }
|
|
|
|
pre, tt, code { font-size:12px; }
|
|
pre { margin:0px 0px 20px; }
|
|
pre.error { color:red; }
|
|
pre.codeinput { padding:10px; border:1px solid #d3d3d3; background:#f7f7f7; }
|
|
pre.codeoutput { padding:10px 11px; margin:0px 0px 20px; color:#4c4c4c; }
|
|
|
|
@media print { pre.codeinput, pre.codeoutput { word-wrap:break-word; width:100%; } }
|
|
|
|
span.keyword { color:#0000FF }
|
|
span.comment { color:#228B22 }
|
|
span.string { color:#A020F0 }
|
|
span.untermstring { color:#B20000 }
|
|
span.syscmd { color:#B28C00 }
|
|
|
|
.footer { width:auto; padding:10px 0px; margin:25px 0px 0px; border-top:1px dotted #878787; font-size:0.8em; line-height:140%; font-style:italic; color:#878787; text-align:left; float:none; }
|
|
.footer p { margin:0px; }
|
|
.footer a { color:#878787; }
|
|
.footer a:hover { color:#878787; text-decoration:underline; }
|
|
.footer a:visited { color:#878787; }
|
|
|
|
table th { padding:7px 5px; text-align:left; vertical-align:middle; border: 1px solid #d6d4d4; font-weight:bold; }
|
|
table td { padding:7px 5px; text-align:left; vertical-align:top; border:1px solid #d6d4d4; }
|
|
|
|
|
|
|
|
|
|
|
|
</style></head><body><div class="content"><h2>Contents</h2><div><ul><li><a href="#2">Parameter Sweep of ODEs</a></li><li><a href="#3">Initialize Problem</a></li><li><a href="#4">Parameter Sweep</a></li><li><a href="#5">Visualize</a></li></ul></div><pre class="codeinput"><span class="keyword">function</span> [peakVals,mainComputationTime,nVals,aVals]=paramSweepParallel(nNum,aNum,hTopAxes)
|
|
</pre><h2>Parameter Sweep of ODEs<a name="2"></a></h2><p>This is a parameter sweep study of a 2nd order ODE system.</p><p><img src="paramSweepParallel_eq65211.png" alt="$m\ddot{x} + b\dot{x} + kx = 0$"></p><p>We solve the ODE for a time span of 0 to 25 seconds, with initial conditions <img src="paramSweepParallel_eq62808.png" alt="$x(0) = 0$"> and <img src="paramSweepParallel_eq08342.png" alt="$\dot{x}(0) = 1$">. We sweep the parameters <img src="paramSweepParallel_eq28812.png" alt="$b$"> and <img src="paramSweepParallel_eq86607.png" alt="$k$"> and record the peak values of <img src="paramSweepParallel_eq43551.png" alt="$x$"> for each condition. At the end, we plot a surface of the results.</p><pre class="codeinput"><span class="comment">% SCd</span>
|
|
<span class="keyword">if</span> ~nargin
|
|
nNum = 5;
|
|
aNum = 5;
|
|
hTopAxes = gca;
|
|
<span class="keyword">end</span>
|
|
</pre><img vspace="5" hspace="5" src="paramSweepParallel_01.png" alt=""> <h2>Initialize Problem<a name="3"></a></h2><pre class="codeinput">nVals = round(linspace(10, 20, nNum)); <span class="comment">% number of segments</span>
|
|
aVals = linspace(1, 200, aNum); <span class="comment">% cross sectional area</span>
|
|
[nGrid, aGrid] = meshgrid(nVals, aVals);
|
|
peakVals = nan(size(aGrid));
|
|
</pre><h2>Parameter Sweep<a name="4"></a></h2><pre class="codeinput">t0 = tic;
|
|
<span class="keyword">parfor</span> ii = 1:numel(aGrid)
|
|
<span class="comment">% Solve ODE</span>
|
|
Y=trussCantilever(nGrid(ii),aGrid(ii));
|
|
|
|
<span class="comment">% Determine peak deflection in Y direction</span>
|
|
peakVals(ii) = max(Y(:,2));
|
|
<span class="keyword">end</span>
|
|
mainComputationTime = toc(t0);
|
|
</pre><pre class="codeoutput">Starting parallel pool (parpool) using the 'local' profile ... connected to 4 workers.
|
|
</pre><h2>Visualize<a name="5"></a></h2><pre class="codeinput"><span class="keyword">if</span> ~isempty(hTopAxes)
|
|
visualizeParamSweep(hTopAxes,nVals, aVals, peakVals);
|
|
<span class="keyword">end</span>
|
|
</pre><pre class="codeoutput">ans =
|
|
1.0e-03 *
|
|
0.0731 0.0342 0.0179 0.0195 0.0187
|
|
0.2926 0.1737 0.1244 0.0790 0.0602
|
|
0.2897 0.1861 0.1397 0.0948 0.0735
|
|
0.2555 0.1783 0.1391 0.0956 0.0768
|
|
0.2257 0.1634 0.1322 0.0952 0.0758
|
|
</pre><img vspace="5" hspace="5" src="paramSweepParallel_02.png" alt=""> <p class="footer">Copyright 2009-2013 The MathWorks, Inc.<br><a href="http://www.mathworks.com/products/matlab/">Published with MATLAB® R2013b</a><br></p></div><!--
|
|
##### SOURCE BEGIN #####
|
|
function [peakVals,mainComputationTime,nVals,aVals]=paramSweepParallel(nNum,aNum,hTopAxes)
|
|
%% Parameter Sweep of ODEs
|
|
% This is a parameter sweep study of a 2nd order ODE system.
|
|
%
|
|
% $m\ddot{x} + b\dot{x} + kx = 0$
|
|
%
|
|
% We solve the ODE for a time span of 0 to 25 seconds, with initial
|
|
% conditions $x(0) = 0$ and $\dot{x}(0) = 1$. We sweep the parameters $b$
|
|
% and $k$ and record the peak values of $x$ for each condition. At the end,
|
|
% we plot a surface of the results.
|
|
%
|
|
% Copyright 2009-2013 The MathWorks, Inc.
|
|
|
|
% SCd
|
|
if ~nargin
|
|
nNum = 5;
|
|
aNum = 5;
|
|
hTopAxes = gca;
|
|
end
|
|
|
|
%% Initialize Problem
|
|
|
|
nVals = round(linspace(10, 20, nNum)); % number of segments
|
|
aVals = linspace(1, 200, aNum); % cross sectional area
|
|
[nGrid, aGrid] = meshgrid(nVals, aVals);
|
|
peakVals = nan(size(aGrid));
|
|
|
|
%% Parameter Sweep
|
|
|
|
t0 = tic;
|
|
parfor ii = 1:numel(aGrid)
|
|
% Solve ODE
|
|
Y=trussCantilever(nGrid(ii),aGrid(ii));
|
|
|
|
% Determine peak deflection in Y direction
|
|
peakVals(ii) = max(Y(:,2));
|
|
end
|
|
mainComputationTime = toc(t0);
|
|
|
|
%% Visualize
|
|
if ~isempty(hTopAxes)
|
|
visualizeParamSweep(hTopAxes,nVals, aVals, peakVals);
|
|
end
|
|
|
|
|
|
|
|
|
|
##### SOURCE END #####
|
|
--></body></html>
|