From 98a26e4bf7e9e9acd9adf9907b67335e75311448 Mon Sep 17 00:00:00 2001 From: Kei Date: Sat, 23 Sep 2023 19:45:48 +0200 Subject: [PATCH] switch to json format --- turtleFSI/monolithic.py | 7 +++---- turtleFSI/problems/__init__.py | 7 ++++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/turtleFSI/monolithic.py b/turtleFSI/monolithic.py index 2a880fc..1d99cb9 100644 --- a/turtleFSI/monolithic.py +++ b/turtleFSI/monolithic.py @@ -10,7 +10,7 @@ from dolfin import * from pathlib import Path -import pickle +import json import time from pprint import pprint @@ -44,8 +44,8 @@ if default_variables["restart_folder"] is not None: restart_folder = Path(default_variables["restart_folder"]) restart_folder = restart_folder if "Checkpoint" in restart_folder.__str__() else restart_folder.joinpath("Checkpoint") - with open(restart_folder.joinpath("default_variables.pickle"), "rb") as f: - restart_dict = pickle.load(f) + with open(restart_folder.joinpath("default_variables.json"), "r") as f: + restart_dict = json.load(f) default_variables.update(restart_dict) default_variables["restart_folder"] = restart_folder @@ -168,7 +168,6 @@ first_step_num = counter # This is so that the solver will recompute the jacobian on the first step of the simulation while t <= T + dt / 10 and not stop: # + dt / 10 is a hack to ensure that we take the final time step t == T t += dt - # Pre solve hook tmp_dict = pre_solve(**vars()) if tmp_dict is not None: diff --git a/turtleFSI/problems/__init__.py b/turtleFSI/problems/__init__.py index 1c2a7e6..1a2d1ec 100644 --- a/turtleFSI/problems/__init__.py +++ b/turtleFSI/problems/__init__.py @@ -8,7 +8,7 @@ """ from dolfin import parameters, XDMFFile, MPI, assign, Mesh, refine, project, VectorElement, FiniteElement, PETScDMCollection, FunctionSpace, Function -import pickle +import json from pathlib import Path from xml.etree import ElementTree as ET import numpy as np @@ -187,8 +187,9 @@ def checkpoint(dvp_, default_variables, checkpoint_folder, mesh, **namespace): # Dump default parameters if MPI.rank(MPI.comm_world) == 0: - with open(str(checkpoint_folder.joinpath("default_variables.pickle")), "bw") as f: - pickle.dump(default_variables, f) + with open(str(checkpoint_folder.joinpath("default_variables.json")), "w") as f: + default_variables["restart_folder"] = str(default_variables["restart_folder"]) + json.dump(default_variables, f) # Dump physical fields fields = _get_fields(dvp_, mesh)