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
|
---|
14 | % overwrite: overwrite qmudir before analysis
|
---|
15 | % keep: keep qmudir after analysis
|
---|
16 | % outfiles: (John?)
|
---|
17 | % rstfile: backup file name
|
---|
18 | % rundakota: (John?)
|
---|
19 | % runmpi: (John?)
|
---|
20 |
|
---|
21 | disp('preprocessing dakota inputs');
|
---|
22 |
|
---|
23 | %first create temporary directory in which we will work
|
---|
24 | if strncmpi(options.overwrite,'y',1)
|
---|
25 | system(['rm -rf ' options.qmudir '/*']);
|
---|
26 | else
|
---|
27 | %does the directory exist? if so, then error out
|
---|
28 | if exist(options.qmudir)==7,
|
---|
29 | error('Existing ''%s'' directory, cannot overwrite. Specify ''overwrite'',''y'' option in solve arguments.',options.qmudir);
|
---|
30 | end
|
---|
31 | end
|
---|
32 | mkdir(options.qmudir)
|
---|
33 | cd(options.qmudir)
|
---|
34 |
|
---|
35 | %when running in library mode, the in file needs to be called md.miscellaneous.name.qmu.in
|
---|
36 | options.qmufile=[md.miscellaneous.name ];
|
---|
37 |
|
---|
38 | %retrieve variables and resposnes for this particular analysis.
|
---|
39 | variables=md.variables(options.ivar);
|
---|
40 | responses=md.responses(options.iresp);
|
---|
41 |
|
---|
42 | %expand variables and responses
|
---|
43 | variables=expandvariables(md,variables);
|
---|
44 | responses=expandresponses(md,responses);
|
---|
45 |
|
---|
46 | %go through variables and responses, and check they don't have more than md.npart values. Also determine numvariables and numresponses{{{1
|
---|
47 | numvariables=0;
|
---|
48 | variable_fieldnames=fieldnames(variables);
|
---|
49 | for i=1:length(variable_fieldnames),
|
---|
50 | field_name=variable_fieldnames{i};
|
---|
51 | fieldvariables=variables.(field_name);
|
---|
52 | for j=1:numel(fieldvariables)
|
---|
53 | if strncmpi(fieldvariables(j).descriptor,'scaled_',7) && str2int(fieldvariables(j).descriptor,'last')>md.npart,
|
---|
54 | error('preqmu error message: one of the expanded variables has more values than the number of partitions (setup in md.npart)');
|
---|
55 | end
|
---|
56 | end
|
---|
57 | numvariables=numvariables+numel(variables.(field_name));
|
---|
58 | end
|
---|
59 |
|
---|
60 | numresponses=0;
|
---|
61 | response_fieldnames=fieldnames(responses);
|
---|
62 | for i=1:length(response_fieldnames),
|
---|
63 | field_name=response_fieldnames{i};
|
---|
64 | fieldresponses=responses.(field_name);
|
---|
65 | for j=1:numel(fieldresponses)
|
---|
66 | if strncmpi(fieldresponses(j).descriptor,'scaled_',7) && str2int(fieldresponses(j).descriptor,'last')>md.npart,
|
---|
67 | error('preqmu error message: one of the expanded responses has more values than the number of partitions (setup in md.npart)');
|
---|
68 | end
|
---|
69 | end
|
---|
70 | numresponses=numresponses+numel(responses.(field_name));
|
---|
71 | end
|
---|
72 | %}}}}
|
---|
73 |
|
---|
74 | %create in file for dakota
|
---|
75 | dakota_in_data(md.qmu_method(options.imethod),variables,responses,md.qmu_params(options.iparams),options.qmufile);
|
---|
76 | system(['rm -rf ' md.miscellaneous.name '.m']);
|
---|
77 |
|
---|
78 | %build a list of variables and responses descriptors. the list is not expanded. {{{1
|
---|
79 | variabledescriptors={};
|
---|
80 | variable_fieldnames=fieldnames(md.variables(options.ivar));
|
---|
81 | for i=1:length(variable_fieldnames),
|
---|
82 | field_name=variable_fieldnames{i};
|
---|
83 | fieldvariables=md.variables(options.ivar).(field_name);
|
---|
84 | for j=1:numel(fieldvariables)
|
---|
85 | variabledescriptors{end+1}=fieldvariables(j).descriptor;
|
---|
86 | end
|
---|
87 | end
|
---|
88 |
|
---|
89 | responsedescriptors={};
|
---|
90 | response_fieldnames=fieldnames(md.responses(options.iresp));
|
---|
91 | for i=1:length(response_fieldnames),
|
---|
92 | field_name=response_fieldnames{i};
|
---|
93 | fieldresponses=md.responses(options.iresp).(field_name);
|
---|
94 | for j=1:numel(fieldresponses)
|
---|
95 | responsedescriptors{end+1}=fieldresponses(j).descriptor;
|
---|
96 | end
|
---|
97 | end
|
---|
98 | %}}}
|
---|
99 |
|
---|
100 | %register the fields that will be needed by the Qmu model.
|
---|
101 | md.numberofresponses=numresponses;
|
---|
102 | md.variabledescriptors=variabledescriptors;
|
---|
103 | md.responsedescriptors=responsedescriptors;
|
---|
104 |
|
---|
105 | %now, we have to provide all the info necessary for the solutions to compute the responses. For ex, if mass_flux
|
---|
106 | %is a response, we need a profile of points. For a misfit, we need the observed velocity, etc ...
|
---|
107 | md=process_qmu_response_data(md);
|
---|