migflow.fluid

Model for Immersed Granular Flow: Fluid user interface

Contact: jonathan.lambrechts@uclouvain.be Webpage: www.migflow.be

MigFlow computes immersed granular flows using an unresolved FEM-DEM model. The continuous phase (mixture) is computed by solving averaged Navier-Stokes equations on unstructured meshes with the continuous finite element method.

class migflow.fluid.FluidProblem(dim, g=None, mu=None, rho=None, sigma=0, coeff_stab=0.01, volume_drag=0.0, quadratic_drag=0.0, solver=None, solver_options='', drag_in_stab=1, drag_coefficient_factor=1, temporal=True, advection=True, flag_div_us=True, p2p1=False, full_implicit=False, model_b=False, density_element=None, viscosity_element=None)

Bases: object

Creates the numerical representation of the fluid.

Builds the fluid structure.

Parameters:
  • dim (int) – Dimension of the problem
  • g (Optional[ndarray]) – Gravity vector
  • mu (Optional[list]) – List of fluid phases viscosities (this should be a vector whom dimension specify if there is one or two fluid)
  • rho (Optional[list]) – List of fluid phases densities (this should be a vector whom dimension specify if there is one or two fluid)
  • alpha – List of fluid phases dilatation coefficients (this should be a vector whom dimension specify if there is one or two fluid)
  • sigma (float) – Surface tension (only when there are two fluids)
  • coeff_stab (float) – Optional argument used as coefficient for extra diffusivity added to stabilise the advection of concentration (only for two fluid problem)
  • solver (Optional[str]) – possible solver are “pardiso”, “mumps”, “petsc”, “scipy”
  • solver_options (str) – Optional argument to specify solver option (only when petsc is used)
  • drag_in_stab (int) – States if the drag force is in the stabilisation term
  • drag_coefficient_factor (int) – Factor multiplicating the drag coefficient
  • temporal (bool) – Enables d/dt (i.e. False = steady)
  • advection (bool) – Enables advective terms (i.e. False = Stokes, True = Navier-Stokes)
  • flag_div_us (bool) – if False, div.u_solid is evaluated = (porosity-old_porosity)/dt (deprecated always True)
  • p2p1 (bool) – if False, use p2p1 without stab, else a stabilised p1p1 formulation is used
Raises:
  • ValueError – If the dimension differs from 2 or 3
  • NameError – If C builder cannot be found
__del__()

Deletes the fluid structure.

adapt_mesh(mesh_file_name=None)

Project the current fluid problem unto a new mesh. If particles are present, one should set them again after adapting the mesh.

mesh_file_name: Name of the msh file. If None the current gmsh model is loaded without the need of a msh file.

add_constraint(constraint_index, constraint_value)
advance_concentration(dt)

Solves the advection equation for the concentration using the current velocity field.

Parameters:dt (float) – Computation time step
assemble_weak_boundaries()

Assembles the weak boundaries contribution to the system.

Parameters:
  • localm – local mass matrix
  • localv – local vector
boundary_force()

Give access to force exerted by the fluid on the boundaries.

Returns:Forces exerted by the fluid on the boundaries.
Return type:np.ndarray
boundary_force_by_contributions(bnd_name)

Returns the forces exerted respectively by the pressure gradient and the viscous stress tensor at the boundaries.

Parameters:bnd_name – boundary name
Returns:(2*D,) : the first D components are the pressure gradient contribution and the last D components are the viscous stress tensor contribution.
Return type:np.ndarray
bounding_box(padding_ratio=0.0)

Returns the bounding box of the Fluid problem. :returns: position of the lower left corner, position of the upper right corner :rtype: Tuple[np.ndarray, np.ndarray]

bulk_force()

Gives access to the volume force at fluid nodes. :returns: Bulk force :rtype: np.ndarray

compute_cfl()

Computes the CFL number divided by the time step

compute_node_force(dt=None)

Computes the forces to apply on each grain resulting from the fluid motion.

Parameters:dt (Optional[float]) – Computation time step
concentration_dg()

Returns the concentration at discontinuous nodes.

Returns:concentration field
Return type:np.ndarray
concentration_dg_grad()

Returns the gradient of the concentration field at discontinuous nodes.

Returns:concentration gradient
Return type:np.ndarray
coordinates()

Gives access to the coordinate of the mesh nodes.

Returns:mesh nodal coordinates
Return type:np.ndarray
coordinates_fields()

Returns the coordinates of each degree of freedom of the solution.

Returns:fields coordinates
Return type:np.ndarray
curvature()

Returns the curvature at each element.

Returns:curvature
Return type:np.ndarray
density()

Reads the density.

Returns:density
Return type:np.ndarray
dimension()

Returns the dimension of the problem

