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

Build on Windows #3

Merged
merged 7 commits into from
Feb 26, 2021
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
89 changes: 89 additions & 0 deletions .github/workflows/conda-and-cmake.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: Build/Test CI

on: [push, pull_request]

jobs:
build-linux-and-macos:
runs-on: ${{ matrix.os }}

defaults:
run:
shell: bash -l {0}

strategy:
matrix:
os: [ubuntu-latest, macos-latest]
python-version: ["3.8"]
build-type: [Release]

steps:
- uses: actions/checkout@v2

- uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
python-version: ${{ matrix.python-version }}
channels: conda-forge
channel-priority: true

- name: Show conda installation info
run: conda info

- name: Install build tools and dependencies into env
run: |
conda install --file=requirements.txt
conda list

- name: Make cmake build directory
run: cmake -E make_directory build

- name: Configure cmake
working-directory: ${{ github.workspace }}/build
run: cmake $GITHUB_WORKSPACE/src -DCMAKE_BUILD_TYPE=${{ matrix.build-type }}

- name: Build
working-directory: ${{ github.workspace }}/build
run: cmake --build . --config ${{ matrix.build-type }}

build-windows:
runs-on: windows-latest

env:
build-type: Release

steps:
- uses: actions/checkout@v2

- uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
python-version: 3.8
channels: conda-forge
channel-priority: true

- name: Show conda installation info
run: conda info

- name: Install build tools and dependencies into env
run: |
conda install --file=requirements.txt
conda list

- name: Make cmake build directory
run: cmake -E make_directory build

- name: Configure, build, and test
shell: cmd /C CALL {0}
working-directory: ${{ github.workspace }}\build
run: |
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat" -vcvars_ver=14.16 10.0.19041.0

:: Configure
cmake ^
-LAH -G "NMake Makefiles" ^
-DPKG_CONFIG_EXECUTABLE:FILEPATH=C:/Miniconda/envs/test/Library/bin/pkg-config.exe ^
-DCMAKE_BUILD_TYPE=${{ env.build-type }} ^
${{ github.workspace }}\src

