39#include "./base/base_uses.f90"
44 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'optimize_basis_utils'
64 CHARACTER(LEN=default_path_length) :: main_dir
65 INTEGER :: iset, iweight, nrep
67 powell_section, train_section
74 CALL section_vals_val_get(optbas_section,
"BASIS_TEMPLATE_FILE", c_val=opt_bas%template_basis_file)
78 opt_bas%work_basis_file = trim(adjustl(main_dir))//
"/"//trim(adjustl(opt_bas%work_basis_file))
81 CALL section_vals_val_get(optbas_section,
"USE_CONDITION_NUMBER", l_val=opt_bas%use_condition_number)
83 CALL generate_initial_basis(kind_section, opt_bas, para_env)
86 IF (opt_bas%ntraining_sets == 0)
THEN
87 cpabort(
"No training set was specified in the Input")
90 ALLOCATE (opt_bas%training_input(opt_bas%ntraining_sets))
91 ALLOCATE (opt_bas%training_dir(opt_bas%ntraining_sets))
92 DO iset = 1, opt_bas%ntraining_sets
95 CALL section_vals_val_get(train_section,
"INPUT_FILE_NAME", c_val=opt_bas%training_input(iset), &
99 CALL init_powell_var(opt_bas%powell_param, powell_section)
100 opt_bas%powell_param%nvar =
SIZE(opt_bas%x_opt)
102 CALL generate_derived_basis_sets(opt_bas, para_env)
104 CALL generate_basis_combinations(opt_bas, optbas_section)
107 ALLOCATE (opt_bas%fval_weight(0:opt_bas%ncombinations))
108 opt_bas%fval_weight = 1.0_dp
110 CALL section_vals_val_get(optbas_section,
"RESIDUUM_WEIGHT", r_val=opt_bas%fval_weight(iweight - 1), &
115 ALLOCATE (opt_bas%condition_weight(0:opt_bas%ncombinations))
116 opt_bas%condition_weight = 1.0_dp
118 CALL section_vals_val_get(optbas_section,
"CONDITION_WEIGHT", r_val=opt_bas%condition_weight(iweight - 1), &
122 CALL generate_computation_groups(opt_bas, optbas_section, para_env)
124 CALL print_opt_info(opt_bas)
132 SUBROUTINE print_opt_info(opt_bas)
135 INTEGER :: icomb, ikind, unit_nr
140 IF (logger%para_env%is_source())
THEN
144 IF (unit_nr > 0)
THEN
145 WRITE (unit_nr,
'(1X,A,A)')
"BASOPT| Total number of calculations ", &
146 trim(
cp_to_string(opt_bas%ncombinations*opt_bas%ntraining_sets))
147 WRITE (unit_nr,
'(A)')
""
148 DO icomb = 1, opt_bas%ncombinations
149 WRITE (unit_nr,
'(1X,A,A)')
"BASOPT| Content of basis combination ", trim(
cp_to_string(icomb))
150 DO ikind = 1, opt_bas%nkind
151 WRITE (unit_nr,
'(1X,A,A4,4X,A,3X,A)')
"BASOPT| Element: ", trim(opt_bas%kind_basis(ikind)%element), &
152 "Basis set: ", trim(opt_bas%kind_basis(ikind)%flex_basis(opt_bas%combination(icomb, ikind))%basis_name)
154 WRITE (unit_nr,
'(A)')
""
157 END SUBROUTINE print_opt_info
166 SUBROUTINE generate_basis_combinations(opt_bas, optbas_section)
170 INTEGER :: i, ikind, j, n_rep
171 INTEGER,
DIMENSION(:),
POINTER :: i_vals, tmp_i, tmp_i2
172 LOGICAL :: explicit, raise
176 CALL section_vals_val_get(optbas_section,
"BASIS_COMBINATIONS", explicit=explicit, n_rep_val=n_rep)
177 IF (.NOT. explicit)
THEN
178 opt_bas%ncombinations = 1
179 ALLOCATE (tmp_i(opt_bas%nkind))
180 ALLOCATE (tmp_i2(opt_bas%nkind))
181 DO ikind = 1, opt_bas%nkind
182 opt_bas%ncombinations = opt_bas%ncombinations*
SIZE(opt_bas%kind_basis(ikind)%flex_basis)
183 tmp_i(ikind) = opt_bas%kind_basis(ikind)%nbasis_deriv
185 ALLOCATE (opt_bas%combination(opt_bas%ncombinations, opt_bas%nkind))
187 DO i = 1, opt_bas%ncombinations
188 DO j = 1, opt_bas%nkind
189 opt_bas%combination(i, j) = tmp_i2(j)
191 tmp_i2(opt_bas%nkind) = tmp_i2(opt_bas%nkind) + 1
193 DO j = opt_bas%nkind, 1, -1
194 IF (raise) tmp_i2(j) = tmp_i2(j) + 1
195 IF (tmp_i2(j) > tmp_i(j))
THEN
204 opt_bas%ncombinations = n_rep
205 ALLOCATE (opt_bas%combination(opt_bas%ncombinations, opt_bas%nkind))
208 opt_bas%combination(i, :) = i_vals(:)
212 END SUBROUTINE generate_basis_combinations
228 INTEGER :: set_id, bas_id
230 INTEGER :: ncom, nset
232 ncom = opt_bas%ncombinations
233 nset = opt_bas%ntraining_sets
235 set_id = (calc_id)/ncom + 1
236 bas_id = mod(calc_id, ncom) + 1
249 SUBROUTINE generate_computation_groups(opt_bas, optbas_section, para_env)
254 INTEGER :: iadd1, iadd2, icount, igroup, isize, j, &
256 INTEGER,
DIMENSION(:),
POINTER :: i_vals
259 nproc = para_env%num_pe
260 ncalc = opt_bas%ncombinations*opt_bas%ntraining_sets
264 IF (.NOT. explicit)
THEN
265 IF (nproc >= ncalc)
THEN
267 iadd2 = mod(nproc, ncalc)
268 ALLOCATE (opt_bas%comp_group(ncalc))
269 ALLOCATE (opt_bas%group_partition(0:ncalc - 1))
270 DO igroup = 0, ncalc - 1
271 ALLOCATE (opt_bas%comp_group(igroup + 1)%member_list(1))
272 opt_bas%comp_group(igroup + 1)%member_list(1) = igroup
273 opt_bas%group_partition(igroup) = iadd1
274 IF (igroup < iadd2) opt_bas%group_partition(igroup) = opt_bas%group_partition(igroup) + 1
278 iadd2 = mod(ncalc, nproc)
279 ALLOCATE (opt_bas%comp_group(nproc))
280 ALLOCATE (opt_bas%group_partition(0:nproc - 1))
282 DO igroup = 0, nproc - 1
283 opt_bas%group_partition(igroup) = 1
285 IF (igroup < iadd2) isize = isize + 1
286 ALLOCATE (opt_bas%comp_group(igroup + 1)%member_list(isize))
288 opt_bas%comp_group(igroup + 1)%member_list(j) = icount
299 IF (nptot /= nproc)
THEN
300 CALL cp_abort(__location__, &
301 "Number of processors in group distribution does not match number of MPI tasks."// &
302 " Please change input.")
304 IF (.NOT. isize <= ncalc)
THEN
305 CALL cp_abort(__location__, &
306 "Number of Groups larger than number of calculations"// &
307 " Please change input.")
309 cpassert(nptot == nproc)
310 ALLOCATE (opt_bas%comp_group(isize))
311 ALLOCATE (opt_bas%group_partition(0:isize - 1))
312 IF (isize < ncalc)
THEN
314 iadd2 = mod(ncalc, isize)
316 DO igroup = 0, isize - 1
317 opt_bas%group_partition(igroup) = i_vals(igroup + 1)
319 IF (igroup < iadd2) isize = isize + 1
320 ALLOCATE (opt_bas%comp_group(igroup + 1)%member_list(isize))
322 opt_bas%comp_group(igroup + 1)%member_list(j) = icount
327 DO igroup = 0, isize - 1
328 opt_bas%group_partition(igroup) = i_vals(igroup + 1)
329 ALLOCATE (opt_bas%comp_group(igroup + 1)%member_list(1))
330 opt_bas%comp_group(igroup + 1)%member_list(1) = igroup
335 END SUBROUTINE generate_computation_groups
349 CHARACTER(LEN=default_path_length) :: output_file
352 INTEGER :: ibasis, ikind, unit_nr
354 DO ikind = 1, opt_bas%nkind
355 DO ibasis = 1, opt_bas%kind_basis(ikind)%nbasis_deriv
356 CALL update_used_parts(opt_bas%kind_basis(ikind)%deriv_info(ibasis), &
357 opt_bas%kind_basis(ikind)%flex_basis(0), &
358 opt_bas%kind_basis(ikind)%flex_basis(ibasis))
363 IF (para_env%is_source())
THEN
364 CALL open_file(file_name=output_file, file_status=
"UNKNOWN", &
365 file_action=
"WRITE", unit_number=unit_nr)
369 DO ikind = 1, opt_bas%nkind
370 DO ibasis = 0, opt_bas%kind_basis(ikind)%nbasis_deriv
371 CALL write_basis(opt_bas%kind_basis(ikind)%flex_basis(ibasis), opt_bas%kind_basis(ikind)%element, &
375 IF (para_env%is_source())
CALL close_file(unit_number=unit_nr)
388 SUBROUTINE update_used_parts(info_new, basis, basis_new)
392 INTEGER :: icont, iset, jcont, jset
395 DO iset = 1, basis%nsets
396 IF (info_new%in_use_set(iset))
THEN
398 basis_new%subset(jset)%exps(:) = basis%subset(iset)%exps
400 DO icont = 1, basis%subset(iset)%ncon_tot
401 IF (info_new%use_contr(iset)%in_use(icont))
THEN
403 basis_new%subset(jset)%coeff(:, jcont) = basis%subset(iset)%coeff(:, icont)
409 END SUBROUTINE update_used_parts
418 SUBROUTINE generate_derived_basis_sets(opt_bas, para_env)
422 INTEGER :: ibasis, ikind, iref, jbasis, unit_nr
424 DO ikind = 1, opt_bas%nkind
425 CALL init_deriv_info_ref(opt_bas%kind_basis(ikind)%deriv_info(0), opt_bas%kind_basis(ikind)%flex_basis(0))
426 opt_bas%kind_basis(ikind)%deriv_info(0)%basis_name = trim(adjustl(opt_bas%kind_basis(ikind)%basis_name))
428 DO ibasis = 1, opt_bas%kind_basis(ikind)%nbasis_deriv
429 iref = opt_bas%kind_basis(ikind)%deriv_info(ibasis)%reference_set
430 DO jbasis = 0, opt_bas%kind_basis(ikind)%nbasis_deriv
431 IF (iref == jbasis)
CALL setup_used_parts_init_basis(opt_bas%kind_basis(ikind)%deriv_info(ibasis), &
432 opt_bas%kind_basis(ikind)%deriv_info(iref), &
433 opt_bas%kind_basis(ikind)%flex_basis(0), &
434 opt_bas%kind_basis(ikind)%flex_basis(ibasis))
439 IF (para_env%is_source())
THEN
440 CALL open_file(file_name=opt_bas%work_basis_file, file_status=
"UNKNOWN", &
441 file_action=
"WRITE", unit_number=unit_nr)
445 DO ikind = 1, opt_bas%nkind
446 DO ibasis = 0, opt_bas%kind_basis(ikind)%nbasis_deriv
447 IF (len_trim(opt_bas%kind_basis(ikind)%deriv_info(ibasis)%basis_name) > 0)
THEN
448 opt_bas%kind_basis(ikind)%flex_basis(ibasis)%basis_name = &
449 trim(adjustl(opt_bas%kind_basis(ikind)%deriv_info(ibasis)%basis_name))
451 opt_bas%kind_basis(ikind)%flex_basis(ibasis)%basis_name = &
452 trim(adjustl(opt_bas%kind_basis(ikind)%basis_name))//
"-DERIVED_SET-"//adjustl(
cp_to_string(ibasis))
454 CALL write_basis(opt_bas%kind_basis(ikind)%flex_basis(ibasis), opt_bas%kind_basis(ikind)%element, &
458 IF (para_env%is_source())
CALL close_file(unit_number=unit_nr)
460 END SUBROUTINE generate_derived_basis_sets
470 SUBROUTINE write_basis(basis, element, unit_nr)
472 CHARACTER(LEN=default_string_length) :: element
475 INTEGER :: iexp, iset
477 IF (unit_nr > 0)
THEN
478 WRITE (unit=unit_nr, fmt=
"(A)") trim(adjustl(element))//
" "//trim(adjustl(basis%basis_name))
479 WRITE (unit=unit_nr, fmt=
"(1X,I0)") basis%nsets
480 DO iset = 1, basis%nsets
481 WRITE (unit=unit_nr, fmt=
"(30(1X,I0))") basis%subset(iset)%n, basis%subset(iset)%lmin, basis%subset(iset)%lmax, &
482 basis%subset(iset)%nexp, basis%subset(iset)%l
483 DO iexp = 1, basis%subset(iset)%nexp
484 WRITE (unit=unit_nr, fmt=
"(T2,F24.14,30(1X,ES24.14))") &
485 basis%subset(iset)%exps(iexp), basis%subset(iset)%coeff(iexp, :)
490 END SUBROUTINE write_basis
502 SUBROUTINE setup_used_parts_init_basis(info_new, info_ref, basis, basis_new)
506 INTEGER :: i, jset, lind, nsets
510 ALLOCATE (info_new%in_use_set(
SIZE(info_ref%in_use_set)))
511 info_new%in_use_set(:) = info_ref%in_use_set
512 ALLOCATE (info_new%use_contr(
SIZE(info_ref%in_use_set)))
513 DO i = 1,
SIZE(info_ref%in_use_set)
514 ALLOCATE (info_new%use_contr(i)%in_use(
SIZE(info_ref%use_contr(i)%in_use)))
515 info_new%use_contr(i)%in_use(:) = info_ref%use_contr(i)%in_use
517 DO i = 1, info_new%nsets
518 info_new%in_use_set(info_new%remove_set(i)) = .false.
520 DO i = 1, info_new%ncontr
521 lind = convert_l_contr_to_entry(basis%subset(info_new%remove_contr(i, 1))%lmin, &
522 basis%subset(info_new%remove_contr(i, 1))%l, &
523 info_new%remove_contr(i, 3), info_new%remove_contr(i, 2))
525 info_new%use_contr(info_new%remove_contr(i, 1))%in_use(lind) = .false.
529 DO i = 1, basis%nsets
530 IF (info_new%in_use_set(i)) nsets = nsets + 1
532 basis_new%nsets = nsets
533 ALLOCATE (basis_new%subset(nsets))
535 DO i = 1, basis%nsets
536 IF (info_new%in_use_set(i))
THEN
538 CALL create_new_subset(basis%subset(i), basis_new%subset(jset), info_new%use_contr(jset)%in_use)
542 END SUBROUTINE setup_used_parts_init_basis
552 SUBROUTINE create_new_subset(subset, subset_new, in_use)
554 LOGICAL,
DIMENSION(:) :: in_use
556 INTEGER :: icon, iind, il
557 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: tmp_l
559 ALLOCATE (tmp_l(
SIZE(subset%l)))
561 subset_new%lmin = subset%lmin
562 subset_new%lmax = subset%lmin - 1
563 subset_new%nexp = subset%nexp
564 subset_new%n = subset%n
565 DO il = 1,
SIZE(subset%l)
566 DO icon = 1, subset%l(il)
567 iind = convert_l_contr_to_entry(subset%lmin, subset%l, icon, subset%lmin + il - 1)
568 IF (.NOT. in_use(iind)) tmp_l(il) = tmp_l(il) - 1
570 IF (tmp_l(il) > 0) subset_new%lmax = subset_new%lmax + 1
572 subset_new%nl = subset_new%lmax - subset_new%lmin + 1
573 subset_new%ncon_tot = sum(tmp_l)
574 ALLOCATE (subset_new%l(subset_new%nl))
575 ALLOCATE (subset_new%coeff(subset_new%nexp, subset_new%ncon_tot))
576 ALLOCATE (subset_new%exps(subset_new%nexp))
577 subset_new%exps(:) = subset%exps
578 DO il = 1,
SIZE(subset%l)
579 IF (tmp_l(il) == 0)
EXIT
580 subset_new%l(il) = tmp_l(il)
584 DO icon = 1, subset%ncon_tot
585 IF (in_use(icon))
THEN
587 subset_new%coeff(:, iind) = subset%coeff(:, icon)
591 END SUBROUTINE create_new_subset
600 SUBROUTINE init_deriv_info_ref(info, basis)
606 ALLOCATE (info%in_use_set(basis%nsets))
607 info%in_use_set = .true.
608 ALLOCATE (info%use_contr(basis%nsets))
609 DO i = 1, basis%nsets
610 ALLOCATE (info%use_contr(i)%in_use(basis%subset(i)%ncon_tot))
611 info%use_contr(i)%in_use = .true.
614 END SUBROUTINE init_deriv_info_ref
625 SUBROUTINE generate_initial_basis(kind_section, opt_bas, para_env)
630 INTEGER :: ikind, variable_counter
635 ALLOCATE (opt_bas%kind_basis(opt_bas%nkind))
639 DO ikind = 1, opt_bas%nkind
640 CALL section_vals_val_get(kind_section,
"_SECTION_PARAMETERS_", c_val=opt_bas%kind_basis(ikind)%element, &
642 CALL section_vals_val_get(kind_section,
"BASIS_SET", c_val=opt_bas%kind_basis(ikind)%basis_name, &
646 CALL section_vals_get(set_section, n_repetition=opt_bas%kind_basis(ikind)%nbasis_deriv, explicit=explicit)
647 IF (.NOT. explicit) opt_bas%kind_basis(ikind)%nbasis_deriv = 0
648 ALLOCATE (opt_bas%kind_basis(ikind)%flex_basis(0:opt_bas%kind_basis(ikind)%nbasis_deriv))
649 ALLOCATE (opt_bas%kind_basis(ikind)%deriv_info(0:opt_bas%kind_basis(ikind)%nbasis_deriv))
651 CALL fill_basis_template(kind_section, opt_bas%kind_basis(ikind)%flex_basis(0), opt_bas%template_basis_file, &
652 opt_bas%kind_basis(ikind)%element, opt_bas%kind_basis(ikind)%basis_name, para_env, ikind)
654 CALL setup_exp_constraints(kind_section, opt_bas%kind_basis(ikind)%flex_basis(0))
656 CALL parse_derived_basis(kind_section, opt_bas%kind_basis(ikind)%deriv_info, ikind)
658 variable_counter = variable_counter + opt_bas%kind_basis(ikind)%flex_basis(0)%nopt
661 ALLOCATE (opt_bas%x_opt(variable_counter))
664 DO ikind = 1, opt_bas%nkind
665 CALL assign_x_to_basis(opt_bas%x_opt, opt_bas%kind_basis(ikind)%flex_basis(0), variable_counter)
668 cpassert(variable_counter ==
SIZE(opt_bas%x_opt))
670 END SUBROUTINE generate_initial_basis
680 SUBROUTINE parse_derived_basis(kind_section, deriv_info, ikind)
685 INTEGER :: i_rep, iset, jset, n_rep, nsets
686 INTEGER,
DIMENSION(:),
POINTER :: i_vals
690 nsets =
SIZE(deriv_info) - 1
699 deriv_info(iset)%reference_set = i_vals(1)
700 CALL section_vals_val_get(set1_section,
"REMOVE_CONTRACTION", explicit=explicit, n_rep_val=n_rep, &
702 deriv_info(iset)%ncontr = n_rep
704 ALLOCATE (deriv_info(iset)%remove_contr(n_rep, 3))
708 deriv_info(iset)%remove_contr(i_rep, :) = i_vals(:)
713 deriv_info(iset)%nsets = n_rep
715 ALLOCATE (deriv_info(iset)%remove_set(n_rep))
719 deriv_info(iset)%remove_set(i_rep) = i_vals(1)
724 END SUBROUTINE parse_derived_basis
733 SUBROUTINE setup_exp_constraints(kind1_section, flex_basis)
737 INTEGER :: ipgf, irep, iset, nrep
738 INTEGER,
DIMENSION(:),
POINTER :: def_exp
739 LOGICAL :: is_bound, is_varlim
747 CALL section_vals_val_get(const_section,
"MAX_VAR_FRACTION", explicit=is_varlim, i_rep_section=irep)
748 IF (is_bound .AND. is_varlim)
THEN
749 CALL cp_abort(__location__,
"Exponent has two constraints. "// &
750 "This is not possible at the moment. Please change input.")
752 IF (.NOT. is_bound .AND. .NOT. is_varlim)
THEN
753 CALL cp_abort(__location__,
"Exponent is declared to be constraint but none is given"// &
754 " Please change input.")
756 IF (def_exp(1) == -1)
THEN
757 DO iset = 1, flex_basis%nsets
758 IF (def_exp(2) == -1)
THEN
759 DO ipgf = 1, flex_basis%subset(iset)%nexp
760 CALL set_constraint(flex_basis, iset, ipgf, const_section, is_bound, is_varlim, irep)
763 IF (def_exp(2) <= flex_basis%subset(iset)%nexp)
THEN
764 CALL cp_abort(__location__, &
765 "Exponent declared in constraint is larger than number of exponents in the set"// &
766 " Please change input.")
768 CALL set_constraint(flex_basis, iset, def_exp(2), const_section, is_bound, is_varlim, irep)
772 IF (.NOT. def_exp(1) <= flex_basis%nsets)
THEN
773 CALL cp_abort(__location__, &
774 "Set number of constraint is larger than number of sets in the template basis set."// &
775 " Please change input.")
777 IF (def_exp(2) == -1)
THEN
778 DO ipgf = 1, flex_basis%subset(iset)%nexp
779 CALL set_constraint(flex_basis, def_exp(1), ipgf, const_section, is_bound, is_varlim, irep)
782 IF (.NOT. def_exp(2) <= flex_basis%subset(def_exp(1))%nexp)
THEN
783 CALL cp_abort(__location__, &
784 "Exponent declared in constraint is larger than number of exponents in the set"// &
785 " Please change input.")
787 CALL set_constraint(flex_basis, def_exp(1), def_exp(2), const_section, is_bound, is_varlim, irep)
792 END SUBROUTINE setup_exp_constraints
807 SUBROUTINE set_constraint(flex_basis, iset, ipgf, const_section, is_bound, is_varlim, irep)
809 INTEGER :: iset, ipgf
811 LOGICAL :: is_bound, is_varlim
814 REAL(kind=
dp) :: r_val
815 REAL(kind=
dp),
DIMENSION(:),
POINTER :: r_vals
817 IF (flex_basis%subset(iset)%exp_has_const(ipgf))
THEN
818 CALL cp_abort(__location__, &
819 "Multiple constraints due to collision in CONSTRAIN_EXPONENTS."// &
820 " Please change input.")
822 flex_basis%subset(iset)%exp_has_const(ipgf) = .true.
824 flex_basis%subset(iset)%exp_const(ipgf)%const_type = 0
826 flex_basis%subset(iset)%exp_const(ipgf)%llim = minval(r_vals)
827 flex_basis%subset(iset)%exp_const(ipgf)%ulim = maxval(r_vals)
828 r_val = flex_basis%subset(iset)%exps(ipgf)
829 IF (flex_basis%subset(iset)%exps(ipgf) > maxval(r_vals) .OR. flex_basis%subset(iset)%exps(ipgf) < minval(r_vals))
THEN
830 CALL cp_abort(__location__, &
832 " declared in constraint is out of bounds of constraint"//
cp_to_string(minval(r_vals))// &
834 " Please change input.")
836 flex_basis%subset(iset)%exp_const(ipgf)%init = sum(r_vals)/2.0_dp
837 flex_basis%subset(iset)%exp_const(ipgf)%var_fac = maxval(r_vals)/flex_basis%subset(iset)%exp_const(ipgf)%init - 1.0_dp
840 flex_basis%subset(iset)%exp_const(ipgf)%const_type = 1
842 flex_basis%subset(iset)%exp_const(ipgf)%var_fac = r_vals(1)
843 flex_basis%subset(iset)%exp_const(ipgf)%init = flex_basis%subset(iset)%exps(ipgf)
846 END SUBROUTINE set_constraint
856 SUBROUTINE assign_x_to_basis(x, basis, x_ind)
857 REAL(kind=
dp),
DIMENSION(:) :: x
861 INTEGER :: icont, ipgf, iset
863 DO iset = 1, basis%nsets
864 DO ipgf = 1, basis%subset(iset)%nexp
865 IF (basis%subset(iset)%opt_exps(ipgf))
THEN
867 basis%subset(iset)%exp_x_ind(ipgf) = x_ind
868 x(x_ind) = basis%subset(iset)%exps(ipgf)
870 DO icont = 1, basis%subset(iset)%ncon_tot
871 IF (basis%subset(iset)%opt_coeff(ipgf, icont))
THEN
873 basis%subset(iset)%coeff_x_ind(ipgf, icont) = x_ind
874 x(x_ind) = basis%subset(iset)%coeff(ipgf, icont)
880 END SUBROUTINE assign_x_to_basis
894 SUBROUTINE fill_basis_template(kind1_section, flex_basis, template_basis_file, element, basis_name, para_env, ikind)
897 CHARACTER(LEN=default_path_length) :: template_basis_file
898 CHARACTER(LEN=default_string_length) :: element, basis_name
902 INTEGER :: icont, idof, ipgf, irep, iset, nrep
903 INTEGER,
DIMENSION(:),
POINTER :: switch
905 CALL parse_basis(flex_basis, template_basis_file, element, basis_name, para_env)
911 DO iset = 1, flex_basis%nsets
916 flex_basis%subset(iset)%opt_coeff = .true.
917 flex_basis%subset(iset)%opt_exps = .true.
919 flex_basis%subset(iset)%opt_coeff = .true.
921 flex_basis%subset(iset)%opt_exps = .true.
923 cpabort(
"No initialization available?????")
927 CALL section_vals_val_get(kind1_section,
"SWITCH_CONTRACTION_STATE", n_rep_val=nrep, i_rep_section=ikind)
930 i_rep_section=ikind, i_vals=switch)
931 icont = convert_l_contr_to_entry(flex_basis%subset(switch(1))%lmin, flex_basis%subset(switch(1))%l, switch(3), switch(2))
932 DO ipgf = 1, flex_basis%subset(switch(1))%nexp
933 flex_basis%subset(switch(1))%opt_coeff(ipgf, icont) = .NOT. flex_basis%subset(switch(1))%opt_coeff(ipgf, icont)
937 CALL section_vals_val_get(kind1_section,
"SWITCH_COEFF_STATE", n_rep_val=nrep, i_rep_section=ikind)
940 i_rep_section=ikind, i_vals=switch)
941 icont = convert_l_contr_to_entry(flex_basis%subset(switch(1))%lmin, flex_basis%subset(switch(1))%l, switch(3), switch(2))
942 flex_basis%subset(switch(1))%opt_coeff(switch(4), icont) = &
943 .NOT. flex_basis%subset(switch(1))%opt_coeff(switch(4), icont)
946 CALL section_vals_val_get(kind1_section,
"SWITCH_EXP_STATE", n_rep_val=nrep, i_rep_section=ikind)
949 i_rep_section=ikind, i_vals=switch)
950 flex_basis%subset(switch(1))%opt_exps(switch(2)) = .NOT. flex_basis%subset(switch(1))%opt_exps(switch(2))
953 CALL section_vals_val_get(kind1_section,
"SWITCH_SET_STATE", n_rep_val=nrep, i_rep_section=ikind)
956 i_rep_section=ikind, i_vals=switch)
957 DO ipgf = 1, flex_basis%subset(switch(2))%nexp
958 SELECT CASE (switch(1))
960 DO icont = 1, flex_basis%subset(switch(2))%ncon_tot
961 flex_basis%subset(switch(2))%opt_coeff(ipgf, icont) = &
962 .NOT. flex_basis%subset(switch(2))%opt_coeff(ipgf, icont)
964 flex_basis%subset(switch(2))%opt_exps(ipgf) = .NOT. flex_basis%subset(switch(2))%opt_exps(ipgf)
966 flex_basis%subset(switch(2))%opt_exps(ipgf) = .NOT. flex_basis%subset(switch(2))%opt_exps(ipgf)
968 DO icont = 1, flex_basis%subset(switch(2))%ncon_tot
969 flex_basis%subset(switch(2))%opt_coeff(ipgf, icont) = &
970 .NOT. flex_basis%subset(switch(2))%opt_coeff(ipgf, icont)
973 cpabort(
"Invalid option in SWITCH_SET_STATE, 1st value has to be 0, 1 or 2")
979 DO irep = 1, flex_basis%nsets
980 IF (flex_basis%subset(irep)%nexp == 1)
THEN
981 DO ipgf = 1, flex_basis%subset(irep)%nexp
982 flex_basis%subset(irep)%opt_coeff(ipgf, 1) = .false.
989 DO irep = 1, flex_basis%nsets
990 DO ipgf = 1, flex_basis%subset(irep)%nexp
991 DO icont = 1, flex_basis%subset(irep)%ncon_tot
992 IF (flex_basis%subset(irep)%opt_coeff(ipgf, icont)) flex_basis%nopt = flex_basis%nopt + 1
994 IF (flex_basis%subset(irep)%opt_exps(ipgf)) flex_basis%nopt = flex_basis%nopt + 1
998 END SUBROUTINE fill_basis_template
1011 FUNCTION convert_l_contr_to_entry(lmin, nl, icontr, l)
RESULT(ientry)
1013 INTEGER,
DIMENSION(:) :: nl
1014 INTEGER :: icontr, l, ientry
1016 INTEGER :: i, icon2l, iwork
1021 icon2l = icon2l + nl(i)
1023 ientry = icon2l + icontr
1025 END FUNCTION convert_l_contr_to_entry
1037 SUBROUTINE parse_basis(flex_basis, template_basis_file, element, basis_name, para_env)
1039 CHARACTER(LEN=default_path_length) :: template_basis_file
1040 CHARACTER(LEN=default_string_length) :: element, basis_name
1043 CHARACTER(LEN=240) :: line
1044 CHARACTER(LEN=242) :: line2
1045 CHARACTER(LEN=LEN(basis_name)+2) :: basis_name2
1046 CHARACTER(LEN=LEN(element)+2) :: element2
1047 INTEGER :: iset, strlen1, strlen2
1048 LOGICAL :: basis_found, found, match
1051 basis_found = .false.
1054 CALL parser_create(parser, template_basis_file, para_env=para_env)
1062 line2 =
" "//line//
" "
1063 element2 =
" "//trim(element)//
" "
1064 basis_name2 =
" "//trim(basis_name)//
" "
1065 strlen1 = len_trim(element2) + 1
1066 strlen2 = len_trim(basis_name2) + 1
1067 IF ((index(line2, element2(:strlen1)) > 0) .AND. &
1068 (index(line2, basis_name2(:strlen2)) > 0)) match = .true.
1071 ALLOCATE (flex_basis%subset(flex_basis%nsets))
1072 DO iset = 1, flex_basis%nsets
1073 CALL parse_subset(parser, flex_basis%subset(iset))
1075 basis_found = .true.
1084 IF (.NOT. basis_found)
CALL cp_abort(__location__, &
1085 "The requested basis set <"//trim(basis_name)// &
1086 "> for element <"//trim(element)//
"> was not "// &
1087 "found in the template basis set file ")
1089 END SUBROUTINE parse_basis
1097 SUBROUTINE parse_subset(parser, subset)
1101 CHARACTER(len=20*default_string_length) :: line_att
1102 INTEGER :: icon1, icon2, il, ipgf, ishell, istart
1103 REAL(kind=
dp) :: gs_scale
1104 REAL(kind=
dp),
POINTER :: r_val
1111 subset%nl = subset%lmax - subset%lmin + 1
1113 ALLOCATE (subset%l(subset%nl))
1114 ALLOCATE (subset%exps(subset%nexp))
1115 ALLOCATE (subset%exp_has_const(subset%nexp))
1116 subset%exp_has_const = .false.
1117 ALLOCATE (subset%opt_exps(subset%nexp))
1118 subset%opt_exps = .false.
1119 ALLOCATE (subset%exp_const(subset%nexp))
1120 ALLOCATE (subset%exp_x_ind(subset%nexp))
1121 DO ishell = 1, subset%nl
1124 subset%ncon_tot = sum(subset%l)
1125 ALLOCATE (subset%coeff(subset%nexp, subset%ncon_tot))
1126 ALLOCATE (subset%opt_coeff(subset%nexp, subset%ncon_tot))
1127 subset%opt_coeff = .false.
1128 ALLOCATE (subset%coeff_x_ind(subset%nexp, subset%ncon_tot))
1129 DO ipgf = 1, subset%nexp
1131 subset%exps(ipgf) = r_val
1132 DO ishell = 1, subset%ncon_tot
1134 subset%coeff(ipgf, ishell) = r_val
1140 DO il = 1, subset%nl
1141 DO icon1 = istart, istart + subset%l(il) - 2
1142 DO icon2 = icon1 + 1, istart + subset%l(il) - 1
1143 gs_scale = dot_product(subset%coeff(:, icon2), subset%coeff(:, icon1))/ &
1144 dot_product(subset%coeff(:, icon1), subset%coeff(:, icon1))
1145 subset%coeff(:, icon2) = subset%coeff(:, icon2) - gs_scale*subset%coeff(:, icon1)
1148 istart = istart + subset%l(il)
1152 DO icon1 = 1, subset%ncon_tot
1153 subset%coeff(:, icon1) = subset%coeff(:, icon1)/norm2(subset%coeff(:, icon1))
1157 END SUBROUTINE parse_subset
1166 SUBROUTINE init_powell_var(p_param, powell_section)
1178 END SUBROUTINE init_powell_var
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
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
Utility routines to read data from files. Kept as close as possible to the old parser because.
subroutine, public parser_search_string(parser, string, ignore_case, found, line, begin_line, search_from_begin_of_file)
Search a string pattern in a file defined by its logical unit number "unit". A case sensitive search ...
Utility routines to read data from files. Kept as close as possible to the old parser because.
subroutine, public parser_release(parser)
releases the parser
subroutine, public parser_create(parser, file_name, unit_nr, para_env, end_section_label, separator_chars, comment_char, continuation_char, quote_char, section_char, parse_white_lines, initial_variables, apply_preprocessing)
Start a parser run. Initial variables allow to @SET stuff before opening the file.
Defines the basic variable types.
integer, parameter, public dp
integer, parameter, public default_string_length
integer, parameter, public default_path_length
Machine interface based on Fortran 2003 and POSIX.
integer, parameter, public default_output_unit
subroutine, public m_getcwd(curdir)
...
Interface to the message passing library MPI.
subroutine, public get_set_and_basis_id(calc_id, opt_bas, set_id, bas_id)
returns a mapping from the calculation id to the trainings set id and basis combination id
subroutine, public optimize_basis_init_read_input(opt_bas, root_section, para_env)
initialize all parts of the optimization type and read input settings
subroutine, public update_derived_basis_sets(opt_bas, write_it, output_file, para_env)
Regenerate the basis sets from reference 0 after an update from the optimizer to reference was perfor...
Utilities for string manipulations.
character(len=1), parameter, public newline
elemental subroutine, public uppercase(string)
Convert all lower case characters in a string to upper case.
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
type containing all information needed for basis matching