Dear all,
trying to implement a spectral decomposition in UFL, I would like to test the parts of my code separately.
That’s why I am wondering if there is a way to enforce printing the numerical values of UFL objects such as tensors in a human readable format.
Concrete example: I want to test the implementation of the functions te_plus(A)+te_minus(A) calculating the positive and negative part of the tensor A (see below):
A = as_tensor(((1,1),(0,1)))
print(A)A_reass=te_plus(A)+te_minus(A)
print(A_reass)
However, the second print command does not give the expected result (which should be the same as the first command’s output) but something not understandable:
]) + ({ A | A_{i_{16}, i_{17}} = -1 * ({ A | A_{i_{14}, i_{15}} = 1.00000001 * I[i_{14}, i_{15}] })[i_{16}, i_{17}] }))[i_{18}, i_{19}] })[i_{22}, i_{23}] })
functions to test (not efficent yet, by the way…)
from dolfin import *
nuz = 5E-12 #numerical zero
rd = 2 #space dimensionnumturb=1E-8 # numerical perturbations to be applied in case of equal eigenvalues
→ assuming 2d problem !#eigenvalues
def eval1(te):
return 0.5*(te[1,1]+te[0,0]+sqrt(pow(te[0,0],2)-2.0*te[0,0]te[1,1]+4.0te[0,1]*te[1,0]+pow(te[1,1],2))) #first eigenvaluedef eval2(te):
return 0.5*(te[1,1]+te[0,0]-sqrt(pow(te[0,0],2)-2.0*te[0,0]te[1,1]+4.0te[0,1]*te[1,0]+pow(te[1,1],2))) #second eigenvalue#positive and negative part
def te_plus(te):
eva1=eval1(te)+numturb
eva2=eval2(te)-numturb#projection tensors
p1=(1.0/(eva1-eva2))(te-eva2Identity(rd))
p2=(1.0/(eva2-eva1))(te-eva1Identity(rd))#“positive part” of eigenvalues
eva1_pos = (abs(eva1)+eva1)/2
eva2_pos = (abs(eva2)+eva2)/2#assemble tensor’s positive part
return eva1_posp1+eva2_posp2def te_minus(te):
eva1=eval1(te)+numturb
eva2=eval2(te)-numturb#projection tensors
p1=(1.0/(eva1-eva2))(te-eva2Identity(rd))
p2=(1.0/(eva2-eva1))(te-eva1Identity(rd))#“negative part” of eigenvalues
eva1_neg = (abs(eva1)-eva1)/2
eva2_neg = (abs(eva2)-eva2)/2#assemble tensor’s negative part
return eva1_negp1+eva2_negp2