-
Notifications
You must be signed in to change notification settings - Fork 7
/
bem_load_model_matrix.m
86 lines (80 loc) · 3.06 KB
/
bem_load_model_matrix.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
% bem_load_model_matrix() - Loads the BEM matrix with extension 'ext'.
% The matrix file name is defined by <model.name>.<ext>
% The matrix is placed into the model with a field name 'ext'
%
% Usage:
% >> model = bem_load_model_matrix(model, ext);
%
% Inputs:
% model - model structure generated by bem_create_model().
% ext - matrix type. The following types are defined:
% 'cmt' - BEM Coefficient matrix
% 'dmt' - band of Coefficient matrix used by IPA
% 'imt' - inner Coefficient Matrix used by IPA
% 'iinv' - inverse of the inner coefficient matrix. This matrix is
% computed from 'imt' if the file does not exist.
%
% Outputs:
% model - model structure.
%
% Author: Zeynep Akalin Acar, SCCN, 2007
% Copyright (C) 2007 Zeynep Akalin Acar, SCCN, [email protected]
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
function model = bem_load_model_matrix(model, ext)
% check model and mesh fields
if ~isempty(find(isfield(model, {'name', 'mesh'}) == 0,1))
error('BEM:bem_load_model_matrix:model','%s','Invalid model');
end
mesh = model.mesh;
if ~isempty(find(isfield(mesh, {'name','num_class'}) == 0,1))
error('BEM:bem_load_model_matrix:mesh','%s','Invalid mesh');
end
if ~ischar(ext)
error('BEM:bem_load_model_matrix:ext','%s','Invalid extension');
end
ext = lower(ext);
if ~(strcmp(ext,'cmt') || strcmp(ext,'dmt') || strcmp(ext,'imt') || ...
strcmp(ext,'iinv'))
error('BEM:bem_load_model_matrix:ext','%s','Unknown matrix type');
end
try
m = load(sprintf('%s.%s', model.name, ext));
catch
% iinv is handled specially
if strcmp(ext,'iinv')
load_imt = 0;
try
if ~isfield(model, 'imt')
load_imt = 1;
model=bem_load_model_matrix(model, 'imt');
end
catch
error('BEM:bem_load_model_matrix:ext','%s','Failed to load "imt" for inverting.');
end
warning('BEM:info','Inverting "imt" to compute "iinv"');
m = inv(model.imt);
fn = sprintf('%s.iinv', model.name);
save(fn, 'm', '-ascii', '-double');
if load_imt
% if we loaded 'imt' remove it to save memory
model = rmfield(model,'imt');
end
else
% for other matrices just return error
error('BEM:bem_load_model_matrix:ext','Failed to load %s.%s', model.name, ext);
end
end
model.(ext) = m;