Skip to content

Commit

Permalink
Merge ffa0767 into 8f9558c
Browse files Browse the repository at this point in the history
  • Loading branch information
hschilling committed Jun 8, 2020
2 parents 8f9558c + ffa0767 commit 20a63c8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 12 deletions.
27 changes: 21 additions & 6 deletions openmdao/core/total_jac.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,38 @@
"""
from collections import OrderedDict, defaultdict
from copy import deepcopy
import os
import pprint
import sys
import time

import numpy as np

try:
from petsc4py import PETSc
from openmdao.vectors.petsc_vector import PETScVector
except ImportError:
PETSc = None

from openmdao.vectors.vector import INT_DTYPE
from openmdao.utils.general_utils import ContainsAll, simple_warning
from openmdao.utils.mpi import MPI
from openmdao.utils.coloring import _initialize_model_approx, Coloring

# Attempt to import petsc4py.
# If OPENMDAO_REQUIRE_MPI is set to a recognized positive value, attempt import
# and raise exception on failure. If set to anything else, no import is attempted.
if 'OPENMDAO_REQUIRE_MPI' in os.environ:
if os.environ['OPENMDAO_REQUIRE_MPI'].lower() in ['always', '1', 'true', 'yes']:
try:
from petsc4py import PETSc
except ImportError:
PETSc = None
else:
PETSc = None
# If OPENMDAO_REQUIRE_MPI is unset, attempt to import petsc4py, but continue on failure
# with a notification.
else:
try:
from petsc4py import PETSc
except ImportError:
PETSc = None
sys.stdout.write("Unable to import petsc4py. Parallel processing unavailable.\n")
sys.stdout.flush()

_contains_all = ContainsAll()

Expand Down
29 changes: 23 additions & 6 deletions openmdao/solvers/linear/petsc_ksp.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
"""LinearSolver that uses PetSC KSP to solve for a system's derivatives."""

import numpy as np

try:
import petsc4py
from petsc4py import PETSc
except ImportError:
PETSc = None
import os
import sys

from openmdao.solvers.solver import LinearSolver

if 'OPENMDAO_REQUIRE_MPI' in os.environ:
if os.environ['OPENMDAO_REQUIRE_MPI'].lower() in ['always', '1', 'true', 'yes']:
try:
import petsc4py
from petsc4py import PETSc
except ImportError:
PETSc = None
else:
PETSc = None
# If OPENMDAO_REQUIRE_MPI is unset, attempt to import petsc4py, but continue on failure
# with a notification.
else:
try:
import petsc4py
from petsc4py import PETSc
except ImportError:
PETSc = None
sys.stdout.write("Unable to import petsc4py. Parallel processing unavailable.\n")
sys.stdout.flush()


KSP_TYPES = [
"richardson",
"chebyshev",
Expand Down

0 comments on commit 20a63c8

Please sign in to comment.