Changeset 32
- Timestamp:
- 04/24/09 10:38:58 (16 years ago)
- Location:
- issm/trunk/src/m/solutions
- Files:
-
- 6 added
- 24 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk/src/m/solutions/dakota/dakota_in_data.m
r1 r32 2 2 % define the data to write the dakota .in file 3 3 % 4 % []=dakota_in_data( md,filei,package)4 % []=dakota_in_data(variables,responses,dmeth,dparams,filei,package,varargin) 5 5 % 6 function []=dakota_in_data( md,filei,package)6 function []=dakota_in_data(dmeth,variables,responses,dparams,filei,package,varargin) 7 7 8 8 if ~nargin … … 11 11 end 12 12 13 %% parameters 14 15 % get default set of parameters 16 17 params=dakota_in_params(struct()); 18 19 % merge specified parameters into default set, whether or not 20 % they already exist 21 22 fnames=fieldnames(dparams); 23 24 for i=1:numel(fnames) 25 if ~isfield(params,fnames{i}) 26 warning('dakota_in_data:unknown_param',... 27 'No parameter ''%s'' in default parameter set.',... 28 fnames{i}); 29 end 30 params.(fnames{i})=dparams.(fnames{i}); 31 end 32 33 if strcmpi(params.analysis_driver,'matlab') && ... 34 isempty(params.analysis_components) 35 [pathstr,name,ext,versn] = fileparts(filei); 36 params.analysis_components=fullfile(pathstr,[name '.m' versn]); 37 end 38 39 % merge method parameters, though they shouldn't be in dparams 40 41 dmeth=dmeth_params_merge(dmeth,dparams) 42 43 13 44 %% variables 14 45 15 fnames=fieldnames(md.variables); 46 fnames=fieldnames(variables); 47 16 48 for i=1:length(fnames) 17 fhandle=str2func([class(md.variables.(fnames{i})) '.empty']); 18 dvar.(fnames{i})=fhandle(); 19 for j=1:length(md.variables.(fnames{i})) 20 %call setupdesign 21 dvar.(fnames{i})=QmuSetupDesign(md,dvar.(fnames{i}),md.variables.(fnames{i})(j)); 49 50 % for linear constraints, just copy 51 52 if strcmp(class(variables.(fnames{i})),'linear_inequality_constraint') || ... 53 strcmp(class(variables.(fnames{i})),'linear_equality_constraint' ) 54 dvar.(fnames{i})=variables.(fnames{i}); 55 56 % for variables, call the setup function 57 58 else 59 fhandle=str2func([class(variables.(fnames{i})) '.empty']); 60 dvar.(fnames{i})=fhandle(); 61 for j=1:length(variables.(fnames{i})) 62 %call setupdesign 63 dvar.(fnames{i})=QmuSetupDesign(dvar.(fnames{i}),variables.(fnames{i})(j),params,varargin{:}); 64 end 22 65 end 23 66 end … … 25 68 %% responses 26 69 27 fnames=fieldnames(md.responses); 70 fnames=fieldnames(responses); 71 28 72 for i=1:length(fnames) 29 fhandle=str2func([class(md.responses.(fnames{i})) '.empty']); 30 dresp.(fnames{i})=fhandle(); 31 for j=1:length(md.responses.(fnames{i})) 32 dresp.(fnames{i})(j)=md.responses.(fnames{i})(j); 33 end 73 % fhandle=str2func([class(responses.(fnames{i})) '.empty']); 74 % dresp.(fnames{i})=fhandle(); 75 % for j=1:length(responses.(fnames{i})) 76 % dresp.(fnames{i})(j)=responses.(fnames{i})(j); 77 % end 78 79 % currently all response types can just be copied 80 81 dresp.(fnames{i})=responses.(fnames{i}); 34 82 end 35 83 36 %% run parameters 37 38 params=dakota_in_params(struct()); 39 40 params.evaluation_concurrency=md.evaluation_concurrency; 41 params.npart=md.npart; 42 disp(md.method); 43 44 if strncmpi(md.method,'nond_l',6), 45 params.method ='nond_local_reliability'; 46 params.interval_type =md.interval_type; 47 params.fd_gradient_step_size=md.fd_gradient_step_size; 48 elseif strncmpi(md.method,'nond_s',6), 49 params.method ='nond_sampling'; 50 params.seed =md.seed; 51 params.samples =md.samples; 52 params.sample_type =md.sample_type; 53 elseif strncmpi(md.method,'conmin_f',8), 54 params.method ='conmin_frcg'; 55 elseif strncmpi(md.method,'conmin_m',8), 56 params.method ='conmin_mfd'; 57 else 58 error('dakota_in_data: error message, method not supported yet!'); 59 end 60 61 if strcmpi(md.analysis_driver,'matlab') 62 params.analysis_driver='matlab'; 63 if ~isempty(md.analysis_components) 64 params.analysis_components=md.analysis_components; 65 else 66 params.analysis_components=filei; 67 end 68 elseif ~isempty(md.analysis_driver) 69 params.analysis_driver=md.analysis_driver; 70 else 71 md.analysis_driver=params.analysis_driver; 72 end 84 %% write files 73 85 74 86 %Write in file 75 dakota_in_write( params.method,dvar,dresp,filei,params);87 dakota_in_write(dmeth.method,dmeth,dvar,dresp,params,filei,varargin{:}); 76 88 77 89 %Write m file 78 dakota_m_write( md,params.method,dvar,dresp,filei,params,package);90 dakota_m_write(dmeth.method,dmeth,dvar,dresp,params,filei,package,varargin{:}); 79 91 80 92 end -
issm/trunk/src/m/solutions/dakota/dakota_in_params.m
r1 r32 5 5 % 6 6 function [params]=dakota_in_params(params) 7 8 global ISSM_DIR;9 7 10 8 if ~nargin … … 34 32 %% method section 35 33 36 % if isfield(params,'method') 37 % method=params.method; 38 % end 34 % all method parameters are in the dakota_method class 39 35 40 % method-independent 41 42 if ~isfield(params,'output') 43 params.output=false; 44 end 45 if ~isfield(params,'max_iterations') 46 params.max_iterations=100; 47 end 48 if ~isfield(params,'max_function_evaluations') 49 params.max_function_evaluations=100; 50 end 51 if ~isfield(params,'convergence_tolerance') 52 params.convergence_tolerance=1.e-4; 53 end 54 55 % nondeterministic methods 56 57 if ~isfield(params,'distribution') 58 params.distribution='cumulative'; 59 end 60 if ~isfield(params,'compute') 61 params.compute='probabilities'; 62 end 63 64 % nond_sampling 65 66 if ~isfield(params,'seed') 67 params.seed=1234; 68 end 69 if ~isfield(params,'samples') 70 params.samples=100; 71 end 72 if ~isfield(params,'sample_type') 73 params.sample_type='lhs'; 74 end 75 if ~isfield(params,'all_variables') 76 params.all_variables=false; 77 end 78 if ~isfield(params,'variance_based_decomp') 79 params.variance_based_decomp=false; 80 end 81 82 % nond_local_reliability 36 %% model section 83 37 84 38 %% interface section … … 91 45 end 92 46 if ~isfield(params,'analysis_driver') 93 params.analysis_driver=[ISSM_DIR '/src/m/solutions/dakota/cielo_ice_script.sh']; 47 params.analysis_driver=''; 48 end 49 if ~isfield(params,'analysis_components') 50 params.analysis_components=''; 94 51 end 95 52 if ~isfield(params,'parameters_file') … … 105 62 params.file_save=true; 106 63 end 107 if ~isfield(params,'analysis_components')108 params.analysis_components='';109 end110 64 111 65 %% responses section 112 66 113 % gradient specifications dependent on method114 % if ~isfield(params,'no_gradients')115 % params.no_gradients=false;116 % end117 67 if ~isfield(params,'numerical_gradients') 118 68 params.numerical_gradients=true; … … 140 90 params.id_numerical_gradients=false; 141 91 end 142 % if ~isfield(params,'no_hessians') 143 % params.no_hessians=false; 144 % end 92 % hessians not fully implemented 93 if ~isfield(params,'numerical_hessians') 94 params.numerical_gradients=true; 95 end 96 if ~isfield(params,'hessian_gradient_step_size') 97 params.fd_gradient_step_size=0.001; 98 end 145 99 146 100 end -
issm/trunk/src/m/solutions/dakota/dakota_in_parse.m
r1 r32 108 108 ncdv=tlist; 109 109 dvar.cdv=[]; 110 display(sprintf(' Number of Dakota %s variables=%d.',...110 display(sprintf(' Number of Dakota %s variables=%d.',... 111 111 'continuous_design',ncdv)); 112 112 case 'cdv_initial_point' … … 135 135 nnuv=tlist; 136 136 dvar.nuv=[]; 137 display(sprintf(' Number of Dakota %s variables=%d.',...137 display(sprintf(' Number of Dakota %s variables=%d.',... 138 138 'normal_uncertain',nnuv)); 139 139 case 'nuv_means' … … 167 167 ncsv=tlist; 168 168 dvar.csv=[]; 169 display(sprintf(' Number of Dakota %s variables=%d.',...169 display(sprintf(' Number of Dakota %s variables=%d.',... 170 170 'continuous_state',ncsv)); 171 171 case 'csv_initial_state' … … 236 236 dresp=[]; 237 237 nof =0; 238 nlst=0; 238 239 nnic=0; 239 240 nnec=0; 240 nlst=0;241 241 nrf =0; 242 242 … … 262 262 nof =tlist; 263 263 dresp.of =[]; 264 display(sprintf(' Number of Dakota %s=%d.',...264 display(sprintf(' Number of Dakota %s=%d.',... 265 265 'objective_functions',nof)); 266 case 'objective_function_scale_types' 267 [tlist,tokens,itoken]=readtlist(fidi,tokens,itoken); 268 for i=1:length(tlist) 269 dresp.of(i).scale_type=char(tlist(i)); 270 end 271 case 'objective_function_scales' 272 [tlist,tokens,itoken]=readtlist(fidi,tokens,itoken); 273 for i=1:length(tlist) 274 dresp.of(i).scale =tlist(i); 275 end 276 case 'multi_objective_weights' 277 [tlist,tokens,itoken]=readtlist(fidi,tokens,itoken); 278 for i=1:length(tlist) 279 dresp.of(i).weight =tlist(i); 280 end 281 282 case 'num_least_squares_terms' 283 [tlist,tokens,itoken]=readtlist(fidi,tokens,itoken); 284 nlst=tlist; 285 dresp.lst=[]; 286 display(sprintf(' Number of Dakota %s=%d.',... 287 'least_squares_terms',nlst)); 288 case 'least_squares_term_scale_types' 289 [tlist,tokens,itoken]=readtlist(fidi,tokens,itoken); 290 for i=1:length(tlist) 291 dresp.lst(i).scale_type=char(tlist(i)); 292 end 293 case 'least_squares_term_scales' 294 [tlist,tokens,itoken]=readtlist(fidi,tokens,itoken); 295 for i=1:length(tlist) 296 dresp.lst(i).scale =tlist(i); 297 end 298 case 'least_squares_weights' 299 [tlist,tokens,itoken]=readtlist(fidi,tokens,itoken); 300 for i=1:length(tlist) 301 dresp.lst(i).weight =tlist(i); 302 end 303 266 304 case 'num_nonlinear_inequality_constraints' 267 305 [tlist,tokens,itoken]=readtlist(fidi,tokens,itoken); 268 306 nnic=tlist; 269 307 dresp.nic=[]; 270 display(sprintf(' Number of Dakota %s=%d.',... 271 'nonlinear_inequality_constraints',nof)); 308 display(sprintf(' Number of Dakota %s=%d.',... 309 'nonlinear_inequality_constraints',nnic)); 310 case 'nonlinear_inequality_scale_types' 311 [tlist,tokens,itoken]=readtlist(fidi,tokens,itoken); 312 for i=1:length(tlist) 313 dresp.nic(i).scale_type=char(tlist(i)); 314 end 315 case 'nonlinear_inequality_scales' 316 [tlist,tokens,itoken]=readtlist(fidi,tokens,itoken); 317 for i=1:length(tlist) 318 dresp.nic(i).scale =tlist(i); 319 end 320 case 'nonlinear_inequality_lower_bounds' 321 [tlist,tokens,itoken]=readtlist(fidi,tokens,itoken); 322 for i=1:length(tlist) 323 dresp.nic(i).lower =tlist(i); 324 end 325 case 'nonlinear_inequality_upper_bounds' 326 [tlist,tokens,itoken]=readtlist(fidi,tokens,itoken); 327 for i=1:length(tlist) 328 dresp.nic(i).upper =tlist(i); 329 end 330 272 331 case 'num_nonlinear_equality_constraints' 273 332 [tlist,tokens,itoken]=readtlist(fidi,tokens,itoken); 274 333 nnec=tlist; 275 display(sprintf(' Number of Dakota %s=%d.',... 276 'nonlinear_equality_constraints',nof)); 277 case 'num_least_squares_terms' 278 [tlist,tokens,itoken]=readtlist(fidi,tokens,itoken); 279 nlst=tlist; 280 dresp.lst=[]; 281 display(sprintf(' Number of Dakota %s=%d.',... 282 'least_squares_terms',nof)); 334 dresp.nec=[]; 335 display(sprintf(' Number of Dakota %s=%d.',... 336 'nonlinear_equality_constraints',nnec)); 337 case 'nonlinear_equality_scale_types' 338 [tlist,tokens,itoken]=readtlist(fidi,tokens,itoken); 339 for i=1:length(tlist) 340 dresp.nec(i).scale_type=char(tlist(i)); 341 end 342 case 'nonlinear_equality_scales' 343 [tlist,tokens,itoken]=readtlist(fidi,tokens,itoken); 344 for i=1:length(tlist) 345 dresp.nec(i).scale =tlist(i); 346 end 347 case 'nonlinear_equality_targets' 348 [tlist,tokens,itoken]=readtlist(fidi,tokens,itoken); 349 for i=1:length(tlist) 350 dresp.nec(i).target =tlist(i); 351 end 352 283 353 case 'num_response_functions' 284 354 [tlist,tokens,itoken]=readtlist(fidi,tokens,itoken); 285 355 nrf =tlist; 286 356 dresp.rf =[]; 287 display(sprintf(' Number of Dakota %s=%d.',...357 display(sprintf(' Number of Dakota %s=%d.',... 288 358 'response_functions',nrf)); 359 289 360 case 'response_descriptors' 290 361 [tlist,tokens,itoken]=readtlist(fidi,tokens,itoken); 291 for i=1:length(tlist) 292 dresp.rf(i).descriptor=char(tlist(i)); 293 end 362 desc=tlist; 294 363 otherwise 295 364 warning('responses_parse:unrec_key',... … … 308 377 strncmpi(tokens{1}{itoken},'responses',9) 309 378 310 % supply default descriptors if necessary 311 312 if isfield(dresp,'of' ) && ~isfield(dresp.of,'descriptor') 313 for i=1:nof 314 dresp.of(i).descriptor=sprintf('obj_fn_%d',i); 315 end 316 end 317 if isfield(dresp,'nic') && ~isfield(dresp.nic,'descriptor') 318 for i=1:nnic 319 dresp.nic(i).descriptor=sprintf('nln_ineq_con_%d',i); 320 end 321 end 322 if isfield(dresp,'nec') && ~isfield(dresp.nec,'descriptor') 323 for i=1:nnec 324 dresp.nec(i).descriptor=sprintf('nln_eq_con_%d',i); 325 end 326 end 327 if isfield(dresp,'lst') && ~isfield(dresp.lst,'descriptor') 328 for i=1:nlst 329 dresp.lst(i).descriptor=sprintf('least_sq_term_%d',i); 330 end 331 end 332 if isfield(dresp,'rf' ) && ~isfield(dresp.rf,'descriptor') 333 for i=1:nrf 334 dresp.rf(i).descriptor=sprintf('response_fn_%d',i); 379 % assign specified or supply default descriptors 380 381 if exist('desc','var') 382 idesc=0; 383 if isfield(dresp,'of' ) 384 for i=1:nof 385 idesc=idesc+1; 386 dresp.of(i).descriptor=char(desc(idesc)); 387 end 388 end 389 if isfield(dresp,'lst') 390 for i=1:nlst 391 idesc=idesc+1; 392 dresp.lst(i).descriptor=char(desc(idesc)); 393 end 394 end 395 if isfield(dresp,'nic') 396 for i=1:nnic 397 idesc=idesc+1; 398 dresp.nic(i).descriptor=char(desc(idesc)); 399 end 400 end 401 if isfield(dresp,'nec') 402 for i=1:nnec 403 idesc=idesc+1; 404 dresp.nec(i).descriptor=char(desc(idesc)); 405 end 406 end 407 if isfield(dresp,'rf' ) 408 for i=1:nrf 409 idesc=idesc+1; 410 dresp.rf(i).descriptor=char(desc(idesc)); 411 end 412 end 413 414 else 415 if isfield(dresp,'of' ) 416 for i=1:nof 417 dresp.of(i).descriptor=sprintf('obj_fn_%d',i); 418 end 419 end 420 if isfield(dresp,'lst') 421 for i=1:nlst 422 dresp.lst(i).descriptor=sprintf('least_sq_term_%d',i); 423 end 424 end 425 if isfield(dresp,'nic') 426 for i=1:nnic 427 dresp.nic(i).descriptor=sprintf('nln_ineq_con_%d',i); 428 end 429 end 430 if isfield(dresp,'nec') 431 for i=1:nnec 432 dresp.nec(i).descriptor=sprintf('nln_eq_con_%d',i); 433 end 434 end 435 if isfield(dresp,'rf' ) 436 for i=1:nrf 437 dresp.rf(i).descriptor=sprintf('response_fn_%d',i); 438 end 335 439 end 336 440 end … … 413 517 % assemble the lists by response function 414 518 415 if exist('nrespl','var') 519 if exist('nrespl','var') && isfield(dresp,'rf') 416 520 if ~exist('nresp','var') 417 521 nresp(1:length(dresp.rf))=floor(length(nrespl)/length(dresp.rf)); … … 424 528 end 425 529 426 if exist('nprobl','var') 530 if exist('nprobl','var') && isfield(dresp,'rf') 427 531 if ~exist('nprob','var') 428 532 nprob(1:length(dresp.rf))=floor(length(nprobl)/length(dresp.rf)); … … 435 539 end 436 540 437 if exist('nrell' ,'var') 541 if exist('nrell' ,'var') && isfield(dresp,'rf') 438 542 if ~exist('nrel' ,'var') 439 543 nrel (1:length(dresp.rf))=floor(length(nrell )/length(dresp.rf)); … … 446 550 end 447 551 448 if exist('ngrell','var') 552 if exist('ngrell','var') && isfield(dresp,'rf') 449 553 if ~exist('ngrel','var') 450 554 ngrel(1:length(dresp.rf))=floor(length(ngrell)/length(dresp.rf)); -
issm/trunk/src/m/solutions/dakota/dakota_in_write.m
r1 r32 2 2 % write a Dakota .in file. 3 3 % 4 % []=dakota_in_write(method,d var,dresp,filei,params)4 % []=dakota_in_write(method,dmeth,dvar,dresp,params,filei,varargin) 5 5 % 6 function []=dakota_in_write(method,d var,dresp,filei,params)6 function []=dakota_in_write(method,dmeth,dvar,dresp,params,filei,varargin) 7 7 8 8 if ~nargin … … 13 13 % process the input parameters 14 14 15 if ~exist('method' ,'var') || isempty(method) 16 method=input('Method: sampling (s) or local reliability (l)? ','s'); 17 if strncmpi(method,'s',1) 18 method='nond_sampling'; 19 elseif strncmpi(method,'l',1) 20 method='nond_local_reliability'; 21 end 22 end 23 24 switch method 25 % case {'dot_bfgs','dot_frcg','dot_mmfd','dot_slp','dot_sqp'} 26 % case {'npsol_sqp'} 27 case {'conmin_frcg','conmin_mfd'} 28 % case {'optpp_cg','optpp_q_newton','optpp_fd_newton',... 29 % 'optpp_newton','optpp_pds'} 30 % case {'asynch_pattern_search'} 31 % case {'coliny_cobyla','coliny_direct','coliny_ea',... 32 % 'coliny_pattern_search','coliny_solis_wets'} 33 % case {'ncsu_direct'} 34 % case {'moga','soga'} 35 % case {'nl2sol','nlssol_sqp','optpp_g_newton'} 36 case {'nond_sampling'} 37 case {'nond_local_reliability'} 38 % case {'dace','fsu_quasi_mc','fsu_cvt'} 39 % case {'vector_parameter_study','list_parameter_study',... 40 % 'centered parameter_study','multidim_parameter_study'} 41 otherwise 42 error('Unrecognized method: ''%s''.',method); 15 if ~exist('method','var') || isempty(method) 16 method=input('Method? ','s'); 17 end 18 19 if ~exist('dmeth' ,'var') || isempty(dmeth) 20 dmeth=dakota_method(method); 43 21 end 44 22 … … 69 47 % write the method section 70 48 71 method_write(fidi, method,dresp,params);49 method_write(fidi,dmeth,dresp,params); 72 50 73 51 % write the model section … … 77 55 % write the variables section 78 56 79 variables_write(fidi, method,dvar);57 variables_write(fidi,dmeth,dvar); 80 58 81 59 % write the interface section … … 85 63 % write the responses section 86 64 87 responses_write(fidi, method,dresp,params);65 responses_write(fidi,dmeth,dresp,params); 88 66 89 67 fclose(fidi); … … 109 87 %% function to write the method section of the file 110 88 111 function []=method_write(fidi, method,dresp,params)89 function []=method_write(fidi,dmeth,dresp,params) 112 90 113 91 display('Writing method section of Dakota input file.'); 114 92 115 93 fprintf(fidi,'method,\n'); 116 fprintf(fidi,'\t%s\n',method); 117 param_write(fidi,'\t ','output',' ','\n',params); 118 param_write(fidi,'\t ','max_iterations',' = ','\n',params); 119 param_write(fidi,'\t ','max_function_evaluations',' = ','\n',params); 120 param_write(fidi,'\t ','convergence_tolerance',' = ','\n',params); 121 122 switch method 123 % case {'dot_bfgs','dot_frcg','dot_mmfd','dot_slp','dot_sqp'} 124 % case {'npsol_sqp'} 125 case {'conmin_frcg','conmin_mfd'} 126 % case {'optpp_cg','optpp_q_newton','optpp_fd_newton',... 127 % 'optpp_newton','optpp_pds'} 128 % case {'asynch_pattern_search'} 129 % case {'coliny_cobyla','coliny_direct','coliny_ea',... 130 % 'coliny_pattern_search','coliny_solis_wets'} 131 % case {'ncsu_direct'} 132 % case {'moga','soga'} 133 % case {'nl2sol','nlssol_sqp','optpp_g_newton'} 134 case {'nond_sampling'} 135 param_write(fidi,'\t ','seed',' = ','\n',params); 136 param_write(fidi,'\t ','samples',' = ','\n',params); 137 param_write(fidi,'\t ','sample_type',' ','\n',params); 138 case {'nond_local_reliability'} 139 % case {'dace','fsu_quasi_mc','fsu_cvt'} 140 % case {'vector_parameter_study','list_parameter_study',... 141 % 'centered parameter_study','multidim_parameter_study'} 142 end 94 fprintf(fidi,'\t%s\n',dmeth.method); 95 96 dmeth_params_write(dmeth,fidi); 143 97 144 98 % write response levels 145 99 146 if isfield(dresp,'rf')100 if strcmp(dmeth.type,'nond') && isfield(dresp,'rf') 147 101 param_write(fidi,'\t ','distribution',' ','\n',params); 148 [respl,probl,rell,grell]= dresp_levels(dresp.rf);102 [respl,probl,rell,grell]=prop_levels(dresp.rf); 149 103 if ~isempty(respl) 150 104 rlev_write(fidi,'response_levels',respl); … … 198 152 %% function to write the variables section of the file 199 153 200 function []=variables_write(fidi, method,dvar)154 function []=variables_write(fidi,dmeth,dvar) 201 155 202 156 display('Writing variables section of Dakota input file.'); … … 206 160 % variables vary by method 207 161 208 switch method 209 % case {'dot_bfgs','dot_frcg','dot_mmfd','dot_slp','dot_sqp'} 210 % case {'npsol_sqp'} 211 case {'conmin_frcg','conmin_mfd'} 212 vsets_write(fidi,dvar,'cdv','csv'); 213 % case {'optpp_cg','optpp_q_newton','optpp_fd_newton',... 214 % 'optpp_newton','optpp_pds'} 215 % case {'asynch_pattern_search'} 216 % case {'coliny_cobyla','coliny_direct','coliny_ea',... 217 % 'coliny_pattern_search','coliny_solis_wets'} 218 % case {'ncsu_direct'} 219 % case {'moga','soga'} 220 % case {'nl2sol','nlssol_sqp','optpp_g_newton'} 221 case {'nond_sampling'} 222 vsets_write(fidi,dvar,'nuv','csv'); 223 case {'nond_local_reliability'} 224 vsets_write(fidi,dvar,'nuv','csv'); 225 % case {'dace','fsu_quasi_mc','fsu_cvt'} 226 % case {'vector_parameter_study','list_parameter_study',... 227 % 'centered parameter_study','multidim_parameter_study'} 228 end 162 vsets_write(fidi,dvar,dmeth.variables); 163 164 % linear constraints vary by method 165 166 lcsets_write(fidi,dvar,dmeth.lcspec); 229 167 230 168 fprintf(fidi,'\n'); … … 234 172 %% function to write variable sets 235 173 236 function []=vsets_write(fidi,dvar,var argin)237 238 for i=1:length(var argin)239 switch(var argin{i})174 function []=vsets_write(fidi,dvar,variables) 175 176 for i=1:length(variables) 177 switch(variables{i}) 240 178 case 'cdv' 241 vstring='continuous_design';179 cstring='continuous_design'; 242 180 case 'nuv' 243 vstring='normal_uncertain';181 cstring='normal_uncertain'; 244 182 case 'csv' 245 vstring='continuous_state';183 cstring='continuous_state'; 246 184 otherwise 247 185 warning('vsets_write:unrec_var',... 248 'Unrecognized variable ''%s''.',var argin{i});249 end 250 251 if isfield(dvar,var argin{i})252 vlist_write(fidi, vstring,varargin{i},dvar.(varargin{i}));186 'Unrecognized variable ''%s''.',variables{i}); 187 end 188 189 if isfield(dvar,variables{i}) 190 vlist_write(fidi,cstring,variables{i},dvar.(variables{i})); 253 191 end 254 192 end … … 258 196 %% function to write variable list 259 197 260 function []=vlist_write(fidi, vstring,vstring2,dvar)198 function []=vlist_write(fidi,cstring,cstring2,dvar) 261 199 262 200 % put variables into lists for writing 263 201 264 vinitpt=dvar_initpt(dvar); 265 vlower =dvar_lower (dvar); 266 vupper =dvar_upper (dvar); 267 vmean =dvar_mean (dvar); 268 vstddev=dvar_stddev(dvar); 269 vinitst=dvar_initst(dvar); 270 vdesc =dvar_desc (dvar); 202 pinitpt=prop_initpt(dvar); 203 plower =prop_lower (dvar); 204 pupper =prop_upper (dvar); 205 pmean =prop_mean (dvar); 206 pstddev=prop_stddev(dvar); 207 pinitst=prop_initst(dvar); 208 pstype =prop_stype (dvar); 209 pscale =prop_scale (dvar); 210 pdesc =prop_desc (dvar); 271 211 272 212 % write variables … … 275 215 disp(sprintf(' Writing %d %s variables.',length(dvar),class(dvar))); 276 216 277 fprintf(fidi,'\t%s = %d\n',vstring,length(dvar)); 278 if ~isempty(vinitpt) 279 fprintf(fidi,'\t %s_initial_point =\n',vstring2); 280 vector_write(fidi,sprintf('\t '),vinitpt,6,76); 281 end 282 if ~isempty(vlower) 283 fprintf(fidi,'\t %s_lower_bounds =\n',vstring2); 284 vector_write(fidi,sprintf('\t '),vlower ,6,76); 285 end 286 if ~isempty(vupper) 287 fprintf(fidi,'\t %s_upper_bounds =\n',vstring2); 288 vector_write(fidi,sprintf('\t '),vupper ,6,76); 289 end 290 if ~isempty(vmean) 291 fprintf(fidi,'\t %s_means =\n',vstring2); 292 vector_write(fidi,sprintf('\t '),vmean ,6,76); 293 end 294 if ~isempty(vstddev) 295 fprintf(fidi,'\t %s_std_deviations =\n',vstring2); 296 vector_write(fidi,sprintf('\t '),vstddev,6,76); 297 end 298 if ~isempty(vinitst) 299 fprintf(fidi,'\t %s_initial_state =\n',vstring2); 300 vector_write(fidi,sprintf('\t '),vinitst,6,76); 301 end 302 if ~isempty(vdesc) 303 fprintf(fidi,'\t %s_descriptors =\n',vstring2); 304 vector_write(fidi,sprintf('\t '),vdesc ,6,76); 217 fprintf(fidi,'\t%s = %d\n',cstring,length(dvar)); 218 if ~isempty(pinitpt) 219 fprintf(fidi,'\t %s_initial_point =\n',cstring2); 220 vector_write(fidi,sprintf('\t '),pinitpt,6,76); 221 end 222 if ~isempty(plower) 223 fprintf(fidi,'\t %s_lower_bounds =\n',cstring2); 224 vector_write(fidi,sprintf('\t '),plower ,6,76); 225 end 226 if ~isempty(pupper) 227 fprintf(fidi,'\t %s_upper_bounds =\n',cstring2); 228 vector_write(fidi,sprintf('\t '),pupper ,6,76); 229 end 230 if ~isempty(pmean) 231 fprintf(fidi,'\t %s_means =\n',cstring2); 232 vector_write(fidi,sprintf('\t '),pmean ,6,76); 233 end 234 if ~isempty(pstddev) 235 fprintf(fidi,'\t %s_std_deviations =\n',cstring2); 236 vector_write(fidi,sprintf('\t '),pstddev,6,76); 237 end 238 if ~isempty(pinitst) 239 fprintf(fidi,'\t %s_initial_state =\n',cstring2); 240 vector_write(fidi,sprintf('\t '),pinitst,6,76); 241 end 242 if ~isempty(pstype) 243 fprintf(fidi,'\t %s_scale_types =\n',cstring2); 244 vector_write(fidi,sprintf('\t '),pstype ,6,76); 245 end 246 if ~isempty(pscale) 247 fprintf(fidi,'\t %s_scales =\n',cstring2); 248 vector_write(fidi,sprintf('\t '),pscale ,6,76); 249 end 250 if ~isempty(pdesc) 251 fprintf(fidi,'\t %s_descriptors =\n',cstring2); 252 vector_write(fidi,sprintf('\t '),pdesc ,6,76); 253 end 254 255 end 256 257 %% function to write linear constraint sets 258 259 function []=lcsets_write(fidi,dvar,lcspec) 260 261 for i=1:length(lcspec) 262 switch(lcspec{i}) 263 case 'lic' 264 cstring ='linear_inequality_constraints'; 265 cstring2='linear_inequality'; 266 case 'lec' 267 cstring ='linear_equality_constraints'; 268 cstring2='linear_equality'; 269 otherwise 270 warning('lcspec_write:unrec_lcspec',... 271 'Unrecognized linear constraint ''%s''.',lcspec{i}); 272 end 273 274 if isfield(dvar,lcspec{i}) 275 lclist_write(fidi,cstring,cstring2,dvar.(lcspec{i})); 276 end 277 end 278 279 end 280 281 %% function to write linear constraint list 282 283 function []=lclist_write(fidi,cstring,cstring2,dvar) 284 285 % put linear constraints into lists for writing 286 287 pmatrix=prop_matrix(dvar); 288 plower =prop_lower (dvar); 289 pupper =prop_upper (dvar); 290 ptarget=prop_target(dvar); 291 pstype =prop_stype (dvar); 292 pscale =prop_scale (dvar); 293 294 % write linear constraints 295 296 disp(sprintf(' Writing %d %s linear constraints.',... 297 length(dvar),class(dvar))); 298 299 if ~isempty(pmatrix) 300 fprintf(fidi,'\t %s_matrix =\n',cstring2); 301 vector_write(fidi,sprintf('\t '),pmatrix,6,76); 302 end 303 if ~isempty(plower) 304 fprintf(fidi,'\t %s_lower_bounds =\n',cstring2); 305 vector_write(fidi,sprintf('\t '),plower ,6,76); 306 end 307 if ~isempty(pupper) 308 fprintf(fidi,'\t %s_upper_bounds =\n',cstring2); 309 vector_write(fidi,sprintf('\t '),pupper ,6,76); 310 end 311 if ~isempty(ptarget) 312 fprintf(fidi,'\t %s_targets =\n',cstring2); 313 vector_write(fidi,sprintf('\t '),ptarget,6,76); 314 end 315 if ~isempty(pstype) 316 fprintf(fidi,'\t %s_scale_types =\n',cstring2); 317 vector_write(fidi,sprintf('\t '),pstype ,6,76); 318 end 319 if ~isempty(pscale) 320 fprintf(fidi,'\t %s_scales =\n',cstring2); 321 vector_write(fidi,sprintf('\t '),pscale ,6,76); 305 322 end 306 323 … … 341 358 %% function to write the responses section of the file 342 359 343 function []=responses_write(fidi, method,dresp,params)360 function []=responses_write(fidi,dmeth,dresp,params) 344 361 345 362 display('Writing responses section of Dakota input file.'); … … 349 366 % functions, gradients, and hessians vary by method 350 367 351 switch method 352 % case {'dot_bfgs','dot_frcg','dot_mmfd','dot_slp','dot_sqp'} 353 % case {'npsol_sqp'} 354 case {'conmin_frcg','conmin_mfd'} 355 rsets_write(fidi,dresp,'of','nic','nec'); 356 ghspec_write(fidi,params,'grad'); 357 % case {'optpp_cg','optpp_q_newton','optpp_fd_newton',... 358 % 'optpp_newton','optpp_pds'} 359 % case {'asynch_pattern_search'} 360 % case {'coliny_cobyla','coliny_direct','coliny_ea',... 361 % 'coliny_pattern_search','coliny_solis_wets'} 362 % case {'ncsu_direct'} 363 % case {'moga','soga'} 364 % case {'nl2sol','nlssol_sqp','optpp_g_newton'} 365 case {'nond_sampling'} 366 rsets_write(fidi,dresp,'rf'); 367 ghspec_write(fidi,params); 368 case {'nond_local_reliability'} 369 rsets_write(fidi,dresp,'rf'); 370 ghspec_write(fidi,params,'grad'); 371 % case {'dace','fsu_quasi_mc','fsu_cvt'} 372 % case {'vector_parameter_study','list_parameter_study',... 373 % 'centered parameter_study','multidim_parameter_study'} 374 end 368 rsets_write(fidi,dresp,dmeth.responses); 369 ghspec_write(fidi,params,dmeth.ghspec); 375 370 376 371 fprintf(fidi,'\n'); … … 380 375 %% function to write response sets 381 376 382 function []=rsets_write(fidi,dresp, varargin)377 function []=rsets_write(fidi,dresp,responses) 383 378 384 379 rdesc={}; 385 380 386 for i=1:length( varargin)387 switch( varargin{i})381 for i=1:length(responses) 382 switch(responses{i}) 388 383 case 'of' 389 rstring ='objective_functions';390 rstring2='objective_function';384 cstring ='objective_functions'; 385 cstring2='objective_function'; 391 386 case 'lst' 392 rstring ='least_squares_terms';393 rstring2='least_squares_term';387 cstring ='least_squares_terms'; 388 cstring2='least_squares_term'; 394 389 case 'nic' 395 rstring ='nonlinear_inequality_constraints';396 rstring2='nonlinear_inequality';390 cstring ='nonlinear_inequality_constraints'; 391 cstring2='nonlinear_inequality'; 397 392 case 'nec' 398 rstring ='nonlinear_equality_constraints';399 rstring2='nonlinear_equality';393 cstring ='nonlinear_equality_constraints'; 394 cstring2='nonlinear_equality'; 400 395 case 'rf' 401 rstring ='response_functions';402 rstring2='response_function';396 cstring ='response_functions'; 397 cstring2='response_function'; 403 398 otherwise 404 399 warning('rsets_write:unrec_resp',... 405 'Unrecognized response ''%s''.', varargin{i});400 'Unrecognized response ''%s''.',responses{i}); 406 401 end 407 402 408 if isfield(dresp, varargin{i})409 [rdesc]=rlist_write(fidi, rstring,rstring2,dresp.(varargin{i}),rdesc);403 if isfield(dresp,responses{i}) 404 [rdesc]=rlist_write(fidi,cstring,cstring2,dresp.(responses{i}),rdesc); 410 405 end 411 406 end … … 422 417 %% function to write response list 423 418 424 function [rdesc]=rlist_write(fidi, rstring,rstring2,dresp,rdesc)419 function [rdesc]=rlist_write(fidi,cstring,cstring2,dresp,rdesc) 425 420 426 421 % put responses into lists for writing 427 422 428 rstype =dresp_stype (dresp);429 rscale =dresp_scale (dresp);430 rweight=dresp_weight(dresp);431 rlower =dresp_lower (dresp);432 rupper =dresp_upper (dresp);433 rtarget=dresp_target(dresp);423 pstype =prop_stype (dresp); 424 pscale =prop_scale (dresp); 425 pweight=prop_weight(dresp); 426 plower =prop_lower (dresp); 427 pupper =prop_upper (dresp); 428 ptarget=prop_target(dresp); 434 429 435 430 % accumulate descriptors into list for subsequent writing 436 431 437 rdesc(end+1:end+numel(dresp))= dresp_desc (dresp);432 rdesc(end+1:end+numel(dresp))=prop_desc (dresp); 438 433 439 434 % write responses … … 441 436 disp(sprintf(' Writing %d %s responses.',length(dresp),class(dresp))); 442 437 443 fprintf(fidi,'\tnum_%s = %d\n', rstring,length(dresp));444 if ~isempty( rstype)445 fprintf(fidi,'\t %s_scale_types =\n', rstring2);446 vector_write(fidi,sprintf('\t '), rstype ,6,76);447 end 448 if ~isempty( rscale)449 fprintf(fidi,'\t %s_scales =\n', rstring2);450 vector_write(fidi,sprintf('\t '), rscale ,6,76);451 end 452 if ~isempty( rweight)453 switch rstring2438 fprintf(fidi,'\tnum_%s = %d\n',cstring,length(dresp)); 439 if ~isempty(pstype) 440 fprintf(fidi,'\t %s_scale_types =\n',cstring2); 441 vector_write(fidi,sprintf('\t '),pstype ,6,76); 442 end 443 if ~isempty(pscale) 444 fprintf(fidi,'\t %s_scales =\n',cstring2); 445 vector_write(fidi,sprintf('\t '),pscale ,6,76); 446 end 447 if ~isempty(pweight) 448 switch cstring2 454 449 case 'objective_function' 455 wtype='multi_objective'; 450 fprintf(fidi,'\t %s_weights =\n','multi_objective'); 451 vector_write(fidi,sprintf('\t '),pweight,6,76); 456 452 case 'least_squares_term' 457 wtype='least_squares'; 458 end 459 fprintf(fidi,'\t %s_weights =\n',wtype); 460 vector_write(fidi,sprintf('\t '),rweight,6,76); 461 end 462 if ~isempty(rlower) 463 fprintf(fidi,'\t %s_lower_bounds =\n',rstring2); 464 vector_write(fidi,sprintf('\t '),rlower ,6,76); 465 end 466 if ~isempty(rupper) 467 fprintf(fidi,'\t %s_upper_bounds =\n',rstring2); 468 vector_write(fidi,sprintf('\t '),rupper ,6,76); 469 end 470 if ~isempty(rtarget) 471 fprintf(fidi,'\t %s_targets =\n',rstring2); 472 vector_write(fidi,sprintf('\t '),rtarget,6,76); 453 fprintf(fidi,'\t %s_weights =\n','least_squares'); 454 vector_write(fidi,sprintf('\t '),pweight,6,76); 455 end 456 end 457 if ~isempty(plower) 458 fprintf(fidi,'\t %s_lower_bounds =\n',cstring2); 459 vector_write(fidi,sprintf('\t '),plower ,6,76); 460 end 461 if ~isempty(pupper) 462 fprintf(fidi,'\t %s_upper_bounds =\n',cstring2); 463 vector_write(fidi,sprintf('\t '),pupper ,6,76); 464 end 465 if ~isempty(ptarget) 466 fprintf(fidi,'\t %s_targets =\n',cstring2); 467 vector_write(fidi,sprintf('\t '),ptarget,6,76); 473 468 end 474 469 … … 477 472 %% function to write gradient and hessian specifications 478 473 479 function []=ghspec_write(fidi,params, varargin)474 function []=ghspec_write(fidi,params,ghspec) 480 475 481 476 % gradients 482 477 483 if find string(varargin,'grad')478 if find_string(ghspec,'grad') 484 479 if params.numerical_gradients 485 480 param_write(fidi,'\t','numerical_gradients','','\n',params); … … 497 492 % hessians (no implemented methods use them yet) 498 493 499 if find string(varargin,'hess')494 if find_string(ghspec,'hess') 500 495 error('Hessians needed by method but not provided.'); 501 496 else 502 497 fprintf(fidi,'\tno_hessians\n'); 503 end504 505 end506 507 %% function to find a string in a cell array508 509 function [ifound]=findstring(cells,str)510 511 ifound=false;512 513 for i=1:length(cells)514 if ischar(cells{i}) && strcmp(cells{i},str)515 ifound=i;516 return517 end518 498 end 519 499 … … 543 523 544 524 end 525 545 526 %% function to write a vector on multiple lines 546 527 … … 560 541 lsvec=cmax; 561 542 543 % transpose vector from column-wise to row-wise 544 545 vec=vec'; 546 562 547 % assemble each line, flushing when necessary 563 548 564 for i=1: length(vec)549 for i=1:numel(vec) 565 550 if isnumeric(vec(i)) 566 551 sitem=sprintf('%g' ,vec(i)); -
issm/trunk/src/m/solutions/dakota/dakota_m_write.m
r1 r32 3 3 % driver. 4 4 % 5 % []=dakota_m_write(m d,method,dvar,dresp,filem,params,package)5 % []=dakota_m_write(method,dmeth,dvar,dresp,params,filem,package) 6 6 % 7 function []=dakota_m_write(m d,method,dvar,dresp,filem,params,package)7 function []=dakota_m_write(method,dmeth,dvar,dresp,params,filem,package,varargin) 8 8 9 9 if ~nargin … … 14 14 % process the input parameters 15 15 16 if ~exist('method','var') || isempty(method) 17 method=input('Method? ','s'); 18 end 19 20 if ~exist('dmeth' ,'var') || isempty(dmeth) 21 dmeth=dakota_method(method); 22 end 23 16 24 if ~exist('params','var') 17 25 params=[]; 18 end19 if ~isfield(params,'npart')20 params.npart=10;21 26 end 22 27 … … 42 47 % write variables into the Matlab m-file 43 48 44 variables_write( md,fidm,method,dvar);49 variables_write(fidm,dmeth,dvar,params,varargin{:}); 45 50 46 51 % write solution into the Matlab m-file … … 50 55 % write responses into the Matlab m-file 51 56 52 responses_write(fidm, method,params,dresp);57 responses_write(fidm,dmeth,params,dresp); 53 58 54 59 % write end of the Matlab m-file … … 84 89 end 85 90 fprintf(fidm,'\tloadmodel(infile);\n\n'); 86 fprintf(fidm,'\tmd=qmuname(md);\n\n');91 % fprintf(fidm,'\tmd=qmuname(md);\n\n'); 87 92 88 93 end … … 90 95 %% function to write design variables into the Matlab m-file 91 96 92 function []=variables_write( md,fidm,method,dvar)97 function []=variables_write(fidm,dmeth,dvar,params,varargin) 93 98 94 99 display('Writing variables for Matlab m-file.'); 95 100 96 fprintf(fidm,'%% Apply the designvariables.\n\n');101 fprintf(fidm,'%% Apply the variables.\n\n'); 97 102 ixc=0; 98 103 99 104 % variables vary by method 100 105 101 switch method 102 % case {'dot_bfgs','dot_frcg','dot_mmfd','dot_slp','dot_sqp'} 103 % case {'npsol_sqp'} 104 case {'conmin_frcg','conmin_mfd'} 105 ixc=vsets_write(md,fidm,ixc,dvar,'cdv','csv'); 106 % case {'optpp_cg','optpp_q_newton','optpp_fd_newton',... 107 % 'optpp_newton','optpp_pds'} 108 % case {'asynch_pattern_search'} 109 % case {'coliny_cobyla','coliny_direct','coliny_ea',... 110 % 'coliny_pattern_search','coliny_solis_wets'} 111 % case {'ncsu_direct'} 112 % case {'moga','soga'} 113 % case {'nl2sol','nlssol_sqp','optpp_g_newton'} 114 case {'nond_sampling'} 115 ixc=vsets_write(md,fidm,ixc,dvar,'nuv','csv'); 116 case {'nond_local_reliability'} 117 ixc=vsets_write(md,fidm,ixc,dvar,'nuv','csv'); 118 % case {'dace','fsu_quasi_mc','fsu_cvt'} 119 % case {'vector_parameter_study','list_parameter_study',... 120 % 'centered parameter_study','multidim_parameter_study'} 121 end 106 ixc=vsets_write(fidm,ixc,dvar,dmeth.variables,params,varargin{:}); 122 107 123 108 end … … 125 110 %% function to write variable sets into the Matlab m-file 126 111 127 function [ixc]=vsets_write( md,fidm,ixc,dvar,varargin)128 129 for i=1:length(var argin)130 if isfield(dvar,var argin{i})131 ixc=vlist_write( md,fidm,ixc,varargin{i},dvar.(varargin{i}));112 function [ixc]=vsets_write(fidm,ixc,dvar,variables,params,varargin) 113 114 for i=1:length(variables) 115 if isfield(dvar,variables{i}) 116 ixc=vlist_write(fidm,ixc,variables{i},dvar.(variables{i}),params,varargin{:}); 132 117 end 133 118 end … … 137 122 %% function to write variable list into the Matlab m-file 138 123 139 function [ixc]=vlist_write( md,fidm,ixc,vtype,dvar)124 function [ixc]=vlist_write(fidm,ixc,vtype,dvar,params,varargin) 140 125 141 126 disp(sprintf(' Writing %d %s variables.',length(dvar),class(dvar))); … … 156 141 %now, we need a string to put in the matlab file, which will update all the design variables 157 142 %for this descriptor. 158 [string,ixc]=QmuUpdateFunctions( md,ixc,descriptor,dvar,i);143 [string,ixc]=QmuUpdateFunctions(ixc,descriptor,dvar,params,i,varargin{:}); 159 144 160 145 %dump this string in the matlab file. … … 178 163 %% function to write responses into the Matlab m-file 179 164 180 function []=responses_write(fidm, method,params,dresp)165 function []=responses_write(fidm,dmeth,params,dresp) 181 166 182 167 display('Writing responses for Matlab m-file.'); 183 168 184 fprintf(fidm,'%% Calculate the response functions.\n\n');169 fprintf(fidm,'%% Calculate the responses.\n\n'); 185 170 ifnvals=0; 186 171 … … 191 176 % responses vary by method 192 177 193 switch method 194 % case {'dot_bfgs','dot_frcg','dot_mmfd','dot_slp','dot_sqp'} 195 % case {'npsol_sqp'} 196 case {'conmin_frcg','conmin_mfd'} 197 ifnvals=rsets_write(fidm,ifnvals,params,dresp,'of','nic','nec'); 198 % case {'optpp_cg','optpp_q_newton','optpp_fd_newton',... 199 % 'optpp_newton','optpp_pds'} 200 % case {'asynch_pattern_search'} 201 % case {'coliny_cobyla','coliny_direct','coliny_ea',... 202 % 'coliny_pattern_search','coliny_solis_wets'} 203 % case {'ncsu_direct'} 204 % case {'moga','soga'} 205 % case {'nl2sol','nlssol_sqp','optpp_g_newton'} 206 case {'nond_sampling'} 207 ifnvals=rsets_write(fidm,ifnvals,params,dresp,'rf'); 208 case {'nond_local_reliability'} 209 ifnvals=rsets_write(fidm,ifnvals,params,dresp,'rf'); 210 % case {'dace','fsu_quasi_mc','fsu_cvt'} 211 % case {'vector_parameter_study','list_parameter_study',... 212 % 'centered parameter_study','multidim_parameter_study'} 213 end 178 ifnvals=rsets_write(fidm,ifnvals,params,dresp,dmeth.responses); 214 179 215 180 fprintf(fidm,'\n'); … … 222 187 %% function to write response sets into the Matlab m-file 223 188 224 function [ifnvals]=rsets_write(fidm,ifnvals,params,dresp, varargin)225 226 for i=1:length( varargin)227 if isfield(dresp, varargin{i})228 ifnvals=rlist_write(fidm,ifnvals,params, varargin{i},dresp.(varargin{i}));189 function [ifnvals]=rsets_write(fidm,ifnvals,params,dresp,responses) 190 191 for i=1:length(responses) 192 if isfield(dresp,responses{i}) 193 ifnvals=rlist_write(fidm,ifnvals,params,responses{i},dresp.(responses{i})); 229 194 end 230 195 end -
issm/trunk/src/m/solutions/dakota/qmu.m
r1 r32 2 2 %INPUT function md=qmu(md,package) 3 3 %Deal with coupled ISSM or Cielo/ Dakota runs, to do sensitivity analyses. 4 5 global ISSM_DIR; 4 6 5 7 %first create temporary directory in which we will work … … 7 9 qmudir='qmu'; 8 10 if exist(qmudir,'dir') 9 overwrite=input( 'Overwrite existing ''qmu'' directory? Y/N [N]: ', 's');11 overwrite=input(['Overwrite existing ''' qmudir ''' directory? Y/N [N]: '], 's'); 10 12 if strncmpi(overwrite,'y',1) 11 13 system(['rm -rf ' qmudir]); 12 14 else 13 error('Existing '' qmu'' directory not overwritten');15 error('Existing ''%s'' directory not overwritten.',qmudir); 14 16 end 15 17 end … … 22 24 23 25 %create m and in files for dakota 24 dakota_in_data(md,'qmu',package); 26 if ~isfield(md.qmu_params,'analysis_driver') || ... 27 isempty(md.qmu_params.analysis_driver) 28 md.qmu_params.analysis_driver=[ISSM_DIR '/src/m/solutions/dakota/cielo_ice_script.sh']; 29 end 30 31 if (numel(md.qmu_method) > 1) 32 imeth=input('Which method? '); 33 else 34 imeth=1; 35 end 36 dakota_in_data(md.qmu_method(imeth),md.variables,md.responses,md.qmu_params,'qmu',package,md); 37 cd .. 38 return 25 39 26 40 %call dakota 27 41 system('dakota -i qmu.in -o qmu.out -e qmu.err'); 42 % system('export MPIRUN_NPROCS=8;mpirun -np 4 dakota -i qmu.in -o qmu.out -e qmu.err'); 28 43 29 44 %parse inputs and results from dakota -
issm/trunk/src/m/solutions/dakota/setupdesign/QmuSetupDesign.m
r1 r32 1 function dvar=QmuSetupDesign( md,dvar,variables)1 function dvar=QmuSetupDesign(dvar,variables,params,varargin) 2 2 3 3 %get descriptor … … 7 7 if strcmpi(descriptor,'rho_ice') 8 8 9 dvar=setuprhoice(md,dvar,variables); 9 dvar=setuprhoice(dvar,variables,params,varargin{:}); 10 11 elseif strcmpi(descriptor,'rho_water') 12 13 dvar=setuprhowater(dvar,variables,params,varargin{:}); 14 15 elseif strcmpi(descriptor,'heat_capacity') 16 17 dvar=setupheatcapacity(dvar,variables,params,varargin{:}); 18 19 elseif strcmpi(descriptor,'thermal_conductivity') 20 21 dvar=setupthermalconductivity(dvar,variables,params,varargin{:}); 22 23 elseif strcmpi(descriptor,'gravity') 24 25 dvar=setupgravity(dvar,variables,params,varargin{:}); 10 26 11 27 elseif strcmpi(descriptor,'thickness') 12 28 13 dvar=setupthickness( md,dvar,variables);29 dvar=setupthickness(dvar,variables,params,varargin{:}); 14 30 15 31 elseif strcmpi(descriptor,'drag') 16 32 17 dvar=setupdrag( md,dvar,variables);33 dvar=setupdrag(dvar,variables,params,varargin{:}); 18 34 19 35 elseif strcmpi(descriptor,'riftsfriction') 20 36 21 dvar=setupriftsfriction( md,dvar,variables);37 dvar=setupriftsfriction(dvar,variables,params,varargin{:}); 22 38 23 39 else -
issm/trunk/src/m/solutions/dakota/setupdesign/setupdrag.m
r1 r32 1 function dvar=setupdrag(md,dvar,variables) 1 function dvar=setupdrag(dvar,variables,params,varargin) 2 3 for i=1:length(varargin) 4 if strcmp(class(varargin{i}),'model') 5 md=varargin{i}; 6 break; 7 end 8 end 2 9 3 10 %ok, dealing with semi-discrete distributed variable. Distribute according to how many -
issm/trunk/src/m/solutions/dakota/setupdesign/setuprhoice.m
r1 r32 1 function dvar=setuprhoice( md,dvar,variables)1 function dvar=setuprhoice(dvar,variables,params,varargin) 2 2 3 3 dvar(end+1)=variables; -
issm/trunk/src/m/solutions/dakota/setupdesign/setupriftsfriction.m
r1 r32 1 function dvar=setupriftsfriction(md,dvar,variables) 1 function dvar=setupriftsfriction(dvar,variables,params,varargin) 2 3 for i=1:length(varargin) 4 if strcmp(class(varargin{i}),'model') 5 md=varargin{i}; 6 break; 7 end 8 end 2 9 3 10 %we have several rifts. -
issm/trunk/src/m/solutions/dakota/setupdesign/setupthickness.m
r1 r32 1 function dvar=setupthickness(md,dvar,variables) 1 function dvar=setupthickness(dvar,variables,params,varargin) 2 3 for i=1:length(varargin) 4 if strcmp(class(varargin{i}),'model') 5 md=varargin{i}; 6 break; 7 end 8 end 2 9 3 10 %ok, dealing with semi-discrete distributed variable. Distribute according to how many -
issm/trunk/src/m/solutions/dakota/updatefunctions/QmuUpdateFunctions.m
r1 r32 1 function [string,ixc]=QmuUpdateFunctions( md,ixc,descriptor,dvar,i)1 function [string,ixc]=QmuUpdateFunctions(ixc,descriptor,dvar,params,i,varargin) 2 2 3 3 if strcmpi(descriptor,'rho_ice') 4 [string,ixc]=updaterho_ice( md,ixc,dvar,i);4 [string,ixc]=updaterho_ice(ixc,dvar,params,i,varargin{:}); 5 5 6 6 elseif strcmpi(descriptor,'rho_water') 7 [string,ixc]=updaterho_water( md,ixc,dvar,i);7 [string,ixc]=updaterho_water(ixc,dvar,params,i,varargin{:}); 8 8 9 9 elseif strcmpi(descriptor,'heatcapacity') 10 [string,ixc]=updateheatcapacity( md,ixc,dvar,i);10 [string,ixc]=updateheatcapacity(ixc,dvar,params,i,varargin{:}); 11 11 12 12 elseif strcmpi(descriptor,'thermalconductivity') 13 [string,ixc]=updatethermalconductivity( md,ixc,dvar,i);13 [string,ixc]=updatethermalconductivity(ixc,dvar,params,i,varargin{:}); 14 14 15 15 elseif strcmpi(descriptor,'gravity') 16 [string,ixc]=updategravity( md,ixc,dvar,i);16 [string,ixc]=updategravity(ixc,dvar,params,i,varargin{:}); 17 17 18 18 elseif strcmpi(descriptor,'thickness') 19 [string,ixc]=updatethickness( md,ixc,dvar);19 [string,ixc]=updatethickness(ixc,dvar,params,varargin{:}); 20 20 21 21 elseif strcmpi(descriptor,'drag') 22 [string,ixc]=updatedrag( md,ixc,dvar);22 [string,ixc]=updatedrag(ixc,dvar,params,varargin{:}); 23 23 24 24 elseif strcmpi(descriptor,'riftsfriction') 25 [string,ixc]=updateriftsfriction( md,ixc,dvar);25 [string,ixc]=updateriftsfriction(ixc,dvar,params,varargin{:}); 26 26 27 27 else 28 warning('QmuUpdateFunctions warning message:','Unrecognized design variable: %s',descriptor)28 warning('QmuUpdateFunctions:warning','Unrecognized design variable: %s',descriptor) 29 29 end -
issm/trunk/src/m/solutions/dakota/updatefunctions/updatedrag.m
r1 r32 1 function [string,ixc]=updatedrag(md,ixc,dvar) 1 function [string,ixc]=updatedrag(ixc,dvar,params,varargin) 2 3 for i=1:length(varargin) 4 if strcmp(class(varargin{i}),'model') 5 md=varargin{i}; 6 break; 7 end 8 end 2 9 3 10 string=sprintf('\n\t[epart,npart]=MeshPartition(md,%d);\n\n',md.npart); … … 7 14 ixc=ixc+1; 8 15 idrag =sscanf(dvar(j).descriptor(5:end),'%d'); 9 if strcmpi( md.analysis_driver,'matlab')16 if strcmpi(params.analysis_driver,'matlab') 10 17 string=[string sprintf('\tdragi(%d,1)=Dakota.xC(%d);\n',idrag,ixc)]; 11 18 else -
issm/trunk/src/m/solutions/dakota/updatefunctions/updategravity.m
r1 r32 1 function [string,ixc]=updategravity( md,ixc,dvar,i)1 function [string,ixc]=updategravity(ixc,dvar,params,i,varargin) 2 2 3 3 ixc=ixc+1; 4 if strcmpi( md.analysis_driver,'matlab')4 if strcmpi(params.analysis_driver,'matlab') 5 5 string=sprintf('\tmd.g=Dakota.xC(%d);\n',ixc); 6 6 else -
issm/trunk/src/m/solutions/dakota/updatefunctions/updateheatcapacity.m
r1 r32 1 function [string,ixc]=updateheatcapacity( md,ixc,dvar,i)1 function [string,ixc]=updateheatcapacity(ixc,dvar,params,i,varargin) 2 2 3 3 ixc=ixc+1; 4 if strcmpi( md.analysis_driver,'matlab')4 if strcmpi(params.analysis_driver,'matlab') 5 5 string=sprintf('\tmd.heatcapacity=Dakota.xC(%d);\n',ixc); 6 6 else -
issm/trunk/src/m/solutions/dakota/updatefunctions/updaterho_ice.m
r1 r32 1 function [string,ixc]=updaterho_ice( md,ixc,dvar,i)1 function [string,ixc]=updaterho_ice(ixc,dvar,params,i,varargin) 2 2 3 3 ixc=ixc+1; 4 if strcmpi( md.analysis_driver,'matlab')4 if strcmpi(params.analysis_driver,'matlab') 5 5 string=sprintf('\tmd.rho_ice=Dakota.xC(%d);\n',ixc); 6 6 else -
issm/trunk/src/m/solutions/dakota/updatefunctions/updaterho_water.m
r1 r32 1 function [string,ixc]=updaterho_water( md,ixc,dvar,i)1 function [string,ixc]=updaterho_water(ixc,dvar,params,i,varargin) 2 2 3 3 ixc=ixc+1; 4 if strcmpi( md.analysis_driver,'matlab')4 if strcmpi(params.analysis_driver,'matlab') 5 5 string=sprintf('\tmd.rho_water=Dakota.xC(%d);\n',ixc); 6 6 else -
issm/trunk/src/m/solutions/dakota/updatefunctions/updateriftsfriction.m
r1 r32 1 function [string,ixc]=updateriftsfriction(md,ixc,dvar) 1 function [string,ixc]=updateriftsfriction(ixc,dvar,params,varargin) 2 3 for i=1:length(varargin) 4 if strcmp(class(varargin{i}),'model') 5 md=varargin{i}; 6 break; 7 end 8 end 2 9 3 10 string=sprintf('\n'); … … 6 13 ixc=ixc+1; 7 14 irift=sscanf(dvar(j).descriptor(14:end),'%d'); 8 if strcmpi( md.analysis_driver,'matlab')15 if strcmpi(params.analysis_driver,'matlab') 9 16 string=[string sprintf('\tmd.rifts(%d).friction=Dakota.xC(%d);\n',irift,ixc)]; 10 17 else -
issm/trunk/src/m/solutions/dakota/updatefunctions/updatethermalconductivity.m
r1 r32 1 function [string,ixc]=updatethermalconductivity( md,ixc,dvar,i)1 function [string,ixc]=updatethermalconductivity(ixc,dvar,params,i,varargin) 2 2 3 3 ixc=ixc+1; 4 if strcmpi( md.analysis_driver,'matlab')4 if strcmpi(params.analysis_driver,'matlab') 5 5 string=sprintf('\tmd.thermalconductivity=Dakota.xC(%d);\n',ixc); 6 6 else -
issm/trunk/src/m/solutions/dakota/updatefunctions/updatethickness.m
r1 r32 1 function [string,ixc]=updatethickness(md,ixc,dvar) 1 function [string,ixc]=updatethickness(ixc,dvar,params,varargin) 2 3 for i=1:length(varargin) 4 if strcmp(class(varargin{i}),'model') 5 md=varargin{i}; 6 break; 7 end 8 end 2 9 3 10 string=sprintf('\n\t[epart,npart]=MeshPartition(md,%d);\n',md.npart); … … 7 14 ixc=ixc+1; 8 15 ithick=sscanf(dvar(j).descriptor(10:end),'%d'); 9 if strcmpi( md.analysis_driver,'matlab')16 if strcmpi(params.analysis_driver,'matlab') 10 17 string=[string sprintf('\tthicki(%d,1)=Dakota.xC(%d);\n',ithick,ixc)]; 11 18 else -
issm/trunk/src/m/solutions/ice/ModelProcessorDiagnosticHoriz.m
r1 r32 312 312 if ~isempty(md.penalties) & ~isnan(md.penalties), 313 313 for i=1:size(md.penalties,1), 314 for j= 1:(md.numlayers-1),314 for j=2:size(md.penalties,2), 315 315 316 316 %constrain first dof 317 317 constraints(count).constraint=rgb; 318 318 constraints(count).constraint.grid1=md.penalties(i,1); 319 constraints(count).constraint.grid2=md.penalties(i,j +1);319 constraints(count).constraint.grid2=md.penalties(i,j); 320 320 constraints(count).constraint.dof=1; 321 321 count=count+1; … … 324 324 constraints(count).constraint=rgb; 325 325 constraints(count).constraint.grid1=md.penalties(i,1); 326 constraints(count).constraint.grid2=md.penalties(i,j +1);326 constraints(count).constraint.grid2=md.penalties(i,j); 327 327 constraints(count).constraint.dof=2; 328 328 count=count+1; -
issm/trunk/src/m/solutions/ice/ModelProcessorPrognostic.m
r1 r32 116 116 loads=struct('load',cell([0,1])); 117 117 118 %Single point constraints: none; 119 constraints=struct('constraint',cell(0,0)); 118 119 %Initialize constraints structure 120 constraints=struct('constraint',cell(length(find(md.gridondirichlet_prog)),1)); 121 122 pos=find(md.gridondirichlet_prog); 123 count=1; 124 for i=1:length(find(md.gridondirichlet_prog)), 125 126 %constrain the thickness 127 constraints(count).constraint=spc; 128 constraints(count).constraint.grid=pos(i); 129 constraints(count).constraint.dof=1; 130 constraints(count).constraint.value=md.dirichletvalues_prog(pos(i)); %in m 131 count=count+1; 132 end 120 133 121 134 %Last thing, return a partitioning vector, and its transpose. -
issm/trunk/src/m/solutions/ice/StrainRateCompute.m
r1 r32 34 34 35 35 strainratematrix=[strainratevector(1) strainratevector(3) 36 36 strainratevector(3) strainratevector(2)]; 37 37 38 38 %eigen values and vectors … … 41 41 %Plug into global vectors 42 42 strainrate1(n,:)=strainratevector; 43 44 45 43 A1(n,1)=value(1,1); A2(n,1)=value(2,2); 44 Vx1(n,1)=directions(1,1); Vx2(n,1)=directions(1,2); 45 Vy1(n,1)=directions(2,1); Vy2(n,1)=directions(2,2); 46 46 end 47 47 end … … 54 54 strainrate.xy=strainrate1(:,3)*(365.25*24*3600); 55 55 %principal axis and values 56 strainrate.principalvalue2=A1 ;56 strainrate.principalvalue2=A1*(365.25*24*3600); %strain rate in 1/a instead of 1/s 57 57 strainrate.principalaxis2=[Vx1 Vy1]; 58 strainrate.principalvalue1=A2 ;58 strainrate.principalvalue1=A2*(365.25*24*3600); 59 59 strainrate.principalaxis1=[Vx2 Vy2]; 60 60 %Norm or effective value -
issm/trunk/src/m/solutions/macayeal/macayealcontrol.m
r1 r32 142 142 index,x,y,nel,rho_ice,g,weighting,alpha,beta,z_thick_bar,B_bar); 143 143 144 if niteration==1 145 scrsz = get(0,'ScreenSize'); 146 figure('Position',[scrsz(3)/3 scrsz(4)*1.8/3 scrsz(3)/3 scrsz(4)/3]) 147 end 148 plotmodel(md,'data',sqrt(u.^2+v.^2)*yts,'title','Modeled velocity',... 149 'data',sqrt(adjointu.^2+adjointv.^2)*yts,'title','Adjoint vectors','colorbar#all', 'on',... 150 'data',sqrt(vx_obs.^2+vy_obs.^2)*yts,'title','Observed velocity',... 151 'data',100*abs(sqrt(vx_obs.^2+vy_obs.^2)-sqrt(u.^2+v.^2))./sqrt(vx_obs.^2+vy_obs.^2),'title','Relative misfit','caxis#4',[0 100],'figure',1);pause(1); 144 if md.plot==1, 145 if niteration==1 146 scrsz = get(0,'ScreenSize'); 147 figure('Position',[scrsz(3)/3 scrsz(4)*1.8/3 scrsz(3)/3 scrsz(4)/3]) 148 end 149 plotmodel(md,'data',sqrt(u.^2+v.^2)*yts,'title','Modeled velocity',... 150 'data',sqrt(adjointu.^2+adjointv.^2)*yts,'title','Adjoint vectors','colorbar#all', 'on',... 151 'data',sqrt(vx_obs.^2+vy_obs.^2)*yts,'title','Observed velocity',... 152 'data',100*abs(sqrt(vx_obs.^2+vy_obs.^2)-sqrt(u.^2+v.^2))./sqrt(vx_obs.^2+vy_obs.^2),'title','Relative misfit','caxis#4',[0 100],'figure',1);drawnow; 153 end 152 154 153 155 %Keep track of u and v to use in objectivefunction_C: … … 164 166 old_direction=direction; 165 167 166 %visualize direction 167 if niteration==1 168 scrsz = get(0,'ScreenSize'); 169 figure('Position',[10 scrsz(4)*1/3 scrsz(3)/3 scrsz(4)/3]) 170 end 171 plotmodel(md,'data',direction,'title','Orthogonal direction','figure',2);pause(1); 168 %visualize direction 169 if md.plot==1, 170 if niteration==1 171 scrsz = get(0,'ScreenSize'); 172 figure('Position',[10 scrsz(4)*1/3 scrsz(3)/3 scrsz(4)/3]) 173 end 174 plotmodel(md,'data',direction,'title','Orthogonal direction','figure',2);drawnow; 175 end 172 176 173 177 … … 208 212 209 213 %visualize new distribution. 210 if niteration==1 211 scrsz = get(0,'ScreenSize'); 212 figure('Position',[scrsz(3)*1.97/3 scrsz(4)*1/3 scrsz(3)/3 scrsz(4)/3]) 213 end 214 plotmodel(md,'data',B*B_to_p,'title',['B at iteration ' num2str(niteration)],'caxis',[200 900],'colorbar','on','figure',3);pause(1); 214 if md.plot==1, 215 if niteration==1 216 scrsz = get(0,'ScreenSize'); 217 figure('Position',[scrsz(3)*1.97/3 scrsz(4)*1/3 scrsz(3)/3 scrsz(4)/3]) 218 end 219 plotmodel(md,'data',B*B_to_p,'title',['B at iteration ' num2str(niteration)],'caxis',[200 900],'colorbar','on','figure',3);drawnow; 220 end 215 221 216 222 %evaluate new misfit. … … 243 249 index,x,y,nel,rho_ice,g,weighting,alpha,beta,z_thick_bar,drag_coeff,drag_coeff_bar); 244 250 245 if niteration==1 246 scrsz = get(0,'ScreenSize'); 247 figure('Position',[scrsz(3)/3 scrsz(4)*1.8/3 scrsz(3)/3 scrsz(4)/3]) 248 end 249 plotmodel(md,'data',sqrt(u.^2+v.^2),'title','Modeled velocity',... 250 'data',sqrt(adjointu.^2+adjointv.^2),'title','Adjoint vectors','colorbar', 'all',... 251 'data',sqrt(vx_obs.^2+vy_obs.^2),'title','Observed velocity',... 252 'data',100*abs(sqrt(vx_obs.^2+vy_obs.^2)-sqrt(u.^2+v.^2))./sqrt(vx_obs.^2+vy_obs.^2),'title','Relative misfit','caxis#3',[0 100],'figure',1);pause(1); 251 if md.plot==1, 252 if niteration==1 253 scrsz = get(0,'ScreenSize'); 254 figure('Position',[scrsz(3)/3 scrsz(4)*1.8/3 scrsz(3)/3 scrsz(4)/3]) 255 end 256 plotmodel(md,'data',sqrt(u.^2+v.^2),'title','Modeled velocity',... 257 'data',sqrt(adjointu.^2+adjointv.^2),'title','Adjoint vectors','colorbar', 'all',... 258 'data',sqrt(vx_obs.^2+vy_obs.^2),'title','Observed velocity',... 259 'data',100*abs(sqrt(vx_obs.^2+vy_obs.^2)-sqrt(u.^2+v.^2))./sqrt(vx_obs.^2+vy_obs.^2),'title','Relative misfit','caxis#3',[0 100],'figure',1);drawnow; 260 end 253 261 254 262 %Keep track of u and v to use in objectivefunction_C: … … 268 276 269 277 %visualize direction 270 if niteration==1 271 scrsz = get(0,'ScreenSize'); 272 figure('Position',[10 scrsz(4)*1/3 scrsz(3)/3 scrsz(4)/3]) 273 end 274 plotmodel(md,'data',direction,'title','Orthogonal direction','figure',2);pause(1); 278 if md.plot==1, 279 if niteration==1 280 scrsz = get(0,'ScreenSize'); 281 figure('Position',[10 scrsz(4)*1/3 scrsz(3)/3 scrsz(4)/3]) 282 end 283 plotmodel(md,'data',direction,'title','Orthogonal direction','figure',2);drawnow; 284 end 275 285 276 286 … … 319 329 320 330 %visualize new distribution. 321 plotmodel(md,'data',drag_coeff,'title',['Drag at iteration ' num2str(niteration)],'caxis',[0 1000],'colorbar','on','figure',3);pause(1); 331 if md.plot==1, 332 plotmodel(md,'data',drag_coeff,'title',['Drag at iteration ' num2str(niteration)],'caxis',[0 1000],'colorbar','on','figure',3);drawnow; 333 end 322 334 323 335 %evaluate new misfit.
Note:
See TracChangeset
for help on using the changeset viewer.