-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalcLagrangianForce.m
87 lines (68 loc) · 2.14 KB
/
calcLagrangianForce.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
function [F] = calcLagrangianForce(Xl, L, dtheta, XT, K, Kp);
%
% [F] = calcLagrangianForce(Xl, L, dtheta, XT, K, Kp);
%
% Calculates the elastic force at each Lagrangian Point
%
% Returns:
% F = elastic force on each Lagrangian point
%
% Input:
% Xl = Lagrangian point positions
% L = number of Lagrangian points
% dtheta = Lagrangian point spacing
% XT = target point config
%
% Notes:
% Does not handle wrapping across periodic boundaries of
% the immersed boundary.
%
%
% License: This code is free to use for any purposes, provided
% any publications resulting from the use of this code
% reference the original code/author.
%
% Author: Samuel Isaacson ([email protected])
% Date: 11/2007
%
% Please notify the author of any bugs, and contribute any
% modifications or bug fixes back to the original author.
%
% Disclaimer:
% This code is provided as is. The author takes no responsibility
% for its results or effects.
persistent Lap isInit L0Up L0Dn idxUp idxDn tmp LUp LDn TUp TDn numL;
if( size( isInit ) == 0 )
isInit = 1;
e = ones(L,1);
Lap = spdiags([e -2*e e], [-1:1], L, L);
% make periodic:
Lap(1,L) = 1;
Lap(L,1) = 1;
Lap = (K / (dtheta * dtheta)) * Lap;
numL = length(XT(:,1));
idxUp = [2:numL 1]';
idxDn = [numL 1:(numL-1)]';
tmp = XT(idxUp,:) - XT;
L0Up = sqrt(dot(tmp,tmp,2));
tmp = XT - XT(idxDn,:);
L0Dn = sqrt(dot(tmp,tmp,2));
LUp = zeros(numL,1);
LDn = zeros(numL,1);
TUp = zeros(numL,2);
TDn = zeros(numL,2);
end
% no rest length springs
F = [( Lap * Xl(:,1) ) ( Lap * Xl(:,2) )];
% springs with rest length:
%tmp = Xl(idxUp,:) - Xl;
%LUp = sqrt(dot(tmp,tmp,2));
%TUp = [(tmp(:,1) ./ LUp) (tmp(:,2) ./ LUp)];
%tmp = Xl - Xl(idxDn,:);
%LDn = sqrt(dot(tmp,tmp,2));
%TDn = [(tmp(:,1) ./ LDn) (tmp(:,2) ./ LDn)];
%F = zeros(numL, 2);
%F(:,1) = (K / (dtheta*dtheta)) * ( (LUp - L0Up) .* TUp(:,1) - (LDn - L0Dn) .* TDn(:,1) );
%F(:,2) = (K / (dtheta*dtheta)) * ( (LUp - L0Up) .* TUp(:,2) - (LDn - L0Dn) .* TDn(:,2) );
% target points
%F = F + Kp * ( XT - Xl );