-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathintegrate_flow.m
91 lines (79 loc) · 2.82 KB
/
integrate_flow.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
%integrate_flow Integrate flow
%
% SYNTAX
% flowSolution = integrate_flow(flow,initialPosition,useEoV)
% flowSolution = integrate_flow(flow,initialPosition,useEoV,verbose)
%
% INPUT ARGUMENTS
% initialPosition: n-by-2 array
% useEoV: true or false
% verbose: true or false
function flowSolution = integrate_flow(flow,initialPosition,varargin)
narginchk(2,4)
p = inputParser;
addRequired(p,'flow',@isstruct)
addRequired(p,'initialPosition',@(i)validateattributes(i,{'double'},{'ncols',2}))
addOptional(p,'useEoV',false,@islogical)
addOptional(p,'verbose',false,@islogical)
parse(p,flow,initialPosition,varargin{:});
useEoV = p.Results.useEoV;
verbose = p.Results.verbose;
% Set default values for flow structure
p = inputParser;
p.KeepUnmatched = true;
addParameter(p,'coupledIntegration',true,@islogical)
addParameter(p,'odeSolverOptions',odeset,@isstruct);
parse(p,flow);
coupledIntegration = p.Results.coupledIntegration;
odeSolverOptions = p.Results.odeSolverOptions;
nPosition = size(initialPosition,1);
if verbose
if ~exist('ParforProgressStarter2','file')
addpath('ParforProgress2')
end
progressBar = ParforProgressStarter2(mfilename,nPosition);
else
progressBar = [];
end
odefun = flow.derivative;
timespan = flow.timespan;
if coupledIntegration
% FIXME Copy-paste from eig_cgStrain
initialPosition = transpose(initialPosition);
initialPosition = initialPosition(:);
flowSolution = ode45(@(t,y)odefun(t,y,useEoV),timespan,initialPosition,odeSolverOptions);
else
flowCgStrainMethodName = flow.cgStrainMethod.name;
% FIXME If ODE solution structure is changed by MathWorks, this will
% break
flowSolution(nPosition) = struct('solver',[],'extdata',[],'x',[],'y',[],'stats',[],'idata',[]);
switch flowCgStrainMethodName
case 'finiteDifference'
parfor iPosition = 1:nPosition
flowSolution(iPosition) = ode45(@(t,y)odefun(t,y,useEoV),timespan,initialPosition(iPosition,:),odeSolverOptions); %#ok<PFBNS>
if verbose
progressBar.increment(iPosition) %#ok<PFBNS>
end
end
case 'equationOfVariation'
parfor iPosition = 1:nPosition
if useEoV
dFlowMap0 = eye(2);
dFlowMap0 = reshape(dFlowMap0,4,1);
iInitialPosition = [initialPosition(iPosition,:),dFlowMap0];
else
iInitialPosition = initialPosition(iPosition,:);
end
flowSolution(iPosition) = ode45(@(t,y)odefun(t,y,useEoV),timespan,iInitialPosition,odeSolverOptions); %#ok<PFBNS>
if verbose
progressBar.increment(iPosition) %#ok<PFBNS>
end
end
end
end
if verbose
try
delete(progressBar)
catch me %#ok<NASGU>
end
end