/* This file is part of LPIC++, a particle-in-cell code for simulating the interaction of laser light with plasma. Copyright (C) 2002 Andreas Kemp Copyright (C) 1994-1997 Roland Lichters LPIC++ is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ ////////////////////////////////////////////////////////////////////////////////////////// // // postprocessor for lpic++ // ////////////////////////////////////////////////////////////////////////////////////////// // changes by A.Kemp, 2002 denoted by ## #include spacetime::spacetime( parameter &p ) : input(p), ft( input.periods_x, input.cells_per_wl, 1 ), ft2d( input.Q_kw, input.periods_t, input.steps_per_period, 1, input.periods_x, input.cells_per_wl, 1 ) { sprintf( errname, "%s/error", p.output_path ); static error_handler bob("spacetime::Constructor",errname); input_path = new char [ filename_size ]; strcpy(input_path,p.file_path); output_path = new char [ filename_size ]; strcpy(output_path,p.output_path); } ////////////////////////////////////////////////////////////////////////////////////////// input_spacetime::input_spacetime( parameter &p ) : rf() { strcpy( errname, p.errname ); static error_handler bob("input_spacetime::Constructor",errname); char fname[filename_size]; rf.openinput( p.read_filename ); t_start = atoi( rf.setget( "&spacetime", "t_start" ) ); t_stop = atoi( rf.setget( "&spacetime", "t_stop" ) ); x_start = atof( rf.setget( "&spacetime", "x_start" ) ); x_stop = atof( rf.setget( "&spacetime", "x_stop" ) ); x_offset = atof( rf.setget( "&spacetime", "x_offset" ) ); periods_x = (int) floor( x_stop - x_start + 0.5 ); periods_t = (int) floor( t_stop - t_start + 0.5 ); average = atoi( rf.setget( "&spacetime", "smooth" ) ); size = atoi( rf.setget( "&spacetime", "imagesize" ) ); contour_1 = atof( rf.setget( "&spacetime", "contour_1" ) ); contour_2 = atof( rf.setget( "&spacetime", "contour_2" ) ); contour_3 = atof( rf.setget( "&spacetime", "contour_3" ) ); Q_kw = atoi( rf.setget( "&spacetime", "Q_kw" ) ); Q_kt = atoi( rf.setget( "&spacetime", "Q_kt" ) ); Q_de = atoi( rf.setget( "&spacetime", "Q_de" ) ); Q_di = atoi( rf.setget( "&spacetime", "Q_di" ) ); Q_jx = atoi( rf.setget( "&spacetime", "Q_jx" ) ); Q_jy = atoi( rf.setget( "&spacetime", "Q_jy" ) ); Q_jz = atoi( rf.setget( "&spacetime", "Q_jz" ) ); Q_ex = atoi( rf.setget( "&spacetime", "Q_ex" ) ); Q_ey = atoi( rf.setget( "&spacetime", "Q_ey" ) ); Q_ez = atoi( rf.setget( "&spacetime", "Q_ez" ) ); // Q_bx = atoi( rf.setget( "&spacetime", "Q_bx" ) ); Q_bx = 0; // ## Q_by = atoi( rf.setget( "&spacetime", "Q_by" ) ); Q_bz = atoi( rf.setget( "&spacetime", "Q_bz" ) ); Q_edens = atoi( rf.setget( "&spacetime", "Q_edens" ) ); Q_de_fi = atoi( rf.setget( "&spacetime", "Q_de_fi" ) ); Q_de_ii = atoi( rf.setget( "&spacetime", "Q_de_ii" ) ); C_kw = atof( rf.setget( "&spacetime", "C_kw" ) ); C_kt = atof( rf.setget( "&spacetime", "C_kt" ) ); K_cut = atof( rf.setget( "&spacetime", "K_cut" ) ); W_cut = atof( rf.setget( "&spacetime", "W_cut" ) ); C_de = atof( rf.setget( "&spacetime", "C_de" ) ); C_di = atof( rf.setget( "&spacetime", "C_di" ) ); C_jx = atof( rf.setget( "&spacetime", "C_jx" ) ); C_jy = atof( rf.setget( "&spacetime", "C_jy" ) ); C_jz = atof( rf.setget( "&spacetime", "C_jz" ) ); C_ex = atof( rf.setget( "&spacetime", "C_ex" ) ); C_ey = atof( rf.setget( "&spacetime", "C_ey" ) ); C_ez = atof( rf.setget( "&spacetime", "C_ez" ) ); // C_bx = atof( rf.setget( "&spacetime", "C_bx" ) ); C_bx = 0; // ## C_by = atof( rf.setget( "&spacetime", "C_by" ) ); C_bz = atof( rf.setget( "&spacetime", "C_bz" ) ); C_edens = atof( rf.setget( "&spacetime", "C_edens" ) ); C_de_fi = atof( rf.setget( "&spacetime", "C_de_fi" ) ); C_de_ii = atof( rf.setget( "&spacetime", "C_de_ii" ) ); rf.closeinput(); sprintf( fname, "%s/lpic.steps", p.file_path ); rf.openinput( fname ); cells_per_wl = atoi( rf.getinput( "spl" ) ); steps_per_period = atoi( rf.getinput( "spp" ) ); rf.closeinput(); bob.message("parameter read"); save(p); } ////////////////////////////////////////////////////////////////////////////////////////// void input_spacetime::save( parameter &p ) { static error_handler bob("input_spacetime::save",errname); ofstream outfile; outfile.open(p.save_path_name,ios::app); outfile << "spacetime" << endl; outfile << "------------------------------------------------------------------" << endl; outfile << "t_start : " << t_start << endl; outfile << "t_stop : " << t_stop << endl; outfile << "periods_t : " << periods_t << endl; outfile << "steps_pp : " << steps_per_period << endl; outfile << "x_start : " << x_start << endl; outfile << "x_stop : " << x_stop << endl; outfile << "periods_x : " << periods_x << endl; outfile << "cells_per_wl : " << cells_per_wl << endl; outfile << "x_offset : " << x_offset << endl; outfile << "average : " << average << endl; outfile << "size : " << size << endl; outfile << "contour_1 : " << contour_1 << endl; outfile << "contour_2 : " << contour_2 << endl; outfile << "contour_3 : " << contour_3 << endl; outfile.setf(ios::left); outfile << "\n kw kt de di jx jy jz ex ey ez ed" < k,t ... " ); fflush(stdout); kspace = fmatrix( 0, t_steps_in-1, 0, ft.steps_half-1 ); transform_k( matrix_read ); printf( "done\n" ); printf( "scaling to byte ... " ); fflush(stdout); matrix_write = ucmatrix( 0, t_steps_in-1, 0, ft.steps_half-1 ); scale( input.C_kt, 0, kspace, matrix_write, t_steps_in, ft.steps_half ); delete_fmatrix( kspace, 0, t_steps_in-1, 0, ft.steps_half-1 ); printf( "done\n" ); printf( "writing to disk ... " ); fflush(stdout); write_transform_k( fname_kt, matrix_write ); delete_ucmatrix( matrix_write, 0, t_steps_in-1, 0, x_steps_in-1 ); printf( "done\n" ); } if (input.Q_kw) { printf( "transforming x,t -> k,w ... " ); fflush(stdout); transform_kw( matrix_read ); printf( "done\n" ); printf( "scaling to byte ... " ); fflush(stdout); matrix_write = ucmatrix( 0, ft2d.steps_half_1-1, 0, ft2d.steps_2-1 ); scale( input.C_kw, 0, ft2d.power, matrix_write, ft2d.steps_half_1, ft2d.steps_2 ); printf( "done\n" ); printf( "writing to disk ... " ); fflush(stdout); write_transform_kw( fname_kw, matrix_write ); delete_ucmatrix( matrix_write, 0, ft2d.steps_half_1-1, 0, ft2d.steps_2-1); printf( "done\n" ); } delete_fmatrix( matrix_read, 0, t_steps_in-1, 0, x_steps_in-1 ); } ////////////////////////////////////////////////////////////////////////////////////////// void spacetime::read_input_array_size( char *unit ) { static error_handler bob("spacetime::read_input_array_size",errname); FILE *file; char fname[ filename_size ]; float x_start, x_stop; int x_steps; int period; fnumber = 0; x_steps_in = 0; do // read all spacetime file headers in order to determine { // the dimension of the input array sprintf( fname, "%s/%s-%d-%d", input_path, unit, fnumber+1, input.t_start ); file = fopen( fname, "rb" ); bob.message( "filename = ",fname); if (file) { fnumber++; fread( &period, sizeof(int), 1, file ); fread( &spp, sizeof(int), 1, file ); fread( &x_start, sizeof(float), 1, file ); fread( &x_stop, sizeof(float), 1, file ); fread( &x_steps, sizeof(int), 1, file ); fclose( file ); if (x_steps_in==0 && x_steps>0) x_start_in = 1e-6 * floor( 1e6 * x_start ); if (x_steps>0 ) { spl = (int) floor( (float) x_steps / (x_stop - x_start) + 0.5 ); x_stop_in = 1e-6 * floor( 1e6 * x_stop ); } x_steps_in += x_steps; } } while( file ); if (fnumber==0) bob.error( "no spacetime files found at time", input.t_start ); bob.message( "found", fnumber, "domain-spacetime file(s) at time", input.t_start ); bob.message( "spp =", spp ); bob.message( "x_start =", x_start_in ); bob.message( "x_stop =", x_stop_in ); bob.message( "x_steps =", x_steps_in ); bob.message( "spl =", spl ); if ( input.x_start < x_start_in ) input.x_start = x_start_in; if ( input.x_stop > x_stop_in ) input.x_stop = x_stop_in; t_steps_in = (input.t_stop - input.t_start) * spp; } ////////////////////////////////////////////////////////////////////////////////////////// void spacetime::read( char *unit ) { static error_handler bob("spacetime::read",errname); FILE *file; char fname[ filename_size ]; float x_start, x_stop; int x_steps; int ti, fi, *x_steps_previous; int period, period_in, spp_in; x_steps_previous = new int [ t_steps_in ]; for( ti=0; ti x_stop_in ) input.x_stop = x_stop_in; xmin = floor( (input.x_start - x_start_in) * spl + 0.5 ); xmax = floor( (input.x_stop - x_start_in) * spl + 0.5 ); bob.message( "t_start_out =", input.t_start ); bob.message( "t_stop_out =", input.t_stop ); bob.message( "x_start_out =", input.x_start ); bob.message( "x_stop_out =", input.x_stop ); bob.message( "spp =", spp ); bob.message( "spl =", spl ); bob.message( "t_steps_in =", t_steps_in ); bob.message( "xmin =", xmin ); bob.message( "xmax =", xmax ); sprintf( filename, "%s/%s", output_path, unit ); file = fopen( filename, "wb" ); if (!file) bob.error( "cannot open file", filename ); bob.message("check point 1"); vector_write = new unsigned char [input.size]; if (scale_write == 1) // de_fi and de_ii { bob.message("check point 2"); for( i=0; i= 0 && k < t_steps_in && l >= 0 && l < x_steps_in && matrix_write[k][l]>0) flag ++; } } max_flag = flag > max_flag ? flag:max_flag; } } for( i=0; i= 0 && k < t_steps_in && l >= 0 && l < x_steps_in && matrix_write[k][l]>0) flag ++; } } if (flag>0) vector_write[j] = (unsigned char) floor(255*flag/max_flag+0.5); else vector_write[j] = (unsigned char) 0; } fwrite( vector_write, sizeof(unsigned char), input.size, file ); } } if (scale_write == 0) // all the others { bob.message("check point 3"); for( i=0; i0 && input.K_cut<=kmax) { xmin = ft2d.steps_half_2 - (int) floor(1.0*input.K_cut/ft2d.df_2); xmax = ft2d.steps_half_2 + (int) floor(1.0*input.K_cut/ft2d.df_2); } else { xmin = 0; xmax = ft2d.steps_2; } if (input.W_cut>0 && input.W_cut<=wmax) { tmin = 0; tmax = (int) floor( 1.0*input.W_cut/ft2d.df_1 ); } else { tmin = 0; tmax = ft2d.steps_half_1; } sprintf( filename, "%s/%s", output_path, unit ); file = fopen( filename, "wb" ); if (!file) bob.error( "cannot open file", filename ); vector_write = new unsigned char [input.size]; for( i=0; i