1 | function sens=sensitivies(md,variablename,responsename)
|
---|
2 | %SENSITIVIES - compute sensitivities for a certain variable and response.
|
---|
3 | %
|
---|
4 | % Usage:
|
---|
5 | % sens=sensitivities(md,variablename,responsename)
|
---|
6 | %
|
---|
7 | %
|
---|
8 | % Example: sens=sensitivities(md,'DragCoefficient','MaxVel');
|
---|
9 | %
|
---|
10 |
|
---|
11 | variablenamelength=length(variablename);
|
---|
12 |
|
---|
13 | %go through all response functions and find the one corresponding to the correct responsename
|
---|
14 | responsefunctions=md.qmu.results.dresp_out;
|
---|
15 | found=0;
|
---|
16 | for i=1:length(responsefunctions),
|
---|
17 | if strcmpi(responsefunctions(i).descriptor,responsename),
|
---|
18 | found=i;
|
---|
19 | break;
|
---|
20 | end
|
---|
21 | end
|
---|
22 | if ~found,
|
---|
23 | error('importancefactors error message: could not find correct response function');
|
---|
24 | end
|
---|
25 | responsefunctions=responsefunctions(found);
|
---|
26 | nfun=size(responsefunctions.var,1);
|
---|
27 |
|
---|
28 | %Now recover response to the correct design variable
|
---|
29 | rawsens=zeros(0,1);
|
---|
30 | count=0;
|
---|
31 | for i=1:nfun,
|
---|
32 | desvar=responsefunctions.var{i};
|
---|
33 | if strncmpi(desvar,variablename,variablenamelength),
|
---|
34 | rawsens(end+1,1)=responsefunctions.sens(i);
|
---|
35 | count=count+1;
|
---|
36 | end
|
---|
37 | end
|
---|
38 |
|
---|
39 | %Now, if this was a distributed variable, the sensitivities need to be scaled by means of the input variable.
|
---|
40 | if IsScaled(variablename),
|
---|
41 |
|
---|
42 | %ipick up the variable in the model
|
---|
43 | switch variablename,
|
---|
44 | case 'thickness', variable = md.geometry.thickness;
|
---|
45 | otherwise, error(['scaled variable ' variablename ' not associated to any model field']);
|
---|
46 | end
|
---|
47 |
|
---|
48 | %average it onto the partition
|
---|
49 | average_variable=AreaAverageOntoPartition(md,variable);
|
---|
50 |
|
---|
51 | %scale the sensitivities: only where the average_variable is not 0
|
---|
52 | if ~isempty(rawsens),
|
---|
53 | pos=find(average_variable);
|
---|
54 | rawsens(pos)=rawsens(pos)./average_variable(pos);
|
---|
55 | end
|
---|
56 | end
|
---|
57 |
|
---|
58 | if count==0,
|
---|
59 | error('sensitivities error message: either response does not exist, or sensitivities are empty');
|
---|
60 | end
|
---|
61 |
|
---|
62 | if count==1, %we have scalar
|
---|
63 | sens=rawsens;
|
---|
64 | return;
|
---|
65 | else
|
---|
66 | %project the sensitivities from the partition onto the mesh
|
---|
67 | sens=rawsens(md.qmu.partition'+1); %md.qmu.partition was created to index "c" style
|
---|
68 | end
|
---|