1 | function md=preqmu(md,options)
|
---|
2 | %QMU - apply Quantification of Margins and Uncertainties techniques
|
---|
3 | % to a solution sequence (like stressbalance.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 | % qmufile: input file for Dakota
|
---|
9 | % ivar: selection number for variables input (if several are specified in variables)
|
---|
10 | % iresp: same thing for response functions
|
---|
11 | % imethod: same thing for methods
|
---|
12 | % iparams: same thing for params
|
---|
13 |
|
---|
14 | disp('preprocessing dakota inputs');
|
---|
15 | qmufile = getfieldvalue(options,'qmufile','qmu');
|
---|
16 | ivar = getfieldvalue(options,'ivar',1);
|
---|
17 | iresp = getfieldvalue(options,'iresp',1);
|
---|
18 | imethod = getfieldvalue(options,'imethod',1);
|
---|
19 | iparams = getfieldvalue(options,'iparams',1);
|
---|
20 |
|
---|
21 | %when running in library mode, the in file needs to be called md.miscellaneous.name.qmu.in
|
---|
22 | qmufile=[md.miscellaneous.name];
|
---|
23 |
|
---|
24 | %retrieve variables and resposnes for this particular analysis.
|
---|
25 | variables=md.qmu.variables(ivar);
|
---|
26 | responses=md.qmu.responses(iresp);
|
---|
27 |
|
---|
28 | %expand variables and responses
|
---|
29 | variables=expandvariables(md,variables);
|
---|
30 | responses=expandresponses(md,responses);
|
---|
31 |
|
---|
32 | %go through variables and responses, and check they don't have more than the number of partitions. Also determine numvariables and numresponses
|
---|
33 | numvariables=0;
|
---|
34 | variable_fieldnames=fieldnames(variables);
|
---|
35 | for i=1:length(variable_fieldnames),
|
---|
36 | field_name=variable_fieldnames{i};
|
---|
37 | fieldvariables=variables.(field_name);
|
---|
38 | for j=1:numel(fieldvariables)
|
---|
39 | if strncmpi(fieldvariables(j).descriptor,'scaled_',7),
|
---|
40 | npart=qmupart2npart(fieldvariables(j).partition);
|
---|
41 | nt=fieldvariables(j).nsteps;
|
---|
42 | if nt==1,
|
---|
43 | if str2int(fieldvariables(j).descriptor,'last')>npart,
|
---|
44 | error('preqmu error message: one of the expanded variables has more values than the number of partitions ');
|
---|
45 | end
|
---|
46 | end
|
---|
47 | end
|
---|
48 | end
|
---|
49 | numvariables=numvariables+numel(variables.(field_name));
|
---|
50 | end
|
---|
51 |
|
---|
52 | numresponses=0;
|
---|
53 | response_fieldnames=fieldnames(responses);
|
---|
54 | for i=1:length(response_fieldnames),
|
---|
55 | field_name=response_fieldnames{i};
|
---|
56 | fieldresponses=responses.(field_name);
|
---|
57 | for j=1:numel(fieldresponses)
|
---|
58 | if strncmpi(fieldresponses(j).descriptor,'scaled_',7),
|
---|
59 | npart=partition_npart(fieldresponses(j).partition);
|
---|
60 | if str2int(fieldresponses(j).descriptor,'last')>npart,
|
---|
61 | error('preqmu error message: one of the expanded responses has more values than the number of partitions');
|
---|
62 | end
|
---|
63 | end
|
---|
64 | end
|
---|
65 | numresponses=numresponses+numel(responses.(field_name));
|
---|
66 | end
|
---|
67 |
|
---|
68 | %create in file for dakota
|
---|
69 | dakota_in_data(md.qmu.method(imethod),variables,responses,md.qmu.params(iparams),qmufile,md.qmu.correlation_matrix);
|
---|
70 |
|
---|
71 | %build a list of variables and responses descriptors. the list is not expanded.
|
---|
72 | variabledescriptors={};
|
---|
73 | variable_fieldnames=fieldnames(md.qmu.variables(ivar));
|
---|
74 | for i=1:length(variable_fieldnames),
|
---|
75 | field_name=variable_fieldnames{i};
|
---|
76 | fieldvariables=md.qmu.variables(ivar).(field_name);
|
---|
77 | for j=1:numel(fieldvariables)
|
---|
78 | variabledescriptors{end+1}=fieldvariables(j).descriptor;
|
---|
79 | end
|
---|
80 | end
|
---|
81 |
|
---|
82 | responsedescriptors={};
|
---|
83 | response_fieldnames=fieldnames(md.qmu.responses(iresp));
|
---|
84 | for i=1:length(response_fieldnames),
|
---|
85 | field_name=response_fieldnames{i};
|
---|
86 | fieldresponses=md.qmu.responses(iresp).(field_name);
|
---|
87 | for j=1:numel(fieldresponses)
|
---|
88 | responsedescriptors{end+1}=fieldresponses(j).descriptor;
|
---|
89 | end
|
---|
90 | end
|
---|
91 |
|
---|
92 | %build a MatArray of variable partitions:
|
---|
93 | variablepartitions={};
|
---|
94 | variablepartitions_npart=[];
|
---|
95 | variablepartitions_nt=[];
|
---|
96 | variable_fieldnames=fieldnames(md.qmu.variables(ivar));
|
---|
97 | for i=1:length(variable_fieldnames),
|
---|
98 | field_name=variable_fieldnames{i};
|
---|
99 | fieldvariable=md.qmu.variables(ivar).(field_name);
|
---|
100 | if fieldvariable.isscaled() | fieldvariable.isdistributed();
|
---|
101 | variablepartitions{end+1}=fieldvariable.partition;
|
---|
102 | variablepartitions_npart(end+1)=qmupart2npart(fieldvariable.partition);
|
---|
103 | if isprop(fieldvariable,'nsteps'),
|
---|
104 | variablepartitions_nt(end+1)=fieldvariable.nsteps;
|
---|
105 | else
|
---|
106 | variablepartitions_nt(end+1)=1;
|
---|
107 | end
|
---|
108 | else
|
---|
109 | variablepartitions{end+1}=[];
|
---|
110 | variablepartitions_npart(end+1)=0;
|
---|
111 | variablepartitions_nt(end+1)=1;
|
---|
112 | end
|
---|
113 | end
|
---|
114 |
|
---|
115 | %build a MatArray of response partitions:
|
---|
116 | responsepartitions={};
|
---|
117 | responsepartitions_npart=[];
|
---|
118 | response_fieldnames=fieldnames(md.qmu.responses(iresp));
|
---|
119 | for i=1:length(response_fieldnames),
|
---|
120 | field_name=response_fieldnames{i};
|
---|
121 | fieldresponse=md.qmu.responses(iresp).(field_name);
|
---|
122 | if fieldresponse.isscaled();
|
---|
123 | responsepartitions{end+1}=fieldresponse.partition;
|
---|
124 | responsepartitions_npart(end+1)=qmupart2npart(fieldresponse.partition);
|
---|
125 | else
|
---|
126 | responsepartitions{end+1}=[];
|
---|
127 | responsepartitions_npart(end+1)=0;
|
---|
128 | end
|
---|
129 | end
|
---|
130 |
|
---|
131 |
|
---|
132 | %register the fields that will be needed by the Qmu model.
|
---|
133 | md.qmu.numberofresponses=numresponses;
|
---|
134 | md.qmu.variabledescriptors=variabledescriptors;
|
---|
135 | md.qmu.variablepartitions=variablepartitions;
|
---|
136 | md.qmu.variablepartitions_npart=variablepartitions_npart;
|
---|
137 | md.qmu.variablepartitions_nt=variablepartitions_nt;
|
---|
138 | md.qmu.responsedescriptors=responsedescriptors;
|
---|
139 | md.qmu.responsepartitions=responsepartitions;
|
---|
140 | md.qmu.responsepartitions_npart=responsepartitions_npart;
|
---|
141 |
|
---|
142 |
|
---|
143 | %now, we have to provide all the info necessary for the solutions to compute the responses. For ex, if mass_flux
|
---|
144 | %is a response, we need a profile of points. For a misfit, we need the observed velocity, etc ...
|
---|
145 | md=process_qmu_response_data(md);
|
---|
146 |
|
---|