Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ab calc #35

Merged
merged 102 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
396da7a
work on hydro coeffs for cone and using bessel functions
rebeccamccabe Oct 11, 2022
4eb04c4
gamma bessel function stuff
rebeccamccabe Nov 15, 2022
b1f67a6
symbolic BVP solving for compound cylinder
rebeccamccabe Dec 4, 2022
c33ad28
Chau Yeung equations implemented but doesnt solve
rebeccamccabe Dec 7, 2022
325a64a
solver runs for n=1 but gives results as a fn of r
rebeccamccabe Dec 11, 2022
07efb72
fix forgetting to sub a for r in Lambda
rebeccamccabe Dec 11, 2022
053b313
working plots of potential
rebeccamccabe Dec 12, 2022
8b61206
get plots for force as function of geometry
rebeccamccabe Dec 13, 2022
7b3d1df
refactor to use a big for loop for each geometry
rebeccamccabe Dec 14, 2022
b6646f5
fix loop running and add dispersion relation m_k equation
rebeccamccabe Dec 15, 2022
c2cc0f2
cleanup unused code and add numerical m_k solver, doesnt run
rebeccamccabe Dec 15, 2022
d54ce89
better error handling on lin solver
rebeccamccabe Dec 15, 2022
3e0882c
try to subs m_k with consts, same problem
rebeccamccabe Dec 15, 2022
ea5c816
frequency loop runs but doesnt produce graph
rebeccamccabe Dec 15, 2022
34292a0
code to make contour plots of force for diff geometries
rebeccamccabe Dec 15, 2022
ae4fbd5
fix contour code by reshaping
rebeccamccabe Dec 15, 2022
bd025f2
fix invalid geometry and m_k substitution, it runs
rebeccamccabe Dec 20, 2022
e025e9d
get rid of override on m_k, runs but phi sometimes negative
rebeccamccabe Dec 20, 2022
0f7aa64
Merge remote-tracking branch 'origin/submission' into better-hydro-co…
rebeccamccabe Dec 21, 2022
7f3ca21
remove dz multiplication
rebeccamccabe Mar 18, 2023
49ef861
fix parentheses problem with N_k, cos problem with Z_k_e
rebeccamccabe Mar 19, 2023
eeea70f
add back dzs on both sides of the eqn, and fix plot
rebeccamccabe Mar 19, 2023
ff13cbc
fix a sinh that is supposed to be sin
rebeccamccabe Mar 20, 2023
08187e5
plot particular and homogeneous potential separately
rebeccamccabe Mar 28, 2023
e78c7e0
demonstrate symbolic differentiation of 5x5 matrix
rebeccamccabe Mar 28, 2023
0f92c48
add velocity field plots
rebeccamccabe Apr 11, 2023
a8e77f7
velocity quiver plot
rebeccamccabe Apr 11, 2023
05399e0
make live script for BC checking, get symbolic solve working
rebeccamccabe May 6, 2023
1c67467
fix z origin of coord system being in wrong spot
rebeccamccabe May 6, 2023
5c8ad26
better boundary condition checking, focus on radial velocity on body
rebeccamccabe May 6, 2023
f18e1f2
revamp sym structure, matlabFunction generation, m_k solver
rebeccamccabe May 7, 2023
e48d41c
matlabFunction works now and produces potential plot
rebeccamccabe May 7, 2023
94fc9ce
m_k solver is now integrated into the solve for the figure, region 2 …
rebeccamccabe May 8, 2023
20be47a
add plots for matching of potential on boundaries
rebeccamccabe May 8, 2023
56a137a
add symbolic derivatives to geometric variables
rebeccamccabe May 8, 2023
39ac9c5
allow coeffs to be complex, doesnt change the solution
rebeccamccabe May 8, 2023
81937bf
update legend
rebeccamccabe May 14, 2023
4e8a367
not sure what changed
rebeccamccabe May 14, 2023
202d4ea
modify plot with contours every 10
rebeccamccabe May 17, 2023
5cfc8b8
integration of phi for AB added
KapilKhanal May 27, 2023
bcf6cac
add integral and hydro coefficients - stuck running
rebeccamccabe May 29, 2023
9c83eb3
integration worked for N=1, possibly N=20
rebeccamccabe May 30, 2023
b406d09
write file for N=20
rebeccamccabe May 30, 2023
008303f
generated file for hydro coeffs
rebeccamccabe May 30, 2023
52a60cc
clean up comments and cells for Kapil to run
rebeccamccabe May 30, 2023
3954c66
add duplicate since other file broken
rebeccamccabe May 30, 2023
4f30f06
dumping changes from summer
rebeccamccabe Jul 6, 2023
d60d283
implement symbolic solve with proper eigenfunctions, n=/=k and coupli…
rebeccamccabe Sep 17, 2023
5398316
numerical solve and plots for new eigenfunctions, BCs dont look satis…
rebeccamccabe Sep 20, 2023
6ec91cc
partially update hydro .m, still need to change matrix size
rebeccamccabe Oct 7, 2023
22a8210
increase N and resolution; h from 10 to 11 to avoid /0; fix BC check
rebeccamccabe Oct 17, 2023
b564a95
reformulate the 2-e BCs and matching looks successful!!
rebeccamccabe Oct 18, 2023
d1f003f
add option for new BCs with different bounds for phi and vel
rebeccamccabe Oct 22, 2023
a84f53e
change dimensions to match h=1 of paper
rebeccamccabe Nov 8, 2023
405b3d7
try scaling for better condition number, but little effect
rebeccamccabe Nov 10, 2023
26d7b2f
systematically compare different matching strategies
rebeccamccabe Dec 11, 2023
add5773
add potential comparison plot
rebeccamccabe Dec 25, 2023
067bd78
plot particular and homogenous potential and velocity
rebeccamccabe Feb 23, 2024
ed0a991
attempt at generating BCs automatically, but n=m issue
rebeccamccabe Mar 11, 2024
3955707
BCs return ok but coefficients arent function of harmonic
rebeccamccabe Mar 12, 2024
79452d9
fix issue with generated BC where C and m_k werent symfuns; add spy o…
rebeccamccabe Apr 17, 2024
a7d0620
fix issue with nested matrix, generated BCs now runs but potential lo…
rebeccamccabe Apr 17, 2024
176712e
plots from fileexchange for showing A matrix values
rebeccamccabe Apr 17, 2024
9105bd4
fix error where C_2n_1 was flipped with C_2n_2 in auto BCs
rebeccamccabe Apr 24, 2024
0f496df
fix parenthesis in 1-2 potential, fiddle with integral bounds. Potent…
rebeccamccabe Apr 24, 2024
6f7b564
add .fig to gitignore for saved figures
rebeccamccabe Apr 24, 2024
599b75e
ready for running nums programatically: comment clear all, add semico…
rebeccamccabe May 1, 2024
630d192
run and display all binary comparisons for velocity
rebeccamccabe May 1, 2024
d0c825e
fix error with ds not being evaluated, and reformat in-out vs region …
rebeccamccabe May 1, 2024
6cf74fd
adjust N,M,K indices to be consistent; use radii eps away from the bo…
rebeccamccabe May 8, 2024
0a3a175
lower N M K down to run faster again
rebeccamccabe May 8, 2024
78a6702
allow for white to be at a point other than zero
rebeccamccabe May 8, 2024
ef85ebe
cleanup and delete old commented code
rebeccamccabe May 9, 2024
838938b
fix error: transpose instead of conjugate transpose. MATCHING WORKS!
rebeccamccabe May 9, 2024
a164ca7
add 2012 validation, remove small large logic, fix N M K assumptions,…
rebeccamccabe May 12, 2024
1c1de19
refactor to use matlabFunction, do symbolic stuff in function, and ou…
rebeccamccabe May 13, 2024
f2f5aab
cleanup by creating MEEM folder and deleting unneeded old generated f…
rebeccamccabe May 13, 2024
0dc31fe
tweak the way normalizing is done
rebeccamccabe May 13, 2024
084d408
fix filename for saving plots
rebeccamccabe May 14, 2024
d6ee404
delete old stuff that is superseded by Chau_Yeung_live.mlx
rebeccamccabe May 17, 2024
9084b2d
add assert for valid geometry
rebeccamccabe May 17, 2024
0bac5cf
refactor to have more smaller functions
rebeccamccabe May 17, 2024
a28ab4c
move remaining functionality out of live script, and include setup in…
rebeccamccabe May 18, 2024
54955e7
change symbolic m_k solve to numeric for big speedup
rebeccamccabe May 18, 2024
660faa7
add convergence study for N=3,5,10
rebeccamccabe May 19, 2024
d80c177
add N=1 and graph with N on x axis to convergence study
rebeccamccabe May 21, 2024
777d1fa
add validation of hydro coeffs, but it doesnt match
rebeccamccabe May 21, 2024
11b302c
find fudge factors which make hydro coeff validation match
rebeccamccabe May 21, 2024
f005a39
move the fudge factor to be on our code rather than validation
rebeccamccabe May 21, 2024
f96c2ef
correct hydro coeff normalization error, validation ok now
rebeccamccabe May 21, 2024
be8b717
integrate MEEM into mdocean, gives LCOE around $3
rebeccamccabe May 21, 2024
31f90ee
update todo list
rebeccamccabe May 21, 2024
0d53293
add N=10 outer functions
rebeccamccabe May 21, 2024
2e46b44
Merge remote-tracking branch 'origin/main' into AB_calc
rebeccamccabe May 21, 2024
3a93eb4
move core MEEM files out of dev folder and into mdocean folder
rebeccamccabe May 21, 2024
0a9acce
update todo and delete finished items
rebeccamccabe May 21, 2024
7d8178c
delete and organize old files for MEEM and diffraction hydro coeffs
rebeccamccabe May 22, 2024
b0eb97a
change mlx to m file
rebeccamccabe May 22, 2024
e52b2ce
rename old file to more appropriately describe content
rebeccamccabe May 22, 2024
fdbf100
clarify license for bluewhitered
rebeccamccabe May 22, 2024
f44381b
add attribution to imrange
rebeccamccabe May 22, 2024
e034aa2
avoid rerunning MEEM for different Hs, resulting in 15x speedup
rebeccamccabe May 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ html/
code-coverage/
test-results/

# figures
*.fig

# mat data files
*.mat

# excel cache
~$*.xlsx
~$*.xlsx
79 changes: 79 additions & 0 deletions dev/MEEM/compare_MEEM_figs.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
%% Comparing using small and large

folder = ['dev' filesep 'MEEM_figs'];

phis = {'small-small','large-large'};
vels = {'small-small','large-small','large-large'};
figure
tcl = tiledlayout(length(vels),length(phis)*2);
for i_phi = 1:length(phis)
for i_vel = 1:length(vels)
file = sprintf('*%s*.fig',['phi = ' phis{i_phi} ', vel = ' vels{i_vel}]);
all_fnames = dir(fullfile(folder,file));
fname = all_fnames(end).name; % latest
fig = openfig(fname);

ax = fig.Children(4);
ax.Parent = tcl;
ax.Layout.Tile = (i_vel-1)*2*length(phis) + 2*i_phi - 1;
if i_vel==length(vels)
xl = xlim;
yl = ylim;
text(ax, 1.25*xl(2), 1.25*yl(1), phis{i_phi})
end
if i_phi == 1
ylabel(ax, {vels{i_vel}, 'Z'})
end
title(ax,'Real')

ax2 = fig.Children(2);
ax2.Parent = tcl;
ax2.Layout.Tile = (i_vel-1)*2*length(phis) + 2*i_phi;
title(ax2,'Imaginary')
end
end
title(tcl,'Total Potential for Different Matching Strategies (N=6)')
subtitle(tcl,'Integration Region Size - Eigenfunction Size')
xlabel(tcl,'Potential Matching Strategy')
ylabel(tcl,'Velocity Matching Strategy')

