コード例 #1
0
ファイル: ex17.py プロジェクト: matthiastaus/PyMFEM
                   str(self.win_y + self.stride_y*(sid/self.win_nx)) +
                   ' ' +  str(self.win_w) +  ' ' +  str(self.win_h))
        self.output.send_text(command)
        self.output.flush()

    def send_solution(self, mesh, x):
        if self.output is None: return        
        self.output.send_solution(mesh, x)
    def send_text(self, x):
        if self.output is None: return        
        self.output.send_text(x)
    def flush(self):        
        if self.output is None: return        
        self.output.flush()
        
parser = ArgParser(description='Ex17')
parser.add_argument('-m', '--mesh',
                    default = 'beam-tri.mesh',
                    action = 'store', type = str,
                    help='Mesh file to use.')
parser.add_argument('-r', '--refine',
                    action = 'store', default = -1, type=int,
       help = "Number of times to refine the mesh uniformly, -1 for auto.")
parser.add_argument('-o', '--order',
                    action = 'store', default = 1, type=int,
                    help = "Finite element order (polynomial degree)");
parser.add_argument('-a', '--alpha',
                    action = 'store', default = -1.0, type=float,
       help = '\n'.join(["One of the two DG penalty parameters, typically +1/-1."
                         " See the documentation of class DGElasticityIntegrator."]))
parser.add_argument('-k', '--kappa',
コード例 #2
0
    pairs = [(num, name) for num, name in zip(nums, names)]
    names = [name for num, name in sorted(pairs)]

    return names


def print_help(self):
    print("python test.py -np -v")


if __name__ == "__main__":
    script_path = sys.path[0]  # the location of this file

    from mfem.common.arg_parser import ArgParser
    parser = ArgParser(description='test')
    parser.add_argument('-np',
                        default=2,
                        action='store',
                        type=long,
                        help='Number of processes for MPI')
    parser.add_argument('-verbose',
                        action='store_true',
                        default=False,
                        help='Verbose print out')
    parser.add_argument('-parallel',
                        action='store',
                        default=True,
                        help='Test parallel version')
    parser.add_argument('-serial',
                        action='store',
コード例 #3
0
      ex8p.py -m star-surf.mesh -o 2
'''
import sys
from os.path import expanduser, join
import numpy as np
from numpy import sin, cos, exp, sqrt

from mfem.common.arg_parser import ArgParser

from mfem import path
import mfem.par as mfem
from mpi4py import MPI
num_procs = MPI.COMM_WORLD.size
myid = MPI.COMM_WORLD.rank

parser = ArgParser(description='Ex8p')
parser.add_argument('-m',
                    '--mesh',
                    default='star.mesh',
                    action='store',
                    type=str,
                    help='Mesh file to use.')
parser.add_argument('-o',
                    '--order',
                    action='store',
                    default=1,
                    type=int,
                    help="Finite element order (polynomial degree)")
parser.add_argument('-vis',
                    '--visualization',
                    action='store_true',
コード例 #4
0
   Description:  This example code demonstrates the use of MFEM to define a
                 simple finite element discretization of the Laplace problem
                 -Delta u = 1 with homogeneous Dirichlet boundary conditions.

'''

import sys
from os.path import expanduser, join
import numpy as np

from mfem.common.arg_parser import ArgParser
from mfem import path
import mfem.ser as mfem

parser = ArgParser(description='Ex1 (Laplace Problem)')
parser.add_argument('-m',
                    '--mesh',
                    default='star.mesh',
                    action='store',
                    type=str,
                    help='Mesh file to use.')
parser.add_argument('-vis',
                    '--visualization',
                    action='store_true',
                    help='Enable GLVis visualization')
parser.add_argument(
    '-o',
    '--order',
    action='store',
    default=1,
コード例 #5
0
ファイル: ex12p.py プロジェクト: matthiastaus/PyMFEM
      ex12p.py -m beam-quad-nurbs.mesh
      ex12p.py -m beam-hex-nurbs.mesh
'''
import sys
from os.path import expanduser, join
import numpy as np

from mfem import path
from mfem.common.arg_parser import ArgParser
import mfem.par as mfem
from mpi4py import MPI

num_procs = MPI.COMM_WORLD.size
myid = MPI.COMM_WORLD.rank

parser = ArgParser(description='Ex12 (linear elastisity)')
parser.add_argument('-m',
                    '--mesh',
                    default='beam-tri.mesh',
                    action='store',
                    type=str,
                    help='Mesh file to use.')
parser.add_argument('-o',
                    '--order',
                    action='store',
                    default=1,
                    type=int,
                    help="Finite element order (polynomial degree)")
parser.add_argument("-n",
                    "--num-eigs",
                    action='store',
コード例 #6
0
      ex4p.py -m amr-hex.mesh -o 2 -hb
      ex4p.py -m star-surf.mesh -o 3 -hb
'''
from mfem import path
from mfem.common.arg_parser import ArgParser
import mfem.par as mfem
from mpi4py import MPI
num_procs = MPI.COMM_WORLD.size
myid = MPI.COMM_WORLD.rank

import sys
from os.path import expanduser, join
import numpy as np
from numpy import sin, array, cos

parser = ArgParser(description='Ex4 ')
parser.add_argument('-m',
                    '--mesh',
                    default='star.mesh',
                    action='store',
                    type=str,
                    help='Mesh file to use.')
parser.add_argument('-o',
                    '--order',
                    action='store',
                    default=1,
                    type=int,
                    help="Finite element order (polynomial degree)")
parser.add_argument('-no-bc',
                    '--dont-impose-bc',
                    action='store_false',
コード例 #7
0
    def initialize(self, inMeshObj=None, inMeshFile=None):
        # 2. Problem initialization
        self.parser = ArgParser(description='Based on MFEM Ex16p')
        self.parser.add_argument('-m',
                                 '--mesh',
                                 default='beam-tet.mesh',
                                 action='store',
                                 type=str,
                                 help='Mesh file to use.')
        self.parser.add_argument('-rs',
                                 '--refine-serial',
                                 action='store',
                                 default=1,
                                 type=int,
                                 help="Number of times to refine the mesh \
                    uniformly in serial")
        self.parser.add_argument('-rp',
                                 '--refine-parallel',
                                 action='store',
                                 default=0,
                                 type=int,
                                 help="Number of times to refine the mesh \
            uniformly in parallel")
        self.parser.add_argument('-o',
                                 '--order',
                                 action='store',
                                 default=1,
                                 type=int,
                                 help="Finite element order (polynomial \
                    degree)")
        self.parser.add_argument(
            '-s',
            '--ode-solver',
            action='store',
            default=3,
            type=int,
            help='\n'.join([
                "ODE solver: 1 - Backward Euler, 2 - SDIRK2, \
              3 - SDIRK3", "\t\t 11 - Forward Euler, \
              12 - RK2, 13 - RK3 SSP, 14 - RK4."
            ]))
        self.parser.add_argument('-t',
                                 '--t-final',
                                 action='store',
                                 default=20.,
                                 type=float,
                                 help="Final time; start time is 0.")
        self.parser.add_argument("-dt",
                                 "--time-step",
                                 action='store',
                                 default=5e-3,
                                 type=float,
                                 help="Time step.")
        self.parser.add_argument("-v",
                                 "--viscosity",
                                 action='store',
                                 default=0.00,
                                 type=float,
                                 help="Viscosity coefficient.")
        self.parser.add_argument('-L',
                                 '--lmbda',
                                 action='store',
                                 default=1.e0,
                                 type=float,
                                 help='Lambda of Hooks law')
        self.parser.add_argument('-mu',
                                 '--shear-modulus',
                                 action='store',
                                 default=1.e0,
                                 type=float,
                                 help='Shear modulus for Hooks law')
        self.parser.add_argument('-rho',
                                 '--density',
                                 action='store',
                                 default=1.0,
                                 type=float,
                                 help='mass density')
        self.parser.add_argument('-vis',
                                 '--visualization',
                                 action='store_true',
                                 help='Enable GLVis visualization')
        self.parser.add_argument('-vs',
                                 '--visualization-steps',
                                 action='store',
                                 default=25,
                                 type=int,
                                 help="Visualize every n-th timestep.")
        args = self.parser.parse_args()
        self.ser_ref_levels = args.refine_serial
        self.par_ref_levels = args.refine_parallel
        self.order = args.order
        self.dt = args.time_step
        self.visc = args.viscosity
        self.t_final = args.t_final
        self.lmbda = args.lmbda
        self.mu = args.shear_modulus
        self.rho = args.density
        self.visualization = args.visualization
        self.ti = 1
        self.vis_steps = args.visualization_steps
        self.ode_solver_type = args.ode_solver
        self.t = 0.0
        self.last_step = False
        if self.myId == 0: self.parser.print_options(args)

        # 3. Reading mesh
        if inMeshObj is None:
            self.meshFile = inMeshFile
            if self.meshFile is None:
                self.meshFile = args.mesh
            self.mesh = mfem.Mesh(self.meshFile, 1, 1)
        else:
            self.mesh = inMeshObj
        self.dim = self.mesh.Dimension()
        print("Mesh dimension: %d" % self.dim)
        print("Number of vertices in the mesh: %d " % self.mesh.GetNV())
        print("Number of elements in the mesh: %d " % self.mesh.GetNE())

        # 4. Define the ODE solver used for time integration.
        #    Several implicit singly diagonal implicit
        #    Runge-Kutta (SDIRK) methods, as well as
        #    explicit Runge-Kutta methods are available.
        if self.ode_solver_type == 1:
            self.ode_solver = BackwardEulerSolver()
        elif self.ode_solver_type == 2:
            self.ode_solver = mfem.SDIRK23Solver(2)
        elif self.ode_solver_type == 3:
            self.ode_solver = mfem.SDIRK33Solver()
        elif self.ode_solver_type == 11:
            self.ode_solver = ForwardEulerSolver()
        elif self.ode_solver_type == 12:
            self.ode_solver = mfem.RK2Solver(0.5)
        elif self.ode_solver_type == 13:
            self.ode_solver = mfem.RK3SSPSolver()
        elif self.ode_solver_type == 14:
            self.ode_solver = mfem.RK4Solver()
        elif self.ode_solver_type == 22:
            self.ode_solver = mfem.ImplicitMidpointSolver()
        elif self.ode_solver_type == 23:
            self.ode_solver = mfem.SDIRK23Solver()
        elif self.ode_solver_type == 24:
            self.ode_solver = mfem.SDIRK34Solver()
        else:
            print("Unknown ODE solver type: " + str(self.ode_solver_type))
            exit

        # 5. Refine the mesh in serial to increase the
        #    resolution. In this example we do
        #    'ser_ref_levels' of uniform refinement, where
        #    'ser_ref_levels' is a command-line parameter.
        for lev in range(self.ser_ref_levels):
            self.mesh.UniformRefinement()

        # 6. Define a parallel mesh by a partitioning of
        #    the serial mesh. Refine this mesh further
        #    in parallel to increase the resolution. Once the
        #    parallel mesh is defined, the serial mesh can
        #    be deleted.
        self.pmesh = mfem.ParMesh(MPI.COMM_WORLD, self.mesh)
        for lev in range(self.par_ref_levels):
            self.pmesh.UniformRefinement()

        # 7. Define the vector finite element space
        #    representing the current and the
        #    initial temperature, u_ref.
        self.fe_coll = mfem.H1_FECollection(self.order, self.dim)
        self.fespace = mfem.ParFiniteElementSpace(self.pmesh, self.fe_coll,
                                                  self.dim)
        self.fe_size = self.fespace.GlobalTrueVSize()
        if self.myId == 0:
            print("FE Number of unknowns: " + str(self.fe_size))
        true_size = self.fespace.TrueVSize()
        self.true_offset = mfem.intArray(3)
        self.true_offset[0] = 0
        self.true_offset[1] = true_size
        self.true_offset[2] = 2 * true_size
        self.vx = mfem.BlockVector(self.true_offset)
        self.v_gf = mfem.ParGridFunction(self.fespace)
        self.v_gfbnd = mfem.ParGridFunction(self.fespace)
        self.x_gf = mfem.ParGridFunction(self.fespace)
        self.x_gfbnd = mfem.ParGridFunction(self.fespace)
        self.x_ref = mfem.ParGridFunction(self.fespace)
        self.pmesh.GetNodes(self.x_ref)

        # 8. Set the initial conditions for u.
        #self.velo = InitialVelocity(self.dim)
        self.velo = velBCs(self.dim)
        #self.deform =  InitialDeformation(self.dim)
        self.deform = defBCs(self.dim)
        self.v_gf.ProjectCoefficient(self.velo)
        self.v_gfbnd.ProjectCoefficient(self.velo)
        self.x_gf.ProjectCoefficient(self.deform)
        self.x_gfbnd.ProjectCoefficient(self.deform)
        #self.v_gf.GetTrueDofs(self.vx.GetBlock(0));
        #self.x_gf.GetTrueDofs(self.vx.GetBlock(1));

        # setup boundary-conditions
        self.xess_bdr = mfem.intArray(
            self.fespace.GetMesh().bdr_attributes.Max())
        self.xess_bdr.Assign(0)
        self.xess_bdr[0] = 1
        self.xess_bdr[1] = 1
        self.xess_tdof_list = intArray()
        self.fespace.GetEssentialTrueDofs(self.xess_bdr, self.xess_tdof_list)
        #print('True x essential BCs are')
        #self.xess_tdof_list.Print()

        self.vess_bdr = mfem.intArray(
            self.fespace.GetMesh().bdr_attributes.Max())
        self.vess_bdr.Assign(0)
        self.vess_bdr[0] = 1
        self.vess_bdr[1] = 1
        self.vess_tdof_list = intArray()
        self.fespace.GetEssentialTrueDofs(self.vess_bdr, self.vess_tdof_list)
        #print('True v essential BCs are')
        #self.vess_tdof_list.Print()

        # 9. Initialize the stiffness operator
        self.oper = StiffnessOperator(self.fespace, self.lmbda, self.mu,
                                      self.rho, self.visc, self.vess_tdof_list,
                                      self.vess_bdr, self.xess_tdof_list,
                                      self.xess_bdr, self.v_gfbnd,
                                      self.x_gfbnd, self.deform, self.velo,
                                      self.vx)

        # 10. Setting up file output
        self.smyid = '{:0>2d}'.format(self.myId)

        # initializing ode solver
        self.ode_solver.Init(self.oper)