Skip to content

Commit

Permalink
#117: VTU exports NaN for initial non-forward fields
Browse files Browse the repository at this point in the history
  • Loading branch information
ddundo committed Oct 31, 2024
1 parent d6d09c4 commit 6f96c36
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
5 changes: 2 additions & 3 deletions demos/gray_scott.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 2 additions & 3 deletions demos/gray_scott_split.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <gray_scott_split.py>`__.
20 changes: 10 additions & 10 deletions goalie/function_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions test_adjoint/test_demos.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""},
Expand Down

0 comments on commit 6f96c36

Please sign in to comment.