Skip to content

Commit

Permalink
Merge e5f1e9a into 31aa16d
Browse files Browse the repository at this point in the history
  • Loading branch information
mandli committed Apr 28, 2017
2 parents 31aa16d + e5f1e9a commit aad8404
Show file tree
Hide file tree
Showing 27 changed files with 429 additions and 96 deletions.
22 changes: 18 additions & 4 deletions .travis.yml
Expand Up @@ -3,8 +3,10 @@ language: python
os: linux

env:
- TEST_PACKAGE="pyclaw"
- TEST_PACKAGE="petclaw"
matrix:
- TEST_PACKAGE="pyclaw"
- TEST_PACKAGE="petclaw"
- TEST_PACKAGE="forestclaw"

python:
- 2.7
Expand Down Expand Up @@ -48,15 +50,20 @@ install:
- python -c "import scipy; print(scipy.__version__)"
- python setup.py install

# The test commands below go in the following order:
# 1. pyclaw doc-tests
# 2. pyclaw examples and io tests
# 3. petclaw examples
# 4. forestclaw tests
script:
- cd pyclaw/src/pyclaw
- nosetests --first-pkg-wins --with-doctest --exclude=limiters --exclude=sharpclaw --exclude=io --exclude=example --with-coverage --cover-package=clawpack.pyclaw
- nosetests --first-pkg-wins --with-doctest --exclude=limiters --exclude=sharpclaw --exclude=fileio --exclude=example --with-coverage --cover-package=clawpack.pyclaw
- mv .coverage temp
- if [[ "${TEST_PACKAGE}" == "pyclaw" ]]; then
nosetests -v --first-pkg-wins --exclude=limiters --exclude=sharpclaw --with-coverage --cover-package=clawpack.pyclaw --include=IOTest;
fi
- if [[ "${TEST_PACKAGE}" == "petclaw" ]]; then
mpirun -n 4 nosetests -v --first-pkg-wins --exclude=limiters --exclude=sharpclaw --exclude=io;
mpirun -n 4 nosetests -v --first-pkg-wins --exclude=limiters --exclude=sharpclaw --exclude=fileio;
fi
- if [[ "${TEST_PACKAGE}" == "petclaw" ]]; then
cd ../petclaw/tests;
Expand All @@ -65,6 +72,13 @@ script:
- if [[ "${TEST_PACKAGE}" == "petclaw" ]]; then
cd ../../pyclaw;
fi
- if [[ "${TEST_PACKAGE}" == "forestclaw" ]]; then
cd ../forestclaw ;
nosetests --first-pkg-wins --exclude=limiters --exclude=sharpclaw --with-coverage --cover-package=clawpack.forestclaw;
fi
- if [[ "${TEST_PACKAGE}" == "forestclaw" ]]; then
cd ../../pyclaw ;
fi
- mv temp .coverage.doctest
- coverage combine

Expand Down
43 changes: 43 additions & 0 deletions src/forestclaw/__init__.py
@@ -0,0 +1,43 @@
"""Additions for ForestClaw support"""

from __future__ import absolute_import
import os
import logging
import logging.config

# Default logging configuration file
_DEFAULT_LOG_CONFIG_PATH = os.path.join(os.path.dirname(__file__),
'../pyclaw/log.config')
del os

# Setup loggers
logging.config.fileConfig(_DEFAULT_LOG_CONFIG_PATH)

__all__ = []

# Module imports - Note the only difference here is the geometry module
__all__.extend(['Controller', 'Dimension', 'Patch', 'Domain', 'Solution',
'State', 'CFL'])#, 'plot'])
from clawpack.forestclaw.controller import Controller
from clawpack.forestclaw.solution import Solution
from clawpack.forestclaw.geometry import Dimension, Patch, Domain
from clawpack.forestclaw.state import State
from clawpack.forestclaw.cfl import CFL

# from clawpack.pyclaw import plot

# The below are not yet needed
# __all__.extend(['ClawSolver1D', 'ClawSolver2D', 'ClawSolver3D',
# 'SharpClawSolver1D', 'SharpClawSolver2D', 'SharpClawSolver3D'])
# from clawpack.pyclaw.classic.solver import ClawSolver1D, ClawSolver2D, ClawSolver3D
# from clawpack.pyclaw.sharpclaw.solver import SharpClawSolver1D, SharpClawSolver2D
# from clawpack.pyclaw.sharpclaw.solver import SharpClawSolver2D, SharpClawSolver3D


# Sub-packages
# from clawpack.pyclaw import limiters
# from clawpack.pyclaw.limiters import *
# __all__.extend(limiters.__all__)

# __all__.append('BC')
# from clawpack.pyclaw.solver import BC
10 changes: 10 additions & 0 deletions src/forestclaw/cfl.py
@@ -0,0 +1,10 @@
#!/usr/bin/env python
# encoding: utf-8
r"""
Module containing the ForestClaw CFL class.
"""

from __future__ import absolute_import
from __future__ import print_function

from clawpack.pyclaw.cfl import CFL
10 changes: 10 additions & 0 deletions src/forestclaw/controller.py
@@ -0,0 +1,10 @@
#!/usr/bin/env python
# encoding: utf-8
r"""
Module containing the ForestClaw Controller class.
"""

from __future__ import absolute_import
from __future__ import print_function

from clawpack.pyclaw.controller import Controller
11 changes: 11 additions & 0 deletions src/forestclaw/fileio/__init__.py
@@ -0,0 +1,11 @@
#!/usr/bin/env python
# encoding: utf-8

"""I/O support for ForestClaw"""

from __future__ import absolute_import
import logging
logger = logging.getLogger('pyclaw.fileio')

from . import ascii
__all__ = ["ascii.read", "ascii.write"]
87 changes: 87 additions & 0 deletions src/forestclaw/fileio/ascii.py
@@ -0,0 +1,87 @@
#!/usr/bin/env python
# encoding: utf-8
r"""
Routines for reading and writing an ascii output file from ForestClaw
"""

from __future__ import absolute_import
from __future__ import print_function

import logging
import numpy as np

import clawpack.forestclaw as forestclaw
from clawpack.pyclaw.fileio.ascii import write
from clawpack.pyclaw.fileio.ascii import read
from clawpack.pyclaw.util import read_data_line

logger = logging.getLogger('pyclaw.fileio')


def write_patch_header(f, patch):
f.write("%5i patch_number\n" % patch.patch_index)
f.write("%5i AMR_level\n" % patch.level)
f.write("%5i block_number\n" % patch.block_number)
f.write("%5i mpi_rank\n" % patch.mpi_rank)
for dim in patch.dimensions:
f.write("%5i m%s\n" % (dim.num_cells, dim.name))
for dim in patch.dimensions:
f.write("%18.8e %slow\n" % (dim.lower, dim.name))
for dim in patch.dimensions:
f.write("%18.8e d%s\n" % (dim.delta, dim.name))

f.write("\n")


def read_patch_header(f, num_dim):
r"""Read header describing the next patch
:Input:
- *f* - (file) Handle to open file
- *num_dim* - (int) Number of dimensions
:Output:
- *patch* - (clawpack.pyclaw.geometry.Patch) Initialized patch represented
by the header data.
"""

n = np.zeros((num_dim))
d = np.zeros((num_dim))
lower = np.zeros((num_dim))

patch_index = read_data_line(f, data_type=int)
level = read_data_line(f, data_type=int)
block_number = read_data_line(f, data_type=int)
mpi_rank = read_data_line(f, data_type=int)
for i in range(num_dim):
n[i] = read_data_line(f, data_type=int)
for i in range(num_dim):
lower[i] = read_data_line(f)
for i in range(num_dim):
d[i] = read_data_line(f)

blank = f.readline()

# Construct the patch
# Since we do not have names here, we will construct the patch with
# dimension names x,y,z
names = ['x', 'y', 'z']
dimensions = [forestclaw.geometry.Dimension(lower[i], lower[i] + n[i] * d[i],
n[i], name=names[i]) for i in range(num_dim)]
patch = forestclaw.geometry.Patch(dimensions)

# Add AMR attributes:
patch.patch_index = patch_index
patch.level = level

# Add ForestClaw attributes
patch.block_number = block_number
patch.mpi_rank = mpi_rank

return patch

# # Replace the ascii module functions with those defined above
# # ascii.read_patch_header = read_patch_header
# # ascii.write_patch_header = write_patch_header
# read = ascii.read
# write = ascii.write
51 changes: 51 additions & 0 deletions src/forestclaw/fileio/test.py
@@ -0,0 +1,51 @@
#!/usr/bin/env python
# encoding: utf-8
r"""
Test suite for forestclaw.io
"""

from __future__ import absolute_import
from __future__ import print_function

import os
import shutil
import tempfile
import shutil

import numpy
import nose

import clawpack.forestclaw as forestclaw


def test_forestclaw_input():
"""Simple test to read in a ForestClaw ASCII file"""

# Create test solution
x = forestclaw.geometry.Dimension(0.0, 1.0, 100, name='x')
state = forestclaw.State(forestclaw.Patch(x), 1)
state.q = numpy.zeros((1, x.num_cells))
sol = forestclaw.Solution(state, forestclaw.geometry.Domain(x))

