Skip to content

Commit ab7b879

Browse files
committed
Essentially the initial commit. There is still much to add from previous versions of this project and refactor.
1 parent b580531 commit ab7b879

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+5257
-0
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "libraries/rapidjson"]
2+
path = libraries/rapidjson
3+
url = [email protected]:miloyip/rapidjson.git

.travis.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
dist: trusty
2+
3+
sudo: required
4+
5+
language: cpp
6+
7+
compiler:
8+
- gcc
9+
10+
addons:
11+
apt:
12+
packages:
13+
- cmake
14+
- lcov
15+
16+
script:
17+
- mkdir build && cd build
18+
- cmake -DCMAKE_BUILD_TYPE=Coverage ..
19+
- make
20+
- make nuflood_coverage
21+
22+
after_success:
23+
- bash <(curl -s https://codecov.io/bash)

CMakeLists.txt

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
project(nuflood)
2+
cmake_minimum_required(VERSION 2.8)
3+
4+
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeModules)
5+
6+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/output)
7+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/output)
8+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/output)
9+
10+
foreach(OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES})
11+
string(TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG)
12+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/output)
13+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/output)
14+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/output)
15+
endforeach(OUTPUTCONFIG CMAKE_CONFIGURATION_TYPES)
16+
17+
include_directories("libraries/rapidjson/include")
18+
add_subdirectory(source)

CMakeModules/CodeCoverage.cmake

