#!/usr/bin/env python
"""The WaveBlocks Project

Compute the differences of serveral wavepackets to the reference wavepacket.

@author: O. Rietmann
@copyright: Copyright (C) 2020 O. Rietmann
@license: Modified BSD License
"""

import argparse
import os

from WaveBlocksND import IOManager
from WaveBlocksND import GlobalDefaults as GD
from WaveBlocksND.Interface import ComputeConvergence


parser = argparse.ArgumentParser()

parser.add_argument("-d", "--datafile",
                    type = str,
                    help = "The data file to store the convergence results",
                    nargs = 1)

parser.add_argument("-i", "--interval",
                    type = float,
                    help = "x-axis interval [a, b] for plot",
                    nargs = 2)

parser.add_argument("-c", "--coefficient",
                    type = float,
                    help = "Prefactor c of the monomial c*h^p",
                    nargs = "*")
                    
parser.add_argument("-p", "--power",
                    type = int,
                    help = "Power p of the monomial c*h^p",
                    nargs = "*")

parser.add_argument("-l", "--linestyle",
                    type = str,
                    help = "Linestyle for plotting",
                    nargs = "*",
                    default = ["--"])

parser.add_argument("-x", "--xlabel",
                    type = str,
                    help = "Running variable of the line (the x-axis label).",
                    nargs = 1)

# TODO: Filter type of objects
# parser.add_argument("-t", "--type",
#                     help = "The type of objects to consider.",
#                     type = str,
#                     default = "all")

args = parser.parse_args()


# Read file with convergence data
datafile = os.path.abspath(args.datafile[0])
if os.path.exists(datafile):
    print("Convergence file already exists: '{}'".format(datafile))
    print("Adding new datasets to file: '{}'".format(datafile))
else:
    raise IOError("Convergence file does not exist: '{}'".format(datafile))

xvalues = args.interval
cvalues = args.coefficient
pvalues = args.power
linestyles = args.linestyle
xlabel = args.xlabel[0]

if len(cvalues) != len(pvalues):
    raise IOError("Length of coefficients and powers needs to be the same.")
if len(linestyles) == 1 and len(cvalues) > 1:
    linestyles *= len(cvalues)
elif len(linestyles) != len(cvalues):
    raise IOError("Incompatible number of linestyles and coefficients.")

print("**************************************************")
print("***               Adding Lines                 ***")
print("**************************************************")

blockid = 0

print("Adding convergence line in data block '{}'".format(blockid))

iom = IOManager()
iom.open_file(datafile)
for c, p, l in zip(cvalues, pvalues, linestyles):
    label = "$O(" + xlabel + "^" + str(p) + ")$"
    diff = [c * xvalues[0]**p, c * xvalues[1]**p]
    if iom.has_convergence(label):
        print("Warning: Overwriting dataset with label '{}'".format(label))
        iom.delete_convergence(label)
    iom.add_convergence(label, xvalues, linestyle=l)
    iom.save_convergence(label, diff, 'L2diff')
    iom.save_convergence(label, diff, 'coeffdiff')
iom.finalize()

print("**************************************************")
print("***           Adding Lines Finished            ***")
print("**************************************************")

b32546183455a7e2f09c4e7b21c5ec542f6651af
<mask token>

<mask token>
parser.add_argument('-d', '--datafile', type=str, help=
    'The data file to store the convergence results', nargs=1)
parser.add_argument('-i', '--interval', type=float, help=
    'x-axis interval [a, b] for plot', nargs=2)
parser.add_argument('-c', '--coefficient', type=float, help=
    'Prefactor c of the monomial c*h^p', nargs='*')
parser.add_argument('-p', '--power', type=int, help=
    'Power p of the monomial c*h^p', nargs='*')
parser.add_argument('-l', '--linestyle', type=str, help=
    'Linestyle for plotting', nargs='*', default=['--'])
parser.add_argument('-x', '--xlabel', type=str, help=
    'Running variable of the line (the x-axis label).', nargs=1)
<mask token>
if os.path.exists(datafile):
    print("Convergence file already exists: '{}'".format(datafile))
    print("Adding new datasets to file: '{}'".format(datafile))
else:
    raise IOError("Convergence file does not exist: '{}'".format(datafile))
<mask token>
if len(cvalues) != len(pvalues):
    raise IOError('Length of coefficients and powers needs to be the same.')
if len(linestyles) == 1 and len(cvalues) > 1:
    linestyles *= len(cvalues)
elif len(linestyles) != len(cvalues):
    raise IOError('Incompatible number of linestyles and coefficients.')
