Skip to content
This repository has been archived by the owner on Apr 23, 2021. It is now read-only.

Commit

Permalink
Merge pull request #326 from simphony/generic-interface-mesh
Browse files Browse the repository at this point in the history
Generic interface for Mesh
  • Loading branch information
mehdisadeghi committed Nov 3, 2016
2 parents cd4b326 + ecf81a6 commit 1d0189d
Show file tree
Hide file tree
Showing 12 changed files with 960 additions and 324 deletions.
3 changes: 2 additions & 1 deletion simphony/cuds/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from .abc_lattice import ABCLattice
from .abc_mesh import ABCMesh
from .abc_particles import ABCParticles
from .mesh import Mesh, Point, Element, Edge, Face, Cell
from .mesh import Mesh
from .mesh_items import Point, Element, Edge, Face, Cell
from .lattice import Lattice, LatticeNode
from .particles import Particles, Particle, Bond
from .model import CUDS
Expand Down
189 changes: 189 additions & 0 deletions simphony/cuds/abc_dataset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
# -*- coding: utf-8 -*-
from abc import ABCMeta, abstractmethod


class ABCDataset(object):
"""Abstract base class for a dataset.
"""
__metaclass__ = ABCMeta

@abstractmethod
def add(self, iterable): # pragma: no cover
"""Adds a set of objects from the provided iterable
to the dataset.
If any object has no uids, the dataset will generate a new
uid for it. If the object has already an uid, it won't add the
object if an object with the same type uid already exists.
If the user wants to replace an existing object in the container
there is an 'update' method for that purpose.
Parameters
----------
iterable : iterable of objects
the new set of objects that will be included in the container.
Returns
-------
uids : list of uuid.UUID
The uids of the added objects.
Raises
------
ValueError :
when there is an object with an uids that already exists
in the dataset.
"""

@abstractmethod
def update(self, iterable): # pragma: no cover
"""Updates a set of objects from the provided iterable.
Takes the uids of the objects and searches inside the dataset for
those objects. If the object exists, they are replaced in the
dataset. If any object doesn't exist, it will raise an exception.
Parameters
----------
iterable : iterable of objects
the objects that will be replaced.
Raises
------
ValueError :
If any object inside the iterable does not exist.
"""

@abstractmethod
def get(self, uid): # pragma: no cover
"""Returns a copy of the object with the 'uid' id.
Parameters
----------
uid : uuid.UUID
the uid of the object
Raises
------
KeyError :
when the object is not in the container.
Returns
-------
object :
A copy of the internally stored info.
"""

@abstractmethod
def remove(self, uids): # pragma: no cover
"""Remove the object with the provided uids from the container.
The uids inside the iterable should exists in the container. Otherwise
an exception will be raised.
Parameters
----------
uids : iterable of uuid.UUID
the uids of the objects to be removed.
Raises
------
KeyError :
If any object doesn't exist.
"""

@abstractmethod
def iter(self, uids=None, item_type=None): # pragma: no cover
"""Generator method for iterating over the objects of the container.
It can receive any kind of sequence of uids to iterate over
those concrete objects. If nothing is passed as parameter, it will
iterate over all the objects.
Parameters
----------
uids : iterable of uuid.UUID, optional
sequence containing the uids of the objects that will be
iterated. When the uids are provided, then the objects are
returned in the same order the uids are returned by the iterable.
If uids is None, then all objects are returned by the iterable
and there is no restriction on the order that they are returned.
Yields
------
object : Particle
The object item.
Raises
------
KeyError :
if any of the ids passed as parameters are not in the dataset.
"""

@abstractmethod
def has(self, uid): # pragma: no cover
"""Checks if an object with the given uid already exists
in the dataset.
Parameters
----------
uid : uuid.UUID
the uid of the object
Returns
-------
True if the uid is found, False otherwise.
"""

@abstractmethod
def has_type(self, item_type): # pragma: no cover
"""Checks if the specified CUDSItem type is present
in the dataset.
Parameters
----------
item_type : CUDSItem
The CUDSItem enum of the type of the items to return the count of.
Returns
-------
True if the type is present, False otherwise.
"""

@abstractmethod
def count_of(self, item_type): # pragma: no cover
""" Return the count of item_type in the container.
Parameters
----------
item_type : CUDSItem
The CUDSItem enum of the type of the items to return the count of.
Returns
-------
count : int
The number of items of item_type in the dataset.
Raises
------
ValueError :
If the type of the item is not supported in the current
dataset.
"""

@abstractmethod
def __len__(self):
"""Returns the total number of items in the container.
Returns
-------
count : int
The number of items of item_type in the dataset.
"""

def __contains__(self, item):
"""Implements the `in` interface. Behaves as the has() method.
"""
return self.has(item)

0 comments on commit 1d0189d

Please sign in to comment.