Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Diff of /branches/ein16/synth/d2/test_eval.py
ViewVC logotype

Diff of /branches/ein16/synth/d2/test_eval.py

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

revision 4210, Thu Jul 14 18:01:19 2016 UTC revision 4230, Tue Jul 19 16:35:13 2016 UTC
# Line 104  Line 104 
104  #gradient of field  #gradient of field
105  def fn_grad(exp, dim):  def fn_grad(exp, dim):
106      if (dim==1):      if (dim==1):
107          return [diff(exp,x)]          return diff(exp,x)
108      elif (dim==2):      elif (dim==2):
109          return [diff(exp,x), diff(exp,y)]          return [diff(exp,x), diff(exp,y)]
110      elif (dim==3):      elif (dim==3):
# Line 496  Line 496 
496          rtn.append(tmpI)          rtn.append(tmpI)
497      return rtn      return rtn
498    
499    def applyToMs(vecA,vecB, unary):
500        rtn = []
501        for (a,b) in zip(vecA,vecB):
502            tmpI = []
503            for (u,v) in zip(a,b):
504                tmpI.append(unary(u, v))
505            rtn.append(tmpI)
506        return rtn
507    
508    
509  def applyToT3(vec, unary):  def applyToT3(vec, unary):
510      rtn = []      rtn = []
511      for i in vec:      for i in vec:
# Line 626  Line 636 
636      else:      else:
637         return applyToExp_B_uneven(e)         return applyToExp_B_uneven(e)
638    
639    def applyToExp_B_M(e):
640        fn_name=e.opr
641        (fld1,fld2) =  apply.get_binary(e)
642        exp1 = field.get_data(fld1)
643        exp2 = field.get_data(fld2)
644        if(op_add==fn_name):#addition
645            return applyToMs(exp1, exp2,  fn_add)
646        elif(op_subtract==fn_name):#subtract
647            return  applyToMs(exp1, exp2, fn_subtract)
648        else:
649            return applyToExp_B_uneven(e)
650    
651    
652  # ***************************  unary/binary operators ***************************  # ***************************  unary/binary operators ***************************
653  def unary(e):  def unary(e):
# Line 660  Line 682 
682          if(field.is_Vector(g)):          if(field.is_Vector(g)):
683              return applyToExp_B_V(e)              return applyToExp_B_V(e)
684          else: # input is a vector field, _          else: # input is a vector field, _
685              return applyToExp_B_uneven(e)              return applyToExp_B_V(e)
686        elif (field.is_Matrix(f)):# input is a matrix field
687            if(field.is_Matrix(g)):
688                return applyToExp_B_M(e)
689      else:      else:
690           return applyToExp_B_uneven(e)              return  applyToExp_B_V(e)
691        else:
692             return applyToExp_B_V(e)
693    
694  def applyUnaryOnce(oexp_inner,app_inner,app_outer):  def applyUnaryOnce(oexp_inner,app_inner,app_outer):
695      #print "applyUnaryOnce"      #print "applyUnaryOnce"
# Line 747  Line 774 
774  # ***************************  evaluate at positions ***************************  # ***************************  evaluate at positions ***************************
775  #evaluate scalar field exp  #evaluate scalar field exp
776  def eval_d1(pos0, exp):  def eval_d1(pos0, exp):
777        #print "eval vec d1"
778      #print "exp:",exp      #print "exp:",exp
779        #print "pos0",pos0
780      #evaluate field defined by coefficients at position      #evaluate field defined by coefficients at position
781      exp = exp.subs(x,pos0)      exp = exp.subs(x,pos0)
782        #print "exp",exp
783      return exp      return exp
784    
785  def eval_d2(pos0, pos1, exp):  def eval_d2(pos0, pos1, exp):
# Line 768  Line 798 
798    
799  #evaluate vector field [exp]  #evaluate vector field [exp]
800  def eval_vec_d1(pos0, vec):  def eval_vec_d1(pos0, vec):
801        #print "eval vec d1"
802      rtn = []      rtn = []
803      for v in vec:      for v in vec:
804          rtn.append(eval_d1(pos0, v))          rtn.append(eval_d1(pos0, v))
# Line 885  Line 916 
916      if (dim==1):      if (dim==1):
917          def get_k():          def get_k():
918              if (fty.is_ScalarField(otyp1)): # output is a scalar field              if (fty.is_ScalarField(otyp1)): # output is a scalar field
919                    #print "s_d1"
920                  return eval_d1                  return eval_d1
921              elif (fty.is_VectorField(otyp1)):              elif (fty.is_VectorField(otyp1)):
922                    #print "v_d1"
923                  return eval_vec_d1                  return eval_vec_d1
924              elif (fty.is_Matrix(otyp1)):              elif (fty.is_Matrix(otyp1)):
925                  return eval_mat_d1                  return eval_mat_d1
# Line 929  Line 962 
962  # operators with scalar field and vector field  # operators with scalar field and vector field
963  def eval(app, pos):  def eval(app, pos):
964      #print "evalname",app.name      #print "evalname",app.name
     # print "inside eval exp:", field.toStr(app.exp[0])  
965      #apply.toStr(app)      #apply.toStr(app)
966      (otyp1, ortn) = sort(app) #apply operations to expressions      (otyp1, ortn) = sort(app) #apply operations to expressions
967      #print "ortn",ortn      #print "ortn",ortn

Legend:
Removed from v.4210  
changed lines
  Added in v.4230

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0