How to use the petsc4py.init function in petsc4py

To help you get started, we’ve selected a few petsc4py examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github petsc / petsc / src / sys / fwk / examples / tutorials / ex2.py View on Github external
import sys, petsc4py
petsc4py.init(sys.argv)
from petsc4py import PETSc


if __name__ == "__main__":
    fwk = PETSc.Fwk().create()
    fwk.setName("ex1")
    fwk.registerComponent("Electrolyte",  "./electrolyte.py:Electrolyte")
    fwk.registerComponent("Viz",          "./viz.py:Viz")
    #fwk.registerComponent("ScreeningAvg", "./avg.py:ScreeningAvg")
    fwk.visit("init")
    viz = fwk.getComponent("Viz")
    #viz.call("viewRhoGamma")
    viz.call("viewRho")
    rhoGamma = fwk.getComponent("Electrolyte").query("rhoGamma")
    rho      = fwk.getComponent("Electrolyte").query("rho")
    #A        = fwk.getComponent("ScreeningAvg")
github MiroK / fenics_ii / sandbox / daniele.py View on Github external
ksp.solve(b, x)
    niters = ksp.getIterationNumber()

    eigs = ksp.computeEigenvalues()
    assert (e > 0 for e in eigs)
    eigs = np.abs(eigs)
    
    return niters, max(eigs)/min(eigs)
    
# --------------------------------------------------------------------

if __name__ == '__main__':
    import argparse, sys, petsc4py

    petsc4py.init(sys.argv)
    from petsc4py import PETSc

    parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    # Problem params
    parser.add_argument('-N', default=[4], nargs='+', type=int, help='Cube partiioned to NxNx2N')
    
    parser.add_argument('-radius', type=float, default=0.1, help='Radius of the tubes')

    parser.add_argument('-solver', type=str, default='direct', choices=['direct', 'iterative'],
                        help='Direct/iterative solver')

    parser.add_argument('-precond', type=str, default='H1', choices=['H1', 'A', 'full'],
                        help='Leading block uses H1 or (H1 + the averaging term) or the full system matrix')
    
    args, petsc_args = parser.parse_known_args()
github firedrakeproject / firedrake / firedrake / petsc.py View on Github external
# Utility module that imports and initialises petsc4py
import petsc4py
import sys
petsc4py.init(sys.argv)
from petsc4py import PETSc
# Always abort on petsc errors
PETSc.Sys.pushErrorHandler("mpiabort")
github Geodels / eSCAPE / eSCAPE / tools / inputparser.py View on Github external
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or any later version.
#
# eSCAPE is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with eSCAPE.  If not, see .
###

import numpy as np
from mpi4py import MPI
import sys,petsc4py
petsc4py.init(sys.argv)
from petsc4py import PETSc
from time import clock
import warnings;warnings.simplefilter('ignore')

import ruamel.yaml as yaml
import meshio

import pandas as pd
from operator import itemgetter
from scipy.interpolate import interp1d

MPIrank = PETSc.COMM_WORLD.Get_rank()
MPIsize = PETSc.COMM_WORLD.Get_size()
MPIcomm = MPI.COMM_WORLD

try: range = xrange
github JesseLu / petsc4py-tutorial / vec_serial.py View on Github external
# Summary
#     Creating and using vectors and basic vector operations in PETSc.
# 
# Description
#     Vectors are a basic mathematical building block.
# 
# For a complete list of vector operations, consult the PETSc user manual.
# Also look at the petsc4py/src/PETSc/Vec.pyx file for petsc4py implementation
# details.

import sys
import petsc4py
petsc4py.init(sys.argv)
from petsc4py import PETSc

n = 10 # Size of vector.

# x = PETSc.Vec().create() # Create vector the long way.
# x.setSizes(n) 
# x.setType('seq') # 'seq' means sequential vector.
# 
# x.assemblyBegin() # Needed in order to work on vector.
# x.assemblyEnd()

x = PETSc.Vec().createSeq(n) # Faster way to create a sequential vector.

x.setValues(range(n), range(n)) # x = [0 1 ... 9]
x.shift(1) # x = x + 1 (add 1 to all elements in x)
github petsc / petsc / src / ts / examples / tutorials / ex8.py View on Github external
import sys, petsc4py
petsc4py.init(sys.argv)
from petsc4py import PETSc
import math

class MyODE:
  def __init__(self,da):
    self.da = da
  def function(self, ts,t,x,f):
    mx = da.getSizes(); mx = mx[0]; hx = 1.0/mx
    (xs,xm) = da.getCorners(); xs = xs[0]; xm = xm[0]
    xx = da.createLocalVector()
    da.globalToLocal(x,xx)
    dt = ts.getTimeStep()
    x0 = ts.getSolution()
    if xs == 0: f[0] = xx[0]/hx; xs = 1;
    if xs+xm >= mx: f[mx-1] = xx[xm-(xs==1)]/hx; xm = xm-(xs==1);
    for i in range(xs,xs+xm-1):
github anstmichaels / emopt / emopt / fdtd.py View on Github external
"""
from __future__ import print_function
from __future__ import absolute_import

from builtins import zip
from builtins import range
from builtins import object
from .simulation import MaxwellSolver
from .defs import FieldComponent
from .misc import DomainCoordinates, RANK, MathDummy, NOT_PARALLEL, COMM, \
info_message, warning_message, N_PROC, run_on_master
from .fdtd_ctypes import libFDTD
from .modes import ModeFullVector
import petsc4py
import sys
petsc4py.init(sys.argv)

from petsc4py import PETSc
import numpy as np
from math import pi
from mpi4py import MPI
import sys

__author__ = "Andrew Michaels"
__license__ = "GPL License, Version 3.0"
__version__ = "2019.5.6"
__maintainer__ = "Andrew Michaels"
__status__ = "development"

class SourceArray(object):
    """A container for source arrays and its associated parameters.
github jolivetr / mpits / massive.py View on Github external
if massiveObject is None:
            
            # Import a bunch of stuff to initialize the mpi communicator
            import mpi4py
            from mpi4py import MPI

            # Stores the communicator
            self.MPI = MPI
            self.Com = MPI.COMM_WORLD

            # Initialize the rank
            self.rank = self.Com.Get_rank()

            # Import a bunch of stuff to initialize the petsc business
            import petsc4py
            petsc4py.init(sys.argv,comm=self.Com)
            from petsc4py import PETSc

            # Store PETSc into self
            self.PETSc = PETSc

        else:
            self.PETSc = massiveObject.PETSc
            self.MPI = massiveObject.MPI
            self.Com = massiveObject.Com
            self.rank = massiveObject.Com.Get_rank()

        # Ignore zero entries in mat() and vec()
        self.ZER = self.PETSc.Mat.Option.IGNORE_ZERO_ENTRIES
        # Insert, rather than Add
        self.INS = self.PETSc.InsertMode.INSERT_VALUES
        # Add, rather than insert
github Geodels / eSCAPE / eSCAPE / __init__.py View on Github external
Submodules
==========

.. autosummary::
    :toctree: _autosummary

    mesher
    flow
    pit
    tools

"""

import petsc4py,sys
petsc4py.init(sys.argv)
from time import clock
from mpi4py import MPI
from .mesher import UnstMesh as _UnstMesh
from .pit import UnstPit as _UnstPit
from .tools import ReadYaml as _ReadYaml
from .tools import WriteMesh as _WriteMesh
from petsc4py import PETSc as _PETSc
from .flow import SPMesh as _SPMesh

import tools

MPIrank = MPI.COMM_WORLD.Get_rank()

def LandscapeEvolutionModel(filename, *args, **kwargs):
    """
    Instantiates eSCAPE model object and performs surface processes evolution.