Skip to content

Commit

Permalink
Devel bounds (#60)
Browse files Browse the repository at this point in the history
* refactor: Use 'args' property instead of '_args' attribute.

As described in Sympy's User Guide, one should never use internal
methods of variables, prefixed with '_' (as an example, it is explicitly
written that one should not use '_args', but use 'args' instead).

Here we apply this rule to the two main modules in the 'topology'
directory: 'basic' and 'domain'.

* refactor: Improve Boundary class

* refactor: Remove obsolete module

* feat: Add coord bounds to Line/Square/Cube domains

Several changes in 'domain' module:

* It is now possible to instantiate objects of type Line, Square and
  Cube (these classes were only used as Domain constructors before);

* Line, Square and Cube are subclasses of the generic NCube class, they
  have different constructor signatures, and use NCube's constructor to
  instantiate an object of their type with minimal code duplication;

* NCube is a subclass of Domain; its constructor returns a Line object
  for dim=1, a Square for dim=2, a Cube for dim=3, and a generic NCube
  for dim>=4;

* Line, Square, Cube, and NCube allow the user to prescribe the
  coordinate bounds, which are (0, 1) by default.

Moreover, unit tests for the new features are provided.

* chore: Do not use latest version of Sympy (1.5)

* refactor: Avoid Codacy errors
  • Loading branch information
yguclu authored Dec 18, 2019
1 parent 013a8c1 commit 860eb6a
Show file tree
Hide file tree
Showing 5 changed files with 376 additions and 145 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

# Dependencies
install_requires = [
'sympy>=1.2',
'sympy>=1.2,<1.5',
'h5py',
'pytest',
'pyyaml',
Expand Down
68 changes: 27 additions & 41 deletions sympde/topology/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __new__(cls, name, dim=None):

@property
def name(self):
return self._args[0]
return self.args[0]

@property
def target(self):
Expand Down Expand Up @@ -122,31 +122,31 @@ def __new__(cls, *args):

@property
def dim(self):
return self._args[0].dim
return self.args[0].dim

def __len__(self):
return len(self._args)
return len(self.args)

def complement(self, arg):
if isinstance(arg, Union):
arg = arg._args
arg = arg.args
elif isinstance(arg, BasicDomain):
arg = [arg]
elif arg is None:
return self
else:
TypeError('Invalid argument {}'.format(arg))

return Union(*[i for i in self._args if (i not in arg)])
return Union(*[i for i in self.args if (i not in arg)])

def __sub__(self, other):
return self.complement(other)

def todict(self):
return [i.todict() for i in self._args]
return [i.todict() for i in self.args]

def as_tuple(self):
ls = [i for i in self._args]
ls = [i for i in self.args]
return tuple(ls)

#==============================================================================
Expand All @@ -161,11 +161,12 @@ def __new__(cls, *args, name=None):
obj = Basic.__new__(cls, *args)
obj._dim = sum(i.dim for i in args)
obj._name = name

return obj

@property
def domains(self):
return self._args
return self.args

#==============================================================================
class Interval(InteriorDomain):
Expand Down Expand Up @@ -193,7 +194,7 @@ def __new__(cls, name=None, coordinate=None, bounds=None):

@property
def name(self):
return self._args[0]
return self.args[0]

@property
def bounds(self):
Expand All @@ -209,37 +210,35 @@ class Boundary(BasicDomain):
"""
def __new__(cls, name, domain, axis=None, ext=None):

if not( axis is None ):
assert(isinstance(axis, int))
if axis is not None:
assert isinstance(axis, int)

if not( ext is None ):
assert(isinstance(ext, int))
if ext is not None:
assert isinstance(ext, int)

obj = Basic.__new__(cls, name, domain, axis, ext)

obj = Basic.__new__(cls, name)
obj._domain = domain
obj._axis = axis
obj._ext = ext
return obj

@property
def name(self):
return self._args[0]
return self.args[0]

@property
def domain(self):
return self._domain

@property
def dim(self):
return self.domain.dim
return self.args[1]

@property
def axis(self):
return self._axis
return self.args[2]

@property
def ext(self):
return self._ext
return self.args[3]

@property
def dim(self):
return self.domain.dim

def _sympystr(self, printer):
sstr = printer.doprint
Expand All @@ -264,19 +263,6 @@ def todict(self):

return OrderedDict(sorted(d.items()))

def __hash__(self):
return hash(self.name)

def __lt__(self, other):
#add this method to avoid sympy error in Basic.compare
return 0

def __eq__(self, other):
if not isinstance(other, Boundary):
return False

return ( self.name == other.name ) and ( self.domain is other.domain )

#==============================================================================
class Interface(BasicDomain):
"""
Expand All @@ -303,15 +289,15 @@ def dim(self):

@property
def name(self):
return self._args[0]
return self.args[0]

@property
def minus(self):
return self._args[1]
return self.args[1]

@property
def plus(self):
return self._args[2]
return self.args[2]

def _sympystr(self, printer):
sstr = printer.doprint
Expand Down
Loading

0 comments on commit 860eb6a

Please sign in to comment.