From 9323b4d771f1321769549fbef1ad1c2a50e75484 Mon Sep 17 00:00:00 2001 From: Lambert Theisen <lambert.theisen@rwth-aachen.de> Date: Tue, 27 Oct 2020 16:00:17 +0100 Subject: [PATCH] Add line_integral feature for abitrary fields --- .gitignore | 3 + examples/channel_flow_force/input.yml | 6 + examples/channel_flow_pressure/input.yml | 6 + examples/knudsen_pump/input.yml | 12 ++ examples/knudsen_pump/study/input.yml | 12 ++ examples/lid_driven_cavity/input.yml | 7 + examples/lid_two_regions/input.yml | 7 + examples/thermal_edge_flow/input.yml | 7 + examples/thermal_edge_flow/input1.yml | 7 + examples/thermal_edge_flow/input10.yml | 7 + examples/thermal_edge_flow/input11.yml | 7 + examples/thermal_edge_flow/input12.yml | 17 +++ examples/thermal_edge_flow/input2.yml | 7 + examples/thermal_edge_flow/input3.yml | 7 + examples/thermal_edge_flow/input4.yml | 7 + examples/thermal_edge_flow/input5.yml | 7 + examples/thermal_edge_flow/input6.yml | 7 + examples/thermal_edge_flow/input7.yml | 7 + examples/thermal_edge_flow/input8.yml | 7 + examples/thermal_edge_flow/input9.yml | 7 + fenicsR13/input.py | 56 +++++++- fenicsR13/solver.py | 122 ++++++++++++++++++ tests/heat/inputs/heat_01_coeffs_p1p1_gls.yml | 7 + .../heat/inputs/heat_01_coeffs_p1p1_stab.yml | 7 + .../inputs/heat_01_coeffs_p1p2_nostab.yml | 7 + .../heat/inputs/heat_01_coeffs_p2p2_stab.yml | 7 + .../heat/inputs/heat_10_coeffs_p2p2_stab.yml | 7 + ..._nosources_norot_inflow_p1p1p1p1p1_gls.yml | 7 + ...nosources_norot_inflow_p1p1p1p1p1_stab.yml | 7 + ...sources_norot_inflow_p1p2p1p1p2_nostab.yml | 7 + ..._nosources_norot_inflow_p2p2p2p2p2_gls.yml | 7 + ...nosources_norot_inflow_p2p2p2p2p2_stab.yml | 7 + ...fs_sources_rot_noinflow_p1p1p1p1p1_gls.yml | 7 + ...s_sources_rot_noinflow_p1p1p1p1p1_stab.yml | 7 + ...fs_sources_rot_noinflow_p2p2p2p2p2_gls.yml | 7 + ...s_sources_rot_noinflow_p2p2p2p2p2_stab.yml | 7 + .../stress_01_nosource_rot_p1p1p1_gls.yml | 7 + .../stress_01_nosource_rot_p1p1p1_stab.yml | 7 + .../stress_01_source_norot_p1p1p1_stab.yml | 7 + .../stress_01_source_rot_p1p1p1_stab.yml | 7 + .../stress_01_source_rot_p1p2p3_nostab.yml | 7 + .../stress_01_source_rot_p2p2p2_stab.yml | 7 + .../stress_10_source_rot_p1p1p1_stab.yml | 7 + 43 files changed, 478 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index d3bef7e..d94e2cc 100644 --- a/.gitignore +++ b/.gitignore @@ -33,6 +33,9 @@ # ignore system matrices *A_*.txt +# ignore line_integrals +*line_integral* + # ignore .ip helper file (X11) *.ip diff --git a/examples/channel_flow_force/input.yml b/examples/channel_flow_force/input.yml index b703c78..a1c6d66 100644 --- a/examples/channel_flow_force/input.yml +++ b/examples/channel_flow_force/input.yml @@ -141,6 +141,12 @@ convergence_study: # - 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 +# - line_integrals: List of line integral dicts: +# - name: Name for output +# - expr: Expression to evaluate +# - start: Start point +# - end: End point +# - res: Sampling resolution of line postprocessing: write_pdfs: True write_vecs: False diff --git a/examples/channel_flow_pressure/input.yml b/examples/channel_flow_pressure/input.yml index 3727c26..fb21454 100644 --- a/examples/channel_flow_pressure/input.yml +++ b/examples/channel_flow_pressure/input.yml @@ -141,6 +141,12 @@ convergence_study: # - 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 +# - line_integrals: List of line integral dicts: +# - name: Name for output +# - expr: Expression to evaluate +# - start: Start point +# - end: End point +# - res: Sampling resolution of line postprocessing: write_pdfs: True write_vecs: False diff --git a/examples/knudsen_pump/input.yml b/examples/knudsen_pump/input.yml index 7c0243a..bc7b143 100644 --- a/examples/knudsen_pump/input.yml +++ b/examples/knudsen_pump/input.yml @@ -170,10 +170,22 @@ convergence_study: # - 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 +# - line_integrals: List of line integral dicts: +# - name: Name for output +# - expr: Expression to evaluate +# - start: Start point +# - end: End point +# - res: Sampling resolution of line postprocessing: write_pdfs: True write_vecs: False massflow: [] + line_integrals: + - name: "avg(abs(ux(x=0,y)))" + expr: abs(ux)/1.5 + start: [0, -2.0] + end: [0, -0.5] + res: 10000 # Parameter Study # ============== diff --git a/examples/knudsen_pump/study/input.yml b/examples/knudsen_pump/study/input.yml index 99f31fe..cb5fe60 100644 --- a/examples/knudsen_pump/study/input.yml +++ b/examples/knudsen_pump/study/input.yml @@ -174,10 +174,22 @@ convergence_study: # - 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 +# - line_integrals: List of line integral dicts: +# - name: Name for output +# - expr: Expression to evaluate +# - start: Start point +# - end: End point +# - res: Sampling resolution of line postprocessing: write_pdfs: True write_vecs: False massflow: [] + line_integrals: + - name: "avg(abs(ux(x=0,y)))" + expr: abs(ux)/1.5 + start: [0, -2.0] + end: [0, -0.5] + res: 10000 # Parameter Study # ============== diff --git a/examples/lid_driven_cavity/input.yml b/examples/lid_driven_cavity/input.yml index a26931e..9f7d560 100644 --- a/examples/lid_driven_cavity/input.yml +++ b/examples/lid_driven_cavity/input.yml @@ -127,10 +127,17 @@ convergence_study: # - 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 +# - line_integrals: List of line integral dicts: +# - name: Name for output +# - expr: Expression to evaluate +# - start: Start point +# - end: End point +# - res: Sampling resolution of line postprocessing: write_pdfs: True write_vecs: False massflow: [] + line_integrals: [] # Parameter Study # ============== diff --git a/examples/lid_two_regions/input.yml b/examples/lid_two_regions/input.yml index f6d35b7..eb099fe 100644 --- a/examples/lid_two_regions/input.yml +++ b/examples/lid_two_regions/input.yml @@ -129,10 +129,17 @@ convergence_study: # - 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 +# - line_integrals: List of line integral dicts: +# - name: Name for output +# - expr: Expression to evaluate +# - start: Start point +# - end: End point +# - res: Sampling resolution of line postprocessing: write_pdfs: False write_vecs: True massflow: [] + line_integrals: [] # Parameter Study # ============== diff --git a/examples/thermal_edge_flow/input.yml b/examples/thermal_edge_flow/input.yml index 8664dc2..9a92521 100644 --- a/examples/thermal_edge_flow/input.yml +++ b/examples/thermal_edge_flow/input.yml @@ -134,10 +134,17 @@ convergence_study: # - 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 +# - line_integrals: List of line integral dicts: +# - name: Name for output +# - expr: Expression to evaluate +# - start: Start point +# - end: End point +# - res: Sampling resolution of line postprocessing: write_pdfs: False write_vecs: False massflow: [] + line_integrals: [] # Parameter Study # ============== diff --git a/examples/thermal_edge_flow/input1.yml b/examples/thermal_edge_flow/input1.yml index 04092a1..7f6381b 100644 --- a/examples/thermal_edge_flow/input1.yml +++ b/examples/thermal_edge_flow/input1.yml @@ -147,10 +147,17 @@ convergence_study: # - 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 +# - line_integrals: List of line integral dicts: +# - name: Name for output +# - expr: Expression to evaluate +# - start: Start point +# - end: End point +# - res: Sampling resolution of line postprocessing: write_pdfs: False write_vecs: False massflow: [] + line_integrals: [] # Parameter Study # ============== diff --git a/examples/thermal_edge_flow/input10.yml b/examples/thermal_edge_flow/input10.yml index cc78c89..885cd4a 100644 --- a/examples/thermal_edge_flow/input10.yml +++ b/examples/thermal_edge_flow/input10.yml @@ -132,10 +132,17 @@ convergence_study: # - 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 +# - line_integrals: List of line integral dicts: +# - name: Name for output +# - expr: Expression to evaluate +# - start: Start point +# - end: End point +# - res: Sampling resolution of line postprocessing: write_pdfs: False write_vecs: False massflow: [] + line_integrals: [] # Parameter Study # ============== diff --git a/examples/thermal_edge_flow/input11.yml b/examples/thermal_edge_flow/input11.yml index 91544d3..269ed1d 100644 --- a/examples/thermal_edge_flow/input11.yml +++ b/examples/thermal_edge_flow/input11.yml @@ -132,10 +132,17 @@ convergence_study: # - 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 +# - line_integrals: List of line integral dicts: +# - name: Name for output +# - expr: Expression to evaluate +# - start: Start point +# - end: End point +# - res: Sampling resolution of line postprocessing: write_pdfs: False write_vecs: False massflow: [] + line_integrals: [] # Parameter Study # ============== diff --git a/examples/thermal_edge_flow/input12.yml b/examples/thermal_edge_flow/input12.yml index 80a20fb..7abb531 100644 --- a/examples/thermal_edge_flow/input12.yml +++ b/examples/thermal_edge_flow/input12.yml @@ -133,10 +133,27 @@ convergence_study: # - 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 +# - line_integrals: List of line integral dicts: +# - name: Name for output +# - expr: Expression to evaluate +# - start: Start point +# - end: End point +# - res: Sampling resolution of line postprocessing: write_pdfs: False write_vecs: False massflow: [] + line_integrals: + - name: "avg(abs(uy(x,y=0.5)))" + expr: abs(uy)/8 + start: [0, 0.5] + end: [8, 0.5] + res: 10000 + - name: "avg(abs(uy(x,y=4.5)))" + expr: abs(uy)/8 + start: [0, 4.5] + end: [8, 4.5] + res: 10000 # Parameter Study # ============== diff --git a/examples/thermal_edge_flow/input2.yml b/examples/thermal_edge_flow/input2.yml index 919506f..1ad44c9 100644 --- a/examples/thermal_edge_flow/input2.yml +++ b/examples/thermal_edge_flow/input2.yml @@ -134,10 +134,17 @@ convergence_study: # - 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 +# - line_integrals: List of line integral dicts: +# - name: Name for output +# - expr: Expression to evaluate +# - start: Start point +# - end: End point +# - res: Sampling resolution of line postprocessing: write_pdfs: False write_vecs: False massflow: [] + line_integrals: [] # Parameter Study # ============== diff --git a/examples/thermal_edge_flow/input3.yml b/examples/thermal_edge_flow/input3.yml index a8b316e..6b69904 100644 --- a/examples/thermal_edge_flow/input3.yml +++ b/examples/thermal_edge_flow/input3.yml @@ -132,10 +132,17 @@ convergence_study: # - 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 +# - line_integrals: List of line integral dicts: +# - name: Name for output +# - expr: Expression to evaluate +# - start: Start point +# - end: End point +# - res: Sampling resolution of line postprocessing: write_pdfs: False write_vecs: False massflow: [] + line_integrals: [] # Parameter Study # ============== diff --git a/examples/thermal_edge_flow/input4.yml b/examples/thermal_edge_flow/input4.yml index 434c710..86c748b 100644 --- a/examples/thermal_edge_flow/input4.yml +++ b/examples/thermal_edge_flow/input4.yml @@ -134,10 +134,17 @@ convergence_study: # - 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 +# - line_integrals: List of line integral dicts: +# - name: Name for output +# - expr: Expression to evaluate +# - start: Start point +# - end: End point +# - res: Sampling resolution of line postprocessing: write_pdfs: False write_vecs: False massflow: [] + line_integrals: [] # Parameter Study # ============== diff --git a/examples/thermal_edge_flow/input5.yml b/examples/thermal_edge_flow/input5.yml index a24ec38..0df65c5 100644 --- a/examples/thermal_edge_flow/input5.yml +++ b/examples/thermal_edge_flow/input5.yml @@ -132,10 +132,17 @@ convergence_study: # - 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 +# - line_integrals: List of line integral dicts: +# - name: Name for output +# - expr: Expression to evaluate +# - start: Start point +# - end: End point +# - res: Sampling resolution of line postprocessing: write_pdfs: False write_vecs: False massflow: [] + line_integrals: [] # Parameter Study # ============== diff --git a/examples/thermal_edge_flow/input6.yml b/examples/thermal_edge_flow/input6.yml index 674f775..72ae021 100644 --- a/examples/thermal_edge_flow/input6.yml +++ b/examples/thermal_edge_flow/input6.yml @@ -134,10 +134,17 @@ convergence_study: # - 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 +# - line_integrals: List of line integral dicts: +# - name: Name for output +# - expr: Expression to evaluate +# - start: Start point +# - end: End point +# - res: Sampling resolution of line postprocessing: write_pdfs: False write_vecs: False massflow: [] + line_integrals: [] # Parameter Study # ============== diff --git a/examples/thermal_edge_flow/input7.yml b/examples/thermal_edge_flow/input7.yml index 56904f6..c6c7d54 100644 --- a/examples/thermal_edge_flow/input7.yml +++ b/examples/thermal_edge_flow/input7.yml @@ -131,10 +131,17 @@ convergence_study: # - 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 +# - line_integrals: List of line integral dicts: +# - name: Name for output +# - expr: Expression to evaluate +# - start: Start point +# - end: End point +# - res: Sampling resolution of line postprocessing: write_pdfs: False write_vecs: False massflow: [] + line_integrals: [] # Parameter Study # ============== diff --git a/examples/thermal_edge_flow/input8.yml b/examples/thermal_edge_flow/input8.yml index 1828bdd..07c47cf 100644 --- a/examples/thermal_edge_flow/input8.yml +++ b/examples/thermal_edge_flow/input8.yml @@ -134,10 +134,17 @@ convergence_study: # - 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 +# - line_integrals: List of line integral dicts: +# - name: Name for output +# - expr: Expression to evaluate +# - start: Start point +# - end: End point +# - res: Sampling resolution of line postprocessing: write_pdfs: False write_vecs: False massflow: [] + line_integrals: [] # Parameter Study # ============== diff --git a/examples/thermal_edge_flow/input9.yml b/examples/thermal_edge_flow/input9.yml index d6e97c2..ead1c66 100644 --- a/examples/thermal_edge_flow/input9.yml +++ b/examples/thermal_edge_flow/input9.yml @@ -132,10 +132,17 @@ convergence_study: # - 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 +# - line_integrals: List of line integral dicts: +# - name: Name for output +# - expr: Expression to evaluate +# - start: Start point +# - end: End point +# - res: Sampling resolution of line postprocessing: write_pdfs: False write_vecs: False massflow: [] + line_integrals: [] # Parameter Study # ============== diff --git a/fenicsR13/input.py b/fenicsR13/input.py index 81e5f18..efb3a9b 100644 --- a/fenicsR13/input.py +++ b/fenicsR13/input.py @@ -156,11 +156,27 @@ class Input: # - 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 + # - line_integrals: List of line integral dicts: + # - name: Name for output + # - expr: Expression to evaluate + # - start: Start point + # - end: End point + # - res: Sampling resolution of line postprocessing: write_pdfs: True write_vecs: True massflow: [] - + line_integrals: + - name: "avg(abs(uy(x,y=0.5)))" + expr: abs(uy)/8 + start: [0, 0.5] + end: [8, 0.5] + res: 10000 + - name: "avg(abs(uy(x,y=4.5)))" + expr: abs(uy)/8 + start: [0, 4.5] + end: [8, 4.5] + res: 10000 # Parameter Study # ============== @@ -298,6 +314,44 @@ class Input: "required": True, "schema": {"type": "integer"} }, + "line_integrals": { + "type": "list", + "required": True, + "schema": { + "type": "dict", + "schema": { + "name": { + "type": "string", + "required": True, + }, + "expr": { + "anyof": [ + {"type": "string"}, {"type": "float"} + ], + "required": True, + }, + "start": { + "type": "list", + "required": True, + "schema": {"anyof": [ + {"type": "string"}, {"type": "float"} + ]} + }, + "end": { + "type": "list", + "required": True, + "schema": {"anyof": [ + {"type": "string"}, {"type": "float"} + ]} + }, + "res": { + "type": "integer", + "required": True, + "min": 1 + }, + }, + }, + }, } }, "parameter_study": { diff --git a/fenicsR13/solver.py b/fenicsR13/solver.py index fdeb9c4..75a7b2e 100644 --- a/fenicsR13/solver.py +++ b/fenicsR13/solver.py @@ -71,6 +71,9 @@ class Solver: self.time = time self.mode = params["mode"] + self.comm = df.MPI.comm_world + self.rank = df.MPI.rank(self.comm) + # CIP self.use_cip = self.params["stabilization"]["cip"]["enable"] self.delta_theta = self.params["stabilization"]["cip"]["delta_theta"] @@ -88,6 +91,7 @@ class Solver: self.write_pdfs = self.params["postprocessing"]["write_pdfs"] self.write_vecs = self.params["postprocessing"]["write_vecs"] self.massflow = self.params["postprocessing"]["massflow"] + self.line_integrals = self.params["postprocessing"]["line_integrals"] # Create region field expressions self.regs = copy.deepcopy(self.params["regs"]) @@ -167,6 +171,42 @@ class Solver: } self.errors = {} + def __createSolMacroScaExpr(self, cpp_string): + """ + Return a DOLFIN scalar expression with predefined macros after solve. + + These macros include: + + ============================ =========== =============================== + Name Macro CPP Replacement + ============================ =========== =============================== + ``theta`` ``theta`` ``sol["theta"]`` + ``sx`` ``sx`` ``sol["s"].split()[0]`` + ``sy`` ``sy`` ``sol["s"].split()[1]`` + ``p`` ``p`` ``sol["p"]`` + ``ux`` ``ux`` ``sol["u"].split()[0]`` + ``uy`` ``uy`` ``sol["u"].split()[1]`` + ``sigmaxx`` ``sigmaxx`` ``sol["sigma"].split()[0]`` + ``sigmaxy`` ``sigmaxy`` ``sol["sigma"].split()[1]`` + ``sigmayx`` ``sigmayx`` ``sol["sigma"].split()[1]`` + ``sigmayy`` ``sigmayy`` ``sol["sigma"].split()[2]`` + ============================ =========== =============================== + """ + return df.Expression( + str(cpp_string), + degree=2, + theta = self.sol["theta"], + sx = self.sol["s"].split()[0], + sy = self.sol["s"].split()[1], + p = self.sol["p"], + ux = self.sol["u"].split()[0], + uy = self.sol["u"].split()[1], + sigmaxx = self.sol["sigma"].split()[0], + sigmaxy = self.sol["sigma"].split()[1], + sigmayx = self.sol["sigma"].split()[1], + sigmayy = self.sol["sigma"].split()[2] + ) + def __createMacroScaExpr(self, cpp_string): """ Return a DOLFIN scalar expression with predefined macros. @@ -870,6 +910,7 @@ class Solver: secs = end_t - start_t self.write_content_to_file("assemble", secs) print("Finish assemble: {}".format(str(secs))) + sys.stdout.flush() print("Start solve") sys.stdout.flush() @@ -899,6 +940,7 @@ class Solver: secs = end_t - start_t self.write_content_to_file("solve", secs) print("Finished solve: {}".format(str(secs))) + sys.stdout.flush() if self.mode == "heat": (self.sol["theta"], self.sol["s"]) = sol.split() @@ -939,6 +981,86 @@ class Solver: print("avg vel:", avgvel) self.write_content_to_file("avgvel", avgvel) + def __line_integral_average(u, A, B, n): + """ + Integrate u over segment [A, B] partitioned into n elements + """ + assert u.value_rank() == 0 + assert len(A) == len(B) > 1 and np.linalg.norm(A-B) > 0 + assert n > 0 + + # Mesh line for integration + mesh_points = [A + t*(B-A) for t in np.linspace(0, 1, n+1)] + tdim, gdim = 1, len(A) + + # Create line mesh + mesh = df.Mesh(df.MPI.comm_world) + if self.rank == 0: + editor = df.MeshEditor() + editor.open(mesh, "interval", tdim, gdim) + editor.init_vertices(n+1) + editor.init_cells(n) + for vi, v in enumerate(mesh_points): + editor.add_vertex(vi, v) + for ci in range(n): + editor.add_cell(ci, np.array([ci, ci+1], dtype='uintp')) + editor.close() + df.MeshPartitioning.build_distributed_mesh(mesh) + print(mesh) + sys.stdout.flush() + + # Setup function space + elm = u.function_space().ufl_element() + family = elm.family() + degree = elm.degree() + V = df.FunctionSpace(mesh, family, degree) + v = df.Function(V) + + # Interpolate to line mesh + # df.interpolate does not work in parallel from different meshes + # -> https://fenicsproject.org/docs/dolfin/1.6.0/python/ + # programmers-reference/cpp/function/LagrangeInterpolator.html + # Use LagrangeInterpolator, which works in parallel + # -> https://fenicsproject.org/qa/7758/ + # function-interpolation-in-parallel/?show=12144#c12144 + df.LagrangeInterpolator.interpolate(v, u) + + custom_dx = df.Measure("dx", domain=mesh) + + return df.assemble(v * custom_dx) + + print("Start line_integrals") + start_t = time_module.time() + sys.stdout.flush() + for li in self.line_integrals: + name = li["name"] + + # Interpolate in "best" Lagrange space + maxdeg = max([ + self.params["elements"]["theta"]["degree"], + self.params["elements"]["s"]["degree"], + self.params["elements"]["p"]["degree"], + self.params["elements"]["u"]["degree"], + self.params["elements"]["sigma"]["degree"] + ]) + expr = df.interpolate( + self.__createSolMacroScaExpr(li["expr"]), + df.FunctionSpace(self.mesh, "Lagrange", maxdeg) + ) + start = np.array(li["start"]) + end = np.array(li["end"]) + res = li["res"] + result = __line_integral_average( + expr, start, end, res + ) + self.write_content_to_file( + "line_integral_{}".format(name), result + ) + end_t = time_module.time() + secs = end_t - start_t + print("Finish line_integrals: {}".format(str(secs))) + sys.stdout.flush() + def __load_exact_solution(self): """ Load exact solution from the location given in ``input.yml``. diff --git a/tests/heat/inputs/heat_01_coeffs_p1p1_gls.yml b/tests/heat/inputs/heat_01_coeffs_p1p1_gls.yml index 6855e36..268ed83 100644 --- a/tests/heat/inputs/heat_01_coeffs_p1p1_gls.yml +++ b/tests/heat/inputs/heat_01_coeffs_p1p1_gls.yml @@ -134,10 +134,17 @@ convergence_study: # - 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 +# - line_integrals: List of line integral dicts: +# - name: Name for output +# - expr: Expression to evaluate +# - start: Start point +# - end: End point +# - res: Sampling resolution of line postprocessing: write_pdfs: False write_vecs: False massflow: [] + line_integrals: [] # Parameter Study # ============== diff --git a/tests/heat/inputs/heat_01_coeffs_p1p1_stab.yml b/tests/heat/inputs/heat_01_coeffs_p1p1_stab.yml index 0494a72..64f023b 100644 --- a/tests/heat/inputs/heat_01_coeffs_p1p1_stab.yml +++ b/tests/heat/inputs/heat_01_coeffs_p1p1_stab.yml @@ -134,10 +134,17 @@ convergence_study: # - 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 +# - line_integrals: List of line integral dicts: +# - name: Name for output +# - expr: Expression to evaluate +# - start: Start point +# - end: End point +# - res: Sampling resolution of line postprocessing: write_pdfs: False write_vecs: False massflow: [] + line_integrals: [] # Parameter Study # ============== diff --git a/tests/heat/inputs/heat_01_coeffs_p1p2_nostab.yml b/tests/heat/inputs/heat_01_coeffs_p1p2_nostab.yml index 157f9e6..e88a3ba 100644 --- a/tests/heat/inputs/heat_01_coeffs_p1p2_nostab.yml +++ b/tests/heat/inputs/heat_01_coeffs_p1p2_nostab.yml @@ -134,10 +134,17 @@ convergence_study: # - 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 +# - line_integrals: List of line integral dicts: +# - name: Name for output +# - expr: Expression to evaluate +# - start: Start point +# - end: End point +# - res: Sampling resolution of line postprocessing: write_pdfs: False write_vecs: False massflow: [] + line_integrals: [] # Parameter Study # ============== diff --git a/tests/heat/inputs/heat_01_coeffs_p2p2_stab.yml b/tests/heat/inputs/heat_01_coeffs_p2p2_stab.yml index f2187e1..80b1df8 100644 --- a/tests/heat/inputs/heat_01_coeffs_p2p2_stab.yml +++ b/tests/heat/inputs/heat_01_coeffs_p2p2_stab.yml @@ -134,10 +134,17 @@ convergence_study: # - 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 +# - line_integrals: List of line integral dicts: +# - name: Name for output +# - expr: Expression to evaluate +# - start: Start point +# - end: End point +# - res: Sampling resolution of line postprocessing: write_pdfs: False write_vecs: False massflow: [] + line_integrals: [] # Parameter Study # ============== diff --git a/tests/heat/inputs/heat_10_coeffs_p2p2_stab.yml b/tests/heat/inputs/heat_10_coeffs_p2p2_stab.yml index 13aaf21..7acfe1d 100644 --- a/tests/heat/inputs/heat_10_coeffs_p2p2_stab.yml +++ b/tests/heat/inputs/heat_10_coeffs_p2p2_stab.yml @@ -135,10 +135,17 @@ convergence_study: # - 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 +# - line_integrals: List of line integral dicts: +# - name: Name for output +# - expr: Expression to evaluate +# - start: Start point +# - end: End point +# - res: Sampling resolution of line postprocessing: write_pdfs: False write_vecs: False massflow: [] + line_integrals: [] # Parameter Study # ============== diff --git a/tests/r13/inputs/r13_1_coeffs_nosources_norot_inflow_p1p1p1p1p1_gls.yml b/tests/r13/inputs/r13_1_coeffs_nosources_norot_inflow_p1p1p1p1p1_gls.yml index 8026b02..bccad84 100644 --- a/tests/r13/inputs/r13_1_coeffs_nosources_norot_inflow_p1p1p1p1p1_gls.yml +++ b/tests/r13/inputs/r13_1_coeffs_nosources_norot_inflow_p1p1p1p1p1_gls.yml @@ -134,10 +134,17 @@ convergence_study: # - 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 +# - line_integrals: List of line integral dicts: +# - name: Name for output +# - expr: Expression to evaluate +# - start: Start point +# - end: End point +# - res: Sampling resolution of line postprocessing: write_pdfs: False write_vecs: False massflow: [] + line_integrals: [] # Parameter Study # ============== diff --git a/tests/r13/inputs/r13_1_coeffs_nosources_norot_inflow_p1p1p1p1p1_stab.yml b/tests/r13/inputs/r13_1_coeffs_nosources_norot_inflow_p1p1p1p1p1_stab.yml index 31deaf6..000e1a2 100644 --- a/tests/r13/inputs/r13_1_coeffs_nosources_norot_inflow_p1p1p1p1p1_stab.yml +++ b/tests/r13/inputs/r13_1_coeffs_nosources_norot_inflow_p1p1p1p1p1_stab.yml @@ -134,10 +134,17 @@ convergence_study: # - 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 +# - line_integrals: List of line integral dicts: +# - name: Name for output +# - expr: Expression to evaluate +# - start: Start point +# - end: End point +# - res: Sampling resolution of line postprocessing: write_pdfs: False write_vecs: False massflow: [] + line_integrals: [] # Parameter Study # ============== diff --git a/tests/r13/inputs/r13_1_coeffs_nosources_norot_inflow_p1p2p1p1p2_nostab.yml b/tests/r13/inputs/r13_1_coeffs_nosources_norot_inflow_p1p2p1p1p2_nostab.yml index 6da3455..42d4585 100644 --- a/tests/r13/inputs/r13_1_coeffs_nosources_norot_inflow_p1p2p1p1p2_nostab.yml +++ b/tests/r13/inputs/r13_1_coeffs_nosources_norot_inflow_p1p2p1p1p2_nostab.yml @@ -133,10 +133,17 @@ convergence_study: # - 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 +# - line_integrals: List of line integral dicts: +# - name: Name for output +# - expr: Expression to evaluate +# - start: Start point +# - end: End point +# - res: Sampling resolution of line postprocessing: write_pdfs: False write_vecs: False massflow: [] + line_integrals: [] # Parameter Study # ============== diff --git a/tests/r13/inputs/r13_1_coeffs_nosources_norot_inflow_p2p2p2p2p2_gls.yml b/tests/r13/inputs/r13_1_coeffs_nosources_norot_inflow_p2p2p2p2p2_gls.yml index aaf5fec..77b3d5d 100644 --- a/tests/r13/inputs/r13_1_coeffs_nosources_norot_inflow_p2p2p2p2p2_gls.yml +++ b/tests/r13/inputs/r13_1_coeffs_nosources_norot_inflow_p2p2p2p2p2_gls.yml @@ -132,10 +132,17 @@ convergence_study: # - 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 +# - line_integrals: List of line integral dicts: +# - name: Name for output +# - expr: Expression to evaluate +# - start: Start point +# - end: End point +# - res: Sampling resolution of line postprocessing: write_pdfs: False write_vecs: False massflow: [] + line_integrals: [] # Parameter Study # ============== diff --git a/tests/r13/inputs/r13_1_coeffs_nosources_norot_inflow_p2p2p2p2p2_stab.yml b/tests/r13/inputs/r13_1_coeffs_nosources_norot_inflow_p2p2p2p2p2_stab.yml index 5f30460..545ce6b 100644 --- a/tests/r13/inputs/r13_1_coeffs_nosources_norot_inflow_p2p2p2p2p2_stab.yml +++ b/tests/r13/inputs/r13_1_coeffs_nosources_norot_inflow_p2p2p2p2p2_stab.yml @@ -132,10 +132,17 @@ convergence_study: # - 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 +# - line_integrals: List of line integral dicts: +# - name: Name for output +# - expr: Expression to evaluate +# - start: Start point +# - end: End point +# - res: Sampling resolution of line postprocessing: write_pdfs: False write_vecs: False massflow: [] + line_integrals: [] # Parameter Study # ============== diff --git a/tests/r13/inputs/r13_1_coeffs_sources_rot_noinflow_p1p1p1p1p1_gls.yml b/tests/r13/inputs/r13_1_coeffs_sources_rot_noinflow_p1p1p1p1p1_gls.yml index 795307a..8eb4ec7 100644 --- a/tests/r13/inputs/r13_1_coeffs_sources_rot_noinflow_p1p1p1p1p1_gls.yml +++ b/tests/r13/inputs/r13_1_coeffs_sources_rot_noinflow_p1p1p1p1p1_gls.yml @@ -134,10 +134,17 @@ convergence_study: # - 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 +# - line_integrals: List of line integral dicts: +# - name: Name for output +# - expr: Expression to evaluate +# - start: Start point +# - end: End point +# - res: Sampling resolution of line postprocessing: write_pdfs: False write_vecs: False massflow: [] + line_integrals: [] # Parameter Study # ============== diff --git a/tests/r13/inputs/r13_1_coeffs_sources_rot_noinflow_p1p1p1p1p1_stab.yml b/tests/r13/inputs/r13_1_coeffs_sources_rot_noinflow_p1p1p1p1p1_stab.yml index fd7474a..0f26bed 100644 --- a/tests/r13/inputs/r13_1_coeffs_sources_rot_noinflow_p1p1p1p1p1_stab.yml +++ b/tests/r13/inputs/r13_1_coeffs_sources_rot_noinflow_p1p1p1p1p1_stab.yml @@ -134,10 +134,17 @@ convergence_study: # - 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 +# - line_integrals: List of line integral dicts: +# - name: Name for output +# - expr: Expression to evaluate +# - start: Start point +# - end: End point +# - res: Sampling resolution of line postprocessing: write_pdfs: False write_vecs: False massflow: [] + line_integrals: [] # Parameter Study # ============== diff --git a/tests/r13/inputs/r13_1_coeffs_sources_rot_noinflow_p2p2p2p2p2_gls.yml b/tests/r13/inputs/r13_1_coeffs_sources_rot_noinflow_p2p2p2p2p2_gls.yml index da87e38..025b779 100644 --- a/tests/r13/inputs/r13_1_coeffs_sources_rot_noinflow_p2p2p2p2p2_gls.yml +++ b/tests/r13/inputs/r13_1_coeffs_sources_rot_noinflow_p2p2p2p2p2_gls.yml @@ -132,10 +132,17 @@ convergence_study: # - 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 +# - line_integrals: List of line integral dicts: +# - name: Name for output +# - expr: Expression to evaluate +# - start: Start point +# - end: End point +# - res: Sampling resolution of line postprocessing: write_pdfs: False write_vecs: False massflow: [] + line_integrals: [] # Parameter Study # ============== diff --git a/tests/r13/inputs/r13_1_coeffs_sources_rot_noinflow_p2p2p2p2p2_stab.yml b/tests/r13/inputs/r13_1_coeffs_sources_rot_noinflow_p2p2p2p2p2_stab.yml index e58ac1b..9b62ee2 100644 --- a/tests/r13/inputs/r13_1_coeffs_sources_rot_noinflow_p2p2p2p2p2_stab.yml +++ b/tests/r13/inputs/r13_1_coeffs_sources_rot_noinflow_p2p2p2p2p2_stab.yml @@ -132,10 +132,17 @@ convergence_study: # - 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 +# - line_integrals: List of line integral dicts: +# - name: Name for output +# - expr: Expression to evaluate +# - start: Start point +# - end: End point +# - res: Sampling resolution of line postprocessing: write_pdfs: False write_vecs: False massflow: [] + line_integrals: [] # Parameter Study # ============== diff --git a/tests/stress/inputs/stress_01_nosource_rot_p1p1p1_gls.yml b/tests/stress/inputs/stress_01_nosource_rot_p1p1p1_gls.yml index 91b9200..f00aebe 100644 --- a/tests/stress/inputs/stress_01_nosource_rot_p1p1p1_gls.yml +++ b/tests/stress/inputs/stress_01_nosource_rot_p1p1p1_gls.yml @@ -134,10 +134,17 @@ convergence_study: # - 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 +# - line_integrals: List of line integral dicts: +# - name: Name for output +# - expr: Expression to evaluate +# - start: Start point +# - end: End point +# - res: Sampling resolution of line postprocessing: write_pdfs: False write_vecs: False massflow: [] + line_integrals: [] # Parameter Study # ============== diff --git a/tests/stress/inputs/stress_01_nosource_rot_p1p1p1_stab.yml b/tests/stress/inputs/stress_01_nosource_rot_p1p1p1_stab.yml index 6c5c4b9..ca6c0d9 100644 --- a/tests/stress/inputs/stress_01_nosource_rot_p1p1p1_stab.yml +++ b/tests/stress/inputs/stress_01_nosource_rot_p1p1p1_stab.yml @@ -134,10 +134,17 @@ convergence_study: # - 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 +# - line_integrals: List of line integral dicts: +# - name: Name for output +# - expr: Expression to evaluate +# - start: Start point +# - end: End point +# - res: Sampling resolution of line postprocessing: write_pdfs: False write_vecs: False massflow: [] + line_integrals: [] # Parameter Study # ============== diff --git a/tests/stress/inputs/stress_01_source_norot_p1p1p1_stab.yml b/tests/stress/inputs/stress_01_source_norot_p1p1p1_stab.yml index 50a1ff6..bb26039 100644 --- a/tests/stress/inputs/stress_01_source_norot_p1p1p1_stab.yml +++ b/tests/stress/inputs/stress_01_source_norot_p1p1p1_stab.yml @@ -135,10 +135,17 @@ convergence_study: # - 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 +# - line_integrals: List of line integral dicts: +# - name: Name for output +# - expr: Expression to evaluate +# - start: Start point +# - end: End point +# - res: Sampling resolution of line postprocessing: write_pdfs: False write_vecs: False massflow: [] + line_integrals: [] # Parameter Study # ============== diff --git a/tests/stress/inputs/stress_01_source_rot_p1p1p1_stab.yml b/tests/stress/inputs/stress_01_source_rot_p1p1p1_stab.yml index 82faaf3..2cbbd23 100644 --- a/tests/stress/inputs/stress_01_source_rot_p1p1p1_stab.yml +++ b/tests/stress/inputs/stress_01_source_rot_p1p1p1_stab.yml @@ -134,10 +134,17 @@ convergence_study: # - 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 +# - line_integrals: List of line integral dicts: +# - name: Name for output +# - expr: Expression to evaluate +# - start: Start point +# - end: End point +# - res: Sampling resolution of line postprocessing: write_pdfs: False write_vecs: False massflow: [] + line_integrals: [] # Parameter Study # ============== diff --git a/tests/stress/inputs/stress_01_source_rot_p1p2p3_nostab.yml b/tests/stress/inputs/stress_01_source_rot_p1p2p3_nostab.yml index 866dbc5..e5bac6d 100644 --- a/tests/stress/inputs/stress_01_source_rot_p1p2p3_nostab.yml +++ b/tests/stress/inputs/stress_01_source_rot_p1p2p3_nostab.yml @@ -132,10 +132,17 @@ convergence_study: # - 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 +# - line_integrals: List of line integral dicts: +# - name: Name for output +# - expr: Expression to evaluate +# - start: Start point +# - end: End point +# - res: Sampling resolution of line postprocessing: write_pdfs: False write_vecs: False massflow: [] + line_integrals: [] # Parameter Study # ============== diff --git a/tests/stress/inputs/stress_01_source_rot_p2p2p2_stab.yml b/tests/stress/inputs/stress_01_source_rot_p2p2p2_stab.yml index 9b13104..371f1cb 100644 --- a/tests/stress/inputs/stress_01_source_rot_p2p2p2_stab.yml +++ b/tests/stress/inputs/stress_01_source_rot_p2p2p2_stab.yml @@ -133,10 +133,17 @@ convergence_study: # - 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 +# - line_integrals: List of line integral dicts: +# - name: Name for output +# - expr: Expression to evaluate +# - start: Start point +# - end: End point +# - res: Sampling resolution of line postprocessing: write_pdfs: False write_vecs: False massflow: [] + line_integrals: [] # Parameter Study # ============== diff --git a/tests/stress/inputs/stress_10_source_rot_p1p1p1_stab.yml b/tests/stress/inputs/stress_10_source_rot_p1p1p1_stab.yml index acdbd67..2f3f8f3 100644 --- a/tests/stress/inputs/stress_10_source_rot_p1p1p1_stab.yml +++ b/tests/stress/inputs/stress_10_source_rot_p1p1p1_stab.yml @@ -135,10 +135,17 @@ convergence_study: # - 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 +# - line_integrals: List of line integral dicts: +# - name: Name for output +# - expr: Expression to evaluate +# - start: Start point +# - end: End point +# - res: Sampling resolution of line postprocessing: write_pdfs: False write_vecs: False massflow: [] + line_integrals: [] # Parameter Study # ============== -- GitLab