Skip to content

Commit 6b6fc00

Browse files
committed
misc: Rename petsc/utils.py
1 parent a4863c8 commit 6b6fc00

9 files changed

Lines changed: 58 additions & 54 deletions

File tree

conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from devito.ir.iet import (FindNodes, FindSymbols, Iteration, ParallelBlock,
1515
retrieve_iteration_tree)
1616
from devito.tools import as_tuple
17-
from devito.petsc.utils import PetscOSError, get_petsc_dir
17+
from devito.petsc.internals import PetscOSError, get_petsc_dir
1818

1919
try:
2020
from mpi4py import MPI # noqa

devito/passes/iet/languages/C.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from devito.symbolics import c_complex, c_double_complex
99
from devito.tools import dtype_to_cstr
1010

11-
from devito.petsc.utils import petsc_type_mappings
11+
from devito.petsc.internals import petsc_type_mappings
1212

1313
__all__ = ['CBB', 'CDataManager', 'COrchestrator']
1414

devito/petsc/iet/callback_builder.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
from devito.ir.iet import (Call, FindSymbols, List, Uxreplace, CallableBody,
44
Dereference, DummyExpr, BlankLine, Callable, Iteration,
55
PointerCast, Definition)
6-
from devito.symbolics import (Byref, FieldFromPointer, IntDiv, Deref, Mod, String, Null, VOID)
6+
from devito.symbolics import (
7+
Byref, FieldFromPointer, IntDiv, Deref, Mod, String, Null, VOID
8+
)
79
from devito.symbolics.unevaluation import Mul
810
from devito.types.basic import AbstractFunction
911
from devito.types import Dimension, Temp, TempArray

devito/petsc/iet/passes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
)
1818
from devito.petsc.types.macros import petsc_func_begin_user
1919
from devito.petsc.iet.nodes import PetscMetaData, petsc_call
20-
from devito.petsc.utils import core_metadata, petsc_languages
20+
from devito.petsc.internals import core_metadata, petsc_languages
2121
from devito.petsc.iet.callback_builder import (
2222
BaseCallback, CoupledCallback, populate_matrix_context, get_user_struct_fields
2323
)

devito/petsc/iet/pre_solver.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,13 @@ def _setup(self):
8383
[sobjs['snes'], Byref(sobjs['ksp'])])
8484

8585
matvec = self.cbbuilder.main_matvec_callback
86-
matvec_operation = petsc_call('MatShellSetOperation',
86+
matvec_operation = petsc_call(
87+
'MatShellSetOperation',
8788
[sobjs['Jac'], 'MATOP_MULT', MatShellSetOp(matvec.name, void, void)]
8889
)
8990
formfunc = self.cbbuilder._F_efunc
90-
formfunc_operation = petsc_call('SNESSetFunction',
91+
formfunc_operation = petsc_call(
92+
'SNESSetFunction',
9193
[sobjs['snes'], Null, FormFunctionCallback(formfunc.name, void, void),
9294
self.snes_ctx]
9395
)
Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
import ctypes
33
from pathlib import Path
44

5-
from devito.tools import memoized_func, filter_ordered, as_tuple
6-
from devito.types import Symbol, SteppingDimension, TimeDimension
7-
from devito.operations.solve import eval_time_derivatives
8-
from devito.symbolics import retrieve_functions, retrieve_dimensions
5+
from devito.tools import memoized_func
96

107

118
class PetscOSError(OSError):
@@ -106,43 +103,3 @@ def get_petsc_type_mappings():
106103

107104

108105
petsc_languages = ['petsc']
109-
110-
111-
def get_funcs(exprs):
112-
funcs = [
113-
f for e in exprs
114-
for f in retrieve_functions(eval_time_derivatives(e.lhs - e.rhs))
115-
]
116-
return as_tuple(filter_ordered(funcs))
117-
118-
119-
def generate_time_mapper(exprs):
120-
"""
121-
Replace time indices with `Symbols` in expressions used within
122-
PETSc callback functions. These symbols are Uxreplaced at the IET
123-
level to align with the `TimeDimension` and `ModuloDimension` objects
124-
present in the initial lowering.
125-
NOTE: All functions used in PETSc callback functions are attached to
126-
the `SolverMetaData` object, which is passed through the initial lowering
127-
(and subsequently dropped and replaced with calls to run the solver).
128-
Therefore, the appropriate time loop will always be correctly generated inside
129-
the main kernel.
130-
Examples
131-
--------
132-
>>> exprs = (Eq(f1(t + dt, x, y), g1(t + dt, x, y) + g2(t, x, y)*f1(t, x, y)),)
133-
>>> generate_time_mapper(exprs)
134-
{t + dt: tau0, t: tau1}
135-
"""
136-
# First, map any actual TimeDimensions
137-
time_indices = [d for d in retrieve_dimensions(exprs) if isinstance(d, TimeDimension)]
138-
139-
funcs = get_funcs(exprs)
140-
141-
time_indices.extend(list({
142-
i if isinstance(d, SteppingDimension) else d
143-
for f in funcs
144-
for i, d in zip(f.indices, f.dimensions)
145-
if d.is_Time
146-
}))
147-
tau_symbs = [Symbol('tau%d' % i) for i in range(len(time_indices))]
148-
return dict(zip(time_indices, tau_symbs))

devito/petsc/logging.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from devito.petsc.types import (
88
PetscInt, PetscScalar, KSPType, KSPConvergedReason, KSPNormType
99
)
10-
from devito.petsc.utils import petsc_type_to_ctype
10+
from devito.petsc.internals import petsc_type_to_ctype
1111

1212

1313
class PetscEntry:

devito/petsc/solve.py

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
from devito.types.equation import PetscEq
2-
from devito.tools import as_tuple
2+
from devito.tools import filter_ordered, as_tuple
3+
from devito.types import Symbol, SteppingDimension, TimeDimension
4+
from devito.operations.solve import eval_time_derivatives
5+
from devito.symbolics import retrieve_functions, retrieve_dimensions
6+
37
from devito.petsc.types import (LinearSolverMetaData, PETScArray, DMDALocalInfo,
48
FieldData, MultipleFieldData, Jacobian, Residual,
59
MixedResidual, MixedJacobian, InitialGuess)
610
from devito.petsc.types.equation import EssentialBC
711
from devito.petsc.solver_parameters import (linear_solver_parameters,
812
format_options_prefix)
9-
from devito.petsc.utils import get_funcs, generate_time_mapper
1013

1114

1215
__all__ = ['PETScSolve']
@@ -186,5 +189,45 @@ def linear_solve_args(self):
186189
return targets[0], funcs, all_data
187190

188191

192+
def get_funcs(exprs):
193+
funcs = [
194+
f for e in exprs
195+
for f in retrieve_functions(eval_time_derivatives(e.lhs - e.rhs))
196+
]
197+
return as_tuple(filter_ordered(funcs))
198+
199+
200+
def generate_time_mapper(exprs):
201+
"""
202+
Replace time indices with `Symbols` in expressions used within
203+
PETSc callback functions. These symbols are Uxreplaced at the IET
204+
level to align with the `TimeDimension` and `ModuloDimension` objects
205+
present in the initial lowering.
206+
NOTE: All functions used in PETSc callback functions are attached to
207+
the `SolverMetaData` object, which is passed through the initial lowering
208+
(and subsequently dropped and replaced with calls to run the solver).
209+
Therefore, the appropriate time loop will always be correctly generated inside
210+
the main kernel.
211+
Examples
212+
--------
213+
>>> exprs = (Eq(f1(t + dt, x, y), g1(t + dt, x, y) + g2(t, x, y)*f1(t, x, y)),)
214+
>>> generate_time_mapper(exprs)
215+
{t + dt: tau0, t: tau1}
216+
"""
217+
# First, map any actual TimeDimensions
218+
time_indices = [d for d in retrieve_dimensions(exprs) if isinstance(d, TimeDimension)]
219+
220+
funcs = get_funcs(exprs)
221+
222+
time_indices.extend(list({
223+
i if isinstance(d, SteppingDimension) else d
224+
for f in funcs
225+
for i, d in zip(f.indices, f.dimensions)
226+
if d.is_Time
227+
}))
228+
tau_symbs = [Symbol('tau%d' % i) for i in range(len(time_indices))]
229+
return dict(zip(time_indices, tau_symbs))
230+
231+
189232
localinfo = DMDALocalInfo(name='info', liveness='eager')
190233
prefixes = ['y', 'x', 'f', 'b']

devito/petsc/types/metadata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from devito.types.equation import Eq
99
from devito.operations.solve import eval_time_derivatives
1010

11-
from devito.petsc.utils import petsc_variables
11+
from devito.petsc.internals import petsc_variables
1212
from devito.petsc.types.equation import EssentialBC, ZeroRow, ZeroColumn
1313

1414

0 commit comments

Comments
 (0)