%% Generate binary combinations
clear all
for num=0:31
disp(['running num=' num2str(num)])
try
Chau_Yeung_live()
catch
disp(['num=' num2str(num) ' failed.'])
end
end

%% Comparing using binary combinations
folder = ['dev' filesep 'MEEM_figs'];

figure

file = sprintf('*%s*%s*%s*.fig','04-30',', BC = ','VelMatch');
all_fnames = dir(fullfile(folder,file));
tile_length = ceil(sqrt(length(all_fnames)));
tcl = tiledlayout(tile_length,tile_length);

for i = 1:length(all_fnames)
fname = all_fnames(i).name;
BC_num = regexp(fname, 'BC = (\d+)', 'tokens', 'once');
fig = openfig(fname);
if i~=length(all_fnames)
legend off
ax = fig.Children;
else
ax = fig.Children(2);
end
ax.Parent = tcl;
ax.Layout.Tile = i;
title(ax,['BC = ', BC_num{:}])


end

title(tcl,'Radial Velocity for Different Matching Strategies (N=2)')

62 changes: 62 additions & 0 deletions dev/MEEM/convergence_study.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@

clear all
close all

%% settings
auto_BCs = false;

heaving_OC = true;
heaving_IC = true;

plot_phi = false;
show_A = false;

%% set numerical values
a1_num = .5;
a2_num = 1;
d1_num = .5;
d2_num = .25;
h_num = 1.001;
m0_nums = linspace(0.1,5,100);
spatial_res = 30;

num_harmonics = [1 3 5 10];
run_multiple_harmonics(num_harmonics, heaving_IC, heaving_OC, auto_BCs, ...
a1_num, a2_num, d1_num, d2_num, h_num, m0_nums, spatial_res, show_A, plot_phi);

function run_multiple_harmonics(num_harmonics, heaving_IC, heaving_OC, auto_BCs, ...
a1_num, a2_num, d1_num, d2_num, h_num, m0_num, spatial_res, show_A, plot_phi)

numels = [numel(a1_num), numel(a2_num), numel(d1_num), numel(d2_num), ...
numel(h_num), numel(m0_num)];
mu_nondim = zeros(length(num_harmonics), max(numels));
lambda_nondim = zeros(length(num_harmonics), max(numels));

for i=1:length(num_harmonics)
N_num = num_harmonics(i);
M_num = num_harmonics(i);
K_num = num_harmonics(i);
[mu_nondim(i,:), lambda_nondim(i,:)] = run_MEEM(heaving_IC, heaving_OC, auto_BCs, N_num, M_num, K_num, ...
a1_num, a2_num, d1_num, d2_num, h_num, m0_num, spatial_res, show_A, plot_phi);
end

%% plot hydro coeffs vs wavenumber
if i==1
figure
end
plot(m0_num,mu_nondim, m0_num,lambda_nondim,'--')
xlabel('Wavenumber m_0')
ylabel('Nondimensional Hydro Coeff')
legend('Added Mass','Damping')
grid on
hold on
legend(cellstr(num2str([num_harmonics(:); num_harmonics(:)])))
improvePlot

figure
plot(num_harmonics, mu_nondim(:,1), '*-', num_harmonics, lambda_nondim(:,1),'*-')
xlabel('Number of Harmonics')
ylabel('Nondimensional Hydro Coefficient')
legend('Added Mass','Damping')
improvePlot
end
207 changes: 207 additions & 0 deletions dev/MEEM/generate_BC.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@

% syms a1 n
% tic
% generate_BC_asdf(0,0,1,1,0,n,a1,4)
% toc

function BC = generate_BC(LHS_d_in_out, LHS_phi_in_out, RHS_d_in_out, ...
RHS_phi_in_out, both_Z_in_out, m, a, N)

% hack to show the eigenfunction names rather than their expressions
global override
override = false;

% pass in five binary bits here for which region (outer/inner) is used
% for which pieces of the matching condition
% false = 0 = out, true = 1 = in
% expected correct answer: 0, 0, 1, 1, 0 for velocity matching

% LHS (left hand side) is defined as the side where orthogonality happens
% RHS (right hand side) is defined as the side where coupling integral happens

% first step: change from in/out to actual region
LHS_d_region = get_region_from_in_out_radius(LHS_d_in_out, a);
LHS_phi_region = get_region_from_in_out_radius(LHS_phi_in_out, a);
RHS_d_region = get_region_from_in_out_radius(RHS_d_in_out, a);
RHS_phi_region = get_region_from_in_out_radius(RHS_phi_in_out, a);
both_Z_region = get_region_from_in_out_radius(both_Z_in_out, a);

Z_m(m) = get_Z(both_Z_region, m);

syms z h
% LHS
integrand_LHS = get_dphi_p_dr(LHS_phi_region,a) * Z_m;
C_LHS(m) = get_C(LHS_phi_region, m);
dR_dr_LHS(m) = get_dR_dr(LHS_phi_region, m, a);
LHS = int(integrand_LHS, z, -h, -get_d(LHS_d_region)) + ...
(h - get_d(LHS_d_region)) * C_LHS * dR_dr_LHS.';

% RHS
j = sym('j'); % summation index
integrand_RHS = get_dphi_p_dr(RHS_phi_region, a) * Z_m;
Z_n(j) = get_Z(RHS_phi_region, j);
coupling_integral(j,m) = int(Z_n(j) * Z_m(m), z, -h, -get_d(RHS_d_region));
C_RHS(j) = get_C(RHS_phi_region, j);
dR_dr_RHS(j) = get_dR_dr(RHS_phi_region, j, a);
sum_RHS(j,m) = C_RHS(j) * dR_dr_RHS(j).' * coupling_integral(j,m);
RHS = int(integrand_RHS, z, -h, -get_d(RHS_d_region)) + symsum(sum_RHS, j, 0, N);

% equation
BC = LHS == RHS;

end

function d_phi_p_dr = get_dphi_p_dr(region, radius)
syms h z r
if strcmp(region,'i1') || strcmp(region,'i2')
di = get_d(region);
% eq 5
phi_p = 1/(2*(h-di)) * ((z+h)^2 - r^2/2);
d_phi_p_dr = subs( diff(phi_p, r), r, radius);
elseif strcmp(region,'e')
d_phi_p_dr = 0;
end

