Skip to content

Commit

Permalink
Merge 637af3f into e2acbe1
Browse files Browse the repository at this point in the history
  • Loading branch information
davidrpugh committed Jul 13, 2015
2 parents e2acbe1 + 637af3f commit b4b734c
Show file tree
Hide file tree
Showing 13 changed files with 365 additions and 270 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
@@ -1,4 +1,5 @@
language: python

python:
- 2.7
- 3.3
Expand Down Expand Up @@ -28,4 +29,4 @@ script:
- nosetests --with-coverage --cover-package=pycollocation

after_success:
- coveralls
- coveralls
6 changes: 5 additions & 1 deletion README.rst
@@ -1,12 +1,16 @@
pyCollocation
=============

|Build Status| |Coverage Status| |Latest Version| |Downloads| |DOI|
|Build Status| |Coverage Status| |Codacy Badge| |Latest Version| |Downloads| |DOI|

.. |Build Status| image:: https://travis-ci.org/davidrpugh/pyCollocation.svg?branch=master
:target: https://travis-ci.org/davidrpugh/pyCollocation
.. |Coverage Status| image:: https://coveralls.io/repos/davidrpugh/pyCollocation/badge.svg?branch=master
:target: https://coveralls.io/r/davidrpugh/pyCollocation?branch=master
.. |Codacy Badge| image:: https://www.codacy.com/project/badge/4838082c243c48afa392aabc7cce54ab
:target: https://www.codacy.com/app/drobert-pugh/pyCollocation
.. |Scrutinizer Code Quality| image:: https://scrutinizer-ci.com/g/davidrpugh/pyCollocation/badges/quality-score.png?b=master
:target: https://scrutinizer-ci.com/g/davidrpugh/pyCollocation/?branch=master
.. |Latest Version| image:: https://img.shields.io/pypi/v/pyCollocation.svg
:target: https://pypi.python.org/pypi/pyCollocation/
.. |Downloads| image:: https://img.shields.io/pypi/dm/pyCollocation.svg
Expand Down
10 changes: 5 additions & 5 deletions pycollocation/__init__.py
Expand Up @@ -2,16 +2,16 @@
Objects imported here will live in the `pycollocation` namespace
"""
__all__ = ["SymbolicBoundaryValueProblem", "OrthogonalPolynomialSolver", "Visualizer"]
__all__ = ["TwoPointBVP", "TwoPointBVPLike", "SymbolicTwoPointBVPLike",
"SymbolicTwoPointBVP", "OrthogonalPolynomialSolver", "Visualizer"]


from . import boundary_value_problems
from . import differential_equations
from . import equilibria
from . import bvp
from . import models
from . import orthogonal_polynomials
from . import visualizers

from . boundary_value_problems import SymbolicBoundaryValueProblem
from . bvp import *
from . orthogonal_polynomials import OrthogonalPolynomialSolver
from . visualizers import Visualizer

Expand Down
80 changes: 0 additions & 80 deletions pycollocation/boundary_value_problems.py

This file was deleted.

142 changes: 142 additions & 0 deletions pycollocation/bvp.py
@@ -0,0 +1,142 @@
"""
Classes for representing two-point boundary value problems.
@author : David R. Pugh
"""
import equilibria
import models


class TwoPointBVPLike(object):

@property
def boundary_conditions(self):
"""
Boundary conditions for the problem.
:getter: Return the boundary conditions for the problem.
:setter: Set new boundary conditions for the problem.
:type: dict
"""
return self._boundary_conditions

@boundary_conditions.setter
def boundary_conditions(self, conditions):
"""Set new boundary conditions for the model."""
self._boundary_conditions = self._validate_boundary(conditions)

def _sufficient_boundary(self, conditions):
"""Check that there are sufficient boundary conditions."""
number_conditions = 0
if conditions['lower'] is not None:
number_conditions += len(conditions['lower'])
if conditions['upper'] is not None:
number_conditions += len(conditions['upper'])
return number_conditions == len(self.dependent_vars)

def _validate_boundary(self, conditions):
"""Validate a dictionary of lower and upper boundary conditions."""
if not isinstance(conditions, dict):
mesg = "Attribute `boundary_conditions` must have type `dict` not {}"
raise AttributeError(mesg.format(conditions.__class__))
elif not (set(conditions.keys()) < set(['lower', 'upper', None])):
mesg = "Keys for `boundary_conditions` dict must be {}, {}, or {}"
raise AttributeError(mesg.format('lower', 'upper', 'None'))
elif not self._sufficient_boundary(conditions):
mesg = "Number of conditions must equal number of dependent vars."
raise ValueError(mesg)
else:
return conditions


class SymbolicTwoPointBVPLike(TwoPointBVPLike, models.SymbolicModelLike):

__lower_boundary_condition = None

__upper_boundary_condition = None

@property
def equilibrium(self):
"""
Object representing the model equilibrium.
:getter: Return the current object.
:type: equilibria.Equilibrium
"""
return equilibria.Equilibrium(self)

@property
def _lower_boundary_condition(self):
"""Cache lambdified lower boundary condition for numerical evaluation."""
condition = self.boundary_conditions['lower']
if condition is not None:
if self.__lower_boundary_condition is None:
self.__lower_boundary_condition = self._lambdify_factory(condition)
return self.__lower_boundary_condition
else:
return None

@property
def _upper_boundary_condition(self):
"""Cache lambdified upper boundary condition for numerical evaluation."""
condition = self.boundary_conditions['upper']
if condition is not None:
if self.__upper_boundary_condition is None:
self.__upper_boundary_condition = self._lambdify_factory(condition)
return self.__upper_boundary_condition
else:
return None

def _validate_boundary(self, conditions):
"""Validate a dictionary of lower and upper boundary conditions."""
bcs = {'lower': self._validate_boundary_exprs(conditions['lower']),
'upper': self._validate_boundary_exprs(conditions['upper'])}
return bcs

def _validate_boundary_exprs(self, expressions):
"""Check that lower/upper boundary_conditions are expressions."""
if expressions is None:
return None
else:
return [self._validate_expression(expr) for expr in expressions]


class SymbolicTwoPointBVP(SymbolicTwoPointBVPLike):
"""Class for representing symbolic two-point boundary value problems."""

def __init__(self, boundary_conditions, dependent_vars, independent_var, params, rhs):
"""Create an instance of a two-point boundary value problem (BVP)."""
self.boundary_conditions = boundary_conditions
self.dependent_vars = dependent_vars
self.independent_var = independent_var
self.params = params
self.rhs = rhs

def _validate_boundary(self, conditions):
"""Validate a dictionary of lower and upper boundary conditions."""
super(SymbolicTwoPointBVP, self)._validate_boundary(conditions)
bcs = {'lower': self._validate_boundary_exprs(conditions['lower']),
'upper': self._validate_boundary_exprs(conditions['upper'])}
return bcs

def _validate_boundary_exprs(self, expressions):
"""Check that lower/upper boundary_conditions are expressions."""
if expressions is None:
return None
else:
return [self._validate_expression(expr) for expr in expressions]


class TwoPointBVP(TwoPointBVPLike):
"""Class for representing two-point boundary value problems."""

def __init__(self, boundary_conditions, dependent_vars, independent_var, params, rhs):
"""Create an instance of a two-point boundary value problem (BVP)."""
self.boundary_conditions = boundary_conditions
self.dependent_vars = dependent_vars
self.independent_var = independent_var
self.params = params
self.rhs = rhs
76 changes: 0 additions & 76 deletions pycollocation/differential_equations.py

This file was deleted.

0 comments on commit b4b734c

Please sign in to comment.