Show Discontinuity in Paraview

23 Views Asked by At

I am trying to visualize data containing points of discontinuity.

Target function is right part of the following formula.

The correct way to plot the data is this gnuplot plot

Paraview visualize it incorrectly, it draws some extra lines in place discontinuity points.

I used python script to generate .csv with my function values

import numpy as np
import csv

def beta(x):
    return 2 * x 

def g(x,c):
    return np.sqrt(-2*(c-1) * c * np.cos(x) + 2*(c - 1)*c + 1)

def phi_k(x,c):
    return 1 - 1 / (x * c) * np.arctan(c * np.sin(x) / (1 - c + np.cos(x)))

cS = [1, 0.75, 0.5, 0.25]

xS = np.arange(-np.pi/2, np.pi/2, 0.01, dtype='float64')

headers = [f"C={c}" for c in cS]
headers.insert(0,'x')

modulus = []
error = []

for x in xS:
    modulus_row = {'x' : x}
    error_row = {'x' : x}
    for c in cS:
        modulus_row[f"C={c}"] = g(beta(x),c)
        error_row[f"C={c}"] = phi_k(beta(x),c)
    modulus.append(modulus_row)
    error.append(error_row)

with open("courant_modulus.csv", 'w') as modulus_file:
    writer = csv.DictWriter(modulus_file, fieldnames=headers)
    writer.writeheader()
    writer.writerows(modulus)

with open("courant_error.csv", 'w') as error_file:
    writer = csv.DictWriter(error_file, fieldnames=headers)
    writer.writeheader()
    writer.writerows(error)

Then I imported courant_error.csv into ParaView and used LineChartView.

How can I visualize my data the same way I performed it in gnuplot?

Edit Fixed myself by performing little changes in data generation script

import numpy as np
import csv

def beta(x):
    return 2 * x 

def g(x,c):
    return np.sqrt(-2*(c-1) * c * np.cos(x) + 2*(c - 1)*c + 1)

def phi_k(x,c):
    return 1 - 1 / (x * c) * np.arctan(c * np.sin(x) / (1 - c + np.cos(x)))

cS = [1, 0.75, 0.5, 0.25]

xS = np.arange(-np.pi/2, np.pi/2, 0.0001, dtype='float64')

headers = [f"C={c}" for c in cS]
headers.insert(0,'x')

modulus = []
error = []

def is_nan(x,c):
    return abs(1-c + np.cos(beta(x))) < 0.001

for x in xS:
    modulus_row = {'x' : x}
    error_row = {'x' : x}
    for c in cS:
        modulus_row[f"C={c}"] = g(beta(x),c)
        error_row[f"C={c}"] = np.nan if is_nan(x,c) else phi_k(beta(x),c)

    modulus.append(modulus_row)
    error.append(error_row)

with open("courant_modulus.csv", 'w') as modulus_file:
    writer = csv.DictWriter(modulus_file, fieldnames=headers)
    writer.writeheader()
    writer.writerows(modulus)

with open("courant_error.csv", 'w') as error_file:
    writer = csv.DictWriter(error_file, fieldnames=headers)
    writer.writeheader()
    writer.writerows(error)

You can set NaN value in some points nearby your discontinuity point.

0

There are 0 best solutions below