Skip to content

Commit

Permalink
added a test for dump and load (#224)
Browse files Browse the repository at this point in the history
* added test_checkpoint and adapted poiseuille.py flow to new architecture

* pep8 cosmetics
  • Loading branch information
PhiSpel authored Aug 22, 2024
1 parent 87a95d2 commit c9e11a2
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions tests/test_checkpoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from copy import deepcopy
from tests.common import *


def test_checkpoint(tmpdir):
context = Context()
flow = PoiseuilleFlow2D(context=context,
resolution=[512, 512],
reynolds_number=1,
mach_number=0.02,
initialize_with_zeros=False)
f0 = deepcopy(flow.f)
filename = tmpdir / 'PoiseuilleFlow2D'
flow.dump(filename)
simulation = Simulation(flow,
BGKCollision(flow.units.relaxation_parameter_lu),
[])
simulation(10)
flow.load(filename)
assert torch.eq(f0, flow.f).all()

"""
This could be a way to test a dump-load workflow which stores all flow
attributes. I did not get it to work, yet.
context = Context('cuda')
flow = PoiseuilleFlow2D(context=context,
resolution=16,
reynolds_number=1,
mach_number=0.02,
initialize_with_zeros=False)
f0 = deepcopy(flow.f)
filename = './PoiseuilleFlow2D'
flow.dump(filename)
simulation = Simulation(flow,
BGKCollision(flow.units.relaxation_parameter_lu),
[])
simulation(10)
context2 = Context('cpu')
flow2 = PoiseuilleFlow2D(context=context2,
resolution=32,
reynolds_number=10,
mach_number=0.01,
initialize_with_zeros=True)
flow2.load(filename)
assert flow2.resolution == flow.resolution
assert flow2.units.reynolds_number == flow.units.reynolds_number
assert flow2.units.mach_number == flow.units.mach_number
assert flow2.initialize_with_zeros == flow.initialize_with_zeros
assert torch.eq(f0, flow2.f).all()
"""

0 comments on commit c9e11a2

Please sign in to comment.