UM2N.generator package

Submodules

UM2N.generator.burgers_solver module

class BurgersSolver(mesh, mesh_fine, mesh_new, idx, **kwargs)[source]

Bases: object

Solves the Burgers equation Input: - mesh: The mesh on which to solve the equation. - dist_params: The parameters of the Gaussian distribution.

project_u_()[source]
monitor_function(mesh)[source]
solve_problem(callback=None)[source]

Solves the Burgers equation.

get_error()[source]

UM2N.generator.equation_generator module

class RandHelmholtzEqGenerator(rand_u_generator)[source]

Bases: object

discretise(mesh)[source]
class HelmholtzEqGenerator(params={'u_exact_func': None})[source]

Bases: object

discretise(mesh)[source]
class RandPoissonEqGenerator(rand_u_generator)[source]

Bases: object

discretise(mesh)[source]
class PoissonEqGenerator(params={'u_exact_func': None})[source]

Bases: object

discretise(mesh)[source]

UM2N.generator.equation_solver module

class EquationSolver(params={'LHS': None, 'RHS': None, 'bc': None, 'function_space': None})[source]

Bases: object

solve_eq()[source]

Solves the Helmholtz equation

UM2N.generator.mesh_generator module

class MeshGenerator(params={'eq': None, 'mesh': None, 'num_grid_x': None, 'num_grid_y': None})[source]

Bases: object

Responsible for generating and moving a mesh based on a given Helmholtz

equation.

This method is based on Pyroteus/movement.

Attributes: - eq: The Helmholtz equation object. - num_grid_x: Number of grid points in the x-dimension. - num_grid_y: Number of grid points in the y-dimension. - mesh: The initial m esh.

move_mesh()[source]

Moves the mesh using the Monge-Ampere equation. Computes and stores the Jacobian and its determinant.

Returns: - The moved mesh

get_grad_phi()[source]

Returns the gradient of phi of the mesh movement.

get_phi()[source]

Returns the phi of the mesh movement.

get_monitor_val()[source]

Returns the monitor function value used for mesh movement.

get_jacobian()[source]

Returns the Jacobian of the mesh movement.

get_jacobian_det()[source]

Returns the determinant of the Jacobian of the mesh movement.

get_gradient(mesh)[source]
get_grad_norm(mesh)[source]
get_hessian(mesh)[source]

Computes and returns the Hessian of the Helmholtz equation on the given mesh.

Parameters: - mesh: The mesh on which to compute the Hessian.

Returns: - The Hessian as a projection in the function space.

get_hessian_norm(mesh)[source]
monitor_func(mesh)[source]

Computes the monitor function value based on the Hessian of the Helmholtz equation.

Parameters: - mesh: The mesh on which to compute the monitor function.

Returns: - The monitor function value.

UM2N.generator.rand_source_generator module

class RandSourceGenerator(use_iso=False, dist_params={'c_max': 0.8, 'c_min': 0.2, 'max_dist': 10, 'n_dist': None, 'sigma_eps': 0.125, 'sigma_mean_scaler': 0.25, 'sigma_sigma_scaler': 0.16666666666666666, 'w_max': 0.2, 'w_min': 0.05, 'x_end': 1, 'x_start': 0, 'y_end': 1, 'y_start': 0, 'z_max': 1, 'z_min': 0})[source]

Bases: object

Class for generating a random Helmholtz equation based on a Gaussian distribution.

Attributes:

simple_u (bool): Flag for using simpler form of u. dist_params (dict): Parameters for Gaussian distribution. u_exact: Analytical Helmholtz equation solution. f: Simulated source function. function_space: Function space for problem. LHS: Left-hand side of Helmholtz equation. RHS: Right-hand side of Helmholtz equation. bc: Dirichlet boundary condition.

set_dist_params(eps=0.05)[source]

Set parameters for Gaussian distribution from dist_params.

get_dist_params()[source]

Return dictionary containing distribution parameters.

Returns:

dict: Dictionary of distribution parameters.

get_u_exact(params={'V': None, 'u': None, 'v': None, 'x': None, 'y': None})[source]

Return analytical solution field. Returns:

firedrake.Function: Analytical solution.

UM2N.generator.swirl_demo module

get_c(x, y, t, threshold=0.5)[source]

Compute the velocity field which transports the solution field u.

Return:

velocity (ufl.tensors): expression of the swirl velocity field

get_u_0(x, y, r_0=0.2, x_0=0.25, y_0=0.25, sigma=0.016666666666666666)[source]

Compute the initial trace value.

Return:

u_0 (ufl.tensors): expression of u_0

UM2N.generator.swirl_solver module

get_log_og(log_path, idx)[source]

Read log file from dataset log dir and return value in it

get_c(x, y, t, threshold=0.5, alpha=1.5)[source]

Compute the velocity field which transports the solution field u. Args:

alpha (float): coefficient for velocity magnitude.

Return:

velocity (ufl.tensors): expression of the swirl velocity field

get_u_0(x, y, r_0=0.2, x_0=0.5, y_0=0.75, sigma=0.016666666666666666)[source]

Compute the initial trace value.

Return:

u_0 (ufl.tensors): expression of u_0

class SwirlSolver(mesh, mesh_fine, mesh_new, mesh_model, **kwargs)[source]

Bases: object

Solver for advection swirl problem:
  1. Solver implementation for the swirl problem

  2. Mesh mover for the swirl problem

  3. Error & Time evaluation

solve_u(t)[source]

Solve the PDE problem using RK (SSPRK) scheme on the coarse mesh store the solution field to a varaible: self.u_cur

solve_u_fine(t)[source]

Solve the PDE problem using RK (SSPRK) scheme on the fine mesh store the solution field to a varaible: self.u_cur_fine

project_u_()[source]
project_from_prev_u_coarse()[source]
project_from_prev_u_adapt()[source]
project_from_prev_u_model()[source]
monitor_function(mesh, alpha=10, beta=5)[source]
monitor_function_on_coarse_mesh(mesh, alpha=10, beta=5)[source]
solve_problem(callback=None, fail_callback=None)[source]
eval_problem(model, ds_root, eval_dir, model_name='model', callback=None, fail_callback=None, device='cuda')[source]
make_all_dirs(log_path, plot_path, plot_more_path, plot_data_path)[source]
make_log_dir(log_path)[source]
make_plot_dir(plot_path)[source]
make_plot_more_dir(plot_more_path)[source]
make_plot_data_dir(plot_data_path)[source]

UM2N.generator.swirl_solver_step module

get_c(x, y, t, threshold=0.5, alpha=1.5)[source]

Compute the velocity field which transports the solution field u. Args:

alpha (float): coefficient for velocity magnitude.

Return:

velocity (ufl.tensors): expression of the swirl velocity field

get_u_0(x, y, r_0=0.2, x_0=0.5, y_0=0.75, sigma=0.016666666666666666)[source]

Compute the initial trace value.

Return:

u_0 (ufl.tensors): expression of u_0

class SwirlSolver(mesh, mesh_fine, mesh_new, **kwargs)[source]

Bases: object

Solver for advection swirl problem:
  1. Solver implementation for the swirl problem

  2. Mesh mover for the swirl problem

  3. Error & Time evaluation

solve_u(t)[source]

Solve the PDE problem using RK (SSPRK) scheme on the coarse mesh store the solution field to a varaible: self.u_cur

solve_u_fine(t)[source]

Solve the PDE problem using RK (SSPRK) scheme on the fine mesh store the solution field to a varaible: self.u_cur_fine

project_u_()[source]
monitor_function_pure_hessian(mesh, beta=5)[source]
monitor_function_smoothed_hessian(mesh, beta=5)[source]
monitor_function_grad(mesh, alpha=5)[source]
monitor_function_smoothed_grad(mesh, alpha=5)[source]
monitor_function_for_merge(mesh, alpha=10, beta=5)[source]
monitor_function(mesh, alpha=10, beta=5)[source]
monitor_function_on_coarse_mesh(mesh, alpha=10, beta=5)[source]
solve_problem(callback=None, fail_callback=None)[source]
get_error_currstep()[source]
get_error()[source]
plot_fine_solution(index)[source]
plot_res()[source]

UM2N.generator.unstructured_mesh module

Module for handling generating unstructured meshes.

class UnstructuredMeshGenerator(scale=1.0, mesh_type=2)[source]

Bases: ABC

Base class for mesh generators.

abstract property corners

Property defining the coordinates of the corner vertices of the domain to be meshed.

Returns:

coordinates of the corner vertices of the domain

Return type:

tuple

generate_mesh(res=0.1, output_filename='./temp.msh', remove_file=False)[source]

Generate a mesh at a given resolution level.

Parameters:
  • res (float) – mesh resolution (element diameter) (default: 0.1, suitable for mesh with scale 1.0)

  • output_filename (str) – filename for saving the mesh, including the path and .msh extension (default: ‘./temp.msh’)

  • remove_file (bool) – should the .msh file be removed after generation? (default: False)

Returns:

mesh generated

Return type:

firedrake.mesh.MeshGeometry

load_mesh(filename)[source]

Load a mesh from a file saved in .msh format.

Parameters:

filename (str) – filename including path and the .msh extension

Returns:

mesh loaded from file

Return type:

firedrake.mesh.MeshGeometry

class UnstructuredSquareMeshGenerator(scale=1.0, mesh_type=2)[source]

Bases: UnstructuredMeshGenerator

Generate an unstructured mesh of a 2D square domain using Gmsh.

property corners

Property defining the coordinates of the corner vertices of the domain to be meshed.

Returns:

coordinates of the corner vertices of the domain

Return type:

tuple

class UnstructuredRandomPolygonalMeshGenerator(scale=1.0, mesh_type=2)[source]

Bases: UnstructuredMeshGenerator

Create a random polygonal mesh by spliting the edge of a square randomly.

static sample_uniform(mean, interval)[source]

Sample a point from a uniform distribution with a given mean and interval.

Note that the interval is either side of the mean, not the overall interval, i.e., overall interval is symmetric: [mean - interval, mean + interval].

Parameters:
  • mean (float) – the mean value of the uniform distribution

  • interval (float) – the interval either side of the mean

Returns:

sampled point

Return type:

float

property corners

Property defining the coordinates of the corner vertices of the domain to be meshed.

Returns:

coordinates of the corner vertices of the domain

Return type:

tuple

Module contents