/[escript]/trunk/downunder/py_src/regularizations.py
ViewVC logotype

Diff of /trunk/downunder/py_src/regularizations.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 4101 by gross, Tue Dec 11 06:55:20 2012 UTC revision 4102 by gross, Wed Dec 12 06:17:03 2012 UTC
# Line 157  class Regularization(CostFunction): Line 157  class Regularization(CostFunction):
157      if not w1 is None:      if not w1 is None:
158            w1 = interpolate(w1,self.__pde.getFunctionSpaceForCoefficient('A'))            w1 = interpolate(w1,self.__pde.getFunctionSpaceForCoefficient('A'))
159            s1=w1.getShape()            s1=w1.getShape()
           print s1, (DIM,)  
           print w1  
160            if numLevelSets is 1 :            if numLevelSets is 1 :
161             if not s1 == (DIM,) :             if not s1 == (DIM,) :
162                raise ValueError("Unexpected shape %s for weight w1."%s1)                raise ValueError("Unexpected shape %s for weight w1."%s1)
# Line 172  class Regularization(CostFunction): Line 170  class Regularization(CostFunction):
170               sc=wc.getShape()               sc=wc.getShape()
171               raise ValueError("Unexpected shape %s for weight wc."%sc)               raise ValueError("Unexpected shape %s for weight wc."%sc)
172          # ============= now we rescale weights: ======================================          # ============= now we rescale weights: ======================================
         self.__vol_d=vol(self.__domain)  
173          L2s=np.asarray(boundingBoxEdgeLengths(domain))**2          L2s=np.asarray(boundingBoxEdgeLengths(domain))**2
174          L4=1/np.sum(1/L2s)**2          L4=1/np.sum(1/L2s)**2
175          if numLevelSets is 1 :          if numLevelSets is 1 :
# Line 182  class Regularization(CostFunction): Line 179  class Regularization(CostFunction):
179          if w1 is not None:          if w1 is not None:
180              A += integrate(inner(w1, 1/L2s))              A += integrate(inner(w1, 1/L2s))
181          if A > 0:          if A > 0:
182              f = scale*self.__vol_d/A              f = scale/A
183              if w0 is not None:              if w0 is not None:
184                   w0*=f                   w0*=f
185              if w1 is not None:              if w1 is not None:
# Line 197  class Regularization(CostFunction): Line 194  class Regularization(CostFunction):
194               if w1 is not None:               if w1 is not None:
195                    A += integrate(inner(w1[k,:], 1/L2s))                    A += integrate(inner(w1[k,:], 1/L2s))
196               if A > 0:               if A > 0:
197                    f = scale[k]*self.__vol_d/A                    f = scale[k]/A
198                    if w0 is not None:                    if w0 is not None:
199                       w0[k]*=f                       w0[k]*=f
200                    if w1 is not None:                    if w1 is not None:
# Line 209  class Regularization(CostFunction): Line 206  class Regularization(CostFunction):
206               for l in xrange(k):                 for l in xrange(k):  
207                   A = integrate(wc[l,k])/L4                   A = integrate(wc[l,k])/L4
208                   if A > 0:                   if A > 0:
209                      f = scale_c[l,k]*self.__vol_d/A                      f = scale_c[l,k]/A
210                      wc[l,k]*=f                      wc[l,k]*=f
211                       else:                       else:
212                      raise ValueError("Non-positive weighting factor for cross-gradient level set components %d and %d detected."%(l,k))                      raise ValueError("Non-positive weighting factor for cross-gradient level set components %d and %d detected."%(l,k))
# Line 229  class Regularization(CostFunction): Line 226  class Regularization(CostFunction):
226    
227          self.__num_tradeoff_factors=numLevelSets+((numLevelSets-1)*numLevelSets)/2          self.__num_tradeoff_factors=numLevelSets+((numLevelSets-1)*numLevelSets)/2
228          self.setTradeOffFactors()          self.setTradeOffFactors()
229            self.__vol_d=vol(self.__domain)
230            
231      def getDomain(self):      def getDomain(self):
232          """          """
233          returns the domain of the regularization term          returns the domain of the regularization term
# Line 465  class Regularization(CostFunction): Line 463  class Regularization(CostFunction):
463                                                    
464              if numLS > 1:              if numLS > 1:
465                  raise NotImplementedError                  raise NotImplementedError
             print A  
466              self.getPDE().setValue(A=A)              self.getPDE().setValue(A=A)
467          self.getPDE().resetRightHandSideCoefficients()          #self.getPDE().resetRightHandSideCoefficients()
468          self.getPDE().setValue(X=r[1])          #self.getPDE().setValue(X=r[1])
469          print "X only: ",self.getPDE().getSolution()          #print "X only: ",self.getPDE().getSolution()
470          self.getPDE().resetRightHandSideCoefficients()          #self.getPDE().resetRightHandSideCoefficients()
471          self.getPDE().setValue(Y=r[0])          #self.getPDE().setValue(Y=r[0])
472          print "Y only: ",self.getPDE().getSolution()          #print "Y only: ",self.getPDE().getSolution()
473    
474          self.getPDE().resetRightHandSideCoefficients()          self.getPDE().resetRightHandSideCoefficients()
475          self.getPDE().setValue(X=r[1], Y=r[0])          self.getPDE().setValue(X=r[1], Y=r[0])

Legend:
Removed from v.4101  
changed lines
  Added in v.4102

  ViewVC Help
Powered by ViewVC 1.1.26