示例#1
0
    def any_from_args(name, geometry, order, base='lagrange',
                      force_bubble=False):
        """
        Construct a particular polynomial space classes according to the
        arguments passed in.
        """
        if name is None:
            name = PolySpace.suggest_name(geometry, order, base, force_bubble)

        if PolySpace._all is None:
            ps_files = get_paths('sfepy/discrete/fem/poly_spaces.py')
            ps_files += get_paths('sfepy/discrete/dg/poly_spaces.py')
            PolySpace._all = load_classes(ps_files, [PolySpace],
                                          ignore_errors=True,
                                          name_attr='name')
        table = PolySpace._all

        key = '%s_%s' % (base, PolySpace.keys[(geometry.dim,
                                               geometry.n_vertex)])
        if (geometry.name == '1_2') and (key not in table):
            key = '%s_%s' % (base, 'tensor_product')

        if force_bubble:
            key += '_bubble'

        return table[key](name, geometry, order)
示例#2
0
文件: fields.py 项目: mingrener/sfepy
    def from_conf(conf, regions):
        """
        Create a Field subclass instance based on the configuration.
        """
        if Field._all is None:
            from sfepy import get_paths
            from sfepy.base.base import load_classes

            field_files = [
                ii for ii in get_paths('sfepy/discrete/fem/fields*.py')
                if 'fields_base.py' not in ii
            ]
            field_files += get_paths('sfepy/discrete/iga/fields*.py')
            field_files += get_paths('sfepy/discrete/structural/fields*.py')
            field_files += get_paths('sfepy/discrete/dg/fields.py')
            Field._all = load_classes(field_files, [Field],
                                      ignore_errors=True,
                                      name_attr='family_name')
        table = Field._all

        space = conf.get('space', 'H1')
        poly_space_base = conf.get('poly_space_base', 'lagrange')

        key = space + '_' + poly_space_base

        approx_order = parse_approx_order(conf.approx_order)
        ao, force_bubble, discontinuous = approx_order
        region = regions[conf.region]

        if region.kind == 'cell':
            # Volume fields.
            kind = 'volume'

            if discontinuous:
                cls = table[kind + '_' + key + '_discontinuous']

            else:
                cls = table[kind + '_' + key]

            obj = cls(conf.name,
                      conf.dtype,
                      conf.shape,
                      region,
                      approx_order=approx_order[:2])

        else:
            # Surface fields.
            kind = 'surface'

            cls = table[kind + '_' + key]
            obj = cls(conf.name,
                      conf.dtype,
                      conf.shape,
                      region,
                      approx_order=approx_order[:2])

        return obj
示例#3
0
文件: fields.py 项目: Nasrollah/sfepy
    def from_conf(conf, regions):
        """
        Create a Field subclass instance based on the configuration.
        """
        if Field._all is None:
            from sfepy import get_paths
            from sfepy.base.base import load_classes

            field_files = [ii for ii
                           in get_paths('sfepy/discrete/fem/fields*.py')
                           if 'fields_base.py' not in ii]
            field_files += get_paths('sfepy/discrete/iga/fields*.py')
            field_files += get_paths('sfepy/discrete/structural/fields*.py')
            Field._all = load_classes(field_files, [Field], ignore_errors=True,
                                      name_attr='family_name')
        table = Field._all

        space = conf.get('space', 'H1')
        poly_space_base = conf.get('poly_space_base', 'lagrange')

        key = space + '_' + poly_space_base

        approx_order = parse_approx_order(conf.approx_order)
        ao, force_bubble, discontinuous = approx_order
        region = regions[conf.region]

        if region.kind == 'cell':
            # Volume fields.
            kind = 'volume'

            if discontinuous:
                cls = table[kind + '_' + key + '_discontinuous']

            else:
                cls = table[kind + '_' + key]

            obj = cls(conf.name, conf.dtype, conf.shape, region,
                      approx_order=approx_order[:2])

        else:
            # Surface fields.
            kind = 'surface'

            cls = table[kind + '_' + key]
            obj = cls(conf.name, conf.dtype, conf.shape, region,
                      approx_order=approx_order[:2])

        return obj
