qtcad.device.poisson module
Non-linear Poisson solver.
- class qtcad.device.poisson.Solver(d, solver_params=None, geo_file=None)
Bases:
Solver
Finite element solver for the non-linear Poisson equation.
- Attributes:
d (device object) – The device for which to solve Poisson’s equation
- __init__(d, solver_params=None, geo_file=None)
Constructor of the solver class.
- Parameters:
d (device object) – Device for which Poisson’s equation must be solved.
solver_params – A SolverParams object containing the parameters of the non-linear Poisson solver.
geo_file (str, optional) – Path to file containing the geometry of the problem. Available formats are .geo_unrolled (recommended when using the built-in Gmsh geometry kernel) and .xao (recommended when using the OpenCASCADE Gmsh geometry kernel). If geo_file is None then Poisson’s equation is solved over the mesh saved in
d
, and the mesh is static. Ifgeo_file
is not None, adaptive meshing will be used.
- get_error_log()
Returns the maximum errors and their location for each self-consistent iteration.
- Returns:
ndarray – The maximum errors. ndarray: The location of the maximum errors. The row index corresponds to iterations, the column index to Cartesian coordinates
- solve(initialize=True)
Iterates the Poisson solver until a specified convergence criterion is achieved.
- Parameters:
initialize (bool) – Automatically initialize potential from qtcad.device properties or not. Default: True.
- Returns:
bool – Whether or not calculation converged
Note
Modifies self.d.phi, self.d.rho, and self.d.rho_prime.
- class qtcad.device.poisson.SolverParams(inp_dict=None)
Bases:
SolverParams
Parameters to pass to a non-linear Poisson solver.
- Attributes:
tol (float) – Tolerance to use in a self-consistent calculation. Default: 1e-5
maxiter (int) – Maximum number of iterations in a self-consistent loop. Default: 200.
method (str) – The method to use to solve the linear problem at each self-consistent iteration: “direct” or “iterative”. Default: “iterative”.
errortype (str) – Type of error to use in a convergence criterion. Relative (‘rel’ or ‘relative’) or absolute (‘abs’ or ‘absolute’). Default: ‘abs’.
output_interval (int) – Number of iterations between outputs in a self-consistent loop. Default: 1.
verbose (bool) – Verbosity level. Default: True.
initial_ref_factor (float between 0 and 1) – The maximal relative error threshold used at every adaptive iteration. Used only for adaptive Poisson solver. Default: 0.1.
final_ref_factor (float between 0 and 1) – Factor that relates to the ‘amount of mesh refinement’ that will occur once the solver saturates. The lower the number the more refined the output mesh will be. Used only for adaptive Poisson solver. Default: 0.75.
maxiter_adapt (int) – Maximal number of iterations permitted before the mesh is adapted. Used only for adaptive Poisson solver. Default: -1, indicating that there is no maximum.
meshing_algo (str) – Algorithm used for meshing. Choices are: ‘hxt’ and ‘delaunay’. The ‘delaunay’ algorithm is the default meshing technique used in Gmsh, and only uses one thread. The ‘hxt’ algorithm is a newer meshing technique in Gmsh, which supports multithreading. The ‘hxt’ algorithm is faster in most cases; however, it is only available in 3D, and may present stability issues on shared workstations (e.g., competition between threads when running several computations on the same node without a job scheduler may cause meshing to crash). In addition, while the ‘delaunay’ algorithm ignores mesh extrusions, the ‘hxt’ algorithm will refine extruded meshes in a structured way that does not lead to optimal meshes for the Poisson solver. Default: ‘delaunay’.
max_threads (int or None) – Maximum number of threads to use in the meshing algorithm. Only used when
meshing_algo
is set to ‘hxt’. Default: 1. If None, use all available threads.dot_region (list of strings and/or lists of tuples or list of 2 – tuples or single string): Regions where we would like to set the maximal value of the characteristic length. If None, no maximal characteristic length will not be set in any region. Used only for adaptive Poisson solver. Default: None.
h_dot (float or list of floats) – Maximal value of the characteristic length in each of the regions defined in dot_region. Used only for adaptive Poisson solver. Default: None.
max_nodes (int) – Maximal number of nodes permitted for an adaptive iteration to be performed. If the maximum is exceeded no aditional adaptive iterations will take place. Used only for adaptive Poisson solver. Default: 1e6.
min_nodes (int) – Minimal number of nodes allowed by the solver. If Poisson solver converges with less nodes, then the initial mesh will be uniformly refined and the adaptive procedure will restart. Used only for adaptive Poisson solver. Default: 1e5.
size_map_filename (string) – Path to .pos file containing size map of refined mesh. Used only for adaptive Poisson solver. Default:
"size_map.pos"
.refined_mesh_filename (string) – Path to the output file where the refined mesh is saved. This is used only for the adaptive Poisson solver. Default: None. If the default value is used, the mesh will not be saved.
h_max (float) – Maximal value of the characteristic length in the mesh. Default is None in which case no maximal value is enforced.
print_gmsh_output (bool, optional) – If True, print the outputs of gmsh. Default: False.
mesh_from_file (bool, optional) – If set to
"False"
, the solver will update the adaptive mesh internally without reading it from a file at each step. If set to"True"
, the solver will read the adaptive mesh from the file specified by the attribute refined_mesh_filename at each mesh update. Default:"False"
.
- __init__(inp_dict=None)
Constructor of the SolverParams class.
- Parameters:
inp_dict (dict, optional) – Dictionary specifying certain solver parameters to be used instead of their default values.