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 4459 - (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 : cchiw 4459 from constants import *
13 : cchiw 3939 from obj_ty import *
14 :     from obj_coeff import mk_exp
15 :    
16 : cchiw 4459 class kernel:
17 :     def __init__(self, name, str, continuity, order):
18 :     self.name = name
19 :     self.str = str
20 :     self.continuity = continuity
21 :     self.order = order
22 :    
23 :     #kernel(name, str, continuity, order)
24 :     krn_hex = kernel("c4hexic", "c4hexic", 3, 3)
25 :     krn_bs3 = kernel("bspln3","bspln3", 2, 2)
26 :     krn_tent = kernel("tent", "tent", 0, 1)
27 :    
28 :     # transform kernel from input global to kernel variable
29 :     def transform_krn(krn, id):
30 :     if(krn == h_bs3):
31 :     return krn_bs3
32 :     elif(krn == h_hex):
33 :     return krn_hex
34 :     elif(krn == h_tent):
35 :     return krn_tent
36 :     elif(krn == h_mixcbc):
37 :     if(id == 0):
38 :     return krn_hex
39 :     elif(id == 1):
40 :     return krn_bs3
41 :     elif(id == 2):
42 :     return krn_hex
43 :     elif(krn == h_mixcbt):
44 :     if(id == 0):
45 :     return krn_hex
46 :     elif(id == 1):
47 :     return krn_bs3
48 :     elif(id == 2):
49 :     return krn_tent
50 :    
51 :     else:
52 :     raise Exception ("unsupported kernel type:", krn)
53 :    
54 :     # transform kernel from input global to kernel variable
55 :     def krn_to_k(krn):
56 :     return krn.continuity
57 :     def set_k(g_krn, id, ty1):
58 :     c_krn = transform_krn(g_krn, id)
59 :     c_k = c_krn.continuity
60 :     ty1.k = c_k
61 :     return
62 :     def set_ks(g_krn, ishapes):
63 :     id = 0
64 :     for i in ishapes:
65 :     set_k(g_krn, id, i)
66 :     id+=1
67 :     return
68 :    
69 :    
70 : cchiw 3939 #returns expression created with coefficients
71 :     class field:
72 :     def __init__(self, isField, name, fldty, krn, data, inputfile):
73 :     self.isField = isField
74 :     self.name = name
75 :     self.fldty = fldty
76 :     self.krn = krn
77 :     self.data = data
78 :     self.inputfile = inputfile
79 :     def toStr(self):
80 :     if (self==None):
81 :     return "field is none"
82 :     else:
83 : cchiw 3946 return ("Field:"+fty.toStr(self.fldty)+" "+self.name+"="+str(self.data))
84 : cchiw 3939 #equal id to fty
85 :     def isEq_id(a,b):
86 :     return (a.fldty.ty.id== b.id)
87 :     # def get_ty(self):
88 :     # return self.fldty.ty
89 :     def get_dim(self):
90 :     #print "inside get dim", self.name
91 :     return self.fldty.dim
92 :     def get_data(self):
93 :     d = self.data
94 :     #print "self get data", d
95 :     return d
96 :     def get_ty(self):
97 :     return self.fldty
98 :     def get_isField(self):
99 :     return self.isField
100 :     # is scalar field
101 :     def is_ScalarField(ty0):
102 :     shape = ty0.fldty.shape
103 :     return (ty0.isField and len(shape)==0)
104 :     def is_Scalar(ty0):
105 :     shape = ty0.fldty.shape
106 :     return (len(shape)==0)
107 :     # is vecor field
108 :     def is_VectorField(ty0):
109 :     shape = ty0.fldty.shape
110 :     return (ty0.isField and len(shape)==1)
111 :     def is_Vector(ty0):
112 :     shape = ty0.fldty.shape
113 :     return (len(shape)==1)
114 :     def is_Matrix(ty0):
115 :     shape = ty0.fldty.shape
116 :     return (len(shape)==2)
117 :     def is_Ten3(ty0):
118 :     shape = ty0.fldty.shape
119 :     return (len(shape)==3)
120 :    
121 : cchiw 4459 # i_fty: field type
122 :     def mk_Field(index, i_fty, k, inputfile, dim, coeff_style, ucoeff, krn):
123 :     #print "inside mk fields: "+str(index)
124 : cchiw 3939 tag="_"+str(index)
125 :     id="F"+tag
126 : cchiw 4459 # field type
127 :     finfo1 = fty.convertTy(i_fty, k)
128 : cchiw 3939 # translate coefficients to expression
129 :     # name of input file
130 :     input1 = inputfile+tag
131 :     def get_vec(n):
132 :     if (n==2):
133 : cchiw 4457 (coeff1, exp1)= mk_exp(dim, coeff_style, ucoeff)
134 :     (coeff2, exp2)= mk_exp(dim, coeff_style, ucoeff)
135 : cchiw 3939 coeffs= [ coeff1,coeff2]
136 :     exps = [exp1,exp2]
137 : cchiw 4411 #print " inside get vec(): exp1", exp1
138 :     #print " inside get vec(): exp2", exp2
139 : cchiw 3939 return (coeffs, exps)
140 :     elif (n==3):
141 : cchiw 4457 (coeff1, exp1)= mk_exp(dim, coeff_style, ucoeff)
142 :     (coeff2, exp2)= mk_exp(dim, coeff_style, ucoeff)
143 :     (coeff3, exp3)= mk_exp(dim, coeff_style, ucoeff)
144 : cchiw 3939 coeffs= [ coeff1,coeff2, coeff3]
145 :     exps = [exp1, exp2, exp3]
146 :     return (coeffs, exps)
147 : cchiw 4456 elif (n==4):
148 : cchiw 4457 (coeff1, exp1)= mk_exp(dim, coeff_style, ucoeff)
149 :     (coeff2, exp2)= mk_exp(dim, coeff_style, ucoeff)
150 :     (coeff3, exp3)= mk_exp(dim, coeff_style, ucoeff)
151 :     (coeff4, exp4)= mk_exp(dim, coeff_style, ucoeff)
152 : cchiw 4456 coeffs= [ coeff1,coeff2, coeff3, coeff4]
153 :     exps = [exp1, exp2, exp3, exp4]
154 :     return (coeffs, exps)
155 : cchiw 3939 else:
156 :     raise Exception ("unsupported length:"+str(n))
157 :     def get_mat(n,m):
158 :     exps=[]
159 :     coeffs=[]
160 : cchiw 4411 #print "starting get_mat"
161 : cchiw 3939 for i in range(n):
162 :     (c1,e1)= get_vec(m)
163 :     exps.append(e1)
164 :     coeffs.append(c1)
165 : cchiw 4230 # (c1,e1) = get_vec(m)
166 :    
167 :     #[a, b, c]=e1
168 :     #e2 = [a*2,b*2,c*2]
169 :     #e3 = [a*3,b*3,c*3]
170 :     #exps = [e1, e1, e1] #each axis has fixed value
171 :     #coeffs = [c1, c1, c1]
172 : cchiw 4411 #print "\n\n ********************** post get exp\n"
173 : cchiw 4230 #print "exps-e1",e1
174 :     #print "coeffs-c1",c1
175 : cchiw 4411 #print " exps[0][0]", exps[0][0]
176 :     #print " exps[0][1]", exps[0][1]
177 :     #print " exps[1][0]", exps[1][0]
178 : cchiw 4230 #print "\n\n --- \n"
179 :     #print "coeffs",coeffs
180 : cchiw 3939 return (coeffs, exps)
181 :     def get_ten3(n,m,o):
182 :     exps=[]
183 :     coeffs=[]
184 :     for i in range(n):
185 :     (c1,e1)= get_mat(m, o)
186 :     exps.append(e1)
187 :     coeffs.append(c1)
188 :     return (coeffs, exps)
189 : cchiw 4458
190 : cchiw 3939 if (fty.is_ScalarField(finfo1)):
191 : cchiw 4457 (coeff1, exp1)= mk_exp(dim, coeff_style, ucoeff)
192 : cchiw 3939 F = field(true, id, finfo1 , krn, exp1, input1)
193 :     #print ("Fsca", field.toStr(F))
194 :     return (F, finfo1, coeff1)
195 :     elif(fty.is_VectorField(finfo1)): # input is a vector field
196 :     n= fty.get_vecLength(finfo1)
197 :     (coeffs, exps) = get_vec(n)
198 :     F = field(true, id, finfo1 ,krn, exps, input1)
199 :     #print ("Fvec", field.toStr(F))
200 :     return (F, finfo1, coeffs)
201 : cchiw 4230 elif(fty.is_MatrixField(finfo1)): # input is a vector field
202 :     [shape0, shape1] = fty.get_shape(finfo1)
203 :     (coeffs, exps) = get_mat(shape0, shape1)
204 :     F = field(true, id, finfo1 ,krn, exps, input1)
205 :     #print ("Fvec", field.toStr(F))
206 :     return (F, finfo1, coeffs)
207 :    
208 : cchiw 3939 elif(fty.get_dim(finfo1)==0): #tensor
209 :     if(fty.is_Scalar(finfo1)):
210 : cchiw 4457 (coeff1, exp1)= mk_exp(dim, coeff_style, ucoeff)
211 : cchiw 3939 (coeffs, exps) = (coeff1, exp1)
212 : cchiw 4459 F = field(false, id, i_fty,"", exps, "")
213 : cchiw 3939 #print ("Ften", field.toStr(F))
214 :     return (F, finfo1, coeff1)
215 :     elif(fty.is_Vector(finfo1)):
216 :     n= fty.get_vecLength(finfo1)
217 : cchiw 4457 (coeff1, exp1)= mk_exp(dim, coeff_style, ucoeff)
218 : cchiw 3939 (coeffs, exps) = get_vec(n)
219 : cchiw 4459 F = field(false, id, i_fty,"", exps, "")
220 : cchiw 3939 #print ("Ften", field.toStr(F))
221 :     return (F, finfo1, coeff1)
222 :     elif(fty.is_Matrix(finfo1)):
223 :     [shape0, shape1] = fty.get_shape(finfo1)
224 :     (coeffs, exps) = get_mat(shape0, shape1)
225 : cchiw 4459 F = field(false, id, i_fty,"", exps, "")
226 : cchiw 3939 #print ("Ften", field.toStr(F))
227 :     return (F, finfo1, coeffs)
228 :     elif(fty.is_Ten3(finfo1)):
229 :     [shape0, shape1, shape2] = fty.get_shape(finfo1)
230 :     (coeffs, exps) = get_ten3(shape0, shape1, shape2)
231 : cchiw 4459 F = field(false, id, i_fty,"", exps, "")
232 : cchiw 3939 #print ("Ften", field.toStr(F))
233 :     return (F, finfo1, coeffs)
234 :     else:
235 :     raise "unsupported field type"
236 :     else:
237 :     raise "unsupported field type"

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