[13980] | 1 | Index: ../trunk-jpl/src/m/classes/autodiff.py
|
---|
| 2 | ===================================================================
|
---|
| 3 | --- ../trunk-jpl/src/m/classes/autodiff.py (revision 13861)
|
---|
| 4 | +++ ../trunk-jpl/src/m/classes/autodiff.py (revision 13862)
|
---|
| 5 | @@ -1,4 +1,6 @@
|
---|
| 6 | #module imports
|
---|
| 7 | +from dependent import *
|
---|
| 8 | +from independent import *
|
---|
| 9 | from fielddisplay import fielddisplay
|
---|
| 10 | from EnumDefinitions import *
|
---|
| 11 | from checkfield import *
|
---|
| 12 | @@ -13,32 +15,183 @@
|
---|
| 13 | """
|
---|
| 14 |
|
---|
| 15 | #properties
|
---|
| 16 | - def __init__(self):
|
---|
| 17 | - # {{{ Properties
|
---|
| 18 | - self.isautodiff = False
|
---|
| 19 | + def __init__(self,*args): # {{{
|
---|
| 20 | + self.isautodiff = False
|
---|
| 21 | + self.dependents = []
|
---|
| 22 | + self.independents = []
|
---|
| 23 | + self.driver = 'fos_forward'
|
---|
| 24 |
|
---|
| 25 | - #set defaults
|
---|
| 26 | - self.setdefaultparameters()
|
---|
| 27 | + if not len(args):
|
---|
| 28 | + self.setdefaultparameters()
|
---|
| 29 | + else:
|
---|
| 30 | + raise RuntimeError("constructor not supported")
|
---|
| 31 | + # }}}
|
---|
| 32 |
|
---|
| 33 | - #}}}
|
---|
| 34 | - def __repr__(self):
|
---|
| 35 | - # {{{ Display
|
---|
| 36 | - string=' automatic differentiation parameters:'
|
---|
| 37 | - string="%s\n%s"%(string,fielddisplay(self,'isautodiff','indicates if the automatic differentiation is activated'))
|
---|
| 38 | - return string
|
---|
| 39 | - #}}}
|
---|
| 40 | - def setdefaultparameters(self):
|
---|
| 41 | - # {{{setdefaultparameters
|
---|
| 42 | + def __repr__(self): # {{{
|
---|
| 43 | + s =" automatic differentiation parameters:"
|
---|
| 44 | +
|
---|
| 45 | + s+="%s\n" % fielddisplay(self,'isautodiff',"indicates if the automatic differentiation is activated")
|
---|
| 46 | + s+="%s\n" % fielddisplay(self,'dependents',"list of dependent variables")
|
---|
| 47 | + s+="%s\n" % fielddisplay(self,'independents',"list of independent variables")
|
---|
| 48 | + s+="%s\n" % fielddisplay(self,'driver',"ADOLC driver ('fos_forward' or 'fov_forward'")
|
---|
| 49 | +
|
---|
| 50 | + return s
|
---|
| 51 | + # }}}
|
---|
| 52 | +
|
---|
| 53 | + def setdefaultparameters(self): # {{{
|
---|
| 54 | return self
|
---|
| 55 | - #}}}
|
---|
| 56 | + # }}}
|
---|
| 57 |
|
---|
| 58 | def checkconsistency(self,md,solution,analyses): # {{{
|
---|
| 59 | +
|
---|
| 60 | + #Early return
|
---|
| 61 | + if not self.isautodiff:
|
---|
| 62 | + return md
|
---|
| 63 | +
|
---|
| 64 | + #Driver value:
|
---|
| 65 | + md = checkfield(md,'autodiff.driver','values',['fos_forward','fov_forward','fov_forward_all','fos_reverse','fov_reverse','fov_reverse_all'])
|
---|
| 66 | +
|
---|
| 67 | + #go through our dependents and independents and check consistency:
|
---|
| 68 | + for dep in self.dependents:
|
---|
| 69 | + dep.checkconsistency(md,solution,analyses)
|
---|
| 70 | + for i,indep in enumerate(self.independents):
|
---|
| 71 | + indep.checkconsistency(md,i,solution,analyses,self.driver)
|
---|
| 72 | +
|
---|
| 73 | return md
|
---|
| 74 | # }}}
|
---|
| 75 |
|
---|
| 76 | def marshall(self,fid): # {{{
|
---|
| 77 | WriteData(fid,'object',self,'fieldname','isautodiff','format','Boolean')
|
---|
| 78 | - WriteData(fid,'data',False,'enum',AutodiffMassFluxSegmentsPresentEnum(),'format','Boolean');
|
---|
| 79 | - WriteData(fid,'data',False,'enum',AutodiffKeepEnum(),'format','Boolean');
|
---|
| 80 | + WriteData(fid,'object',self,'fieldname','driver','format','String')
|
---|
| 81 | +
|
---|
| 82 | + #early return
|
---|
| 83 | + if not self.isautodiff:
|
---|
| 84 | + WriteData(fid,'data',False,'enum',AutodiffMassFluxSegmentsPresentEnum(),'format','Boolean')
|
---|
| 85 | + WriteData(fid,'data',False,'enum',AutodiffKeepEnum(),'format','Boolean')
|
---|
| 86 | + return
|
---|
| 87 | +
|
---|
| 88 | + #process dependent variables {{{
|
---|
| 89 | + num_dependent_objects=len(self.dependents)
|
---|
| 90 | + WriteData(fid,'data',num_dependent_objects,'enum',AutodiffNumDependentObjectsEnum(),'format','Integer')
|
---|
| 91 | +
|
---|
| 92 | + if num_dependent_objects:
|
---|
| 93 | + names=numpy.zeros(num_dependent_objects)
|
---|
| 94 | + types=numpy.zeros(num_dependent_objects)
|
---|
| 95 | + indices=numpy.zeros(num_dependent_objects)
|
---|
| 96 | +
|
---|
| 97 | + for i,dep in enumerate(self.dependents):
|
---|
| 98 | + names[i]=StringToEnum(dep.name)[0]
|
---|
| 99 | + types[i]=dep.typetoscalar()
|
---|
| 100 | + indices[i]=dep.index
|
---|
| 101 | +
|
---|
| 102 | + WriteData(fid,'data',names,'enum',AutodiffDependentObjectNamesEnum(),'format','IntMat','mattype',3)
|
---|
| 103 | + WriteData(fid,'data',types,'enum',AutodiffDependentObjectTypesEnum(),'format','IntMat','mattype',3)
|
---|
| 104 | + WriteData(fid,'data',indices,'enum',AutodiffDependentObjectIndicesEnum(),'format','IntMat','mattype',3)
|
---|
| 105 | + #}}}
|
---|
| 106 | +
|
---|
| 107 | + #process independent variables {{{
|
---|
| 108 | + num_independent_objects=len(self.independents)
|
---|
| 109 | + WriteData(fid,'data',num_independent_objects,'enum',AutodiffNumIndependentObjectsEnum(),'format','Integer')
|
---|
| 110 | +
|
---|
| 111 | + if num_independent_objects:
|
---|
| 112 | + names=numpy.zeros(num_independent_objects)
|
---|
| 113 | + types=numpy.zeros(num_independent_objects)
|
---|
| 114 | +
|
---|
| 115 | + for i,indep in enumerate(self.independents):
|
---|
| 116 | + names[i]=StringToEnum(indep.name)[0]
|
---|
| 117 | + types[i]=indep.typetoscalar()
|
---|
| 118 | +
|
---|
| 119 | + WriteData(fid,'data',names,'enum',AutodiffIndependentObjectNamesEnum(),'format','IntMat','mattype',3)
|
---|
| 120 | + WriteData(fid,'data',types,'enum',AutodiffIndependentObjectTypesEnum(),'format','IntMat','mattype',3)
|
---|
| 121 | + #}}}
|
---|
| 122 | +
|
---|
| 123 | + #if driver is fos_forward, build index: {{{
|
---|
| 124 | + if strcmpi(self.driver,'fos_forward'):
|
---|
| 125 | + index=0
|
---|
| 126 | +
|
---|
| 127 | + for indep in self.independents:
|
---|
| 128 | + if not isnan(indep.fos_forward_index):
|
---|
| 129 | + index+=indep.fos_forward_index
|
---|
| 130 | + break
|
---|
| 131 | + else:
|
---|
| 132 | + if strcmpi(indep.type,'scalar'):
|
---|
| 133 | + index+=1
|
---|
| 134 | + else:
|
---|
| 135 | + index+=indep.nods
|
---|
| 136 | +
|
---|
| 137 | + index-=1 #get c-index numbering going
|
---|
| 138 | + WriteData(fid,'data',index,'enum',AutodiffFosForwardIndexEnum(),'format','Integer')
|
---|
| 139 | + #}}}
|
---|
| 140 | +
|
---|
| 141 | + #if driver is fos_reverse, build index: {{{
|
---|
| 142 | + if strcmpi(self.driver,'fos_reverse'):
|
---|
| 143 | + index=0
|
---|
| 144 | +
|
---|
| 145 | + for dep in self.dependents:
|
---|
| 146 | + if not isnan(dep.fos_reverse_index):
|
---|
| 147 | + index+=dep.fos_reverse_index
|
---|
| 148 | + break
|
---|
| 149 | + else:
|
---|
| 150 | + if strcmpi(dep.type,'scalar'):
|
---|
| 151 | + index+=1
|
---|
| 152 | + else:
|
---|
| 153 | + index+=dep.nods
|
---|
| 154 | +
|
---|
| 155 | + index-=1 #get c-index numbering going
|
---|
| 156 | + WriteData(fid,'data',index,'enum',AutodiffFosReverseIndexEnum(),'format','Integer')
|
---|
| 157 | + end
|
---|
| 158 | + #}}}
|
---|
| 159 | +
|
---|
| 160 | + #if driver is fov_forward, build indices: {{{
|
---|
| 161 | + if strcmpi(self.driver,'fov_forward'):
|
---|
| 162 | + indices=0
|
---|
| 163 | +
|
---|
| 164 | + for indep in self.independents:
|
---|
| 165 | + if indep.fos_forward_index:
|
---|
| 166 | + indices+=indep.fov_forward_indices
|
---|
| 167 | + break
|
---|
| 168 | + else:
|
---|
| 169 | + if strcmpi(indep.type,'scalar'):
|
---|
| 170 | + indices+=1
|
---|
| 171 | + else:
|
---|
| 172 | + indices+=indep.nods
|
---|
| 173 | +
|
---|
| 174 | + indices-=1 #get c-indices numbering going
|
---|
| 175 | + WriteData(fid,'data',indices,'enum',AutodiffFovForwardIndicesEnum(),'format','IntMat','mattype',3)
|
---|
| 176 | + end
|
---|
| 177 | + #}}}
|
---|
| 178 | +
|
---|
| 179 | + #deal with mass fluxes: {{{
|
---|
| 180 | + mass_flux_segments=[dep.segments for dep in self.dependents if strcmpi(dep.name,'MassFlux')]
|
---|
| 181 | +
|
---|
| 182 | + if mass_flux_segments:
|
---|
| 183 | + WriteData(fid,'data',mass_flux_segments,'enum',MassFluxSegmentsEnum(),'format','MatArray')
|
---|
| 184 | + flag=True
|
---|
| 185 | + else:
|
---|
| 186 | + flag=False
|
---|
| 187 | + WriteData(fid,'data',flag,'enum',AutodiffMassFluxSegmentsPresentEnum(),'format','Boolean')
|
---|
| 188 | + #}}}
|
---|
| 189 | +
|
---|
| 190 | + #deal with trace keep on: {{{
|
---|
| 191 | + keep=False
|
---|
| 192 | +
|
---|
| 193 | + #From ADOLC userdoc:
|
---|
| 194 | + # The optional integer argument keep of trace on determines whether the numerical values of all active variables are
|
---|
| 195 | + # recorded in a buffered temporary array or file called the taylor stack. This option takes effect if keep = 1 and
|
---|
| 196 | + # prepares the scene for an immediately following gradient evaluation by a call to a routine implementing the reverse
|
---|
| 197 | + # mode as described in the Section 4 and Section 5.
|
---|
| 198 | + #
|
---|
| 199 | +
|
---|
| 200 | + if len(self.driver)<=3:
|
---|
| 201 | + keep=False #there is no "_reverse" string within the driver string:
|
---|
| 202 | + else:
|
---|
| 203 | + if strncmpi(self.driver[3:],'_reverse',8):
|
---|
| 204 | + keep=True
|
---|
| 205 | + else:
|
---|
| 206 | + keep=False
|
---|
| 207 | + WriteData(fid,'data',keep,'enum',AutodiffKeepEnum(),'format','Boolean')
|
---|
| 208 | + #}}}
|
---|
| 209 | +
|
---|
| 210 | + return
|
---|
| 211 | # }}}
|
---|
| 212 |
|
---|
| 213 | Index: ../trunk-jpl/src/m/classes/autodiff.m
|
---|
| 214 | ===================================================================
|
---|
| 215 | --- ../trunk-jpl/src/m/classes/autodiff.m (revision 13861)
|
---|
| 216 | +++ ../trunk-jpl/src/m/classes/autodiff.m (revision 13862)
|
---|
| 217 | @@ -54,10 +54,10 @@
|
---|
| 218 | WriteData(fid,'object',obj,'fieldname','driver','format','String');
|
---|
| 219 |
|
---|
| 220 | %early return
|
---|
| 221 | - if ~obj.isautodiff,
|
---|
| 222 | - WriteData(fid,'data',false,'enum',AutodiffMassFluxSegmentsPresentEnum,'format','Boolean');
|
---|
| 223 | - WriteData(fid,'data',false,'enum',AutodiffKeepEnum,'format','Boolean');
|
---|
| 224 | - return;
|
---|
| 225 | + if ~obj.isautodiff,
|
---|
| 226 | + WriteData(fid,'data',false,'enum',AutodiffMassFluxSegmentsPresentEnum(),'format','Boolean');
|
---|
| 227 | + WriteData(fid,'data',false,'enum',AutodiffKeepEnum(),'format','Boolean');
|
---|
| 228 | + return;
|
---|
| 229 | end
|
---|
| 230 |
|
---|
| 231 | %process dependent variables {{{
|
---|
| 232 | @@ -117,7 +117,7 @@
|
---|
| 233 | end
|
---|
| 234 | end
|
---|
| 235 | index=index-1; %get c-index numbering going
|
---|
| 236 | - WriteData(fid,'data',index,'enum',AutodiffFosForwardIndexEnum(),'format','Integer');
|
---|
| 237 | + WriteData(fid,'data',index,'enum',AutodiffFosForwardIndexEnum(),'format','Integer');
|
---|
| 238 | end
|
---|
| 239 | %}}}
|
---|
| 240 | %if driver is fos_reverse, build index: {{{
|
---|
| 241 | @@ -138,7 +138,7 @@
|
---|
| 242 | end
|
---|
| 243 | end
|
---|
| 244 | index=index-1; %get c-index numbering going
|
---|
| 245 | - WriteData(fid,'data',index,'enum',AutodiffFosReverseIndexEnum(),'format','Integer');
|
---|
| 246 | + WriteData(fid,'data',index,'enum',AutodiffFosReverseIndexEnum(),'format','Integer');
|
---|
| 247 | end
|
---|
| 248 | %}}}
|
---|
| 249 | %if driver is fov_forward, build indices: {{{
|
---|
| 250 | @@ -159,8 +159,7 @@
|
---|
| 251 | end
|
---|
| 252 | end
|
---|
| 253 | indices=indices-1; %get c-indices numbering going
|
---|
| 254 | -
|
---|
| 255 | - WriteData(fid,'data',indices,'enum',AutodiffFovForwardIndicesEnum,'format','IntMat','mattype',3);
|
---|
| 256 | + WriteData(fid,'data',indices,'enum',AutodiffFovForwardIndicesEnum(),'format','IntMat','mattype',3);
|
---|
| 257 | end
|
---|
| 258 | %}}}
|
---|
| 259 | %deal with mass fluxes: {{{
|
---|
| 260 | @@ -172,12 +171,12 @@
|
---|
| 261 | end
|
---|
| 262 | end
|
---|
| 263 | if ~isempty(mass_flux_segments),
|
---|
| 264 | - WriteData(fid,'data',mass_flux_segments,'enum',MassFluxSegmentsEnum,'format','MatArray');
|
---|
| 265 | + WriteData(fid,'data',mass_flux_segments,'enum',MassFluxSegmentsEnum(),'format','MatArray');
|
---|
| 266 | flag=true;
|
---|
| 267 | - else
|
---|
| 268 | - flag=false;
|
---|
| 269 | + else
|
---|
| 270 | + flag=false;
|
---|
| 271 | end
|
---|
| 272 | - WriteData(fid,'data',flag,'enum',AutodiffMassFluxSegmentsPresentEnum,'format','Boolean');
|
---|
| 273 | + WriteData(fid,'data',flag,'enum',AutodiffMassFluxSegmentsPresentEnum(),'format','Boolean');
|
---|
| 274 | %}}}
|
---|
| 275 | %deal with trace keep on: {{{
|
---|
| 276 | keep=false;
|
---|
| 277 | @@ -198,7 +197,7 @@
|
---|
| 278 | keep=false;
|
---|
| 279 | end
|
---|
| 280 | end
|
---|
| 281 | - WriteData(fid,'data',keep,'enum',AutodiffKeepEnum,'format','Boolean');
|
---|
| 282 | + WriteData(fid,'data',keep,'enum',AutodiffKeepEnum(),'format','Boolean');
|
---|
| 283 | %}}}
|
---|
| 284 |
|
---|
| 285 | end % }}}
|
---|
| 286 | Index: ../trunk-jpl/src/m/classes/dependent.m
|
---|
| 287 | ===================================================================
|
---|
| 288 | --- ../trunk-jpl/src/m/classes/dependent.m (revision 13861)
|
---|
| 289 | +++ ../trunk-jpl/src/m/classes/dependent.m (revision 13862)
|
---|
| 290 | @@ -14,35 +14,34 @@
|
---|
| 291 | nods = 0;
|
---|
| 292 | end
|
---|
| 293 | methods
|
---|
| 294 | - function obj= dependent(varargin) % {{{
|
---|
| 295 | + function obj = dependent(varargin) % {{{
|
---|
| 296 |
|
---|
| 297 | - %use provided options to change fields
|
---|
| 298 | - options=pairoptions(varargin{:});
|
---|
| 299 | + %use provided options to change fields
|
---|
| 300 | + options=pairoptions(varargin{:});
|
---|
| 301 |
|
---|
| 302 | - obj.name=getfieldvalue(options,'name','');
|
---|
| 303 | - obj.type=getfieldvalue(options,'type','');
|
---|
| 304 | - obj.exp=getfieldvalue(options,'exp','');
|
---|
| 305 | - obj.segments=getfieldvalue(options,'segments',[]);
|
---|
| 306 | - obj.index=getfieldvalue(options,'index',-1);
|
---|
| 307 | - obj.nods=getfieldvalue(options,'nods',0);
|
---|
| 308 | + obj.name=getfieldvalue(options,'name','');
|
---|
| 309 | + obj.type=getfieldvalue(options,'type','');
|
---|
| 310 | + obj.exp=getfieldvalue(options,'exp','');
|
---|
| 311 | + obj.segments=getfieldvalue(options,'segments',[]);
|
---|
| 312 | + obj.index=getfieldvalue(options,'index',-1);
|
---|
| 313 | + obj.nods=getfieldvalue(options,'nods',0);
|
---|
| 314 |
|
---|
| 315 | - %if name is mass flux:
|
---|
| 316 | - if strcmpi(obj.name,'MassFlux'),
|
---|
| 317 | - %make sure that we supplied a file and that it exists!
|
---|
| 318 | - if exist(obj.exp)~=2,
|
---|
| 319 | - error('dependent checkconsistency: specified ''exp'' file does not exist!');
|
---|
| 320 | - end
|
---|
| 321 | - %process the file and retrieve segments
|
---|
| 322 | - mesh=getfieldvalue(options,'mesh');
|
---|
| 323 | - obj.segments=MeshProfileIntersection(mesh.elements,mesh.x,mesh.y,obj.exp);
|
---|
| 324 | - end
|
---|
| 325 | - end
|
---|
| 326 | - %}}}
|
---|
| 327 | + %if name is mass flux:
|
---|
| 328 | + if strcmpi(obj.name,'MassFlux'),
|
---|
| 329 | + %make sure that we supplied a file and that it exists!
|
---|
| 330 | + if exist(obj.exp)~=2,
|
---|
| 331 | + error('dependent checkconsistency: specified ''exp'' file does not exist!');
|
---|
| 332 | + end
|
---|
| 333 | + %process the file and retrieve segments
|
---|
| 334 | + mesh=getfieldvalue(options,'mesh');
|
---|
| 335 | + obj.segments=MeshProfileIntersection(mesh.elements,mesh.x,mesh.y,obj.exp);
|
---|
| 336 | + end
|
---|
| 337 | + end
|
---|
| 338 | + %}}}
|
---|
| 339 | function obj = setdefaultparameters(obj) % {{{
|
---|
| 340 | - %do nothing
|
---|
| 341 | + %do nothing
|
---|
| 342 | end % }}}
|
---|
| 343 | function md = checkconsistency(obj,md,solution,analyses) % {{{
|
---|
| 344 | - %do nothing for now
|
---|
| 345 | if strcmpi(obj.name,'MassFlux'),
|
---|
| 346 | if isempty(obj.segments),
|
---|
| 347 | error('dependent checkconsistency error: need segments to compute this dependent response');
|
---|
| 348 | @@ -56,14 +55,13 @@
|
---|
| 349 | error('cannot declare a dependent with a fos_reverse_index when the driver is not fos_reverse!');
|
---|
| 350 | end
|
---|
| 351 | if obj.nods==0,
|
---|
| 352 | - error('ependent checkconsistency error: nods should be set to the size of the independent variable');
|
---|
| 353 | + error('dependent checkconsistency error: nods should be set to the size of the independent variable');
|
---|
| 354 | end
|
---|
| 355 | -
|
---|
| 356 | end
|
---|
| 357 |
|
---|
| 358 | end % }}}
|
---|
| 359 | function disp(obj) % {{{
|
---|
| 360 | - disp(sprintf(' dependent variable :'));
|
---|
| 361 | + disp(sprintf(' dependent variable:'));
|
---|
| 362 |
|
---|
| 363 | fielddisplay(obj,'name','variable name (must match corresponding Enum)');
|
---|
| 364 | fielddisplay(obj,'type','type of variable (''vertex'' or ''scalar'')');
|
---|
| 365 | @@ -78,11 +76,11 @@
|
---|
| 366 |
|
---|
| 367 | end % }}}
|
---|
| 368 | function scalar=typetoscalar(obj) % {{{
|
---|
| 369 | - if strcmpi(obj.type,'scalar'),
|
---|
| 370 | - scalar=0;
|
---|
| 371 | - elseif strcmpi(obj.type,'vertex'),
|
---|
| 372 | - scalar=1;
|
---|
| 373 | - end
|
---|
| 374 | + if strcmpi(obj.type,'scalar'),
|
---|
| 375 | + scalar=0;
|
---|
| 376 | + elseif strcmpi(obj.type,'vertex'),
|
---|
| 377 | + scalar=1;
|
---|
| 378 | + end
|
---|
| 379 |
|
---|
| 380 | end % }}}
|
---|
| 381 | end
|
---|
| 382 | Index: ../trunk-jpl/src/m/classes/independent.py
|
---|
| 383 | ===================================================================
|
---|
| 384 | --- ../trunk-jpl/src/m/classes/independent.py (revision 0)
|
---|
| 385 | +++ ../trunk-jpl/src/m/classes/independent.py (revision 13862)
|
---|
| 386 | @@ -0,0 +1,75 @@
|
---|
| 387 | +from pairoptions import *
|
---|
| 388 | +from MatlabFuncs import *
|
---|
| 389 | +from EnumDefinitions import *
|
---|
| 390 | +from WriteData import *
|
---|
| 391 | +
|
---|
| 392 | +class independent(object):
|
---|
| 393 | + """
|
---|
| 394 | + INDEPENDENT class definition
|
---|
| 395 | +
|
---|
| 396 | + Usage:
|
---|
| 397 | + independent=independent();
|
---|
| 398 | + """
|
---|
| 399 | +
|
---|
| 400 | + def __init__(self,*args): # {{{
|
---|
| 401 | + self.name = ''
|
---|
| 402 | + self.type = ''
|
---|
| 403 | + self.fos_forward_index = float('NaN')
|
---|
| 404 | + self.fov_forward_indices = numpy.array([])
|
---|
| 405 | + self.nods = 0
|
---|
| 406 | +
|
---|
| 407 | + #set defaults
|
---|
| 408 | + self.setdefaultparameters()
|
---|
| 409 | +
|
---|
| 410 | + #use provided options to change fields
|
---|
| 411 | + options=pairoptions(*args)
|
---|
| 412 | +
|
---|
| 413 | + #OK get other fields
|
---|
| 414 | + self=options.AssignObjectFields(self)
|
---|
| 415 | + # }}}
|
---|
| 416 | +
|
---|
| 417 | + def setdefaultparameters(self): # {{{
|
---|
| 418 | + #do nothing
|
---|
| 419 | + return self
|
---|
| 420 | + # }}}
|
---|
| 421 | +
|
---|
| 422 | + def checkconsistency(self,md,i,solution,analyses,driver): # {{{
|
---|
| 423 | + if not isnan(self.fos_forward_index):
|
---|
| 424 | + if not strcmpi(driver,'fos_forward'):
|
---|
| 425 | + raise TypeError("cannot declare an independent with a fos_forward_index when the driver is not fos_forward!")
|
---|
| 426 | + if self.nods==0:
|
---|
| 427 | + raise TypeError("independent checkconsistency error: nods should be set to the size of the independent variable")
|
---|
| 428 | +
|
---|
| 429 | + if self.fov_forward_indices:
|
---|
| 430 | + if not strcmpi(driver,'fov_forward'):
|
---|
| 431 | + raise TypeError("cannot declare an independent with fov_forward_indices when the driver is not fov_forward!")
|
---|
| 432 | + if self.nods==0:
|
---|
| 433 | + raise TypeError("independent checkconsistency error: nods should be set to the size of the independent variable")
|
---|
| 434 | + end
|
---|
| 435 | + md = checkfield(md,"autodiff.independents[%d].fov_forward_indices" % i,'>=',1,'<=',self.nods,'size',[float('NaN'),1])
|
---|
| 436 | +
|
---|
| 437 | + return md
|
---|
| 438 | + # }}}
|
---|
| 439 | +
|
---|
| 440 | + def __repr__(self): # {{{
|
---|
| 441 | + s =" independent variable:\n"
|
---|
| 442 | +
|
---|
| 443 | + s+="%s\n" % fielddisplay(self,'name',"variable name (must match corresponding Enum)")
|
---|
| 444 | + s+="%s\n" % fielddisplay(self,'type',"type of variable ('vertex' or 'scalar')")
|
---|
| 445 | + if not isnan(self.fos_forward_index):
|
---|
| 446 | + s+="%s\n" % fielddisplay(self,'fos_forward_index',"index for fos_foward driver of ADOLC")
|
---|
| 447 | + if numpy.any(numpy.logical_not(numpy.isnan(self.fov_forward_indices))):
|
---|
| 448 | + s+="%s\n" % fielddisplay(self,'fov_forward_indices',"indices for fov_foward driver of ADOLC")
|
---|
| 449 | +
|
---|
| 450 | + return s
|
---|
| 451 | + # }}}
|
---|
| 452 | +
|
---|
| 453 | + def typetoscalar(self): # {{{
|
---|
| 454 | + if strcmpi(self.type,'scalar'):
|
---|
| 455 | + scalar=0
|
---|
| 456 | + elif strcmpi(self.type,'vertex'):
|
---|
| 457 | + scalar=1
|
---|
| 458 | +
|
---|
| 459 | + return scalar
|
---|
| 460 | + # }}}
|
---|
| 461 | +
|
---|
| 462 | Index: ../trunk-jpl/src/m/classes/independent.m
|
---|
| 463 | ===================================================================
|
---|
| 464 | --- ../trunk-jpl/src/m/classes/independent.m (revision 13861)
|
---|
| 465 | +++ ../trunk-jpl/src/m/classes/independent.m (revision 13862)
|
---|
| 466 | @@ -12,22 +12,21 @@
|
---|
| 467 | nods = 0;
|
---|
| 468 | end
|
---|
| 469 | methods
|
---|
| 470 | - function obj= independent(varargin) % {{{
|
---|
| 471 | + function obj = independent(varargin) % {{{
|
---|
| 472 |
|
---|
| 473 | - %use provided options to change fields
|
---|
| 474 | - options=pairoptions(varargin{:});
|
---|
| 475 | + %use provided options to change fields
|
---|
| 476 | + options=pairoptions(varargin{:});
|
---|
| 477 |
|
---|
| 478 | - %OK get other fields
|
---|
| 479 | - obj=AssignObjectFields(pairoptions(varargin{:}),obj);
|
---|
| 480 | + %OK get other fields
|
---|
| 481 | + obj=AssignObjectFields(pairoptions(varargin{:}),obj);
|
---|
| 482 |
|
---|
| 483 | - end
|
---|
| 484 | - %}}}
|
---|
| 485 | + end
|
---|
| 486 | + %}}}
|
---|
| 487 | function obj = setdefaultparameters(obj) % {{{
|
---|
| 488 | %do nothing
|
---|
| 489 |
|
---|
| 490 | end % }}}
|
---|
| 491 | function md = checkconsistency(obj,md,i,solution,analyses,driver) % {{{
|
---|
| 492 | - %do nothing for now
|
---|
| 493 | if ~isnan(obj.fos_forward_index),
|
---|
| 494 | if ~strcmpi(driver,'fos_forward'),
|
---|
| 495 | error('cannot declare an independent with a fos_forward_index when the driver is not fos_forward!');
|
---|
| 496 | @@ -41,7 +40,6 @@
|
---|
| 497 | if ~strcmpi(driver,'fov_forward'),
|
---|
| 498 | error('cannot declare an independent with fov_forward_indices when the driver is not fov_forward!');
|
---|
| 499 | end
|
---|
| 500 | -
|
---|
| 501 | if obj.nods==0,
|
---|
| 502 | error('independent checkconsistency error: nods should be set to the size of the independent variable');
|
---|
| 503 | end
|
---|
| 504 | @@ -50,7 +48,7 @@
|
---|
| 505 |
|
---|
| 506 | end % }}}
|
---|
| 507 | function disp(obj) % {{{
|
---|
| 508 | - disp(sprintf(' independent variable :'));
|
---|
| 509 | + disp(sprintf(' independent variable:'));
|
---|
| 510 |
|
---|
| 511 | fielddisplay(obj,'name','variable name (must match corresponding Enum)');
|
---|
| 512 | fielddisplay(obj,'type','type of variable (''vertex'' or ''scalar'')');
|
---|
| 513 | Index: ../trunk-jpl/src/m/classes/dependent.py
|
---|
| 514 | ===================================================================
|
---|
| 515 | --- ../trunk-jpl/src/m/classes/dependent.py (revision 0)
|
---|
| 516 | +++ ../trunk-jpl/src/m/classes/dependent.py (revision 13862)
|
---|
| 517 | @@ -0,0 +1,94 @@
|
---|
| 518 | +import os.path
|
---|
| 519 | +from pairoptions import *
|
---|
| 520 | +from MatlabFuncs import *
|
---|
| 521 | +from EnumDefinitions import *
|
---|
| 522 | +from WriteData import *
|
---|
| 523 | +#from MeshProfileIntersection import *
|
---|
| 524 | +
|
---|
| 525 | +class dependent(object):
|
---|
| 526 | + """
|
---|
| 527 | + DEPENDENT class definition
|
---|
| 528 | +
|
---|
| 529 | + Usage:
|
---|
| 530 | + dependent=dependent();
|
---|
| 531 | + """
|
---|
| 532 | +
|
---|
| 533 | + def __init__(self,*args): # {{{
|
---|
| 534 | + self.name = ''
|
---|
| 535 | + self.type = ''
|
---|
| 536 | + self.fos_reverse_index = float('NaN')
|
---|
| 537 | + self.exp = ''
|
---|
| 538 | + self.segments = []
|
---|
| 539 | + self.index = -1
|
---|
| 540 | + self.nods = 0
|
---|
| 541 | +
|
---|
| 542 | + #set defaults
|
---|
| 543 | + self.setdefaultparameters()
|
---|
| 544 | +
|
---|
| 545 | + #use provided options to change fields
|
---|
| 546 | + options=pairoptions(*args)
|
---|
| 547 | +
|
---|
| 548 | + self.name=options.getfieldvalue('name','')
|
---|
| 549 | + self.type=options.getfieldvalue('type','')
|
---|
| 550 | + self.exp=options.getfieldvalue('exp','')
|
---|
| 551 | + self.segments=options.getfieldvalue('segments',[])
|
---|
| 552 | + self.index=options.getfieldvalue('index',-1)
|
---|
| 553 | + self.nods=options.getfieldvalue('nods',0)
|
---|
| 554 | +
|
---|
| 555 | + #if name is mass flux:
|
---|
| 556 | + if strcmpi(self.name,'MassFlux'):
|
---|
| 557 | + #make sure that we supplied a file and that it exists!
|
---|
| 558 | + if not os.path.exists(self.exp):
|
---|
| 559 | + raise IOError("dependent checkconsistency: specified 'exp' file does not exist!")
|
---|
| 560 | + #process the file and retrieve segments
|
---|
| 561 | + mesh=options.getfieldvalue('mesh')
|
---|
| 562 | + raise RuntimeError("MeshProfileIntersection is not complete.")
|
---|
| 563 | + self.segments=MeshProfileIntersection(mesh.elements,mesh.x,mesh.y,self.exp)
|
---|
| 564 | + # }}}
|
---|
| 565 | +
|
---|
| 566 | + def setdefaultparameters(self): # {{{
|
---|
| 567 | + #do nothing
|
---|
| 568 | + return self
|
---|
| 569 | + # }}}
|
---|
| 570 | +
|
---|
| 571 | + def checkconsistency(self,md,solution,analyses): # {{{
|
---|
| 572 | + if strcmpi(self.name,'MassFlux'):
|
---|
| 573 | + if not self.segments:
|
---|
| 574 | + raise RuntimeError("dependent checkconsistency error: need segments to compute this dependent response")
|
---|
| 575 | + if self.index<0:
|
---|
| 576 | + raise RuntimeError("dependent checkconsistency error: index for segments should be >=0")
|
---|
| 577 | +
|
---|
| 578 | + if not isnan(self.fos_reverse_index):
|
---|
| 579 | + if not strcmpi(driver,'fos_reverse'):
|
---|
| 580 | + raise TypeError("cannot declare a dependent with a fos_reverse_index when the driver is not fos_reverse!")
|
---|
| 581 | + if self.nods==0:
|
---|
| 582 | + raise TypeError("dependent checkconsistency error: nods should be set to the size of the independent variable")
|
---|
| 583 | +
|
---|
| 584 | + return md
|
---|
| 585 | + # }}}
|
---|
| 586 | +
|
---|
| 587 | + def __repr__(self): # {{{
|
---|
| 588 | + s =" dependent variable:\n"
|
---|
| 589 | +
|
---|
| 590 | + s+="%s\n" % fielddisplay(self,'name',"variable name (must match corresponding Enum)")
|
---|
| 591 | + s+="%s\n" % fielddisplay(self,'type',"type of variable ('vertex' or 'scalar')")
|
---|
| 592 | +
|
---|
| 593 | + if not isnan(self.fos_reverse_index):
|
---|
| 594 | + s+="%s\n" % fielddisplay(self,'fos_reverse_index',"index for fos_reverse driver of ADOLC")
|
---|
| 595 | + end
|
---|
| 596 | + if self.exp:
|
---|
| 597 | + s+="%s\n" % fielddisplay(self,'exp',"file needed to compute dependent variable")
|
---|
| 598 | + s+="%s\n" % fielddisplay(self,'segments',"mass flux segments")
|
---|
| 599 | +
|
---|
| 600 | + return s
|
---|
| 601 | + # }}}
|
---|
| 602 | +
|
---|
| 603 | + def typetoscalar(self): # {{{
|
---|
| 604 | + if strcmpi(self.type,'scalar'):
|
---|
| 605 | + scalar=0
|
---|
| 606 | + elif strcmpi(self.type,'vertex'):
|
---|
| 607 | + scalar=1
|
---|
| 608 | +
|
---|
| 609 | + return scalar
|
---|
| 610 | + # }}}
|
---|
| 611 | +
|
---|