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