conv_plot.py (1f814bfddc5363a01c33fc7166b9ab66f1decae9) conv_plot.py (19c461940713c27deb7bdc6400a2fadc4b78b6be)
1#!/usr/bin/env python3
1#!/usr/bin/env python3
2
2# Copyright (c) 2017-2018, Lawrence Livermore National Security, LLC.
3# Produced at the Lawrence Livermore National Laboratory. LLNL-CODE-734707.
4# All Rights reserved. See files LICENSE and NOTICE for details.
5#
6# This file is part of CEED, a collection of benchmarks, miniapps, software
7# libraries and APIs for efficient high-order finite element and spectral
8# element discretizations for exascale applications. For more information and
9# source code availability see http://github.com/ceed.
10#
11# The CEED research is supported by the Exascale Computing Project 17-SC-20-SC,
12# a collaborative effort of two U.S. Department of Energy organizations (Office
13# of Science and the National Nuclear Security Administration) responsible for
14# the planning and preparation of a capable exascale ecosystem, including
15# software, applications, hardware, advanced system engineering and early
16# testbed platforms, in support of the nation's exascale computing imperative.
17
3# Copyright (c) 2017-2018, Lawrence Livermore National Security, LLC.
4# Produced at the Lawrence Livermore National Laboratory. LLNL-CODE-734707.
5# All Rights reserved. See files LICENSE and NOTICE for details.
6#
7# This file is part of CEED, a collection of benchmarks, miniapps, software
8# libraries and APIs for efficient high-order finite element and spectral
9# element discretizations for exascale applications. For more information and
10# source code availability see http://github.com/ceed.
11#
12# The CEED research is supported by the Exascale Computing Project 17-SC-20-SC,
13# a collaborative effort of two U.S. Department of Energy organizations (Office
14# of Science and the National Nuclear Security Administration) responsible for
15# the planning and preparation of a capable exascale ecosystem, including
16# software, applications, hardware, advanced system engineering and early
17# testbed platforms, in support of the nation's exascale computing imperative.
18
18import numpy as np
19import pandas as pd
20import argparse
21from pylab import *
22from matplotlib import use
23
24
25def plot():
26 # Define argparse for the input variables
27 parser = argparse.ArgumentParser(description='Get input arguments')
19import pandas as pd
20import argparse
21from pylab import *
22from matplotlib import use
23
24
25def plot():
26 # Define argparse for the input variables
27 parser = argparse.ArgumentParser(description='Get input arguments')
28 parser.add_argument('--conv_result_file',
28 parser.add_argument('-f',
29 dest='conv_result_file',
30 type=str,
31 required=True,
32 help='Path to the CSV file')
33 args = parser.parse_args()
34 conv_result_file = args.conv_result_file
35
36 # Load the data
37 runs = pd.read_csv(conv_result_file)
38 colors = ['orange', 'red', 'navy', 'green', 'magenta',
39 'gray', 'blue', 'purple', 'pink', 'black']
40 res = 'mesh_res'
41 fig, ax = plt.subplots()
29 dest='conv_result_file',
30 type=str,
31 required=True,
32 help='Path to the CSV file')
33 args = parser.parse_args()
34 conv_result_file = args.conv_result_file
35
36 # Load the data
37 runs = pd.read_csv(conv_result_file)
38 colors = ['orange', 'red', 'navy', 'green', 'magenta',
39 'gray', 'blue', 'purple', 'pink', 'black']
40 res = 'mesh_res'
41 fig, ax = plt.subplots()
42 # Arbitrary coefficients
43 C = [2.2e-2, .24e0, .22e0, .7e0, 2.5e0,
44 3e0, 3.5e0, 4e0, 4.5e0, 5e0]
42
45 i = 0
46 for group in runs.groupby('degree'):
47 data = group[1]
48 data = data.sort_values('rel_error')
49 p = data['degree'].values[0]
50 h = 1/data[res]
43 i = 0
44 for group in runs.groupby('degree'):
45 data = group[1]
46 data = data.sort_values('rel_error')
47 p = data['degree'].values[0]
48 h = 1/data[res]
51 H = C[i] * h**p # H = C h^p
52 E = data['rel_error']
49 E = data['rel_error']
53 log_h = np.log10(h)
54 log_H = np.log10(H)
50 h_min = amin(h)
51 E_min = amin(E)
52 H = E_min * (h/h_min)**p
55 ax.loglog(h, E, 'o', color=colors[i])
53 ax.loglog(h, E, 'o', color=colors[i])
56 m, b = np.polyfit(log_h, log_H, 1)
57 ax.loglog(h, 10**b * h**m, '--', color=colors[i], label='O(h^' + str(p) + ')')
54 ax.loglog(h, H, '--', color=colors[i], label='O(h$^' + str(p) + '$)')
58 i = i + 1
59
60 ax.legend(loc='best')
61 ax.set_xlabel('h')
62 ax.set_ylabel('Relative Error')
63 ax.set_title('Convergence by h Refinement')
55 i = i + 1
56
57 ax.legend(loc='best')
58 ax.set_xlabel('h')
59 ax.set_ylabel('Relative Error')
60 ax.set_title('Convergence by h Refinement')
64 xlim(.03, .3)
65 fig.tight_layout()
66 plt.savefig('conv_plt_h.png', bbox_inches='tight')
61 plt.savefig('conv_plt_h.png')
67
68
69if __name__ == "__main__":
70 plot()
62
63
64if __name__ == "__main__":
65 plot()