# This file was automatically generated by SWIG (https://www.swig.org).
# Version 4.1.1
#
# Do not make changes to this file unless you know what you are doing - modify
# the SWIG interface file instead.

from sys import version_info as _swig_python_version_info
# Import the low-level C/C++ module
if __package__ or "." in __name__:
    from . import _propertyoutput
else:
    import _propertyoutput

try:
    import builtins as __builtin__
except ImportError:
    import __builtin__

def _swig_repr(self):
    try:
        strthis = "proxy of " + self.this.__repr__()
    except __builtin__.Exception:
        strthis = ""
    return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)


def _swig_setattr_nondynamic_instance_variable(set):
    def set_instance_attr(self, name, value):
        if name == "this":
            set(self, name, value)
        elif name == "thisown":
            self.this.own(value)
        elif hasattr(self, name) and isinstance(getattr(type(self), name), property):
            set(self, name, value)
        else:
            raise AttributeError("You cannot add instance attributes to %s" % self)
    return set_instance_attr


def _swig_setattr_nondynamic_class_variable(set):
    def set_class_attr(cls, name, value):
        if hasattr(cls, name) and not isinstance(getattr(cls, name), property):
            set(cls, name, value)
        else:
            raise AttributeError("You cannot add class attributes to %s" % cls)
    return set_class_attr


def _swig_add_metaclass(metaclass):
    """Class decorator for adding a metaclass to a SWIG wrapped class - a slimmed down version of six.add_metaclass"""
    def wrapper(cls):
        return metaclass(cls.__name__, cls.__bases__, cls.__dict__.copy())
    return wrapper


class _SwigNonDynamicMeta(type):
    """Meta class to enforce nondynamic attributes (no new attributes) for a class"""
    __setattr__ = _swig_setattr_nondynamic_class_variable(type.__setattr__)


import ooflib.SWIG.engine.mastercoord
import ooflib.SWIG.engine.property
import ooflib.SWIG.engine.outputval
import ooflib.SWIG.engine.fieldindex
import ooflib.SWIG.engine.planarity
class PropertyOutputValInit(object):
    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")

    def __init__(self, *args, **kwargs):
        raise AttributeError("No constructor defined")
    __repr__ = _swig_repr
    __swig_destroy__ = _propertyoutput.delete_PropertyOutputValInit

# Register PropertyOutputValInit in _propertyoutput:
_propertyoutput.PropertyOutputValInit_swigregister(PropertyOutputValInit)
class DefaultPropertyOutputValInit(PropertyOutputValInit):
    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
    __repr__ = _swig_repr

    def __init__(self, arg2):
        _propertyoutput.DefaultPropertyOutputValInit_swiginit(self, _propertyoutput.new_DefaultPropertyOutputValInit(arg2))
    __swig_destroy__ = _propertyoutput.delete_DefaultPropertyOutputValInit

# Register DefaultPropertyOutputValInit in _propertyoutput:
_propertyoutput.DefaultPropertyOutputValInit_swigregister(DefaultPropertyOutputValInit)
class PropertyOutputInit(object):
    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")

    def __init__(self, *args, **kwargs):
        raise AttributeError("No constructor defined")
    __repr__ = _swig_repr
    __swig_destroy__ = _propertyoutput.delete_PropertyOutputInit

# Register PropertyOutputInit in _propertyoutput:
_propertyoutput.PropertyOutputInit_swigregister(PropertyOutputInit)
class ArithmeticPropertyOutputInit(PropertyOutputInit):
    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
    __repr__ = _swig_repr

    def __init__(self):
        _propertyoutput.ArithmeticPropertyOutputInit_swiginit(self, _propertyoutput.new_ArithmeticPropertyOutputInit())
    __swig_destroy__ = _propertyoutput.delete_ArithmeticPropertyOutputInit

# Register ArithmeticPropertyOutputInit in _propertyoutput:
_propertyoutput.ArithmeticPropertyOutputInit_swigregister(ArithmeticPropertyOutputInit)
class NonArithmeticPropertyOutputInit(PropertyOutputInit):
    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
    __repr__ = _swig_repr

    def __init__(self):
        _propertyoutput.NonArithmeticPropertyOutputInit_swiginit(self, _propertyoutput.new_NonArithmeticPropertyOutputInit())
    __swig_destroy__ = _propertyoutput.delete_NonArithmeticPropertyOutputInit

