def ifem_solve(root, mu, i): with open('case.xinp') as f: template = Template(f.read()) with open(root / 'case.xinp', 'w') as f: f.write(template.render(geometry='square.g2', **mu)) patch = Surface() patch.set_dimension(3) with G2(str(root / 'square.g2')) as g2: g2.write(patch) try: g2.fstream.close() except: pass result = run([ '/home/eivind/repos/IFEM/Apps/Poisson/build/bin/Poisson', 'case.xinp', '-adap', '-hdf5' ], cwd=root, stdout=PIPE, stderr=PIPE) result.check_returncode() with h5py.File(root / 'case.hdf5', 'r') as h5: final = str(len(h5) - 1) group = h5[final]['Poisson-1'] patchbytes = group['basis']['1'][:].tobytes() geompatch = lr.LRSplineSurface(patchbytes) coeffs = group['fields']['u']['1'][:] solpatch = geompatch.clone() solpatch.controlpoints = coeffs.reshape(len(solpatch), -1) with open(f'poisson-mesh-single-{i}.ps', 'wb') as f: geompatch.write_postscript(f) return geompatch, solpatch