def __init__(self, sigma_0=1., x_c=0.5, x_w=0.5, y_c=0.5, y_w=0.5, eta_0=1., nmodes=10, *args, **kwargs): import warning warning.warm( "SolHA does not appear to generate correct pressure (and possibly other) results." ) if not isinstance(sigma_0, float): raise TypeError("'sigma_0' must be a float.") if not isinstance(eta_0, float) or eta_0 <= 0: raise TypeError("'eta_0' must be a positive float.") if not isinstance(x_c, float): raise TypeError("'x_c' parameter must be of type 'float'.") if not isinstance(x_w, float): raise TypeError("'x_w' parameter must be of type 'float'.") if not isinstance(y_c, float): raise TypeError("'y_c' parameter must be of type 'float'.") if not isinstance(y_w, float): raise TypeError("'y_w' parameter must be of type 'float'.") if not isinstance(nmodes, int) or nmodes <= 0: raise TypeError("'nmodes' parameter must be a positive int.") self._ckeep = _cfn.SolHA(sigma_0, x_c, x_w, y_c, y_w, eta_0, nmodes) super(SolHA, self).__init__(_cfn.SolHACRTP(self._ckeep, 3), **kwargs)
def __init__(self, sigma_0=1., x_c=0.375, x_w=0.25, eta_A=1., eta_B=10., z_c=0.75, nmodes=200, *args, **kwargs): if not isinstance(sigma_0, float): raise TypeError("'sigma_0' must be a float.") if not isinstance(eta_A, float) or eta_A <= 0: raise TypeError("'eta_A' must be a positive float.") if not isinstance(eta_B, float) or eta_B <= 0: raise TypeError("'eta_B' must be a positive float.") if not isinstance(x_c, float): raise TypeError("'x_c' parameter must be of type 'float'.") if not isinstance(x_w, float): raise TypeError("'x_w' parameter must be of type 'float'.") if not isinstance(z_c, float): raise TypeError("'z_c' parameter must be of type 'float'.") if not isinstance(nmodes, int) or nmodes <= 0: raise TypeError("'nmodes' parameter must be a positive int.") self._ckeep = _cfn.SolDA(sigma_0, x_c, x_w, eta_A, eta_B, z_c, nmodes) super(SolDA, self).__init__(_cfn.SolDACRTP(self._ckeep, 2), **kwargs)
def __init__(self, eta_0=1., n_z=1, r=1.5, *args, **kwargs): if not isinstance(eta_0, float) or eta_0 <= 0.: raise TypeError("'eta_0' can be any positive float.") if not isinstance(n_z, int): raise TypeError("'n_z' must be an int.") if not isinstance(r, float): raise TypeError("'r' parameter must be a 'float'.") self._ckeep = _cfn.SolNL(eta_0, n_z, r) super(SolNL, self).__init__(_cfn.SolNLCRTP(self._ckeep, 2), **kwargs) self.nonlinear = True
def _functionio_for_numpy(self, function_io_guy): """ This method simply takes a swig proxy to a FunctionIO, and returns the data as a numpy array. """ # create input function just so we can process using query inputfn = _function.input() # create function_io iterator func_io_it = _cfn.FunctionIOIter(function_io_guy) # process return _cfn.Query(inputfn._fncself).query(func_io_it)
def __init__(self, sigma_0=1., n_x=3, n_z=2., eta_0=1., *args, **kwargs): if eta_0 <= 0: raise TypeError("'eta_0' parameter must be positive.") if sigma_0 <= 0: raise TypeError("'sigma_0' parameter must be positive.") if not isinstance(n_x, int): raise TypeError("'n_x' parameter must be of 'int' type.") if abs(float(n_x) - float(n_z)) < 1e-5: raise TypeError("'n_z' must be different than 'n_z'.") self._ckeep = _cfn.SolB(float(sigma_0), float(eta_0), n_x, float(n_z)) super(SolB, self).__init__(_cfn.SolBCRTP(self._ckeep, 2), **kwargs)
def __init__(self, n_z=3, eta_A=1., eta_B=1.e8, x_c=0.75, *args, **kwargs): if not isinstance(eta_A, float) or eta_A <= 0: raise TypeError("'eta_A' must be a positive float.") if not isinstance(eta_B, float) or eta_B <= 0: raise TypeError("'eta_B' must be a positive float.") if not isinstance(x_c, float): raise TypeError("'x_c' parameter must be of type 'float'.") if not isinstance(n_z, int): raise TypeError("'n_z' parameter must be of type 'int'.") self._ckeep = _cfn.SolCx(eta_A, eta_B, x_c, n_z) super(SolCx, self).__init__(_cfn.SolCxCRTP(self._ckeep, 2), **kwargs)
def __init__(self, eta_0=1., n_x=3, n_z=2, m_x=4., *args, **kwargs): if not isinstance(eta_0, float) or eta_0 <= 0.: raise TypeError("'eta_0' can be any positive float.") if not isinstance(n_x, int): raise TypeError("'n_x' must be an int.") if not isinstance(n_z, int): raise TypeError("'n_z' must be an int.") if not isinstance(m_x, float): raise TypeError("'m_x' parameter must be a 'float' and != 'n_z'.") if abs(float(n_z) - m_x) < 1e-5: raise TypeError("'m_x' must be different than 'n_z'.") self._ckeep = _cfn.SolM(eta_0, n_x, n_z, m_x) super(SolM, self).__init__(_cfn.SolMCRTP(self._ckeep, 2), **kwargs)
def __init__(self, sigma_0=1., n_x=3, n_z=2., eta_0=1., *args, **kwargs): if eta_0 <= 0: raise TypeError("'eta_0' parameter must be positive.") if sigma_0 <= 0: raise TypeError("'sigma_0' parameter must be positive.") if not isinstance(n_x, int): raise TypeError("'n_x' parameter must be of 'int' type.") # note the way we need to use the swig generated constructor is somewhat # ass about.. swig doesn't play particularly nice with CRTP, but there # might be a better way. self._ckeep = _cfn.SolA(float(sigma_0), float(eta_0), n_x, float(n_z)) # the second parameter to SolACRTP is the dimensionality super(SolA, self).__init__(_cfn.SolACRTP(self._ckeep, 2), **kwargs)
def __init__(self, sigma_0=1., x_c=0.5, eta_0=1., nmodes=200, *args, **kwargs): if not isinstance(eta_0, float) or eta_0 <= 0: raise TypeError("'eta_0' must be a positive float.") if not isinstance(x_c, float): raise TypeError("'x_c' parameter must be of type 'float'.") self._ckeep = _cfn.SolC(sigma_0, eta_0, x_c, nmodes) super(SolC, self).__init__(_cfn.SolCCRTP(self._ckeep, 2), **kwargs)
def __init__(self, *args, **kwargs): # create instance self._fncself = _cfn.Input() # build parent super(input,self).__init__(argument_fns=None, *args, **kwargs)
def __init__(self, vertices, fn=None, *args, **kwargs): if fn: self._fn = _Function.convert(fn) else: self._fn = _input() if not isinstance(vertices, _np.ndarray): raise TypeError("Provided 'vertices' must be a numpy array.") if len(vertices.shape) != 2: raise TypeError("Provided 'vertices' array must be 2 dimensional.") if vertices.shape[0] < 3: raise TypeError( "Provided 'vertices' array must contain at least 3 vertices.") if vertices.shape[1] != 2: raise TypeError( "Provided 'vertices' array must contain 2d vectors.") # ok, need to create a 3d array from the 2d array.. create array of required size threedeearray = _np.zeros((vertices.shape[0], 3)) # now copy threedeearray[:, 0:2] = vertices[:, 0:2] # create instance self._fncself = _cfn.Polygon(self._fn._fncself, threedeearray) # build parent super(Polygon, self).__init__(argument_fns=[ fn, ], *args, **kwargs)
def __init__(self, clauses, *args, **kwargs): # error check mapping if not isinstance(clauses, (list, tuple)): raise TypeError( "'clauses' object passed in must be of python type 'list' or 'tuple'" ) self._clauses = [] funcSet = set() for clause in clauses: if not isinstance(clause, (list, tuple)): raise TypeError( "Clauses within the clause list must be of python type 'list' or 'tuple'" ) if len(clause) != 2: raise ValueError("Clauses tuples must be of length 2.") conditionFn = _Function.convert(clause[0]) funcSet.add(conditionFn) resultantFn = _Function.convert(clause[1]) funcSet.add(resultantFn) self._clauses.append((conditionFn, resultantFn)) # build parent self._fncself = _cfn.Conditional() super(conditional, self).__init__(argument_fns=funcSet, **kwargs) # insert clause into c object now for clause in self._clauses: self._fncself.insert(clause[0]._fncself, clause[1]._fncself)
def __init__(self, fn, fn_norm=None, fn_auxiliary=None, *args, **kwargs): _fn = _function.Function.convert(fn) if _fn == None: raise ValueError("provided 'fn' must a 'Function' or convertible.") self._fn = _fn fn_norm_cself = None if fn_norm: _fn_norm = _function.Function.convert(fn_norm) if _fn_norm == None: raise ValueError( "provided 'fn_norm' must a 'Function' or convertible.") self._fn_norm = _fn_norm fn_norm_cself = _fn_norm._fncself fn_auxiliary_cself = None if fn_auxiliary: _fn_auxiliary = _function.Function.convert(fn_auxiliary) if _fn_auxiliary == None: raise ValueError( "provided 'fn_auxiliary' must a 'Function' or convertible." ) self._fn_auxiliary = _fn_auxiliary fn_auxiliary_cself = _fn_auxiliary._fncself # create c instance self._fncself = _cfn.MinMax(self._fn._fncself, fn_norm_cself, fn_auxiliary_cself) # build parent super(min_max, self).__init__(argument_fns=[ fn, ], **kwargs)
def __init__(self, swarm, **kwargs): # create instance self._fncself = _cfn.ParticleFound(swarm._cself) # build parent super(_fn_particle_found,self).__init__(argument_fns=None, **kwargs) self._underlyingDataItems.add(swarm)
def __init__(self, value, *args, **kwargs): # lets try and convert self._ioguy = self._GetIOForPyInput(value) self._value = value self._fncself = _cfn.Constant(self._ioguy) # build parent super(constant,self).__init__(argument_fns=None,**kwargs)
def __init__(self, sigma_0=1., n_x=3, n_z=2., B=2.302585092994046, *args, **kwargs): if not isinstance(sigma_0, float) or sigma_0 != 1.: raise TypeError("'sigma_0' can be any float as long as it's 1.") if not isinstance(n_x, int): raise TypeError("'n_x' must be an int.") if not isinstance(n_z, (int, float)): raise TypeError("'n_z' parameter must be of type 'float'.") if not isinstance(B, float): raise TypeError("'B' parameter must be of type 'float'.") self._ckeep = _cfn.SolKz(sigma_0, n_x, n_z, B) super(SolKz, self).__init__(_cfn.SolKzCRTP(self._ckeep, 2), **kwargs)
def __init__(self, meshvariable, **kwargs): # create instance self._fncself = _cfn.GradFeVariableFn(meshvariable._cself) # build parent super(_gradient, self).__init__(argument_fns=None, **kwargs) self._underlyingDataItems.add(meshvariable)
def __init__(self, sigma_0=1000., x_c=0.5, y_c=0.5, eta_0=1., nmodes=30, *args, **kwargs): if not isinstance(sigma_0, float): raise TypeError("'sigma_0' must be a float.") if not isinstance(eta_0, float) or eta_0 <= 0: raise TypeError("'eta_0' must be a positive float.") if not isinstance(x_c, float): raise TypeError("'x_c' parameter must be of type 'float'.") if not isinstance(y_c, float): raise TypeError("'y_c' parameter must be of type 'float'.") if not isinstance(nmodes, int) or nmodes <= 0: raise TypeError("'nmodes' parameter must be a positive int.") self._ckeep = _cfn.SolH(sigma_0, x_c, y_c, eta_0, nmodes) super(SolH, self).__init__(_cfn.SolHCRTP(self._ckeep, 3), **kwargs)
def __init__(self, fn1, fn2, **kwargs): fn1fn = Function.convert( fn1 ) if not isinstance( fn1fn, Function ): raise TypeError("Functions must be of type (or convertible to) 'Function'.") fn2fn = Function.convert( fn2 ) if not isinstance( fn2fn, Function ): raise TypeError("Functions must be of type (or convertible to) 'Function'.") self._fn1 = fn1fn self._fn2 = fn2fn # ok finally lets create the fn self._fncself = _cfn.Multiply(self._fn1._fncself, self._fn2._fncself ) # build parent super(multiply,self).__init__(argument_fns=[fn1fn,fn2fn], **kwargs)
def __init__(self, fn_key=None, mapping=None, fn_default=None, *args, **kwargs): if not mapping: raise ValueError( "You must specify a mapping via the 'mapping' parameter.") if not isinstance(mapping, dict): raise TypeError( "'mapping' object passed in must be of python type 'dict'") if not fn_key: raise ValueError( "You must specify a key function via the 'fn_key' parameter.") fn_key = _Function.convert(fn_key) self.fn_default = _Function.convert(fn_default) if self.fn_default == None: fn_defaultCself = None else: fn_defaultCself = self.fn_default._fncself # create instance self._fncself = _cfn.Map(fn_key._fncself, fn_defaultCself) self._fn_key = fn_key self._mapping = mapping # build parent super(map, self).__init__(argument_fns=[fn_key, self.fn_default], **kwargs) self._map = {} for key, value in mapping.items(): if not isinstance(key, int) or key < 0: raise ValueError( "Key '{}' not valid. Mapping keys must be unsigned integers." .format(key)) funcVal = _Function.convert(value) if funcVal == None: raise ValueError("'None' is not valid for mapped functions.") self._underlyingDataItems.update( funcVal._underlyingDataItems) # update dictionary # insert mapping and keep handles in py dict self._map[key] = funcVal self._fncself.insert(key, funcVal._fncself)
def __init__(self, x_Fn, y_Fn, **kwargs): fn1fn = Function.convert( x_Fn ) if not isinstance( fn1fn, Function ): raise TypeError("Functions must be of type (or convertible to) 'Function'.") fn2fn = Function.convert( y_Fn ) if not isinstance( fn2fn, Function ): raise TypeError("Functions must be of type (or convertible to) 'Function'.") self._fn1 = fn1fn self._fn2 = fn2fn # ok finally lets create the fn self._fncself = _cfn.Subtract(self._fn1._fncself, self._fn2._fncself ) # build parent super(subtract,self).__init__(argument_fns=[fn1fn,fn2fn], **kwargs)
def __init__(self, fn, *args, **kwargs): _fn = _Function.convert(fn) if _fn == None: raise ValueError("provided 'fn' must a 'Function' or convertible.") self._fn = _fn # create instance self._fncself = _cfn.SafeMaths(self._fn._fncself) # build parent super(SafeMaths, self).__init__(argument_fns=[ _fn, ], **kwargs)
def __init__(self, fn): _fn = _function.Function.convert(fn) if _fn == None: raise ValueError("provided 'fn' must a 'Function' or convertible.") self._fn = _fn # create c instance self._fncself = _cfn.Count(self._fn._fncself) # build parent super(count, self).__init__(argument_fns=[ fn, ])
def __init__(self, fn_input, fn_condition, fn_print=None, *args, **kwargs): _fn_input = _Function.convert(fn_input) if _fn_input == None: raise ValueError( "provided 'fn_input' must a 'Function' or convertible.") self._fn_input = _fn_input _fn_condition = _Function.convert(fn_condition) if _fn_condition == None: raise ValueError( "provided 'fn_condition' must a 'Function' or convertible.") self._fn_condition = _fn_condition if fn_print != None: _fn_print = _Function.convert(fn_print) if _fn_print == None: raise ValueError( "provided 'fn_print' must a 'Function' or convertible.") self._fn_print = _fn_print # create instance if not fn_print: self._fncself = _cfn.CustomException(self._fn_input._fncself, self._fn_condition._fncself) else: self._fncself = _cfn.CustomException(self._fn_input._fncself, self._fn_condition._fncself, self._fn_print._fncself) # build parent # note that we only pass in _fn_input as the argument_fns, as _fn_condition & _fn_print are # not dynamically relevant... it is only used for performing the exception check. super(CustomException, self).__init__(argument_fns=[ _fn_input, ], **kwargs)
def __init__(self, fn=None, *args, **kwargs): self._fn = _Function.convert(fn) fncself = None if self._fn: fncself = self._fn._fncself # create instance self._fncself = _cfn.MathUnary_sin(fncself) # build parent super(sin, self).__init__(argument_fns=[ fn, ], **kwargs)
def __init__(self, fn, *args, **kwargs): _fn = _Function.convert(fn) if _fn == None: raise ValueError("provided 'fn' must a 'Function' or convertible.") self._fn = _fn # create instance self._fncself = _cfn.TensorFunc(self._fn._fncself, _cfn.TensorFunc.get_antisymmetric) # build parent super(antisymmetric, self).__init__(argument_fns=[ fn, ], **kwargs)
def __init__(self, fn, n, *args, **kwargs): _fn = Function.convert(fn) if _fn == None: raise ValueError( "provided 'fn' must a 'Function' or convertible.") self._fn = _fn if not isinstance( n, int ): raise TypeError("'n' argument is expected to be of type 'int'.") if n < 0: raise TypeError("'n' argument must be a non-negative integer.") # create instance self._fncself = _cfn.At( self._fn._fncself, n ) # build parent super(at,self).__init__(argument_fns=[fn,], *args, **kwargs)
def _GetIOForPyInput(self, value): if isinstance(value, (int,float,bool) ): if isinstance(value,bool): ioguy = _cfn.IO_bool(1,_cfn.FunctionIO.Scalar) elif isinstance(value, int): ioguy = _cfn.IO_int(1,_cfn.FunctionIO.Scalar) elif isinstance(value,float): ioguy = _cfn.IO_double(1,_cfn.FunctionIO.Scalar) else: raise RuntimeError("Failure during object creation. Please contact developers.") # now set val ioguy.value(value,0) else: try: iterator = iter(value) except TypeError: raise ValueError("'value' object provided to Constant Function constructor does not appear to be valid. " +"Only python types 'int', 'float' and 'bool' are acceptable, or iterable objects " +"homogeneous in these types. Provided object was of type '{}'.".format(value.__class__.__name__) ) else: # iterable tupleGuy = tuple(iterator) try: lenTupleGuy = len(tupleGuy) except: raise ValueError("'value' object provided to Constant function appears to be an iterable, but " +"does not appear to have a known length.") if lenTupleGuy == 0: raise ValueError("'value' object provided to Constant function appears to be an iterable, but " +"seems to be of zero size. Iterable values must be of non-zero size.") firstFella = tupleGuy[0] if isinstance(firstFella,bool): ioguy = _cfn.IO_bool(lenTupleGuy,_cfn.FunctionIO.Array) elif isinstance(firstFella, int): ioguy = _cfn.IO_int(lenTupleGuy,_cfn.FunctionIO.Array) elif isinstance(firstFella,float): ioguy = _cfn.IO_double(lenTupleGuy,_cfn.FunctionIO.Array) else: raise ValueError("'value' object provided to Constant function appears to be an iterable, but " +"does not appear to contain objects of python type 'int', 'float' or 'bool'.") # right, now load in ze data ii = 0 for val in tupleGuy: if not isinstance(val,type(firstFella)): raise ValueError("'value' object provided to Constant function appears to be an iterable, but " +"does not appear to be homogeneous in type. Objects in iterable must all be " +"of python type 'int', 'float' or 'bool'.") ioguy.value(val,ii) ii+=1; return ioguy
def __init__(self, fn1, fn2, **kwargs): # lets convert integer powers to floats if isinstance(fn2, int): fn2 = float(fn2) fn1fn = _Function.convert(fn1) if not isinstance(fn1fn, _Function): raise TypeError( "Functions must be of type (or convertible to) 'Function'.") fn2fn = _Function.convert(fn2) if not isinstance(fn2fn, _Function): raise TypeError( "Functions must be of type (or convertible to) 'Function'.") self._fn1 = fn1fn self._fn2 = fn2fn # ok finally lets create the fn self._fncself = _cfn.Pow(self._fn1._fncself, self._fn2._fncself) # build parent super(pow, self).__init__(argument_fns=[fn1fn, fn2fn], **kwargs)
def __init__(self, Beta=4., *args, **kwargs): self._ckeep = _cfn.SolDB3d(Beta) super(SolDB3d, self).__init__(_cfn.SolDB3dCRTP(self._ckeep, 3), **kwargs)