# Register NonArithmeticPropertyOutputInit in _propertyoutput:
_propertyoutput.NonArithmeticPropertyOutputInit_swigregister(NonArithmeticPropertyOutputInit)
class PropertyOutput(object):
    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")

    def __init__(self, *args, **kwargs):
        raise AttributeError("No constructor defined")
    __repr__ = _swig_repr
    __swig_destroy__ = _propertyoutput.delete_PropertyOutput

    def name(self):
        return _propertyoutput.PropertyOutput_name(self)

    def getFloatParam(self, arg2):
        return _propertyoutput.PropertyOutput_getFloatParam(self, arg2)

    def getIntParam(self, arg2):
        return _propertyoutput.PropertyOutput_getIntParam(self, arg2)

    def setInitializer(self, arg2):
        return _propertyoutput.PropertyOutput_setInitializer(self, arg2)

    def getStringParam(self, arg2):
        return _propertyoutput.PropertyOutput_getStringParam(self, arg2)

    def getEnumParam(self, arg2):
        return _propertyoutput.PropertyOutput_getEnumParam(self, arg2)

    def getRegisteredParamName(self, arg2):
        return _propertyoutput.PropertyOutput_getRegisteredParamName(self, arg2)

    def getListOfStringsParam(self, arg2):
        return _propertyoutput.PropertyOutput_getListOfStringsParam(self, arg2)

# Register PropertyOutput in _propertyoutput:
_propertyoutput.PropertyOutput_swigregister(PropertyOutput)
class ArithmeticPropertyOutput(PropertyOutput):
    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")

    def __init__(self, *args, **kwargs):
        raise AttributeError("No constructor defined")
    __repr__ = _swig_repr

    def evaluate(self, arg2, arg3, arg4):
        return _propertyoutput.ArithmeticPropertyOutput_evaluate(self, arg2, arg3, arg4)
    __swig_destroy__ = _propertyoutput.delete_ArithmeticPropertyOutput

# Register ArithmeticPropertyOutput in _propertyoutput:
_propertyoutput.ArithmeticPropertyOutput_swigregister(ArithmeticPropertyOutput)
class NonArithmeticPropertyOutput(PropertyOutput):
    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")

    def __init__(self, *args, **kwargs):
        raise AttributeError("No constructor defined")
    __repr__ = _swig_repr

    def evaluate(self, arg2, arg3, arg4):
        return _propertyoutput.NonArithmeticPropertyOutput_evaluate(self, arg2, arg3, arg4)
    __swig_destroy__ = _propertyoutput.delete_NonArithmeticPropertyOutput

# Register NonArithmeticPropertyOutput in _propertyoutput:
_propertyoutput.NonArithmeticPropertyOutput_swigregister(NonArithmeticPropertyOutput)
class PropertyOutputRegistration(object):
    thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
    __repr__ = _swig_repr

    def __init__(self, arg2):
        _propertyoutput.PropertyOutputRegistration_swiginit(self, _propertyoutput.new_PropertyOutputRegistration(arg2))
    __swig_destroy__ = _propertyoutput.delete_PropertyOutputRegistration

    def name(self):
        return _propertyoutput.PropertyOutputRegistration_name(self)

    def instantiateArithmetic(self, arg2, arg3):
        return _propertyoutput.PropertyOutputRegistration_instantiateArithmetic(self, arg2, arg3)

    def instantiateNonArithmetic(self, arg2, arg3):
        return _propertyoutput.PropertyOutputRegistration_instantiateNonArithmetic(self, arg2, arg3)

# Register PropertyOutputRegistration in _propertyoutput:
_propertyoutput.PropertyOutputRegistration_swigregister(PropertyOutputRegistration)
# -*- python -*-

# This software was produced by NIST, an agency of the U.S. government,
# and by statute is not subject to copyright in the United States.
# Recipients of this software assume all responsibilities associated
# with its operation, modification and maintenance. However, to
# facilitate maintenance we ask that before distributing modified
# versions of this software, you first contact the authors at
# oof_manager@nist.gov.

