source: issm/trunk-jpl/src/m/qmu/sensitivities.m@ 13241

Last change on this file since 13241 was 13241, checked in by Mathieu Morlighem, 12 years ago

CHG: getting rid of EnumToModelField, which has not been working for almost a year

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