Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assorted fixes while supporting PETSc #700

Merged
merged 10 commits into from
Jan 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ install:
- cmd: conda.exe config --add channels conda-forge

# Configure the VM.
- cmd: if "%TARGET_ARCH%" == "x64" if "%CONDA_PY%" == "27" conda.exe install --quiet --name root --only-deps python=2.7 fipy
- cmd: if "%TARGET_ARCH%" == "x64" if "%CONDA_PY%" == "36" conda.exe install --quiet --name root --only-deps python=3.6 fipy
- cmd: if "%TARGET_ARCH%" == "x64" if "%CONDA_PY%" == "27" conda.exe install --quiet --name root python=2.7 fipy
- cmd: if "%TARGET_ARCH%" == "x64" if "%CONDA_PY%" == "36" conda.exe install --quiet --name root python=3.6 fipy "gmsh<4.0"
- cmd: conda.exe remove --quiet --force fipy
# FIXME: fipy recipe on conda-forge doesn't have gmsh compatible with Python 2.7
- ps: |
$ErrorActionPreference = "Stop";
Expand Down
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ commands:
- run:
name: Create Conda Environment
command: |
conda create -v --quiet --prefix << parameters.condaenv >> --show-channel-urls --channel conda-forge --only-deps << parameters.packages >>
conda create -v --quiet --prefix << parameters.condaenv >> --show-channel-urls --channel conda-forge << parameters.packages >> "gmsh<4.0"
source activate ~/project/<< parameters.condaenv >>
pip install future
pip install scikit-fmm
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ before_install:
- hash -r
- conda config --set always_yes yes --set changeps1 no
- conda update -q conda
- conda create --quiet --name test-environment --show-channel-urls --channel conda-forge --only-deps python=$TRAVIS_PYTHON_VERSION fipy;
- conda create --quiet --name test-environment --show-channel-urls --channel conda-forge python=$TRAVIS_PYTHON_VERSION fipy "gmsh<4.0";
- source activate test-environment
# Useful for debugging any issues with conda
- conda info -a
Expand Down
4 changes: 3 additions & 1 deletion INSTALLATION.rst
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ Recommended Method
.. _Linux: http://www.linux.org/
.. _Windows: http://www.microsoft.com/windows/
.. |CondaForge| image:: https://anaconda.org/conda-forge/fipy/badges/installer/conda.svg
.. _CondaForge: https://anaconda.org/guyer/fipy
.. _CondaForge: https://anaconda.org/conda-forge/fipy


--------------
Expand Down Expand Up @@ -256,6 +256,8 @@ Gmsh
http://www.geuz.org/gmsh/

:term:`Gmsh` is an application that allows the creation of irregular meshes.
When running in parallel, :term:`FiPy` requires a version of :term:`Gmsh`
>= 2.5 and < 4.0.

SciPy
=====
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ or a
.. |PyPI| image:: https://img.shields.io/pypi/v/fipy.svg
.. _PyPI: https://pypi.python.org/pypi/FiPy
.. |CondaForge| image:: https://anaconda.org/conda-forge/fipy/badges/installer/conda.svg
.. _CondaForge: https://anaconda.org/guyer/fipy
.. _CondaForge: https://anaconda.org/conda-forge/fipy
.. |Depsy| image:: http://depsy.org/api/package/pypi/FiPy/badge.svg
.. _Depsy: http://depsy.org/package/python/FiPy
.. |Codacy| image:: https://api.codacy.com/project/badge/Grade/d02921bb54b14e88a1e2e1f5520133f4
Expand Down
27 changes: 15 additions & 12 deletions _setup/upload_products.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,17 @@ def finalize_options (self):

def run(self):
if self.pdf:
fname = 'dist/fipy-%s.pdf' % self.distribution.metadata.get_version()
print("setting permissions of manual...")
os.system('chmod -R g+w documentation/_build/latex/fipy.pdf')

print("linking manual to `dist/`...")
os.system('mkdir dist/')
os.system('ln -f documentation/_build/latex/fipy.pdf dist/fipy-%s.pdf'%self.distribution.metadata.get_version())
os.system('ln -f documentation/_build/latex/fipy.pdf %s' % fname)