示例#4
0
    def from_conf(conf, regions):
        """
        Create a Field subclass instance based on the configuration.
        """
        if Field._all is None:
            import sfepy
            from sfepy.base.base import load_classes

            field_files = [ii for ii in sfepy.get_paths('sfepy/fem/fields*.py')
                           if 'fields_base.py' not in ii]
            Field._all = load_classes(field_files, [Field], ignore_errors=True,
                                      name_attr='family_name')
        table = Field._all

        space = conf.get_default_attr('space', 'H1')
        poly_space_base = conf.get_default_attr('poly_space_base', 'lagrange')

        key = space + '_' + poly_space_base

        approx_order = parse_approx_order(conf.approx_order)
        ao, force_bubble, discontinuous = approx_order

        if isinstance(conf.region, tuple):
            # Surface fields.
            region_name, kind = conf.region
            region = regions[region_name]

            cls = table[kind + '_' + key]
            obj = cls(conf.name, conf.dtype, conf.shape, region,
                      approx_order=approx_order[:2])


        else:
            # Volume fields.
            kind = 'volume'

            if discontinuous:
                cls = table[kind + '_' + key + '_discontinuous']

            else:
                cls = table[kind + '_' + key]

            obj = cls(conf.name, conf.dtype, conf.shape, regions[conf.region],
                      approx_order=approx_order[:2])

        return obj
示例#5
0
文件: fields.py 项目: Gkdnz/sfepy
    def from_conf(conf, regions):
        """
        Create a Field subclass instance based on the configuration.
        """
        if Field._all is None:
            from sfepy import get_paths
            from sfepy.base.base import load_classes

            field_files = [ii for ii in get_paths("sfepy/discrete/fem/fields*.py") if "fields_base.py" not in ii]
            field_files += get_paths("sfepy/discrete/iga/fields*.py")
            field_files += get_paths("sfepy/discrete/structural/fields*.py")
            Field._all = load_classes(field_files, [Field], ignore_errors=True, name_attr="family_name")
        table = Field._all

        space = conf.get("space", "H1")
        poly_space_base = conf.get("poly_space_base", "lagrange")

        key = space + "_" + poly_space_base

        approx_order = parse_approx_order(conf.approx_order)
        ao, force_bubble, discontinuous = approx_order
        region = regions[conf.region]

        if region.kind == "cell":
            # Volume fields.
            kind = "volume"

            if discontinuous:
                cls = table[kind + "_" + key + "_discontinuous"]

            else:
                cls = table[kind + "_" + key]

            obj = cls(conf.name, conf.dtype, conf.shape, region, approx_order=approx_order[:2])

        else:
            # Surface fields.
            kind = "surface"

            cls = table[kind + "_" + key]
            obj = cls(conf.name, conf.dtype, conf.shape, region, approx_order=approx_order[:2])

        return obj
示例#6
0
from __future__ import absolute_import
import os
import sfepy
from sfepy.base.base import load_classes, insert_static_method
from .solvers import *
from .eigen import eig

solver_files = sfepy.get_paths('sfepy/solvers/*.py')
remove = ['setup.py', 'solvers.py', 'petsc_worker.py']
solver_files = [name for name in solver_files
                if os.path.basename(name) not in remove]
solver_table = load_classes(solver_files,
                            [LinearSolver, NonlinearSolver,
                             TimeSteppingSolver, EigenvalueSolver,
                             OptimizationSolver], package_name='sfepy.solvers')

def register_solver(cls):
    """
    Register a custom solver.
    """
    solver_table[cls.name] = cls

def any_from_conf(conf, **kwargs):
    """Create an instance of a solver class according to the configuration."""
    return solver_table[conf.kind](conf, **kwargs)
insert_static_method(Solver, any_from_conf)
del any_from_conf
del sfepy
示例#7
0
import sfepy
import terms
import extmods
from terms import Terms, Term, CharacteristicFunction, vector_chunk_generator
from terms_th import THTerm, ETHTerm
from sfepy.base.base import load_classes

term_files = sfepy.get_paths('sfepy/terms/terms*.py')
term_table = load_classes(term_files, [Term], ignore_errors=True)

del sfepy

def register_term(cls):
    """
    Register a custom term.
    """
    term_table[cls.name] = cls
示例#8
0
import sfepy
from sfepy.base.base import load_classes
from sfepy.solvers import NonlinearSolver, TimeSteppingSolver, LinearSolver, \
    EigenvalueSolver, OptimizationSolver

solver_by_type_table = [[[TimeSteppingSolver], "Time-Stepping Solvers"],
                        [[NonlinearSolver], "Nonlinear Solvers"],
                        [[LinearSolver], "Linear Solvers"],
                        [[EigenvalueSolver], "Eigenvalue Problem Solvers"],
                        [[OptimizationSolver], "Optimization Solvers"]]

