From f144de98a23e1d2d7197318d2e5935ddf84ee0bc Mon Sep 17 00:00:00 2001 From: Connor Ward Date: Mon, 3 Feb 2025 10:24:32 +0000 Subject: [PATCH 1/5] Test with single precision --- .github/workflows/build.yml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1a79936f0a..8e47b292e9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -48,6 +48,7 @@ jobs: COMPLEX: ${{ matrix.complex }} RDMAV_FORK_SAFE: 1 EXTRA_PYTEST_ARGS: --splitting-algorithm least_duration --timeout=1800 --timeout-method=thread -o faulthandler_timeout=1860 tests/firedrake + PETSC_CONFIGURE_OPTIONS: --with-precision=single steps: - uses: actions/checkout@v4 @@ -59,12 +60,12 @@ jobs: - name: Build Firedrake run: | + unset PETSC_DIR PETSC_ARCH SLEPC_DIR cd .. # Linting should ignore unquoted shell variable $COMPLEX # shellcheck disable=SC2086 ./firedrake/scripts/firedrake-install \ $COMPLEX \ - --honour-petsc-dir \ --mpicc="$MPICH_DIR"/mpicc \ --mpicxx="$MPICH_DIR"/mpicxx \ --mpif90="$MPICH_DIR"/mpif90 \ @@ -92,6 +93,7 @@ jobs: - name: Install test dependencies id: build run: | + unset PETSC_DIR PETSC_ARCH SLEPC_DIR sudo apt update sudo apt -y install parallel . ../firedrake_venv/bin/activate @@ -101,6 +103,7 @@ jobs: - name: Run tests (nprocs = 1) run: | + unset PETSC_DIR PETSC_ARCH SLEPC_DIR : # Use pytest-xdist here so we can have a single collated output (not possible : # for parallel tests) . ../firedrake_venv/bin/activate @@ -110,42 +113,49 @@ jobs: # Run even if earlier tests failed if: ${{ success() || steps.build.conclusion == 'success' }} run: | + unset PETSC_DIR PETSC_ARCH SLEPC_DIR . ../firedrake_venv/bin/activate firedrake-run-split-tests 2 6 "$EXTRA_PYTEST_ARGS --junit-xml=firedrake2_{#}.xml" - name: Run tests (nprocs = 3) if: ${{ success() || steps.build.conclusion == 'success' }} run: | + unset PETSC_DIR PETSC_ARCH SLEPC_DIR . ../firedrake_venv/bin/activate firedrake-run-split-tests 3 4 "$EXTRA_PYTEST_ARGS --junit-xml=firedrake3_{#}.xml" - name: Run tests (nprocs = 4) if: ${{ success() || steps.build.conclusion == 'success' }} run: | + unset PETSC_DIR PETSC_ARCH SLEPC_DIR . ../firedrake_venv/bin/activate firedrake-run-split-tests 4 3 "$EXTRA_PYTEST_ARGS --junit-xml=firedrake4_{#}.xml" - name: Run tests (nprocs = 5) if: ${{ success() || steps.build.conclusion == 'success' }} run: | + unset PETSC_DIR PETSC_ARCH SLEPC_DIR . ../firedrake_venv/bin/activate firedrake-run-split-tests 5 2 "$EXTRA_PYTEST_ARGS --junit-xml=firedrake5_{#}.xml" - name: Run tests (nprocs = 6) if: ${{ success() || steps.build.conclusion == 'success' }} run: | + unset PETSC_DIR PETSC_ARCH SLEPC_DIR . ../firedrake_venv/bin/activate firedrake-run-split-tests 6 2 "$EXTRA_PYTEST_ARGS --junit-xml=firedrake6_{#}.xml" - name: Run tests (nprocs = 7) if: ${{ success() || steps.build.conclusion == 'success' }} run: | + unset PETSC_DIR PETSC_ARCH SLEPC_DIR . ../firedrake_venv/bin/activate firedrake-run-split-tests 7 1 "$EXTRA_PYTEST_ARGS --junit-xml=firedrake7_{#}.xml" - name: Run tests (nprocs = 8) if: ${{ success() || steps.build.conclusion == 'success' }} run: | + unset PETSC_DIR PETSC_ARCH SLEPC_DIR . ../firedrake_venv/bin/activate firedrake-run-split-tests 8 1 "$EXTRA_PYTEST_ARGS --junit-xml=firedrake8_{#}.xml" @@ -171,6 +181,7 @@ jobs: - name: Test pyadjoint if: ${{ matrix.scalar-type == 'real' }} run: | + unset PETSC_DIR PETSC_ARCH SLEPC_DIR . ../firedrake_venv/bin/activate cd ../firedrake_venv/src/pyadjoint python -m pytest \ From 3857a8e0d95f0679d572d6d920fe90f462dc2baf Mon Sep 17 00:00:00 2001 From: Connor Ward Date: Mon, 3 Feb 2025 10:57:49 +0000 Subject: [PATCH 2/5] No pastix --- scripts/firedrake-install | 3 --- 1 file changed, 3 deletions(-) diff --git a/scripts/firedrake-install b/scripts/firedrake-install index aaf3f293f9..0ce05d0b2f 100755 --- a/scripts/firedrake-install +++ b/scripts/firedrake-install @@ -750,9 +750,6 @@ def get_petsc_options(minimal=False): petsc_options.add("--download-pnetcdf") # Sparse direct solvers petsc_options.add("--download-suitesparse") - petsc_options.add("--download-pastix") - # Required by pastix - petsc_options.update({"--download-hwloc", "--download-netlib-lapack", "--with-netlib-lapack-c-bindings"}) if osname == "Darwin": petsc_options.add("--download-hwloc-configure-arguments=--disable-opencl") # Serial mesh partitioner From 48e042b599f38a8f3d6bdc79ad61461084a3c007 Mon Sep 17 00:00:00 2001 From: Connor Ward Date: Mon, 3 Feb 2025 11:08:23 +0000 Subject: [PATCH 3/5] more options tweaks --- .github/workflows/build.yml | 1 - scripts/firedrake-install | 8 +------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8e47b292e9..20312d96f6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -48,7 +48,6 @@ jobs: COMPLEX: ${{ matrix.complex }} RDMAV_FORK_SAFE: 1 EXTRA_PYTEST_ARGS: --splitting-algorithm least_duration --timeout=1800 --timeout-method=thread -o faulthandler_timeout=1860 tests/firedrake - PETSC_CONFIGURE_OPTIONS: --with-precision=single steps: - uses: actions/checkout@v4 diff --git a/scripts/firedrake-install b/scripts/firedrake-install index 0ce05d0b2f..ec87bff8e1 100755 --- a/scripts/firedrake-install +++ b/scripts/firedrake-install @@ -727,6 +727,7 @@ def get_petsc_options(minimal=False): "--with-shared-libraries=1", "--with-c2html=0", "--with-strict-petscerrorcode", + "--with-precision=single", # Parser generator "--download-bison"} for pkg in get_minimal_petsc_packages(): @@ -742,16 +743,9 @@ def get_petsc_options(minimal=False): petsc_options.add("--download-cmake") if (not options["minimal_petsc"]) and (not minimal): - # Another sparse direct solver - petsc_options.add("--download-superlu_dist") - petsc_options.add("--with-zlib") # File formats petsc_options.add("--download-netcdf") petsc_options.add("--download-pnetcdf") - # Sparse direct solvers - petsc_options.add("--download-suitesparse") - if osname == "Darwin": - petsc_options.add("--download-hwloc-configure-arguments=--disable-opencl") # Serial mesh partitioner petsc_options.add("--download-metis") if options.get("with_parmetis", None): From ba82b7e802fdd1be6ab2e4fce219db14ad6fae21 Mon Sep 17 00:00:00 2001 From: Connor Ward Date: Mon, 3 Feb 2025 11:18:02 +0000 Subject: [PATCH 4/5] fixup --- scripts/firedrake-install | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/firedrake-install b/scripts/firedrake-install index ec87bff8e1..9ef050caf7 100755 --- a/scripts/firedrake-install +++ b/scripts/firedrake-install @@ -743,6 +743,7 @@ def get_petsc_options(minimal=False): petsc_options.add("--download-cmake") if (not options["minimal_petsc"]) and (not minimal): + petsc_options.add("--with-zlib") # File formats petsc_options.add("--download-netcdf") petsc_options.add("--download-pnetcdf") From 10c434229c407c4c8d43bbc6aeb44104fedd5a7c Mon Sep 17 00:00:00 2001 From: Iglesia Dolci Date: Thu, 6 Feb 2025 13:24:23 +0000 Subject: [PATCH 5/5] wip --- firedrake/assemble.py | 8 ++--- firedrake/cython/supermeshimpl.pyx | 4 +-- firedrake/functionspaceimpl.py | 2 +- firedrake/interpolation.py | 4 +-- firedrake/mesh.py | 48 +++++++++++++++--------------- firedrake/mg/kernels.py | 2 +- firedrake/pointquery_utils.py | 4 +-- firedrake/utility_meshes.py | 46 ++++++++++++++-------------- tsfc/kernel_interface/common.py | 2 +- 9 files changed, 60 insertions(+), 60 deletions(-) diff --git a/firedrake/assemble.py b/firedrake/assemble.py index b093baf945..f154794267 100644 --- a/firedrake/assemble.py +++ b/firedrake/assemble.py @@ -26,7 +26,7 @@ from firedrake.petsc import PETSc from firedrake.slate import slac, slate from firedrake.slate.slac.kernel_builder import CellFacetKernelArg, LayerCountKernelArg -from firedrake.utils import ScalarType, assert_empty, tuplify +from firedrake.utils import ScalarType, assert_empty, tuplify, IntType from pyop2 import op2 from pyop2.exceptions import MapValueError, SparsityFormatError from pyop2.types.mat import _GlobalMatPayload, _DatMatPayload @@ -1699,8 +1699,8 @@ def _make_mat_global_kernel_arg(self, Vrow, Vcol): else: rmap_arg, cmap_arg = (V.topological.entity_node_map(self._mesh.topology, self._integral_type, self._subdomain_id, self._all_integer_subdomain_ids)._global_kernel_arg for V in [Vrow, Vcol]) # PyOP2 matrix objects have scalar dims so we flatten them here - rdim = numpy.prod(self._get_dim(relem), dtype=int) - cdim = numpy.prod(self._get_dim(celem), dtype=int) + rdim = numpy.prod(self._get_dim(relem), dtype=IntType) + cdim = numpy.prod(self._get_dim(celem), dtype=IntType) return op2.MatKernelArg((((rdim, cdim),),), (rmap_arg, cmap_arg), unroll=self._unroll) @staticmethod @@ -1777,7 +1777,7 @@ def _as_global_kernel_arg_coefficient(_, self): @_as_global_kernel_arg.register(kernel_args.ConstantKernelArg) def _as_global_kernel_arg_constant(_, self): const = next(self._constants) - value_size = numpy.prod(const.ufl_shape, dtype=int) + value_size = numpy.prod(const.ufl_shape, dtype=IntType) return op2.GlobalKernelArg((value_size,)) diff --git a/firedrake/cython/supermeshimpl.pyx b/firedrake/cython/supermeshimpl.pyx index ad3387cd82..fd6da4b32a 100644 --- a/firedrake/cython/supermeshimpl.pyx +++ b/firedrake/cython/supermeshimpl.pyx @@ -160,8 +160,8 @@ def intersection_finder(mesh_A, mesh_B): libsupermesh_tree_intersection_finder_query_output(&nindices) - indices = numpy.empty((nindices,), dtype=int) - indptr = numpy.empty((mesh_A.num_cells() + 1,), dtype=int) + indices = numpy.empty((nindices,), dtype=IntType) + indptr = numpy.empty((mesh_A.num_cells() + 1,), dtype=IntType) libsupermesh_tree_intersection_finder_get_output(&ncells_A, &nindices, indices.data, indptr.data) diff --git a/firedrake/functionspaceimpl.py b/firedrake/functionspaceimpl.py index f6a6f8e6b5..5e61e41608 100644 --- a/firedrake/functionspaceimpl.py +++ b/firedrake/functionspaceimpl.py @@ -509,7 +509,7 @@ def __init__(self, mesh, element, name=None): the number of components of their :attr:`finat.ufl.finiteelementbase.FiniteElementBase.value_shape`.""" - self.block_size = int(numpy.prod(self.shape, dtype=int)) + self.block_size = int(numpy.prod(self.shape, dtype=PETSc.IntType)) r"""The total number of degrees of freedom at each function space node.""" self.name = name diff --git a/firedrake/interpolation.py b/firedrake/interpolation.py index b4b18d3cc1..0636b2e867 100644 --- a/firedrake/interpolation.py +++ b/firedrake/interpolation.py @@ -1014,9 +1014,9 @@ def callable(): # Make sure we have an expression of the right length i.e. a value for # each component in the value shape of each function space loops = [] - if numpy.prod(expr.ufl_shape, dtype=int) != V.value_size: + if numpy.prod(expr.ufl_shape, dtype=PETSc.IntType) != V.value_size: raise RuntimeError('Expression of length %d required, got length %d' - % (V.value_size, numpy.prod(expr.ufl_shape, dtype=int))) + % (V.value_size, numpy.prod(expr.ufl_shape, dtype=PETSc.intType))) if len(V) == 1: loops.extend(_interpolator(V, tensor, expr, subset, arguments, access, bcs=bcs)) diff --git a/firedrake/mesh.py b/firedrake/mesh.py index 8a0f8ec8a9..129a6214a7 100644 --- a/firedrake/mesh.py +++ b/firedrake/mesh.py @@ -422,7 +422,7 @@ def _from_triangle(filename, dim, comm): nodecount = header[0] nodedim = header[1] assert nodedim == dim - coordinates = np.loadtxt(nodefile, usecols=list(range(1, dim+1)), skiprows=1, dtype=np.double) + coordinates = np.loadtxt(nodefile, usecols=list(range(1, dim+1)), skiprows=1, dtype=PETSc.RealType) assert nodecount == coordinates.shape[0] with open(basename+".ele") as elefile: @@ -477,7 +477,7 @@ def plex_from_cell_list(dim, cells, coords, comm, name=None): # and double (not PetscInt, PetscReal). if comm.rank == 0: cells = np.asarray(cells, dtype=np.int32) - coords = np.asarray(coords, dtype=np.double) + coords = np.asarray(coords, dtype=PETSc.RealType) comm.bcast(cells.shape, root=0) comm.bcast(coords.shape, root=0) # Provide the actual data on rank 0. @@ -491,7 +491,7 @@ def plex_from_cell_list(dim, cells, coords, comm, name=None): # A subsequent call to plex.distribute() takes care of parallel partitioning plex = PETSc.DMPlex().createFromCellList(dim, np.zeros(cell_shape, dtype=np.int32), - np.zeros(coord_shape, dtype=np.double), + np.zeros(coord_shape, dtype=PETSc.RealType), comm=icomm) if name is not None: plex.setName(name) @@ -522,7 +522,7 @@ def _from_cell_list(dim, cells, coords, comm, name=None): # and double (not PetscInt, PetscReal). if comm.rank == 0: cells = np.asarray(cells, dtype=np.int32) - coords = np.asarray(coords, dtype=np.double) + coords = np.asarray(coords, dtype=PETSc.RealType) comm.bcast(cells.shape, root=0) comm.bcast(coords.shape, root=0) # Provide the actual data on rank 0. @@ -536,7 +536,7 @@ def _from_cell_list(dim, cells, coords, comm, name=None): # A subsequent call to plex.distribute() takes care of parallel partitioning plex = PETSc.DMPlex().createFromCellList(dim, np.zeros(cell_shape, dtype=np.int32), - np.zeros(coord_shape, dtype=np.double), + np.zeros(coord_shape, dtype=PETSc.RealType), comm=comm) if name is not None: plex.setName(name) @@ -619,7 +619,7 @@ def callback(self): # Mark OP2 entities and derive the resulting Plex renumbering with PETSc.Log.Event("Mesh: numbering"): self._mark_entity_classes() - self._entity_classes = dmcommon.get_entity_classes(self.topology_dm).astype(int) + self._entity_classes = dmcommon.get_entity_classes(self.topology_dm).astype(IntType) if perm_is: self._dm_renumbering = perm_is else: @@ -1816,13 +1816,13 @@ def node_classes(self, nodes_per_entity, real_tensorproduct=False): :returns: the number of nodes in each of core, owned, and ghost classes. """ if real_tensorproduct: - nodes = np.asarray(nodes_per_entity) + nodes = np.asarray(nodes_per_entity, dtype=IntType) nodes_per_entity = sum(nodes[:, i] for i in range(2)) return super(ExtrudedMeshTopology, self).node_classes(nodes_per_entity) elif self.variable_layers: return extnum.node_classes(self, nodes_per_entity) else: - nodes = np.asarray(nodes_per_entity) + nodes = np.asarray(nodes_per_entity, dtype=IntType) if self.extruded_periodic: nodes_per_entity = sum(nodes[:, i]*(self.layers - 1) for i in range(2)) else: @@ -2482,8 +2482,8 @@ def spatial_index(self): # Calculate the bounding boxes for all cells by running a kernel V = functionspace.VectorFunctionSpace(self, "DG", 0, dim=gdim) - coords_min = function.Function(V, dtype=RealType) - coords_max = function.Function(V, dtype=RealType) + coords_min = function.Function(V, dtype=PETSc.RealType) + coords_max = function.Function(V, dtype=PETSc.RealType) coords_min.dat.data.fill(np.inf) coords_max.dat.data.fill(-np.inf) @@ -2493,7 +2493,7 @@ def spatial_index(self): raise ValueError("Coordinate field has non-zero imaginary part") coords = function.Function(self.coordinates.function_space(), val=self.coordinates.dat.data_ro_with_halos.real.copy(), - dtype=RealType) + dtype=PETSc.RealType) else: coords = self.coordinates @@ -2584,7 +2584,7 @@ def locate_cell_and_reference_coordinate(self, x, tolerance=None, cell_ignore=No (cell number, reference coordinates) of type (int, numpy array), or, when point is not in the domain, (None, None). """ - x = np.asarray(x) + x = np.asarray(x, dtype=PETSc.RealType) if x.size != self.geometric_dimension(): raise ValueError("Point must have the same geometric dimension as the mesh") x = x.reshape((1, self.geometric_dimension())) @@ -2621,7 +2621,7 @@ def locate_cells_ref_coords_and_dists(self, xs, tolerance=None, cells_ignore=Non tolerance = self.tolerance else: self.tolerance = tolerance - xs = np.asarray(xs, dtype=utils.ScalarType) + xs = np.asarray(xs, dtype=PETSc.RealType) xs = xs.real.copy() if xs.shape[1] != self.geometric_dimension(): raise ValueError("Point coordinate dimension does not match mesh geometric dimension") @@ -3349,7 +3349,7 @@ def VertexOnlyMesh(mesh, vertexcoords, reorder=None, missing_points_behaviour='e else: mesh.tolerance = tolerance mesh.init() - vertexcoords = np.asarray(vertexcoords, dtype=RealType) + vertexcoords = np.asarray(vertexcoords, dtype=PETSc.RealType) if reorder is None: reorder = parameters["reorder_meshes"] gdim = mesh.geometric_dimension() @@ -3578,7 +3578,7 @@ def _pic_swarm_in_mesh( parent_mesh.tolerance = tolerance # Check coords - coords = np.asarray(coords, dtype=RealType) + coords = np.asarray(coords, dtype=PETSc.RealType) plex = parent_mesh.topology.topology_dm tdim = parent_mesh.topological_dimension() @@ -4094,10 +4094,10 @@ def _parent_mesh_embedding( ncoords_local = coords_local.shape[0] coords_global = coords_local ncoords_global = coords_global.shape[0] - global_idxs_global = np.arange(coords_global.shape[0]) + global_idxs_global = np.arange(coords_global.shape[0], dtype=IntType) input_coords_idxs_local = np.arange(ncoords_local) input_coords_idxs_global = input_coords_idxs_local - input_ranks_local = np.zeros(ncoords_local, dtype=int) + input_ranks_local = np.zeros(ncoords_local, dtype=IntType) input_ranks_global = input_ranks_local else: # Here, we have to assume that all points we can see are unique. @@ -4113,7 +4113,7 @@ def _parent_mesh_embedding( # The below code looks complicated but it's just an allgather of the # (variable length) coords_local array such that they are concatenated. coords_local_size = np.array(coords_local.size) - coords_local_sizes = np.empty(parent_mesh._comm.size, dtype=int) + coords_local_sizes = np.empty(parent_mesh._comm.size, dtype=IntType) parent_mesh._comm.Allgatherv(coords_local_size, coords_local_sizes) coords_global = np.empty( (ncoords_global, coords.shape[1]), dtype=coords_local.dtype @@ -4127,12 +4127,12 @@ def _parent_mesh_embedding( # global_idxs_global = np.arange(startidx, endidx) global_idxs_global = np.arange(coords_global.shape[0]) input_coords_idxs_local = np.arange(ncoords_local) - input_coords_idxs_global = np.empty(ncoords_global, dtype=int) + input_coords_idxs_global = np.empty(ncoords_global, dtype=IntType) parent_mesh._comm.Allgatherv( input_coords_idxs_local, (input_coords_idxs_global, ncoords_local_allranks) ) - input_ranks_local = np.full(ncoords_local, parent_mesh._comm.rank, dtype=int) - input_ranks_global = np.empty(ncoords_global, dtype=int) + input_ranks_local = np.full(ncoords_local, parent_mesh._comm.rank, dtype=IntType) + input_ranks_global = np.empty(ncoords_global, dtype=IntType) parent_mesh._comm.Allgatherv( input_ranks_local, (input_ranks_global, ncoords_local_allranks) ) @@ -4222,7 +4222,7 @@ def _parent_mesh_embedding( # point. changed_ranks_tied = changed_ranks & ~changed_ref_cell_dists_l1 if any(changed_ranks_tied): - cells_ignore_T = np.asarray([np.copy(parent_cell_nums)]) + cells_ignore_T = np.asarray([np.copy(parent_cell_nums)], dtype=IntType) while any(changed_ranks_tied): ( parent_cell_nums[changed_ranks_tied], @@ -4347,8 +4347,8 @@ def _swarm_original_ordering_preserve( (plex_parent_cell_nums_global, ncoords_local_allranks), ) - reference_coords_local_size = np.array(reference_coords_local.size) - reference_coords_local_sizes = np.empty(comm.size, dtype=int) + reference_coords_local_size = np.array(reference_coords_local.size, dtype=IntType) + reference_coords_local_sizes = np.empty(comm.size, dtype=IntType) comm.Allgatherv(reference_coords_local_size, reference_coords_local_sizes) reference_coords_global = np.empty( (ncoords_global, reference_coords_local.shape[1]), diff --git a/firedrake/mg/kernels.py b/firedrake/mg/kernels.py index 6ce9c4eb55..c2987fc1ae 100644 --- a/firedrake/mg/kernels.py +++ b/firedrake/mg/kernels.py @@ -506,7 +506,7 @@ def set_coordinates(self, domain): def _coefficient(self, coefficient, name): element = create_element(coefficient.ufl_element()) shape = self.shape + element.index_shape - size = numpy.prod(shape, dtype=int) + size = numpy.prod(shape, dtype=IntType) funarg = lp.GlobalArg(name, dtype=ScalarType, shape=(size,)) expression = gem.reshape(gem.Variable(name, (size, )), shape) expression = gem.partial_indexed(expression, self.indices) diff --git a/firedrake/pointquery_utils.py b/firedrake/pointquery_utils.py index 2308616622..0a45f29d78 100644 --- a/firedrake/pointquery_utils.py +++ b/firedrake/pointquery_utils.py @@ -149,10 +149,10 @@ def to_reference_coords_newton_step(ufl_coordinate_element, parameters, x0_dtype x0_expr = builder._coefficient(x0, "x0") loopy_args = [ lp.GlobalArg( - "C", dtype=ScalarType, shape=(numpy.prod(Cexpr.shape, dtype=int),) + "C", dtype=ScalarType, shape=(numpy.prod(Cexpr.shape, dtype=IntType),) ), lp.GlobalArg( - "x0", dtype=x0_dtype, shape=(numpy.prod(x0_expr.shape, dtype=int),) + "x0", dtype=x0_dtype, shape=(numpy.prod(x0_expr.shape, dtype=IntType),) ), ] diff --git a/firedrake/utility_meshes.py b/firedrake/utility_meshes.py index 99d687449e..dcbc1514a7 100644 --- a/firedrake/utility_meshes.py +++ b/firedrake/utility_meshes.py @@ -151,7 +151,7 @@ def IntervalMesh( raise ValueError("Requested mesh has negative length") dx = length / ncells # This ensures the rightmost point is actually present. - coords = np.arange(left, right + 0.01 * dx, dx, dtype=np.double).reshape(-1, 1) + coords = np.arange(left, right + 0.01 * dx, dx, dtype=PETSc.RealType).reshape(-1, 1) cells = np.dstack( ( np.arange(0, len(coords) - 1, dtype=np.int32), @@ -367,7 +367,7 @@ def OneElementThickMesh( right = np.roll(left, -1) cells = np.array([left, left, right, right]).T dx = Lx / ncells - X = np.arange(1.0 * ncells, dtype=np.double) * dx + X = np.arange(1.0 * ncells, dtype=PETSc.RealType) * dx Y = 0.0 * X coords = np.array([X, Y]).T @@ -632,8 +632,8 @@ def RectangleMesh( if n <= 0 or n % 1: raise ValueError("Number of cells must be a postive integer") - xcoords = np.linspace(originX, Lx, nx + 1, dtype=np.double) - ycoords = np.linspace(originY, Ly, ny + 1, dtype=np.double) + xcoords = np.linspace(originX, Lx, nx + 1, dtype=PETSc.RealType) + ycoords = np.linspace(originY, Ly, ny + 1, dtype=PETSc.RealType) return TensorRectangleMesh( xcoords, ycoords, @@ -1180,8 +1180,8 @@ def CircleManifoldMesh( vertices = radius * np.column_stack( ( - np.cos(np.arange(ncells, dtype=np.double) * (2 * np.pi / ncells)), - np.sin(np.arange(ncells, dtype=np.double) * (2 * np.pi / ncells)), + np.cos(np.arange(ncells, dtype=PETSc.RealType) * (2 * np.pi / ncells)), + np.sin(np.arange(ncells, dtype=PETSc.RealType) * (2 * np.pi / ncells)), ) ) @@ -1252,7 +1252,7 @@ def UnitDiskMesh( """ vertices = np.array( [[0, 0], [1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]], - dtype=np.double, + dtype=PETSc.RealType, ) cells = np.array( @@ -1340,7 +1340,7 @@ def UnitBallMesh( [0, -1, 0], [0, 0, -1], ], - dtype=np.double, + dtype=PETSc.RealType, ) cells = np.array( @@ -1662,9 +1662,9 @@ def BoxMesh( ) return m else: - xcoords = np.linspace(0, Lx, nx + 1, dtype=np.double) - ycoords = np.linspace(0, Ly, ny + 1, dtype=np.double) - zcoords = np.linspace(0, Lz, nz + 1, dtype=np.double) + xcoords = np.linspace(0, Lx, nx + 1, dtype=PETSc.RealType) + ycoords = np.linspace(0, Ly, ny + 1, dtype=PETSc.RealType) + zcoords = np.linspace(0, Lz, nz + 1, dtype=PETSc.RealType) return TensorBoxMesh( xcoords, ycoords, @@ -1916,9 +1916,9 @@ def PeriodicBoxMesh( else: if tuple(directions) != (True, True, True): raise NotImplementedError("Can only specify directions with hexahedral = True") - xcoords = np.arange(0.0, Lx, Lx / nx, dtype=np.double) - ycoords = np.arange(0.0, Ly, Ly / ny, dtype=np.double) - zcoords = np.arange(0.0, Lz, Lz / nz, dtype=np.double) + xcoords = np.arange(0.0, Lx, Lx / nx, dtype=PETSc.RealType) + ycoords = np.arange(0.0, Ly, Ly / ny, dtype=PETSc.RealType) + zcoords = np.arange(0.0, Lz, Lz / nz, dtype=PETSc.RealType) coords = ( np.asarray(np.meshgrid(xcoords, ycoords, zcoords)).swapaxes(0, 3).reshape(-1, 3) ) @@ -2137,7 +2137,7 @@ def IcosahedralSphereMesh( [-phi, 0, -1], [-phi, 0, 1], ], - dtype=np.double, + dtype=PETSc.RealType, ) # faces of the base icosahedron faces = np.array( @@ -2465,7 +2465,7 @@ def _cubedsphere_cells_and_coords(radius, refinement_level): # transformation dtheta = 2 ** (-refinement_level + 1) * np.arctan(1.0) a = 3.0 ** (-0.5) * radius - theta = np.arange(np.arctan(-1.0), np.arctan(1.0) + dtheta, dtheta, dtype=np.double) + theta = np.arange(np.arctan(-1.0), np.arctan(1.0) + dtheta, dtheta, dtype=PETSc.RealType) x = a * np.tan(theta) Nx = x.size @@ -2551,7 +2551,7 @@ def _cubedsphere_cells_and_coords(radius, refinement_level): # Set up an array for all of the mesh coordinates Npoints = panel_numbering.max() + 1 - coords = np.zeros((Npoints, 3), dtype=np.double) + coords = np.zeros((Npoints, 3), dtype=PETSc.RealType) lX, lY = np.meshgrid(x, x) lX.shape = (Nx**2,) lY.shape = (Nx**2,) @@ -2758,7 +2758,7 @@ def TorusMesh( r * np.sin(idx_temp[:, 1] * (2 * np.pi / nr)), ) ), - dtype=np.double, + dtype=PETSc.RealType, ) # cell vertices @@ -2960,7 +2960,7 @@ def CylinderMesh( np.column_stack( (np.tile(coord_xy, (nl + 1, 1)), np.tile(coord_z, (1, nr)).reshape(-1, 1)) ), - dtype=np.double, + dtype=PETSc.RealType, ) # intervals on circumference @@ -2976,7 +2976,7 @@ def CylinderMesh( if not quadrilateral and diagonal == "crossed": dxy = np.pi / nr Lxy = 2 * np.pi - extra_uv = np.linspace(dxy, Lxy - dxy, nr, dtype=np.double) + extra_uv = np.linspace(dxy, Lxy - dxy, nr, dtype=PETSc.RealType) extra_xy = radius * np.column_stack((np.cos(extra_uv), np.sin(extra_uv))) dz = 1 * 0.5 / nl extra_z = depth * np.linspace(dz, 1 - dz, nl).reshape(-1, 1) @@ -2984,7 +2984,7 @@ def CylinderMesh( np.column_stack( (np.tile(extra_xy, (nl, 1)), np.tile(extra_z, (1, nr)).reshape(-1, 1)) ), - dtype=np.double, + dtype=PETSc.RealType, ) origvertices = vertices vertices = np.vstack([vertices, extras]) @@ -3021,10 +3021,10 @@ def CylinderMesh( cells = cells[:, idx].reshape(-1, 3) if longitudinal_direction == "x": - rotation = np.asarray([[0, 0, 1], [0, 1, 0], [-1, 0, 0]], dtype=np.double) + rotation = np.asarray([[0, 0, 1], [0, 1, 0], [-1, 0, 0]], dtype=PETSc.RealType) vertices = np.dot(vertices, rotation.T) elif longitudinal_direction == "y": - rotation = np.asarray([[1, 0, 0], [0, 0, 1], [0, -1, 0]], dtype=np.double) + rotation = np.asarray([[1, 0, 0], [0, 0, 1], [0, -1, 0]], dtype=PETSc.RealType) vertices = np.dot(vertices, rotation.T) elif longitudinal_direction != "z": raise ValueError("Unknown longitudinal direction '%s'" % longitudinal_direction) diff --git a/tsfc/kernel_interface/common.py b/tsfc/kernel_interface/common.py index 3f7daa5383..3c6a69ed12 100644 --- a/tsfc/kernel_interface/common.py +++ b/tsfc/kernel_interface/common.py @@ -453,7 +453,7 @@ def prepare_constant(constant, number): :returns: (funarg, expression) expression - GEM expression referring to the Constant value(s) """ - value_size = numpy.prod(constant.ufl_shape, dtype=int) + value_size = numpy.prod(constant.ufl_shape, dtype=constant.dat.dtype) return gem.reshape(gem.Variable(f"c_{number}", (value_size,)), constant.ufl_shape)