print("uploading pdf...")
os.system('rsync -pgoDLC -e ssh %s %s/download/' % (fname, os.environ['FIPY_WWWHOST']))

if self.html:
print("setting group and ownership of web pages...")
os.system('chmod -R g+w documentation/_build/html/')
Expand All @@ -46,21 +50,20 @@ def run(self):
os.system('rsync -rlpgoDLC -e ssh %s %s' % ('documentation/_build/html/', os.environ['FIPY_WWWHOST']))

if self.tarball:
file = 'dist/FiPy-%s.tar.gz' % self.distribution.metadata.get_version()
print("setting permissions for %s ..." % file)
os.system('chmod -R g+w %s' % file)
fname = 'dist/FiPy-%s.tar.gz' % self.distribution.metadata.get_version()
print("setting permissions for %s ..." % fname)
os.system('chmod -R g+w %s' % fname)

print("uploading tarball...")
os.system('rsync -pgoDLC -e ssh %s %s/download/' % (file, os.environ['FIPY_WWWHOST']))
os.system('rsync -pgoDLC -e ssh %s %s/download/' % (fname, os.environ['FIPY_WWWHOST']))

if self.winzip:
file = 'dist/FiPy-%s.win32.zip' % self.distribution.metadata.get_version()
print("setting permissions for %s ..." % file)
os.system('chmod -R g+w %s' % file)
fname = 'dist/FiPy-%s.win32.zip' % self.distribution.metadata.get_version()
print("setting permissions for %s ..." % fname)
os.system('chmod -R g+w %s' % fname)

print("uploading winzip...")
os.system('rsync -pgoDLC -e ssh %s %s/download/' % (file, os.environ['FIPY_WWWHOST']))
os.system('rsync -pgoDLC -e ssh %s %s/download/' % (fname, os.environ['FIPY_WWWHOST']))

if self.pdf or self.tarball or self.winzip:
print("activating web pages...")
os.system(os.environ['FIPY_WWWACTIVATE'])
print("activating web pages...")
os.system(os.environ['FIPY_WWWACTIVATE'])
5 changes: 3 additions & 2 deletions documentation/USAGE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,10 @@ package.

If present, causes the graphical display of the solution matrix of each
equation at each call of :meth:`~Term.solve` or :meth:`~Term.sweep`.
Setting the value to "``terms``," causes the display of the matrix for each
Setting the value to "``terms``" causes the display of the matrix for each
:class:`Term` that composes the equation. Requires the :term:`Matplotlib`
package.
package. Setting the value to "``print``" causes the matrix to be
printed to the console.

.. envvar:: FIPY_INLINE

