diff --git a/demos/multicomponent/multicomponent.py.rst b/demos/multicomponent/multicomponent.py.rst index 04178b608c..ebf4e9f3b7 100644 --- a/demos/multicomponent/multicomponent.py.rst +++ b/demos/multicomponent/multicomponent.py.rst @@ -22,6 +22,7 @@ The chemicals then mix in the center of the container and exit through an outlet We use :doc:`netgen ` to build a curved mesh of order :math:`k=3`:: from firedrake import * + from firedrake.petsc import PETSc import netgen.occ as ngocc # The polynomial order we will use for our curved mesh and finite element spaces diff --git a/firedrake/__init__.py b/firedrake/__init__.py index 70dec1d6ca..b0c3eae993 100644 --- a/firedrake/__init__.py +++ b/firedrake/__init__.py @@ -45,8 +45,8 @@ def init_petsc(): del atexit del petsc -from ufl import * -from finat.ufl import * +from ufl import * # noqa: F401 +from finat.ufl import * # noqa: F401 from pyop2 import op2 # noqa: F401 from pyop2.mpi import COMM_WORLD, COMM_SELF # noqa: F401 @@ -56,41 +56,110 @@ def init_petsc(): petsctools.cite("FiredrakeUserManual") del petsctools -from firedrake.assemble import * -from firedrake.bcs import * -from firedrake.checkpointing import * -from firedrake.cofunction import * -from firedrake.constant import * -from firedrake.deflation import * -from firedrake.exceptions import * -from firedrake.function import * -from firedrake.functionspace import * -from firedrake.interpolation import * -from firedrake.linear_solver import * -from firedrake.preconditioners import * -from firedrake.mesh import * -from firedrake.mg.mesh import * -from firedrake.mg.interface import * -from firedrake.mg.embedded import * -from firedrake.mg.opencascade_mh import * -from firedrake.norms import * -from firedrake.nullspace import * -from firedrake.parameters import * -from firedrake.parloops import * -from firedrake.projection import * -from firedrake.slate import * -from firedrake.slope_limiter import * -from firedrake.solving import * -from firedrake.ufl_expr import * -from firedrake.utility_meshes import * -from firedrake.variational_solver import * -from firedrake.eigensolver import * -from firedrake.ensemble import * -from firedrake.randomfunctiongen import * -from firedrake.external_operators import * +from firedrake.assemble import assemble # noqa: F401 +from firedrake.bcs import DirichletBC, homogenize, EquationBC # noqa: F401 +from firedrake.checkpointing import ( # noqa: F401 + DumbCheckpoint, HDF5File, FILE_READ, FILE_CREATE, + FILE_UPDATE, CheckpointFile +) +from firedrake.cofunction import Cofunction, RieszMap # noqa: F401 +from firedrake.constant import Constant # noqa: F401 +from firedrake.deflation import DeflatedSNES, Deflation # noqa: F401 +from firedrake.exceptions import ConvergenceError # noqa: F401 +from firedrake.function import ( # noqa: F401 + Function, PointNotInDomainError, + CoordinatelessFunction, PointEvaluator +) +from firedrake.functionspace import ( # noqa: F401 + MixedFunctionSpace, FunctionSpace, VectorFunctionSpace, + TensorFunctionSpace, RestrictedFunctionSpace +) +from firedrake.interpolation import ( # noqa: F401 + interpolate, Interpolate, Interpolator, DofNotDefinedError, + CrossMeshInterpolator, SameMeshInterpolator +) +from firedrake.linear_solver import LinearSolver # noqa: F401 +from firedrake.preconditioners import ( # noqa: F401 + PCBase, SNESBase, PCSNESBase, ASMPatchPC, ASMStarPC, ASMVankaPC, + ASMLinesmoothPC, ASMExtrudedStarPC, AssembledPC, AuxiliaryOperatorPC, + MassInvPC, PCDPC, PatchPC, PlaneSmoother, PatchSNES, P1PC, P1SNES, + LORPC, GTMGPC, PMGPC, PMGSNES, HypreAMS, HypreADS, FDMPC, + PoissonFDMPC, TwoLevelPC, HiptmairPC, FacetSplitPC, BDDCPC +) +from firedrake.mesh import ( # noqa: F401 + Mesh, ExtrudedMesh, VertexOnlyMesh, RelabeledMesh, + SubDomainData, unmarked, DistributedMeshOverlapType, + DEFAULT_MESH_NAME, MeshGeometry, MeshTopology, + AbstractMeshTopology, ExtrudedMeshTopology, Submesh, + VertexOnlyMeshTopology, VertexOnlyMeshMissingPointsError, + MeshSequenceGeometry, MeshSequenceTopology +) +from firedrake.mg import ( # noqa: F401 + HierarchyBase, MeshHierarchy, ExtrudedMeshHierarchy, + NonNestedHierarchy, SemiCoarsenedExtrudedHierarchy, + prolong, restrict, inject, TransferManager, + OpenCascadeMeshHierarchy +) +from firedrake.norms import errornorm, norm # noqa: F401 +from firedrake.nullspace import VectorSpaceBasis, MixedVectorSpaceBasis # noqa: F401 +from firedrake.parameters import ( # noqa: F401 + Parameters, parameters, disable_performance_optimisations +) +from firedrake.parloops import ( # noqa: F401 + par_loop, direct, READ, WRITE, RW, INC, MIN, MAX +) +from firedrake.projection import ( # noqa: F401 + project, Projector +) +from firedrake.slate import ( # noqa: F401 + AssembledVector, Block, Factorization, Tensor, Inverse, + Transpose, Negative, Add, Mul, Solve, BlockAssembledVector, + DiagonalTensor, Reciprocal, HybridizationPC, SchurComplementBuilder, + SCPC, TensorOp +) +from firedrake.slope_limiter import ( # noqa: F401 + Limiter, VertexBasedLimiter +) +from firedrake.solving import solve # noqa: F401 +from firedrake.ufl_expr import ( # noqa: F401 + Argument, Coargument, TestFunction, TrialFunction, + TestFunctions, TrialFunctions, derivative, adjoint, + action, CellSize, FacetNormal +) +from firedrake.utility_meshes import ( # noqa: F401 + IntervalMesh, UnitIntervalMesh, PeriodicIntervalMesh, + PeriodicUnitIntervalMesh, UnitTriangleMesh, RectangleMesh, + TensorRectangleMesh, SquareMesh, UnitSquareMesh, PeriodicRectangleMesh, + PeriodicSquareMesh, PeriodicUnitSquareMesh, CircleManifoldMesh, + UnitDiskMesh, UnitBallMesh, UnitTetrahedronMesh, TensorBoxMesh, + BoxMesh, CubeMesh, UnitCubeMesh, PeriodicBoxMesh, PeriodicUnitCubeMesh, + IcosahedralSphereMesh, UnitIcosahedralSphereMesh, OctahedralSphereMesh, + UnitOctahedralSphereMesh, CubedSphereMesh, UnitCubedSphereMesh, + TorusMesh, AnnulusMesh, SolidTorusMesh, CylinderMesh +) +from firedrake.variational_solver import ( # noqa: F401 + LinearVariationalProblem, LinearVariationalSolver, + NonlinearVariationalProblem, NonlinearVariationalSolver +) +from firedrake.eigensolver import ( # noqa: F401 + LinearEigenproblem, LinearEigensolver +) +from firedrake.ensemble import ( # noqa: F401 + Ensemble, EnsembleFunction, EnsembleCofunction, + EnsembleFunctionSpace, EnsembleDualSpace +) +from firedrake.randomfunctiongen import * # noqa: F401 +from firedrake.external_operators import ( # noqa: F401 + AbstractExternalOperator, assemble_method, + PointexprOperator, point_expr, MLOperator +) from firedrake.progress_bar import ProgressBar # noqa: F401 -from firedrake.logging import * +from firedrake.logging import ( # noqa: F401 + set_level, set_log_handlers, set_log_level, DEBUG, INFO, + WARNING, ERROR, CRITICAL, log, debug, info, warning, error, + critical, info_red, info_green, info_blue, RED, GREEN, BLUE +) # Set default log level set_log_level(WARNING) set_log_handlers(comm=COMM_WORLD) @@ -100,10 +169,10 @@ def init_petsc(): # Once `File` is deprecated update the above line removing `File` and add # from firedrake._deprecation import output # sys.modules["firedrake.output"] = output -from firedrake.output import * +from firedrake.output import * # noqa: F401 import sys sys.modules["firedrake.plot"] = plot -from firedrake.plot import * +from firedrake.plot import * # noqa: F401 del sys diff --git a/firedrake/adjoint/__init__.py b/firedrake/adjoint/__init__.py index d3d28e6129..04a1a63f4d 100644 --- a/firedrake/adjoint/__init__.py +++ b/firedrake/adjoint/__init__.py @@ -17,41 +17,46 @@ else: raise ImportError("'backend' module already exists?") -from pyadjoint.tape import Tape, set_working_tape, get_working_tape, \ - pause_annotation, continue_annotation, \ - stop_annotating, annotate_tape # noqa F401 +from pyadjoint.tape import ( # noqa: F401 + Tape, set_working_tape, get_working_tape, pause_annotation, + continue_annotation, stop_annotating, annotate_tape +) from pyadjoint.reduced_functional import ReducedFunctional # noqa F401 from pyadjoint.checkpointing import disk_checkpointing_callback # noqa F401 -from firedrake.adjoint_utils.checkpointing import \ - enable_disk_checkpointing, pause_disk_checkpointing, \ - continue_disk_checkpointing, stop_disk_checkpointing, \ - checkpointable_mesh # noqa F401 +from firedrake.adjoint_utils.checkpointing import ( # noqa: F401 + enable_disk_checkpointing, pause_disk_checkpointing, + continue_disk_checkpointing, stop_disk_checkpointing, + checkpointable_mesh +) from firedrake.adjoint_utils import get_solve_blocks # noqa F401 - from pyadjoint.verification import taylor_test, taylor_to_dict # noqa F401 from pyadjoint.drivers import compute_gradient, compute_derivative, compute_hessian # noqa F401 from pyadjoint.adjfloat import AdjFloat # noqa F401 from pyadjoint.control import Control # noqa F401 -from pyadjoint import IPOPTSolver, ROLSolver, MinimizationProblem, \ - InequalityConstraint, minimize # noqa F401 - -from firedrake.adjoint.ufl_constraints import UFLInequalityConstraint, \ - UFLEqualityConstraint # noqa F401 +from pyadjoint import ( # noqa: F401 + IPOPTSolver, ROLSolver, MinimizationProblem, InequalityConstraint, minimize +) +from firedrake.adjoint.ufl_constraints import ( # noqa: F401 + UFLInequalityConstraint, UFLEqualityConstraint +) from firedrake.adjoint.ensemble_reduced_functional import EnsembleReducedFunctional # noqa F401 import numpy_adjoint # noqa F401 import firedrake.ufl_expr -import types -import sys - # Work around the name clash of firedrake.adjoint vs ufl.adjoint. # This will eventually become cleaner once we can rely on users having # Python 3.12 (see PEP 713). +import types + + class _AdjointModule(types.ModuleType): def __call__(self, form): return firedrake.ufl_expr.adjoint(form) +del types + sys.modules[__name__].__class__ = _AdjointModule +del sys set_working_tape(Tape()) diff --git a/firedrake/adjoint_utils/__init__.py b/firedrake/adjoint_utils/__init__.py index fba6df5d74..e1a31c8f1b 100644 --- a/firedrake/adjoint_utils/__init__.py +++ b/firedrake/adjoint_utils/__init__.py @@ -5,11 +5,19 @@ :mod:`firedrake.adjoint`. """ -from firedrake.adjoint_utils.function import * # noqa: F401 -from firedrake.adjoint_utils.assembly import * # noqa: F401 -from firedrake.adjoint_utils.projection import * # noqa: F401 -from firedrake.adjoint_utils.variational_solver import * # noqa: F401 -from firedrake.adjoint_utils.solving import * # noqa: F401 -from firedrake.adjoint_utils.mesh import * # noqa: F401 -from firedrake.adjoint_utils.checkpointing import * # noqa: F401 -from firedrake.adjoint_utils.ensemble_function import * # noqa: F401 +from firedrake.adjoint_utils.function import ( # noqa F401 + FunctionMixin, CofunctionMixin +) +from firedrake.adjoint_utils.assembly import annotate_assemble # noqa F401 +from firedrake.adjoint_utils.projection import annotate_project # noqa F401 +from firedrake.adjoint_utils.variational_solver import ( # noqa F401 + NonlinearVariationalProblemMixin, NonlinearVariationalSolverMixin +) +from firedrake.adjoint_utils.solving import annotate_solve, get_solve_blocks # noqa F401 +from firedrake.adjoint_utils.mesh import MeshGeometryMixin # noqa F401 +from firedrake.adjoint_utils.checkpointing import ( # noqa F401 + enable_disk_checkpointing, disk_checkpointing, + pause_disk_checkpointing, continue_disk_checkpointing, + stop_disk_checkpointing, checkpointable_mesh +) +from firedrake.adjoint_utils.ensemble_function import EnsembleFunctionMixin # noqa F401 diff --git a/firedrake/adjoint_utils/blocks/__init__.py b/firedrake/adjoint_utils/blocks/__init__.py index bf83b896cc..3bbc926ce9 100644 --- a/firedrake/adjoint_utils/blocks/__init__.py +++ b/firedrake/adjoint_utils/blocks/__init__.py @@ -1,9 +1,12 @@ -from .assembly import AssembleBlock # NOQA F401 -from .solving import GenericSolveBlock, SolveLinearSystemBlock, \ - ProjectBlock, SupermeshProjectBlock, SolveVarFormBlock, \ - NonlinearVariationalSolveBlock # NOQA F401 -from .function import FunctionAssignBlock, FunctionMergeBlock, \ - SubfunctionBlock # NOQA F401 -from .dirichlet_bc import DirichletBCBlock # NOQA F401 -from .constant import ConstantAssignBlock # NOQA F401 -from .mesh import MeshInputBlock, MeshOutputBlock # NOQA F401 +from firedrake.adjoint_utils.blocks.assembly import AssembleBlock # noqa F401 +from firedrake.adjoint_utils.blocks.solving import ( # noqa F401 + GenericSolveBlock, SolveLinearSystemBlock, ProjectBlock, + SupermeshProjectBlock, SolveVarFormBlock, + NonlinearVariationalSolveBlock +) +from firedrake.adjoint_utils.blocks.function import ( # noqa F401 + FunctionAssignBlock, FunctionMergeBlock, SubfunctionBlock +) +from firedrake.adjoint_utils.blocks.dirichlet_bc import DirichletBCBlock # noqa F401 +from firedrake.adjoint_utils.blocks.constant import ConstantAssignBlock # noqa F401 +from firedrake.adjoint_utils.blocks.mesh import MeshInputBlock, MeshOutputBlock # noqa F401 diff --git a/firedrake/assemble.py b/firedrake/assemble.py index 2992fad9d9..ee6df3bbe0 100644 --- a/firedrake/assemble.py +++ b/firedrake/assemble.py @@ -624,7 +624,7 @@ def base_form_assembly_visitor(self, expr, tensor, bcs, *args): interpolator = firedrake.Interpolator(expr, V, bcs=bcs, **interp_data) # Assembly return interpolator.assemble(tensor=tensor, default_missing_val=default_missing_val) - elif tensor and isinstance(expr, (firedrake.Function, firedrake.Cofunction, firedrake.MatrixBase)): + elif tensor and isinstance(expr, (firedrake.Function, firedrake.Cofunction, matrix.MatrixBase)): return tensor.assign(expr) elif tensor and isinstance(expr, ufl.ZeroBaseForm): return tensor.zero() diff --git a/firedrake/ensemble/__init__.py b/firedrake/ensemble/__init__.py index 6662a06f72..82e3fde3bd 100644 --- a/firedrake/ensemble/__init__.py +++ b/firedrake/ensemble/__init__.py @@ -1,3 +1,7 @@ -from firedrake.ensemble.ensemble import * # noqa: F401 -from firedrake.ensemble.ensemble_function import * # noqa: F401 -from firedrake.ensemble.ensemble_functionspace import * # noqa: F401 +from firedrake.ensemble.ensemble import Ensemble # noqa F401 +from firedrake.ensemble.ensemble_function import ( # noqa F401 + EnsembleFunction, EnsembleCofunction +) +from firedrake.ensemble.ensemble_functionspace import ( # noqa F401 + EnsembleFunctionSpace, EnsembleDualSpace +) diff --git a/firedrake/external_operators/__init__.py b/firedrake/external_operators/__init__.py index 363751d49b..8f2e6717f5 100644 --- a/firedrake/external_operators/__init__.py +++ b/firedrake/external_operators/__init__.py @@ -1,3 +1,7 @@ -from firedrake.external_operators.abstract_external_operators import * # noqa: F401 -from firedrake.external_operators.point_expr_operator import * # noqa: F401 -from firedrake.external_operators.ml_operator import * # noqa: F401 +from firedrake.external_operators.abstract_external_operators import ( # noqa F401 + AbstractExternalOperator, assemble_method +) +from firedrake.external_operators.point_expr_operator import ( # noqa F401 + PointexprOperator, point_expr +) +from firedrake.external_operators.ml_operator import MLOperator # noqa F401 diff --git a/firedrake/fml/__init__.py b/firedrake/fml/__init__.py index d0f951305d..56d86fd9c1 100644 --- a/firedrake/fml/__init__.py +++ b/firedrake/fml/__init__.py @@ -1,2 +1,7 @@ -from firedrake.fml.form_manipulation_language import * # noqa -from firedrake.fml.replacement import * # noqa +from firedrake.fml.form_manipulation_language import ( # noqa F401 + Label, Term, LabelledForm, identity, drop, all_terms, + keep, subject, name_label +) +from firedrake.fml.replacement import ( # noqa F401 + replace_test_function, replace_trial_function, replace_subject +) diff --git a/firedrake/interpolation.py b/firedrake/interpolation.py index 0ead02b064..24ce9bc377 100644 --- a/firedrake/interpolation.py +++ b/firedrake/interpolation.py @@ -29,6 +29,7 @@ from firedrake.mesh import MissingPointsBehaviour, VertexOnlyMeshMissingPointsError, VertexOnlyMeshTopology from firedrake.petsc import PETSc from firedrake.halo import _get_mtype as get_dat_mpi_type +from firedrake.matrix import AssembledMatrix from mpi4py import MPI from pyadjoint import stop_annotating, no_annotations @@ -370,7 +371,7 @@ def assemble(self, tensor=None, default_missing_val=None): petsc_mat.copy(tensor.petscmat) else: res = petsc_mat - return tensor or firedrake.AssembledMatrix(arguments, self.bcs, res) + return tensor or AssembledMatrix(arguments, self.bcs, res) else: # Assembling the action cofunctions = () @@ -1727,7 +1728,7 @@ def _assemble_matnest(self): for i in self: blocks[i] = self[i].callable().handle petscmat = PETSc.Mat().createNest(blocks) - tensor = firedrake.AssembledMatrix(self.arguments, self.bcs, petscmat) + tensor = AssembledMatrix(self.arguments, self.bcs, petscmat) return tensor.M def _interpolate(self, *function, output=None, adjoint=False, **kwargs): diff --git a/firedrake/mg/__init__.py b/firedrake/mg/__init__.py index f5e043c3d1..3aa6c7e021 100644 --- a/firedrake/mg/__init__.py +++ b/firedrake/mg/__init__.py @@ -1,4 +1,9 @@ -from .mesh import * # noqa: F401 -from .interface import * # noqa: F401 -from .embedded import * # noqa: F401 -from .opencascade_mh import * # noqa: F401 +from firedrake.mg.mesh import ( # noqa F401 + HierarchyBase, MeshHierarchy, ExtrudedMeshHierarchy, + NonNestedHierarchy, SemiCoarsenedExtrudedHierarchy +) +from firedrake.mg.interface import ( # noqa F401 + prolong, restrict, inject +) +from firedrake.mg.embedded import TransferManager # noqa F401 +from firedrake.mg.opencascade_mh import OpenCascadeMeshHierarchy # noqa F401 diff --git a/firedrake/output/__init__.py b/firedrake/output/__init__.py index 409149cccf..eaf15ce6cd 100644 --- a/firedrake/output/__init__.py +++ b/firedrake/output/__init__.py @@ -1,5 +1,5 @@ try: import vtkmodules.vtkCommonDataModel # noqa: F401 - from .vtk_output import VTKFile # noqa: F401 + from firedrake.output.vtk_output import VTKFile # noqa: F401 except ModuleNotFoundError: - from .vtk_unavailable import VTKFile # noqa: F401 + from firedrake.output.vtk_unavailable import VTKFile # noqa: F401 diff --git a/firedrake/preconditioners/__init__.py b/firedrake/preconditioners/__init__.py index 491a73657b..eb37e4f61b 100644 --- a/firedrake/preconditioners/__init__.py +++ b/firedrake/preconditioners/__init__.py @@ -1,15 +1,26 @@ -from firedrake.preconditioners.base import * # noqa: F401 -from firedrake.preconditioners.asm import * # noqa: F401 -from firedrake.preconditioners.assembled import * # noqa: F401 -from firedrake.preconditioners.massinv import * # noqa: F401 -from firedrake.preconditioners.pcd import * # noqa: F401 -from firedrake.preconditioners.patch import * # noqa: F401 -from firedrake.preconditioners.low_order import * # noqa: F401 -from firedrake.preconditioners.gtmg import * # noqa: F401 -from firedrake.preconditioners.pmg import * # noqa: F401 -from firedrake.preconditioners.hypre_ams import * # noqa: F401 -from firedrake.preconditioners.hypre_ads import * # noqa: F401 -from firedrake.preconditioners.fdm import * # noqa: F401 -from firedrake.preconditioners.hiptmair import * # noqa: F401 -from firedrake.preconditioners.facet_split import * # noqa: F401 -from firedrake.preconditioners.bddc import * # noqa: F401 +from firedrake.preconditioners.base import ( # noqa: F401 + PCBase, SNESBase, PCSNESBase +) +from firedrake.preconditioners.asm import ( # noqa: F401 + ASMPatchPC, ASMStarPC, ASMVankaPC, + ASMLinesmoothPC, ASMExtrudedStarPC +) +from firedrake.preconditioners.assembled import ( # noqa: F401 + AssembledPC, AuxiliaryOperatorPC +) +from firedrake.preconditioners.massinv import MassInvPC # noqa: F401 +from firedrake.preconditioners.pcd import PCDPC # noqa: F401 +from firedrake.preconditioners.patch import ( # noqa: F401 + PatchPC, PlaneSmoother, PatchSNES +) +from firedrake.preconditioners.low_order import ( # noqa: F401 + P1PC, P1SNES, LORPC +) +from firedrake.preconditioners.gtmg import GTMGPC # noqa: F401 +from firedrake.preconditioners.pmg import PMGPC, PMGSNES # noqa: F401 +from firedrake.preconditioners.hypre_ams import HypreAMS # noqa: F401 +from firedrake.preconditioners.hypre_ads import HypreADS # noqa: F401 +from firedrake.preconditioners.fdm import FDMPC, PoissonFDMPC # noqa: F401 +from firedrake.preconditioners.hiptmair import TwoLevelPC, HiptmairPC # noqa: F401 +from firedrake.preconditioners.facet_split import FacetSplitPC # noqa: F401 +from firedrake.preconditioners.bddc import BDDCPC # noqa: F401 diff --git a/firedrake/pyplot/__init__.py b/firedrake/pyplot/__init__.py index ae91f23f2e..2eb6de5976 100644 --- a/firedrake/pyplot/__init__.py +++ b/firedrake/pyplot/__init__.py @@ -1,8 +1,8 @@ -from .mpl import ( +from firedrake.pyplot.mpl import ( plot, triplot, tricontourf, tricontour, trisurf, tripcolor, quiver, streamplot, FunctionPlotter ) -from .pgf import pgfplot +from firedrake.pyplot.pgf import pgfplot __all__ = [ "plot", "triplot", "tricontourf", "tricontour", "trisurf", "tripcolor", diff --git a/firedrake/slate/__init__.py b/firedrake/slate/__init__.py index b54e4a1446..af3993a88a 100644 --- a/firedrake/slate/__init__.py +++ b/firedrake/slate/__init__.py @@ -1,2 +1,8 @@ -from firedrake.slate.slate import * # noqa: F401 -from firedrake.slate.static_condensation import * # noqa: F401 +from firedrake.slate.slate import ( # noqa: F401 + AssembledVector, Block, Factorization, Tensor, Inverse, + Transpose, Negative, Add, Mul, Solve, BlockAssembledVector, + DiagonalTensor, Reciprocal, TensorOp, TensorBase +) +from firedrake.slate.static_condensation import ( # noqa: F401 + HybridizationPC, SchurComplementBuilder, SCPC +) diff --git a/firedrake/slate/slac/__init__.py b/firedrake/slate/slac/__init__.py index 33016cea08..7d7a5e6a07 100644 --- a/firedrake/slate/slac/__init__.py +++ b/firedrake/slate/slac/__init__.py @@ -1 +1 @@ -from firedrake.slate.slac.compiler import * # noqa: F401 +from firedrake.slate.slac.compiler import compile_expression # noqa: F401 diff --git a/firedrake/slate/static_condensation/__init__.py b/firedrake/slate/static_condensation/__init__.py index 53debc0caf..b37bc83da4 100644 --- a/firedrake/slate/static_condensation/__init__.py +++ b/firedrake/slate/static_condensation/__init__.py @@ -1,2 +1,4 @@ -from firedrake.slate.static_condensation.hybridization import * # noqa: F401 -from firedrake.slate.static_condensation.scpc import * # noqa: F401 +from firedrake.slate.static_condensation.hybridization import ( # noqa: F401 + HybridizationPC, SchurComplementBuilder +) +from firedrake.slate.static_condensation.scpc import SCPC # noqa: F401 diff --git a/firedrake/slope_limiter/__init__.py b/firedrake/slope_limiter/__init__.py index e72ee1d4d1..eaba2f087b 100644 --- a/firedrake/slope_limiter/__init__.py +++ b/firedrake/slope_limiter/__init__.py @@ -1,2 +1,2 @@ -from firedrake.slope_limiter.limiter import * # noqa: F401 -from firedrake.slope_limiter.vertex_based_limiter import * # noqa: F401 +from firedrake.slope_limiter.limiter import Limiter # noqa: F401 +from firedrake.slope_limiter.vertex_based_limiter import VertexBasedLimiter # noqa: F401 diff --git a/firedrake/utility_meshes.py b/firedrake/utility_meshes.py index 7b1818c2de..f75cd514ae 100644 --- a/firedrake/utility_meshes.py +++ b/firedrake/utility_meshes.py @@ -30,9 +30,13 @@ real ) from firedrake.cython import dmcommon -from firedrake import mesh -from firedrake import function -from firedrake import functionspace +from firedrake.mesh import ( + Mesh, DistributedMeshOverlapType, DEFAULT_MESH_NAME, + plex_from_cell_list, _generate_default_mesh_topology_name, + _generate_default_mesh_coordinates_name, MeshTopology, + make_mesh_from_mesh_topology, RelabeledMesh, + make_mesh_from_coordinates, ExtrudedMesh +) from firedrake.parameters import parameters from firedrake.petsc import PETSc @@ -76,7 +80,7 @@ distribution_parameters_no_overlap = {"partition": True, - "overlap_type": (mesh.DistributedMeshOverlapType.NONE, 0)} + "overlap_type": (DistributedMeshOverlapType.NONE, 0)} reorder_noop = False @@ -92,7 +96,7 @@ def _postprocess_periodic_mesh(coords, comm, distribution_parameters, reorder, n V.finat_element, V.dm.getLocalSection(), coords.dat._vec) - return mesh.Mesh( + return Mesh( dm, comm=comm, distribution_parameters=distribution_parameters, @@ -111,7 +115,7 @@ def IntervalMesh( distribution_parameters=None, reorder=False, comm=COMM_WORLD, - name=mesh.DEFAULT_MESH_NAME, + name=DEFAULT_MESH_NAME, distribution_name=None, permutation_name=None, ): @@ -159,8 +163,8 @@ def IntervalMesh( np.arange(1, len(coords), dtype=np.int32), ) ).reshape(-1, 2) - plex = mesh.plex_from_cell_list( - 1, cells, coords, comm, mesh._generate_default_mesh_topology_name(name) + plex = plex_from_cell_list( + 1, cells, coords, comm, _generate_default_mesh_topology_name(name) ) # Apply boundary IDs plex.createLabel(dmcommon.FACE_SETS_LABEL) @@ -174,7 +178,7 @@ def IntervalMesh( if vcoord[0] == coords[-1]: plex.setLabelValue(dmcommon.FACE_SETS_LABEL, v, 2) - m = mesh.Mesh( + m = Mesh( plex, reorder=reorder, distribution_parameters=distribution_parameters, @@ -192,7 +196,7 @@ def UnitIntervalMesh( distribution_parameters=None, reorder=False, comm=COMM_WORLD, - name=mesh.DEFAULT_MESH_NAME, + name=DEFAULT_MESH_NAME, distribution_name=None, permutation_name=None, ): @@ -235,7 +239,7 @@ def PeriodicIntervalMesh( distribution_parameters=None, reorder=False, comm=COMM_WORLD, - name=mesh.DEFAULT_MESH_NAME, + name=DEFAULT_MESH_NAME, distribution_name=None, permutation_name=None, ): @@ -275,7 +279,7 @@ def PeriodicIntervalMesh( m, FiniteElement("DG", interval, 1, variant="equispaced"), dim=1 ) new_coordinates = Function( - coord_fs, name=mesh._generate_default_mesh_coordinates_name(name) + coord_fs, name=_generate_default_mesh_coordinates_name(name) ) x, y = SpatialCoordinate(m) eps = 1.e-14 @@ -303,7 +307,7 @@ def PeriodicUnitIntervalMesh( distribution_parameters=None, reorder=False, comm=COMM_WORLD, - name=mesh.DEFAULT_MESH_NAME, + name=DEFAULT_MESH_NAME, distribution_name=None, permutation_name=None, ): @@ -341,7 +345,7 @@ def OneElementThickMesh( Ly, distribution_parameters=None, comm=COMM_WORLD, - name=mesh.DEFAULT_MESH_NAME, + name=DEFAULT_MESH_NAME, distribution_name=None, permutation_name=None, ): @@ -373,10 +377,10 @@ def OneElementThickMesh( coords = np.array([X, Y]).T # a line of coordinates, with a looped topology - plex = mesh.plex_from_cell_list( - 2, cells, coords, comm, mesh._generate_default_mesh_topology_name(name) + plex = plex_from_cell_list( + 2, cells, coords, comm, _generate_default_mesh_topology_name(name) ) - tmesh1 = mesh.MeshTopology( + tmesh1 = MeshTopology( plex, plex.getName(), reorder=parameters["reorder_meshes"], @@ -481,14 +485,14 @@ def OneElementThickMesh( cell_closure[row][0:4] = [v1, v1, v2, v2] tmesh1.cell_closure = np.array(cell_closure, dtype=IntType) - mesh1 = mesh.make_mesh_from_mesh_topology(tmesh1, "temp") + mesh1 = make_mesh_from_mesh_topology(tmesh1, "temp") fe_dg = FiniteElement("DQ", mesh1.ufl_cell(), 1, variant="equispaced") Vc = VectorFunctionSpace(mesh1, fe_dg) fc = Function( - Vc, name=mesh._generate_default_mesh_coordinates_name(name) + Vc, name=_generate_default_mesh_coordinates_name(name) ).interpolate(mesh1.coordinates) - mash = mesh.Mesh( + mash = Mesh( fc, name=name, distribution_name=distribution_name, @@ -525,7 +529,7 @@ def UnitTriangleMesh( refinement_level=0, distribution_parameters=None, comm=COMM_WORLD, - name=mesh.DEFAULT_MESH_NAME, + name=DEFAULT_MESH_NAME, distribution_name=None, permutation_name=None, ): @@ -545,7 +549,7 @@ def UnitTriangleMesh( """ coords = [[0.0, 0.0], [1.0, 0.0], [0.0, 1.0]] cells = [[0, 1, 2]] - plex = mesh.plex_from_cell_list(2, cells, coords, comm) + plex = plex_from_cell_list(2, cells, coords, comm) # mark boundary facets plex.createLabel(dmcommon.FACE_SETS_LABEL) @@ -571,8 +575,8 @@ def UnitTriangleMesh( for i in range(refinement_level): plex = plex.refine() - plex.setName(mesh._generate_default_mesh_topology_name(name)) - return mesh.Mesh( + plex.setName(_generate_default_mesh_topology_name(name)) + return Mesh( plex, reorder=False, distribution_parameters=distribution_parameters, @@ -596,7 +600,7 @@ def RectangleMesh( diagonal="left", distribution_parameters=None, comm=COMM_WORLD, - name=mesh.DEFAULT_MESH_NAME, + name=DEFAULT_MESH_NAME, distribution_name=None, permutation_name=None, ): @@ -660,7 +664,7 @@ def TensorRectangleMesh( diagonal="left", distribution_parameters=None, comm=COMM_WORLD, - name=mesh.DEFAULT_MESH_NAME, + name=DEFAULT_MESH_NAME, distribution_name=None, permutation_name=None, ): @@ -735,8 +739,8 @@ def TensorRectangleMesh( # two cells per cell above... cells = cells[:, idx].reshape(-1, 3) - plex = mesh.plex_from_cell_list( - 2, cells, coords, comm, mesh._generate_default_mesh_topology_name(name) + plex = plex_from_cell_list( + 2, cells, coords, comm, _generate_default_mesh_topology_name(name) ) # mark boundary facets @@ -763,7 +767,7 @@ def TensorRectangleMesh( if abs(face_coords[1] - y1) < ytol and abs(face_coords[3] - y1) < ytol: plex.setLabelValue(dmcommon.FACE_SETS_LABEL, face, 4) plex.removeLabel("boundary_faces") - m = mesh.Mesh( + m = Mesh( plex, reorder=reorder, distribution_parameters=distribution_parameters, @@ -785,7 +789,7 @@ def SquareMesh( diagonal="left", distribution_parameters=None, comm=COMM_WORLD, - name=mesh.DEFAULT_MESH_NAME, + name=DEFAULT_MESH_NAME, distribution_name=None, permutation_name=None, ): @@ -839,7 +843,7 @@ def UnitSquareMesh( quadrilateral=False, distribution_parameters=None, comm=COMM_WORLD, - name=mesh.DEFAULT_MESH_NAME, + name=DEFAULT_MESH_NAME, distribution_name=None, permutation_name=None, ): @@ -894,7 +898,7 @@ def PeriodicRectangleMesh( distribution_parameters=None, diagonal=None, comm=COMM_WORLD, - name=mesh.DEFAULT_MESH_NAME, + name=DEFAULT_MESH_NAME, distribution_name=None, permutation_name=None, ): @@ -989,7 +993,7 @@ def PeriodicRectangleMesh( m, FiniteElement(coord_family, cell, 1, variant="equispaced"), dim=2 ) new_coordinates = Function( - coord_fs, name=mesh._generate_default_mesh_coordinates_name(name) + coord_fs, name=_generate_default_mesh_coordinates_name(name) ) x, y, z = SpatialCoordinate(m) eps = 1.e-14 @@ -1034,7 +1038,7 @@ def PeriodicSquareMesh( distribution_parameters=None, diagonal=None, comm=COMM_WORLD, - name=mesh.DEFAULT_MESH_NAME, + name=DEFAULT_MESH_NAME, distribution_name=None, permutation_name=None, ): @@ -1097,7 +1101,7 @@ def PeriodicUnitSquareMesh( distribution_parameters=None, diagonal=None, comm=COMM_WORLD, - name=mesh.DEFAULT_MESH_NAME, + name=DEFAULT_MESH_NAME, distribution_name=None, permutation_name=None, ): @@ -1156,7 +1160,7 @@ def CircleManifoldMesh( distribution_parameters=None, reorder=False, comm=COMM_WORLD, - name=mesh.DEFAULT_MESH_NAME, + name=DEFAULT_MESH_NAME, distribution_name=None, permutation_name=None, ): @@ -1196,10 +1200,10 @@ def CircleManifoldMesh( ) ) - plex = mesh.plex_from_cell_list( - 1, cells, vertices, comm, mesh._generate_default_mesh_topology_name(name) + plex = plex_from_cell_list( + 1, cells, vertices, comm, _generate_default_mesh_topology_name(name) ) - m = mesh.Mesh( + m = Mesh( plex, dim=2, reorder=reorder, @@ -1210,15 +1214,13 @@ def CircleManifoldMesh( comm=comm, ) if degree > 1: - new_coords = function.Function( - functionspace.VectorFunctionSpace(m, "CG", degree) - ) + new_coords = Function(VectorFunctionSpace(m, "CG", degree)) new_coords.interpolate(ufl.SpatialCoordinate(m)) # "push out" to circle new_coords.dat.data[:] *= ( radius / np.linalg.norm(new_coords.dat.data, axis=1) ).reshape(-1, 1) - m = mesh.Mesh( + m = Mesh( new_coords, name=name, distribution_name=distribution_name, @@ -1235,7 +1237,7 @@ def UnitDiskMesh( reorder=None, distribution_parameters=None, comm=COMM_WORLD, - name=mesh.DEFAULT_MESH_NAME, + name=DEFAULT_MESH_NAME, distribution_name=None, permutation_name=None, ): @@ -1273,8 +1275,8 @@ def UnitDiskMesh( np.int32, ) - plex = mesh.plex_from_cell_list( - 2, cells, vertices, comm, mesh._generate_default_mesh_topology_name(name) + plex = plex_from_cell_list( + 2, cells, vertices, comm, _generate_default_mesh_topology_name(name) ) # mark boundary facets @@ -1296,7 +1298,7 @@ def UnitDiskMesh( t = np.max(np.abs(x)) / norm x[:] *= t - m = mesh.Mesh( + m = Mesh( plex, dim=2, reorder=reorder, @@ -1315,7 +1317,7 @@ def UnitBallMesh( reorder=None, distribution_parameters=None, comm=COMM_WORLD, - name=mesh.DEFAULT_MESH_NAME, + name=DEFAULT_MESH_NAME, distribution_name=None, permutation_name=None, ): @@ -1361,8 +1363,8 @@ def UnitBallMesh( np.int32, ) - plex = mesh.plex_from_cell_list( - 3, cells, vertices, comm, mesh._generate_default_mesh_topology_name(name) + plex = plex_from_cell_list( + 3, cells, vertices, comm, _generate_default_mesh_topology_name(name) ) plex.createLabel(dmcommon.FACE_SETS_LABEL) @@ -1383,7 +1385,7 @@ def UnitBallMesh( t = np.sum(np.abs(x)) / norm x[:] *= t - m = mesh.Mesh( + m = Mesh( plex, dim=3, reorder=reorder, @@ -1399,7 +1401,7 @@ def UnitBallMesh( @PETSc.Log.EventDecorator() def UnitTetrahedronMesh( comm=COMM_WORLD, - name=mesh.DEFAULT_MESH_NAME, + name=DEFAULT_MESH_NAME, distribution_name=None, permutation_name=None, ): @@ -1416,10 +1418,10 @@ def UnitTetrahedronMesh( """ coords = [[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]] cells = [[0, 1, 2, 3]] - plex = mesh.plex_from_cell_list( - 3, cells, coords, comm, mesh._generate_default_mesh_topology_name(name) + plex = plex_from_cell_list( + 3, cells, coords, comm, _generate_default_mesh_topology_name(name) ) - m = mesh.Mesh( + m = Mesh( plex, reorder=False, name=name, @@ -1438,7 +1440,7 @@ def TensorBoxMesh( distribution_parameters=None, diagonal="default", comm=COMM_WORLD, - name=mesh.DEFAULT_MESH_NAME, + name=DEFAULT_MESH_NAME, distribution_name=None, permutation_name=None, ): @@ -1526,8 +1528,8 @@ def TensorBoxMesh( ) else: raise ValueError("Unrecognised value for diagonal '%r'", diagonal) - plex = mesh.plex_from_cell_list( - 3, cells, coords, comm, mesh._generate_default_mesh_topology_name(name) + plex = plex_from_cell_list( + 3, cells, coords, comm, _generate_default_mesh_topology_name(name) ) nvert = 3 # num. vertices on facet @@ -1565,7 +1567,7 @@ def TensorBoxMesh( if all([abs(face_coords[2 + cdim * i] - z1) < ztol for i in range(nvert)]): plex.setLabelValue(dmcommon.FACE_SETS_LABEL, face, 6) plex.removeLabel("boundary_faces") - m = mesh.Mesh( + m = Mesh( plex, reorder=reorder, distribution_parameters=distribution_parameters, @@ -1590,7 +1592,7 @@ def BoxMesh( distribution_parameters=None, diagonal="default", comm=COMM_WORLD, - name=mesh.DEFAULT_MESH_NAME, + name=DEFAULT_MESH_NAME, distribution_name=None, permutation_name=None, ): @@ -1655,7 +1657,7 @@ def BoxMesh( if all([abs(face_coords[2 + cdim * i] - Lz) < ztol for i in range(nvert)]): plex.setLabelValue(dmcommon.FACE_SETS_LABEL, face, 6) plex.removeLabel("boundary_faces") - m = mesh.Mesh( + m = Mesh( plex, reorder=reorder, distribution_parameters=distribution_parameters, @@ -1693,7 +1695,7 @@ def CubeMesh( reorder=None, distribution_parameters=None, comm=COMM_WORLD, - name=mesh.DEFAULT_MESH_NAME, + name=DEFAULT_MESH_NAME, distribution_name=None, permutation_name=None, ): @@ -1751,7 +1753,7 @@ def UnitCubeMesh( reorder=None, distribution_parameters=None, comm=COMM_WORLD, - name=mesh.DEFAULT_MESH_NAME, + name=DEFAULT_MESH_NAME, distribution_name=None, permutation_name=None, ): @@ -1810,7 +1812,7 @@ def PeriodicBoxMesh( reorder=None, distribution_parameters=None, comm=COMM_WORLD, - name=mesh.DEFAULT_MESH_NAME, + name=DEFAULT_MESH_NAME, distribution_name=None, permutation_name=None, ): @@ -1887,7 +1889,7 @@ def PeriodicBoxMesh( sparseLocalize=False, comm=comm, ) - m = mesh.Mesh( + m = Mesh( plex, reorder=reorder, distribution_parameters=distribution_parameters, @@ -1916,7 +1918,7 @@ def PeriodicBoxMesh( else: fz0 = Function(V).interpolate(conditional(z < eps, 1., 0.)) fz1 = Function(V).interpolate(conditional(z > Lz - eps, 1., 0.)) - return mesh.RelabeledMesh(m, [fx0, fx1, fy0, fy1, fz0, fz1], [1, 2, 3, 4, 5, 6], name=name) + return RelabeledMesh(m, [fx0, fx1, fy0, fy1, fz0, fz1], [1, 2, 3, 4, 5, 6], name=name) else: if tuple(directions) != (True, True, True): raise NotImplementedError("Can only specify directions with hexahedral = True") @@ -1949,10 +1951,10 @@ def PeriodicBoxMesh( [v0, v2, v6, v7], ] cells = np.asarray(cells).reshape(-1, ny, nx, nz).swapaxes(0, 3).reshape(-1, 4) - plex = mesh.plex_from_cell_list( - 3, cells, coords, comm, mesh._generate_default_mesh_topology_name(name) + plex = plex_from_cell_list( + 3, cells, coords, comm, _generate_default_mesh_topology_name(name) ) - m = mesh.Mesh( + m = Mesh( plex, reorder=reorder_noop, distribution_parameters=distribution_parameters_no_overlap, @@ -1966,7 +1968,7 @@ def PeriodicBoxMesh( VectorFunctionSpace( m, FiniteElement("DG", tetrahedron, 1, variant="equispaced") ), - name=mesh._generate_default_mesh_coordinates_name(name), + name=_generate_default_mesh_coordinates_name(name), ) new_coordinates.interpolate(m.coordinates) @@ -2007,7 +2009,7 @@ def PeriodicUnitCubeMesh( reorder=None, distribution_parameters=None, comm=COMM_WORLD, - name=mesh.DEFAULT_MESH_NAME, + name=DEFAULT_MESH_NAME, distribution_name=None, permutation_name=None, ): @@ -2086,7 +2088,7 @@ def IcosahedralSphereMesh( reorder=None, distribution_parameters=None, comm=COMM_WORLD, - name=mesh.DEFAULT_MESH_NAME, + name=DEFAULT_MESH_NAME, distribution_name=None, permutation_name=None, ): @@ -2170,16 +2172,16 @@ def IcosahedralSphereMesh( dtype=np.int32, ) - plex = mesh.plex_from_cell_list(2, faces, vertices, comm) + plex = plex_from_cell_list(2, faces, vertices, comm) plex.setRefinementUniform(True) for i in range(refinement_level): plex = plex.refine() - plex.setName(mesh._generate_default_mesh_topology_name(name)) + plex.setName(_generate_default_mesh_topology_name(name)) coords = plex.getCoordinatesLocal().array.reshape(-1, 3) scale = (radius / np.linalg.norm(coords, axis=1)).reshape(-1, 1) coords *= scale - m = mesh.Mesh( + m = Mesh( plex, dim=3, reorder=reorder, @@ -2190,15 +2192,13 @@ def IcosahedralSphereMesh( comm=comm, ) if degree > 1: - new_coords = function.Function( - functionspace.VectorFunctionSpace(m, "CG", degree) - ) + new_coords = Function(VectorFunctionSpace(m, "CG", degree)) new_coords.interpolate(ufl.SpatialCoordinate(m)) # "push out" to sphere new_coords.dat.data[:] *= ( radius / np.linalg.norm(new_coords.dat.data, axis=1) ).reshape(-1, 1) - m = mesh.Mesh( + m = Mesh( new_coords, name=name, distribution_name=distribution_name, @@ -2216,7 +2216,7 @@ def UnitIcosahedralSphereMesh( reorder=None, distribution_parameters=None, comm=COMM_WORLD, - name=mesh.DEFAULT_MESH_NAME, + name=DEFAULT_MESH_NAME, distribution_name=None, permutation_name=None, ): @@ -2263,7 +2263,7 @@ def OctahedralSphereMesh( reorder=None, distribution_parameters=None, comm=COMM_WORLD, - name=mesh.DEFAULT_MESH_NAME, + name=DEFAULT_MESH_NAME, distribution_name=None, permutation_name=None, ): @@ -2332,14 +2332,14 @@ def OctahedralSphereMesh( for new, idx in enumerate(indices): faces[faces == idx] = new - plex = mesh.plex_from_cell_list(2, faces, vertices, comm) + plex = plex_from_cell_list(2, faces, vertices, comm) plex.setRefinementUniform(True) for i in range(refinement_level): plex = plex.refine() - plex.setName(mesh._generate_default_mesh_topology_name(name)) + plex.setName(_generate_default_mesh_topology_name(name)) # build the initial mesh - m = mesh.Mesh( + m = Mesh( plex, dim=3, reorder=reorder, @@ -2352,7 +2352,7 @@ def OctahedralSphereMesh( if degree > 1: # use it to build a higher-order mesh m = assemble(interpolate(ufl.SpatialCoordinate(m), VectorFunctionSpace(m, "CG", degree))) - m = mesh.Mesh( + m = Mesh( m, name=name, distribution_name=distribution_name, @@ -2417,7 +2417,7 @@ def UnitOctahedralSphereMesh( reorder=None, distribution_parameters=None, comm=COMM_WORLD, - name=mesh.DEFAULT_MESH_NAME, + name=DEFAULT_MESH_NAME, distribution_name=None, permutation_name=None, ): @@ -2599,7 +2599,7 @@ def CubedSphereMesh( reorder=None, distribution_parameters=None, comm=COMM_WORLD, - name=mesh.DEFAULT_MESH_NAME, + name=DEFAULT_MESH_NAME, distribution_name=None, permutation_name=None, ): @@ -2629,11 +2629,11 @@ def CubedSphereMesh( raise ValueError("Mesh coordinate degree must be at least 1") cells, coords = _cubedsphere_cells_and_coords(radius, refinement_level) - plex = mesh.plex_from_cell_list( - 2, cells, coords, comm, mesh._generate_default_mesh_topology_name(name) + plex = plex_from_cell_list( + 2, cells, coords, comm, _generate_default_mesh_topology_name(name) ) - m = mesh.Mesh( + m = Mesh( plex, dim=3, reorder=reorder, @@ -2645,15 +2645,13 @@ def CubedSphereMesh( ) if degree > 1: - new_coords = function.Function( - functionspace.VectorFunctionSpace(m, "Q", degree) - ) + new_coords = Function(VectorFunctionSpace(m, "Q", degree)) new_coords.interpolate(ufl.SpatialCoordinate(m)) # "push out" to sphere new_coords.dat.data[:] *= ( radius / np.linalg.norm(new_coords.dat.data, axis=1) ).reshape(-1, 1) - m = mesh.Mesh( + m = Mesh( new_coords, distribution_name=distribution_name, permutation_name=permutation_name, @@ -2670,7 +2668,7 @@ def UnitCubedSphereMesh( reorder=None, distribution_parameters=None, comm=COMM_WORLD, - name=mesh.DEFAULT_MESH_NAME, + name=DEFAULT_MESH_NAME, distribution_name=None, permutation_name=None, ): @@ -2713,7 +2711,7 @@ def TorusMesh( reorder=None, distribution_parameters=None, comm=COMM_WORLD, - name=mesh.DEFAULT_MESH_NAME, + name=DEFAULT_MESH_NAME, distribution_name=None, permutation_name=None, ): @@ -2780,10 +2778,10 @@ def TorusMesh( # two cells per cell above... cells = cells[:, [0, 1, 3, 1, 2, 3]].reshape(-1, 3) - plex = mesh.plex_from_cell_list( - 2, cells, vertices, comm, mesh._generate_default_mesh_topology_name(name) + plex = plex_from_cell_list( + 2, cells, vertices, comm, _generate_default_mesh_topology_name(name) ) - m = mesh.Mesh( + m = Mesh( plex, dim=3, reorder=reorder, @@ -2804,7 +2802,7 @@ def AnnulusMesh( nt=32, distribution_parameters=None, comm=COMM_WORLD, - name=mesh.DEFAULT_MESH_NAME, + name=DEFAULT_MESH_NAME, distribution_name=None, permutation_name=None, ): @@ -2836,12 +2834,12 @@ def AnnulusMesh( name=base_name, distribution_name=distribution_name, permutation_name=permutation_name) - bar = mesh.ExtrudedMesh(base, layers=nt, layer_height=2 * np.pi / nt, extrusion_type="uniform", periodic=True) + bar = ExtrudedMesh(base, layers=nt, layer_height=2 * np.pi / nt, extrusion_type="uniform", periodic=True) x, y = ufl.SpatialCoordinate(bar) V = bar.coordinates.function_space() coord = Function(V).interpolate(ufl.as_vector([x * ufl.cos(y), x * ufl.sin(y)])) - annulus = mesh.make_mesh_from_coordinates(coord.topological, name) - annulus.topology.name = mesh._generate_default_mesh_topology_name(name) + annulus = make_mesh_from_coordinates(coord.topological, name) + annulus.topology.name = _generate_default_mesh_topology_name(name) annulus._base_mesh = base return annulus @@ -2855,7 +2853,7 @@ def SolidTorusMesh( reorder=None, distribution_parameters=None, comm=COMM_WORLD, - name=mesh.DEFAULT_MESH_NAME, + name=DEFAULT_MESH_NAME, distribution_name=None, permutation_name=None, ): @@ -2889,15 +2887,15 @@ def SolidTorusMesh( x, y = ufl.SpatialCoordinate(unit) V = unit.coordinates.function_space() coord = Function(V).interpolate(ufl.as_vector([r * x + R, r * y])) - disk = mesh.make_mesh_from_coordinates(coord.topological, base_name) - disk.topology.name = mesh._generate_default_mesh_topology_name(base_name) + disk = make_mesh_from_coordinates(coord.topological, base_name) + disk.topology.name = _generate_default_mesh_topology_name(base_name) disk.topology.topology_dm.setName(disk.topology.name) - bar = mesh.ExtrudedMesh(disk, layers=nR, layer_height=2 * np.pi / nR, extrusion_type="uniform", periodic=True) + bar = ExtrudedMesh(disk, layers=nR, layer_height=2 * np.pi / nR, extrusion_type="uniform", periodic=True) x, y, z = ufl.SpatialCoordinate(bar) V = bar.coordinates.function_space() coord = Function(V).interpolate(ufl.as_vector([x * ufl.cos(z), x * ufl.sin(z), -y])) - torus = mesh.make_mesh_from_coordinates(coord.topological, name) - torus.topology.name = mesh._generate_default_mesh_topology_name(name) + torus = make_mesh_from_coordinates(coord.topological, name) + torus.topology.name = _generate_default_mesh_topology_name(name) torus._base_mesh = disk return torus @@ -2914,7 +2912,7 @@ def CylinderMesh( distribution_parameters=None, diagonal=None, comm=COMM_WORLD, - name=mesh.DEFAULT_MESH_NAME, + name=DEFAULT_MESH_NAME, distribution_name=None, permutation_name=None, ): @@ -3033,8 +3031,8 @@ def CylinderMesh( elif longitudinal_direction != "z": raise ValueError("Unknown longitudinal direction '%s'" % longitudinal_direction) - plex = mesh.plex_from_cell_list( - 2, cells, vertices, comm, mesh._generate_default_mesh_topology_name(name) + plex = plex_from_cell_list( + 2, cells, vertices, comm, _generate_default_mesh_topology_name(name) ) plex.createLabel(dmcommon.FACE_SETS_LABEL) @@ -3058,7 +3056,7 @@ def CylinderMesh( plex.setLabelValue(dmcommon.FACE_SETS_LABEL, face, 2) plex.removeLabel("boundary_faces") - return mesh.Mesh( + return Mesh( plex, dim=3, reorder=reorder, @@ -3082,7 +3080,7 @@ def PartiallyPeriodicRectangleMesh( distribution_parameters=None, diagonal=None, comm=COMM_WORLD, - name=mesh.DEFAULT_MESH_NAME, + name=DEFAULT_MESH_NAME, distribution_name=None, permutation_name=None, ): @@ -3153,7 +3151,7 @@ def PartiallyPeriodicRectangleMesh( m, FiniteElement(coord_family, cell, 1, variant="equispaced"), dim=2 ) new_coordinates = Function( - coord_fs, name=mesh._generate_default_mesh_coordinates_name(name) + coord_fs, name=_generate_default_mesh_coordinates_name(name) ) x, y, z = SpatialCoordinate(m) eps = 1.e-14 diff --git a/tests/firedrake/adjoint/test_optimisation.py b/tests/firedrake/adjoint/test_optimisation.py index 2189a7882b..62c6ee5964 100644 --- a/tests/firedrake/adjoint/test_optimisation.py +++ b/tests/firedrake/adjoint/test_optimisation.py @@ -3,8 +3,10 @@ from enum import Enum, auto from numpy.testing import assert_allclose import numpy as np +from ufl.duals import is_primal from firedrake import * from firedrake.adjoint import * +from firedrake.petsc import PETSc from pyadjoint import Block, MinimizationProblem, TAOSolver, get_working_tape from pyadjoint.optimization.tao_solver import PETScVecInterface import petsctools @@ -192,9 +194,9 @@ def transform(v, transform_type, *args, mfn_parameters=None, **kwargs): mfn_parameters = dict(mfn_parameters) space = v.function_space() - if not ufl.duals.is_primal(space): + if not is_primal(space): space = space.dual() - if not ufl.duals.is_primal(space): + if not is_primal(space): raise NotImplementedError("Mixed primal/dual space case not implemented") comm = v.comm @@ -243,7 +245,7 @@ def mult(self, A, x, y): if mfn.getConvergedReason() <= 0: raise RuntimeError("Convergence failure") - if ufl.duals.is_primal(v): + if is_primal(v): u = Function(space) else: u = Cofunction(space.dual()) diff --git a/tests/firedrake/adjoint/test_reduced_functional.py b/tests/firedrake/adjoint/test_reduced_functional.py index 5184e94b70..4e33915258 100644 --- a/tests/firedrake/adjoint/test_reduced_functional.py +++ b/tests/firedrake/adjoint/test_reduced_functional.py @@ -1,11 +1,10 @@ import pytest +import numpy as np from firedrake import * from firedrake.adjoint import * from pytest_mpi.parallel_assert import parallel_assert -from numpy.random import rand - @pytest.fixture(autouse=True) def handle_taping(): @@ -66,7 +65,7 @@ def test_function(): Jhat = ReducedFunctional(J, Control(f)) h = Function(V) - h.dat.data[:] = rand(V.dof_dset.size) + h.dat.data[:] = np.random.rand(V.dof_dset.size) assert taylor_test(Jhat, f, h) > 1.9 diff --git a/tests/firedrake/ensemble/test_ensemble_manual.py b/tests/firedrake/ensemble/test_ensemble_manual.py index 59c6b0ee8e..2dd65098fa 100644 --- a/tests/firedrake/ensemble/test_ensemble_manual.py +++ b/tests/firedrake/ensemble/test_ensemble_manual.py @@ -82,6 +82,8 @@ def test_ensemble_manual_example(): # [test_ensemble_manual_example 7 <] # [test_ensemble_manual_example 8 >] + from firedrake.petsc import PETSc + with efunc.vec_ro() as vec: PETSc.Sys.Print(f"{vec.norm()=}") # [test_ensemble_manual_example 8 <] diff --git a/tests/firedrake/external_operators/test_external_operators.py b/tests/firedrake/external_operators/test_external_operators.py index f3ae664782..f4db50fc86 100644 --- a/tests/firedrake/external_operators/test_external_operators.py +++ b/tests/firedrake/external_operators/test_external_operators.py @@ -3,6 +3,7 @@ import ufl from firedrake import * +from firedrake.matrix import MatrixBase @pytest.fixture(scope='module') diff --git a/tests/firedrake/multigrid/test_p_multigrid.py b/tests/firedrake/multigrid/test_p_multigrid.py index 8541c190e5..a78727de37 100644 --- a/tests/firedrake/multigrid/test_p_multigrid.py +++ b/tests/firedrake/multigrid/test_p_multigrid.py @@ -1,4 +1,5 @@ import pytest +import numpy as np from firedrake import * diff --git a/tests/firedrake/multigrid/test_poisson_gtmg.py b/tests/firedrake/multigrid/test_poisson_gtmg.py index a4154dd392..5d5203579d 100644 --- a/tests/firedrake/multigrid/test_poisson_gtmg.py +++ b/tests/firedrake/multigrid/test_poisson_gtmg.py @@ -1,4 +1,5 @@ from firedrake import * +from firedrake.petsc import PETSc import pytest diff --git a/tests/firedrake/regression/test_assemble.py b/tests/firedrake/regression/test_assemble.py index 9972715746..6fe9d115d1 100644 --- a/tests/firedrake/regression/test_assemble.py +++ b/tests/firedrake/regression/test_assemble.py @@ -3,6 +3,7 @@ from firedrake import * from firedrake.assemble import TwoFormAssembler from firedrake.utils import ScalarType, IntType +from firedrake.petsc import PETSc @pytest.fixture(scope='module') diff --git a/tests/firedrake/regression/test_bddc.py b/tests/firedrake/regression/test_bddc.py index c111c07181..06f28425be 100644 --- a/tests/firedrake/regression/test_bddc.py +++ b/tests/firedrake/regression/test_bddc.py @@ -1,4 +1,5 @@ import pytest +import numpy as np from firedrake import * from firedrake.petsc import DEFAULT_DIRECT_SOLVER @@ -106,7 +107,7 @@ def solve_riesz_map(rg, mesh, family, degree, variant, bcs, cellwise=False, cond a = (inner(u, v) + inner(d(u), d(v))) * dx u_exact = rg.uniform(V, -1, 1) - L = ufl.replace(a, {u: u_exact}) + L = replace(a, {u: u_exact}) bcs = [DirichletBC(V, u_exact, sub) for sub in dirichlet_ids] nsp = None if formdegree == 0: diff --git a/tests/firedrake/regression/test_constant.py b/tests/firedrake/regression/test_constant.py index 3dd40ed068..0c89c85b73 100644 --- a/tests/firedrake/regression/test_constant.py +++ b/tests/firedrake/regression/test_constant.py @@ -287,7 +287,7 @@ def test_constant_ufl2unicode(): _ = ufl2unicode(dFda) _ = ufl2unicode(dFdb) - dFda_du = derivative(F, u=a, du=ufl.classes.IntValue(1)) - dFdb_du = derivative(F, u=b, du=ufl.classes.IntValue(1)) + dFda_du = derivative(F, u=a, du=IntValue(1)) + dFdb_du = derivative(F, u=b, du=IntValue(1)) _ = ufl2unicode(dFda_du) _ = ufl2unicode(dFdb_du) diff --git a/tests/firedrake/regression/test_fdm.py b/tests/firedrake/regression/test_fdm.py index 872b5eeb9b..a2245b72e4 100644 --- a/tests/firedrake/regression/test_fdm.py +++ b/tests/firedrake/regression/test_fdm.py @@ -2,7 +2,7 @@ import numpy from firedrake import * from pyop2.utils import as_tuple -from firedrake.petsc import DEFAULT_DIRECT_SOLVER +from firedrake.petsc import DEFAULT_DIRECT_SOLVER, PETSc ksp = { "mat_type": "matfree", diff --git a/tests/firedrake/regression/test_interpolate_zany.py b/tests/firedrake/regression/test_interpolate_zany.py index 248ebd29bf..5799bd2d33 100644 --- a/tests/firedrake/regression/test_interpolate_zany.py +++ b/tests/firedrake/regression/test_interpolate_zany.py @@ -1,5 +1,6 @@ import numpy import pytest +import ufl from firedrake import * diff --git a/tests/firedrake/regression/test_jax_coupling.py b/tests/firedrake/regression/test_jax_coupling.py index 0982d93e84..4e2fa02e98 100644 --- a/tests/firedrake/regression/test_jax_coupling.py +++ b/tests/firedrake/regression/test_jax_coupling.py @@ -1,5 +1,5 @@ import pytest - +import numpy as np from firedrake import * from pyadjoint.tape import get_working_tape, pause_annotation diff --git a/tests/firedrake/regression/test_matrix.py b/tests/firedrake/regression/test_matrix.py index 48680747fe..32623c418c 100644 --- a/tests/firedrake/regression/test_matrix.py +++ b/tests/firedrake/regression/test_matrix.py @@ -1,5 +1,5 @@ from firedrake import * -from firedrake import matrix +from firedrake.matrix import Matrix, AssembledMatrix import pytest @@ -33,7 +33,7 @@ def mat_type(request): def test_assemble_returns_matrix(a): A = assemble(a) - assert isinstance(A, matrix.Matrix) + assert isinstance(A, Matrix) def test_solve_with_assembled_matrix(a): diff --git a/tests/firedrake/regression/test_quadrature.py b/tests/firedrake/regression/test_quadrature.py index 9c738b888b..42e7b4423d 100644 --- a/tests/firedrake/regression/test_quadrature.py +++ b/tests/firedrake/regression/test_quadrature.py @@ -1,5 +1,6 @@ from firedrake import * import pytest +import numpy as np @pytest.fixture diff --git a/tests/firedrake/regression/test_solving_interface.py b/tests/firedrake/regression/test_solving_interface.py index 4df72c68e4..6fa3beb6cb 100644 --- a/tests/firedrake/regression/test_solving_interface.py +++ b/tests/firedrake/regression/test_solving_interface.py @@ -1,4 +1,5 @@ import pytest +import numpy as np from firedrake import * from firedrake.petsc import PETSc from numpy.linalg import norm as np_norm diff --git a/tests/firedrake/submesh/test_submesh_assign.py b/tests/firedrake/submesh/test_submesh_assign.py index 6609068a60..12adf956ce 100644 --- a/tests/firedrake/submesh/test_submesh_assign.py +++ b/tests/firedrake/submesh/test_submesh_assign.py @@ -1,4 +1,5 @@ import pytest +import numpy as np from firedrake import * import finat from os.path import abspath, dirname, join diff --git a/tests/firedrake/submesh/test_submesh_base.py b/tests/firedrake/submesh/test_submesh_base.py index db877ff23c..e2c93fdad3 100644 --- a/tests/firedrake/submesh/test_submesh_base.py +++ b/tests/firedrake/submesh/test_submesh_base.py @@ -1,4 +1,5 @@ import pytest +import numpy as np from firedrake import * diff --git a/tests/firedrake/vertexonly/test_poisson_inverse_conductivity.py b/tests/firedrake/vertexonly/test_poisson_inverse_conductivity.py index 4b890dae8f..15b03e867c 100644 --- a/tests/firedrake/vertexonly/test_poisson_inverse_conductivity.py +++ b/tests/firedrake/vertexonly/test_poisson_inverse_conductivity.py @@ -1,7 +1,7 @@ import pytest import numpy as np from firedrake import * -from pyadjoint.tape import get_working_tape, pause_annotation +from pyadjoint.tape import get_working_tape, pause_annotation, stop_annotating @pytest.fixture(autouse=True)