def test_int_type(): import firedrake_configuration from pyop2.datatypes import IntType expected = firedrake_configuration.get_config()["options"]["petsc_int_type"] actual = {4: "int32", 8: "int64"}[IntType.itemsize] assert expected == actual
def test_config_exist(): import firedrake_configuration config = firedrake_configuration.get_config() assert config is not None
from distutils.core import setup from setuptools import find_packages from glob import glob from os import environ as env, path from Cython.Distutils import build_ext import os import sys import numpy as np import petsc4py import versioneer from firedrake_configuration import get_config try: from Cython.Distutils.extension import Extension config = get_config() complex_mode = config['options'].get('complex', False) except ImportError: # No Cython Extension means no complex mode! from distutils.extension import Extension complex_mode = False def get_petsc_dir(): try: petsc_dir = os.environ["PETSC_DIR"] petsc_arch = os.environ.get("PETSC_ARCH", "") except KeyError: try: petsc_dir = os.path.join(os.environ["VIRTUAL_ENV"], "src", "petsc") petsc_arch = "default"
import firedrake_configuration import os import sys config = firedrake_configuration.get_config() if "PETSC_DIR" in os.environ and not config["options"]["honour_petsc_dir"]: raise ImportError( "PETSC_DIR is set, but you did not install with --honour-petsc-dir.\n" "Please unset PETSC_DIR (and PETSC_ARCH) before using Firedrake.") elif "PETSC_DIR" not in os.environ and config["options"]["honour_petsc_dir"]: raise ImportError( "Firedrake was installed with --honour-petsc-dir, but PETSC_DIR is not set.\n" "Please set PETSC_DIR (and PETSC_ARCH) before using Firedrake.") del os, sys, config # Ensure petsc is initialised by us before anything else gets in there. import firedrake.petsc as petsc del petsc # UFL Exprs come with a custom __del__ method, but we hold references # to them /everywhere/, some of which are circular (the Mesh object # holds a ufl.Domain that references the Mesh). The Python2 GC # explicitly DOES NOT collect such reference cycles (even though it # can deal with normal cycles). Quoth the documentation: # # Objects that have __del__() methods and are part of a reference # cycle cause the entire reference cycle to be uncollectable, # including objects not necessarily in the cycle but reachable # only from it. # # To get around this, since the default __del__ on Expr is just # "pass", we just remove the method from the definition of Expr.
from firedrake.utils import cached_property from firedrake.logging import warning def _make_reasons(reasons): return dict([(getattr(reasons, r), r) for r in dir(reasons) if not r.startswith('_')]) KSPReasons = _make_reasons(PETSc.KSP.ConvergedReason()) SNESReasons = _make_reasons(PETSc.SNES.ConvergedReason()) if get_config()["options"]["petsc_int_type"] == "int32": DEFAULT_KSP_PARAMETERS = {"mat_type": "aij", "ksp_type": "preonly", "ksp_rtol": 1e-7, "pc_type": "lu", "pc_factor_mat_solver_type": "mumps", "mat_mumps_icntl_14": 200} else: DEFAULT_KSP_PARAMETERS = {"mat_type": "aij", "ksp_type": "preonly", "ksp_rtol": 1e-7, "pc_type": "lu", "pc_factor_mat_solver_type": "superlu_dist"} def set_defaults(solver_parameters, arguments, *, ksp_defaults={}, snes_defaults={}):
# Some generic python utilities not really specific to our work. from decorator import decorator from pyop2.utils import cached_property # noqa: F401 from pyop2.datatypes import ScalarType, as_cstr from pyop2.datatypes import RealType # noqa: F401 from pyop2.datatypes import IntType # noqa: F401 from pyop2.datatypes import as_ctypes # noqa: F401 from firedrake_configuration import get_config _current_uid = 0 ScalarType_c = as_cstr(ScalarType) IntType_c = as_cstr(IntType) complex_mode = get_config()["options"].get("complex", False) # Remove this (and update test suite) when Slate supports complex mode. SLATE_SUPPORTS_COMPLEX = False def _new_uid(): global _current_uid _current_uid += 1 return _current_uid def _init(): """Cause :func:`pyop2.init` to be called in case the user has not done it for themselves. The result of this is that the user need only call :func:`pyop2.init` if she wants to set a non-default option, for example to switch the debug or log level."""
import firedrake_configuration import os import sys config = firedrake_configuration.get_config() if "PETSC_DIR" in os.environ and not config["options"]["honour_petsc_dir"]: raise ImportError("PETSC_DIR is set, but you did not install with --honour-petsc-dir.\n" "Please unset PETSC_DIR (and PETSC_ARCH) before using Firedrake.") elif "PETSC_DIR" not in os.environ and config["options"]["honour_petsc_dir"]: raise ImportError("Firedrake was installed with --honour-petsc-dir, but PETSC_DIR is not set.\n" "Please set PETSC_DIR (and PETSC_ARCH) before using Firedrake.") del os, sys, config # Ensure petsc is initialised by us before anything else gets in there. import firedrake.petsc as petsc del petsc # UFL Exprs come with a custom __del__ method, but we hold references # to them /everywhere/, some of which are circular (the Mesh object # holds a ufl.Domain that references the Mesh). The Python2 GC # explicitly DOES NOT collect such reference cycles (even though it # can deal with normal cycles). Quoth the documentation: # # Objects that have __del__() methods and are part of a reference # cycle cause the entire reference cycle to be uncollectable, # including objects not necessarily in the cycle but reachable # only from it. # # To get around this, since the default __del__ on Expr is just # "pass", we just remove the method from the definition of Expr. import ufl try: