Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to plotting function for flow-over-heated-plate #570

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions flow-over-heated-plate/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ cases:
run: ./run.sh
component: openfoam-adapter

fluid-su2:
participant: Fluid
directory: ./fluid-su2
run: ./run.sh
component: su2-adapter

solid-fenics:
participant: Solid
directory: ./solid-fenics
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
vtk
numpy
matplotlib
os
79 changes: 37 additions & 42 deletions flow-over-heated-plate/plot-final-interface-temperature.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
#!/usr/bin/env python3
import vtk
from matplotlib import pyplot as plt
import numpy as np

import os

def vtk_to_dict(case):
vtkFileName = "solid-{}/precice-exports/Fluid-Mesh-Solid.dt100.vtk".format(case)
if not os.path.exists(vtkFileName):
print("No file found for " + vtkFileName)
return {} # return empty dict if file not found

# read the vtk file as an unstructured grid
reader = vtk.vtkUnstructuredGridReader()
reader.SetFileName(vtkFileName)
Expand All @@ -16,53 +21,43 @@ def vtk_to_dict(case):
data = reader.GetOutput()
n_data = data.GetPointData().GetNumberOfTuples()

name = "Temperature"
data_names = []
i = 0
max_i = data.GetPointData().GetNumberOfArrays()
while i < max_i:
this_data_name = data.GetPointData().GetArray(i).GetName()
data_names.append(this_data_name)
if (this_data_name == name):
data_id = i
break
i += 1

data_dict = {}

if not data_id:
raise Exception(
"For file {} name {} not found. Only the following names are available: {}. "
"Aborting!".format(vtkFileName, name, data_names))
for i in range(n_data):
data_dict[data.GetPoint(i)] = data.GetPointData().GetArray(data_id).GetValue(i)

data_dict[data.GetPoint(i)] = data.GetPointData().GetArray("Temperature").GetValue(i)
return data_dict


cases = []
cases.append('fenics')
cases.append('openfoam')
cases.append('nutils')
cases.append('dunefem')

case_labels = {
'fenics': 'OpenFOAM-FEniCS',
'openfoam': 'OpenFOAM-OpenFOAM',
'nutils': 'OpenFOAM-Nutils',
'dunefem': 'OpenFOAM-DuneFem'}
styles = [':', '-', '--']
colors = ['r', 'b', 'g', 'k']
i = 0
def main():
case_labels = {
'fenics': 'Fluid-FEniCS',
'openfoam': 'Fluid-OpenFOAM',
'nutils': 'Fluid-Nutils',
'dunefem': 'Fluid-DuneFem'}
styles = [':', '-', '--']
colors = ['r', 'b', 'g', 'k']

for i, case in enumerate(case_labels.keys()):
case_data = vtk_to_dict(case)
if not case_data:
continue
x, t = [p[0] for p in case_data.keys()], np.array(list(case_data.values()))

# sort by x
combined = list(zip(x,t))
combined.sort()
x, t = zip(*combined)
x = np.array(x)
t = np.array(t)

theta = (t - 300) / (310 - 300)
plt.plot(x, theta, colors[i % 4] + styles[i % 3], label=case_labels[case])

for case in cases:
case_data = vtk_to_dict(case)
x, t = [p[0] for p in case_data.keys()], np.array(list(case_data.values()))
theta = (t - 300) / (310 - 300)
plt.plot(x, theta, colors[i % 4] + styles[i % 3], label=case_labels[case])
i += 1
plt.ylabel("Theta")
plt.xlabel("x-coordinate along coupling interface")
plt.legend()
plt.show()

plt.ylabel("Theta")
plt.xlabel("x-coordinate along coupling interface")
plt.legend()
plt.show()
if __name__ == '__main__':
main()
Loading