Skip to content
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions demos/multicomponent/multicomponent.py.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ The chemicals then mix in the center of the container and exit through an outlet
We use :doc:`netgen <netgen_mesh.py>` 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
Expand Down
143 changes: 106 additions & 37 deletions firedrake/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could probably remove firedrake.output and firedrake.plot from the global namespace now? It was moved to firedrake.pyplot around two years ago: #3117. Also #3324

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah good idea

import sys
sys.modules["firedrake.plot"] = plot
from firedrake.plot import *
from firedrake.plot import * # noqa: F401
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto


del sys

Expand Down
37 changes: 21 additions & 16 deletions firedrake/adjoint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
24 changes: 16 additions & 8 deletions firedrake/adjoint_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 12 additions & 9 deletions firedrake/adjoint_utils/blocks/__init__.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion firedrake/assemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 7 additions & 3 deletions firedrake/ensemble/__init__.py
Original file line number Diff line number Diff line change
@@ -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
)
10 changes: 7 additions & 3 deletions firedrake/external_operators/__init__.py
Original file line number Diff line number Diff line change
@@ -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
9 changes: 7 additions & 2 deletions firedrake/fml/__init__.py
Original file line number Diff line number Diff line change
@@ -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
)
13 changes: 9 additions & 4 deletions firedrake/mg/__init__.py
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions firedrake/output/__init__.py
Original file line number Diff line number Diff line change
@@ -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
41 changes: 26 additions & 15 deletions firedrake/preconditioners/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Loading
Loading