Returns:dimension
Return type:int
element_tags()

Gives read-only access to the tags of the elements of the mesh.

Returns:mesh elements ags
Return type:np.ndarray
elements()

Gives read-only access to the elements of the mesh.

Returns:mesh elements
Return type:np.ndarray
enable_stability(enable_pspg=True, enable_supg=True)

Enable stabilty flags in the fluid problem :type enable_pspg: bool :param enable_pspg: Enable PSPG stabilisation. Defaults to True. :type enable_pspg: bool, optional :type enable_supg: bool :param enable_supg: Enable SUPG stabilisation. Defaults to True. :type enable_supg: bool, optional

field_index(ifield)

Gives access to all the index of a field into the solution vector.

Parameters:ifield (int) – field index (0,..,dimension-1) is a velocity, dimension gives the pressure.
Returns:index array.
Return type:np.ndarray
fields_gradient()

Returns an continuous gradient estimation of each field on a P1 mesh.

Returns:Fields_gradient
Return type:np.ndarray
free_csr(csr_ptr, csr_element_id, csr_xi, csr_surface)
full_implicit_euler(**kwargs)
g()

Returns the gravity field.

Returns:gravity field
Return type:np.ndarray
get_bodies_csr_force()
get_bodies_csr_size()
get_default_discretisation()

Returns the default discretisation elements as a dictionnary {field : discretisation_element} :returns: default discretisation elements :rtype: dict

get_default_export(dtype=<class 'numpy.float64'>)

Returns the default fields to write in your output as a dictionnary {field : (values, discretisation_element)} :param dtype: numpy representation. Defaults to np.float64.

Returns:default fields
Return type:dict
get_density_element()

Returns the density element used.

Returns:“element used”
Return type:str
get_forces_on_bodies()
get_mapping(etype)

Get mapping associated to an element.

Parameters:etype (str) – element type (“P1”, “P1DG”, “P2”, “P2DG”)
Returns:mapping associated to the element type.
Return type:np.ndarray
get_mesh_disc_overlap(x_disc, radius)

Returns the centroid of the overlap of the discs with the mesh as a csr matrix.

Return type:tuple
get_mesh_particle_centroid(x_particles, radius)

Returns the centroid of the particles with the mesh as a csr matrix.

Return type:tuple
get_mesh_polygons_overlap(vertices)
Return type:tuple
get_p1_element()

Returns the P1 element used -> “triangle_p1” or “tetrahedron_p1”

Returns:“triangle_p1”
Return type:str
get_particle_forces(dt)
get_pressure_element()

Returns the discretisation element of the pressure field :returns: pressure element :rtype: str

get_velocity_element()

Returns the discretisation element of the velocity field :returns: velocity element :rtype: str

get_viscosity_element()

Returns the viscosity element used.

Returns:“element used”
Return type:str
global_map()

Gives access to the map of all the degrees of freedom.

Returns:global mapping
Return type:np.ndarray
ic_source()
implicit_euler(**kwargs)
implicit_euler_advect_nodes(**kwargs)
interpolate(solution=None, velocity=None, velocity_x=None, velocity_y=None, velocity_z=None, pressure=None)

Imposes the solution (or the field) to the prescribed value. If a callback is given, the solution (or field) is estimated at its local position. The solution (or field) is strongly imposed (not weakly).

Parameters:
  • solution (Union[ndarray, <built-in function callable>, None]) – imposed solution vector
  • velocity (Union[ndarray, <built-in function callable>, None]) – imposed velocity vector.
  • velocity_x (Union[ndarray, <built-in function callable>, None]) – imposed horizontal velocity component.
  • velocity_y (Union[ndarray, <built-in function callable>, None]) – imposed horizontal velocity component.
  • velocity_z (Union[ndarray, <built-in function callable>, None]) – imposed horizontal velocity component.
  • pressure (Union[ndarray, <built-in function callable>, None]) – imposed pressure field.
load_msh(filename)

Sets the domain geometry for the fluid computation.

Parameters:filename (str) – Name of the msh file. If None the current gmsh model is loaded without the need to a msh file.
local_boundary_force_by_contribution(bnd_name)

Returns the forces exerted by the pressure gradient and the viscous stress at each edge of the boundary.

Parameters:bnd_name (_type_) – boundary name
Returns:the first D components are the pressure gradient contribution and the last D components are the viscous stress tensor contribution.
Return type:np.ndarray(n_edges, 2*D)
local_size()

Returns the number of degree of freedom by element.

Returns:number of degree of freedom by element
Return type:int
mesh_boundaries()

Returns the mesh boundaries information as a dictionnary : {boundary_number : edges} :returns: Mesh information : {boundary_number : edges} :rtype: dict

mesh_velocity()