# The PropertyOutputRegistration subclasses create an Output object
# for each registered PropertyOutput.  This bridges the gap between
# the C++ PropertyOutputs and the more general Python Outputs.

from ooflib.SWIG.engine import ooferror
from ooflib.common import debug
from ooflib.common import utils

class _PORegBase(PropertyOutputRegistration):

# initializer is either a PropertyOutputValInit object, or None.
# If it's None, a default initializer will be used, which
# initializes the OutputVal to zero (or the equivalent).  Most of
# the time, the default should be sufficient.
# Subclasses' constructors must create an actual Output object and
# pass it in here as the 'output' argument.
    def __init__(self, name, output, initializer=None):
        self.initializer = initializer
        self.output = output
        PropertyOutputRegistration.__init__(self, name)

## Callback for all PropertyOutputs.  Outputs that need to return
## something other than a list of OutputVal instances should
## override the convert method.
    def opfunc(self, mesh, elements, coords, **params):

# params is a dictionary of parameter values keyed by
# parameter names.  At this point, the values have already
# been extracted from the Parameter objects.

# instantiate is PropertyOutputRegistration.instantiate,
# defined in propertyoutput.h.  It calls
# PropertyOutputInit::instantiate and creates an instance of a
# PropertyOutput subclass.
        po = self._instantiate(self.name(), params)

# initializer initializes the OutputVal at each evaluation
# point. If an initializer wasn't provided, the default
# initializer just clones a zero-valued OutputVal.  The
# initializer can't be set in _instantiate because its
# constructor might need to retrieve parameters from the
# Output.
# Keep a reference to the initializer so that it persists
# until the opfunc finishes.
        self.zeroObj = None
        if self.initializer is not None:
            self.initObj = self.initializer
        else:
            self.zeroObj = self.zeroVal(params)
            self.initObj = DefaultPropertyOutputValInit(self.zeroObj)

        po.setInitializer(self.initObj)

        mesh.precompute_all_subproblems()
        results = []
        for element, ecoords, in zip(elements, coords):
            mat = element.material()
            if mat and not mat.self_consistent():
                raise ooferror.PyErrBadMaterial(element.material().name())
            mesh.begin_all_subproblems(element)
            results.extend(po.evaluate(mesh, element, ecoords))
            mesh.end_all_subproblems(element)
        return self.convert(results)
    def convert(self, results):
        return results

    def zeroVal(self, argdict):
# Subclasses must define this method, which returns "zero" in
# the format desired for the output.  The argument is a
# dictionary containing the Parameter values keyed by
# Parameter name.
        raise ErrPyProgrammingError("%s.zeroVal is not defined!"
                                    % self.__class__.__name__)
    def instancefn(self, output):
# Return an instance of the OutputVal class that this Output
# will produce when run.  This is non-trivial because the
# OutputVal class may depend on the parameters.  This is
# called when the Output is run, but also used to build GUI
# widgets, so it can't assume that _instaniate has already
# been called.

# output is an Output that was built from a PropertyOutput.
# Its params is a dict of Parameter objects keyed by name.  It
# has to be converted into a dict of parameter values keyed by
# name before begin passed to the C++
# PropertyOutputRegistration for instantiation of the
# PropertyOutput.
        pdict = {name:param.value for name,param in output.params.items()}
# Get an OutputVal representing zero
        return self.zeroVal(pdict)

class ArithmeticPropertyOutputRegistration(_PORegBase):
    def __init__(self, name, output, initializer=None):
        output._allowsArithmetic = True
        _PORegBase.__init__(self, name, output, initializer)
    def _instantiate(self, name, params):
        return self.instantiateArithmetic(name, params)

class NonArithmeticPropertyOutputRegistration(_PORegBase):
    def __init__(self, name, output, initializer=None):
        output._allowsArithmetic = False
        _PORegBase.__init__(self, name, output, initializer)
    def _instantiate(self, name, params):
        return self.instantiateNonArithmetic(name, params)

# Concrete subclasses of ArithmeticPropertyOutputRegistration and
# NonArithmeticPropertyOutputRegistration are defined in
# propertyoutputreg.py.