print('**************************************************')
print('***               Adding Lines                 ***')
print('**************************************************')
<mask token>
print("Adding convergence line in data block '{}'".format(blockid))
<mask token>
iom.open_file(datafile)
for c, p, l in zip(cvalues, pvalues, linestyles):
    label = '$O(' + xlabel + '^' + str(p) + ')$'
    diff = [c * xvalues[0] ** p, c * xvalues[1] ** p]
    if iom.has_convergence(label):
        print("Warning: Overwriting dataset with label '{}'".format(label))
        iom.delete_convergence(label)
    iom.add_convergence(label, xvalues, linestyle=l)
    iom.save_convergence(label, diff, 'L2diff')
    iom.save_convergence(label, diff, 'coeffdiff')
iom.finalize()
print('**************************************************')
print('***           Adding Lines Finished            ***')
print('**************************************************')

<mask token>
parser = argparse.ArgumentParser()
parser.add_argument('-d', '--datafile', type=str, help=
    'The data file to store the convergence results', nargs=1)
parser.add_argument('-i', '--interval', type=float, help=
    'x-axis interval [a, b] for plot', nargs=2)
parser.add_argument('-c', '--coefficient', type=float, help=
    'Prefactor c of the monomial c*h^p', nargs='*')
parser.add_argument('-p', '--power', type=int, help=
    'Power p of the monomial c*h^p', nargs='*')
parser.add_argument('-l', '--linestyle', type=str, help=
    'Linestyle for plotting', nargs='*', default=['--'])
parser.add_argument('-x', '--xlabel', type=str, help=
    'Running variable of the line (the x-axis label).', nargs=1)
args = parser.parse_args()
datafile = os.path.abspath(args.datafile[0])
if os.path.exists(datafile):
    print("Convergence file already exists: '{}'".format(datafile))
    print("Adding new datasets to file: '{}'".format(datafile))
else:
    raise IOError("Convergence file does not exist: '{}'".format(datafile))
xvalues = args.interval
cvalues = args.coefficient
pvalues = args.power
linestyles = args.linestyle
xlabel = args.xlabel[0]
if len(cvalues) != len(pvalues):
    raise IOError('Length of coefficients and powers needs to be the same.')
if len(linestyles) == 1 and len(cvalues) > 1:
    linestyles *= len(cvalues)
elif len(linestyles) != len(cvalues):
    raise IOError('Incompatible number of linestyles and coefficients.')
print('**************************************************')
print('***               Adding Lines                 ***')
print('**************************************************')
blockid = 0
print("Adding convergence line in data block '{}'".format(blockid))
iom = IOManager()
iom.open_file(datafile)
for c, p, l in zip(cvalues, pvalues, linestyles):
    label = '$O(' + xlabel + '^' + str(p) + ')$'
    diff = [c * xvalues[0] ** p, c * xvalues[1] ** p]
    if iom.has_convergence(label):
        print("Warning: Overwriting dataset with label '{}'".format(label))
        iom.delete_convergence(label)
    iom.add_convergence(label, xvalues, linestyle=l)
    iom.save_convergence(label, diff, 'L2diff')
    iom.save_convergence(label, diff, 'coeffdiff')
iom.finalize()
print('**************************************************')
print('***           Adding Lines Finished            ***')
print('**************************************************')

<mask token>
import argparse
import os
from WaveBlocksND import IOManager
from WaveBlocksND import GlobalDefaults as GD
from WaveBlocksND.Interface import ComputeConvergence
parser = argparse.ArgumentParser()
parser.add_argument('-d', '--datafile', type=str, help=
    'The data file to store the convergence results', nargs=1)
parser.add_argument('-i', '--interval', type=float, help=
    'x-axis interval [a, b] for plot', nargs=2)
parser.add_argument('-c', '--coefficient', type=float, help=
    'Prefactor c of the monomial c*h^p', nargs='*')
parser.add_argument('-p', '--power', type=int, help=
    'Power p of the monomial c*h^p', nargs='*')
parser.add_argument('-l', '--linestyle', type=str, help=
    'Linestyle for plotting', nargs='*', default=['--'])
parser.add_argument('-x', '--xlabel', type=str, help=
    'Running variable of the line (the x-axis label).', nargs=1)
args = parser.parse_args()
datafile = os.path.abspath(args.datafile[0])
if os.path.exists(datafile):
    print("Convergence file already exists: '{}'".format(datafile))
    print("Adding new datasets to file: '{}'".format(datafile))
