def test_laplace(): props = make_props(petsc=' -iga_elements 1') assert allclose(laplace_test(props),0.03723796978507308) props = make_props(petsc=' -iga_elements 10') assert allclose(laplace_test(props),0.000109646) def laplace_plot(props): petsc = props.petsc() elements = 2**arange(2,7) errors = [] for e in elements: props.petsc.set(petsc+' -iga_elements %d'%e) errors.append(laplace_test(props)) a,b = polyfit(log(elements),log(errors),deg=1) Log.write('slope = %g'%a) import pylab pylab.loglog(elements,errors,'bo-',label='errors') pylab.loglog(elements,exp(a*log(elements)+b),'g-',label='fit') pylab.legend() pylab.show() if __name__=='__main__': props = make_props() parser.parse(props,'Laplace test') print('command = %s'%parser.command(props)) if props.plot(): laplace_plot(props) else: laplace_test(props)
def main(): parser.parse(props,'visualizer') view()
def test_dirichlet_linear(): props = make_props(bc='dirichlet',order=1,resolution=2) u,e = laplace_test(props) assert allclose(e,13/162) assert allclose(u.local_copy(),[13/36,25/36]) def test_dirichlet_quadratic(): props = make_props(bc='dirichlet',order=2,resolution=1) u,e = laplace_test(props) assert allclose(e,0) assert allclose(u.local_copy(),[1/2]) def test_neumann_linear(): props = make_props(bc='neumann',order=1,resolution=1) u,e = laplace_test(props) assert allclose(e,0) # Zero only because of low order quadrature assert allclose(u.local_copy(),asarray([-5,-1,-1,7])/6) def test_neumann_quadratic(): props = make_props(bc='neumann',order=2,resolution=1) u,e = laplace_test(props) assert allclose(e,0) assert allclose(u.local_copy(),asarray([-10,2,2,14,-7,-7,-4,5,5])/12) if __name__=='__main__': props = make_props() parser.parse(props,'Laplace test') print('command = %s'%parser.command(props)) laplace_test(props)
def main(): #Pulls the properties for props parser.parse(props,'visualizer') view_1()
if any([s in props_set for s in 'origin target rotation'.split()]): cam = main.view.cam d = target()-origin() cam.distance = magnitude(d) d = normalized(d) up = normalized(projected_orthogonal_to_unit_direction((0,0,1),d)) cam.frame = Frames(target(),Rotation.from_matrix(vstack([cross(d,up),up,-d]).T.copy())) else: main.view.show_all(True) def dump(): thicken_instances.dump(0) if __name__=='__main__': Log.configure('fractal',0,0,100) props_set = parser.parse(props,'Dragon curve visualizer') if console(): up_frame = Prop('up_frame',Frame.identity(3)) load_misc(props_set) if output(): save_mesh() if mitsuba_dir(): save_mitsuba() else: from OpenGL import GL app = QEApp(sys.argv,True) main = MainWindow(props) main.view.add_scene('dragon',DragonScene()) extra = MeshScene(props,cache(lambda:extra_mesh()[0]),cache(lambda:extra_mesh()[1]),(.1,.3,.9),(.1,.9,.2)) extra.active = cache(lambda:bool(extra_mesh_name())) main.view.add_scene('extra',extra)
if data.shape: return '{'+','.join(cpp_init(format,d) for d in data)+'}' else: return format%data props = PropManager() prefix = props.add('prefix','gen').set_help('directory to store generated files') def save(filename,tables): note = '// Autogenerated by precompute: do not edit directly' for header in 0,1: file = open('%s/%s.%s'%(prefix(),filename,('h' if header else 'cpp')),'w') print>>file, note if header: print>>file, '#pragma once\n\n#include <geode/utility/config.h>\n#include <stdint.h>' else: print>>file, '#include "%s.h"'%filename print>>file, 'namespace pentago {\n' for type,name,format,data in tables: if header: print>>file, 'GEODE_EXPORT extern const %s %s%s;'%(type,name,cpp_sizes(data)) else: print>>file, 'const %s %s%s = %s;'%(type,name,cpp_sizes(data),cpp_init(format,data)) print>>file, '\n}' if __name__=='__main__': parser.parse(props,'Pentago precomputation script',positional=[prefix]) if not os.path.exists(prefix()): os.makedirs(prefix()) save('tables',[t for f in remembered for t in f()])