Raw File
script.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#####################################################################################
# This file is part of NS2DDV.                                                      #
#                                                                                   #
# Copyright(C) 2011-2018    C. Calgaro  (caterina.calgaro@math.univ-lille1.fr)      #
#                           E. Creusé   (emmanuel.creuse@math.univ-lille1.fr)       #
#                           T. Goudon   (thierry.goudon@inria.fr)                   #
#                           A. Mouton   (alexandre.mouton@math.univ-lille1.fr)      #
#                                                                                   #
# NS2DDV is free software: you can redistribute it and/or modify it under the terms #
# of the GNU General Public License as published by the Free Software Foundation,   #
# either version 3 of the License, or (at your option) any later version.           #
#                                                                                   #
# NS2DDV is distributed in the hope that it will be useful, but WITHOUT ANY         #
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A   #
# PARTICULAR PURPOSE. See the GNU General Public License for more details.          #
#                                                                                   #
# You should have received a copy of the GNU General Public License along with      #
# NS2DDV. If not, see <http://www.gnu.org/licenses/>.                               #
#####################################################################################

# Import the module for plotting the contents of HDF5 files
from plots import *

# Import the module for building movies
from make_movie import *


meshh5 = '/home/mouton/NS2DDV/current/RESULTS/diags_MESH_0.h5'
tuple_inches_figsize = (19.2,12)
outputpng = './test.png'
plot_mesh(meshh5, 'P1', 'P1 mesh', tuple_inches_figsize=(19.2,12.), outputpng='./mesh_force.png', \
          list_bbox=[0., 3., -6., 7.])
plot_mesh(meshh5, 'P1', 'P1 mesh')
exit()


inputh5 = '/home/mouton/NS2DDV/current/RESULTS/diags_4.h5'
plot_contour(inputh5, 'Velocity_x')
plot_contour(inputh5, 'Velocity_x', aliasfield='ux', list_bbox=[-1., 2., -1., 8.])

# Build a list of files diags_0.h5, diags_1.h5, ... diags_22.h5
inputh5set = []
nfiles = 36
ndigits = int(numpy.ceil(numpy.log10(nfiles))+1)
for i in range(0,nfiles):
    inputh5 = '/home/mouton/NS2DDV/current/RESULTS/diags-1_'+str(i)+'.h5'
    inputh5set.append(inputh5)

#plot_contour_set(inputh5set, 'Velocity_x')
#plot_contour_set(inputh5set, 'Velocity_x', \
#                     aliasfield='ux', \
#                     nlevels=10, \
#                     fix_isovalues=False, \
#                     list_bbox=[0., 1., 0., 1.], \
#                     tuple_anchor_legend=(1.01,1.01), \
#                     tuple_inches_figsize=(19.2, 12.), \
#                     outputdir='.')
plot_pseudocolor_set(inputh5set, field, \
                         aliasfield='', \
                         list_minmax=[], \
                         list_bbox=['default', 'default', 'default', 'default'], \
                         tuple_leg_position=(0.8,0.45,0.2,0.3), \
                         tuple_inches_figsize=(19.2, 12.), \
                         outputdir='.')

plot_pseudocolor(inputh5, 'Velocity_x', aliasfield='ux', list_minmax=[], \
                     tuple_leg_position=(0.8,0.45,0.2,0.3), \
                     tuple_inches_figsize=(19.2,12.), \
                     outputpng='./temp.png')

exit()








# Build a list of files diags_0.h5, diags_1.h5, ... diags_22.h5
inputh5set = []
nfiles = 36
ndigits = int(numpy.ceil(numpy.log10(nfiles))+1)
for i in range(0,nfiles):
    inputh5 = '/home/mouton/NS2DDV/current/RESULTS/diags-1_'+str(i)+'.h5'
    inputh5set.append(inputh5)

#### We aim to build a movie that shows the time dynamics of ux, uy, and p

# Limits in x-direction ('default' or a list of 2 floats)
list_xlim = 'default'

# Size of figure in inches
tuple_inches_figsize = (19.2,12)

# Directory for output PNG files
outputdir = './tmp'

# Relative position of the legend
tuple_anchor_legend = (1.04,1.04)


# Build 10 isovalues for ux
list_min = []
list_max = []
for inputh5 in inputh5set:
   theminmax = extract_minmax(inputh5, 'Velocity_x')
   list_min.append(theminmax[0])
   list_max.append(theminmax[1])
list_minmax = [min(list_min), max(list_max)]
nlevels = 10

# Plot ux
plot_contour_set(inputh5set, 'Velocity_x', 'ux', nlevels, \
                     list_minmax, list_xlim, tuple_anchor_legend, \
                     tuple_inches_figsize, outputdir)

# Build 10 isovalues for uy
list_min = []
list_max = []
for inputh5 in inputh5set:
   theminmax = extract_minmax(inputh5, 'Velocity_y')
   list_min.append(theminmax[0])
   list_max.append(theminmax[1])
list_minmax = [min(list_min), max(list_max)]
nlevels = 10

# Plot uy
plot_contour_set(inputh5set, 'Velocity_y', 'uy', nlevels, \
                     list_minmax, list_xlim, tuple_anchor_legend, \
                     tuple_inches_figsize, outputdir)

# Build 10 isovalues for p
list_min = []
list_max = []
for inputh5 in inputh5set:
   theminmax = extract_minmax(inputh5, 'Pressure')
   list_min.append(theminmax[0])
   list_max.append(theminmax[1])
list_minmax = [min(list_min), max(list_max)]
nlevels = 10

# Plot uy
plot_contour_set(inputh5set, 'Pressure', 'p', nlevels, \
                     list_minmax, list_xlim, tuple_anchor_legend, \
                     tuple_inches_figsize, outputdir)


# Transform each list [diags_i_ux.png, diags_i_uy.png, diags_i_p.png]
# into a mosaic-type picture diags_i.png
for i in range(0,nfiles):
   inputpngs = [outputdir+'/diags-1_'+str(i).rjust(ndigits, '0')+'_ux.png', \
                outputdir+'/diags-1_'+str(i).rjust(ndigits, '0')+'_uy.png', \
                outputdir+'/diags-1_'+str(i).rjust(ndigits, '0')+'_p.png']
   outputpng = outputdir+'/diags-1_'+str(i).rjust(ndigits, '0')+'.png'
   build_mosaic(inputpngs, 2, 2, outputpng)

# Prepare the list of PNG frames to encode
inputpngs = []
for i in range(0,nfiles):
   inputpngs.append(outputdir+'/diags-1_'+str(i).rjust(ndigits, '0')+'.png')

# Encode movie
encode_video(inputpngs, './tmp', 'simulation-1.mp4')
back to top