Skip to content

Commit

Permalink
maint: revised physics.mesh.test()
Browse files Browse the repository at this point in the history
  • Loading branch information
tfrederiksen committed Mar 11, 2018
1 parent 17b13fb commit eb2f8d6
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions Inelastica/physics/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,17 +159,34 @@ def mesh2file(self, fn):


def test():
mesh = kmesh(4, 3, 1, meshtype=['LIN', 'GK', 'LIN'])
"""
Test function
"""
mesh = kmesh(4, 3, 3, meshtype=['LIN', 'GK', 'LIN'],invsymmetry=False)
keys = mesh.__dict__.keys()
print keys
print mesh.Nk
print mesh.NNk
print mesh.type
print mesh.invsymmetry
print 'ki wi'
for i in range(len(mesh.k)):
print mesh.k[i], mesh.w[0, i]
#print 'ki wi'
#for i in range(len(mesh.k)):
# print mesh.k[i], mesh.w[0, i]
mesh.mesh2file('mesh-test.dat')

print 'Integrate some simple functions over [-0.5,0.5]:'
print ' f(x,y,z)=1 => \int f dxdydz =',N.sum(mesh.w[0])
for i,s in enumerate(['x','y','z']):
f = mesh.k[:,i]
print ' f(x,y,z)=%s => \int f dxdydz ='%s, N.sum(f*mesh.w[0])
f = mesh.k[:,0]*mesh.k[:,1]*mesh.k[:,2]
print ' f(x,y,z)=x*y*z => \int f dxdydz =',N.sum(f*mesh.w[0])
f = (mesh.k[:,0]+1)*(mesh.k[:,1]+1)*(mesh.k[:,2]+1)
print ' f(x,y,z)=(x+1)*(y+1)*(z+1) => \int f dxdydz =',N.sum(f*mesh.w[0])
import math
for i,s in enumerate(['x','y','z']):
f = N.cos(2*mesh.k[:,i])
print ' f(x,y,z)=cos(2%s) => \int f dxdydz ='%s, N.sum(f*mesh.w[0]), '[exact: sin(1) ~ 0.841470984807897]'

if __name__ == '__main__':
test()

0 comments on commit eb2f8d6

Please sign in to comment.