# Test specific extensions to Patch
sol.domain.patches[0].block_number = 2
sol.domain.patches[0].mpi_rank = 2

# Create temporary directory to write to and read from
try:
temp_path = tempfile.mkdtemp()

# Real test
sol.write(0, path=temp_path)
read_sol = forestclaw.Solution(0, path=temp_path,
file_format='forestclaw')
nose.tools.assert_equal(sol, read_sol,
"ForestClaw IO read/write test failed, " +
"solutions are not equal.")
except:
shutil.copy(os.path.join(temp_path, 'fort.q0000'), os.getcwd())
finally:
shutil.rmtree(temp_path)

if __name__ == '__main__':
nose.main()
28 changes: 28 additions & 0 deletions src/forestclaw/geometry.py
@@ -0,0 +1,28 @@
#!/usr/bin/env python
# encoding: utf-8
r"""
Module containing forestclaw.geometry.
"""

from __future__ import absolute_import

from clawpack import pyclaw
from clawpack.pyclaw import geometry as pyclaw_geometry
from clawpack.pyclaw.geometry import Dimension
from clawpack.pyclaw.geometry import Domain


class Patch(pyclaw_geometry.Patch):
"""Patch class with specific ForestClaw attributes.
"""

__doc__ += pyclaw.util.add_parent_doc(pyclaw_geometry.Patch)

def __init__(self, dimensions):

super(Patch, self).__init__(dimensions)

self.block_number = 0
r"""(int) - Block number of current patch, ``default = 0``"""
self.mpi_rank = 0
r"""(int) - MPI rank this patch belongs to, ``default = 0``"""
17 changes: 17 additions & 0 deletions src/forestclaw/setup.py
@@ -0,0 +1,17 @@
#!/usr/bin/env python

from __future__ import absolute_import
def configuration(parent_package='',top_path=None):
from numpy.distutils.misc_util import Configuration

config = Configuration('forestclaw', parent_package, top_path)
config.add_data_files('log.config')
config.add_subpackage('classic')
config.add_subpackage('sharpclaw')
config.add_subpackage('limiters')
config.add_subpackage('fileio')
return config

if __name__ == '__main__':
from numpy.distutils.core import setup
setup(**configuration(top_path='').todict())
10 changes: 10 additions & 0 deletions src/forestclaw/solution.py
@@ -0,0 +1,10 @@
#!/usr/bin/env python
# encoding: utf-8
r"""
Module containing the ForestClaw Solution class.
"""

from __future__ import absolute_import
from __future__ import print_function

from clawpack.pyclaw.solution import Solution
10 changes: 10 additions & 0 deletions src/forestclaw/state.py
@@ -0,0 +1,10 @@
#!/usr/bin/env python
# encoding: utf-8
r"""
Module containing the ForestClaw State class.
"""

from __future__ import absolute_import
from __future__ import print_function

from clawpack.pyclaw.state import State
22 changes: 22 additions & 0 deletions src/forestclaw/test.py
@@ -0,0 +1,22 @@
#!/usr/bin/env python
# encoding: utf-8
r"""
Test suite for forestclaw
"""

from __future__ import absolute_import

from .geometry import Patch, Dimension


def test_forestclaw_patch():
"""Test the simple extension of the pyclaw.Patch class"""

patch = Patch(Dimension(0.0, 1.0, 10))
patch.block_number = 2
patch.mpi_rank = 3


if __name__ == '__main__':
import nose
nose.main()
12 changes: 3 additions & 9 deletions src/petclaw/io/__init__.py → src/petclaw/fileio/__init__.py
@@ -1,16 +1,10 @@
#!/usr/bin/env python
# encoding: utf-8
# ======================================================================
# Package: pyclaw.io
# File: __init__.py
# Created: Feb 10, 2008
# Author: Kyle Mandli
# ======================================================================
"""Output package for Pyclaw"""
"""Output package for PetClaw"""

from __future__ import absolute_import
import logging
from clawpack.pyclaw.io import ascii
from clawpack.pyclaw.fileio import ascii
__all__ = ['ascii.read','ascii.write']

# Check for HDF 5 support
Expand All @@ -24,7 +18,7 @@
# Check for netcdf support
try:
import netCDF4
from clawpack.pyclaw.io import netcdf
from clawpack.pyclaw.fileio import netcdf
__all__ += ['netcdf.read','netcdf.write']
except(ImportError):
logging.debug("No netcdf4 support found.")
Expand Down

0 comments on commit aad8404

Please sign in to comment.