Commit d21912d5 authored by Christopher Subich's avatar Christopher Subich

Merge remote-tracking branch 'david/master'

parents 8ae27fe5 d317ebc8
#include "BaseCase.hpp"
#include "Science.hpp"
#include "NSIntegrator.hpp"
#include "TArray.hpp"
#include <blitz/array.h>
......@@ -412,7 +413,7 @@ void BaseCase::write_diagnostics(string header, string line,
FILE * diagnos_file = fopen("diagnostics.txt","a");
assert(diagnos_file);
// print header
if (iter == 1 and !restarting) {
if (iter == 0 and !restarting) {
fprintf(diagnos_file,"%s\n",clean_header.c_str());
}
// print the line of values
......@@ -421,6 +422,25 @@ void BaseCase::write_diagnostics(string header, string line,
fclose(diagnos_file);
}
// Write plot time information
void BaseCase::write_plot_times(double time, double clock_time, double comp_duration,
double avg_write_time, int plot_number, bool restarting) {
if (master()) {
// in log file
fprintf(stdout,"*Write time: %.6g. Average write time: %.6g.\n",
clock_time - comp_duration, avg_write_time);
// track in a file
FILE * plottimes_file = fopen("plot_times.txt","a");
assert(plottimes_file);
if ( plot_number==get_restart_sequence()+1 and !restarting )
fprintf(plottimes_file,"Output number, Simulation time (s), "
"Write time (s), Average write time (s)\n");
fprintf(plottimes_file,"%d, %.17f, %.12g, %.12g\n",
plot_number, time, clock_time - comp_duration, avg_write_time);
fclose(plottimes_file);
}
}
// parse expansion types
void parse_boundary_conditions(const string xgrid_type, const string ygrid_type,
const string zgrid_type, DIMTYPE & intype_x, DIMTYPE & intype_y, DIMTYPE & intype_z) {
......@@ -452,3 +472,93 @@ void parse_boundary_conditions(const string xgrid_type, const string ygrid_type,
}
}
// Top stresses
void BaseCase::stresses_top(TArrayn::DTArray & u, TArrayn::DTArray & v, TArrayn::DTArray & w,
TArrayn::DTArray & Hprime, TArrayn::DTArray & temp, TArrayn::Grad * gradient_op,
const string * grid_type, const double mu, double time, int itercount, bool restarting) {
// set-up
static DTArray *tx = alloc_array(size_x(),size_y(),1);
static DTArray *ty = alloc_array(size_x(),size_y(),1);
blitz::firstIndex ii;
blitz::secondIndex jj;
// top stress ( along channel - x )
top_stress_x(*tx, u, temp, gradient_op, grid_type, size_z(), mu);
double top_tx_tot = pssum(sum(
(*get_quad_x())(ii)*
(*get_quad_y())(jj)*(*tx)));
double top_tx_abs = pssum(sum(
(*get_quad_x())(ii)*
(*get_quad_y())(jj)*abs(*tx)));
// top stress ( across channel - y )
top_stress_y(*ty, v, temp, gradient_op, grid_type, size_z(), mu);
double top_ty_tot = pssum(sum(
(*get_quad_x())(ii)*
(*get_quad_y())(jj)*(*ty)));
double top_ty_abs = pssum(sum(
(*get_quad_x())(ii)*
(*get_quad_y())(jj)*abs(*ty)));
// total top stress
double top_ts = pssum(sum(
(*get_quad_x())(ii)*
(*get_quad_y())(jj)*pow(pow(*tx,2)+pow(*ty,2),0.5)));
// write to a stress diagnostic file
if (master()) {
FILE * stresses_file = fopen("stresses_top.txt","a");
assert(stresses_file);
if ( itercount==0 and !restarting )
fprintf(stresses_file,"Time, "
"Top_tx_tot, Top_tx_abs, Top_ty_tot, Top_ty_abs, Top_ts\n");
fprintf(stresses_file,"%.17f, "
"%.17g, %.17g, %.17g, %.17g, %.17g\n",
time,
top_tx_tot, top_tx_abs, top_ty_tot, top_ty_abs, top_ts);
fclose(stresses_file);
}
}
// Bottom stresses
void BaseCase::stresses_bottom(TArrayn::DTArray & u, TArrayn::DTArray & v, TArrayn::DTArray & w,
TArrayn::DTArray & Hprime, TArrayn::DTArray & temp, TArrayn::Grad * gradient_op,
const string * grid_type, const double mu, double time, int itercount, bool restarting) {
// set-up
static DTArray *tx = alloc_array(size_x(),size_y(),1);
static DTArray *ty = alloc_array(size_x(),size_y(),1);
blitz::firstIndex ii;
blitz::secondIndex jj;
// bottom stress ( along channel - x )
bottom_stress_x(*tx, Hprime, u, w, temp, gradient_op, grid_type, is_mapped(), mu);
double bot_tx_tot = pssum(sum(
(*get_quad_x())(ii)*pow(1+pow(Hprime,2),0.5)*
(*get_quad_y())(jj)*(*tx)));
double bot_tx_abs = pssum(sum(
(*get_quad_x())(ii)*pow(1+pow(Hprime,2),0.5)*
(*get_quad_y())(jj)*abs(*tx)));
// bottom stress ( across channel - y )
bottom_stress_y(*ty, Hprime, v, temp, gradient_op, grid_type, is_mapped(), mu);
double bot_ty_tot = pssum(sum(
(*get_quad_x())(ii)*pow(1+pow(Hprime,2),0.5)*
(*get_quad_y())(jj)*(*ty)));
double bot_ty_abs = pssum(sum(
(*get_quad_x())(ii)*pow(1+pow(Hprime,2),0.5)*
(*get_quad_y())(jj)*abs(*ty)));
// total bottom stress
double bot_ts = pssum(sum(
(*get_quad_x())(ii)*pow(1+pow(Hprime,2),0.5)*
(*get_quad_y())(jj)*pow(pow(*tx,2)+pow(*ty,2),0.5)));
// write to a stress diagnostic file
if (master()) {
FILE * stresses_file = fopen("stresses_bottom.txt","a");
assert(stresses_file);
if ( itercount==0 and !restarting )
fprintf(stresses_file,"Time, "
"Bottom_tx_tot, Bottom_tx_abs, Bottom_ty_tot, Bottom_ty_abs, Bottom_ts\n");
fprintf(stresses_file,"%.17f, "
"%.17g, %.17g, %.17g, %.17g, %.17g\n",
time,
bot_tx_tot, bot_tx_abs, bot_ty_tot, bot_ty_abs, bot_ts);
fclose(stresses_file);
}
}
......@@ -6,6 +6,7 @@
#include <blitz/array.h>
#include "TArray.hpp"
#include "NSIntegrator.hpp"
#include "Science.hpp" // Science content
using namespace TArrayn;
using namespace NSIntegrator;
......@@ -166,10 +167,20 @@ class BaseCase {
template <class T> void add_diagnostic(const string str, const T val,
string & header, string & line);
void write_diagnostics(string header, string line, int iter, bool restarting);
void write_plot_times(double time, double clock_time, double comp_duration,
double avg_write_time, int plot_number, bool restarting);
// Generate an automatic grid for unmapped cases
virtual void automatic_grid(double MinX, double MinY, double MinZ,
Array<double,1> *xx=0, Array<double,1> *yy=0, Array<double,1> *zz=0);
// Surface Stresses
void stresses_top(TArrayn::DTArray & u, TArrayn::DTArray & v, TArrayn::DTArray & w,
TArrayn::DTArray & Hprime, TArrayn::DTArray & temp, TArrayn::Grad * gradient_op,
const string * grid_type, const double mu, double time, int itercount, bool restarting);
void stresses_bottom(TArrayn::DTArray & u, TArrayn::DTArray & v, TArrayn::DTArray & w,
TArrayn::DTArray & Hprime, TArrayn::DTArray & temp, TArrayn::Grad * gradient_op,
const string * grid_type, const double mu, double time, int itercount, bool restarting);
};
#include "BaseCase_impl.cc" // Include the implementation of the add_diagnostic template
......
......@@ -5,7 +5,7 @@
void WriteCaseFileSource(void)
{
char* filename;
if ( strcmp(casefilename, "cases/derivatives/derivatives.cpp") ) {
if ( strcmp(casefilename, "cases/derivatives/derivatives.cpp") == 0 ) {
filename = "derivatives.cpp";
} else {
filename = "spinscase.cpp";
......
......@@ -35,6 +35,9 @@ namespace NSIntegrator {
/* Control framework for a full run. At the first timestep(s), take
fractional timesteps to start up. */
// Analyze the initial conditions
usercode->analysis(times[0],us[0],vs[0],ws[0],tracers_now,pressure);
while (times[0] < (fintime - 1e-8*fabs(fintime))) {
// Since we're not done, we need to take a timestep.
......@@ -70,9 +73,6 @@ namespace NSIntegrator {
double desttime = times[0] + the_timestep;
// Analyze the initial conditions
usercode->analysis(times[0],us[0],vs[0],ws[0],tracers_now,pressure);
/* Now, take timesteps until we reach our one-timestep destination*/
bool starting_step = false;
......
This diff is collapsed.
......@@ -34,14 +34,18 @@ void compute_vort_z(TArrayn::DTArray & vortz, TArrayn::DTArray & u, TArrayn::DTA
void compute_vorticity(TArrayn::DTArray & vortx, TArrayn::DTArray & vorty, TArrayn::DTArray & vortz,
TArrayn::DTArray & u, TArrayn::DTArray & v, TArrayn::DTArray & w,
TArrayn::Grad * gradient_op, const string * grid_type);
// Enstrophy density
void enstrophy_density(TArrayn::DTArray & enst, TArrayn::DTArray & u, TArrayn::DTArray & v,
TArrayn::DTArray & w, TArrayn::Grad * gradient_op, const string * grid_type,
const int Nx, const int Ny, const int Nz);
// Viscous dissipation
void dissipation(TArrayn::DTArray & diss, TArrayn::DTArray & u, TArrayn::DTArray & v,
TArrayn::DTArray & w, TArrayn::Grad * gradient_op, const string * grid_type,
const int Nx, const int Ny, const int Nz, const double visco);
// Background Potential Energy (BPE)
void compute_Background_PE(double & BPE_tot, TArrayn::DTArray & rho, int Nx, int Ny, int Nz,
double Lx, double Ly, double Lz, double g, double rho_0, int iter,
void compute_Background_PE(double & BPE_tot, TArrayn::DTArray & rho, TArrayn::DTArray & quad3,
int Nx, int Ny, int Nz, double Lx, double Ly, double Lz, double g, double rho_0, int iter,
bool dimensional_rho = false, bool mapped = false, Array<double,1> hill = Array<double,1>());
// Internal energy converted to BPE
void compute_BPE_from_internal(double & phi_i, TArrayn::DTArray & rho,
......@@ -62,6 +66,27 @@ void find_expansion(const string * grid_type, Transformer::S_EXP * expan, string
// switch trig function
Transformer::S_EXP swap_trig( Transformer::S_EXP the_exp );
// Bottom slope
void bottom_slope(TArrayn::DTArray & Hprime, TArrayn::DTArray & zgrid,
TArrayn::DTArray & temp, TArrayn::Grad * gradient_op,
const string * grid_type, const int Nx, const int Ny, const int Nz);
// Top stresses
void top_stress_x(TArrayn::DTArray & stress_x, TArrayn::DTArray & u,
TArrayn::DTArray & temp, TArrayn::Grad * gradient_op,
const string * grid_type, const int Nz, const double visco);
void top_stress_y(TArrayn::DTArray & stress_y, TArrayn::DTArray & v,
TArrayn::DTArray & temp, TArrayn::Grad * gradient_op,
const string * grid_type, const int Nz, const double visco);
// Bottom stresses
void bottom_stress_x(TArrayn::DTArray & stress_x, TArrayn::DTArray & Hprime,
TArrayn::DTArray & u, TArrayn::DTArray & w, TArrayn::DTArray & temp,
TArrayn::Grad * gradient_op, const string * grid_type, const bool mapped,
const double visco);
void bottom_stress_y(TArrayn::DTArray & stress_y, TArrayn::DTArray & Hprime,
TArrayn::DTArray & v, TArrayn::DTArray & temp,
TArrayn::Grad * gradient_op, const string * grid_type, const bool mapped,
const double visco);
// Equation of state for seawater, polynomial fit from
// Brydon, Sun, Bleck (1999) (JGR)
......
......@@ -243,7 +243,7 @@ class userControl : public BaseCase {
}
// Calculate Enstrophy
/*if ( do_enstrophy ) {
if ( do_enstrophy ) {
enstrophy_density(deriv_var, u, v, w, gradient_op, grid_type,
Nx, Ny, Nz);
double tot_enst = pssum(sum(
......@@ -255,6 +255,7 @@ class userControl : public BaseCase {
if (master())
fprintf(stdout,"Completed the write for enst.%d\n",plotnum);
}
// Calculate Viscous dissipation
if ( do_dissipation ) {
double mu = visco*rho_0; // dynamic viscosity
......@@ -268,7 +269,7 @@ class userControl : public BaseCase {
write_array(deriv_var,"diss",plotnum);
if (master())
fprintf(stdout,"Completed the write for diss.%d\n",plotnum);
}*/
}
}
}
......
......@@ -3,7 +3,7 @@
# Spatial Parameters
Lx = 1.0
Ly = 0.1
Lz = 0.1
Lz = 0.5
Nx = 256
Ny = 1
Nz = 128
......@@ -29,9 +29,22 @@ delta_rho = 0.005
delta_x = 0.02
Lmix = 0.1
# Problem topography parameters
hill_height = 0.1
hill_centre = 0.5
hill_width = 0.05
# Temporal Parameters
final_time = 50
plot_interval = 1
#dt_max = 0.0
# Restart Options
restart = false
restart_time = 0.0
restart_sequence = 0
restart_from_dump = false
compute_time = -1
# Perturbation Parameter
perturb = 1e-3
......@@ -41,9 +54,10 @@ f_cutoff = 0.6
f_order = 2.0
f_strength = 20.0
# Restart Options
restart = false
restart_time = 0.0
restart_sequence = 0
restart_from_dump = false
compute_time = -1
# secondary diagnostics
#compute_enstrophy = true
#compute_dissipation = true
#compute_BPE = true
#compute_internal_to_BPE = true
#compute_stresses_top = false
#compute_stresses_bottom = false
......@@ -13,7 +13,7 @@ SYSTEM_LDFLAGS=
# Compiler flags for debugging
DEBUG_CFLAGS="-g -DBZ_DEBUG"
DEBUG_LDFLAGS=
DEBUG_LDFLAGS="-g -DBZ_DEBUG"
# Compiler flags for optimization
OPTIM_CFLAGS="-O3 -fp-model fast=2"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment