arnica.solvers_2d package¶
Solver 2D (Deprecated)¶
This package contains a solver of second partial derivative equations to treat heat conduction and heat radiation problem. The 2nd order finit difference scheme is used to solve the inside of a computational domain and that of first order for boundaries.
This development is now hosted in a separate repository at nitrox - calcifer
Submodules¶
arnica.solvers_2d.boundary module¶
Contains class and functions necessary to handle boundary conditions
-
class
arnica.solvers_2d.boundary.
Boundary2d
(boundary_param)¶ Bases:
object
Class containing Boundary Condition information
-
arnica.solvers_2d.boundary.
apply_bc
(lhs, rhs, metric, boundaries)¶ Give the altered version of LHS matrix and RHS vector to apply boundary conditions
lhs: left-hand side matrix (A in AX=B) rhs: right-hand side matrix (B in AX=B) metric: an instance of class Metrics2d containing gradient operators boundaries: dictionary with boundary data
lhs: modified left-hand side matrix rhs: modified right-hand side matrix
-
arnica.solvers_2d.boundary.
bc_dirichlet
(matrix_lhs, matrix_rhs, positions, grad_n_bc, target_value)¶ Function to enforce Dirichlet Boundary Condition in the Robin formalism:
a * (df / dn) + b * f + c = Otarget_value matrix_lhs : Left Hand Side square matrix (shape (size_i_w * size_j_ns)^2) matrix_rhs : Right Hand Side vector (shape (size_i_w * size_j_ns)) positions : indices of lines corresponding to the patch being processed
Altered left-hand side matrix and right-hand side vector
-
arnica.solvers_2d.boundary.
bc_neumann
(matrix_lhs, matrix_rhs, positions, grad_n_bc, target_gradient)¶ Function to enforce the Neumann Boundary Condition in the Robin formalism:
a * (df / dn) + b * f + c = Ograd_n_bc target_gradient matrix_lhs : Left Hand Side square matrix (shape (size_i_w * size_j_ns)^2) matrix_rhs : Right Hand Side vector (shape (size_i_w * size_j_ns)) positions : indices of lines corresponding to the patch being processed
Altered left-hand side matrix and right-hand side vector
-
arnica.solvers_2d.boundary.
bc_robin
(matrix_lhs, matrix_rhs, positions, grad_n_bc, a_val, b_val, c_val)¶ Function to enforce the Boundary Condition in the Robin formalism:
a * (df / dn) + b * f + c = Omatrix_lhs: Left Hand Side square matrix (shape (size_i_w * size_j_ns)^2) matrix_rhs: Right Hand Side vector (shape (size_i_w * size_j_ns)) positions: indices of lines corresponding to the patch being processed grad_n_bc: normal gradient to boundary nodes a_val: value of the “a” Robin parameter b_val: value of the “b” Robin parameter c_val: value of the “a” Robin parameter
Altered left-hand side matrix and right-hand side vector
-
arnica.solvers_2d.boundary.
bc_robin_csr
(matrix_lhs, matrix_rhs, positions, grad_n_bc, a_val, b_val, c_val)¶ Function to enforce the Boundary Condition in the Robin formalism:
a * (df / dn) + b * f + c = O- matrix_lhs: [CSR] Left Hand Side square matrix
- (shape (size_i_w * size_j_ns)^2)
- matrix_rhs: [ndarray] Right Hand Side vector
- (shape (size_i_w * size_j_ns))
positions: indices of lines corresponding to the patch being processed grad_n_bc: [CSR] normal gradient to boundary nodes a_val: value of the “a” Robin parameter b_val: value of the “b” Robin parameter c_val: value of the “a” Robin parameter
Altered left-hand side matrix and right-hand side vector
arnica.solvers_2d.conduction module¶
Module to test the heat transfer resolution on grids curvilinear 2D grids
-
arnica.solvers_2d.conduction.
build_heat_equation
(metric)¶ Create the LHS matrix corresponding to heat equation Parameters ———- metric : an instance of the class Metrics2d containing the gradient operators
LHS matrix RHS matrix
-
arnica.solvers_2d.conduction.
compute_constants
(params)¶ compute_constants parameters
params : dict of setup parameters
const : dict of constant parameters
-
arnica.solvers_2d.conduction.
example_params
()¶ Example input
-
arnica.solvers_2d.conduction.
main_2d_condution
(params)¶ Set up main 2D heat transfer resolution
params : dict of setup parameters
-
arnica.solvers_2d.conduction.
set_bc_heat_transfer
(bc_params)¶ Fill the generic bc_values from wall_temperature. (bc_dirichlet function is generic, we have to tell the solver that the value that we want to impose is the wall temperature here)
bc_params: dictionary of boundary parameters
bc_params: updated dictionary of boundary parameters
-
arnica.solvers_2d.conduction.
slope_function
(coor, min_val, max_val)¶ create a slope x test function, with analytically known derivatives
coor : numpy array (n,m) , coordinates min_val : minimum value max_val ; maximum value
slop : numpy array (n,m) , slope test function
arnica.solvers_2d.core_fd module¶
This module is contains the core of Finite Differences 2D solvers.
- The class metrics:
- Builds the jacobian to handle curvilinear meshes.
- Computes the gradients operators
- Computes the boundary-normal-gradient operator
-
class
arnica.solvers_2d.core_fd.
Metrics2d
(x_coor, y_coor, periodic_ns=False, periodic_we=False)¶ Bases:
object
Compute operators onto a curvilinear 2D mesh
-
check_compute_matrices
()¶ compute the matrix form of operators DO NOT REMOVE! –> USED FOR TESTING CSR GRADIENTS
-
diff_ns_2
(array_)¶ compute differentiation in direction west (j-direction)
-
diff_we_2
(array_)¶ compute differentiation in direction eta (i-direction)
-
-
arnica.solvers_2d.core_fd.
set_row_csr
(csr, row_idx, new_row)¶ Replace a row in a CSR sparse matrix A.
- csr: csr_matrix
- Matrix to change
- row_idx: int
- index of the row to be changed
- new_row: np.array
- list of new values for the row of A
None (the matrix A is changed in place)
The row index shall be smaller than the number of rows in A The number of elements in new row must be equal to the number of columns in matrix A
arnica.solvers_2d.radiation module¶
Module to test the p1 (radiation) solver for grey gas
-
arnica.solvers_2d.radiation.
adim_flux_test_case
(dim_data, params)¶ Non-dimensional conversion of heat fluxes
dim_data: dimensional data params: parameter dictionary
non dimensional data
-
arnica.solvers_2d.radiation.
analytical_temperature
(abs_coeff, radius, temp_1, temp_2)¶ Analytical temperature profile for P1. Book –> Radiative Heat Transfer (Modest, p. 479)
abs_coeff : absorption coefficient radius : radial coordinates temp_1 : temperature of inner cylinder temp_2 : temperature of outer cylinder
Analytical temperature field
-
arnica.solvers_2d.radiation.
analytical_test_case
(metric, params)¶ This functions returns fields corresponding to the 2 concentric cylinder with grey gas (Modest’s book, 2nd edition, p. 477)
metric: metric object params: dict of parameters
analytic_temperature: temperature field analytic_spectral_radiance: spectral radance compute from temperature absorption_field: absorption coefficient field
-
arnica.solvers_2d.radiation.
compute_robin_values_p1
(absorption_coeff, t_wall, emissivity=1)¶ Compute values of the Marshak boundary condition in the Robin formalism:
a * (df / dn) + b * f + c = Oabsorption_coeff: absorption coefficient field t_wall: temperature of the boundary wall emissivity: emissivity of the wall (1 if it is a black body)
a_value: pre-normal-derivative coefficient b_value: f-linear coefficient c_value: constant coefficient (does not depend on f)
-
arnica.solvers_2d.radiation.
dump_solution
(metric, incident_radiation_sol, s_r_sum, s_r_div, analytic_spectral_radiance, analytic_temperature, q_r_flux)¶ Dump generic postprocessing data
metric: metric object incident_radiation_sol: G field S_r_sum: radiative source term computed using method 1 (cf function) S_r_div: radiative source term computed using method 2 (cf function) analytic_spectral_radiance: Ib calculated from analytic_temperature analytic_temperature: initial temperature q_r_flux: radiative heat flux (x, y and normal)
None
-
arnica.solvers_2d.radiation.
dump_solution_test_case
(metric, q_r_flux, params)¶ Dump Analytical-test-case-related data.
metric: metric object q_r_flux: heat flux params: dict of parameters
None
-
arnica.solvers_2d.radiation.
filter_stupid_characters
(string)¶
-
arnica.solvers_2d.radiation.
get_heat_flux_inner
(x_coor, y_coor, q_n)¶
-
arnica.solvers_2d.radiation.
get_heat_fluxes
(absorption_coefficient, metric, g_solution)¶ Computes radiative heat fluxes
absorption_coefficient metric : Metrics object g_solution : solution of incident radiation
x and y heat fluxes
-
arnica.solvers_2d.radiation.
get_heat_source_term
(g_solution, absorption_coefficient, spectral_radiance)¶ Computes radiative heat source term
g_solution : solution of incident radiation absorption_coefficient: field of absorption coefficient spectral_radiance: field of spectral radiance
heat source term
-
arnica.solvers_2d.radiation.
get_p1_eq_field
(metric, absorption_coeff, spectral_radiance)¶ Create the LHS matrix corresponding to P1 equation
metric : an instance of the class Metrics2d containing the gradient operators absorption_coeff : absorption coefficient of shape (size_ns * size_we) spectral_radiance : field of spectral radiation (size_ns * size_we)
LHS matrix
-
arnica.solvers_2d.radiation.
get_p1_eq_field_csr
(metric, absorption_coeff, spectral_radiance)¶ Create the LHS matrix corresponding to P1 equation Book –> Radiative Heat Transfer (Modest, p. 479) Parameters ———- metric : an instance of the class Metrics containing the gradient operators absorption_coeff : absorption coefficient of shape (size_ns * size_we) spectral_radiance : field of spectral radiation (size_ns * size_we)
LHS matrix
-
arnica.solvers_2d.radiation.
get_source_term_div
(heat_fluxes, metric)¶ Compute the radiative in the conventional way by taking the divergence of the radiative heat flux vector
heat_fluxes: numpy arrays containing heat fluxes in x, y, and projected onto the boundaries metric: object containing information relative to metric (gradients, coordinates, etc.)
Returns source_term: radiative source term ——-
-
arnica.solvers_2d.radiation.
get_spectral_radiance
(temp)¶ Compute blackbody thermal radiation intensity Parameters ———- temp : temperature
blackbody thermal radiation intensity
-
arnica.solvers_2d.radiation.
main_p1_solver
(params)¶ Radiation solver (P1 Approximation)
params : dict of setup parameters
-
arnica.solvers_2d.radiation.
postproc_analytical_test_case
(metric, params, heat_fluxes)¶ This functions returns the non dimensional normal heat flux of the inner cylinder in the analytices test case (2 concentric cylinders with grey gas (Modest’s book, 2nd edition, p. 477))
Non-dimensional normal heat flux at the inner cylinder wall.
-
arnica.solvers_2d.radiation.
postproc_radiation
(metric, incident_radiation_sol, absorption_field, analytic_spectral_radiance)¶ Generic post proc for P1 solver
metric: object containing metrics (coord, gradients, etc.) incident_radiation_sol: G solution absorption_field: kappa field analytic_spectral_radiance: Ib for test case
Radiative heat fluxes and source terms
-
arnica.solvers_2d.radiation.
set_bc_p1
(bc_params, absorption_coeff)¶ Apply Marshak boundary conditions for the P1 solver from physical params
bc_params: dictionary of boundary parameters absorption_coeff: absorption coefficient field
bc_params: updated dictionary of boundary parameters
-
arnica.solvers_2d.radiation.
temperature_slope
(x_coor, y_coor, t_hot, t_cold, mesh_kind)¶ Compute initial temperature field as a temperature slope Parameters ———- x_coor: x coordinates y_coor: y coordinates t_hot: higher value of temperature t_cold: lower value of temperature mesh_kind: mesh kind (either ‘cyl’ or ‘rect’
temperature field (same shape that x_coor)