global override
if override
name = ['dphi_p_' region '_dr'];
syms(name)
d_phi_p_dr = eval(name);
end

end

function lambda = lambda(j,region)
syms h
% eq 4
di = get_d(region);
lambda(j) = j*pi/(h-di);
end

function di = get_d(region)
syms d1 d2
if strcmp(region,'i1')
di = d1;
elseif strcmp(region,'i2')
di = d2;
elseif strcmp(region,'e')
di = 0;
end
end

function Z = get_Z(region, j)
syms z h

if strcmp(region,'i1') || strcmp(region,'i2')
% equation 9
Z = piecewise(j==0, 1, ...
j>=1, sqrt(2)*cos(lambda(j,region)*(z+h)) ...
);
elseif strcmp(region,'e')
syms m0 m_k(dv)
% dv means dummy variable: due to weird symbolic syntax it's necessary
% to create the symfun as a function of the dummy and then replace it with j,
% instead of directly creating it as a function of j
m_k(j) = subs(m_k,dv,j);

% eq 2.34 in analytical methods book, also eq 16 in Seah and Yeung 2006
N_k(j) = piecewise(j==0, 1/2*(1+sinh(2*m0*h)/(2*m0*h)), ...
j>=1, 1/2*(1+sin(2*m_k(j)*h)/(2*m_k(j)*h)) ...
);
% equation 14
Z(j) = piecewise(j==0, 1/sqrt(N_k(j)) * cosh(m0 * (z+h)), ...
j>=1, 1/sqrt(N_k(j)) * cos(m_k(j) * (z+h)) ...
);
end
global override
if override
name = ['Z_' region];
syms(name)
Z(j) = eval(name);
end
end

function C = get_C(region, j)
% dv means dummy variable: due to weird symbolic syntax it's necessary
% to create the symfun as a function of the dummy and then replace it with j,
% instead of directly creating it as a function of j
syms C_1n_1(dv) C_1n_2(dv) C_2n_2(dv) B_k(dv)
C_1n_1(j) = subs(C_1n_1,dv,j);
C_1n_2(j) = subs(C_1n_2,dv,j);
C_2n_2(j) = subs(C_2n_2,dv,j);
B_k(j) = subs(B_k, dv,j);

if strcmp(region,'i1')
C(j) = [C_1n_1(j), 0];
elseif strcmp(region,'i2')
C(j) = [C_1n_2(j), C_2n_2(j)];
elseif strcmp(region,'e')
C(j) = B_k(j);
end

end

function dR_dr = get_dR_dr(region, j, radius)

syms r
R = get_R(region, j);
dR_dr = subs( diff(R,r), r, radius);

global override
if override
if strcmp(region,'i2') || strcmp(region,'i1')
names = {['dR_1n_' region '_dr'], ['dR_2n_' region '_dr']};
syms(names{1},names{2});
dR_dr = [eval(names{1}), eval(names{2})];
else
name = ['dR_' region '_dr'];
syms(name);
dR_dr = eval(name);
end
end

end

function R = get_R(region, j)
syms r a2 m0

% dv means dummy variable: due to weird symbolic syntax it's necessary
% to create the symfun as a function of the dummy and then replace it with j,
% instead of directly creating it as a function of j
syms R(dv) m_k(dv)
R(j) = subs(R,dv,j);
m_k(j) = subs(m_k,dv,j);

if strcmp(region,'i1') || strcmp(region,'i2')
% eq 7
R_1n(j) = piecewise(j==0, 1/2, j>=1, ...
besseli(0,lambda(j,region)*r)/besseli(0,lambda(j,region)*a2));
if strcmp(region,'i1')
% eq 8
R_2n(j) = sym(0);
else
R_2n(j) = piecewise(j==0, 1/2*log(r/a2), ...
j>=1, besselk(0,lambda(j,region)*r)/besselk(0,lambda(j,region)*a2));
end
R = [R_1n, R_2n];

elseif strcmp(region,'e')
% eq 13
Lambda_k(j) = piecewise(j==0, besselh(0,1,m0*r)/besselh(0,1,m0*a2), ...
j>=1, besselk(0,m_k(j)*r)/besselk(0,m_k(j)*a2));
R = Lambda_k;
end
end

function region = get_region_from_in_out_radius(in_out,radius)
syms a1 a2
if radius==a1 && in_out==1
region = 'i1';
elseif (radius==a1 && in_out==0) || (radius==a2 && in_out==1)
region = 'i2';
elseif radius==a2 && in_out==0
region = 'e';
else
error('invalid radius or in/out value')
end
end
Loading
Loading