v0.14.0
Loading...
Searching...
No Matches
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.
14if [[ "$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
23fi
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')
27grep -E "(Propagation step|F_lambda2|Crack surface area)" log | \
28perl -pe 's/\e\[[0-9;]*m//g' | \
29awk '{$1=""; $2=""; sub(" ", " "); print}' | awk '{$1=$1;print}' | \
30sed 'N; s/\nCrack//;P;D'| sed '/Not Converged/ s/$/ TODELETE/' | \
31sed 's/Not Converged //g'| \
32awk '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}'| \
34tee data_raw.dat
35
36# Keep unique updated data only (in case of restart from previous steps)
37cat 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
40cat unique_analysis_steps.dat | grep -v "TODELETE" | \
41sed 's/[[:space:]]\{1,\}[^[:space:]]\{1,\}$//' | \
42tee displacement_loadFactor_crackArea_energy.txt
43
44# Format columns
45printf "%14s %14s %14s %14s %14s\n" \
46$(cat displacement_loadFactor_crackArea_energy.txt) > temp_file; \
47mv temp_file displacement_loadFactor_crackArea_energy.txt
48
49# Make a csv copy
50awk '{print $1","$2","$3","$4","$5}' displacement_loadFactor_crackArea_energy.txt| \
51tee displacement_loadFactor_crackArea_energy.csv
52
53# Print final data file to console
54cat displacement_loadFactor_crackArea_energy.txt
55
56# Remove text file
57rm displacement_loadFactor_crackArea_energy.txt
58
59# Make graphs using gnuplot. Note: ignore the first row of zeros when plotting
60# crack area
61DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
62gnuplot -e "load '$DIR/get_graphs.gnu'; quit"
63
64# Convert graphs on .ps to .pdf
65for i in `ls *.ps`; do
66 ps2pdf $i;
67 rm $i;
68 # echo 'Converted $i into pdf, deleted original file.';
69done
70
71# Delete output files of non-converged steps if '-d' option is used
72if [[ $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
81fi
82
83# Open pdf graphs
84machine="$(uname -s)"
85# echo ${machine}
86if [[ ${machine} = "Darwin" && "$1" != "-s" ]]
87then
88 # echo "This is a Mac computer"
89 open graph_*.pdf
90else
91 echo "PDF graphs are ready to open."
92fi
93
94# Remove unnecessary files
95rm -f *.dat