Called upon model initialisation. Will basically read from the options database and set options in the database that are appropriate.
63 type(model_state_type),
target,
intent(inout) :: current_state
65 petscerrorcode :: ierr
69 integer :: y_lengths(current_state%parallel%dim_sizes(Y_INDEX)), x_lengths(current_state%parallel%dim_sizes(X_INDEX))
70 integer new_communicator, my_transposed_rank, x_rank_val, y_rank_val
72 call apply_dimension_bounds(current_state%global_grid%size(y_index), current_state%parallel%dim_sizes(y_index), y_lengths)
73 call apply_dimension_bounds(current_state%global_grid%size(x_index), current_state%parallel%dim_sizes(x_index), x_lengths)
75 allocate(p_source(current_state%local_grid%size(z_index)-1, current_state%local_grid%size(y_index), &
76 current_state%local_grid%size(x_index)), prev_p(current_state%local_grid%size(z_index)-1, &
77 current_state%local_grid%size(y_index), current_state%local_grid%size(x_index)))
79 cx=current_state%global_grid%configuration%horizontal%cx
80 cy=current_state%global_grid%configuration%horizontal%cy
81 allocate(rdzn(current_state%local_grid%size(z_index)-1), rdz(current_state%local_grid%size(z_index)-1), &
82 rho(current_state%local_grid%size(z_index)-1), rhon(current_state%local_grid%size(z_index)-1), &
83 dz(current_state%local_grid%size(z_index)-1), dzn(current_state%local_grid%size(z_index)-1))
84 rdzn=current_state%global_grid%configuration%vertical%rdzn(2:)
85 rdz=current_state%global_grid%configuration%vertical%rdz(2:)
86 rho=current_state%global_grid%configuration%vertical%rho(2:)
87 rhon=current_state%global_grid%configuration%vertical%rhon(2:)
88 dz=current_state%global_grid%configuration%vertical%dz(2:)
89 dzn=current_state%global_grid%configuration%vertical%dzn(2:)
91 z_start=current_state%local_grid%halo_size(z_index)+2
92 z_end=current_state%local_grid%halo_size(z_index)+current_state%local_grid%size(z_index)
93 y_start=current_state%local_grid%halo_size(y_index)+1
94 y_end=current_state%local_grid%halo_size(y_index)+current_state%local_grid%size(y_index)
95 x_start=current_state%local_grid%halo_size(x_index)+1
96 x_end=current_state%local_grid%halo_size(x_index)+current_state%local_grid%size(x_index)
98 y_rank_val = current_state%parallel%my_rank / current_state%parallel%dim_sizes(x_index)
99 x_rank_val = mod(current_state%parallel%my_rank, current_state%parallel%dim_sizes(x_index))
100 my_transposed_rank = x_rank_val*current_state%parallel%dim_sizes(y_index) + y_rank_val
102 call mpi_comm_split(current_state%parallel%monc_communicator, 1, my_transposed_rank, new_communicator, ierr)
103 petsc_comm_world = new_communicator
105 call petscinitialize(petsc_null_character, ierr)
106 call kspcreate(petsc_comm_world, ksp, ierr)
107 call dmdacreate3d(petsc_comm_world, dm_boundary_none, dm_boundary_periodic, dm_boundary_periodic, dmda_stencil_star, &
108 current_state%global_grid%size(z_index)-1, current_state%global_grid%size(y_index), &
109 current_state%global_grid%size(x_index), 1, current_state%parallel%dim_sizes(y_index), &
110 current_state%parallel%dim_sizes(x_index), 1, 1, (/ current_state%global_grid%size(z_index)-1 /), &
111 y_lengths, x_lengths, da, ierr)
112 call kspsetdm(ksp, da, ierr)
113 call kspsetcomputerhs(ksp, compute_rhs, petsc_null_object, ierr)
114 call kspsetcomputeoperators(ksp, compute_matrix, petsc_null_object, ierr)
115 call kspsetcomputeinitialguess(ksp, compute_initial_guess, petsc_null_object, ierr)
116 call petscoptionssetvalue(
"-options_left",
"no", ierr)
117 if (trim(
options_get_string(current_state%options_database,
"solver_type")) .ne.
"auto")
then
118 call petscoptionssetvalue(
"-ksp_type", trim(
options_get_string(current_state%options_database,
"solver_type")), ierr)
120 if (trim(
options_get_string(current_state%options_database,
"preconditioner_type")) .ne.
"auto")
then
121 call petscoptionssetvalue(
"-pc_type", trim(
options_get_string(current_state%options_database,
"preconditioner_type")), ierr)
123 if (trim(
options_get_string(current_state%options_database,
"norm_type")) .ne.
"auto")
then
124 if (trim(
options_get_string(current_state%options_database,
"norm_type")) .eq.
"preconditioned" .or. &
125 trim(
options_get_string(current_state%options_database,
"norm_type")) .eq.
"unpreconditioned" .or. &
126 trim(
options_get_string(current_state%options_database,
"norm_type")) .eq.
"natural" .or. &
127 trim(
options_get_string(current_state%options_database,
"norm_type")) .eq.
"none")
then
128 call petscoptionssetvalue(
"-ksp_norm_type", trim(
options_get_string(current_state%options_database,
"norm_type")), ierr)
131 trim(
options_get_string(current_state%options_database,
"norm_type"))//
"' not recognised")
134 call petscoptionssetvalue(
"-ksp_rtol", conv_to_string(
options_get_real(current_state%options_database,
"tolerance")), ierr)
136 call petscoptionssetvalue(
"-ksp_max_it", &
137 conv_to_string(
options_get_integer(current_state%options_database,
"max_iterations")), ierr)
139 call kspsetfromoptions(ksp, ierr)
140 call kspsetinitialguessnonzero(ksp, petsc_true, ierr)
143 call kspmonitorset(ksp,ksp_monitor,petsc_null_object, petsc_null_function,ierr)
145 prev_p=0.0_default_precision
146 call init_halo_communication(current_state, get_single_field_per_halo_cell, halo_swap_state, 1, .false.)
147 call kspgettype(ksp, ksp_type, ierr)
148 call kspgetpc(ksp, pc_instance, ierr)
149 call pcgettype(pc_instance, pc_type, ierr)
150 call log_master_log(
log_info,
"PETSc iterative solver initialised, using "//trim(pc_type)//
" preconditioner with "//&
151 trim(ksp_type)//
" solver")