Skip to content
Open
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
137 changes: 137 additions & 0 deletions cmake/FindNetCDF.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
#[==[
Provides the following variables:

* `NetCDF_FOUND`: Whether NetCDF was found or not.
* `NetCDF_INCLUDE_DIRS`: Include directories necessary to use NetCDF.
* `NetCDF_LIBRARIES`: Libraries necessary to use NetCDF.
* `NetCDF_VERSION`: The version of NetCDF found.
* `NetCDF::NetCDF`: A target to use with `target_link_libraries`.
#]==]

# Stolen from VTK with some small modifications
# https://github.com/Kitware/VTK/blob/master/CMake/FindNetCDF.cmake
# (BSD 3-Clause License)

#[[=========================================================================

Program: Visualization Toolkit
Module: Copyright.txt

Copyright (c) 1993-2015 Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither name of Ken Martin, Will Schroeder, or Bill Lorensen nor the names
of any contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

=========================================================================]]
# Note: The version from VTK tries to first find a CMake built version of CMake and then
# a pkgConf built one. This doesn't work on all systems with custom built versions of
# CMake + HDF5.
# Thus, first try to find it manually, then fall back on CMake/PkgConfig

find_path(NetCDF_INCLUDE_DIR
NAMES netcdf.h
HINTS $ENV{NETCDF_DIR}/include $ENV{NETCDF_INCLUDE_DIR}
DOC "netcdf include directories")
mark_as_advanced(NetCDF_INCLUDE_DIR)

find_library(NetCDF_LIBRARY
NAMES netcdf
HINTS $ENV{NETCDF_DIR}/lib $ENV{NETCDF_LIB_DIR}
DOC "netcdf library")
mark_as_advanced(NetCDF_LIBRARY)

string(REGEX REPLACE "(.*)libnetcdf\.(so|a)" "\\1" NetCDF_LIBRARY_DIR "${NetCDF_LIBRARY}")
mark_as_advanced(NetCDF_LIBRARY_DIR)

if (NetCDF_INCLUDE_DIR)
file(STRINGS "${NetCDF_INCLUDE_DIR}/netcdf_meta.h" _netcdf_version_lines
REGEX "#define[ \t]+NC_VERSION_(MAJOR|MINOR|PATCH|NOTE)")
string(REGEX REPLACE ".*NC_VERSION_MAJOR *\([0-9]*\).*" "\\1" _netcdf_version_major "${_netcdf_version_lines}")
string(REGEX REPLACE ".*NC_VERSION_MINOR *\([0-9]*\).*" "\\1" _netcdf_version_minor "${_netcdf_version_lines}")
string(REGEX REPLACE ".*NC_VERSION_PATCH *\([0-9]*\).*" "\\1" _netcdf_version_patch "${_netcdf_version_lines}")
string(REGEX REPLACE ".*NC_VERSION_NOTE *\"\([^\"]*\)\".*" "\\1" _netcdf_version_note "${_netcdf_version_lines}")
set(NetCDF_VERSION "${_netcdf_version_major}.${_netcdf_version_minor}.${_netcdf_version_patch}${_netcdf_version_note}")
unset(_netcdf_version_major)
unset(_netcdf_version_minor)
unset(_netcdf_version_patch)
unset(_netcdf_version_note)
unset(_netcdf_version_lines)
endif ()

if (NetCDF_FOUND)
set(NetCDF_INCLUDE_DIRS "${NetCDF_INCLUDE_DIR}")
set(NetCDF_LIBRARIES "${NetCDF_LIBRARY}")

if (NOT TARGET NetCDF::NetCDF)
add_library(NetCDF::NetCDF UNKNOWN IMPORTED)
set_target_properties(NetCDF::NetCDF PROPERTIES
IMPORTED_LOCATION "${NetCDF_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${NetCDF_INCLUDE_DIR}")
endif ()
else()
# Try to find a CMake-built NetCDF.
find_package(netCDF CONFIG QUIET)
if (netCDF_FOUND)
# Forward the variables in a consistent way.
set(NetCDF_FOUND "${netCDF_FOUND}")
set(NetCDF_INCLUDE_DIRS "${netCDF_INCLUDE_DIR}")
set(NetCDF_LIBRARIES "${netCDF_LIBRARIES}")
set(NetCDF_VERSION "${NetCDFVersion}")
if (NOT TARGET NetCDF::NetCDF)
add_library(NetCDF::NetCDF INTERFACE IMPORTED)
set_target_properties(NetCDF::NetCDF PROPERTIES
INTERFACE_LINK_LIBRARIES "${NetCDF_LIBRARIES}")
endif ()
# Skip the rest of the logic in this file.
return ()
endif ()

find_package(PkgConfig QUIET)
if (PkgConfig_FOUND)
pkg_check_modules(_NetCDF QUIET netcdf IMPORTED_TARGET)
if (_NetCDF_FOUND)
# Forward the variables in a consistent way.
set(NetCDF_FOUND "${_NetCDF_FOUND}")
set(NetCDF_INCLUDE_DIRS "${_NetCDF_INCLUDE_DIRS}")
set(NetCDF_LIBRARIES "${_NetCDF_LIBRARIES}")
set(NetCDF_VERSION "${_NetCDF_VERSION}")
if (NOT TARGET NetCDF::NetCDF)
add_library(NetCDF::NetCDF INTERFACE IMPORTED)
set_target_properties(NetCDF::NetCDF PROPERTIES
INTERFACE_LINK_LIBRARIES "PkgConfig::_NetCDF")
endif ()
# Skip the rest of the logic in this file.
return ()
endif ()
endif ()
endif ()


