rbmatlab 0.10.01
models/common/renew_model.m
Go to the documentation of this file.
00001 function [nmodel,nddata,plot_params] = renew_model(model, detailed_data)
00002 % function [nmodel,nddata] = renew_model(model, detailed_data)
00003 % change fields of old 'param' structure to new 'model' structure with
00004 % excessive use of function pointers.
00005 %
00006 % This function can be used to make old demos work. Simply load the old
00007 % 'params' and 'detailed_data' and then call 
00008 % @code
00009 %  [model,detailed_data,plot_params] = renewmodel(params, detailed_data);
00010 %  demo_rb_gui(model, detailed_data, [],plot_params,'title');
00011 % @endcode
00012 
00013 if isequal(model.rb_problem_type, 'nonlin_evol')
00014   nmodel = nonlin_evol_model_default;
00015 else
00016   nmodel = lin_evol_model_default;
00017 end
00018 
00019 nmodel.init_values_ptr      = str2func(['init_values_', model.name_init_values]);
00020 model=rmfield(model,'name_init_values');
00021 
00022 if isfield(model, 'name_dirichlet_values')
00023   nmodel.dirichlet_values_ptr = str2func(['dirichlet_values_', model.name_dirichlet_values]);
00024   model=rmfield(model,'name_dirichlet_values');
00025 end
00026 
00027 if isfield(model, 'name_neuman_values')
00028   nmodel.neumann_values_ptr   = str2func(['neumann_values_', model.name_neuman_values]);
00029   model=rmfield(model,'name_neuman_values');
00030 end
00031 
00032 nmodel.conv_flux_ptr        = str2func(['conv_flux_', model.name_flux]);
00033 model=rmfield(model,'name_flux');
00034 
00035 if ~isequal(model.name_diffusive_num_flux, 'none')
00036   nmodel.num_diff_flux_ptr    = str2func(['fv_num_diff_flux_', model.name_diffusive_num_flux]);
00037   nmodel.fv_expl_diff_weight = 1.0;
00038 end
00039 model=rmfield(model,'name_diffusive_num_flux');
00040 
00041 if ~isequal(model.name_convective_num_flux, 'none')
00042   if isequal(model.name_convective_num_flux, 'enquist-osher')
00043     nmodel.num_conv_flux_ptr = @fv_num_conv_flux_engquist_osher;
00044   else
00045     nmodel.num_conv_flux_ptr    = str2func(['fv_num_conv_flux_', strrep(model.name_convective_num_flux,'-','_')]);
00046   end
00047   if ~model.flux_linear
00048     conv_lin_name = ['velocity_', model.name_convective_num_flux];
00049     if exist(conv_lin_name)
00050       nmodel.velocity_ptr = str2func(conv_lin_name);
00051     else
00052       warning(['using forward difference linearization for non-linear convective flux. Maybe, you need to implement:', conv_lin_name]);
00053       nmodel.velocity_ptr = @velocity_forward_difference;
00054     end;
00055   end
00056   nmodel.fv_expl_conv_weight = 1.0;
00057 end
00058 model=rmfield(model,'name_convective_num_flux');
00059 
00060 nmodel.init_values_algorithm = str2func(model.init_values_algorithm);
00061 model=rmfield(model,'init_values_algorithm');
00062 
00063 nmodel.implicit_operators_algorithm = str2func(model.implicit_operators_algorithm);
00064 model=rmfield(model,'implicit_operators_algorithm');
00065 
00066 nmodel.inner_product_matrix_algorithm = str2func(model.inner_product_matrix_algorithm);
00067 model=rmfield(model,'inner_product_matrix_algorithm');
00068 
00069 model.bnd_rect_index = [];
00070 model.flux_quad_degree = 1;
00071 model.divclean_mode = 0;
00072 
00073 plot_params = [];
00074 [plot_params, model] = copy_and_rm(plot_params, model, {'yscale_uicontrols', 'xscale_uicontrols', 'xscale_gui', 'yscale_gui', 'axis_equal', 'clim', 'bind_to_model', 'no_lines', 'geometry_transformation', 'show_colorbar', 'colorbar_mode'});
00075 
00076 nmodel     = structcpy(nmodel, model);
00077 
00078 nmodel     = model_default(nmodel);
00079 
00080 model_data = gen_model_data(nmodel);
00081 nddata     = structcpy(detailed_data, model_data);
00082 
00083 if isfield(detailed_data, 'BM')
00084   nddata.BM=cell(1);
00085   nddata.TM=cell(1);
00086   nddata.QM=cell(1);
00087   nddata.ei_info=cell(1);
00088   nddata.BM{1} = detailed_data.BM;
00089   nddata.QM{1} = detailed_data.QM;
00090   nddata.TM{1} = detailed_data.TM;
00091   nddata.ei_info{1} = detailed_data.ei_info;
00092   nddata.implicit_crb_index = 1;
00093   nddata.explicit_crb_index = 1;
00094 end
00095 
00096 
00097 end
00098 
00099 function [np,op] = copy_and_rm(np,op,list)
00100   for i=1:length(list)
00101     if isfield(op, list{i})
00102       np.(list{i}) = op.(list{i});
00103       op=rmfield(op,list{i});
00104     end
00105   end
00106 end
00107 %| \docupdate 
All Classes Namespaces Files Functions Variables