Commit 04ef2c31 authored by Johannes Spazier's avatar Johannes Spazier

Removed strange control character '^M' from files.

parent b940b99c
...@@ -22,183 +22,183 @@ ...@@ -22,183 +22,183 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#define HEADER "\neasyWave ver.2013-04-11\n" #define HEADER "\neasyWave ver.2013-04-11\n"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include <utilits.h> #include <utilits.h>
#include "easywave.h" #include "easywave.h"
#include "ewGpuNode.cuh" #include "ewGpuNode.cuh"
CNode *gNode; CNode *gNode;
double diff(timespec start, timespec end) { double diff(timespec start, timespec end) {
timespec temp; timespec temp;
if ((end.tv_nsec-start.tv_nsec)<0) { if ((end.tv_nsec-start.tv_nsec)<0) {
temp.tv_sec = end.tv_sec-start.tv_sec-1; temp.tv_sec = end.tv_sec-start.tv_sec-1;
temp.tv_nsec = 1000000000+end.tv_nsec-start.tv_nsec; temp.tv_nsec = 1000000000+end.tv_nsec-start.tv_nsec;
} else { } else {
temp.tv_sec = end.tv_sec-start.tv_sec; temp.tv_sec = end.tv_sec-start.tv_sec;
temp.tv_nsec = end.tv_nsec-start.tv_nsec; temp.tv_nsec = end.tv_nsec-start.tv_nsec;
} }
return (double)((double)temp.tv_nsec / 1000000000.0 + (double)temp.tv_sec); return (double)((double)temp.tv_nsec / 1000000000.0 + (double)temp.tv_sec);
} }
int commandLineHelp( void ); int commandLineHelp( void );
int main( int argc, char **argv ) int main( int argc, char **argv )
{ {
char buf[1024]; char buf[1024];
int ierr,argn,elapsed; int ierr,argn,elapsed;
int lastProgress,lastPropagation,lastDump; int lastProgress,lastPropagation,lastDump;
int loop; int loop;
printf(HEADER); printf(HEADER);
Err.setchannel(MSG_OUTFILE); Err.setchannel(MSG_OUTFILE);
// Read parameters from command line and use default // Read parameters from command line and use default
ierr = ewParam( argc, argv ); if(ierr) return commandLineHelp(); ierr = ewParam( argc, argv ); if(ierr) return commandLineHelp();
// Log command line // Log command line
/* FIXME: buffer overflow */ /* FIXME: buffer overflow */
sprintf( buf, "Command line: " ); sprintf( buf, "Command line: " );
for( argn=1; argn<argc; argn++ ) { for( argn=1; argn<argc; argn++ ) {
strcat( buf, " " ); strcat( buf, " " );
strcat( buf, argv[argn] ); strcat( buf, argv[argn] );
} }
Log.print( "%s", buf ); Log.print( "%s", buf );
if( Par.gpu ) { if( Par.gpu ) {
gNode = new CGpuNode(); gNode = new CGpuNode();
} else { } else {
gNode = new CStructNode(); gNode = new CStructNode();
//gNode = new CArrayNode(); //gNode = new CArrayNode();
} }
CNode& Node = *gNode; CNode& Node = *gNode;
// Read bathymetry // Read bathymetry
ierr = ewLoadBathymetry(); if(ierr) return ierr; ierr = ewLoadBathymetry(); if(ierr) return ierr;
// Read points of interest // Read points of interest
ierr = ewLoadPOIs(); if(ierr) return ierr; ierr = ewLoadPOIs(); if(ierr) return ierr;
// Init tsunami with faults or uplift-grid // Init tsunami with faults or uplift-grid
ierr = ewSource(); if(ierr) return ierr; ierr = ewSource(); if(ierr) return ierr;
Log.print( "Read source from %s", Par.fileSource ); Log.print( "Read source from %s", Par.fileSource );
// Write model parameters into the log // Write model parameters into the log
ewLogParams(); ewLogParams();
if( Par.outPropagation ) ewStart2DOutput(); if( Par.outPropagation ) ewStart2DOutput();
Node.copyToGPU(); Node.copyToGPU();
// Main loop // Main loop
Log.print("Starting main loop..."); Log.print("Starting main loop...");
printf("Starting main loop %ld msec\n", clock()/(CLOCKS_PER_SEC/1000) ); printf("Starting main loop %ld msec\n", clock()/(CLOCKS_PER_SEC/1000) );
timespec start, end; timespec start, end;
clock_gettime(CLOCK_MONOTONIC, &start); clock_gettime(CLOCK_MONOTONIC, &start);
for( Par.time=0,loop=1,lastProgress=Par.outProgress,lastPropagation=Par.outPropagation,lastDump=0; for( Par.time=0,loop=1,lastProgress=Par.outProgress,lastPropagation=Par.outPropagation,lastDump=0;
Par.time<=Par.timeMax; loop++,Par.time+=Par.dt,lastProgress+=Par.dt,lastPropagation+=Par.dt ) { Par.time<=Par.timeMax; loop++,Par.time+=Par.dt,lastProgress+=Par.dt,lastPropagation+=Par.dt ) {
/* FIXME: check if Par.poiDt can be used for those purposes */ /* FIXME: check if Par.poiDt can be used for those purposes */
if( Par.filePOIs && Par.poiDt && ((Par.time/Par.poiDt)*Par.poiDt == Par.time) ) { if( Par.filePOIs && Par.poiDt && ((Par.time/Par.poiDt)*Par.poiDt == Par.time) ) {
Node.copyPOIs(); Node.copyPOIs();
ewSavePOIs(); ewSavePOIs();
} }
Node.run(); Node.run();
elapsed = ((int)clock())/CLOCKS_PER_SEC; elapsed = ((int)clock())/CLOCKS_PER_SEC;
if( Par.outProgress ) { if( Par.outProgress ) {
if( lastProgress >= Par.outProgress ) { if( lastProgress >= Par.outProgress ) {
printf( "Model time = %s, elapsed: %ld msec\n", utlTimeSplitString(Par.time), clock()/(CLOCKS_PER_SEC/1000) ); printf( "Model time = %s, elapsed: %ld msec\n", utlTimeSplitString(Par.time), clock()/(CLOCKS_PER_SEC/1000) );
Log.print( "Model time = %s, elapsed: %ld msec", utlTimeSplitString(Par.time), clock()/(CLOCKS_PER_SEC/1000) ); Log.print( "Model time = %s, elapsed: %ld msec", utlTimeSplitString(Par.time), clock()/(CLOCKS_PER_SEC/1000) );
lastProgress = 0; lastProgress = 0;
} }
} }
if( Par.outPropagation ) { if( Par.outPropagation ) {
if( lastPropagation >= Par.outPropagation ) { if( lastPropagation >= Par.outPropagation ) {
Node.copyIntermediate(); Node.copyIntermediate();
ewOut2D(); ewOut2D();
lastPropagation = 0; lastPropagation = 0;
} }
} }
fflush(stdout); fflush(stdout);
if( Par.outDump ) { if( Par.outDump ) {
if( (elapsed-lastDump) >= Par.outDump ) { if( (elapsed-lastDump) >= Par.outDump ) {
Node.copyIntermediate(); Node.copyIntermediate();
/* FIXME: needs tArr as well */ /* FIXME: needs tArr as well */
ewDumpPOIs(); ewDumpPOIs();
ewDump2D(); ewDump2D();
lastDump = elapsed; lastDump = elapsed;
} }
} }
} // main loop } // main loop
clock_gettime(CLOCK_MONOTONIC, &end); clock_gettime(CLOCK_MONOTONIC, &end);
Log.print("Finishing main loop"); Log.print("Finishing main loop");
/* TODO: check if theses calls can be combined */ /* TODO: check if theses calls can be combined */
Node.copyIntermediate(); Node.copyIntermediate();
Node.copyFromGPU(); Node.copyFromGPU();
// Final output // Final output
Log.print("Final dump..."); Log.print("Final dump...");
ewDumpPOIs(); ewDumpPOIs();
ewDump2D(); ewDump2D();
Node.freeMem(); Node.freeMem();
printf_v("Runtime: %.3lf\n", diff(start, end) * 1000.0); printf_v("Runtime: %.3lf\n", diff(start, end) * 1000.0);
delete gNode; delete gNode;
return 0; return 0;
} }
//======================================================================== //========================================================================
int commandLineHelp( void ) int commandLineHelp( void )
{ {
printf( "Usage: easyWave -grid ... -source ... -time ... [optional parameters]\n" ); printf( "Usage: easyWave -grid ... -source ... -time ... [optional parameters]\n" );
printf( "-grid ... bathymetry in GoldenSoftware(C) GRD format (text or binary)\n" ); printf( "-grid ... bathymetry in GoldenSoftware(C) GRD format (text or binary)\n" );
printf( "-source ... input wave either als GRD-file or file with Okada faults\n" ); printf( "-source ... input wave either als GRD-file or file with Okada faults\n" );
printf( "-time ... simulation time in [min]\n" ); printf( "-time ... simulation time in [min]\n" );
printf( "Optional parameters:\n" ); printf( "Optional parameters:\n" );
printf( "-step ... simulation time step, default- estimated from bathymetry\n" ); printf( "-step ... simulation time step, default- estimated from bathymetry\n" );
printf( "-coriolis use Coriolis fource, default- no\n" ); printf( "-coriolis use Coriolis fource, default- no\n" );
printf( "-poi ... POIs file\n" ); printf( "-poi ... POIs file\n" );
printf( "-label ... model name, default- 'eWave'\n" ); printf( "-label ... model name, default- 'eWave'\n" );
printf( "-progress ... show simulation progress each ... minutes, default- 10\n" ); printf( "-progress ... show simulation progress each ... minutes, default- 10\n" );
printf( "-propagation ... write wave propagation grid each ... minutes, default- 5\n" ); printf( "-propagation ... write wave propagation grid each ... minutes, default- 5\n" );
printf( "-dump ... make solution dump each ... physical seconds, default- 0\n" ); printf( "-dump ... make solution dump each ... physical seconds, default- 0\n" );
printf( "-nolog deactivate logging\n" ); printf( "-nolog deactivate logging\n" );
printf( "-poi_dt_out ... output time step for mariograms in [sec], default- 30\n" ); printf( "-poi_dt_out ... output time step for mariograms in [sec], default- 30\n" );
printf( "-poi_search_dist ... in [km], default- 10\n" ); printf( "-poi_search_dist ... in [km], default- 10\n" );
printf( "-poi_min_depth ... in [m], default- 1\n" ); printf( "-poi_min_depth ... in [m], default- 1\n" );
printf( "-poi_max_depth ... in [m], default- 10 000\n" ); printf( "-poi_max_depth ... in [m], default- 10 000\n" );
printf( "-poi_report enable POIs loading report, default- disabled\n" ); printf( "-poi_report enable POIs loading report, default- disabled\n" );
printf( "-ssh0_rel ... relative threshold for initial wave, default- 0.01\n" ); printf( "-ssh0_rel ... relative threshold for initial wave, default- 0.01\n" );
printf( "-ssh0_abs ... absolute threshold for initial wave in [m], default- 0\n" ); printf( "-ssh0_abs ... absolute threshold for initial wave in [m], default- 0\n" );
printf( "-ssh_arrival ... threshold for arrival times in [m], default- 0.001\n" ); printf( "-ssh_arrival ... threshold for arrival times in [m], default- 0.001\n" );
printf( " negative value considered as relative threshold\n" ); printf( " negative value considered as relative threshold\n" );
printf( "-gpu start GPU version of EasyWave (requires a CUDA capable device)\n" ); printf( "-gpu start GPU version of EasyWave (requires a CUDA capable device)\n" );
printf( "-verbose generate verbose output on stdout\n" ); printf( "-verbose generate verbose output on stdout\n" );
printf( "\nExample:\n" ); printf( "\nExample:\n" );
printf( "\t easyWave -grid gebcoIndonesia.grd -source fault.inp -time 120\n\n" ); printf( "\t easyWave -grid gebcoIndonesia.grd -source fault.inp -time 120\n\n" );
return -1; return -1;
} }
...@@ -22,1162 +22,1162 @@ ...@@ -22,1162 +22,1162 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <math.h> #include <math.h>
#include <utilits.h> #include <utilits.h>
#include <cOgrd.h> #include <cOgrd.h>
#define DEFAULT_NOVAL 0.0 #define DEFAULT_NOVAL 0.0
#define ROWWISE 1 #define ROWWISE 1
#define COLWISE 2 #define COLWISE 2
#define TOP2BOT -1 #define TOP2BOT -1
#define BOT2TOP 1 #define BOT2TOP 1
int iabs( int i ) int iabs( int i )
{ {
return( (i<0) ? (-i) : i ); return( (i<0) ? (-i) : i );
} }
//========================================================================= //=========================================================================
// Zero Constructor // Zero Constructor
cOgrd::cOgrd( ) cOgrd::cOgrd( )
{ {
xmin = xmax = dx = 0.; xmin = xmax = dx = 0.;
nx = 0; nx = 0;
ymin = ymax = dy = 0.; ymin = ymax = dy = 0.;
ny = 0; ny = 0;
nnod = 0; nnod = 0;
noval = DEFAULT_NOVAL; noval = DEFAULT_NOVAL;
val = NULL; val = NULL;
} }
//========================================================================= //=========================================================================
// Copy constructor similar to operator = // Copy constructor similar to operator =
cOgrd::cOgrd( const cOgrd& grd ) cOgrd::cOgrd( const cOgrd& grd )
{ {
xmin=grd.xmin; xmax=grd.xmax; dx=grd.dx; nx=grd.nx; xmin=grd.xmin; xmax=grd.xmax; dx=grd.dx; nx=grd.nx;
ymin=grd.ymin; ymax=grd.ymax; dy=grd.dy; ny=grd.ny; ymin=grd.ymin; ymax=grd.ymax; dy=grd.dy; ny=grd.ny;
nnod=grd.nnod; nnod=grd.nnod;
noval=grd.noval; noval=grd.noval;
val = new double[nnod]; val = new double[nnod];
memcpy( val, grd.val, nnod*sizeof(double) ); memcpy( val, grd.val, nnod*sizeof(double) );
} }
//========================================================================= //=========================================================================
cOgrd::cOgrd( double xmin0, double xmax0, int nx0, double ymin0, double ymax0, int ny0 ) cOgrd::cOgrd( double xmin0, double xmax0, int nx0, double ymin0, double ymax0, int ny0 )
{ {
noval = DEFAULT_NOVAL; noval = DEFAULT_NOVAL;
val = NULL; val = NULL;
initialize( xmin0, xmax0, nx0, ymin0, ymax0, ny0 ); initialize( xmin0, xmax0, nx0, ymin0, ymax0, ny0 );
} }
//========================================================================= //=========================================================================
cOgrd::cOgrd( double xmin0, double xmax0, double dx0, double ymin0, double ymax0, double dy0 ) cOgrd::cOgrd( double xmin0, double xmax0, double dx0, double ymin0, double ymax0, double dy0 )
{ {
noval = DEFAULT_NOVAL; noval = DEFAULT_NOVAL;
val = NULL; val = NULL;
initialize( xmin0, xmax0, dx0, ymin0, ymax0, dy0 ); initialize( xmin0, xmax0, dx0, ymin0, ymax0, dy0 );
} }
//========================================================================= //=========================================================================
// Destructor // Destructor
cOgrd::~cOgrd() cOgrd::~cOgrd()
{ {
if(val) delete [] val; if(val) delete [] val;
} }
//========================================================================= //=========================================================================
// Initialize with number of nodes // Initialize with number of nodes
int cOgrd::initialize( double xmin0, double xmax0, int nx0, double ymin0, double ymax0, int ny0 ) int cOgrd::initialize( double xmin0, double xmax0, int nx0, double ymin0, double ymax0, int ny0 )
{ {
xmin = xmin0; xmin = xmin0;
xmax = xmax0; xmax = xmax0;
nx = nx0; nx = nx0;
dx = (xmax-xmin)/(nx-1); dx = (xmax-xmin)/(nx-1);
ymin = ymin0; ymin = ymin0;
ymax = ymax0; ymax = ymax0;
ny = ny0; ny = ny0;
dy = (ymax-ymin)/(ny-1); dy = (ymax-ymin)/(ny-1);
nnod = nx*ny; nnod = nx*ny;
if( val ) delete [] val; if( val ) delete [] val;
val = new double[nnod]; val = new double[nnod];
for( int l=0; l<nnod; l++ ) val[l]=noval; for( int l=0; l<nnod; l++ ) val[l]=noval;
return 0; return 0;
} }
//========================================================================= //=========================================================================
// Initialize with grid step // Initialize with grid step
int cOgrd::initialize( double xmin0, double xmax0, double dx0, double ymin0, double ymax0, double dy0 ) int cOgrd::initialize( double xmin0, double xmax0, double dx0, double ymin0, double ymax0, double dy0 )
{ {
xmin = xmin0; xmin = xmin0;
xmax = xmax0; xmax = xmax0;
dx = dx0; dx = dx0;
nx = (int)((xmax-xmin)/dx + 1.e-10) + 1; nx = (int)((xmax-xmin)/dx + 1.e-10) + 1;
ymin = ymin0; ymin = ymin0;
ymax = ymax0; ymax = ymax0;
dy = dy0; dy = dy0;
ny = (int)((ymax-ymin)/dy + 1.e-10) + 1; ny = (int)((ymax-ymin)/dy + 1.e-10) + 1;
nnod = nx*ny; nnod = nx*ny;
if( val ) delete [] val; if( val ) delete [] val;
val = new double[nnod]; val = new double[nnod];
for( int l=0; l<nnod; l++ ) val[l]=noval; for( int l=0; l<nnod; l++ ) val[l]=noval;
return 0; return 0;
} }
//========================================================================= //=========================================================================
void cOgrd::setNoval( double val ) void cOgrd::setNoval( double val )
{ {
noval = val; noval = val;
} }