47 use,
intrinsic :: iso_c_binding
62 integer(c_int),
parameter :: cd = c_double
63 integer(c_int),
parameter :: dim = 3
67 real(c_double),
parameter :: model_cutsq =
model_cutoff**2
84 real(c_double),
parameter :: lj_epsilon = 0.0104_cd
85 real(c_double),
parameter :: lj_sigma = 3.40_cd
86 real(c_double),
parameter :: lj_cutnorm =
model_cutoff / lj_sigma
87 real(c_double),
parameter :: &
88 lj_a = 12.0_cd * lj_epsilon * (-26.0_cd + 7.0_cd * lj_cutnorm**6) &
89 / (lj_cutnorm**14 * lj_sigma**2)
90 real(c_double),
parameter :: &
91 lj_b = 96.0_cd * lj_epsilon * (7.0_cd - 2.0_cd * lj_cutnorm**6) &
92 / (lj_cutnorm**13 * lj_sigma)
93 real(c_double),
parameter :: &
94 lj_c = 28.0_cd * lj_epsilon * (-13.0_cd + 4.0_cd * lj_cutnorm**6) &
97 type, bind(c) :: buffer_type
98 real(c_double) :: influence_distance
99 real(c_double) :: cutoff(1)
101 model_will_not_request_neighbors_of_noncontributing_particles(1)
111 recursive subroutine calc_phi(r, phi)
115 real(c_double),
intent(in) :: r
116 real(c_double),
intent(out) :: phi
119 real(c_double) rsq, sor, sor6, sor12
123 sor6 = sor * sor * sor
130 phi = 4.0_cd * lj_epsilon * (sor12 - sor6) + lj_a * rsq + lj_b * r + lj_c
144 real(c_double),
intent(in) :: r
145 real(c_double),
intent(out) :: phi, dphi
148 real(c_double) rsq, sor, sor6, sor12
152 sor6 = sor * sor * sor
160 phi = 4.0_cd * lj_epsilon * (sor12 - sor6) + lj_a * rsq + lj_b * r + lj_c
161 dphi = 24.0_cd * lj_epsilon * (-2.0_cd * sor12 + sor6) / r &
162 + 2.0_cd * lj_a * r + lj_b
173 model_compute_handle, model_compute_arguments_handle, ierr) bind(c)
177 type(kim_model_compute_handle_type),
intent(in) :: model_compute_handle
178 type(kim_model_compute_arguments_handle_type),
intent(in) :: &
179 model_compute_arguments_handle
180 integer(c_int),
intent(out) :: ierr
183 real(c_double) :: Rij(dim)
184 real(c_double) :: r, Rsqij, phi, dphi, dEidr = 0.0_cd
185 integer(c_int) :: i, j, jj, numnei, comp_force, comp_enepot, &
186 comp_virial, comp_energy
187 integer(c_int) :: ierr2
190 integer(c_int),
pointer :: N
191 real(c_double),
pointer :: energy
192 real(c_double),
pointer :: coor(:, :)
193 real(c_double),
pointer :: force(:, :)
194 real(c_double),
pointer :: enepot(:)
195 integer(c_int),
pointer :: nei1part(:)
196 integer(c_int),
pointer :: particleSpeciesCodes(:)
197 integer(c_int),
pointer :: particleContributing(:)
198 real(c_double),
pointer :: virial(:)
203 call kim_get_argument_pointer( &
204 model_compute_arguments_handle, &
205 kim_compute_argument_name_number_of_particles, n, ierr2)
207 call kim_get_argument_pointer( &
208 model_compute_arguments_handle, &
209 kim_compute_argument_name_particle_species_codes, n, &
210 particlespeciescodes, ierr2)
212 call kim_get_argument_pointer( &
213 model_compute_arguments_handle, &
214 kim_compute_argument_name_particle_contributing, n, &
215 particlecontributing, ierr2)
217 call kim_get_argument_pointer( &
218 model_compute_arguments_handle, &
219 kim_compute_argument_name_coordinates, dim, n, coor, ierr2)
221 call kim_get_argument_pointer( &
222 model_compute_arguments_handle, &
223 kim_compute_argument_name_partial_energy, energy, ierr2)
225 call kim_get_argument_pointer( &
226 model_compute_arguments_handle, &
227 kim_compute_argument_name_partial_forces, dim, n, force, ierr2)
229 call kim_get_argument_pointer( &
230 model_compute_arguments_handle, &
231 kim_compute_argument_name_partial_particle_energy, n, enepot, ierr2)
233 call kim_get_argument_pointer( &
234 model_compute_arguments_handle, &
235 kim_compute_argument_name_partial_virial, 6, virial, ierr2)
238 call kim_log_entry(model_compute_arguments_handle, &
239 kim_log_verbosity_error,
"get data")
247 if (
associated(energy))
then 252 if (
associated(force))
then 257 if (
associated(enepot))
then 262 if (
associated(virial))
then 272 if (particlespeciescodes(i) /=
speccode)
then 273 call kim_log_entry( &
274 model_compute_handle, kim_log_verbosity_error, &
275 "Unexpected species code detected")
284 if (comp_enepot == 1) enepot = 0.0_cd
285 if (comp_energy == 1) energy = 0.0_cd
286 if (comp_force == 1) force = 0.0_cd
287 if (comp_virial == 1) virial = 0.0_cd
296 if (particlecontributing(i) == 1)
then 298 call kim_get_neighbor_list( &
299 model_compute_arguments_handle, 1, i, numnei, nei1part, ierr)
302 call kim_log_entry( &
303 model_compute_arguments_handle, kim_log_verbosity_error, &
304 "GetNeighborList failed")
317 rij(:) = coor(:, j) - coor(:, i)
321 rsqij = dot_product(rij, rij)
322 if (rsqij < model_cutsq)
then 325 if (comp_force == 1 .or. comp_virial == 1)
then 328 deidr = 0.5_cd * dphi
335 if (comp_enepot == 1)
then 336 enepot(i) = enepot(i) + 0.5_cd * phi
338 if (comp_energy == 1)
then 339 energy = energy + 0.5_cd * phi
344 if (comp_virial == 1)
then 345 virial(1) = virial(1) + rij(1) * rij(1) * deidr / r
346 virial(2) = virial(2) + rij(2) * rij(2) * deidr / r
347 virial(3) = virial(3) + rij(3) * rij(3) * deidr / r
348 virial(4) = virial(4) + rij(2) * rij(3) * deidr / r
349 virial(5) = virial(5) + rij(1) * rij(3) * deidr / r
350 virial(6) = virial(6) + rij(1) * rij(2) * deidr / r
355 if (comp_force == 1)
then 356 force(:, i) = force(:, i) + deidr * rij / r
357 force(:, j) = force(:, j) - deidr * rij / r
381 use,
intrinsic :: iso_c_binding
385 type(kim_model_destroy_handle_type),
intent(inout) :: model_destroy_handle
386 integer(c_int),
intent(out) :: ierr
388 type(buffer_type),
pointer :: buf;
type(c_ptr) :: pbuf
390 call kim_get_model_buffer_pointer(model_destroy_handle, pbuf)
391 call c_f_pointer(pbuf, buf)
392 call kim_log_entry(model_destroy_handle, &
393 kim_log_verbosity_information, &
394 "deallocating model buffer")
405 model_compute_handle, model_compute_arguments_create_handle, ierr) bind(c)
406 use,
intrinsic :: iso_c_binding
410 type(kim_model_compute_handle_type),
intent(in) :: model_compute_handle
411 type(kim_model_compute_arguments_create_handle_type),
intent(inout) :: &
412 model_compute_arguments_create_handle
413 integer(c_int),
intent(out) :: ierr
415 integer(c_int) :: ierr2
418 if (model_compute_handle == kim_model_compute_null_handle)
continue 424 call kim_set_argument_support_status( &
425 model_compute_arguments_create_handle, &
426 kim_compute_argument_name_partial_energy, &
427 kim_support_status_optional, ierr2)
429 call kim_set_argument_support_status( &
430 model_compute_arguments_create_handle, &
431 kim_compute_argument_name_partial_forces, &
432 kim_support_status_optional, ierr2)
434 call kim_set_argument_support_status( &
435 model_compute_arguments_create_handle, &
436 kim_compute_argument_name_partial_particle_energy, &
437 kim_support_status_optional, ierr2)
439 call kim_set_argument_support_status( &
440 model_compute_arguments_create_handle, &
441 kim_compute_argument_name_partial_virial, &
442 kim_support_status_optional, ierr2)
450 call kim_log_entry( &
451 model_compute_arguments_create_handle, kim_log_verbosity_error, &
452 "Unable to successfully create compute_arguments object")
465 model_compute_handle, model_compute_arguments_destroy_handle, ierr) bind(c)
466 use,
intrinsic :: iso_c_binding
470 type(kim_model_compute_handle_type),
intent(in) :: model_compute_handle
471 type(kim_model_compute_arguments_destroy_handle_type),
intent(inout) :: &
472 model_compute_arguments_destroy_handle
473 integer(c_int),
intent(out) :: ierr
476 if (model_compute_handle == kim_model_compute_null_handle)
continue 477 if (model_compute_arguments_destroy_handle == &
478 kim_model_compute_arguments_destroy_null_handle)
continue 491 recursive subroutine model_create_routine( &
492 model_create_handle, requested_length_unit, requested_energy_unit, &
493 requested_charge_unit, requested_temperature_unit, requested_time_unit, &
495 use,
intrinsic :: iso_c_binding
501 type(kim_model_create_handle_type),
intent(inout) :: model_create_handle
502 type(kim_length_unit_type),
intent(in),
value :: requested_length_unit
503 type(kim_energy_unit_type),
intent(in),
value :: requested_energy_unit
504 type(kim_charge_unit_type),
intent(in),
value :: requested_charge_unit
505 type(kim_temperature_unit_type),
intent(in),
value :: &
506 requested_temperature_unit
507 type(kim_time_unit_type),
intent(in),
value :: requested_time_unit
508 integer(c_int),
intent(out) :: ierr
511 integer(c_int) :: ierr2
512 type(buffer_type),
pointer :: buf
518 if (requested_length_unit == kim_length_unit_unused)
continue 519 if (requested_energy_unit == kim_energy_unit_unused)
continue 520 if (requested_charge_unit == kim_charge_unit_unused)
continue 521 if (requested_temperature_unit == kim_temperature_unit_unused)
continue 522 if (requested_time_unit == kim_time_unit_unused)
continue 525 call kim_set_units(model_create_handle, &
527 kim_energy_unit_ev, &
528 kim_charge_unit_unused, &
529 kim_temperature_unit_unused, &
530 kim_time_unit_unused, &
535 call kim_set_species_code(model_create_handle, &
536 kim_species_name_ar,
speccode, ierr2)
540 call kim_set_model_numbering(model_create_handle, &
541 kim_numbering_one_based, ierr2)
545 call kim_set_routine_pointer( &
546 model_create_handle, &
547 kim_model_routine_name_compute, kim_language_name_fortran, &
550 call kim_set_routine_pointer( &
551 model_create_handle, kim_model_routine_name_compute_arguments_create, &
555 call kim_set_routine_pointer( &
556 model_create_handle, kim_model_routine_name_compute_arguments_destroy, &
560 call kim_set_routine_pointer( &
561 model_create_handle, &
562 kim_model_routine_name_destroy, kim_language_name_fortran, &
570 call kim_set_model_buffer_pointer(model_create_handle, &
576 buf%model_will_not_request_neighbors_of_noncontributing_particles = 1
579 call kim_set_influence_distance_pointer( &
580 model_create_handle, buf%influence_distance)
583 call kim_set_neighbor_list_pointers( &
584 model_create_handle, 1, buf%cutoff, &
585 buf%model_will_not_request_neighbors_of_noncontributing_particles)
590 call kim_log_entry(model_create_handle, kim_log_verbosity_error, &
591 "Unable to successfully initialize model")
597 end subroutine model_create_routine
recursive subroutine, public compute_energy_forces(model_compute_handle, model_compute_arguments_handle, ierr)
static void calc_phi_dphi(double const *epsilon, double const *C, double const *Rzero, double const *shift, double const cutoff, double const r, double *phi, double *dphi)
recursive subroutine, public model_destroy_func(model_destroy_handle, ierr)
recursive subroutine, public model_compute_arguments_create(model_compute_handle, model_compute_arguments_create_handle, ierr)
static void calc_phi(double const *epsilon, double const *C, double const *Rzero, double const *shift, double const cutoff, double const r, double *phi)
real(c_double), parameter, public model_cutoff
recursive subroutine, public model_compute_arguments_destroy(model_compute_handle, model_compute_arguments_destroy_handle, ierr)
integer(c_int), parameter, public speccode