Expand Down
2 changes: 1 addition & 1 deletion documentation/_templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ <h1>FiPy: A Finite Volume PDE Solver Using Python</h1>
<a href="https://github.com/usnistgov/fipy"><img src="https://img.shields.io/github/contributors/usnistgov/fipy.svg" alt="GitHub"></img></a>
<a href="https://pypi.python.org/pypi/FiPy"><img src="https://img.shields.io/pypi/v/fipy.svg" alt="PyPi"></img></a>
<a class="badge-align" href="https://www.codacy.com/app/tkphd/fipy?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=usnistgov/fipy&amp;utm_campaign=Badge_Grade"><img src="https://api.codacy.com/project/badge/Grade/d02921bb54b14e88a1e2e1f5520133f4"/></a>
<a href="https://anaconda.org/guyer/fipy"><img src="https://anaconda.org/conda-forge/fipy/badges/installer/conda.svg" alt="CondaForge"></img></a>
<a href="https://anaconda.org/conda-forge/fipy"><img src="https://anaconda.org/conda-forge/fipy/badges/installer/conda.svg" alt="CondaForge"></img></a>
<a href="https://mybinder.org/v2/gh/usnistgov/fipy/master?filepath=examples%2Findex.ipynb"><img src="https://mybinder.org/badge.svg" alt="Binder"></img></a>
<br>
<!-- Community Badges -->
Expand Down
9 changes: 9 additions & 0 deletions examples/cahnHilliard/mesh2DCoupled.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
r"""Solve the Cahn-Hilliard problem in two dimensions.

.. warning:: This formulation has
`serious performance problems`_
and is **not automatically tested**. Specifically, for non-trivial mesh
sizes, :term:`PySparse` requires enormous amounts of memory,
:term:`Trilinos` cannot solve the coupled form, and :term:`PETSc` cannot
solve the vector form.

.. _serious performance problems: https://github.com/usnistgov/fipy/issues/378

The spinodal decomposition phenomenon is a spontaneous separation of
an initially homogeneous mixture into two distinct regions of different
properties (spin-up/spin-down, component A/component B). It is a
Expand Down
6 changes: 3 additions & 3 deletions examples/cahnHilliard/tanh1D.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@
... if __name__ == '__main__':
... diff = abs(answer - numerix.array(var))
... maxarg = numerix.argmax(diff)
... print('maximum error:', diff[maxarg])
... print('maximum error: {}'.format(diff[maxarg]))
... print('element id:', maxarg)
... print('value at element ', maxarg, ' is ', var[maxarg])
... print('solution value', answer[maxarg])
... print('value at element {} is {}'.format(maxarg, var[maxarg]))
... print('solution value: {}'.format(answer[maxarg]))
...
... viewer.plot()

Expand Down
2 changes: 1 addition & 1 deletion examples/cahnHilliard/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def _suite():
'mesh2D',
'mesh3D',
'sphere',
'mesh2DCoupled',
# 'mesh2DCoupled', # FIXME: this test is [borked](https://github.com/usnistgov/fipy/issues/378)
), base = __name__)

if __name__ == '__main__':
Expand Down
211 changes: 106 additions & 105 deletions examples/chemotaxis/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,113 +4,114 @@

Here are some test cases for the model.

>>> from builtins import range
>>> for i in range(28):
... for var, eqn in eqs:
... var.updateOld()
... for var, eqn in eqs:
... eqn.solve(var, dt = 1.0)

>>> accuracy = 1e-2
>>> print(KMVar.allclose(params['KM'], atol = accuracy))
1
>>> print(TMVar.allclose(params['TM'], atol = accuracy))
1
>>> print(TCVar.allclose(params['TC'], atol = accuracy))
1
>>> print(P2Var.allclose(params['P2'], atol = accuracy))
1
>>> print(P3Var.allclose(params['P3'], atol = accuracy))
1
>>> print(KCVar.allclose(params['KC'], atol = accuracy))
1

>>> from __future__ import division

>>> from builtins import input
>>> from builtins import range
>>> from examples.chemotaxis.parameters import parameters
>>> from fipy import CellVariable, Grid1D, TransientTerm, DiffusionTerm, ImplicitSourceTerm, Viewer, numerix

>>> params = parameters['case 2']

>>> nx = 50
>>> dx = 1.
>>> L = nx * dx

>>> mesh = Grid1D(nx=nx, dx=dx)

>>> shift = 1.

>>> KMVar = CellVariable(mesh=mesh, value=params['KM'] * shift, hasOld=1)
>>> KCVar = CellVariable(mesh=mesh, value=params['KC'] * shift, hasOld=1)
>>> TMVar = CellVariable(mesh=mesh, value=params['TM'] * shift, hasOld=1)
>>> TCVar = CellVariable(mesh=mesh, value=params['TC'] * shift, hasOld=1)
>>> P3Var = CellVariable(mesh=mesh, value=params['P3'] * shift, hasOld=1)
>>> P2Var = CellVariable(mesh=mesh, value=params['P2'] * shift, hasOld=1)
>>> RVar = CellVariable(mesh=mesh, value=params['R'], hasOld=1)

>>> PN = P3Var + P2Var

>>> KMscCoeff = params['chiK'] * (RVar + 1) * (1 - KCVar - KMVar.cellVolumeAverage)
>>> KMspCoeff = params['lambdaK'] / (1 + PN / params['kappaK'])
>>> KMEq = TransientTerm() - KMscCoeff + ImplicitSourceTerm(KMspCoeff)

>>> TMscCoeff = params['chiT'] * (1 - TCVar - TMVar.cellVolumeAverage)
>>> TMspCoeff = params['lambdaT'] * (KMVar + params['zetaT'])
>>> TMEq = TransientTerm() - TMscCoeff + ImplicitSourceTerm(TMspCoeff)

>>> TCscCoeff = params['lambdaT'] * (TMVar * KMVar).cellVolumeAverage
>>> TCspCoeff = params['lambdaTstar']
>>> TCEq = TransientTerm() - TCscCoeff + ImplicitSourceTerm(TCspCoeff)

>>> PIP2PITP = PN / (PN / params['kappam'] + PN.cellVolumeAverage / params['kappac'] + 1) + params['zetaPITP']

>>> P3spCoeff = params['lambda3'] * (TMVar + params['zeta3T'])
>>> P3scCoeff = params['chi3'] * KMVar * (PIP2PITP / (1 + KMVar / params['kappa3']) + params['zeta3PITP']) + params['zeta3']
>>> P3Eq = TransientTerm() - DiffusionTerm(params['diffusionCoeff']) - P3scCoeff + ImplicitSourceTerm(P3spCoeff)

>>> P2scCoeff = scCoeff = params['chi2'] + params['lambda3'] * params['zeta3T'] * P3Var
>>> P2spCoeff = params['lambda2'] * (TMVar + params['zeta2T'])
>>> P2Eq = TransientTerm() - DiffusionTerm(params['diffusionCoeff']) - P2scCoeff + ImplicitSourceTerm(P2spCoeff)

>>> KCscCoeff = params['alphaKstar'] * params['lambdaK'] * (KMVar / (1 + PN / params['kappaK'])).cellVolumeAverage
>>> KCspCoeff = params['lambdaKstar'] / (params['kappaKstar'] + KCVar)
>>> KCEq = TransientTerm() - KCscCoeff + ImplicitSourceTerm(KCspCoeff)

>>> eqs = ((KMVar, KMEq), (TMVar, TMEq), (TCVar, TCEq), (P3Var, P3Eq), (P2Var, P2Eq), (KCVar, KCEq))

>>> if __name__ == '__main__':
... steps = 100
... else:
... steps = 28

>>> for i in range(steps):
... for var, eqn in eqs:
... var.updateOld()
... for var, eqn in eqs:
... eqn.solve(var, dt=1.)

>>> accuracy = 1e-2
>>> print(KMVar.allclose(params['KM'], atol=accuracy))
1
>>> print(TMVar.allclose(params['TM'], atol=accuracy))
1
>>> print(TCVar.allclose(params['TC'], atol=accuracy))
1
>>> print(P2Var.allclose(params['P2'], atol=accuracy))
1
>>> print(P3Var.allclose(params['P3'], atol=accuracy))
1
>>> print(KCVar.allclose(params['KC'], atol=accuracy))
1

>>> PNView = PN / PN.cellVolumeAverage
>>> PNView.name = 'PN'

>>> KMView = KMVar / KMVar.cellVolumeAverage
>>> KMView.name = 'KM'

>>> TMView = TMVar / TMVar.cellVolumeAverage
>>> TMView.naem = 'TM'

>>> RVar[:] = params['S'] + (1 + params['S']) * params['G'] * numerix.cos((2 * numerix.pi * mesh.cellCenters[0]) / L)

>>> if __name__ == '__main__':
... KMViewer = Viewer((PNView, KMView, TMView), title = 'Gradient Stimulus: Profile')
...
... for i in range(100):
... for var, eqn in eqs:
... var.updateOld()
... for var, eqn in eqs:
... eqn.solve(var, dt=0.1)
...
... KMViewer.plot()
...
... input("finished")
"""
from __future__ import division
from __future__ import unicode_literals

