Skip to content

Commit

Permalink
Merge pull request #105 from SophT-Team/54_eulerian_grid_field_io
Browse files Browse the repository at this point in the history
(#54) Eulerian grid field IO
  • Loading branch information
bhosale2 authored Jan 18, 2023
2 parents a42e862 + 3ba4327 commit e7d24c7
Show file tree
Hide file tree
Showing 13 changed files with 191 additions and 158 deletions.
21 changes: 7 additions & 14 deletions examples/2d_examples/FlowPastRodCase/flow_past_rod.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,20 +131,13 @@ class FlowPastRodSimulator(
)
# ==================FLOW-ROD COMMUNICATOR SETUP END======
if save_flow_data:
# setup IO
# TODO internalise this in flow simulator as dump_fields
io_origin = np.array(
[
flow_sim.position_field[y_axis_idx].min(),
flow_sim.position_field[x_axis_idx].min(),
]
)
io_dx = flow_sim.dx * np.ones(grid_dim)
io_grid_size = np.array(grid_size)
io = spu.IO(dim=grid_dim, real_dtype=real_t)
io.define_eulerian_grid(origin=io_origin, dx=io_dx, grid_size=io_grid_size)
io.add_as_eulerian_fields_for_io(
vorticity=flow_sim.vorticity_field, velocity=flow_sim.velocity_field
# setup flow IO
io = spu.EulerianFieldIO(
position_field=flow_sim.position_field,
eulerian_fields_dict={
"vorticity": flow_sim.vorticity_field,
"velocity": flow_sim.velocity_field,
},
)
# Initialize rod IO
rod_io = spu.CosseratRodIO(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,20 +238,13 @@ class FlowPastRodSimulator(ea.BaseSystemCollection, ea.Constraints, ea.Forcing):
# ==================FLOW-ROD COMMUNICATOR SETUP END======
# =================FLOW H5 DUMPING====================
if save_flow_data:
# setup IO
# TODO internalise this in flow simulator as dump_fields
io_origin = np.array(
[
flow_sim.position_field[y_axis_idx].min(),
flow_sim.position_field[x_axis_idx].min(),
]
)
io_dx = flow_sim.dx * np.ones(grid_dim)
io_grid_size = np.array(grid_size)
io = spu.IO(dim=grid_dim, real_dtype=real_t)
io.define_eulerian_grid(origin=io_origin, dx=io_dx, grid_size=io_grid_size)
io.add_as_eulerian_fields_for_io(
vorticity=flow_sim.vorticity_field, velocity=flow_sim.velocity_field
# setup flow IO
io = spu.EulerianFieldIO(
position_field=flow_sim.position_field,
eulerian_fields_dict={
"vorticity": flow_sim.vorticity_field,
"velocity": flow_sim.velocity_field,
},
)
# Initialize rod IO
rod_io = spu.CosseratRodIO(
Expand Down
23 changes: 7 additions & 16 deletions examples/3d_examples/ElasticNetCase/immersed_elastic_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def immersed_elastic_net_case(
grid_dim = 3
real_t = spu.get_real_t(precision)
x_axis_idx = spu.VectorField.x_axis_idx()
y_axis_idx = spu.VectorField.y_axis_idx()
z_axis_idx = spu.VectorField.z_axis_idx()
z_range, y_range, x_range = domain_range
grid_size_y = round(y_range / x_range * grid_size_x)
Expand Down Expand Up @@ -72,21 +71,13 @@ def immersed_elastic_net_case(
)
# ==================FLOW-ROD COMMUNICATOR SETUP END======
if save_flow_data:
# setup IO
# TODO internalise this in flow simulator as dump_fields
io_origin = np.array(
[
flow_sim.position_field[z_axis_idx].min(),
flow_sim.position_field[y_axis_idx].min(),
flow_sim.position_field[x_axis_idx].min(),
]
)
io_dx = flow_sim.dx * np.ones(grid_dim)
io_grid_size = np.array(grid_size)
io = spu.IO(dim=grid_dim, real_dtype=real_t)
io.define_eulerian_grid(origin=io_origin, dx=io_dx, grid_size=io_grid_size)
io.add_as_eulerian_fields_for_io(
vorticity=flow_sim.vorticity_field, velocity=flow_sim.velocity_field
# setup flow IO
io = spu.EulerianFieldIO(
position_field=flow_sim.position_field,
eulerian_fields_dict={
"vorticity": flow_sim.vorticity_field,
"velocity": flow_sim.velocity_field,
},
)
# Initialize carpet IO
elastic_net_io = spu.IO(dim=grid_dim, real_dtype=real_t)
Expand Down
23 changes: 7 additions & 16 deletions examples/3d_examples/FlowPastRodCase/flow_past_rod_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def flow_past_rod_case(
grid_size_z, grid_size_y, grid_size_x = grid_size
real_t = spu.get_real_t(precision)
x_axis_idx = spu.VectorField.x_axis_idx()
y_axis_idx = spu.VectorField.y_axis_idx()
z_axis_idx = spu.VectorField.z_axis_idx()
rho_f = 1.0
U_free_stream = 1.0
Expand Down Expand Up @@ -139,21 +138,13 @@ class FlowPastRodSimulator(
)

if save_data:
# setup IO
# TODO internalise this in flow simulator as dump_fields
io_origin = np.array(
[
flow_sim.position_field[z_axis_idx].min(),
flow_sim.position_field[y_axis_idx].min(),
flow_sim.position_field[x_axis_idx].min(),
]
)
io_dx = flow_sim.dx * np.ones(grid_dim)
io_grid_size = np.array(grid_size)
io = spu.IO(dim=grid_dim, real_dtype=real_t)
io.define_eulerian_grid(origin=io_origin, dx=io_dx, grid_size=io_grid_size)
io.add_as_eulerian_fields_for_io(
vorticity=flow_sim.vorticity_field, velocity=flow_sim.velocity_field
# setup flow IO
io = spu.EulerianFieldIO(
position_field=flow_sim.position_field,
eulerian_fields_dict={
"vorticity": flow_sim.vorticity_field,
"velocity": flow_sim.velocity_field,
},
)
# Initialize sphere IO
rod_io = spu.CosseratRodIO(
Expand Down
23 changes: 7 additions & 16 deletions examples/3d_examples/FlowPastSphereCase/flow_past_sphere_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def flow_past_sphere_case(
grid_size_z, grid_size_y, grid_size_x = grid_size
real_t = spu.get_real_t(precision)
x_axis_idx: int = spu.VectorField.x_axis_idx()
y_axis_idx = spu.VectorField.y_axis_idx()
z_axis_idx = spu.VectorField.z_axis_idx()
x_range = 1.0
far_field_velocity = 1.0
Expand Down Expand Up @@ -79,21 +78,13 @@ def flow_past_sphere_case(
# ==================FLOW-BODY COMMUNICATOR SETUP END======

if save_flow_data:
# setup IO
# TODO internalise this in flow simulator as dump_fields
io_origin = np.array(
[
flow_sim.position_field[z_axis_idx].min(),
flow_sim.position_field[y_axis_idx].min(),
flow_sim.position_field[x_axis_idx].min(),
]
)
io_dx = flow_sim.dx * np.ones(grid_dim)
io_grid_size = np.array(grid_size)
io = spu.IO(dim=grid_dim, real_dtype=real_t)
io.define_eulerian_grid(origin=io_origin, dx=io_dx, grid_size=io_grid_size)
io.add_as_eulerian_fields_for_io(
vorticity=flow_sim.vorticity_field, velocity=flow_sim.velocity_field
# setup flow IO
io = spu.EulerianFieldIO(
position_field=flow_sim.position_field,
eulerian_fields_dict={
"vorticity": flow_sim.vorticity_field,
"velocity": flow_sim.velocity_field,
},
)
# Initialize sphere IO
sphere_io = spu.IO(dim=grid_dim, real_dtype=real_t)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def flow_through_circular_pipe_case(
real_t = spu.get_real_t(precision)
x_axis_idx = spu.VectorField.x_axis_idx()
y_axis_idx = spu.VectorField.y_axis_idx()
z_axis_idx = spu.VectorField.z_axis_idx()
x_range = 1.0
nu = 1e-2
flow_sim = sps.UnboundedNavierStokesFlowSimulator3D(
Expand Down Expand Up @@ -72,21 +71,13 @@ def flow_through_circular_pipe_case(
# ==================FLOW-BODY COMMUNICATOR SETUP END======

if save_data:
# setup IO
# TODO internalise this in flow simulator as dump_fields
io_origin = np.array(
[
flow_sim.position_field[z_axis_idx].min(),
flow_sim.position_field[y_axis_idx].min(),
flow_sim.position_field[x_axis_idx].min(),
]
)
io_dx = flow_sim.dx * np.ones(grid_dim)
io_grid_size = np.array(grid_size)
io = spu.IO(dim=grid_dim, real_dtype=real_t)
io.define_eulerian_grid(origin=io_origin, dx=io_dx, grid_size=io_grid_size)
io.add_as_eulerian_fields_for_io(
vorticity=flow_sim.vorticity_field, velocity=flow_sim.velocity_field
# setup flow IO
io = spu.EulerianFieldIO(
position_field=flow_sim.position_field,
eulerian_fields_dict={
"vorticity": flow_sim.vorticity_field,
"velocity": flow_sim.velocity_field,
},
)

t_end = 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ def hill_sphere_vortex_case(
the velocity recovery and vortex stretching steps, for the solver,
by comparing against analytical expressions.
"""
grid_dim = 3
grid_size_z, grid_size_y, grid_size_x = grid_size
real_t = spu.get_real_t(precision)
x_axis_idx = spu.VectorField.x_axis_idx()
Expand Down Expand Up @@ -116,23 +115,14 @@ def hill_sphere_vortex_case(
fig2.savefig("midplane_radial_velocity.png")

if save_data:
# setup IO
# TODO internalise this in flow simulator as dump_fields
io_origin = np.array(
[
flow_sim.position_field[z_axis_idx].min(),
flow_sim.position_field[y_axis_idx].min(),
flow_sim.position_field[x_axis_idx].min(),
]
)
io_dx = flow_sim.dx * np.ones(grid_dim)
io_grid_size = np.array(grid_size)
io = spu.IO(dim=grid_dim, real_dtype=real_t)
io.define_eulerian_grid(origin=io_origin, dx=io_dx, grid_size=io_grid_size)
io.add_as_eulerian_fields_for_io(
vorticity=flow_sim.vorticity_field,
stream_func=flow_sim.stream_func_field,
velocity=flow_sim.velocity_field,
# setup flow IO
io = spu.EulerianFieldIO(
position_field=flow_sim.position_field,
eulerian_fields_dict={
"vorticity": flow_sim.vorticity_field,
"stream_func": flow_sim.stream_func_field,
"velocity": flow_sim.velocity_field,
},
)
io.save(h5_file_name="sopht.h5")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def immersed_magnetic_cilia_carpet_case(
grid_dim = 3
real_t = spu.get_real_t(precision)
x_axis_idx = spu.VectorField.x_axis_idx()
y_axis_idx = spu.VectorField.y_axis_idx()
z_axis_idx = spu.VectorField.z_axis_idx()
z_range, y_range, x_range = domain_range
grid_size_y = round(y_range / x_range * grid_size_x)
Expand Down Expand Up @@ -65,21 +64,13 @@ def immersed_magnetic_cilia_carpet_case(
)
# ==================FLOW-ROD COMMUNICATOR SETUP END======
if save_data:
# setup IO
# TODO internalise this in flow simulator as dump_fields
io_origin = np.array(
[
flow_sim.position_field[z_axis_idx].min(),
flow_sim.position_field[y_axis_idx].min(),
flow_sim.position_field[x_axis_idx].min(),
]
)
io_dx = flow_sim.dx * np.ones(grid_dim)
io_grid_size = np.array(grid_size)
io = spu.IO(dim=grid_dim, real_dtype=real_t)
io.define_eulerian_grid(origin=io_origin, dx=io_dx, grid_size=io_grid_size)
io.add_as_eulerian_fields_for_io(
vorticity=flow_sim.vorticity_field, velocity=flow_sim.velocity_field
# setup flow IO
io = spu.EulerianFieldIO(
position_field=flow_sim.position_field,
eulerian_fields_dict={
"vorticity": flow_sim.vorticity_field,
"velocity": flow_sim.velocity_field,
},
)
# Initialize carpet IO
carpet_io = spu.IO(dim=grid_dim, real_dtype=real_t)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,22 +183,13 @@ def tapered_arm_and_cylinder_flow_coupling(
# ==================FLOW-ROD COMMUNICATOR SETUP END======

if save_data:
# setup IO
# TODO internalise this in flow simulator as dump_fields
io_origin = np.array(
[
flow_sim.position_field[z_axis_idx].min(),
flow_sim.position_field[y_axis_idx].min(),
flow_sim.position_field[x_axis_idx].min(),
]
)
io_dx = flow_sim.dx * np.ones(grid_dim)
io_grid_size = np.array(grid_size)
# Initialize flow eulerian grid IO
io = spu.IO(dim=grid_dim, real_dtype=real_t)
io.define_eulerian_grid(origin=io_origin, dx=io_dx, grid_size=io_grid_size)
io.add_as_eulerian_fields_for_io(
vorticity=flow_sim.vorticity_field, velocity=flow_sim.velocity_field
# setup flow IO
io = spu.EulerianFieldIO(
position_field=flow_sim.position_field,
eulerian_fields_dict={
"vorticity": flow_sim.vorticity_field,
"velocity": flow_sim.velocity_field,
},
)
# Initialize rod io
rod_io = spu.CosseratRodIO(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ def point_source_advection_diffusion_case(
constant velocity in 3D, while it diffuses in time.
"""
grid_dim = 3
grid_size_z, grid_size_y, grid_size_x = grid_size
real_t = spu.get_real_t(precision)
x_axis_idx = spu.VectorField.x_axis_idx()
y_axis_idx = spu.VectorField.y_axis_idx()
Expand Down Expand Up @@ -62,20 +61,13 @@ def point_source_advection_diffusion_case(
flow_sim.velocity_field[...] = velocity_free_stream

if save_data:
# setup IO
# TODO internalise this in flow simulator as dump_fields
io_origin = np.array(
[
flow_sim.position_field[z_axis_idx].min(),
flow_sim.position_field[y_axis_idx].min(),
flow_sim.position_field[x_axis_idx].min(),
]
# setup flow IO
io = spu.EulerianFieldIO(
position_field=flow_sim.position_field,
eulerian_fields_dict={
"vorticity": vorticity_field,
},
)
io_dx = flow_sim.dx * np.ones(grid_dim)
io_grid_size = np.array([grid_size_z, grid_size_y, grid_size_x])
io = spu.IO(dim=grid_dim, real_dtype=real_t)
io.define_eulerian_grid(origin=io_origin, dx=io_dx, grid_size=io_grid_size)
io.add_as_eulerian_fields_for_io(vorticity=vorticity_field)

foto_timer = 0.0
foto_timer_limit = (t_end - t_start) / 20
Expand Down
2 changes: 1 addition & 1 deletion sopht/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from .plot_field import create_figure_and_axes, save_and_clear_fig
from .post_process import make_video_from_image_series, make_dir_and_transfer_h5_data
from .field import VectorField
from .io import IO, CosseratRodIO
from .io import IO, CosseratRodIO, EulerianFieldIO
from .rod_viz import plot_video_of_rod_surface
from .precision import get_real_t, get_test_tol
from .pyst_kernel_config import get_pyst_dtype, get_pyst_kernel_config
Loading

0 comments on commit e7d24c7

Please sign in to comment.