-
Notifications
You must be signed in to change notification settings - Fork 2
/
applyForces.m
executable file
·32 lines (23 loc) · 1.05 KB
/
applyForces.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
function [xyOut, headingsOut] = applyForces(arrayPrev,forceArray,dT,headings,bc,L)
% update positions based on current directions, respecting boundary
% conditions
% issues/to-do's:
% - length can be violated again by boundary conditions (though
% should be met considering arclength of high M limit)
% short-hand for indexing coordinates
x = 1;
y = 2;
% N = size(arrayPrev,1); % number of woids
% M = size(arrayPrev,2); % number of nodes
arrayNow = arrayPrev;
% forceAngles = atan2(forceArray(:,:,y),forceArray(:,:,x));
v = sqrt(sum(forceArray.^2,3));
% update position - forward Euler
arrayNow(:,:,x) = arrayPrev(:,:,x) + forceArray(:,:,x)*dT;
arrayNow(:,:,y) = arrayPrev(:,:,y) + forceArray(:,:,y)*dT;
% assert no large displacements - max(v)*dT = v0*dT0
assert(~any(abs(arrayPrev(:) - arrayNow(:))>4*max(v(:))*dT),...
'Uh-oh, something has gone wrong... (large displacements)')
% correct heading (e.g. if movement has been constrained)
headings = correctHeading(forceArray);
[xyOut, headingsOut] = checkWoidBoundaryConditions(arrayNow,headings,bc,L);