Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
429 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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``""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.