- Timestamp:
- 05/12/23 23:08:06 (23 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/branches/trunk-larour-SLPS2022/src/m/classes/qmu/continuous_design.m
r24820 r27750 38 38 scale_type='none'; 39 39 scale = 1.; 40 partition = []; 41 nsteps = 0; 40 42 end 41 43 42 44 methods 43 function [cdv]=continuous_design(varargin) 44 45 switch nargin 46 47 % create a default object 48 49 case 0 50 51 % copy the object 52 53 case 1 54 if isa(varargin{1},'continuous_design') 55 cdv=varargin{1}; 56 else 57 error('Object ''%s'' is a ''%s'' class object, not ''%s''.',... 58 inputname(1),class(varargin{1}),'continuous_design'); 59 end 60 61 % create the object from the input 62 63 otherwise 64 asizec=num2cell(array_size(varargin{1:min(nargin,6)})); 65 cdv(asizec{:})=continuous_design; 66 clear asizec 67 68 if ischar(varargin{1}) 69 varargin{1}=cellstr(varargin{1}); 70 end 71 for i=1:numel(cdv) 72 if (numel(varargin{1}) > 1) 73 cdv(i).descriptor=varargin{1}{i}; 74 else 75 cdv(i).descriptor=[char(varargin{1}) string_dim(cdv,i,'vector')]; 76 end 77 end 78 79 if (nargin >= 2) 80 for i=1:numel(cdv) 81 if (numel(varargin{2}) > 1) 82 cdv(i).initpt =varargin{2}(i); 83 else 84 cdv(i).initpt =varargin{2}; 85 end 86 end 87 if (nargin >= 3) 88 for i=1:numel(cdv) 89 if (numel(varargin{3}) > 1) 90 cdv(i).lower =varargin{3}(i); 91 else 92 cdv(i).lower =varargin{3}; 93 end 94 end 95 if (nargin >= 4) 96 for i=1:numel(cdv) 97 if (numel(varargin{4}) > 1) 98 cdv(i).upper =varargin{4}(i); 99 else 100 cdv(i).upper =varargin{4}; 101 end 102 end 103 if (nargin >= 5) 104 if ischar(varargin{5}) 105 varargin{5}=cellstr(varargin{5}); 106 end 107 for i=1:numel(cdv) 108 if (numel(varargin{5}) > 1) 109 cdv(i).scale_type=varargin{5}{i}; 110 else 111 cdv(i).scale_type=char(varargin{5}); 112 end 113 end 114 if (nargin >= 6) 115 for i=1:numel(cdv) 116 if (numel(varargin{6}) > 1) 117 cdv(i).scale =varargin{6}(i); 118 else 119 cdv(i).scale =varargin{6}; 120 end 121 end 122 if (nargin > 6) 123 warning('continuous_design:extra_arg',... 124 'Extra arguments for object of class ''%s''.',... 125 class(cdv)); 126 end 127 end 128 end 129 end 130 end 131 end 132 end 133 134 end 135 136 function []=disp(cdv) 137 138 % display the object 139 140 disp(sprintf('\n')); 141 for i=1:numel(cdv) 142 disp(sprintf('class ''%s'' object ''%s%s'' = \n',... 143 class(cdv),inputname(1),string_dim(cdv,i))); 144 disp(sprintf(' descriptor: ''%s''' ,cdv(i).descriptor)); 145 disp(sprintf(' initpt: %g' ,cdv(i).initpt)); 146 disp(sprintf(' lower: %g' ,cdv(i).lower)); 147 disp(sprintf(' upper: %g' ,cdv(i).upper)); 148 disp(sprintf(' scale_type: ''%s''' ,cdv(i).scale_type)); 149 disp(sprintf(' scale: %g\n' ,cdv(i).scale)); 150 end 151 152 end 153 154 function [desc] =prop_desc(cdv,dstr) 45 function self=continuous_design(varargin) % {{{ 46 47 %recover options: 48 options=pairoptions(varargin{:}); 49 50 %initialize fields: 51 self.descriptor=getfieldvalue(options,'descriptor'); 52 self.initpt=getfieldvalue(options,'initpt'); 53 self.lower=getfieldvalue(options,'lower'); 54 self.upper=getfieldvalue(options,'upper'); 55 self.scale_type=getfieldvalue(options,'scale_type','none'); 56 self.scale=getfieldvalue(options,'scale',1.); 57 58 %if the variable is scaled, a partition vector should have been 59 %supplied, and that partition vector should have as many partitions 60 %as the upper and lower vectors: 61 if self.isscaled() | self.isdistributed(), 62 self.partition=getfieldvalue(options,'partition'); 63 self.nsteps=getfieldvalue(options,'nsteps',1); 64 npart=qmupart2npart(self.partition); 65 if npart~=size(self.upper,1), 66 error(['continuous_design constructor: for the scaled variable ' self.descriptor ' the row size of the upper field should be identical to the number of partitions']); 67 end 68 if npart~=size(self.lower,1), 69 error(['continuous_design constructor: for the scaled variable ' self.descriptor ' the row size of the lower field should be identical to the number of partitions']); 70 end 71 if self.nsteps~=size(self.upper,2), 72 error(['continuous_design constructor: for the scaled variable ' self.descriptor ' the col size of the upper field should be identical to the number of time steps']); 73 end 74 if self.nsteps~=size(self.lower,2), 75 error(['continuous_design constructor: for the scaled variable ' self.descriptor ' the col size of the lower field should be identical to the number of time steps']); 76 end 77 78 end 79 80 81 82 end % }}} 83 function disp(self) % {{{ 84 85 disp(sprintf(' continuous design variable: ')); 86 fielddisplay(self,'descriptor','name tag'); 87 fielddisplay(self,'initpt','initial point'); 88 fielddisplay(self,'lower','lower values'); 89 fielddisplay(self,'upper','upper values'); 90 fielddisplay(self,'scale_type','scale type'); 91 fielddisplay(self,'scale','scale'); 92 93 end % }}} 94 function md=checkconsistency(self,md,solution,analyses) % {{{ 95 96 md = checkfield(md,'field',self.upper,'fieldname','continuous_design.upper','NaN',1,'Inf',1,'>=',0); 97 md = checkfield(md,'field',self.lower,'fieldname','continuous_design.lower','NaN',1,'Inf',1,'>=',0); 98 if self.isscaled(), 99 if isempty(self.partition), 100 error('continuous_design is a scaled variable, but it''s missing a partition vector'); 101 end 102 %better have a partition vector that has as many partitions as loer's size: 103 if size(self.lower,1)~=partition_npart(self.partition), 104 error('continuous_design error message: row size of lower and partition size should be identical'); 105 end 106 if size(self.upper,1)~=partition_npart(self.partition), 107 error('continuous_design error message: row size of upper and partition size should be identical'); 108 end 109 %we need as steps in lower and upper as there are time steps: 110 if size(self.lower,2)~=self.nsteps, 111 error('continuous_design error message: col size of lower and number of time steps should be identical'); 112 end 113 if size(self.upper,2)~=self.nsteps, 114 error('continuous_design error message: col size of upper and number of time steps should be identical'); 115 end 116 117 md = checkfield(md,'field',self.partition,'fieldname','continuous_design.partition','NaN',1,'Inf',1,'>=',-1,'numel',[md.mesh.numberofvertices,md.mesh.numberofelements]); 118 if size(self.partition,2)>1, 119 error('continuous_design error message: partition should be a column vector'); 120 end 121 partcheck=unique(self.partition); 122 partmin=min(partcheck); 123 partmax=max(partcheck); 124 if partmax<-1, 125 error('continuous_design error message: partition vector''s min value should be -1 (for no partition), or start at 0'); 126 end 127 nmax=max(md.mesh.numberofelements,md.mesh.numberofvertices); 128 if partmax>nmax, 129 error('continuous_design error message: partition vector''s values cannot go over the number of vertices or elements'); 130 end 131 end 132 end % }}} 133 function [desc] =prop_desc(cdv,dstr) % {{{ 155 134 desc=cell(1,numel(cdv)); 156 135 for i=1:numel(cdv) … … 166 145 end 167 146 desc=allempty(desc); 168 end 169 function [initpt]=prop_initpt(cdv) 147 end % }}} 148 function [initpt]=prop_initpt(cdv) % {{{ 170 149 initpt=zeros(1,numel(cdv)); 171 150 for i=1:numel(cdv) … … 173 152 end 174 153 initpt=allequal(initpt,0.); 175 end 176 function [lower] =prop_lower(cdv) 154 end % }}} 155 function [lower] =prop_lower(cdv) % {{{ 177 156 lower=zeros(1,numel(cdv)); 178 157 for i=1:numel(cdv) … … 180 159 end 181 160 lower=allequal(lower,-Inf); 182 end 183 function [upper] =prop_upper(cdv) 161 end % }}} 162 function [upper] =prop_upper(cdv) % {{{ 184 163 upper=zeros(1,numel(cdv)); 185 164 for i=1:numel(cdv) … … 187 166 end 188 167 upper=allequal(upper, Inf); 189 end 190 function [mean] =prop_mean(cdv) 168 end % }}} 169 function [mean] =prop_mean(cdv) % {{{ 191 170 mean=[]; 192 end 193 function [stddev]=prop_stddev(cdv) 171 end % }}} 172 function [stddev]=prop_stddev(cdv) % {{{ 194 173 stddev=[]; 195 end 196 function [initst]=prop_initst(cdv) 174 end % }}} 175 function [initst]=prop_initst(cdv) % {{{ 197 176 initst=[]; 198 end 199 function [stype] =prop_stype(cdv) 177 end % }}} 178 function [stype] =prop_stype(cdv) % {{{ 200 179 stype=cell(1,numel(cdv)); 201 180 for i=1:numel(cdv) … … 203 182 end 204 183 stype=allequal(stype,'none'); 205 end 206 function [scale] =prop_scale(cdv) 184 end % }}} 185 function [scale] =prop_scale(cdv) % {{{ 207 186 scale=zeros(1,numel(cdv)); 208 187 for i=1:numel(cdv) … … 210 189 end 211 190 scale=allequal(scale,1.); 212 end 191 end % }}} 213 192 function [abscissas] =prop_abscissas(hbu) % {{{ 214 193 abscissas=[]; … … 220 199 pairs_per_variable=[]; 221 200 end % }}} 222 function checkconsistency(self,md,solution,analyses) % {{{ 223 end % }}} 224 201 %new methods: 202 function distributed=isdistributed(self) % {{{ 203 if strncmp(self.descriptor,'distributed_',12), 204 distributed=1; 205 else 206 distributed=0; 207 end 208 end % }}} 209 function scaled=isscaled(self) % {{{ 210 if strncmp(self.descriptor,'scaled_',7), 211 scaled=1; 212 else 213 scaled=0; 214 end 215 end % }}} 225 216 end 226 217 227 218 methods (Static) 228 function []=dakota_write(fidi,dvar) 229 219 function []=dakota_write(fidi,dvar) % {{{ 230 220 % collect only the variables of the appropriate class 231 232 221 cdv=struc_class(dvar,'continuous_design'); 233 234 222 % write variables 235 236 223 vlist_write(fidi,'continuous_design','cdv',cdv); 237 end 224 end % }}} 238 225 end 239 226 end
Note:
See TracChangeset
for help on using the changeset viewer.