Commit 2d9a7181 authored by Lambert Theisen's avatar Lambert Theisen 🔥

Add write_vec option and lid_two_region example

parent 8817df3b
Pipeline #307465 passed with stages
in 21 minutes and 50 seconds
......@@ -125,9 +125,11 @@ convergence_study:
# Postprocessing
# ==============
# - write_pdfs: Write all solution fields as PDF plot
# - write_vecs: Write all solution fields as vectors
# - massflow: List of BC IDs to compute massflow J=int_bc dot(u,n) ds
postprocessing:
write_pdfs: True
write_vecs: False
massflow: [3002]
# Parameter Study
......
......@@ -125,9 +125,11 @@ convergence_study:
# Postprocessing
# ==============
# - write_pdfs: Write all solution fields as PDF plot
# - write_vecs: Write all solution fields as vectors
# - massflow: List of BC IDs to compute massflow J=int_bc dot(u,n) ds
postprocessing:
write_pdfs: True
write_vecs: False
massflow: [3002]
# Parameter Study
......
......@@ -154,9 +154,11 @@ convergence_study:
# Postprocessing
# ==============
# - write_pdfs: Write all solution fields as PDF plot
# - write_vecs: Write all solution fields as vectors
# - massflow: List of BC IDs to compute massflow J=int_bc dot(u,n) ds
postprocessing:
write_pdfs: True
write_vecs: False
massflow: []
# Parameter Study
......
......@@ -111,9 +111,11 @@ convergence_study:
# Postprocessing
# ==============
# - write_pdfs: Write all solution fields as PDF plot
# - write_vecs: Write all solution fields as vectors
# - massflow: List of BC IDs to compute massflow J=int_bc dot(u,n) ds
postprocessing:
write_pdfs: True
write_vecs: False
massflow: []
# Parameter Study
......
# General
# =======
# - output_folder: Used as output folder
output_folder: results_lid_driven_cavity
output_folder: results_lid_two_regions
# Meshes
# ======
......@@ -64,9 +64,9 @@ body_force: [0,0]
# - kn: Knudsen number
regs:
4000: # top
kn: 0.08
kn: 0.1
4100: # bot
kn: 0.08
kn: 1.0
# Boundary Conditions
# ===================
......@@ -113,9 +113,11 @@ convergence_study:
# Postprocessing
# ==============
# - write_pdfs: Write all solution fields as PDF plot
# - write_vecs: Write all solution fields as vectors
# - massflow: List of BC IDs to compute massflow J=int_bc dot(u,n) ds
postprocessing:
write_pdfs: True
write_vecs: False
massflow: []
# Parameter Study
......
......@@ -45,6 +45,14 @@ class TestExamples(object):
self.create_meshes(working_dir)
self.run_solver("input.yml", working_dir)
def test_lid_two_regions(self):
r"""
Test the lid case with two region.
"""
working_dir = "examples/lid_two_regions"
self.create_meshes(working_dir)
self.run_solver("input.yml", working_dir)
@pytest.mark.skip(reason="Skip, needs too much time")
def test_channel_flow_pressure(self):
r"""
......
......@@ -140,9 +140,12 @@ class Input:
# Postprocessing
# ==============
# - write_pdfs: Write all solution fields as PDF plot
# - write_vecs: Write all solution fields as vectors
# - massflow: List of BC IDs to compute massflow J=int_bc dot(u,n) ds
postprocessing:
write_pdfs: True
write_vecs: True
massflow: []
# Parameter Study
......@@ -272,6 +275,10 @@ class Input:
"type": "boolean",
"required": True
},
"write_vecs": {
"type": "boolean",
"required": True
},
"massflow": {
"type": "list",
"required": True,
......
......@@ -75,6 +75,7 @@ class Solver:
self.delta_p = self.params["stabilization"]["cip"]["delta_p"]
self.write_pdfs = self.params["postprocessing"]["write_pdfs"]
self.write_vecs = self.params["postprocessing"]["write_vecs"]
self.massflow = self.params["postprocessing"]["massflow"]
# Create region field expressions
......@@ -1145,6 +1146,8 @@ class Solver:
print("Write fields..")
self.__write_solutions()
if self.write_vecs:
self.__write_vecs()
self.__write_parameters()
if self.write_systemmatrix:
self.__write_discrete_system()
......@@ -1156,6 +1159,13 @@ class Solver:
if sols[field] is not None:
self.__write_xdmf(field, sols[field], self.write_pdfs)
def __write_vecs(self):
"""Write all solutions to vectors."""
sols = self.sol
for field in sols:
if sols[field] is not None:
self.__write_vec(field, sols[field], self.write_pdfs)
def __write_parameters(self):
"""
Write parameter functions for debug reasons.
......@@ -1356,3 +1366,44 @@ class Solver:
print("Write {}".format(fname_pdf))
plt.savefig(fname_pdf, dpi=150)
plt.close()
def __write_vec(self, name, field, write_pdf):
"""
Write a given field to a vector.
"""
dimension = len(field.value_shape())
if dimension == 0:
# scalar
fname_mat = (
self.output_folder + name + "_" + str(self.time)
+ ".mat"
)
np.savetxt(
self.output_folder + name + "_" + str(self.time) + ".mat",
field.compute_vertex_values()
)
print("Write {}".format(fname_mat))
else:
# vector or tensor
components = len(field.split())
indexMap = {
1: {
1: "x",
2: "y"
},
2: {
1: "xx",
2: "xy",
3: "yx",
4: "yy",
}
}
for i in range(components):
fieldname = name + "_" + str(indexMap[dimension][i + 1])
fname_mat = (
self.output_folder + fieldname + "_" + str(self.time)
+ ".mat"
)
np.savetxt(fname_mat, field.split()[i].compute_vertex_values())
print("Write {}".format(fname_mat))
......@@ -118,9 +118,11 @@ convergence_study:
# Postprocessing
# ==============
# - write_pdfs: Write all solution fields as PDF plot
# - write_vecs: Write all solution fields as vectors
# - massflow: List of BC IDs to compute massflow J=int_bc dot(u,n) ds
postprocessing:
write_pdfs: False
write_vecs: False
massflow: []
# Parameter Study
......
......@@ -118,9 +118,11 @@ convergence_study:
# Postprocessing
# ==============
# - write_pdfs: Write all solution fields as PDF plot
# - write_vecs: Write all solution fields as vectors
# - massflow: List of BC IDs to compute massflow J=int_bc dot(u,n) ds
postprocessing:
write_pdfs: False
write_vecs: False
massflow: []
# Parameter Study
......
......@@ -118,9 +118,11 @@ convergence_study:
# Postprocessing
# ==============
# - write_pdfs: Write all solution fields as PDF plot
# - write_vecs: Write all solution fields as vectors
# - massflow: List of BC IDs to compute massflow J=int_bc dot(u,n) ds
postprocessing:
write_pdfs: False
write_vecs: False
massflow: []
# Parameter Study
......
......@@ -119,9 +119,11 @@ convergence_study:
# Postprocessing
# ==============
# - write_pdfs: Write all solution fields as PDF plot
# - write_vecs: Write all solution fields as vectors
# - massflow: List of BC IDs to compute massflow J=int_bc dot(u,n) ds
postprocessing:
write_pdfs: False
write_vecs: False
massflow: []
# Parameter Study
......
......@@ -118,9 +118,11 @@ convergence_study:
# Postprocessing
# ==============
# - write_pdfs: Write all solution fields as PDF plot
# - write_vecs: Write all solution fields as vectors
# - massflow: List of BC IDs to compute massflow J=int_bc dot(u,n) ds
postprocessing:
write_pdfs: False
write_vecs: False
massflow: []
# Parameter Study
......
......@@ -117,9 +117,11 @@ convergence_study:
# Postprocessing
# ==============
# - write_pdfs: Write all solution fields as PDF plot
# - write_vecs: Write all solution fields as vectors
# - massflow: List of BC IDs to compute massflow J=int_bc dot(u,n) ds
postprocessing:
write_pdfs: False
write_vecs: False
massflow: []
# Parameter Study
......
......@@ -116,9 +116,11 @@ convergence_study:
# Postprocessing
# ==============
# - write_pdfs: Write all solution fields as PDF plot
# - write_vecs: Write all solution fields as vectors
# - massflow: List of BC IDs to compute massflow J=int_bc dot(u,n) ds
postprocessing:
write_pdfs: False
write_vecs: False
massflow: []
# Parameter Study
......
......@@ -118,9 +118,11 @@ convergence_study:
# Postprocessing
# ==============
# - write_pdfs: Write all solution fields as PDF plot
# - write_vecs: Write all solution fields as vectors
# - massflow: List of BC IDs to compute massflow J=int_bc dot(u,n) ds
postprocessing:
write_pdfs: False
write_vecs: False
massflow: []
# Parameter Study
......
......@@ -116,9 +116,11 @@ convergence_study:
# Postprocessing
# ==============
# - write_pdfs: Write all solution fields as PDF plot
# - write_vecs: Write all solution fields as vectors
# - massflow: List of BC IDs to compute massflow J=int_bc dot(u,n) ds
postprocessing:
write_pdfs: False
write_vecs: False
massflow: []
# Parameter Study
......
......@@ -118,9 +118,11 @@ convergence_study:
# Postprocessing
# ==============
# - write_pdfs: Write all solution fields as PDF plot
# - write_vecs: Write all solution fields as vectors
# - massflow: List of BC IDs to compute massflow J=int_bc dot(u,n) ds
postprocessing:
write_pdfs: False
write_vecs: False
massflow: []
# Parameter Study
......
......@@ -119,9 +119,11 @@ convergence_study:
# Postprocessing
# ==============
# - write_pdfs: Write all solution fields as PDF plot
# - write_vecs: Write all solution fields as vectors
# - massflow: List of BC IDs to compute massflow J=int_bc dot(u,n) ds
postprocessing:
write_pdfs: False
write_vecs: False
massflow: []
# Parameter Study
......
......@@ -118,9 +118,11 @@ convergence_study:
# Postprocessing
# ==============
# - write_pdfs: Write all solution fields as PDF plot
# - write_vecs: Write all solution fields as vectors
# - massflow: List of BC IDs to compute massflow J=int_bc dot(u,n) ds
postprocessing:
write_pdfs: False
write_vecs: False
massflow: []
# Parameter Study
......
......@@ -116,9 +116,11 @@ convergence_study:
# Postprocessing
# ==============
# - write_pdfs: Write all solution fields as PDF plot
# - write_vecs: Write all solution fields as vectors
# - massflow: List of BC IDs to compute massflow J=int_bc dot(u,n) ds
postprocessing:
write_pdfs: False
write_vecs: False
massflow: []
# Parameter Study
......
......@@ -117,9 +117,11 @@ convergence_study:
# Postprocessing
# ==============
# - write_pdfs: Write all solution fields as PDF plot
# - write_vecs: Write all solution fields as vectors
# - massflow: List of BC IDs to compute massflow J=int_bc dot(u,n) ds
postprocessing:
write_pdfs: False
write_vecs: False
massflow: []
# Parameter Study
......
......@@ -119,9 +119,11 @@ convergence_study:
# Postprocessing
# ==============
# - write_pdfs: Write all solution fields as PDF plot
# - write_vecs: Write all solution fields as vectors
# - massflow: List of BC IDs to compute massflow J=int_bc dot(u,n) ds
postprocessing:
write_pdfs: False
write_vecs: False
massflow: []
# Parameter Study
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment