[963] | 1 | function md=preqmu(md,options)
|
---|
| 2 | %QMU - apply Quantification of Margins and Uncertainties techniques
|
---|
| 3 | % to a solution sequence (like diagnostic.m, progonstic.m, etc ...),
|
---|
| 4 | % using the Dakota software from Sandia.
|
---|
| 5 | %
|
---|
| 6 | % options come from the solve.m routine. They can include Dakota options:
|
---|
| 7 | %
|
---|
| 8 | % qmudir: any directory where to run the qmu analysis
|
---|
| 9 | % qmufile: input file for Dakota
|
---|
| 10 | % ivar: selection number for variables input (if several are specified in variables)
|
---|
| 11 | % iresp: same thing for response functions
|
---|
| 12 | % imethod: same thing for methods
|
---|
| 13 | % iparams: same thing for params
|
---|
[6568] | 14 | % overwrite: overwrite qmudir before analysis
|
---|
| 15 | % keep: keep qmudir after analysis
|
---|
[963] | 16 | % outfiles: (John?)
|
---|
| 17 | % rstfile: backup file name
|
---|
| 18 | % rundakota: (John?)
|
---|
| 19 | % runmpi: (John?)
|
---|
| 20 |
|
---|
[6088] | 21 | global ISSM_TIER;
|
---|
[963] | 22 |
|
---|
[6309] | 23 | disp('preprocessing dakota inputs');
|
---|
[963] | 24 |
|
---|
| 25 | %first create temporary directory in which we will work
|
---|
[5029] | 26 | if strncmpi(options.overwrite,'y',1)
|
---|
| 27 | system(['rm -rf ' options.qmudir '/*']);
|
---|
| 28 | else
|
---|
| 29 | %does the directory exist? if so, then error out
|
---|
| 30 | if exist(options.qmudir)==7,
|
---|
| 31 | error('Existing ''%s'' directory, cannot overwrite. Specify ''overwrite'',''y'' option in solve arguments.',options.qmudir);
|
---|
| 32 | end
|
---|
[963] | 33 | end
|
---|
| 34 | mkdir(options.qmudir)
|
---|
| 35 | cd(options.qmudir)
|
---|
| 36 |
|
---|
| 37 | %when running in library mode, the in file needs to be called md.name.qmu.in
|
---|
| 38 | options.qmufile=[md.name ];
|
---|
| 39 |
|
---|
| 40 | %retrieve variables and resposnes for this particular analysis.
|
---|
| 41 | variables=md.variables(options.ivar);
|
---|
| 42 | responses=md.responses(options.iresp);
|
---|
| 43 |
|
---|
[5487] | 44 | %expand variables and responses
|
---|
[6615] | 45 | variables=expandvariables(md,variables);
|
---|
| 46 | responses=expandresponses(md,responses);
|
---|
[5215] | 47 |
|
---|
[5487] | 48 | %go through variables and responses, and check they don't have more than md.npart values. Also determine numvariables and numresponses{{{1
|
---|
| 49 | numvariables=0;
|
---|
[5215] | 50 | variable_fieldnames=fieldnames(variables);
|
---|
| 51 | for i=1:length(variable_fieldnames),
|
---|
| 52 | field_name=variable_fieldnames{i};
|
---|
| 53 | fieldvariables=variables.(field_name);
|
---|
[6615] | 54 | for j=1:numel(fieldvariables)
|
---|
| 55 | if strncmpi(fieldvariables(j).descriptor,'scaled_',7) && str2int(fieldvariables(j).descriptor,'last')>md.npart,
|
---|
| 56 | error('preqmu error message: one of the expanded variables has more values than the number of partitions (setup in md.npart)');
|
---|
| 57 | end
|
---|
[5215] | 58 | end
|
---|
[963] | 59 | numvariables=numvariables+numel(variables.(field_name));
|
---|
| 60 | end
|
---|
| 61 |
|
---|
| 62 | numresponses=0;
|
---|
| 63 | response_fieldnames=fieldnames(responses);
|
---|
| 64 | for i=1:length(response_fieldnames),
|
---|
| 65 | field_name=response_fieldnames{i};
|
---|
| 66 | fieldresponses=responses.(field_name);
|
---|
[6615] | 67 | for j=1:numel(fieldresponses)
|
---|
| 68 | if strncmpi(fieldresponses(j).descriptor,'scaled_',7) && str2int(fieldresponses(j).descriptor,'last')>md.npart,
|
---|
| 69 | error('preqmu error message: one of the expanded responses has more values than the number of partitions (setup in md.npart)');
|
---|
| 70 | end
|
---|
[5487] | 71 | end
|
---|
[963] | 72 | numresponses=numresponses+numel(responses.(field_name));
|
---|
| 73 | end
|
---|
[5487] | 74 | %}}}}
|
---|
[963] | 75 |
|
---|
[5487] | 76 | %create in file for dakota
|
---|
| 77 | dakota_in_data(md.qmu_method(options.imethod),variables,responses,md.qmu_params(options.iparams),options.qmufile);
|
---|
| 78 | system(['rm -rf ' md.name '.m']);
|
---|
[963] | 79 |
|
---|
[5487] | 80 | %build a list of variables and responses descriptors. the list is not expanded. {{{1
|
---|
[963] | 81 | variabledescriptors={};
|
---|
[6615] | 82 | variable_fieldnames=fieldnames(md.variables(options.ivar));
|
---|
[963] | 83 | for i=1:length(variable_fieldnames),
|
---|
| 84 | field_name=variable_fieldnames{i};
|
---|
[6615] | 85 | fieldvariables=md.variables(options.ivar).(field_name);
|
---|
| 86 | for j=1:numel(fieldvariables)
|
---|
| 87 | variabledescriptors{end+1}=fieldvariables(j).descriptor;
|
---|
| 88 | end
|
---|
[963] | 89 | end
|
---|
| 90 |
|
---|
| 91 | responsedescriptors={};
|
---|
[6615] | 92 | response_fieldnames=fieldnames(md.responses(options.iresp));
|
---|
[963] | 93 | for i=1:length(response_fieldnames),
|
---|
| 94 | field_name=response_fieldnames{i};
|
---|
[6615] | 95 | fieldresponses=md.responses(options.iresp).(field_name);
|
---|
| 96 | for j=1:numel(fieldresponses)
|
---|
| 97 | responsedescriptors{end+1}=fieldresponses(j).descriptor;
|
---|
| 98 | end
|
---|
[963] | 99 | end
|
---|
[5487] | 100 | %}}}
|
---|
[963] | 101 |
|
---|
| 102 | %register the fields that will be needed by the Qmu model.
|
---|
| 103 | md.numberofvariables=numvariables;
|
---|
| 104 | md.numberofresponses=numresponses;
|
---|
| 105 | md.variabledescriptors=variabledescriptors;
|
---|
| 106 | md.responsedescriptors=responsedescriptors;
|
---|
[5487] | 107 | md.numvariabledescriptors=numel(md.variabledescriptors);
|
---|
| 108 | md.numresponsedescriptors=numel(md.responsedescriptors);
|
---|
[963] | 109 |
|
---|
[2110] | 110 | %now, we have to provide all the info necessary for the solutions to compute the responses. For ex, if mass_flux
|
---|
[4761] | 111 | %is a response, we need a profile of points. For a misfit, we need the observed velocity, etc ...
|
---|
[2110] | 112 | md=process_qmu_response_data(md);
|
---|