:: Build and install
cmake --build . --target install --config ${{ env.build-type }}
93 changes: 92 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,93 @@
# CDM_v2.48
![Build/Test CI](https://github.com/mcflugen/CDM_v3.0/workflows/Build/Test%20CI/badge.svg)

# Coastal Dune Model

Coastal Dune Model that includes updated vegetation and wrack dynamics.


## Install

### Prerequisites

To install the Coastal Dune Model from source, you will need to install some
prerequisite packages.
* A C++ compiler
* CMake
* FFTW

If you are using Anaconda, these can be installed through the *conda* command.

$ conda create -n cdm --file=requirements.txt
$ conda activate cdm

This creates a new conda environment, *cdm*, with all of the prequisite packages
installed.

### Compile

#### Linux and Mac

To build and install cmake, run

$ mkdir _build && cd _build
$ cmake ../src -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX
$ make -j4
$ make install

This will install Coastal Dune Model into your current conda environment.

#### Windows

To build the *CDM* on Windows, you will need to install a C++ compiler. The
following instructions assume *Microsoft Visual Studio 2017 or Microsoft Build
Tools for Visual Studio 2017*.

After you have activated the conda environment you created in the previous
section, you need to set up your compiler by running *vcvarsall.bat*. This
can be done from within the Anaconda Powershell Prompt by running the
following,

$ & 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat' x86

You should now be able to run *cmake* and then compile the program in a
way that is similar to with Linux and Mac,

$ mkdir _build
$ cd _build
$ cmake ../src -DCMAKE_INSTALL_PREFIX:PATH=$env:CONDA_PREFIX
$ cmake --build . --target install

## Use

With the Coastal Dune Model installed following the above instructions, you
can run it with the *coastal-dune-model* executable that was installed in
`<path-to-installation>/bin`. If this folder is in your *PATH*,

$ coastal-dune-model params.par

## References

Biel, R. G., Moore, L. J., and Goldstein, E. B. (submitted). Influence of wrack on dune forma-
tion.Journal of Geophysical Research: Biogeosciences.

Biel, R. G., Moore, L. J., Zinnert, J., and Brown, J. (in prep.). Inhibition or facilitation of
dune development on barriers: The influence of back-beach vegetation on barrier island sta-
ble states.Journal of Geophysical Research: Biogeosciences.

Duran, O. and Moore, L. J. (2013). Vegetation controls on the maximum size of coastal dunes.
Proceedings of the National Academy of Sciences, 110(43):17217–17222.

Duran, O., Parteli, E. J., and Herrmann, H. J. (2010). A continuous model for sand dunes:
Review, new developments and application to barchan dunes and barchan dune fields.Earth
Surface Processes and Landforms, 35(13):1591–1600.

Duran Vinent, O. and Moore, L. J. (2015). Barrier island bistability induced by biophysical
interactions.Nature Clim. Change, 5(2):158–162.

Moore, L. J., Vinent, O. D., and Ruggiero, P. (2016). Vegetation control allows autocyclic
formation of multiple dunes on prograding coasts.Geology, 44(7):559–562.

Weng, W. S., Hunt, J. C. R., Carruthers, D. J., Warren, A., Wiggs, G. F. S., Livingstone, I.,
and Castro, I. (1991). Air flow and sand transport over sand-dunes. In Barndorff-Nielsen,
O. E. and Willetts, B. B., editors,Aeolian Grain Transport, pages 1–22, Vienna. Springer
Vienna.
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cmake
cxx-compiler
fftw
pkg-config
66 changes: 66 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
cmake_minimum_required(VERSION 3.0)
include(CheckIncludeFile)

# project (cdm CXX)
project (cdm)

set (CDM_VERSION 3.0)

find_package(PkgConfig REQUIRED)
pkg_check_modules(FFTW3 REQUIRED IMPORTED_TARGET fftw3)
include_directories(${FFTW3_INCLUDE_DIRS})
link_directories(${FFTW3_LIBRARY_DIRS})

check_include_file(unistd.h WITH_UNISTD)
check_include_file(sys/utsname.h WITH_UTSNAME)
find_library(LIB_M m)

if (WITH_UNISTD)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DWITH_UNISTD")
endif (WITH_UNISTD)
if (WITH_UTSNAME)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DWITH_UTSNAME")
endif (WITH_UTSNAME)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_USE_MATH_DEFINES")

set(
CDM_SRCS
PTG_Func2dScalar.cc
PTG_Func2dVec.cc
analyze_new.cc
avalanche.cc
dune_evolution.cc
evolution.cc
flux_stationary.cc
func.cc
globals.cc
influx.cc
initsurf.cc
initsurfalea.cc
initsurfbeach.cc
iter_aval_new.cc
rfftw12d.cc
rotatematrix.cc
save.cc
sepbubble.cc
shear.cc
shear_hlr.cc
shore.cc
storm.cc
vegetation.cc
wind.cc
)

add_executable(coastal-dune-model main.cc ${CDM_SRCS})
if (LIB_M)
target_link_libraries(coastal-dune-model fftw3 m)
elseif (NOT LIB_M)
target_link_libraries(coastal-dune-model fftw3)
endif (LIB_M)

install(
TARGETS coastal-dune-model
RUNTIME DESTINATION bin
)

File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 3 additions & 2 deletions PTG_Func2dScalar.cc → src/PTG_Func2dScalar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
******************************************************************************/

#include <iostream>

#include <math.h>
#include "globals.h"
#include "PTG_Func2dScalar.h"
Expand Down Expand Up @@ -147,13 +148,13 @@ double PTG_Func2dScalar::CenterOfMassX() const
for (int x=0; x < SizeX(); x++) {
double linesum= 0.0;
for (int y=0; y < SizeY(); y++)
if( finite((*this)(x, y)) )
if( isfinite((*this)(x, y)) )
linesum += (*this)(x,y);
xsum += linesum * x;
sum += linesum;
}
centerx= Delta()*xsum/sum;
if( finite(centerx) )
if( isfinite(centerx) )
return centerx;
else
return Delta()*SizeX()/2.0;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 5 additions & 1 deletion globals.cc → src/globals.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#ifdef WITH_UNISTD
#include <unistd.h>
#endif
#include <errno.h>
#include <math.h>

Expand Down Expand Up @@ -463,11 +465,13 @@ duneglobals::duneglobals( const dunepar& parameters )
"'. Data directory doesn't exist or permission denied. Aborting.\n";
exit(1);
}
#ifdef WITH_UNISTD
if( !S_ISDIR(savedirstat.st_mode) ) {
cerr << "duneglobals constructor: Data directory `" << m_datadir <<
"' is not a directory. Aborting.\n";
exit(1);
}
#endif
}


Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 8 additions & 2 deletions main.cc → src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
******************************************************************************/

