├── Makefile ├── README.md ├── drivers ├── Makefile ├── pod_reconstruction │ ├── Makefile │ ├── bin │ │ ├── pod_reconstruction.in │ │ └── pod_reconstruction.run │ ├── input_data.cpp │ ├── input_data.h │ ├── main.cpp │ └── plotting │ │ ├── plot_eps_one_file.gp │ │ └── plot_eps_separate_files.gp ├── pod_reconstruction_mpi │ ├── Makefile │ ├── bin │ │ ├── pod_reconstruction_mpi.in │ │ └── pod_reconstruction_mpi.run │ ├── input_data.cpp │ ├── input_data.h │ ├── main.cpp │ └── plotting │ │ ├── plot_eps_one_file.gp │ │ └── plot_eps_separate_files.gp ├── snapshot_pod │ ├── Makefile │ ├── bin │ │ ├── snapshot_pod.in │ │ └── snapshot_pod.run │ ├── input_data.cpp │ ├── input_data.h │ ├── main.cpp │ └── plotting │ │ ├── plot_eps_one_file.gp │ │ └── plot_eps_separate_files.gp └── snapshot_pod_mpi │ ├── Makefile │ ├── bin │ ├── snapshot_pod_mpi.in │ └── snapshot_pod_mpi.run │ ├── input_data.cpp │ ├── input_data.h │ ├── main.cpp │ └── plotting │ ├── plot_eps_one_file.gp │ └── plot_eps_separate_files.gp ├── makefiles ├── Makefile.MacBook.in ├── Makefile.dell.in ├── Makefile.edda.in └── Makefile.tango.in ├── src ├── Makefile ├── libPodUtils │ ├── Field_Reconstructor_t.cpp │ ├── Field_Reconstructor_t.h │ ├── Inner_Product_Calculator_t.cpp │ ├── Inner_Product_Calculator_t.h │ ├── Makefile │ ├── POD_t.cpp │ ├── POD_t.h │ ├── Snapshot_Data_t.cpp │ ├── Snapshot_Data_t.h │ ├── Snapshot_Derivative_Data_t.cpp │ ├── Snapshot_Derivative_Data_t.h │ ├── Spatial_Mode_Calculator_t.cpp │ ├── Spatial_Mode_Calculator_t.h │ ├── real_sym_eig_solver.cpp │ └── real_sym_eig_solver.h └── libUtils │ ├── Makefile │ ├── binary_read_or_write.cpp │ ├── binary_read_or_write.h │ ├── cubic_spline.cpp │ ├── cubic_spline.h │ ├── file_opening_closing.cpp │ ├── file_opening_closing.h │ ├── finite_difference.cpp │ ├── finite_difference.h │ ├── interpolation.cpp │ ├── interpolation.h │ ├── interpolation_1D.cpp │ ├── interpolation_1D.h │ ├── matrix.cpp │ ├── matrix.h │ ├── memory_allocations.cpp │ ├── memory_allocations.h │ ├── misc.cpp │ ├── misc.h │ ├── param.cpp │ ├── param.h │ ├── string.cpp │ ├── string.h │ ├── time_stats.cpp │ ├── time_stats.h │ ├── tridiagonal_solver.cpp │ └── tridiagonal_solver.h └── tests ├── snapshot_pod ├── pbs-script └── snapshot_pod.in └── snapshot_pod_mpi ├── pbs-script └── snapshot_pod_mpi.in /Makefile: -------------------------------------------------------------------------------- 1 | #------------------------------------------- 2 | # To add in new system options: 3 | # 1) copy the ./makefiles/Makefile.generic.in file to ./makefiles/Makefile.YOUR_SYSTEM.in 4 | # 2) make required changes to ./makefiles/Makefile.YOUR_SYSTEM.in 5 | # 3) in the present Makefile modify the default print statement to includei "YOUR_SYSTEM" 6 | # 4) in the present Makefile add "YOUR_SYSTEM" to the line currently containing "generic" and "cygwin" 7 | #------------------------------------------- 8 | 9 | default: 10 | @echo "-------------------------------------------" 11 | @echo "The system options are:" 12 | @echo " make MacBook" 13 | @echo " make edda" 14 | @echo " make tango" 15 | @echo " make dell" 16 | @echo " make all (uses current architecture)" 17 | @echo "-------------------------------------------" 18 | 19 | all: 20 | (cd ./src ; make ; cd ../drivers ; make) 21 | 22 | MacBook edda tango alienor dell: 23 | (rm -f Makefile.in ; ln -s makefiles/Makefile.$@.in Makefile.in ; make clean ; make all) 24 | 25 | clean: 26 | (rm -fv *~ ._* ; cd ./src ; make clean ; cd ../drivers ; make clean ; cd ../makefiles ; rm -fv *~) 27 | 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ---------------------------------------------------------------------- 2 | 1) Code overview: 3 | ---------------------------------------------------------------------- 4 | 5 | Author: Vassili Kitsios 6 | 7 | This C++ code has been written to perform snapshot POD analysis in serial and in parallel using the VTK data format. 8 | 9 | This README file contains installation instructions and an overview of the code. If you are to use this code in your own projects please cite the following documents: 10 | 11 | Kitsios, V., Cordier, L., Bonnet, J.-P., Ooi, A. & Soria, J., 2011, On the coherent structures and stability properties of a leading edge separated aerofoil with turbulent recirculation, Journal of Fluid Mechanics, Vol. 683, pp 395-416. 12 | http://journals.cambridge.org/action/displayAbstract?fromPage=online&aid=8378263 13 | 14 | Kitsios, V., 2010, Recovery of fluid mechanical modes in unsteady separated flows, PhD Thesis, The University of Melbourne 15 | https://minerva-access.unimelb.edu.au/handle/11343/35705 16 | 17 | 18 | ---------------------------------------------------------------------- 19 | 2) Installation instructions: 20 | ---------------------------------------------------------------------- 21 | 22 | Prior to compliling this code the following libraries are required on the system: 23 | 24 | clapack http://www.netlib.org/clapack/ 25 | 26 | VTK http://www.vtk.org 27 | 28 | MPICH http://www.mcs.anl.gov/research/projects/mpi/mpich1-old/ 29 | 30 | 31 | Once these components are installed see "./Makefile" for details on how to compile the present code. 32 | 33 | 34 | ---------------------------------------------------------------------- 35 | 3) List of files and directories with brief explanations: 36 | ---------------------------------------------------------------------- 37 | 38 | drivers/ - directory containing executable directory and Makefile 39 | 40 | /Makefile - Makefile to jump make executable directory 41 | 42 | /snapshot_pod/ - serial snapshot POD code 43 | 44 | /snapshot_pod_mpi/ - parallel snapshot POD code 45 | 46 | /pod_reconstruction/ - serial POD reconstruction code 47 | 48 | /pod_reconstruction_mpi/ - parallel POD reconstruction code 49 | 50 | 51 | include/ - directory containing include files from libraries made from src directory 52 | 53 | 54 | lib/ - directory containing libraries made from src directory 55 | 56 | 57 | Makefile - main makefile 58 | 59 | Makefile.in - input makefile with system specific settings. See "Makefile" for how to create your own "Makefile.in" 60 | 61 | makefiles/ - directory containing system specific makefiles 62 | 63 | 64 | src/ - directory containing the library source directories 65 | 66 | /libUtils/ - directory containing the source for a general Utilities library 67 | 68 | /libPodUtils/ - directory containing the source for the POD library common to all POD driver codes 69 | 70 | 71 | tests/ 72 | 73 | snapsho_pod/ - example of how to set up the input deck and output for a serial snapshot POD run 74 | 75 | pbs-script - script to launch job on cluster 76 | 77 | snapshot_pod_mpi.in - input deck containing parameters specifying the job details 78 | 79 | snapsho_pod_mpi/ - example of how to set up the input deck and output for a parallel snapshot POD run 80 | 81 | pbs-script - script to launch job on cluster 82 | 83 | snapshot_pod_mpi.in - input deck containing parameters specifying the job details 84 | 85 | 86 | ---------------------------------------------------------------------- 87 | -------------------------------------------------------------------------------- /drivers/Makefile: -------------------------------------------------------------------------------- 1 | 2 | default: 3 | (cd ./snapshot_pod ; make ; cd ../snapshot_pod_mpi ; make ; cd ../pod_reconstruction ; make ; cd ../pod_reconstruction_mpi ; make) 4 | 5 | clean: 6 | (cd ./snapshot_pod ; make clean ; cd ../snapshot_pod_mpi ; make clean ; cd ../pod_reconstruction ; make clean ; cd ../pod_reconstruction_mpi ; make clean) 7 | -------------------------------------------------------------------------------- /drivers/pod_reconstruction/Makefile: -------------------------------------------------------------------------------- 1 | # Vassili Kitsios 1/12/2006 2 | # ------------------------- 3 | BASE_DIR = ../.. 4 | include $(BASE_DIR)/Makefile.in 5 | 6 | LIBS = -lm -L$(LIB_DIR)/ $(POD_LIBS) $(UTILS_LIBS) $(VTK_LIBS) $(CLAPACK_LIBS) 7 | INCL = -I$(INCLUDE_DIR) $(CLAPACK_INC) $(VTK_INC) 8 | 9 | # --------Suffixes--------- 10 | .SUFFIXES: .cpp 11 | 12 | .cpp.o: 13 | $(CPP) $(CPPFLAGS) $(LIBS) $(INCL) -c $*.cpp 14 | 15 | .cpp : 16 | $(CPP) $(CPPFLAGS) $(LIBS) $(INCL) -o $< $@ 17 | 18 | # -------Dependencies------ 19 | BIN_NAME = pod_reconstruction 20 | INPUT_DECK_NAME = $(BIN_NAME).in 21 | RUN_NAME = $(BIN_NAME).run 22 | 23 | SRC = input_data.cpp main.cpp 24 | 25 | OBJS = $(addsuffix .o, $(basename $(SRC))) 26 | 27 | # -------Make Commands------ 28 | default: $(BIN_NAME) 29 | (mkdir -p $(BASE_DIR)/bin ; mv $(BIN_NAME) ./bin ; cp ./bin/$(BIN_NAME)* $(BASE_DIR)/bin) 30 | 31 | $(BIN_NAME): $(OBJS) 32 | $(CPP) $(CPPFLAGS) -o $@ $(OBJS) $(LIBS) 33 | 34 | clean: 35 | rm -fv ./bin/$(BIN_NAME) $(BASE_DIR)/bin/$(BIN_NAME)* ~/bin/$(BIN_NAME)* *.o *~ ._* ./bin/*~ 36 | 37 | # This automatically updates all the dependencies shown below 38 | depend: 39 | makedepend -Y $(SRC) 40 | 41 | -------------------------------------------------------------------------------- /drivers/pod_reconstruction/bin/pod_reconstruction.in: -------------------------------------------------------------------------------- 1 | #---------------------------------------- 2 | # pod_reconstruction input deck 3 | #---------------------------------------- 4 | 5 | #shear region 6 | x_min = -0.05 7 | x_max = 0.25 8 | y_min = -0.105 9 | y_max = 0.145 10 | z_min = -10.0 11 | z_max = 10.0 12 | 13 | #temporal_correlation_type = u 14 | #temporal_correlation_type = v 15 | #temporal_correlation_type = w 16 | temporal_correlation_type = ke 17 | #temporal_correlation_type = p 18 | #temporal_correlation_type = q 19 | 20 | normalisation = none 21 | #normalisation = local 22 | #normalisation = global 23 | 24 | snapshot_list_filename = ../snapshots/data_files.100T.list 25 | snapshot_dir = ../snapshots/ 26 | file_name_with_cell_volumes = ../snapshots/cell_volumes.vtk 27 | spatial_modes_dir = ./restart/ 28 | 29 | two_dimensional = true 30 | #two_dimensional = false 31 | 32 | test_reconstruction = true 33 | #test_reconstruction = false 34 | 35 | test_orthogonality = true 36 | #test_orthogonality = false 37 | 38 | dt = 0.002 39 | 40 | #---------------------------------- 41 | # End of Deck 42 | #---------------------------------- 43 | 44 | -------------------------------------------------------------------------------- /drivers/pod_reconstruction/bin/pod_reconstruction.run: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # ---------------------------------------------------------------------------- 4 | # Some important filenames: 5 | PROGRAM="pod_reconstruction" 6 | OUTPUT_FILE=${PROGRAM}".out" 7 | ERROR_FILE=${PROGRAM}".err" 8 | 9 | PROGRAM_BASE_DIR="/Users/vas/Documents/3Coding/4Analysis_codes/drivers/POD" 10 | PROGRAM_BIN_DIR=$PROGRAM_BASE_DIR"/bin" 11 | PROGRAM_SRC_DIR=$PROGRAM_BASE_DIR"/drivers" 12 | GNU_PLOT_FILES_DIR=$PROGRAM_SRC_DIR/$PROGRAM"/plotting" 13 | GNU_PLOT_ONE_EPS_FILE="plot_eps_one_file.gp" 14 | GNU_PLOT_SEPARATE_EPS_FILES="plot_eps_separate_files.gp" 15 | 16 | RESULTS_DIR="./results" 17 | IMAGES_DIR="./images" 18 | 19 | # ---------------------------------------------------------------------------- 20 | # Organise files: 21 | rm -vrf $PROGRAM $OUTPUT_FILE $ERROR_FILE $RESULTS_DIR $IMAGES_DIR *~ 22 | cp $PROGRAM_BIN_DIR/$PROGRAM . 23 | 24 | mkdir $RESULTS_DIR $IMAGES_DIR 25 | cp $GNU_PLOT_FILES_DIR/$GNU_PLOT_ONE_EPS_FILE $IMAGES_DIR 26 | cp $GNU_PLOT_FILES_DIR/$GNU_PLOT_SEPARATE_EPS_FILES $IMAGES_DIR 27 | 28 | # ---------------------------------------------------------------------------- 29 | # Running code: 30 | #$PROGRAM 1>${PROGRAM}.out 2> ${PROGRAM}.err 31 | ./$PROGRAM 32 | 33 | # ---------------------------------------------------------------------------- 34 | # Generate images: 35 | echo "Generating images..." 36 | cd $IMAGES_DIR 37 | gnuplot $GNU_PLOT_ONE_EPS_FILE 38 | gnuplot $GNU_PLOT_SEPARATE_EPS_FILES 39 | cd .. 40 | echo "done." 41 | echo " " 42 | 43 | # ---------------------------------------------------------------------------- 44 | -------------------------------------------------------------------------------- /drivers/pod_reconstruction/input_data.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Utils.h" 3 | #include "input_data.h" 4 | 5 | //------------------------------------------------------------------------- 6 | InputData_t::InputData_t() 7 | { 8 | ParamListHead_t param_list_head; 9 | 10 | param_list_head.get_params_from_file((char*)"pod_reconstruction.in"); 11 | param_list_head.print_params(); 12 | 13 | temporal_correlation_type = param_list_head.get_string_param((char*)"temporal_correlation_type"); 14 | normalisation = param_list_head.get_string_param((char*)"normalisation"); 15 | 16 | snapshot_list_filename = param_list_head.get_string_param((char*)"snapshot_list_filename"); 17 | snapshot_dir = param_list_head.get_string_param((char*)"snapshot_dir"); 18 | file_name_with_cell_volumes = param_list_head.get_string_param((char*)"file_name_with_cell_volumes"); 19 | 20 | spatial_modes_dir = param_list_head.get_string_param((char*)"spatial_modes_dir"); 21 | 22 | char *test_reconstruction_char; 23 | test_reconstruction_char = param_list_head.get_string_param((char*)"test_reconstruction"); 24 | if (strcmp(test_reconstruction_char,"true")==0) { 25 | test_reconstruction = true; 26 | } else if (strcmp(test_reconstruction_char,"false")==0) { 27 | test_reconstruction = false; 28 | } else { 29 | quit_error((char*)" = 'true' or 'false'\n"); 30 | } 31 | 32 | char *test_orthogonality_char; 33 | test_orthogonality_char = param_list_head.get_string_param((char*)"test_orthogonality"); 34 | if (strcmp(test_orthogonality_char,"true")==0) { 35 | test_orthogonality = true; 36 | } else if (strcmp(test_orthogonality_char,"false")==0) { 37 | test_orthogonality = false; 38 | } else { 39 | quit_error((char*)" = 'true' or 'false'\n"); 40 | } 41 | 42 | two_dimensional = param_list_head.get_string_param((char*)"two_dimensional"); 43 | 44 | dt = param_list_head.get_double_param((char*)"dt"); 45 | 46 | x_min = param_list_head.get_double_param((char*) "x_min"); 47 | x_max = param_list_head.get_double_param((char*) "x_max"); 48 | y_min = param_list_head.get_double_param((char*) "y_min"); 49 | y_max = param_list_head.get_double_param((char*) "y_max"); 50 | z_min = param_list_head.get_double_param((char*) "z_min"); 51 | z_max = param_list_head.get_double_param((char*) "z_max"); 52 | } 53 | 54 | //------------------------------------------------------------------------- 55 | InputData_t::~InputData_t() 56 | { 57 | } 58 | -------------------------------------------------------------------------------- /drivers/pod_reconstruction/input_data.h: -------------------------------------------------------------------------------- 1 | 2 | //============================================================================ 3 | // InputData_t 4 | //============================================================================ 5 | class InputData_t 6 | { 7 | private: 8 | //------------------------------------------------------------------------- 9 | public: 10 | //------------------------------------------------------------------------- 11 | // variables 12 | //------------------------------------------------------------------------- 13 | double x_min; // Domain of interest 14 | double x_max; 15 | double y_min; 16 | double y_max; 17 | double z_min; 18 | double z_max; 19 | 20 | char *snapshot_list_filename; // file containing list of snapshot files 21 | char *snapshot_dir; // location of snapshots 22 | char *file_name_with_cell_volumes; // file number with cell volumes, first file number is 0 23 | 24 | char *spatial_modes_list_filename; // file containing list of spatial modes files 25 | char *spatial_modes_dir; // location of spatial modes 26 | 27 | char *two_dimensional; // if data is 2D "true" or "false" 28 | char *temporal_correlation_type; // u, v, w, p, ke, q 29 | char *normalisation; // none local global 30 | char *restart; // 'false' or location of the temporal correlations file 31 | double dt; // time between each snapshot - assuming constant dt 32 | 33 | bool test_reconstruction; 34 | bool test_orthogonality; 35 | 36 | //------------------------------------------------------------------------- 37 | // functions 38 | //------------------------------------------------------------------------- 39 | InputData_t(); 40 | //------------------------------------------------------------------------- 41 | ~InputData_t(); 42 | //------------------------------------------------------------------------- 43 | }; 44 | 45 | -------------------------------------------------------------------------------- /drivers/pod_reconstruction/main.cpp: -------------------------------------------------------------------------------- 1 | /*========================================================================= 2 | pod_reconstruction 3 | ========================================================================= 4 | 5 | This program performs a POD reconstruction of the snapshots used to create 6 | the basis. 7 | 8 | =========================================================================*/ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include "Utils.h" 15 | #include "PodUtils.h" 16 | #include "input_data.h" 17 | 18 | //---------------------------------------------------------------------------- 19 | int main(int argc, char *argv[]) 20 | { 21 | //............................................................................ 22 | cout << "Cleaning results directory..." << endl; 23 | string results_directory("./results"); rmdir(results_directory.c_str()); mkdir(results_directory.c_str(), 0777); 24 | 25 | //............................................................................ 26 | cout << "Reading input deck..." << endl; 27 | InputData_t input_deck; 28 | 29 | //............................................................................ 30 | POD_t pod(input_deck.temporal_correlation_type, input_deck.normalisation, input_deck.dt, input_deck.two_dimensional, 31 | input_deck.snapshot_list_filename, input_deck.snapshot_dir, input_deck.file_name_with_cell_volumes, 32 | input_deck.x_min, input_deck.x_max, input_deck.y_min, input_deck.y_max, input_deck.z_min, input_deck.z_max, 33 | input_deck.spatial_modes_dir); 34 | 35 | pod.allocate_memory(); 36 | pod.report_memory_usage(); 37 | 38 | pod.read_spatial_modes(); 39 | pod.read_mean_field(input_deck.spatial_modes_dir); 40 | pod.read_rms_field(input_deck.spatial_modes_dir); 41 | pod.read_spatial_rms_history(input_deck.spatial_modes_dir); 42 | pod.write_spatial_rms_history(); 43 | 44 | if (input_deck.test_orthogonality) 45 | pod.test_spatial_orthogonality(); 46 | 47 | if (input_deck.test_reconstruction) { 48 | pod.calculate_L2_reconstruction_error(); 49 | pod.write_reconstruction_L2_error(); 50 | pod.calculate_L_infinite_reconstruction_error(); 51 | pod.write_reconstruction_L_infinite_error(); 52 | } 53 | 54 | //............................................................................ 55 | return 0; 56 | } 57 | 58 | //---------------------------------------------------------------------------- 59 | -------------------------------------------------------------------------------- /drivers/pod_reconstruction/plotting/plot_eps_one_file.gp: -------------------------------------------------------------------------------- 1 | 2 | # -------------------------------- Ouput settings -------------------------------- 3 | set terminal postscript enhanced font "Times-Roman" 20 4 | set output 'view_output.eps' 5 | 6 | # -------------------------------- L infinite Error -------------------------------- 7 | 8 | set xlabel 'time' 9 | 10 | set title 'L_{\infty} Error for each Mode level reconstruction across all snapshots' 11 | set logscale y 10 12 | set xlabel 'mode' 13 | set ylabel 'max L2 Error' rotate by 90 14 | plot '../results/max_spatial_reconstruction_L2_error.dat' using 1:2 title "u" with linespoints lt 2 pt 2, \ 15 | '../results/max_spatial_reconstruction_L2_error.dat' using 1:3 title "v" with linespoints lt 3 pt 3, \ 16 | '../results/max_spatial_reconstruction_L2_error.dat' using 1:4 title "w" with linespoints lt 4 pt 4, \ 17 | '../results/max_spatial_reconstruction_L2_error.dat' using 1:5 title "pressure" with linespoints lt 5 pt 5, \ 18 | '../results/max_spatial_reconstruction_L2_error.dat' using 1:6 title "total" with linespoints lt 6 pt 6 19 | 20 | 21 | # -------------------------------- Reconstriction L2 Error -------------------------------- 22 | 23 | unset logscale 24 | set xlabel 'time' 25 | set ylabel 'L2 Error' rotate by 90 26 | 27 | set title 'Spatial Reconstruction L2 Error Using 1 Mode' 28 | plot '../results/spatial_reconstruction_L2_error_0001.dat' using 1:2 title "u" with lines lt 2, \ 29 | '../results/spatial_reconstruction_L2_error_0001.dat' using 1:3 title "v" with lines lt 3, \ 30 | '../results/spatial_reconstruction_L2_error_0001.dat' using 1:4 title "w" with lines lt 4, \ 31 | '../results/spatial_reconstruction_L2_error_0001.dat' using 1:5 title "p" with lines lt 5, \ 32 | '../results/spatial_reconstruction_L2_error_0001.dat' using 1:6 title "total" with lines lt 6 33 | 34 | set title 'Spatial Reconstruction L2 Error Using 2 Modes' 35 | plot '../results/spatial_reconstruction_L2_error_0002.dat' using 1:2 title "u" with lines lt 2, \ 36 | '../results/spatial_reconstruction_L2_error_0002.dat' using 1:3 title "v" with lines lt 3, \ 37 | '../results/spatial_reconstruction_L2_error_0002.dat' using 1:4 title "w" with lines lt 4, \ 38 | '../results/spatial_reconstruction_L2_error_0002.dat' using 1:5 title "p" with lines lt 5, \ 39 | '../results/spatial_reconstruction_L2_error_0002.dat' using 1:6 title "total" with lines lt 6 40 | 41 | set title 'Spatial Reconstruction L2 Error Using 3 Modes' 42 | plot '../results/spatial_reconstruction_L2_error_0003.dat' using 1:2 title "u" with lines lt 2, \ 43 | '../results/spatial_reconstruction_L2_error_0003.dat' using 1:3 title "v" with lines lt 3, \ 44 | '../results/spatial_reconstruction_L2_error_0003.dat' using 1:4 title "w" with lines lt 4, \ 45 | '../results/spatial_reconstruction_L2_error_0003.dat' using 1:5 title "p" with lines lt 5, \ 46 | '../results/spatial_reconstruction_L2_error_0003.dat' using 1:6 title "total" with lines lt 6 47 | 48 | set title 'Spatial Reconstruction L2 Error Using 4 Modes' 49 | plot '../results/spatial_reconstruction_L2_error_0004.dat' using 1:2 title "u" with lines lt 2, \ 50 | '../results/spatial_reconstruction_L2_error_0004.dat' using 1:3 title "v" with lines lt 3, \ 51 | '../results/spatial_reconstruction_L2_error_0004.dat' using 1:4 title "w" with lines lt 4, \ 52 | '../results/spatial_reconstruction_L2_error_0004.dat' using 1:5 title "p" with lines lt 5, \ 53 | '../results/spatial_reconstruction_L2_error_0004.dat' using 1:6 title "total" with lines lt 6 54 | 55 | set title 'Spatial Reconstruction L2 Error Using 5 Modes' 56 | plot '../results/spatial_reconstruction_L2_error_0005.dat' using 1:2 title "u" with lines lt 2, \ 57 | '../results/spatial_reconstruction_L2_error_0005.dat' using 1:3 title "v" with lines lt 3, \ 58 | '../results/spatial_reconstruction_L2_error_0005.dat' using 1:4 title "w" with lines lt 4, \ 59 | '../results/spatial_reconstruction_L2_error_0005.dat' using 1:5 title "p" with lines lt 5, \ 60 | '../results/spatial_reconstruction_L2_error_0005.dat' using 1:6 title "total" with lines lt 6 61 | 62 | set title 'Spatial Reconstruction L2 Error Using 6 Modes' 63 | plot '../results/spatial_reconstruction_L2_error_0006.dat' using 1:2 title "u" with lines lt 2, \ 64 | '../results/spatial_reconstruction_L2_error_0006.dat' using 1:3 title "v" with lines lt 3, \ 65 | '../results/spatial_reconstruction_L2_error_0006.dat' using 1:4 title "w" with lines lt 4, \ 66 | '../results/spatial_reconstruction_L2_error_0006.dat' using 1:5 title "p" with lines lt 5, \ 67 | '../results/spatial_reconstruction_L2_error_0006.dat' using 1:6 title "total" with lines lt 6 68 | 69 | set title 'Spatial Reconstruction L2 Error Using 7 Modes' 70 | plot '../results/spatial_reconstruction_L2_error_0007.dat' using 1:2 title "u" with lines lt 2, \ 71 | '../results/spatial_reconstruction_L2_error_0007.dat' using 1:3 title "v" with lines lt 3, \ 72 | '../results/spatial_reconstruction_L2_error_0007.dat' using 1:4 title "w" with lines lt 4, \ 73 | '../results/spatial_reconstruction_L2_error_0007.dat' using 1:5 title "p" with lines lt 5, \ 74 | '../results/spatial_reconstruction_L2_error_0007.dat' using 1:6 title "total" with lines lt 6 75 | 76 | set title 'Spatial Reconstruction L2 Error Using 8 Modes' 77 | plot '../results/spatial_reconstruction_L2_error_0008.dat' using 1:2 title "u" with lines lt 2, \ 78 | '../results/spatial_reconstruction_L2_error_0008.dat' using 1:3 title "v" with lines lt 3, \ 79 | '../results/spatial_reconstruction_L2_error_0008.dat' using 1:4 title "w" with lines lt 4, \ 80 | '../results/spatial_reconstruction_L2_error_0008.dat' using 1:5 title "p" with lines lt 5, \ 81 | '../results/spatial_reconstruction_L2_error_0008.dat' using 1:6 title "total" with lines lt 6 82 | 83 | set title 'Spatial Reconstruction L2 Error Using 9 Modes' 84 | plot '../results/spatial_reconstruction_L2_error_0009.dat' using 1:2 title "u" with lines lt 2, \ 85 | '../results/spatial_reconstruction_L2_error_0009.dat' using 1:3 title "v" with lines lt 3, \ 86 | '../results/spatial_reconstruction_L2_error_0009.dat' using 1:4 title "w" with lines lt 4, \ 87 | '../results/spatial_reconstruction_L2_error_0009.dat' using 1:5 title "p" with lines lt 5, \ 88 | '../results/spatial_reconstruction_L2_error_0009.dat' using 1:6 title "total" with lines lt 6 89 | 90 | set title 'Spatial Reconstruction L2 Error Using 10 Modes' 91 | plot '../results/spatial_reconstruction_L2_error_0010.dat' using 1:2 title "u" with lines lt 2, \ 92 | '../results/spatial_reconstruction_L2_error_0010.dat' using 1:3 title "v" with lines lt 3, \ 93 | '../results/spatial_reconstruction_L2_error_0010.dat' using 1:4 title "w" with lines lt 4, \ 94 | '../results/spatial_reconstruction_L2_error_0010.dat' using 1:5 title "p" with lines lt 5, \ 95 | '../results/spatial_reconstruction_L2_error_0010.dat' using 1:6 title "total" with lines lt 6 96 | 97 | 98 | # -------------------------------- EOF -------------------------------- 99 | -------------------------------------------------------------------------------- /drivers/pod_reconstruction/plotting/plot_eps_separate_files.gp: -------------------------------------------------------------------------------- 1 | 2 | # -------------------------------- Ouput settings -------------------------------- 3 | set terminal postscript enhanced eps font "Times-Roman" 32 dashlength 3 4 | 5 | # -------------------------------- Max Reconstriction L2 Error -------------------------------- 6 | 7 | set logscale y 10 8 | set xlabel 'mode' 9 | set ylabel 'max L2 Error' rotate by 90 10 | set output './max_spatial_reconstruction_L2_error.eps' 11 | plot '../results/max_spatial_reconstruction_L2_error.dat' using 1:2 title "u" with linespoints lt 2 pt 2, \ 12 | '../results/max_spatial_reconstruction_L2_error.dat' using 1:3 title "v" with linespoints lt 3 pt 3, \ 13 | '../results/max_spatial_reconstruction_L2_error.dat' using 1:4 title "w" with linespoints lt 4 pt 4, \ 14 | '../results/max_spatial_reconstruction_L2_error.dat' using 1:5 title "pressure" with linespoints lt 5 pt 5, \ 15 | '../results/max_spatial_reconstruction_L2_error.dat' using 1:6 title "total" with linespoints lt 6 pt 6 16 | 17 | 18 | # -------------------------------- Reconstriction L2 Error -------------------------------- 19 | 20 | unset logscale 21 | set xlabel 'time' 22 | set ylabel 'L2 Error' rotate by 90 23 | 24 | set output './spatial_reconstruction_L2_error_0001.eps' 25 | plot '../results/spatial_reconstruction_L2_error_0001.dat' using 1:2 title "u" with lines lt 2, \ 26 | '../results/spatial_reconstruction_L2_error_0001.dat' using 1:3 title "v" with lines lt 3, \ 27 | '../results/spatial_reconstruction_L2_error_0001.dat' using 1:4 title "w" with lines lt 4, \ 28 | '../results/spatial_reconstruction_L2_error_0001.dat' using 1:5 title "p" with lines lt 5, \ 29 | '../results/spatial_reconstruction_L2_error_0001.dat' using 1:6 title "total" with lines lt 6 30 | 31 | set output './spatial_reconstruction_L2_error_0002.eps' 32 | plot '../results/spatial_reconstruction_L2_error_0002.dat' using 1:2 title "u" with lines lt 2, \ 33 | '../results/spatial_reconstruction_L2_error_0002.dat' using 1:3 title "v" with lines lt 3, \ 34 | '../results/spatial_reconstruction_L2_error_0002.dat' using 1:4 title "w" with lines lt 4, \ 35 | '../results/spatial_reconstruction_L2_error_0002.dat' using 1:5 title "p" with lines lt 5, \ 36 | '../results/spatial_reconstruction_L2_error_0002.dat' using 1:6 title "total" with lines lt 6 37 | 38 | 39 | 40 | # -------------------------------- EOF -------------------------------- 41 | -------------------------------------------------------------------------------- /drivers/pod_reconstruction_mpi/Makefile: -------------------------------------------------------------------------------- 1 | # Vassili Kitsios 1/12/2006 2 | # ------------------------- 3 | BASE_DIR = ../.. 4 | include $(BASE_DIR)/Makefile.in 5 | 6 | LIBS = -lm $(MPI_LIBS) -L$(LIB_DIR)/ $(POD_LIBS) $(UTILS_LIBS) $(VTK_LIBS) $(CLAPACK_LIBS) 7 | INCL = $(MPI_INC) -I$(INCLUDE_DIR)/ $(VTK_INC) $(CLAPACK_INC) 8 | 9 | CPP=$(MPI_CPP) 10 | 11 | # --------Suffixes--------- 12 | .SUFFIXES: .cpp 13 | 14 | .cpp.o: 15 | $(CPP) $(CPPFLAGS) $(LIBS) $(INCL) -c $*.cpp 16 | 17 | .cpp : 18 | $(CPP) $(CPPFLAGS) $(LIBS) $(INCL) -o $< $@ 19 | 20 | # -------Dependencies------ 21 | BIN_NAME = pod_reconstruction_mpi 22 | INPUT_DECK_NAME = $(BIN_NAME).in 23 | RUN_NAME = $(BIN_NAME).run 24 | 25 | SRC = input_data.cpp main.cpp 26 | 27 | OBJS = $(addsuffix .o, $(basename $(SRC))) 28 | 29 | # -------Make Commands------ 30 | default: $(BIN_NAME) 31 | (mkdir -p $(BASE_DIR)/bin ; mv $(BIN_NAME) ./bin ; cp ./bin/$(BIN_NAME)* $(BASE_DIR)/bin) 32 | 33 | 34 | $(BIN_NAME): $(OBJS) 35 | $(CPP) $(CPPFLAGS) -o $@ $(OBJS) $(LIBS) 36 | 37 | clean: 38 | rm -fv ./bin/$(BIN_NAME) $(BASE_DIR)/bin/$(BIN_NAME)* ~/bin/$(BIN_NAME)* *.o *~ ._* ./bin/*~ 39 | 40 | # This automatically updates all the dependencies shown below 41 | depend: 42 | makedepend -Y $(SRC) 43 | 44 | -------------------------------------------------------------------------------- /drivers/pod_reconstruction_mpi/bin/pod_reconstruction_mpi.in: -------------------------------------------------------------------------------- 1 | #---------------------------------------- 2 | # pod_reconstruction_mpi input deck 3 | #---------------------------------------- 4 | 5 | #shear region 6 | x_min = -0.05 7 | x_max = 0.25 8 | y_min = -0.105 9 | y_max = 0.145 10 | z_min = -10.0 11 | z_max = 10.0 12 | 13 | #temporal_correlation_type = u 14 | #temporal_correlation_type = v 15 | #temporal_correlation_type = w 16 | temporal_correlation_type = ke 17 | #temporal_correlation_type = p 18 | #temporal_correlation_type = q 19 | 20 | normalisation = none 21 | #normalisation = local 22 | #normalisation = global 23 | 24 | snapshot_list_filename = ../snapshots/data_files.100T.list 25 | snapshot_dir = ../snapshots/ 26 | file_name_with_cell_volumes = ../snapshots/cell_volumes.vtk 27 | spatial_modes_dir = ./restart/ 28 | 29 | two_dimensional = true 30 | #two_dimensional = false 31 | 32 | test_reconstruction = true 33 | #test_reconstruction = false 34 | 35 | test_orthogonality = true 36 | #test_orthogonality = false 37 | 38 | dt = 0.002 39 | 40 | #---------------------------------- 41 | # End of Deck 42 | #---------------------------------- 43 | 44 | -------------------------------------------------------------------------------- /drivers/pod_reconstruction_mpi/bin/pod_reconstruction_mpi.run: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # ---------------------------------------------------------------------------- 4 | # Some important filenames: 5 | PROGRAM="pod_reconstruction_mpi" 6 | OUTPUT_FILE=${PROGRAM}".out" 7 | ERROR_FILE=${PROGRAM}".err" 8 | 9 | PROGRAM_BASE_DIR="/Users/vas/Documents/3Coding/4Analysis_codes/drivers/POD" 10 | PROGRAM_BIN_DIR=$PROGRAM_BASE_DIR"/bin" 11 | PROGRAM_SRC_DIR=$PROGRAM_BASE_DIR"/drivers" 12 | GNU_PLOT_FILES_DIR=$PROGRAM_SRC_DIR/$PROGRAM"/plotting" 13 | GNU_PLOT_ONE_EPS_FILE="plot_eps_one_file.gp" 14 | GNU_PLOT_SEPARATE_EPS_FILES="plot_eps_separate_files.gp" 15 | 16 | RESULTS_DIR="./results" 17 | IMAGES_DIR="./images" 18 | 19 | # ---------------------------------------------------------------------------- 20 | # Organise files: 21 | rm -vrf $PROGRAM $OUTPUT_FILE $ERROR_FILE $RESULTS_DIR $IMAGES_DIR *~ 22 | cp $PROGRAM_BIN_DIR/$PROGRAM . 23 | 24 | mkdir $RESULTS_DIR $IMAGES_DIR 25 | cp $GNU_PLOT_FILES_DIR/$GNU_PLOT_ONE_EPS_FILE $IMAGES_DIR 26 | cp $GNU_PLOT_FILES_DIR/$GNU_PLOT_SEPARATE_EPS_FILES $IMAGES_DIR 27 | 28 | # ---------------------------------------------------------------------------- 29 | # Running code: 30 | #$PROGRAM 1>${PROGRAM}.out 2> ${PROGRAM}.err 31 | ./$PROGRAM 32 | 33 | # ---------------------------------------------------------------------------- 34 | # Generate images: 35 | echo "Generating images..." 36 | cd $IMAGES_DIR 37 | gnuplot $GNU_PLOT_ONE_EPS_FILE 38 | gnuplot $GNU_PLOT_SEPARATE_EPS_FILES 39 | cd .. 40 | echo "done." 41 | echo " " 42 | 43 | # ---------------------------------------------------------------------------- 44 | -------------------------------------------------------------------------------- /drivers/pod_reconstruction_mpi/input_data.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Utils.h" 3 | #include "input_data.h" 4 | 5 | //------------------------------------------------------------------------- 6 | InputData_t::InputData_t() 7 | { 8 | ParamListHead_t param_list_head; 9 | 10 | param_list_head.get_params_from_file((char*)"pod_reconstruction_mpi.in"); 11 | param_list_head.print_params(); 12 | 13 | temporal_correlation_type = param_list_head.get_string_param((char*)"temporal_correlation_type"); 14 | normalisation = param_list_head.get_string_param((char*)"normalisation"); 15 | 16 | snapshot_list_filename = param_list_head.get_string_param((char*)"snapshot_list_filename"); 17 | snapshot_dir = param_list_head.get_string_param((char*)"snapshot_dir"); 18 | file_name_with_cell_volumes = param_list_head.get_string_param((char*)"file_name_with_cell_volumes"); 19 | 20 | spatial_modes_dir = param_list_head.get_string_param((char*)"spatial_modes_dir"); 21 | 22 | char *test_reconstruction_char; 23 | test_reconstruction_char = param_list_head.get_string_param((char*)"test_reconstruction"); 24 | if (strcmp(test_reconstruction_char,"true")==0) { 25 | test_reconstruction = true; 26 | } else if (strcmp(test_reconstruction_char,"false")==0) { 27 | test_reconstruction = false; 28 | } else { 29 | quit_error((char*)" = 'true' or 'false'\n"); 30 | } 31 | 32 | char *test_orthogonality_char; 33 | test_orthogonality_char = param_list_head.get_string_param((char*)"test_orthogonality"); 34 | if (strcmp(test_orthogonality_char,"true")==0) { 35 | test_orthogonality = true; 36 | } else if (strcmp(test_orthogonality_char,"false")==0) { 37 | test_orthogonality = false; 38 | } else { 39 | quit_error((char*)" = 'true' or 'false'\n"); 40 | } 41 | 42 | two_dimensional = param_list_head.get_string_param((char*)"two_dimensional"); 43 | 44 | dt = param_list_head.get_double_param((char*)"dt"); 45 | 46 | x_min = param_list_head.get_double_param((char*) "x_min"); 47 | x_max = param_list_head.get_double_param((char*) "x_max"); 48 | y_min = param_list_head.get_double_param((char*) "y_min"); 49 | y_max = param_list_head.get_double_param((char*) "y_max"); 50 | z_min = param_list_head.get_double_param((char*) "z_min"); 51 | z_max = param_list_head.get_double_param((char*) "z_max"); 52 | } 53 | 54 | //------------------------------------------------------------------------- 55 | InputData_t::~InputData_t() 56 | { 57 | } 58 | -------------------------------------------------------------------------------- /drivers/pod_reconstruction_mpi/input_data.h: -------------------------------------------------------------------------------- 1 | 2 | //============================================================================ 3 | // InputData_t 4 | //============================================================================ 5 | class InputData_t 6 | { 7 | private: 8 | //------------------------------------------------------------------------- 9 | public: 10 | //------------------------------------------------------------------------- 11 | // variables 12 | //------------------------------------------------------------------------- 13 | double x_min; // Domain of interest 14 | double x_max; 15 | double y_min; 16 | double y_max; 17 | double z_min; 18 | double z_max; 19 | 20 | char *snapshot_list_filename; // file containing list of snapshot files 21 | char *snapshot_dir; // location of snapshots 22 | char *file_name_with_cell_volumes; // file number with cell volumes, first file number is 0 23 | 24 | char *spatial_modes_list_filename; // file containing list of spatial modes files 25 | char *spatial_modes_dir; // location of spatial modes 26 | 27 | char *two_dimensional; // if data is 2D "true" or "false" 28 | char *temporal_correlation_type; // u, v, w, p, ke, q 29 | char *normalisation; // none local global 30 | char *restart; // 'false' or location of the temporal correlations file 31 | double dt; // time between each snapshot - assuming constant dt 32 | 33 | bool test_reconstruction; 34 | bool test_orthogonality; 35 | 36 | //------------------------------------------------------------------------- 37 | // functions 38 | //------------------------------------------------------------------------- 39 | InputData_t(); 40 | //------------------------------------------------------------------------- 41 | ~InputData_t(); 42 | //------------------------------------------------------------------------- 43 | }; 44 | 45 | -------------------------------------------------------------------------------- /drivers/pod_reconstruction_mpi/main.cpp: -------------------------------------------------------------------------------- 1 | /*========================================================================= 2 | pod_reconstruction_mpi 3 | ========================================================================= 4 | 5 | This program performs a POD reconstruction of the snapshots used to create 6 | the basis. 7 | 8 | =========================================================================*/ 9 | 10 | #include "mpi.h" 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | #include "Utils.h" 17 | #include "PodUtils.h" 18 | #include "input_data.h" 19 | 20 | #define COUNTER_NOTIFY_INTERVAL 10000 21 | 22 | //---------------------------------------------------------------------------- 23 | // mpi helper functions 24 | //---------------------------------------------------------------------------- 25 | double report_time(double start_time, string message); 26 | 27 | void test_spatial_orthogonality_MPI(POD_t *pod); 28 | void calculate_L2_reconstruction_error_MPI(POD_t *pod, bool two_dimensional, int myrank); 29 | 30 | int nprocs, myrank; 31 | 32 | //---------------------------------------------------------------------------- 33 | int main(int argc, char *argv[]) 34 | { 35 | //............................................................................ 36 | // Initialising MPI 37 | if (MPI_Init(&argc, &argv) != MPI_SUCCESS) quit_error_mpi(myrank, nprocs, (char*)"MPI didn't initialise..."); 38 | if (MPI_Comm_size(MPI_COMM_WORLD, &nprocs) != MPI_SUCCESS) quit_error_mpi(myrank, nprocs, (char*)"Couldn't get nprocs..."); 39 | if (MPI_Comm_rank(MPI_COMM_WORLD, &myrank) != MPI_SUCCESS) quit_error_mpi(myrank, nprocs, (char*)"Couldn't get myrank..."); 40 | double start_time = MPI_Wtime(); 41 | 42 | //............................................................................ 43 | if (myrank==0) fprintf(stdout, "Cleaning results directory...\n"); 44 | string results_directory("./results"); 45 | if (myrank==0) rmdir(results_directory.c_str()); 46 | if (myrank==0) mkdir(results_directory.c_str(), 0777); 47 | 48 | //............................................................................ 49 | if (myrank==0) fprintf(stdout, "Reading input deck...\n"); 50 | InputData_t input_deck; 51 | 52 | //............................................................................ 53 | POD_t pod(input_deck.temporal_correlation_type, input_deck.normalisation, input_deck.dt, input_deck.two_dimensional, 54 | input_deck.snapshot_list_filename, input_deck.snapshot_dir, input_deck.file_name_with_cell_volumes, 55 | input_deck.x_min, input_deck.x_max, input_deck.y_min, input_deck.y_max, input_deck.z_min, input_deck.z_max, 56 | input_deck.spatial_modes_dir); 57 | 58 | long int N_nodes_per_cpu = (long int) round(pod.get_total_number_of_points()/nprocs)+1; 59 | long int first_node_number = myrank*N_nodes_per_cpu; 60 | long int last_node_number = (myrank + 1) * N_nodes_per_cpu - 1; 61 | if (myrank==nprocs-1) last_node_number = pod.get_total_number_of_points() - 1; 62 | pod.set_node_number_range(first_node_number, last_node_number); 63 | 64 | pod.allocate_memory(); 65 | pod.report_memory_usage(myrank); 66 | if (myrank==0) start_time = report_time(start_time,"memory allocation"); 67 | 68 | pod.read_spatial_modes(myrank); 69 | pod.read_mean_field(input_deck.spatial_modes_dir, myrank); 70 | pod.read_rms_field(input_deck.spatial_modes_dir, myrank); 71 | pod.read_spatial_rms_history(input_deck.spatial_modes_dir); 72 | if (myrank==0)pod.write_spatial_rms_history(); 73 | 74 | if (input_deck.test_orthogonality) { 75 | test_spatial_orthogonality_MPI(&pod); 76 | if (myrank==0) start_time = report_time(start_time,"spatial orthogonality tests"); 77 | } 78 | 79 | if (input_deck.test_reconstruction) { 80 | calculate_L2_reconstruction_error_MPI(&pod, input_deck.two_dimensional, myrank); 81 | if (myrank==0) { 82 | pod.write_reconstruction_L2_error(); 83 | pod.calculate_L_infinite_reconstruction_error(); 84 | pod.write_reconstruction_L_infinite_error(); 85 | start_time = report_time(start_time,"reconstruction tests"); 86 | } 87 | } 88 | 89 | //............................................................................ 90 | // finalising MPI 91 | if (MPI_Finalize() != MPI_SUCCESS) quit_error_mpi(myrank, nprocs, (char*)"MPI didn't finalize..."); 92 | 93 | //............................................................................ 94 | return 0; 95 | } 96 | 97 | //---------------------------------------------------------------------------- 98 | double report_time(double start_time, string message) 99 | { 100 | double end_time = MPI_Wtime(); 101 | double elapsed_time = end_time - start_time; 102 | fprintf(stdout,"DURATION %s: sec = %f, min = %f, hours = %f\n", message.c_str(), elapsed_time, elapsed_time/60.0, elapsed_time/3600.0); 103 | return end_time; 104 | } 105 | 106 | //---------------------------------------------------------------------------- 107 | void test_spatial_orthogonality_MPI(POD_t *pod) 108 | { 109 | double norm_this_cpu, norm_all_cpus; 110 | int buffer_count = 1; 111 | for (long int i=0; iget_number_of_modes(); i++) { 112 | for (long int j=0; jget_number_of_modes(); j++) { 113 | norm_this_cpu = pod->test_spatial_orthogonality(i, j); 114 | MPI_Allreduce(&norm_this_cpu, &norm_all_cpus, buffer_count, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); 115 | if (myrank==0) pod->spatial_mode_calculator.norm_check(i, j, norm_all_cpus); 116 | } 117 | } 118 | } 119 | 120 | //---------------------------------------------------------------------------- 121 | void calculate_L2_reconstruction_error_MPI(POD_t *pod, bool two_dimensional, int myrank) 122 | { 123 | double inner_product_this_cpu, p_this_cpu, u_this_cpu, v_this_cpu, w_this_cpu; 124 | double inner_product_all_cpus, p_all_cpus, u_all_cpus, v_all_cpus, w_all_cpus; 125 | double ke; 126 | int buffer_count = 1; 127 | long int first_node_number = pod->get_first_point_number(); 128 | long int last_node_number = pod->get_last_point_number(); 129 | long int num_snapshots = pod->get_number_of_snapshots(); 130 | long int num_modes = pod->get_number_of_modes(); 131 | long int num_points = pod->get_number_of_points(); 132 | 133 | double *inner_products = malloc_1d_array_double(num_points); 134 | Snapshot_Data_t **snapshot = malloc_2d_array_Snapshot_Data_t(num_points,1); 135 | Snapshot_Data_t *pod_reconstruction = malloc_1d_array_Snapshot_Data_t(num_points); 136 | vtkUnstructuredGridReader *reader; 137 | 138 | for (long int snapshot_num=0; snapshot_num < num_snapshots; snapshot_num++) { 139 | 140 | // Read snapshot 141 | fprintf(stdout, "Reading file %ld of %ld name: %s on processor %d for data\n", 142 | snapshot_num+1, num_snapshots, pod->list_of_snapshots[snapshot_num].c_str(), myrank); 143 | reader = vtkUnstructuredGridReader::New(); 144 | reader->SetFileName(pod->list_of_snapshots[snapshot_num].c_str()); 145 | reader->ReadAllScalarsOn(); 146 | reader->ReadAllVectorsOn(); 147 | reader->Update(); 148 | for(long int node = first_node_number; node <= last_node_number; node++) { 149 | snapshot[node-first_node_number][0].p = reader->GetOutput()->GetPointData()->GetScalars("p")->GetComponent(node,0) 150 | - pod->mean_field[node-first_node_number].p; 151 | snapshot[node-first_node_number][0].u = reader->GetOutput()->GetPointData()->GetVectors("u")->GetComponent(node,0) 152 | - pod->mean_field[node-first_node_number].u; 153 | snapshot[node-first_node_number][0].v = reader->GetOutput()->GetPointData()->GetVectors("u")->GetComponent(node,1) 154 | - pod->mean_field[node-first_node_number].v; 155 | snapshot[node-first_node_number][0].w = reader->GetOutput()->GetPointData()->GetVectors("u")->GetComponent(node,2) 156 | - pod->mean_field[node-first_node_number].w; 157 | if(two_dimensional) snapshot[node-first_node_number][0].w = 0.0; 158 | } 159 | reader->Delete(); 160 | 161 | // Reconstruct and scale each mode 162 | ke = SQ(pod->spatial_rms_history[snapshot_num].u) + SQ(pod->spatial_rms_history[snapshot_num].v) + SQ(pod->spatial_rms_history[snapshot_num].w); 163 | for (long int mode_num=0; mode_num < num_modes; mode_num++) { 164 | inner_product_this_cpu = pod->inner_product_calculator.calculate_inner_product(snapshot, pod->spatial_modes, pod->rms_field, 165 | pod->rms_spatial_average, pod->cell_volumes, 0, mode_num); 166 | MPI_Allreduce(&inner_product_this_cpu, &inner_product_all_cpus, buffer_count, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); 167 | inner_products[mode_num] = inner_product_all_cpus; 168 | 169 | pod->field_reconstructor.reconstruct_field(mode_num, inner_products, pod->spatial_modes, pod_reconstruction); 170 | pod->field_reconstructor.calculate_spatial_L2_error(mode_num, snapshot_num, snapshot, pod_reconstruction, pod->cell_volumes, pod->spatial_L2_error); 171 | 172 | u_this_cpu = pod->spatial_L2_error[mode_num][snapshot_num].u; 173 | v_this_cpu = pod->spatial_L2_error[mode_num][snapshot_num].v; 174 | w_this_cpu = pod->spatial_L2_error[mode_num][snapshot_num].w; 175 | p_this_cpu = pod->spatial_L2_error[mode_num][snapshot_num].p; 176 | 177 | MPI_Allreduce(&u_this_cpu, &u_all_cpus, buffer_count, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); 178 | MPI_Allreduce(&v_this_cpu, &v_all_cpus, buffer_count, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); 179 | MPI_Allreduce(&w_this_cpu, &w_all_cpus, buffer_count, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); 180 | MPI_Allreduce(&p_this_cpu, &p_all_cpus, buffer_count, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); 181 | 182 | pod->spatial_L2_error[mode_num][snapshot_num].u = u_all_cpus / ke; 183 | pod->spatial_L2_error[mode_num][snapshot_num].v = v_all_cpus / ke; 184 | pod->spatial_L2_error[mode_num][snapshot_num].w = w_all_cpus / ke; 185 | if (pod->two_dimensional) pod->spatial_L2_error[mode_num][snapshot_num].w = 0.0; 186 | pod->spatial_L2_error[mode_num][snapshot_num].p = p_all_cpus / ke; 187 | } 188 | } 189 | 190 | free_2d_array_Snapshot_Data_t(snapshot, num_points); 191 | free_1d_array_Snapshot_Data_t(pod_reconstruction); 192 | free_1d_array_double(inner_products); 193 | } 194 | 195 | //---------------------------------------------------------------------------- 196 | -------------------------------------------------------------------------------- /drivers/pod_reconstruction_mpi/plotting/plot_eps_one_file.gp: -------------------------------------------------------------------------------- 1 | 2 | # -------------------------------- Ouput settings -------------------------------- 3 | set terminal postscript enhanced font "Times-Roman" 20 4 | set output 'view_output.eps' 5 | 6 | # -------------------------------- L infinite Error -------------------------------- 7 | 8 | set xlabel 'time' 9 | 10 | set title 'L_{\infty} Error for each Mode level reconstruction across all snapshots' 11 | set logscale y 10 12 | set xlabel 'mode' 13 | set ylabel 'max L2 Error' rotate by 90 14 | plot '../results/max_spatial_reconstruction_L2_error.dat' using 1:2 title "u" with linespoints lt 2 pt 2, \ 15 | '../results/max_spatial_reconstruction_L2_error.dat' using 1:3 title "v" with linespoints lt 3 pt 3, \ 16 | '../results/max_spatial_reconstruction_L2_error.dat' using 1:4 title "w" with linespoints lt 4 pt 4, \ 17 | '../results/max_spatial_reconstruction_L2_error.dat' using 1:5 title "pressure" with linespoints lt 5 pt 5, \ 18 | '../results/max_spatial_reconstruction_L2_error.dat' using 1:6 title "total" with linespoints lt 6 pt 6 19 | 20 | 21 | # -------------------------------- Reconstriction L2 Error -------------------------------- 22 | 23 | unset logscale 24 | set xlabel 'time' 25 | set ylabel 'L2 Error' rotate by 90 26 | 27 | set title 'Spatial Reconstruction L2 Error Using 1 Mode' 28 | plot '../results/spatial_reconstruction_L2_error_0001.dat' using 1:2 title "u" with lines lt 2, \ 29 | '../results/spatial_reconstruction_L2_error_0001.dat' using 1:3 title "v" with lines lt 3, \ 30 | '../results/spatial_reconstruction_L2_error_0001.dat' using 1:4 title "w" with lines lt 4, \ 31 | '../results/spatial_reconstruction_L2_error_0001.dat' using 1:5 title "p" with lines lt 5, \ 32 | '../results/spatial_reconstruction_L2_error_0001.dat' using 1:6 title "total" with lines lt 6 33 | 34 | set title 'Spatial Reconstruction L2 Error Using 2 Modes' 35 | plot '../results/spatial_reconstruction_L2_error_0002.dat' using 1:2 title "u" with lines lt 2, \ 36 | '../results/spatial_reconstruction_L2_error_0002.dat' using 1:3 title "v" with lines lt 3, \ 37 | '../results/spatial_reconstruction_L2_error_0002.dat' using 1:4 title "w" with lines lt 4, \ 38 | '../results/spatial_reconstruction_L2_error_0002.dat' using 1:5 title "p" with lines lt 5, \ 39 | '../results/spatial_reconstruction_L2_error_0002.dat' using 1:6 title "total" with lines lt 6 40 | 41 | set title 'Spatial Reconstruction L2 Error Using 3 Modes' 42 | plot '../results/spatial_reconstruction_L2_error_0003.dat' using 1:2 title "u" with lines lt 2, \ 43 | '../results/spatial_reconstruction_L2_error_0003.dat' using 1:3 title "v" with lines lt 3, \ 44 | '../results/spatial_reconstruction_L2_error_0003.dat' using 1:4 title "w" with lines lt 4, \ 45 | '../results/spatial_reconstruction_L2_error_0003.dat' using 1:5 title "p" with lines lt 5, \ 46 | '../results/spatial_reconstruction_L2_error_0003.dat' using 1:6 title "total" with lines lt 6 47 | 48 | set title 'Spatial Reconstruction L2 Error Using 4 Modes' 49 | plot '../results/spatial_reconstruction_L2_error_0004.dat' using 1:2 title "u" with lines lt 2, \ 50 | '../results/spatial_reconstruction_L2_error_0004.dat' using 1:3 title "v" with lines lt 3, \ 51 | '../results/spatial_reconstruction_L2_error_0004.dat' using 1:4 title "w" with lines lt 4, \ 52 | '../results/spatial_reconstruction_L2_error_0004.dat' using 1:5 title "p" with lines lt 5, \ 53 | '../results/spatial_reconstruction_L2_error_0004.dat' using 1:6 title "total" with lines lt 6 54 | 55 | set title 'Spatial Reconstruction L2 Error Using 5 Modes' 56 | plot '../results/spatial_reconstruction_L2_error_0005.dat' using 1:2 title "u" with lines lt 2, \ 57 | '../results/spatial_reconstruction_L2_error_0005.dat' using 1:3 title "v" with lines lt 3, \ 58 | '../results/spatial_reconstruction_L2_error_0005.dat' using 1:4 title "w" with lines lt 4, \ 59 | '../results/spatial_reconstruction_L2_error_0005.dat' using 1:5 title "p" with lines lt 5, \ 60 | '../results/spatial_reconstruction_L2_error_0005.dat' using 1:6 title "total" with lines lt 6 61 | 62 | set title 'Spatial Reconstruction L2 Error Using 6 Modes' 63 | plot '../results/spatial_reconstruction_L2_error_0006.dat' using 1:2 title "u" with lines lt 2, \ 64 | '../results/spatial_reconstruction_L2_error_0006.dat' using 1:3 title "v" with lines lt 3, \ 65 | '../results/spatial_reconstruction_L2_error_0006.dat' using 1:4 title "w" with lines lt 4, \ 66 | '../results/spatial_reconstruction_L2_error_0006.dat' using 1:5 title "p" with lines lt 5, \ 67 | '../results/spatial_reconstruction_L2_error_0006.dat' using 1:6 title "total" with lines lt 6 68 | 69 | set title 'Spatial Reconstruction L2 Error Using 7 Modes' 70 | plot '../results/spatial_reconstruction_L2_error_0007.dat' using 1:2 title "u" with lines lt 2, \ 71 | '../results/spatial_reconstruction_L2_error_0007.dat' using 1:3 title "v" with lines lt 3, \ 72 | '../results/spatial_reconstruction_L2_error_0007.dat' using 1:4 title "w" with lines lt 4, \ 73 | '../results/spatial_reconstruction_L2_error_0007.dat' using 1:5 title "p" with lines lt 5, \ 74 | '../results/spatial_reconstruction_L2_error_0007.dat' using 1:6 title "total" with lines lt 6 75 | 76 | set title 'Spatial Reconstruction L2 Error Using 8 Modes' 77 | plot '../results/spatial_reconstruction_L2_error_0008.dat' using 1:2 title "u" with lines lt 2, \ 78 | '../results/spatial_reconstruction_L2_error_0008.dat' using 1:3 title "v" with lines lt 3, \ 79 | '../results/spatial_reconstruction_L2_error_0008.dat' using 1:4 title "w" with lines lt 4, \ 80 | '../results/spatial_reconstruction_L2_error_0008.dat' using 1:5 title "p" with lines lt 5, \ 81 | '../results/spatial_reconstruction_L2_error_0008.dat' using 1:6 title "total" with lines lt 6 82 | 83 | set title 'Spatial Reconstruction L2 Error Using 9 Modes' 84 | plot '../results/spatial_reconstruction_L2_error_0009.dat' using 1:2 title "u" with lines lt 2, \ 85 | '../results/spatial_reconstruction_L2_error_0009.dat' using 1:3 title "v" with lines lt 3, \ 86 | '../results/spatial_reconstruction_L2_error_0009.dat' using 1:4 title "w" with lines lt 4, \ 87 | '../results/spatial_reconstruction_L2_error_0009.dat' using 1:5 title "p" with lines lt 5, \ 88 | '../results/spatial_reconstruction_L2_error_0009.dat' using 1:6 title "total" with lines lt 6 89 | 90 | set title 'Spatial Reconstruction L2 Error Using 10 Modes' 91 | plot '../results/spatial_reconstruction_L2_error_0010.dat' using 1:2 title "u" with lines lt 2, \ 92 | '../results/spatial_reconstruction_L2_error_0010.dat' using 1:3 title "v" with lines lt 3, \ 93 | '../results/spatial_reconstruction_L2_error_0010.dat' using 1:4 title "w" with lines lt 4, \ 94 | '../results/spatial_reconstruction_L2_error_0010.dat' using 1:5 title "p" with lines lt 5, \ 95 | '../results/spatial_reconstruction_L2_error_0010.dat' using 1:6 title "total" with lines lt 6 96 | 97 | 98 | # -------------------------------- EOF -------------------------------- 99 | -------------------------------------------------------------------------------- /drivers/pod_reconstruction_mpi/plotting/plot_eps_separate_files.gp: -------------------------------------------------------------------------------- 1 | 2 | # -------------------------------- Ouput settings -------------------------------- 3 | set terminal postscript enhanced eps font "Times-Roman" 32 dashlength 3 4 | 5 | # -------------------------------- Max Reconstriction L2 Error -------------------------------- 6 | 7 | set logscale y 10 8 | set xlabel 'mode' 9 | set ylabel 'max L2 Error' rotate by 90 10 | set output './max_spatial_reconstruction_L2_error.eps' 11 | plot '../results/max_spatial_reconstruction_L2_error.dat' using 1:2 title "u" with linespoints lt 2 pt 2, \ 12 | '../results/max_spatial_reconstruction_L2_error.dat' using 1:3 title "v" with linespoints lt 3 pt 3, \ 13 | '../results/max_spatial_reconstruction_L2_error.dat' using 1:4 title "w" with linespoints lt 4 pt 4, \ 14 | '../results/max_spatial_reconstruction_L2_error.dat' using 1:5 title "pressure" with linespoints lt 5 pt 5, \ 15 | '../results/max_spatial_reconstruction_L2_error.dat' using 1:6 title "total" with linespoints lt 6 pt 6 16 | 17 | # -------------------------------- Reconstriction L2 Error -------------------------------- 18 | 19 | unset logscale 20 | set xlabel 'time' 21 | set ylabel 'L2 Error' rotate by 90 22 | 23 | set output './spatial_reconstruction_L2_error_0001.eps' 24 | plot '../results/spatial_reconstruction_L2_error_0001.dat' using 1:2 title "u" with lines lt 2, \ 25 | '../results/spatial_reconstruction_L2_error_0001.dat' using 1:3 title "v" with lines lt 3, \ 26 | '../results/spatial_reconstruction_L2_error_0001.dat' using 1:4 title "w" with lines lt 4, \ 27 | '../results/spatial_reconstruction_L2_error_0001.dat' using 1:5 title "p" with lines lt 5, \ 28 | '../results/spatial_reconstruction_L2_error_0001.dat' using 1:6 title "total" with lines lt 6 29 | 30 | set output './spatial_reconstruction_L2_error_0002.eps' 31 | plot '../results/spatial_reconstruction_L2_error_0002.dat' using 1:2 title "u" with lines lt 2, \ 32 | '../results/spatial_reconstruction_L2_error_0002.dat' using 1:3 title "v" with lines lt 3, \ 33 | '../results/spatial_reconstruction_L2_error_0002.dat' using 1:4 title "w" with lines lt 4, \ 34 | '../results/spatial_reconstruction_L2_error_0002.dat' using 1:5 title "p" with lines lt 5, \ 35 | '../results/spatial_reconstruction_L2_error_0002.dat' using 1:6 title "total" with lines lt 6 36 | 37 | # -------------------------------- EOF -------------------------------- 38 | -------------------------------------------------------------------------------- /drivers/snapshot_pod/Makefile: -------------------------------------------------------------------------------- 1 | # Vassili Kitsios 1/12/2006 2 | # ------------------------- 3 | BASE_DIR = ../.. 4 | include $(BASE_DIR)/Makefile.in 5 | 6 | LIBS = -lm -L$(LIB_DIR)/ $(POD_LIBS) $(UTILS_LIBS) $(VTK_LIBS) $(CLAPACK_LIBS) 7 | INCL = -I$(INCLUDE_DIR)/ $(UTILS_INC) $(VTK_INC) $(CLAPACK_INC) 8 | 9 | # --------Suffixes--------- 10 | .SUFFIXES: .cpp 11 | 12 | .cpp.o: 13 | $(CPP) $(CPPFLAGS) $(LIBS) $(INCL) -c $*.cpp 14 | 15 | .cpp : 16 | $(CPP) $(CPPFLAGS) $(LIBS) $(INCL) -o $< $@ 17 | 18 | # -------Dependencies------ 19 | BIN_NAME = snapshot_pod 20 | INPUT_DECK_NAME = $(BIN_NAME).in 21 | RUN_NAME = $(BIN_NAME).run 22 | 23 | SRC = input_data.cpp main.cpp 24 | 25 | OBJS = $(addsuffix .o, $(basename $(SRC))) 26 | 27 | # -------Make Commands------ 28 | default: $(BIN_NAME) 29 | (mkdir -p $(BASE_DIR)/bin ; mv $(BIN_NAME) ./bin ; cp ./bin/$(BIN_NAME)* $(BASE_DIR)/bin) 30 | 31 | $(BIN_NAME): $(OBJS) 32 | $(CPP) $(CPPFLAGS) -o $@ $(OBJS) $(LIBS) 33 | 34 | clean: 35 | rm -fv ./bin/$(BIN_NAME) $(BASE_DIR)/bin/$(BIN_NAME)* ~/bin/$(BIN_NAME)* *.o *~ ._* ./bin/*~ 36 | 37 | # This automatically updates all the dependencies shown below 38 | depend: 39 | makedepend -Y $(SRC) 40 | 41 | -------------------------------------------------------------------------------- /drivers/snapshot_pod/bin/snapshot_pod.in: -------------------------------------------------------------------------------- 1 | #---------------------------------------- 2 | # Snapshot POD input deck 3 | #---------------------------------------- 4 | 5 | #shear region 6 | x_min = -0.05 7 | x_max = 0.25 8 | y_min = -0.105 9 | y_max = 0.145 10 | z_min = -10.0 11 | z_max = 10.0 12 | 13 | #temporal_correlation_type = u 14 | #temporal_correlation_type = v 15 | #temporal_correlation_type = w 16 | temporal_correlation_type = ke 17 | #temporal_correlation_type = p 18 | #temporal_correlation_type = q 19 | 20 | normalisation = none 21 | #normalisation = local 22 | #normalisation = global 23 | 24 | snapshot_list_filename = ../snapshots/data_files.100T.list 25 | snapshot_dir = ../snapshots/ 26 | file_name_with_cell_volumes = ../snapshots/cell_volumes.vtk 27 | 28 | restart = false 29 | #restart = ./restart 30 | 31 | two_dimensional = true 32 | test_orthogonality = true 33 | check_eigensolution = false 34 | 35 | dt = 0.002 36 | 37 | threshhold_energy = 99.9 38 | min_number_of_eigenvalues = 10 39 | max_number_of_eigenvalues = 20 40 | 41 | #---------------------------------- 42 | # End of Deck 43 | #---------------------------------- 44 | 45 | -------------------------------------------------------------------------------- /drivers/snapshot_pod/bin/snapshot_pod.run: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # ---------------------------------------------------------------------------- 4 | # Some important filenames: 5 | PROGRAM="snapshot_pod" 6 | OUTPUT_FILE=${PROGRAM}".out" 7 | ERROR_FILE=${PROGRAM}".err" 8 | 9 | PROGRAM_BASE_DIR="/Users/vas/Documents/3Coding/4Analysis_codes/drivers/POD" 10 | PROGRAM_BIN_DIR=$PROGRAM_BASE_DIR/$PROGRAM"/bin" 11 | GNU_PLOT_FILES_DIR=$PROGRAM_BASE_DIR/$PROGRAM"/plotting" 12 | GNU_PLOT_ONE_EPS_FILE="plot_eps_one_file.gp" 13 | GNU_PLOT_SEPARATE_EPS_FILES="plot_eps_separate_files.gp" 14 | 15 | RESULTS_DIR="./results" 16 | IMAGES_DIR="./images" 17 | 18 | # ---------------------------------------------------------------------------- 19 | # Organise files: 20 | rm -vrf $PROGRAM $OUTPUT_FILE $ERROR_FILE $RESULTS_DIR $IMAGES_DIR *~ 21 | cp $PROGRAM_BIN_DIR/$PROGRAM . 22 | 23 | mkdir $RESULTS_DIR $IMAGES_DIR 24 | cp $GNU_PLOT_FILES_DIR/$GNU_PLOT_ONE_EPS_FILE $IMAGES_DIR 25 | cp $GNU_PLOT_FILES_DIR/$GNU_PLOT_SEPARATE_EPS_FILES $IMAGES_DIR 26 | 27 | # ---------------------------------------------------------------------------- 28 | # Running code: 29 | #$PROGRAM 1>${PROGRAM}.out 2> ${PROGRAM}.err 30 | ./$PROGRAM 31 | 32 | # ---------------------------------------------------------------------------- 33 | # Generate images: 34 | echo "Generating images..." 35 | cd $IMAGES_DIR 36 | gnuplot $GNU_PLOT_ONE_EPS_FILE 37 | gnuplot $GNU_PLOT_SEPARATE_EPS_FILES 38 | cd .. 39 | echo "done." 40 | echo " " 41 | 42 | # ---------------------------------------------------------------------------- 43 | -------------------------------------------------------------------------------- /drivers/snapshot_pod/input_data.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Utils.h" 3 | #include "input_data.h" 4 | 5 | //------------------------------------------------------------------------- 6 | InputData_t::InputData_t() 7 | { 8 | ParamListHead_t param_list_head; 9 | 10 | param_list_head.get_params_from_file((char*)"snapshot_pod.in"); 11 | param_list_head.print_params(); 12 | 13 | temporal_correlation_type = param_list_head.get_string_param((char*)"temporal_correlation_type"); 14 | normalisation = param_list_head.get_string_param((char*)"normalisation"); 15 | 16 | snapshot_list_filename = param_list_head.get_string_param((char*)"snapshot_list_filename"); 17 | snapshot_dir = param_list_head.get_string_param((char*)"snapshot_dir"); 18 | file_name_with_cell_volumes = param_list_head.get_string_param((char*)"file_name_with_cell_volumes"); 19 | 20 | dt = param_list_head.get_double_param((char*)"dt"); 21 | 22 | char *test_orthogonality_char; 23 | test_orthogonality_char = param_list_head.get_string_param((char*)"test_orthogonality"); 24 | if (strcmp(test_orthogonality_char,"true")==0) { 25 | test_orthogonality = true; 26 | } else if (strcmp(test_orthogonality_char,"false")==0) { 27 | test_orthogonality = false; 28 | } else { 29 | quit_error((char*)" = 'true' or 'false'\n"); 30 | } 31 | 32 | char *check_eigensolution_char; 33 | check_eigensolution_char = param_list_head.get_string_param((char*)"check_eigensolution"); 34 | if (strcmp(check_eigensolution_char,"true")==0) { 35 | check_eigensolution = true; 36 | } else if (strcmp(check_eigensolution_char,"false")==0) { 37 | check_eigensolution = false; 38 | } else { 39 | quit_error((char*)" = 'true' or 'false'\n"); 40 | } 41 | 42 | restart = param_list_head.get_string_param((char*)"restart"); 43 | 44 | threshhold_energy = param_list_head.get_double_param((char*)"threshhold_energy"); 45 | min_number_of_eigenvalues = param_list_head.get_int_param((char*)"min_number_of_eigenvalues"); 46 | max_number_of_eigenvalues = param_list_head.get_int_param((char*)"max_number_of_eigenvalues"); 47 | 48 | two_dimensional = param_list_head.get_string_param((char*)"two_dimensional"); 49 | 50 | x_min = param_list_head.get_double_param((char*) "x_min"); 51 | x_max = param_list_head.get_double_param((char*) "x_max"); 52 | y_min = param_list_head.get_double_param((char*) "y_min"); 53 | y_max = param_list_head.get_double_param((char*) "y_max"); 54 | z_min = param_list_head.get_double_param((char*) "z_min"); 55 | z_max = param_list_head.get_double_param((char*) "z_max"); 56 | } 57 | 58 | //------------------------------------------------------------------------- 59 | InputData_t::~InputData_t() 60 | { 61 | } 62 | -------------------------------------------------------------------------------- /drivers/snapshot_pod/input_data.h: -------------------------------------------------------------------------------- 1 | 2 | //============================================================================ 3 | // InputData_t 4 | //============================================================================ 5 | class InputData_t 6 | { 7 | private: 8 | //------------------------------------------------------------------------- 9 | public: 10 | //------------------------------------------------------------------------- 11 | // variables 12 | //------------------------------------------------------------------------- 13 | double x_min; // Domain of interest 14 | double x_max; 15 | double y_min; 16 | double y_max; 17 | double z_min; 18 | double z_max; 19 | 20 | char *snapshot_list_filename; // file containing list of snapshot files 21 | char *snapshot_dir; // location of snapshots 22 | char *file_name_with_cell_volumes; // file number with cell volumes, first file number is 0 23 | 24 | char *two_dimensional; // if data is 2D "true" or "false" 25 | char *temporal_correlation_type; // u, v, w, p, ke, q 26 | char *normalisation; // none local global 27 | char *restart; // 'false' or location of the temporal correlations file 28 | double dt; // time between each snapshot - assuming constant dt 29 | 30 | bool test_orthogonality; 31 | bool check_eigensolution; 32 | 33 | double threshhold_energy; 34 | int min_number_of_eigenvalues; 35 | int max_number_of_eigenvalues; 36 | 37 | //------------------------------------------------------------------------- 38 | // functions 39 | //------------------------------------------------------------------------- 40 | InputData_t(); 41 | //------------------------------------------------------------------------- 42 | ~InputData_t(); 43 | //------------------------------------------------------------------------- 44 | }; 45 | 46 | -------------------------------------------------------------------------------- /drivers/snapshot_pod/main.cpp: -------------------------------------------------------------------------------- 1 | /*========================================================================= 2 | snapshot_pod 3 | ========================================================================= 4 | 5 | This program performs the snapshot POD analysis. The snapshots are 6 | binary vtk files and the output eigenmodes are written as binary vtk files 7 | 8 | =========================================================================*/ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include "Utils.h" 15 | #include "PodUtils.h" 16 | #include "input_data.h" 17 | 18 | //---------------------------------------------------------------------------- 19 | int main(int argc, char *argv[]) 20 | { 21 | //............................................................................ 22 | cout << "Cleaning results directory..." << endl; 23 | string results_directory("./results"); rmdir(results_directory.c_str()); mkdir(results_directory.c_str(), 0777); 24 | 25 | //............................................................................ 26 | cout << "Reading input deck..." << endl; 27 | InputData_t input_deck; 28 | 29 | //............................................................................ 30 | POD_t pod(input_deck.temporal_correlation_type, input_deck.normalisation, input_deck.dt, input_deck.two_dimensional, 31 | input_deck.snapshot_list_filename, input_deck.snapshot_dir, input_deck.file_name_with_cell_volumes, 32 | input_deck.x_min, input_deck.x_max, input_deck.y_min, input_deck.y_max, input_deck.z_min, input_deck.z_max, 33 | "none"); // Needed for reconstruction code 34 | 35 | pod.allocate_memory(); 36 | pod.report_memory_usage(); 37 | 38 | pod.read_temporal_correlations(input_deck.restart); 39 | pod.read_snapshots(); 40 | 41 | pod.calculate_temporal_mean(); 42 | pod.write_mean_field(); 43 | 44 | pod.subtract_temporal_mean_from_snapshots(); 45 | pod.write_first_snapshot_unsteady_component(); 46 | 47 | pod.calculate_temporal_rms(); 48 | pod.write_rms_field(); 49 | 50 | pod.calculate_spatial_rms_history(); 51 | pod.write_spatial_rms_history(); 52 | 53 | pod.calculate_spatial_average_of_temporal_rms(); 54 | pod.write_rms_spatial_average(); 55 | 56 | pod.calculate_and_write_temporal_correlations(); 57 | 58 | pod.calculate_and_scale_eigenvalues(input_deck.check_eigensolution); 59 | pod.calculate_number_of_modes_for_threshhold_energy(input_deck.threshhold_energy, 60 | input_deck.min_number_of_eigenvalues, input_deck.max_number_of_eigenvalues); 61 | pod.write_eigenvalues(); 62 | 63 | pod.calculate_and_scale_temporal_modes(); 64 | if (input_deck.test_orthogonality) pod.test_temporal_orthogonality(); 65 | pod.write_temporal_modes(); 66 | 67 | pod.calculate_and_write_spatial_modes(); 68 | 69 | pod.write_summary(); 70 | 71 | //............................................................................ 72 | return 0; 73 | } 74 | 75 | //---------------------------------------------------------------------------- 76 | -------------------------------------------------------------------------------- /drivers/snapshot_pod/plotting/plot_eps_one_file.gp: -------------------------------------------------------------------------------- 1 | # 2 | # gnuplot> load 'plot_snapshot_pod_results_eps.gp' 3 | # 4 | 5 | 6 | # -------------------------------- Ouput settings -------------------------------- 7 | set terminal postscript enhanced font "Times-Roman" 20 8 | set output 'view_output.eps' 9 | 10 | 11 | # -------------------------------- Eigenvalues -------------------------------- 12 | 13 | set title 'Snapshot POD eigenvalues' 14 | set logscale y 10 15 | set logscale y2 10 16 | set xlabel 'mode' 17 | set ylabel 'energy' rotate by 90 18 | set y2label 'cumulative energy' rotate by 90 19 | set ytics nomirror 20 | set y2tics nomirror 21 | plot '../results/eigenvalues.dat' using 1:3 title "eigenvalues" with linespoints lt 1 pt 1 axes x1y1, \ 22 | '../results/eigenvalues.dat' using 1:4 title "cumulative" with linespoints lt 2 pt 2 axes x1y2 23 | 24 | 25 | # -------------------------------- Temporal Modes -------------------------------- 26 | 27 | unset logscale 28 | set xlabel 'time' 29 | set ylabel 'fourier coefficients' rotate by 90 30 | 31 | set title 'Snapshot POD temporal modes 1 and 2' 32 | plot '../results/temporal_mode_0001.dat' using 1:2 title "mode 1" with lines lt 1, '../results/temporal_mode_0002.dat' using 1:2 title "mode 2" with lines lt 2 33 | 34 | set title 'Snapshot POD temporal modes 3 and 4' 35 | plot '../results/temporal_mode_0003.dat' using 1:2 title "mode 3" with lines lt 1, '../results/temporal_mode_0004.dat' using 1:2 title "mode 4" with lines lt 2 36 | 37 | set title 'Snapshot POD temporal modes 5 and 6' 38 | plot '../results/temporal_mode_0005.dat' using 1:2 title "mode 5" with lines lt 1, '../results/temporal_mode_0006.dat' using 1:2 title "mode 6" with lines lt 2 39 | 40 | set title 'Snapshot POD temporal modes 7 and 8' 41 | plot '../results/temporal_mode_0007.dat' using 1:2 title "mode 7" with lines lt 1, '../results/temporal_mode_0008.dat' using 1:2 title "mode 8" with lines lt 2 42 | 43 | set title 'Snapshot POD temporal modes 9 and 10' 44 | plot '../results/temporal_mode_0009.dat' using 1:2 title "mode 9" with lines lt 1, '../results/temporal_mode_0010.dat' using 1:2 title "mode 10" with lines lt 2 45 | 46 | # -------------------------------- EOF -------------------------------- 47 | -------------------------------------------------------------------------------- /drivers/snapshot_pod/plotting/plot_eps_separate_files.gp: -------------------------------------------------------------------------------- 1 | 2 | # -------------------------------- Ouput settings -------------------------------- 3 | set terminal postscript enhanced eps font "Times-Roman" 32 dashlength 3 4 | 5 | # -------------------------------- Eigenvalues -------------------------------- 6 | 7 | set output './eigenvalues.eps' 8 | set logscale y 10 9 | set logscale y2 10 10 | set xlabel 'mode' 11 | set ylabel 'energy' rotate by 90 12 | set y2label 'cumulative energy' rotate by 90 13 | set ytics nomirror 14 | set y2tics nomirror 15 | plot '../results/eigenvalues.dat' using 1:3 title "eigenvalues" with linespoints lt 1 pt 1 axes x1y1, \ 16 | '../results/eigenvalues.dat' using 1:4 title "cumulative" with linespoints lt 2 pt 2 axes x1y2 17 | 18 | # -------------------------------- Temporal Modes -------------------------------- 19 | 20 | unset logscale 21 | set xlabel 'time' 22 | set ylabel 'fourier coefficients' rotate by 90 23 | unset y2label 24 | unset y2tics 25 | set ytics mirror 26 | 27 | set output './temporal_modes_0001_0002.eps' 28 | plot '../results/temporal_mode_0001.dat' using 1:2 title "mode 1" with lines lt 1, '../results/temporal_mode_0002.dat' using 1:2 title "mode 2" with lines lt 2 29 | 30 | set output './temporal_modes_0003_0004.eps' 31 | plot '../results/temporal_mode_0003.dat' using 1:2 title "mode 3" with lines lt 1, '../results/temporal_mode_0004.dat' using 1:2 title "mode 4" with lines lt 2 32 | 33 | set output './temporal_modes_0005_0006.eps' 34 | plot '../results/temporal_mode_0005.dat' using 1:2 title "mode 5" with lines lt 1, '../results/temporal_mode_0006.dat' using 1:2 title "mode 6" with lines lt 2 35 | 36 | set output './temporal_modes_0007_0008.eps' 37 | plot '../results/temporal_mode_0007.dat' using 1:2 title "mode 7" with lines lt 1, '../results/temporal_mode_0008.dat' using 1:2 title "mode 8" with lines lt 2 38 | 39 | set output './temporal_modes_0009_0010.eps' 40 | plot '../results/temporal_mode_0009.dat' using 1:2 title "mode 9" with lines lt 1, '../results/temporal_mode_0010.dat' using 1:2 title "mode 10" with lines lt 2 41 | 42 | # -------------------------------- EOF -------------------------------- 43 | -------------------------------------------------------------------------------- /drivers/snapshot_pod_mpi/Makefile: -------------------------------------------------------------------------------- 1 | # Vassili Kitsios 1/12/2006 2 | # ------------------------- 3 | BASE_DIR = ../.. 4 | include $(BASE_DIR)/Makefile.in 5 | 6 | LIBS = $(MPI_LIBS) -lm -L$(LIB_DIR)/ $(POD_LIBS) $(UTILS_LIBS) $(VTK_LIBS) $(CLAPACK_LIBS) 7 | INCL = $(MPI_INC) -I$(INCLUDE_DIR)/ $(UTILS_INC) $(VTK_INC) $(CLAPACK_INC) 8 | 9 | CPP=$(MPI_CPP) 10 | 11 | # --------Suffixes--------- 12 | .SUFFIXES: .cpp 13 | 14 | .cpp.o: 15 | $(CPP) $(CPPFLAGS) $(LIBS) $(INCL) -c $*.cpp 16 | 17 | .cpp : 18 | $(CPP) $(CPPFLAGS) $(LIBS) $(INCL) -o $< $@ 19 | 20 | # -------Dependencies------ 21 | BIN_NAME = snapshot_pod_mpi 22 | INPUT_DECK_NAME = $(BIN_NAME).in 23 | RUN_NAME = $(BIN_NAME).run 24 | 25 | SRC = input_data.cpp main.cpp 26 | 27 | OBJS = $(addsuffix .o, $(basename $(SRC))) 28 | 29 | # -------Make Commands------ 30 | default: $(BIN_NAME) 31 | (mkdir -p $(BASE_DIR)/bin ; mv $(BIN_NAME) ./bin ; cp ./bin/$(BIN_NAME)* $(BASE_DIR)/bin) 32 | 33 | 34 | $(BIN_NAME): $(OBJS) 35 | $(CPP) $(CPPFLAGS) -o $@ $(OBJS) $(LIBS) 36 | 37 | clean: 38 | rm -fv ./bin/$(BIN_NAME) $(BASE_DIR)/bin/$(BIN_NAME)* ~/bin/$(BIN_NAME)* *.o *~ ._* ./bin/*~ 39 | 40 | # This automatically updates all the dependencies shown below 41 | depend: 42 | makedepend -Y $(SRC) 43 | 44 | -------------------------------------------------------------------------------- /drivers/snapshot_pod_mpi/bin/snapshot_pod_mpi.in: -------------------------------------------------------------------------------- 1 | #---------------------------------------- 2 | # Snapshot POD input deck 3 | #---------------------------------------- 4 | 5 | #shear region 6 | x_min = -0.05 7 | x_max = 0.25 8 | y_min = -0.105 9 | y_max = 0.145 10 | z_min = -10.0 11 | z_max = 10.0 12 | 13 | #temporal_correlation_type = u 14 | #temporal_correlation_type = v 15 | #temporal_correlation_type = w 16 | temporal_correlation_type = ke 17 | #temporal_correlation_type = p 18 | #temporal_correlation_type = q 19 | 20 | normalisation = none 21 | #normalisation = local 22 | #normalisation = global 23 | 24 | snapshot_list_filename = ../snapshots/data_files.100T.list 25 | snapshot_dir = ../snapshots/ 26 | file_name_with_cell_volumes = ../snapshots/cell_volumes.vtk 27 | 28 | restart = false 29 | #restart = ./restart 30 | 31 | two_dimensional = true 32 | test_orthogonality = true 33 | check_eigensolution = false 34 | 35 | dt = 0.002 36 | 37 | threshhold_energy = 99.9 38 | min_number_of_eigenvalues = 10 39 | max_number_of_eigenvalues = 20 40 | 41 | #---------------------------------- 42 | # End of Deck 43 | #---------------------------------- 44 | 45 | -------------------------------------------------------------------------------- /drivers/snapshot_pod_mpi/bin/snapshot_pod_mpi.run: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # ---------------------------------------------------------------------------- 4 | # Some important filenames: 5 | PROGRAM="snapshot_pod_mpi" 6 | OUTPUT_FILE=${PROGRAM}".out" 7 | ERROR_FILE=${PROGRAM}".err" 8 | 9 | PROGRAM_BASE_DIR="/Users/vas/Documents/3Coding/4Analysis_codes/drivers/POD" 10 | PROGRAM_BIN_DIR=$PROGRAM_BASE_DIR/$PROGRAM"/bin" 11 | GNU_PLOT_FILES_DIR=$PROGRAM_BASE_DIR/$PROGRAM"/plotting" 12 | GNU_PLOT_ONE_EPS_FILE="plot_eps_one_file.gp" 13 | GNU_PLOT_SEPARATE_EPS_FILES="plot_eps_separate_files.gp" 14 | 15 | RESULTS_DIR="./results" 16 | IMAGES_DIR="./images" 17 | 18 | # ---------------------------------------------------------------------------- 19 | # Organise files: 20 | rm -vrf $PROGRAM $OUTPUT_FILE $ERROR_FILE $RESULTS_DIR $IMAGES_DIR *~ 21 | cp $PROGRAM_BIN_DIR/$PROGRAM . 22 | 23 | mkdir $RESULTS_DIR $IMAGES_DIR 24 | cp $GNU_PLOT_FILES_DIR/$GNU_PLOT_ONE_EPS_FILE $IMAGES_DIR 25 | cp $GNU_PLOT_FILES_DIR/$GNU_PLOT_SEPARATE_EPS_FILES $IMAGES_DIR 26 | 27 | # ---------------------------------------------------------------------------- 28 | # Running code: 29 | #$PROGRAM 1>${PROGRAM}.out 2> ${PROGRAM}.err 30 | ./$PROGRAM 31 | 32 | # ---------------------------------------------------------------------------- 33 | # Generate images: 34 | echo "Generating images..." 35 | cd $IMAGES_DIR 36 | gnuplot $GNU_PLOT_ONE_EPS_FILE 37 | gnuplot $GNU_PLOT_SEPARATE_EPS_FILES 38 | cd .. 39 | echo "done." 40 | echo " " 41 | 42 | # ---------------------------------------------------------------------------- 43 | -------------------------------------------------------------------------------- /drivers/snapshot_pod_mpi/input_data.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Utils.h" 3 | #include "input_data.h" 4 | 5 | //------------------------------------------------------------------------- 6 | InputData_t::InputData_t() 7 | { 8 | ParamListHead_t param_list_head; 9 | 10 | param_list_head.get_params_from_file((char*)"snapshot_pod_mpi.in"); 11 | param_list_head.print_params(); 12 | 13 | temporal_correlation_type = param_list_head.get_string_param((char*)"temporal_correlation_type"); 14 | normalisation = param_list_head.get_string_param((char*)"normalisation"); 15 | 16 | snapshot_list_filename = param_list_head.get_string_param((char*)"snapshot_list_filename"); 17 | snapshot_dir = param_list_head.get_string_param((char*)"snapshot_dir"); 18 | file_name_with_cell_volumes = param_list_head.get_string_param((char*)"file_name_with_cell_volumes"); 19 | 20 | char *test_orthogonality_char; 21 | test_orthogonality_char = param_list_head.get_string_param((char*)"test_orthogonality"); 22 | if (strcmp(test_orthogonality_char,"true")==0) { 23 | test_orthogonality = true; 24 | } else if (strcmp(test_orthogonality_char,"false")==0) { 25 | test_orthogonality = false; 26 | } else { 27 | quit_error((char*)" = 'true' or 'false'\n"); 28 | } 29 | 30 | char *check_eigensolution_char; 31 | check_eigensolution_char = param_list_head.get_string_param((char*)"check_eigensolution"); 32 | if (strcmp(check_eigensolution_char,"true")==0) { 33 | check_eigensolution = true; 34 | } else if (strcmp(check_eigensolution_char,"false")==0) { 35 | check_eigensolution = false; 36 | } else { 37 | quit_error((char*)" = 'true' or 'false'\n"); 38 | } 39 | 40 | restart = param_list_head.get_string_param((char*)"restart"); 41 | 42 | dt = param_list_head.get_double_param((char*)"dt"); 43 | 44 | threshhold_energy = param_list_head.get_double_param((char*)"threshhold_energy"); 45 | min_number_of_eigenvalues = param_list_head.get_int_param((char*)"min_number_of_eigenvalues"); 46 | max_number_of_eigenvalues = param_list_head.get_int_param((char*)"max_number_of_eigenvalues"); 47 | 48 | two_dimensional = param_list_head.get_string_param((char*)"two_dimensional"); 49 | 50 | x_min = param_list_head.get_double_param((char*) "x_min"); 51 | x_max = param_list_head.get_double_param((char*) "x_max"); 52 | y_min = param_list_head.get_double_param((char*) "y_min"); 53 | y_max = param_list_head.get_double_param((char*) "y_max"); 54 | z_min = param_list_head.get_double_param((char*) "z_min"); 55 | z_max = param_list_head.get_double_param((char*) "z_max"); 56 | } 57 | 58 | //------------------------------------------------------------------------- 59 | InputData_t::~InputData_t() 60 | { 61 | } 62 | -------------------------------------------------------------------------------- /drivers/snapshot_pod_mpi/input_data.h: -------------------------------------------------------------------------------- 1 | 2 | //============================================================================ 3 | // InputData_t 4 | //============================================================================ 5 | class InputData_t 6 | { 7 | private: 8 | //------------------------------------------------------------------------- 9 | public: 10 | //------------------------------------------------------------------------- 11 | // variables 12 | //------------------------------------------------------------------------- 13 | double x_min; // Domain of interest 14 | double x_max; 15 | double y_min; 16 | double y_max; 17 | double z_min; 18 | double z_max; 19 | 20 | char *snapshot_list_filename; // file containing list of snapshot files 21 | char *snapshot_dir; // location of snapshots 22 | char *file_name_with_cell_volumes; // file number with cell volumes, first file number is 0 23 | 24 | char *two_dimensional; // if data is 2D "true" or "false" 25 | char *temporal_correlation_type; // u, v, w, p, ke, q 26 | char *normalisation; // none local global 27 | char *restart; // 'false' or location of the temporal correlations file 28 | double dt; // time between each snapshot - assuming constant dt 29 | 30 | bool test_orthogonality; 31 | bool check_eigensolution; 32 | 33 | double threshhold_energy; 34 | int min_number_of_eigenvalues; 35 | int max_number_of_eigenvalues; 36 | 37 | //------------------------------------------------------------------------- 38 | // functions 39 | //------------------------------------------------------------------------- 40 | InputData_t(); 41 | //------------------------------------------------------------------------- 42 | ~InputData_t(); 43 | //------------------------------------------------------------------------- 44 | }; 45 | 46 | -------------------------------------------------------------------------------- /drivers/snapshot_pod_mpi/plotting/plot_eps_one_file.gp: -------------------------------------------------------------------------------- 1 | # 2 | # gnuplot> load 'plot_snapshot_pod_results_eps.gp' 3 | # 4 | 5 | 6 | # -------------------------------- Ouput settings -------------------------------- 7 | set terminal postscript enhanced font "Times-Roman" 20 8 | set output 'view_output.eps' 9 | 10 | 11 | # -------------------------------- Eigenvalues -------------------------------- 12 | 13 | set title 'Snapshot POD eigenvalues' 14 | set logscale y 10 15 | set logscale y2 10 16 | set xlabel 'mode' 17 | set ylabel 'energy' rotate by 90 18 | set y2label 'cumulative energy' rotate by 90 19 | set ytics nomirror 20 | set y2tics nomirror 21 | plot '../results/eigenvalues.dat' using 1:3 title "eigenvalues" with linespoints lt 1 pt 1 axes x1y1, \ 22 | '../results/eigenvalues.dat' using 1:4 title "cumulative" with linespoints lt 2 pt 2 axes x1y2 23 | 24 | 25 | # -------------------------------- Temporal Modes -------------------------------- 26 | 27 | unset logscale 28 | set xlabel 'time' 29 | set ylabel 'fourier coefficients' rotate by 90 30 | 31 | set title 'Snapshot POD temporal modes 1 and 2' 32 | plot '../results/temporal_mode_0001.dat' using 1:2 title "mode 1" with lines lt 1, '../results/temporal_mode_0002.dat' using 1:2 title "mode 2" with lines lt 2 33 | 34 | set title 'Snapshot POD temporal modes 3 and 4' 35 | plot '../results/temporal_mode_0003.dat' using 1:2 title "mode 3" with lines lt 1, '../results/temporal_mode_0004.dat' using 1:2 title "mode 4" with lines lt 2 36 | 37 | set title 'Snapshot POD temporal modes 5 and 6' 38 | plot '../results/temporal_mode_0005.dat' using 1:2 title "mode 5" with lines lt 1, '../results/temporal_mode_0006.dat' using 1:2 title "mode 6" with lines lt 2 39 | 40 | set title 'Snapshot POD temporal modes 7 and 8' 41 | plot '../results/temporal_mode_0007.dat' using 1:2 title "mode 7" with lines lt 1, '../results/temporal_mode_0008.dat' using 1:2 title "mode 8" with lines lt 2 42 | 43 | set title 'Snapshot POD temporal modes 9 and 10' 44 | plot '../results/temporal_mode_0009.dat' using 1:2 title "mode 9" with lines lt 1, '../results/temporal_mode_0010.dat' using 1:2 title "mode 10" with lines lt 2 45 | 46 | # -------------------------------- EOF -------------------------------- 47 | -------------------------------------------------------------------------------- /drivers/snapshot_pod_mpi/plotting/plot_eps_separate_files.gp: -------------------------------------------------------------------------------- 1 | 2 | # -------------------------------- Ouput settings -------------------------------- 3 | set terminal postscript enhanced eps font "Times-Roman" 32 dashlength 3 4 | 5 | # -------------------------------- Eigenvalues -------------------------------- 6 | 7 | set output './eigenvalues.eps' 8 | set logscale y 10 9 | set logscale y2 10 10 | set xlabel 'mode' 11 | set ylabel 'energy' rotate by 90 12 | set y2label 'cumulative energy' rotate by 90 13 | set ytics nomirror 14 | set y2tics nomirror 15 | plot '../results/eigenvalues.dat' using 1:3 title "eigenvalues" with linespoints lt 1 pt 1 axes x1y1, \ 16 | '../results/eigenvalues.dat' using 1:4 title "cumulative" with linespoints lt 2 pt 2 axes x1y2 17 | 18 | # -------------------------------- Temporal Modes -------------------------------- 19 | 20 | unset logscale 21 | set xlabel 'time' 22 | set ylabel 'fourier coefficients' rotate by 90 23 | unset y2label 24 | unset y2tics 25 | set ytics mirror 26 | 27 | set output './temporal_modes_0001_0002.eps' 28 | plot '../results/temporal_mode_0001.dat' using 1:2 title "mode 1" with lines lt 1, '../results/temporal_mode_0002.dat' using 1:2 title "mode 2" with lines lt 2 29 | 30 | set output './temporal_modes_0003_0004.eps' 31 | plot '../results/temporal_mode_0003.dat' using 1:2 title "mode 3" with lines lt 1, '../results/temporal_mode_0004.dat' using 1:2 title "mode 4" with lines lt 2 32 | 33 | set output './temporal_modes_0005_0006.eps' 34 | plot '../results/temporal_mode_0005.dat' using 1:2 title "mode 5" with lines lt 1, '../results/temporal_mode_0006.dat' using 1:2 title "mode 6" with lines lt 2 35 | 36 | set output './temporal_modes_0007_0008.eps' 37 | plot '../results/temporal_mode_0007.dat' using 1:2 title "mode 7" with lines lt 1, '../results/temporal_mode_0008.dat' using 1:2 title "mode 8" with lines lt 2 38 | 39 | set output './temporal_modes_0009_0010.eps' 40 | plot '../results/temporal_mode_0009.dat' using 1:2 title "mode 9" with lines lt 1, '../results/temporal_mode_0010.dat' using 1:2 title "mode 10" with lines lt 2 41 | 42 | # -------------------------------- EOF -------------------------------- 43 | -------------------------------------------------------------------------------- /makefiles/Makefile.MacBook.in: -------------------------------------------------------------------------------- 1 | # Vassili Kitsios 27/02/2007 2 | SYSTEM_NAME = MACBOOK 3 | 4 | # ---------------------------------------------------------------------------- 5 | CPP = g++ 6 | MPI_CPP = mpicxx 7 | 8 | # ---------------------------------------------------------------------------- 9 | #CPPFLAGS = -O0 -Wall -ansi -pedantic -DDEBUG 10 | CPPFLAGS = -O0 11 | #CPPFLAGS = -O0 -Wall -ansi -Wno-deprecated 12 | # CPPFLAGS = -O0 -Wall -ansi -pedantic 13 | #CPPFLAGS = -O2 -Wall -ansi -pedantic 14 | # CPPFLAGS = -O1 -Wall -ansi -pedantic 15 | # CPPFLAGS = -O3 -Wall -ansi -pedantic 16 | 17 | # ---------------------------------------------------------------------------- 18 | # ar - create, modify, and extract from archives 19 | # r = insert file into archive 20 | # c = create archive if necessary 21 | # v = verbose 22 | AR = ar rcv 23 | 24 | # ---------------------------------------------------------------------------- 25 | # Library Locations 26 | 27 | VTK_LIBS_DIR = /usr/local/libs/vtk-5.4 28 | VTK_INC_DIR = /usr/local/include/vtk-5.4 29 | VTK_LIBS = -L$(VTK_LIBS_DIR) -lvtkCommon -lvtkDICOMParser -lvtkFiltering -lvtkGenericFiltering -lvtkGraphics -lvtkHybrid -lvtkIO -lvtkImaging -lvtkNetCDF -lvtkRendering -lvtkVolumeRendering -lvtkWidgets -lvtkexoIIc -lvtkexpat -lvtkfreetype -lvtkftgl -lvtkjpeg -lvtkpng -lvtksys -lvtktiff -lvtkzlib 30 | VTK_INC = -I$(VTK_INC_DIR)/ -I$(VTK_INC_DIR)/Common -I$(VTK_INC_DIR)/Filtering -I$(VTK_INC_DIR)/Rendering -I$(VTK_INC_DIR)/Graphics -I$(VTK_INC_DIR)/Imaging -I$(VTK_INC_DIR)/IO -I$(VTK_INC_DIR)/VolumeRendering -I$(VTK_INC_DIR)/Hybrid -I$(VTK_INC_DIR)/Widgets -I$(VTK_INC_DIR)/Parallel -I$(VTK_INC_DIR)/GenericFiltering 31 | 32 | FFTW_LIBS = -lfftw3 33 | 34 | CLAPACK_DIR = /usr/local 35 | CLAPACK_LIBS = -L$(CLAPACK_DIR)/lib -lc -lctmg -lclapack -lcblas -lF77 -lI77 36 | CLAPACK_INC = -I$(CLAPACK_DIR)/include 37 | 38 | MPI_DIR = /usr/local 39 | MPI_LIBS = -L$(MPI_DIR)/lib -lmpich 40 | MPI_INC = -I$(MPI_DIR)/include 41 | 42 | # ---------------------------------------------------------------------------- 43 | # My library Locations 44 | 45 | BASE_DIR = /home/kit027/transition_codes 46 | INCLUDE_DIR = $(BASE_DIR)/include 47 | LIB_DIR = $(BASE_DIR)/lib 48 | 49 | UTILS_LIBS = -lUtils 50 | TECPLOT_IO_LIBS = -lTecplotIO 51 | TEMPORAL_IO_LIBS = -lTemporalIO 52 | COMPLEX_EIGENSOLVER_LIBS = -lEigenSolver 53 | STABILTY_LIBS = -lLocalStability 54 | CURVI_LIBS = -lCurvilinear 55 | VTKUTILS_LIBS = -lVTKUtils 56 | POD_LIBS = -lPODUtils 57 | PODROM_LIBS = -lPODRomUtils 58 | 59 | # ---------------------------------------------------------------------------- 60 | # ranlib - generate index to archive. 61 | RANLIB = ranlib 62 | 63 | # ---------------------------------------------------------------------------- 64 | -------------------------------------------------------------------------------- /makefiles/Makefile.dell.in: -------------------------------------------------------------------------------- 1 | # Vassili Kitsios 27/02/2007 2 | SYSTEM_NAME = DELL 3 | 4 | # ---------------------------------------------------------------------------- 5 | CPP = g++ 6 | #MPI_CPP = mpicxx 7 | MPI_CPP = g++ 8 | 9 | # ---------------------------------------------------------------------------- 10 | #CPPFLAGS = -O0 -DDEBUG 11 | #CPPFLAGS = -O0 -Wno-deprecated 12 | CPPFLAGS = -O0 -Wall -Wno-deprecated 13 | #CPPFLAGS = -O0 -Wall 14 | #CPPFLAGS = -O0 -Wall -pedantic -fbounds-check 15 | #CPPFLAGS = -O1 -Wall -pedantic -fbounds-check 16 | #CPPFLAGS = -O2 -Wall -pedantic -fbounds-check 17 | #CPPFLAGS = -O3 -Wall -pedantic -fbounds-check 18 | 19 | # ---------------------------------------------------------------------------- 20 | # ar - create, modify, and extract from archives 21 | # r = insert file into archive 22 | # c = create archive if necessary 23 | # v = verbose 24 | AR = ar rcv 25 | 26 | # ---------------------------------------------------------------------------- 27 | # Library Locations 28 | 29 | VTK_LIBS_DIR = /usr/local/lib/vtk-5.6 30 | VTK_INC_DIR = /usr/local/include/vtk-5.6 31 | #VTK_LIBS = -L$(VTK_LIBS_DIR) -lvtkCommon -lvtkDICOMParser -lvtkFiltering -lvtkGenericFiltering -lvtkGraphics -lvtkHybrid -lvtkIO -lvtkImaging -lvtkNetCDF -lvtkRendering -lvtkVolumeRendering -lvtkWidgets -lvtkexoIIc -lvtkexpat -lvtkfreetype -lvtkftgl -lvtkjpeg -lvtkpng -lvtksys -lvtktiff -lvtkzlib 32 | VTK_LIBS = -L$(VTK_LIBS_DIR) -lvtkCommon -lvtkDICOMParser -lvtkFiltering -lvtkGenericFiltering -lvtkGraphics -lvtkIO -lvtkImaging -lvtkNetCDF -lvtkexoIIc -lvtkexpat -lvtkfreetype -lvtkjpeg -lvtkpng -lvtksys -lvtktiff -lvtkzlib 33 | VTK_INC = -I$(VTK_INC_DIR)/ -I$(VTK_INC_DIR)/Common -I$(VTK_INC_DIR)/Filtering -I$(VTK_INC_DIR)/Graphics -I$(VTK_INC_DIR)/Imaging -I$(VTK_INC_DIR)/IO -I$(VTK_INC_DIR)/Parallel -I$(VTK_INC_DIR)/GenericFiltering 34 | 35 | FFTW_LIBS = -lfftw3 -lm 36 | 37 | CLAPACK_DIR = /home/kit027/Documents/2code/clapack 38 | #CLAPACK_LIBS = -L$(CLAPACK_DIR) -lc -lctmg -lclapack -lcblas 39 | CLAPACK_LIBS = -L$(CLAPACK_DIR) -L$(CLAPACK_DIR)/F2CLIBS/ -lc -lctmg -lclapack -lcblas -lf2c 40 | CLAPACK_INC = -I$(CLAPACK_DIR)/INCLUDE 41 | 42 | #MPI_LIBS = -L/usr/lib/mpich2 -lmpich 43 | #MPI_INC = -I/usr/include/mpich2 44 | MPI_LIBS = -L/usr/lib -lmpich 45 | MPI_INC = -I/usr/include/mpi 46 | 47 | # ---------------------------------------------------------------------------- 48 | # My library Locations 49 | 50 | BASE_DIR = ../.. 51 | INCLUDE_DIR = $(BASE_DIR)/include 52 | LIB_DIR = $(BASE_DIR)/lib 53 | 54 | UTILS_LIBS = -lUtils 55 | TECPLOT_IO_LIBS = -lTecplotIO 56 | TEMPORAL_IO_LIBS = -lTemporalIO 57 | COMPLEX_EIGENSOLVER_LIBS = -lEigenSolver 58 | STABILTY_LIBS = -lLocalStability 59 | CURVI_LIBS = -lCurvilinear 60 | VTKUTILS_LIBS = -lVTKUtils 61 | POD_LIBS = -lPodUtils 62 | PODROM_LIBS = -lPodRomUtils 63 | 64 | # ---------------------------------------------------------------------------- 65 | # ranlib - generate index to archive. 66 | RANLIB = ranlib 67 | 68 | # ---------------------------------------------------------------------------- 69 | -------------------------------------------------------------------------------- /makefiles/Makefile.edda.in: -------------------------------------------------------------------------------- 1 | # Vassili Kitsios 27/02/2007 2 | SYSTEM_NAME = edda 3 | 4 | # ---------------------------------------------------------------------------- 5 | # Library Locations 6 | MESH_IO_DIR = /home/vzgd12/mesh_io 7 | MESH_IO_LIBS = -L$(MESH_IO_DIR)/lib -lmesh_io 8 | MESH_IO_INC = -I$(MESH_IO_DIR)/include 9 | 10 | UTILS_DIR = /home/vzgd12/utils 11 | UTILS_LIBS = -L$(UTILS_DIR)/lib -lutils 12 | UTILS_INC = -I$(UTILS_DIR)/include 13 | 14 | CLAPACK_DIR = /home/vzgd12/CLAPACK 15 | CLAPACK_LIBS = -L$(CLAPACK_DIR) -L$(CLAPACK_DIR)/F2CLIBS -lc -lclapack -lcblas -lF77 -lI77 16 | CLAPACK_INC = -I$(CLAPACK_DIR) -I$(CLAPACK_DIR)/F2CLIBS 17 | 18 | MPI_DIR = /usr/local/mpichgm-1.2.6..14b-gcc33-xlf-gm-32 19 | MPI_LIBS = -L$(MPI_DIR)/lib -lmpich 20 | #MPI_INC = -I$(MPI_DIR)/include 21 | MPI_CPP = $(MPI_DIR)/bin/mpicxx 22 | 23 | CURVI_DIR = /Users/vas/Documents/3Coding/4Analysis_codes/conformal_mapping 24 | CURVI_LIBS = -L$(CURVI_DIR)/lib -lCurvilinear -lVTKUtils 25 | CURVI_INC = -I$(CURVI_DIR)/include 26 | 27 | # or run: compileEdda32gcc - see ~/.bash_profile 28 | #MPI_CPP = mpicxx 29 | 30 | # ---------------------------------------------------------------------------- 31 | # CPP = /usr/local/gcc-4.1.1/bin/g++ 32 | #CPP = $(MPI_CPP) 33 | CPP = g++ 34 | 35 | # ---------------------------------------------------------------------------- 36 | #CPPFLAGS = -O0 -Wall -ansi -pedantic -DDEBUG 37 | #CPPFLAGS = -O0 -Wall -ansi -pedantic 38 | CPPFLAGS = -O2 -Wall -ansi -pedantic 39 | #CPPFLAGS = -O1 -Wall -ansi -pedantic 40 | #CPPFLAGS = -O3 -Wall -ansi -pedantic 41 | 42 | # ---------------------------------------------------------------------------- 43 | # ar - create, modify, and extract from archives 44 | # r = insert file into archive 45 | # c = create archive if necessary 46 | # v = verbose 47 | AR = ar rcv 48 | 49 | # ---------------------------------------------------------------------------- 50 | # ranlib - generate index to archive. 51 | RANLIB = ranlib 52 | 53 | # ---------------------------------------------------------------------------- 54 | -------------------------------------------------------------------------------- /makefiles/Makefile.tango.in: -------------------------------------------------------------------------------- 1 | # Vassili Kitsios 27/02/2007 2 | SYSTEM_NAME = tango 3 | 4 | # ---------------------------------------------------------------------------- 5 | CPP = /usr/local/gcc/4.2.1/bin/g++ 6 | 7 | # ---------------------------------------------------------------------------- 8 | # CPPFLAGS = -O0 -Wall -ansi -pedantic -DDEBUG 9 | # CPPFLAGS = -O2 -Wall -ansi -pedantic 10 | # CPPFLAGS = -O1 -Wall -ansi -pedantic 11 | #CPPFLAGS = -O3 -Wall -ansi -pedantic 12 | #CPPFLAGS = -O2 -lstdc++ 13 | CPPFLAGS = -O0 -Wno-deprecated 14 | 15 | # ---------------------------------------------------------------------------- 16 | # ar - create, modify, and extract from archives 17 | # r = insert file into archive 18 | # c = create archive if necessary 19 | # v = verbose 20 | AR = ar rcv 21 | 22 | # ---------------------------------------------------------------------------- 23 | # Library Locations 24 | UTILS_DIR = /home/vzgd12/local/utils 25 | UTILS_LIBS = -L$(UTILS_DIR)/lib/ -lUtils 26 | UTILS_INC = -I$(UTILS_DIR)/include/ 27 | 28 | VTK_DIR = /home/vzgd12/lib/VTK 29 | VTK_LIBS = -L$(VTK_DIR)/bin -lvtkCommon -lvtkDICOMParser -lvtkFiltering -lvtkGenericFiltering -lvtkGraphics -lvtkHybrid -lvtkIO -lvtkImaging -lvtkNetCDF -lvtkRendering -lvtkVolumeRendering -lvtkWidgets -lvtkexoIIc -lvtkexpat -lvtkfreetype -lvtkftgl -lvtkjpeg -lvtkpng -lvtksys -lvtktiff -lvtkzlib 30 | VTK_INC = -I$(VTK_DIR)/ -I$(VTK_DIR)/Common -I$(VTK_DIR)/Filtering -I$(VTK_DIR)/GUISupport -I$(VTK_DIR)/GenericFiltering -I$(VTK_DIR)/Graphics -I$(VTK_DIR)/Hybrid -I$(VTK_DIR)/IO -I$(VTK_DIR)/Imaging -I$(VTK_DIR)/Parallel -I$(VTK_DIR)/Rendering -I$(VTK_DIR)/Testing -I$(VTK_DIR)/Utilities -I$(VTK_DIR)/VolumeRendering -I$(VTK_DIR)/Widgets -I$(VTK_DIR)/Wrapping -I$(VTK_DIR)/bin 31 | 32 | CLAPACK_DIR = /home/vzgd12/lib/clapack 33 | CLAPACK_LIBS = -L$(CLAPACK_DIR) -L$(CLAPACK_DIR)/F2CLIBS -lc -lclapack -lcblas -lF77 -lI77 34 | CLAPACK_INC = -I$(CLAPACK_DIR) -I$(CLAPACK_DIR)/F2CLIBS 35 | 36 | CURVI_DIR = /Users/vas/Documents/3Coding/4Analysis_codes/conformal_mapping 37 | CURVI_LIBS = -L$(CURVI_DIR)/lib -lCurvilinear -lVTKUtils 38 | CURVI_INC = -I$(CURVI_DIR)/include 39 | 40 | # need to run: module load openmpi/1.2.4-gcc 41 | MPI_CPP = mpicxx 42 | 43 | MPI_DIR = /usr/local/openmpi/1.2.4-gcc 44 | MPI_LIBS = -L$(MPI_DIR)/lib/ -lmpi -lmpi_cxx 45 | MPI_INC = -I$(MPI_DIR)/include/ 46 | MPI_CPP = $(MPI_DIR)/bin/mpic++ 47 | 48 | # or need to run: module load openmpi/1.2.4-gcc 49 | #MPI_CPP = mpicxx 50 | 51 | # ---------------------------------------------------------------------------- 52 | # ranlib - generate index to archive. 53 | RANLIB = ranlib 54 | 55 | # ---------------------------------------------------------------------------- 56 | -------------------------------------------------------------------------------- /src/Makefile: -------------------------------------------------------------------------------- 1 | # Libraries made in order so that interdepancies are taken into account 2 | # 3 | default: 4 | (cd ./libUtils ; make ; cd ../libPodUtils ; make) 5 | 6 | clean: 7 | (cd ./libUtils ; make clean ; cd ../libPodUtils ; make clean) 8 | 9 | -------------------------------------------------------------------------------- /src/libPodUtils/Field_Reconstructor_t.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | #include "Utils.h" 6 | #include "Snapshot_Data_t.h" 7 | #include "real_sym_eig_solver.h" 8 | #include "Field_Reconstructor_t.h" 9 | 10 | #define COUNTER_NOTIFY_INTERVAL 1000 11 | 12 | //---------------------------------------------------------------------------- 13 | Field_Reconstructor_t::Field_Reconstructor_t() 14 | { 15 | } 16 | 17 | //---------------------------------------------------------------------------- 18 | Field_Reconstructor_t::~Field_Reconstructor_t() 19 | { 20 | } 21 | 22 | //---------------------------------------------------------------------------- 23 | void Field_Reconstructor_t::set_problem_parameters(char *temporal_correlation_type, long int N_points) 24 | { 25 | this->temporal_correlation_type = temporal_correlation_type; 26 | this->N_points = N_points; 27 | } 28 | 29 | //---------------------------------------------------------------------------- 30 | void Field_Reconstructor_t::reconstruct_field(long int num_modes, double *inner_products, Snapshot_Data_t **spatial_modes, 31 | Snapshot_Data_t *pod_reconstruction) 32 | { 33 | // Assuming the spatial modes are zero for the appropriate temporal correlation types this code should work for all cases 34 | 35 | for (long int node=0; node 3 | #include 4 | 5 | #include "Utils.h" 6 | #include "Snapshot_Data_t.h" 7 | #include "Inner_Product_Calculator_t.h" 8 | 9 | #define COUNTER_NOTIFY_INTERVAL 1000 10 | 11 | //---------------------------------------------------------------------------- 12 | Inner_Product_Calculator_t::Inner_Product_Calculator_t() 13 | { 14 | } 15 | 16 | //---------------------------------------------------------------------------- 17 | Inner_Product_Calculator_t::~Inner_Product_Calculator_t() 18 | { 19 | } 20 | 21 | //---------------------------------------------------------------------------- 22 | void Inner_Product_Calculator_t::set_problem_parameters(char *temporal_correlation_type, char *normalisation, bool two_dimensional, long int N_points) 23 | { 24 | this->temporal_correlation_type = temporal_correlation_type; 25 | this->normalisation = normalisation; 26 | this->two_dimensional = two_dimensional; 27 | this->N_points = N_points; 28 | } 29 | 30 | //---------------------------------------------------------------------------- 31 | double Inner_Product_Calculator_t::calculate_inner_product(Snapshot_Data_t **a, Snapshot_Data_t **b, 32 | Snapshot_Data_t *rms_field, Snapshot_Data_t rms_spatial_average, 33 | double *cell_volumes, long int i, long int j) 34 | { 35 | double correlation = 0.0; 36 | 37 | if (strcmp(temporal_correlation_type,"u")==0) { 38 | if (strcmp(normalisation,"none")==0) { 39 | correlation = calculate_inner_product_for_u(a, b, cell_volumes, i, j); 40 | } else if (strcmp(normalisation,"local")==0) { 41 | correlation = calculate_inner_product_for_u_local_norm(a, b, rms_field, rms_spatial_average, cell_volumes, i, j); 42 | } 43 | 44 | } else if (strcmp(temporal_correlation_type,"v")==0) { 45 | if (strcmp(normalisation,"none")==0) { 46 | correlation = calculate_inner_product_for_v(a, b, cell_volumes, i, j); 47 | } else if (strcmp(normalisation,"local")==0) { 48 | correlation = calculate_inner_product_for_v_local_norm(a, b, rms_field, rms_spatial_average, cell_volumes, i, j); 49 | } 50 | 51 | } else if ( (strcmp(temporal_correlation_type,"w")==0) && (!two_dimensional) ) { 52 | if (strcmp(normalisation,"none")==0) { 53 | correlation = calculate_inner_product_for_w(a, b, cell_volumes, i, j); 54 | } else if (strcmp(normalisation,"local")==0) { 55 | correlation = calculate_inner_product_for_w_local_norm(a, b, rms_field, rms_spatial_average, cell_volumes, i, j); 56 | } 57 | 58 | } else if (strcmp(temporal_correlation_type,"p")==0) { 59 | if (strcmp(normalisation,"none")==0) { 60 | correlation = calculate_inner_product_for_p(a, b, cell_volumes, i, j); 61 | } else if (strcmp(normalisation,"local")==0) { 62 | correlation = calculate_inner_product_for_p_local_norm(a, b, rms_field, rms_spatial_average, cell_volumes, i, j); 63 | } 64 | 65 | } else if (strcmp(temporal_correlation_type,"ke")==0) { 66 | if (strcmp(normalisation,"none")==0) { 67 | correlation = calculate_inner_product_for_ke(a, b, cell_volumes, i, j); 68 | } else if (strcmp(normalisation,"local")==0) { 69 | correlation = calculate_inner_product_for_ke_local_norm(a, b, rms_field, rms_spatial_average, cell_volumes, i, j); 70 | } else if (strcmp(normalisation,"global")==0) { 71 | correlation = calculate_inner_product_for_ke_global_norm(a, b, rms_spatial_average, cell_volumes, i, j); 72 | } 73 | 74 | } else if (strcmp(temporal_correlation_type,"q")==0) { 75 | if (strcmp(normalisation,"none")==0) { 76 | correlation = calculate_inner_product_for_q(a, b, cell_volumes, i, j); 77 | } else if (strcmp(normalisation,"local")==0) { 78 | correlation = calculate_inner_product_for_q_local_norm(a, b, rms_field, rms_spatial_average, cell_volumes, i, j); 79 | } else if (strcmp(normalisation,"global")==0) { 80 | correlation = calculate_inner_product_for_q_global_norm(a, b, rms_spatial_average, cell_volumes, i, j); 81 | } 82 | } 83 | 84 | return correlation; 85 | } 86 | 87 | //---------------------------------------------------------------------------- 88 | double Inner_Product_Calculator_t::calculate_inner_product_for_u(Snapshot_Data_t **a, Snapshot_Data_t **b, double *cell_volumes, long int i, long int j) 89 | { 90 | double inner_product = 0.0; 91 | for (int k=0; k $(INCLUDE_DIR)/$(HEADER_NAME) 34 | mv -v $(ARCHIVE_NAME) $(LIB_DIR) 35 | 36 | # This automatically updates all the dependencies shown below 37 | depend: 38 | makedepend -Y $(SRC) 39 | 40 | clean: 41 | rm -fv *.o *~ ._* $(LIB_DIR)/$(ARCHIVE_NAME) $(INCLUDE_DIR)/$(HEADER_NAME) 42 | -------------------------------------------------------------------------------- /src/libPodUtils/POD_t.h: -------------------------------------------------------------------------------- 1 | 2 | #include "vtkUnstructuredGrid.h" 3 | #include "vtkUnstructuredGridReader.h" 4 | #include "vtkUnstructuredGridWriter.h" 5 | #include "vtkPointData.h" 6 | #include "vtkExtractUnstructuredGrid.h" 7 | 8 | #include 9 | 10 | //------------------------------------------------------------------------- 11 | // POD_t 12 | //------------------------------------------------------------------------- 13 | class POD_t 14 | { 15 | private: 16 | //------------------------------------------------------------------------- 17 | // variables 18 | //------------------------------------------------------------------------- 19 | long int N_snapshots, N_points, N_non_zero_eigenvalues, N_modes; 20 | char *temporal_correlation_type, *normalisation; 21 | double dt; 22 | long int first_node_number, last_node_number; 23 | long int first_snapshot_number, last_snapshot_number; // for parallelisation - but not used as spatial parallelisaiton is more efficient 24 | long int last_restart_snapshot_i, last_restart_snapshot_j; // from reading temporal correlations file 25 | bool snapshots_allocated, spatial_modes_allocated; 26 | //------------------------------------------------------------------------- 27 | void read_list_of_snapshots(char *snapshot_list_filename, char *snapshot_dir); 28 | void read_list_of_spatial_modes(char *spatial_modes_dir); 29 | void read_and_save_first_snapshot(char *first_snapshot_filename); 30 | //------------------------------------------------------------------------- 31 | void scale_eigenvalues(); 32 | //------------------------------------------------------------------------- 33 | public: 34 | //------------------------------------------------------------------------- 35 | // variables 36 | //------------------------------------------------------------------------- 37 | vector list_of_snapshots, list_of_spatial_modes; 38 | 39 | vtkUnstructuredGrid *first_snapshot; // Actually the snapshot with the cell volumes stored, usually the first snapshot but not necessarily 40 | Snapshot_Data_t **snapshots; 41 | double *cell_volumes; 42 | Snapshot_Data_t *mean_field; // temporal mean of the snapshots 43 | Snapshot_Data_t *rms_field; // rms of the unsteady components i.e. the mean has already been subtracted 44 | Snapshot_Data_t rms_spatial_average; // spatial average of the rms fields 45 | Snapshot_Data_t *spatial_rms_history; // spatial rms of each snapshot 46 | 47 | double **A; // Initially stores the temporal correlation, after eigensolution is complete it stores temporal modes 48 | double *eigenvalues; 49 | double *scaled_eigenvalues; 50 | double x_min, x_max, y_min, y_max, z_min, z_max; // Domain extents 51 | Snapshot_Data_t **spatial_modes; 52 | //------------------------------------------------------------------------- 53 | bool two_dimensional; 54 | Inner_Product_Calculator_t inner_product_calculator; 55 | Spatial_Mode_Calculator_t spatial_mode_calculator; 56 | Field_Reconstructor_t field_reconstructor; 57 | //------------------------------------------------------------------------- 58 | Snapshot_Data_t **spatial_L2_error; 59 | Snapshot_Data_t *max_spatial_L2_error; 60 | //------------------------------------------------------------------------- 61 | // constructor 62 | //------------------------------------------------------------------------- 63 | POD_t(char *temporal_correlation_type, char *normalisation, double dt, char *two_dimensional_char, 64 | char *snapshot_list_filename, char *snapshot_dir, char *file_name_with_cell_volumes, 65 | double x_min, double x_max, double y_min, double y_max, double z_min, double z_max, 66 | char *spatial_modes_dir); 67 | //------------------------------------------------------------------------- 68 | // applying test functions 69 | //------------------------------------------------------------------------- 70 | void allocate_memory(); 71 | void report_memory_usage(int myrank); 72 | void report_memory_usage(); 73 | 74 | void set_node_number_range(long int first_node_number, long int last_node_number); 75 | long int get_number_of_points(); 76 | long int get_first_point_number(); 77 | long int get_last_point_number(); 78 | long int get_total_number_of_points(); 79 | 80 | void set_snapshot_number_range(long int first_snapshot_number, long int last_snapshot_number); 81 | long int get_number_of_snapshots(); 82 | long int get_number_of_modes(); 83 | 84 | void read_snapshots(); 85 | void read_snapshots(int myrank); 86 | 87 | void read_spatial_modes(); 88 | void read_spatial_modes(int myrank); 89 | 90 | void read_temporal_correlations(char *temporal_correlations_filename); 91 | long int get_last_restart_snapshot_i(); 92 | long int get_last_restart_snapshot_j(); 93 | 94 | void calculate_temporal_mean(); 95 | void write_mean_field(); 96 | void read_mean_field(char *restart_dir, int myrank); 97 | void read_mean_field(char *restart_dir); 98 | 99 | void subtract_temporal_mean_from_snapshots(); 100 | void write_first_snapshot_unsteady_component(); 101 | 102 | void calculate_temporal_rms(); 103 | void write_rms_field(); 104 | void read_rms_field(char *restart_dir, int myrank); 105 | void read_rms_field(char *restart_dir); 106 | 107 | void calculate_spatial_rms_history(); 108 | void write_spatial_rms_history(); 109 | void read_spatial_rms_history(char *restart_dir); 110 | 111 | void calculate_spatial_average_of_temporal_rms(); 112 | void write_rms_spatial_average(); 113 | 114 | void calculate_and_write_temporal_correlations(); 115 | double calculate_inner_product(long int i, long int j); // Used for MPI driver 116 | 117 | void calculate_and_scale_eigenvalues(bool check_eigensolution); 118 | void calculate_number_of_modes_for_threshhold_energy(double threshhold_energy, int min_number_of_eigenvalues, int max_number_of_eigenvalues); 119 | void write_eigenvalues(); 120 | 121 | void calculate_and_scale_temporal_modes(); 122 | void test_temporal_orthogonality(); 123 | void write_temporal_modes(); 124 | void read_temporal_pod_modes(char *file_location); 125 | 126 | void calculate_and_scale_mode_i(long int mode_i); 127 | void calculate_and_write_spatial_modes(); 128 | 129 | void test_spatial_orthogonality(); 130 | double test_spatial_orthogonality(long int i, long int j); 131 | 132 | void calculate_L2_reconstruction_error(); 133 | void write_reconstruction_L2_error(); 134 | 135 | void calculate_L_infinite_reconstruction_error(); 136 | void write_reconstruction_L_infinite_error(); 137 | 138 | void write_summary(); 139 | //------------------------------------------------------------------------- 140 | // destructor 141 | //------------------------------------------------------------------------- 142 | ~POD_t(); 143 | //------------------------------------------------------------------------- 144 | }; 145 | 146 | -------------------------------------------------------------------------------- /src/libPodUtils/Snapshot_Data_t.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "Utils.h" 9 | #include "Snapshot_Data_t.h" 10 | 11 | 12 | //------------------------------------------------------------------------- 13 | // Non class functions 14 | //------------------------------------------------------------------------- 15 | 16 | //------------------------------------------------------------------------- 17 | Snapshot_Data_t **malloc_2d_array_Snapshot_Data_t(long int Nx, long int Ny) 18 | { 19 | if(Nx <= 0) quit_error((char*)"Can't allocate array of length <= 0"); 20 | Snapshot_Data_t **f = (Snapshot_Data_t **) malloc(sizeof(Snapshot_Data_t*) * Nx); 21 | 22 | if( ! f ) quit_error((char*)"Malloc failed in malloc_2d_array_Snapshot_Data_t()"); 23 | for(int i=0;i 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "Utils.h" 9 | #include "Snapshot_Derivative_Data_t.h" 10 | 11 | 12 | //------------------------------------------------------------------------- 13 | void Snapshot_Derivative_Data_t::apply_constant_test_field() 14 | { 15 | // u velocity set then v selected to satisfy continuity 16 | u = 1.0; v = 1.0; w = 0.0; 17 | 18 | du_dx = 0.0; du_dy = 0.0; du_dz = 0.0; 19 | dv_dx = 0.0; dv_dy = -du_dx; dv_dz = 0.0; 20 | dw_dx = 0.0; dw_dy = 0.0; dw_dz = 0.0; 21 | 22 | d2u_dx2 = 0.0; d2v_dy2 = 0.0; d2w_dz2 = 0.0; 23 | 24 | p = u; 25 | } 26 | 27 | //------------------------------------------------------------------------- 28 | void Snapshot_Derivative_Data_t::apply_linear_test_field(double x, double y) 29 | { 30 | // u velocity set then v selected to satisfy continuity 31 | u = x + y; v = -x - y; w = 0.0; 32 | 33 | du_dx = 1.0; du_dy = 1.0; du_dz = 0.0; 34 | dv_dx = -1.0; dv_dy = -du_dx; dv_dz = 0.0; 35 | dw_dx = 0.0; dw_dy = 0.0; dw_dz = 0.0; 36 | 37 | d2u_dx2 = 0.0; d2v_dy2 = 0.0; d2w_dz2 = 0.0; 38 | 39 | p = u; 40 | } 41 | 42 | //------------------------------------------------------------------------- 43 | void Snapshot_Derivative_Data_t::apply_quadratic_test_field(double x, double y) 44 | { 45 | // u velocity set then v selected to satisfy continuity 46 | u = x*x+x*y; v = -2.0*x*y-0.5*y*y; w = 0.0; 47 | 48 | du_dx = 2.0*x+y; du_dy = x; du_dz = 0.0; 49 | dv_dx = -2.0*y; dv_dy = -du_dx; dv_dz = 0.0; 50 | dw_dx = 0.0; dw_dy = 0.0; dw_dz = 0.0; 51 | 52 | d2u_dx2 = 2.0; d2v_dy2 = -1.0; d2w_dz2 = 0.0; 53 | 54 | p = u; 55 | } 56 | 57 | //------------------------------------------------------------------------- 58 | // Non class functions 59 | //------------------------------------------------------------------------- 60 | 61 | //------------------------------------------------------------------------- 62 | Snapshot_Derivative_Data_t **malloc_2d_array_Snapshot_Derivative_Data_t(long int Nx, long int Ny) 63 | { 64 | if(Nx <= 0) quit_error((char*)"Can't allocate array of length <= 0"); 65 | Snapshot_Derivative_Data_t **f = (Snapshot_Derivative_Data_t **) malloc(sizeof(Snapshot_Derivative_Data_t*)*Nx); 66 | 67 | if( ! f ) quit_error((char*)"Malloc failed in malloc_2d_array_Snapshot_Derivative_Data_t()"); 68 | for(int i=0;i 3 | #include 4 | 5 | #include "Utils.h" 6 | #include "Snapshot_Data_t.h" 7 | #include "real_sym_eig_solver.h" 8 | #include "Spatial_Mode_Calculator_t.h" 9 | 10 | #define COUNTER_NOTIFY_INTERVAL 1000 11 | 12 | //---------------------------------------------------------------------------- 13 | Spatial_Mode_Calculator_t::Spatial_Mode_Calculator_t() 14 | { 15 | } 16 | 17 | //---------------------------------------------------------------------------- 18 | Spatial_Mode_Calculator_t::~Spatial_Mode_Calculator_t() 19 | { 20 | free_1d_array_Snapshot_Data_t(spatial_mode); 21 | } 22 | 23 | //---------------------------------------------------------------------------- 24 | void Spatial_Mode_Calculator_t::set_problem_parameters(char *temporal_correlation_type, char *normalisation, long int N_points, long int N_snapshots) 25 | { 26 | this->temporal_correlation_type = temporal_correlation_type; 27 | this->normalisation = normalisation; 28 | this->N_points = N_points; 29 | this->N_snapshots = N_snapshots; 30 | spatial_mode = malloc_1d_array_Snapshot_Data_t(N_points); 31 | } 32 | 33 | //---------------------------------------------------------------------------- 34 | void Spatial_Mode_Calculator_t::calculate_spatial_mode(long int mode_num, double **A, Snapshot_Data_t **snapshots, double *eigenvalues) 35 | { 36 | if (strcmp(temporal_correlation_type,"ke")==0) { 37 | calculate_spatial_mode_ke(mode_num, A, snapshots); 38 | 39 | } else if (strcmp(temporal_correlation_type,"p")==0) { 40 | calculate_spatial_mode_p(mode_num, A, snapshots); 41 | 42 | } else if (strcmp(temporal_correlation_type,"q")==0) { 43 | calculate_spatial_mode_q(mode_num, A, snapshots); 44 | 45 | } else if (strcmp(temporal_correlation_type,"u")==0) { 46 | calculate_spatial_mode_u(mode_num, A, snapshots); 47 | 48 | } else if (strcmp(temporal_correlation_type,"v")==0) { 49 | calculate_spatial_mode_v(mode_num, A, snapshots); 50 | 51 | } else if (strcmp(temporal_correlation_type,"w")==0) { 52 | calculate_spatial_mode_w(mode_num, A, snapshots); 53 | } 54 | 55 | for (long int k=0; k ZERO*1.0e3) 226 | fprintf(stdout,"WARNING norm check failed for spatial mode pair (%ld, %ld), should be %g, resulted in %g\n", i, j, 1.0, norm); 227 | } else { 228 | if (sqrt(SQ(norm)) > ZERO*1.0e3) 229 | fprintf(stdout,"WARNING norm check failed for spatial mode pair (%ld, %ld), should be %g, resulted in %g\n", i, j, 0.0, norm); 230 | } 231 | } 232 | 233 | //---------------------------------------------------------------------------- 234 | 235 | -------------------------------------------------------------------------------- /src/libPodUtils/Spatial_Mode_Calculator_t.h: -------------------------------------------------------------------------------- 1 | 2 | //------------------------------------------------------------------------- 3 | // Spatial_Mode_Calculator_t 4 | //------------------------------------------------------------------------- 5 | class Spatial_Mode_Calculator_t 6 | { 7 | private: 8 | //------------------------------------------------------------------------- 9 | // variables 10 | //------------------------------------------------------------------------- 11 | long int N_points, N_snapshots, N_modes; 12 | char *temporal_correlation_type, *normalisation; 13 | //------------------------------------------------------------------------- 14 | void calculate_spatial_mode_u(long int mode_num, double **A, Snapshot_Data_t **snapshots); 15 | void calculate_spatial_mode_v(long int mode_num, double **A, Snapshot_Data_t **snapshots); 16 | void calculate_spatial_mode_w(long int mode_num, double **A, Snapshot_Data_t **snapshots); 17 | void calculate_spatial_mode_ke(long int mode_num, double **A, Snapshot_Data_t **snapshots); 18 | void calculate_spatial_mode_p(long int mode_num, double **A, Snapshot_Data_t **snapshots); 19 | void calculate_spatial_mode_q(long int mode_num, double **A, Snapshot_Data_t **snapshots); 20 | //------------------------------------------------------------------------- 21 | double test_spatial_orthogonality(Snapshot_Data_t **spatial_modes, double *cell_volumes, long int i, long int j); 22 | double test_spatial_orthogonality_norm_local(Snapshot_Data_t **spatial_modes, double *cell_volumes, 23 | Snapshot_Data_t *rms_field, Snapshot_Data_t rms_spatial_average, long int i, long int j); 24 | double test_spatial_orthogonality_norm_global(Snapshot_Data_t **spatial_modes, double *cell_volumes, 25 | Snapshot_Data_t rms_spatial_average, long int i, long int j); 26 | //------------------------------------------------------------------------- 27 | public: 28 | //------------------------------------------------------------------------- 29 | // variables 30 | //------------------------------------------------------------------------- 31 | Snapshot_Data_t *spatial_mode; 32 | //------------------------------------------------------------------------- 33 | // constructor 34 | //------------------------------------------------------------------------- 35 | Spatial_Mode_Calculator_t(); 36 | //------------------------------------------------------------------------- 37 | // applying test functions 38 | //------------------------------------------------------------------------- 39 | void set_problem_parameters(char *temporal_correlation_type, char *normalisation, long int N_points, long int N_snapshots); 40 | void calculate_spatial_mode(long int mode_num, double **A, Snapshot_Data_t **snapshots, double *eigenvalues); 41 | 42 | double test_spatial_orthogonality(Snapshot_Data_t **spatial_modes, double *cell_volumes, 43 | Snapshot_Data_t *rms_field, Snapshot_Data_t rms_spatial_average, 44 | long int i, long int j); 45 | void norm_check(long int i, long int j, double norm); 46 | //------------------------------------------------------------------------- 47 | // destructor 48 | //------------------------------------------------------------------------- 49 | ~Spatial_Mode_Calculator_t(); 50 | //------------------------------------------------------------------------- 51 | }; 52 | 53 | -------------------------------------------------------------------------------- /src/libPodUtils/real_sym_eig_solver.h: -------------------------------------------------------------------------------- 1 | 2 | long int calculate_eigensolution(long int n, double **A, double *eigenvalues, bool check_solution); 3 | 4 | long int calculate_eigensolution(long int n, double **A, double *eigenvalues); 5 | 6 | long int calculate_real_sym_eigensolution(long int n, double **A, double *eigenvalues); 7 | -------------------------------------------------------------------------------- /src/libUtils/Makefile: -------------------------------------------------------------------------------- 1 | # ------------------------- 2 | BASE_DIR=../.. 3 | include $(BASE_DIR)/Makefile.in 4 | 5 | LIBS = -lm 6 | 7 | # --------Suffixes--------- 8 | .SUFFIXES: .cpp 9 | 10 | .cpp.o: 11 | $(CPP) $(CPPFLAGS) $(LIBS) -c $*.cpp 12 | 13 | .cpp : 14 | $(CPP) $(CPPFLAGS) $(LIBS) -o $< $@ 15 | 16 | # -------Dependencies------ 17 | ARCHIVE_NAME = libUtils.a 18 | HEADER_NAME = Utils.h 19 | 20 | SRC = binary_read_or_write.cpp file_opening_closing.cpp memory_allocations.cpp misc.cpp param.cpp string.cpp time_stats.cpp tridiagonal_solver.cpp matrix.cpp cubic_spline.cpp finite_difference.cpp interpolation.cpp interpolation_1D.cpp 21 | 22 | OBJS = $(addsuffix .o, $(basename $(SRC))) 23 | 24 | HEADER_FILES = $(addsuffix .h, $(basename $(SRC))) 25 | 26 | default: $(ARCHIVE_NAME) 27 | 28 | $(ARCHIVE_NAME): $(OBJS) 29 | mkdir -p $(LIB_DIR) $(INCLUDE_DIR) 30 | $(AR) $@ $(OBJS) 31 | $(RANLIB) $@ 32 | cat $(HEADER_FILES) > $(INCLUDE_DIR)/$(HEADER_NAME) 33 | mv -v $(ARCHIVE_NAME) $(LIB_DIR) 34 | 35 | # This automatically updates all the dependencies shown below 36 | depend: 37 | makedepend -Y $(SRC) 38 | 39 | clean: 40 | rm -fv *.o *~ ._* $(LIB_DIR)/$(ARCHIVE_NAME) $(INCLUDE_DIR)/$(HEADER_NAME) 41 | 42 | # DO NOT DELETE 43 | 44 | -------------------------------------------------------------------------------- /src/libUtils/binary_read_or_write.cpp: -------------------------------------------------------------------------------- 1 | // binary_read_or_write.cpp 2 | 3 | #include "misc.h" 4 | #include "binary_read_or_write.h" 5 | 6 | //**************************************************************************** 7 | //binary_read_or_write() 8 | //**************************************************************************** 9 | void binary_read_or_write(FILE *fp, ReadOrWrite read_or_write, int count, int *val) 10 | { 11 | const size_t size = sizeof(int); 12 | if(read_or_write == Write) 13 | { 14 | fwrite((const void *)val, size, count, fp); 15 | } 16 | else 17 | { 18 | fread((void *)val, size, count, fp); 19 | } 20 | return; 21 | } 22 | 23 | //**************************************************************************** 24 | //binary_read_or_write() 25 | //**************************************************************************** 26 | void binary_read_or_write(FILE *fp, ReadOrWrite read_or_write, int count, double *val) 27 | { 28 | const size_t size = sizeof(double); 29 | if(read_or_write == Write) 30 | { 31 | fwrite((const void *)val, size, count, fp); 32 | } 33 | else 34 | { 35 | fread((void *)val, size, count, fp); 36 | } 37 | return; 38 | } 39 | 40 | //**************************************************************************** 41 | //binary_read_or_write() 42 | //**************************************************************************** 43 | void binary_read_or_write(FILE *fp, ReadOrWrite read_or_write, int count, char *val) 44 | { 45 | const size_t size = sizeof(char); 46 | if(read_or_write == Write) 47 | { 48 | fwrite((const void *)val, size, count, fp); 49 | } 50 | else 51 | { 52 | fread((void *)val, size, count, fp); 53 | } 54 | return; 55 | } 56 | 57 | //**************************************************************************** 58 | //binary_read_or_write() 59 | //**************************************************************************** 60 | void binary_read_or_write(FILE *fp, ReadOrWrite read_or_write, int count, bool *val) 61 | { 62 | const size_t size = sizeof(bool); 63 | if(read_or_write == Write) 64 | { 65 | fwrite((const void *)val, size, count, fp); 66 | } 67 | else 68 | { 69 | fread((void *)val, size, count, fp); 70 | } 71 | return; 72 | } 73 | 74 | 75 | -------------------------------------------------------------------------------- /src/libUtils/binary_read_or_write.h: -------------------------------------------------------------------------------- 1 | //========================== 2 | //binary_read_or_write.h 3 | //========================== 4 | 5 | using namespace std; 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | enum ReadOrWrite {Read, Write}; 14 | 15 | //**************************************************************************** 16 | 17 | extern void binary_read_or_write(FILE *fp, ReadOrWrite read_or_write, int count, int *val); 18 | extern void binary_read_or_write(FILE *fp, ReadOrWrite read_or_write, int count, double *val); 19 | extern void binary_read_or_write(FILE *fp, ReadOrWrite read_or_write, int count, char *val); 20 | extern void binary_read_or_write(FILE *fp, ReadOrWrite read_or_write, int count, bool *val); 21 | 22 | -------------------------------------------------------------------------------- /src/libUtils/cubic_spline.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "memory_allocations.h" 5 | #include "misc.h" 6 | #include "cubic_spline.h" 7 | 8 | //---------------------------------------------------------------------------- 9 | Cubic_Spline_t::Cubic_Spline_t(long int num_points) 10 | { 11 | this->num_points = num_points; 12 | a = malloc_1d_array_double(num_points+1); 13 | c = malloc_1d_array_double(num_points+1); 14 | b = malloc_1d_array_double(num_points); 15 | d = malloc_1d_array_double(num_points); 16 | points = malloc_1d_array_double(num_points); 17 | } 18 | 19 | //---------------------------------------------------------------------------- 20 | Cubic_Spline_t::~Cubic_Spline_t() 21 | { 22 | free_1d_array_double(a); 23 | free_1d_array_double(c); 24 | free_1d_array_double(b); 25 | free_1d_array_double(d); 26 | free_1d_array_double(points); 27 | } 28 | 29 | //---------------------------------------------------------------------------- 30 | void Cubic_Spline_t::calculate_interpolation_function(double *points_in, double *data) 31 | { 32 | // Need to solve the system Ac=Q for 'c' to then determine 'b' and 'd' coefficients 33 | 34 | // Allocate memory 35 | double *h, *diag1, *diag2, *diag3, *Q; 36 | h = malloc_1d_array_double(num_points); 37 | diag1 = malloc_1d_array_double(num_points); 38 | diag2 = malloc_1d_array_double(num_points); 39 | diag3 = malloc_1d_array_double(num_points); 40 | Q = malloc_1d_array_double(num_points); 41 | 42 | // Copt across the points 43 | for (long int i=0; i=0 ; i--) { 96 | c[i] = (Q[i] - diag3[i] * c[i+1]) / diag2[i]; 97 | // fprintf(stdout, "c = %f\n",c[i]); 98 | } 99 | 100 | // Back out 'b' and 'd' coefficients 101 | for (int i=0; i= points[i] ) && ( interp_point <= points[i+1] ) ) { 121 | f = a[i] + b[i] * ( interp_point - points[i] ) 122 | + c[i] * SQ( interp_point - points[i]) 123 | + d[i] * CU( interp_point - points[i]); 124 | // fprintf(stdout, "within class %f %f %f %f\n", f, interp_point, points[i], points[i+1]); 125 | } 126 | } 127 | return f; 128 | } 129 | 130 | //---------------------------------------------------------------------------- 131 | double Cubic_Spline_t::evaluate_first_derivative(double interp_point) 132 | { 133 | double df=0; 134 | for (long int i=0; i= points[i] ) && ( interp_point <= points[i+1] ) ) { 136 | df = b[i] + 2.0 * c[i] * ( interp_point - points[i] ) 137 | + 3.0 * d[i] * SQ( interp_point - points[i] ); 138 | // fprintf(stdout, "%f\n",df); 139 | } 140 | } 141 | return df; 142 | } 143 | 144 | //---------------------------------------------------------------------------- 145 | double Cubic_Spline_t::evaluate_second_derivative(double interp_point) 146 | { 147 | double d2f=0; 148 | for (long int i=0; i= points[i] ) && ( interp_point <= points[i+1] ) ) { 150 | d2f = 2.0 * c[i] + 6.0 * d[i] * ( interp_point - points[i] ); 151 | // fprintf(stdout, "%f\n",d2f); 152 | } 153 | } 154 | return d2f; 155 | } 156 | 157 | //---------------------------------------------------------------------------- 158 | -------------------------------------------------------------------------------- /src/libUtils/cubic_spline.h: -------------------------------------------------------------------------------- 1 | 2 | //**************************************************************************** 3 | // Cubic_Spline_t 4 | //**************************************************************************** 5 | class Cubic_Spline_t 6 | { 7 | private: 8 | //------------------------------------------------------------------------- 9 | // variables 10 | //------------------------------------------------------------------------- 11 | double *a, *b, *c, *d, *points; 12 | //------------------------------------------------------------------------- 13 | public: 14 | //------------------------------------------------------------------------- 15 | // variables 16 | //------------------------------------------------------------------------- 17 | long int num_points; // Numer of points in the spline 18 | //------------------------------------------------------------------------- 19 | // constructor 20 | //------------------------------------------------------------------------- 21 | Cubic_Spline_t(long int num_points); 22 | //------------------------------------------------------------------------- 23 | // functions 24 | //------------------------------------------------------------------------- 25 | void calculate_interpolation_function(double *points, double *data); 26 | double evaluate_function(double interp_point); 27 | double evaluate_first_derivative(double interp_point); 28 | double evaluate_second_derivative(double interp_point); 29 | //------------------------------------------------------------------------- 30 | // destructor 31 | //------------------------------------------------------------------------- 32 | ~Cubic_Spline_t(); 33 | //------------------------------------------------------------------------- 34 | }; 35 | -------------------------------------------------------------------------------- /src/libUtils/file_opening_closing.cpp: -------------------------------------------------------------------------------- 1 | // file_opening_closing.cpp 2 | 3 | using namespace std; 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "misc.h" 12 | #include "file_opening_closing.h" 13 | 14 | //**************************************************************************** 15 | //open_file() 16 | //**************************************************************************** 17 | FILE *open_file(char *filename, char *mode) 18 | { 19 | return open_file(filename,mode,true); 20 | } 21 | 22 | //**************************************************************************** 23 | //open_file() 24 | //**************************************************************************** 25 | FILE *open_file(char *filename, char *mode, bool verbose) 26 | { 27 | FILE *fp; 28 | if (verbose == true) printf("Opening the file \"%s\" using the mode \"%s\"...\n", filename, mode); 29 | fp = fopen(filename,mode); 30 | if (fp==NULL) quit_error((char*)"Unable to open file \"%s\" using mode \"%s\".", filename, mode); 31 | 32 | return fp; 33 | } 34 | 35 | //**************************************************************************** 36 | //close_file() 37 | //**************************************************************************** 38 | void close_file(FILE *fp, char *filename) 39 | { 40 | close_file(fp,filename,true); 41 | return; 42 | } 43 | 44 | //**************************************************************************** 45 | //close_file() 46 | //**************************************************************************** 47 | void close_file(FILE *fp, char *filename, bool verbose) 48 | { 49 | if (verbose==true) printf("Closing the file \"%s\"...\n", filename); 50 | if (fp==NULL) 51 | { 52 | print_warning((char *)"Trying to close a file that has a NULL file pointer."); 53 | return; 54 | } 55 | else 56 | fclose(fp); 57 | } 58 | 59 | 60 | -------------------------------------------------------------------------------- /src/libUtils/file_opening_closing.h: -------------------------------------------------------------------------------- 1 | //========================== 2 | //file_opening_closing.h 3 | //========================== 4 | 5 | //**************************************************************************** 6 | // files 7 | //**************************************************************************** 8 | /** 9 | Opens a file in the given mode. 10 | **/ 11 | extern FILE *open_file(char *filename, char *mode); 12 | /** 13 | Opens a file in the given mode. 14 | **/ 15 | extern FILE *open_file(char *filename, char *mode, bool verbose); 16 | /** 17 | Closes a file. 18 | **/ 19 | extern void close_file(FILE *fp, char *filename); 20 | /** 21 | Closes a file. 22 | **/ 23 | extern void close_file(FILE *fp, char *filename, bool verbose); 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/libUtils/finite_difference.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // Note for all of the following delta_x = x_i_plus_1 - x_i 5 | 6 | //**************************************************************************** 7 | // calculate_second_order_centred_finite_difference() 8 | //**************************************************************************** 9 | double calculate_second_order_centred_finite_difference(double delta_x, double f_i_minus_1, double f_i_plus_1) 10 | { 11 | double df_dx; 12 | df_dx = (f_i_plus_1 - f_i_minus_1) / 2.0 / delta_x; 13 | return df_dx; 14 | } 15 | 16 | //**************************************************************************** 17 | // calculate_forth_order_centred_finite_difference() 18 | //**************************************************************************** 19 | double calculate_forth_order_centred_finite_difference(double delta_x, double f_i_minus_2, double f_i_minus_1, double f_i_plus_1, double f_i_plus_2) 20 | { 21 | double df_dx; 22 | df_dx = (f_i_minus_2 - 8.0 * f_i_minus_1 + 8.0 * f_i_plus_1 - f_i_plus_2) / 12.0 / delta_x; 23 | return df_dx; 24 | } 25 | 26 | //**************************************************************************** 27 | // calculate_third_order_semi_centred_forward_finite_difference() 28 | //**************************************************************************** 29 | double calculate_semi_centred_forward_finite_difference(double delta_x, double f_i_minus_1, double f_i, double f_i_plus_1, double f_i_plus_2) 30 | { 31 | double df_dx; 32 | df_dx = (-2.0 * f_i_minus_1 - 3.0 * f_i + 6.0 * f_i_plus_1 - f_i_plus_2) / 6.0 / delta_x; 33 | return df_dx; 34 | } 35 | 36 | //**************************************************************************** 37 | // calculate_third_order_semi_centred_backward_finite_difference() 38 | //**************************************************************************** 39 | double calculate_semi_centred_backward_finite_difference(double delta_x, double f_i_minus_2, double f_i_minus_1, double f_i, double f_i_plus_1) 40 | { 41 | double df_dx; 42 | df_dx = (f_i_minus_2 - 6.0 * f_i_minus_1 + 3.0 * f_i + 2.0 * f_i_plus_1) / 6.0 / delta_x; 43 | return df_dx; 44 | } 45 | 46 | //**************************************************************************** 47 | // calculate_second_order_forward_finite_difference() 48 | //**************************************************************************** 49 | double calculate_second_order_forward_finite_difference(double delta_x, double f_i, double f_i_plus_1, double f_i_plus_2) 50 | { 51 | double df_dx; 52 | df_dx = (-3.0 * f_i + 4.0 * f_i_plus_1 - f_i_plus_2) / 2.0 / delta_x; 53 | return df_dx; 54 | } 55 | 56 | //**************************************************************************** 57 | // calculate_second_order_backward_finite_difference() 58 | //**************************************************************************** 59 | double calculate_second_order_backward_finite_difference(double delta_x, double f_i_minus_3, double f_i_minus_2, double f_i_minus_1, double f_i) 60 | { 61 | double df_dx; 62 | df_dx = (f_i_minus_2 - 4.0 * f_i_minus_1 + 3.0 * f_i) / 6.0 / delta_x; 63 | return df_dx; 64 | } 65 | 66 | //**************************************************************************** 67 | // calculate_third_order_forward_finite_difference() 68 | //**************************************************************************** 69 | double calculate_third_order_forward_finite_difference(double delta_x, double f_i, double f_i_plus_1, double f_i_plus_2, double f_i_plus_3) 70 | { 71 | double df_dx; 72 | df_dx = (-11.0 * f_i + 18.0 * f_i_plus_1 - 9.0 * f_i_plus_2 + 2.0 * f_i_plus_3) / 6.0 / delta_x; 73 | return df_dx; 74 | } 75 | 76 | //**************************************************************************** 77 | // calculate_third_order_backward_finite_difference() 78 | //**************************************************************************** 79 | double calculate_third_order_backward_finite_difference(double delta_x, double f_i_minus_3, double f_i_minus_2, double f_i_minus_1, double f_i) 80 | { 81 | double df_dx; 82 | df_dx = (-2.0 * f_i_minus_3 + 9.0 * f_i_minus_2 - 18.0 * f_i_minus_1 + 11.0 * f_i) / 6.0 / delta_x; 83 | return df_dx; 84 | } 85 | -------------------------------------------------------------------------------- /src/libUtils/finite_difference.h: -------------------------------------------------------------------------------- 1 | double calculate_second_order_centred_finite_difference(double delta_x, double f_i_minus_1, double f_i_plus_1); 2 | double calculate_forth_order_centred_finite_difference(double delta_x, double f_i_minus_2, double f_i_minus_1, double f_i_plus_1, double f_i_plus_2); 3 | double calculate_semi_centred_forward_finite_difference(double delta_x, double f_i_minus_1, double f_i, double f_i_plus_1, double f_i_plus_2); 4 | double calculate_semi_centred_backward_finite_difference(double delta_x, double f_i_minus_2, double f_i_minus_1, double f_i, double f_i_plus_1); 5 | double calculate_second_order_forward_finite_difference(double delta_x, double f_i, double f_i_plus_1, double f_i_plus_2); 6 | double calculate_second_order_backward_finite_difference(double delta_x, double f_i_minus_3, double f_i_minus_2, double f_i_minus_1, double f_i); 7 | double calculate_third_order_forward_finite_difference(double delta_x, double f_i, double f_i_plus_1, double f_i_plus_2, double f_i_plus_3); 8 | double calculate_third_order_backward_finite_difference(double delta_x, double f_i_minus_3, double f_i_minus_2, double f_i_minus_1, double f_i); 9 | -------------------------------------------------------------------------------- /src/libUtils/interpolation.h: -------------------------------------------------------------------------------- 1 | 2 | //============================================================================ 3 | // Dist_t 4 | //============================================================================ 5 | class Dist_t 6 | { 7 | public: 8 | //------------------------------------------------------------------------- 9 | // variables 10 | //------------------------------------------------------------------------- 11 | double delta_x; 12 | double delta_y; 13 | double delta_z; 14 | double delta_mag; 15 | long int node_num; 16 | //------------------------------------------------------------------------- 17 | }; 18 | 19 | //============================================================================ 20 | // Interpolation_t 21 | //============================================================================ 22 | class Interpolation_t 23 | { 24 | private: 25 | //------------------------------------------------------------------------- 26 | // variables 27 | //------------------------------------------------------------------------- 28 | int order; // Polynomial Order 29 | int p; // Number of terms in polynomial 30 | int max_redundancy; // Maximum number of additional points required above that needed to calculate a polynomial surface of order "order" 31 | int m; // Number of points used in stencil 32 | double epsilon; // Constant used for Gaussian weights 33 | double singularity_tolerance; // Tolerance for determining if a stencil is singular or not 34 | bool two_PI_periodic; // Flag if mesh is 2PI periodic 35 | 36 | long int num_data_points; // Number of points in the source mesh 37 | double *D; // Multiply this matrix by the data points in the stencil to get the results of the interpolation 38 | //------------------------------------------------------------------------- 39 | // functions 40 | //------------------------------------------------------------------------- 41 | void order_closest_nodes_on_extruded_2D_data(double **x_data, double x_interp_point, double y_interp_point); 42 | void order_closest_nodes_on_2D_data(double **x_data, double x_interp_point, double y_interp_point); 43 | 44 | void generate_stencil_and_test_stability(double x_interp_point, double y_interp_point); 45 | void generate_stencil(double x_interp_point, double y_interp_point); 46 | 47 | void generate_w_matrix(double *w); 48 | void generate_w_matrix_for_continuity(double *w); 49 | 50 | void generate_B_matrix(double *B); 51 | void generate_B_matrix_for_continuity(double *B); 52 | void generate_b_matrix(double *b); 53 | void generate_b_x_matrix(double *b_x); 54 | void generate_b_y_matrix(double *b_y); 55 | 56 | void generate_C_matrix(double *interpolation_data, double *C); 57 | void generate_C_matrix_for_continuity(double *u, double *v, double *C); 58 | //------------------------------------------------------------------------- 59 | public: 60 | //------------------------------------------------------------------------- 61 | // variables 62 | //------------------------------------------------------------------------- 63 | Dist_t *distance_to_points; // Sorted list of distance to points used to determine the stencil of closest points to the desired interpolation point 64 | double f, df_dx, df_dy, d2f_dx2, d2f_dxdy, d2f_dy2; // Results of interpolation 65 | double u, du_dx, du_dy, d2u_dx2, d2u_dxdy, d2u_dy2; // Results of interpolation for continuity conservation 66 | double v, dv_dx, dv_dy, d2v_dx2, d2v_dxdy, d2v_dy2; 67 | //------------------------------------------------------------------------- 68 | // constructor 69 | //------------------------------------------------------------------------- 70 | Interpolation_t(long int num_data_points, int order, int max_redundancy, double epsilon, double singularity_tolerance, bool two_PI_periodic); 71 | //------------------------------------------------------------------------- 72 | // functions 73 | //------------------------------------------------------------------------- 74 | void form_interpolation_function_on_extruded_2D_data(double **x_data, double x_interp_point, double y_interp_point); 75 | void form_interpolation_function_on_2D_data(double **x_data, double x_interp_point, double y_interp_point); 76 | 77 | void evaluate_interpolation_function(double *interpolation_data); 78 | //------------------------------------------------------------------------- 79 | // destructor 80 | //------------------------------------------------------------------------- 81 | ~Interpolation_t(); 82 | //------------------------------------------------------------------------- 83 | }; 84 | 85 | //============================================================================ 86 | // Non class function 87 | //============================================================================ 88 | Dist_t* malloc_Dist_t(long int N); 89 | void free_Dist_t(Dist_t *dist); 90 | int qsort_distance_compare_function(Dist_t *dist1, Dist_t *dist2); 91 | -------------------------------------------------------------------------------- /src/libUtils/interpolation_1D.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | #include "misc.h" 11 | #include "memory_allocations.h" 12 | #include "matrix.h" 13 | #include "interpolation.h" 14 | #include "interpolation_1D.h" 15 | 16 | //------------------------------------------------------------------------- 17 | Interpolation_1D_t::Interpolation_1D_t(long int num_data_points, int order, int max_redundancy, double epsilon, double singularity_tolerance) 18 | { 19 | this->num_data_points = num_data_points; 20 | this->order = order; 21 | this->max_redundancy = max_redundancy; 22 | this->epsilon = epsilon; 23 | this->singularity_tolerance = singularity_tolerance; 24 | p = order+1; 25 | m = max_redundancy + p; 26 | 27 | distance_to_points = malloc_Dist_t(num_data_points); 28 | D = malloc_1d_array_double(p*2 * m*3); 29 | } 30 | 31 | //------------------------------------------------------------------------- 32 | Interpolation_1D_t::~Interpolation_1D_t() 33 | { 34 | free_Dist_t(distance_to_points); 35 | } 36 | 37 | //------------------------------------------------------------------------- 38 | void Interpolation_1D_t::form_interpolation_function(double *x_data, double x_interp_point) 39 | { 40 | order_closest_points(x_data, x_interp_point); 41 | if (order>0) generate_stencil(x_interp_point); 42 | } 43 | 44 | //------------------------------------------------------------------------- 45 | void Interpolation_1D_t::order_closest_points(double *x_data, double x_interp_point) 46 | { 47 | for (long int i=0; i0) { 137 | // Find P = D . C 138 | P = malloc_1d_array_double(p); 139 | matrix_multiply(D, p, m, C, m, 1, P); 140 | 141 | //Evaluate function and its derivatives 142 | f = P[0]; 143 | df_dx = P[1]; 144 | d2f_dx2 = 2.0*P[2]; 145 | 146 | free_1d_array_double(P); 147 | } else { 148 | f = C[0]; 149 | df_dx = 0.0; 150 | d2f_dx2 = 0.0; 151 | } 152 | 153 | free_1d_array_double(C); 154 | } 155 | 156 | //------------------------------------------------------------------------- 157 | 158 | -------------------------------------------------------------------------------- /src/libUtils/interpolation_1D.h: -------------------------------------------------------------------------------- 1 | 2 | //============================================================================ 3 | // Interpolation_1D_t 4 | //============================================================================ 5 | class Interpolation_1D_t 6 | { 7 | private: 8 | //------------------------------------------------------------------------- 9 | // variables 10 | //------------------------------------------------------------------------- 11 | int order; // Polynomial Order 12 | int p; // Number of terms in polynomial 13 | int max_redundancy; // Maximum number of additional points required above that needed to calculate a polynomial surface of order "order" 14 | int m; // Number of points used in stencil 15 | double epsilon; // Constant used for Gaussian weights 16 | double singularity_tolerance; // Tolerance for determining if a stencil is singular or not 17 | 18 | long int num_data_points; // Number of points in the source mesh 19 | double *D; // Multiply this matrix by the data points in the stencil to get the results of the interpolation 20 | //------------------------------------------------------------------------- 21 | // functions 22 | //------------------------------------------------------------------------- 23 | void generate_stencil(double x_interp_point); 24 | void order_closest_points(double *x_data, double x_interp_point); 25 | void generate_w_matrix(double *w); 26 | void generate_B_matrix(double *B); 27 | void generate_C_matrix(double *interpolation_data, double *C); 28 | //------------------------------------------------------------------------- 29 | public: 30 | //------------------------------------------------------------------------- 31 | // variables 32 | //------------------------------------------------------------------------- 33 | Dist_t *distance_to_points; // Sorted list of distance to points used to determine the stencil of closest points to the desired interpolation point 34 | double f, df_dx, d2f_dx2; // Results of interpolation 35 | //------------------------------------------------------------------------- 36 | // constructor 37 | //------------------------------------------------------------------------- 38 | Interpolation_1D_t(long int num_data_points, int order, int max_redundancy, double epsilon, double singularity_tolerance); 39 | //------------------------------------------------------------------------- 40 | // functions 41 | //------------------------------------------------------------------------- 42 | void form_interpolation_function(double *x_data, double x_interp_point); 43 | void evaluate_interpolation_function(double *interpolation_data); 44 | //------------------------------------------------------------------------- 45 | // destructor 46 | //------------------------------------------------------------------------- 47 | ~Interpolation_1D_t(); 48 | //------------------------------------------------------------------------- 49 | }; 50 | -------------------------------------------------------------------------------- /src/libUtils/matrix.h: -------------------------------------------------------------------------------- 1 | extern int matrix_invert(double *A, double *Ainv, long int N); 2 | extern void matrix_display(double *A, long int R, long int C); 3 | extern void matrix_multiply(double *A, long int Arows, long int Acols, double *B, long int Brows, long int Bcols, double *product); 4 | extern double matrix_determinant(double *A, long int N); 5 | extern void display_augmented(double *A, double *B, long int N); 6 | extern void matrix_transpose(double *A, long int R, long int C); 7 | extern int matrix_cholesky(double *A, double *L, long int N); 8 | extern void matrix_copy(double *A, long int R, long int C, double *Cp); 9 | extern int matrix_cholesky_invert(double *A, double *Ainv, long int N); 10 | extern void matrix_constant_multiply(double *A, long int Arows, long int Acols, double constant, double *product); 11 | extern void matrix_add(double *A, long int Arows, long int Acols, double *B, long int Brows, long int Bcols, double *sum); 12 | extern long int find_null_space_vectors(double *A, long int rows, long int cols, double **P, double absolute_tolerance); 13 | extern void svd(double *A, long int rows, long int cols, double *U, double *D, double *V); 14 | extern int matrix_row_reduce(double *A, long int rows, long int cols, double tolerance); 15 | extern long int matrix_nullity(double *A, long int rows, long int cols, double absolute_tolerance); 16 | extern long int find_null_space_decomposition(double *A, long int rows, long int cols, double **D, double **V, double tolerance); 17 | extern long int find_null_space_decomposition(double *A, long int rows, long int cols, double tolerance); 18 | 19 | -------------------------------------------------------------------------------- /src/libUtils/memory_allocations.h: -------------------------------------------------------------------------------- 1 | //======================== 2 | //memory_allocations.h 3 | //======================== 4 | 5 | //**************************************************************************** 6 | // memory allocations 7 | //**************************************************************************** 8 | // int 9 | extern int *malloc_1d_array_int(long int Nx); 10 | extern int **malloc_2d_array_int(long int Nx, long int Ny); 11 | extern int ***malloc_3d_array_int(long int Nx, long int Ny, long int Nz); 12 | extern int ****malloc_4d_array_int(int num_dimensions, long int Nx, long int Ny, long int Nz); 13 | // int - fortran indices 14 | extern int *malloc_1d_array_int_fortran_indices(long int i0, long int i1); 15 | extern int **malloc_2d_array_int_fortran_indices(long int i0, long int i1, long int j0, long int j1); 16 | extern int ***malloc_3d_array_int_fortran_indices(long int i0, long int i1, long int j0, long int j1, long int k0, long int k1); 17 | extern int ****malloc_4d_array_int_fortran_indices(long int I0, long int I1, long int i0, long int i1, long int j0, long int j1, long int k0, long int k1); 18 | // long int 19 | extern long int *malloc_1d_array_long_int(long int Nx); 20 | extern long int **malloc_2d_array_long_int(long int Nx, long int Ny); 21 | // bool 22 | extern bool *malloc_1d_array_bool(long int Nx); 23 | // double 24 | extern double *malloc_1d_array_double(long int Nx); 25 | extern double **malloc_2d_array_double(long int Nx, long int Ny); 26 | extern double ***malloc_3d_array_double(long int Nx, long int Ny, long int Nz); 27 | extern double ****malloc_4d_array_double(int num_dimensions, long int Nx, long int Ny, long int Nz); 28 | // double - fortran indices 29 | extern double *malloc_1d_array_double_fortran_indices(long int i0, long int i1); 30 | extern double **malloc_2d_array_double_fortran_indices(long int i0, long int i1, long int j0, long int j1); 31 | extern double ***malloc_3d_array_double_fortran_indices(long int i0, long int i1, long int j0, long int j1, long int k0, long int k1); 32 | extern double ****malloc_4d_array_double_fortran_indices(long int I0, long int I1, long int i0, long int i1, long int j0, long int j1, long int k0, long int k1); 33 | // char 34 | extern char *malloc_1d_array_char(long int Nx); 35 | extern char **malloc_2d_array_char(long int Nx, long int Ny); 36 | 37 | //**************************************************************************** 38 | // memory re-allocations 39 | //**************************************************************************** 40 | // double 41 | extern double *realloc_1d_array_double(double *f_old, long int Nx); 42 | 43 | //**************************************************************************** 44 | // memory de-allocations 45 | //**************************************************************************** 46 | // double 47 | extern void free_1d_array_double(double *f); 48 | extern void free_2d_array_double(double **f, long int Nx); 49 | extern void free_3d_array_double(double ***f, long int Nx, long int Ny); 50 | extern void free_4d_array_double(double ****f, int num_dimensions, long int Nx, long int Ny); 51 | // double - fortran indices 52 | extern void free_1d_array_double_fortran_indices(double *f,long int i0, long int i1); 53 | extern void free_2d_array_double_fortran_indices(double **f,long int i0, long int i1, long int j0, long int j1); 54 | extern void free_3d_array_double_fortran_indices(double ***f,long int i0, long int i1, long int j0, long int j1, long int k0, long int k1); 55 | extern void free_4d_array_double_fortran_indices(double ****f,long int i0, long int i1, long int j0, long int j1, long int k0, long int k1, long int l0, long int l1); 56 | // int 57 | extern void free_1d_array_int(int *f); 58 | extern void free_2d_array_int(int **f, long int Nx); 59 | extern void free_3d_array_int(int ***f, long int Nx, long int Ny); 60 | extern void free_4d_array_int(int ****f, int num_dimensions, long int Nx, long int Ny); 61 | // int - fortran indices 62 | extern void free_1d_array_int_fortran_indices(int *f,long int i0, long int i1); 63 | extern void free_2d_array_int_fortran_indices(int **f,long int i0, long int i1, long int j0, long int j1); 64 | extern void free_3d_array_int_fortran_indices(int ***f,long int i0, long int i1, long int j0, long int j1, long int k0, long int k1); 65 | extern void free_4d_array_int_fortran_indices(int ****f,long int i0, long int i1, long int j0, long int j1, long int k0, long int k1, long int l0, long int l1); 66 | // long int 67 | extern void free_1d_array_long_int(long int *f); 68 | extern void free_2d_array_long_int(long int **f, long int Nx); 69 | // bool 70 | extern void free_1d_array_bool(bool *f); 71 | //char 72 | extern void free_1d_array_char(char *f); 73 | extern void free_2d_array_char(char **f, long int Nx); 74 | 75 | -------------------------------------------------------------------------------- /src/libUtils/misc.cpp: -------------------------------------------------------------------------------- 1 | // misc.h 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | 10 | #include "misc.h" 11 | 12 | //**************************************************************************** 13 | //print_warning() 14 | //**************************************************************************** 15 | void print_warning(char *fmt, ...) 16 | { 17 | va_list args; 18 | 19 | va_start(args,fmt); // must be run first 20 | fprintf(stdout, "WARNING: "); 21 | vfprintf(stdout, fmt, args); // special printf that takes in the variable argument list 22 | fprintf(stdout,"\n"); 23 | va_end(args); // must be called at the end 24 | 25 | return; 26 | } 27 | 28 | //**************************************************************************** 29 | //quit_error() 30 | //This takes in a variable length argument list in the same way that fprintf 31 | //does. 32 | //**************************************************************************** 33 | void quit_error(char *fmt, ...) 34 | { 35 | FILE *fp[2] = {stderr,stdout}; 36 | va_list args; 37 | int i; 38 | 39 | for(i=0;i<=1;i++) 40 | { 41 | va_start(args,fmt); // must be run first 42 | fprintf(fp[i], "TERMINATING PROGRAM: "); 43 | vfprintf(fp[i], fmt, args); // special printf that takes in the variable argument list 44 | fprintf(fp[i],"\n"); 45 | va_end(args); // must be called at the end 46 | } 47 | 48 | exit(EXIT_FAILURE); 49 | } 50 | 51 | //**************************************************************************** 52 | //quit_error_mpi() 53 | //This takes in a variable length argument list in the same way that fprintf 54 | //does. 55 | //**************************************************************************** 56 | void quit_error_mpi(int myrank, int nprocs, char *fmt, ...) 57 | { 58 | FILE *fp[2] = {stderr,stdout}; 59 | va_list args; 60 | int i; 61 | 62 | for(i=0;i<=1;i++) 63 | { 64 | va_start(args,fmt); // must be run first 65 | fprintf(fp[i], "TERMINATING PROGRAM: "); 66 | vfprintf(fp[i], fmt, args); // special printf that takes in the variable argument list 67 | fprintf(fp[i]," on processor %d of %d", myrank, nprocs); 68 | fprintf(fp[i],"\n"); 69 | va_end(args); // must be called at the end 70 | } 71 | 72 | exit(EXIT_FAILURE); 73 | } 74 | -------------------------------------------------------------------------------- /src/libUtils/misc.h: -------------------------------------------------------------------------------- 1 | //========== 2 | //misc.h 3 | //========== 4 | 5 | #include 6 | 7 | //**************************************************************************** 8 | // defines 9 | //**************************************************************************** 10 | //#define PI 3.14159265358979 11 | #define MAX_VAL(X,Y) ((X)>=(Y)?(X):(Y)) 12 | #define MIN_VAL(X,Y) ((X)<=(Y)?(X):(Y)) 13 | #define MAX(X,Y) (((X) > (Y) ? (X) : (Y))) 14 | #define MIN(X,Y) (((X) < (Y) ? (X) : (Y))) 15 | 16 | #define true 1 17 | #define false 0 18 | 19 | //#define PI 3.1415926535897932384626433832795 20 | #define PI M_PI 21 | //#define E 2.7182818284590452353602874713527 22 | #define E M_E 23 | 24 | #define BIG_NUMBER HUGE_VAL 25 | #define ZERO 1.0e-14 26 | #define SMALL_NUMBER -HUGE_VAL 27 | 28 | #define SQ(X) ( (X) * (X) ) 29 | #define CU(X) ( (X) * (X) * (X) ) 30 | #define ABS(X) sqrt( SQ(X) ) 31 | #define SIGN(X) ABS(X)/X 32 | 33 | // The maximum allowable line length whenever fgets or whatever is used to read 34 | // from a file. 35 | #define MAX_LINE_LENGTH 1000 36 | 37 | // The maximum length for a string which is expected to be fairly short 38 | #define MAX_STRING_LENGTH 1000 39 | 40 | // Convert a string to upper case 41 | #define ucase(STR) {long int __ucase_i;for(__ucase_i=0; __ucase_i 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "misc.h" 12 | #include "string.h" 13 | 14 | //---------------------------------------------------------------------------- 15 | int strcmp_case_insensitive(char *s1, char *s2) 16 | { 17 | // continue comparing while both strings aren't finished 18 | while(*s1 != '\0' && *s2 != '\0') 19 | { 20 | if(tolower(*s1) > tolower(*s2)) return 1; 21 | if(tolower(*s1) < tolower(*s2)) return -1; 22 | s1++; 23 | s2++; 24 | } 25 | if(tolower(*s1) > tolower(*s2)) return 1; 26 | if(tolower(*s1) < tolower(*s2)) return -1; 27 | // otherwise the strings must be the same... 28 | return 0; 29 | } 30 | 31 | //---------------------------------------------------------------------------- 32 | char *copy_string(char *str1) 33 | { 34 | int len; 35 | char *str2; 36 | 37 | len = strlen(str1); 38 | str2 = (char *) malloc(sizeof(char)*(len+1)); 39 | if(str2 == NULL) quit_error((char*)"Malloc failed in copy_string()"); 40 | strcpy(str2,str1); 41 | return str2; 42 | } 43 | 44 | //---------------------------------------------------------------------------- 45 | char *concatenate_strings(char *str1, char *str2) 46 | { 47 | int len1, len2; 48 | char *str3; 49 | 50 | len1 = strlen(str1); 51 | len2 = strlen(str2); 52 | 53 | str3 = (char *) malloc(sizeof(char)*(len1+len2+1)); 54 | if(str3 == NULL) quit_error((char*)"Malloc failed in copy_string()"); 55 | strcpy(str3,str1); 56 | strcpy(str3+len1,str2); 57 | 58 | return str3; 59 | } 60 | 61 | //---------------------------------------------------------------------------- 62 | string convert_int_to_string(int number) 63 | { 64 | ostringstream oss; 65 | oss << number; // Works just like cout 66 | return oss.str(); // Return the underlying string 67 | } 68 | 69 | //---------------------------------------------------------------------------- 70 | string convert_int_to_zero_padded_string(int number) 71 | { 72 | string mode_number_string, pad_zeros; 73 | mode_number_string = convert_int_to_string(number); 74 | if (number>9999) { 75 | quit_error("Too many modes to output, increase digits in output file names"); 76 | } else if ( (number<9999) && (number>=1000) ) { 77 | pad_zeros = ""; 78 | } else if ( (number<1000) && (number>=100) ) { 79 | pad_zeros = "0"; 80 | } else if ( (number<100) && (number>=10) ) { 81 | pad_zeros = "00"; 82 | } else if (number<10) { 83 | pad_zeros = "000"; 84 | } 85 | return pad_zeros + mode_number_string; 86 | } 87 | 88 | //---------------------------------------------------------------------------- 89 | double char_to_double(char *input) 90 | { 91 | std::stringstream ss(input); 92 | double result = 0; 93 | ss >> result; 94 | return result; 95 | } 96 | 97 | //---------------------------------------------------------------------------- 98 | -------------------------------------------------------------------------------- /src/libUtils/string.h: -------------------------------------------------------------------------------- 1 | 2 | #include // Required for stringstreams 3 | #include 4 | 5 | extern int strcmp_case_insensitive(char *s1, char *s2); 6 | 7 | extern char *copy_string(char *str1); 8 | 9 | extern char *concatenate_strings(char *str1, char *str2); 10 | 11 | extern string convert_int_to_string(int number); 12 | extern string convert_int_to_zero_padded_string(int number); 13 | 14 | extern double char_to_double(char *input); 15 | -------------------------------------------------------------------------------- /src/libUtils/time_stats.cpp: -------------------------------------------------------------------------------- 1 | // time_stats.cpp 2 | // **************************************************************************** 3 | #include 4 | // **************************************************************************** 5 | #include "time_stats.h" 6 | // **************************************************************************** 7 | 8 | // **************************************************************************** 9 | // TimeStats::TimeStats() 10 | // **************************************************************************** 11 | TimeStats::TimeStats(long int step_start, long int step_finish) 12 | { 13 | reset(step_start, step_finish); 14 | return; 15 | } 16 | 17 | // **************************************************************************** 18 | // TimeStats::TimeStats() 19 | // **************************************************************************** 20 | void TimeStats::reset(long int step_start, long int step_finish) 21 | { 22 | this->step_start = step_start; 23 | this->step_finish = step_finish; 24 | total_steps = step_finish - step_start; 25 | time(&(time_start)); 26 | 27 | return; 28 | } 29 | 30 | // **************************************************************************** 31 | // TimeStats::convert_seconds() 32 | // **************************************************************************** 33 | inline void TimeStats::convert_seconds(double total_seconds, int &days, int &hours, int &minutes, int &seconds) 34 | { 35 | days = (int) (total_seconds / (60.0*60.0*24.0)); 36 | total_seconds -= (double)(days * 24 * 60 * 60); 37 | hours = (int) (total_seconds / (60.0*60.0)); 38 | total_seconds -= (double)(hours * 60 * 60); 39 | minutes = (int) (total_seconds / (60.0)); 40 | total_seconds -= (double)(minutes * 60); 41 | seconds = (int) total_seconds; 42 | 43 | return; 44 | } 45 | 46 | // **************************************************************************** 47 | // TimeStats::produce_stats() 48 | // **************************************************************************** 49 | void TimeStats::produce_stats(long int step_current) 50 | { 51 | double steps_done = (double) (step_current - step_start); 52 | double steps_remaining = (double) (step_finish - step_current); 53 | int days[2], hours[2], minutes[2], seconds[2]; 54 | double time_spent; 55 | double time_remaining; 56 | time_t time_current; 57 | 58 | // ********************* 59 | // grab the current time 60 | // ********************* 61 | time(&(time_current)); 62 | 63 | time_spent = difftime(time_current, time_start); 64 | 65 | percentage_complete = steps_done / total_steps * 100.0; 66 | 67 | convert_seconds(time_spent, days[0], hours[0], minutes[0], seconds[0]); 68 | 69 | 70 | if( steps_done > 0.0 ) 71 | time_remaining = time_spent / steps_done * steps_remaining; 72 | else 73 | time_remaining = 0.0; 74 | 75 | convert_seconds(time_remaining, days[1], hours[1], minutes[1], seconds[1]); 76 | 77 | if(time_spent > 0.0) 78 | timesteps_per_minute = steps_done / time_spent * 60.0; 79 | else 80 | timesteps_per_minute = 0.0; 81 | 82 | if(days[0] == 0 && days[1] == 0) 83 | { 84 | sprintf(time_spent_string,"%02dh%02dm%02ds", hours[0], minutes[0], seconds[0]); 85 | sprintf(time_remaining_string,"%02dh%02dm%02ds", hours[1], minutes[1], seconds[1]); 86 | } 87 | else 88 | { 89 | sprintf(time_spent_string,"%dd%02dh%02dm%02ds", days[0], hours[0], minutes[0], seconds[0]); 90 | sprintf(time_remaining_string,"%dd%02dh%02dm%02ds", days[1], hours[1], minutes[1], seconds[1]); 91 | } 92 | 93 | return; 94 | } 95 | 96 | 97 | 98 | -------------------------------------------------------------------------------- /src/libUtils/time_stats.h: -------------------------------------------------------------------------------- 1 | // time_stats.h 2 | // **************************************************************************** 3 | #include 4 | // **************************************************************************** 5 | //typedef class TimeStats; 6 | // **************************************************************************** 7 | // TimeStats 8 | // **************************************************************************** 9 | class TimeStats 10 | { 11 | private: 12 | time_t time_start; 13 | long int computationStartStep; 14 | long int step_start; 15 | long int step_finish; 16 | long int total_steps; 17 | inline void convert_seconds(double total_seconds, int &days, int &hours, int &minutes, int &seconds); 18 | public: 19 | char time_spent_string[40]; 20 | char time_remaining_string[40]; 21 | double percentage_complete; 22 | double timesteps_per_minute; 23 | 24 | TimeStats(long int step_start, long int step_finish); 25 | void reset(long int step_start, long int step_finish); 26 | void produce_stats(long int step_current); 27 | }; 28 | // **************************************************************************** 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /src/libUtils/tridiagonal_solver.h: -------------------------------------------------------------------------------- 1 | // tridiagonal_solver.h 2 | 3 | extern void tridiagonal_solver_nondestructive(int N, double *a, double *b, double *c, double *d, double *x, double *bb, double *dd); 4 | extern void tridiagonal_solver_nondestructive_static(int N, double *a, double *b, double *c, double *d, double *x); 5 | extern void tridiagonal_solver_destructive(int N, double *a, double *b, double *c, double *d, double *x); 6 | extern void tridiagonal_solver_periodic_nondestructive(int N, double *a, double *b, double *c, double *d, double *x, double *bb, double *dd, double *C); 7 | extern void tridiagonal_solver_periodic_nondestructive_static(int N, double *a, double *b, double *c, double *d, double *x); 8 | extern void tridiagonal_solver_periodic_destructive(int N, double *a, double *b, double *c, double *d, double *x); 9 | 10 | extern void tridiagonal_solver_test(void); 11 | extern void tridiagonal_solver_periodic_test(void); 12 | 13 | 14 | -------------------------------------------------------------------------------- /tests/snapshot_pod/pbs-script: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # ---------------------------------------- 4 | # Assign pbs settings 5 | 6 | #PBS -S /bin/bash 7 | #PBS -N JdN001 8 | #PBS -l nodes=1 9 | #PBS -l walltime=24:00:00 10 | 11 | # PBS -m ae 12 | 13 | # ---------------------------------------- 14 | # set important file names 15 | 16 | PROGRAM="snapshot_pod" 17 | OUTPUT_FILE=${PROGRAM}".out" 18 | ERROR_FILE=${PROGRAM}".err" 19 | RESULTS_DIR="./results" 20 | 21 | # ---------------------------------------- 22 | # prepare working directory 23 | 24 | cd $PBS_O_WORKDIR 25 | rm -vrf $PROGRAM $OUTPUT_FILE $ERROR_FILE $RESULTS_DIR J* *~ 26 | mkdir $RESULTS_DIR 27 | cp ./snapshot_pod_parallel_cpp/tests/snapshot_pod_mpi/bin/$PROGRAM . 28 | # ---------------------------------------- 29 | # run code 30 | 31 | source $HOME/.bash_profile 32 | ./$PROGRAM 1>$OUTPUT_FILE 2>$ERROR_FILE 33 | 34 | # -------------- EOF --------------------- 35 | 36 | -------------------------------------------------------------------------------- /tests/snapshot_pod/snapshot_pod.in: -------------------------------------------------------------------------------- 1 | #---------------------------------------- 2 | # Snapshot POD input deck 3 | #---------------------------------------- 4 | 5 | x_min = -1.0 6 | x_max = 4.0 7 | y_min = -1.5 8 | y_max = 1.5 9 | z_min = -1.0 10 | z_max = 1.0 11 | 12 | #x_min = -1000.0 13 | #x_max = 1000.0 14 | #y_min = -1000 15 | #y_max = 1000 16 | #z_min = -1000.0 17 | #z_max = 1000.0 18 | 19 | #temporal_correlation_type = u 20 | #temporal_correlation_type = v 21 | #temporal_correlation_type = w 22 | #temporal_correlation_type = p 23 | temporal_correlation_type = ke 24 | #temporal_correlation_type = q 25 | 26 | normalisation = none 27 | #normalisation = local 28 | #normalisation = global 29 | 30 | snapshot_list_filename = ./data/2cycle_dN001.list 31 | snapshot_dir = ./data/ 32 | file_name_with_cell_volumes = ./data/cell_volumes.vtk 33 | 34 | restart = false 35 | #restart = ./restart 36 | 37 | two_dimensional = true 38 | #two_dimensional = false 39 | 40 | #test_orthogonality = true 41 | test_orthogonality = false 42 | 43 | #check_eigensolution = true 44 | check_eigensolution = false 45 | 46 | dt = 0.0095 47 | 48 | threshhold_energy = 100.0 49 | min_number_of_eigenvalues = 10 50 | max_number_of_eigenvalues = 10 51 | 52 | #---------------------------------- 53 | # End of Deck 54 | #---------------------------------- 55 | 56 | -------------------------------------------------------------------------------- /tests/snapshot_pod_mpi/pbs-script: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # ---------------------------------------- 4 | # Assign pbs settings 5 | 6 | #PBS -S /bin/bash 7 | #PBS -N JdN001_N06 8 | #PBS -l nodes=16 9 | #PBS -l walltime=24:00:00 10 | 11 | # PBS -m ae 12 | 13 | # ---------------------------------------- 14 | # set important file names 15 | 16 | PROGRAM="snapshot_pod_mpi" 17 | OUTPUT_FILE=${PROGRAM}".out" 18 | ERROR_FILE=${PROGRAM}".err" 19 | RESULTS_DIR="./results" 20 | 21 | # ---------------------------------------- 22 | # prepare working directory 23 | 24 | cd $PBS_O_WORKDIR 25 | rm -vrf $PROGRAM $OUTPUT_FILE $ERROR_FILE $RESULTS_DIR J* *~ 26 | mkdir $RESULTS_DIR 27 | cp ./snapshot_pod_parallel_cpp/tests/snapshot_pod_mpi/bin/$PROGRAM . 28 | # ---------------------------------------- 29 | # run code 30 | 31 | source $HOME/.bash_profile 32 | module load openmpi/1.2.4-gcc 33 | mpiexec -np 16 ./$PROGRAM 1>$OUTPUT_FILE 2>$ERROR_FILE 34 | 35 | # -------------- EOF --------------------- 36 | 37 | -------------------------------------------------------------------------------- /tests/snapshot_pod_mpi/snapshot_pod_mpi.in: -------------------------------------------------------------------------------- 1 | #---------------------------------------- 2 | # Snapshot POD input deck 3 | #---------------------------------------- 4 | 5 | x_min = -1000.0 6 | x_max = 1000.0 7 | y_min = -1000 8 | y_max = 1000 9 | z_min = -1000.0 10 | z_max = 1000.0 11 | 12 | #temporal_correlation_type = u 13 | #temporal_correlation_type = v 14 | #temporal_correlation_type = w 15 | #temporal_correlation_type = p 16 | temporal_correlation_type = ke 17 | #temporal_correlation_type = q 18 | 19 | normalisation = none 20 | #normalisation = local 21 | #normalisation = global 22 | 23 | snapshot_list_filename = ./data/dN001_N06.list 24 | snapshot_dir = ./data/ 25 | file_name_with_cell_volumes = ./data/cell_volumes.vtk 26 | 27 | restart = false 28 | #restart = ./restart 29 | 30 | two_dimensional = true 31 | #two_dimensional = false 32 | 33 | #test_orthogonality = true 34 | test_orthogonality = false 35 | 36 | #check_eigensolution = true 37 | check_eigensolution = false 38 | 39 | dt = 0.0095 40 | 41 | threshhold_energy = 100.0 42 | min_number_of_eigenvalues = 10 43 | max_number_of_eigenvalues = 10 44 | 45 | #---------------------------------- 46 | # End of Deck 47 | #---------------------------------- 48 | 49 | --------------------------------------------------------------------------------