include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(NetCDF
REQUIRED_VARS NetCDF_LIBRARY NetCDF_INCLUDE_DIR
VERSION_VAR NetCDF_VERSION)

1 change: 1 addition & 0 deletions cmake/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A selective copy of the CMake files from the SeisSol main repository.
68 changes: 68 additions & 0 deletions cube/cubeGenerator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/python
##
# @file
# This file is part of SeisSol.
#
# @author Sebastian Rettenberger (rettenbs AT in.tum.de, http://www5.in.tum.de/wiki/index.php/Sebastian_Rettenberger,_M.Sc.)
#
# @section LICENSE
# Copyright (c) 2013, SeisSol Group
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from this
# software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

from lib.args import Args
from lib.gambit import GambitWriter
from lib.mesh import Mesh

import operator

def main():
# Parse command line arguements
args = Args()

print 'Generating mesh with size', ', '.join(map(str, args.size()))

# Create Mesh
mesh = Mesh(args.size(), args.boundary())

print 'Number of elements:', len(mesh.elements())

# Write mesh
if args.netcdf():
try:
from lib.netcdf import NetcdfWriter
except ImportError, e:
print 'netcdf4-python could not be loaded:', e
return
print 'Mesh will contain', ' * '.join(map(str, args.partitions())), '=', reduce(operator.mul, args.partitions(), 1), 'partitions'
NetcdfWriter(mesh, args.partitions(), args.outputFile())
else:
GambitWriter(mesh, args.outputFile())

if __name__ == '__main__':
main()
36 changes: 36 additions & 0 deletions cube/lib/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/python
##
# @file
# This file is part of SeisSol.
#
# @author Sebastian Rettenberger (rettenbs AT in.tum.de, http://www5.in.tum.de/wiki/index.php/Sebastian_Rettenberger,_M.Sc.)
#
# @section LICENSE
# Copyright (c) 2013, SeisSol Group
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from this
# software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
111 changes: 111 additions & 0 deletions cube/lib/args.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#! /usr/bin/python
##
# @file
# This file is part of SeisSol.
#
# @author Sebastian Rettenberger (rettenbs AT in.tum.de, http://www5.in.tum.de/wiki/index.php/Sebastian_Rettenberger,_M.Sc.)
#
# @section LICENSE
# Copyright (c) 2013, SeisSol Group
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from this
# software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

import argparse
import operator
import sys

class Args:
"""Parses the command line arguments using
argparse.ArgumentParser"""

def __init__(self):
parser = argparse.ArgumentParser(prog='cubeGenerator')
parser.add_argument('-s', '--size', type=int,
help='number of cubes in each dimensions')
parser.add_argument('-x', '--size-x', type=int,
help='number of cubes in x dimension')
parser.add_argument('-y', '--size-y', type=int,
help='number of cubes in y dimension')
parser.add_argument('-z', '--size-z', type=int,
help='number of cubes in z dimension')
parser.add_argument('--px', type=int,
help='number of partitions x dimension')
parser.add_argument('--py', type=int,
help='number of partitions in y dimension')
parser.add_argument('--pz', type=int,
help='number of partitions in z dimension')
parser.add_argument('-o', '--output', type=argparse.FileType('w'),
required=True, help='output file for resulting Gambit or netCDF mesh')
parser.add_argument('-n', '--netcdf', action='store_true',
help='Create netCDF files'),
parser.add_argument('-b', '--boundary', type=int,
help='boundary condition (default 106 = periodic)', default=106)
parser.add_argument('-v', '--version', action='version', version='%(prog)s 0.1')

try:
# Parse cmd line options
self.__options = parser.parse_args(sys.argv[1:])
if self.__options.size == None \
and (self.__options.size_x == None \
or self.__options.size_y == None \
or self.__options.size_z == None):
raise IOError('Either size or x/y/z is required')

if self.__options.netcdf:
partitions = [getattr(self.__options, 'p'+i) for i in ['x', 'y', 'z']]
p = sum(p != None for p in partitions)
if p != 3:
raise IOError('Number of partitions is required for netCDF files')

except IOError, e:
parser.error(str(e))

# Set correct size options
self.__options.size = [self.__options.size for _ in range(3)]

if self.__options.size_x != None:
self.__options.size[0] = self.__options.size_x
if self.__options.size_y != None:
self.__options.size[1] = self.__options.size_y
if self.__options.size_z != None:
self.__options.size[2] = self.__options.size_z

def size(self):
return self.__options.size

def outputFile(self):
return self.__options.output

def boundary(self):
return self.__options.boundary

def netcdf(self):
return self.__options.netcdf

def partitions(self):
return (self.__options.px, self.__options.py, self.__options.pz)
Loading