3D EM based on Schur decomposition
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. import numpy as np
  2. import pprint
  3. def calcH( oxx, nxx, dxx, pad ):
  4. """Calculates grid spacing along a dimension, if padding cells are requested those are incorporated too"""
  5. pp = 1.1 # fixed padding expansion factor
  6. if not pad:
  7. px = np.arange(oxx-dxx/2, oxx-dxx/2+(nxx+1)*dxx, dxx)
  8. hx = dxx*np.ones(nxx)
  9. return hx, px
  10. else:
  11. hx = np.zeros( nxx )
  12. for ip in range(0,pad):
  13. hx[ip] = dxx*pp**(pad-ip)
  14. hx[pad:nxx-pad] = dxx
  15. ip = 1
  16. for ii in range (nxx-pad, nxx):
  17. hx[ii] = dxx*pp**ip
  18. ip += 1
  19. px = np.zeros( nxx + 1 ) # interfaces
  20. px[0] = oxx - (dxx*pp**pad)/2
  21. for i, h in enumerate(hx):
  22. px[i+1] = px[i]+h
  23. return hx, px
  24. def writeH(fout, h, p):
  25. ix = 0
  26. rx,rxm1 = 0,0
  27. while (ix < len(h)):
  28. fout.write ("%6.2f" %( h[ix]) )
  29. ix += 1
  30. rx += 1
  31. if rx > 4:
  32. fout.write(" //") # [%i:%i]\n" %(rxm1,ix-1))
  33. #fout.write( (p[rxm1:ix-1]) )
  34. for pp in p[rxm1:ix+1]:
  35. fout.write(" %6.2f" %(pp))
  36. fout.write("\n")
  37. rxm1 += rx
  38. rx = 0
  39. else:
  40. fout.write(" ")
  41. def writeGRD(fout, args):
  42. fout.write( "%i\t%i\t%i\t// nx ny nz\n" %(args.nx[0],args.ny[0],args.nz[0]) )
  43. fout.write( "%f\t%f\t%f\t// ox oy oz\n" %(args.ox[0],args.oy[0],args.oz[0]) )
  44. fout.write("\n// hx\n")
  45. hx,px = calcH( args.ox[0], args.nx[0], args.dx[0], args.pad )
  46. writeH(fout, hx, px)
  47. fout.write("\n// hy\n")
  48. hy,py = calcH( args.oy[0], args.ny[0], args.dy[0], args.pad )
  49. writeH(fout, hy, py)
  50. fout.write("\n// hz\n")
  51. hz,pz = calcH( args.oz[0], args.nz[0], args.dz[0], args.pad )
  52. writeH(fout, hz, pz)
  53. fout.write("\n\n")
  54. #fout.write( "// vim: set tabstop=4 expandtab:\n")
  55. fout.write( "// vim: set filetype=cpp:\n")
  56. return px,py,pz
  57. def writeMOD(fout, args, px, py, pz):
  58. sigma = np.zeros( (args.nx[0], args.ny[0], args.nz[0]) )
  59. sigma[:,:,pz[1:]>0] = 0.05
  60. xlo = np.where( px[0:-1] >= args.bxlo[0] )[0][0]
  61. xhi = np.where( px[1:] <= args.bxhi[0] )[0][-1] + 1
  62. ylo = np.where( py[0:-1] >= args.bylo[0] )[0][0]
  63. yhi = np.where( py[1:] <= args.byhi[0] )[0][-1] + 1
  64. zlo = np.where( pz[0:-1] >= args.bzlo[0] )[0][0]
  65. zhi = np.where( pz[1:] <= args.bzhi[0] )[0][-1] + 1
  66. sigma[xlo:xhi, ylo:yhi, zlo:zhi] = .1
  67. for val in np.ravel(sigma, order='C'):
  68. fout.write("%f\n" %(val) )
  69. def str2bool(v):
  70. if v.lower() in ('yes', 'true', 't', 'y', '1'):
  71. return True
  72. elif v.lower() in ('no', 'false', 'f', 'n', '0'):
  73. return False
  74. else:
  75. raise argparse.ArgumentTypeError('Boolean value expected.')
  76. import argparse
  77. PAD = 0
  78. parser = argparse.ArgumentParser(description='Set up test EMSchur3D block problem.')
  79. parser.add_argument('nx', metavar='nx', type=int, nargs=1,
  80. help='number of cells in x')
  81. parser.add_argument('ny', metavar='ny', type=int, nargs=1,
  82. help='number of cells in y')
  83. parser.add_argument('nz', metavar='nz', type=int, nargs=1,
  84. help='number of cells in z')
  85. parser.add_argument('ox', metavar='ox', type=float, nargs=1,
  86. help='offset of grid in x')
  87. parser.add_argument('oy', metavar='oy', type=float, nargs=1,
  88. help='offset of grid in y')
  89. parser.add_argument('oz', metavar='oz', type=float, nargs=1,
  90. help='offset of grid in z')
  91. parser.add_argument('dx', metavar='dx', type=int, nargs=1,
  92. help='minimum spacing in x')
  93. parser.add_argument('dy', metavar='dy', type=int, nargs=1,
  94. help='minimum spacing in y')
  95. parser.add_argument('dz', metavar='dz', type=int, nargs=1,
  96. help='minimum spacing in z')
  97. parser.add_argument('bxlo', metavar='bxlo', type=float, nargs=1,
  98. help='low end of block cell location in x')
  99. parser.add_argument('bxhi', metavar='bxhi', type=float, nargs=1,
  100. help='high end of block cell location in x')
  101. parser.add_argument('bylo', metavar='bylo', type=float, nargs=1,
  102. help='low end of block cell location in y')
  103. parser.add_argument('byhi', metavar='byhi', type=float, nargs=1,
  104. help='high end of block cell location in y')
  105. parser.add_argument('bzlo', metavar='bzlo', type=float, nargs=1,
  106. help='low end of block cell location in z')
  107. parser.add_argument('bzhi', metavar='bzhi', type=float, nargs=1,
  108. help='high end of block cell location in z')
  109. parser.add_argument("--pad", type=int, nargs='?',
  110. const=True, default=PAD,
  111. help="Activate this number of padding cells with 10%% growth factor.")
  112. args = parser.parse_args()
  113. fout = open("example.grd", 'w')
  114. px,py,pz = writeGRD(fout, args)
  115. fout.close()
  116. mout = open("example.mod", 'w')
  117. writeMOD(mout, args, px, py, pz)
  118. #print(args.nx)
  119. #print(args.accumulate(args.nx))
  120. #print(args.accumulate(args.ny))