54#include "../base/base_uses.f90"
59 LOGICAL,
PRIVATE,
PARAMETER :: debug_this_module = .true.
60 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'cell_opt_utils'
82 CHARACTER(len=default_string_length),
INTENT(OUT) :: project_name
83 INTEGER,
INTENT(IN) :: id_run
85 CHARACTER(len=default_path_length) :: c_val, input_file_path, output_file_path
86 CHARACTER(len=default_string_length) :: label
87 INTEGER :: i, lp, unit_nr
93 NULLIFY (new_logger, logger, enum, keyword, section)
104 input_file_path = trim(project_name)
105 lp = len_trim(input_file_path)
106 i = logger%iter_info%iteration(logger%iter_info%n_rlevel)
107 input_file_path(lp + 1:len(input_file_path)) =
"-"//trim(label)//
"-"//adjustl(
cp_to_string(i))
108 lp = len_trim(input_file_path)
113 output_file_path = input_file_path(1:lp)//
".out"
114 IF (para_env%is_source())
THEN
115 CALL open_file(file_name=output_file_path, file_status=
"UNKNOWN", &
116 file_action=
"WRITE", file_position=
"APPEND", unit_number=unit_nr)
120 CALL cp_logger_create(new_logger, para_env=para_env, default_global_unit_nr=unit_nr, &
121 close_global_unit_on_dealloc=.false.)
123 IF (c_val /=
"")
THEN
124 CALL cp_logger_set(new_logger, local_filename=trim(c_val)//
"_localLog")
126 new_logger%iter_info%project_name = trim(c_val)
128 i_val=new_logger%iter_info%print_level)
145 CHARACTER(len=default_string_length),
INTENT(IN) :: project_name
146 INTEGER,
INTENT(IN) :: id_run
150 IF (para_env%is_source())
THEN
172 REAL(kind=
dp),
INTENT(OUT) :: pres_ext
173 REAL(kind=
dp),
DIMENSION(3, 3),
INTENT(OUT) :: mtrx
174 REAL(kind=
dp),
DIMENSION(3, 3),
INTENT(IN) :: rot
178 REAL(kind=
dp),
DIMENSION(3, 3) :: pres_ext_tens
179 REAL(kind=
dp),
DIMENSION(:),
POINTER :: pvals
183 pres_ext_tens = 0.0_dp
186 check = (
SIZE(pvals) == 1) .OR. (
SIZE(pvals) == 9)
188 cpabort(
"EXTERNAL_PRESSURE can have 1 or 9 components only!")
190 IF (
SIZE(pvals) == 9)
THEN
195 pres_ext_tens(j, i) = pvals(ind)
200 pres_ext_tens = matmul(transpose(rot), pres_ext_tens)
202 pres_ext = pres_ext + pres_ext_tens(i, i)
204 pres_ext = pres_ext/3.0_dp
206 pres_ext_tens(i, i) = pres_ext_tens(i, i) - pres_ext
212 IF (any(pres_ext_tens > 1.0e-5_dp))
THEN
213 mtrx = cell%deth*matmul(cell%h_inv, matmul(pres_ext_tens, transpose(cell%h_inv)))
232 SUBROUTINE get_dg_dh(gradient, av_ptens, pres_ext, cell, mtrx, keep_angles, &
233 keep_symmetry, pres_int, pres_constr, constraint_id)
235 REAL(kind=
dp),
DIMENSION(:),
POINTER :: gradient
236 REAL(kind=
dp),
DIMENSION(3, 3),
INTENT(IN) :: av_ptens
237 REAL(kind=
dp),
INTENT(IN) :: pres_ext
239 REAL(kind=
dp),
DIMENSION(3, 3),
INTENT(IN) :: mtrx
240 LOGICAL,
INTENT(IN),
OPTIONAL :: keep_angles, keep_symmetry
241 REAL(kind=
dp),
INTENT(OUT) :: pres_int, pres_constr
242 INTEGER,
INTENT(IN),
OPTIONAL :: constraint_id
244 INTEGER :: i, my_constraint_id
245 LOGICAL :: my_keep_angles, my_keep_symmetry
246 REAL(kind=
dp),
DIMENSION(3, 3) :: correction, pten_hinv_old, ptens
248 my_keep_angles = .false.
249 IF (
PRESENT(keep_angles)) my_keep_angles = keep_angles
250 my_keep_symmetry = .false.
251 IF (
PRESENT(keep_symmetry)) my_keep_symmetry = keep_symmetry
253 IF (
PRESENT(constraint_id))
THEN
254 my_constraint_id = constraint_id
266 pres_int = pres_int + ptens(i, i)
268 pres_int = pres_int/3.0_dp
270 SELECT CASE (my_constraint_id)
272 pres_constr = 0.5_dp*(ptens(2, 2) + ptens(3, 3))
274 pres_constr = 0.5_dp*(ptens(1, 1) + ptens(3, 3))
276 pres_constr = 0.5_dp*(ptens(1, 1) + ptens(2, 2))
278 pres_constr = ptens(3, 3)
280 pres_constr = ptens(2, 2)
282 pres_constr = ptens(1, 1)
284 pres_constr = (ptens(1, 1) + ptens(2, 2) + ptens(3, 3))/3.0_dp
287 ptens(1, 1) = av_ptens(1, 1) - pres_ext
288 ptens(2, 2) = av_ptens(2, 2) - pres_ext
289 ptens(3, 3) = av_ptens(3, 3) - pres_ext
291 pten_hinv_old = cell%deth*matmul(cell%h_inv, ptens)
292 correction = matmul(mtrx, cell%hmat)
294 gradient(1) = pten_hinv_old(1, 1) - correction(1, 1)
295 gradient(2) = pten_hinv_old(2, 1) - correction(2, 1)
296 gradient(3) = pten_hinv_old(2, 2) - correction(2, 2)
297 gradient(4) = pten_hinv_old(3, 1) - correction(3, 1)
298 gradient(5) = pten_hinv_old(3, 2) - correction(3, 2)
299 gradient(6) = pten_hinv_old(3, 3) - correction(3, 3)
318 REAL(kind=
dp),
DIMENSION(:),
POINTER :: gradient
320 LOGICAL,
INTENT(IN) :: keep_angles, keep_symmetry
321 INTEGER,
INTENT(IN) :: constraint_id
323 REAL(kind=
dp) :: a, a_length, ab_length, b_length, cosa, &
324 cosah, cosg, deriv_gamma, g,
gamma, &
325 norm, norm_b, norm_c, sina, sinah, sing
327 IF (keep_angles)
THEN
330 norm_b = dot_product(cell%hmat(:, 2), cell%hmat(:, 2))
331 norm = dot_product(cell%hmat(1:2, 2), gradient(2:3))
332 gradient(2:3) = cell%hmat(1:2, 2)/norm_b*norm
333 norm_c = dot_product(cell%hmat(:, 3), cell%hmat(:, 3))
334 norm = dot_product(cell%hmat(1:3, 3), gradient(4:6))
335 gradient(4:6) = cell%hmat(1:3, 3)/norm_c*norm
338 IF (cell%orthorhombic)
THEN
345 IF (keep_symmetry)
THEN
346 SELECT CASE (cell%symmetry_id)
352 SELECT CASE (cell%symmetry_id)
354 g = (gradient(1) + gradient(3) + gradient(6))/3.0_dp
361 SELECT CASE (cell%symmetry_id)
363 g = 0.5_dp*(gradient(1) + gradient(3))
367 g = 0.5_dp*(gradient(1) + gradient(6))
371 g = 0.5_dp*(gradient(3) + gradient(6))
382 g = 0.5_dp*(gradient(1) + 0.5_dp*(gradient(2) +
sqrt3*gradient(3)))
384 gradient(2) = 0.5_dp*g
385 gradient(3) =
sqrt3*gradient(2)
389 g = 0.5_dp*(gradient(1) - 0.5_dp*(gradient(2) -
sqrt3*gradient(3)))
391 gradient(2) = -0.5_dp*g
392 gradient(3) = -
sqrt3*gradient(2)
396 a = (
angle(cell%hmat(:, 3), cell%hmat(:, 2)) + &
397 angle(cell%hmat(:, 1), cell%hmat(:, 3)) + &
398 angle(cell%hmat(:, 1), cell%hmat(:, 2)))/3.0_dp
401 cosah = cos(0.5_dp*a)
402 sinah = sin(0.5_dp*a)
404 norm_c = sqrt(1.0_dp - norm*norm)
405 g = (gradient(1) + gradient(2)*cosa + gradient(3)*sina + &
406 gradient(4)*cosah*norm + gradient(5)*sinah*norm + gradient(6)*norm_c)/3.0_dp
410 gradient(4) = g*cosah*norm
411 gradient(5) = g*sinah*norm
412 gradient(6) = g*norm_c
418 a_length = sqrt(cell%hmat(1, 1)*cell%hmat(1, 1) + &
419 cell%hmat(2, 1)*cell%hmat(2, 1) + &
420 cell%hmat(3, 1)*cell%hmat(3, 1))
421 b_length = sqrt(cell%hmat(1, 2)*cell%hmat(1, 2) + &
422 cell%hmat(2, 2)*cell%hmat(2, 2) + &
423 cell%hmat(3, 2)*cell%hmat(3, 2))
424 ab_length = 0.5_dp*(a_length + b_length)
425 gamma =
angle(cell%hmat(:, 1), cell%hmat(:, 2))
429 g = 0.5_dp*(gradient(1) + cosg*gradient(2) + sing*gradient(3))
430 deriv_gamma = (gradient(3)*cosg - gradient(2)*sing)/b_length
432 gradient(2) = g*cosg - ab_length*sing*deriv_gamma
433 gradient(3) = g*sing + ab_length*cosg*deriv_gamma
441 SELECT CASE (constraint_id)
443 gradient(1:2) = 0.0_dp
446 gradient(2:3) = 0.0_dp
449 gradient(4:6) = 0.0_dp
451 gradient(1:5) = 0.0_dp
453 gradient(1:2) = 0.0_dp
454 gradient(4:6) = 0.0_dp
456 gradient(2:6) = 0.0_dp
471 REAL(kind=
dp),
INTENT(IN) :: vol
472 REAL(kind=
dp),
DIMENSION(:),
POINTER :: x
473 INTEGER,
INTENT(IN) :: idg
475 INTEGER :: i, j, my_idg
476 REAL(kind=
dp) :: ratio
477 REAL(kind=
dp),
DIMENSION(3, 3) :: hmat_tmp
479 cpassert((
SIZE(x) == idg + 6))
482 hmat_tmp(:, :) = 0.0_dp
486 hmat_tmp(j, i) = x(my_idg)
490 ratio = vol/abs(
det_3x3(hmat_tmp))
491 ratio = ratio**(1.0_dp/3.0_dp)
497 x(my_idg) = x(my_idg)*ratio
contains a functional that calculates the energy and its derivatives for the geometry optimizer
subroutine, public apply_cell_constraints(gradient, cell, keep_angles, keep_symmetry, constraint_id)
Apply cell constraints.
subroutine, public rescale_new_cell_volume(vol, x, idg)
Rescale x(idg+1:idg+6) according to vol.
subroutine, public get_dg_dh(gradient, av_ptens, pres_ext, cell, mtrx, keep_angles, keep_symmetry, pres_int, pres_constr, constraint_id)
Computes the derivatives for the cell.
subroutine, public read_external_press_tensor(geo_section, cell, pres_ext, mtrx, rot)
Reads the external pressure tensor.
subroutine, public gopt_new_logger_release(new_logger, root_section, para_env, project_name, id_run)
releases a new logger used for cell optimization algorithm
subroutine, public gopt_new_logger_create(new_logger, root_section, para_env, project_name, id_run)
creates a new logger used for cell optimization algorithm
Handles all functions related to the CELL.
integer, parameter, public cell_sym_monoclinic
integer, parameter, public cell_sym_triclinic
integer, parameter, public cell_sym_tetragonal_ab
integer, parameter, public cell_sym_rhombohedral
integer, parameter, public cell_sym_tetragonal_ac
integer, parameter, public cell_sym_hexagonal_gamma_60
integer, parameter, public cell_sym_orthorhombic
integer, parameter, public cell_sym_hexagonal_gamma_120
integer, parameter, public cell_sym_monoclinic_gamma_ab
integer, parameter, public cell_sym_cubic
integer, parameter, public cell_sym_tetragonal_bc
Utility routines to open and close files. Tracking of preconnections.
subroutine, public open_file(file_name, file_status, file_form, file_action, file_position, file_pad, unit_number, debug, skip_get_unit_number, file_access)
Opens the requested file using a free unit number.
subroutine, public close_file(unit_number, file_status, keep_preconnection)
Close an open file given by its logical unit number. Optionally, keep the file and unit preconnected.
various routines to log and control the output. The idea is that decisions about where to log should ...
recursive integer function, public cp_logger_get_default_unit_nr(logger, local, skip_not_ionode)
asks the default unit number of the given logger. try to use cp_logger_get_unit_nr
subroutine, public cp_logger_set(logger, local_filename, global_filename)
sets various attributes of the given logger
subroutine, public cp_logger_release(logger)
releases this logger
subroutine, public cp_logger_create(logger, para_env, print_level, default_global_unit_nr, default_local_unit_nr, global_filename, local_filename, close_global_unit_on_dealloc, iter_info, close_local_unit_on_dealloc, suffix, template_logger)
initializes a logger
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
Calculation of the incomplete Gamma function F_n(t) for multi-center integrals over Cartesian Gaussia...
Defines the basic variable types.
integer, parameter, public dp
integer, parameter, public default_string_length
integer, parameter, public default_path_length
Definition of mathematical constants and functions.
real(kind=dp), parameter, public sqrt3
Collection of simple mathematical functions and subroutines.
pure real(kind=dp) function, public angle(a, b)
Calculation of the angle between the vectors a and b. The angle is returned in radians.
Interface to the message passing library MPI.
Type defining parameters related to the simulation cell.
type of a logger, at the moment it contains just a print level starting at which level it should be l...
stores all the informations relevant to an mpi environment