Give access to the mesh velocity value at the mesh nodes.

Returns:mesh velocities at the mesh nodes
Return type:np.ndarray
move_particles(position, velocity, omega, contact)

Set location of the grains in the mesh and compute the porosity in each cell (deprecated, use set_particles instead).

Parameters:
  • position (ndarray) – List of particles centre positions
  • velocity (ndarray) – List of particles velocity
  • omega (ndarray) – List of particles angular velocity
  • contact (ndarray) – List of particles contact resultant forces
n_bodies()
n_elements()

Returns the number of mesh elements.

Returns:number of elements
Return type:int
n_fields()

Returns the number of fluid fields.

Returns:number of fields
Return type:int
n_fluids()

Returns the number of fluids (only one or two).

Returns:Number of fluids
Return type:int
n_nodes()

Returns the number of mesh nodes.

Returns:number of nodes
Return type:int
node_volume()

Returns the volume associated with each node. :returns: node volume :rtype: np.ndarray

p_jump()

Set jump pressure variable.

Parameters:jump – jump values
parent_nodes()

Gives access to the parent nodes of each node.

Returns:The parent nodes mapping
Return type:np.ndarray
porosity()

Returns the porosity at independant nodes.

Returns:volume fluid fraction
Return type:np.ndarray
pressure()

Reads the pressure solution.

Returns:pressure
Return type:np.ndarray
pressure_index()

Returns the index of the pressure field into the solution vector.

Returns:pressure index array
Return type:np.ndarray
read_field(odir, fields_name, t=None, iteration=None, etype='P1')

Reads a field from output file.

Parameters:
  • odir (str) – Directory in which to read the file
  • fields_name (list) – list of field names to read
  • t (Optional[float]) – Time at which to read the file
  • iteration to read, -1 for last iteration (iteration;) –
Returns:

field values

Return type:

np.ndarray

read_mig(odir, t=None, iteration=None)

Reads output file to reload computation.

Parameters:
  • odir (str) – Directory in which to read the file
  • t (Optional[float]) – Time at which to read the file
  • iteration to read, -1 for last iteration (iteration;) –
read_vtk(dirname, i)

(DEPRECATED) Reads output file to reload computation.

Parameters:filename – Name of the file to read
set_bodies(density, volume, csr_ptr, csr_element_id, csr_xi, csr_surface, csr_velocity, csr_gamma, csr_contact)
set_concentration_cg(concentration)

Sets the concentration at nodes. :type concentration: ndarray :param concentration: concentration field

set_coordinates(x)

Sets the coordinates of the mesh nodes

Parameters:x (ndarray) – new nodes positions
set_detmin(detmin)

Sets the detmin value in each element. :type detmin: ndarray :param detmin: detmin value of each element

set_mean_pressure(mean_pressure)

Enables the nodal mean pressure constraint and imposes its value.

Parameters:mean_pressure (float) – add a constraint to impose sum_i vol_i p_i = mean_pressure*volume
set_mesh(nodes, elements, elementTags, boundaries, advected_solution=None)

Sets the domain geometry for the fluid computation.

Parameters:
  • nodes (ndarray) – (n_node, 3) numpy float array of the nodes coordinates
  • elements (ndarray) – (n_elements, dimension+1) numpy int array of the elements
  • elementsTags – (n_elements) numpy int array of the elements tags
  • boundaries (list) – [(name, (n_elements, dimension))] list of pair of name (string)
  • numpy int array with the corresponding boundary elements (and) –
set_open_boundary(tag, velocity=None, pressure=None, concentration=None, viscous_flag=1)

Sets the weak open boundaries (=normal fluxes) for the fluid problem.

Parameters:
  • tag (Union[str, List[str]]) – Physical tag (or list of tags), set in the mesh, of the open boundaries
  • velocity (Union[float, <built-in function callable>, None]) – The velocity value if imposed (callback or number)
  • pressure (Union[float, <built-in function callable>, None]) – The pressure value if imposed (callback or number)
  • concentration (Union[float, <built-in function callable>, None]) – Concentration outside the boundary
  • viscous_flag (bool) – Flag to compute the viscous term at the boundary
set_particles(delassus, volume, position, velocity, omega, contact=None)

Set location of the grains in the mesh and compute the porosity in each cell.

Parameters:
  • delassus (ndarray) – List of particles delassus operators
  • volume (ndarray) – List of particles volume
  • position (ndarray) – List of particles centre positions
  • velocity (ndarray) – List of particles velocity
  • omega (ndarray) – List of particles angular velocity
  • contact (Optional[ndarray]) – List of particles contact resultant forces
set_particles_body(xp, rp, density, velocity=None, omega=None, contact_forces=None, discretisation='overlap', use_voidage=True)
set_stability_flags(pspg=True, supg=True, lsic=True)

Set the stability flags into the Fluid Problem structure. One can enable/disable : the pspg, supg and lsic stabilisations.

set_strong_boundary(tag, pressure=None, velocity=None, velocity_x=None, velocity_y=None, velocity_z=None, solution=None)

Sets the strong boundaries (=constrains) for the fluid problem.

Parameters:
  • tag (str) – Physical tag (set in the mesh) of the boundary on which the constraint is added
  • pressure (Union[float, <built-in function callable>, None]) – value or callback assigned to the pressure field
  • velocity (Union[float, <built-in function callable>, None]) – value or callback assigned to the velocity field
  • velocity_x (Union[float, <built-in function callable>, None]) – value or callback assigned to the velocity_x field
  • velocity_y (Union[float, <built-in function callable>, None]) – value or callback assigned to the velocity_y field
  • velocity_z (Union[float, <built-in function callable>, None]) – value or callback assigned to the velocity_z field
  • solution (Union[float, <built-in function callable>, None]) – value or callback assigned to the solution field
set_symmetry_boundary(tag, pressure=None)

Sets the weak symmetry boundaries (=normal fluxes) for the fluid problem.

Parameters:
  • tag (Union[str, List[str]]) – Physical tag (or list of tags), set in the mesh file, of the symmetry boundaries
  • pressure (Union[float, <built-in function callable>, None]) – The pressure value if imposed (callback or number)
set_wall_boundary(tag, pressure=None, velocity=None, viscous_flag=None)

Sets the weak wall boundaries (=normal fluxes) for the fluid problem.

Parameters:
  • tag (Union[str, List[str]]) – Physical tag (or list of tags), set in the mesh, of the wall boundaries
  • pressure (Union[float, <built-in function callable>, None]) – The pressure value if imposed (callback or number)
  • velocity (Union[float, <built-in function callable>, None]) – The velocity value if imposed (callback or number)
  • viscous_flag (Optional[bool]) – Flag to compute the viscous term at the boundary
set_weak_boundary(tag, pressure=None, velocity=None, concentration=None, viscous_flag=None)

Sets the weak boundaries (=normal fluxes) for the fluid problem.

Parameters:
  • tag (Union[str, List[str]]) – Physical tag (or list of tags), set in the mesh, of the weak boundaries
  • pressure (Union[float, <built-in function callable>, None]) – The pressure value if imposed (callback or number)
  • velocity (Union[float, <built-in function callable>, None]) – The velocity value if imposed (callback or number)
  • concentration (Union[float, <built-in function callable>, None]) – Concentration outside the boundary
  • viscous_flag (Optional[bool]) – Flag to compute the viscous term at the boundary
set_weak_boundary_nodal_values(tag, values)

Set the nodal values to use for the weak boundary instead of using a callback or a prescribed value. Only available for p1p1 formulation.

Parameters:
  • tag (str) – Physical tag (or list of tags), set in the mesh
  • values (ndarray) – nodal values imposed on the boundary
Raises :
ValueError: if the tag is not found
solution()

Gives access to the fluid field value at each degree of freedom as a flat array.

Returns:fluid solution
Return type:np.ndarray
solution_at_coordinates(x)

Returns the solution vector interpolated at the given coordinates.

Parameters:x (ndarray) – coordinates
Returns:solution at given coordinates
Return type:np.ndarray
u_background()

Sets the background velocity field at each node.

Parameters:u – background velocity field
Return type:ndarray
u_solid()

Returns the solid velocity as a p1-continuous field.

Returns:solid velocity
Return type:np.ndarray
update_node_volume()

Update the nodes volume

velocity()

Reads the velocity solution.

Returns:velocity
Return type:np.ndarray
velocity_index()

Returns the index of the velocities into the solution vector as a bidimensionnal array.

Returns:velocities index array
Return type:np.ndarray
viscosity()

Reads the viscosity.

Returns:viscosity
Return type:np.ndarray
volume_flux(bnd_tag)

Computes the integral of the (outgoing) normal velocity through boundary with tag bnd_tag.

Returns:volume flux
Return type:float
write_mig(output_dir, t, fields=None, mesh_dtype=<class 'numpy.float64'>)

Writes the output files for post-visualization. Metadata are stored into a file called “fluid.migf” while the data are stored into the “fluid” directory. :type output_dir: str :param output_dir: Output directory :type t: float :param t: Computational time :param extra_fields: extra field as a dictionnary {name : values at p1 degree of freedom}

write_vtk(output_dir, it, t)

(DEPRECATED) Writes output file for post-visualization. :param output_dir: Output directory :param it: Computation iteration :param t: Computation time

migflow.fluid.removeprefix(str, prefix)
Return type:str