#include <time.h>
#include <sys/utsname.h>
#ifdef WITH_UTSNAME
#include <sys/utsname.h>
#endif
#include <sys/types.h>
#include <unistd.h>
// #include <unistd.h>

#include "globals.h"
#include "dune_evolution.h"
Expand Down Expand Up @@ -39,12 +41,16 @@ parameter file version, a CPde object (for backward compatibility; version <
CApp::CApp(int argc, char **argv) : m_evol(0)

{
#ifdef UTSNAME
struct utsname u;
#endif
time_t t= time(NULL);

#ifdef UTSNAME
if( !uname(&u) )
cout << "Running on " << u.nodename << ", machine type " << u.machine << ", with process id " << getpid() << "\n";
cout << ctime( &t ) << "\n";
#endif

// find name for parameter file
// Format for command line arguments: <token>=<value>, for instance
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions shear_hlr.cc → src/shear_hlr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ double shearHLR::CalcPertTau(TFktScal& h, TFktVec& tau)
ky2= ky*ky;
ka= sqrt(kx2+ky2);

if( (!finite(fft_h.freqre(x, y)) || !finite(fft_h.freqim(x, y))) && !naninfwarned ) {
if( (!isfinite(fft_h.freqre(x, y)) || !isfinite(fft_h.freqim(x, y))) && !naninfwarned ) {
fprintf(stderr, "CShearHLR::CalcPertTau: NAN or INF in fft_h after FT.\n");
naninfwarned= true;
}
Expand Down Expand Up @@ -226,7 +226,7 @@ double shearHLR::CalcPertTau(TFktScal& h, TFktVec& tau)
}
L = Int/(Int_x*m_dkx);

if( !finite(L) ) L= iNx;
if( !isfinite(L) ) L= iNx;

return L;
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 9 additions & 5 deletions wind.cc → src/wind.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
$Id: wind.cc,v 1.5 2004/12/22 10:21:57 schatz Exp $
******************************************************************************/

#include <random>
#include <stdlib.h>
#include <math.h>
#include <time.h>
Expand Down Expand Up @@ -118,7 +119,8 @@ wind_flatrand::wind_flatrand(const dunepar& par)
m_dir0= par.getdefault( "flatwind.avgdir", 0.0 ) / 360.0;
m_ddir= par.getrequired<double>( "flatwind.ddir" ) / 360.0;

initstate( time(NULL), m_statearray, 256 );
// initstate( time(NULL), m_statearray, 256 );
srand(1973);
}


Expand All @@ -130,17 +132,19 @@ void wind_flatrand::advance( double )
{
char *prevrngstate;

prevrngstate= setstate(m_statearray);
// prevrngstate = setstate(m_statearray);
srand(1973);
if( m_ddir==0.0 )
m_dir= m_dir0;
else
m_dir= m_dir0 + m_ddir * 2.0 * ((double)random()/(double)RAND_MAX - 0.5);
m_dir= m_dir0 + m_ddir * 2.0 * ((double)rand()/(double)RAND_MAX - 0.5);
if( m_dustar==0.0 )
m_ustar= m_ustar0;
else
m_ustar= m_ustar0 +
m_dustar * 2.0 * ((double)random()/(double)RAND_MAX - 0.5);
setstate(prevrngstate);
m_dustar * 2.0 * ((double)rand()/(double)RAND_MAX - 0.5);
// setstate(prevrngstate);
srand(1973);
}


Expand Down
File renamed without changes.