1 function model=gen_rbmatlab_model_from_comsol_model(comsol_model_name)
2 %
function model=gen_rbmatlab_model_from_comsol_model(comsol_model_name)
4 %
function creating a rbmatlab model from a comsol model automatically, so
5 % that mainly only the model.comsol_calculate_inner_product_matrices,
6 % model.operators and model.output_operators have to be
7 % implemented by hand but all the rest is done automatically!
9 % This
function checks whether the problem is stationary or time-dependent and sets all
10 % the fields in the model the according way so it can be used
for both!
12 % This is the first
function to be called when transferring a comsol model
16 % comsol_model_name: a
string with the name of the file of the comsol model
19 % model: the rbmatlab model struture that can be used to create model_data,
20 % detailed_data and so on...
22 % Oliver Zeeb, 26.08.2012
26 model.comsol_model_name = comsol_model_name;
27 comsol_model=mphload([model.comsol_model_name
'.mph']);
29 comsol_tags = comsol_get_tags(comsol_model);
30 model.comsol_tags = comsol_tags;
32 %time-dependent or stationary model?
33 study_name = char(comsol_model.study.tags);
34 study_type = char(comsol_model.study(study_name).feature.tags);
40 model.rb_problem_type =
'comsol_model_stat';
41 model.gen_model_data = @comsol_stat_gen_model_data;
42 model.detailed_simulation = @comsol_stat_detailed_simulation;
43 model.plot_sim_data = @comsol_stat_plot_sim_data;
44 model.gen_detailed_data = @comsol_lin_stat_gen_detailed_data;
45 model.RB_extension_algorithm = @comsol_RB_extension_greedy_lin_stat;
47 model.get_dofs_from_sim_data = @(sim_data) sim_data.U;
48 model.gen_reduced_data = @comsol_lin_stat_gen_reduced_data;
49 model.rb_simulation = @lin_stat_rb_simulation;
51 model.set_rb_in_detailed_data= @lin_stat_set_rb_in_detailed_data;
52 model.get_rb_size = @(model,detailed_data) size(detailed_data.RB,2);
56 model.rb_problem_type =
'comsol_model_evol';
57 model.gen_model_data = @comsol_evol_gen_model_data;
58 model.detailed_simulation = @comsol_evol_detailed_simulation;
59 model.plot_sim_data = @comsol_evol_plot_sim_data;
60 model.gen_detailed_data = @comsol_evol_gen_detailed_data;
61 model.set_rb_in_detailed_data= @(detailed_data,RB) setfield(detailed_data,
'RB',RB);
62 model.get_rb_size = @(model,detailed_data)size(detailed_data.RB,2);
63 model.gen_reduced_data = @comsol_evol_gen_reduced_data;
64 model.get_dofs_from_sim_data = @(sim_data) sim_data.U;
65 tlist = comsol_model.study(comsol_tags.study).feature(
'time').getDoubleArray(
'tlist');
66 model.nt=length(tlist)-1;
68 model.dt = model.T / model.nt;
69 model.rb_simulation = @lin_evol_rb_simulation;
70 model.rb_operators = @lin_evol_rb_operators;
72 model.init_values_algorithm = @comsol_get_init_values;
73 model.compute_output_functional = 0;
75 model.error_norm=
'l2';
76 model.data_const_in_time = 0;
78 model.filecache_ignore_fields_in_model={};
79 model.filecache_ignore_fields_in_detailed_data={};
80 model.rb_reconstruction = @comsol_evol_rb_reconstruction;
82 error(
'Comsol study type not supported!')
85 %information about the solution, the grid and the used finite elements
86 model.element_type = comsol_get_element_type(comsol_model); %determines the element type! Must be lagrange fininte elements!
87 model.pdeg=comsol_get_pdeg(comsol_model); %degree of the used fininte elements (linear, quadratic, ...?)
88 model.qdeg = 2; %quadrature degree --> needed in some rbmatlab fem_functions
89 model.dimrange=size(
char(comsol_model.field.tags),1); %determines the number of field variables from the comsol_model
91 %rbmatlab parameters for debugging
96 model.set_mu = @set_mu_default;
97 model.get_mu = @get_mu_default;
98 model = comsol_get_global_params_from_comsol_model(model,comsol_model); %sets all the global parameters as rb-parameters mu
99 model.mu_ranges = my_mu_ranges_default(model);
100 model.decomp_mode = 0; % default: complete evaluation
102 model.compute_output_functional = 0;
107 % model.RB_generation_mode = 'lagrangian';
108 % model.RB_mu_list = {[...], [...]};
111 model.RB_generation_mode =
'greedy_uniform_fixed'; %
default: greedy
112 model.RB_error_indicator =
'estimator'; %
'error'
113 model.RB_numintervals = 2*ones(length(model.mu_names),1);
114 model.rb_init_data_basis = @comsol_rb_init_data_basis;
115 model.get_estimator_from_sim_data = @(sim_data)sim_data.Delta(end);
116 model.inner_product = @calc_inner_product;
117 model.RB_stop_epsilon = 1e-4;
118 model.RB_stop_Nmax = 20;
119 model.get_rb_from_detailed_data=@(detailed_data)detailed_data.RB;
121 model.comsol_calculate_inner_product_matrices = @comsol_calculate_inner_product_matrices_default;
122 model.get_inner_product_matrix = @(detailed_data)detailed_data.inner_product_matrices.L2;
125 model.use_comsol = 1;% This field indicates whether the matrices are extracted from COMSOL
126 % or
if they are just forwarded from the model_data. That allows to
127 % create the model_data
using COMSOL and afterwards doing all the
128 % computations without COMSOL. Especially on a Mac
this really
129 % accelerates things a lot!!!
131 model.comsol_get_eliminated_data = 0; %This field indicates in some functions, whether they
return
132 %the full or the full or the eleiminated matrices! This is needed
133 %since the eliminated matrices must be used
for simulation (the
134 %full matrices are singular!!!), but
for some operations the full
135 %matrices should be used!
138 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
139 % Auxiliary functions
140 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
142 function mu_ranges = my_mu_ranges_default(model)
143 % sets the mu_ranges according to which mus are set in the comsol_model
146 mu_variation = mu_var_factor * abs(mu);
147 mu_low = mu - mu_variation;
148 mu_up = mu + mu_variation;
149 mu_ranges = cell(1,length(mu));
151 mu_ranges{k} = [mu_low(k), mu_up(k)];
152 if mu_low(k) == mu_up(k) %are both equal? --> mu must be zero!!!
153 mu_ranges{k} = [-mu_var_factor mu_var_factor];
157 function dummy = my_rb_init_data_basis(model)
158 % only needed
for loading the greedy_opt stuff!
function [ RBext , dummy ] = RB_extension_PCA_fixspace(model, detailed_data)
function computing a RB basis extension for given parameters by the POD-Greedy algorithm.
function a0 = rb_init_values_default(model, detailed_data)
function computing the reduced basis initial values. If the decomposition mode is coefficients...
function reduced_data_subset = lin_stat_reduced_data_subset(model, reduced_data)
method which modifies reduced_data, which is the data, that will be passed to the online-simulation a...
function rb_sim_data = rb_reconstruction_comsol(model, detailed_data, rb_sim_data)
(trivial) function computing a detailed reconstruction by linear combination of the coefficients in t...
function reduced_data_subset = lin_evol_reduced_data_subset(model, reduced_data)
method which modifies reduced_data, which is the data, that will be passed to the online-simulation a...
Customizable implementation of an abstract greedy algorithm.