from builtins import range
from examples.chemotaxis.parameters import parameters

from fipy import input
from fipy import CellVariable, Grid1D, TransientTerm, DiffusionTerm, ImplicitSourceTerm, Viewer

params = parameters['case 2']

nx = 50
dx = 1.
L = nx * dx

mesh = Grid1D(nx = nx, dx = dx)

shift = 1.

KMVar = CellVariable(mesh = mesh, value = params['KM'] * shift, hasOld = 1)
KCVar = CellVariable(mesh = mesh, value = params['KC'] * shift, hasOld = 1)
TMVar = CellVariable(mesh = mesh, value = params['TM'] * shift, hasOld = 1)
TCVar = CellVariable(mesh = mesh, value = params['TC'] * shift, hasOld = 1)
P3Var = CellVariable(mesh = mesh, value = params['P3'] * shift, hasOld = 1)
P2Var = CellVariable(mesh = mesh, value = params['P2'] * shift, hasOld = 1)
RVar = CellVariable(mesh = mesh, value = params['R'], hasOld = 1)

PN = P3Var + P2Var

KMscCoeff = params['chiK'] * (RVar + 1) * (1 - KCVar - KMVar.cellVolumeAverage)
KMspCoeff = params['lambdaK'] / (1 + PN / params['kappaK'])
KMEq = TransientTerm() - KMscCoeff + ImplicitSourceTerm(KMspCoeff)

