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

SCM Repository

[diderot] Annotation of /branches/ein16/synth/d2/obj_field.py
ViewVC logotype

Annotation of /branches/ein16/synth/d2/obj_field.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4456 - (view) (download) (as text)

1 : cchiw 3939 # -*- coding: utf-8 -*-
2 :    
3 :     from __future__ import unicode_literals
4 :    
5 :     import sympy
6 :     from sympy import *
7 :     #symbols
8 :     x,y,z =symbols('x y z')
9 :     import sys
10 :     import re
11 :     import os
12 :     from obj_ty import *
13 :     from obj_coeff import mk_exp
14 :    
15 :     #returns expression created with coefficients
16 :     class field:
17 :     def __init__(self, isField, name, fldty, krn, data, inputfile):
18 :     self.isField = isField
19 :     self.name = name
20 :     self.fldty = fldty
21 :     self.krn = krn
22 :     self.data = data
23 :     self.inputfile = inputfile
24 :     def toStr(self):
25 :     if (self==None):
26 :     return "field is none"
27 :     else:
28 : cchiw 3946 return ("Field:"+fty.toStr(self.fldty)+" "+self.name+"="+str(self.data))
29 : cchiw 3939 #equal id to fty
30 :     def isEq_id(a,b):
31 :     return (a.fldty.ty.id== b.id)
32 :     # def get_ty(self):
33 :     # return self.fldty.ty
34 :     def get_dim(self):
35 :     #print "inside get dim", self.name
36 :     return self.fldty.dim
37 :     def get_data(self):
38 :     d = self.data
39 :     #print "self get data", d
40 :     return d
41 :     def get_ty(self):
42 :     return self.fldty
43 :     def get_isField(self):
44 :     return self.isField
45 :     # is scalar field
46 :     def is_ScalarField(ty0):
47 :     shape = ty0.fldty.shape
48 :     return (ty0.isField and len(shape)==0)
49 :     def is_Scalar(ty0):
50 :     shape = ty0.fldty.shape
51 :     return (len(shape)==0)
52 :     # is vecor field
53 :     def is_VectorField(ty0):
54 :     shape = ty0.fldty.shape
55 :     return (ty0.isField and len(shape)==1)
56 :     def is_Vector(ty0):
57 :     shape = ty0.fldty.shape
58 :     return (len(shape)==1)
59 :     def is_Matrix(ty0):
60 :     shape = ty0.fldty.shape
61 :     return (len(shape)==2)
62 :     def is_Ten3(ty0):
63 :     shape = ty0.fldty.shape
64 :     return (len(shape)==3)
65 :    
66 :     def mk_Field(index, tys, k, inputfile, dim):
67 :     #print "inside mk_fields: "+str(index)
68 :     tag="_"+str(index)
69 :     id="F"+tag
70 :     #print "index:", index," dim:",dim
71 :    
72 :     finfo1 = fty.convertTy(tys[index], k)
73 :     # translate coefficients to expression
74 : cchiw 4252
75 : cchiw 3939
76 :     # name of input file
77 :     input1 = inputfile+tag
78 :     def get_vec(n):
79 :     if (n==2):
80 : cchiw 4383 (coeff1, exp1)= mk_exp(dim)
81 : cchiw 3939 (coeff2, exp2)= mk_exp(dim)
82 :     coeffs= [ coeff1,coeff2]
83 :     exps = [exp1,exp2]
84 : cchiw 4411 #print " inside get vec(): exp1", exp1
85 :     #print " inside get vec(): exp2", exp2
86 : cchiw 3939 return (coeffs, exps)
87 :     elif (n==3):
88 : cchiw 4383 (coeff1, exp1)= mk_exp(dim)
89 : cchiw 3939 (coeff2, exp2)= mk_exp(dim)
90 :     (coeff3, exp3)= mk_exp(dim)
91 :     coeffs= [ coeff1,coeff2, coeff3]
92 :     exps = [exp1, exp2, exp3]
93 :     return (coeffs, exps)
94 : cchiw 4456 elif (n==4):
95 :     (coeff1, exp1)= mk_exp(dim)
96 :     (coeff2, exp2)= mk_exp(dim)
97 :     (coeff3, exp3)= mk_exp(dim)
98 :     (coeff4, exp4)= mk_exp(dim)
99 :     coeffs= [ coeff1,coeff2, coeff3, coeff4]
100 :     exps = [exp1, exp2, exp3, exp4]
101 :     return (coeffs, exps)
102 : cchiw 3939 else:
103 :     raise Exception ("unsupported length:"+str(n))
104 :     def get_mat(n,m):
105 :     exps=[]
106 :     coeffs=[]
107 : cchiw 4411 #print "starting get_mat"
108 : cchiw 3939 for i in range(n):
109 :     (c1,e1)= get_vec(m)
110 :     exps.append(e1)
111 :     coeffs.append(c1)
112 : cchiw 4230 # (c1,e1) = get_vec(m)
113 :    
114 :     #[a, b, c]=e1
115 :     #e2 = [a*2,b*2,c*2]
116 :     #e3 = [a*3,b*3,c*3]
117 :     #exps = [e1, e1, e1] #each axis has fixed value
118 :     #coeffs = [c1, c1, c1]
119 : cchiw 4411 #print "\n\n ********************** post get exp\n"
120 : cchiw 4230 #print "exps-e1",e1
121 :     #print "coeffs-c1",c1
122 : cchiw 4411 #print " exps[0][0]", exps[0][0]
123 :     #print " exps[0][1]", exps[0][1]
124 :     #print " exps[1][0]", exps[1][0]
125 : cchiw 4230 #print "\n\n --- \n"
126 :     #print "coeffs",coeffs
127 : cchiw 3939 return (coeffs, exps)
128 :     def get_ten3(n,m,o):
129 :     exps=[]
130 :     coeffs=[]
131 :     for i in range(n):
132 :     (c1,e1)= get_mat(m, o)
133 :     exps.append(e1)
134 :     coeffs.append(c1)
135 :     return (coeffs, exps)
136 : cchiw 4321 #krn = "bspln3"#"ctmr"
137 :     krn = "c4hexic"
138 : cchiw 3939 if (fty.is_ScalarField(finfo1)):
139 : cchiw 4383 (coeff1, exp1)= mk_exp(dim)
140 : cchiw 3939 F = field(true, id, finfo1 , krn, exp1, input1)
141 :     #print ("Fsca", field.toStr(F))
142 :     return (F, finfo1, coeff1)
143 :     elif(fty.is_VectorField(finfo1)): # input is a vector field
144 :     n= fty.get_vecLength(finfo1)
145 :     (coeffs, exps) = get_vec(n)
146 :     F = field(true, id, finfo1 ,krn, exps, input1)
147 :     #print ("Fvec", field.toStr(F))
148 :     return (F, finfo1, coeffs)
149 : cchiw 4230 elif(fty.is_MatrixField(finfo1)): # input is a vector field
150 :     [shape0, shape1] = fty.get_shape(finfo1)
151 :     (coeffs, exps) = get_mat(shape0, shape1)
152 :     F = field(true, id, finfo1 ,krn, exps, input1)
153 :     #print ("Fvec", field.toStr(F))
154 :     return (F, finfo1, coeffs)
155 :    
156 : cchiw 3939 elif(fty.get_dim(finfo1)==0): #tensor
157 :     if(fty.is_Scalar(finfo1)):
158 : cchiw 4383 (coeff1, exp1)= mk_exp(dim)
159 : cchiw 3939 (coeffs, exps) = (coeff1, exp1)
160 :     F = field(false, id, tys[index],"", exps, "")
161 :     #print ("Ften", field.toStr(F))
162 :     return (F, finfo1, coeff1)
163 :     elif(fty.is_Vector(finfo1)):
164 :     n= fty.get_vecLength(finfo1)
165 : cchiw 4383 (coeff1, exp1)= mk_exp(dim)
166 : cchiw 3939 (coeffs, exps) = get_vec(n)
167 :     F = field(false, id, tys[index],"", exps, "")
168 :     #print ("Ften", field.toStr(F))
169 :     return (F, finfo1, coeff1)
170 :     elif(fty.is_Matrix(finfo1)):
171 :     [shape0, shape1] = fty.get_shape(finfo1)
172 :     (coeffs, exps) = get_mat(shape0, shape1)
173 :     F = field(false, id, tys[index],"", exps, "")
174 :     #print ("Ften", field.toStr(F))
175 :     return (F, finfo1, coeffs)
176 :     elif(fty.is_Ten3(finfo1)):
177 :     [shape0, shape1, shape2] = fty.get_shape(finfo1)
178 :     (coeffs, exps) = get_ten3(shape0, shape1, shape2)
179 :     F = field(false, id, tys[index],"", exps, "")
180 :     #print ("Ften", field.toStr(F))
181 :     return (F, finfo1, coeffs)
182 :     else:
183 :     raise "unsupported field type"
184 :     else:
185 :     raise "unsupported field type"

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