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

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

CHG: cosmetics, removed multiple blank lines

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
11variablenamelength=length(variablename);
12
13%go through all response functions and find the one corresponding to the correct responsename
14responsefunctions=md.qmu.results.dresp_out;
15found=0;
16for i=1:length(responsefunctions),
17 if strcmpi(responsefunctions(i).descriptor,responsename),
18 found=i;
19 break;
20 end
21end
22if ~found,
23 error('importancefactors error message: could not find correct response function');
24end
25responsefunctions=responsefunctions(found);
26nfun=size(responsefunctions.var,1);
27
28%Now recover response to the correct design variable
29rawsens=zeros(0,1);
30count=0;
31for 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
37end
38
39%Now, if this was a distributed variable, the sensitivities need to be scaled by means of the input variable.
40if 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
56end
57
58if count==0,
59 error('sensitivities error message: either response does not exist, or sensitivities are empty');
60end
61
62if count==1, %we have scalar
63 sens=rawsens;
64 return;
65else
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
68end
Note: See TracBrowser for help on using the repository browser.