Changeset 13862
- Timestamp:
- 10/31/12 15:42:39 (12 years ago)
- Location:
- issm/trunk-jpl/src/m/classes
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/classes/autodiff.m
r13646 r13862 55 55 56 56 %early return 57 if ~obj.isautodiff, 58 WriteData(fid,'data',false,'enum',AutodiffMassFluxSegmentsPresentEnum ,'format','Boolean');59 WriteData(fid,'data',false,'enum',AutodiffKeepEnum ,'format','Boolean');60 return; 57 if ~obj.isautodiff, 58 WriteData(fid,'data',false,'enum',AutodiffMassFluxSegmentsPresentEnum(),'format','Boolean'); 59 WriteData(fid,'data',false,'enum',AutodiffKeepEnum(),'format','Boolean'); 60 return; 61 61 end 62 62 … … 118 118 end 119 119 index=index-1; %get c-index numbering going 120 WriteData(fid,'data',index,'enum',AutodiffFosForwardIndexEnum(),'format','Integer'); 120 WriteData(fid,'data',index,'enum',AutodiffFosForwardIndexEnum(),'format','Integer'); 121 121 end 122 122 %}}} … … 139 139 end 140 140 index=index-1; %get c-index numbering going 141 WriteData(fid,'data',index,'enum',AutodiffFosReverseIndexEnum(),'format','Integer'); 141 WriteData(fid,'data',index,'enum',AutodiffFosReverseIndexEnum(),'format','Integer'); 142 142 end 143 143 %}}} … … 160 160 end 161 161 indices=indices-1; %get c-indices numbering going 162 163 WriteData(fid,'data',indices,'enum',AutodiffFovForwardIndicesEnum,'format','IntMat','mattype',3); 162 WriteData(fid,'data',indices,'enum',AutodiffFovForwardIndicesEnum(),'format','IntMat','mattype',3); 164 163 end 165 164 %}}} … … 173 172 end 174 173 if ~isempty(mass_flux_segments), 175 WriteData(fid,'data',mass_flux_segments,'enum',MassFluxSegmentsEnum ,'format','MatArray');174 WriteData(fid,'data',mass_flux_segments,'enum',MassFluxSegmentsEnum(),'format','MatArray'); 176 175 flag=true; 177 else 178 flag=false; 179 end 180 WriteData(fid,'data',flag,'enum',AutodiffMassFluxSegmentsPresentEnum ,'format','Boolean');176 else 177 flag=false; 178 end 179 WriteData(fid,'data',flag,'enum',AutodiffMassFluxSegmentsPresentEnum(),'format','Boolean'); 181 180 %}}} 182 181 %deal with trace keep on: {{{ … … 199 198 end 200 199 end 201 WriteData(fid,'data',keep,'enum',AutodiffKeepEnum ,'format','Boolean');200 WriteData(fid,'data',keep,'enum',AutodiffKeepEnum(),'format','Boolean'); 202 201 %}}} 203 202 -
issm/trunk-jpl/src/m/classes/autodiff.py
r13516 r13862 1 1 #module imports 2 from dependent import * 3 from independent import * 2 4 from fielddisplay import fielddisplay 3 5 from EnumDefinitions import * … … 14 16 15 17 #properties 16 def __init__(self): 17 # {{{ Properties 18 self.isautodiff = False 18 def __init__(self,*args): # {{{ 19 self.isautodiff = False 20 self.dependents = [] 21 self.independents = [] 22 self.driver = 'fos_forward' 19 23 20 #set defaults 21 self.setdefaultparameters() 24 if not len(args): 25 self.setdefaultparameters() 26 else: 27 raise RuntimeError("constructor not supported") 28 # }}} 22 29 23 #}}} 24 def __repr__(self): 25 # {{{ Display 26 string=' automatic differentiation parameters:' 27 string="%s\n%s"%(string,fielddisplay(self,'isautodiff','indicates if the automatic differentiation is activated')) 28 return string 29 #}}} 30 def setdefaultparameters(self): 31 # {{{setdefaultparameters 30 def __repr__(self): # {{{ 31 s =" automatic differentiation parameters:" 32 33 s+="%s\n" % fielddisplay(self,'isautodiff',"indicates if the automatic differentiation is activated") 34 s+="%s\n" % fielddisplay(self,'dependents',"list of dependent variables") 35 s+="%s\n" % fielddisplay(self,'independents',"list of independent variables") 36 s+="%s\n" % fielddisplay(self,'driver',"ADOLC driver ('fos_forward' or 'fov_forward'") 37 38 return s 39 # }}} 40 41 def setdefaultparameters(self): # {{{ 32 42 return self 33 # }}}43 # }}} 34 44 35 45 def checkconsistency(self,md,solution,analyses): # {{{ 46 47 #Early return 48 if not self.isautodiff: 49 return md 50 51 #Driver value: 52 md = checkfield(md,'autodiff.driver','values',['fos_forward','fov_forward','fov_forward_all','fos_reverse','fov_reverse','fov_reverse_all']) 53 54 #go through our dependents and independents and check consistency: 55 for dep in self.dependents: 56 dep.checkconsistency(md,solution,analyses) 57 for i,indep in enumerate(self.independents): 58 indep.checkconsistency(md,i,solution,analyses,self.driver) 59 36 60 return md 37 61 # }}} … … 39 63 def marshall(self,fid): # {{{ 40 64 WriteData(fid,'object',self,'fieldname','isautodiff','format','Boolean') 41 WriteData(fid,'data',False,'enum',AutodiffMassFluxSegmentsPresentEnum(),'format','Boolean'); 42 WriteData(fid,'data',False,'enum',AutodiffKeepEnum(),'format','Boolean'); 65 WriteData(fid,'object',self,'fieldname','driver','format','String') 66 67 #early return 68 if not self.isautodiff: 69 WriteData(fid,'data',False,'enum',AutodiffMassFluxSegmentsPresentEnum(),'format','Boolean') 70 WriteData(fid,'data',False,'enum',AutodiffKeepEnum(),'format','Boolean') 71 return 72 73 #process dependent variables {{{ 74 num_dependent_objects=len(self.dependents) 75 WriteData(fid,'data',num_dependent_objects,'enum',AutodiffNumDependentObjectsEnum(),'format','Integer') 76 77 if num_dependent_objects: 78 names=numpy.zeros(num_dependent_objects) 79 types=numpy.zeros(num_dependent_objects) 80 indices=numpy.zeros(num_dependent_objects) 81 82 for i,dep in enumerate(self.dependents): 83 names[i]=StringToEnum(dep.name)[0] 84 types[i]=dep.typetoscalar() 85 indices[i]=dep.index 86 87 WriteData(fid,'data',names,'enum',AutodiffDependentObjectNamesEnum(),'format','IntMat','mattype',3) 88 WriteData(fid,'data',types,'enum',AutodiffDependentObjectTypesEnum(),'format','IntMat','mattype',3) 89 WriteData(fid,'data',indices,'enum',AutodiffDependentObjectIndicesEnum(),'format','IntMat','mattype',3) 90 #}}} 91 92 #process independent variables {{{ 93 num_independent_objects=len(self.independents) 94 WriteData(fid,'data',num_independent_objects,'enum',AutodiffNumIndependentObjectsEnum(),'format','Integer') 95 96 if num_independent_objects: 97 names=numpy.zeros(num_independent_objects) 98 types=numpy.zeros(num_independent_objects) 99 100 for i,indep in enumerate(self.independents): 101 names[i]=StringToEnum(indep.name)[0] 102 types[i]=indep.typetoscalar() 103 104 WriteData(fid,'data',names,'enum',AutodiffIndependentObjectNamesEnum(),'format','IntMat','mattype',3) 105 WriteData(fid,'data',types,'enum',AutodiffIndependentObjectTypesEnum(),'format','IntMat','mattype',3) 106 #}}} 107 108 #if driver is fos_forward, build index: {{{ 109 if strcmpi(self.driver,'fos_forward'): 110 index=0 111 112 for indep in self.independents: 113 if not isnan(indep.fos_forward_index): 114 index+=indep.fos_forward_index 115 break 116 else: 117 if strcmpi(indep.type,'scalar'): 118 index+=1 119 else: 120 index+=indep.nods 121 122 index-=1 #get c-index numbering going 123 WriteData(fid,'data',index,'enum',AutodiffFosForwardIndexEnum(),'format','Integer') 124 #}}} 125 126 #if driver is fos_reverse, build index: {{{ 127 if strcmpi(self.driver,'fos_reverse'): 128 index=0 129 130 for dep in self.dependents: 131 if not isnan(dep.fos_reverse_index): 132 index+=dep.fos_reverse_index 133 break 134 else: 135 if strcmpi(dep.type,'scalar'): 136 index+=1 137 else: 138 index+=dep.nods 139 140 index-=1 #get c-index numbering going 141 WriteData(fid,'data',index,'enum',AutodiffFosReverseIndexEnum(),'format','Integer') 142 end 143 #}}} 144 145 #if driver is fov_forward, build indices: {{{ 146 if strcmpi(self.driver,'fov_forward'): 147 indices=0 148 149 for indep in self.independents: 150 if indep.fos_forward_index: 151 indices+=indep.fov_forward_indices 152 break 153 else: 154 if strcmpi(indep.type,'scalar'): 155 indices+=1 156 else: 157 indices+=indep.nods 158 159 indices-=1 #get c-indices numbering going 160 WriteData(fid,'data',indices,'enum',AutodiffFovForwardIndicesEnum(),'format','IntMat','mattype',3) 161 end 162 #}}} 163 164 #deal with mass fluxes: {{{ 165 mass_flux_segments=[dep.segments for dep in self.dependents if strcmpi(dep.name,'MassFlux')] 166 167 if mass_flux_segments: 168 WriteData(fid,'data',mass_flux_segments,'enum',MassFluxSegmentsEnum(),'format','MatArray') 169 flag=True 170 else: 171 flag=False 172 WriteData(fid,'data',flag,'enum',AutodiffMassFluxSegmentsPresentEnum(),'format','Boolean') 173 #}}} 174 175 #deal with trace keep on: {{{ 176 keep=False 177 178 #From ADOLC userdoc: 179 # The optional integer argument keep of trace on determines whether the numerical values of all active variables are 180 # recorded in a buffered temporary array or file called the taylor stack. This option takes effect if keep = 1 and 181 # prepares the scene for an immediately following gradient evaluation by a call to a routine implementing the reverse 182 # mode as described in the Section 4 and Section 5. 183 # 184 185 if len(self.driver)<=3: 186 keep=False #there is no "_reverse" string within the driver string: 187 else: 188 if strncmpi(self.driver[3:],'_reverse',8): 189 keep=True 190 else: 191 keep=False 192 WriteData(fid,'data',keep,'enum',AutodiffKeepEnum(),'format','Boolean') 193 #}}} 194 195 return 43 196 # }}} 44 197 -
issm/trunk-jpl/src/m/classes/dependent.m
r13646 r13862 15 15 end 16 16 methods 17 function obj= dependent(varargin) % {{{17 function obj = dependent(varargin) % {{{ 18 18 19 20 19 %use provided options to change fields 20 options=pairoptions(varargin{:}); 21 21 22 23 24 25 26 27 22 obj.name=getfieldvalue(options,'name',''); 23 obj.type=getfieldvalue(options,'type',''); 24 obj.exp=getfieldvalue(options,'exp',''); 25 obj.segments=getfieldvalue(options,'segments',[]); 26 obj.index=getfieldvalue(options,'index',-1); 27 obj.nods=getfieldvalue(options,'nods',0); 28 28 29 30 31 32 33 34 35 36 37 38 39 40 29 %if name is mass flux: 30 if strcmpi(obj.name,'MassFlux'), 31 %make sure that we supplied a file and that it exists! 32 if exist(obj.exp)~=2, 33 error('dependent checkconsistency: specified ''exp'' file does not exist!'); 34 end 35 %process the file and retrieve segments 36 mesh=getfieldvalue(options,'mesh'); 37 obj.segments=MeshProfileIntersection(mesh.elements,mesh.x,mesh.y,obj.exp); 38 end 39 end 40 %}}} 41 41 function obj = setdefaultparameters(obj) % {{{ 42 %do nothing42 %do nothing 43 43 end % }}} 44 44 function md = checkconsistency(obj,md,solution,analyses) % {{{ 45 %do nothing for now46 45 if strcmpi(obj.name,'MassFlux'), 47 46 if isempty(obj.segments), … … 57 56 end 58 57 if obj.nods==0, 59 error(' ependent checkconsistency error: nods should be set to the size of the independent variable');58 error('dependent checkconsistency error: nods should be set to the size of the independent variable'); 60 59 end 61 62 60 end 63 61 64 62 end % }}} 65 63 function disp(obj) % {{{ 66 disp(sprintf(' dependent variable 64 disp(sprintf(' dependent variable:')); 67 65 68 66 fielddisplay(obj,'name','variable name (must match corresponding Enum)'); … … 79 77 end % }}} 80 78 function scalar=typetoscalar(obj) % {{{ 81 if strcmpi(obj.type,'scalar'),82 scalar=0;83 elseif strcmpi(obj.type,'vertex'),84 scalar=1;85 end79 if strcmpi(obj.type,'scalar'), 80 scalar=0; 81 elseif strcmpi(obj.type,'vertex'), 82 scalar=1; 83 end 86 84 87 85 end % }}} -
issm/trunk-jpl/src/m/classes/independent.m
r13646 r13862 13 13 end 14 14 methods 15 function obj= independent(varargin) % {{{15 function obj = independent(varargin) % {{{ 16 16 17 18 17 %use provided options to change fields 18 options=pairoptions(varargin{:}); 19 19 20 21 20 %OK get other fields 21 obj=AssignObjectFields(pairoptions(varargin{:}),obj); 22 22 23 24 23 end 24 %}}} 25 25 function obj = setdefaultparameters(obj) % {{{ 26 26 %do nothing … … 28 28 end % }}} 29 29 function md = checkconsistency(obj,md,i,solution,analyses,driver) % {{{ 30 %do nothing for now31 30 if ~isnan(obj.fos_forward_index), 32 31 if ~strcmpi(driver,'fos_forward'), … … 42 41 error('cannot declare an independent with fov_forward_indices when the driver is not fov_forward!'); 43 42 end 44 45 43 if obj.nods==0, 46 44 error('independent checkconsistency error: nods should be set to the size of the independent variable'); … … 51 49 end % }}} 52 50 function disp(obj) % {{{ 53 disp(sprintf(' independent variable 51 disp(sprintf(' independent variable:')); 54 52 55 53 fielddisplay(obj,'name','variable name (must match corresponding Enum)');
Note:
See TracChangeset
for help on using the changeset viewer.