else:
    raise IOError("Convergence file does not exist: '{}'".format(datafile))
xvalues = args.interval
cvalues = args.coefficient
pvalues = args.power
linestyles = args.linestyle
xlabel = args.xlabel[0]
if len(cvalues) != len(pvalues):
    raise IOError('Length of coefficients and powers needs to be the same.')
if len(linestyles) == 1 and len(cvalues) > 1:
    linestyles *= len(cvalues)
elif len(linestyles) != len(cvalues):
    raise IOError('Incompatible number of linestyles and coefficients.')
print('**************************************************')
print('***               Adding Lines                 ***')
print('**************************************************')
blockid = 0
print("Adding convergence line in data block '{}'".format(blockid))
iom = IOManager()
iom.open_file(datafile)
for c, p, l in zip(cvalues, pvalues, linestyles):
    label = '$O(' + xlabel + '^' + str(p) + ')$'
    diff = [c * xvalues[0] ** p, c * xvalues[1] ** p]
    if iom.has_convergence(label):
        print("Warning: Overwriting dataset with label '{}'".format(label))
        iom.delete_convergence(label)
    iom.add_convergence(label, xvalues, linestyle=l)
    iom.save_convergence(label, diff, 'L2diff')
    iom.save_convergence(label, diff, 'coeffdiff')
iom.finalize()
print('**************************************************')
print('***           Adding Lines Finished            ***')
print('**************************************************')

#!/usr/bin/env python
"""The WaveBlocks Project

Compute the differences of serveral wavepackets to the reference wavepacket.

@author: O. Rietmann
@copyright: Copyright (C) 2020 O. Rietmann
@license: Modified BSD License
"""

import argparse
import os

from WaveBlocksND import IOManager
from WaveBlocksND import GlobalDefaults as GD
from WaveBlocksND.Interface import ComputeConvergence


parser = argparse.ArgumentParser()

parser.add_argument("-d", "--datafile",
                    type = str,
                    help = "The data file to store the convergence results",
                    nargs = 1)

parser.add_argument("-i", "--interval",
                    type = float,
                    help = "x-axis interval [a, b] for plot",
                    nargs = 2)

parser.add_argument("-c", "--coefficient",
                    type = float,
                    help = "Prefactor c of the monomial c*h^p",
                    nargs = "*")
                    
parser.add_argument("-p", "--power",
                    type = int,
                    help = "Power p of the monomial c*h^p",
                    nargs = "*")

parser.add_argument("-l", "--linestyle",
                    type = str,
                    help = "Linestyle for plotting",
                    nargs = "*",
                    default = ["--"])

parser.add_argument("-x", "--xlabel",
                    type = str,
                    help = "Running variable of the line (the x-axis label).",
                    nargs = 1)

# TODO: Filter type of objects
# parser.add_argument("-t", "--type",
#                     help = "The type of objects to consider.",
#                     type = str,
#                     default = "all")

args = parser.parse_args()


# Read file with convergence data
datafile = os.path.abspath(args.datafile[0])
if os.path.exists(datafile):
    print("Convergence file already exists: '{}'".format(datafile))
    print("Adding new datasets to file: '{}'".format(datafile))
else:
    raise IOError("Convergence file does not exist: '{}'".format(datafile))

xvalues = args.interval
cvalues = args.coefficient
pvalues = args.power
linestyles = args.linestyle
xlabel = args.xlabel[0]

if len(cvalues) != len(pvalues):
    raise IOError("Length of coefficients and powers needs to be the same.")
if len(linestyles) == 1 and len(cvalues) > 1:
    linestyles *= len(cvalues)
elif len(linestyles) != len(cvalues):
    raise IOError("Incompatible number of linestyles and coefficients.")

print("**************************************************")
print("***               Adding Lines                 ***")
print("**************************************************")

blockid = 0

print("Adding convergence line in data block '{}'".format(blockid))

iom = IOManager()
iom.open_file(datafile)
for c, p, l in zip(cvalues, pvalues, linestyles):
    label = "$O(" + xlabel + "^" + str(p) + ")$"
    diff = [c * xvalues[0]**p, c * xvalues[1]**p]
    if iom.has_convergence(label):
        print("Warning: Overwriting dataset with label '{}'".format(label))
        iom.delete_convergence(label)
    iom.add_convergence(label, xvalues, linestyle=l)
    iom.save_convergence(label, diff, 'L2diff')
    iom.save_convergence(label, diff, 'coeffdiff')
iom.finalize()

print("**************************************************")
print("***           Adding Lines Finished            ***")
print("**************************************************")
