Commit 2e379eb9 authored by Ben Storer's avatar Ben Storer
Browse files

Adding a bunch of stuff

- Added 1D and 2D outputs
- Added parallel writing and reading
parent 1ac02e05
......@@ -180,7 +180,7 @@ void BaseCase::analysis(double t, DTArray & u, DTArray & v, DTArray & w,
void BaseCase::automatic_grid(double MinX, double MinY, double MinZ,
Array<double,1> * xx, Array<double,1> * yy, Array<double,1> * zz){
//Array<double,1> xx(split_range(size_x())), yy(size_y()), zz(size_z());
bool xxa = false, yya = false, zza = false;
if (!xx) {
xxa = true; // Delete xx when returning
......@@ -216,17 +216,17 @@ void BaseCase::automatic_grid(double MinX, double MinY, double MinZ,
// Write grid/reader
grid = (*xx)(ii) + 0*jj + 0*kk;
write_array(grid,"xgrid");
write_array_old(grid,"xgrid");
write_reader(grid,"xgrid",false);
if (size_y() > 1) {
grid = 0*ii + (*yy)(jj) + 0*kk;
write_array(grid,"ygrid");
write_array_old(grid,"ygrid");
write_reader(grid,"ygrid",false);
}
grid = 0*ii + 0*jj + (*zz)(kk);
write_array(grid,"zgrid");
write_array_old(grid,"zgrid");
write_reader(grid,"zgrid",false);
// Clean up
......@@ -304,20 +304,6 @@ void BaseCase::init_tracer_dump(const std::string & field, DTArray & the_tracer)
return;
}
/* write out vertical chain of data */
void BaseCase::write_chain(const char *filename, DTArray & val, int Iout, int Jout, double time) {
FILE *fid=fopen(filename,"a");
if (fid == NULL) {
fprintf(stderr,"Unable to open %s for writing\n",filename);
MPI_Finalize(); exit(1);
}
fprintf(fid,"%g",time);
for (int ki=0; ki<size_z(); ki++) fprintf(fid," %g",val(Iout,Jout,ki));
fprintf(fid,"\n");
fclose(fid);
}
/* Check and dump */
void BaseCase::check_and_dump(double clock_time, double real_start_time,
double compute_time, double sim_time, double avg_write_time, int plot_number,
......
......@@ -98,8 +98,6 @@ class BaseCase {
assert(0 && "init_tracer not implemented");
abort();}; // single-tracer
/* Write vertical chain */
virtual void write_chain(const char *filename, DTArray & val, int Iout, int Jout, double time);
/* dumping functions */
virtual void check_and_dump(double clock_time, double real_start_time,
double compute_time, double sim_time, double avg_write_time, int plot_number,
......
......@@ -9,6 +9,7 @@
#include "Split_reader.hpp"
#include "T_util.hpp"
#include "Parformer.hpp"
#include <stdlib.h>
// Marek's Overturning Diagnostic
......@@ -273,29 +274,285 @@ void vorticity(TArrayn::DTArray & u, TArrayn::DTArray & v,
return;
}
void dudx(TArrayn::DTArray & u, TArrayn::DTArray * & out,
double Lx, double Ly, double Lz,
int szx, int szy, int szz,
NSIntegrator::DIMTYPE DIM_X, NSIntegrator::DIMTYPE DIM_Y,
NSIntegrator::DIMTYPE DIM_Z) {
static Transformer::Trans1D trans_x(szx,szy,szz,firstDim,
(DIM_X == PERIODIC ? FOURIER : REAL)),
trans_y(szx,szy,szz,secondDim,
(DIM_Y == PERIODIC ? FOURIER : REAL)),
trans_z (szx,szy,szz,thirdDim,
(DIM_Z == PERIODIC ? FOURIER : REAL));
static blitz::TinyVector<int,3>
local_lbounds(alloc_lbound(szx,szy,szz)),
local_extent(alloc_extent(szx,szy,szz));
static blitz::GeneralArrayStorage<3>
local_storage(alloc_storage(szx,szy,szz));
static DTArray temp(local_lbounds,local_extent,local_storage);
if (DIM_X == PERIODIC) {
deriv_fft(u,trans_x,temp);
temp *= 2*M_PI/Lx;
} else if (DIM_X == FREE_SLIP) {
deriv_dst(u,trans_x,temp);
temp *= M_PI/Lx;
} else {
assert(DIM_X == NO_SLIP);
deriv_cheb(u,trans_x,temp);
temp *= -2/Lx;
}
out = &temp;
return;
}
void dudy(TArrayn::DTArray & u, TArrayn::DTArray * & out,
double Lx, double Ly, double Lz,
int szx, int szy, int szz,
NSIntegrator::DIMTYPE DIM_X, NSIntegrator::DIMTYPE DIM_Y,
NSIntegrator::DIMTYPE DIM_Z) {
static Transformer::Trans1D trans_x(szx,szy,szz,firstDim,
(DIM_X == PERIODIC ? FOURIER : REAL)),
trans_y(szx,szy,szz,secondDim,
(DIM_Y == PERIODIC ? FOURIER : REAL)),
trans_z (szx,szy,szz,thirdDim,
(DIM_Z == PERIODIC ? FOURIER : REAL));
static blitz::TinyVector<int,3>
local_lbounds(alloc_lbound(szx,szy,szz)),
local_extent(alloc_extent(szx,szy,szz));
static blitz::GeneralArrayStorage<3>
local_storage(alloc_storage(szx,szy,szz));
static DTArray temp(local_lbounds,local_extent,local_storage);
if (DIM_Y == PERIODIC) {
deriv_fft(u,trans_y,temp);
temp *= 2*M_PI/Ly;
} else if (DIM_Y == FREE_SLIP) {
deriv_dct(u,trans_y,temp);
temp *= M_PI/Ly;
} else {
assert(DIM_Y == NO_SLIP);
deriv_cheb(u,trans_y,temp);
temp *= -2/Ly;
}
out = &temp;
return;
}
void dudz(TArrayn::DTArray & u, TArrayn::DTArray * & out,
double Lx, double Ly, double Lz,
int szx, int szy, int szz,
NSIntegrator::DIMTYPE DIM_X, NSIntegrator::DIMTYPE DIM_Y,
NSIntegrator::DIMTYPE DIM_Z) {
static Transformer::Trans1D trans_x(szx,szy,szz,firstDim,
(DIM_X == PERIODIC ? FOURIER : REAL)),
trans_y(szx,szy,szz,secondDim,
(DIM_Y == PERIODIC ? FOURIER : REAL)),
trans_z (szx,szy,szz,thirdDim,
(DIM_Z == PERIODIC ? FOURIER : REAL));
static blitz::TinyVector<int,3>
local_lbounds(alloc_lbound(szx,szy,szz)),
local_extent(alloc_extent(szx,szy,szz));
static blitz::GeneralArrayStorage<3>
local_storage(alloc_storage(szx,szy,szz));
static DTArray temp(local_lbounds,local_extent,local_storage);
if (DIM_Z == PERIODIC) {
deriv_fft(u,trans_z,temp);
temp *= 2*M_PI/Lz;
} else if (DIM_Z == FREE_SLIP) {
deriv_dct(u,trans_z,temp);
temp *= M_PI/Lz;
} else {
assert(DIM_Z == NO_SLIP);
deriv_cheb(u,trans_z,temp);
temp *= -2/Lz;
}
out = &temp;
return;
}
void ertel_pv(TArrayn::DTArray & u, TArrayn::DTArray & v,
TArrayn::DTArray & w, TArrayn::DTArray & rho,
TArrayn::DTArray * & e_pv, double f0, double N0,
double Lx, double Ly, double Lz,
int szx, int szy, int szz,
NSIntegrator::DIMTYPE DIM_X, NSIntegrator::DIMTYPE DIM_Y,
NSIntegrator::DIMTYPE DIM_Z) {
static int Nx = 0, Ny = 0, Nz = 0;
static Transformer::Trans1D trans_x(szx,szy,szz,firstDim,
(DIM_X == PERIODIC ? FOURIER : REAL)),
trans_y(szx,szy,szz,secondDim,
(DIM_Y == PERIODIC ? FOURIER : REAL)),
trans_z (szx,szy,szz,thirdDim,
(DIM_Z == PERIODIC ? FOURIER : REAL));
static blitz::TinyVector<int,3>
local_lbounds(alloc_lbound(szx,szy,szz)),
local_extent(alloc_extent(szx,szy,szz));
static blitz::GeneralArrayStorage<3>
local_storage(alloc_storage(szx,szy,szz));
static DTArray temp_pv(local_lbounds,local_extent,local_storage),
temp_a(local_lbounds,local_extent,local_storage),
temp_b(local_lbounds,local_extent,local_storage);
/* Initialization */
if (Nx == 0 || Ny == 0 || Nz == 0) {
Nx = szx; Ny = szy; Nz = szz;
}
assert (Nx == szx && Ny == szy && Nz == szz);
/* x-vorticity is w_y - v_z */
/* b_x*(w_y - v_z) */
temp_pv = 0;
if (szx > 1) { // b_x
if (DIM_X == PERIODIC) {
deriv_fft(rho,trans_x,temp_b);
temp_b *= 2*M_PI/Lx;
} else if (DIM_X == FREE_SLIP) {
deriv_dct(rho,trans_x,temp_b);
temp_b *= M_PI/Lx;
} else {
assert(DIM_X == NO_SLIP);
deriv_cheb(rho,trans_x,temp_b);
temp_b *= -2/Lx;
}
}
if (szy > 1) { // w_y
if (DIM_X == PERIODIC) {
deriv_fft(w,trans_y,temp_a);
temp_pv += temp_a*temp_b*(2*M_PI/Ly);
} else if (DIM_X == FREE_SLIP) {
deriv_dct(w,trans_y,temp_a);
temp_pv += temp_a*temp_b*(M_PI/Ly);
} else {
assert(DIM_X == NO_SLIP);
deriv_cheb(w,trans_y,temp_a);
temp_pv += temp_a*temp_b*(-2/Ly);
}
}
if (szz > 1) { // v_z
if (DIM_Z == PERIODIC) {
deriv_fft(v,trans_z,temp_a);
temp_pv -= temp_a*temp_b*(2*M_PI/Lz);
} else if (DIM_Z == FREE_SLIP) {
deriv_dct(v,trans_z,temp_a);
temp_pv -= temp_a*temp_b*(M_PI/Lz);
} else {
assert(DIM_Z == NO_SLIP);
deriv_cheb(v,trans_z,temp_a);
temp_pv -= temp_a*temp_b*(-2/Lz);
}
}
// y-vorticity is u_z - w_x
/* b_y*(u_z - w_x) */
if (szy > 1) { // b_y
if (DIM_Y == PERIODIC) {
deriv_fft(rho,trans_y,temp_b);
temp_b *= 2*M_PI/Ly;
} else if (DIM_Y == FREE_SLIP) {
deriv_dct(rho,trans_y,temp_b);
temp_b *= M_PI/Ly;
} else {
assert(DIM_Y == NO_SLIP);
deriv_cheb(rho,trans_y,temp_b);
temp_b *= -2/Ly;
}
}
if (szz > 1) { // u_z
if (DIM_Z == PERIODIC) {
deriv_fft(u,trans_z,temp_a);
temp_pv += temp_a*temp_b*(2*M_PI/Lz);
} else if (DIM_Z == FREE_SLIP) {
deriv_dct(u,trans_z,temp_a);
temp_pv += temp_a*temp_b*(M_PI/Lz);
} else {
assert(DIM_Z == NO_SLIP);
deriv_cheb(u,trans_z,temp_a);
temp_pv += temp_a*temp_b*(-2/Lz);
}
}
if (szx > 1) { // w_x
if (DIM_X == PERIODIC) {
deriv_fft(w,trans_x,temp_a);
temp_pv -= temp_a*temp_b*(2*M_PI/Lx);
} else if (DIM_X == FREE_SLIP) {
deriv_dct(w,trans_x,temp_a);
temp_pv -= temp_a*temp_b*(M_PI/Lx);
} else {
assert(DIM_X == NO_SLIP);
deriv_cheb(w,trans_x,temp_a);
temp_pv -= temp_a*temp_b*(-2/Lx);
}
}
// And finally, vort_z is v_x - u_y
// b_z*(v_x - u_y)
if (szz > 1) { // b_z
if (DIM_Z == PERIODIC) {
deriv_fft(rho,trans_z,temp_b);
temp_b *= 2*M_PI/Lz;
} else if (DIM_Z == FREE_SLIP) {
deriv_dct(rho,trans_z,temp_b);
temp_b *= M_PI/Lz;
} else {
assert(DIM_Z == NO_SLIP);
deriv_cheb(rho,trans_z,temp_b);
temp_b *= -2/Lz;
}
temp_b += N0*N0;
temp_pv += f0*temp_b;
}
if (szx > 1) { // v_x
if (DIM_X == PERIODIC) {
deriv_fft(v,trans_x,temp_a);
temp_pv += temp_a*temp_b*(2*M_PI/Lx);
} else if (DIM_X == FREE_SLIP) {
deriv_dct(v,trans_x,temp_a);
temp_pv += temp_a*temp_b*(M_PI/Lx);
} else {
assert(DIM_X == NO_SLIP);
deriv_cheb(v,trans_x,temp_a);
temp_pv += temp_a*temp_b*(-2/Lx);
}
}
if (szy > 1) { // u_y
if (DIM_Y == PERIODIC) {
deriv_fft(u,trans_y,temp_a);
temp_pv -= temp_a*temp_b*(2*M_PI/Ly);
} else if (DIM_Y == FREE_SLIP) {
deriv_dct(u,trans_y,temp_a);
temp_pv -= temp_a*temp_b*(M_PI/Ly);
} else {
assert(DIM_Y == NO_SLIP);
deriv_cheb(u,trans_y,temp_a);
temp_pv -= temp_a*temp_b*(-2/Ly);
}
}
e_pv = &temp_pv;
return;
}
// Global arrays to store quadrature weights
Array<double,1> _quadw_x, _quadw_y, _quadw_z;
// Compute quadrature weights
void compute_quadweights(int szx, int szy, int szz,
double Lx, double Ly, double Lz,
NSIntegrator::DIMTYPE DIM_X, NSIntegrator::DIMTYPE DIM_Y,
NSIntegrator::DIMTYPE DIM_Z) {
_quadw_x.resize(split_range(szx));
_quadw_y.resize(szy); _quadw_z.resize(szz);
if (DIM_X == NO_SLIP) {
blitz::firstIndex ii;
_quadw_x = 1;
for (int k = 1; k <= (szx-2)/2; k++) {
// From Trefethen, Spectral Methods in MATLAB
// clenshaw-curtis quadrature weights
_quadw_x -= 2*cos(2*k*M_PI*ii/(szx-1))/(4*k*k-1);
}
if ((szx%2))
_quadw_x -= cos(M_PI*ii)/((szx-1)*(szx-1)-1);
_quadw_x = 2*_quadw_x/(szx-1);
if (_quadw_x.lbound(firstDim) == 0) {
_quadw_x(0) = 1.0/(szx-1)/(szx-1);
double Lx, double Ly, double Lz,
NSIntegrator::DIMTYPE DIM_X, NSIntegrator::DIMTYPE DIM_Y,
NSIntegrator::DIMTYPE DIM_Z) {
_quadw_x.resize(split_range(szx));
_quadw_y.resize(szy); _quadw_z.resize(szz);
if (DIM_X == NO_SLIP) {
blitz::firstIndex ii;
_quadw_x = 1;
for (int k = 1; k <= (szx-2)/2; k++) {
// From Trefethen, Spectral Methods in MATLAB
// clenshaw-curtis quadrature weights
_quadw_x -= 2*cos(2*k*M_PI*ii/(szx-1))/(4*k*k-1);
}
if ((szx%2))
_quadw_x -= cos(M_PI*ii)/((szx-1)*(szx-1)-1);
_quadw_x = 2*_quadw_x/(szx-1);
if (_quadw_x.lbound(firstDim) == 0) {
_quadw_x(0) = 1.0/(szx-1)/(szx-1);
}
if (_quadw_x.ubound(firstDim) == (szx-1)) {
_quadw_x(szx-1) = 1.0/(szx-1)/(szx-1);
......@@ -361,3 +618,4 @@ const blitz::Array<double,1> * get_quad_z() {
}
return &_quadw_z;
}
......@@ -32,6 +32,35 @@ void vorticity(TArrayn::DTArray & u, TArrayn::DTArray & v,
NSIntegrator::DIMTYPE DIM_X, NSIntegrator::DIMTYPE DIM_Y,
NSIntegrator::DIMTYPE DIM_Z);
/* Compute dudx */
void dudx(TArrayn::DTArray & u, TArrayn::DTArray * & out,
double Lx, double Ly, double Lz,
int szx, int szy, int szz,
NSIntegrator::DIMTYPE DIM_X, NSIntegrator::DIMTYPE DIM_Y,
NSIntegrator::DIMTYPE DIM_Z);
/* Compute dudy */
void dudy(TArrayn::DTArray & u, TArrayn::DTArray * & out,
double Lx, double Ly, double Lz,
int szx, int szy, int szz,
NSIntegrator::DIMTYPE DIM_X, NSIntegrator::DIMTYPE DIM_Y,
NSIntegrator::DIMTYPE DIM_Z);
/* Compute dudz */
void dudz(TArrayn::DTArray & u, TArrayn::DTArray * & out,
double Lx, double Ly, double Lz,
int szx, int szy, int szz,
NSIntegrator::DIMTYPE DIM_X, NSIntegrator::DIMTYPE DIM_Y,
NSIntegrator::DIMTYPE DIM_Z);
/* Compute ertel pv */
void ertel_pv(TArrayn::DTArray & u, TArrayn::DTArray & v,
TArrayn::DTArray & w, TArrayn::DTArray & rho,
TArrayn::DTArray * & e_pv, double f0, double N0,
double Lx, double Ly, double Lz,
int szx, int szy, int szz,
NSIntegrator::DIMTYPE DIM_X, NSIntegrator::DIMTYPE DIM_Y,
NSIntegrator::DIMTYPE DIM_Z);
// Quadrature weights
void compute_quadweights(int szx, int szy, int szz,
......
This diff is collapsed.
......@@ -9,37 +9,87 @@
namespace TArrayn {
using namespace Transformer;
/* Real-to-complex Fourier derivative */
void deriv_fft(DTArray & source, Trans1D & tform, blitz::Array<double, 3> & dest);
/* Cosine derivative (DCT10) */
void deriv_dct(DTArray & source, Trans1D & tform, blitz::Array<double, 3> & dest);
/* Sine derivative (DST10), for symmetry with cosine */
void deriv_dst(DTArray & source, Trans1D & tform, blitz::Array<double, 3> & dest);
/* Chebyshev derivative */
void deriv_cheb(DTArray & source, Trans1D & tform, blitz::Array<double, 3> & dest);
/* Spectral filtering, with sensible defaults */
void filter3(DTArray & source, TransWrapper & tform,
S_EXP dim1_type, S_EXP dim2_type, S_EXP dim3_type,
double cutoff=0.7, double order = 4, double strength = 20);
/* Array-to-file writer, for MATLAB input */
void write_array(blitz::Array<double, 3> const & ar, const std::string basename,
int seq_num = -1, MPI_Comm c = MPI_COMM_WORLD);
/* Create .m matlab file to read a written array in as a proper MATLAB array
with the same semanticcs */
void write_reader(blitz::Array<double, 3> const & ar, const std::string basename,
bool seq = false, MPI_Comm c = MPI_COMM_WORLD);
/* Read from an array written via write_array to an appropriate (subset)
processor-local array. Required for restarting. */
void read_array(blitz::Array<double,3> & ar, const char * filename,
int size_x, int size_y, int size_z, MPI_Comm c = MPI_COMM_WORLD);
using namespace Transformer;
/* Real-to-complex Fourier derivative */
void deriv_fft(DTArray & source, Trans1D & tform, blitz::Array<double, 3> & dest);
/* Cosine derivative (DCT10) */
void deriv_dct(DTArray & source, Trans1D & tform, blitz::Array<double, 3> & dest);
/* Sine derivative (DST10), for symmetry with cosine */
void deriv_dst(DTArray & source, Trans1D & tform, blitz::Array<double, 3> & dest);
/* Chebyshev derivative */
void deriv_cheb(DTArray & source, Trans1D & tform, blitz::Array<double, 3> & dest);
/* Spectral filtering, with sensible defaults */
void filter3(DTArray & source, TransWrapper & tform,
S_EXP dim1_type, S_EXP dim2_type, S_EXP dim3_type,
double cutoff=0.7, double order = 4, double strength = 20);
/* Array-to-file writer, for MATLAB input */
void write_array_old(blitz::Array<double, 3> const & ar, const std::string basename,
int seq_num = -1, MPI_Comm c = MPI_COMM_WORLD);
/* Create .m matlab file to read a written array in as a proper MATLAB array
with the same semanticcs */
void write_reader(blitz::Array<double, 3> const & ar, const std::string basename,
bool seq = false, MPI_Comm c = MPI_COMM_WORLD);
/* Read from an array written via write_array to an appropriate (subset)
processor-local array. Required for restarting. */
void read_array_old(blitz::Array<double,3> & ar, const char * filename,
int size_x, int size_y, int size_z, MPI_Comm c = MPI_COMM_WORLD);
void convert_index_2(int n, int Nx, int Ny, int Nz, int * I, int * J, int * K);
// Parallel version of read_array
void read_array(TArrayn::DTArray & ar, const char * filename,
int size_x, int size_y, int size_z, MPI_Comm c = MPI_COMM_WORLD);
// Parallel version of write_array
void write_array(TArrayn::DTArray & ar, char * basename,
int seq_num = -1, MPI_Comm c = MPI_COMM_WORLD);
// Initialize temporary files for chains
void initialize_chain_tmps(char* varname, MPI_File ** files,
double *** chain_coords, int * num_chains, MPI_Comm = MPI_COMM_WORLD);
// Initialize files for chains
void initialize_chain_finals(char* varname, MPI_File ** files,
double *** chain_coords, int * num_chains, MPI_Comm = MPI_COMM_WORLD);
// Write data to chain temporary files
void write_chains_2(DTArray & var, MPI_File ** files,
double *** chain_coords, int * num_chains,
int Nx, int Ny, int Nz, int chain_count,
double * x_chain_data_buffer, double * y_chain_data_buffer,
double * z_chain_data_buffer, MPI_Comm c = MPI_COMM_WORLD);
// Stitch temporary files into final files
void stitch_chains_2(char* varname, MPI_File ** files_from, MPI_File ** files_to, int * num_chains,
int Nx, int Ny, int Nz, double *** chain_coords, int chain_write_count,
int prev_chain_write, int lb, int ub, MPI_Comm c = MPI_COMM_WORLD);
// Initialize temporary files for slicess
void initialize_slice_tmps(char* varname, MPI_File ** files,
double ** slice_coords, int * num_slices, MPI_Comm c = MPI_COMM_WORLD);
// Initialize files for slices
void initialize_slice_finals(char* varname, MPI_File ** files,
double ** slice_coords, int * num_slices, MPI_Comm c = MPI_COMM_WORLD);
// Write data to slice temporary files
void write_slices_2(DTArray & var, MPI_File ** files,
double ** slice_coords, int * num_slices,
int Nx, int Ny, int Nz, int slice_count, MPI_Comm c = MPI_COMM_WORLD);
// Stitch temporary files into final files
void stitch_slices_2(char* varname, MPI_File ** files_from, MPI_File ** files_to, int * num_slices,
int Nx, int Ny, int Nz, double ** slice_coords, int slice_write_count,
int prev_slice_write, int lb, int ub, MPI_Comm c = MPI_COMM_WORLD);
} // end namespace
#endif
This diff is collapsed.
Supports Markdown
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