Commit d4bb5300 authored by Christopher Subich's avatar Christopher Subich
Browse files

Merge remote-tracking branch 'david/dump'

parents 355ad2b3 c6a6c09a
......@@ -109,6 +109,12 @@ double BaseCase::get_visco() const {
double BaseCase::get_diffusivity(int t) const {
return 0;
}
double BaseCase::get_rot_f() const {
return 0;
}
int BaseCase::get_restart_sequence() const {
return 0;
}
/* Initialization */
......@@ -172,8 +178,9 @@ 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(split_range(size_x())), yy(size_y()), zz(size_z());
void BaseCase::automatic_grid(double MinX, double MinY, double MinZ,
Array<double,1> * xx=0, Array<double,1> * yy=0, Array<double,1> * zz = 0){
//Array<double,1> xx(split_range(size_x())), yy(size_y()), zz(size_z());
Array<double,3> grid(alloc_lbound(size_x(),size_y(),size_z()),
alloc_extent(size_x(),size_y(),size_z()),
alloc_storage(size_x(),size_y(),size_z()));
......@@ -183,30 +190,161 @@ void BaseCase::automatic_grid(double MinX,double MinY,double MinZ) {
// Generate 1D arrays
if (type_x() == NO_SLIP) {
xx = MinX+length_x()*(0.5+0.5*cos(M_PI*ii/(size_x()-1)));
*xx = MinX+length_x()*(0.5+0.5*cos(M_PI*ii/(size_x()-1)));
} else {
xx = MinX + length_x()*(ii+0.5)/size_x();
*xx = MinX + length_x()*(ii+0.5)/size_x();
}
yy = MinY + length_y()*(ii+0.5)/size_y();
*yy = MinY + length_y()*(ii+0.5)/size_y();
if (type_z() == NO_SLIP) {
zz = MinZ+length_z()*(0.5+0.5*cos(M_PI*ii/(size_z()-1)));
*zz = MinZ+length_z()*(0.5+0.5*cos(M_PI*ii/(size_z()-1)));
} else {
zz = MinZ + length_z()*(0.5+ii)/size_z();
*zz = MinZ + length_z()*(0.5+ii)/size_z();
}
// Write grid/reader
grid = xx(ii) + 0*jj + 0*kk;
grid = (*xx)(ii) + 0*jj + 0*kk;
write_array(grid,"xgrid");
write_reader(grid,"xgrid",false);
if (size_y() > 1) {
grid = 0*ii + yy(jj) + 0*kk;
grid = 0*ii + (*yy)(jj) + 0*kk;
write_array(grid,"ygrid");
write_reader(grid,"ygrid",false);
}
grid = 0*ii + 0*jj + zz(kk);
grid = 0*ii + 0*jj + (*zz)(kk);
write_array(grid,"zgrid");
write_reader(grid,"zgrid",false);
}
/* Read velocities from regular output */
void BaseCase::init_vels_restart(DTArray & u, DTArray & v, DTArray & w){
/* Restarting, so build the proper filenames and load the data into u, v, w */
char filename[100];
/* u */
snprintf(filename,100,"u.%d",get_restart_sequence());
if (master()) fprintf(stdout,"Reading u from %s\n",filename);
read_array(u,filename,size_x(),size_y(),size_z());
/* v, only necessary if this is an actual 3D run or if
rotation is noNzero */
if (size_y() > 1 || get_rot_f() != 0) {
snprintf(filename,100,"v.%d",get_restart_sequence());
if (master()) fprintf(stdout,"Reading v from %s\n",filename);
read_array(v,filename,size_x(),size_y(),size_z());
}
/* w */
snprintf(filename,100,"w.%d",get_restart_sequence());
if (master()) fprintf(stdout,"Reading w from %s\n",filename);
read_array(w,filename,size_x(),size_y(),size_z());
return;
}
/* Read velocities from dump output */
void BaseCase::init_vels_dump(DTArray & u, DTArray & v, DTArray & w){
/* Restarting, so build the proper filenames and load the data into u, v, w */
/* u */
if (master()) fprintf(stdout,"Reading u from u.dump\n");
read_array(u,"u.dump",size_x(),size_y(),size_z());
/* v, only necessary if this is an actual 3D run or if
rotation is noNzero */
if (size_y() > 1 || get_rot_f() != 0) {
if (master()) fprintf(stdout,"Reading v from v.dump\n");
read_array(v,"v.dump",size_x(),size_y(),size_z());
}
/* w */
if (master()) fprintf(stdout,"Reading w from w.dump\n");
read_array(w,"w.dump",size_x(),size_y(),size_z());
return;
}
/* Read field from regular output */
void BaseCase::init_tracer_restart(const std::string & field, DTArray & the_tracer){
/* Restarting, so build the proper filenames and load the data */
char filename[100];
snprintf(filename,100,"%s.%d",field.c_str(),get_restart_sequence());
if (master()) fprintf(stdout,"Reading %s from %s\n",field.c_str(),filename);
read_array(the_tracer,filename,size_x(),size_y(),size_z());
return;
}
/* Read field from dump output */
void BaseCase::init_tracer_dump(const std::string & field, DTArray & the_tracer){
/* Restarting, so build the proper filenames and load the data */
char filename[100];
snprintf(filename,100,"%s.dump",field.c_str());
if (master()) fprintf(stdout,"Reading %s from %s\n",field.c_str(),filename);
read_array(the_tracer,filename,size_x(),size_y(),size_z());
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,
DTArray & u, DTArray & v, DTArray & w, vector<DTArray *> & tracer){
int do_dump = 0;
if (master()) {
double total_run_time = clock_time - real_start_time;
// check if close to end of compute time
if ((compute_time > 0) && (compute_time - total_run_time < 3*avg_write_time)){
do_dump = 1; // true
}
}
MPI_Bcast(&do_dump, 1, MPI_INT, 0, MPI_COMM_WORLD);
if (do_dump == 1) {
if (master()){
fprintf(stdout,"Too close to final time, dumping!\n");
}
write_variables(u, v, w, tracer);
// Write the dump time to a text file for restart purposes
if (master()){
FILE * dump_file;
dump_file = fopen("dump_time.txt","w");
assert(dump_file);
fprintf(dump_file,"The dump time was:\n%.12g\n", sim_time);
fprintf(dump_file,"The dump index was:\n%d\n", plot_number);
fclose(dump_file);
}
// Die gracefully
MPI_Finalize(); exit(0);
}
}
/* Change dump log file for successful completion*/
void BaseCase::successful_dump(int plot_number, double final_time, double plot_interval){
if (master() && (plot_number == final_time/plot_interval)){
// Write the dump time to a text file for restart purposes
FILE * dump_file;
dump_file = fopen("dump_time.txt","w");
assert(dump_file);
fprintf(dump_file,"The dump 'time' was:\n%.12g\n", 2*final_time);
fprintf(dump_file,"The dump index was:\n%d\n", plot_number);
fclose(dump_file);
}
}
......@@ -79,6 +79,8 @@ class BaseCase {
/* Physical parameters */
virtual double get_visco() const; // Physical viscosity
virtual double get_diffusivity(int tracernum) const; // Diffusivity
virtual double get_rot_f() const; // Physical rotation rate
virtual int get_restart_sequence() const; // restart sequence
/* Initialization */
virtual double init_time() const; // Initialization time
......@@ -86,11 +88,28 @@ class BaseCase {
virtual void init_vels(DTArray & u, DTArray & v, DTArray & w) {
assert(0 && "init_vels not implemented");
abort();};
// Initialize velocities and tracer
virtual void init_vels_restart(DTArray & u, DTArray & v, DTArray & w);
virtual void init_vels_dump(DTArray & u, DTArray & v, DTArray & w);
virtual void init_tracer_restart(const std::string & field, DTArray & the_tracer);
virtual void init_tracer_dump(const std::string & field, DTArray & the_tracer);
virtual void init_tracer(int t_num, DTArray & tracer) {
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,
DTArray & u, DTArray & v, DTArray & w, vector<DTArray *> & tracer);
virtual void successful_dump(int plot_number, double final_time, double plot_interval);
virtual void write_variables(DTArray & u, DTArray & v, DTArray & w, vector<DTArray *> & tracer) {
assert(0 && "write_variables not defined");
abort();}; //
/* Numerical checks */
virtual double check_timestep(double step, double now);
......@@ -140,7 +159,8 @@ class BaseCase {
abort();}; // Single-tracer analysis
// Generate an automatic grid for unmapped cases
virtual void automatic_grid(double MinX,double MinY,double MinZ);
virtual void automatic_grid(double MinX, double MinY, double MinZ,
Array<double,1> *xx, Array<double,1> *yy, Array<double,1> *zz);
};
extern template class FluidEvolve<BaseCase>;
......
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