This documentation is not for the latest stable Salvus version.
# Standard Python packages
import matplotlib.pyplot as plt
import numpy as np
import os
import toml
# Salvus imports
import salvus.namespace as sn
SALVUS_FLOW_SITE_NAME = os.environ.get("SITE_NAME", "token")
mesh = sn.simple_mesh.basic_mesh.CartesianHomogeneousAcoustic2D(
x_max=4.0, y_max=6.0, vp=1000.0, rho=1000.0, max_frequency=5000.0
).create_mesh()
# We don't need any material parameters.
mesh.elemental_fields = {}
input_mesh = mesh.copy()
input_mesh.attach_field("some_field", np.random.randn(mesh.npoint))
input_mesh.map_nodal_fields_to_element_nodal()
input_mesh.write_h5("initial_values.h5")
input_mesh
<salvus.mesh.unstructured_mesh.UnstructuredMesh at 0x7fa585943750>
smoothing_length_in_meters = 0.1
mesh.attach_field("M0", np.ones_like(mesh.get_element_nodes()[:, :, 0]))
mesh.attach_field(
"M1",
0.5
* smoothing_length_in_meters**2
* np.ones_like(mesh.get_element_nodes()[:, :, 0]),
)
mesh.attach_field("fluid", np.ones(mesh.nelem))
mesh
<salvus.mesh.unstructured_mesh.UnstructuredMesh at 0x7fa5859764d0>
sim = sn.simple_config.simulation.Diffusion(mesh=mesh)
sim.domain.polynomial_order = 1
sim.physics.diffusion_equation.time_step_in_seconds = 1e-3
sim.physics.diffusion_equation.courant_number = 0.06
sim.physics.diffusion_equation.initial_values.filename = "initial_values.h5"
sim.physics.diffusion_equation.initial_values.format = "hdf5"
sim.physics.diffusion_equation.initial_values.field = "some_field"
sim.physics.diffusion_equation.final_values.filename = "out.h5"
sim.output.volume_data.filename = "diffusion.h5"
sim.output.volume_data.format = "hdf5"
sim.output.volume_data.fields = ["phi"]
sim.output.volume_data.sampling_interval_in_time_steps = 10
sim.validate()
sn.api.run(
site_name=SALVUS_FLOW_SITE_NAME,
input_file=sim,
ranks=1,
output_folder="output",
get_all=True,
overwrite=True,
wall_time_in_seconds=600,
)
SalvusJob `job_2403150930502348_7aaeda8d53` running on `local` with 1 rank(s). Site information: * Salvus version: 0.12.16 * Floating point size: 32
* Downloaded 8.0 MB of results to `output`. * Total run time: 1.01 seconds. * Pure simulation time: 0.71 seconds.
<salvus.flow.sites.salvus_job.SalvusJob at 0x7fa57d6bf150>
mesh = sn.UnstructuredMesh.from_h5(filename="output/out.h5")
mesh
<salvus.mesh.unstructured_mesh.UnstructuredMesh at 0x7fa57d61be90>