xref: /libCEED/examples/fluids/conv_plot.py (revision 1f814bfddc5363a01c33fc7166b9ab66f1decae9)
1#!/usr/bin/env python3
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
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')
28    parser.add_argument('--conv_result_file',
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]
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]
51        H = C[i] * h**p # H = C h^p
52        E = data['rel_error']
53        log_h = np.log10(h)
54        log_H = np.log10(H)
55        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) + ')')
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')
64    xlim(.03, .3)
65    fig.tight_layout()
66    plt.savefig('conv_plt_h.png', bbox_inches='tight')
67
68
69if __name__ == "__main__":
70    plot()
71