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.

Initialise the solver. kwargs: - nu: The viscosity of the fluid. - dt: The time interval.

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

Solves the Burgers equation.

UM2N.generator.equation_generator module

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

Bases: object

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

Bases: object

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

Bases: object

discretise(mesh)[source]
class RandPoissonEqGenerator(rand_u_generator)[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.

get_grad_norm(mesh)[source]
get_grad_phi()[source]

Returns the gradient of phi of the mesh movement.

get_gradient(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]
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_monitor_val()[source]

Returns the monitor function value used for mesh movement.

get_phi()[source]

Returns the phi of the mesh movement.

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.

move_mesh()[source]

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

Returns: - The moved mesh

UM2N.generator.polymesh module

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

Bases: object

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

get_boundaries()[source]
get_curve()[source]
get_line()[source]
get_mesh(res=0.1, file_path='./temp.msh')[source]
get_plane()[source]
get_points()[source]
get_rand(mean, interval)[source]
get_rand_points()[source]
show(file_path)[source]

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.

Initialize RandomHelmholtzGenerator.

Parameters:
simple_u (bool): Use simpler form of u (isotripic dataset) if True.

Default False.

dist_params (dict): Parameters for Gaussian distribution.

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.

set_dist_params(eps=0.05)[source]

Set parameters for Gaussian distribution from dist_params.

UM2N.generator.squaremesh module

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

Bases: object

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

get_boundaries()[source]
get_corner_points()[source]
get_curve()[source]
get_line()[source]
get_mesh(res=0.1, file_path='./temp.msh')[source]
get_plane()[source]
get_points()[source]
load_mesh(file_path)[source]
show(file_path)[source]

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

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

Init the problem:
  1. define problem on fine mesh and coarse mesh

  2. init function space on fine & coarse mesh

  3. define hessian solver on coarse mesh

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_data_dir(plot_data_path)[source]
make_plot_dir(plot_path)[source]
make_plot_more_dir(plot_more_path)[source]
monitor_function(mesh, alpha=10, beta=5)[source]
monitor_function_on_coarse_mesh(mesh, alpha=10, beta=5)[source]
project_from_prev_u_adapt()[source]
project_from_prev_u_coarse()[source]
project_from_prev_u_model()[source]
project_u_()[source]
solve_problem(callback=None, fail_callback=None)[source]
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

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_log_og(log_path, idx)[source]

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

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

UM2N.generator.swirl_solver_step module

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

Init the problem:
  1. define problem on fine mesh and coarse mesh

  2. init function space on fine & coarse mesh

  3. define hessian solver on coarse mesh

get_error()[source]
get_error_currstep()[source]
monitor_function(mesh, alpha=10, beta=5)[source]
monitor_function_for_merge(mesh, alpha=10, beta=5)[source]
monitor_function_grad(mesh, alpha=5)[source]
monitor_function_on_coarse_mesh(mesh, alpha=10, beta=5)[source]
monitor_function_pure_hessian(mesh, beta=5)[source]
monitor_function_smoothed_grad(mesh, alpha=5)[source]
monitor_function_smoothed_hessian(mesh, beta=5)[source]
plot_fine_solution(index)[source]
plot_res()[source]
project_u_()[source]
solve_problem(callback=None, fail_callback=None)[source]
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

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

Module contents