This documentation is not for the latest stable Salvus version.
We consider a spatial domain (d = 2 or 3), a time interval , and a diffusion equation of the following form:
with initial conditions
.
Here, denotes the space- and time-dependent diffusive field and are describes external forces. denotes the first time derivative and the spatial gradient operator. Furthermore, the scalar parameter and the symmetric second-order diffusion tensor are space-dependent coefficients.
can be related to a Wiener process using the relation
which direction-dependent smoothing lengths .
For the special case of and , corresponds to the standard deviation of the Gaussian smoothing in meters.
In the isotropic case, simplifies to a scalar value, in which case we may re-write the diffusion equation as
with and the isotropic smoothing length .
%config Completer.use_jedi = False
# Standard Python packages
import matplotlib.pyplot as plt
import numpy as np
import os
import toml
# Salvus imports
from salvus.mesh.structured_grid_2D import StructuredGrid2D
from salvus.mesh.unstructured_mesh import UnstructuredMesh
import salvus.flow.api
import salvus.flow.simple_config as sc
SALVUS_FLOW_SITE_NAME = os.environ.get("SITE_NAME", "token")
sg = StructuredGrid2D.rectangle(nelem_x=40, nelem_y=60, max_x=4.0, max_y=6.0)
mesh = sg.get_unstructured_mesh()
mesh.find_side_sets("cartesian")
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 0x7f4271c9d650>
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 0x7f4271c9d190>
sim = sc.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()
salvus.flow.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,
)
Job `job_2010191434989367_fad98f254e` running on `local` with 1 rank(s). Site information: * Salvus version: 0.11.19 * Floating point size: 32
* Downloaded 30.2 MB of results to `output`. * Total run time: 4.38 seconds. * Pure simulation time: 3.84 seconds.
<salvus.flow.sites.salvus_job.SalvusJob at 0x7f41dd2e4bd0>
mesh = UnstructuredMesh.from_h5(filename="output/out.h5")
mesh
<salvus.mesh.unstructured_mesh.UnstructuredMesh at 0x7f413dbbe850>
!open .
/bin/sh: 1: open: not found