Peano
Loading...
Searching...
No Matches
test8.py
Go to the documentation of this file.
1import os, sys
2import argparse
3import peano4.api
4import numpy as np
5import mghype
6
7from time import sleep
8
9# custom action set
10from actionsets.test8 import InitDofsTest8
11
12print( """
13 WARNING: implementation file (eg CollocatedPoisson.cpp) must be removed before
14 running this script if you want custom behaviour.
15
16""")
17
18sleep(2)
19
20parser = argparse.ArgumentParser(description='Multigrid - Poisson solver')
21parser.add_argument("-j", "--parallel-builds", dest="j", type=int, default=-1, help="Parallel builds" )
22parser.add_argument("-pt", "--plot-timestep", dest="plot_after_each_mesh_sweep", action="store_true", default=False, help="Plot after each timestep. By default (False) we plot after initialisation and at the end" )
23parser.add_argument("-pd", "--peano-dir", dest="peanodir", default="../../../../", help="Peano4 directory" )
24parser.add_argument("-v", "--verbose", dest="verbose", action="store_true", default=False, help="Verbose")
25parser.add_argument("-d", "--dimensions", dest="dimensions", type=int, default=2, help="Dimensions")
26parser.add_argument("-meshsize", "--meshsize", dest="meshsize", default=0.3, help="Mesh size")
27parser.add_argument("-m", "--mode", dest="mode", choices=["release","stats","asserts", "trace"], required=True, help="Pick build type" )
28args = parser.parse_args()
29
30project = mghype.matrixfree.api.Project( project_name = "CollocatedFEM",
31 namespace = [ "tests", "multigrid", "matrixfree", "verifyRandom" ]
32 )
33
34#! [Construct matrices]
35poisson_equation_matrices = mghype.api.matrixgenerators.DLinear(
36 dimensions = args.dimensions,
37 unknowns_per_node = 1
38)
39
40system_matrix, system_matrix_scaling = poisson_equation_matrices.get_cell_system_matrix_for_laplacian()
41mass_matrix, maxx_matrix_scaling = poisson_equation_matrices.get_cell_mass_matrix()
42#! [Construct matrices]
43
44# Construct custom rhs:
45
46custom_boundary_conditions="""
47 for (int i=0; i<value.size(); i++) {
48 value[i] = 0.0;
49 }
50"""
51
52solver = mghype.matrixfree.solvers.api.CollocatedDLinearDiscretisationWithPointJacobi("CollocatedPoisson",
53 1, # unknowns
54 args.dimensions,
55 args.meshsize,
56 args.meshsize,
57 local_assembly_matrix = system_matrix,
58 local_assembly_matrix_scaling=system_matrix_scaling,
59 mass_matrix = mass_matrix,
60 mass_matrix_scaling = maxx_matrix_scaling,
61 solver_tolerance=1e-6,
62 custom_init_actionset=InitDofsTest8,
63 custom_plot_actionset=[("vu","getVu"), (("vb","getVb"))],
64 custom_boundary_conditions=custom_boundary_conditions
65 )
66
67# need to make sure we have the correct field name to support extra random field
68solver.add_to_vertex_data("vu", 1)
69solver.add_to_vertex_data("vb", 1)
70
71project.add_solver(solver)
72
73#
74# Configure build
75#
76if args.mode=="release":
77 build_mode = peano4.api.output.CompileMode.RELEASE
78if args.mode=="stats":
79 build_mode = peano4.api.output.CompileMode.STATS
80if args.mode=="asserts":
81 build_mode = peano4.api.output.CompileMode.ASSERTS
82if args.mode=="trace":
83 build_mode = peano4.api.output.CompileMode.TRACE
84
85cube_size = 1.0
86project.set_global_simulation_parameters(
87 dimensions = args.dimensions,
88 offset = [ 0.0 for _ in range(args.dimensions) ],
89 domain_size = [ cube_size for _ in range(args.dimensions) ],
90 plot_after_each_mesh_sweep = args.plot_after_each_mesh_sweep,
91 max_iterations = 1
92)
93
94project.set_load_balancing( "toolbox::loadbalancing::RecursiveSubdivision", "new ::exahype2::LoadBalancingConfiguration()" )
95project.set_Peano4_installation( args.peanodir, build_mode )
96
97peano4_project = project.generate_Peano4_project(args.verbose)
98peano4_project.generate()
99
100os.system( "make clean" )
101if args.j>0:
102 os.system( "make -j{}".format(args.j) )
103else:
104 os.system( "make -j" )
105
106print("Done")
107
Simple matrix generator for continuous d-linear finite elements.
Definition DLinear.py:10