Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
klist = []
transformkernel = Transformer()
oriented = False
for v in kernel_exprs.values():
for ks in v:
oriented = oriented or ks.kinfo.oriented
# TODO: Think about this. Is this true for SLATE?
assert ks.kinfo.subdomain_id == "otherwise"
kast = transformkernel.visit(ks.kinfo.kernel._ast)
klist.append(kast)
klist.append(kernel)
kernelast = ast.Node(klist)
# Need to get the correct PETSc directory
inc.append(petsc.get_petsc_dir() + '/include/eigen3/')
# Produce the op2 kernel object for assembly
op2kernel = op2.Kernel(kernelast,
"slac_compile_slate",
cpp=True,
include_dirs=inc,
headers=['#include ', '#define restrict __restrict'])
# TODO: What happens for multiple ufl domains?
assert len(slate_expr.ufl_domains()) == 1
kinfo = KernelInfo(kernel=op2kernel,
integral_type="cell",
oriented=oriented,
subdomain_id="otherwise",
domain_number=0,
coefficient_map=range(len(coeffs)),
def get_petsc_dir():
try:
petsc_arch = env.get('PETSC_ARCH', '')
petsc_dir = env['PETSC_DIR']
if petsc_arch:
return (petsc_dir, path.join(petsc_dir, petsc_arch))
return (petsc_dir,)
except KeyError:
try:
import petsc
return (petsc.get_petsc_dir(), )
except ImportError:
sys.exit("""Error: Could not find PETSc library.
def get_petsc_dir():
try:
arch = '/' + env.get('PETSC_ARCH', '')
dir = env['PETSC_DIR']
return (dir, dir + arch)
except KeyError:
try:
import petsc
return (petsc.get_petsc_dir(), )
except ImportError:
sys.exit("""Error: Could not find PETSc library.
def get_petsc_dir():
try:
arch = '/' + os.environ.get('PETSC_ARCH', '')
dir = os.environ['PETSC_DIR']
return (dir, dir + arch)
except KeyError:
try:
import petsc
return (petsc.get_petsc_dir(), )
except ImportError:
sys.exit("""Error: Could not find PETSc library.
def get_petsc_dir():
try:
petsc_arch = env.get('PETSC_ARCH', '')
petsc_dir = env['PETSC_DIR']
if petsc_arch:
return (petsc_dir, path.join(petsc_dir, petsc_arch))
return (petsc_dir,)
except KeyError:
try:
import petsc
return (petsc.get_petsc_dir(), )
except ImportError:
sys.exit("""Error: Could not find PETSc library.
def update_parameters(obj, petsc_obj):
"""Update parameters on a petsc object
:arg obj: An object with a parameters dict (mapping to petsc options).
:arg petsc_obj: The PETSc object to set parameters on."""
# Skip if parameters haven't changed
if hasattr(obj, '_set_parameters') and obj.parameters == obj._set_parameters:
return
opts = PETSc.Options(obj._opt_prefix)
for k, v in obj.parameters.iteritems():
if type(v) is bool:
if v:
opts[k] = None
else:
opts[k] = v
petsc_obj.setFromOptions()
obj._set_parameters = obj.parameters.copy()
def _from_cell_list(dim, cells, coords, comm=None):
"""
Create a DMPlex from a list of cells and coords.
:arg dim: The topological dimension of the mesh
:arg cells: The vertices of each cell
:arg coords: The coordinates of each vertex
:arg comm: An optional communicator to build the plex on (defaults to COMM_WORLD)
"""
if comm is None:
comm = MPI.comm
if comm.rank == 0:
# Provide the actual data on rank 0.
return PETSc.DMPlex().createFromCellList(dim, cells, coords, comm=comm)
# Provide empty plex on other ranks
# A subsequent call to plex.distribute() takes care of parallel partitioning
return PETSc.DMPlex().createFromCellList(dim,
np.zeros((0, 0), dtype=np.int32),
np.zeros((0, 0), dtype=np.int32),
comm=comm)
opts[k] = None
else:
opts[k] = v
petsc_obj.setFromOptions()
obj._set_parameters = obj.parameters.copy()
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())
def check_snes_convergence(snes):
r = snes.getConvergedReason()
try:
reason = SNESReasons[r]
inner = False
except KeyError:
r = snes.getKSP().getConvergedReason()
try:
reason = KSPReasons[r]
inner = True
except KeyError:
reason = 'unknown reason (petsc4py enum incomplete?)'
if r < 0:
if inner:
for k, v in obj.parameters.iteritems():
if type(v) is bool:
if v:
opts[k] = None
else:
opts[k] = v
petsc_obj.setFromOptions()
obj._set_parameters = obj.parameters.copy()
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())
def check_snes_convergence(snes):
r = snes.getConvergedReason()
try:
reason = SNESReasons[r]
inner = False
except KeyError:
r = snes.getKSP().getConvergedReason()
try:
reason = KSPReasons[r]
inner = True
except KeyError:
def permute_global_numbering(plex):
"""Permute the global/universal DoF numbering according to a
depth-first traversal of the Plex graph."""
dim = plex.getDimension()
glbl = plex.getDefaultSection()
univ = plex.getDefaultGlobalSection()
pStart, pEnd = glbl.getChart()
entity_classes = [0, 0, 0, 0]
permutation = -1 * np.ones(pEnd-pStart, dtype=np.int)
glbl_num = 0
# Create new numbering sections
glbl_new = PETSc.Section().create()
glbl_new.setChart(pStart, pEnd)
glbl_new.setUp()
univ_new = PETSc.Section().create()
univ_new.setChart(pStart, pEnd)
univ_new.setUp()
# Get a list of current universal DoFs
universal_dofs = []
for p in range(pStart, pEnd):
for c in range(univ.getDof(p)):
universal_dofs.append(univ.getOffset(p)+c)
# Renumber core DoFs
seen = set()
if plex.getStratumSize("op2_core", dim) > 0:
for cell in plex.getStratumIS("op2_core", dim).getIndices():