for i in enumerate(solver_by_type_table):
    solver_by_type_table[i[0]][0] = \
        load_classes(sfepy.solvers.solver_files,
                     solver_by_type_table[i[0]][0],
                     package_name='sfepy.solvers')


def trim(docstring):
    """Trim and split (doc)string."""
    if not docstring:
        return ''
    # Convert tabs to spaces (following the normal Python rules)
    # and split into a list of lines:
    lines = docstring.expandtabs().splitlines()
    # Determine minimum indentation (first line doesn't count):
    indent = sys.maxsize
    for line in lines[1:]:
        stripped = line.lstrip()
        if stripped:
示例#9
0
import sfepy
import terms
import extmods
from terms import Terms, Term, CharacteristicFunction, vector_chunk_generator
from cache import DataCache, DataCaches
from sfepy.base.base import load_classes

term_files = sfepy.get_paths('sfepy/terms/terms*.py')
term_table = load_classes(term_files, [Term], ignore_errors=True)

cache_files = sfepy.get_paths('sfepy/terms/caches*.py')
cache_table = load_classes(cache_files, [DataCache], ignore_errors=True)
del sfepy

def register_term(cls):
    """
    Register a custom term.
    """
    term_table[cls.name] = cls
示例#10
0
import sfepy
import terms
import extmods
from terms import Terms, Term
from terms_th import THTerm, ETHTerm
from sfepy.base.base import load_classes

term_files = sfepy.get_paths('sfepy/terms/terms*.py')
term_table = load_classes(term_files, [Term], ignore_errors=True)

del sfepy


def register_term(cls):
    """
    Register a custom term.
    """
    term_table[cls.name] = cls
示例#11
0
import sfepy
import terms
import extmods
from terms import Terms, Term, CharacteristicFunction, vector_chunk_generator
from cache import DataCache, DataCaches
from sfepy.base.base import load_classes

term_files = sfepy.get_paths('sfepy/terms/terms*.py')
term_table = load_classes(term_files, [Term])

cache_files = sfepy.get_paths('sfepy/terms/caches*.py')
cache_table = load_classes(cache_files, [DataCache])
del sfepy
示例#12
0
from sfepy.solvers.auto_fallback import AutoFallbackSolver

solver_by_type_table = [
    [[AutoFallbackSolver], "Virtual Solvers with Automatic Fallback"],
    [[TimeSteppingSolver], "Time-Stepping Solvers"],
    [[NonlinearSolver], "Nonlinear Solvers"],
    [[LinearSolver], "Linear Solvers"],
    [[EigenvalueSolver], "Eigenvalue Problem Solvers"],
    [[QuadraticEVPSolver], "Quadratic Eigenvalue Problem Solvers"],
    [[OptimizationSolver], "Optimization Solvers"]
]

for i in enumerate(solver_by_type_table):
    solver_by_type_table[i[0]][0] = \
        load_classes(sfepy.solvers.solver_files,
                     solver_by_type_table[i[0]][0],
                     package_name='sfepy.solvers')


def trim(docstring):
    """Trim and split (doc)string."""
    if not docstring:
        return ''
    # Convert tabs to spaces (following the normal Python rules)
    # and split into a list of lines:
    lines = docstring.expandtabs().splitlines()
    # Determine minimum indentation (first line doesn't count):
    indent = sys.maxsize
    for line in lines[1:]:
        stripped = line.lstrip()
        if stripped:
示例#13
0
文件: __init__.py 项目: rc/sfepy
from __future__ import absolute_import
import os
import sfepy
from sfepy.base.base import load_classes, insert_static_method
from .solvers import *
from .eigen import eig
from .auto_fallback import AutoFallbackSolver

solver_files = sfepy.get_paths('sfepy/solvers/*.py')
remove = ['setup.py', 'solvers.py', 'ls_mumps_parallel.py']
solver_files = [name for name in solver_files
                if os.path.basename(name) not in remove]
solver_table = load_classes(solver_files,
                            [AutoFallbackSolver,
                             LinearSolver, NonlinearSolver,
                             TimeSteppingSolver, EigenvalueSolver,
                             QuadraticEVPSolver,
                             OptimizationSolver], package_name='sfepy.solvers')


def register_solver(cls):
    """
    Register a custom solver.
    """
    solver_table[cls.name] = cls

def any_from_conf(conf, **kwargs):
    """Create an instance of a solver class according to the configuration."""
    try:
        return solver_table[conf.kind](conf, **kwargs)
    except Exception: