Exemplo n.º 1
0
 def plot(self, V):
     f_source = df.interpolate(self, V)
     from util import matplot4dolfin
     matplot = matplot4dolfin()
     fig = matplot.plot(f_source)
     #         matplot.show()
     return fig
Exemplo n.º 2
0
 def _plot_mpl(self, SAVE=False):
     import matplotlib.pyplot as plt
     from util import matplot4dolfin
     matplot = matplot4dolfin()
     # codes for plotting solutions
     import matplotlib as mpl
     for i, titl in enumerate(self.titles):
         # get solution
         try:
             soln = getattr(self, '_'.join(['states', self.sols[i]]))
         except AttributeError:
             print(self.sols_names[i] + 'solution not found!')
             pass
         else:
             soln = soln.split(True)
             fig, axes = plt.subplots(nrows=2,
                                      ncols=2,
                                      sharex=True,
                                      sharey=True,
                                      num=i,
                                      figsize=(10, 6))
             for j, ax in enumerate(axes.flat):
                 plt.axes(ax)
                 sub_fig = matplot.plot(soln[j])
                 plt.axis('tight')
                 ax.set_title(self.sub_titles[j])
             cax, kw = mpl.colorbar.make_axes([ax for ax in axes.flat])
             plt.colorbar(sub_fig, cax=cax,
                          **kw)  # TODO: fix the issue of common color range
             # set common titles
             fig.suptitle(titl)
             if SAVE:
                 matplot.save(self.savepath,
                              self.sols_names[i] + '.png',
                              bbox_inches='tight')
Exemplo n.º 3
0
 def plot_soln(self,soln_f):
     """
     Plot solution function.
     """
     from util import matplot4dolfin
     matplot=matplot4dolfin()
     fig=matplot.plot(soln_f)
     return fig
Exemplo n.º 4
0
 def plot(self, V):
     u_coeff = df.interpolate(self, V)
     from util import matplot4dolfin
     matplot = matplot4dolfin(
         overloaded=False
     )  # switch overloaded to use the default or the manually coded plotting function
     fig = matplot.plot(u_coeff)
     #         matplot.show()
     return fig
Exemplo n.º 5
0
 def plot_data(self):
     """
     Plot the data information.
     """
     import matplotlib.pyplot as plt
     from util import matplot4dolfin
     matplot = matplot4dolfin()
     fig = matplot.plot(self.pde.mesh)
     plt.axis('tight')
     #         plt.plot(self.loc[:,0],self.loc[:,1],'bo',markersize=10)
     plt.scatter(self.loc[:, 0],
                 self.loc[:, 1],
                 c=self.obs,
                 s=200,
                 zorder=2)
     #         plt.xlim(0,1); plt.ylim(0,1)
     #         plt.axis('tight')
     #         plt.xlabel('x',fontsize=12); plt.ylabel('y',fontsize=12,rotation=0)
     #         plt.title('Observations on selected locations',fontsize=12)
     #         matplot.show()
     return fig
Shiwei Lan @ U of Warwick, 2016
"""

import os
import dolfin as df
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mp

from Elliptic_dili import Elliptic
import sys

sys.path.append("../")
from util import matplot4dolfin

matplot = matplot4dolfin()

# define the inverse problem
np.random.seed(2017)
SNR = 100
elliptic = Elliptic(nx=40, ny=40, SNR=SNR)

# algorithms
algs = ('pCN', 'infMALA', 'infHMC', 'DRinfmMALA', 'DRinfmHMC', 'DILI',
        'aDRinfmMALA', 'aDRinfmHMC')
alg_names = ('pCN', '$\infty$-MALA', '$\infty$-HMC', 'DR-$\infty$-mMALA',
             'DR-$\infty$-mHMC', 'DILI', 'aDR-$\infty$-mMALA',
             'aDR-$\infty$-mHMC')
num_algs = len(algs)
# preparation for estimates
folder = './analysis_f_SNR' + str(SNR)