def __new__(typ, name, **kwargs): obj = IndexedBase.__new__(typ, name) return obj
def __new__(cls, label, shape=None, function=None): obj = IndexedBase.__new__(cls, label, shape) obj.function = function return obj
def __new__(cls, name, rdim, coordinates=None): if isinstance(rdim, (tuple, list, Tuple)): if not len(rdim) == 1: raise ValueError( '> Expecting a tuple, list, Tuple of length 1') rdim = rdim[0] obj = IndexedBase.__new__(cls, name, shape=(rdim)) if coordinates is None: _coordinates = [Symbol(name) for name in ['x', 'y', 'z'][:rdim]] else: if not isinstance(coordinates, (list, tuple, Tuple)): raise TypeError('> Expecting list, tuple, Tuple') for a in coordinates: if not isinstance(a, (str, Symbol)): raise TypeError('> Expecting str or Symbol') _coordinates = [Symbol(name) for name in coordinates] obj._name = name obj._rdim = rdim obj._coordinates = _coordinates obj._jacobian = None obj._det_jacobian = None obj._covariant = None obj._contravariant = None obj._hessian = None # ... if not (obj._expressions is None): coords = ['x', 'y', 'z'][:rdim] # ... args = [] for i in coords: x = obj._expressions[i] x = sympify(x) args.append(x) args = Tuple(*args) # ... # ... lcoords = ['x1', 'x2', 'x3'][:rdim] lcoords = [Symbol(i) for i in lcoords] constants = list(set(args.free_symbols) - set(lcoords)) # subs constants as Constant objects instead of Symbol d = {} for i in constants: # TODO shall we add the type? # by default it is real d[i] = Constant(i.name) args = args.subs(d) # ... obj._expressions = args # ... return obj
def __new__(cls, label, shape=None, **kw_args): return IndexedBase.__new__(cls, label, shape, **kw_args)
def __new__(cls, name, dim=None, **kwargs): ldim = kwargs.pop('ldim', cls._ldim) pdim = kwargs.pop('pdim', cls._pdim) coordinates = kwargs.pop('coordinates', None) evaluate = kwargs.pop('evaluate', True) dims = [dim, ldim, pdim] for i, d in enumerate(dims): if isinstance(d, (tuple, list, Tuple, Matrix, ImmutableDenseMatrix)): if not len(d) == 1: raise ValueError( '> Expecting a tuple, list, Tuple of length 1') dims[i] = d[0] dim, ldim, pdim = dims if dim is None: assert ldim is not None assert pdim is not None assert pdim >= ldim else: ldim = dim pdim = dim obj = IndexedBase.__new__(cls, name, shape=pdim) if not evaluate: return obj if coordinates is None: _coordinates = [Symbol(name) for name in ['x', 'y', 'z'][:pdim]] else: if not isinstance(coordinates, (list, tuple, Tuple)): raise TypeError('> Expecting list, tuple, Tuple') for a in coordinates: if not isinstance(a, (str, Symbol)): raise TypeError('> Expecting str or Symbol') _coordinates = [Symbol(u) for u in coordinates] obj._name = name obj._ldim = ldim obj._pdim = pdim obj._coordinates = tuple(_coordinates) obj._jacobian = kwargs.pop('jacobian', JacobianSymbol(obj)) obj._is_minus = None obj._is_plus = None lcoords = ['x1', 'x2', 'x3'][:ldim] lcoords = [Symbol(i) for i in lcoords] obj._logical_coordinates = Tuple(*lcoords) # ... if not (obj._expressions is None): coords = ['x', 'y', 'z'][:pdim] # ... args = [] for i in coords: x = obj._expressions[i] x = sympify(x) args.append(x) args = Tuple(*args) # ... zero_coords = ['x1', 'x2', 'x3'][ldim:] for i in zero_coords: x = sympify(i) args = args.subs(x, 0) # ... constants = list(set(args.free_symbols) - set(lcoords)) constants_values = {a.name: Constant(a.name) for a in constants} # subs constants as Constant objects instead of Symbol constants_values.update(kwargs) d = {a: constants_values[a.name] for a in constants} args = args.subs(d) obj._expressions = args obj._constants = tuple( a for a in constants if isinstance(constants_values[a.name], Symbol)) args = [obj[i] for i in range(pdim)] exprs = obj._expressions subs = list(zip(_coordinates, exprs)) if obj._jac is None and obj._inv_jac is None: obj._jac = Jacobian(obj).subs(list(zip(args, exprs))) obj._inv_jac = obj._jac.inv() elif obj._inv_jac is None: obj._jac = ImmutableDenseMatrix(sympify(obj._jac)).subs(subs) obj._inv_jac = obj._jac.inv() elif obj._jac is None: obj._inv_jac = ImmutableDenseMatrix(sympify( obj._inv_jac)).subs(subs) obj._jac = obj._inv_jac.inv() else: obj._jac = ImmutableDenseMatrix(sympify(obj._jac)).subs(subs) obj._inv_jac = ImmutableDenseMatrix(sympify( obj._inv_jac)).subs(subs) else: obj._jac = Jacobian(obj) obj._metric = obj._jac.T * obj._jac obj._metric_det = obj._metric.det() return obj