Skip to content

Commit

Permalink
nlopt contants; roll back makefile for merge
Browse files Browse the repository at this point in the history
  • Loading branch information
14N16O committed Jun 28, 2022
1 parent 56c9c91 commit 8b36452
Show file tree
Hide file tree
Showing 4 changed files with 180 additions and 49 deletions.
88 changes: 52 additions & 36 deletions F1_fitting.f90
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
module F1_fitting
use accuracy
use accuracy
use nlopt_constants
use F1_hyperfine, only : eigen_all_F1, F1_global_min, &
F1_hyperfine_structrure, min_eigen_value_F1, &
F1_list, primitive_F1_basis
use diatom_module, only : action, job, duo_j0, fieldmap, fieldT, &
grid, fitting, linkT, &
grid, fitting, linkT, F1_hyperfine_setup, &
poten, spinorbit, l2, lxly, spinspin, spinspino, spinrot, &
bobrot, diabatic, lambdaopq, lambdap2q, lambdaq, &
l_omega_obj, s_omega_obj, quadrupoletm, hfcc1, &
Expand All @@ -15,8 +16,6 @@ module F1_fitting
! use nlopt_enum, only : NLOPT_SUCCESS, algorithm_from_string

implicit none

include "nlopt.f"

type fit_indexT
integer(ik) :: i
Expand Down Expand Up @@ -47,9 +46,7 @@ module F1_fitting
type(fit_indexT), allocatable :: fit_index(:)
type(object_containerT), allocatable :: objects(:, :)

! type :: constraint_data
! real(rk) :: d(2)
! end type
integer :: optimization_algorithm

contains

Expand All @@ -65,7 +62,7 @@ subroutine F1_refine()
write(out, '(/A)') 'Start hyperfine refinement'

! call nlo_create(opt, NLOPT_LD_MMA, num_parameters)
call nlo_create(opt, NLOPT_LN_COBYLA, num_parameters)
call nlo_create(opt, optimization_algorithm, num_parameters)


call nlo_set_min_objective(ires, opt, objective_function_F1_hyperfine_fit, 0)
Expand All @@ -77,7 +74,7 @@ subroutine F1_refine()
! d2(2) = 1.
! call nlo_add_inequality_constraint(ires, opt, myconstraint, d2, 1.D-8)

call nlo_set_xtol_rel(ires, opt, 1.0E-4)
call nlo_set_xtol_rel(ires, opt, 1.0E-7)
call nlo_set_ftol_rel(ires, opt, 1.0E-4);
! call nlo_set_ftol_abs(ires, opt, double tol)
call nlo_set_stopval(ires, opt, 100);
Expand All @@ -91,7 +88,7 @@ subroutine F1_refine()
! write(out, '(A2, A, I3, A, F24.14)') '', 'x(', i, ') = ', x(i)
! enddo

xtol = 0.001
xtol = 0.00001
lb = x * (1 - xtol)
ub = x * (1 + xtol)

Expand Down Expand Up @@ -125,34 +122,34 @@ subroutine F1_refine()
function nlopt_flag(ires) result(flag)
implicit none
integer(ik) :: ires
character(100):: flag
character(cl):: flag

select case(ires)
case (NLOPT_SUCCESS)
flag = "NLOPT_SUCCESS"
case (NLOPT_STOPVAL_REACHED)
flag = "NLOPT_STOPVAL_REACHED"
case (NLOPT_FTOL_REACHED)
flag = "NLOPT_FTOL_REACHED"
case (NLOPT_XTOL_REACHED)
flag = "NLOPT_XTOL_REACHED"
case (NLOPT_MAXEVAL_REACHED)
flag = "NLOPT_MAXEVAL_REACHED"
case (NLOPT_MAXTIME_REACHED)
flag = "NLOPT_MAXTIME_REACHED ="
case (NLOPT_FAILURE)
flag = "NLOPT_FAILURE"
case (NLOPT_INVALID_ARGS)
flag = "NLOPT_INVALID_ARGS"
case (NLOPT_OUT_OF_MEMORY )
flag = "NLOPT_OUT_OF_MEMORY "
case (NLOPT_ROUNDOFF_LIMITED)
flag = "NLOPT_ROUNDOFF_LIMITED"
case (NLOPT_FORCED_STOP)
flag = "NLOPT_FORCED_STOP"

