diff --git a/demos/gray_scott.py b/demos/gray_scott.py index 36dd3e12..9d1a8c9d 100644 --- a/demos/gray_scott.py +++ b/demos/gray_scott.py @@ -160,11 +160,10 @@ def qoi(): # Finally, plot the outputs to be viewed in Paraview. :: solutions.export( - "gray_scott/forward.pvd", - export_field_types="forward", + "gray_scott/solutions.pvd", + export_field_types=["forward", "adjoint"], initial_condition=mesh_seq.get_initial_condition(), ) -solutions.export("gray_scott/adjoint.pvd", export_field_types="adjoint") # In the `next demo <./gray_scott_split.py.html>`__, we consider solving the same # problem, but splitting the solution field into multiple components. diff --git a/demos/gray_scott_split.py b/demos/gray_scott_split.py index f8f74b63..5adcf89b 100644 --- a/demos/gray_scott_split.py +++ b/demos/gray_scott_split.py @@ -162,10 +162,9 @@ def qoi(): solutions = mesh_seq.solve_adjoint() solutions.export( - "gray_scott_split/forward.pvd", - export_field_types="forward", + "gray_scott_split/solutions.pvd", + export_field_types=["forward", "adjoint"], initial_condition=mesh_seq.get_initial_condition(), ) -solutions.export("gray_scott_split/adjoint.pvd", export_field_types="adjoint") # This tutorial can be dowloaded as a `Python script `__. diff --git a/goalie/function_data.py b/goalie/function_data.py index 5c39d51a..c2815914 100644 --- a/goalie/function_data.py +++ b/goalie/function_data.py @@ -211,25 +211,25 @@ def _export_vtk(self, output_fpath, export_field_types, initial_condition=None): tp = self.time_partition outfile = VTKFile(output_fpath, adaptive=True) if initial_condition is not None: - if export_field_types != ["forward"]: - print( - "Initial condition not exported because more than 'forward' field" - " type is selected for export." - ) - else: - ics = [] + ics = [] + for field_type in export_field_types: for field, ic in initial_condition.items(): ic = ic.copy(deepcopy=True) # If the function space is mixed, rename and append each # subfunction separately if hasattr(ic.function_space(), "num_sub_spaces"): for idx, sf in enumerate(ic.subfunctions): - sf.rename(f"{field}[{idx}]_forward") + if field_type != "forward": + sf = sf.copy(deepcopy=True) + sf.assign(float("nan")) + sf.rename(f"{field}[{idx}]_{field_type}") ics.append(sf) else: - ic.rename(f"{field}_forward") + if field_type != "forward": + ic.assign(float("nan")) + ic.rename(f"{field}_{field_type}") ics.append(ic) - outfile.write(*ics, time=tp.subintervals[0][0]) + outfile.write(*ics, time=tp.subintervals[0][0]) for i in range(tp.num_subintervals): for j in range(tp.num_exports_per_subinterval[i] - 1): diff --git a/test_adjoint/test_demos.py b/test_adjoint/test_demos.py index da9a58e1..22d99370 100644 --- a/test_adjoint/test_demos.py +++ b/test_adjoint/test_demos.py @@ -25,11 +25,11 @@ "burgers-hessian.py": {""""maxiter": 35""": """"maxiter": 3"""}, "gray_scott.py": { "end_time = 2000.0": "end_time = 10.0", - r"solutions\.export\((.*?)\)\s*solutions\.export\((.*?)\)": "", + r"solutions\.export\((.*?)\)": "", }, "gray_scott_split.py": { "end_time = 2000.0": "end_time = 10.0", - r"solutions\.export\((.*?)\)\s*solutions\.export\((.*?)\)": "", + r"solutions\.export\((.*?)\)": "", }, "point_discharge2d-hessian.py": {""""maxiter": 35""": """"maxiter": 3"""}, "point_discharge2d-goal_oriented.py": {""""maxiter": 35""": """"maxiter": 3"""},