Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/manual.txt
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ to find more details of the MFEM library.
GridFunction(fes, vec.GetData() + sc)
the same is used for ParGridFunction

GridFunction::Save(std::ostream &out) is wrapped as Save(filename, precision=8)
GridFunction::Save(std::ostream &out) is wrapped as Save(filename, precision)
QuadratureFunction::Save(std::ostream &out) is wrapped as Save(filename, precision=8)

GridFunction::WriteToStream(IOString) writes data to io.IOString
Expand Down
4 changes: 2 additions & 2 deletions examples/ex24.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def p_coef(x):

@mfem.jit.vector(shape=(sdim,))
def gradp_coef(x):
out = np.zeros(shape, dtype=np.float)
out = np.zeros(shape, dtype=np.float64)
if dim == 3:
out[0] = cos(x[0]) * sin(x[1]) * sin(x[2])
out[1] = sin(x[0]) * cos(x[1]) * sin(x[2])
Expand All @@ -104,7 +104,7 @@ def gradp_coef(x):

@mfem.jit.vector(vdim=sdim, interface="c++")
def v_coef(x, out):
out = np.zeros(shape, dtype=np.float)
out = np.zeros(shape, dtype=np.float64)
if dim == 3:
out[0] = sin(kappa * x[1])
out[1] = sin(kappa * x[2])
Expand Down
4 changes: 2 additions & 2 deletions examples/ex25p.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ def detJ_JT_J_inv_f(x):

def detJ_JT_J_inv_abs_f(x):
dim = shape[0]
D = np.zeros(dim, dtype=np.float)
D = np.zeros(dim, dtype=np.float64)

dxs = np.empty(dim, dtype=np.complex128)
det = complex(1.0)
Expand Down Expand Up @@ -702,7 +702,7 @@ def detJ_inv_JT_J_f(x):

def detJ_inv_JT_J_abs_f(x):
dim = shape[0]
D = np.zeros(dim, dtype=np.float)
D = np.zeros(dim, dtype=np.float64)

dxs = np.empty(dim, dtype=np.complex128)
det = 1.0
Expand Down
6 changes: 3 additions & 3 deletions examples/ex31.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def run(order=1,


def E_exact(x):
E = np.zeros(shape, dtype=np.float)
E = np.zeros(shape, dtype=np.float64)
if dim == 1:
E[0] = 1.1 * sin(kappa * x[0] + 0.0 * pi)
E[1] = 1.2 * sin(kappa * x[0] + 0.4 * pi)
Expand All @@ -301,7 +301,7 @@ def E_exact(x):


def CurlE_exact(x):
dE = np.zeros(shape, dtype=np.float)
dE = np.zeros(shape, dtype=np.float64)
if dim == 1:
c4 = cos(kappa * x[0] + 0.4 * pi)
c9 = cos(kappa * x[0] + 0.9 * pi)
Expand Down Expand Up @@ -341,7 +341,7 @@ def CurlE_exact(x):


def f_exact(x):
f = np.zeros(shape, dtype=np.float)
f = np.zeros(shape, dtype=np.float64)
if dim == 1:
s0 = sin(kappa * x[0] + 0.0 * pi)
s4 = sin(kappa * x[0] + 0.4 * pi)
Expand Down
2 changes: 1 addition & 1 deletion examples/ex31p.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ def CurlE_exact(x):


def f_exact(x):
f = np.zeros(vdim, dtype=np.float)
f = np.zeros(vdim, dtype=np.float64)
if dim == 1:
s0 = sin(kappa * x[0] + 0.0 * pi)
s4 = sin(kappa * x[0] + 0.4 * pi)
Expand Down
2 changes: 1 addition & 1 deletion examples/ex3p.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def EvalValue(self, x):

# 16. Save the refined mesh and the solution in parallel. This output can
# be viewed later using GLVis: "glvis -np <np> -m mesh -g sol".
x.Save('sol.'+smyid)
x.Save('sol.'+smyid, 8)
pmesh.Print('mesh.'+smyid)

# 17. Send the solution by socket to a GLVis server
Expand Down
6 changes: 3 additions & 3 deletions mfem/_par/dist_solver.i
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
%module(package="mfem._par") dist_solver
%{
#include "mfem.hpp"
#include "miniapps/shifted/dist_solver.hpp"
#include "miniapps/common/dist_solver.hpp"
#include "pyoperator.hpp"
#include "../common/pysolvers.hpp"
#include "../common/pycoefficient.hpp"
Expand All @@ -13,7 +13,7 @@ import_array();
%}

%inline %{
#include "miniapps/shifted/dist_solver.cpp"
#include "miniapps/common/dist_solver.cpp"
%}


Expand All @@ -26,5 +26,5 @@ import_array();
%import "pmesh.i"
%import "solvers.i"

%include "miniapps/shifted/dist_solver.hpp"
%include "miniapps/common/dist_solver.hpp"

93 changes: 61 additions & 32 deletions test/run_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ class bcolors:
# special handling of text (needs to be set manually)
ignore_txt_def = ['seconds', 'residual']
ignore_txt_dict = {'ex15p': ['seconds', 'residual', ],
'ex12p' : ['seconds'],
'ex18p': ['time step' ],
'ex12p': ['seconds'],
'ex18p': ['time step'],
'ex10': ['iteration', 'seconds', 'residual', ],
'ex10p': ['iteration', 'seconds', 'residual', 'rtol'],
'ex13p': ['iteration', 'seconds', 'residual', ]}
Expand All @@ -84,7 +84,8 @@ def run_file(command, num=5):
lines, errs = p.communicate()

lines = lines.decode('utf-8').split('\n')
lines = [x for x in lines if not x.startswith('\x1b')] # remove line with ESC
lines = [x for x in lines if not x.startswith(
'\x1b')] # remove line with ESC

# debug print all output....
# print("\n".join(lines))
Expand All @@ -93,6 +94,7 @@ def run_file(command, num=5):
lines = [l for l in lines if len(l.strip()) != 0]
return t2-t1, lines[-num:]


def pad_lines(lines):
length = max([len(l.strip()) for l in lines])
return [l.strip() + " "*(length-len(l.strip())) for l in lines]
Expand Down Expand Up @@ -137,10 +139,11 @@ def compare_results(lines1, lines2, case, verbose=True):
compare.append(flag)
return all(compare)


def do_compare_outputs(dir1, dir2):
files1 = os.listdir(dir1)
files2 = os.listdir(dir2)

unique_file = list(set(files1+files2))
if (len(unique_file) != len(files1) or
len(unique_file) != len(files2)):
Expand All @@ -158,50 +161,77 @@ def do_compare_outputs(dir1, dir2):
if not flag:
return False
continue

if not f in files2:
print("File not found in python outputs", f)
return False
l1 = open(os.path.join(dir1, f), 'r').readlines()
l2 = open(os.path.join(dir2, f), 'r').readlines()

mismatch = 0

# compute average of all the values in file
total = 0
for ll1 in l1:
try:
total = total + sum([abs(float(x)) for x in ll1.split(' ')])
except:
pass

www = total/len(l1)

for ll1, ll2 in zip(l1, l2):
if ll1 != ll2:
try:
# compare 3 digits
d1 = ['%s' % float('%.3g' % float(x)) for x in ll1.split(' ')]
d2 = ['%s' % float('%.3g' % float(x)) for x in ll2.split(' ')]
if d1 == d2:
continue
check = [abs(float(x))/www for x in ll1.split(' ')]
flag = sum([x < 1e-7 for x in check])

# find ratio as number
dd1 = [float(x) for x in ll1.split(' ')]
dd2 = [float(x) for x in ll2.split(' ')]
mratio = max([abs(v1-v2)/abs(v1+v2)
for v1, v2 in zip(dd1, dd2)])

# compare 5 digits in text
d1 = ['%s' % float('%.5g' % float(x))
for x in ll1.split(' ')]
d2 = ['%s' % float('%.5g' % float(x))
for x in ll2.split(' ')]
if d1 != d2 and flag == 0: # and mratio > 1e-7:
print("line with difference", d1, d2, check, maratio)
mismatch += 1
else:
#print("line with difference", d1, d2)
mismatch += 1
#print("line with the same", d1, d2, check)
continue

except:
#print("found a line mismatch :", ll1, ll2)
mismatch += 1
if mismatch > 3:
print("Contents does not agree: ", f)
print("# "+str(mismatch) + " lines do not agree out of "+str(len(l1)))
fail = True
print("Contents does not agree: ", f)
print("# "+str(mismatch) + " lines do not agree out of "+str(len(l1)))
fail = True

if not fail:
print("No difference in generate files (Passed output file check) in " + os.path.basename(dir1))

print("No difference in generate files (Passed output file check) in " +
os.path.basename(dir1))

return not fail

def compare_outputs(case):

def compare_outputs(case):
dir1 = os.path.join(sandbox, case, 'exe')
dir2 = os.path.join(sandbox, case, 'py')
return do_compare_outputs(dir1, dir2)


def run_test(mfem_exes, pymfem_exes, sandbox, serial=True, np=2, verbose=False):
print("mfem examples from : " + os.path.dirname(mfem_exes[0]))
print("PyMFEM examples from : " + os.path.dirname(pymfem_exes[0]))
print(', '.join([os.path.basename(x) for x in mfem_exes]))

cwd = os.getcwd()

if not serial:
comm_mpi = ["mpirun", "-np", str(np)]
else:
Expand All @@ -219,19 +249,19 @@ def run_test(mfem_exes, pymfem_exes, sandbox, serial=True, np=2, verbose=False):
continue
case = os.path.basename(e1)
opts = options_dict.get(case, options_def)

print("Running : " + case)

path = os.path.join(sandbox, case)
os.makedirs(path)
os.chdir(path)
datadir = os.path.join(os.path.dirname(os.path.dirname(e1)), 'data')
os.symlink(datadir, 'data')

path = os.path.join(sandbox, case, 'exe')
os.makedirs(path)
os.chdir(path)

comm = comm_mpi + [e1] + opts
t1, l1 = run_file(comm, num=5)

Expand Down Expand Up @@ -280,7 +310,7 @@ def find_mfem_examples(dir, serial=True, example='all'):
names = [x for x in names if not x.endswith('p')]
else:
names = [x for x in names if x.endswith('p')]

if example != 'all':
names = [n for n in names if n == example]
names = [n for n in names if not n in skip_test]
Expand Down Expand Up @@ -334,7 +364,7 @@ def print_help(self):
help='mfem (parallel) directory')
parser.add_argument('-mfemsdir',
action='store',
default=def_mfemsdir,
default=def_mfemsdir,
help='mfem (serial) directory')
parser.add_argument('-sandbox',
action='store', default="./sandbox",
Expand All @@ -357,9 +387,8 @@ def print_help(self):
if not os.path.exists(os.path.join(mfempdir, "data")) and testp:
assert False, "data file (under par dir) does not exist in the package directory"


sandbox = os.path.abspath(os.path.expanduser(args.sandbox))

if clean:
od = os.getcwd()
files = os.listdir(od)
Expand All @@ -374,7 +403,7 @@ def print_help(self):
shutil.rmtree(sandbox)
sys.exit()
import mfem

if os.path.exists(sandbox):
shutil.rmtree(sandbox)
os.mkdir(sandbox)
Expand Down Expand Up @@ -423,9 +452,9 @@ def print_help(self):
print("Serial Test \t" + bcolors.FAIL +
" ".join(fails) + bcolors.ENDC)
sys.exit(1)
if len(skipped) > 0:
if len(skipped) > 0:
print("Serial Test Skipped due to the lack of Python vesion \t" + bcolors.FAIL +
" ".join(skipped) + bcolors.ENDC)
" ".join(skipped) + bcolors.ENDC)

if testp and len(resultp) != 0:
if all(resultp):
Expand All @@ -438,4 +467,4 @@ def print_help(self):

if len(skippedp) > 0:
print("Parallel Test Skipped due to the lack of Python vesion \t" + bcolors.FAIL +
" ".join(skippedp) + bcolors.ENDC)
" ".join(skippedp) + bcolors.ENDC)