Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 58190b82 authored by PETIT Manuel's avatar PETIT Manuel
Browse files

Refactor solution and growth handling in GBVP class

Centralize solution and growth copying to improve code clarity and reduce redundancy. Updated file output logic to use pre-copied variables for consistency. Also fixed test to align with updated file format, switching from `.xdmf` to `.h5`.
parent a2fa8a47
No related branches found
No related tags found
No related merge requests found
Pipeline #1104600 skipped
......@@ -114,9 +114,12 @@ class GBVP(BVP):
self.set_time(tmin)
self.growth_scheme.dt = dt
current_solution = self.solution.copy(deepcopy=True)
current_growth = self.growth_scheme.get_growth().copy(deepcopy=True)
if store_steps:
self.solution_steps[self.time.current] = self.solution.copy(deepcopy=True)
self.growth_steps[self.time.current] = self.growth_scheme.get_growth()
self.solution_steps[self.time.current] = current_solution
self.growth_steps[self.time.current] = current_growth
if filename is not None:
with fe.HDF5File(MPI_COMM_WORLD, filename, 'w') as file:
......@@ -124,8 +127,8 @@ class GBVP(BVP):
#file.write(self.domain.cdata, "cell_labels")
#file.write(self.domain.bdata, "boundary_labels")
file.write(self.solution, f'solution_t{self.time.current}')
file.write(self.growth_steps[self.time.current], f'growth_t{self.time.current}')
file.write(current_solution, f'solution_t{self.time.current}')
file.write(current_growth, f'growth_t{self.time.current}')
# Add parameters related to the domain : sub_domain / sub_boundary
# if MPI_COMM_WORLD.rank == 0: # h5py does not support parallal mode, use only the main process
......@@ -146,14 +149,17 @@ class GBVP(BVP):
while tmax - self.time.current >= dt:
self.step(dt, **kwargs)
current_solution = self.solution.copy(deepcopy=True)
current_growth = self.growth_scheme.get_growth().copy(deepcopy=True)
if store_steps:
self.solution_steps[self.time.current] = self.solution.copy(deepcopy=True)
self.growth_steps[self.time.current] = self.growth_scheme.get_growth().copy(deepcopy=True)
self.solution_steps[self.time.current] = current_solution
self.growth_steps[self.time.current] = current_growth
if filename is not None:
with fe.HDF5File(MPI_COMM_WORLD, filename, 'a') as file:
file.write(self.solution, f'solution_t{self.time.current}')
file.write(self.growth_steps[self.time.current], f'growth_t{self.time.current}')
file.write(current_solution, f'solution_t{self.time.current}')
file.write(current_growth, f'growth_t{self.time.current}')
self._progressbar.update(self.time.current)
self._progressbar.show()
......
......@@ -35,7 +35,7 @@ class TestGBVP(unittest.TestCase):
def test_run_with_file(self):
gbvp = GBVP(self.domain, self.vform, self.bc, growth_scheme=self.growth_scheme)
gbvp.info()
gbvp.run(0, 0.4, 0.2, filename=self.dir.name+'/solution.xdmf', linear_solver='mumps')
gbvp.run(0, 0.4, 0.2, filename=self.dir.name+'/solution.h5', linear_solver='mumps')
def test_run_without_file(self):
ibvp = GBVP(self.domain, self.vform, self.bc, growth_scheme=self.growth_scheme)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment