-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomputeAsmIntegral.m
112 lines (94 loc) · 3 KB
/
computeAsmIntegral.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
function [V, f] = computeAsmIntegral(func, asmParams, varargin)
% computeAsmIntegral - Computes the integral over the function func.
%
% [V, f] = computeAsmIntegral(func, asmParams,...
% 'param1', value1, 'param2', value2, ...)
%
%
% Input:
% func - Function handle to integral* function
% asmParams - Struct that describes the model, see parseAsmInput
% varargin - Additional parameter values to quadgk
%
%
% Output:
% V - Frequency response
% f - Frequencies (Hz)
%
%
% Example:
% p = generateAsmConfig('water', 'steel');
% p.f = linspace(100e3, 500e3, 500);
% [pt, f] = computeAsmIntegral(@integralFluidSolidFluid, p,...
% 'MaxIntervalCount', 1000);
% figure
% plot(f, abs(pt))
%% Parse default arguments
if nargin < 2
fprintf('\n Usage: [pt, f] = computeAsmIntegral(func, asmParams)\n\n');
return;
end
if ~isa(func, 'function_handle')
fprintf('\n computeAsmIntegral - First input must be a function handle.\n\n');
return;
end
%% This requires git to be installed
if ~asmParams.debug
pdir = pwd();
cd(fileparts(mfilename('fullpath')));
gitStatus = git('status');
isunmodified = ~isempty(regexp(gitStatus, 'modified', 'ONCE'));
isnotup2date = ~isempty(regexp(gitStatus, 'up-to-date', 'ONCE'));
if isunmodified || isnotup2date
warning('ASM:NOTUPTODATE',...
'The ASM repos is modified or not up-to-date!')
elseif strcmp(gitStatus, 'git is not included in the path')
warning('ASM:NOGIT',...
'Git not found in path, version information is not included in saved data.')
else
asmParams.gitInfo = getGitInfo();
end
cd(pdir)
end
%% Integrate over all angles for the point on the axis
[V, f] = func(asmParams, varargin{:});
%% Save results if savemat is true
if asmParams.savemat
dtstr = datestr(now, 'dd_mm_yyyy_HHMMSS');
fprintf('Finnished: %s\n', dtstr);
outfilename = generateFilenameString(asmParams, dtstr);
fprintf('Saved to %s\n', outfilename);
save(outfilename, 'asmParams', 'V', 'f');
end
end
function outfilename = generateFilenameString(parameters, dtestr)
% generateFilenameString - Generates a file name based on the asm
% parameter struct
%
%
% outfilename = generateFilenameString(parameters, dtestr)
%
% Input:
% parameters - ASM parameter struct
% dtestr - Current date in string format
prefix = 'asm';
fnvars = parameters.filenamevars;
idf = strcmp(fnvars, 'f');
if any(idf)
fnvars = {fnvars{~idf}, 'fmin', 'fmax'};
parameters.('fmin') = min(parameters.f);
parameters.('fmax') = max(parameters.f);
df = diff(parameters.f);
if length(unique(df)) == 1
parameters.df = unique(df);
fnvars{end+1} = 'df';
end
end
if isempty(fnvars)
outfilename = sprintf('%s_%s.mat', prefix, dtestr);
else
c = cellfun(@(x) sprintf('%s_%d', x, parameters.(x)) , fnvars, 'uni', 0);
paramstr = strjoin(c, '_');
outfilename = sprintf('%s_%s_%s.mat', prefix, paramstr, dtestr);
end
end