TMscCoeff = params['chiT'] * (1 - TCVar - TMVar.cellVolumeAverage)
TMspCoeff = params['lambdaT'] * (KMVar + params['zetaT'])
TMEq = TransientTerm() - TMscCoeff + ImplicitSourceTerm(TMspCoeff)

TCscCoeff = params['lambdaT'] * (TMVar * KMVar).cellVolumeAverage
TCspCoeff = params['lambdaTstar']
TCEq = TransientTerm() - TCscCoeff + ImplicitSourceTerm(TCspCoeff)

PIP2PITP = PN / (PN / params['kappam'] + PN.cellVolumeAverage / params['kappac'] + 1) + params['zetaPITP']

P3spCoeff = params['lambda3'] * (TMVar + params['zeta3T'])
P3scCoeff = params['chi3'] * KMVar * (PIP2PITP / (1 + KMVar / params['kappa3']) + params['zeta3PITP']) + params['zeta3']
P3Eq = TransientTerm() - DiffusionTerm(params['diffusionCoeff']) - P3scCoeff + ImplicitSourceTerm(P3spCoeff)

P2scCoeff = scCoeff = params['chi2'] + params['lambda3'] * params['zeta3T'] * P3Var
P2spCoeff = params['lambda2'] * (TMVar + params['zeta2T'])
P2Eq = TransientTerm() - DiffusionTerm(params['diffusionCoeff']) - P2scCoeff + ImplicitSourceTerm(P2spCoeff)

KCscCoeff = params['alphaKstar'] * params['lambdaK'] * (KMVar / (1 + PN / params['kappaK'])).cellVolumeAverage
KCspCoeff = params['lambdaKstar'] / (params['kappaKstar'] + KCVar)
KCEq = TransientTerm() - KCscCoeff + ImplicitSourceTerm(KCspCoeff)

eqs = ((KMVar, KMEq), (TMVar, TMEq), (TCVar, TCEq), (P3Var, P3Eq), (P2Var, P2Eq), (KCVar, KCEq))
__docformat__ = 'restructuredtext'

if __name__ == '__main__':

v1 = KMVar / KMVar.cellVolumeAverage
v2 = PN / PN.cellVolumeAverage
v3 = TMVar / TMVar.cellVolumeAverage
v1.setName('KM')
v2.setName('PN')
v3.setName('TM')

KMViewer = Viewer((v1, v2, v3), title = 'Gradient Stimulus: Profile')

KMViewer.plot()

for i in range(100):
for var, eqn in eqs:
var.updateOld()
for var, eqn in eqs:
eqn.solve(var, dt = 1.)

RVar[:] = params['S'] + (1 + params['S']) * params['G'] * cos((2 * pi * mesh.cellCenters[0]) / L)

for i in range(100):
for var, eqn in eqs:
var.updateOld()
for var, eqn in eqs:
eqn.solve(var, dt = 0.1)
KMViewer.plot()

KMViewer.plot()

input("finished")
import fipy.tests.doctestPlus
exec(fipy.tests.doctestPlus._getScript())
Loading