case default
flag = "Unknown NLOPT flag"
case (NLOPT_SUCCESS)
flag = "NLOPT_SUCCESS"
case (NLOPT_STOPVAL_REACHED)
flag = "NLOPT_STOPVAL_REACHED"
case (NLOPT_FTOL_REACHED)
flag = "NLOPT_FTOL_REACHED"
case (NLOPT_XTOL_REACHED)
flag = "NLOPT_XTOL_REACHED"
case (NLOPT_MAXEVAL_REACHED)
flag = "NLOPT_MAXEVAL_REACHED"
case (NLOPT_MAXTIME_REACHED)
flag = "NLOPT_MAXTIME_REACHED ="
case (NLOPT_FAILURE)
flag = "NLOPT_FAILURE"
case (NLOPT_INVALID_ARGS)
flag = "NLOPT_INVALID_ARGS"
case (NLOPT_OUT_OF_MEMORY )
flag = "NLOPT_OUT_OF_MEMORY "
case (NLOPT_ROUNDOFF_LIMITED)
flag = "NLOPT_ROUNDOFF_LIMITED"
case (NLOPT_FORCED_STOP)
flag = "NLOPT_FORCED_STOP"

case default
flag = "Unknown NLOPT flag"
endselect

end function nlopt_flag
Expand Down Expand Up @@ -189,6 +186,9 @@ subroutine F1_refinement_init()

action%save_eigen_J = .true.
job%basis_set = 'KEEP'

optimization_algorithm = &
get_nlopt_algorithm(F1_hyperfine_setup%fit_optimization_algorithm)

call read_F1_hyperfine_states_fit

Expand Down Expand Up @@ -284,6 +284,22 @@ subroutine F1_refinement_init()
enddo
enddo
enddo

contains
function get_nlopt_algorithm(fit_optimization_algorithm) &
result(algorithm)

character(cl), intent(in) :: fit_optimization_algorithm
integer :: algorithm

select case(trim(fit_optimization_algorithm))
case ("NLOPT_LN_BOBYQA")
algorithm = NLOPT_LN_BOBYQA
case default
algorithm = NLOPT_LN_COBYLA
end select

end function get_nlopt_algorithm

end subroutine F1_refinement_init

Expand Down
11 changes: 7 additions & 4 deletions duo.f90
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,13 @@ function isatty(fd) bind(c)
call F1_hyperfine_intensity
stop
else if (action%fitting) then
call map_fields_onto_grid(verbose)
call F1_refinement_init
CALL F1_refine
stop
write(out, '(a)') 'Fitting and hyperfine should not be used at the same time'
stop 'please switch-off/remove either fitting or hyperfine'
! else if (action%fitting) then
! call map_fields_onto_grid(verbose)
! call F1_refinement_init
! CALL F1_refine
! stop
else
call duo_j0
call F1_hyperfine_structrure(verbose)
Expand Down
17 changes: 8 additions & 9 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,23 @@ FFLAGS = -O3 -ip -qopenmp -mkl=parallel # -xHost -fast

#ARPACK = ~/libraries/ARPACK/libarpack_omp_64.a

LAPACK = -Qmkl:parallel -static-intel
LAPACK = -Qmkl:parallel -static

LIB = $(LAPACK) -lnlopt -cxxlib
LIB = $(LAPACK)

###############################################################################

OBJ = F1_fitting.o F1_hyperfine.o F1_intensity.o grids.o accuracy.o lapack.o timer.o input.o diatom.o refinement.o functions.o symmetry.o dipole.o quadrupole.o header_info.o atomic_and_nuclear_data.o Lobatto.o me_numer.o RWF.o
OBJ = F1_hyperfine.o F1_intensity.o grids.o accuracy.o lapack.o timer.o input.o diatom.o refinement.o functions.o symmetry.o dipole.o quadrupole.o header_info.o atomic_and_nuclear_data.o Lobatto.o me_numer.o RWF.o

diatom.o: symmetry.o functions.o input.o lapack.o Lobatto.o timer.o atomic_and_nuclear_data.o accuracy.o me_numer.o
dipole.o: timer.o accuracy.o diatom.o symmetry.o
quadrupole.o: timer.o accuracy.o diatom.o symmetry.o
duo.o: header_info.o diatom.o accuracy.o refinement.o timer.o dipole.o F1_hyperfine.o F1_intensity.o F1_fitting.o
F1_hyperfine.o: accuracy.o diatom.o lapack.o symmetry.o
F1_intensity.o: F1_hyperfine.o accuracy.o diatom.o
F1_fitting.o: accuracy.o diatom.o F1_hyperfine.o
duo.o: header_info.o diatom.o accuracy.o refinement.o timer.o dipole.o F1_hyperfine.o F1_intensity.o
functions.o: accuracy.o timer.o
grids.o: accuracy.o Lobatto.o
header_info.o: accuracy.o
F1_hyperfine.o: accuracy.o diatom.o lapack.o symmetry.o
F1_intensity.o: F1_hyperfine.o accuracy.o diatom.o
me_numer.o : accuracy.o lapack.o timer.o
lapack.o: accuracy.o timer.o
Lobatto.o: accuracy.o timer.o
Expand All @@ -92,10 +91,10 @@ RWF.o: accuracy.o diatom.o timer.o symmetry.o lapack.o
$(FOR) -c -o $@ $< $(FFLAGS)

duo: $(OBJ) duo.o
$(FOR) $(OBJ) duo.o $(LIB) $(FFLAGS) -o $(EXE)
$(FOR) -o $(EXE) $(OBJ) $(FFLAGS) duo.o $(LIB)

clean:
rm -f $(OBJ) *.mod *__genmod.f90 duo.o duo_test_0* eigen_vectors.chk eigen_vib.chk Bob-Rot_centrifugal_functions.dat _Lp__functions.dat Spin-Orbit.dat Spin-spin_functions.dat Dipole_moment_functions.dat Potential_functions.dat Spin-rotation_functions.dat Spin-spin-o__non-diagonal__functions.dat

