|
5 | 5 | switchconfig) |
6 | 6 | from devito.petsc import PETScSolve |
7 | 7 | from devito.petsc.initialize import PetscInitialize |
8 | | -import petsctools |
9 | | -from petsctools import get_commandline_options, OptionsManager, flatten_parameters |
10 | 8 | configuration['compiler'] = 'custom' |
11 | 9 | os.environ['CC'] = 'mpicc' |
12 | 10 |
|
|
34 | 32 |
|
35 | 33 | eq = Eq(v, u.laplace, subdomain=grid.interior) |
36 | 34 |
|
37 | | -solver = PETScSolve([eq], u, solver_parameters={'ksp_rtol': 1e-8}, options_prefix='poisson') |
| 35 | +solver = PETScSolve([eq], u) |
38 | 36 |
|
39 | | -with switchconfig(language='petsc'): |
| 37 | +with switchconfig(language='petsc', opt='noop'): |
40 | 38 | op = Operator(solver) |
41 | 39 | op.apply() |
42 | | - print(op.ccode) |
43 | | - |
44 | | - |
45 | | -# import sys |
46 | | -# petsctools.options._commandline_options = sys.argv[1:] |
47 | | -# tmp = get_commandline_options() |
48 | | -# print("Command line options:", tmp) |
49 | | - |
50 | | - |
51 | | - |
52 | | -# class DevitoOptionsManager(OptionsManager): |
53 | | -# """ |
54 | | -# """ |
55 | | -# def __init__(self, parameters, options_prefix): |
56 | | -# if parameters is None: |
57 | | -# parameters = {} |
58 | | -# else: |
59 | | -# # Convert nested dicts |
60 | | -# parameters = flatten_parameters(parameters) |
61 | | -# if options_prefix is None: |
62 | | -# self.options_prefix = "firedrake_%d_" % next(self.count) |
63 | | -# self.parameters = parameters |
64 | | -# self.to_delete = set(parameters) |
65 | | -# else: |
66 | | -# if len(options_prefix) and not options_prefix.endswith("_"): |
67 | | -# options_prefix += "_" |
68 | | -# self.options_prefix = options_prefix |
69 | | -# # Remove those options from the dict that were passed on |
70 | | -# # the commandline. |
71 | | -# self.parameters = { |
72 | | -# k: v |
73 | | -# for k, v in parameters.items() |
74 | | -# if options_prefix + k not in get_commandline_options() |
75 | | -# } |
76 | | -# self.to_delete = set(self.parameters) |
77 | | -# # Now update parameters from options, so that they're |
78 | | -# # available to solver setup (for, e.g., matrix-free). |
79 | | -# # Can't ask for the prefixed guy in the options object, |
80 | | -# # since that does not DTRT for flag options. |
81 | | -# # for k, v in self.options_object.getAll().items(): |
82 | | -# # if k.startswith(self.options_prefix): |
83 | | -# # self.parameters[k[len(self.options_prefix):]] = v |
84 | | - |
85 | | -# for k, v in get_commandline_options(): |
86 | | -# if k.startswith(self.options_prefix): |
87 | | -# self.parameters[k[len(self.options_prefix):]] = v |
88 | | -# self._setfromoptions = False |
89 | | - |
90 | | - |
91 | | - |
92 | | -# options_manager = DevitoOptionsManager(solver.rhs.solver_parameters, solver.rhs.options_prefix) |
93 | | - |
94 | | - |
95 | | -# nested = {"ksp_type": "cg", |
96 | | -# "pc_type": "fieldsplit", |
97 | | -# "fieldsplit_0": {"ksp_type": "gmres", |
98 | | -# "pc_type": "hypre", |
99 | | -# "ksp_rtol": 1e-5}, |
100 | | -# "fieldsplit_1": {"ksp_type": "richardson", |
101 | | -# "pc_type": "ilu"}} |
102 | | - |
103 | | -# tmp = flatten_parameters(nested) |
104 | | -# # from IPython import embed; embed() |
105 | | - |
106 | | -# # convert all values into strings |
107 | | - |
108 | | -# tmp_str = {k: str(v) for k, v in tmp.items()} |
| 40 | + # print(op.ccode) |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | +grid = Grid(shape=(11, 11), dtype=np.float64) |
| 47 | +functions = [Function(name=n, grid=grid, space_order=2) |
| 48 | + for n in ['e', 'f']] |
| 49 | +e, f = functions |
| 50 | + |
| 51 | +eq = Eq(e.laplace, f) |
| 52 | + |
| 53 | +petsc = PETScSolve(eq, target=e, solver_parameters={'snes_view': None}) |
| 54 | + |
| 55 | +with switchconfig(language='petsc'): |
| 56 | + op = Operator(petsc) |
| 57 | + op.apply() |
| 58 | + |
| 59 | +assert 'PetscCall(SetPetscOption("-snes_view",NULL));' \ |
| 60 | + in str(op._func_table['SetPetscOptions0'].root) |
| 61 | + |
| 62 | +from devito.petsc.solver_parameters import linear_solve_defaults |
| 63 | + |
| 64 | + |
109 | 65 |
|
| 66 | +from IPython import embed; embed() |
110 | 67 |
|
111 | 68 |
|
112 | 69 |
|
0 commit comments