| 1 | function factors=importancefactors(md,variablename,responsename)
|
|---|
| 2 | %IMPORTANCEFACTORS - compute importance factors for a certain variable and response.
|
|---|
| 3 | %
|
|---|
| 4 | % Usage:
|
|---|
| 5 | % factors=importancefactors(md,variablename,responsename)
|
|---|
| 6 | %
|
|---|
| 7 | %
|
|---|
| 8 | % Example: factors=importancefactors(md,'drag','max_vel');
|
|---|
| 9 | %
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 | variablenamelength=length(variablename);
|
|---|
| 13 |
|
|---|
| 14 | %go through all response functions and find the one corresponding to the correct responsename
|
|---|
| 15 | responsefunctions=md.dakotaresults.dresp_out;
|
|---|
| 16 | found=0;
|
|---|
| 17 | for i=1:length(responsefunctions),
|
|---|
| 18 | if strcmpi(responsefunctions(i).descriptor,responsename),
|
|---|
| 19 | found=i;
|
|---|
| 20 | break;
|
|---|
| 21 | end
|
|---|
| 22 | end
|
|---|
| 23 | if ~found,
|
|---|
| 24 | error('importancefactors error message: could not find correct response function');
|
|---|
| 25 | end
|
|---|
| 26 | responsefunctions=responsefunctions(found);
|
|---|
| 27 | nfun=size(responsefunctions.var,1);
|
|---|
| 28 |
|
|---|
| 29 | %Now recover response to the correct design variable
|
|---|
| 30 | importancefactors=zeros(1,0);
|
|---|
| 31 | count=0;
|
|---|
| 32 | for i=1:nfun,
|
|---|
| 33 | desvar=responsefunctions.var{i};
|
|---|
| 34 | if strncmpi(desvar,variablename,variablenamelength),
|
|---|
| 35 | importancefactors(end+1)=responsefunctions.impfac(i);
|
|---|
| 36 | count=count+1;
|
|---|
| 37 | end
|
|---|
| 38 | end
|
|---|
| 39 |
|
|---|
| 40 | if count==0,
|
|---|
| 41 | error('importancefactors error message: could not find to response functions with corresponding design variable');
|
|---|
| 42 | end
|
|---|
| 43 |
|
|---|
| 44 | if count==1, %we have scalar
|
|---|
| 45 | factors=importancefactors;
|
|---|
| 46 | return;
|
|---|
| 47 | else
|
|---|
| 48 | %Ok, get partitioning, unless already supplied
|
|---|
| 49 | if isempty(md.part),
|
|---|
| 50 | [epart npart]=MeshPartition(md,md.npart);
|
|---|
| 51 | else
|
|---|
| 52 | npart=md.part+1;
|
|---|
| 53 | end
|
|---|
| 54 |
|
|---|
| 55 | %distribute importance factor
|
|---|
| 56 | factors=importancefactors(npart)';
|
|---|
| 57 | end
|
|---|
| 58 |
|
|---|
| 59 | if numel(factors)==md.numberofgrids,
|
|---|
| 60 | %get areas for each vertex.
|
|---|
| 61 | aire=GetAreas(md.elements,md.x,md.y);
|
|---|
| 62 | num_elements_by_node=md.nodeconnectivity(:,end);
|
|---|
| 63 | grid_aire=zeros(md.numberofgrids,1);
|
|---|
| 64 | for i=1:md.numberofgrids,
|
|---|
| 65 | for j=1:num_elements_by_node(i),
|
|---|
| 66 | grid_aire(i)=grid_aire(i)+aire(md.nodeconnectivity(i,j));
|
|---|
| 67 | end
|
|---|
| 68 | end
|
|---|
| 69 | factors=factors./grid_aire;
|
|---|
| 70 | end
|
|---|