+193
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
# Copyright (c) 2012 - 2015, Lars Bilke
2+
# All rights reserved.
3+
#
4+
# Redistribution and use in source and binary forms, with or without modification,
5+
# are permitted provided that the following conditions are met:
6+
#
7+
# 1. Redistributions of source code must retain the above copyright notice, this
8+
# list of conditions and the following disclaimer.
9+
#
10+
# 2. Redistributions in binary form must reproduce the above copyright notice,
11+
# this list of conditions and the following disclaimer in the documentation
12+
# and/or other materials provided with the distribution.
13+
#
14+
# 3. Neither the name of the copyright holder nor the names of its contributors
15+
# may be used to endorse or promote products derived from this software without
16+
# specific prior written permission.
17+
#
18+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
22+
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25+
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
#
29+
#
30+
#
31+
# 2012-01-31, Lars Bilke
32+
# - Enable Code Coverage
33+
#
34+
# 2013-09-17, Joakim Söderberg
35+
# - Added support for Clang.
36+
# - Some additional usage instructions.
37+
#
38+
# USAGE:
39+
40+
# 0. (Mac only) If you use Xcode 5.1 make sure to patch geninfo as described here:
41+
# http://stackoverflow.com/a/22404544/80480
42+
#
43+
# 1. Copy this file into your cmake modules path.
44+
#
45+
# 2. Add the following line to your CMakeLists.txt:
46+
# INCLUDE(CodeCoverage)
47+
#
48+
# 3. Set compiler flags to turn off optimization and enable coverage:
49+
# SET(CMAKE_CXX_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
50+
# SET(CMAKE_C_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
51+
#
52+
# 3. Use the function SETUP_TARGET_FOR_COVERAGE to create a custom make target
53+
# which runs your test executable and produces a lcov code coverage report:
54+
# Example:
55+
# SETUP_TARGET_FOR_COVERAGE(
56+
# my_coverage_target # Name for custom target.
57+
# test_driver # Name of the test driver executable that runs the tests.
58+
# # NOTE! This should always have a ZERO as exit code
59+
# # otherwise the coverage generation will not complete.
60+
# coverage # Name of output directory.
61+
# )
62+
#
63+
# 4. Build a Debug build:
64+
# cmake -DCMAKE_BUILD_TYPE=Debug ..
65+
# make
66+
# make my_coverage_target
67+
#
68+
#
69+
70+
# Check prereqs
71+
FIND_PROGRAM( GCOV_PATH gcov )
72+
FIND_PROGRAM( LCOV_PATH lcov )
73+
FIND_PROGRAM( GENHTML_PATH genhtml )
74+
FIND_PROGRAM( GCOVR_PATH gcovr PATHS ${CMAKE_SOURCE_DIR}/tests)
75+
76+
IF(NOT GCOV_PATH)
77+
MESSAGE(FATAL_ERROR "gcov not found! Aborting...")
78+
ENDIF() # NOT GCOV_PATH
79+
80+
IF(NOT CMAKE_COMPILER_IS_GNUCXX)
81+
# Clang version 3.0.0 and greater now supports gcov as well.
82+
MESSAGE(WARNING "Compiler is not GNU gcc! Clang Version 3.0.0 and greater supports gcov as well, but older versions don't.")
83+
84+
IF(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
85+
MESSAGE(FATAL_ERROR "Compiler is not GNU gcc! Aborting...")
86+
ENDIF()
87+
ENDIF() # NOT CMAKE_COMPILER_IS_GNUCXX
88+
89+
SET(CMAKE_CXX_FLAGS_COVERAGE
90+
"-g -O0 --coverage -fprofile-arcs -ftest-coverage"
91+
CACHE STRING "Flags used by the C++ compiler during coverage builds."
92+
FORCE )
93+
SET(CMAKE_C_FLAGS_COVERAGE
94+
"-g -O0 --coverage -fprofile-arcs -ftest-coverage"
95+
CACHE STRING "Flags used by the C compiler during coverage builds."
96+
FORCE )
97+
SET(CMAKE_EXE_LINKER_FLAGS_COVERAGE
98+
""
99+
CACHE STRING "Flags used for linking binaries during coverage builds."
100+
FORCE )
101+
SET(CMAKE_SHARED_LINKER_FLAGS_COVERAGE
102+
""
103+
CACHE STRING "Flags used by the shared libraries linker during coverage builds."
104+
FORCE )
105+
MARK_AS_ADVANCED(
106+
CMAKE_CXX_FLAGS_COVERAGE
107+
CMAKE_C_FLAGS_COVERAGE
108+
CMAKE_EXE_LINKER_FLAGS_COVERAGE
109+
CMAKE_SHARED_LINKER_FLAGS_COVERAGE )
110+
111+
IF ( NOT (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "Coverage"))
112+
MESSAGE( WARNING "Code coverage results with an optimized (non-Debug) build may be misleading" )
113+
ENDIF() # NOT CMAKE_BUILD_TYPE STREQUAL "Debug"
114+
115+
116+
# Param _targetname The name of new the custom make target
117+
# Param _testrunner The name of the target which runs the tests.
118+
# MUST return ZERO always, even on errors.
119+
# If not, no coverage report will be created!
120+
# Param _outputname lcov output is generated as _outputname.info
121+
# HTML report is generated in _outputname/index.html
122+
# Optional fourth parameter is passed as arguments to _testrunner
123+
# Pass them in list form, e.g.: "-j;2" for -j 2
124+
FUNCTION(SETUP_TARGET_FOR_COVERAGE _targetname _testrunner _outputname)
125+
126+
IF(NOT LCOV_PATH)
127+
MESSAGE(FATAL_ERROR "lcov not found! Aborting...")
128+
ENDIF() # NOT LCOV_PATH
129+
130+
IF(NOT GENHTML_PATH)
131+
MESSAGE(FATAL_ERROR "genhtml not found! Aborting...")
132+
ENDIF() # NOT GENHTML_PATH
133+
134+
# Setup target
135+
ADD_CUSTOM_TARGET(${_targetname}
136+
137+
# Cleanup lcov
138+
${LCOV_PATH} --directory . --zerocounters
139+
140+
# Run tests
141+
COMMAND ${_testrunner} ${ARGV3}
142+
143+
# Capturing lcov counters and generating report
144+
COMMAND ${LCOV_PATH} --directory . --capture --output-file ${_outputname}.info
145+
COMMAND ${LCOV_PATH} --remove ${_outputname}.info 'tests/*' '/usr/*' --output-file ${_outputname}.info.cleaned
146+
COMMAND ${GENHTML_PATH} -o ${_outputname} ${_outputname}.info.cleaned
147+
COMMAND ${CMAKE_COMMAND} -E remove ${_outputname}.info ${_outputname}.info.cleaned
148+
149+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
150+
COMMENT "Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report."
151+
)
152+
153+
# Show info where to find the report
154+
ADD_CUSTOM_COMMAND(TARGET ${_targetname} POST_BUILD
155+
COMMAND ;
156+
COMMENT "Open ./${_outputname}/index.html in your browser to view the coverage report."
157+
)
158+
159+
ENDFUNCTION() # SETUP_TARGET_FOR_COVERAGE
160+
161+
# Param _targetname The name of new the custom make target
162+
# Param _testrunner The name of the target which runs the tests
163+
# Param _outputname cobertura output is generated as _outputname.xml
164+
# Optional fourth parameter is passed as arguments to _testrunner
165+
# Pass them in list form, e.g.: "-j;2" for -j 2
166+
FUNCTION(SETUP_TARGET_FOR_COVERAGE_COBERTURA _targetname _testrunner _outputname)
167+
168+
IF(NOT PYTHON_EXECUTABLE)
169+
MESSAGE(FATAL_ERROR "Python not found! Aborting...")
170+
ENDIF() # NOT PYTHON_EXECUTABLE
171+
172+
IF(NOT GCOVR_PATH)
173+
MESSAGE(FATAL_ERROR "gcovr not found! Aborting...")
174+
ENDIF() # NOT GCOVR_PATH
175+
176+
ADD_CUSTOM_TARGET(${_targetname}
177+
178+
# Run tests
179+
${_testrunner} ${ARGV3}
180+
181+
# Running gcovr
182+
COMMAND ${GCOVR_PATH} -x -r ${CMAKE_SOURCE_DIR} -e '${CMAKE_SOURCE_DIR}/tests/' -o ${_outputname}.xml
183+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
184+
COMMENT "Running gcovr to produce Cobertura code coverage report."
185+
)
186+
187+
# Show info where to find the report
188+
ADD_CUSTOM_COMMAND(TARGET ${_targetname} POST_BUILD
189+
COMMAND ;
190+
COMMENT "Cobertura code coverage report saved in ${_outputname}.xml."
191+
)
192+
193+
ENDFUNCTION() # SETUP_TARGET_FOR_COVERAGE_COBERTURA

Dockerfile

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM ubuntu:14.04
2+
3+
MAINTAINER Byron Tasseff <[email protected]>
4+
5+
ENV HOME /root
6+
WORKDIR $HOME/
7+
8+
ADD . nuflood/
9+
10+
RUN apt-get update && apt-get -y upgrade
11+
RUN apt-get -y install gcc g++ make cmake
12+
13+
RUN cd /root/nuflood/ && mkdir build && cd build/ && cmake .. && make
14+
RUN mv nuflood/build/output/kurganov_petrova /usr/bin/kurganov_petrova
15+
RUN rm -r nuflood/

libraries/rapidjson

Submodule rapidjson added at ab791ae

source/CMakeLists.txt

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
add_definitions(-DUSE_DOUBLE=1)
2+
add_definitions(-DBIG_GRID=0)
3+
4+
find_program (INTEL_COMPILER icc)
5+
if(INTEL_COMPILER)
6+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11; -O3; -parallel; -openmp;
7+
-lpthread; -Wall; -g; -shared-intel; -debug inline-debug-info")
8+
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
9+
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fPIC")
10+
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fPIC")
11+
endif()
12+
elseif(CMAKE_COMPILER_IS_GNUCXX)
13+
IF(NOT(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "Coverage"))
14+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Ofast -fopenmp -Wall")
15+
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
16+
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fPIC")
17+
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fPIC")
18+
endif()
19+
ELSE()
20+
include(CodeCoverage)
21+
setup_target_for_coverage(${PROJECT_NAME}_coverage kurganov_petrova coverage "../test/coverage.json")
22+
set(CMAKE_CXX_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage -std=c++11")
23+
SET(CMAKE_C_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
24+
ENDIF()
25+
endif()
26+
27+
if(APPLE)
28+
set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "c++11")
29+
set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")
30+
set(CMAKE_XCODE_ATTRIBUTE_GCC_VERSION "com.apple.compilers.llvm.clang.1_0")
31+
endif()
32+
33+
if(WIN32)
34+
add_definitions(-DUNICODE -D_UNICODE)
35+
set(TARGET_ARCHITECTURE "x86")
36+
endif()
37+
38+
find_package(CUDA)
39+
if(CUDA_FOUND)
40+
#add_definitions(-DCUDA)
41+
include_directories(${CUDA_INCLUDE_DIRS})
42+
link_directories(${CUDA_LIBRARIES})
43+
list(APPEND LIBS ${CUDA_LIBRARIES})
44+
set(CUDA_PROPAGATE_HOST_FLAGS OFF)
45+
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -std=c++11; -O3; -use_fast_math;
46+
-ftz=true; -prec-div=false; -prec-sqrt=false; -Xptxas -dlcm=ca;
47+
-lineinfo; -Wno-deprecated-gpu-targets")
48+
endif()
49+
50+
include_directories("${CMAKE_CURRENT_SOURCE_DIR}")
51+
52+
add_subdirectory(common)
53+
add_subdirectory(models)

source/common/CMakeLists.txt

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
set(SOURCE_FILES
2+
iconstants.cpp document.cpp error.cpp file.cpp gpu_error.cpp folder.cpp
3+
isinks.cpp isources.cpp index_table.cpp itime.cpp name_list.cpp
4+
timer.cpp itopography.cpp ioutput.cpp)
5+
set(HEADER_FILES
6+
iconstants.h document.h error.h file.h folder.h gpu_error.h gpu_grid.h
7+
gpu_vector.h grid.h isinks.h isources.h index_table.h itime.h
8+
name_list.h parameter.h point_sink.h point_source.h point_source_list.h
9+
time_series.h timer.h itopography.h ioutput.h)
10+
11+
include_directories(${CMAKE_CURRENT_BINARY_DIR})
12+
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
13+
add_library(Common STATIC ${SOURCE_FILES} ${HEADER_FILES})
14+
15+
INSTALL(FILES ${HEADER_FILES} DESTINATION "include/nuflood/common")

source/common/document.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include "document.h"
2+
#include "error.h"
3+
#include "file.h"
4+
5+
Document::Document(const File& file) {
6+
FILE* p_file = fopen(file.path().c_str(), "r");
7+
8+
char buffer[65536];
9+
rapidjson::FileReadStream file_read_stream(p_file, buffer, sizeof(buffer));
10+
root.ParseStream<0>(file_read_stream);
11+
fclose(p_file);
12+
13+
if (!root.IsObject()) {
14+
PrintErrorAndExit("File '" + file.path() + "' is not a valid JSON document.");
15+
}
16+
}

source/common/document.h

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#pragma once
2+
3+
#include <rapidjson/document.h>
4+
#include <rapidjson/writer.h>
5+
#include <rapidjson/stringbuffer.h>
6+
#include <rapidjson/filereadstream.h>
7+
#include "file.h"
8+
9+
class Document {
10+
public:
11+
Document(const File& file);
12+
rapidjson::Document root;
13+
};

source/common/error.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <iostream>
2+
#include <fstream>
3+
#include <cstdlib>
4+
#include "error.h"
5+
6+
void PrintErrorAndExit(const std::string& error_message, int exit_code) {
7+
std::cerr << "Error: " << error_message << std::endl;
8+
std::exit(exit_code);
9+
}
10+
11+
void PrintWarning(const std::string& warning_message) {
12+
std::cerr << "Warning: " << warning_message << std::endl;
13+
}

source/common/error.h

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#pragma once
2+
3+
#include <string>
4+
5+
void PrintErrorAndExit(const std::string& error_message, int error_code = 1);
6+
void PrintWarning(const std::string& warning_message);

0 commit comments

Comments
 (0)