v0.14.0
plotting_data.sh
Go to the documentation of this file.
1 #!/bin/bash
2 # This script reads the log file then extracts result data and
3 # plots relation graphs in MoFEM fracture module.
4 # Plot setttings can be changed by modifying the gnuplot script get_graphs.gnu
5 #
6 # Input:
7 # log file named 'log'
8 #
9 # Output:
10 # pdf graphs
11 # displacement_loadFactor_crackArea_energy.csv
12 
13 # Help.
14 if [[ "$1" == "-h" || "$1" == "--help" ]]; then
15  echo 'Plotting script for MoFEM Fracture Module
16  Usage:
17  plotting_data.sh Create and open graphs from log file
18  plotting_data.sh -s Create only, do not open graphs. Silent
19  plotting_data.sh -d Delete all output files of non-converged steps
20  plotting_data.sh -d out_skin Delete out_skin* files of non-converged steps
21  '
22  exit 0
23 fi
24 
25 # Create raw data file of displacement - loadFactor - crack area - energy
26 # from log file (append 'TODELETE' to end of line with 'Not Converged')
27 grep -E "(Propagation step|F_lambda2|Crack surface area)" log | \
28 perl -pe 's/\e\[[0-9;]*m//g' | \
29 awk '{$1=""; $2=""; sub(" ", " "); print}' | awk '{$1=$1;print}' | \
30 sed 'N; s/\nCrack//;P;D'| sed '/Not Converged/ s/$/ TODELETE/' | \
31 sed 's/Not Converged //g'| \
32 awk 'BEGIN {print "-1 0 0 0 0 0"} /F_lambda2 / { lambda = $NF } \
33 /Propagation step/ { F=lambda; print $3 "\t" 2*$9/F "\t" F "\t" $13 "\t" $9 "\t" $NF}'| \
34 tee data_raw.dat
35 
36 # Keep unique updated data only (in case of restart from previous steps)
37 cat data_raw.dat | sed '1!G;h;$!d' | sort -u -n | tee unique_analysis_steps.dat
38 
39 # Remove unused last column data 'TODELETE', and write to a text file
40 cat unique_analysis_steps.dat | grep -v "TODELETE" | \
41 sed 's/[[:space:]]\{1,\}[^[:space:]]\{1,\}$//' | \
42 tee displacement_loadFactor_crackArea_energy.txt
43 
44 # Format columns
45 printf "%14s %14s %14s %14s %14s\n" \
46 $(cat displacement_loadFactor_crackArea_energy.txt) > temp_file; \
47 mv temp_file displacement_loadFactor_crackArea_energy.txt
48 
49 # Make a csv copy
50 awk '{print $1","$2","$3","$4","$5}' displacement_loadFactor_crackArea_energy.txt| \
51 tee displacement_loadFactor_crackArea_energy.csv
52 
53 # Print final data file to console
54 cat displacement_loadFactor_crackArea_energy.txt
55 
56 # Remove text file
57 rm displacement_loadFactor_crackArea_energy.txt
58 
59 # Make graphs using gnuplot. Note: ignore the first row of zeros when plotting
60 # crack area
61 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
62 gnuplot -e "load '$DIR/get_graphs.gnu'; quit"
63 
64 # Convert graphs on .ps to .pdf
65 for i in `ls *.ps`; do
66  ps2pdf $i;
67  rm $i;
68  # echo 'Converted $i into pdf, deleted original file.';
69 done
70 
71 # Delete output files of non-converged steps if '-d' option is used
72 if [[ $1 = "-d" ]]; then
73  echo -e "\nDeleting output files $2* associated with non-converged steps"
74  cat unique_analysis_steps.dat | grep TODELETE | awk '{print $1}' | \
75  tee non_converged_steps.txt
76  while read p; do
77  # echo "Non-converged step: $p"
78  rm -rf $2*_$p.*
79  done <non_converged_steps.txt
80 
81 fi
82 
83 # Open pdf graphs
84 machine="$(uname -s)"
85 # echo ${machine}
86 if [[ ${machine} = "Darwin" && "$1" != "-s" ]]
87 then
88  # echo "This is a Mac computer"
89  open graph_*.pdf
90 else
91  echo "PDF graphs are ready to open."
92 fi
93 
94 # Remove unnecessary files
95 rm -f *.dat