test: test_duo.f90
$(FOR) -O0 test_duo.f90 -o duo_test.exe
$(FOR) -O0 test_duo.f90 -o duo_test.exe
113 changes: 113 additions & 0 deletions nlopt_constants.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
module nlopt_constants
public
integer NLOPT_GN_DIRECT
parameter (NLOPT_GN_DIRECT=0)
integer NLOPT_GN_DIRECT_L
parameter (NLOPT_GN_DIRECT_L=1)
integer NLOPT_GN_DIRECT_L_RAND
parameter (NLOPT_GN_DIRECT_L_RAND=2)
integer NLOPT_GN_DIRECT_NOSCAL
parameter (NLOPT_GN_DIRECT_NOSCAL=3)
integer NLOPT_GN_DIRECT_L_NOSCAL
parameter (NLOPT_GN_DIRECT_L_NOSCAL=4)
integer NLOPT_GN_DIRECT_L_RAND_NOSCAL
parameter (NLOPT_GN_DIRECT_L_RAND_NOSCAL=5)
integer NLOPT_GN_ORIG_DIRECT
parameter (NLOPT_GN_ORIG_DIRECT=6)
integer NLOPT_GN_ORIG_DIRECT_L
parameter (NLOPT_GN_ORIG_DIRECT_L=7)
integer NLOPT_GD_STOGO
parameter (NLOPT_GD_STOGO=8)
integer NLOPT_GD_STOGO_RAND
parameter (NLOPT_GD_STOGO_RAND=9)
integer NLOPT_LD_LBFGS_NOCEDAL
parameter (NLOPT_LD_LBFGS_NOCEDAL=10)
integer NLOPT_LD_LBFGS
parameter (NLOPT_LD_LBFGS=11)
integer NLOPT_LN_PRAXIS
parameter (NLOPT_LN_PRAXIS=12)
integer NLOPT_LD_VAR1
parameter (NLOPT_LD_VAR1=13)
integer NLOPT_LD_VAR2
parameter (NLOPT_LD_VAR2=14)
integer NLOPT_LD_TNEWTON
parameter (NLOPT_LD_TNEWTON=15)
integer NLOPT_LD_TNEWTON_RESTART
parameter (NLOPT_LD_TNEWTON_RESTART=16)
integer NLOPT_LD_TNEWTON_PRECOND
parameter (NLOPT_LD_TNEWTON_PRECOND=17)
integer NLOPT_LD_TNEWTON_PRECOND_RESTART
parameter (NLOPT_LD_TNEWTON_PRECOND_RESTART=18)
integer NLOPT_GN_CRS2_LM
parameter (NLOPT_GN_CRS2_LM=19)
integer NLOPT_GN_MLSL
parameter (NLOPT_GN_MLSL=20)
integer NLOPT_GD_MLSL
parameter (NLOPT_GD_MLSL=21)
integer NLOPT_GN_MLSL_LDS
parameter (NLOPT_GN_MLSL_LDS=22)
integer NLOPT_GD_MLSL_LDS
parameter (NLOPT_GD_MLSL_LDS=23)
integer NLOPT_LD_MMA
parameter (NLOPT_LD_MMA=24)
integer NLOPT_LN_COBYLA
parameter (NLOPT_LN_COBYLA=25)
integer NLOPT_LN_NEWUOA
parameter (NLOPT_LN_NEWUOA=26)
integer NLOPT_LN_NEWUOA_BOUND
parameter (NLOPT_LN_NEWUOA_BOUND=27)
integer NLOPT_LN_NELDERMEAD
parameter (NLOPT_LN_NELDERMEAD=28)
integer NLOPT_LN_SBPLX
parameter (NLOPT_LN_SBPLX=29)
integer NLOPT_LN_AUGLAG
parameter (NLOPT_LN_AUGLAG=30)
integer NLOPT_LD_AUGLAG
parameter (NLOPT_LD_AUGLAG=31)
integer NLOPT_LN_AUGLAG_EQ
parameter (NLOPT_LN_AUGLAG_EQ=32)
integer NLOPT_LD_AUGLAG_EQ
parameter (NLOPT_LD_AUGLAG_EQ=33)
integer NLOPT_LN_BOBYQA
parameter (NLOPT_LN_BOBYQA=34)
integer NLOPT_GN_ISRES
parameter (NLOPT_GN_ISRES=35)
integer NLOPT_AUGLAG
parameter (NLOPT_AUGLAG=36)
integer NLOPT_AUGLAG_EQ
parameter (NLOPT_AUGLAG_EQ=37)
integer NLOPT_G_MLSL
parameter (NLOPT_G_MLSL=38)
integer NLOPT_G_MLSL_LDS
parameter (NLOPT_G_MLSL_LDS=39)
integer NLOPT_LD_SLSQP
parameter (NLOPT_LD_SLSQP=40)
integer NLOPT_LD_CCSAQ
parameter (NLOPT_LD_CCSAQ=41)
integer NLOPT_GN_ESCH
parameter (NLOPT_GN_ESCH=42)
integer NLOPT_GN_AGS
parameter (NLOPT_GN_AGS=43)
integer NLOPT_FAILURE
parameter (NLOPT_FAILURE=-1)
integer NLOPT_INVALID_ARGS
parameter (NLOPT_INVALID_ARGS=-2)
integer NLOPT_OUT_OF_MEMORY
parameter (NLOPT_OUT_OF_MEMORY=-3)
integer NLOPT_ROUNDOFF_LIMITED
parameter (NLOPT_ROUNDOFF_LIMITED=-4)
integer NLOPT_FORCED_STOP
parameter (NLOPT_FORCED_STOP=-5)
integer NLOPT_SUCCESS
parameter (NLOPT_SUCCESS=1)
integer NLOPT_STOPVAL_REACHED
parameter (NLOPT_STOPVAL_REACHED=2)
integer NLOPT_FTOL_REACHED
parameter (NLOPT_FTOL_REACHED=3)
integer NLOPT_XTOL_REACHED
parameter (NLOPT_XTOL_REACHED=4)
integer NLOPT_MAXEVAL_REACHED
parameter (NLOPT_MAXEVAL_REACHED=5)
integer NLOPT_MAXTIME_REACHED
parameter (NLOPT_MAXTIME_REACHED=6)
end module nlopt_constants

0 comments on commit 8b36452

Please sign in to comment.