diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index d05b5d8b00..033939551b 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -119,6 +119,8 @@ src/utils.* @akohlmey @rbberger tools/msi2lmp/* @akohlmey tools/emacs/* @HaoZeke tools/singularity/* @akohlmey @rbberger +tools/code_standard/* @rbberger +tools/valgrind/* @akohlmey # tests unittest/* @akohlmey @rbberger diff --git a/cmake/Modules/Packages/GPU.cmake b/cmake/Modules/Packages/GPU.cmake index d3a73100c0..dce28c305a 100644 --- a/cmake/Modules/Packages/GPU.cmake +++ b/cmake/Modules/Packages/GPU.cmake @@ -268,10 +268,17 @@ elseif(GPU_API STREQUAL "HIP") if(HIP_PLATFORM STREQUAL "hcc") configure_file(${CU_FILE} ${CU_CPP_FILE} COPYONLY) - add_custom_command(OUTPUT ${CUBIN_FILE} - VERBATIM COMMAND ${HIP_HIPCC_EXECUTABLE} --genco -t="${HIP_ARCH}" -f=\"-O3 -ffast-math -DUSE_HIP -D_${GPU_PREC_SETTING} -I${LAMMPS_LIB_SOURCE_DIR}/gpu\" -o ${CUBIN_FILE} ${CU_CPP_FILE} - DEPENDS ${CU_CPP_FILE} - COMMENT "Generating ${CU_NAME}.cubin") + if(HIP_COMPILER STREQUAL "clang") + add_custom_command(OUTPUT ${CUBIN_FILE} + VERBATIM COMMAND ${HIP_HIPCC_EXECUTABLE} --genco --offload-arch=${HIP_ARCH} -O3 -ffast-math -DUSE_HIP -D_${GPU_PREC_SETTING} -I${LAMMPS_LIB_SOURCE_DIR}/gpu -o ${CUBIN_FILE} ${CU_CPP_FILE} + DEPENDS ${CU_CPP_FILE} + COMMENT "Generating ${CU_NAME}.cubin") + else() + add_custom_command(OUTPUT ${CUBIN_FILE} + VERBATIM COMMAND ${HIP_HIPCC_EXECUTABLE} --genco -t="${HIP_ARCH}" -f=\"-O3 -ffast-math -DUSE_HIP -D_${GPU_PREC_SETTING} -I${LAMMPS_LIB_SOURCE_DIR}/gpu\" -o ${CUBIN_FILE} ${CU_CPP_FILE} + DEPENDS ${CU_CPP_FILE} + COMMENT "Generating ${CU_NAME}.cubin") + endif() elseif(HIP_PLATFORM STREQUAL "nvcc") add_custom_command(OUTPUT ${CUBIN_FILE} VERBATIM COMMAND ${HIP_HIPCC_EXECUTABLE} --fatbin --use_fast_math -DUSE_HIP -D_${GPU_PREC_SETTING} ${HIP_CUDA_GENCODE} -I${LAMMPS_LIB_SOURCE_DIR}/gpu -o ${CUBIN_FILE} ${CU_FILE} diff --git a/cmake/Modules/Packages/USER-INTEL.cmake b/cmake/Modules/Packages/USER-INTEL.cmake index 0ae1ec018a..ff0858f0ff 100644 --- a/cmake/Modules/Packages/USER-INTEL.cmake +++ b/cmake/Modules/Packages/USER-INTEL.cmake @@ -77,7 +77,7 @@ else() foreach(_FLAG -O2 -fp-model fast=2 -no-prec-div -qoverride-limits -qopt-zmm-usage=high -qno-offload -fno-alias -ansi-alias -restrict) check_cxx_compiler_flag("${_FLAG}" COMPILER_SUPPORTS${_FLAG}) if(COMPILER_SUPPORTS${_FLAG}) - target_compile_options(lammps PRIVATE ${_FLAG}) + target_compile_options(lammps PRIVATE ${_FLAG}) endif() endforeach() endif() diff --git a/doc/lammps.1 b/doc/lammps.1 index 4624403a67..d8617ce550 100644 --- a/doc/lammps.1 +++ b/doc/lammps.1 @@ -1,4 +1,4 @@ -.TH LAMMPS "15 June 2020" "2020-06-15" +.TH LAMMPS "30 June 2020" "2020-06-30" .SH NAME .B LAMMPS \- Molecular Dynamics Simulator. diff --git a/doc/src/Speed_gpu.rst b/doc/src/Speed_gpu.rst index 9981b22b03..647e40c28f 100644 --- a/doc/src/Speed_gpu.rst +++ b/doc/src/Speed_gpu.rst @@ -88,7 +88,7 @@ GPUs/node to 1. Using the "-pk" switch explicitly allows for setting of the number of GPUs/node to use and additional options. Its syntax is the same as -same as the "package gpu" command. See the :doc:`package ` +the "package gpu" command. See the :doc:`package ` command doc page for details, including the default values used for all its options if it is not specified. diff --git a/doc/src/compute_orientorder_atom.rst b/doc/src/compute_orientorder_atom.rst index a68aa563ec..22cf8b066c 100644 --- a/doc/src/compute_orientorder_atom.rst +++ b/doc/src/compute_orientorder_atom.rst @@ -61,8 +61,8 @@ The summation is over the *nnn* nearest neighbors of the central atom. The angles :math:`theta` and :math:`phi` are the standard spherical polar angles defining the direction of the bond vector :math:`r_{ij}`. -The phase and sign of :math:`Y_{lm}` follow the standard conventions, -so that :math:`{\rm sign}(Y_{ll}(0,0)) = (-1)^l`. +The phase and sign of :math:`Y_{lm}` follow the standard conventions, +so that :math:`{\rm sign}(Y_{ll}(0,0)) = (-1)^l`. The second equation defines :math:`Q_l`, which is a rotationally invariant non-negative amplitude obtained by summing over all the components of degree *l*\ . @@ -181,13 +181,13 @@ values for each atom will be added to the output array, which are real numbers. If the keyword *components* is set, then the real and imaginary parts of each component of *normalized* :math:`\hat{Y}_{lm}` will be added to the -output array in the following order: :math:`{\rm Re}(\hat{Y}_{-m}), {\rm Im}(\hat{Y}_{-m}), -{\rm Re}(\hat{Y}_{-m+1}), {\rm Im}(\hat{Y}_{-m+1}), \dots , {\rm Re}(\hat{Y}_m), {\rm Im}(\hat{Y}_m)`. +output array in the following order: :math:`{\rm Re}(\hat{Y}_{-m}), {\rm Im}(\hat{Y}_{-m}), +{\rm Re}(\hat{Y}_{-m+1}), {\rm Im}(\hat{Y}_{-m+1}), \dots , {\rm Re}(\hat{Y}_m), {\rm Im}(\hat{Y}_m)`. In summary, the per-atom array will contain *nlvalues* columns, followed by an additional *nlvalues* columns if *wl* is set to yes, followed by an additional *nlvalues* columns if *wl/hat* is set to yes, followed -by an additional 2\*(2\* *ldegree*\ +1) columns if the *components* +by an additional 2\*(2\* *ldegree*\ +1) columns if the *components* keyword is set. These values can be accessed by any command that uses per-atom values diff --git a/doc/src/pair_coeff.rst b/doc/src/pair_coeff.rst index c42d79fe68..0f5d5f7cec 100644 --- a/doc/src/pair_coeff.rst +++ b/doc/src/pair_coeff.rst @@ -89,14 +89,20 @@ LAMMPS so long as they are in the format LAMMPS expects, as discussed on the individual doc pages. The first line of potential files may contain metadata with upper case tags followed their value. These may be parsed and used by LAMMPS. Currently supported are the "DATE:" -tag and the "UNITS:" tag. For pair styles that have been programmed +tag and the ``UNITS:`` tag. For pair styles that have been programmed to support the metadata, the value of the "DATE:" tag is printed to the screen and logfile so that the version of a potential file can be -later identified. The "UNITS:" tag indicates the :doc:`units ` +later identified. The ``UNITS:`` tag indicates the :doc:`units ` setting required for this particular potential file. If the potential -file ware created for a different sets of units, LAMMPS will terminate +file was created for a different sets of units, LAMMPS will terminate with an error. If the potential file does not contain the tag, no -check will be made. +check will be made and it is the responsibility of the user to determine +that the unit style is correct. + +In some select cases and for specific combinations of unit styles, +LAMMPS is capable of automatically converting potential parameters +from a file. In those cases, a warning message signaling that an +automatic conversion has happened is printed to the screen. When a pair_coeff command using a potential file is specified, LAMMPS looks for the potential file in 2 places. First it looks in the diff --git a/doc/src/pair_eam.rst b/doc/src/pair_eam.rst index 50b55084c2..c5ef02f849 100644 --- a/doc/src/pair_eam.rst +++ b/doc/src/pair_eam.rst @@ -76,7 +76,7 @@ Examples pair_style eam pair_coeff * * cuu3 - pair_coeff 1*3 1\*3 niu3.eam + pair_coeff 1*3 1*3 niu3.eam pair_style eam/alloy pair_coeff * * ../potentials/NiAlH_jea.eam.alloy Ni Al Ni Ni diff --git a/doc/src/pair_eim.rst b/doc/src/pair_eim.rst index 1cea2f0993..107edda78d 100644 --- a/doc/src/pair_eim.rst +++ b/doc/src/pair_eim.rst @@ -48,7 +48,7 @@ and :math:`sigma_i` are calculated as \sigma_i = & \sum_{j=i_1}^{i_N} q_j \cdot \psi_{ij} \left(r_{ij}\right) \\ E_i\left(q_i,\sigma_i\right) = & \frac{1}{2} \cdot q_i \cdot \sigma_i -where :math:`\eta_{ji} is a pairwise function describing electron flow from atom +where :math:`\eta_{ji}` is a pairwise function describing electron flow from atom I to atom J, and :math:`\psi_{ij}` is another pairwise function. The multi-body nature of the EIM potential is a result of the embedding energy term. A complete list of all the pair functions used in EIM is summarized @@ -63,7 +63,7 @@ below \right.\\ \eta_{ji} = & A_{\eta,ij}\left(\chi_j-\chi_i\right)f_c\left(r,r_{s,\eta,ij},r_{c,\eta,ij}\right) \\ \psi_{ij}\left(r\right) = & A_{\psi,ij}\exp\left(-\zeta_{ij}r\right)f_c\left(r,r_{s,\psi,ij},r_{c,\psi,ij}\right) \\ - f_{c}\left(r,r_p,r_c\right) = & 0.510204 \mathrm{erfc}\left[\frac{1.64498\left(2r-r_p-r_c\right)}{r_c-r_p}\right] - 0.010204 + f_{c}\left(r,r_p,r_c\right) = & 0.510204 \cdot \mathrm{erfc}\left[\frac{1.64498\left(2r-r_p-r_c\right)}{r_c-r_p}\right] - 0.010204 Here :math:`E_b, r_e, r_(c,\phi), \alpha, \beta, A_(\psi), \zeta, r_(s,\psi), r_(c,\psi), A_(\eta), r_(s,\eta), r_(c,\eta), \chi,` and pair function type diff --git a/doc/src/pair_mliap.rst b/doc/src/pair_mliap.rst index d4fd897b95..d96e35a7f4 100644 --- a/doc/src/pair_mliap.rst +++ b/doc/src/pair_mliap.rst @@ -28,7 +28,7 @@ Examples .. code-block:: LAMMPS pair_style mliap model linear InP.mliap.model descriptor sna InP.mliap.descriptor - pair_style mliap model quadratic W.mliap.model descriptor sna W.mliap.descriptor + pair_style mliap model quadratic W.mliap.model descriptor sna W.mliap.descriptor pair_coeff * * In P Description @@ -38,9 +38,9 @@ Pair style *mliap* provides a general interface to families of machine-learning interatomic potentials. It allows separate definitions of the interatomic potential functional form (*model*) and the geometric quantities that characterize the atomic positions -(*descriptor*). By defining *model* and *descriptor* separately, +(*descriptor*). By defining *model* and *descriptor* separately, it is possible to use many different models with a given descriptor, -or many different descriptors with a given model. Currently, the pair_style +or many different descriptors with a given model. Currently, the pair_style supports just two models, *linear* and *quadratic*, and one descriptor, *sna*, the SNAP descriptor used by :doc:`pair_style snap `, including the linear, quadratic, and chem variants. Work is currently underway to extend @@ -52,11 +52,11 @@ can be accessed using the related :doc:`compute mliap ` command. The pair_style *mliap* command must be followed by two keywords *model* and *descriptor* in either order. A single -*pair_coeff* command is also required. The first 2 arguments +*pair_coeff* command is also required. The first 2 arguments must be \* \* so as to span all LAMMPS atom types. This is followed by a list of N arguments that specify the mapping of MLIAP -element names to LAMMPS atom types, +element names to LAMMPS atom types, where N is the number of LAMMPS atom types. The *model* keyword is followed by a model style, currently limited to @@ -68,7 +68,7 @@ It may contain parameters for many elements. The only requirement is that it contain at least those element names appearing in the *pair_coeff* command. -The top of the model file can contain any number of blank and comment lines (start with #), +The top of the model file can contain any number of blank and comment lines (start with #), but follows a strict format after that. The first non-blank non-comment line must contain two integers: @@ -79,20 +79,20 @@ This is followed by one block for each of the *nelem* elements. Each block consists of *nparams* parameters, one per line. Note that this format is similar, but not identical to that used for the :doc:`pair_style snap ` coefficient file. -Specifically, the line containing the element weight and radius is omitted, +Specifically, the line containing the element weight and radius is omitted, since these are handled by the *descriptor*. The *descriptor* keyword is followed by a descriptor style, and additional arguments. -Currently the only descriptor style is *sna*, indicating the bispectrum component -descriptors used by the Spectral Neighbor Analysis Potential (SNAP) potentials of +Currently the only descriptor style is *sna*, indicating the bispectrum component +descriptors used by the Spectral Neighbor Analysis Potential (SNAP) potentials of :doc:`pair_style snap `. -The \'p\' in SNAP is dropped, because keywords that match pair_styles are silently stripped -out by the LAMMPS command parser. A single additional argument specifies the descriptor filename -containing the parameters and setting used by the SNAP descriptor. +The \'p\' in SNAP is dropped, because keywords that match pair_styles are silently stripped +out by the LAMMPS command parser. A single additional argument specifies the descriptor filename +containing the parameters and setting used by the SNAP descriptor. The descriptor filename usually ends in the *.mliap.descriptor* extension. -The SNAP descriptor file closely follows the format of the -:doc:`pair_style snap ` parameter file. +The SNAP descriptor file closely follows the format of the +:doc:`pair_style snap ` parameter file. The file can contain blank and comment lines (start with #) anywhere. Each non-blank non-comment line must contain one keyword/value pair. The required keywords are *rcutfac* and @@ -102,7 +102,7 @@ In addition, the SNAP descriptor file must contain the *nelems*, *elems*, *radelems*, and *welems* keywords. The *nelems* keyword specifies the number of elements provided in the other three keywords. -The *elems* keyword is followed by a list of *nelems* +The *elems* keyword is followed by a list of *nelems* element names that must include the element names appearing in the *pair_coeff* command, but can contain other names too. diff --git a/doc/src/pair_snap.rst b/doc/src/pair_snap.rst index a46df30609..0ff6f1dfcc 100644 --- a/doc/src/pair_snap.rst +++ b/doc/src/pair_snap.rst @@ -25,9 +25,9 @@ Description """"""""""" Pair style *snap* defines the spectral -neighbor analysis potential (SNAP), a machine-learning +neighbor analysis potential (SNAP), a machine-learning interatomic potential :ref:`(Thompson) `. -Like the GAP framework of Bartok et al. :ref:`(Bartok2010) `, +Like the GAP framework of Bartok et al. :ref:`(Bartok2010) `, SNAP uses bispectrum components to characterize the local neighborhood of each atom in a very general way. The mathematical definition of the @@ -139,7 +139,7 @@ The SNAP parameter file can contain blank and comment lines (start with #) anywhere. Each non-blank non-comment line must contain one keyword/value pair. The required keywords are *rcutfac* and *twojmax*\ . Optional keywords are *rfac0*\ , *rmin0*\ , -*switchflag*\ , *bzeroflag*\ , *quadraticflag*\ , *chemflag*\ , +*switchflag*\ , *bzeroflag*\ , *quadraticflag*\ , *chemflag*\ , *bnormflag*\ , *wselfallflag*\ , and *chunksize*\ . The default values for these keywords are @@ -154,34 +154,34 @@ The default values for these keywords are * *wselfallflag* = 0 * *chunksize* = 2000 -If *quadraticflag* is set to 1, then the SNAP energy expression includes additional quadratic terms +If *quadraticflag* is set to 1, then the SNAP energy expression includes additional quadratic terms that have been shown to increase the overall accuracy of the potential without much increase -in computational cost :ref:`(Wood) `. +in computational cost :ref:`(Wood) `. .. math:: E^i_{SNAP}(\mathbf{B}^i) = \beta^{\mu_i}_0 + \boldsymbol{\beta}^{\mu_i} \cdot \mathbf{B}_i + \frac{1}{2}\mathbf{B}^t_i \cdot \boldsymbol{\alpha}^{\mu_i} \cdot \mathbf{B}_i -where :math:`\mathbf{B}_i` is the *K*-vector of bispectrum components, -:math:`\boldsymbol{\beta}^{\mu_i}` is the *K*-vector of linear coefficients -for element :math:`\mu_i`, and :math:`\boldsymbol{\alpha}^{\mu_i}` +where :math:`\mathbf{B}_i` is the *K*-vector of bispectrum components, +:math:`\boldsymbol{\beta}^{\mu_i}` is the *K*-vector of linear coefficients +for element :math:`\mu_i`, and :math:`\boldsymbol{\alpha}^{\mu_i}` is the symmetric *K* by *K* matrix of quadratic coefficients. The SNAP element file should contain *K*\ (\ *K*\ +1)/2 additional coefficients for each element, the upper-triangular elements of :math:`\boldsymbol{\alpha}^{\mu_i}`. If *chemflag* is set to 1, then the energy expression is written in terms of explicit multi-element bispectrum components indexed on ordered triplets of elements, which has been shown to increase the ability of the SNAP -potential to capture energy differences in chemically complex systems, +potential to capture energy differences in chemically complex systems, at the expense of a significant increase in computational cost :ref:`(Cusentino) `. .. math:: - E^i_{SNAP}(\mathbf{B}^i) = \beta^{\mu_i}_0 + \sum_{\kappa,\lambda,\mu} \boldsymbol{\beta}^{\kappa\lambda\mu}_{\mu_i} \cdot \mathbf{B}^{\kappa\lambda\mu}_i + E^i_{SNAP}(\mathbf{B}^i) = \beta^{\mu_i}_0 + \sum_{\kappa,\lambda,\mu} \boldsymbol{\beta}^{\kappa\lambda\mu}_{\mu_i} \cdot \mathbf{B}^{\kappa\lambda\mu}_i -where :math:`\mathbf{B}^{\kappa\lambda\mu}_i` is the *K*-vector of bispectrum components -for neighbors of elements :math:`\kappa`, :math:`\lambda`, and :math:`\mu` and -:math:`\boldsymbol{\beta}^{\kappa\lambda\mu}_{\mu_i}` is the corresponding *K*-vector -of linear coefficients for element :math:`\mu_i`. The SNAP element file should contain +where :math:`\mathbf{B}^{\kappa\lambda\mu}_i` is the *K*-vector of bispectrum components +for neighbors of elements :math:`\kappa`, :math:`\lambda`, and :math:`\mu` and +:math:`\boldsymbol{\beta}^{\kappa\lambda\mu}_{\mu_i}` is the corresponding *K*-vector +of linear coefficients for element :math:`\mu_i`. The SNAP element file should contain a total of :math:`K N_{elem}^3` coefficients for each of the :math:`N_{elem}` elements. The keyword *chunksize* is only applicable when using the diff --git a/doc/src/pair_tersoff_mod.rst b/doc/src/pair_tersoff_mod.rst index 7c969ad490..333f4a21bc 100644 --- a/doc/src/pair_tersoff_mod.rst +++ b/doc/src/pair_tersoff_mod.rst @@ -74,7 +74,7 @@ formulation of the V_ij term, where it contains an additional c0 term. .. math:: - V_{ij} & = f_C(r_{ij}) \left[ f_R(r_{ij}) + b_{ij} f_A(r_{ij}) + c_0 \right] + V_{ij} = f_C(r_{ij}) \left[ f_R(r_{ij}) + b_{ij} f_A(r_{ij}) + c_0 \right] The modified cutoff function :math:`f_C` proposed by :ref:`(Murty) ` and having a continuous second-order differential is employed. The diff --git a/doc/src/units.rst b/doc/src/units.rst index 65638b541a..ffcdde85f4 100644 --- a/doc/src/units.rst +++ b/doc/src/units.rst @@ -49,6 +49,15 @@ new units. And you must correctly convert all output from the new units to the old units when comparing to the original results. That is often not simple to do. +Potential or table files may have a ``UNITS:`` tag included in the +first line indicating the unit style those files were created for. +If the tag exists, its value will be compared to the chosen unit style +and LAMMPS will stop with an error message if there is a mismatch. +In some select cases and for specific combinations of unit styles, +LAMMPS is capable of automatically converting potential parameters +from a file. In those cases, a warning message signaling that an +automatic conversion has happened is printed to the screen. + ---------- For style *lj*\ , all quantities are unitless. Without loss of diff --git a/doc/utils/sphinx-config/false_positives.txt b/doc/utils/sphinx-config/false_positives.txt index 9f188bd2f8..1cc94328e8 100644 --- a/doc/utils/sphinx-config/false_positives.txt +++ b/doc/utils/sphinx-config/false_positives.txt @@ -1760,6 +1760,7 @@ mem memalign MEMALIGN membered +memcheck Mendelev mer Meremianin diff --git a/examples/README b/examples/README index dbb9623e3f..c840ede803 100644 --- a/examples/README +++ b/examples/README @@ -88,6 +88,7 @@ melt: rapid melt of 3d LJ system message: client/server coupling of 2 codes micelle: self-assembly of small lipid-like molecules into 2d bilayers min: energy minimization of 2d LJ melt +mliap: examples for using several bundled MLIAP potentials mscg: parameterize a multi-scale coarse-graining (MSCG) model msst: MSST shock dynamics nb3b: use of nonbonded 3-body harmonic pair style diff --git a/examples/USER/qtb/alpha_quartz_qbmsst/alpha_quartz_potential.mod b/examples/USER/qtb/alpha_quartz_qbmsst/alpha_quartz_potential.mod index 277907d907..1074ac6bb4 100644 --- a/examples/USER/qtb/alpha_quartz_qbmsst/alpha_quartz_potential.mod +++ b/examples/USER/qtb/alpha_quartz_qbmsst/alpha_quartz_potential.mod @@ -1,15 +1,15 @@ #This script implements the BKS pair potential for various silicon dioxide compounds. Inner part is fixed with a harmonic potential. Long range Coulomb interactions are evaluated with the pppm method. #Pair Potentials -pair_style hybrid/overlay buck/coul/long ${cut_off} table linear 39901 -pair_coeff 1 1 buck/coul/long 0.0 1.0 0.0 #No interactions between Si atoms -pair_coeff 1 2 buck/coul/long 18003.757200 0.205205 133.538100 -pair_coeff 2 2 buck/coul/long 1388.773000 0.362319 175.000000 #BKS interaction in PRL 64 1955 (1990) -pair_modify shift yes -pair_coeff 1 2 table potential_SiO2.TPF Si-O ${cut_off} -pair_coeff 2 2 table potential_SiO2.TPF O-O ${cut_off} #See the potential file for more information -kspace_style pppm 1.0e-4 +pair_style hybrid/overlay buck/coul/long ${cut_off} table linear 39901 +pair_coeff 1 1 buck/coul/long 0.0 1.0 0.0 #No interactions between Si atoms +pair_coeff 1 2 buck/coul/long 18003.757200 0.205205 133.538100 +pair_coeff 2 2 buck/coul/long 1388.773000 0.362319 175.000000 #BKS interaction in PRL 64 1955 (1990) +pair_modify shift yes +pair_coeff 1 2 table potential_SiO2.TPF Si-O ${cut_off} +pair_coeff 2 2 table potential_SiO2.TPF O-O ${cut_off} #See the potential file for more information +kspace_style pppm 1.0e-4 #Neighbor style -neighbor 2.0 bin -neigh_modify check yes every 1 delay 0 page 100000 one 2000 +neighbor 2.0 bin +neigh_modify check yes every 1 delay 0 page 100000 one 2000 diff --git a/examples/USER/qtb/alpha_quartz_qbmsst/alpha_quartz_qbmsst.in b/examples/USER/qtb/alpha_quartz_qbmsst/alpha_quartz_qbmsst.in deleted file mode 100644 index a8479b87ef..0000000000 --- a/examples/USER/qtb/alpha_quartz_qbmsst/alpha_quartz_qbmsst.in +++ /dev/null @@ -1,55 +0,0 @@ -## This script first uses fix qtb to equilibrate alpha quartz structure to an initial state with quantum nuclear correction and then simulate shock induced phase transition through the quantum thermal bath multi-scale shock technique -variable x_rep equal 2 #plot is made with x_rep = 8 #x-direction replication number -variable y_rep equal 1 #plot is made with y_rep = 5 #y-direction replication number -variable z_rep equal 4 #plot is made with z_rep = 15 #z-direction replication number -variable cut_off equal 10.0 #Cut-off distance for the Buckingham term (Angstrom in metal units) -variable pressure equal 1.03125 #Initial state pressure (bar in metal units) -variable temperature equal 300.0 #Initial state quantum temperature (K in metal units) -variable delta_t equal 1.0e-3 #MD timestep length (ps in metal units) -variable damp_qtb equal 1 #1/gamma where gamma is the friction coefficient in quantum thermal bath (ps in metal units) -variable v_msst equal 78.0 #Shock velocity (Angstrom/ps in metal units) -variable q_msst equal 40.0 #Box mass-like parameter in the MSST (mass^2/length^4, where mass=grams/mole and length=Angstrom in metal units) -variable tscale_msst equal 0.05 #Temperature reduction parameter in the MSST (unitless) -variable eta_qbmsst equal 1.0 #Coupling constant between the shock and the quantum thermal bath (unitless constant) - - -## This part uses fix qtb to prepare alpha-quartz with quantum nuclear correction of the initial state -include alpha_quartz_qtb.mod - - -## This part demonstrates how to retart fix qbmsst during any stage of the shock simulation. -## PPPM may break down when compression ratio becomes extremely large. One can always use this restart technique to resume the shock simulation. -#Compression restart 1 -reset_timestep 0 -#Beta is the number of time steps between each update of the quantum bath temperature. Setting a larger beta can reduce thermal flactuations. -fix shock all qbmsst z ${v_msst} q ${q_msst} tscale ${tscale_msst} damp ${damp_qtb} f_max 120 N_f 100 seed 35082 eta ${eta_qbmsst} beta 5 T_init ${temperature} -fix_modify shock energy yes -variable dhug equal f_shock[1] -variable dray equal f_shock[2] -variable lgr_vel equal f_shock[3] -variable lgr_pos equal f_shock[4] -variable T_qm equal f_shock[5] #Temperature with quantum nuclear correction -thermo_style custom step v_T_qm press etotal vol lx ly lz pzz v_dhug v_dray v_lgr_vel v_lgr_pos -thermo 100 -timestep ${delta_t} -run 1000 -write_restart restart.1000 - -#Compression restart 2 -#Read restart file and load potential again -clear -read_restart restart.1000 -include alpha_quartz_potential.mod -#Use the same fix id and add no tscale if the system is already compressed -fix shock all qbmsst z ${v_msst} q ${q_msst} tscale 0.0 damp ${damp_qtb} f_max 120 N_f 100 seed 35082 eta ${eta_qbmsst} beta 5 T_init ${temperature} -fix_modify shock energy yes -variable dhug equal f_shock[1] -variable dray equal f_shock[2] -variable lgr_vel equal f_shock[3] -variable lgr_pos equal f_shock[4] -variable T_qm equal f_shock[5] #Temperature with quantum nuclear correction -thermo_style custom step v_T_qm press etotal vol lx ly lz pzz v_dhug v_dray v_lgr_vel v_lgr_pos -thermo 100 -timestep ${delta_t} -restart 1000 restart -run 10000 #10 ps diff --git a/examples/USER/qtb/alpha_quartz_qbmsst/alpha_quartz_qtb.mod b/examples/USER/qtb/alpha_quartz_qbmsst/alpha_quartz_qtb.mod index e28624efeb..5ddcc078b0 100644 --- a/examples/USER/qtb/alpha_quartz_qbmsst/alpha_quartz_qtb.mod +++ b/examples/USER/qtb/alpha_quartz_qbmsst/alpha_quartz_qtb.mod @@ -3,60 +3,60 @@ ## This part defines units, alpha-quartz crystal, and atomic information #General -units metal -dimension 3 -boundary p p p -atom_style charge +units metal +dimension 3 +boundary p p p +atom_style charge #Lattice -lattice custom 1.0 & - a1 4.916000 0.000000 0.000000 & - a2 -2.45800 4.257381 0.000000 & - a3 0.000000 0.000000 5.405400 & - & - basis 0.469700 0.000000 0.000000 & - basis 0.000000 0.469700 0.666667 & - basis 0.530300 0.530300 0.333333 & - & - basis 0.413500 0.266900 0.119100 & - basis 0.266900 0.413500 0.547567 & - basis 0.733100 0.146600 0.785767 & - basis 0.586500 0.853400 0.214233 & - basis 0.853400 0.586500 0.452433 & - basis 0.146600 0.733100 0.880900 #American Mineralogist 65 920 1980 (Space Group 154) +lattice custom 1.0 & + a1 4.916000 0.000000 0.000000 & + a2 -2.45800 4.257381 0.000000 & + a3 0.000000 0.000000 5.405400 & + & + basis 0.469700 0.000000 0.000000 & + basis 0.000000 0.469700 0.666667 & + basis 0.530300 0.530300 0.333333 & + & + basis 0.413500 0.266900 0.119100 & + basis 0.266900 0.413500 0.547567 & + basis 0.733100 0.146600 0.785767 & + basis 0.586500 0.853400 0.214233 & + basis 0.853400 0.586500 0.452433 & + basis 0.146600 0.733100 0.880900 #American Mineralogist 65 920 1980 (Space Group 154) #Computational Cell -region orthorhombic_unit_cell block 0 4.916000 0 8.514762 0 5.405400 units box -create_box 2 orthorhombic_unit_cell -create_atoms 1 box & - basis 1 1 & - basis 2 1 & - basis 3 1 & - basis 4 2 & - basis 5 2 & - basis 6 2 & - basis 7 2 & - basis 8 2 & - basis 9 2 -replicate ${x_rep} ${y_rep} ${z_rep} +region orthorhombic_unit_cell block 0 4.916000 0 8.514762 0 5.405400 units box +create_box 2 orthorhombic_unit_cell +create_atoms 1 box & + basis 1 1 & + basis 2 1 & + basis 3 1 & + basis 4 2 & + basis 5 2 & + basis 6 2 & + basis 7 2 & + basis 8 2 & + basis 9 2 +replicate ${x_rep} ${y_rep} ${z_rep} #Atomic Information -mass 1 28.085500 -mass 2 15.999400 -set type 1 charge +2.4 -set type 2 charge -1.2 +mass 1 28.085500 +mass 2 15.999400 +set type 1 charge +2.4 +set type 2 charge -1.2 ## This part implements the BKS pair potential with a cut-off distance for the Buckingham term. Long range Coulomb interactions are evaluated with the pppm method. -include alpha_quartz_potential.mod +include alpha_quartz_potential.mod ## This part equilibrates your crystal to a pressure of ${pressure}(unit pressure) and a temperature of ${temperature}(unit temperatureture) with quantum nuclear effects -variable p_damp equal ${delta_t}*1000 #Recommended pressure damping parameter in fix nph -fix scapegoat_qtb all nph iso ${pressure} ${pressure} ${p_damp} #NPH does the time integration -fix quartz_qtb all qtb temp ${temperature} damp ${damp_qtb} seed 35082 f_max 120.00 N_f 100 #Change f_max (THz) if your Debye frequency is higher -thermo_style custom step temp press etotal vol lx ly lz pxx pyy pzz pxy pyz pxz -thermo 100 -run 2000 # 2 ps -unfix quartz_qtb -unfix scapegoat_qtb +variable p_damp equal ${delta_t}*1000 #Recommended pressure damping parameter in fix nph +fix scapegoat_qtb all nph iso ${pressure} ${pressure} ${p_damp} ptemp ${temperature} #NPH does the time integration +fix quartz_qtb all qtb temp ${temperature} damp ${damp_qtb} seed 35082 f_max 120.00 N_f 100 #Change f_max (THz) if your Debye frequency is higher +thermo_style custom step temp press etotal vol lx ly lz pxx pyy pzz pxy pyz pxz +thermo 200 +run 2000 # 2 ps +unfix quartz_qtb +unfix scapegoat_qtb diff --git a/examples/USER/qtb/alpha_quartz_qbmsst/in.alpha_quartz_qbmsst b/examples/USER/qtb/alpha_quartz_qbmsst/in.alpha_quartz_qbmsst new file mode 100644 index 0000000000..3ee0bd0ca5 --- /dev/null +++ b/examples/USER/qtb/alpha_quartz_qbmsst/in.alpha_quartz_qbmsst @@ -0,0 +1,55 @@ +## This script first uses fix qtb to equilibrate alpha quartz structure to an initial state with quantum nuclear correction and then simulate shock induced phase transition through the quantum thermal bath multi-scale shock technique +variable x_rep equal 2 #plot is made with x_rep = 8 #x-direction replication number +variable y_rep equal 1 #plot is made with y_rep = 5 #y-direction replication number +variable z_rep equal 4 #plot is made with z_rep = 15 #z-direction replication number +variable cut_off equal 10.0 #Cut-off distance for the Buckingham term (Angstrom in metal units) +variable pressure equal 1.03125 #Initial state pressure (bar in metal units) +variable temperature equal 300.0 #Initial state quantum temperature (K in metal units) +variable delta_t equal 1.0e-3 #MD timestep length (ps in metal units) +variable damp_qtb equal 1 #1/gamma where gamma is the friction coefficient in quantum thermal bath (ps in metal units) +variable v_msst equal 78.0 #Shock velocity (Angstrom/ps in metal units) +variable q_msst equal 40.0 #Box mass-like parameter in the MSST (mass^2/length^4, where mass=grams/mole and length=Angstrom in metal units) +variable tscale_msst equal 0.05 #Temperature reduction parameter in the MSST (unitless) +variable eta_qbmsst equal 1.0 #Coupling constant between the shock and the quantum thermal bath (unitless constant) + + +## This part uses fix qtb to prepare alpha-quartz with quantum nuclear correction of the initial state +include alpha_quartz_qtb.mod + + +## This part demonstrates how to retart fix qbmsst during any stage of the shock simulation. +## PPPM may break down when compression ratio becomes extremely large. One can always use this restart technique to resume the shock simulation. +#Compression restart 1 +reset_timestep 0 +#Beta is the number of time steps between each update of the quantum bath temperature. Setting a larger beta can reduce thermal flactuations. +fix shock all qbmsst z ${v_msst} q ${q_msst} tscale ${tscale_msst} damp ${damp_qtb} f_max 120 N_f 100 seed 35082 eta ${eta_qbmsst} beta 5 T_init ${temperature} +fix_modify shock energy yes +variable dhug equal f_shock[1] +variable dray equal f_shock[2] +variable lgr_vel equal f_shock[3] +variable lgr_pos equal f_shock[4] +variable T_qm equal f_shock[5] #Temperature with quantum nuclear correction +thermo_style custom step v_T_qm press etotal vol lx ly lz pzz v_dhug v_dray v_lgr_vel v_lgr_pos +thermo 200 +timestep ${delta_t} +run 1000 +write_restart restart.1000 + +#Compression restart 2 +#Read restart file and load potential again +clear +read_restart restart.1000 +include alpha_quartz_potential.mod +#Use the same fix id and add no tscale if the system is already compressed +fix shock all qbmsst z ${v_msst} q ${q_msst} tscale 0.0 damp ${damp_qtb} f_max 120 N_f 100 seed 35082 eta ${eta_qbmsst} beta 5 T_init ${temperature} +fix_modify shock energy yes +variable dhug equal f_shock[1] +variable dray equal f_shock[2] +variable lgr_vel equal f_shock[3] +variable lgr_pos equal f_shock[4] +variable T_qm equal f_shock[5] #Temperature with quantum nuclear correction +thermo_style custom step v_T_qm press etotal vol lx ly lz pzz v_dhug v_dray v_lgr_vel v_lgr_pos +thermo 500 +timestep ${delta_t} +restart 1000 restart +run 10000 #10 ps diff --git a/examples/USER/qtb/alpha_quartz_qbmsst/log.15Jun20.alpha_quartz_qbmsst.g++.1 b/examples/USER/qtb/alpha_quartz_qbmsst/log.15Jun20.alpha_quartz_qbmsst.g++.1 new file mode 100644 index 0000000000..cb5ebe31a9 --- /dev/null +++ b/examples/USER/qtb/alpha_quartz_qbmsst/log.15Jun20.alpha_quartz_qbmsst.g++.1 @@ -0,0 +1,430 @@ +LAMMPS (15 Jun 2020) + using 1 OpenMP thread(s) per MPI task +## This script first uses fix qtb to equilibrate alpha quartz structure to an initial state with quantum nuclear correction and then simulate shock induced phase transition through the quantum thermal bath multi-scale shock technique +variable x_rep equal 2 #plot is made with x_rep = 8 #x-direction replication number +variable y_rep equal 1 #plot is made with y_rep = 5 #y-direction replication number +variable z_rep equal 4 #plot is made with z_rep = 15 #z-direction replication number +variable cut_off equal 10.0 #Cut-off distance for the Buckingham term (Angstrom in metal units) +variable pressure equal 1.03125 #Initial state pressure (bar in metal units) +variable temperature equal 300.0 #Initial state quantum temperature (K in metal units) +variable delta_t equal 1.0e-3 #MD timestep length (ps in metal units) +variable damp_qtb equal 1 #1/gamma where gamma is the friction coefficient in quantum thermal bath (ps in metal units) +variable v_msst equal 78.0 #Shock velocity (Angstrom/ps in metal units) +variable q_msst equal 40.0 #Box mass-like parameter in the MSST (mass^2/length^4, where mass=grams/mole and length=Angstrom in metal units) +variable tscale_msst equal 0.05 #Temperature reduction parameter in the MSST (unitless) +variable eta_qbmsst equal 1.0 #Coupling constant between the shock and the quantum thermal bath (unitless constant) + + +## This part uses fix qtb to prepare alpha-quartz with quantum nuclear correction of the initial state +include alpha_quartz_qtb.mod +## This script first constructs an alpha quartz structure of a given size. It then uses fix qtb to equilibrate the computational cell to the specified temperature and pressure. + + +## This part defines units, alpha-quartz crystal, and atomic information +#General +units metal +dimension 3 +boundary p p p +atom_style charge + +#Lattice +lattice custom 1.0 a1 4.916000 0.000000 0.000000 a2 -2.45800 4.257381 0.000000 a3 0.000000 0.000000 5.405400 basis 0.469700 0.000000 0.000000 basis 0.000000 0.469700 0.666667 basis 0.530300 0.530300 0.333333 basis 0.413500 0.266900 0.119100 basis 0.266900 0.413500 0.547567 basis 0.733100 0.146600 0.785767 basis 0.586500 0.853400 0.214233 basis 0.853400 0.586500 0.452433 basis 0.146600 0.733100 0.880900 #American Mineralogist 65 920 1980 (Space Group 154) +Lattice spacing in x,y,z = 7.374 4.25738 5.4054 + +#Computational Cell +region orthorhombic_unit_cell block 0 4.916000 0 8.514762 0 5.405400 units box +create_box 2 orthorhombic_unit_cell +Created orthogonal box = (0.0 0.0 0.0) to (4.916 8.514762 5.4054) + 1 by 1 by 1 MPI processor grid +create_atoms 1 box basis 1 1 basis 2 1 basis 3 1 basis 4 2 basis 5 2 basis 6 2 basis 7 2 basis 8 2 basis 9 2 +Created 18 atoms + create_atoms CPU = 0.000 seconds +replicate ${x_rep} ${y_rep} ${z_rep} +replicate 2 ${y_rep} ${z_rep} +replicate 2 1 ${z_rep} +replicate 2 1 4 + orthogonal box = (0.0 0.0 0.0) to (9.832 8.514762 21.6216) + 1 by 1 by 1 MPI processor grid + 144 atoms + replicate CPU = 0.000271082 secs + +#Atomic Information +mass 1 28.085500 +mass 2 15.999400 +set type 1 charge +2.4 + 48 settings made for charge +set type 2 charge -1.2 + 96 settings made for charge + + +## This part implements the BKS pair potential with a cut-off distance for the Buckingham term. Long range Coulomb interactions are evaluated with the pppm method. +include alpha_quartz_potential.mod +#This script implements the BKS pair potential for various silicon dioxide compounds. Inner part is fixed with a harmonic potential. Long range Coulomb interactions are evaluated with the pppm method. + +#Pair Potentials +pair_style hybrid/overlay buck/coul/long ${cut_off} table linear 39901 +pair_style hybrid/overlay buck/coul/long 10 table linear 39901 +pair_coeff 1 1 buck/coul/long 0.0 1.0 0.0 #No interactions between Si atoms +pair_coeff 1 2 buck/coul/long 18003.757200 0.205205 133.538100 +pair_coeff 2 2 buck/coul/long 1388.773000 0.362319 175.000000 #BKS interaction in PRL 64 1955 (1990) +pair_modify shift yes +pair_coeff 1 2 table potential_SiO2.TPF Si-O ${cut_off} +pair_coeff 1 2 table potential_SiO2.TPF Si-O 10 +pair_coeff 2 2 table potential_SiO2.TPF O-O ${cut_off} #See the potential file for more information +pair_coeff 2 2 table potential_SiO2.TPF O-O 10 +WARNING: 1 of 39901 force values in table are inconsistent with -dE/dr. + Should only be flagged at inflection points (src/pair_table.cpp:471) +kspace_style pppm 1.0e-4 + +#Neighbor style +neighbor 2.0 bin +neigh_modify check yes every 1 delay 0 page 100000 one 2000 + + +## This part equilibrates your crystal to a pressure of ${pressure}(unit pressure) and a temperature of ${temperature}(unit temperatureture) with quantum nuclear effects +variable p_damp equal ${delta_t}*1000 #Recommended pressure damping parameter in fix nph +variable p_damp equal 0.001*1000 +fix scapegoat_qtb all nph iso ${pressure} ${pressure} ${p_damp} ptemp ${temperature} #NPH does the time integration +fix scapegoat_qtb all nph iso 1.03125 ${pressure} ${p_damp} ptemp ${temperature} +fix scapegoat_qtb all nph iso 1.03125 1.03125 ${p_damp} ptemp ${temperature} +fix scapegoat_qtb all nph iso 1.03125 1.03125 1 ptemp ${temperature} +fix scapegoat_qtb all nph iso 1.03125 1.03125 1 ptemp 300 +fix quartz_qtb all qtb temp ${temperature} damp ${damp_qtb} seed 35082 f_max 120.00 N_f 100 #Change f_max (THz) if your Debye frequency is higher +fix quartz_qtb all qtb temp 300 damp ${damp_qtb} seed 35082 f_max 120.00 N_f 100 +fix quartz_qtb all qtb temp 300 damp 1 seed 35082 f_max 120.00 N_f 100 +thermo_style custom step temp press etotal vol lx ly lz pxx pyy pzz pxy pyz pxz +thermo 200 +run 2000 # 2 ps +PPPM initialization ... + using 12-bit tables for long-range coulomb (src/kspace.cpp:332) + G vector (1/distance) = 0.301598 + grid = 9 8 15 + stencil order = 5 + estimated absolute RMS force accuracy = 0.00117056 + estimated relative force accuracy = 8.12908e-05 + using double precision FFTW3 + 3d grid and FFT values/proc = 5280 1080 +Neighbor list info ... + update every 1 steps, delay 0 steps, check yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 12 + ghost atom cutoff = 12 + binsize = 6, bins = 2 2 4 + 2 neighbor lists, perpetual/occasional/extra = 2 0 0 + (1) pair buck/coul/long, perpetual + attributes: half, newton on + pair build: half/bin/atomonly/newton + stencil: half/bin/3d/newton + bin: standard + (2) pair table, perpetual, skip from (1) + attributes: half, newton on + pair build: skip + stencil: none + bin: none +Per MPI rank memory allocation (min/avg/max) = 80.09 | 80.09 | 80.09 Mbytes +Step Temp Press TotEng Volume Lx Ly Lz Pxx Pyy Pzz Pxy Pyz Pxz + 0 0 -34026.791 -2793.6042 1810.0985 9.832 8.514762 21.6216 -37470.578 -37470.432 -27139.363 -6.4345368e-12 0.94245783 4.2212262e-10 + 200 170.7381 43248.332 -2790.8398 1879.164 9.9554912 8.6217086 21.89317 39337.624 42979.126 47428.246 324.91326 454.85872 -2034.6053 + 400 258.09921 -28257.8 -2788.3487 1856.1432 9.9146707 8.5863569 21.803402 -19478.873 -29571.375 -35723.152 4633.9026 8487.8103 -626.12005 + 600 277.77032 -22751.351 -2786.2715 1866.9783 9.9339253 8.6030319 21.845744 -21727.335 -29200.027 -17326.692 -4327.8571 -8218.4965 252.30681 + 800 349.8665 30508.003 -2784.2204 1873.4953 9.9454706 8.6130304 21.871134 29929.055 33562.672 28032.281 -3188.5605 12329.482 7558.5678 + 1000 373.67651 -18839.569 -2783.2178 1855.5937 9.9136922 8.5855095 21.80125 -18063.486 -22288.321 -16166.902 -416.09547 -10368.975 9030.4208 + 1200 423.3474 6846.9905 -2781.9271 1896.2131 9.9855083 8.6477041 21.959181 2147.3938 11765.857 6627.7202 -7627.6782 -1297.6517 -4758.4746 + 1400 418.54527 -6416.7506 -2781.4358 1834.2719 9.8755745 8.5524986 21.717425 5693.0543 -19487.901 -5455.405 827.66513 -523.1508 -3890.9919 + 1600 429.42796 3939.8836 -2780.5861 1895.8859 9.984934 8.6472068 21.957918 3755.6959 -1326.4343 9390.3893 1948.1153 4489.8629 1466.0914 + 1800 447.7623 -8344.6306 -2780.1071 1858.4925 9.9188518 8.5899779 21.812596 -17549.498 3336.8135 -10821.208 1643.4226 -644.56065 -8935.9666 + 2000 438.1306 -6691.4691 -2780.7407 1871.3547 9.9416812 8.6097487 21.862801 -6959.2196 -8486.8466 -4628.341 -1019.9006 443.03694 -2751.917 +Loop time of 2.46815 on 1 procs for 2000 steps with 144 atoms + +Performance: 70.012 ns/day, 0.343 hours/ns, 810.323 timesteps/s +99.8% CPU use with 1 MPI tasks x 1 OpenMP threads + +MPI task timing breakdown: +Section | min time | avg time | max time |%varavg| %total +--------------------------------------------------------------- +Pair | 2.0003 | 2.0003 | 2.0003 | 0.0 | 81.04 +Kspace | 0.20006 | 0.20006 | 0.20006 | 0.0 | 8.11 +Neigh | 0 | 0 | 0 | 0.0 | 0.00 +Comm | 0.023753 | 0.023753 | 0.023753 | 0.0 | 0.96 +Output | 0.0001986 | 0.0001986 | 0.0001986 | 0.0 | 0.01 +Modify | 0.23896 | 0.23896 | 0.23896 | 0.0 | 9.68 +Other | | 0.004907 | | | 0.20 + +Nlocal: 144 ave 144 max 144 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Nghost: 3943 ave 3943 max 3943 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Neighs: 41952 ave 41952 max 41952 min +Histogram: 1 0 0 0 0 0 0 0 0 0 + +Total # of neighbors = 41952 +Ave neighs/atom = 291.333 +Neighbor list builds = 0 +Dangerous builds = 0 +unfix quartz_qtb +unfix scapegoat_qtb + + +## This part demonstrates how to retart fix qbmsst during any stage of the shock simulation. +## PPPM may break down when compression ratio becomes extremely large. One can always use this restart technique to resume the shock simulation. +#Compression restart 1 +reset_timestep 0 +#Beta is the number of time steps between each update of the quantum bath temperature. Setting a larger beta can reduce thermal flactuations. +fix shock all qbmsst z ${v_msst} q ${q_msst} tscale ${tscale_msst} damp ${damp_qtb} f_max 120 N_f 100 seed 35082 eta ${eta_qbmsst} beta 5 T_init ${temperature} +fix shock all qbmsst z 78 q ${q_msst} tscale ${tscale_msst} damp ${damp_qtb} f_max 120 N_f 100 seed 35082 eta ${eta_qbmsst} beta 5 T_init ${temperature} +fix shock all qbmsst z 78 q 40 tscale ${tscale_msst} damp ${damp_qtb} f_max 120 N_f 100 seed 35082 eta ${eta_qbmsst} beta 5 T_init ${temperature} +fix shock all qbmsst z 78 q 40 tscale 0.05 damp ${damp_qtb} f_max 120 N_f 100 seed 35082 eta ${eta_qbmsst} beta 5 T_init ${temperature} +fix shock all qbmsst z 78 q 40 tscale 0.05 damp 1 f_max 120 N_f 100 seed 35082 eta ${eta_qbmsst} beta 5 T_init ${temperature} +fix shock all qbmsst z 78 q 40 tscale 0.05 damp 1 f_max 120 N_f 100 seed 35082 eta 1 beta 5 T_init ${temperature} +fix shock all qbmsst z 78 q 40 tscale 0.05 damp 1 f_max 120 N_f 100 seed 35082 eta 1 beta 5 T_init 300 +QBMSST parameters: + Shock in z direction + Cell mass-like parameter qmass (units of mass^2/length^4) = 4.00000e+01 + Shock velocity = 7.80000e+01 + Artificial viscosity (units of mass/length/time) = 0.00000e+00 + Initial pressure calculated on first step + Initial volume calculated on first step + Initial energy calculated on first step +fix_modify shock energy yes +variable dhug equal f_shock[1] +variable dray equal f_shock[2] +variable lgr_vel equal f_shock[3] +variable lgr_pos equal f_shock[4] +variable T_qm equal f_shock[5] #Temperature with quantum nuclear correction +thermo_style custom step v_T_qm press etotal vol lx ly lz pzz v_dhug v_dray v_lgr_vel v_lgr_pos +thermo 200 +timestep ${delta_t} +timestep 0.001 +run 1000 +PPPM initialization ... + using 12-bit tables for long-range coulomb (src/kspace.cpp:332) + G vector (1/distance) = 0.303132 + grid = 9 8 16 + stencil order = 5 + estimated absolute RMS force accuracy = 0.00104699 + estimated relative force accuracy = 7.27093e-05 + using double precision FFTW3 + 3d grid and FFT values/proc = 5520 1152 +Neighbor list info ... + update every 1 steps, delay 0 steps, check yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 12 + ghost atom cutoff = 12 + binsize = 6, bins = 2 2 4 + 2 neighbor lists, perpetual/occasional/extra = 2 0 0 + (1) pair buck/coul/long, perpetual + attributes: half, newton on + pair build: half/bin/atomonly/newton + stencil: half/bin/3d/newton + bin: standard + (2) pair table, perpetual, skip from (1) + attributes: half, newton on + pair build: skip + stencil: none + bin: none +Fix QBMSST v0 = 1.87135e+03 +Fix QBMSST p0 = -4.62948e+03 +Fix QBMSST e0 = to be -2.78074e+03 +Fix QBMSST initial strain rate of -4.01096e-01 established by reducing temperature by factor of 5.00000e-02 +Per MPI rank memory allocation (min/avg/max) = 80.1 | 80.1 | 80.1 Mbytes +Step v_T_qm Press TotEng Volume Lx Ly Lz Pzz v_dhug v_dray v_lgr_vel v_lgr_pos + 0 300 -6922.9433 -2780.7394 1871.3547 9.9416812 8.6097487 21.862801 -4819.9907 10.953265 -190.51273 0 0 + 200 294.95797 54876.416 -2779.2988 1723.7621 9.9416812 8.6097487 20.138495 108897.19 -29.773973 -9271.7281 6.1518102 -15.057867 + 400 288.3711 139521.03 -2778.7321 1628.5574 9.9416812 8.6097487 19.026231 222107.71 8.0682073 24727.575 10.120041 -28.714693 + 600 280.56521 98070.281 -2779.8934 1687.2434 9.9416812 8.6097487 19.711852 164558.51 2.6076928 16005.656 7.6739491 -42.705007 + 800 274.94701 106060.26 -2779.2916 1651.0723 9.9416812 8.6097487 19.289269 176842.6 -39.645354 -1804.9466 9.1815975 -56.628078 + 1000 268.47106 189695.34 -2779.4951 1492.6355 9.9416812 8.6097487 17.438272 277351.5 -84.834482 -33116.996 15.785409 -69.870519 +Loop time of 2.05219 on 1 procs for 1000 steps with 144 atoms + +Performance: 42.101 ns/day, 0.570 hours/ns, 487.284 timesteps/s +99.8% CPU use with 1 MPI tasks x 1 OpenMP threads + +MPI task timing breakdown: +Section | min time | avg time | max time |%varavg| %total +--------------------------------------------------------------- +Pair | 1.6815 | 1.6815 | 1.6815 | 0.0 | 81.94 +Kspace | 0.10373 | 0.10373 | 0.10373 | 0.0 | 5.05 +Neigh | 0.0061183 | 0.0061183 | 0.0061183 | 0.0 | 0.30 +Comm | 0.012444 | 0.012444 | 0.012444 | 0.0 | 0.61 +Output | 0.00014687 | 0.00014687 | 0.00014687 | 0.0 | 0.01 +Modify | 0.24529 | 0.24529 | 0.24529 | 0.0 | 11.95 +Other | | 0.002948 | | | 0.14 + +Nlocal: 144 ave 144 max 144 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Nghost: 4243 ave 4243 max 4243 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Neighs: 48210 ave 48210 max 48210 min +Histogram: 1 0 0 0 0 0 0 0 0 0 + +Total # of neighbors = 48210 +Ave neighs/atom = 334.792 +Neighbor list builds = 8 +Dangerous builds = 0 +write_restart restart.1000 +PPPM initialization ... + using 12-bit tables for long-range coulomb (src/kspace.cpp:332) + G vector (1/distance) = 0.306435 + grid = 9 8 15 + stencil order = 5 + estimated absolute RMS force accuracy = 0.000955688 + estimated relative force accuracy = 6.63689e-05 + using double precision FFTW3 + 3d grid and FFT values/proc = 5280 1080 +Neighbor list info ... + update every 1 steps, delay 0 steps, check yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 12 + ghost atom cutoff = 12 + binsize = 6, bins = 2 2 3 + 2 neighbor lists, perpetual/occasional/extra = 2 0 0 + (1) pair buck/coul/long, perpetual + attributes: half, newton on + pair build: half/bin/atomonly/newton + stencil: half/bin/3d/newton + bin: standard + (2) pair table, perpetual, skip from (1) + attributes: half, newton on + pair build: skip + stencil: none + bin: none + +#Compression restart 2 +#Read restart file and load potential again +clear + using 1 OpenMP thread(s) per MPI task +read_restart restart.1000 + restoring atom style charge from restart + orthogonal box = (-0.05484062286382799 -0.04749337384227555 2.0916641327653274) to (9.886840622863804 8.562255373842252 19.52993586723476) + 1 by 1 by 1 MPI processor grid + restoring pair style hybrid/overlay from restart + 144 atoms + read_restart CPU = 0.0002563 secs +include alpha_quartz_potential.mod +#This script implements the BKS pair potential for various silicon dioxide compounds. Inner part is fixed with a harmonic potential. Long range Coulomb interactions are evaluated with the pppm method. + +#Pair Potentials +pair_style hybrid/overlay buck/coul/long ${cut_off} table linear 39901 +pair_style hybrid/overlay buck/coul/long 10 table linear 39901 +pair_coeff 1 1 buck/coul/long 0.0 1.0 0.0 #No interactions between Si atoms +pair_coeff 1 2 buck/coul/long 18003.757200 0.205205 133.538100 +pair_coeff 2 2 buck/coul/long 1388.773000 0.362319 175.000000 #BKS interaction in PRL 64 1955 (1990) +pair_modify shift yes +pair_coeff 1 2 table potential_SiO2.TPF Si-O ${cut_off} +pair_coeff 1 2 table potential_SiO2.TPF Si-O 10 +pair_coeff 2 2 table potential_SiO2.TPF O-O ${cut_off} #See the potential file for more information +pair_coeff 2 2 table potential_SiO2.TPF O-O 10 +WARNING: 1 of 39901 force values in table are inconsistent with -dE/dr. + Should only be flagged at inflection points (src/pair_table.cpp:471) +kspace_style pppm 1.0e-4 + +#Neighbor style +neighbor 2.0 bin +neigh_modify check yes every 1 delay 0 page 100000 one 2000 +#Use the same fix id and add no tscale if the system is already compressed +fix shock all qbmsst z ${v_msst} q ${q_msst} tscale 0.0 damp ${damp_qtb} f_max 120 N_f 100 seed 35082 eta ${eta_qbmsst} beta 5 T_init ${temperature} +fix shock all qbmsst z 78 q ${q_msst} tscale 0.0 damp ${damp_qtb} f_max 120 N_f 100 seed 35082 eta ${eta_qbmsst} beta 5 T_init ${temperature} +fix shock all qbmsst z 78 q 40 tscale 0.0 damp ${damp_qtb} f_max 120 N_f 100 seed 35082 eta ${eta_qbmsst} beta 5 T_init ${temperature} +fix shock all qbmsst z 78 q 40 tscale 0.0 damp 1 f_max 120 N_f 100 seed 35082 eta ${eta_qbmsst} beta 5 T_init ${temperature} +fix shock all qbmsst z 78 q 40 tscale 0.0 damp 1 f_max 120 N_f 100 seed 35082 eta 1 beta 5 T_init ${temperature} +fix shock all qbmsst z 78 q 40 tscale 0.0 damp 1 f_max 120 N_f 100 seed 35082 eta 1 beta 5 T_init 300 +QBMSST parameters: + Shock in z direction + Cell mass-like parameter qmass (units of mass^2/length^4) = 4.00000e+01 + Shock velocity = 7.80000e+01 + Artificial viscosity (units of mass/length/time) = 0.00000e+00 + Initial pressure calculated on first step + Initial volume calculated on first step + Initial energy calculated on first step +Resetting global fix info from restart file: + fix style: qbmsst, fix ID: shock +fix_modify shock energy yes +variable dhug equal f_shock[1] +variable dray equal f_shock[2] +variable lgr_vel equal f_shock[3] +variable lgr_pos equal f_shock[4] +variable T_qm equal f_shock[5] #Temperature with quantum nuclear correction +thermo_style custom step v_T_qm press etotal vol lx ly lz pzz v_dhug v_dray v_lgr_vel v_lgr_pos +thermo 500 +timestep ${delta_t} +timestep 0.001 +restart 1000 restart +run 10000 #10 ps +PPPM initialization ... + using 12-bit tables for long-range coulomb (src/kspace.cpp:332) + G vector (1/distance) = 0.306435 + grid = 9 8 15 + stencil order = 5 + estimated absolute RMS force accuracy = 0.000955688 + estimated relative force accuracy = 6.63689e-05 + using double precision FFTW3 + 3d grid and FFT values/proc = 5280 1080 +All restart file global fix info was re-assigned +Neighbor list info ... + update every 1 steps, delay 0 steps, check yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 12 + ghost atom cutoff = 12 + binsize = 6, bins = 2 2 3 + 2 neighbor lists, perpetual/occasional/extra = 2 0 0 + (1) pair buck/coul/long, perpetual + attributes: half, newton on + pair build: half/bin/atomonly/newton + stencil: half/bin/3d/newton + bin: standard + (2) pair table, perpetual, skip from (1) + attributes: half, newton on + pair build: skip + stencil: none + bin: none +Per MPI rank memory allocation (min/avg/max) = 80.12 | 80.12 | 80.12 Mbytes +Step v_T_qm Press TotEng Volume Lx Ly Lz Pzz v_dhug v_dray v_lgr_vel v_lgr_pos + 1000 268.47106 189686.77 -2781.5194 1492.6355 9.9416812 8.6097487 17.438272 277378.37 -84.692548 -33090.129 15.785409 0 + 1500 362.13476 692245.96 -2800.9352 1011.2037 9.9416812 8.6097487 11.813766 661095.53 188.71833 -49928.712 35.851981 -24.11484 + 2000 860.78914 714816.8 -2830.893 997.64749 9.9416812 8.6097487 11.65539 653537.64 852.68158 -68765.537 36.41702 -44.978484 + 2500 1620.8281 709511.19 -2840.8217 1000.3425 9.9416812 8.6097487 11.686875 660030.01 1184.3105 -60030.892 36.304689 -65.69966 + 3000 2395.6824 649526.84 -2832.6859 995.56591 9.9416812 8.6097487 11.631071 660984.37 939.07209 -63050.693 36.503782 -86.383242 + 3500 3034.6774 715794.56 -2822.6098 995.8622 9.9416812 8.6097487 11.634532 712849.74 1055.7295 -10938.816 36.491433 -106.99315 + 4000 3487.9039 736791.25 -2804.1216 994.13867 9.9416812 8.6097487 11.614397 765817.85 943.15747 40595.305 36.563271 -127.76315 + 4500 3718.6279 813775.8 -2788.1942 995.82514 9.9416812 8.6097487 11.634099 881961.06 1370.5559 158141.68 36.492977 -148.68649 + 5000 3691.4947 750146.58 -2770.5541 1018.4785 9.9416812 8.6097487 11.898756 770500.36 196.2793 65528.786 35.548762 -169.8589 + 5500 3585.8602 831522.51 -2766.0198 1005.6834 9.9416812 8.6097487 11.749273 916093.67 1088.1987 200476.48 36.082073 -190.89436 + 6000 3431.6405 749891.94 -2771.6404 1011.9077 9.9416812 8.6097487 11.82199 781321.11 268.24344 70882.55 35.82264 -212.20913 + 6500 3350.2876 666113.16 -2780.4124 1028.8353 9.9416812 8.6097487 12.019753 749294.32 371.38231 52939.676 35.117081 -233.59556 + 7000 3339.2397 675783.2 -2782.7559 1022.6541 9.9416812 8.6097487 11.947539 690109.39 -26.949124 -11388.054 35.374719 -254.95868 + 7500 3395.582 726601.74 -2784.7652 1018.1439 9.9416812 8.6097487 11.894846 759167.86 506.5811 53917.852 35.56271 -276.24361 + 8000 3393.2372 625141.93 -2771.6398 1035.4915 9.9416812 8.6097487 12.097517 598674.46 -895.80046 -92142.112 34.839641 -297.61681 + 8500 3272.9752 659367.77 -2776.608 1031.8188 9.9416812 8.6097487 12.054609 688358.42 -142.30814 -5513.8593 34.992722 -318.94541 + 9000 3277.8848 724828.76 -2777.6502 1017.6314 9.9416812 8.6097487 11.888859 724452.11 58.574942 18775.738 35.58407 -340.1718 + 9500 3273.7854 620652.38 -2780.0794 1023.5922 9.9416812 8.6097487 11.958499 747175.42 317.3826 46458.505 35.335617 -361.41643 + 10000 3329.1766 668606.38 -2786.3493 1022.9534 9.9416812 8.6097487 11.951035 703351.81 168.14538 2103.38 35.362244 -382.64609 + 10500 3398.9956 642919.16 -2784.2833 1016.2587 9.9416812 8.6097487 11.872822 661298.16 -230.03577 -45520.34 35.641287 -403.78721 + 11000 3418.7053 675754.06 -2782.6318 1005.7483 9.9416812 8.6097487 11.75003 689789.84 -136.97148 -25773.422 36.079372 -424.97556 +Loop time of 32.4277 on 1 procs for 10000 steps with 144 atoms + +Performance: 26.644 ns/day, 0.901 hours/ns, 308.378 timesteps/s +99.5% CPU use with 1 MPI tasks x 1 OpenMP threads + +MPI task timing breakdown: +Section | min time | avg time | max time |%varavg| %total +--------------------------------------------------------------- +Pair | 28.397 | 28.397 | 28.397 | 0.0 | 87.57 +Kspace | 1.0225 | 1.0225 | 1.0225 | 0.0 | 3.15 +Neigh | 0.27594 | 0.27594 | 0.27594 | 0.0 | 0.85 +Comm | 0.1797 | 0.1797 | 0.1797 | 0.0 | 0.55 +Output | 0.10409 | 0.10409 | 0.10409 | 0.0 | 0.32 +Modify | 2.4112 | 2.4112 | 2.4112 | 0.0 | 7.44 +Other | | 0.03707 | | | 0.11 + +Nlocal: 144 ave 144 max 144 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Nghost: 5541 ave 5541 max 5541 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Neighs: 74662 ave 74662 max 74662 min +Histogram: 1 0 0 0 0 0 0 0 0 0 + +Total # of neighbors = 74662 +Ave neighs/atom = 518.486 +Neighbor list builds = 207 +Dangerous builds = 0 +Total wall time: 0:00:37 diff --git a/examples/USER/qtb/alpha_quartz_qbmsst/log.15Jun20.alpha_quartz_qbmsst.g++.4 b/examples/USER/qtb/alpha_quartz_qbmsst/log.15Jun20.alpha_quartz_qbmsst.g++.4 new file mode 100644 index 0000000000..58738cd639 --- /dev/null +++ b/examples/USER/qtb/alpha_quartz_qbmsst/log.15Jun20.alpha_quartz_qbmsst.g++.4 @@ -0,0 +1,430 @@ +LAMMPS (15 Jun 2020) + using 1 OpenMP thread(s) per MPI task +## This script first uses fix qtb to equilibrate alpha quartz structure to an initial state with quantum nuclear correction and then simulate shock induced phase transition through the quantum thermal bath multi-scale shock technique +variable x_rep equal 2 #plot is made with x_rep = 8 #x-direction replication number +variable y_rep equal 1 #plot is made with y_rep = 5 #y-direction replication number +variable z_rep equal 4 #plot is made with z_rep = 15 #z-direction replication number +variable cut_off equal 10.0 #Cut-off distance for the Buckingham term (Angstrom in metal units) +variable pressure equal 1.03125 #Initial state pressure (bar in metal units) +variable temperature equal 300.0 #Initial state quantum temperature (K in metal units) +variable delta_t equal 1.0e-3 #MD timestep length (ps in metal units) +variable damp_qtb equal 1 #1/gamma where gamma is the friction coefficient in quantum thermal bath (ps in metal units) +variable v_msst equal 78.0 #Shock velocity (Angstrom/ps in metal units) +variable q_msst equal 40.0 #Box mass-like parameter in the MSST (mass^2/length^4, where mass=grams/mole and length=Angstrom in metal units) +variable tscale_msst equal 0.05 #Temperature reduction parameter in the MSST (unitless) +variable eta_qbmsst equal 1.0 #Coupling constant between the shock and the quantum thermal bath (unitless constant) + + +## This part uses fix qtb to prepare alpha-quartz with quantum nuclear correction of the initial state +include alpha_quartz_qtb.mod +## This script first constructs an alpha quartz structure of a given size. It then uses fix qtb to equilibrate the computational cell to the specified temperature and pressure. + + +## This part defines units, alpha-quartz crystal, and atomic information +#General +units metal +dimension 3 +boundary p p p +atom_style charge + +#Lattice +lattice custom 1.0 a1 4.916000 0.000000 0.000000 a2 -2.45800 4.257381 0.000000 a3 0.000000 0.000000 5.405400 basis 0.469700 0.000000 0.000000 basis 0.000000 0.469700 0.666667 basis 0.530300 0.530300 0.333333 basis 0.413500 0.266900 0.119100 basis 0.266900 0.413500 0.547567 basis 0.733100 0.146600 0.785767 basis 0.586500 0.853400 0.214233 basis 0.853400 0.586500 0.452433 basis 0.146600 0.733100 0.880900 #American Mineralogist 65 920 1980 (Space Group 154) +Lattice spacing in x,y,z = 7.374 4.25738 5.4054 + +#Computational Cell +region orthorhombic_unit_cell block 0 4.916000 0 8.514762 0 5.405400 units box +create_box 2 orthorhombic_unit_cell +Created orthogonal box = (0.0 0.0 0.0) to (4.916 8.514762 5.4054) + 1 by 2 by 2 MPI processor grid +create_atoms 1 box basis 1 1 basis 2 1 basis 3 1 basis 4 2 basis 5 2 basis 6 2 basis 7 2 basis 8 2 basis 9 2 +Created 18 atoms + create_atoms CPU = 0.000 seconds +replicate ${x_rep} ${y_rep} ${z_rep} +replicate 2 ${y_rep} ${z_rep} +replicate 2 1 ${z_rep} +replicate 2 1 4 + orthogonal box = (0.0 0.0 0.0) to (9.832 8.514762 21.6216) + 1 by 1 by 4 MPI processor grid + 144 atoms + replicate CPU = 0.000225782 secs + +#Atomic Information +mass 1 28.085500 +mass 2 15.999400 +set type 1 charge +2.4 + 48 settings made for charge +set type 2 charge -1.2 + 96 settings made for charge + + +## This part implements the BKS pair potential with a cut-off distance for the Buckingham term. Long range Coulomb interactions are evaluated with the pppm method. +include alpha_quartz_potential.mod +#This script implements the BKS pair potential for various silicon dioxide compounds. Inner part is fixed with a harmonic potential. Long range Coulomb interactions are evaluated with the pppm method. + +#Pair Potentials +pair_style hybrid/overlay buck/coul/long ${cut_off} table linear 39901 +pair_style hybrid/overlay buck/coul/long 10 table linear 39901 +pair_coeff 1 1 buck/coul/long 0.0 1.0 0.0 #No interactions between Si atoms +pair_coeff 1 2 buck/coul/long 18003.757200 0.205205 133.538100 +pair_coeff 2 2 buck/coul/long 1388.773000 0.362319 175.000000 #BKS interaction in PRL 64 1955 (1990) +pair_modify shift yes +pair_coeff 1 2 table potential_SiO2.TPF Si-O ${cut_off} +pair_coeff 1 2 table potential_SiO2.TPF Si-O 10 +pair_coeff 2 2 table potential_SiO2.TPF O-O ${cut_off} #See the potential file for more information +pair_coeff 2 2 table potential_SiO2.TPF O-O 10 +WARNING: 1 of 39901 force values in table are inconsistent with -dE/dr. + Should only be flagged at inflection points (src/pair_table.cpp:471) +kspace_style pppm 1.0e-4 + +#Neighbor style +neighbor 2.0 bin +neigh_modify check yes every 1 delay 0 page 100000 one 2000 + + +## This part equilibrates your crystal to a pressure of ${pressure}(unit pressure) and a temperature of ${temperature}(unit temperatureture) with quantum nuclear effects +variable p_damp equal ${delta_t}*1000 #Recommended pressure damping parameter in fix nph +variable p_damp equal 0.001*1000 +fix scapegoat_qtb all nph iso ${pressure} ${pressure} ${p_damp} ptemp ${temperature} #NPH does the time integration +fix scapegoat_qtb all nph iso 1.03125 ${pressure} ${p_damp} ptemp ${temperature} +fix scapegoat_qtb all nph iso 1.03125 1.03125 ${p_damp} ptemp ${temperature} +fix scapegoat_qtb all nph iso 1.03125 1.03125 1 ptemp ${temperature} +fix scapegoat_qtb all nph iso 1.03125 1.03125 1 ptemp 300 +fix quartz_qtb all qtb temp ${temperature} damp ${damp_qtb} seed 35082 f_max 120.00 N_f 100 #Change f_max (THz) if your Debye frequency is higher +fix quartz_qtb all qtb temp 300 damp ${damp_qtb} seed 35082 f_max 120.00 N_f 100 +fix quartz_qtb all qtb temp 300 damp 1 seed 35082 f_max 120.00 N_f 100 +thermo_style custom step temp press etotal vol lx ly lz pxx pyy pzz pxy pyz pxz +thermo 200 +run 2000 # 2 ps +PPPM initialization ... + using 12-bit tables for long-range coulomb (src/kspace.cpp:332) + G vector (1/distance) = 0.301598 + grid = 9 8 15 + stencil order = 5 + estimated absolute RMS force accuracy = 0.00117056 + estimated relative force accuracy = 8.12908e-05 + using double precision FFTW3 + 3d grid and FFT values/proc = 2400 288 +Neighbor list info ... + update every 1 steps, delay 0 steps, check yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 12 + ghost atom cutoff = 12 + binsize = 6, bins = 2 2 4 + 2 neighbor lists, perpetual/occasional/extra = 2 0 0 + (1) pair buck/coul/long, perpetual + attributes: half, newton on + pair build: half/bin/atomonly/newton + stencil: half/bin/3d/newton + bin: standard + (2) pair table, perpetual, skip from (1) + attributes: half, newton on + pair build: skip + stencil: none + bin: none +Per MPI rank memory allocation (min/avg/max) = 79.7 | 79.7 | 79.7 Mbytes +Step Temp Press TotEng Volume Lx Ly Lz Pxx Pyy Pzz Pxy Pyz Pxz + 0 0 -34026.791 -2793.6042 1810.0985 9.832 8.514762 21.6216 -37470.578 -37470.432 -27139.363 1.0530512e-10 0.94245783 4.0087238e-10 + 200 153.57631 45538.205 -2790.8177 1873.0866 9.9447472 8.612404 21.869543 41721.016 44095.248 50798.351 -3961.4596 1223.325 2871.656 + 400 234.74785 -34404.175 -2789.0189 1850.2127 9.9041 8.5772024 21.780156 -28329.333 -39376.313 -35506.88 -1154.5043 -5411.1071 2246.6749 + 600 265.24833 -20905.145 -2786.2727 1874.9981 9.948129 8.6153326 21.87698 -22753.886 -21091.083 -18870.468 -4645.5548 2968.2945 1415.0311 + 800 297.79035 32990.58 -2784.8247 1853.6946 9.910309 8.5825796 21.79381 30061.364 35359.18 33551.195 -3092.2971 1525.52 -6461.0249 + 1000 367.71884 -27539.239 -2783.0102 1864.7161 9.9299114 8.5995557 21.836917 -20273.387 -38720.429 -23623.901 7639.0334 -866.35665 543.52723 + 1200 399.77109 3807.7814 -2781.511 1893.4978 9.9807399 8.6435745 21.948695 1625.8226 7441.2236 2356.298 -4057.1674 3814.9305 1528.4567 + 1400 466.57962 -4148.235 -2780.1546 1851.5925 9.9065614 8.5793341 21.785568 -10883.19 1816.768 -3378.2828 896.25296 -7208.541 -42.253127 + 1600 497.86539 14505.31 -2778.9409 1882.2616 9.9609584 8.6264432 21.905193 8268.1103 20614.738 14633.082 -2690.5669 6807.3187 11995.878 + 1800 557.31182 -108.04462 -2778.1875 1875.514 9.9490413 8.6161228 21.878986 948.68308 -1929.7575 656.94053 -1628.2172 -6594.5909 -4423.4368 + 2000 480.39449 -8852.2243 -2778.4963 1862.9552 9.9267847 8.596848 21.830042 -18274.307 3038.8369 -11321.203 -5002.1016 12023.282 6845.2769 +Loop time of 1.42181 on 4 procs for 2000 steps with 144 atoms + +Performance: 121.535 ns/day, 0.197 hours/ns, 1406.656 timesteps/s +87.5% CPU use with 4 MPI tasks x 1 OpenMP threads + +MPI task timing breakdown: +Section | min time | avg time | max time |%varavg| %total +--------------------------------------------------------------- +Pair | 0.72578 | 0.80093 | 0.87518 | 6.1 | 56.33 +Kspace | 0.33737 | 0.41245 | 0.48642 | 8.4 | 29.01 +Neigh | 0 | 0 | 0 | 0.0 | 0.00 +Comm | 0.066098 | 0.071334 | 0.076039 | 1.6 | 5.02 +Output | 0.00021172 | 0.00039291 | 0.00093484 | 0.0 | 0.03 +Modify | 0.090105 | 0.1077 | 0.11384 | 3.1 | 7.58 +Other | | 0.029 | | | 2.04 + +Nlocal: 36 ave 36 max 36 min +Histogram: 4 0 0 0 0 0 0 0 0 0 +Nghost: 2614 ave 2614 max 2614 min +Histogram: 4 0 0 0 0 0 0 0 0 0 +Neighs: 10488 ave 11326 max 9404 min +Histogram: 1 0 0 0 0 0 2 0 0 1 + +Total # of neighbors = 41952 +Ave neighs/atom = 291.333 +Neighbor list builds = 0 +Dangerous builds = 0 +unfix quartz_qtb +unfix scapegoat_qtb + + +## This part demonstrates how to retart fix qbmsst during any stage of the shock simulation. +## PPPM may break down when compression ratio becomes extremely large. One can always use this restart technique to resume the shock simulation. +#Compression restart 1 +reset_timestep 0 +#Beta is the number of time steps between each update of the quantum bath temperature. Setting a larger beta can reduce thermal flactuations. +fix shock all qbmsst z ${v_msst} q ${q_msst} tscale ${tscale_msst} damp ${damp_qtb} f_max 120 N_f 100 seed 35082 eta ${eta_qbmsst} beta 5 T_init ${temperature} +fix shock all qbmsst z 78 q ${q_msst} tscale ${tscale_msst} damp ${damp_qtb} f_max 120 N_f 100 seed 35082 eta ${eta_qbmsst} beta 5 T_init ${temperature} +fix shock all qbmsst z 78 q 40 tscale ${tscale_msst} damp ${damp_qtb} f_max 120 N_f 100 seed 35082 eta ${eta_qbmsst} beta 5 T_init ${temperature} +fix shock all qbmsst z 78 q 40 tscale 0.05 damp ${damp_qtb} f_max 120 N_f 100 seed 35082 eta ${eta_qbmsst} beta 5 T_init ${temperature} +fix shock all qbmsst z 78 q 40 tscale 0.05 damp 1 f_max 120 N_f 100 seed 35082 eta ${eta_qbmsst} beta 5 T_init ${temperature} +fix shock all qbmsst z 78 q 40 tscale 0.05 damp 1 f_max 120 N_f 100 seed 35082 eta 1 beta 5 T_init ${temperature} +fix shock all qbmsst z 78 q 40 tscale 0.05 damp 1 f_max 120 N_f 100 seed 35082 eta 1 beta 5 T_init 300 +QBMSST parameters: + Shock in z direction + Cell mass-like parameter qmass (units of mass^2/length^4) = 4.00000e+01 + Shock velocity = 7.80000e+01 + Artificial viscosity (units of mass/length/time) = 0.00000e+00 + Initial pressure calculated on first step + Initial volume calculated on first step + Initial energy calculated on first step +fix_modify shock energy yes +variable dhug equal f_shock[1] +variable dray equal f_shock[2] +variable lgr_vel equal f_shock[3] +variable lgr_pos equal f_shock[4] +variable T_qm equal f_shock[5] #Temperature with quantum nuclear correction +thermo_style custom step v_T_qm press etotal vol lx ly lz pzz v_dhug v_dray v_lgr_vel v_lgr_pos +thermo 200 +timestep ${delta_t} +timestep 0.001 +run 1000 +PPPM initialization ... + using 12-bit tables for long-range coulomb (src/kspace.cpp:332) + G vector (1/distance) = 0.30088 + grid = 9 8 15 + stencil order = 5 + estimated absolute RMS force accuracy = 0.00120534 + estimated relative force accuracy = 8.37062e-05 + using double precision FFTW3 + 3d grid and FFT values/proc = 2400 288 +Neighbor list info ... + update every 1 steps, delay 0 steps, check yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 12 + ghost atom cutoff = 12 + binsize = 6, bins = 2 2 4 + 2 neighbor lists, perpetual/occasional/extra = 2 0 0 + (1) pair buck/coul/long, perpetual + attributes: half, newton on + pair build: half/bin/atomonly/newton + stencil: half/bin/3d/newton + bin: standard + (2) pair table, perpetual, skip from (1) + attributes: half, newton on + pair build: skip + stencil: none + bin: none +Fix QBMSST v0 = 1.86296e+03 +Fix QBMSST p0 = -1.13219e+04 +Fix QBMSST e0 = to be -2.77850e+03 +Fix QBMSST initial strain rate of -4.21890e-01 established by reducing temperature by factor of 5.00000e-02 +Per MPI rank memory allocation (min/avg/max) = 79.7 | 79.7 | 79.7 Mbytes +Step v_T_qm Press TotEng Volume Lx Ly Lz Pzz v_dhug v_dray v_lgr_vel v_lgr_pos + 0 300 -9106.318 -2778.4963 1862.9552 9.9267847 8.596848 21.830042 -11562.002 12.009862 -240.0699 0 0 + 200 296.47213 25984.111 -2777.5178 1770.2164 9.9267847 8.596848 20.743332 64970.204 -25.305765 -1564.7673 3.8828772 -15.16768 + 400 291.06707 69977.517 -2777.6325 1684.893 9.9267847 8.596848 19.743515 144833.82 -12.184734 6667.384 7.4552796 -29.607028 + 600 287.21118 39706.699 -2778.0322 1716.9533 9.9267847 8.596848 20.119196 87971.152 -38.593844 -23279.741 6.1129484 -43.751298 + 800 284.33611 18833.281 -2778.1637 1792.7576 9.9267847 8.596848 21.007468 43725.433 -8.1267799 -3885.5802 2.9391022 -58.454556 + 1000 281.98328 -6030.6935 -2778.3314 1881.8369 9.9267847 8.596848 22.051297 -14118.602 1.3183874 13055.078 -0.79055793 -73.780965 +Loop time of 1.25215 on 4 procs for 1000 steps with 144 atoms + +Performance: 69.001 ns/day, 0.348 hours/ns, 798.628 timesteps/s +90.6% CPU use with 4 MPI tasks x 1 OpenMP threads + +MPI task timing breakdown: +Section | min time | avg time | max time |%varavg| %total +--------------------------------------------------------------- +Pair | 0.67979 | 0.73665 | 0.8091 | 5.4 | 58.83 +Kspace | 0.18687 | 0.25893 | 0.31544 | 9.1 | 20.68 +Neigh | 0.0011306 | 0.0012404 | 0.0013735 | 0.3 | 0.10 +Comm | 0.040339 | 0.041345 | 0.042296 | 0.4 | 3.30 +Output | 0.00020051 | 0.00035506 | 0.00081801 | 0.0 | 0.03 +Modify | 0.19595 | 0.2007 | 0.20253 | 0.6 | 16.03 +Other | | 0.01292 | | | 1.03 + +Nlocal: 36 ave 38 max 34 min +Histogram: 1 0 1 0 0 0 0 1 0 1 +Nghost: 2527.75 ave 2547 max 2518 min +Histogram: 2 0 0 1 0 0 0 0 0 1 +Neighs: 10194.8 ave 11177 max 9437 min +Histogram: 2 0 0 0 0 0 1 0 0 1 + +Total # of neighbors = 40779 +Ave neighs/atom = 283.188 +Neighbor list builds = 6 +Dangerous builds = 0 +write_restart restart.1000 +PPPM initialization ... + using 12-bit tables for long-range coulomb (src/kspace.cpp:332) + G vector (1/distance) = 0.302953 + grid = 9 8 16 + stencil order = 5 + estimated absolute RMS force accuracy = 0.00105569 + estimated relative force accuracy = 7.33134e-05 + using double precision FFTW3 + 3d grid and FFT values/proc = 2640 288 +Neighbor list info ... + update every 1 steps, delay 0 steps, check yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 12 + ghost atom cutoff = 12 + binsize = 6, bins = 2 2 4 + 2 neighbor lists, perpetual/occasional/extra = 2 0 0 + (1) pair buck/coul/long, perpetual + attributes: half, newton on + pair build: half/bin/atomonly/newton + stencil: half/bin/3d/newton + bin: standard + (2) pair table, perpetual, skip from (1) + attributes: half, newton on + pair build: skip + stencil: none + bin: none + +#Compression restart 2 +#Read restart file and load potential again +clear + using 1 OpenMP thread(s) per MPI task +read_restart restart.1000 + restoring atom style charge from restart + orthogonal box = (-0.04739235907204603 -0.041042988010289584 -0.21484841641189512) to (9.879392359072014 8.555804988010294 21.83644841641206) + 1 by 1 by 4 MPI processor grid + restoring pair style hybrid/overlay from restart + 144 atoms + read_restart CPU = 0.000472307 secs +include alpha_quartz_potential.mod +#This script implements the BKS pair potential for various silicon dioxide compounds. Inner part is fixed with a harmonic potential. Long range Coulomb interactions are evaluated with the pppm method. + +#Pair Potentials +pair_style hybrid/overlay buck/coul/long ${cut_off} table linear 39901 +pair_style hybrid/overlay buck/coul/long 10 table linear 39901 +pair_coeff 1 1 buck/coul/long 0.0 1.0 0.0 #No interactions between Si atoms +pair_coeff 1 2 buck/coul/long 18003.757200 0.205205 133.538100 +pair_coeff 2 2 buck/coul/long 1388.773000 0.362319 175.000000 #BKS interaction in PRL 64 1955 (1990) +pair_modify shift yes +pair_coeff 1 2 table potential_SiO2.TPF Si-O ${cut_off} +pair_coeff 1 2 table potential_SiO2.TPF Si-O 10 +pair_coeff 2 2 table potential_SiO2.TPF O-O ${cut_off} #See the potential file for more information +pair_coeff 2 2 table potential_SiO2.TPF O-O 10 +WARNING: 1 of 39901 force values in table are inconsistent with -dE/dr. + Should only be flagged at inflection points (src/pair_table.cpp:471) +kspace_style pppm 1.0e-4 + +#Neighbor style +neighbor 2.0 bin +neigh_modify check yes every 1 delay 0 page 100000 one 2000 +#Use the same fix id and add no tscale if the system is already compressed +fix shock all qbmsst z ${v_msst} q ${q_msst} tscale 0.0 damp ${damp_qtb} f_max 120 N_f 100 seed 35082 eta ${eta_qbmsst} beta 5 T_init ${temperature} +fix shock all qbmsst z 78 q ${q_msst} tscale 0.0 damp ${damp_qtb} f_max 120 N_f 100 seed 35082 eta ${eta_qbmsst} beta 5 T_init ${temperature} +fix shock all qbmsst z 78 q 40 tscale 0.0 damp ${damp_qtb} f_max 120 N_f 100 seed 35082 eta ${eta_qbmsst} beta 5 T_init ${temperature} +fix shock all qbmsst z 78 q 40 tscale 0.0 damp 1 f_max 120 N_f 100 seed 35082 eta ${eta_qbmsst} beta 5 T_init ${temperature} +fix shock all qbmsst z 78 q 40 tscale 0.0 damp 1 f_max 120 N_f 100 seed 35082 eta 1 beta 5 T_init ${temperature} +fix shock all qbmsst z 78 q 40 tscale 0.0 damp 1 f_max 120 N_f 100 seed 35082 eta 1 beta 5 T_init 300 +QBMSST parameters: + Shock in z direction + Cell mass-like parameter qmass (units of mass^2/length^4) = 4.00000e+01 + Shock velocity = 7.80000e+01 + Artificial viscosity (units of mass/length/time) = 0.00000e+00 + Initial pressure calculated on first step + Initial volume calculated on first step + Initial energy calculated on first step +Resetting global fix info from restart file: + fix style: qbmsst, fix ID: shock +fix_modify shock energy yes +variable dhug equal f_shock[1] +variable dray equal f_shock[2] +variable lgr_vel equal f_shock[3] +variable lgr_pos equal f_shock[4] +variable T_qm equal f_shock[5] #Temperature with quantum nuclear correction +thermo_style custom step v_T_qm press etotal vol lx ly lz pzz v_dhug v_dray v_lgr_vel v_lgr_pos +thermo 500 +timestep ${delta_t} +timestep 0.001 +restart 1000 restart +run 10000 #10 ps +PPPM initialization ... + using 12-bit tables for long-range coulomb (src/kspace.cpp:332) + G vector (1/distance) = 0.302953 + grid = 9 8 16 + stencil order = 5 + estimated absolute RMS force accuracy = 0.00105569 + estimated relative force accuracy = 7.33134e-05 + using double precision FFTW3 + 3d grid and FFT values/proc = 2640 288 +All restart file global fix info was re-assigned +Neighbor list info ... + update every 1 steps, delay 0 steps, check yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 12 + ghost atom cutoff = 12 + binsize = 6, bins = 2 2 4 + 2 neighbor lists, perpetual/occasional/extra = 2 0 0 + (1) pair buck/coul/long, perpetual + attributes: half, newton on + pair build: half/bin/atomonly/newton + stencil: half/bin/3d/newton + bin: standard + (2) pair table, perpetual, skip from (1) + attributes: half, newton on + pair build: skip + stencil: none + bin: none +Per MPI rank memory allocation (min/avg/max) = 79.71 | 79.71 | 79.71 Mbytes +Step v_T_qm Press TotEng Volume Lx Ly Lz Pzz v_dhug v_dray v_lgr_vel v_lgr_pos + 1000 281.98328 -6031.2395 -2778.6227 1881.8369 9.9267847 8.596848 22.051297 -14113.621 1.3373278 13060.059 -0.79055793 0 + 1500 266.12746 44405.573 -2777.9815 1739.6543 9.9267847 8.596848 20.385206 92590.239 -12.06041 397.47049 5.1624821 -37.823748 + 2000 255.79411 17620.408 -2777.9685 1785.7619 9.9267847 8.596848 20.925494 48670.364 -16.082827 -4813.6764 3.2320016 -73.974437 + 2500 256.8887 40153.833 -2778.4337 1752.9461 9.9267847 8.596848 20.540959 79665.002 7.7413878 -1368.8927 4.6059671 -112.35254 + 3000 261.55251 5315.4799 -2779.0755 1834.3375 9.9267847 8.596848 21.4947 15896.368 22.588205 3192.882 1.1981949 -148.36068 + 3500 261.57101 57911.809 -2778.1223 1713.3956 9.9267847 8.596848 20.077507 110996.8 -9.4471543 -3240.9018 6.2619064 -186.41261 + 4000 254.88665 13952.95 -2778.4816 1818.2782 9.9267847 8.596848 21.306518 26833.588 2.2818412 647.88057 1.8705799 -222.72504 + 4500 240.08908 73322.997 -2776.7382 1668.6666 9.9267847 8.596848 19.553375 151978.11 -43.917346 189.1572 8.1346613 -260.52885 + 5000 214.49084 1925.2557 -2777.0657 1890.0985 9.9267847 8.596848 22.148106 -5218.7292 -44.5537 28890.787 -1.1364617 -297.26329 + 5500 194.6515 71804.842 -2777.3417 1669.7297 9.9267847 8.596848 19.565832 146911.42 -34.911593 -3985.0635 8.0901523 -334.1879 + 6000 186.23814 10196.007 -2777.1394 1837.3793 9.9267847 8.596848 21.530344 23550.907 -18.381207 13401.096 1.0708382 -371.9208 + 6500 172.53603 5474.3725 -2777.4502 1818.0038 9.9267847 8.596848 21.303303 18389.825 -22.65951 -8026.2088 1.8820667 -407.83084 + 7000 160.91186 107908.64 -2777.6746 1621.7378 9.9267847 8.596848 19.003464 196841.27 -8.6606903 5654.1938 10.099523 -444.9925 + 7500 146.01905 147030.69 -2777.2543 1539.7536 9.9267847 8.596848 18.042777 253089.02 -43.928324 -6926.1018 13.532114 -478.63113 + 8000 207.17758 837859.1 -2796.8957 989.32874 9.9267847 8.596848 11.592918 811765.11 1172.3778 89652.363 36.577833 -503.41923 + 8500 725.15657 853732.89 -2832.3144 974.18299 9.9267847 8.596848 11.415441 773926.64 1749.5702 39098.598 37.21197 -524.17835 + 9000 1554.6089 807867.74 -2843.0063 990.10922 9.9267847 8.596848 11.602064 749697.22 1959.0322 28239.71 36.545155 -544.77354 + 9500 2440.1194 748145.05 -2839.2364 992.38871 9.9267847 8.596848 11.628775 691503.58 1437.0708 -28040.223 36.449715 -565.41198 + 10000 3112.1817 823862.43 -2820.0495 982.35471 9.9267847 8.596848 11.511197 754954.89 1330.6807 26987.244 36.869828 -586.12357 + 10500 3550.0273 868916.79 -2803.7678 983.70386 9.9267847 8.596848 11.527006 867368.45 1727.9058 140533.46 36.813341 -607.00946 + 11000 3839.7527 830581.55 -2795.3804 995.31485 9.9267847 8.596848 11.663063 811740 1150.0462 94652.768 36.327201 -628.02229 +Loop time of 15.1476 on 4 procs for 10000 steps with 144 atoms + +Performance: 57.039 ns/day, 0.421 hours/ns, 660.171 timesteps/s +91.3% CPU use with 4 MPI tasks x 1 OpenMP threads + +MPI task timing breakdown: +Section | min time | avg time | max time |%varavg| %total +--------------------------------------------------------------- +Pair | 7.7228 | 9.085 | 10.626 | 36.0 | 59.98 +Kspace | 1.6343 | 3.1795 | 4.5467 | 61.0 | 20.99 +Neigh | 0.02063 | 0.027076 | 0.034395 | 3.1 | 0.18 +Comm | 0.54719 | 0.57781 | 0.60468 | 2.8 | 3.81 +Output | 0.10128 | 0.1019 | 0.10373 | 0.3 | 0.67 +Modify | 2.0819 | 2.1159 | 2.1495 | 1.8 | 13.97 +Other | | 0.06035 | | | 0.40 + +Nlocal: 36 ave 38 max 33 min +Histogram: 1 0 0 0 0 0 1 0 1 1 +Nghost: 4267 ave 4304 max 4239 min +Histogram: 1 0 1 0 1 0 0 0 0 1 +Neighs: 18859.2 ave 25108 max 12333 min +Histogram: 1 0 0 1 0 0 1 0 0 1 + +Total # of neighbors = 75437 +Ave neighs/atom = 523.868 +Neighbor list builds = 95 +Dangerous builds = 0 +Total wall time: 0:00:17 diff --git a/examples/USER/qtb/alpha_quartz_qbmsst/potential_SiO2.TPF b/examples/USER/qtb/alpha_quartz_qbmsst/potential_SiO2.TPF old mode 100755 new mode 100644 index 66de5e8c66..85fd7a2edc --- a/examples/USER/qtb/alpha_quartz_qbmsst/potential_SiO2.TPF +++ b/examples/USER/qtb/alpha_quartz_qbmsst/potential_SiO2.TPF @@ -1,4 +1,4 @@ -#Potential between O,Si atoms. r ranges from 0.1 to 20.0. This file+BKS(with no shift)=alpha*(r-rs)^2(0.1r>rs). alpha=100, rsOO=1.43869, rsSiO=1.19362. All with metal units. +#Potential between O,Si atoms. UNITS: metal r ranges from 0.1 to 20.0. This file+BKS(with no shift)=alpha*(r-rs)^2(0.1r>rs). alpha=100, rsOO=1.43869, rsSiO=1.19362. All with metal units. Si-O N 39901 diff --git a/examples/USER/qtb/alpha_quartz_qtb/alpha_quartz_qtb.in b/examples/USER/qtb/alpha_quartz_qtb/alpha_quartz_qtb.in deleted file mode 100644 index 3ead319dc0..0000000000 --- a/examples/USER/qtb/alpha_quartz_qtb/alpha_quartz_qtb.in +++ /dev/null @@ -1,79 +0,0 @@ -## This script first constructs an alpha quartz structure of a given size. It then uses fix qtb to equilibrate the computational cell to the specified temperature and pressure. -variable x_rep equal 2 #x-direction replication number -variable y_rep equal 2 #y-direction replication number -variable z_rep equal 2 #z-direction replication number -variable cut_off equal 10.0 #Cut-off distance for the Buckingham term (Angstrom in metal units) -variable pressure equal 1.03125 #Initial state pressure (bar in metal units) -variable temperature equal 300.0 #Initial state quantum temperature (K in metal units) -variable delta_t equal 1.0e-3 #MD timestep length (ps in metal units) -variable damp_qtb equal 1 #1/gamma where gamma is the friction coefficient in quantum thermal bath (ps in metal units) - -## This part defines units, alpha-quartz crystal, and atomic information -#General -units metal -dimension 3 -boundary p p p -atom_style charge - -#Lattice -lattice custom 1.0 & - a1 4.916000 0.000000 0.000000 & - a2 -2.45800 4.257381 0.000000 & - a3 0.000000 0.000000 5.405400 & - & - basis 0.469700 0.000000 0.000000 & - basis 0.000000 0.469700 0.666667 & - basis 0.530300 0.530300 0.333333 & - & - basis 0.413500 0.266900 0.119100 & - basis 0.266900 0.413500 0.547567 & - basis 0.733100 0.146600 0.785767 & - basis 0.586500 0.853400 0.214233 & - basis 0.853400 0.586500 0.452433 & - basis 0.146600 0.733100 0.880900 #American Mineralogist 65 920 1980 (Space Group 154) - -#Computational Cell -region orthorhombic_unit_cell block 0 4.916000 0 8.514762 0 5.405400 units box -create_box 2 orthorhombic_unit_cell -create_atoms 1 box & - basis 1 1 & - basis 2 1 & - basis 3 1 & - basis 4 2 & - basis 5 2 & - basis 6 2 & - basis 7 2 & - basis 8 2 & - basis 9 2 -replicate ${x_rep} ${y_rep} ${z_rep} - -#Atomic Information -mass 1 28.085500 -mass 2 15.999400 -set type 1 charge +2.4 -set type 2 charge -1.2 - - -## This part implements the BKS pair potential with a cut-off distance for the Buckingham term. Long range Coulomb interactions are evaluated with the pppm method. -#Pair Potentials -pair_style buck/coul/long ${cut_off} #BKS interaction, PRL 64 1955 (1990) -pair_coeff 1 1 0.0 1.0 0.0 -pair_coeff 1 2 18003.757200 0.205205 133.538100 -pair_coeff 2 2 1388.773000 0.362319 175.000000 -pair_modify shift yes -kspace_style pppm 1.0e-4 - -#Neighbor style -neighbor 2.0 bin -neigh_modify check yes every 1 delay 0 page 100000 one 2000 - - -## This part equilibrates your crystal to a pressure of ${pressure}(unit pressure) and a temperature of ${temperature}(unit temperatureture) with quantum nuclear effects -variable p_damp equal ${delta_t}*1000 #Recommended pressure damping parameter in fix nph -fix scapegoat_qtb all nph iso ${pressure} ${pressure} ${p_damp} #NPH does the time integration -fix quartz_qtb all qtb temp ${temperature} damp ${damp_qtb} seed 35082 f_max 120.00 N_f 100 #Change f_max (THz) if your Debye frequency is higher -thermo_style custom step temp press etotal vol lx ly lz pxx pyy pzz pxy pyz pxz -thermo 100 -run 20000 # 20 ps -unfix quartz_qtb -unfix scapegoat_qtb diff --git a/examples/USER/qtb/alpha_quartz_qtb/in.alpha_quartz_qtb b/examples/USER/qtb/alpha_quartz_qtb/in.alpha_quartz_qtb new file mode 100644 index 0000000000..d9b5e67de1 --- /dev/null +++ b/examples/USER/qtb/alpha_quartz_qtb/in.alpha_quartz_qtb @@ -0,0 +1,79 @@ +## This script first constructs an alpha quartz structure of a given size. It then uses fix qtb to equilibrate the computational cell to the specified temperature and pressure. +variable x_rep equal 2 #x-direction replication number +variable y_rep equal 2 #y-direction replication number +variable z_rep equal 2 #z-direction replication number +variable cut_off equal 10.0 #Cut-off distance for the Buckingham term (Angstrom in metal units) +variable pressure equal 1.03125 #Initial state pressure (bar in metal units) +variable temperature equal 300.0 #Initial state quantum temperature (K in metal units) +variable delta_t equal 1.0e-3 #MD timestep length (ps in metal units) +variable damp_qtb equal 1 #1/gamma where gamma is the friction coefficient in quantum thermal bath (ps in metal units) + +## This part defines units, alpha-quartz crystal, and atomic information +#General +units metal +dimension 3 +boundary p p p +atom_style charge + +#Lattice +lattice custom 1.0 & + a1 4.916000 0.000000 0.000000 & + a2 -2.45800 4.257381 0.000000 & + a3 0.000000 0.000000 5.405400 & + & + basis 0.469700 0.000000 0.000000 & + basis 0.000000 0.469700 0.666667 & + basis 0.530300 0.530300 0.333333 & + & + basis 0.413500 0.266900 0.119100 & + basis 0.266900 0.413500 0.547567 & + basis 0.733100 0.146600 0.785767 & + basis 0.586500 0.853400 0.214233 & + basis 0.853400 0.586500 0.452433 & + basis 0.146600 0.733100 0.880900 #American Mineralogist 65 920 1980 (Space Group 154) + +#Computational Cell +region orthorhombic_unit_cell block 0 4.916000 0 8.514762 0 5.405400 units box +create_box 2 orthorhombic_unit_cell +create_atoms 1 box & + basis 1 1 & + basis 2 1 & + basis 3 1 & + basis 4 2 & + basis 5 2 & + basis 6 2 & + basis 7 2 & + basis 8 2 & + basis 9 2 +replicate ${x_rep} ${y_rep} ${z_rep} + +#Atomic Information +mass 1 28.085500 +mass 2 15.999400 +set type 1 charge +2.4 +set type 2 charge -1.2 + + +## This part implements the BKS pair potential with a cut-off distance for the Buckingham term. Long range Coulomb interactions are evaluated with the pppm method. +#Pair Potentials +pair_style buck/coul/long ${cut_off} #BKS interaction, PRL 64 1955 (1990) +pair_coeff 1 1 0.0 1.0 0.0 +pair_coeff 1 2 18003.757200 0.205205 133.538100 +pair_coeff 2 2 1388.773000 0.362319 175.000000 +pair_modify shift yes +kspace_style pppm 1.0e-4 + +#Neighbor style +neighbor 2.0 bin +neigh_modify check yes every 1 delay 0 page 100000 one 2000 + + +## This part equilibrates your crystal to a pressure of ${pressure}(unit pressure) and a temperature of ${temperature}(unit temperatureture) with quantum nuclear effects +variable p_damp equal ${delta_t}*1000 #Recommended pressure damping parameter in fix nph +fix scapegoat_qtb all nph iso ${pressure} ${pressure} ${p_damp} ptemp ${temperature} #NPH does the time integration +fix quartz_qtb all qtb temp ${temperature} damp ${damp_qtb} seed 35082 f_max 120.00 N_f 100 #Change f_max (THz) if your Debye frequency is higher +thermo_style custom step temp press etotal vol lx ly lz pxx pyy pzz pxy pyz pxz +thermo 500 +run 10000 # 20 ps +unfix quartz_qtb +unfix scapegoat_qtb diff --git a/examples/USER/qtb/alpha_quartz_qtb/log.15Jun20.alpha_quartz_qtb.g++.1 b/examples/USER/qtb/alpha_quartz_qtb/log.15Jun20.alpha_quartz_qtb.g++.1 new file mode 100644 index 0000000000..6c67ea87cc --- /dev/null +++ b/examples/USER/qtb/alpha_quartz_qtb/log.15Jun20.alpha_quartz_qtb.g++.1 @@ -0,0 +1,152 @@ +LAMMPS (15 Jun 2020) + using 1 OpenMP thread(s) per MPI task +## This script first constructs an alpha quartz structure of a given size. It then uses fix qtb to equilibrate the computational cell to the specified temperature and pressure. +variable x_rep equal 2 #x-direction replication number +variable y_rep equal 2 #y-direction replication number +variable z_rep equal 2 #z-direction replication number +variable cut_off equal 10.0 #Cut-off distance for the Buckingham term (Angstrom in metal units) +variable pressure equal 1.03125 #Initial state pressure (bar in metal units) +variable temperature equal 300.0 #Initial state quantum temperature (K in metal units) +variable delta_t equal 1.0e-3 #MD timestep length (ps in metal units) +variable damp_qtb equal 1 #1/gamma where gamma is the friction coefficient in quantum thermal bath (ps in metal units) + +## This part defines units, alpha-quartz crystal, and atomic information +#General +units metal +dimension 3 +boundary p p p +atom_style charge + +#Lattice +lattice custom 1.0 a1 4.916000 0.000000 0.000000 a2 -2.45800 4.257381 0.000000 a3 0.000000 0.000000 5.405400 basis 0.469700 0.000000 0.000000 basis 0.000000 0.469700 0.666667 basis 0.530300 0.530300 0.333333 basis 0.413500 0.266900 0.119100 basis 0.266900 0.413500 0.547567 basis 0.733100 0.146600 0.785767 basis 0.586500 0.853400 0.214233 basis 0.853400 0.586500 0.452433 basis 0.146600 0.733100 0.880900 #American Mineralogist 65 920 1980 (Space Group 154) +Lattice spacing in x,y,z = 7.374 4.25738 5.4054 + +#Computational Cell +region orthorhombic_unit_cell block 0 4.916000 0 8.514762 0 5.405400 units box +create_box 2 orthorhombic_unit_cell +Created orthogonal box = (0.0 0.0 0.0) to (4.916 8.514762 5.4054) + 1 by 1 by 1 MPI processor grid +create_atoms 1 box basis 1 1 basis 2 1 basis 3 1 basis 4 2 basis 5 2 basis 6 2 basis 7 2 basis 8 2 basis 9 2 +Created 18 atoms + create_atoms CPU = 0.000 seconds +replicate ${x_rep} ${y_rep} ${z_rep} +replicate 2 ${y_rep} ${z_rep} +replicate 2 2 ${z_rep} +replicate 2 2 2 + orthogonal box = (0.0 0.0 0.0) to (9.832 17.029524 10.8108) + 1 by 1 by 1 MPI processor grid + 144 atoms + replicate CPU = 0.000219584 secs + +#Atomic Information +mass 1 28.085500 +mass 2 15.999400 +set type 1 charge +2.4 + 48 settings made for charge +set type 2 charge -1.2 + 96 settings made for charge + + +## This part implements the BKS pair potential with a cut-off distance for the Buckingham term. Long range Coulomb interactions are evaluated with the pppm method. +#Pair Potentials +pair_style buck/coul/long ${cut_off} #BKS interaction, PRL 64 1955 (1990) +pair_style buck/coul/long 10 +pair_coeff 1 1 0.0 1.0 0.0 +pair_coeff 1 2 18003.757200 0.205205 133.538100 +pair_coeff 2 2 1388.773000 0.362319 175.000000 +pair_modify shift yes +kspace_style pppm 1.0e-4 + +#Neighbor style +neighbor 2.0 bin +neigh_modify check yes every 1 delay 0 page 100000 one 2000 + + +## This part equilibrates your crystal to a pressure of ${pressure}(unit pressure) and a temperature of ${temperature}(unit temperatureture) with quantum nuclear effects +variable p_damp equal ${delta_t}*1000 #Recommended pressure damping parameter in fix nph +variable p_damp equal 0.001*1000 +fix scapegoat_qtb all nph iso ${pressure} ${pressure} ${p_damp} ptemp ${temperature} #NPH does the time integration +fix scapegoat_qtb all nph iso 1.03125 ${pressure} ${p_damp} ptemp ${temperature} +fix scapegoat_qtb all nph iso 1.03125 1.03125 ${p_damp} ptemp ${temperature} +fix scapegoat_qtb all nph iso 1.03125 1.03125 1 ptemp ${temperature} +fix scapegoat_qtb all nph iso 1.03125 1.03125 1 ptemp 300 +fix quartz_qtb all qtb temp ${temperature} damp ${damp_qtb} seed 35082 f_max 120.00 N_f 100 #Change f_max (THz) if your Debye frequency is higher +fix quartz_qtb all qtb temp 300 damp ${damp_qtb} seed 35082 f_max 120.00 N_f 100 +fix quartz_qtb all qtb temp 300 damp 1 seed 35082 f_max 120.00 N_f 100 +thermo_style custom step temp press etotal vol lx ly lz pxx pyy pzz pxy pyz pxz +thermo 500 +run 10000 # 20 ps +PPPM initialization ... + using 12-bit tables for long-range coulomb (src/kspace.cpp:332) + G vector (1/distance) = 0.307414 + grid = 9 15 10 + stencil order = 5 + estimated absolute RMS force accuracy = 0.000822922 + estimated relative force accuracy = 5.71487e-05 + using double precision FFTW3 + 3d grid and FFT values/proc = 5984 1350 +Neighbor list info ... + update every 1 steps, delay 0 steps, check yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 12 + ghost atom cutoff = 12 + binsize = 6, bins = 2 3 2 + 1 neighbor lists, perpetual/occasional/extra = 1 0 0 + (1) pair buck/coul/long, perpetual + attributes: half, newton on + pair build: half/bin/atomonly/newton + stencil: half/bin/3d/newton + bin: standard +Per MPI rank memory allocation (min/avg/max) = 79.54 | 79.54 | 79.54 Mbytes +Step Temp Press TotEng Volume Lx Ly Lz Pxx Pyy Pzz Pxy Pyz Pxz + 0 0 -34025.794 -2793.6041 1810.0985 9.832 17.029524 10.8108 -37478.502 -37477.413 -27121.466 -1.3649088e-10 1.3388978 5.8209479e-10 + 500 281.29079 -40385.348 -2786.6755 1844.5575 9.893999 17.136909 10.878971 -44649.574 -45631.516 -30874.953 -5970.3691 3630.1324 5208.8966 + 1000 405.39848 -15491.657 -2783.3315 1874.0851 9.9465141 17.227868 10.936714 -7770.4561 -21469.887 -17234.627 -4706.5632 -8313.9522 -5109.7918 + 1500 428.98568 -12118.951 -2781.3232 1874.1627 9.9466513 17.228106 10.936865 -11239.135 -11740.052 -13377.666 -3778.9317 -6220.1431 12775.412 + 2000 522.11905 -6687.482 -2779.2181 1855.9626 9.914349 17.172157 10.901347 -8016.0133 -10737.23 -1309.2028 -4980.3805 5270.2674 5848.5479 + 2500 496.74376 4264.2623 -2778.9979 1849.3244 9.9025147 17.151659 10.888335 -477.1374 3487.19 9782.7343 -4961.2016 2380.6522 4736.0758 + 3000 456.49628 2320.781 -2779.3844 1853.2925 9.9095923 17.163918 10.896117 5479.6232 -2954.3023 4437.022 3719.9287 4445.0723 -3278.5058 + 3500 485.20722 -7480.1789 -2778.6062 1859.6305 9.920876 17.183462 10.908524 -9340.6334 -6129.8494 -6970.0541 -7379.3507 1772.8159 334.33057 + 4000 527.61216 -13499.73 -2777.3433 1889.9405 9.9744857 17.276316 10.96747 -16483.038 -7465.2297 -16550.923 -2517.02 -1863.063 3314.927 + 4500 519.94117 721.60614 -2777.8506 1879.6562 9.9563603 17.244922 10.947541 -913.2791 -1765.7541 4843.8516 4466.5704 -14141.087 -6439.5669 + 5000 505.27757 -6278.3805 -2777.3641 1881.2931 9.9592497 17.249927 10.950718 -14254.233 -2653.6233 -1927.2858 1838.1568 5767.9267 597.47761 + 5500 500.70903 11303.821 -2777.8881 1871.0076 9.9410666 17.218433 10.930724 -6452.7947 24876.967 15487.29 522.01171 10473.257 9780.893 + 6000 526.65329 7991.2419 -2777.172 1856.9227 9.9160583 17.175117 10.903227 -68.823156 11005.468 13037.081 1253.9214 10039.559 1053.0486 + 6500 485.30026 12811.546 -2777.5866 1845.31 9.8953442 17.139239 10.88045 10063.921 20215.037 8155.6798 -3886.954 2249.2807 4855.0011 + 7000 507.85472 2649.7919 -2777.3359 1861.2877 9.923822 17.188564 10.911763 -4214.7779 6995.1472 5169.0064 -2188.489 6157.0955 533.65478 + 7500 528.5729 3161.4629 -2779.0851 1855.7946 9.9140499 17.171639 10.901018 2935.365 -2873.1363 9422.1601 771.1885 -4360.9131 4939.8209 + 8000 533.77283 4534.849 -2777.6538 1858.4772 9.9188246 17.179909 10.906268 -1187.9433 15739.396 -946.90551 -5187.8588 2446.5059 8079.2032 + 8500 518.71765 1108.9877 -2777.7019 1866.6125 9.9332765 17.20494 10.922159 8720.4976 -8234.9325 2841.3979 5148.5004 -2125.3524 -4127.7468 + 9000 536.71495 -496.88283 -2778.0262 1877.7099 9.9529227 17.238968 10.943761 -3481.5874 -4611.6246 6602.5634 -2788.5111 -13323.148 4338.813 + 9500 527.06773 -236.09043 -2778.1125 1895.9227 9.9849986 17.294525 10.97903 -12233.409 7578.0514 3947.0863 -6399.0254 995.22838 8590.7109 + 10000 526.77335 -4480.6866 -2777.7171 1886.8998 9.9691335 17.267046 10.961585 -3139.961 1336.993 -11639.092 13496.371 -11543.676 -6180.9262 +Loop time of 8.86837 on 1 procs for 10000 steps with 144 atoms + +Performance: 97.425 ns/day, 0.246 hours/ns, 1127.603 timesteps/s +99.8% CPU use with 1 MPI tasks x 1 OpenMP threads + +MPI task timing breakdown: +Section | min time | avg time | max time |%varavg| %total +--------------------------------------------------------------- +Pair | 6.1503 | 6.1503 | 6.1503 | 0.0 | 69.35 +Kspace | 1.1522 | 1.1522 | 1.1522 | 0.0 | 12.99 +Neigh | 0 | 0 | 0 | 0.0 | 0.00 +Comm | 0.11705 | 0.11705 | 0.11705 | 0.0 | 1.32 +Output | 0.00035834 | 0.00035834 | 0.00035834 | 0.0 | 0.00 +Modify | 1.4245 | 1.4245 | 1.4245 | 0.0 | 16.06 +Other | | 0.02397 | | | 0.27 + +Nlocal: 144 ave 144 max 144 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Nghost: 3804 ave 3804 max 3804 min +Histogram: 1 0 0 0 0 0 0 0 0 0 +Neighs: 41952 ave 41952 max 41952 min +Histogram: 1 0 0 0 0 0 0 0 0 0 + +Total # of neighbors = 41952 +Ave neighs/atom = 291.333 +Neighbor list builds = 0 +Dangerous builds = 0 +unfix quartz_qtb +unfix scapegoat_qtb +Total wall time: 0:00:08 diff --git a/examples/USER/qtb/alpha_quartz_qtb/log.15Jun20.alpha_quartz_qtb.g++.4 b/examples/USER/qtb/alpha_quartz_qtb/log.15Jun20.alpha_quartz_qtb.g++.4 new file mode 100644 index 0000000000..5b0d2b3569 --- /dev/null +++ b/examples/USER/qtb/alpha_quartz_qtb/log.15Jun20.alpha_quartz_qtb.g++.4 @@ -0,0 +1,152 @@ +LAMMPS (15 Jun 2020) + using 1 OpenMP thread(s) per MPI task +## This script first constructs an alpha quartz structure of a given size. It then uses fix qtb to equilibrate the computational cell to the specified temperature and pressure. +variable x_rep equal 2 #x-direction replication number +variable y_rep equal 2 #y-direction replication number +variable z_rep equal 2 #z-direction replication number +variable cut_off equal 10.0 #Cut-off distance for the Buckingham term (Angstrom in metal units) +variable pressure equal 1.03125 #Initial state pressure (bar in metal units) +variable temperature equal 300.0 #Initial state quantum temperature (K in metal units) +variable delta_t equal 1.0e-3 #MD timestep length (ps in metal units) +variable damp_qtb equal 1 #1/gamma where gamma is the friction coefficient in quantum thermal bath (ps in metal units) + +## This part defines units, alpha-quartz crystal, and atomic information +#General +units metal +dimension 3 +boundary p p p +atom_style charge + +#Lattice +lattice custom 1.0 a1 4.916000 0.000000 0.000000 a2 -2.45800 4.257381 0.000000 a3 0.000000 0.000000 5.405400 basis 0.469700 0.000000 0.000000 basis 0.000000 0.469700 0.666667 basis 0.530300 0.530300 0.333333 basis 0.413500 0.266900 0.119100 basis 0.266900 0.413500 0.547567 basis 0.733100 0.146600 0.785767 basis 0.586500 0.853400 0.214233 basis 0.853400 0.586500 0.452433 basis 0.146600 0.733100 0.880900 #American Mineralogist 65 920 1980 (Space Group 154) +Lattice spacing in x,y,z = 7.374 4.25738 5.4054 + +#Computational Cell +region orthorhombic_unit_cell block 0 4.916000 0 8.514762 0 5.405400 units box +create_box 2 orthorhombic_unit_cell +Created orthogonal box = (0.0 0.0 0.0) to (4.916 8.514762 5.4054) + 1 by 2 by 2 MPI processor grid +create_atoms 1 box basis 1 1 basis 2 1 basis 3 1 basis 4 2 basis 5 2 basis 6 2 basis 7 2 basis 8 2 basis 9 2 +Created 18 atoms + create_atoms CPU = 0.000 seconds +replicate ${x_rep} ${y_rep} ${z_rep} +replicate 2 ${y_rep} ${z_rep} +replicate 2 2 ${z_rep} +replicate 2 2 2 + orthogonal box = (0.0 0.0 0.0) to (9.832 17.029524 10.8108) + 1 by 2 by 2 MPI processor grid + 144 atoms + replicate CPU = 0.000231981 secs + +#Atomic Information +mass 1 28.085500 +mass 2 15.999400 +set type 1 charge +2.4 + 48 settings made for charge +set type 2 charge -1.2 + 96 settings made for charge + + +## This part implements the BKS pair potential with a cut-off distance for the Buckingham term. Long range Coulomb interactions are evaluated with the pppm method. +#Pair Potentials +pair_style buck/coul/long ${cut_off} #BKS interaction, PRL 64 1955 (1990) +pair_style buck/coul/long 10 +pair_coeff 1 1 0.0 1.0 0.0 +pair_coeff 1 2 18003.757200 0.205205 133.538100 +pair_coeff 2 2 1388.773000 0.362319 175.000000 +pair_modify shift yes +kspace_style pppm 1.0e-4 + +#Neighbor style +neighbor 2.0 bin +neigh_modify check yes every 1 delay 0 page 100000 one 2000 + + +## This part equilibrates your crystal to a pressure of ${pressure}(unit pressure) and a temperature of ${temperature}(unit temperatureture) with quantum nuclear effects +variable p_damp equal ${delta_t}*1000 #Recommended pressure damping parameter in fix nph +variable p_damp equal 0.001*1000 +fix scapegoat_qtb all nph iso ${pressure} ${pressure} ${p_damp} ptemp ${temperature} #NPH does the time integration +fix scapegoat_qtb all nph iso 1.03125 ${pressure} ${p_damp} ptemp ${temperature} +fix scapegoat_qtb all nph iso 1.03125 1.03125 ${p_damp} ptemp ${temperature} +fix scapegoat_qtb all nph iso 1.03125 1.03125 1 ptemp ${temperature} +fix scapegoat_qtb all nph iso 1.03125 1.03125 1 ptemp 300 +fix quartz_qtb all qtb temp ${temperature} damp ${damp_qtb} seed 35082 f_max 120.00 N_f 100 #Change f_max (THz) if your Debye frequency is higher +fix quartz_qtb all qtb temp 300 damp ${damp_qtb} seed 35082 f_max 120.00 N_f 100 +fix quartz_qtb all qtb temp 300 damp 1 seed 35082 f_max 120.00 N_f 100 +thermo_style custom step temp press etotal vol lx ly lz pxx pyy pzz pxy pyz pxz +thermo 500 +run 10000 # 20 ps +PPPM initialization ... + using 12-bit tables for long-range coulomb (src/kspace.cpp:332) + G vector (1/distance) = 0.307414 + grid = 9 15 10 + stencil order = 5 + estimated absolute RMS force accuracy = 0.000822922 + estimated relative force accuracy = 5.71487e-05 + using double precision FFTW3 + 3d grid and FFT values/proc = 2688 405 +Neighbor list info ... + update every 1 steps, delay 0 steps, check yes + max neighbors/atom: 2000, page size: 100000 + master list distance cutoff = 12 + ghost atom cutoff = 12 + binsize = 6, bins = 2 3 2 + 1 neighbor lists, perpetual/occasional/extra = 1 0 0 + (1) pair buck/coul/long, perpetual + attributes: half, newton on + pair build: half/bin/atomonly/newton + stencil: half/bin/3d/newton + bin: standard +Per MPI rank memory allocation (min/avg/max) = 79.08 | 79.08 | 79.09 Mbytes +Step Temp Press TotEng Volume Lx Ly Lz Pxx Pyy Pzz Pxy Pyz Pxz + 0 0 -34025.794 -2793.6041 1810.0985 9.832 17.029524 10.8108 -37478.502 -37477.413 -27121.466 -5.9958847e-10 1.3388978 7.2750373e-10 + 500 222.04947 -50221.579 -2787.6677 1851.5661 9.9065143 17.158586 10.892732 -61493.697 -53512.432 -35658.61 4973.9976 7095.5481 -2041.6341 + 1000 361.92367 -14345.85 -2783.1509 1861.0579 9.9234137 17.187857 10.911314 -4145.4149 -28701.195 -10190.939 7896.3934 -3901.2874 -490.57107 + 1500 457.97039 -4934.8727 -2779.8321 1860.2254 9.9219337 17.185294 10.909687 -3680.7192 -3045.0707 -8078.8283 456.70383 -4705.3346 -2175.8144 + 2000 523.52684 -9516.755 -2778.5181 1866.3577 9.9328244 17.204157 10.921662 -11042.489 -7777.5634 -9730.2127 -2016.3336 6027.001 -4150.3656 + 2500 489.58881 -4968.5157 -2777.3948 1864.0745 9.9287723 17.197139 10.917206 -13652.344 -2823.514 1570.3111 -7481.9537 -1150.3548 10502.368 + 3000 559.52782 -2882.7076 -2777.5527 1883.2223 9.9626528 17.255821 10.95446 3061.1755 -10570.656 -1138.642 -12045.354 -856.20951 16292.443 + 3500 521.67929 9974.5929 -2776.7752 1880.5936 9.9580152 17.247789 10.94936 15358.559 7855.8683 6709.3509 7292.9372 -9848.9204 -523.61056 + 4000 497.90872 -2012.9259 -2776.5554 1862.1703 9.9253904 17.191281 10.913488 -1154.5123 4270.0275 -9154.2927 971.94826 -10157.618 4694.0509 + 4500 533.64016 -7218.9278 -2775.8789 1883.3041 9.962797 17.256071 10.954618 -18299.547 -5497.566 2140.3296 -1335.6063 -10353.21 5703.7506 + 5000 551.61416 1590.9702 -2777.6093 1866.2047 9.9325531 17.203687 10.921363 -4600.02 6535.3 2837.6306 3412.3383 9492.18 1017.5742 + 5500 499.36075 188.82067 -2777.9872 1863.2925 9.9273838 17.194734 10.91568 -3238.914 1143.013 2662.363 4193.7623 -11565.423 2575.9361 + 6000 478.563 4064.8319 -2778.946 1867.7185 9.935238 17.208337 10.924316 1947.7246 3346.7411 6900.0301 -6339.9554 4133.6942 -4555.406 + 6500 512.63865 10227.461 -2778.8476 1855.5323 9.9135828 17.17083 10.900505 7423.8967 7558.2024 15700.285 -621.4585 -2620.4837 -3256.7524 + 7000 489.9889 13037.303 -2778.8793 1856.2469 9.9148553 17.173034 10.901904 10690.345 16770.786 11650.779 -4056.5527 -5023.8847 469.21909 + 7500 495.52187 1320.5068 -2778.1189 1871.7467 9.9423755 17.2207 10.932164 1978.2905 738.78041 1244.4496 1826.0923 -7829.3563 1873.2713 + 8000 474.60945 -4203.2068 -2778.8915 1866.5966 9.9332482 17.204891 10.922128 -1480.6896 -12516.261 1387.3306 2731.4462 -1292.9741 10743.939 + 8500 473.16225 -6266.1992 -2778.594 1872.9075 9.9444304 17.224259 10.934423 -12680.492 -2832.6603 -3285.4455 7226.9632 3762.6841 -5834.9064 + 9000 486.6579 2843.7947 -2778.0388 1877.3735 9.9523282 17.237939 10.943107 805.23659 6213.7247 1512.4228 2685.2063 -3517.5266 -17054.035 + 9500 549.35112 -1028.3899 -2776.8124 1880.7965 9.9583733 17.248409 10.949754 -1817.8413 2754.8459 -4022.1743 -3101.1463 8397.2345 -8608.1342 + 10000 562.27081 12885.53 -2775.7435 1850.2864 9.9042316 17.154633 10.890222 15758.218 9989.5121 12908.859 -25.724137 -16691.374 267.85371 +Loop time of 3.80648 on 4 procs for 10000 steps with 144 atoms + +Performance: 226.981 ns/day, 0.106 hours/ns, 2627.100 timesteps/s +94.8% CPU use with 4 MPI tasks x 1 OpenMP threads + +MPI task timing breakdown: +Section | min time | avg time | max time |%varavg| %total +--------------------------------------------------------------- +Pair | 1.3526 | 1.6581 | 1.9634 | 21.3 | 43.56 +Kspace | 0.92143 | 1.2222 | 1.5232 | 24.7 | 32.11 +Neigh | 0 | 0 | 0 | 0.0 | 0.00 +Comm | 0.31886 | 0.32256 | 0.32604 | 0.5 | 8.47 +Output | 0.0003643 | 0.00083923 | 0.0022533 | 0.0 | 0.02 +Modify | 0.39166 | 0.45985 | 0.52607 | 8.9 | 12.08 +Other | | 0.143 | | | 3.76 + +Nlocal: 36 ave 36 max 36 min +Histogram: 4 0 0 0 0 0 0 0 0 0 +Nghost: 2614 ave 2614 max 2614 min +Histogram: 4 0 0 0 0 0 0 0 0 0 +Neighs: 10488 ave 12570 max 8406 min +Histogram: 2 0 0 0 0 0 0 0 0 2 + +Total # of neighbors = 41952 +Ave neighs/atom = 291.333 +Neighbor list builds = 0 +Dangerous builds = 0 +unfix quartz_qtb +unfix scapegoat_qtb +Total wall time: 0:00:03 diff --git a/examples/threebody/Si.sw b/examples/threebody/Si.sw deleted file mode 100644 index db4be100ef..0000000000 --- a/examples/threebody/Si.sw +++ /dev/null @@ -1,18 +0,0 @@ -# DATE: 2007-06-11 CONTRIBUTOR: Aidan Thompson, athomps@sandia.gov CITATION: Stillinger and Weber, Phys Rev B, 31, 5262, (1985) -# Stillinger-Weber parameters for various elements and mixtures -# multiple entries can be added to this file, LAMMPS reads the ones it needs -# these entries are in LAMMPS "metal" units: -# epsilon = eV; sigma = Angstroms -# other quantities are unitless - -# format of a single entry (one or more lines): -# element 1, element 2, element 3, -# epsilon, sigma, a, lambda, gamma, costheta0, A, B, p, q, tol - -# Here are the original parameters in metal units, for Silicon from: -# -# Stillinger and Weber, Phys. Rev. B, v. 31, p. 5262, (1985) -# - -Si Si Si 2.1683 2.0951 1.80 21.0 1.20 -0.333333333333 - 7.049556277 0.6022245584 4.0 0.0 0.0 diff --git a/examples/threebody/Si.sw b/examples/threebody/Si.sw new file mode 120000 index 0000000000..812023f52d --- /dev/null +++ b/examples/threebody/Si.sw @@ -0,0 +1 @@ +../../potentials/Si.sw \ No newline at end of file diff --git a/lib/awpmd/ivutils/include/pairhash.h b/lib/awpmd/ivutils/include/pairhash.h index 1fbc1b8b64..c29f72773f 100644 --- a/lib/awpmd/ivutils/include/pairhash.h +++ b/lib/awpmd/ivutils/include/pairhash.h @@ -122,12 +122,9 @@ # define PAIRHASH_H /*e @file pairhash.h @brief pair hash table -*/ +*/ -/*r @file pairhash.h @brief ðàáîòà ñ õåø-òàáëèöàìè ïàðíûõ âåëè÷èí -*/ - # include "refobj.h" @@ -146,7 +143,7 @@ public: incr=inc_first ? parent->sizex : 1 ; }; iterator(T *ptr_,size_t incr_):ptr(ptr_),incr(incr_){} - public: + public: iterator(const iterator &other):ptr(other.ptr),incr(other.incr){ } iterator():ptr(NULL),incr(0){} @@ -159,7 +156,7 @@ public: ++*this; return tmp; } - iterator operator+(int delta) const { + iterator operator+(int delta) const { return iterator(ptr+delta*incr,incr); } bool operator!=(const iterator &other) const { @@ -194,7 +191,7 @@ public: init(other.sizex,other.sizey,1); size_t n=get_datasize(sizex,sizey); for(size_t i=0;i=0){ // for changing the managed flag? @@ -241,14 +238,14 @@ public: arr=parr.ptr(); } return 1; - } + } - recmatrix(size_t nx, size_t ny):sizex(0), sizey(0){ + recmatrix(size_t nx, size_t ny):sizex(0), sizey(0){ init(nx,ny,1); } //e initializes by unmanaged pointer - recmatrix(size_t nx, size_t ny , T *ptr):parr(ptr,0),sizex(nx), sizey(ny) { + recmatrix(size_t nx, size_t ny , T *ptr):parr(ptr,0),sizex(nx), sizey(ny) { init(nx,ny); } @@ -264,14 +261,14 @@ public: size_t i, n=get_datasize(sizex,sizey); for(i=0;isizey? sizey: sizex); for(i=0;i class sqmatrix: public recmatrix { - + public: size_t size; @@ -313,18 +310,18 @@ public: return n*n; } - + virtual int init(size_t n, int smanaged=-1){ size=n; return recmatrix::init(n,n,smanaged); - } + } - sqmatrix(size_t n):size(0){ + sqmatrix(size_t n):size(0){ init(n,1); } //e initializes by unmanaged pointer - sqmatrix(size_t n, T * /* ptr */):size(n){ + sqmatrix(size_t n, T * /* ptr */):size(n){ init(n); } @@ -335,7 +332,7 @@ public: recmatrix::parr.reset(ptr,0); } - + }; @@ -355,7 +352,7 @@ public: incr=inc_first ? parent->size : 1 ; }; iterator(T *ptr_,size_t incr_):ptr(ptr_),incr(incr_){} - public: + public: iterator(const iterator &other):ptr(other.ptr),incr(other.incr){ } iterator():ptr(NULL),incr(0){} @@ -368,7 +365,7 @@ public: ++*this; return tmp; } - iterator operator+(int delta) const { + iterator operator+(int delta) const { return iterator(ptr+delta*incr,incr); } bool operator!=(const iterator &other) const { @@ -403,7 +400,7 @@ public: init(other.size,1); size_t n=get_datasize(size); for(size_t i=0;i=0){ // for changing the managed flag? @@ -448,14 +445,14 @@ public: arr=parr.ptr(); } return 1; - } + } - sqmatrix(size_t n):size(0){ + sqmatrix(size_t n):size(0){ init(n,1); } //e initializes by unmanaged pointer - sqmatrix(size_t n, T *ptr):parr(ptr,0),size(n){ + sqmatrix(size_t n, T *ptr):parr(ptr,0),size(n){ init(n); } @@ -470,14 +467,14 @@ public: size_t i, n=get_datasize(size); for(i=0;i int fileout(FILE *f, const matrix_t &matr, const char *elm_fmt, const char *elm_sep=" ", const char *line_sep="\n"){ - size_t i, j; + size_t i, j; int res=0; for(i=0;i class smatrix: public sqmatrix{ typedef sqmatrix base_t; public: - + virtual size_t get_datasize(size_t n) const{ return n*(n+1)/2; } - + size_t index(size_t i, size_t j) const { if(i>=j) return (2*base_t::size-j-1)*j/2+i; - else + else return (2*base_t::size-i-1)*i/2+j; } @@ -572,7 +569,7 @@ public: hmatrix() : smatrix() {} hmatrix(const smatrix &other) : smatrix(other) {} - + //e copy constructor: makes a managed copy hmatrix(const hmatrix &other): smatrix(other){} @@ -671,7 +668,7 @@ public: indm.Set(-1); return 1; } - + virtual ~PairHashM(){ delete [] arr; } diff --git a/lib/gpu/Makefile.hip b/lib/gpu/Makefile.hip index 62d34592d1..e2fd3c22d7 100644 --- a/lib/gpu/Makefile.hip +++ b/lib/gpu/Makefile.hip @@ -33,10 +33,10 @@ HIP_HOST_OPTS += -DMPI_GERYON -DUCL_NO_EXIT # this settings should match LAMMPS Makefile MPI_COMP_OPTS = $(shell mpicxx --showme:compile) MPI_LINK_OPTS = $(shell mpicxx --showme:link) -#MPI_COMP_OPTS += -I/usr/include/mpi -DMPICH_IGNORE_CXX_SEEK -DOMPI_SKIP_MPICXX=1 HIP_PATH ?= $(wildcard /opt/rocm/hip) -HIP_PLATFORM=$(shell $(HIP_PATH)/bin/hipconfig --compiler) +HIP_PLATFORM=$(shell $(HIP_PATH)/bin/hipconfig --platform) +HIP_COMPILER=$(shell $(HIP_PATH)/bin/hipconfig --compiler) ifeq (hcc,$(HIP_PLATFORM)) HIP_OPTS += -ffast-math @@ -48,8 +48,6 @@ else ifeq (nvcc,$(HIP_PLATFORM)) -gencode arch=compute_50,code=[sm_50,compute_50] -gencode arch=compute_52,code=[sm_52,compute_52] -gencode arch=compute_53,code=[sm_53,compute_53]\ -gencode arch=compute_60,code=[sm_60,compute_60] -gencode arch=compute_61,code=[sm_61,compute_61] -gencode arch=compute_62,code=[sm_62,compute_62]\ -gencode arch=compute_70,code=[sm_70,compute_70] -gencode arch=compute_72,code=[sm_72,compute_72] -gencode arch=compute_75,code=[sm_75,compute_75] -else - $(error Specify HIP platform using 'export HIP_PLATFORM=(hcc,nvcc)') endif BIN_DIR = . @@ -66,7 +64,15 @@ BSH = /bin/sh HIP_OPTS += -DUSE_HIP $(HIP_PRECISION) HIP_GPU_OPTS += $(HIP_OPTS) -I./ -ifeq (hcc,$(HIP_PLATFORM)) +ifeq (clang,$(HIP_COMPILER)) + HIP_HOST_OPTS += -fPIC + HIP_GPU_CC = $(HIP_PATH)/bin/hipcc --genco + HIP_GPU_OPTS_S = --offload-arch=$(HIP_ARCH) + HIP_GPU_OPTS_E = + HIP_KERNEL_SUFFIX = .cpp + HIP_LIBS_TARGET = export HCC_AMDGPU_TARGET := $(HIP_ARCH) + export HCC_AMDGPU_TARGET := $(HIP_ARCH) +else ifeq (hcc,$(HIP_COMPILER)) HIP_HOST_OPTS += -fPIC HIP_GPU_CC = $(HIP_PATH)/bin/hipcc --genco HIP_GPU_OPTS_S = -t="$(HIP_ARCH)" -f=\" diff --git a/lib/gpu/lal_lj_tip4p_long.cpp b/lib/gpu/lal_lj_tip4p_long.cpp index 5dd082df33..bb848ad5c3 100644 --- a/lib/gpu/lal_lj_tip4p_long.cpp +++ b/lib/gpu/lal_lj_tip4p_long.cpp @@ -250,22 +250,22 @@ void LJTIP4PLongT::copy_relations_data(int n, tagint *tag, int *map_array, if (ago == 0) { hneight.zero(); + { - UCL_H_Vec host_tag_write(nall,*(this->ucl_device),UCL_WRITE_ONLY); + UCL_H_Vec host_tag_write; + host_tag_write.view(tag, nall, *(this->ucl_device)); this->tag.resize_ib(nall); - for(int i=0; itag, host_tag_write, nall, false); + ucl_copy(this->tag, host_tag_write, false); } - UCL_H_Vec host_write(max_same,*(this->ucl_device),UCL_WRITE_ONLY); + UCL_H_Vec host_write; + host_write.view(sametag, max_same, *(this->ucl_device)); this->atom_sametag.resize_ib(max_same); - for(int i=0; iatom_sametag, host_write, max_same, false); + ucl_copy(this->atom_sametag, host_write, false); - host_write.resize_ib(map_size); this->map_array.resize_ib(map_size); - for(int i=0; imap_array, host_write, map_size, false); + host_write.view(map_array, map_size, *(this->ucl_device)); + ucl_copy(this->map_array, host_write, false); } } diff --git a/lib/gpu/lal_lj_tip4p_long.cu b/lib/gpu/lal_lj_tip4p_long.cu index 66c9a6071e..782ae43662 100644 --- a/lib/gpu/lal_lj_tip4p_long.cu +++ b/lib/gpu/lal_lj_tip4p_long.cu @@ -110,10 +110,8 @@ __kernel void k_lj_tip4p_long_distrib(const __global numtyp4 *restrict x_, const int typeO, const int typeH, const numtyp alpha, const __global numtyp *restrict q_, const __global acctyp4 *restrict ansO) { - int tid, ii, offset; - atom_info(t_per_atom,ii,tid,offset); - int i = BLOCK_ID_X*(BLOCK_SIZE_X)+tid; + int i = BLOCK_ID_X*(BLOCK_SIZE_X)+THREAD_ID_X; acctyp4 f; f.x=(acctyp)0; f.y=(acctyp)0; f.z=(acctyp)0; @@ -122,6 +120,8 @@ __kernel void k_lj_tip4p_long_distrib(const __global numtyp4 *restrict x_, int itype = ix.w; acctyp4 fM, vM; acctyp eM; + // placement of the virial in engv depends on eflag value + int engv_iter = eflag ? 2 : 0; if (itype == typeH) { int iO = hneigh[i*4]; if (iO < inum) { @@ -131,13 +131,13 @@ __kernel void k_lj_tip4p_long_distrib(const __global numtyp4 *restrict x_, f.z += fM.z * (acctyp)0.5 * alpha; if (vflag > 0) { vM = ansO[inum +iO]; - engv[inum*2 + i] += vM.x * (acctyp)0.5 * alpha; - engv[inum*3 + i] += vM.y * (acctyp)0.5 * alpha; - engv[inum*4 + i] += vM.z * (acctyp)0.5 * alpha; + engv[inum*engv_iter + i] += vM.x * (acctyp)0.5 * alpha; engv_iter++; + engv[inum*engv_iter + i] += vM.y * (acctyp)0.5 * alpha; engv_iter++; + engv[inum*engv_iter + i] += vM.z * (acctyp)0.5 * alpha; engv_iter++; vM = ansO[inum*2+iO]; - engv[inum*5 + i] += vM.x * (acctyp)0.5 * alpha; - engv[inum*6 + i] += vM.y * (acctyp)0.5 * alpha; - engv[inum*7 + i] += vM.z * (acctyp)0.5 * alpha; + engv[inum*engv_iter + i] += vM.x * (acctyp)0.5 * alpha; engv_iter++; + engv[inum*engv_iter + i] += vM.y * (acctyp)0.5 * alpha; engv_iter++; + engv[inum*engv_iter + i] += vM.z * (acctyp)0.5 * alpha; } } } else { @@ -155,13 +155,13 @@ __kernel void k_lj_tip4p_long_distrib(const __global numtyp4 *restrict x_, } if (vflag > 0) { vM = ansO[inum + i]; - engv[inum*2 + i] += vM.x * (acctyp)(1 - alpha); - engv[inum*3 + i] += vM.y * (acctyp)(1 - alpha); - engv[inum*4 + i] += vM.z * (acctyp)(1 - alpha); + engv[inum*engv_iter + i] += vM.x * (acctyp)(1 - alpha); engv_iter++; + engv[inum*engv_iter + i] += vM.y * (acctyp)(1 - alpha); engv_iter++; + engv[inum*engv_iter + i] += vM.z * (acctyp)(1 - alpha); engv_iter++; vM = ansO[inum*2 + i]; - engv[inum*5 + i] += vM.x * (acctyp)(1 - alpha); - engv[inum*6 + i] += vM.y * (acctyp)(1 - alpha); - engv[inum*7 + i] += vM.z * (acctyp)(1 - alpha); + engv[inum*engv_iter + i] += vM.x * (acctyp)(1 - alpha); engv_iter++; + engv[inum*engv_iter + i] += vM.y * (acctyp)(1 - alpha); engv_iter++; + engv[inum*engv_iter + i] += vM.z * (acctyp)(1 - alpha); } } acctyp4 old=ans[i]; @@ -182,9 +182,8 @@ __kernel void k_lj_tip4p_reneigh(const __global numtyp4 *restrict x_, const int typeO, const int typeH, const __global tagint *restrict tag, const __global int *restrict map, const __global int *restrict sametag) { - int tid, ii, offset; - atom_info(t_per_atom,ii,tid,offset); - int i = BLOCK_ID_X*(BLOCK_SIZE_X)+tid; + + int i = BLOCK_ID_X*(BLOCK_SIZE_X)+THREAD_ID_X; if (i +#include #include "modify.h" #include "error.h" @@ -35,35 +36,21 @@ FixNPHAsphere::FixNPHAsphere(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); + std::string tcmd = id + std::string("_temp"); + id_temp = new char[tcmd.size()+1]; + strcpy(id_temp,tcmd.c_str()); - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp/asphere"; - - modify->add_compute(3,newarg); - delete [] newarg; + modify->add_compute(tcmd + " all temp/asphere"); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); + std::string pcmd = id + std::string("_press"); + id_press = new char[pcmd.size()+1]; + strcpy(id_press,pcmd.c_str()); - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + modify->add_compute(pcmd + " all pressure " + std::string(id_temp)); pcomputeflag = 1; } diff --git a/src/ASPHERE/fix_npt_asphere.cpp b/src/ASPHERE/fix_npt_asphere.cpp index 26d4fff81d..f7f253f40b 100644 --- a/src/ASPHERE/fix_npt_asphere.cpp +++ b/src/ASPHERE/fix_npt_asphere.cpp @@ -13,6 +13,7 @@ #include "fix_npt_asphere.h" #include +#include #include "modify.h" #include "error.h" @@ -34,35 +35,21 @@ FixNPTAsphere::FixNPTAsphere(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); + std::string tcmd = id + std::string("_temp"); + id_temp = new char[tcmd.size()+1]; + strcpy(id_temp,tcmd.c_str()); - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp/asphere"; - - modify->add_compute(3,newarg); - delete [] newarg; + modify->add_compute(tcmd + " all temp/asphere"); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); + std::string pcmd = id + std::string("_press"); + id_press = new char[pcmd.size()+1]; + strcpy(id_press,pcmd.c_str()); - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + modify->add_compute(pcmd + " all pressure " + std::string(id_temp)); pcomputeflag = 1; } diff --git a/src/ASPHERE/fix_nvt_asphere.cpp b/src/ASPHERE/fix_nvt_asphere.cpp index 597fb03514..e0275d4acf 100644 --- a/src/ASPHERE/fix_nvt_asphere.cpp +++ b/src/ASPHERE/fix_nvt_asphere.cpp @@ -13,9 +13,11 @@ #include "fix_nvt_asphere.h" #include +#include #include "group.h" #include "modify.h" #include "error.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -33,17 +35,11 @@ FixNVTAsphere::FixNVTAsphere(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); + std::string cmd = id + std::string("_temp"); + id_temp = new char[cmd.size()+1]; + strcpy(id_temp,cmd.c_str()); - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = group->names[igroup]; - newarg[2] = (char *) "temp/asphere"; - - modify->add_compute(3,newarg); - delete [] newarg; + cmd += fmt::format(" {} temp/asphere",group->names[igroup]); + modify->add_compute(cmd); tcomputeflag = 1; } diff --git a/src/BODY/fix_nph_body.cpp b/src/BODY/fix_nph_body.cpp index a65c951c96..8dc1b568da 100644 --- a/src/BODY/fix_nph_body.cpp +++ b/src/BODY/fix_nph_body.cpp @@ -17,6 +17,7 @@ #include "fix_nph_body.h" #include +#include #include "modify.h" #include "error.h" @@ -38,35 +39,21 @@ FixNPHBody::FixNPHBody(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); + std::string tcmd = id + std::string("_temp"); + id_temp = new char[tcmd.size()+1]; + strcpy(id_temp,tcmd.c_str()); - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp/body"; - - modify->add_compute(3,newarg); - delete [] newarg; + modify->add_compute(tcmd + " all temp/body"); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); + std::string pcmd = id + std::string("_press"); + id_press = new char[pcmd.size()+1]; + strcpy(id_press,pcmd.c_str()); - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + modify->add_compute(pcmd + " all pressure " + std::string(id_temp)); pcomputeflag = 1; } diff --git a/src/BODY/fix_npt_body.cpp b/src/BODY/fix_npt_body.cpp index 7e8097486e..a4b6b2263c 100644 --- a/src/BODY/fix_npt_body.cpp +++ b/src/BODY/fix_npt_body.cpp @@ -17,6 +17,7 @@ #include "fix_npt_body.h" #include +#include #include "modify.h" #include "error.h" @@ -38,35 +39,21 @@ FixNPTBody::FixNPTBody(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); + std::string tcmd = id + std::string("_temp"); + id_temp = new char[tcmd.size()+1]; + strcpy(id_temp,tcmd.c_str()); - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp/body"; - - modify->add_compute(3,newarg); - delete [] newarg; + modify->add_compute(tcmd + " all temp/body"); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); + std::string pcmd = id + std::string("_press"); + id_press = new char[pcmd.size()+1]; + strcpy(id_press,pcmd.c_str()); - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + modify->add_compute(pcmd + " all pressure " + std::string(id_temp)); pcomputeflag = 1; } diff --git a/src/BODY/fix_nvt_body.cpp b/src/BODY/fix_nvt_body.cpp index efb05143a1..10da2d6f42 100644 --- a/src/BODY/fix_nvt_body.cpp +++ b/src/BODY/fix_nvt_body.cpp @@ -17,6 +17,7 @@ #include "fix_nvt_body.h" #include +#include #include "group.h" #include "modify.h" #include "error.h" @@ -37,17 +38,10 @@ FixNVTBody::FixNVTBody(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); + std::string tcmd = id + std::string("_temp"); + id_temp = new char[tcmd.size()+1]; + strcpy(id_temp,tcmd.c_str()); - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = group->names[igroup]; - newarg[2] = (char *) "temp/body"; - - modify->add_compute(3,newarg); - delete [] newarg; + modify->add_compute(tcmd + " all temp/body"); tcomputeflag = 1; } diff --git a/src/BODY/pair_body_rounded_polygon.cpp b/src/BODY/pair_body_rounded_polygon.cpp index 8e51f3ac5f..22a6d82b44 100644 --- a/src/BODY/pair_body_rounded_polygon.cpp +++ b/src/BODY/pair_body_rounded_polygon.cpp @@ -236,7 +236,7 @@ void PairBodyRoundedPolygon::compute(int eflag, int vflag) edge[jefirst+nj][4] = 0; } - int interact, num_contacts, done; + int num_contacts, done; double delta_a, j_a; Contact contact_list[MAX_CONTACTS]; @@ -244,15 +244,13 @@ void PairBodyRoundedPolygon::compute(int eflag, int vflag) // check interaction between i's vertices and j' edges - interact = vertex_against_edge(i, j, k_nij, k_naij, - x, f, torque, tag, contact_list, - num_contacts, evdwl, facc); + vertex_against_edge(i, j, k_nij, k_naij, x, f, torque, tag, + contact_list, num_contacts, evdwl, facc); // check interaction between j's vertices and i' edges - interact = vertex_against_edge(j, i, k_nij, k_naij, - x, f, torque, tag, contact_list, - num_contacts, evdwl, facc); + vertex_against_edge(j, i, k_nij, k_naij, x, f, torque, tag, + contact_list, num_contacts, evdwl, facc); if (num_contacts >= 2) { @@ -595,7 +593,7 @@ void PairBodyRoundedPolygon::sphere_against_sphere(int i, int j, { double rradi,rradj; double vr1,vr2,vr3,vnnr,vn1,vn2,vn3,vt1,vt2,vt3; - double rij,rsqinv,R,fx,fy,fz,fpair,shift,energy; + double rij,rsqinv,R,fx,fy,fz,fn[3],ft[3],fpair,shift,energy; int nlocal = atom->nlocal; int newton_pair = force->newton_pair; @@ -641,6 +639,23 @@ void PairBodyRoundedPolygon::sphere_against_sphere(int i, int j, vt1 = vr1 - vn1; vt2 = vr2 - vn2; vt3 = vr3 - vn3; + + // normal friction term at contact + + fn[0] = -c_n * vn1; + fn[1] = -c_n * vn2; + fn[2] = -c_n * vn3; + + // tangential friction term at contact, + // excluding the tangential deformation term for now + + ft[0] = -c_t * vt1; + ft[1] = -c_t * vt2; + ft[2] = -c_t * vt3; + + fx += fn[0] + ft[0]; + fy += fn[1] + ft[1]; + fz += fn[2] + ft[2]; } f[i][0] += fx; @@ -1349,4 +1364,3 @@ void PairBodyRoundedPolygon::distance(const double* x2, const double* x1, + (x2[1] - x1[1]) * (x2[1] - x1[1]) + (x2[2] - x1[2]) * (x2[2] - x1[2])); } - diff --git a/src/CLASS2/dihedral_class2.cpp b/src/CLASS2/dihedral_class2.cpp index 6b43257908..73b6a420e8 100644 --- a/src/CLASS2/dihedral_class2.cpp +++ b/src/CLASS2/dihedral_class2.cpp @@ -28,6 +28,7 @@ #include "memory.h" #include "error.h" #include "utils.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace MathConst; @@ -207,24 +208,16 @@ void DihedralClass2::compute(int eflag, int vflag) // error check if (c > 1.0 + TOLERANCE || c < (-1.0 - TOLERANCE)) { - int me; - MPI_Comm_rank(world,&me); + int me = comm->me; if (screen) { - char str[128]; - sprintf(str,"Dihedral problem: %d " BIGINT_FORMAT " " - TAGINT_FORMAT " " TAGINT_FORMAT " " - TAGINT_FORMAT " " TAGINT_FORMAT, - me,update->ntimestep, - atom->tag[i1],atom->tag[i2],atom->tag[i3],atom->tag[i4]); - error->warning(FLERR,str,0); - fprintf(screen," 1st atom: %d %g %g %g\n", - me,x[i1][0],x[i1][1],x[i1][2]); - fprintf(screen," 2nd atom: %d %g %g %g\n", - me,x[i2][0],x[i2][1],x[i2][2]); - fprintf(screen," 3rd atom: %d %g %g %g\n", - me,x[i3][0],x[i3][1],x[i3][2]); - fprintf(screen," 4th atom: %d %g %g %g\n", - me,x[i4][0],x[i4][1],x[i4][2]); + error->warning(FLERR,fmt::format("Dihedral problem: {} {} {} {} {} {}", + me,update->ntimestep, + atom->tag[i1],atom->tag[i2], + atom->tag[i3],atom->tag[i4])); + fmt::print(screen," 1st atom: {} {} {} {}\n",me,x[i1][0],x[i1][1],x[i1][2]); + fmt::print(screen," 2nd atom: {} {} {} {}\n",me,x[i2][0],x[i2][1],x[i2][2]); + fmt::print(screen," 3rd atom: {} {} {} {}\n",me,x[i3][0],x[i3][1],x[i3][2]); + fmt::print(screen," 4th atom: {} {} {} {}\n",me,x[i4][0],x[i4][1],x[i4][2]); } } diff --git a/src/CLASS2/improper_class2.cpp b/src/CLASS2/improper_class2.cpp index a3b8b4b672..2d5918fdef 100644 --- a/src/CLASS2/improper_class2.cpp +++ b/src/CLASS2/improper_class2.cpp @@ -28,6 +28,7 @@ #include "memory.h" #include "error.h" #include "utils.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace MathConst; @@ -153,24 +154,16 @@ void ImproperClass2::compute(int eflag, int vflag) for (i = 0; i < 3; i++) { if (costheta[i] == -1.0) { - int me; - MPI_Comm_rank(world,&me); + int me = comm->me; if (screen) { - char str[128]; - sprintf(str,"Improper problem: %d " BIGINT_FORMAT " " - TAGINT_FORMAT " " TAGINT_FORMAT " " - TAGINT_FORMAT " " TAGINT_FORMAT, - me,update->ntimestep, - atom->tag[i1],atom->tag[i2],atom->tag[i3],atom->tag[i4]); - error->warning(FLERR,str,0); - fprintf(screen," 1st atom: %d %g %g %g\n", - me,x[i1][0],x[i1][1],x[i1][2]); - fprintf(screen," 2nd atom: %d %g %g %g\n", - me,x[i2][0],x[i2][1],x[i2][2]); - fprintf(screen," 3rd atom: %d %g %g %g\n", - me,x[i3][0],x[i3][1],x[i3][2]); - fprintf(screen," 4th atom: %d %g %g %g\n", - me,x[i4][0],x[i4][1],x[i4][2]); + error->warning(FLERR,fmt::format("Improper problem: {} {} {} {} {} {}", + me,update->ntimestep, + atom->tag[i1],atom->tag[i2], + atom->tag[i3],atom->tag[i4])); + fmt::print(screen," 1st atom: {} {} {} {}\n",me,x[i1][0],x[i1][1],x[i1][2]); + fmt::print(screen," 2nd atom: {} {} {} {}\n",me,x[i2][0],x[i2][1],x[i2][2]); + fmt::print(screen," 3rd atom: {} {} {} {}\n",me,x[i3][0],x[i3][1],x[i3][2]); + fmt::print(screen," 4th atom: {} {} {} {}\n",me,x[i4][0],x[i4][1],x[i4][2]); } } } diff --git a/src/CORESHELL/compute_temp_cs.cpp b/src/CORESHELL/compute_temp_cs.cpp index 0dc03e47f2..d8f952551d 100644 --- a/src/CORESHELL/compute_temp_cs.cpp +++ b/src/CORESHELL/compute_temp_cs.cpp @@ -19,6 +19,7 @@ #include "compute_temp_cs.h" #include #include +#include #include "atom.h" #include "atom_vec.h" #include "domain.h" @@ -30,6 +31,7 @@ #include "comm.h" #include "memory.h" #include "error.h" +#include "fmt/format.h" using namespace LAMMPS_NS; @@ -66,21 +68,13 @@ ComputeTempCS::ComputeTempCS(LAMMPS *lmp, int narg, char **arg) : // create a new fix STORE style // id = compute-ID + COMPUTE_STORE, fix group = compute group - int n = strlen(id) + strlen("_COMPUTE_STORE") + 1; - id_fix = new char[n]; - strcpy(id_fix,id); - strcat(id_fix,"_COMPUTE_STORE"); + std::string fixcmd = id + std::string("_COMPUTE_STORE"); + id_fix = new char[fixcmd.size()+1]; + strcpy(id_fix,fixcmd.c_str()); - char **newarg = new char*[6]; - newarg[0] = id_fix; - newarg[1] = group->names[igroup]; - newarg[2] = (char *) "STORE"; - newarg[3] = (char *) "peratom"; - newarg[4] = (char *) "0"; - newarg[5] = (char *) "1"; - modify->add_fix(6,newarg); + fixcmd += fmt::format(" {} STORE peratom 0 1", group->names[igroup]); + modify->add_fix(fixcmd); fix = (FixStore *) modify->fix[modify->nfix-1]; - delete [] newarg; // set fix store values = 0 for now // fill them in via setup() once Comm::borders() has been called diff --git a/src/GPU/pair_eam_alloy_gpu.cpp b/src/GPU/pair_eam_alloy_gpu.cpp index 1fbdbf9ba8..275838385c 100644 --- a/src/GPU/pair_eam_alloy_gpu.cpp +++ b/src/GPU/pair_eam_alloy_gpu.cpp @@ -371,8 +371,14 @@ void PairEAMAlloyGPU::read_file(char *filename) // read potential file if(comm->me == 0) { - PotentialFileReader reader(lmp, filename, "EAM"); + PotentialFileReader reader(PairEAM::lmp, filename, + "EAMAlloy", unit_convert_flag); + // transparently convert units for supported conversions + + int unit_convert = reader.get_unit_convert(); + double conversion_factor = utils::get_conversion_factor(utils::ENERGY, + unit_convert); try { reader.skip_line(); reader.skip_line(); @@ -417,11 +423,19 @@ void PairEAMAlloyGPU::read_file(char *filename) reader.next_dvector(&file->frho[i][1], file->nrho); reader.next_dvector(&file->rhor[i][1], file->nr); + if (unit_convert) { + for (int j = 1; j < file->nrho; ++j) + file->frho[i][j] *= conversion_factor; + } } for (int i = 0; i < file->nelements; i++) { for (int j = 0; j <= i; j++) { reader.next_dvector(&file->z2r[i][j][1], file->nr); + if (unit_convert) { + for (int k = 1; k < file->nr; ++k) + file->z2r[i][j][k] *= conversion_factor; + } } } } catch (TokenizerException & e) { diff --git a/src/GPU/pair_eam_fs_gpu.cpp b/src/GPU/pair_eam_fs_gpu.cpp index a316d08c54..271cb313da 100644 --- a/src/GPU/pair_eam_fs_gpu.cpp +++ b/src/GPU/pair_eam_fs_gpu.cpp @@ -371,8 +371,14 @@ void PairEAMFSGPU::read_file(char *filename) // read potential file if(comm->me == 0) { - PotentialFileReader reader(lmp, filename, "EAM"); + PotentialFileReader reader(PairEAM::lmp, filename, "EAMFS", + unit_convert_flag); + // transparently convert units for supported conversions + + int unit_convert = reader.get_unit_convert(); + double conversion_factor = utils::get_conversion_factor(utils::ENERGY, + unit_convert); try { reader.skip_line(); reader.skip_line(); @@ -416,6 +422,10 @@ void PairEAMFSGPU::read_file(char *filename) file->mass[i] = values.next_double(); reader.next_dvector(&file->frho[i][1], file->nrho); + if (unit_convert) { + for (int j = 1; j <= file->nrho; ++j) + file->frho[i][j] *= conversion_factor; + } for (int j = 0; j < file->nelements; j++) { reader.next_dvector(&file->rhor[i][j][1], file->nr); @@ -425,6 +435,10 @@ void PairEAMFSGPU::read_file(char *filename) for (int i = 0; i < file->nelements; i++) { for (int j = 0; j <= i; j++) { reader.next_dvector(&file->z2r[i][j][1], file->nr); + if (unit_convert) { + for (int k = 1; k <= file->nr; ++k) + file->z2r[i][j][k] *= conversion_factor; + } } } } catch (TokenizerException & e) { diff --git a/src/GPU/pair_lj_cut_tip4p_long_gpu.cpp b/src/GPU/pair_lj_cut_tip4p_long_gpu.cpp index c0304f19ae..7c1bb74158 100644 --- a/src/GPU/pair_lj_cut_tip4p_long_gpu.cpp +++ b/src/GPU/pair_lj_cut_tip4p_long_gpu.cpp @@ -109,10 +109,7 @@ PairLJCutTIP4PLongGPU::~PairLJCutTIP4PLongGPU() void PairLJCutTIP4PLongGPU::compute(int eflag, int vflag) { - - if (eflag || vflag) ev_setup(eflag,vflag); - else evflag = vflag_fdotr = 0; - + ev_init(eflag,vflag); int nall = atom->nlocal + atom->nghost; int inum, host_start; diff --git a/src/GRANULAR/pair_gran_hooke_history.cpp b/src/GRANULAR/pair_gran_hooke_history.cpp index 29ca53d361..af46d813ca 100644 --- a/src/GRANULAR/pair_gran_hooke_history.cpp +++ b/src/GRANULAR/pair_gran_hooke_history.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include "atom.h" #include "force.h" #include "update.h" @@ -65,13 +66,7 @@ PairGranHookeHistory::PairGranHookeHistory(LAMMPS *lmp) : Pair(lmp) // this is so final order of Modify:fix will conform to input script fix_history = NULL; - - char **fixarg = new char*[3]; - fixarg[0] = (char *) "NEIGH_HISTORY_HH_DUMMY"; - fixarg[1] = (char *) "all"; - fixarg[2] = (char *) "DUMMY"; - modify->add_fix(3,fixarg,1); - delete [] fixarg; + modify->add_fix("NEIGH_HISTORY_HH_DUMMY all DUMMY"); fix_dummy = (FixDummy *) modify->fix[modify->nfix-1]; } diff --git a/src/GRANULAR/pair_granular.cpp b/src/GRANULAR/pair_granular.cpp index fef8ded5f7..1784f4562c 100644 --- a/src/GRANULAR/pair_granular.cpp +++ b/src/GRANULAR/pair_granular.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include "atom.h" #include "force.h" #include "update.h" @@ -96,13 +97,7 @@ PairGranular::PairGranular(LAMMPS *lmp) : Pair(lmp) // this is so final order of Modify:fix will conform to input script fix_history = NULL; - - char **fixarg = new char*[3]; - fixarg[0] = (char *) "NEIGH_HISTORY_GRANULAR_DUMMY"; - fixarg[1] = (char *) "all"; - fixarg[2] = (char *) "DUMMY"; - modify->add_fix(3,fixarg,1); - delete [] fixarg; + modify->add_fix("NEIGH_HISTORY_GRANULAR_DUMMY all DUMMY"); fix_dummy = (FixDummy *) modify->fix[modify->nfix-1]; } diff --git a/src/KIM/kim_init.cpp b/src/KIM/kim_init.cpp index 57112997ab..f90db79aa7 100644 --- a/src/KIM/kim_init.cpp +++ b/src/KIM/kim_init.cpp @@ -291,11 +291,7 @@ void KimInit::do_init(char *model_name, char *user_units, char *model_units, KIM int ifix = modify->find_fix("KIM_MODEL_STORE"); if (ifix >= 0) modify->delete_fix(ifix); - char *fixarg[3]; - fixarg[0] = (char *)"KIM_MODEL_STORE"; - fixarg[1] = (char *)"all"; - fixarg[2] = (char *)"STORE/KIM"; - modify->add_fix(3,fixarg); + modify->add_fix("KIM_MODEL_STORE all STORE/KIM"); ifix = modify->find_fix("KIM_MODEL_STORE"); FixStoreKIM *fix_store = (FixStoreKIM *) modify->fix[ifix]; diff --git a/src/KOKKOS/atom_vec_kokkos.h b/src/KOKKOS/atom_vec_kokkos.h index b93fb42e75..7d8796b1ae 100644 --- a/src/KOKKOS/atom_vec_kokkos.h +++ b/src/KOKKOS/atom_vec_kokkos.h @@ -103,14 +103,14 @@ class AtomVecKokkos : public AtomVec { ExecutionSpace space) = 0; virtual int - pack_border_vel_kokkos(int n, DAT::tdual_int_2d k_sendlist, - DAT::tdual_xfloat_2d buf,int iswap, - int pbc_flag, int *pbc, ExecutionSpace space) { return 0; } + pack_border_vel_kokkos(int /*n*/, DAT::tdual_int_2d /*k_sendlist*/, + DAT::tdual_xfloat_2d /*buf*/,int /*iswap*/, + int /*pbc_flag*/, int * /*pbc*/, ExecutionSpace /*space*/) { return 0; } virtual void - unpack_border_vel_kokkos(const int &n, const int &nfirst, - const DAT::tdual_xfloat_2d &buf, - ExecutionSpace space) {} + unpack_border_vel_kokkos(const int &/*n*/, const int & /*nfirst*/, + const DAT::tdual_xfloat_2d & /*buf*/, + ExecutionSpace /*space*/) {} virtual int pack_exchange_kokkos(const int &nsend, DAT::tdual_xfloat_2d &buf, diff --git a/src/KOKKOS/kokkos_type.h b/src/KOKKOS/kokkos_type.h index 796f4612a4..29f98725ba 100644 --- a/src/KOKKOS/kokkos_type.h +++ b/src/KOKKOS/kokkos_type.h @@ -272,7 +272,7 @@ template class ScatterViewHelper { public: KOKKOS_INLINE_FUNCTION - static T1 get(const T1 &dup, const T2 &nondup) { + static T1 get(const T1 &dup, const T2 & /*nondup*/) { return dup; } }; @@ -1025,7 +1025,7 @@ struct params_lj_coul { KOKKOS_INLINE_FUNCTION params_lj_coul(){cut_ljsq=0;cut_coulsq=0;lj1=0;lj2=0;lj3=0;lj4=0;offset=0;}; KOKKOS_INLINE_FUNCTION - params_lj_coul(int i){cut_ljsq=0;cut_coulsq=0;lj1=0;lj2=0;lj3=0;lj4=0;offset=0;}; + params_lj_coul(int /*i*/){cut_ljsq=0;cut_coulsq=0;lj1=0;lj2=0;lj3=0;lj4=0;offset=0;}; F_FLOAT cut_ljsq,cut_coulsq,lj1,lj2,lj3,lj4,offset; }; diff --git a/src/KOKKOS/pair_eam_alloy_kokkos.cpp b/src/KOKKOS/pair_eam_alloy_kokkos.cpp index 2d0d229e00..2f03c5b00e 100644 --- a/src/KOKKOS/pair_eam_alloy_kokkos.cpp +++ b/src/KOKKOS/pair_eam_alloy_kokkos.cpp @@ -985,8 +985,13 @@ void PairEAMAlloyKokkos::read_file(char *filename) // read potential file if(comm->me == 0) { - PotentialFileReader reader(lmp, filename, "EAM"); + PotentialFileReader reader(lmp, filename, "EAMAlloy", unit_convert_flag); + // transparently convert units for supported conversions + + int unit_convert = reader.get_unit_convert(); + double conversion_factor = utils::get_conversion_factor(utils::ENERGY, + unit_convert); try { reader.skip_line(); reader.skip_line(); @@ -1031,11 +1036,19 @@ void PairEAMAlloyKokkos::read_file(char *filename) reader.next_dvector(&file->frho[i][1], file->nrho); reader.next_dvector(&file->rhor[i][1], file->nr); + if (unit_convert) { + for (int j = 1; j < file->nrho; ++j) + file->frho[i][j] *= conversion_factor; + } } for (int i = 0; i < file->nelements; i++) { for (int j = 0; j <= i; j++) { reader.next_dvector(&file->z2r[i][j][1], file->nr); + if (unit_convert) { + for (int k = 1; k < file->nr; ++k) + file->z2r[i][j][k] *= conversion_factor; + } } } } catch (TokenizerException & e) { diff --git a/src/KOKKOS/pair_eam_fs_kokkos.cpp b/src/KOKKOS/pair_eam_fs_kokkos.cpp index 8b1e6b348a..3bd5c644c6 100644 --- a/src/KOKKOS/pair_eam_fs_kokkos.cpp +++ b/src/KOKKOS/pair_eam_fs_kokkos.cpp @@ -985,8 +985,13 @@ void PairEAMFSKokkos::read_file(char *filename) // read potential file if(comm->me == 0) { - PotentialFileReader reader(lmp, filename, "EAM"); + PotentialFileReader reader(lmp, filename, "EAMFS", unit_convert_flag); + // transparently convert units for supported conversions + + int unit_convert = reader.get_unit_convert(); + double conversion_factor = utils::get_conversion_factor(utils::ENERGY, + unit_convert); try { reader.skip_line(); reader.skip_line(); @@ -1030,6 +1035,10 @@ void PairEAMFSKokkos::read_file(char *filename) file->mass[i] = values.next_double(); reader.next_dvector(&file->frho[i][1], file->nrho); + if (unit_convert) { + for (int j = 1; j <= file->nrho; ++j) + file->frho[i][j] *= conversion_factor; + } for (int j = 0; j < file->nelements; j++) { reader.next_dvector(&file->rhor[i][j][1], file->nr); @@ -1039,6 +1048,10 @@ void PairEAMFSKokkos::read_file(char *filename) for (int i = 0; i < file->nelements; i++) { for (int j = 0; j <= i; j++) { reader.next_dvector(&file->z2r[i][j][1], file->nr); + if (unit_convert) { + for (int k = 1; k < file->nr; ++k) + file->z2r[i][j][k] *= conversion_factor; + } } } } catch (TokenizerException & e) { diff --git a/src/KOKKOS/pair_snap_kokkos_impl.h b/src/KOKKOS/pair_snap_kokkos_impl.h index 6bedf5554e..d6c677d14c 100644 --- a/src/KOKKOS/pair_snap_kokkos_impl.h +++ b/src/KOKKOS/pair_snap_kokkos_impl.h @@ -632,8 +632,8 @@ void PairSNAPKokkos::operator() (TagPairSNAPComputeNeigh,const typen template KOKKOS_INLINE_FUNCTION void PairSNAPKokkos::operator() (TagPairSNAPBeta,const int& ii) const { - - if (ii >= chunk_size) return; + + if (ii >= chunk_size) return; const int iatom_mod = ii % 32; const int iatom_div = ii / 32; diff --git a/src/KOKKOS/sna_kokkos.h b/src/KOKKOS/sna_kokkos.h index 121f293633..7edac7de00 100644 --- a/src/KOKKOS/sna_kokkos.h +++ b/src/KOKKOS/sna_kokkos.h @@ -160,17 +160,17 @@ inline t_sna_3c_ll ulist; t_sna_3c_ll ylist; - + // derivatives of data t_sna_4c3_ll dulist; - + // Modified structures for GPU backend t_sna_3d_ll ulisttot_re; // split real, t_sna_3d_ll ulisttot_im; // imag t_sna_4c_ll ulisttot_pack; // AoSoA layout t_sna_4c_ll zlist_pack; // AoSoA layout t_sna_4d_ll blist_pack; - t_sna_4d_ll ylist_pack_re; // split real, + t_sna_4d_ll ylist_pack_re; // split real, t_sna_4d_ll ylist_pack_im; // imag AoSoA layout int idxcg_max, idxu_max, idxz_max, idxb_max; diff --git a/src/KOKKOS/sna_kokkos_impl.h b/src/KOKKOS/sna_kokkos_impl.h index 866b4c516f..b017751c60 100644 --- a/src/KOKKOS/sna_kokkos_impl.h +++ b/src/KOKKOS/sna_kokkos_impl.h @@ -295,7 +295,7 @@ void SNAKokkos::pre_ui(const typename Kokkos::TeamPolicy // if m is on the "diagonal", initialize it with the self energy. // Otherwise zero it out - double re_part = 0.; + double re_part = 0.; if (m % (j+2) == 0 && (!chem_flag || ielem == jelem || wselfall_flag)) { re_part = wself; } ulisttot_re(jjup, jelem, iatom) = re_part; @@ -368,7 +368,6 @@ void SNAKokkos::compute_ui(const typename Kokkos::TeamPolicy::compute_ui(const typename Kokkos::TeamPolicy::compute_bi(const int& iatom_mod, const int& jjb, con int idouble = 0; for (int elem1 = 0; elem1 < nelements; elem1++) { for (int elem2 = 0; elem2 < nelements; elem2++) { - const int jalloy = idouble; - for (int elem3 = 0; elem3 < nelements; elem3++) { - const int jjballoy = itriple; double sumzu = 0.0; double sumzu_temp = 0.0; @@ -566,7 +562,7 @@ void SNAKokkos::compute_bi(const int& iatom_mod, const int& jjb, con const int jjz_index = jjz+mb*(j+1)+ma; if (2*mb == j) return; // I think we can remove this? const auto utot = ulisttot_pack(iatom_mod, jju_index, elem3, iatom_div); - const auto zloc = zlist_pack(iatom_mod, jjz_index, jalloy, iatom_div); + const auto zloc = zlist_pack(iatom_mod, jjz_index, idouble, iatom_div); sumzu_temp += utot.re * zloc.re + utot.im * zloc.im; } } @@ -582,7 +578,7 @@ void SNAKokkos::compute_bi(const int& iatom_mod, const int& jjb, con const int jjz_index = jjz+(mb-1)*(j+1)+(j+1)+ma; const auto utot = ulisttot_pack(iatom_mod, jju_index, elem3, iatom_div); - const auto zloc = zlist_pack(iatom_mod, jjz_index, jalloy, iatom_div); + const auto zloc = zlist_pack(iatom_mod, jjz_index, idouble, iatom_div); sumzu_temp += utot.re * zloc.re + utot.im * zloc.im; } @@ -593,7 +589,7 @@ void SNAKokkos::compute_bi(const int& iatom_mod, const int& jjb, con const int jjz_index = jjz+(mb-1)*(j+1)+(j+1)+ma; const auto utot = ulisttot_pack(iatom_mod, jju_index, elem3, iatom_div); - const auto zloc = zlist_pack(iatom_mod, jjz_index, jalloy, iatom_div); + const auto zloc = zlist_pack(iatom_mod, jjz_index, idouble, iatom_div); sumzu += 0.5 * (utot.re * zloc.re + utot.im * zloc.im); } // end if jeven @@ -607,10 +603,10 @@ void SNAKokkos::compute_bi(const int& iatom_mod, const int& jjb, con sumzu -= bzero[j]; } } - blist_pack(iatom_mod, jjb, jjballoy, iatom_div) = sumzu; + blist_pack(iatom_mod, jjb, itriple, iatom_div) = sumzu; //} // end loop over j //} // end loop over j1, j2 - itriple++; + itriple++; } // end loop over elem3 idouble++; } // end loop over elem2 @@ -791,7 +787,7 @@ void SNAKokkos::compute_fused_deidrj(const typename Kokkos::TeamPoli // single has a warp barrier at the end Kokkos::single(Kokkos::PerThread(team), [=]() { - + ulist_buf1[0] = {1., 0.}; dulist_buf1[0] = {0., 0.}; }); @@ -881,7 +877,7 @@ void SNAKokkos::compute_fused_deidrj(const typename Kokkos::TeamPoli // u[ma-j][mb-j] = (-1)^(ma-mb)*Conj([u[ma][mb]) if (j%2==1 && mb+1==n_mb) { int sign_factor = (((ma+mb)%2==0)?1:-1); - + const int jju_shared_flip = (j+1-mb)*(j+1)-(ma+1); if (sign_factor == 1) { @@ -1078,12 +1074,11 @@ void SNAKokkos::compute_bi_cpu(const typename Kokkos::TeamPolicy::compute_bi_cpu(const typename Kokkos::TeamPolicy::compute_bi_cpu(const typename Kokkos::TeamPolicy::memory_usage() { int jdimpq = twojmax + 2; int jdim = twojmax + 1; - int natom_pad = ((natom + 32 - 1) / 32) * 32; // for AoSoA layouts double bytes; bytes = 0; @@ -2035,11 +2029,10 @@ double SNAKokkos::memory_usage() bytes += jdimpq*jdimpq * sizeof(double); // pqarray bytes += idxcg_max * sizeof(double); // cglist - - #ifdef KOKKOS_ENABLE_CUDA if (std::is_same::value) { - + int natom_pad = ((natom + 32 - 1) / 32) * 32; // for AoSoA layouts + bytes += natom * idxu_max * nelements * sizeof(double); // ulisttot_re bytes += natom * idxu_max * nelements * sizeof(double); // ulisttot_im bytes += natom_pad * idxu_max * nelements * sizeof(double) * 2; // ulisttot_pack diff --git a/src/KSPACE/ewald.cpp b/src/KSPACE/ewald.cpp index bbadad8505..faa8944368 100644 --- a/src/KSPACE/ewald.cpp +++ b/src/KSPACE/ewald.cpp @@ -21,6 +21,7 @@ #include "ewald.h" #include #include +#include #include "atom.h" #include "comm.h" #include "force.h" @@ -29,6 +30,8 @@ #include "math_const.h" #include "memory.h" #include "error.h" +#include "utils.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace MathConst; @@ -88,10 +91,7 @@ Ewald::~Ewald() void Ewald::init() { - if (comm->me == 0) { - if (screen) fprintf(screen,"Ewald initialization ...\n"); - if (logfile) fprintf(logfile,"Ewald initialization ...\n"); - } + if (comm->me == 0) utils::logmesg(lmp,"Ewald initialization ...\n"); // error check @@ -185,28 +185,16 @@ void Ewald::init() // stats if (comm->me == 0) { - if (screen) { - fprintf(screen," G vector (1/distance) = %g\n",g_ewald); - fprintf(screen," estimated absolute RMS force accuracy = %g\n", - estimated_accuracy); - fprintf(screen," estimated relative force accuracy = %g\n", - estimated_accuracy/two_charge_force); - fprintf(screen," KSpace vectors: actual max1d max3d = %d %d %d\n", - kcount,kmax,kmax3d); - fprintf(screen," kxmax kymax kzmax = %d %d %d\n", - kxmax,kymax,kzmax); - } - if (logfile) { - fprintf(logfile," G vector (1/distance) = %g\n",g_ewald); - fprintf(logfile," estimated absolute RMS force accuracy = %g\n", - estimated_accuracy); - fprintf(logfile," estimated relative force accuracy = %g\n", - estimated_accuracy/two_charge_force); - fprintf(logfile," KSpace vectors: actual max1d max3d = %d %d %d\n", - kcount,kmax,kmax3d); - fprintf(logfile," kxmax kymax kzmax = %d %d %d\n", - kxmax,kymax,kzmax); - } + std::string mesg = fmt::format(" G vector (1/distance) = {}\n",g_ewald); + mesg += fmt::format(" estimated absolute RMS force accuracy = {}\n", + estimated_accuracy); + mesg += fmt::format(" estimated relative force accuracy = {}\n", + estimated_accuracy/two_charge_force); + mesg += fmt::format(" KSpace vectors: actual max1d max3d = {} {} {}\n", + kcount,kmax,kmax3d); + mesg += fmt::format(" kxmax kymax kzmax = {} {} {}\n", + kxmax,kymax,kzmax); + utils::logmesg(lmp,mesg); } } diff --git a/src/KSPACE/ewald_dipole.cpp b/src/KSPACE/ewald_dipole.cpp index c8267b461d..667f9a172a 100644 --- a/src/KSPACE/ewald_dipole.cpp +++ b/src/KSPACE/ewald_dipole.cpp @@ -18,6 +18,7 @@ #include "ewald_dipole.h" #include #include +#include #include #include "atom.h" #include "comm.h" @@ -29,6 +30,8 @@ #include "memory.h" #include "error.h" #include "update.h" +#include "utils.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace MathConst; @@ -63,10 +66,7 @@ EwaldDipole::~EwaldDipole() void EwaldDipole::init() { - if (comm->me == 0) { - if (screen) fprintf(screen,"EwaldDipole initialization ...\n"); - if (logfile) fprintf(logfile,"EwaldDipole initialization ...\n"); - } + if (comm->me == 0) utils::logmesg(lmp,"EwaldDipole initialization ...\n"); // error check @@ -192,28 +192,16 @@ void EwaldDipole::init() // stats if (comm->me == 0) { - if (screen) { - fprintf(screen," G vector (1/distance) = %g\n",g_ewald); - fprintf(screen," estimated absolute RMS force accuracy = %g\n", - estimated_accuracy); - fprintf(screen," estimated relative force accuracy = %g\n", - estimated_accuracy/two_charge_force); - fprintf(screen," KSpace vectors: actual max1d max3d = %d %d %d\n", - kcount,kmax,kmax3d); - fprintf(screen," kxmax kymax kzmax = %d %d %d\n", - kxmax,kymax,kzmax); - } - if (logfile) { - fprintf(logfile," G vector (1/distance) = %g\n",g_ewald); - fprintf(logfile," estimated absolute RMS force accuracy = %g\n", - estimated_accuracy); - fprintf(logfile," estimated relative force accuracy = %g\n", - estimated_accuracy/two_charge_force); - fprintf(logfile," KSpace vectors: actual max1d max3d = %d %d %d\n", - kcount,kmax,kmax3d); - fprintf(logfile," kxmax kymax kzmax = %d %d %d\n", - kxmax,kymax,kzmax); - } + std::string mesg = fmt::format(" G vector (1/distance) = {}\n",g_ewald); + mesg += fmt::format(" estimated absolute RMS force accuracy = {}\n", + estimated_accuracy); + mesg += fmt::format(" estimated relative force accuracy = {}\n", + estimated_accuracy/two_charge_force); + mesg += fmt::format(" KSpace vectors: actual max1d max3d = {} {} {}\n", + kcount,kmax,kmax3d); + mesg += fmt::format(" kxmax kymax kzmax = {} {} {}\n", + kxmax,kymax,kzmax); + utils::logmesg(lmp,mesg); } } diff --git a/src/KSPACE/ewald_dipole_spin.cpp b/src/KSPACE/ewald_dipole_spin.cpp index 4f19c2580f..e44ef92110 100644 --- a/src/KSPACE/ewald_dipole_spin.cpp +++ b/src/KSPACE/ewald_dipole_spin.cpp @@ -18,6 +18,7 @@ #include "ewald_dipole_spin.h" #include #include +#include #include #include "atom.h" #include "comm.h" @@ -28,6 +29,8 @@ #include "memory.h" #include "error.h" #include "update.h" +#include "utils.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace MathConst; @@ -61,10 +64,7 @@ EwaldDipoleSpin::~EwaldDipoleSpin() {} void EwaldDipoleSpin::init() { - if (comm->me == 0) { - if (screen) fprintf(screen,"EwaldDipoleSpin initialization ...\n"); - if (logfile) fprintf(logfile,"EwaldDipoleSpin initialization ...\n"); - } + if (comm->me == 0) utils::logmesg(lmp,"EwaldDipoleSpin initialization ...\n"); // error check @@ -182,28 +182,16 @@ void EwaldDipoleSpin::init() // stats if (comm->me == 0) { - if (screen) { - fprintf(screen," G vector (1/distance) = %g\n",g_ewald); - fprintf(screen," estimated absolute RMS force accuracy = %g\n", - estimated_accuracy); - fprintf(screen," estimated relative force accuracy = %g\n", - estimated_accuracy/two_charge_force); - fprintf(screen," KSpace vectors: actual max1d max3d = %d %d %d\n", - kcount,kmax,kmax3d); - fprintf(screen," kxmax kymax kzmax = %d %d %d\n", - kxmax,kymax,kzmax); - } - if (logfile) { - fprintf(logfile," G vector (1/distance) = %g\n",g_ewald); - fprintf(logfile," estimated absolute RMS force accuracy = %g\n", - estimated_accuracy); - fprintf(logfile," estimated relative force accuracy = %g\n", - estimated_accuracy/two_charge_force); - fprintf(logfile," KSpace vectors: actual max1d max3d = %d %d %d\n", - kcount,kmax,kmax3d); - fprintf(logfile," kxmax kymax kzmax = %d %d %d\n", - kxmax,kymax,kzmax); - } + std::string mesg = fmt::format(" G vector (1/distance) = {}\n",g_ewald); + mesg += fmt::format(" estimated absolute RMS force accuracy = {}\n", + estimated_accuracy); + mesg += fmt::format(" estimated relative force accuracy = {}\n", + estimated_accuracy/two_charge_force); + mesg += fmt::format(" KSpace vectors: actual max1d max3d = {} {} {}\n", + kcount,kmax,kmax3d); + mesg += fmt::format(" kxmax kymax kzmax = {} {} {}\n", + kxmax,kymax,kzmax); + utils::logmesg(lmp,mesg); } } diff --git a/src/KSPACE/ewald_disp.cpp b/src/KSPACE/ewald_disp.cpp index 5cb6ed619c..9ca89f0b74 100644 --- a/src/KSPACE/ewald_disp.cpp +++ b/src/KSPACE/ewald_disp.cpp @@ -18,6 +18,7 @@ #include "ewald_disp.h" #include #include +#include #include #include "math_vector.h" #include "math_const.h" @@ -30,6 +31,8 @@ #include "memory.h" #include "error.h" #include "update.h" +#include "utils.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace MathConst; @@ -89,10 +92,7 @@ void EwaldDisp::init() nbox = -1; bytes = 0.0; - if (!comm->me) { - if (screen) fprintf(screen,"EwaldDisp initialization ...\n"); - if (logfile) fprintf(logfile,"EwaldDisp initialization ...\n"); - } + if (!comm->me) utils::logmesg(lmp,"EwaldDisp initialization ...\n"); triclinic_check(); if (domain->dimension == 2) @@ -169,11 +169,9 @@ void EwaldDisp::init() if (qsqsum == 0.0 && bsbsum == 0.0 && M2 == 0.0) error->all(FLERR,"Cannot use Ewald/disp solver " "on system with no charge, dipole, or LJ particles"); - if (fabs(qsum) > SMALL && comm->me == 0) { - char str[128]; - sprintf(str,"System is not charge neutral, net charge = %g",qsum); - error->warning(FLERR,str); - } + if (fabs(qsum) > SMALL && comm->me == 0) + error->warning(FLERR,fmt::format("System is not charge neutral, " + "net charge = {}",qsum)); if (!function[1] && !function[2]) dispersionflag = 0; if (!function[3]) dipoleflag = 0; @@ -229,10 +227,9 @@ void EwaldDisp::init() } } - if (!comm->me) { - if (screen) fprintf(screen, " G vector = %g, accuracy = %g\n", g_ewald,accuracy); - if (logfile) fprintf(logfile, " G vector = %g accuracy = %g\n", g_ewald,accuracy); - } + if (!comm->me) + utils::logmesg(lmp,fmt::format(" G vector = {}, accuracy = {}\n", + g_ewald,accuracy)); g_ewald_6 = g_ewald; deallocate_peratom(); @@ -294,10 +291,8 @@ void EwaldDisp::setup() if (!(first_output||comm->me)) { first_output = 1; - if (screen) fprintf(screen, - " vectors: nbox = %d, nkvec = %d\n", nbox, nkvec); - if (logfile) fprintf(logfile, - " vectors: nbox = %d, nkvec = %d\n", nbox, nkvec); + utils::logmesg(lmp,fmt::format(" vectors: nbox = {}, nkvec = {}\n", + nbox, nkvec)); } } diff --git a/src/KSPACE/fix_tune_kspace.cpp b/src/KSPACE/fix_tune_kspace.cpp index a3a4956214..0eb29cf485 100644 --- a/src/KSPACE/fix_tune_kspace.cpp +++ b/src/KSPACE/fix_tune_kspace.cpp @@ -19,6 +19,8 @@ #include #include #include +#include +#include "comm.h" #include "update.h" #include "force.h" #include "kspace.h" @@ -29,6 +31,8 @@ #include "neighbor.h" #include "modify.h" #include "compute.h" +#include "utils.h" +#include "fmt/format.h" #define SWAP(a,b) {temp=(a);(a)=(b);(b)=temp;} #define SIGN(a,b) ((b) >= 0.0 ? fabs(a) : -fabs(a)) @@ -146,10 +150,11 @@ void FixTuneKspace::pre_exchange() update_kspace_style(new_kspace_style,new_acc_str); } else if (niter == 4) { store_old_kspace_settings(); - if (screen) fprintf(screen,"ewald_time = %g\npppm_time = %g\nmsm_time = %g", - ewald_time, pppm_time, msm_time); - if (logfile) fprintf(logfile,"ewald_time = %g\npppm_time = %g\nmsm_time = %g", - ewald_time, pppm_time, msm_time); + if (comm->me == 0) + utils::logmesg(lmp,fmt::format("ewald_time = {}\n" + "pppm_time = {}\n" + "msm_time = {}\n", + ewald_time, pppm_time, msm_time)); // switch to fastest one strcpy(new_kspace_style,"ewald"); snprintf(new_pair_style,64,"%s/long",base_pair_style); @@ -240,8 +245,8 @@ void FixTuneKspace::update_pair_style(char *new_pair_style, p_pair_settings_file = tmpfile(); force->pair->write_restart(p_pair_settings_file); rewind(p_pair_settings_file); - if (screen) fprintf(screen,"Creating new pair style: %s\n",new_pair_style); - if (logfile) fprintf(logfile,"Creating new pair style: %s\n",new_pair_style); + if (comm->me == 0) + utils::logmesg(lmp,fmt::format("Creating new pair style: {}\n",new_pair_style)); // delete old pair style and create new one force->create_pair(new_pair_style,1); @@ -250,8 +255,9 @@ void FixTuneKspace::update_pair_style(char *new_pair_style, double *pcutoff = (double *) force->pair->extract("cut_coul",itmp); double current_cutoff = *pcutoff; - if (screen) fprintf(screen,"Coulomb cutoff for real space: %g\n", current_cutoff); - if (logfile) fprintf(logfile,"Coulomb cutoff for real space: %g\n", current_cutoff); + if (comm->me == 0) + utils::logmesg(lmp,fmt::format("Coulomb cutoff for real space: {}\n", + current_cutoff)); // close temporary file fclose(p_pair_settings_file); @@ -319,8 +325,9 @@ void FixTuneKspace::adjust_rcut(double time) int itmp; double *p_cutoff = (double *) force->pair->extract("cut_coul",itmp); double current_cutoff = *p_cutoff; - if (screen) fprintf(screen,"Old Coulomb cutoff for real space: %g\n",current_cutoff); - if (logfile) fprintf(logfile,"Old Coulomb cutoff for real space: %g\n",current_cutoff); + if (comm->me == 0) + utils::logmesg(lmp,fmt::format("Old Coulomb cutoff for real space: {}\n", + current_cutoff)); // use Brent's method from Numerical Recipes to find optimal real space cutoff @@ -390,8 +397,8 @@ void FixTuneKspace::adjust_rcut(double time) // report the new cutoff double *new_cutoff = (double *) force->pair->extract("cut_coul",itmp); current_cutoff = *new_cutoff; - if (screen) fprintf(screen,"Adjusted Coulomb cutoff for real space: %g\n", current_cutoff); - if (logfile) fprintf(logfile,"Adjusted Coulomb cutoff for real space: %g\n", current_cutoff); + if (comm->me == 0) + utils::logmesg(lmp,fmt::format("Adjusted Coulomb cutoff for real space: {}\n", current_cutoff)); store_old_kspace_settings(); update_pair_style(new_pair_style,pair_cut_coul); diff --git a/src/KSPACE/msm_cg.cpp b/src/KSPACE/msm_cg.cpp index 97e423a6e9..6baeb3e62c 100644 --- a/src/KSPACE/msm_cg.cpp +++ b/src/KSPACE/msm_cg.cpp @@ -26,6 +26,8 @@ #include "force.h" #include "neighbor.h" #include "memory.h" +#include "utils.h" +#include "fmt/format.h" using namespace LAMMPS_NS; @@ -140,20 +142,12 @@ void MSMCG::compute(int eflag, int vflag) charged_frac = static_cast(charged_all) * 100.0 / static_cast(atom->natoms); - if (me == 0) { - if (screen) - fprintf(screen, - " MSM/cg optimization cutoff: %g\n" - " Total charged atoms: %.1f%%\n" - " Min/max charged atoms/proc: %.1f%% %.1f%%\n", - smallq,charged_frac,charged_fmin,charged_fmax); - if (logfile) - fprintf(logfile, - " MSM/cg optimization cutoff: %g\n" - " Total charged atoms: %.1f%%\n" - " Min/max charged atoms/proc: %.1f%% %.1f%%\n", - smallq,charged_frac,charged_fmin,charged_fmax); - } + if (me == 0) + utils::logmesg(lmp,fmt::format(" MSM/cg optimization cutoff: {}\n" + " Total charged atoms: {:.1f}%\n" + " Min/max charged atoms/proc: {:.1f}%" + " {:.1f}%\n",smallq, + charged_frac,charged_fmin,charged_fmax)); } // only need to rebuild this list after a neighbor list update diff --git a/src/KSPACE/pppm.cpp b/src/KSPACE/pppm.cpp index f7ed168395..becfeb31ef 100644 --- a/src/KSPACE/pppm.cpp +++ b/src/KSPACE/pppm.cpp @@ -21,6 +21,7 @@ #include "pppm.h" #include #include +#include #include #include "atom.h" #include "comm.h" @@ -35,6 +36,8 @@ #include "remap_wrap.h" #include "memory.h" #include "error.h" +#include "utils.h" +#include "fmt/format.h" #include "math_const.h" #include "math_special.h" @@ -185,10 +188,7 @@ PPPM::~PPPM() void PPPM::init() { - if (me == 0) { - if (screen) fprintf(screen,"PPPM initialization ...\n"); - if (logfile) fprintf(logfile,"PPPM initialization ...\n"); - } + if (me == 0) utils::logmesg(lmp,"PPPM initialization ...\n"); // error check @@ -203,13 +203,14 @@ void PPPM::init() if (domain->triclinic && slabflag) error->all(FLERR,"Cannot (yet) use PPPM with triclinic box and " "slab correction"); - if (domain->dimension == 2) error->all(FLERR, - "Cannot use PPPM with 2d simulation"); + if (domain->dimension == 2) + error->all(FLERR,"Cannot use PPPM with 2d simulation"); if (comm->style != 0) error->universe_all(FLERR,"PPPM can only currently be used with " "comm_style brick"); - if (!atom->q_flag) error->all(FLERR,"Kspace style requires atom attribute q"); + if (!atom->q_flag) + error->all(FLERR,"Kspace style requires atom attribute q"); if (slabflag == 0 && domain->nonperiodic > 0) error->all(FLERR,"Cannot use non-periodic boundaries with PPPM"); @@ -219,11 +220,8 @@ void PPPM::init() error->all(FLERR,"Incorrect boundaries with slab PPPM"); } - if (order < 2 || order > MAXORDER) { - char str[128]; - sprintf(str,"PPPM order cannot be < 2 or > than %d",MAXORDER); - error->all(FLERR,str); - } + if (order < 2 || order > MAXORDER) + error->all(FLERR,fmt::format("PPPM order cannot be < 2 or > {}",MAXORDER)); // compute two charge force @@ -246,10 +244,7 @@ void PPPM::init() qdist = 0.0; if (tip4pflag) { - if (me == 0) { - if (screen) fprintf(screen," extracting TIP4P info from pair style\n"); - if (logfile) fprintf(logfile," extracting TIP4P info from pair style\n"); - } + if (me == 0) utils::logmesg(lmp," extracting TIP4P info from pair style\n"); double *p_qdist = (double *) force->pair->extract("qdist",itmp); int *p_typeO = (int *) force->pair->extract("typeO",itmp); @@ -351,31 +346,17 @@ void PPPM::init() MPI_Allreduce(&nfft_both,&nfft_both_max,1,MPI_INT,MPI_MAX,world); if (me == 0) { - - if (screen) { - fprintf(screen," G vector (1/distance) = %g\n",g_ewald); - fprintf(screen," grid = %d %d %d\n",nx_pppm,ny_pppm,nz_pppm); - fprintf(screen," stencil order = %d\n",order); - fprintf(screen," estimated absolute RMS force accuracy = %g\n", - estimated_accuracy); - fprintf(screen," estimated relative force accuracy = %g\n", - estimated_accuracy/two_charge_force); - fprintf(screen," using " LMP_FFT_PREC " precision " LMP_FFT_LIB "\n"); - fprintf(screen," 3d grid and FFT values/proc = %d %d\n", - ngrid_max,nfft_both_max); - } - if (logfile) { - fprintf(logfile," G vector (1/distance) = %g\n",g_ewald); - fprintf(logfile," grid = %d %d %d\n",nx_pppm,ny_pppm,nz_pppm); - fprintf(logfile," stencil order = %d\n",order); - fprintf(logfile," estimated absolute RMS force accuracy = %g\n", - estimated_accuracy); - fprintf(logfile," estimated relative force accuracy = %g\n", - estimated_accuracy/two_charge_force); - fprintf(logfile," using " LMP_FFT_PREC " precision " LMP_FFT_LIB "\n"); - fprintf(logfile," 3d grid and FFT values/proc = %d %d\n", - ngrid_max,nfft_both_max); - } + std::string mesg = fmt::format(" G vector (1/distance) = {}\n",g_ewald); + mesg += fmt::format(" grid = {} {} {}\n",nx_pppm,ny_pppm,nz_pppm); + mesg += fmt::format(" stencil order = {}\n",order); + mesg += fmt::format(" estimated absolute RMS force accuracy = {}\n", + estimated_accuracy); + mesg += fmt::format(" estimated relative force accuracy = {}\n", + estimated_accuracy/two_charge_force); + mesg += " using " LMP_FFT_PREC " precision " LMP_FFT_LIB "\n"; + mesg += fmt::format(" 3d grid and FFT values/proc = {} {}\n", + ngrid_max,nfft_both_max); + utils::logmesg(lmp,mesg); } // allocate K-space dependent memory @@ -1291,10 +1272,7 @@ void PPPM::adjust_gewald() g_ewald -= dx; if (fabs(newton_raphson_f()) < SMALL) return; } - - char str[128]; - sprintf(str, "Could not compute g_ewald"); - error->all(FLERR, str); + error->all(FLERR, "Could not compute g_ewald"); } /* ---------------------------------------------------------------------- diff --git a/src/KSPACE/pppm_cg.cpp b/src/KSPACE/pppm_cg.cpp index 25609f70fd..de4a7aa494 100644 --- a/src/KSPACE/pppm_cg.cpp +++ b/src/KSPACE/pppm_cg.cpp @@ -28,6 +28,8 @@ #include "memory.h" #include "math_const.h" #include "remap.h" +#include "utils.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace MathConst; @@ -151,20 +153,12 @@ void PPPMCG::compute(int eflag, int vflag) charged_frac = static_cast(charged_all) * 100.0 / static_cast(atom->natoms); - if (me == 0) { - if (screen) - fprintf(screen, - " PPPM/cg optimization cutoff: %g\n" - " Total charged atoms: %.1f%%\n" - " Min/max charged atoms/proc: %.1f%% %.1f%%\n", - smallq,charged_frac,charged_fmin,charged_fmax); - if (logfile) - fprintf(logfile, - " PPPM/cg optimization cutoff: %g\n" - " Total charged atoms: %.1f%%\n" - " Min/max charged atoms/proc: %.1f%% %.1f%%\n", - smallq,charged_frac,charged_fmin,charged_fmax); - } + if (me == 0) + utils::logmesg(lmp,fmt::format(" PPPM/cg optimization cutoff: {}\n" + " Total charged atoms: {:.1f}%\n" + " Min/max charged atoms/proc: {:.1f}%" + " {:.1f}%\n",smallq, + charged_frac,charged_fmin,charged_fmax)); } // only need to rebuild this list after a neighbor list update diff --git a/src/KSPACE/pppm_dipole.cpp b/src/KSPACE/pppm_dipole.cpp index f1151aee1d..0ec7949a1a 100644 --- a/src/KSPACE/pppm_dipole.cpp +++ b/src/KSPACE/pppm_dipole.cpp @@ -18,6 +18,7 @@ #include "pppm_dipole.h" #include #include +#include #include #include "atom.h" #include "comm.h" @@ -30,6 +31,8 @@ #include "memory.h" #include "error.h" #include "update.h" +#include "utils.h" +#include "fmt/format.h" #include "math_const.h" #include "math_special.h" @@ -102,10 +105,7 @@ PPPMDipole::~PPPMDipole() void PPPMDipole::init() { - if (me == 0) { - if (screen) fprintf(screen,"PPPMDipole initialization ...\n"); - if (logfile) fprintf(logfile,"PPPMDipole initialization ...\n"); - } + if (me == 0) utils::logmesg(lmp,"PPPMDipole initialization ...\n"); // error check @@ -143,11 +143,9 @@ void PPPMDipole::init() error->all(FLERR,"Incorrect boundaries with slab PPPMDipole"); } - if (order < 2 || order > MAXORDER) { - char str[128]; - sprintf(str,"PPPMDipole order cannot be < 2 or > than %d",MAXORDER); - error->all(FLERR,str); - } + if (order < 2 || order > MAXORDER) + error->all(FLERR,fmt::format("PPPMDipole order cannot be < 2 or > {}", + MAXORDER)); // compute two charge force @@ -246,37 +244,17 @@ void PPPMDipole::init() MPI_Allreduce(&nfft_both,&nfft_both_max,1,MPI_INT,MPI_MAX,world); if (me == 0) { - -#ifdef FFT_SINGLE - const char fft_prec[] = "single"; -#else - const char fft_prec[] = "double"; -#endif - - if (screen) { - fprintf(screen," G vector (1/distance) = %g\n",g_ewald); - fprintf(screen," grid = %d %d %d\n",nx_pppm,ny_pppm,nz_pppm); - fprintf(screen," stencil order = %d\n",order); - fprintf(screen," estimated absolute RMS force accuracy = %g\n", - estimated_accuracy); - fprintf(screen," estimated relative force accuracy = %g\n", - estimated_accuracy/two_charge_force); - fprintf(screen," using %s precision FFTs\n",fft_prec); - fprintf(screen," 3d grid and FFT values/proc = %d %d\n", - ngrid_max,nfft_both_max); - } - if (logfile) { - fprintf(logfile," G vector (1/distance) = %g\n",g_ewald); - fprintf(logfile," grid = %d %d %d\n",nx_pppm,ny_pppm,nz_pppm); - fprintf(logfile," stencil order = %d\n",order); - fprintf(logfile," estimated absolute RMS force accuracy = %g\n", - estimated_accuracy); - fprintf(logfile," estimated relative force accuracy = %g\n", - estimated_accuracy/two_charge_force); - fprintf(logfile," using %s precision FFTs\n",fft_prec); - fprintf(logfile," 3d grid and FFT values/proc = %d %d\n", - ngrid_max,nfft_both_max); - } + std::string mesg = fmt::format(" G vector (1/distance) = {}\n",g_ewald); + mesg += fmt::format(" grid = {} {} {}\n",nx_pppm,ny_pppm,nz_pppm); + mesg += fmt::format(" stencil order = {}\n",order); + mesg += fmt::format(" estimated absolute RMS force accuracy = {}\n", + estimated_accuracy); + mesg += fmt::format(" estimated relative force accuracy = {}\n", + estimated_accuracy/two_charge_force); + mesg += " using " LMP_FFT_PREC " precision " LMP_FFT_LIB "\n"; + mesg += fmt::format(" 3d grid and FFT values/proc = {} {}\n", + ngrid_max,nfft_both_max); + utils::logmesg(lmp,mesg); } // allocate K-space dependent memory diff --git a/src/KSPACE/pppm_dipole_spin.cpp b/src/KSPACE/pppm_dipole_spin.cpp index 35145b5ca8..71ef5a1b44 100644 --- a/src/KSPACE/pppm_dipole_spin.cpp +++ b/src/KSPACE/pppm_dipole_spin.cpp @@ -18,6 +18,7 @@ #include "pppm_dipole_spin.h" #include #include +#include #include "atom.h" #include "comm.h" #include "gridcomm.h" @@ -27,6 +28,8 @@ #include "memory.h" #include "error.h" #include "update.h" +#include "utils.h" +#include "fmt/format.h" #include "math_const.h" @@ -87,10 +90,7 @@ PPPMDipoleSpin::~PPPMDipoleSpin() void PPPMDipoleSpin::init() { - if (me == 0) { - if (screen) fprintf(screen,"PPPMDipoleSpin initialization ...\n"); - if (logfile) fprintf(logfile,"PPPMDipoleSpin initialization ...\n"); - } + if (me == 0) utils::logmesg(lmp,"PPPMDipoleSpin initialization ...\n"); // error check @@ -123,11 +123,9 @@ void PPPMDipoleSpin::init() error->all(FLERR,"Incorrect boundaries with slab PPPMDipoleSpin"); } - if (order < 2 || order > MAXORDER) { - char str[128]; - sprintf(str,"PPPMDipoleSpin order cannot be < 2 or > than %d",MAXORDER); - error->all(FLERR,str); - } + if (order < 2 || order > MAXORDER) + error->all(FLERR,fmt::format("PPPMDipoleSpin order cannot be < 2 or > {}", + MAXORDER)); // compute two charge force @@ -226,37 +224,17 @@ void PPPMDipoleSpin::init() MPI_Allreduce(&nfft_both,&nfft_both_max,1,MPI_INT,MPI_MAX,world); if (me == 0) { - -#ifdef FFT_SINGLE - const char fft_prec[] = "single"; -#else - const char fft_prec[] = "double"; -#endif - - if (screen) { - fprintf(screen," G vector (1/distance) = %g\n",g_ewald); - fprintf(screen," grid = %d %d %d\n",nx_pppm,ny_pppm,nz_pppm); - fprintf(screen," stencil order = %d\n",order); - fprintf(screen," estimated absolute RMS force accuracy = %g\n", - estimated_accuracy); - fprintf(screen," estimated relative force accuracy = %g\n", - estimated_accuracy/two_charge_force); - fprintf(screen," using %s precision FFTs\n",fft_prec); - fprintf(screen," 3d grid and FFT values/proc = %d %d\n", - ngrid_max,nfft_both_max); - } - if (logfile) { - fprintf(logfile," G vector (1/distance) = %g\n",g_ewald); - fprintf(logfile," grid = %d %d %d\n",nx_pppm,ny_pppm,nz_pppm); - fprintf(logfile," stencil order = %d\n",order); - fprintf(logfile," estimated absolute RMS force accuracy = %g\n", - estimated_accuracy); - fprintf(logfile," estimated relative force accuracy = %g\n", - estimated_accuracy/two_charge_force); - fprintf(logfile," using %s precision FFTs\n",fft_prec); - fprintf(logfile," 3d grid and FFT values/proc = %d %d\n", - ngrid_max,nfft_both_max); - } + std::string mesg = fmt::format(" G vector (1/distance) = {}\n",g_ewald); + mesg += fmt::format(" grid = {} {} {}\n",nx_pppm,ny_pppm,nz_pppm); + mesg += fmt::format(" stencil order = {}\n",order); + mesg += fmt::format(" estimated absolute RMS force accuracy = {}\n", + estimated_accuracy); + mesg += fmt::format(" estimated relative force accuracy = {}\n", + estimated_accuracy/two_charge_force); + mesg += " using " LMP_FFT_PREC " precision " LMP_FFT_LIB "\n"; + mesg += fmt::format(" 3d grid and FFT values/proc = {} {}\n", + ngrid_max,nfft_both_max); + utils::logmesg(lmp,mesg); } // allocate K-space dependent memory diff --git a/src/KSPACE/pppm_disp.cpp b/src/KSPACE/pppm_disp.cpp index 00615c740e..7c1b01f674 100644 --- a/src/KSPACE/pppm_disp.cpp +++ b/src/KSPACE/pppm_disp.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include "math_const.h" #include "atom.h" #include "comm.h" @@ -34,6 +35,8 @@ #include "remap_wrap.h" #include "memory.h" #include "error.h" +#include "utils.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace MathConst; @@ -254,10 +257,7 @@ PPPMDisp::~PPPMDisp() void PPPMDisp::init() { - if (me == 0) { - if (screen) fprintf(screen,"PPPMDisp initialization ...\n"); - if (logfile) fprintf(logfile,"PPPMDisp initialization ...\n"); - } + if (me == 0) utils::logmesg(lmp,"PPPMDisp initialization ...\n"); // error check @@ -277,11 +277,9 @@ void PPPMDisp::init() error->all(FLERR,"Incorrect boundaries with slab PPPMDisp"); } - if (order > MAXORDER || order_6 > MAXORDER) { - char str[128]; - sprintf(str,"PPPMDisp coulomb order cannot be greater than %d",MAXORDER); - error->all(FLERR,str); - } + if (order > MAXORDER || order_6 > MAXORDER) + error->all(FLERR,fmt::format("PPPMDisp coulomb or dispersion order cannot" + " be greater than {}",MAXORDER)); // compute two charge force @@ -318,7 +316,6 @@ void PPPMDisp::init() for (int i=0; i<=EWALD_MAXORDER; ++i) // transcribe order if (ewald_order&(1<all(FLERR,"Unsupported mixing rule in kspace_style pppm/disp"); break; default: - sprintf(str, "Unsupported order in kspace_style " - "pppm/disp, pair_style %s", force->pair_style); - error->all(FLERR,str); + error->all(FLERR,std::string("Unsupported order in kspace_style " + "pppm/disp, pair_style ") + + force->pair_style); } function[k] = 1; } @@ -340,11 +337,8 @@ void PPPMDisp::init() // warn, if function[0] is not set but charge attribute is set! - if (!function[0] && atom->q_flag && me == 0) { - char str[128]; - sprintf(str, "Charges are set, but coulombic solver is not used"); - error->warning(FLERR, str); - } + if (!function[0] && atom->q_flag && me == 0) + error->warning(FLERR, "Charges are set, but coulombic solver is not used"); // show error message if pppm/disp is not used correctly @@ -481,31 +475,19 @@ void PPPMDisp::init() MPI_Allreduce(&nfft_both,&nfft_both_max,1,MPI_INT,MPI_MAX,world); if (me == 0) { - if (screen) { - fprintf(screen," Coulomb G vector (1/distance)= %g\n",g_ewald); - fprintf(screen," Coulomb grid = %d %d %d\n",nx_pppm,ny_pppm,nz_pppm); - fprintf(screen," Coulomb stencil order = %d\n",order); - fprintf(screen," Coulomb estimated absolute RMS force accuracy = %g\n", - acc); - fprintf(screen," Coulomb estimated relative force accuracy = %g\n", - acc/two_charge_force); - fprintf(screen," using " LMP_FFT_PREC " precision " LMP_FFT_LIB "\n"); - fprintf(screen," 3d grid and FFT values/proc = %d %d\n", - ngrid_max, nfft_both_max); - } - if (logfile) { - fprintf(logfile," Coulomb G vector (1/distance) = %g\n",g_ewald); - fprintf(logfile," Coulomb grid = %d %d %d\n",nx_pppm,ny_pppm,nz_pppm); - fprintf(logfile," Coulomb stencil order = %d\n",order); - fprintf(logfile, - " Coulomb estimated absolute RMS force accuracy = %g\n", - acc); - fprintf(logfile," Coulomb estimated relative force accuracy = %g\n", - acc/two_charge_force); - fprintf(logfile," using " LMP_FFT_PREC " precision " LMP_FFT_LIB "\n"); - fprintf(logfile," 3d grid and FFT values/proc = %d %d\n", - ngrid_max, nfft_both_max); - } + std::string mesg = fmt::format(" Coulomb G vector (1/distance)= {}\n", + g_ewald); + mesg += fmt::format(" Coulomb grid = {} {} {}\n", + nx_pppm,ny_pppm,nz_pppm); + mesg += fmt::format(" Coulomb stencil order = {}\n",order); + mesg += fmt::format(" Coulomb estimated absolute RMS force accuracy " + "= {}\n",acc); + mesg += fmt::format(" Coulomb estimated relative force accuracy = {}\n", + acc/two_charge_force); + mesg += " using " LMP_FFT_PREC " precision " LMP_FFT_LIB "\n"; + mesg += fmt::format(" 3d grid and FFT values/proc = {} {}\n", + ngrid_max, nfft_both_max); + utils::logmesg(lmp,mesg); } } @@ -573,46 +555,19 @@ void PPPMDisp::init() MPI_Allreduce(&nfft_both_6,&nfft_both_max,1,MPI_INT,MPI_MAX,world); if (me == 0) { - #ifdef FFT_SINGLE - const char fft_prec[] = "single"; - #else - const char fft_prec[] = "double"; - #endif - - if (screen) { - fprintf(screen," Dispersion G vector (1/distance)= %g\n",g_ewald_6); - fprintf(screen," Dispersion grid = %d %d %d\n", - nx_pppm_6,ny_pppm_6,nz_pppm_6); - fprintf(screen," Dispersion stencil order = %d\n",order_6); - fprintf(screen," Dispersion estimated absolute " - "RMS force accuracy = %g\n",acc); - fprintf(screen," Dispersion estimated absolute " - "real space RMS force accuracy = %g\n",acc_real); - fprintf(screen," Dispersion estimated absolute " - "kspace RMS force accuracy = %g\n",acc_kspace); - fprintf(screen," Dispersion estimated relative force accuracy = %g\n", - acc/two_charge_force); - fprintf(screen," using %s precision FFTs\n",fft_prec); - fprintf(screen," 3d grid and FFT values/proc dispersion = %d %d\n", - ngrid_max,nfft_both_max); - } - if (logfile) { - fprintf(logfile," Dispersion G vector (1/distance) = %g\n",g_ewald_6); - fprintf(logfile," Dispersion grid = %d %d %d\n", - nx_pppm_6,ny_pppm_6,nz_pppm_6); - fprintf(logfile," Dispersion stencil order = %d\n",order_6); - fprintf(logfile," Dispersion estimated absolute " - "RMS force accuracy = %g\n",acc); - fprintf(logfile," Dispersion estimated absolute " - "real space RMS force accuracy = %g\n",acc_real); - fprintf(logfile," Dispersion estimated absolute " - "kspace RMS force accuracy = %g\n",acc_kspace); - fprintf(logfile," Disperion estimated relative force accuracy = %g\n", - acc/two_charge_force); - fprintf(logfile," using %s precision FFTs\n",fft_prec); - fprintf(logfile," 3d grid and FFT values/proc dispersion = %d %d\n", - ngrid_max,nfft_both_max); - } + std::string mesg = fmt::format(" Dispersion G vector (1/distance)= " + "{}\n", g_ewald_6); + mesg += fmt::format(" Dispersion grid = {} {} {}\n", + nx_pppm_6,ny_pppm_6,nz_pppm_6); + mesg += fmt::format(" Dispersion stencil order = {}\n",order_6); + mesg += fmt::format(" Dispersion estimated absolute RMS force accuracy " + "= {}\n",acc); + mesg += fmt::format(" Dispersion estimated relative force accuracy " + "= {}\n",acc/two_charge_force); + mesg += " using " LMP_FFT_PREC " precision " LMP_FFT_LIB "\n"; + mesg += fmt::format(" 3d grid and FFT values/proc = {} {}\n", + ngrid_max, nfft_both_max); + utils::logmesg(lmp,mesg); } } @@ -1285,10 +1240,8 @@ void PPPMDisp::init_coeffs() // local pair coeffs delete [] B; B = NULL; if (function[3] + function[2]) { // no mixing rule or arithmetic - if (function[2] && me == 0) { - if (screen) fprintf(screen," Optimizing splitting of Dispersion coefficients\n"); - if (logfile) fprintf(logfile," Optimizing splitting of Dispersion coefficients\n"); - } + if (function[2] && me == 0) + utils::logmesg(lmp," Optimizing splitting of Dispersion coefficients\n"); // allocate data for eigenvalue decomposition double **A=NULL; @@ -1349,11 +1302,9 @@ void PPPMDisp::init_coeffs() // local pair coeffs } err = bmax/amax; - if (err > 1.0e-4) { - char str[128]; - sprintf(str,"Estimated error in splitting of dispersion coeffs is %g",err); - error->warning(FLERR, str); - } + if (err > 1.0e-4 && comm->me == 0) + error->warning(FLERR,fmt::format("Estimated error in splitting of " + "dispersion coeffs is {}",err)); // set B B = new double[nsplit*n+nsplit]; for (int i = 0; i< nsplit; i++) { @@ -1374,31 +1325,24 @@ void PPPMDisp::init_coeffs() // local pair coeffs function[3] = 0; function[2] = 0; function[1] = 1; - if (me == 0) { - if (screen) fprintf(screen," Using geometric mixing for reciprocal space\n"); - if (logfile) fprintf(logfile," Using geometric mixing for reciprocal space\n"); - } + if (me == 0) + utils::logmesg(lmp," Using geometric mixing for reciprocal space\n"); } if (function[2] && nsplit <= 6) { - if (me == 0) { - if (screen) fprintf(screen," Using %d instead of 7 structure factors\n",nsplit); - if (logfile) fprintf(logfile," Using %d instead of 7 structure factors\n",nsplit); - } + if (me == 0) + utils::logmesg(lmp,fmt::format(" Using {} instead of 7 structure " + "factors\n",nsplit)); function[3] = 1; function[2] = 0; } if (function[2] && (nsplit > 6)) { - if (me == 0) { - if (screen) fprintf(screen," Using 7 structure factors\n"); - if (logfile) fprintf(logfile," Using 7 structure factors\n"); - } + if (me == 0) utils::logmesg(lmp," Using 7 structure factors\n"); if ( B ) delete [] B; } if (function[3]) { - if (me == 0) { - if (screen) fprintf(screen," Using %d structure factors\n",nsplit); - if (logfile) fprintf(logfile," Using %d structure factors\n",nsplit); - } + if (me == 0) + utils::logmesg(lmp,fmt::format(" Using {} structure factors\n", + nsplit)); if (nsplit > 9) error->warning(FLERR, "Simulations might be very slow because of large number of structure factors"); } @@ -2884,9 +2828,7 @@ void PPPMDisp::adjust_gewald() // Failed to converge - char str[128]; - sprintf(str, "Could not compute g_ewald"); - error->all(FLERR, str); + error->all(FLERR, "Could not compute g_ewald"); } @@ -3517,9 +3459,7 @@ void PPPMDisp::adjust_gewald_6() // Failed to converge - char str[128]; - sprintf(str, "Could not adjust g_ewald_6"); - error->all(FLERR, str); + error->all(FLERR, "Could not adjust g_ewald_6"); } diff --git a/src/MANYBODY/fix_qeq_comb.cpp b/src/MANYBODY/fix_qeq_comb.cpp index 2f324bf097..31d62f0645 100644 --- a/src/MANYBODY/fix_qeq_comb.cpp +++ b/src/MANYBODY/fix_qeq_comb.cpp @@ -31,6 +31,7 @@ #include "memory.h" #include "error.h" #include "utils.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -64,11 +65,9 @@ FixQEQComb::FixQEQComb(LAMMPS *lmp, int narg, char **arg) : Fix(lmp, narg, arg), if (iarg+2 > narg) error->all(FLERR,"Illegal fix qeq/comb command"); if (me == 0) { fp = fopen(arg[iarg+1],"w"); - if (fp == NULL) { - char str[128]; - snprintf(str,128,"Cannot open fix qeq/comb file %s",arg[iarg+1]); - error->one(FLERR,str); - } + if (fp == NULL) + error->one(FLERR,std::string("Cannot open fix qeq/comb file ") + + arg[iarg+1]); } iarg += 2; } else error->all(FLERR,"Illegal fix qeq/comb command"); @@ -191,8 +190,7 @@ void FixQEQComb::post_force(int /*vflag*/) // charge-equilibration loop if (me == 0 && fp) - fprintf(fp,"Charge equilibration on step " BIGINT_FORMAT "\n", - update->ntimestep); + fmt::print(fp,"Charge equilibration on step {}\n", update->ntimestep); heatpq = 0.05; qmass = 0.016; @@ -253,9 +251,9 @@ void FixQEQComb::post_force(int /*vflag*/) if (enegchk <= precision && enegmax <= 100.0*precision) break; if (me == 0 && fp) - fprintf(fp," iteration: %d, enegtot %.6g, " - "enegmax %.6g, fq deviation: %.6g\n", - iloop,enegtot,enegmax,enegchk); + fmt::print(fp," iteration: {}, enegtot {:.6g}, " + "enegmax {:.6g}, fq deviation: {:.6g}\n", + iloop,enegtot,enegmax,enegchk); for (ii = 0; ii < inum; ii++) { i = ilist[ii]; @@ -266,10 +264,10 @@ void FixQEQComb::post_force(int /*vflag*/) if (me == 0 && fp) { if (iloop == loopmax) - fprintf(fp,"Charges did not converge in %d iterations\n",iloop); + fmt::print(fp,"Charges did not converge in {} iterations\n",iloop); else - fprintf(fp,"Charges converged in %d iterations to %.10f tolerance\n", - iloop,enegchk); + fmt::print(fp,"Charges converged in {} iterations to {:.10f} tolerance\n", + iloop,enegchk); } } diff --git a/src/MANYBODY/pair_bop.cpp b/src/MANYBODY/pair_bop.cpp index 21630ad001..0a944c20a4 100644 --- a/src/MANYBODY/pair_bop.cpp +++ b/src/MANYBODY/pair_bop.cpp @@ -48,6 +48,7 @@ #include "utils.h" #include "tokenizer.h" #include "potential_file_reader.h" +#include "fmt/format.h" using namespace LAMMPS_NS; @@ -689,12 +690,9 @@ void PairBOP::init_style() // check that user sets comm->cutghostuser to 3x the max BOP cutoff - if (comm->cutghostuser < 3.0*cutmax - EPSILON) { - char str[128]; - sprintf(str,"Pair style bop requires comm ghost cutoff " - "at least 3x larger than %g",cutmax); - error->all(FLERR,str); - } + if (comm->cutghostuser < 3.0*cutmax - EPSILON) + error->all(FLERR,fmt::format("Pair style bop requires comm ghost cutoff " + "at least 3x larger than {}",cutmax)); // need a full neighbor list and neighbors of ghosts diff --git a/src/MANYBODY/pair_comb.cpp b/src/MANYBODY/pair_comb.cpp index d966fa723f..ce42dcd82e 100644 --- a/src/MANYBODY/pair_comb.cpp +++ b/src/MANYBODY/pair_comb.cpp @@ -493,15 +493,17 @@ void PairComb::coeff(int narg, char **arg) // generate streitz-mintmire direct 1/r energy look-up table - if (comm->me == 0 && screen) fprintf(screen,"Pair COMB:\n"); if (comm->me == 0 && screen) - fprintf(screen," generating Coulomb integral lookup table ...\n"); + fputs("Pair COMB:\n" + " generating Coulomb integral lookup table ...\n",screen); sm_table(); - if (cor_flag && comm->me == 0 && screen) - fprintf(screen," will apply over-coordination correction ...\n"); - if (!cor_flag&& comm->me == 0 && screen) - fprintf(screen," will not apply over-coordination correction ...\n"); + if (comm->me == 0 && screen) { + if (cor_flag) + fputs(" will apply over-coordination correction ...\n",screen); + else + fputs(" will not apply over-coordination correction ...\n",screen); + } // clear setflag since coeff() called once with I,J = * * diff --git a/src/MANYBODY/pair_comb3.cpp b/src/MANYBODY/pair_comb3.cpp index e5f729f19a..289225608c 100644 --- a/src/MANYBODY/pair_comb3.cpp +++ b/src/MANYBODY/pair_comb3.cpp @@ -36,6 +36,7 @@ #include "utils.h" #include "tokenizer.h" #include "potential_file_reader.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace MathConst; @@ -165,17 +166,13 @@ void PairComb3::settings(int narg, char **arg) if (narg != 1) error->all(FLERR,"Illegal pair_style command"); - if (strcmp(arg[0],"polar_on") == 0) { - pol_flag = 1; - if (comm->me == 0 && screen) fprintf(screen, - " PairComb3: polarization is on \n"); - } else if (strcmp(arg[0],"polar_off") == 0) { - pol_flag = 0; - if (comm->me == 0 && screen) fprintf(screen, - " PairComb3: polarization is off \n"); - } else { - error->all(FLERR,"Illegal pair_style command"); - } + if (strcmp(arg[0],"polar_on") == 0) pol_flag = 1; + else if (strcmp(arg[0],"polar_off") == 0) pol_flag = 0; + else error->all(FLERR,"Illegal pair_style command"); + + if (comm->me == 0 && screen) + fmt::print(screen," PairComb3: polarization is {} \n", + pol_flag ? "on" : "off"); } /* ---------------------------------------------------------------------- @@ -210,8 +207,8 @@ void PairComb3::coeff(int narg, char **arg) nelements = 0; for (i = 3; i < narg; i++) { if ((strcmp(arg[i],"C") == 0) && (cflag == 0)) { - if (comm->me == 0 && screen) fprintf(screen, - " PairComb3: Found C: reading additional library file\n"); + if (comm->me == 0 && screen) + fputs(" PairComb3: Found C: reading additional library file\n",screen); read_lib(); cflag = 1; } diff --git a/src/MANYBODY/pair_eam.cpp b/src/MANYBODY/pair_eam.cpp index 53f1b7a328..ba347ccf96 100644 --- a/src/MANYBODY/pair_eam.cpp +++ b/src/MANYBODY/pair_eam.cpp @@ -43,6 +43,7 @@ PairEAM::PairEAM(LAMMPS *lmp) : Pair(lmp) restartinfo = 0; manybody_flag = 1; embedstep = -1; + unit_convert_flag = utils::get_supported_conversions(utils::ENERGY); nmax = 0; rho = NULL; @@ -466,8 +467,13 @@ void PairEAM::read_file(char *filename) // read potential file if(comm->me == 0) { - PotentialFileReader reader(lmp, filename, "EAM"); + PotentialFileReader reader(lmp, filename, "EAM", unit_convert_flag); + // transparently convert units for supported conversions + + int unit_convert = reader.get_unit_convert(); + double conversion_factor = utils::get_conversion_factor(utils::ENERGY, + unit_convert); try { reader.skip_line(); @@ -492,6 +498,14 @@ void PairEAM::read_file(char *filename) reader.next_dvector(&file->frho[1], file->nrho); reader.next_dvector(&file->zr[1], file->nr); reader.next_dvector(&file->rhor[1], file->nr); + + if (unit_convert) { + const double sqrt_conv = sqrt(conversion_factor); + for (int i = 1; i <= file->nrho; ++i) + file->frho[i] *= conversion_factor; + for (int j = 1; j <= file->nr; ++j) + file->zr[j] *= sqrt_conv; + } } catch (TokenizerException & e) { error->one(FLERR, e.what()); } @@ -655,6 +669,7 @@ void PairEAM::file2array() // create a z2r array for each file against other files, only for I >= J // interpolate zri and zrj to a single grid and cutoff + // final z2r includes unit conversion of 27.2 eV/Hartree and 0.529 Ang/Bohr double zri,zrj; diff --git a/src/MANYBODY/pair_eam_alloy.cpp b/src/MANYBODY/pair_eam_alloy.cpp index 42587e9434..1d6148f8f3 100644 --- a/src/MANYBODY/pair_eam_alloy.cpp +++ b/src/MANYBODY/pair_eam_alloy.cpp @@ -119,8 +119,13 @@ void PairEAMAlloy::read_file(char *filename) // read potential file if(comm->me == 0) { - PotentialFileReader reader(lmp, filename, "EAM"); + PotentialFileReader reader(lmp, filename, "EAMAlloy", unit_convert_flag); + // transparently convert units for supported conversions + + int unit_convert = reader.get_unit_convert(); + double conversion_factor = utils::get_conversion_factor(utils::ENERGY, + unit_convert); try { reader.skip_line(); reader.skip_line(); @@ -165,11 +170,19 @@ void PairEAMAlloy::read_file(char *filename) reader.next_dvector(&file->frho[i][1], file->nrho); reader.next_dvector(&file->rhor[i][1], file->nr); + if (unit_convert) { + for (int j = 1; j < file->nrho; ++j) + file->frho[i][j] *= conversion_factor; + } } for (int i = 0; i < file->nelements; i++) { for (int j = 0; j <= i; j++) { reader.next_dvector(&file->z2r[i][j][1], file->nr); + if (unit_convert) { + for (int k = 1; k < file->nr; ++k) + file->z2r[i][j][k] *= conversion_factor; + } } } } catch (TokenizerException & e) { diff --git a/src/MANYBODY/pair_eam_cd.cpp b/src/MANYBODY/pair_eam_cd.cpp index 102e2a62f3..01c8a3fffe 100644 --- a/src/MANYBODY/pair_eam_cd.cpp +++ b/src/MANYBODY/pair_eam_cd.cpp @@ -29,6 +29,8 @@ #include "memory.h" #include "error.h" #include "tokenizer.h" +#include "utils.h" +#include "fmt/format.h" using namespace LAMMPS_NS; @@ -40,6 +42,7 @@ PairEAMCD::PairEAMCD(LAMMPS *lmp, int _cdeamVersion) { single_enable = 0; restartinfo = 0; + unit_convert_flag = utils::get_supported_conversions(utils::ENERGY); rhoB = NULL; D_values = NULL; @@ -500,12 +503,11 @@ void PairEAMCD::read_h_coeff(char *filename) FILE *fptr; char line[MAXLINE]; char nextline[MAXLINE]; - fptr = force->open_potential(filename); - if (fptr == NULL) { - char str[128]; - snprintf(str,128,"Cannot open EAM potential file %s", filename); - error->one(FLERR,str); - } + int convert_flag = unit_convert_flag; + fptr = force->open_potential(filename, &convert_flag); + if (fptr == NULL) + error->one(FLERR,fmt::format("Cannot open EAMCD potential file {}", + filename)); // h coefficients are stored at the end of the file. // Skip to last line of file. diff --git a/src/MANYBODY/pair_eam_fs.cpp b/src/MANYBODY/pair_eam_fs.cpp index 448a1d2701..654c64bbd5 100644 --- a/src/MANYBODY/pair_eam_fs.cpp +++ b/src/MANYBODY/pair_eam_fs.cpp @@ -119,8 +119,15 @@ void PairEAMFS::read_file(char *filename) // read potential file if(comm->me == 0) { - PotentialFileReader reader(lmp, filename, "EAM"); + PotentialFileReader reader(lmp, filename, "EAMFS", unit_convert_flag); + // transparently convert units for supported conversions + + // transparently convert units for supported conversions + + int unit_convert = reader.get_unit_convert(); + double conversion_factor = utils::get_conversion_factor(utils::ENERGY, + unit_convert); try { reader.skip_line(); reader.skip_line(); @@ -164,6 +171,10 @@ void PairEAMFS::read_file(char *filename) file->mass[i] = values.next_double(); reader.next_dvector(&file->frho[i][1], file->nrho); + if (unit_convert) { + for (int j = 1; j <= file->nrho; ++j) + file->frho[i][j] *= conversion_factor; + } for (int j = 0; j < file->nelements; j++) { reader.next_dvector(&file->rhor[i][j][1], file->nr); @@ -173,6 +184,10 @@ void PairEAMFS::read_file(char *filename) for (int i = 0; i < file->nelements; i++) { for (int j = 0; j <= i; j++) { reader.next_dvector(&file->z2r[i][j][1], file->nr); + if (unit_convert) { + for (int k = 1; k <= file->nr; ++k) + file->z2r[i][j][k] *= conversion_factor; + } } } } catch (TokenizerException & e) { diff --git a/src/MANYBODY/pair_eim.cpp b/src/MANYBODY/pair_eim.cpp index bdc08662f3..7b84de9de9 100644 --- a/src/MANYBODY/pair_eim.cpp +++ b/src/MANYBODY/pair_eim.cpp @@ -41,6 +41,7 @@ PairEIM::PairEIM(LAMMPS *lmp) : Pair(lmp) restartinfo = 0; one_coeff = 1; manybody_flag = 1; + unit_convert_flag = utils::get_supported_conversions(utils::ENERGY); setfl = NULL; nmax = 0; @@ -477,7 +478,7 @@ void PairEIM::read_file(char *filename) // read potential file if( comm->me == 0) { - EIMPotentialFileReader reader(lmp, filename); + EIMPotentialFileReader reader(lmp, filename, unit_convert_flag); reader.get_global(setfl); @@ -1050,14 +1051,18 @@ double PairEIM::memory_usage() return bytes; } -EIMPotentialFileReader::EIMPotentialFileReader(LAMMPS * lmp, const std::string & filename) : +EIMPotentialFileReader::EIMPotentialFileReader(LAMMPS *lmp, + const std::string &filename, + const int auto_convert) : Pointers(lmp), filename(filename) { if (comm->me != 0) { error->one(FLERR, "EIMPotentialFileReader should only be called by proc 0!"); } - FILE * fp = force->open_potential(filename.c_str()); + int unit_convert = auto_convert; + FILE *fp = force->open_potential(filename.c_str(), &unit_convert); + conversion_factor = utils::get_conversion_factor(utils::ENERGY,unit_convert); if (fp == NULL) { error->one(FLERR, fmt::format("cannot open EIM potential file {}", filename)); @@ -1186,7 +1191,7 @@ void EIMPotentialFileReader::parse(FILE * fp) PairData data; data.rcutphiA = values.next_double(); data.rcutphiR = values.next_double(); - data.Eb = values.next_double(); + data.Eb = values.next_double() * conversion_factor; data.r0 = values.next_double(); data.alpha = values.next_double(); data.beta = values.next_double(); @@ -1194,7 +1199,7 @@ void EIMPotentialFileReader::parse(FILE * fp) data.Asigma = values.next_double(); data.rq = values.next_double(); data.rcutsigma = values.next_double(); - data.Ac = values.next_double(); + data.Ac = values.next_double() * conversion_factor; data.zeta = values.next_double(); data.rs = values.next_double(); @@ -1217,20 +1222,18 @@ void EIMPotentialFileReader::parse(FILE * fp) } } -void EIMPotentialFileReader::get_global(PairEIM::Setfl * setfl) { +void EIMPotentialFileReader::get_global(PairEIM::Setfl *setfl) { setfl->division = division; setfl->rbig = rbig; setfl->rsmall = rsmall; } -void EIMPotentialFileReader::get_element(PairEIM::Setfl * setfl, int i, const std::string & name) { - if (elements.find(name) == elements.end()) { - char str[128]; - snprintf(str, 128, "Element %s not defined in EIM potential file", name.c_str()); - error->one(FLERR, str); - } +void EIMPotentialFileReader::get_element(PairEIM::Setfl *setfl, int i, + const std::string &name) { + if (elements.find(name) == elements.end()) + error->one(FLERR,"Element " + name + " not defined in EIM potential file"); - ElementData & data = elements[name]; + ElementData &data = elements[name]; setfl->ielement[i] = data.ielement; setfl->mass[i] = data.mass; setfl->negativity[i] = data.negativity; @@ -1240,16 +1243,16 @@ void EIMPotentialFileReader::get_element(PairEIM::Setfl * setfl, int i, const st setfl->q0[i] = data.q0; } -void EIMPotentialFileReader::get_pair(PairEIM::Setfl * setfl, int ij, const std::string & elemA, const std::string & elemB) { +void EIMPotentialFileReader::get_pair(PairEIM::Setfl *setfl, int ij, + const std::string &elemA, + const std::string &elemB) { auto p = get_pair(elemA, elemB); - if (pairs.find(p) == pairs.end()) { - char str[128]; - snprintf(str, 128, "Pair (%s, %s) not defined in EIM potential file", elemA.c_str(), elemB.c_str()); - error->one(FLERR, str); - } + if (pairs.find(p) == pairs.end()) + error->one(FLERR,"Element pair (" + elemA + ", " + elemB + + ") is not defined in EIM potential file"); - PairData & data = pairs[p]; + PairData &data = pairs[p]; setfl->rcutphiA[ij] = data.rcutphiA; setfl->rcutphiR[ij] = data.rcutphiR; setfl->Eb[ij] = data.Eb; diff --git a/src/MANYBODY/pair_eim.h b/src/MANYBODY/pair_eim.h index 986db52453..1266ffd242 100644 --- a/src/MANYBODY/pair_eim.h +++ b/src/MANYBODY/pair_eim.h @@ -98,17 +98,21 @@ class EIMPotentialFileReader : protected Pointers { std::string filename; static const int MAXLINE = 1024; char line[MAXLINE]; + double conversion_factor; - void parse(FILE * fp); - char * next_line(FILE * fp); - std::pair get_pair(const std::string & a, const std::string & b); + void parse(FILE *fp); + char *next_line(FILE *fp); + std::pair get_pair(const std::string &a, + const std::string &b); public: - EIMPotentialFileReader(class LAMMPS* lmp, const std::string & filename); + EIMPotentialFileReader(class LAMMPS* lmp, const std::string &filename, + const int auto_convert=0); - void get_global(PairEIM::Setfl * setfl); - void get_element(PairEIM::Setfl * setfl, int i, const std::string & name); - void get_pair(PairEIM::Setfl * setfl, int ij, const std::string & elemA, const std::string & elemB); + void get_global(PairEIM::Setfl *setfl); + void get_element(PairEIM::Setfl *setfl, int i, const std::string &name); + void get_pair(PairEIM::Setfl *setfl, int ij, + const std::string &elemA, const std::string &elemB); private: // potential parameters diff --git a/src/MANYBODY/pair_gw.cpp b/src/MANYBODY/pair_gw.cpp index e9604523b5..32b48f7eca 100644 --- a/src/MANYBODY/pair_gw.cpp +++ b/src/MANYBODY/pair_gw.cpp @@ -48,6 +48,7 @@ PairGW::PairGW(LAMMPS *lmp) : Pair(lmp) restartinfo = 0; one_coeff = 1; manybody_flag = 1; + unit_convert_flag = utils::get_supported_conversions(utils::ENERGY); nelements = 0; elements = NULL; @@ -375,9 +376,14 @@ void PairGW::read_file(char *file) // open file on proc 0 if (comm->me == 0) { - PotentialFileReader reader(lmp, file, "GW"); + PotentialFileReader reader(lmp, file, "GW", unit_convert_flag); char * line; + // transparently convert units for supported conversions + + int unit_convert = reader.get_unit_convert(); + double conversion_factor = utils::get_conversion_factor(utils::ENERGY, + unit_convert); while((line = reader.next_line(NPARAMS_PER_LINE))) { try { ValueTokenizer values(line); @@ -427,6 +433,11 @@ void PairGW::read_file(char *file) params[nparams].lam1 = values.next_double(); params[nparams].biga = values.next_double(); params[nparams].powermint = int(params[nparams].powerm); + + if (unit_convert) { + params[nparams].biga *= conversion_factor; + params[nparams].bigb *= conversion_factor; + } } catch (TokenizerException & e) { error->one(FLERR, e.what()); } diff --git a/src/MANYBODY/pair_gw_zbl.cpp b/src/MANYBODY/pair_gw_zbl.cpp index 96fc742b42..ddc70174f6 100644 --- a/src/MANYBODY/pair_gw_zbl.cpp +++ b/src/MANYBODY/pair_gw_zbl.cpp @@ -70,9 +70,14 @@ void PairGWZBL::read_file(char *file) // open file on proc 0 if (comm->me == 0) { - PotentialFileReader reader(lmp, file, "GW/ZBL"); + PotentialFileReader reader(lmp, file, "GW/ZBL", unit_convert_flag); char * line; + // transparently convert units for supported conversions + + int unit_convert = reader.get_unit_convert(); + double conversion_factor = utils::get_conversion_factor(utils::ENERGY, + unit_convert); while((line = reader.next_line(NPARAMS_PER_LINE))) { try { ValueTokenizer values(line); @@ -126,6 +131,11 @@ void PairGWZBL::read_file(char *file) params[nparams].ZBLcut = values.next_double(); params[nparams].ZBLexpscale = values.next_double(); params[nparams].powermint = int(params[nparams].powerm); + + if (unit_convert) { + params[nparams].biga *= conversion_factor; + params[nparams].bigb *= conversion_factor; + } } catch (TokenizerException & e) { error->one(FLERR, e.what()); } diff --git a/src/MANYBODY/pair_nb3b_harmonic.cpp b/src/MANYBODY/pair_nb3b_harmonic.cpp index 7491c375db..6f1bfb8905 100644 --- a/src/MANYBODY/pair_nb3b_harmonic.cpp +++ b/src/MANYBODY/pair_nb3b_harmonic.cpp @@ -47,6 +47,7 @@ PairNb3bHarmonic::PairNb3bHarmonic(LAMMPS *lmp) : Pair(lmp) restartinfo = 0; one_coeff = 1; manybody_flag = 1; + unit_convert_flag = utils::get_supported_conversions(utils::ENERGY); nelements = 0; elements = NULL; @@ -291,9 +292,14 @@ void PairNb3bHarmonic::read_file(char *file) // open file on proc 0 if (comm->me == 0) { - PotentialFileReader reader(lmp, file, "nb3b/harmonic"); + PotentialFileReader reader(lmp, file, "nb3b/harmonic", unit_convert_flag); char * line; + // transparently convert units for supported conversions + + int unit_convert = reader.get_unit_convert(); + double conversion_factor = utils::get_conversion_factor(utils::ENERGY, + unit_convert); while((line = reader.next_line(NPARAMS_PER_LINE))) { try { ValueTokenizer values(line); @@ -331,6 +337,8 @@ void PairNb3bHarmonic::read_file(char *file) params[nparams].k_theta = values.next_double(); params[nparams].theta0 = values.next_double(); params[nparams].cutoff = values.next_double(); + + if (unit_convert) params[nparams].k_theta *= conversion_factor; } catch (TokenizerException & e) { error->one(FLERR, e.what()); } diff --git a/src/MANYBODY/pair_sw.cpp b/src/MANYBODY/pair_sw.cpp index 0aed2ec68b..68ce28e9a1 100644 --- a/src/MANYBODY/pair_sw.cpp +++ b/src/MANYBODY/pair_sw.cpp @@ -44,6 +44,7 @@ PairSW::PairSW(LAMMPS *lmp) : Pair(lmp) restartinfo = 0; one_coeff = 1; manybody_flag = 1; + unit_convert_flag = utils::get_supported_conversions(utils::ENERGY); nelements = 0; elements = NULL; @@ -355,9 +356,16 @@ void PairSW::read_file(char *file) // open file on proc 0 if (comm->me == 0) { - PotentialFileReader reader(lmp, file, "Stillinger-Weber"); + PotentialFileReader reader(lmp, file, "Stillinger-Weber", + unit_convert_flag); char * line; + // transparently convert units for supported conversions + + int unit_convert = reader.get_unit_convert(); + double conversion_factor = utils::get_conversion_factor(utils::ENERGY, + unit_convert); + while((line = reader.next_line(NPARAMS_PER_LINE))) { try { ValueTokenizer values(line); @@ -407,6 +415,10 @@ void PairSW::read_file(char *file) error->one(FLERR, e.what()); } + if (unit_convert) { + params[nparams].epsilon *= conversion_factor; + } + if (params[nparams].epsilon < 0.0 || params[nparams].sigma < 0.0 || params[nparams].littlea < 0.0 || params[nparams].lambda < 0.0 || params[nparams].gamma < 0.0 || params[nparams].biga < 0.0 || diff --git a/src/MANYBODY/pair_tersoff.cpp b/src/MANYBODY/pair_tersoff.cpp index 4ba7471e60..d690c96497 100644 --- a/src/MANYBODY/pair_tersoff.cpp +++ b/src/MANYBODY/pair_tersoff.cpp @@ -49,6 +49,7 @@ PairTersoff::PairTersoff(LAMMPS *lmp) : Pair(lmp) restartinfo = 0; one_coeff = 1; manybody_flag = 1; + unit_convert_flag = utils::get_supported_conversions(utils::ENERGY); nelements = 0; elements = NULL; @@ -400,9 +401,14 @@ void PairTersoff::read_file(char *file) // open file on proc 0 if (comm->me == 0) { - PotentialFileReader reader(lmp, file, "Tersoff"); - char * line; + PotentialFileReader reader(lmp, file, "Tersoff", unit_convert_flag); + char *line; + // transparently convert units for supported conversions + + int unit_convert = reader.get_unit_convert(); + double conversion_factor = utils::get_conversion_factor(utils::ENERGY, + unit_convert); while((line = reader.next_line(NPARAMS_PER_LINE))) { try { ValueTokenizer values(line); @@ -426,7 +432,6 @@ void PairTersoff::read_file(char *file) if (kname == elements[kelement]) break; if (kelement == nelements) continue; - // load up parameter settings and error check their values if (nparams == maxparam) { @@ -453,6 +458,11 @@ void PairTersoff::read_file(char *file) params[nparams].lam1 = values.next_double(); params[nparams].biga = values.next_double(); params[nparams].powermint = int(params[nparams].powerm); + + if (unit_convert) { + params[nparams].biga *= conversion_factor; + params[nparams].bigb *= conversion_factor; + } } catch (TokenizerException & e) { error->one(FLERR, e.what()); } diff --git a/src/MANYBODY/pair_tersoff_mod.cpp b/src/MANYBODY/pair_tersoff_mod.cpp index 441ba6f21e..6a60b0855c 100644 --- a/src/MANYBODY/pair_tersoff_mod.cpp +++ b/src/MANYBODY/pair_tersoff_mod.cpp @@ -53,9 +53,14 @@ void PairTersoffMOD::read_file(char *file) // open file on proc 0 if (comm->me == 0) { - PotentialFileReader reader(lmp, file, "Tersoff"); + PotentialFileReader reader(lmp, file, "TersoffMod", unit_convert_flag); char * line; + // transparently convert units for supported conversions + + int unit_convert = reader.get_unit_convert(); + double conversion_factor = utils::get_conversion_factor(utils::ENERGY, + unit_convert); while((line = reader.next_line(NPARAMS_PER_LINE))) { try { ValueTokenizer values(line); @@ -109,6 +114,11 @@ void PairTersoffMOD::read_file(char *file) params[nparams].c4 = values.next_double(); params[nparams].c5 = values.next_double(); params[nparams].powermint = int(params[nparams].powerm); + + if (unit_convert) { + params[nparams].biga *= conversion_factor; + params[nparams].bigb *= conversion_factor; + } } catch (TokenizerException & e) { error->one(FLERR, e.what()); } diff --git a/src/MANYBODY/pair_tersoff_mod_c.cpp b/src/MANYBODY/pair_tersoff_mod_c.cpp index 33e88c70b8..da14463112 100644 --- a/src/MANYBODY/pair_tersoff_mod_c.cpp +++ b/src/MANYBODY/pair_tersoff_mod_c.cpp @@ -44,9 +44,14 @@ void PairTersoffMODC::read_file(char *file) // open file on proc 0 if (comm->me == 0) { - PotentialFileReader reader(lmp, file, "Tersoff"); + PotentialFileReader reader(lmp, file, "TersoffModC", unit_convert_flag); char * line; + // transparently convert units for supported conversions + + int unit_convert = reader.get_unit_convert(); + double conversion_factor = utils::get_conversion_factor(utils::ENERGY, + unit_convert); while((line = reader.next_line(NPARAMS_PER_LINE))) { try { ValueTokenizer values(line); @@ -101,6 +106,12 @@ void PairTersoffMODC::read_file(char *file) params[nparams].c5 = values.next_double(); params[nparams].c0 = values.next_double(); params[nparams].powermint = int(params[nparams].powerm); + + if (unit_convert) { + params[nparams].biga *= conversion_factor; + params[nparams].bigb *= conversion_factor; + params[nparams].c0 *= conversion_factor; + } } catch (TokenizerException & e) { error->one(FLERR, e.what()); } diff --git a/src/MANYBODY/pair_tersoff_zbl.cpp b/src/MANYBODY/pair_tersoff_zbl.cpp index 2b464061ca..adf78fe070 100644 --- a/src/MANYBODY/pair_tersoff_zbl.cpp +++ b/src/MANYBODY/pair_tersoff_zbl.cpp @@ -71,9 +71,15 @@ void PairTersoffZBL::read_file(char *file) // open file on proc 0 if (comm->me == 0) { - PotentialFileReader reader(lmp, file, "Tersoff"); + PotentialFileReader reader(lmp, file, "TersoffZBL", unit_convert_flag); char * line; + // transparently convert units for supported conversions + + int unit_convert = reader.get_unit_convert(); + double conversion_factor = utils::get_conversion_factor(utils::ENERGY, + unit_convert); + while((line = reader.next_line(NPARAMS_PER_LINE))) { try { ValueTokenizer values(line); @@ -97,7 +103,6 @@ void PairTersoffZBL::read_file(char *file) if (kname == elements[kelement]) break; if (kelement == nelements) continue; - // load up parameter settings and error check their values if (nparams == maxparam) { @@ -128,6 +133,11 @@ void PairTersoffZBL::read_file(char *file) params[nparams].ZBLcut = values.next_double(); params[nparams].ZBLexpscale = values.next_double(); params[nparams].powermint = int(params[nparams].powerm); + + if (unit_convert) { + params[nparams].biga *= conversion_factor; + params[nparams].bigb *= conversion_factor; + } } catch (TokenizerException & e) { error->one(FLERR, e.what()); } diff --git a/src/MANYBODY/pair_vashishta.cpp b/src/MANYBODY/pair_vashishta.cpp index 37fea2582f..1b905a259b 100644 --- a/src/MANYBODY/pair_vashishta.cpp +++ b/src/MANYBODY/pair_vashishta.cpp @@ -45,6 +45,7 @@ PairVashishta::PairVashishta(LAMMPS *lmp) : Pair(lmp) restartinfo = 0; one_coeff = 1; manybody_flag = 1; + unit_convert_flag = utils::get_supported_conversions(utils::ENERGY); nelements = 0; elements = NULL; @@ -361,9 +362,15 @@ void PairVashishta::read_file(char *file) // open file on proc 0 if (comm->me == 0) { - PotentialFileReader reader(lmp, file, "Vashishta"); + PotentialFileReader reader(lmp, file, "Vashishta", unit_convert_flag); char * line; + // transparently convert units for supported conversions + + int unit_convert = reader.get_unit_convert(); + double conversion_factor = utils::get_conversion_factor(utils::ENERGY, + unit_convert); + while((line = reader.next_line(NPARAMS_PER_LINE))) { try { ValueTokenizer values(line); @@ -412,6 +419,14 @@ void PairVashishta::read_file(char *file) params[nparams].r0 = values.next_double(); params[nparams].bigc = values.next_double(); params[nparams].costheta = values.next_double(); + + if (unit_convert) { + params[nparams].bigh *= conversion_factor; + params[nparams].bigd *= conversion_factor; + params[nparams].bigw *= conversion_factor; + params[nparams].bigb *= conversion_factor; + } + } catch (TokenizerException & e) { error->one(FLERR, e.what()); } diff --git a/src/MC/fix_bond_swap.cpp b/src/MC/fix_bond_swap.cpp index 187c552416..8d3ff14f48 100644 --- a/src/MC/fix_bond_swap.cpp +++ b/src/MC/fix_bond_swap.cpp @@ -86,17 +86,11 @@ FixBondSwap::FixBondSwap(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp, compute group = fix group - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); + std::string cmd = id + std::string("_temp"); + id_temp = new char[cmd.size()+1]; + strcpy(id_temp,cmd.c_str()); - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp"; - modify->add_compute(3,newarg); - delete [] newarg; + modify->add_compute(cmd + " all temp"); tflag = 1; // initialize atom list diff --git a/src/MC/pair_dsmc.cpp b/src/MC/pair_dsmc.cpp index dbb68b56f7..ed03ca6ffc 100644 --- a/src/MC/pair_dsmc.cpp +++ b/src/MC/pair_dsmc.cpp @@ -28,6 +28,7 @@ #include "update.h" #include "random_mars.h" #include "utils.h" +#include "fmt/format.h" using namespace LAMMPS_NS; @@ -283,12 +284,9 @@ void PairDSMC::init_style() celly = (domain->boxhi[1] - domain->boxlo[1])/ncellsy; cellz = (domain->boxhi[2] - domain->boxlo[2])/ncellsz; - if (comm->me == 0) { - if (screen) fprintf(screen,"DSMC cell size = %g x %g x %g\n", - cellx,celly,cellz); - if (logfile) fprintf(logfile,"DSMC cell size = %g x %g x %g\n", - cellx,celly,cellz); - } + if (comm->me == 0) + utils::logmesg(lmp,fmt::format("DSMC cell size = {} x {} x {}\n", + cellx,celly,cellz)); total_ncells = ncellsx*ncellsy*ncellsz; vol = cellx*celly*cellz; diff --git a/src/MISC/fix_deposit.cpp b/src/MISC/fix_deposit.cpp index a15a359881..4d65457340 100644 --- a/src/MISC/fix_deposit.cpp +++ b/src/MISC/fix_deposit.cpp @@ -31,6 +31,7 @@ #include "math_const.h" #include "memory.h" #include "error.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -286,12 +287,9 @@ void FixDeposit::init() } else maxradinsert = 0.5; double separation = MAX(2.0*maxradinsert,maxradall+maxradinsert); - if (sqrt(nearsq) < separation && comm->me == 0) { - char str[128]; - sprintf(str,"Fix deposit near setting < possible overlap separation %g", - separation); - error->warning(FLERR,str); - } + if (sqrt(nearsq) < separation && comm->me == 0) + error->warning(FLERR,fmt::format("Fix deposit near setting < possible " + "overlap separation {}",separation)); } } diff --git a/src/MISC/fix_orient_bcc.cpp b/src/MISC/fix_orient_bcc.cpp index f93c7f8a6a..8548ee04cf 100644 --- a/src/MISC/fix_orient_bcc.cpp +++ b/src/MISC/fix_orient_bcc.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include "atom.h" #include "update.h" #include "respa.h" @@ -35,6 +36,8 @@ #include "citeme.h" #include "memory.h" #include "error.h" +#include "utils.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -450,20 +453,12 @@ void FixOrientBCC::post_force(int /*vflag*/) MPI_Allreduce(&maxcount,&max,1,MPI_INT,MPI_MAX,world); if (me == 0) { - if (screen) fprintf(screen, - "orient step " BIGINT_FORMAT ": " BIGINT_FORMAT - " atoms have %d neighbors\n", - update->ntimestep,atom->natoms,total); - if (logfile) fprintf(logfile, - "orient step " BIGINT_FORMAT ": " BIGINT_FORMAT - " atoms have %d neighbors\n", - update->ntimestep,atom->natoms,total); - if (screen) - fprintf(screen," neighs: min = %d, max = %d, ave = %g\n", - min,max,ave); - if (logfile) - fprintf(logfile," neighs: min = %d, max = %d, ave = %g\n", - min,max,ave); + std::string mesg = fmt::format("orient step {}: {} atoms have {} " + "neighbors\n", update->ntimestep, + atom->natoms,total); + mesg += fmt::format(" neighs: min = {}, max ={}, ave = {}\n", + min,max,ave); + utils::logmesg(lmp,mesg); } } } diff --git a/src/MISC/fix_orient_fcc.cpp b/src/MISC/fix_orient_fcc.cpp index 082ecaf459..97c545d189 100644 --- a/src/MISC/fix_orient_fcc.cpp +++ b/src/MISC/fix_orient_fcc.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include "atom.h" #include "update.h" #include "respa.h" @@ -32,6 +33,8 @@ #include "citeme.h" #include "memory.h" #include "error.h" +#include "utils.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -448,20 +451,12 @@ void FixOrientFCC::post_force(int /*vflag*/) MPI_Allreduce(&maxcount,&max,1,MPI_INT,MPI_MAX,world); if (me == 0) { - if (screen) fprintf(screen, - "orient step " BIGINT_FORMAT ": " BIGINT_FORMAT - " atoms have %d neighbors\n", - update->ntimestep,atom->natoms,total); - if (logfile) fprintf(logfile, - "orient step " BIGINT_FORMAT ": " BIGINT_FORMAT - " atoms have %d neighbors\n", - update->ntimestep,atom->natoms,total); - if (screen) - fprintf(screen," neighs: min = %d, max = %d, ave = %g\n", - min,max,ave); - if (logfile) - fprintf(logfile," neighs: min = %d, max = %d, ave = %g\n", - min,max,ave); + std::string mesg = fmt::format("orient step {}: {} atoms have {} " + "neighbors\n", update->ntimestep, + atom->natoms,total); + mesg += fmt::format(" neighs: min = {}, max ={}, ave = {}\n", + min,max,ave); + utils::logmesg(lmp,mesg); } } } diff --git a/src/MISC/fix_ttm.cpp b/src/MISC/fix_ttm.cpp index eb9eb2620d..1c27e8affe 100644 --- a/src/MISC/fix_ttm.cpp +++ b/src/MISC/fix_ttm.cpp @@ -29,6 +29,8 @@ #include "random_mars.h" #include "memory.h" #include "error.h" +#include "utils.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -66,25 +68,22 @@ FixTTM::FixTTM(LAMMPS *lmp, int narg, char **arg) : nynodes = force->inumeric(FLERR,arg[11]); nznodes = force->inumeric(FLERR,arg[12]); - fpr = fopen(arg[13],"r"); - if (fpr == NULL) { - char str[128]; - snprintf(str,128,"Cannot open file %s",arg[13]); - error->one(FLERR,str); + if (comm->me == 0) { + fpr = fopen(arg[13],"r"); + if (fpr == NULL) + error->all(FLERR,fmt::format("Cannot open input file {}: {}", + arg[13], utils::getsyserror())); } nfileevery = force->inumeric(FLERR,arg[14]); if (nfileevery) { if (narg != 16) error->all(FLERR,"Illegal fix ttm command"); - MPI_Comm_rank(world,&me); - if (me == 0) { + if (comm->me == 0) { fp = fopen(arg[15],"w"); - if (fp == NULL) { - char str[128]; - snprintf(str,128,"Cannot open fix ttm file %s",arg[15]); - error->one(FLERR,str); - } + if (fp == NULL) + error->one(FLERR,fmt::format("Cannot open output file {}: {}", + arg[15], utils::getsyserror())); } } diff --git a/src/MLIAP/mliap_descriptor_snap.cpp b/src/MLIAP/mliap_descriptor_snap.cpp index 87b6c17166..b1542f25d4 100644 --- a/src/MLIAP/mliap_descriptor_snap.cpp +++ b/src/MLIAP/mliap_descriptor_snap.cpp @@ -36,7 +36,7 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ -MLIAPDescriptorSNAP::MLIAPDescriptorSNAP(LAMMPS *lmp, char *paramfilename): +MLIAPDescriptorSNAP::MLIAPDescriptorSNAP(LAMMPS *lmp, char *paramfilename): MLIAPDescriptor(lmp) { nelements = 0; @@ -154,15 +154,13 @@ void MLIAPDescriptorSNAP::forward(int* map, NeighList* list, double **descriptor void MLIAPDescriptorSNAP::backward(PairMLIAP* pairmliap, NeighList* list, double **beta, int vflag) { int i,j,jnum,ninside; - double delx,dely,delz,evdwl,rsq; + double delx,dely,delz,rsq; double fij[3]; int *jlist,*numneigh,**firstneigh; double **x = atom->x; double **f = atom->f; int *type = atom->type; - int nlocal = atom->nlocal; - int newton_pair = force->newton_pair; numneigh = list->numneigh; firstneigh = list->firstneigh; @@ -245,13 +243,13 @@ void MLIAPDescriptorSNAP::backward(PairMLIAP* pairmliap, NeighList* list, double // add in global and per-atom virial contributions // this is optional and has no effect on force calculation - + if (vflag) pairmliap->v_tally(i,j, fij[0],fij[1],fij[2], -snaptr->rij[jj][0],-snaptr->rij[jj][1], -snaptr->rij[jj][2]); - + } } @@ -404,11 +402,9 @@ void MLIAPDescriptorSNAP::read_paramfile(char *paramfilename) FILE *fpparam; if (comm->me == 0) { fpparam = force->open_potential(paramfilename); - if (fpparam == NULL) { - char str[128]; - snprintf(str,128,"Cannot open SNAP parameter file %s",paramfilename); - error->one(FLERR,str); - } + if (fpparam == NULL) + error->one(FLERR,fmt::format("Cannot open SNAP parameter file {}: {}", + paramfilename, utils::getsyserror())); } char line[MAXLINE],*ptr; @@ -444,8 +440,8 @@ void MLIAPDescriptorSNAP::read_paramfile(char *paramfilename) utils::logmesg(lmp, fmt::format("SNAP keyword {} {} \n", keywd, keyval)); } - // check for keywords with one value per element - + // check for keywords with one value per element + if (strcmp(keywd,"elems") == 0 || strcmp(keywd,"radelems") == 0 || strcmp(keywd,"welems") == 0) { @@ -478,9 +474,9 @@ void MLIAPDescriptorSNAP::read_paramfile(char *paramfilename) } else { - // all other keywords take one value + // all other keywords take one value - if (nwords != 2) + if (nwords != 2) error->all(FLERR,"Incorrect SNAP parameter file"); if (strcmp(keywd,"nelems") == 0) { @@ -514,8 +510,8 @@ void MLIAPDescriptorSNAP::read_paramfile(char *paramfilename) } } - - if (!rcutfacflag || !twojmaxflag || !nelementsflag || + + if (!rcutfacflag || !twojmaxflag || !nelementsflag || !elementsflag || !radelemflag || !wjelemflag) error->all(FLERR,"Incorrect SNAP parameter file"); diff --git a/src/MLIAP/mliap_model.cpp b/src/MLIAP/mliap_model.cpp index 5ab96e19d4..1f88465304 100644 --- a/src/MLIAP/mliap_model.cpp +++ b/src/MLIAP/mliap_model.cpp @@ -22,6 +22,7 @@ #include "neigh_list.h" #include "memory.h" #include "error.h" +#include "fmt/format.h" using namespace LAMMPS_NS; @@ -73,11 +74,9 @@ void MLIAPModel::read_coeffs(char *coefffilename) FILE *fpcoeff; if (comm->me == 0) { fpcoeff = force->open_potential(coefffilename); - if (fpcoeff == NULL) { - char str[128]; - snprintf(str,128,"Cannot open MLIAPModel coefficient file %s",coefffilename); - error->one(FLERR,str); - } + if (fpcoeff == NULL) + error->one(FLERR,fmt::format("Cannot open MLIAPModel coeff file {}: {}", + coefffilename,utils::getsyserror())); } char line[MAXLINE],*ptr; @@ -153,7 +152,6 @@ void MLIAPModel::read_coeffs(char *coefffilename) } if (comm->me == 0) fclose(fpcoeff); - } /* ---------------------------------------------------------------------- @@ -164,9 +162,7 @@ double MLIAPModel::memory_usage() { double bytes = 0; - int n = atom->ntypes+1; bytes += nelements*nparams*sizeof(double); // coeffelem - return bytes; } diff --git a/src/MLIAP/mliap_model_linear.cpp b/src/MLIAP/mliap_model_linear.cpp index f597d10b33..b8d06155ba 100644 --- a/src/MLIAP/mliap_model_linear.cpp +++ b/src/MLIAP/mliap_model_linear.cpp @@ -28,7 +28,7 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ -MLIAPModelLinear::MLIAPModelLinear(LAMMPS* lmp, char* coefffilename) : +MLIAPModelLinear::MLIAPModelLinear(LAMMPS* lmp, char* coefffilename) : MLIAPModel(lmp, coefffilename) { ndescriptors = nparams - 1; @@ -79,7 +79,7 @@ void MLIAPModelLinear::gradient(PairMLIAP* pairmliap, NeighList* list, double ** for (int icoeff = 0; icoeff < ndescriptors; icoeff++) etmp += coeffi[icoeff+1]*descriptors[ii][icoeff]; - + pairmliap->e_tally(i,etmp); } } diff --git a/src/MLIAP/mliap_model_quadratic.cpp b/src/MLIAP/mliap_model_quadratic.cpp index 062e66959a..f5aae1d89d 100644 --- a/src/MLIAP/mliap_model_quadratic.cpp +++ b/src/MLIAP/mliap_model_quadratic.cpp @@ -28,7 +28,7 @@ using namespace LAMMPS_NS; /* ---------------------------------------------------------------------- */ -MLIAPModelQuadratic::MLIAPModelQuadratic(LAMMPS* lmp, char* coefffilename) : +MLIAPModelQuadratic::MLIAPModelQuadratic(LAMMPS* lmp, char* coefffilename) : MLIAPModel(lmp, coefffilename) { nonlinearflag = 1; @@ -81,7 +81,7 @@ void MLIAPModelQuadratic::gradient(PairMLIAP* pairmliap, NeighList* list, double // add in contributions to global and per-atom energy // this is optional and has no effect on force calculation - + if (eflag) { // energy of atom I diff --git a/src/MLIAP/pair_mliap.cpp b/src/MLIAP/pair_mliap.cpp index 129fcdd6b7..14d4cce753 100644 --- a/src/MLIAP/pair_mliap.cpp +++ b/src/MLIAP/pair_mliap.cpp @@ -93,10 +93,10 @@ void PairMLIAP::compute(int eflag, int vflag) model->gradient(this, list, descriptors, beta, eflag); // calculate force contributions beta_i*dB_i/dR_j - + descriptor->backward(this, list, beta, vflag); - // calculate stress + // calculate stress if (vflag_fdotr) virial_fdotr_compute(); } diff --git a/src/MLIAP/pair_mliap.h b/src/MLIAP/pair_mliap.h index 66bafab97a..4d4499edd1 100644 --- a/src/MLIAP/pair_mliap.h +++ b/src/MLIAP/pair_mliap.h @@ -45,7 +45,7 @@ protected: double** beta; // betas for all atoms in list double** descriptors; // descriptors for all atoms in list - int ndescriptors; // number of descriptors + int ndescriptors; // number of descriptors int beta_max; // number of atoms allocated for beta, descriptors class MLIAPModel* model; diff --git a/src/MOLECULE/bond_fene.cpp b/src/MOLECULE/bond_fene.cpp index f87f12a3b1..357c37b7a2 100644 --- a/src/MOLECULE/bond_fene.cpp +++ b/src/MOLECULE/bond_fene.cpp @@ -83,7 +83,6 @@ void BondFENE::compute(int eflag, int vflag) // if r -> r0, then rlogarg < 0.0 which is an error // issue a warning and reset rlogarg = epsilon // if r > 2*r0 something serious is wrong, abort - printf("r = %g r0 = %g rlogarg = %g\n",sqrt(rsq),sqrt(r0sq),rlogarg); if (rlogarg < 0.1) { error->warning(FLERR,fmt::format("FENE bond too long: {} {} {} {}", diff --git a/src/MOLECULE/fix_cmap.cpp b/src/MOLECULE/fix_cmap.cpp index a1b4d23b05..6fbf82e4cc 100644 --- a/src/MOLECULE/fix_cmap.cpp +++ b/src/MOLECULE/fix_cmap.cpp @@ -42,6 +42,7 @@ #include "memory.h" #include "error.h" #include "utils.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -253,17 +254,12 @@ void FixCMAP::pre_neighbor() atom5 = atom->map(crossterm_atom5[i][m]); if (atom1 == -1 || atom2 == -1 || atom3 == -1 || - atom4 == -1 || atom5 == -1) { - char str[128]; - sprintf(str,"CMAP atoms " - TAGINT_FORMAT " " TAGINT_FORMAT " " TAGINT_FORMAT " " - TAGINT_FORMAT " " TAGINT_FORMAT - " missing on proc %d at step " BIGINT_FORMAT, - crossterm_atom1[i][m],crossterm_atom2[i][m], - crossterm_atom3[i][m],crossterm_atom4[i][m], - crossterm_atom5[i][m],me,update->ntimestep); - error->one(FLERR,str); - } + atom4 == -1 || atom5 == -1) + error->one(FLERR,fmt::format("CMAP atoms {} {} {} {} {} missing on " + "proc {} at step {}", + crossterm_atom1[i][m],crossterm_atom2[i][m], + crossterm_atom3[i][m],crossterm_atom4[i][m], + crossterm_atom5[i][m],me,update->ntimestep)); atom1 = domain->closest_image(i,atom1); atom2 = domain->closest_image(i,atom2); atom3 = domain->closest_image(i,atom3); @@ -638,11 +634,10 @@ void FixCMAP::read_grid_map(char *cmapfile) FILE *fp = NULL; if (comm->me == 0) { fp = force->open_potential(cmapfile); - if (fp == NULL) { - char str[128]; - snprintf(str,128,"Cannot open fix cmap file %s",cmapfile); - error->one(FLERR,str); - } + if (fp == NULL) + error->one(FLERR,fmt::format("Cannot open fix cmap file {}: {}", + cmapfile, utils::getsyserror())); + } for (int ix1 = 0; ix1 < 6; ix1++) @@ -1070,11 +1065,8 @@ void FixCMAP::read_data_section(char *keyword, int n, char *buf, int nwords = utils::count_words(utils::trim_comment(buf)); *next = '\n'; - if (nwords != 7) { - char str[128]; - snprintf(str,128,"Incorrect %s format in data file",keyword); - error->all(FLERR,str); - } + if (nwords != 7) + error->all(FLERR,fmt::format("Incorrect {} format in data file",keyword)); // loop over lines of CMAP crossterms // tokenize the line into values diff --git a/src/OPT/pair_eam_opt.cpp b/src/OPT/pair_eam_opt.cpp index 7dff5cff4b..e6b6fb72f4 100644 --- a/src/OPT/pair_eam_opt.cpp +++ b/src/OPT/pair_eam_opt.cpp @@ -27,6 +27,7 @@ #include "force.h" #include "neigh_list.h" #include "memory.h" +#include "update.h" using namespace LAMMPS_NS; @@ -176,8 +177,6 @@ void PairEAMOpt::eval() // rho = density at each atom // loop over neighbors of my atoms - // loop over neighbors of my atoms - for (ii = 0; ii < inum; ii++) { i = ilist[ii]; double xtmp = xx[i].x; @@ -234,10 +233,11 @@ void PairEAMOpt::eval() for (ii = 0; ii < inum; ii++) { i = ilist[ii]; - double p = rho[i]*rdrho; - int m = MIN((int)p,nrho-2); - p -= (double)m; - ++m; + double p = rho[i]*rdrho + 1.0; + int m = static_cast (p); + m = MAX(1,MIN(m,nrho-1)); + p -= m; + p = MIN(p,1.0); coeff = frho_spline[type2frho[type[i]]][m]; fp[i] = (coeff[0]*p + coeff[1])*p + coeff[2]; if (EFLAG) { @@ -252,6 +252,7 @@ void PairEAMOpt::eval() // communicate derivative of embedding function comm->forward_comm_pair(this); + embedstep = update->ntimestep; // compute forces on each atom // loop over neighbors of my atoms @@ -290,7 +291,9 @@ void PairEAMOpt::eval() double p = r*tmp_rdr; if ( (int)p <= nr2 ) { int m = (int) p + 1; + m = MIN(m,nr-1); p -= (double)((int) p); + p = MIN(p,1.0); fast_gamma_t& a = tabssi[jtype*nr+m]; rhoip = (a.rhor6i*p + a.rhor5i)*p + a.rhor4i; diff --git a/src/PERI/pair_peri_eps.cpp b/src/PERI/pair_peri_eps.cpp index ff79320fc3..cae33fe580 100644 --- a/src/PERI/pair_peri_eps.cpp +++ b/src/PERI/pair_peri_eps.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include "atom.h" #include "domain.h" #include "lattice.h" @@ -515,14 +516,7 @@ void PairPeriEPS::init_style() // if first init, create Fix needed for storing fixed neighbors - if (ifix_peri == -1) { - char **fixarg = new char*[3]; - fixarg[0] = (char *) "PERI_NEIGH"; - fixarg[1] = (char *) "all"; - fixarg[2] = (char *) "PERI_NEIGH"; - modify->add_fix(3,fixarg); - delete [] fixarg; - } + if (ifix_peri == -1) modify->add_fix("PERI_NEIGH all PERI_NEIGH"); // find associated PERI_NEIGH fix that must exist // could have changed locations in fix list since created diff --git a/src/PERI/pair_peri_lps.cpp b/src/PERI/pair_peri_lps.cpp index 0ad6a7b0d2..65c6c30e19 100644 --- a/src/PERI/pair_peri_lps.cpp +++ b/src/PERI/pair_peri_lps.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include "atom.h" #include "domain.h" #include "lattice.h" @@ -439,14 +440,7 @@ void PairPeriLPS::init_style() // if first init, create Fix needed for storing fixed neighbors - if (ifix_peri == -1) { - char **fixarg = new char*[3]; - fixarg[0] = (char *) "PERI_NEIGH"; - fixarg[1] = (char *) "all"; - fixarg[2] = (char *) "PERI_NEIGH"; - modify->add_fix(3,fixarg); - delete [] fixarg; - } + if (ifix_peri == -1) modify->add_fix("PERI_NEIGH all PERI_NEIGH"); // find associated PERI_NEIGH fix that must exist // could have changed locations in fix list since created diff --git a/src/PERI/pair_peri_pmb.cpp b/src/PERI/pair_peri_pmb.cpp index 88aca99efb..7c900b5c4e 100644 --- a/src/PERI/pair_peri_pmb.cpp +++ b/src/PERI/pair_peri_pmb.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include "atom.h" #include "domain.h" #include "lattice.h" @@ -369,14 +370,7 @@ void PairPeriPMB::init_style() // if first init, create Fix needed for storing fixed neighbors - if (ifix_peri == -1) { - char **fixarg = new char*[3]; - fixarg[0] = (char *) "PERI_NEIGH"; - fixarg[1] = (char *) "all"; - fixarg[2] = (char *) "PERI_NEIGH"; - modify->add_fix(3,fixarg); - delete [] fixarg; - } + if (ifix_peri == -1) modify->add_fix("PERI_NEIGH all PERI_NEIGH"); // find associated PERI_NEIGH fix that must exist // could have changed locations in fix list since created diff --git a/src/PERI/pair_peri_ves.cpp b/src/PERI/pair_peri_ves.cpp index 1d9f3819ff..ed9babf5ed 100644 --- a/src/PERI/pair_peri_ves.cpp +++ b/src/PERI/pair_peri_ves.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include "atom.h" #include "domain.h" #include "lattice.h" @@ -495,14 +496,7 @@ void PairPeriVES::init_style() // if first init, create Fix needed for storing fixed neighbors - if (ifix_peri == -1) { - char **fixarg = new char*[3]; - fixarg[0] = (char *) "PERI_NEIGH"; - fixarg[1] = (char *) "all"; - fixarg[2] = (char *) "PERI_NEIGH"; - modify->add_fix(3,fixarg); - delete [] fixarg; - } + if (ifix_peri == -1) modify->add_fix("PERI_NEIGH all PERI_NEIGH"); // find associated PERI_NEIGH fix that must exist // could have changed locations in fix list since created diff --git a/src/POEMS/fix_poems.cpp b/src/POEMS/fix_poems.cpp index c8646f5b14..b0b1287717 100644 --- a/src/POEMS/fix_poems.cpp +++ b/src/POEMS/fix_poems.cpp @@ -34,6 +34,8 @@ #include "citeme.h" #include "memory.h" #include "error.h" +#include "utils.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -275,14 +277,9 @@ FixPOEMS::FixPOEMS(LAMMPS *lmp, int narg, char **arg) : for (ibody = 0; ibody < nbody; ibody++) nsum += nrigid[ibody]; nsum -= njoint; - if (me == 0) { - if (screen) - fprintf(screen,"%d clusters, %d bodies, %d joints, %d atoms\n", - ncluster,nbody,njoint,nsum); - if (logfile) - fprintf(logfile,"%d clusters, %d bodies, %d joints, %d atoms\n", - ncluster,nbody,njoint,nsum); - } + if (me == 0) + utils::logmesg(lmp,fmt::format("{} clusters, {} bodies, {} joints, {} atoms\n", + ncluster,nbody,njoint,nsum)); } /* ---------------------------------------------------------------------- @@ -366,9 +363,9 @@ void FixPOEMS::init() if (strcmp(modify->fix[i]->style,"poems") == 0) pflag = 1; if (pflag && (modify->fmask[i] & POST_FORCE) && !modify->fix[i]->rigid_flag) { - char str[128]; - snprintf(str,128,"Fix %s alters forces after fix poems",modify->fix[i]->id); - error->warning(FLERR,str); + if (comm->me == 0) + error->warning(FLERR,std::string("Fix ") + modify->fix[i]->id + + std::string(" alters forces after fix poems")); } } } diff --git a/src/REPLICA/fix_hyper_local.cpp b/src/REPLICA/fix_hyper_local.cpp index 8e14affef8..d5311fc37d 100644 --- a/src/REPLICA/fix_hyper_local.cpp +++ b/src/REPLICA/fix_hyper_local.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include "atom.h" #include "update.h" #include "group.h" @@ -29,6 +30,7 @@ #include "math_extra.h" #include "memory.h" #include "error.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -858,12 +860,11 @@ void FixHyperLocal::pre_reverse(int /* eflag */, int /* vflag */) int allcount; MPI_Allreduce(&checkbias_count,&allcount,1,MPI_INT,MPI_SUM,world); if (allcount) { - char str[128]; - sprintf(str,"Fix hyper/local biased bonds too close: " - "cumulative atom count %d",allcount); + std::string mesg = fmt::format("Fix hyper/local biased bonds too close: " + "cumulative atom count {}",allcount); if (checkbias_flag == WARN) { - if (me == 0) error->warning(FLERR,str); - } else error->all(FLERR,str); + if (me == 0) error->warning(FLERR,mesg); + } else error->all(FLERR,mesg); } } } @@ -1682,7 +1683,7 @@ double FixHyperLocal::compute_vector(int i) return (double) allovercount; } */ - + return 0.0; } diff --git a/src/REPLICA/fix_neb.cpp b/src/REPLICA/fix_neb.cpp index 7b377ae9ec..b3af01fda4 100644 --- a/src/REPLICA/fix_neb.cpp +++ b/src/REPLICA/fix_neb.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include "universe.h" #include "update.h" #include "atom.h" @@ -148,17 +149,10 @@ FixNEB::FixNEB(LAMMPS *lmp, int narg, char **arg) : // create a new compute pe style // id = fix-ID + pe, compute group = all - int n = strlen(id) + 4; - id_pe = new char[n]; - strcpy(id_pe,id); - strcat(id_pe,"_pe"); - - char **newarg = new char*[3]; - newarg[0] = id_pe; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pe"; - modify->add_compute(3,newarg); - delete [] newarg; + std::string cmd = id + std::string("_pe"); + id_pe = new char[cmd.size()+1]; + strcpy(id_pe,cmd.c_str()); + modify->add_compute(cmd + " all pe"); // initialize local storage diff --git a/src/REPLICA/hyper.cpp b/src/REPLICA/hyper.cpp index 54b865108e..6a2891dee1 100644 --- a/src/REPLICA/hyper.cpp +++ b/src/REPLICA/hyper.cpp @@ -14,6 +14,7 @@ #include "hyper.h" #include #include +#include #include "update.h" #include "domain.h" #include "region.h" @@ -31,6 +32,8 @@ #include "timer.h" #include "memory.h" #include "error.h" +#include "utils.h" +#include "fmt/format.h" using namespace LAMMPS_NS; @@ -100,13 +103,8 @@ void Hyper::command(int narg, char **arg) // create FixEventHyper class to store event and pre-quench states - char **args = new char*[3]; - args[0] = (char *) "hyper_event"; - args[1] = (char *) "all"; - args[2] = (char *) "EVENT/HYPER"; - modify->add_fix(3,args); + modify->add_fix("hyper_event all EVENT/HYPER"); fix_event = (FixEventHyper *) modify->fix[modify->nfix-1]; - delete [] args; // create Finish for timing output @@ -247,10 +245,7 @@ void Hyper::command(int narg, char **arg) update->nsteps = nsteps; - if (me == 0) { - if (screen) fprintf(screen,"Final hyper stats ...\n\n"); - if (logfile) fprintf(logfile,"Final hyper stats ...\n\n"); - } + if (me == 0) utils::logmesg(lmp,"Final hyper stats ...\n\n"); // subset of quantities also available in fix hyper output // set t_hyper to no-boost value when hyperenable is not set @@ -298,55 +293,47 @@ void Hyper::command(int narg, char **arg) } if (me == 0) { - FILE *out; - for (int iout = 0; iout < 2; iout++) { - if (iout == 0) out = screen; - if (iout == 1) out = logfile; - if (!out) continue; - fprintf(out,"Cummulative quantities for fix hyper:\n"); - fprintf(out," hyper time = %g\n",t_hyper); - if (hyperenable) - fprintf(out," time boost factor = %g\n", t_hyper / - ((update->ntimestep-fix_hyper->ntimestep_initial)*update->dt)); - else fprintf(out," time boost factor = 1\n"); - fprintf(out," event timesteps = %d\n",nevent_running); - fprintf(out," # of atoms in events = %d\n",nevent_atoms_running); - fprintf(out,"Quantities for this hyper run:\n"); - fprintf(out," event timesteps = %d\n",nevent); - fprintf(out," # of atoms in events = %d\n",nevent_atoms); - fprintf(out," max length of any bond = %g\n",maxbondlen); - fprintf(out," max drift distance of any atom = %g\n",maxdrift); - fprintf(out," fraction of biased bonds with zero bias = %g\n",fraczero); - fprintf(out," fraction of biased bonds with negative strain = %g\n", - fracneg); - fprintf(out,"Current quantities:\n"); - fprintf(out," ave bonds/atom = %g\n",avebonds); + std::string mesg = "Cummulative quantities for fix hyper:\n"; + mesg += fmt::format(" hyper time = {}\n",t_hyper); + if (hyperenable) + mesg += fmt::format(" time boost factor = {}\n", t_hyper / + ((update->ntimestep -fix_hyper->ntimestep_initial)*update->dt)); + else mesg += " time boost factor = 1\n"; + mesg += fmt::format(" event timesteps = {}\n",nevent_running); + mesg += fmt::format(" # of atoms in events = {}\n",nevent_atoms_running); + mesg += "Quantities for this hyper run:\n"; + mesg += fmt::format(" event timesteps = {}\n",nevent); + mesg += fmt::format(" # of atoms in events = {}\n",nevent_atoms); + mesg += fmt::format(" max length of any bond = {}\n",maxbondlen); + mesg += fmt::format(" max drift distance of any atom = {}\n",maxdrift); + mesg += fmt::format(" fraction of biased bonds with zero bias = {}\n",fraczero); + mesg += fmt::format(" fraction of biased bonds with negative strain = {}\n",fracneg); + mesg += "Current quantities:\n"; + mesg += fmt::format(" ave bonds/atom = {}\n",avebonds); - if (hyperstyle == LOCAL) { - fprintf(out,"Cummulative quantities specific to fix hyper/local:\n"); - fprintf(out," # of new bonds formed = %g\n",nnewbond); - fprintf(out," max bonds/atom = %g\n",maxbondperatom); - fprintf(out,"Quantities for this hyper run specific to " - "fix hyper/local:\n"); - fprintf(out," ave boost for all bonds/step = %g\n",aveboost); - fprintf(out," ave biased bonds/step = %g\n",avenbias); - fprintf(out," ave bias coeff of all bonds = %g\n",avebiascoeff); - fprintf(out," min bias coeff of any bond = %g\n",minbiascoeff); - fprintf(out," max bias coeff of any bond = %g\n",maxbiascoeff); - fprintf(out," max dist from my subbox of any " - "non-maxstrain bond ghost atom = %g\n",rmaxever); - fprintf(out," max dist from my box of any bond ghost atom = %g\n", - rmaxeverbig); - fprintf(out," count of bond ghost neighbors " - "not found on reneighbor steps = %g\n",allghost_toofar); - fprintf(out," bias overlaps = %g\n",biasoverlap); - fprintf(out," CPU time for bond builds = %g\n",tbondbuild); - fprintf(out,"Current quantities specific to fix hyper/local:\n"); - fprintf(out," neighbor bonds/bond = %g\n",neighbondperbond); - fprintf(out," ave boost coeff for all bonds = %g\n",avebiasnow); - } - fprintf(out,"\n"); + if (hyperstyle == LOCAL) { + mesg += "Cummulative quantities specific to fix hyper/local:\n"; + mesg += fmt::format(" # of new bonds formed = {}\n",nnewbond); + mesg += fmt::format(" max bonds/atom = {}\n",maxbondperatom); + mesg += "Quantities for this hyper run specific to fix hyper/local:\n"; + mesg += fmt::format(" ave boost for all bonds/step = {}\n",aveboost); + mesg += fmt::format(" ave biased bonds/step = {}\n",avenbias); + mesg += fmt::format(" ave bias coeff of all bonds = {}\n",avebiascoeff); + mesg += fmt::format(" min bias coeff of any bond = {}\n",minbiascoeff); + mesg += fmt::format(" max bias coeff of any bond = {}\n",maxbiascoeff); + mesg += fmt::format(" max dist from my subbox of any " + "non-maxstrain bond ghost atom = {}\n",rmaxever); + mesg += fmt::format(" max dist from my box of any bond ghost atom = {}\n", + rmaxeverbig); + mesg += fmt::format(" count of bond ghost neighbors " + "not found on reneighbor steps = {}\n",allghost_toofar); + mesg += fmt::format(" bias overlaps = {}\n",biasoverlap); + mesg += fmt::format(" CPU time for bond builds = {}\n",tbondbuild); + mesg += "Current quantities specific to fix hyper/local:\n"; + mesg += fmt::format(" neighbor bonds/bond = {}\n",neighbondperbond); + mesg += fmt::format(" ave boost coeff for all bonds = {}\n",avebiasnow); } + utils::logmesg(lmp, mesg); } // timing stats diff --git a/src/REPLICA/prd.cpp b/src/REPLICA/prd.cpp index 63e569d0c2..633fcefc80 100644 --- a/src/REPLICA/prd.cpp +++ b/src/REPLICA/prd.cpp @@ -18,6 +18,7 @@ #include "prd.h" #include #include +#include #include "universe.h" #include "update.h" #include "atom.h" @@ -40,6 +41,7 @@ #include "timer.h" #include "memory.h" #include "error.h" +#include "utils.h" using namespace LAMMPS_NS; @@ -146,11 +148,7 @@ void PRD::command(int narg, char **arg) // create ComputeTemp class to monitor temperature - char **args = new char*[3]; - args[0] = (char *) "prd_temp"; - args[1] = (char *) "all"; - args[2] = (char *) "temp"; - modify->add_compute(3,args); + modify->add_compute("prd_temp all temp"); temperature = modify->compute[modify->ncompute-1]; // create Velocity class for velocity creation in dephasing @@ -160,6 +158,7 @@ void PRD::command(int narg, char **arg) velocity = new Velocity(lmp); velocity->init_external("all"); + char *args[2]; args[0] = (char *) "temp"; args[1] = (char *) "prd_temp"; velocity->options(2,args); @@ -172,10 +171,7 @@ void PRD::command(int narg, char **arg) // create FixEventPRD class to store event and pre-quench states - args[0] = (char *) "prd_event"; - args[1] = (char *) "all"; - args[2] = (char *) "EVENT/PRD"; - modify->add_fix(3,args); + modify->add_fix("prd_event all EVENT/PRD"); fix_event = (FixEventPRD *) modify->fix[modify->nfix-1]; // create Finish for timing output @@ -184,7 +180,6 @@ void PRD::command(int narg, char **arg) // string clean-up - delete [] args; delete [] loop_setting; delete [] dist_setting; @@ -440,10 +435,7 @@ void PRD::command(int narg, char **arg) nsteps,atom->natoms); } - if (me == 0) { - if (screen) fprintf(screen,"\nPRD done\n"); - if (logfile) fprintf(logfile,"\nPRD done\n"); - } + if (me == 0) utils::logmesg(lmp,"\nPRD done\n"); finish->end(2); diff --git a/src/REPLICA/tad.cpp b/src/REPLICA/tad.cpp index b2fbb74071..a629ee6b04 100644 --- a/src/REPLICA/tad.cpp +++ b/src/REPLICA/tad.cpp @@ -37,6 +37,7 @@ #include "timer.h" #include "memory.h" #include "error.h" +#include "utils.h" using namespace LAMMPS_NS; @@ -398,10 +399,7 @@ void TAD::command(int narg, char **arg) if ((me_universe == 0) && ulogfile_neb) fclose(ulogfile_neb); - if (me == 0) { - if (screen) fprintf(screen,"\nTAD done\n"); - if (logfile) fprintf(logfile,"\nTAD done\n"); - } + if (me == 0) utils::logmesg(lmp,"\nTAD done\n"); finish->end(3); diff --git a/src/RIGID/fix_rigid_small.cpp b/src/RIGID/fix_rigid_small.cpp index 56c4773b2b..75cd141247 100644 --- a/src/RIGID/fix_rigid_small.cpp +++ b/src/RIGID/fix_rigid_small.cpp @@ -410,9 +410,9 @@ FixRigidSmall::FixRigidSmall(LAMMPS *lmp, int narg, char **arg) : if (comm->me == 0) { if (screen) - fprintf(screen," create bodies CPU = %g secs\n",time2-time1); + fprintf(screen," create bodies CPU = %g seconds\n",time2-time1); if (logfile) - fprintf(logfile," create bodies CPU = %g secs\n",time2-time1); + fprintf(logfile," create bodies CPU = %g seconds\n",time2-time1); } // set nlocal_body and allocate bodies I own diff --git a/src/RIGID/fix_shake.cpp b/src/RIGID/fix_shake.cpp index 32d49fd7b7..215a5947e1 100644 --- a/src/RIGID/fix_shake.cpp +++ b/src/RIGID/fix_shake.cpp @@ -229,9 +229,9 @@ FixShake::FixShake(LAMMPS *lmp, int narg, char **arg) : if (comm->me == 0) { if (screen) - fprintf(screen," find clusters CPU = %g secs\n",time2-time1); + fprintf(screen," find clusters CPU = %g seconds\n",time2-time1); if (logfile) - fprintf(logfile," find clusters CPU = %g secs\n",time2-time1); + fprintf(logfile," find clusters CPU = %g seconds\n",time2-time1); } // initialize list of SHAKE clusters to constrain diff --git a/src/SNAP/compute_sna_atom.cpp b/src/SNAP/compute_sna_atom.cpp index a90bfbfa28..4a57f31ec3 100644 --- a/src/SNAP/compute_sna_atom.cpp +++ b/src/SNAP/compute_sna_atom.cpp @@ -259,7 +259,7 @@ void ComputeSNAAtom::compute_peratom() int jtype = type[j]; int jelem = 0; if (chemflag) - int jelem = map[jtype]; + jelem = map[jtype]; if (rsq < cutsq[itype][jtype] && rsq>1e-20) { snaptr->rij[ninside][0] = delx; snaptr->rij[ninside][1] = dely; diff --git a/src/USER-CGDNA/bond_oxdna_fene.cpp b/src/USER-CGDNA/bond_oxdna_fene.cpp index be59858e66..bf44e1d5ed 100644 --- a/src/USER-CGDNA/bond_oxdna_fene.cpp +++ b/src/USER-CGDNA/bond_oxdna_fene.cpp @@ -328,29 +328,9 @@ void BondOxdnaFene::coeff(int narg, char **arg) void BondOxdnaFene::init_style() { - /* special bonds have to be lj = 0 1 1 and coul = 1 1 1 to exclude - the ss excluded volume interaction between nearest neighbors */ - - force->special_lj[1] = 0.0; - force->special_lj[2] = 1.0; - force->special_lj[3] = 1.0; - force->special_coul[1] = 1.0; - force->special_coul[2] = 1.0; - force->special_coul[3] = 1.0; - - fprintf(screen,"Finding 1-2 1-3 1-4 neighbors ...\n" - " Special bond factors lj: %-10g %-10g %-10g\n" - " Special bond factors coul: %-10g %-10g %-10g\n", - force->special_lj[1],force->special_lj[2],force->special_lj[3], - force->special_coul[1],force->special_coul[2],force->special_coul[3]); - if (force->special_lj[1] != 0.0 || force->special_lj[2] != 1.0 || force->special_lj[3] != 1.0 || force->special_coul[1] != 1.0 || force->special_coul[2] != 1.0 || force->special_coul[3] != 1.0) - { - if (comm->me == 0) - error->warning(FLERR,"Use special bonds lj = 0,1,1 and coul = 1,1,1 with bond style oxdna/fene"); - } - + error->all(FLERR,"Must use 'special_bonds lj 0 1 1 coul 1 1 1' with bond style oxdna/fene"); } /* ---------------------------------------------------------------------- */ diff --git a/src/USER-COLVARS/ndx_group.cpp b/src/USER-COLVARS/ndx_group.cpp index 3756208212..feab2f22b2 100644 --- a/src/USER-COLVARS/ndx_group.cpp +++ b/src/USER-COLVARS/ndx_group.cpp @@ -226,12 +226,7 @@ void Ndx2Group::create(char *name, bigint num, tagint *tags) { // wipe out all members if the group exists. gid==0 is group "all" int gid = group->find(name); - if (gid > 0) { - char *cmd[2]; - cmd[0] = name; - cmd[1] = (char *)"clear"; - group->assign(2,cmd); - } + if (gid > 0) group->assign(std::string(name) + " clear"); // map from global to local const int nlocal = atom->nlocal; diff --git a/src/USER-INTEL/pair_eam_alloy_intel.cpp b/src/USER-INTEL/pair_eam_alloy_intel.cpp index 16a55e4b2b..15c6a985ce 100644 --- a/src/USER-INTEL/pair_eam_alloy_intel.cpp +++ b/src/USER-INTEL/pair_eam_alloy_intel.cpp @@ -119,8 +119,13 @@ void PairEAMAlloyIntel::read_file(char *filename) // read potential file if(comm->me == 0) { - PotentialFileReader reader(lmp, filename, "EAM"); + PotentialFileReader reader(lmp, filename, "EAMAlloy", unit_convert_flag); + // transparently convert units for supported conversions + + int unit_convert = reader.get_unit_convert(); + double conversion_factor = utils::get_conversion_factor(utils::ENERGY, + unit_convert); try { reader.skip_line(); reader.skip_line(); @@ -165,11 +170,19 @@ void PairEAMAlloyIntel::read_file(char *filename) reader.next_dvector(&file->frho[i][1], file->nrho); reader.next_dvector(&file->rhor[i][1], file->nr); + if (unit_convert) { + for (int j = 1; j < file->nrho; ++j) + file->frho[i][j] *= conversion_factor; + } } for (int i = 0; i < file->nelements; i++) { for (int j = 0; j <= i; j++) { reader.next_dvector(&file->z2r[i][j][1], file->nr); + if (unit_convert) { + for (int k = 1; k < file->nr; ++k) + file->z2r[i][j][k] *= conversion_factor; + } } } } catch (TokenizerException & e) { diff --git a/src/USER-INTEL/pair_eam_fs_intel.cpp b/src/USER-INTEL/pair_eam_fs_intel.cpp index e68d5687cf..f0306f7426 100644 --- a/src/USER-INTEL/pair_eam_fs_intel.cpp +++ b/src/USER-INTEL/pair_eam_fs_intel.cpp @@ -119,8 +119,13 @@ void PairEAMFSIntel::read_file(char *filename) // read potential file if(comm->me == 0) { - PotentialFileReader reader(lmp, filename, "EAM"); + PotentialFileReader reader(lmp, filename, "EAMFS", unit_convert_flag); + // transparently convert units for supported conversions + + int unit_convert = reader.get_unit_convert(); + double conversion_factor = utils::get_conversion_factor(utils::ENERGY, + unit_convert); try { reader.skip_line(); reader.skip_line(); @@ -164,6 +169,10 @@ void PairEAMFSIntel::read_file(char *filename) file->mass[i] = values.next_double(); reader.next_dvector(&file->frho[i][1], file->nrho); + if (unit_convert) { + for (int j = 1; j <= file->nrho; ++j) + file->frho[i][j] *= conversion_factor; + } for (int j = 0; j < file->nelements; j++) { reader.next_dvector(&file->rhor[i][j][1], file->nr); @@ -173,6 +182,10 @@ void PairEAMFSIntel::read_file(char *filename) for (int i = 0; i < file->nelements; i++) { for (int j = 0; j <= i; j++) { reader.next_dvector(&file->z2r[i][j][1], file->nr); + if (unit_convert) { + for (int k = 1; k <= file->nr; ++k) + file->z2r[i][j][k] *= conversion_factor; + } } } } catch (TokenizerException & e) { diff --git a/src/USER-MISC/pair_tersoff_table.cpp b/src/USER-MISC/pair_tersoff_table.cpp index 8ab64b1d5a..590a32c2c6 100644 --- a/src/USER-MISC/pair_tersoff_table.cpp +++ b/src/USER-MISC/pair_tersoff_table.cpp @@ -33,6 +33,8 @@ #include "comm.h" #include "memory.h" #include "utils.h" +#include "tokenizer.h" +#include "potential_file_reader.h" #include "error.h" @@ -59,6 +61,7 @@ PairTersoffTable::PairTersoffTable(LAMMPS *lmp) : Pair(lmp) restartinfo = 0; one_coeff = 1; manybody_flag = 1; + unit_convert_flag = utils::get_supported_conversions(utils::ENERGY); nelements = 0; elements = nullptr; @@ -840,146 +843,115 @@ double PairTersoffTable::init_one(int i, int j) void PairTersoffTable::read_file(char *file) { - int params_per_line = 17; - char **words = new char*[params_per_line+1]; - memory->sfree(params); - params = NULL; + params = nullptr; nparams = maxparam = 0; // open file on proc 0 - FILE *fp; if (comm->me == 0) { - fp = force->open_potential(file); - if (fp == NULL) { - char str[128]; - snprintf(str,128,"Cannot open Tersoff potential file %s",file); - error->one(FLERR,str); - } - } + PotentialFileReader reader(lmp, file, "TersoffTable", unit_convert_flag); + char *line; - // read each set of params from potential file - // one set of params can span multiple lines - // store params if all 3 element tags are in element list + // transparently convert units for supported conversions - int n,nwords,ielement,jelement,kelement; - char line[MAXLINE],*ptr; - int eof = 0; + int unit_convert = reader.get_unit_convert(); + double conversion_factor = utils::get_conversion_factor(utils::ENERGY, + unit_convert); - while (1) { - if (comm->me == 0) { - ptr = fgets(line,MAXLINE,fp); - if (ptr == NULL) { - eof = 1; - fclose(fp); - } else n = strlen(line) + 1; - } - MPI_Bcast(&eof,1,MPI_INT,0,world); - if (eof) break; - MPI_Bcast(&n,1,MPI_INT,0,world); - MPI_Bcast(line,n,MPI_CHAR,0,world); + while((line = reader.next_line(NPARAMS_PER_LINE))) { - // strip comment, skip line if blank + try { + ValueTokenizer values(line); - if ((ptr = strchr(line,'#'))) *ptr = '\0'; - nwords = utils::count_words(line); - if (nwords == 0) continue; + std::string iname = values.next_string(); + std::string jname = values.next_string(); + std::string kname = values.next_string(); - // concatenate additional lines until have params_per_line words + // ielement,jelement,kelement = 1st args + // if all 3 args are in element list, then parse this line + // else skip to next entry in file - while (nwords < params_per_line) { - n = strlen(line); - if (comm->me == 0) { - ptr = fgets(&line[n],MAXLINE-n,fp); - if (ptr == NULL) { - eof = 1; - fclose(fp); - } else n = strlen(line) + 1; + int ielement, jelement, kelement; + + for (ielement = 0; ielement < nelements; ielement++) + if (iname == elements[ielement]) break; + if (ielement == nelements) continue; + for (jelement = 0; jelement < nelements; jelement++) + if (jname == elements[jelement]) break; + if (jelement == nelements) continue; + for (kelement = 0; kelement < nelements; kelement++) + if (kname == elements[kelement]) break; + if (kelement == nelements) continue; + + // load up parameter settings and error check their values + + if (nparams == maxparam) { + maxparam += DELTA; + params = (Param *) memory->srealloc(params,maxparam*sizeof(Param), + "pair:params"); + } + + // some parameters are not used since only Tersoff_2 is implemented + + params[nparams].ielement = ielement; + params[nparams].jelement = jelement; + params[nparams].kelement = kelement; + params[nparams].powerm = values.next_double(); // not used + params[nparams].gamma = values.next_double(); // not used + params[nparams].lam3 = values.next_double(); // not used + params[nparams].c = values.next_double(); + params[nparams].d = values.next_double(); + params[nparams].h = values.next_double(); + params[nparams].powern = values.next_double(); + params[nparams].beta = values.next_double(); + params[nparams].lam2 = values.next_double(); + params[nparams].bigb = values.next_double(); + double bigr = values.next_double(); + double bigd = values.next_double(); + params[nparams].cutoffR = bigr - bigd; + params[nparams].cutoffS = bigr + bigd; + params[nparams].lam1 = values.next_double(); + params[nparams].biga = values.next_double(); + + if (unit_convert) { + params[nparams].biga *= conversion_factor; + params[nparams].bigb *= conversion_factor; + } + } catch (TokenizerException & e) { + error->one(FLERR, e.what()); } - MPI_Bcast(&eof,1,MPI_INT,0,world); - if (eof) break; - MPI_Bcast(&n,1,MPI_INT,0,world); - MPI_Bcast(line,n,MPI_CHAR,0,world); - if ((ptr = strchr(line,'#'))) *ptr = '\0'; - nwords = utils::count_words(line); + + if (params[nparams].c < 0.0 || + params[nparams].d < 0.0 || + params[nparams].powern < 0.0 || + params[nparams].beta < 0.0 || + params[nparams].lam2 < 0.0 || + params[nparams].bigb < 0.0 || + params[nparams].cutoffR < 0.0 || + params[nparams].cutoffS < 0.0 || + params[nparams].cutoffR > params[nparams].cutoffS || + params[nparams].lam1 < 0.0 || + params[nparams].biga < 0.0 + ) error->one(FLERR,"Illegal Tersoff parameter"); + + // only tersoff_2 parametrization is implemented + + if (params[nparams].gamma != 1.0 || params[nparams].lam3 != 0.0) + error->one(FLERR,"Currently the tersoff/table pair_style only " + "implements the Tersoff_2 parametrization"); + nparams++; } - - if (nwords != params_per_line) - error->all(FLERR,"Incorrect format in Tersoff potential file"); - - // words = ptrs to all words in line - - nwords = 0; - words[nwords++] = strtok(line," \t\n\r\f"); - while ((words[nwords++] = strtok(NULL," \t\n\r\f"))) continue; - - // ielement,jelement,kelement = 1st args - // if all 3 args are in element list, then parse this line - // else skip to next entry in file - - for (ielement = 0; ielement < nelements; ielement++) - if (strcmp(words[0],elements[ielement]) == 0) break; - if (ielement == nelements) continue; - for (jelement = 0; jelement < nelements; jelement++) - if (strcmp(words[1],elements[jelement]) == 0) break; - if (jelement == nelements) continue; - for (kelement = 0; kelement < nelements; kelement++) - if (strcmp(words[2],elements[kelement]) == 0) break; - if (kelement == nelements) continue; - - // load up parameter settings and error check their values - - if (nparams == maxparam) { - maxparam += DELTA; - params = (Param *) memory->srealloc(params,maxparam*sizeof(Param), - "pair:params"); - } - - params[nparams].ielement = ielement; - params[nparams].jelement = jelement; - params[nparams].kelement = kelement; - params[nparams].powerm = atof(words[3]); // not used (only tersoff_2 is implemented) - params[nparams].gamma = atof(words[4]); // not used (only tersoff_2 is implemented) - params[nparams].lam3 = atof(words[5]); // not used (only tersoff_2 is implemented) - params[nparams].c = atof(words[6]); - params[nparams].d = atof(words[7]); - params[nparams].h = atof(words[8]); - params[nparams].powern = atof(words[9]); - params[nparams].beta = atof(words[10]); - params[nparams].lam2 = atof(words[11]); - params[nparams].bigb = atof(words[12]); - - // current implementation is based on functional form - // of tersoff_2 as reported in the reference paper - - double bigr = atof(words[13]); - double bigd = atof(words[14]); - params[nparams].cutoffR = bigr - bigd; - params[nparams].cutoffS = bigr + bigd; - params[nparams].lam1 = atof(words[15]); - params[nparams].biga = atof(words[16]); - - if (params[nparams].c < 0.0 || - params[nparams].d < 0.0 || - params[nparams].powern < 0.0 || - params[nparams].beta < 0.0 || - params[nparams].lam2 < 0.0 || - params[nparams].bigb < 0.0 || - params[nparams].cutoffR < 0.0 || - params[nparams].cutoffS < 0.0 || - params[nparams].cutoffR > params[nparams].cutoffS || - params[nparams].lam1 < 0.0 || - params[nparams].biga < 0.0 - ) error->all(FLERR,"Illegal Tersoff parameter"); - - // only tersoff_2 parametrization is implemented - if (params[nparams].gamma != 1.0 || params[nparams].lam3 != 0.0) - error->all(FLERR,"Current tersoff/table pair_style implements only tersoff_2 parametrization"); - nparams++; } - delete [] words; + MPI_Bcast(&nparams, 1, MPI_INT, 0, world); + MPI_Bcast(&maxparam, 1, MPI_INT, 0, world); + + if(comm->me != 0) { + params = (Param *) memory->srealloc(params,maxparam*sizeof(Param), "pair:params"); + } + + MPI_Bcast(params, maxparam*sizeof(Param), MPI_BYTE, 0, world); } /* ---------------------------------------------------------------------- */ diff --git a/src/USER-MISC/pair_tersoff_table.h b/src/USER-MISC/pair_tersoff_table.h index cd5549c345..faa704191c 100644 --- a/src/USER-MISC/pair_tersoff_table.h +++ b/src/USER-MISC/pair_tersoff_table.h @@ -40,8 +40,10 @@ class PairTersoffTable : public Pair { virtual void compute(int, int); void settings(int, char **); void coeff(int, char **); - double init_one(int, int); void init_style(); + double init_one(int, int); + + static const int NPARAMS_PER_LINE = 17; protected: struct Param { diff --git a/src/USER-OMP/pair_eam_alloy_omp.cpp b/src/USER-OMP/pair_eam_alloy_omp.cpp index e8f56a9700..552bab14cd 100644 --- a/src/USER-OMP/pair_eam_alloy_omp.cpp +++ b/src/USER-OMP/pair_eam_alloy_omp.cpp @@ -119,8 +119,14 @@ void PairEAMAlloyOMP::read_file(char *filename) // read potential file if(comm->me == 0) { - PotentialFileReader reader(PairEAM::lmp, filename, "EAM"); + PotentialFileReader reader(PairEAM::lmp, filename, + "EAMAlloy", unit_convert_flag); + // transparently convert units for supported conversions + + int unit_convert = reader.get_unit_convert(); + double conversion_factor = utils::get_conversion_factor(utils::ENERGY, + unit_convert); try { reader.skip_line(); reader.skip_line(); @@ -165,11 +171,19 @@ void PairEAMAlloyOMP::read_file(char *filename) reader.next_dvector(&file->frho[i][1], file->nrho); reader.next_dvector(&file->rhor[i][1], file->nr); + if (unit_convert) { + for (int j = 1; j < file->nrho; ++j) + file->frho[i][j] *= conversion_factor; + } } for (int i = 0; i < file->nelements; i++) { for (int j = 0; j <= i; j++) { reader.next_dvector(&file->z2r[i][j][1], file->nr); + if (unit_convert) { + for (int k = 1; k < file->nr; ++k) + file->z2r[i][j][k] *= conversion_factor; + } } } } catch (TokenizerException & e) { diff --git a/src/USER-OMP/pair_eam_fs_omp.cpp b/src/USER-OMP/pair_eam_fs_omp.cpp index c68d5f6019..5e9c76fa86 100644 --- a/src/USER-OMP/pair_eam_fs_omp.cpp +++ b/src/USER-OMP/pair_eam_fs_omp.cpp @@ -119,8 +119,14 @@ void PairEAMFSOMP::read_file(char *filename) // read potential file if(comm->me == 0) { - PotentialFileReader reader(PairEAM::lmp, filename, "EAM"); + PotentialFileReader reader(PairEAM::lmp, filename, + "EAMFS", unit_convert_flag); + // transparently convert units for supported conversions + + int unit_convert = reader.get_unit_convert(); + double conversion_factor = utils::get_conversion_factor(utils::ENERGY, + unit_convert); try { reader.skip_line(); reader.skip_line(); @@ -164,6 +170,10 @@ void PairEAMFSOMP::read_file(char *filename) file->mass[i] = values.next_double(); reader.next_dvector(&file->frho[i][1], file->nrho); + if (unit_convert) { + for (int j = 1; j <= file->nrho; ++j) + file->frho[i][j] *= conversion_factor; + } for (int j = 0; j < file->nelements; j++) { reader.next_dvector(&file->rhor[i][j][1], file->nr); @@ -173,6 +183,10 @@ void PairEAMFSOMP::read_file(char *filename) for (int i = 0; i < file->nelements; i++) { for (int j = 0; j <= i; j++) { reader.next_dvector(&file->z2r[i][j][1], file->nr); + if (unit_convert) { + for (int k = 1; k <= file->nr; ++k) + file->z2r[i][j][k] *= conversion_factor; + } } } } catch (TokenizerException & e) { diff --git a/src/USER-OMP/pair_tersoff_zbl_omp.cpp b/src/USER-OMP/pair_tersoff_zbl_omp.cpp index 6a9232f888..fa6e84c71b 100644 --- a/src/USER-OMP/pair_tersoff_zbl_omp.cpp +++ b/src/USER-OMP/pair_tersoff_zbl_omp.cpp @@ -92,9 +92,16 @@ void PairTersoffZBLOMP::read_file(char *file) // open file on proc 0 if (comm->me == 0) { - PotentialFileReader reader(PairTersoff::lmp, file, "Tersoff"); + PotentialFileReader reader(PairTersoff::lmp, file, "TersoffZBLOMP", + unit_convert_flag); char * line; + // transparently convert units for supported conversions + + int unit_convert = reader.get_unit_convert(); + double conversion_factor = utils::get_conversion_factor(utils::ENERGY, + unit_convert); + while((line = reader.next_line(NPARAMS_PER_LINE))) { try { ValueTokenizer values(line); @@ -118,7 +125,6 @@ void PairTersoffZBLOMP::read_file(char *file) if (kname == elements[kelement]) break; if (kelement == nelements) continue; - // load up parameter settings and error check their values if (nparams == maxparam) { @@ -149,6 +155,11 @@ void PairTersoffZBLOMP::read_file(char *file) params[nparams].ZBLcut = values.next_double(); params[nparams].ZBLexpscale = values.next_double(); params[nparams].powermint = int(params[nparams].powerm); + + if (unit_convert) { + params[nparams].biga *= conversion_factor; + params[nparams].bigb *= conversion_factor; + } } catch (TokenizerException & e) { error->one(FLERR, e.what()); } diff --git a/src/USER-REACTION/fix_bond_react.cpp b/src/USER-REACTION/fix_bond_react.cpp index 6ba5d1ce49..2c6c20c844 100644 --- a/src/USER-REACTION/fix_bond_react.cpp +++ b/src/USER-REACTION/fix_bond_react.cpp @@ -19,6 +19,7 @@ Contributing Author: Jacob Gissinger (jacob.gissinger@colorado.edu) #include #include #include +#include #include "update.h" #include "modify.h" #include "respa.h" @@ -41,6 +42,7 @@ Contributing Author: Jacob Gissinger (jacob.gissinger@colorado.edu) #include "error.h" #include "input.h" #include "variable.h" +#include "fmt/format.h" #include @@ -575,17 +577,11 @@ FixBondReact::~FixBondReact() delete [] set; if (group) { - char **newarg; - newarg = new char*[2]; - newarg[0] = master_group; - newarg[1] = (char *) "delete"; - group->assign(2,newarg); + group->assign(std::string(master_group) + " delete"); if (stabilization_flag == 1) { - newarg[0] = exclude_group; - group->assign(2,newarg); + group->assign(std::string(exclude_group) + " delete"); delete [] exclude_group; } - delete [] newarg; } } @@ -608,59 +604,38 @@ it will have the name 'i_limit_tags' and will be intitialized to 0 (not in group void FixBondReact::post_constructor() { + int len; // let's add the limit_tags per-atom property fix - int len = strlen("bond_react_props_internal") + 1; - id_fix2 = new char[len]; - strcpy(id_fix2,"bond_react_props_internal"); + std::string cmd = std::string("bond_react_props_internal"); + id_fix2 = new char[cmd.size()+1]; + strcpy(id_fix2,cmd.c_str()); int ifix = modify->find_fix(id_fix2); if (ifix == -1) { - char **newarg = new char*[7]; - newarg[0] = (char *) "bond_react_props_internal"; - newarg[1] = (char *) "all"; // group ID is ignored - newarg[2] = (char *) "property/atom"; - newarg[3] = (char *) "i_limit_tags"; - newarg[4] = (char *) "i_react_tags"; - newarg[5] = (char *) "ghost"; - newarg[6] = (char *) "yes"; - modify->add_fix(7,newarg); - delete [] newarg; + cmd += std::string(" all property/atom i_limit_tags i_react_tags ghost yes"); + modify->add_fix(cmd); } // create master_group if not already existing // NOTE: limit_tags and react_tags automaticaly intitialized to zero (unless read from restart) group->find_or_create(master_group); - char **newarg; - newarg = new char*[5]; - newarg[0] = master_group; - newarg[1] = (char *) "dynamic"; - newarg[2] = (char *) "all"; - newarg[3] = (char *) "property"; - newarg[4] = (char *) "limit_tags"; - group->assign(5,newarg); - delete [] newarg; + cmd = fmt::format("{} dynamic all property limit_tags",master_group); + group->assign(cmd); if (stabilization_flag == 1) { int igroup = group->find(exclude_group); // create exclude_group if not already existing, or use as parent group if static if (igroup == -1 || group->dynamic[igroup] == 0) { // create stabilization per-atom property - len = strlen("bond_react_stabilization_internal") + 1; - id_fix3 = new char[len]; - strcpy(id_fix3,"bond_react_stabilization_internal"); + cmd = std::string("bond_react_stabilization_internal"); + id_fix3 = new char[cmd.size()+1]; + strcpy(id_fix3,cmd.c_str()); ifix = modify->find_fix(id_fix3); if (ifix == -1) { - char **newarg = new char*[6]; - newarg[0] = (char *) id_fix3; - newarg[1] = (char *) "all"; // group ID is ignored - newarg[2] = (char *) "property/atom"; - newarg[3] = (char *) "i_statted_tags"; - newarg[4] = (char *) "ghost"; - newarg[5] = (char *) "yes"; - modify->add_fix(6,newarg); + cmd += std::string(" all property/atom i_statted_tags ghost yes"); + modify->add_fix(cmd); fix3 = modify->fix[modify->nfix-1]; - delete [] newarg; } len = strlen("statted_tags") + 1; @@ -680,16 +655,11 @@ void FixBondReact::post_constructor() strcat(exclude_group,"_REACT"); group->find_or_create(exclude_group); - char **newarg; - newarg = new char*[5]; - newarg[0] = exclude_group; - newarg[1] = (char *) "dynamic"; - if (igroup == -1) newarg[2] = (char *) "all"; - else newarg[2] = (char *) exclude_PARENT_group; - newarg[3] = (char *) "property"; - newarg[4] = (char *) "statted_tags"; - group->assign(5,newarg); - delete [] newarg; + if (igroup == -1) + cmd = fmt::format("{} dynamic all property statted_tags",exclude_group); + else + cmd = fmt::format("{} dynamic {} property statted_tags",exclude_group,exclude_PARENT_group); + group->assign(cmd); delete [] exclude_PARENT_group; // on to statted_tags (system-wide thermostat) @@ -737,21 +707,16 @@ void FixBondReact::post_constructor() // let's create a new nve/limit fix to limit newly reacted atoms - len = strlen("bond_react_MASTER_nve_limit") + 1; - id_fix1 = new char[len]; - strcpy(id_fix1,"bond_react_MASTER_nve_limit"); + cmd = std::string("bond_react_MASTER_nve_limit"); + id_fix1 = new char[cmd.size()+1]; + strcpy(id_fix1,cmd.c_str()); ifix = modify->find_fix(id_fix1); if (ifix == -1) { - char **newarg = new char*[4]; - newarg[0] = id_fix1; - newarg[1] = master_group; - newarg[2] = (char *) "nve/limit"; - newarg[3] = nve_limit_xmax; - modify->add_fix(4,newarg); + cmd += fmt::format(" {} nve/limit {}",master_group,nve_limit_xmax); + modify->add_fix(cmd); fix1 = modify->fix[modify->nfix-1]; - delete [] newarg; } } } diff --git a/src/atom_vec_hybrid.cpp b/src/atom_vec_hybrid.cpp index 9ba2b6f468..4149a362e6 100644 --- a/src/atom_vec_hybrid.cpp +++ b/src/atom_vec_hybrid.cpp @@ -18,6 +18,7 @@ #include "memory.h" #include "error.h" #include "tokenizer.h" +#include "fmt/format.h" using namespace LAMMPS_NS; @@ -56,8 +57,6 @@ AtomVecHybrid::~AtomVecHybrid() delete [] styles; for (int k = 0; k < nstyles; k++) delete [] keywords[k]; delete [] keywords; - - for (int k = 0; k < nstyles_bonus; k++) delete styles_bonus[k]; delete [] styles_bonus; if (!fields_allocated) return; @@ -215,18 +214,16 @@ void AtomVecHybrid::process_args(int narg, char **arg) for (int idup = 0; idup < ndupfield; idup++) { char *dup = (char *) dupfield[idup]; ptr = strstr(concat_grow,dup); - if (ptr && strstr(ptr+1,dup)) { - char str[128]; - sprintf(str,"Peratom %s is in multiple sub-styles - " - "must be used consistently",dup); - if (comm->me == 0) error->warning(FLERR,str); - } + if ((ptr && strstr(ptr+1,dup)) && (comm->me == 0)) + error->warning(FLERR,fmt::format("Peratom {} is in multiple sub-styles " + "- must be used consistently",dup)); } delete [] concat_grow; // set bonus_flag if any substyle has bonus data // set nstyles_bonus & styles_bonus + // sum two sizes over contributions from each substyle with bonus data. nstyles_bonus = 0; for (int k = 0; k < nstyles; k++) @@ -236,9 +233,14 @@ void AtomVecHybrid::process_args(int narg, char **arg) bonus_flag = 1; styles_bonus = new AtomVec*[nstyles_bonus]; nstyles_bonus = 0; + size_forward_bonus = 0; + size_border_bonus = 0; for (int k = 0; k < nstyles; k++) { - if (styles[k]->bonus_flag) + if (styles[k]->bonus_flag) { styles_bonus[nstyles_bonus++] = styles[k]; + size_forward_bonus += styles[k]->size_forward_bonus; + size_border_bonus += styles[k]->size_border_bonus; + } } } diff --git a/src/balance.cpp b/src/balance.cpp index 1df2116b72..9731a66f51 100644 --- a/src/balance.cpp +++ b/src/balance.cpp @@ -489,32 +489,21 @@ void Balance::options(int iarg, int narg, char **arg) void Balance::weight_storage(char *prefix) { - char *fixargs[6]; + std::string cmd = ""; - if (prefix) { - int n = strlen(prefix) + 32; - fixargs[0] = new char[n]; - strcpy(fixargs[0],prefix); - strcat(fixargs[0],"IMBALANCE_WEIGHTS"); - } else fixargs[0] = (char *) "IMBALANCE_WEIGHTS"; + if (prefix) cmd = prefix; + cmd += "IMBALANCE_WEIGHTS"; - fixargs[1] = (char *) "all"; - fixargs[2] = (char *) "STORE"; - fixargs[3] = (char *) "peratom"; - fixargs[4] = (char *) "0"; - fixargs[5] = (char *) "1"; - - int ifix = modify->find_fix(fixargs[0]); + int ifix = modify->find_fix(cmd); if (ifix < 1) { - modify->add_fix(6,fixargs); + cmd += " all STORE peratom 0 1"; + modify->add_fix(cmd); fixstore = (FixStore *) modify->fix[modify->nfix-1]; } else fixstore = (FixStore *) modify->fix[ifix]; // do not carry weights with atoms during normal atom migration fixstore->disable = 1; - - if (prefix) delete [] fixargs[0]; } /* ---------------------------------------------------------------------- diff --git a/src/compute_chunk_atom.cpp b/src/compute_chunk_atom.cpp index 92567101de..f7e2db69b9 100644 --- a/src/compute_chunk_atom.cpp +++ b/src/compute_chunk_atom.cpp @@ -36,6 +36,7 @@ #include "math_const.h" #include "memory.h" #include "error.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace MathConst; @@ -581,21 +582,13 @@ void ComputeChunkAtom::init() // fixstore initializes all values to 0.0 if ((idsflag == ONCE || lockcount) && !fixstore) { - int n = strlen(id) + strlen("_COMPUTE_STORE") + 1; - id_fix = new char[n]; - strcpy(id_fix,id); - strcat(id_fix,"_COMPUTE_STORE"); + std::string cmd = id + std::string("_COMPUTE_STORE"); + id_fix = new char[cmd.size()+1]; + strcpy(id_fix,cmd.c_str()); - char **newarg = new char*[6]; - newarg[0] = id_fix; - newarg[1] = group->names[igroup]; - newarg[2] = (char *) "STORE"; - newarg[3] = (char *) "peratom"; - newarg[4] = (char *) "1"; - newarg[5] = (char *) "1"; - modify->add_fix(6,newarg); + cmd += fmt::format(" {} STORE peratom 1 1", group->names[igroup]); + modify->add_fix(cmd); fixstore = (FixStore *) modify->fix[modify->nfix-1]; - delete [] newarg; } if ((idsflag != ONCE && !lockcount) && fixstore) { diff --git a/src/compute_cna_atom.cpp b/src/compute_cna_atom.cpp index 5f0f047958..7ab9e8adf2 100644 --- a/src/compute_cna_atom.cpp +++ b/src/compute_cna_atom.cpp @@ -30,6 +30,7 @@ #include "comm.h" #include "memory.h" #include "error.h" +#include "fmt/format.h" using namespace LAMMPS_NS; @@ -184,11 +185,9 @@ void ComputeCNAAtom::compute_peratom() int nerrorall; MPI_Allreduce(&nerror,&nerrorall,1,MPI_INT,MPI_SUM,world); - if (nerrorall && comm->me == 0) { - char str[128]; - sprintf(str,"Too many neighbors in CNA for %d atoms",nerrorall); - error->warning(FLERR,str,0); - } + if (nerrorall && comm->me == 0) + error->warning(FLERR,fmt::format("Too many neighbors in CNA for {} " + "atoms",nerrorall),0); // compute CNA for each atom in group // only performed if # of nearest neighbors = 12 or 14 (fcc,hcp) @@ -345,11 +344,9 @@ void ComputeCNAAtom::compute_peratom() // warning message MPI_Allreduce(&nerror,&nerrorall,1,MPI_INT,MPI_SUM,world); - if (nerrorall && comm->me == 0) { - char str[128]; - sprintf(str,"Too many common neighbors in CNA %d times",nerrorall); - error->warning(FLERR,str); - } + if (nerrorall && comm->me == 0) + error->warning(FLERR,fmt::format("Too many common neighbors in CNA {} " + "times", nerrorall)); } /* ---------------------------------------------------------------------- diff --git a/src/compute_displace_atom.cpp b/src/compute_displace_atom.cpp index 41db4db1d6..b20dd3bec3 100644 --- a/src/compute_displace_atom.cpp +++ b/src/compute_displace_atom.cpp @@ -24,6 +24,7 @@ #include "variable.h" #include "memory.h" #include "error.h" +#include "fmt/format.h" using namespace LAMMPS_NS; @@ -72,21 +73,13 @@ ComputeDisplaceAtom::ComputeDisplaceAtom(LAMMPS *lmp, int narg, char **arg) : // create a new fix STORE style // id = compute-ID + COMPUTE_STORE, fix group = compute group - int n = strlen(id) + strlen("_COMPUTE_STORE") + 1; - id_fix = new char[n]; - strcpy(id_fix,id); - strcat(id_fix,"_COMPUTE_STORE"); + std::string cmd = id + std::string("_COMPUTE_STORE"); + id_fix = new char[cmd.size()+1]; + strcpy(id_fix,cmd.c_str()); - char **newarg = new char*[6]; - newarg[0] = id_fix; - newarg[1] = group->names[igroup]; - newarg[2] = (char *) "STORE"; - newarg[3] = (char *) "peratom"; - newarg[4] = (char *) "1"; - newarg[5] = (char *) "3"; - modify->add_fix(6,newarg); + cmd += fmt::format(" {} STORE peratom 1 3", group->names[igroup]); + modify->add_fix(cmd); fix = (FixStore *) modify->fix[modify->nfix-1]; - delete [] newarg; // calculate xu,yu,zu for fix store array // skip if reset from restart file diff --git a/src/compute_group_group.cpp b/src/compute_group_group.cpp index c64db19fc1..c8876daeef 100644 --- a/src/compute_group_group.cpp +++ b/src/compute_group_group.cpp @@ -147,12 +147,9 @@ void ComputeGroupGroup::init() if (kspaceflag) { kspace_correction(); - if (fabs(e_correction) > SMALL && comm->me == 0) { - char str[128]; - sprintf(str,"Both groups in compute group/group have a net charge; " - "the Kspace boundary correction to energy will be non-zero"); - error->warning(FLERR,str); - } + if ((fabs(e_correction) > SMALL) && (comm->me == 0)) + error->warning(FLERR,"Both groups in compute group/group have a net charge; " + "the Kspace boundary correction to energy will be non-zero"); } // recheck that group 2 has not been deleted diff --git a/src/compute_msd.cpp b/src/compute_msd.cpp index b15bb8e875..930f979bf0 100644 --- a/src/compute_msd.cpp +++ b/src/compute_msd.cpp @@ -14,6 +14,7 @@ #include "compute_msd.h" #include #include +#include #include "atom.h" #include "update.h" #include "group.h" @@ -21,6 +22,7 @@ #include "modify.h" #include "fix_store.h" #include "error.h" +#include "fmt/format.h" using namespace LAMMPS_NS; @@ -63,21 +65,13 @@ ComputeMSD::ComputeMSD(LAMMPS *lmp, int narg, char **arg) : // create a new fix STORE style for reference positions // id = compute-ID + COMPUTE_STORE, fix group = compute group - int n = strlen(id) + strlen("_COMPUTE_STORE") + 1; - id_fix = new char[n]; - strcpy(id_fix,id); - strcat(id_fix,"_COMPUTE_STORE"); + std::string fixcmd = id + std::string("_COMPUTE_STORE"); + id_fix = new char[fixcmd.size()+1]; + strcpy(id_fix,fixcmd.c_str()); - char **newarg = new char*[6]; - newarg[0] = id_fix; - newarg[1] = group->names[igroup]; - newarg[2] = (char *) "STORE"; - newarg[3] = (char *) "peratom"; - newarg[4] = (char *) "1"; - newarg[5] = (char *) "3"; - modify->add_fix(6,newarg); + fixcmd += fmt::format(" {} STORE peratom 1 3",group->names[igroup]); + modify->add_fix(fixcmd); fix = (FixStore *) modify->fix[modify->nfix-1]; - delete [] newarg; // calculate xu,yu,zu for fix store array // skip if reset from restart file diff --git a/src/compute_msd_chunk.cpp b/src/compute_msd_chunk.cpp index 8039a4fcd5..dda921ef42 100644 --- a/src/compute_msd_chunk.cpp +++ b/src/compute_msd_chunk.cpp @@ -14,6 +14,7 @@ #include "compute_msd_chunk.h" #include #include +#include #include "atom.h" #include "group.h" #include "update.h" @@ -23,6 +24,7 @@ #include "fix_store.h" #include "memory.h" #include "error.h" +#include "fmt/format.h" using namespace LAMMPS_NS; @@ -56,21 +58,13 @@ ComputeMSDChunk::ComputeMSDChunk(LAMMPS *lmp, int narg, char **arg) : // potentially re-populate the fix array (and change it to correct size) // otherwise size reset and init will be done in setup() - n = strlen(id) + strlen("_COMPUTE_STORE") + 1; - id_fix = new char[n]; - strcpy(id_fix,id); - strcat(id_fix,"_COMPUTE_STORE"); + std::string fixcmd = id + std::string("_COMPUTE_STORE"); + id_fix = new char[fixcmd.size()+1]; + strcpy(id_fix,fixcmd.c_str()); - char **newarg = new char*[6]; - newarg[0] = id_fix; - newarg[1] = group->names[igroup]; - newarg[2] = (char *) "STORE"; - newarg[3] = (char *) "global"; - newarg[4] = (char *) "1"; - newarg[5] = (char *) "1"; - modify->add_fix(6,newarg); + fixcmd += fmt::format(" {} STORE global 1 1",group->names[igroup]); + modify->add_fix(fixcmd); fix = (FixStore *) modify->fix[modify->nfix-1]; - delete [] newarg; } /* ---------------------------------------------------------------------- */ diff --git a/src/compute_orientorder_atom.cpp b/src/compute_orientorder_atom.cpp index 979935b12e..34d11f9ac1 100644 --- a/src/compute_orientorder_atom.cpp +++ b/src/compute_orientorder_atom.cpp @@ -32,6 +32,7 @@ #include "memory.h" #include "error.h" #include "math_const.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace MathConst; @@ -715,11 +716,8 @@ void ComputeOrientOrderAtom::init_clebsch_gordan() double ComputeOrientOrderAtom::factorial(int n) { - if (n < 0 || n > nmaxfactorial) { - char str[128]; - sprintf(str, "Invalid argument to factorial %d", n); - error->all(FLERR, str); - } + if (n < 0 || n > nmaxfactorial) + error->all(FLERR,fmt::format("Invalid argument to factorial {}", n)); return nfac_table[n]; } diff --git a/src/compute_vacf.cpp b/src/compute_vacf.cpp index 5123e3aab4..ec19137a0e 100644 --- a/src/compute_vacf.cpp +++ b/src/compute_vacf.cpp @@ -14,12 +14,14 @@ #include "compute_vacf.h" #include #include +#include #include "atom.h" #include "update.h" #include "group.h" #include "modify.h" #include "fix_store.h" #include "error.h" +#include "fmt/format.h" using namespace LAMMPS_NS; @@ -39,21 +41,12 @@ ComputeVACF::ComputeVACF(LAMMPS *lmp, int narg, char **arg) : // create a new fix STORE style // id = compute-ID + COMPUTE_STORE, fix group = compute group - int n = strlen(id) + strlen("_COMPUTE_STORE") + 1; - id_fix = new char[n]; - strcpy(id_fix,id); - strcat(id_fix,"_COMPUTE_STORE"); - - char **newarg = new char*[6]; - newarg[0] = id_fix; - newarg[1] = group->names[igroup]; - newarg[2] = (char *) "STORE"; - newarg[3] = (char *) "peratom"; - newarg[4] = (char *) "1"; - newarg[5] = (char *) "3"; - modify->add_fix(6,newarg); + std::string fixcmd = id + std::string("_COMPUTE_STORE"); + id_fix = new char[fixcmd.size()+1]; + strcpy(id_fix,fixcmd.c_str()); + fixcmd += fmt::format(" {} STORE peratom 1 3", group->names[igroup]); + modify->add_fix(fixcmd); fix = (FixStore *) modify->fix[modify->nfix-1]; - delete [] newarg; // store current velocities in fix store array // skip if reset from restart file diff --git a/src/domain.cpp b/src/domain.cpp index 2d6d52c369..ad1e5896b8 100644 --- a/src/domain.cpp +++ b/src/domain.cpp @@ -1939,12 +1939,13 @@ void Domain::print_box(const std::string &prefix) if (comm->me == 0) { std::string mesg = prefix; if (triclinic == 0) { - mesg += fmt::format("orthogonal box = ({} {} {}) to ({} {} {})\n", - boxlo[0],boxlo[1],boxlo[2], - boxhi[0],boxhi[1],boxhi[2]); + mesg += fmt::format("orthogonal box = ({:.8g} {:.8g} {:.8g}) to " + "({:.8g} {:.8g} {:.8g})\n",boxlo[0],boxlo[1], + boxlo[2],boxhi[0],boxhi[1],boxhi[2]); } else { - mesg += fmt::format("triclinic box = ({} {} {}) to ({} {} {}) " - "with tilt ({} {} {})\n",boxlo[0],boxlo[1], + mesg += fmt::format("triclinic box = ({:.8g} {:.8g} {:.8g}) to " + "({:.8g} {:.8g} {:.8g}) with tilt " + "({:.8g} {:.8g} {:.8g})\n",boxlo[0],boxlo[1], boxlo[2],boxhi[0],boxhi[1],boxhi[2],xy,xz,yz); } utils::logmesg(lmp,mesg); diff --git a/src/dump_cfg.cpp b/src/dump_cfg.cpp index 3430720b8c..da9740d9ca 100644 --- a/src/dump_cfg.cpp +++ b/src/dump_cfg.cpp @@ -126,9 +126,7 @@ void DumpCFG::write_header(bigint n) if (atom->peri_flag) scale = atom->pdscale; else if (unwrapflag == 1) scale = UNWRAPEXPAND; - char str[64]; - sprintf(str,"Number of particles = %s\n",BIGINT_FORMAT); - fprintf(fp,str,n); + fprintf(fp,"Number of particles = " BIGINT_FORMAT "\n", n); fprintf(fp,"A = %g Angstrom (basic length-scale)\n",scale); fprintf(fp,"H0(1,1) = %g A\n",domain->xprd); fprintf(fp,"H0(1,2) = 0 A \n"); diff --git a/src/dump_custom.cpp b/src/dump_custom.cpp index 4b25896d79..e82636efac 100644 --- a/src/dump_custom.cpp +++ b/src/dump_custom.cpp @@ -14,6 +14,7 @@ #include "dump_custom.h" #include #include +#include #include "atom.h" #include "force.h" #include "domain.h" @@ -28,6 +29,7 @@ #include "error.h" #include "update.h" #include "variable.h" +#include "fmt/format.h" using namespace LAMMPS_NS; @@ -1981,22 +1983,12 @@ int DumpCustom::modify_param(int narg, char **arg) "dump:thresh_fixID"); memory->grow(thresh_first,(nthreshlast+1),"dump:thresh_first"); - int n = strlen(id) + strlen("_DUMP_STORE") + 8; - thresh_fixID[nthreshlast] = new char[n]; - strcpy(thresh_fixID[nthreshlast],id); - sprintf(&thresh_fixID[nthreshlast][strlen(id)],"%d",nthreshlast); - strcat(thresh_fixID[nthreshlast],"_DUMP_STORE"); - - char **newarg = new char*[6]; - newarg[0] = thresh_fixID[nthreshlast]; - newarg[1] = group->names[igroup]; - newarg[2] = (char *) "STORE"; - newarg[3] = (char *) "peratom"; - newarg[4] = (char *) "1"; - newarg[5] = (char *) "1"; - modify->add_fix(6,newarg); + std::string threshid = fmt::format("{}{}_DUMP_STORE",id,nthreshlast); + thresh_fixID[nthreshlast] = new char[threshid.size()+1]; + strcpy(thresh_fixID[nthreshlast],threshid.c_str()); + modify->add_fix(fmt::format("{} {} STORE peratom 1 1",threshid, + group->names[igroup])); thresh_fix[nthreshlast] = (FixStore *) modify->fix[modify->nfix-1]; - delete [] newarg; thresh_last[nthreshlast] = nthreshlast; thresh_first[nthreshlast] = 1; diff --git a/src/dump_movie.cpp b/src/dump_movie.cpp index ea67320d4a..68a77c8f63 100644 --- a/src/dump_movie.cpp +++ b/src/dump_movie.cpp @@ -20,6 +20,7 @@ #include "comm.h" #include "force.h" #include "error.h" +#include "fmt/format.h" using namespace LAMMPS_NS; @@ -58,11 +59,9 @@ void DumpMovie::openfile() fp = popen(moviecmd,"w"); #endif - if (fp == NULL) { - char str[128]; - sprintf(str,"Failed to open FFmpeg pipeline to file %s",filename); - error->one(FLERR,str); - } + if (fp == NULL) + error->one(FLERR,fmt::format("Failed to open FFmpeg pipeline to " + "file {}",filename)); } } /* ---------------------------------------------------------------------- */ diff --git a/src/finish.cpp b/src/finish.cpp index 9ab97ae410..9483e4e04f 100644 --- a/src/finish.cpp +++ b/src/finish.cpp @@ -32,6 +32,8 @@ #include "error.h" #include "timer.h" #include "universe.h" +#include "utils.h" +#include "fmt/format.h" #ifdef LMP_USER_OMP #include "modify.h" @@ -121,12 +123,9 @@ void Finish::end(int flag) if (me == 0) { int ntasks = nprocs * nthreads; - const char fmt1[] = "Loop time of %g on %d procs " - "for %d steps with " BIGINT_FORMAT " atoms\n\n"; - if (screen) fprintf(screen,fmt1,time_loop,ntasks,update->nsteps, - atom->natoms); - if (logfile) fprintf(logfile,fmt1,time_loop,ntasks,update->nsteps, - atom->natoms); + utils::logmesg(lmp,fmt::format("Loop time of {:.6g} on {} procs for " + "{} steps with {} atoms\n\n",time_loop, + ntasks,update->nsteps,atom->natoms)); // Gromacs/NAMD-style performance metric for suitable unit settings @@ -144,24 +143,20 @@ void Finish::end(int flag) if (strcmp(update->unit_style,"lj") == 0) { double tau_day = 24.0*3600.0 / t_step * update->dt / one_fs; - const char perf[] = "Performance: %.3f tau/day, %.3f timesteps/s\n"; - if (screen) fprintf(screen,perf,tau_day,step_t); - if (logfile) fprintf(logfile,perf,tau_day,step_t); + utils::logmesg(lmp,fmt::format("Performance: {:.3f} tau/day, {:.3f} " + "timesteps/s\n",tau_day,step_t)); } else if (strcmp(update->unit_style,"electron") == 0) { double hrs_fs = t_step / update->dt * one_fs / 3600.0; double fs_day = 24.0*3600.0 / t_step * update->dt / one_fs; - const char perf[] = - "Performance: %.3f fs/day, %.3f hours/fs, %.3f timesteps/s\n"; - if (screen) fprintf(screen,perf,fs_day,hrs_fs,step_t); - if (logfile) fprintf(logfile,perf,fs_day,hrs_fs,step_t); - + utils::logmesg(lmp,fmt::format("Performance: {:.3f} fs/day, {:.3f} " + "hours/fs, {:.3f} timesteps/s\n", + fs_day,hrs_fs,step_t)); } else { double hrs_ns = t_step / update->dt * 1000000.0 * one_fs / 3600.0; double ns_day = 24.0*3600.0 / t_step * update->dt / one_fs/1000000.0; - const char perf[] = - "Performance: %.3f ns/day, %.3f hours/ns, %.3f timesteps/s\n"; - if (screen) fprintf(screen,perf,ns_day,hrs_ns,step_t); - if (logfile) fprintf(logfile,perf,ns_day,hrs_ns,step_t); + utils::logmesg(lmp,fmt::format("Performance: {:.3f} ns/day, {:.3f} " + "hours/ns, {:.3f} timesteps/s\n", + ns_day,hrs_ns,step_t)); } } @@ -169,23 +164,17 @@ void Finish::end(int flag) if (timeflag) { if (lmp->kokkos) { - const char fmt2[] = - "%.1f%% CPU use with %d MPI tasks x %d OpenMP threads\n"; - if (screen) fprintf(screen,fmt2,cpu_loop,nprocs, - lmp->kokkos->nthreads); - if (logfile) fprintf(logfile,fmt2,cpu_loop,nprocs, - lmp->kokkos->nthreads); + utils::logmesg(lmp,fmt::format("{:.1f}% CPU use with {} MPI tasks " + "x {} OpenMP threads\n",cpu_loop,nprocs, + lmp->kokkos->nthreads)); } else { #if defined(_OPENMP) - const char fmt2[] = - "%.1f%% CPU use with %d MPI tasks x %d OpenMP threads\n"; - if (screen) fprintf(screen,fmt2,cpu_loop,nprocs,nthreads); - if (logfile) fprintf(logfile,fmt2,cpu_loop,nprocs,nthreads); + utils::logmesg(lmp,fmt::format("{:.1f}% CPU use with {} MPI tasks " + "x {} OpenMP threads\n", + cpu_loop,nprocs,nthreads)); #else - const char fmt2[] = - "%.1f%% CPU use with %d MPI tasks x no OpenMP threads\n"; - if (screen) fprintf(screen,fmt2,cpu_loop,nprocs); - if (logfile) fprintf(logfile,fmt2,cpu_loop,nprocs); + utils::logmesg(lmp,fmt::format("{:.1f}% CPU use with {} MPI tasks " + "x no OpenMP threads\n",cpu_loop,nprocs)); #endif } } @@ -206,289 +195,140 @@ void Finish::end(int flag) if (minflag) { if (me == 0) { - if (screen) fprintf(screen,"\n"); - if (logfile) fprintf(logfile,"\n"); - } + std::string mesg = "\nMinimization stats:\n"; - if (me == 0) { - if (screen) { - fprintf(screen,"Minimization stats:\n"); - fprintf(screen," Stopping criterion = %s\n", - update->minimize->stopstr); - fprintf(screen," Energy initial, next-to-last, final = \n" - " %18.12g %18.12g %18.12g\n", - update->minimize->einitial,update->minimize->eprevious, - update->minimize->efinal); - fprintf(screen," Force two-norm initial, final = %g %g\n", - update->minimize->fnorm2_init,update->minimize->fnorm2_final); - fprintf(screen," Force max component initial, final = %g %g\n", - update->minimize->fnorminf_init, - update->minimize->fnorminf_final); - fprintf(screen," Final line search alpha, max atom move = %g %g\n", - update->minimize->alpha_final, - update->minimize->alpha_final* - update->minimize->fnorminf_final); - fprintf(screen," Iterations, force evaluations = %d %d\n", - update->minimize->niter,update->minimize->neval); - } - if (logfile) { - fprintf(logfile,"Minimization stats:\n"); - fprintf(logfile," Stopping criterion = %s\n", - update->minimize->stopstr); - fprintf(logfile," Energy initial, next-to-last, final = \n" - " %18.12g %18.12g %18.12g\n", - update->minimize->einitial,update->minimize->eprevious, - update->minimize->efinal); - fprintf(logfile," Force two-norm initial, final = %g %g\n", - update->minimize->fnorm2_init,update->minimize->fnorm2_final); - fprintf(logfile," Force max component initial, final = %g %g\n", - update->minimize->fnorminf_init, - update->minimize->fnorminf_final); - fprintf(logfile," Final line search alpha, max atom move = %g %g\n", - update->minimize->alpha_final, - update->minimize->alpha_final* - update->minimize->fnorminf_final); - fprintf(logfile," Iterations, force evaluations = %d %d\n", - update->minimize->niter,update->minimize->neval); - } + mesg += fmt::format(" Stopping criterion = {}\n", + update->minimize->stopstr); + mesg += fmt::format(" Energy initial, next-to-last, final = \n" + " {:18.15g} {:18.15g} {:18.15g}\n", + update->minimize->einitial, + update->minimize->eprevious, + update->minimize->efinal); + mesg += fmt::format(" Force two-norm initial, final = {} {}\n", + update->minimize->fnorm2_init,update->minimize->fnorm2_final); + mesg += fmt::format(" Force max component initial, final = {} {}\n", + update->minimize->fnorminf_init, + update->minimize->fnorminf_final); + mesg += fmt::format(" Final line search alpha, max atom move = {} {}\n", + update->minimize->alpha_final, + update->minimize->alpha_final* + update->minimize->fnorminf_final); + mesg += fmt::format(" Iterations, force evaluations = {} {}\n", + update->minimize->niter,update->minimize->neval); + utils::logmesg(lmp,mesg); } } // PRD stats if (prdflag) { - if (me == 0) { - if (screen) fprintf(screen,"\nPRD stats:\n"); - if (logfile) fprintf(logfile,"\nPRD stats:\n"); - } + if (me == 0) utils::logmesg(lmp,"\nPRD stats:\n"); time = timer->get_wall(Timer::DEPHASE); MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); time = tmp/nprocs; - if (me == 0) { - if (screen) - fprintf(screen," Dephase time (%%) = %g (%g)\n", - time,time/time_loop*100.0); - if (logfile) - fprintf(logfile," Dephase time (%%) = %g (%g)\n", - time,time/time_loop*100.0); - } - + if (me == 0) utils::logmesg(lmp,fmt::format(" Dephase time (%) = {} ({})\n", + time,time/time_loop*100.0)); time = timer->get_wall(Timer::DYNAMICS); MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); time = tmp/nprocs; - if (me == 0) { - if (screen) - fprintf(screen," Dynamics time (%%) = %g (%g)\n", - time,time/time_loop*100.0); - if (logfile) - fprintf(logfile," Dynamics time (%%) = %g (%g)\n", - time,time/time_loop*100.0); - } - + if (me == 0) utils::logmesg(lmp,fmt::format(" Dynamics time (%) = {} ({})\n", + time,time/time_loop*100.0)); time = timer->get_wall(Timer::QUENCH); MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); time = tmp/nprocs; - if (me == 0) { - if (screen) - fprintf(screen," Quench time (%%) = %g (%g)\n", - time,time/time_loop*100.0); - if (logfile) - fprintf(logfile," Quench time (%%) = %g (%g)\n", - time,time/time_loop*100.0); - } - - time = timer->get_wall(Timer::REPCOMM); + if (me == 0) utils::logmesg(lmp,fmt::format(" Quench time (%) = {} ({})\n", + time,time/time_loop*100.0)); + time = timer->get_wall(Timer::REPCOMM); MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); time = tmp/nprocs; - if (me == 0) { - if (screen) - fprintf(screen," Comm time (%%) = %g (%g)\n", - time,time/time_loop*100.0); - if (logfile) - fprintf(logfile," Comm time (%%) = %g (%g)\n", - time,time/time_loop*100.0); - } - - + if (me == 0) utils::logmesg(lmp,fmt::format(" Comm time (%) = {} ({})\n", + time,time/time_loop*100.0)); time = timer->get_wall(Timer::REPOUT); MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); time = tmp/nprocs; - if (me == 0) { - if (screen) - fprintf(screen," Output time (%%) = %g (%g)\n", - time,time/time_loop*100.0); - if (logfile) - fprintf(logfile," Output time (%%) = %g (%g)\n", - time,time/time_loop*100.0); - } - + if (me == 0) utils::logmesg(lmp,fmt::format(" Output time (%) = {} ({})\n", + time,time/time_loop*100.0)); time = time_other; MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); time = tmp/nprocs; - if (me == 0) { // XXXX: replica comm, replica output - if (screen) - fprintf(screen," Other time (%%) = %g (%g)\n", - time,time/time_loop*100.0); - if (logfile) - fprintf(logfile," Other time (%%) = %g (%g)\n", - time,time/time_loop*100.0); - } + if (me == 0) utils::logmesg(lmp,fmt::format(" Other time (%) = {} ({})\n", + time,time/time_loop*100.0)); } // TAD stats if (tadflag) { - if (me == 0) { - if (screen) fprintf(screen,"\n"); - if (logfile) fprintf(logfile,"\n"); - } - - if (screen) fprintf(screen,"TAD stats:\n"); - if (logfile) fprintf(logfile,"TAD stats:\n"); + if (me == 0) utils::logmesg(lmp,"\nTAD stats:\n"); time = timer->get_wall(Timer::NEB); MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); time = tmp/nprocs; - if (me == 0) { - if (screen) - fprintf(screen," NEB time (%%) = %g (%g)\n", - time,time/time_loop*100.0); - if (logfile) - fprintf(logfile," NEB time (%%) = %g (%g)\n", - time,time/time_loop*100.0); - } - + if (me == 0) utils::logmesg(lmp,fmt::format(" NEB time (%) = {} ({})\n", + time,time/time_loop*100.0)); time = timer->get_wall(Timer::DYNAMICS); MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); time = tmp/nprocs; - if (me == 0) { - if (screen) - fprintf(screen," Dynamics time (%%) = %g (%g)\n", - time,time/time_loop*100.0); - if (logfile) - fprintf(logfile," Dynamics time (%%) = %g (%g)\n", - time,time/time_loop*100.0); - } - + if (me == 0) utils::logmesg(lmp,fmt::format(" Dynamics time (%) = {} ({})\n", + time,time/time_loop*100.0)); time = timer->get_wall(Timer::QUENCH); MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); time = tmp/nprocs; - if (me == 0) { - if (screen) - fprintf(screen," Quench time (%%) = %g (%g)\n", - time,time/time_loop*100.0); - if (logfile) - fprintf(logfile," Quench time (%%) = %g (%g)\n", - time,time/time_loop*100.0); - } - - + if (me == 0) utils::logmesg(lmp,fmt::format(" Quench time (%) = {} ({})\n", + time,time/time_loop*100.0)); time = timer->get_wall(Timer::REPCOMM); MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); time = tmp/nprocs; - if (me == 0) { - if (screen) - fprintf(screen," Comm time (%%) = %g (%g)\n", - time,time/time_loop*100.0); - if (logfile) - fprintf(logfile," Comm time (%%) = %g (%g)\n", - time,time/time_loop*100.0); - } - - + if (me == 0) utils::logmesg(lmp,fmt::format(" Comm time (%) = {} ({})\n", + time,time/time_loop*100.0)); time = timer->get_wall(Timer::REPOUT); MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); time = tmp/nprocs; - if (me == 0) { - if (screen) - fprintf(screen," Output time (%%) = %g (%g)\n", - time,time/time_loop*100.0); - if (logfile) - fprintf(logfile," Output time (%%) = %g (%g)\n", - time,time/time_loop*100.0); - } - + if (me == 0) utils::logmesg(lmp,fmt::format(" Output time (%) = {} ({})\n", + time,time/time_loop*100.0)); time = time_other; MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); time = tmp/nprocs; - if (me == 0) { - if (screen) - fprintf(screen," Other time (%%) = %g (%g)\n", - time,time/time_loop*100.0); - if (logfile) - fprintf(logfile," Other time (%%) = %g (%g)\n", - time,time/time_loop*100.0); - } + if (me == 0) utils::logmesg(lmp,fmt::format(" Other time (%) = {} ({})\n", + time,time/time_loop*100.0)); } // HYPER stats if (hyperflag) { - if (me == 0) { - if (screen) fprintf(screen,"\nHyper stats:\n"); - if (logfile) fprintf(logfile,"\nHyper stats:\n"); - } + if (me == 0) utils::logmesg(lmp,"\nHyper stats:\n"); time = timer->get_wall(Timer::DYNAMICS); MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); time = tmp/nprocs; - if (me == 0) { - if (screen) - fprintf(screen," Dynamics time (%%) = %g (%g)\n", - time,time/time_loop*100.0); - if (logfile) - fprintf(logfile," Dynamics time (%%) = %g (%g)\n", - time,time/time_loop*100.0); - } - + if (me == 0) utils::logmesg(lmp,fmt::format(" Dynamics time (%) = {} ({})\n", + time,time/time_loop*100.0)); time = timer->get_wall(Timer::QUENCH); MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); time = tmp/nprocs; - if (me == 0) { - if (screen) - fprintf(screen," Quench time (%%) = %g (%g)\n", - time,time/time_loop*100.0); - if (logfile) - fprintf(logfile," Quench time (%%) = %g (%g)\n", - time,time/time_loop*100.0); - } - + if (me == 0) utils::logmesg(lmp,fmt::format(" Quench time (%) = {} ({})\n", + time,time/time_loop*100.0)); time = time_other; MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); time = tmp/nprocs; - if (me == 0) { - if (screen) - fprintf(screen," Other time (%%) = %g (%g)\n", - time,time/time_loop*100.0); - if (logfile) - fprintf(logfile," Other time (%%) = %g (%g)\n", - time,time/time_loop*100.0); - } + if (me == 0) utils::logmesg(lmp,fmt::format(" Other time (%) = {} ({})\n", + time,time/time_loop*100.0)); } // further timing breakdowns if (timeflag && timer->has_normal()) { - if (timer->has_full()) { - const char hdr[] = "\nMPI task timing breakdown:\n" - "Section | min time | avg time | max time " - "|%varavg| %CPU | %total\n" - "-----------------------------------------------" - "------------------------\n"; - if (me == 0) { - if (screen) fputs(hdr,screen); - if (logfile) fputs(hdr,logfile); - } - } else { - const char hdr[] = "\nMPI task timing breakdown:\n" - "Section | min time | avg time | max time |%varavg| %total\n" - "---------------------------------------------------------------\n"; - if (me == 0) { - if (screen) fputs(hdr,screen); - if (logfile) fputs(hdr,logfile); - } + if (me == 0) { + if (timer->has_full()) + utils::logmesg(lmp,"\nMPI task timing breakdown:\nSection | min time " + " | avg time | max time |%varavg| %CPU | %total\n" + "-----------------------------------------------------" + "------------------\n"); + else + utils::logmesg(lmp,"\nMPI task timing breakdown:\nSection | min time " + " | avg time | max time |%varavg| %total\n---------" + "------------------------------------------------------\n"); } mpi_timings("Pair",timer,Timer::PAIR, world,nprocs, @@ -518,25 +358,19 @@ void Finish::end(int flag) MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); time = tmp/nprocs; - const char *fmt; - if (timer->has_full()) - fmt = "Other | |%- 12.4g| | | |%6.2f\n"; - else - fmt = "Other | |%- 12.4g| | |%6.2f\n"; - if (me == 0) { - if (screen) fprintf(screen,fmt,time,time/time_loop*100.0); - if (logfile) fprintf(logfile,fmt,time,time/time_loop*100.0); + if (timer->has_full()) + utils::logmesg(lmp,fmt::format("Other | | {:<10.4g} | " + " | | |{:6.2f}\n", + time,time/time_loop*100.0)); + else + utils::logmesg(lmp,fmt::format("Other | | {:<10.4g} | " + " | |{:6.2f}\n", + time,time/time_loop*100.0)); } } #ifdef LMP_USER_OMP - const char thr_hdr_fmt[] = - "\nThread timing breakdown (MPI rank %d):\nTotal threaded time %.4g / %.1f%%\n"; - const char thr_header[] = - "Section | min time | avg time | max time |%varavg| %total\n" - "---------------------------------------------------------------\n"; - int ifix = modify->find_fix("package_omp"); // print thread breakdown only with full timer detail @@ -552,23 +386,17 @@ void Finish::end(int flag) thr_total /= (double) nthreads; if (thr_total > 0.0) { - if (screen) { - fprintf(screen,thr_hdr_fmt,me,thr_total,thr_total/time_loop*100.0); - fputs(thr_header,screen); - } - if (logfile) { - fprintf(logfile,thr_hdr_fmt,me,thr_total,thr_total/time_loop*100.0); - fputs(thr_header,logfile); - } + const std::string thr_fmt = + "\nThread timing breakdown (MPI rank {}):\nTotal threaded time {:.4g} / {:.1f}%\n" + "Section | min time | avg time | max time |%varavg| %total\n" + "---------------------------------------------------------------\n"; + utils::logmesg(lmp,fmt::format(thr_fmt,me,thr_total,thr_total/time_loop*100.0)); omp_times(fixomp,"Pair",Timer::PAIR,nthreads,screen,logfile); - if (atom->molecular) omp_times(fixomp,"Bond",Timer::BOND,nthreads,screen,logfile); - if (force->kspace) omp_times(fixomp,"Kspace",Timer::KSPACE,nthreads,screen,logfile); - omp_times(fixomp,"Neigh",Timer::NEIGH,nthreads,screen,logfile); omp_times(fixomp,"Reduce",Timer::COMM,nthreads,screen,logfile); } @@ -590,11 +418,7 @@ void Finish::end(int flag) // time_kspace may be 0.0 if another partition is doing Kspace if (fftflag) { - if (me == 0) { - if (screen) fprintf(screen,"\n"); - if (logfile) fprintf(logfile,"\n"); - } - + if (me == 0) utils::logmesg(lmp,"\n"); int nsteps = update->nsteps; double time3d; @@ -637,56 +461,30 @@ void Finish::end(int flag) flop1 = nfft*nflops/1.0e9/(time1d/nsteps); } else fraction = flop3 = flop1 = 0.0; - if (me == 0) { - if (screen) { - fprintf(screen,"FFT time (%% of Kspce) = %g (%g)\n",time3d,fraction); - fprintf(screen,"FFT Gflps 3d (1d only) = %g %g\n",flop3,flop1); - } - if (logfile) { - fprintf(logfile,"FFT time (%% of Kspce) = %g (%g)\n",time3d,fraction); - fprintf(logfile,"FFT Gflps 3d (1d only) = %g %g\n",flop3,flop1); - } - } + if (me == 0) + utils::logmesg(lmp,fmt::format("FFT time (% of Kspce) = {} ({})\n" + "FFT Gflps 3d (1d only) = {} {}\n", + time3d,fraction,flop3,flop1)); } if (histoflag) { - if (me == 0) { - if (screen) fprintf(screen,"\n"); - if (logfile) fprintf(logfile,"\n"); - } - + std::string mesg = "\n"; tmp = atom->nlocal; stats(1,&tmp,&ave,&max,&min,10,histo); if (me == 0) { - if (screen) { - fprintf(screen,"Nlocal: %g ave %g max %g min\n",ave,max,min); - fprintf(screen,"Histogram:"); - for (i = 0; i < 10; i++) fprintf(screen," %d",histo[i]); - fprintf(screen,"\n"); - } - if (logfile) { - fprintf(logfile,"Nlocal: %g ave %g max %g min\n",ave,max,min); - fprintf(logfile,"Histogram:"); - for (i = 0; i < 10; i++) fprintf(logfile," %d",histo[i]); - fprintf(logfile,"\n"); - } + mesg += fmt::format("Nlocal: {} ave {} max {} min\n",ave,max,min); + mesg += "Histogram:"; + for (i = 0; i < 10; i++) mesg += fmt::format(" {}",histo[i]); + mesg += "\n"; } tmp = atom->nghost; stats(1,&tmp,&ave,&max,&min,10,histo); if (me == 0) { - if (screen) { - fprintf(screen,"Nghost: %g ave %g max %g min\n",ave,max,min); - fprintf(screen,"Histogram:"); - for (i = 0; i < 10; i++) fprintf(screen," %d",histo[i]); - fprintf(screen,"\n"); - } - if (logfile) { - fprintf(logfile,"Nghost: %g ave %g max %g min\n",ave,max,min); - fprintf(logfile,"Histogram:"); - for (i = 0; i < 10; i++) fprintf(logfile," %d",histo[i]); - fprintf(logfile,"\n"); - } + mesg += fmt::format("Nghost: {} ave {} max {} min\n",ave,max,min); + mesg += "Histogram:"; + for (i = 0; i < 10; i++) mesg += fmt::format(" {}",histo[i]); + mesg += "\n"; } // find a non-skip neighbor list containing half pairwise interactions @@ -712,18 +510,10 @@ void Finish::end(int flag) tmp = nneigh; stats(1,&tmp,&ave,&max,&min,10,histo); if (me == 0) { - if (screen) { - fprintf(screen,"Neighs: %g ave %g max %g min\n",ave,max,min); - fprintf(screen,"Histogram:"); - for (i = 0; i < 10; i++) fprintf(screen," %d",histo[i]); - fprintf(screen,"\n"); - } - if (logfile) { - fprintf(logfile,"Neighs: %g ave %g max %g min\n",ave,max,min); - fprintf(logfile,"Histogram:"); - for (i = 0; i < 10; i++) fprintf(logfile," %d",histo[i]); - fprintf(logfile,"\n"); - } + mesg += fmt::format("Neighs: {} ave {} max {} min\n",ave,max,min); + mesg += "Histogram:"; + for (i = 0; i < 10; i++) mesg += fmt::format(" {}",histo[i]); + mesg += "\n"; } // find a non-skip neighbor list containing full pairwise interactions @@ -743,32 +533,23 @@ void Finish::end(int flag) for (i = 0; i < inum; i++) nneighfull += numneigh[ilist[i]]; } else if (lmp->kokkos) - nneighfull = lmp->kokkos->neigh_count(m); + nneighfull = lmp->kokkos->neigh_count(m); tmp = nneighfull; stats(1,&tmp,&ave,&max,&min,10,histo); if (me == 0) { - if (screen) { - fprintf(screen,"FullNghs: %g ave %g max %g min\n",ave,max,min); - fprintf(screen,"Histogram:"); - for (i = 0; i < 10; i++) fprintf(screen," %d",histo[i]); - fprintf(screen,"\n"); - } - if (logfile) { - fprintf(logfile,"FullNghs: %g ave %g max %g min\n",ave,max,min); - fprintf(logfile,"Histogram:"); - for (i = 0; i < 10; i++) fprintf(logfile," %d",histo[i]); - fprintf(logfile,"\n"); - } + mesg += fmt::format("FullNghs: {} ave {} max {} min\n",ave,max,min); + mesg += "Histogram:"; + for (i = 0; i < 10; i++) mesg += fmt::format(" {}",histo[i]); + mesg += "\n"; + } } + if (me == 0) utils::logmesg(lmp,mesg); } if (neighflag) { - if (me == 0) { - if (screen) fprintf(screen,"\n"); - if (logfile) fprintf(logfile,"\n"); - } + if (me == 0) utils::logmesg(lmp,"\n"); tmp = MAX(nneigh,nneighfull); double nall; @@ -801,40 +582,19 @@ void Finish::end(int flag) } if (me == 0) { - if (screen) { - if (nall < 2.0e9) - fprintf(screen, - "Total # of neighbors = %d\n",static_cast (nall)); - else fprintf(screen,"Total # of neighbors = %g\n",nall); - if (atom->natoms > 0) - fprintf(screen,"Ave neighs/atom = %g\n",nall/atom->natoms); - if (atom->molecular && atom->natoms > 0) - fprintf(screen,"Ave special neighs/atom = %g\n", - nspec_all/atom->natoms); - fprintf(screen,"Neighbor list builds = " BIGINT_FORMAT "\n", - neighbor->ncalls); - if (neighbor->dist_check) - fprintf(screen,"Dangerous builds = " BIGINT_FORMAT "\n", - neighbor->ndanger); - else fprintf(screen,"Dangerous builds not checked\n"); - } - if (logfile) { - if (nall < 2.0e9) - fprintf(logfile, - "Total # of neighbors = %d\n",static_cast (nall)); - else fprintf(logfile,"Total # of neighbors = %g\n",nall); - if (atom->natoms > 0) - fprintf(logfile,"Ave neighs/atom = %g\n",nall/atom->natoms); - if (atom->molecular && atom->natoms > 0) - fprintf(logfile,"Ave special neighs/atom = %g\n", - nspec_all/atom->natoms); - fprintf(logfile,"Neighbor list builds = " BIGINT_FORMAT "\n", - neighbor->ncalls); - if (neighbor->dist_check) - fprintf(logfile,"Dangerous builds = " BIGINT_FORMAT "\n", - neighbor->ndanger); - else fprintf(logfile,"Dangerous builds not checked\n"); - } + std::string mesg; + + mesg += fmt::format("Total # of neighbors = {}\n",static_cast(nall)); + if (atom->natoms > 0) + mesg += fmt::format("Ave neighs/atom = {}\n",nall/atom->natoms); + if (atom->molecular && atom->natoms > 0) + mesg += fmt::format("Ave special neighs/atom = {}\n", + nspec_all/atom->natoms); + mesg += fmt::format("Neighbor list builds = {}\n",neighbor->ncalls); + if (neighbor->dist_check) + mesg += fmt::format("Dangerous builds = {}\n",neighbor->ndanger); + else mesg += "Dangerous builds not checked\n"; + utils::logmesg(lmp,mesg); } } @@ -921,23 +681,18 @@ void mpi_timings(const char *label, Timer *t, enum Timer::ttype tt, else time_sq = 0.0; - if (me == 0) { tmp = time/time_loop*100.0; - if (t->has_full()) { - const char fmt[] = "%-8s|%- 12.5g|%- 12.5g|%- 12.5g|%6.1f |%6.1f |%6.2f\n"; - if (scr) - fprintf(scr,fmt,label,time_min,time,time_max,time_sq,time_cpu,tmp); - if (log) - fprintf(log,fmt,label,time_min,time,time_max,time_sq,time_cpu,tmp); - time_loop = 100.0/time_loop; - } else { - const char fmt[] = "%-8s|%- 12.5g|%- 12.5g|%- 12.5g|%6.1f |%6.2f\n"; - if (scr) - fprintf(scr,fmt,label,time_min,time,time_max,time_sq,tmp); - if (log) - fprintf(log,fmt,label,time_min,time,time_max,time_sq,tmp); - } + std::string mesg; + if (t->has_full()) + mesg = fmt::format("{:<8s}| {:<10.5g} | {:<10.5g} | {:<10.5g} |{:6.1f} |" + "{:6.1f} |{:6.2f}\n", + label,time_min,time,time_max,time_sq,time_cpu,tmp); + else + mesg = fmt::format("{:<8s}| {:<10.5g} | {:<10.5g} | {:<10.5g} |{:6.1f} |" + "{:6.2f}\n",label,time_min,time,time_max,time_sq,tmp); + if (scr) fputs(mesg.c_str(),scr); + if (log) fputs(mesg.c_str(),log); } } @@ -947,7 +702,6 @@ void mpi_timings(const char *label, Timer *t, enum Timer::ttype tt, void omp_times(FixOMP *fix, const char *label, enum Timer::ttype which, const int nthreads,FILE *scr, FILE *log) { - const char fmt[] = "%-8s|%- 12.5g|%- 12.5g|%- 12.5g|%6.1f |%6.2f\n"; double time_min, time_max, time_avg, time_total, time_std; time_min = 1.0e100; @@ -973,10 +727,11 @@ void omp_times(FixOMP *fix, const char *label, enum Timer::ttype which, else time_std = 0.0; - if (scr) fprintf(scr,fmt,label,time_min,time_avg,time_max,time_std, - time_avg/time_total*100.0); - if (log) fprintf(log,fmt,label,time_min,time_avg,time_max,time_std, - time_avg/time_total*100.0); + std::string mesg = fmt::format("{:<8s}| {:10.5g} | {:10.5g} | {:10.5g} |" + "{:6.1f} |{:6.2f}\n",label,time_min,time_avg, + time_max,time_std,time_avg/time_total*100.0); + if (scr) fputs(mesg.c_str(),scr); + if (log) fputs(mesg.c_str(),log); } #endif diff --git a/src/fix_adapt.cpp b/src/fix_adapt.cpp index e7254e77d7..c502dc6595 100644 --- a/src/fix_adapt.cpp +++ b/src/fix_adapt.cpp @@ -31,6 +31,7 @@ #include "memory.h" #include "error.h" #include "utils.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -139,12 +140,12 @@ nadapt(0), id_fix_diam(NULL), id_fix_chg(NULL), adapt(NULL) } else error->all(FLERR,"Illegal fix adapt command"); nadapt++; iarg += 2; - + } else if (strcmp(arg[iarg],"atom") == 0) { if (iarg+3 > narg) error->all(FLERR,"Illegal fix adapt command"); adapt[nadapt].which = ATOM; if (strcmp(arg[iarg+1],"diameter") == 0 || - strcmp(arg[iarg+1],"diameter/disc") == 0) { + strcmp(arg[iarg+1],"diameter/disc") == 0) { adapt[nadapt].aparam = DIAMETER; diamflag = 1; discflag = 0; @@ -194,10 +195,10 @@ nadapt(0), id_fix_diam(NULL), id_fix_chg(NULL), adapt(NULL) // if scaleflag set with diameter or charge adaptation, // then previous step scale factors are written to restart file // initialize them here in case one is used and other is never defined - + if (scaleflag && (diamflag || chgflag)) restart_global = 1; previous_diam_scale = previous_chg_scale = 1.0; - + // allocate pair style arrays int n = atom->ntypes; @@ -265,20 +266,12 @@ void FixAdapt::post_constructor() id_fix_diam = NULL; id_fix_chg = NULL; - char **newarg = new char*[6]; - newarg[1] = group->names[igroup]; - newarg[2] = (char *) "STORE"; - newarg[3] = (char *) "peratom"; - newarg[4] = (char *) "1"; - newarg[5] = (char *) "1"; - if (diamflag && atom->radius_flag) { - int n = strlen(id) + strlen("_FIX_STORE_DIAM") + 1; - id_fix_diam = new char[n]; - strcpy(id_fix_diam,id); - strcat(id_fix_diam,"_FIX_STORE_DIAM"); - newarg[0] = id_fix_diam; - modify->add_fix(6,newarg); + std::string fixcmd = id + std::string("_FIX_STORE_DIAM"); + id_fix_diam = new char[fixcmd.size()+1]; + strcpy(id_fix_diam,fixcmd.c_str()); + fixcmd += fmt::format(" {} STORE peratom 1 1",group->names[igroup]); + modify->add_fix(fixcmd); fix_diam = (FixStore *) modify->fix[modify->nfix-1]; if (fix_diam->restart_reset) fix_diam->restart_reset = 0; @@ -296,12 +289,11 @@ void FixAdapt::post_constructor() } if (chgflag && atom->q_flag) { - int n = strlen(id) + strlen("_FIX_STORE_CHG") + 1; - id_fix_chg = new char[n]; - strcpy(id_fix_chg,id); - strcat(id_fix_chg,"_FIX_STORE_CHG"); - newarg[0] = id_fix_chg; - modify->add_fix(6,newarg); + std::string fixcmd = id + std::string("_FIX_STORE_CHG"); + id_fix_chg = new char[fixcmd.size()+1]; + strcpy(id_fix_chg,fixcmd.c_str()); + fixcmd += fmt::format(" {} STORE peratom 1 1",group->names[igroup]); + modify->add_fix(fixcmd); fix_chg = (FixStore *) modify->fix[modify->nfix-1]; if (fix_chg->restart_reset) fix_chg->restart_reset = 0; @@ -317,8 +309,6 @@ void FixAdapt::post_constructor() } } } - - delete [] newarg; } /* ---------------------------------------------------------------------- */ @@ -462,7 +452,7 @@ void FixAdapt::init() } } } - + if (restart_reset) restart_reset = 0; // make copy of original pair/bond array values @@ -596,9 +586,9 @@ void FixAdapt::change_settings() // reset radius to new value, for both owned and ghost atoms // also reset rmass to new value assuming density remains constant // for scaleflag, previous_diam_scale is the scale factor on previous step - + if (ad->aparam == DIAMETER) { - double density,scale; + double scale; double *radius = atom->radius; double *rmass = atom->rmass; int *mask = atom->mask; @@ -618,7 +608,7 @@ void FixAdapt::change_settings() else radius[i] = 0.5*value; } } - + if (scaleflag) previous_diam_scale = value; // reset charge to new value, for both owned and ghost atoms @@ -631,15 +621,15 @@ void FixAdapt::change_settings() int nlocal = atom->nlocal; int nall = nlocal + atom->nghost; - if (scaleflag) scale = value / previous_chg_scale; - + if (scaleflag) scale = value / previous_chg_scale; + for (i = 0; i < nall; i++) { if (mask[i] & groupbit) { if (scaleflag) q[i] *= scale; else q[i] = value; } - } - + } + if (scaleflag) previous_chg_scale = value; } } @@ -701,14 +691,14 @@ void FixAdapt::restore_settings() } else if (ad->which == ATOM) { if (diamflag) { - double density,scale; + double scale; double *vec = fix_diam->vstore; double *radius = atom->radius; double *rmass = atom->rmass; int *mask = atom->mask; int nlocal = atom->nlocal; - + if (scaleflag) scale = previous_diam_scale; for (int i = 0; i < nlocal; i++) @@ -755,7 +745,7 @@ void FixAdapt::set_arrays(int i) void FixAdapt::write_restart(FILE *fp) { int size = 2*sizeof(double); - + fwrite(&size,sizeof(int),1,fp); fwrite(&previous_diam_scale,sizeof(double),1,fp); fwrite(&previous_chg_scale,sizeof(double),1,fp); @@ -768,7 +758,7 @@ void FixAdapt::write_restart(FILE *fp) void FixAdapt::restart(char *buf) { double *dbuf = (double *) buf; - + previous_diam_scale = dbuf[0]; previous_chg_scale = dbuf[1]; } diff --git a/src/fix_box_relax.cpp b/src/fix_box_relax.cpp index 8d6111c0a0..832799831e 100644 --- a/src/fix_box_relax.cpp +++ b/src/fix_box_relax.cpp @@ -18,6 +18,7 @@ #include "fix_box_relax.h" #include #include +#include #include "atom.h" #include "domain.h" #include "update.h" @@ -28,6 +29,7 @@ #include "compute.h" #include "error.h" #include "math_extra.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -317,36 +319,24 @@ FixBoxRelax::FixBoxRelax(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); + std::string tcmd = id + std::string("_temp"); + id_temp = new char[tcmd.size()+1]; + strcpy(id_temp,tcmd.c_str()); - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp"; - modify->add_compute(3,newarg); - delete [] newarg; + tcmd += " all temp"; + modify->add_compute(tcmd); tflag = 1; // create a new compute pressure style (virial only) // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); + std::string pcmd = id + std::string("_press"); + id_press = new char[pcmd.size()+1]; + strcpy(id_press,pcmd.c_str()); - newarg = new char*[5]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - newarg[4] = (char *) "virial"; - modify->add_compute(5,newarg); - delete [] newarg; + pcmd += " all pressure " + std::string(id_temp) + " virial"; + modify->add_compute(pcmd); pflag = 1; dimension = domain->dimension; diff --git a/src/fix_halt.cpp b/src/fix_halt.cpp index 42b63c69f1..c5960dfe13 100644 --- a/src/fix_halt.cpp +++ b/src/fix_halt.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include "update.h" #include "force.h" #include "input.h" @@ -25,6 +26,7 @@ #include "comm.h" #include "timer.h" #include "error.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -224,15 +226,13 @@ void FixHalt::end_of_step() // soft/continue halt -> trigger timer to break from run loop // print message with ID of fix halt in case multiple instances - char str[128]; - sprintf(str,"Fix halt condition for fix-id %s met on step " - BIGINT_FORMAT " with value %g", - id, update->ntimestep, attvalue); - + std::string message = fmt::format("Fix halt condition for fix-id {} met on " + "step {} with value {}", + id, update->ntimestep, attvalue); if (eflag == HARD) { - error->all(FLERR,str); + error->all(FLERR,message); } else if (eflag == SOFT || eflag == CONTINUE) { - if (comm->me == 0 && msgflag == YESMSG) error->message(FLERR,str); + if (comm->me == 0 && msgflag == YESMSG) error->message(FLERR,message); timer->force_timeout(); } } diff --git a/src/fix_nph.cpp b/src/fix_nph.cpp index 7148b024de..9251ce384e 100644 --- a/src/fix_nph.cpp +++ b/src/fix_nph.cpp @@ -13,6 +13,7 @@ #include "fix_nph.h" #include +#include #include "modify.h" #include "error.h" @@ -34,35 +35,23 @@ FixNPH::FixNPH(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); + std::string tcmd = id + std::string("_temp"); + id_temp = new char[tcmd.size()+1]; + strcpy(id_temp,tcmd.c_str()); - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp"; - - modify->add_compute(3,newarg); - delete [] newarg; + tcmd += " all temp"; + modify->add_compute(tcmd); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); + std::string pcmd = id + std::string("_press"); + id_press = new char[pcmd.size()+1]; + strcpy(id_press,pcmd.c_str()); - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + pcmd += " all pressure " + std::string(id_temp); + modify->add_compute(pcmd); pcomputeflag = 1; } diff --git a/src/fix_nph_sphere.cpp b/src/fix_nph_sphere.cpp index f64f144f34..cf2298f5f8 100644 --- a/src/fix_nph_sphere.cpp +++ b/src/fix_nph_sphere.cpp @@ -13,6 +13,7 @@ #include "fix_nph_sphere.h" #include +#include #include "modify.h" #include "error.h" @@ -34,35 +35,21 @@ FixNPHSphere::FixNPHSphere(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); + std::string tcmd = id + std::string("_temp"); + id_temp = new char[tcmd.size()+1]; + strcpy(id_temp,tcmd.c_str()); - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp/sphere"; - - modify->add_compute(3,newarg); - delete [] newarg; + modify->add_compute(tcmd + " all temp/sphere"); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); + std::string pcmd = id + std::string("_press"); + id_press = new char[pcmd.size()+1]; + strcpy(id_press,pcmd.c_str()); - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + modify->add_compute(pcmd + " all pressure " + std::string(id_temp)); pcomputeflag = 1; } diff --git a/src/fix_npt.cpp b/src/fix_npt.cpp index e856fafe2d..6949ead1d6 100644 --- a/src/fix_npt.cpp +++ b/src/fix_npt.cpp @@ -13,6 +13,7 @@ #include "fix_npt.h" #include +#include #include "modify.h" #include "error.h" @@ -34,35 +35,23 @@ FixNPT::FixNPT(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); + std::string tcmd = id + std::string("_temp"); + id_temp = new char[tcmd.size()+1]; + strcpy(id_temp,tcmd.c_str()); - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp"; - - modify->add_compute(3,newarg); - delete [] newarg; + tcmd += " all temp"; + modify->add_compute(tcmd); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); + std::string pcmd = id + std::string("_press"); + id_press = new char[pcmd.size()+1]; + strcpy(id_press,pcmd.c_str()); - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + pcmd += " all pressure " + std::string(id_temp); + modify->add_compute(pcmd); pcomputeflag = 1; } diff --git a/src/fix_npt_sphere.cpp b/src/fix_npt_sphere.cpp index 9cbb17b0ca..e38d88fadd 100644 --- a/src/fix_npt_sphere.cpp +++ b/src/fix_npt_sphere.cpp @@ -13,6 +13,7 @@ #include "fix_npt_sphere.h" #include +#include #include "modify.h" #include "error.h" @@ -34,35 +35,21 @@ FixNPTSphere::FixNPTSphere(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); + std::string tcmd = id + std::string("_temp"); + id_temp = new char[tcmd.size()+1]; + strcpy(id_temp,tcmd.c_str()); - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp/sphere"; - - modify->add_compute(3,newarg); - delete [] newarg; + modify->add_compute(tcmd + " all temp/sphere"); tcomputeflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); + std::string pcmd = id + std::string("_press"); + id_press = new char[pcmd.size()+1]; + strcpy(id_press,pcmd.c_str()); - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + modify->add_compute(pcmd + " all pressure " + std::string(id_temp)); pcomputeflag = 1; } diff --git a/src/fix_numdiff.cpp b/src/fix_numdiff.cpp index 0fc5b4ada0..a4ac86e0c5 100644 --- a/src/fix_numdiff.cpp +++ b/src/fix_numdiff.cpp @@ -55,17 +55,12 @@ FixNumDiff::FixNumDiff(LAMMPS *lmp, int narg, char **arg) : if (nevery <= 0 || delta <= 0.0) error->all(FLERR,"Illegal fix numdiff command"); - int n = strlen(id) + 6; - id_pe = new char[n]; - strcpy(id_pe,id); - strcat(id_pe,"_pe"); + std::string cmd = id + std::string("_pe"); + id_pe = new char[cmd.size()+1]; + strcpy(id_pe,cmd.c_str()); - char **newarg = new char*[3]; - newarg[0] = id_pe; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pe"; - modify->add_compute(3,newarg); - delete [] newarg; + cmd += " all pe"; + modify->add_compute(cmd); maxatom = 0; diff --git a/src/fix_nvt.cpp b/src/fix_nvt.cpp index 6f0d4c6c50..7868693b69 100644 --- a/src/fix_nvt.cpp +++ b/src/fix_nvt.cpp @@ -13,9 +13,11 @@ #include "fix_nvt.h" #include +#include #include "group.h" #include "modify.h" #include "error.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -33,17 +35,11 @@ FixNVT::FixNVT(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); + std::string tcmd = id + std::string("_temp"); + id_temp = new char[tcmd.size()+1]; + strcpy(id_temp,tcmd.c_str()); - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = group->names[igroup]; - newarg[2] = (char *) "temp"; - - modify->add_compute(3,newarg); - delete [] newarg; + tcmd += fmt::format(" {} temp",group->names[igroup]); + modify->add_compute(tcmd); tcomputeflag = 1; } diff --git a/src/fix_nvt_sllod.cpp b/src/fix_nvt_sllod.cpp index 138794862a..ccf7aaecaf 100644 --- a/src/fix_nvt_sllod.cpp +++ b/src/fix_nvt_sllod.cpp @@ -26,6 +26,7 @@ #include "fix_deform.h" #include "compute.h" #include "error.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -48,18 +49,12 @@ FixNVTSllod::FixNVTSllod(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); + std::string cmd = id + std::string("_temp"); + id_temp = new char[cmd.size()+1]; + strcpy(id_temp,cmd.c_str()); - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = group->names[igroup]; - newarg[2] = (char *) "temp/deform"; - - modify->add_compute(3,newarg); - delete [] newarg; + cmd += fmt::format(" {} temp/deform",group->names[igroup]); + modify->add_compute(cmd); tcomputeflag = 1; } diff --git a/src/fix_nvt_sphere.cpp b/src/fix_nvt_sphere.cpp index fed3799011..40c3ba19e3 100644 --- a/src/fix_nvt_sphere.cpp +++ b/src/fix_nvt_sphere.cpp @@ -13,9 +13,11 @@ #include "fix_nvt_sphere.h" #include +#include #include "group.h" #include "modify.h" #include "error.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -33,17 +35,11 @@ FixNVTSphere::FixNVTSphere(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); + std::string cmd = id + std::string("_temp"); + id_temp = new char[cmd.size()+1]; + strcpy(id_temp,cmd.c_str()); - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = group->names[igroup]; - newarg[2] = (char *) "temp/sphere"; - - modify->add_compute(3,newarg); - delete [] newarg; + cmd += fmt::format(" {} temp/sphere",group->names[igroup]); + modify->add_compute(cmd); tcomputeflag = 1; } diff --git a/src/fix_press_berendsen.cpp b/src/fix_press_berendsen.cpp index 184f02c440..db6d56799a 100644 --- a/src/fix_press_berendsen.cpp +++ b/src/fix_press_berendsen.cpp @@ -14,6 +14,7 @@ #include "fix_press_berendsen.h" #include #include +#include #include "atom.h" #include "force.h" #include "comm.h" @@ -217,35 +218,24 @@ FixPressBerendsen::FixPressBerendsen(LAMMPS *lmp, int narg, char **arg) : // compute group = all since pressure is always global (group all) // and thus its KE/temperature contribution should use group all - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); + std::string tcmd = id + std::string("_temp"); + id_temp = new char[tcmd.size()+1]; + strcpy(id_temp,tcmd.c_str()); - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp"; - modify->add_compute(3,newarg); - delete [] newarg; + tcmd += " all temp"; + modify->add_compute(tcmd); tflag = 1; // create a new compute pressure style // id = fix-ID + press, compute group = all // pass id_temp as 4th arg to pressure constructor - n = strlen(id) + 7; - id_press = new char[n]; - strcpy(id_press,id); - strcat(id_press,"_press"); + std::string pcmd = id + std::string("_press"); + id_press = new char[pcmd.size()+1]; + strcpy(id_press,pcmd.c_str()); - newarg = new char*[4]; - newarg[0] = id_press; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = id_temp; - modify->add_compute(4,newarg); - delete [] newarg; + pcmd += " all pressure " + std::string(id_temp); + modify->add_compute(pcmd); pflag = 1; nrigid = 0; diff --git a/src/fix_temp_berendsen.cpp b/src/fix_temp_berendsen.cpp index be8922be4e..9b385bf96c 100644 --- a/src/fix_temp_berendsen.cpp +++ b/src/fix_temp_berendsen.cpp @@ -13,6 +13,7 @@ #include "fix_temp_berendsen.h" #include +#include #include #include "atom.h" #include "force.h" @@ -24,6 +25,7 @@ #include "modify.h" #include "compute.h" #include "error.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -70,17 +72,12 @@ FixTempBerendsen::FixTempBerendsen(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp, compute group = fix group - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); + std::string cmd = id + std::string("_temp"); + id_temp = new char[cmd.size()+1]; + strcpy(id_temp,cmd.c_str()); - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = group->names[igroup]; - newarg[2] = (char *) "temp"; - modify->add_compute(3,newarg); - delete [] newarg; + cmd += fmt::format(" {} temp",group->names[igroup]); + modify->add_compute(cmd); tflag = 1; energy = 0; diff --git a/src/fix_temp_csld.cpp b/src/fix_temp_csld.cpp index f827c88f51..f83d593c96 100644 --- a/src/fix_temp_csld.cpp +++ b/src/fix_temp_csld.cpp @@ -17,6 +17,7 @@ #include "fix_temp_csld.h" #include +#include #include #include "atom.h" #include "force.h" @@ -30,6 +31,7 @@ #include "compute.h" #include "random_mars.h" #include "error.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -79,17 +81,12 @@ FixTempCSLD::FixTempCSLD(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp, compute group = fix group - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); + std::string cmd = id + std::string("_temp"); + id_temp = new char[cmd.size()+1]; + strcpy(id_temp,cmd.c_str()); - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = group->names[igroup]; - newarg[2] = (char *) "temp"; - modify->add_compute(3,newarg); - delete [] newarg; + cmd += fmt::format(" {} temp",group->names[igroup]); + modify->add_compute(cmd); tflag = 1; vhold = NULL; diff --git a/src/fix_temp_csvr.cpp b/src/fix_temp_csvr.cpp index 55cbb60407..cca204a4b2 100644 --- a/src/fix_temp_csvr.cpp +++ b/src/fix_temp_csvr.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include "atom.h" #include "force.h" #include "comm.h" @@ -31,6 +32,7 @@ #include "compute.h" #include "random_mars.h" #include "error.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -156,17 +158,12 @@ FixTempCSVR::FixTempCSVR(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp style // id = fix-ID + temp, compute group = fix group - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); + std::string cmd = id + std::string("_temp"); + id_temp = new char[cmd.size()+1]; + strcpy(id_temp,cmd.c_str()); - char **newarg = new char*[3]; - newarg[0] = id_temp; - newarg[1] = group->names[igroup]; - newarg[2] = (char *) "temp"; - modify->add_compute(3,newarg); - delete [] newarg; + cmd += fmt::format(" {} temp",group->names[igroup]); + modify->add_compute(cmd); tflag = 1; nmax = -1; diff --git a/src/fix_temp_rescale.cpp b/src/fix_temp_rescale.cpp index a9d605d5ba..575a81c40b 100644 --- a/src/fix_temp_rescale.cpp +++ b/src/fix_temp_rescale.cpp @@ -13,6 +13,7 @@ #include "fix_temp_rescale.h" #include +#include #include #include "atom.h" #include "force.h" @@ -24,6 +25,7 @@ #include "modify.h" #include "compute.h" #include "error.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace FixConst; @@ -66,17 +68,12 @@ FixTempRescale::FixTempRescale(LAMMPS *lmp, int narg, char **arg) : // create a new compute temp // id = fix-ID + temp, compute group = fix group - int n = strlen(id) + 6; - id_temp = new char[n]; - strcpy(id_temp,id); - strcat(id_temp,"_temp"); + std::string cmd = id + std::string("_temp"); + id_temp = new char[cmd.size()+1]; + strcpy(id_temp,cmd.c_str()); - char **newarg = new char*[6]; - newarg[0] = id_temp; - newarg[1] = group->names[igroup]; - newarg[2] = (char *) "temp"; - modify->add_compute(3,newarg); - delete [] newarg; + cmd += fmt::format(" {} temp",group->names[igroup]); + modify->add_compute(cmd); tflag = 1; energy = 0.0; diff --git a/src/force.cpp b/src/force.cpp index 5824e35648..653af05d41 100644 --- a/src/force.cpp +++ b/src/force.cpp @@ -1011,7 +1011,7 @@ tagint Force::tnumeric(const char *file, int line, char *str) if fails, search in dir specified by env variable LAMMPS_POTENTIALS ------------------------------------------------------------------------- */ -FILE *Force::open_potential(const char *name) +FILE *Force::open_potential(const char *name, int *auto_convert) { std::string filepath = utils::get_potential_file_path(name); @@ -1024,9 +1024,35 @@ FILE *Force::open_potential(const char *name) utils::logmesg(lmp, fmt::format("Reading potential file {} " "with DATE: {}\n", name, date)); } - if (!units.empty() && (units != unit_style)) { - error->one(FLERR, fmt::format("Potential file {} requires {} units " - "but {} units are in use", name, units, unit_style)); + + if (auto_convert == nullptr) { + if (!units.empty() && (units != unit_style)) { + error->one(FLERR, fmt::format("Potential file {} requires {} units " + "but {} units are in use", name, units, + unit_style)); + return nullptr; + } + } else { + if (units.empty() || units == unit_style) { + *auto_convert = utils::NOCONVERT; + } else { + if ((units == "metal") && (unit_style == "real") + && (*auto_convert & utils::METAL2REAL)) { + *auto_convert = utils::METAL2REAL; + } else if ((units == "real") && (unit_style == "metal") + && (*auto_convert & utils::REAL2METAL)) { + *auto_convert = utils::REAL2METAL; + } else { + error->one(FLERR, fmt::format("Potential file {} requires {} units " + "but {} units are in use", name, + units, unit_style)); + return nullptr; + } + } + if (*auto_convert != utils::NOCONVERT) + lmp->error->warning(FLERR, fmt::format("Converting potential file in " + "{} units to {} units", + units, unit_style)); } return fopen(filepath.c_str(), "r"); } diff --git a/src/force.h b/src/force.h index fa0c0f6877..b566f02fb7 100644 --- a/src/force.h +++ b/src/force.h @@ -135,7 +135,7 @@ class Force : protected Pointers { bigint bnumeric(const char *, int, char *); tagint tnumeric(const char *, int, char *); - FILE *open_potential(const char *); + FILE *open_potential(const char *, int *auto_convert = nullptr); bigint memory_usage(); diff --git a/src/group.cpp b/src/group.cpp index 93cd668194..61f28c2551 100644 --- a/src/group.cpp +++ b/src/group.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include "domain.h" #include "atom.h" @@ -32,6 +33,7 @@ #include "memory.h" #include "error.h" #include "utils.h" +#include "fmt/format.h" #include @@ -122,13 +124,8 @@ void Group::assign(int narg, char **arg) int bits = inversemask[igroup]; for (i = 0; i < nlocal; i++) mask[i] &= bits; - if (dynamic[igroup]) { - int n = strlen("GROUP_") + strlen(names[igroup]) + 1; - char *fixID = new char[n]; - sprintf(fixID,"GROUP_%s",names[igroup]); - modify->delete_fix(fixID); - delete [] fixID; - } + if (dynamic[igroup]) + modify->delete_fix(std::string("GROUP_") + names[igroup]); delete [] names[igroup]; names[igroup] = NULL; @@ -491,28 +488,15 @@ void Group::assign(int narg, char **arg) // if group is already dynamic, delete existing FixGroup - if (dynamic[igroup]) { - int n = strlen("GROUP_") + strlen(names[igroup]) + 1; - char *fixID = new char[n]; - sprintf(fixID,"GROUP_%s",names[igroup]); - modify->delete_fix(fixID); - delete [] fixID; - } + if (dynamic[igroup]) + modify->delete_fix(std::string("GROUP_") + names[igroup]); dynamic[igroup] = 1; - int n = strlen("GROUP_") + strlen(names[igroup]) + 1; - char *fixID = new char[n]; - sprintf(fixID,"GROUP_%s",names[igroup]); - - char **newarg = new char*[narg]; - newarg[0] = fixID; - newarg[1] = arg[2]; - newarg[2] = (char *) "GROUP"; - for (int i = 3; i < narg; i++) newarg[i] = arg[i]; - modify->add_fix(narg,newarg); - delete [] newarg; - delete [] fixID; + std::string fixcmd = "GROUP_"; + fixcmd += fmt::format("{} {} GROUP",names[igroup],arg[2]); + for (int i = 3; i < narg; i++) fixcmd += std::string(" ") + arg[i]; + modify->add_fix(fixcmd); // style = static // remove dynamic FixGroup if necessary @@ -521,13 +505,8 @@ void Group::assign(int narg, char **arg) if (narg != 2) error->all(FLERR,"Illegal group command"); - if (dynamic[igroup]) { - int n = strlen("GROUP_") + strlen(names[igroup]) + 1; - char *fixID = new char[n]; - sprintf(fixID,"GROUP_%s",names[igroup]); - modify->delete_fix(fixID); - delete [] fixID; - } + if (dynamic[igroup]) + modify->delete_fix(std::string("GROUP_") + names[igroup]); dynamic[igroup] = 0; @@ -546,18 +525,29 @@ void Group::assign(int narg, char **arg) MPI_Allreduce(&rlocal,&all,1,MPI_DOUBLE,MPI_SUM,world); if (me == 0) { - if (dynamic[igroup]) { - if (screen) fprintf(screen,"dynamic group %s defined\n",names[igroup]); - if (logfile) fprintf(logfile,"dynamic group %s defined\n",names[igroup]); - } else { - if (screen) - fprintf(screen,"%.15g atoms in group %s\n",all,names[igroup]); - if (logfile) - fprintf(logfile,"%.15g atoms in group %s\n",all,names[igroup]); - } + if (dynamic[igroup]) + utils::logmesg(lmp,fmt::format("dynamic group {} defined\n",names[igroup])); + else + utils::logmesg(lmp,fmt::format("{:.15g} atoms in group {}\n",all,names[igroup])); } } +/* ---------------------------------------------------------------------- + convenience function to allow assigning to groups from a single string +------------------------------------------------------------------------- */ + +void Group::assign(const std::string &groupcmd) +{ + std::vector args = utils::split_words(groupcmd); + char **newarg = new char*[args.size()]; + int i=0; + for (const auto &arg : args) { + newarg[i++] = (char *)arg.c_str(); + } + assign(args.size(),newarg); + delete[] newarg; +} + /* ---------------------------------------------------------------------- add flagged atoms to a new or existing group ------------------------------------------------------------------------- */ diff --git a/src/group.h b/src/group.h index ec913f98bc..4c7dca0835 100644 --- a/src/group.h +++ b/src/group.h @@ -16,6 +16,7 @@ #include "pointers.h" #include +#include namespace LAMMPS_NS { @@ -30,6 +31,7 @@ class Group : protected Pointers { Group(class LAMMPS *); ~Group(); void assign(int, char **); // assign atoms to a group + void assign(const std::string &); // convenience function void create(char *, int *); // add flagged atoms to a group int find(const char *); // lookup name in list of groups int find_or_create(const char *); // lookup name or create new group diff --git a/src/info.cpp b/src/info.cpp index 76e8d9bd09..de0dbb3917 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -793,7 +793,6 @@ bool Info::is_active(const char *category, const char *name) { if ((category == NULL) || (name == NULL)) return false; const char *style = "none"; - const int len = strlen(name); if (strcmp(category,"package") == 0) { if (strcmp(name,"gpu") == 0) { @@ -848,16 +847,12 @@ bool Info::is_active(const char *category, const char *name) if (!match && lmp->suffix_enable) { if (lmp->suffix) { - char *name_w_suffix = new char [len + 2 + strlen(lmp->suffix)]; - sprintf(name_w_suffix,"%s/%s",name,lmp->suffix); - if (strcmp(style,name_w_suffix) == 0) match = 1; - delete[] name_w_suffix; + std::string name_w_suffix = name + std::string("/") + lmp->suffix; + if (name_w_suffix == style) match = 1; } if (!match && lmp->suffix2) { - char *name_w_suffix = new char [len + 2 + strlen(lmp->suffix2)]; - sprintf(name_w_suffix,"%s/%s",name,lmp->suffix2); - if (strcmp(style,name_w_suffix) == 0) match = 1; - delete[] name_w_suffix; + std::string name_w_suffix = name + std::string("/") + lmp->suffix2; + if (name_w_suffix == style) match = 1; } } return match ? true : false; diff --git a/src/input.cpp b/src/input.cpp index 412084133e..e5f8034e72 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -227,11 +227,8 @@ void Input::file() // execute the command - if (execute_command()) { - char *str = new char[maxline+32]; - sprintf(str,"Unknown command: %s",line); - error->all(FLERR,str); - } + if (execute_command()) + error->all(FLERR,fmt::format("Unknown command: {}",line)); } } @@ -1246,10 +1243,10 @@ void Input::quit() char *shell_failed_message(const char* cmd, int errnum) { - const char *errmsg = strerror(errnum); - int len = strlen(cmd)+strlen(errmsg)+64; - char *msg = new char[len]; - sprintf(msg,"Shell command '%s' failed with error '%s'", cmd, errmsg); + std::string errmsg = fmt::format("Shell command '{}' failed with error '{}'", + cmd, strerror(errnum)); + char *msg = new char[errmsg.size()+1]; + strcpy(msg, errmsg.c_str()); return msg; } diff --git a/src/kspace.cpp b/src/kspace.cpp index a9356a39f1..8769409331 100644 --- a/src/kspace.cpp +++ b/src/kspace.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include "atom.h" #include "comm.h" #include "force.h" @@ -25,6 +26,7 @@ #include "error.h" #include "suffix.h" #include "domain.h" +#include "fmt/format.h" using namespace LAMMPS_NS; @@ -307,10 +309,10 @@ void KSpace::qsum_qsq(int warning_flag) // so issue warning or error if (fabs(qsum) > SMALL) { - char str[128]; - sprintf(str,"System is not charge neutral, net charge = %g",qsum); - if (!warn_nonneutral) error->all(FLERR,str); - if (warn_nonneutral == 1 && comm->me == 0) error->warning(FLERR,str); + std::string message = fmt::format("System is not charge neutral, net " + "charge = {}",qsum); + if (!warn_nonneutral) error->all(FLERR,message); + if (warn_nonneutral == 1 && comm->me == 0) error->warning(FLERR,message); warn_nonneutral = 2; } } @@ -324,12 +326,10 @@ double KSpace::estimate_table_accuracy(double q2_over_sqrt, double spr) double table_accuracy = 0.0; int nctb = force->pair->ncoultablebits; if (comm->me == 0) { - char str[128]; if (nctb) - sprintf(str," using %d-bit tables for long-range coulomb",nctb); + error->message(FLERR,fmt::format(" using {}-bit tables for long-range coulomb",nctb)); else - sprintf(str," using polynomial approximation for long-range coulomb"); - error->message(FLERR,str); + error->message(FLERR," using polynomial approximation for long-range coulomb"); } if (nctb) { diff --git a/src/lammps.cpp b/src/lammps.cpp index e0cca74e85..3b768d1862 100644 --- a/src/lammps.cpp +++ b/src/lammps.cpp @@ -667,15 +667,12 @@ LAMMPS::~LAMMPS() double totalclock = MPI_Wtime() - initclock; if ((me == 0) && (screen || logfile)) { - char outtime[128]; int seconds = fmod(totalclock,60.0); totalclock = (totalclock - seconds) / 60.0; int minutes = fmod(totalclock,60.0); int hours = (totalclock - minutes) / 60.0; - sprintf(outtime,"Total wall time: " - "%d:%02d:%02d\n", hours, minutes, seconds); - if (screen) fputs(outtime,screen); - if (logfile) fputs(outtime,logfile); + utils::logmesg(this,fmt::format("Total wall time: {}:{:02d}:{:02d}\n", + hours, minutes, seconds)); } if (universe->nworlds == 1) { diff --git a/src/lattice.cpp b/src/lattice.cpp index 98faf680e8..cc403d592d 100644 --- a/src/lattice.cpp +++ b/src/lattice.cpp @@ -21,6 +21,8 @@ #include "force.h" #include "memory.h" #include "error.h" +#include "utils.h" +#include "fmt/format.h" using namespace LAMMPS_NS; @@ -301,14 +303,10 @@ Lattice::Lattice(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) // print lattice spacings - if (comm->me == 0) { - if (screen) - fprintf(screen,"Lattice spacing in x,y,z = %g %g %g\n", - xlattice,ylattice,zlattice); - if (logfile) - fprintf(logfile,"Lattice spacing in x,y,z = %g %g %g\n", - xlattice,ylattice,zlattice); - } + if (comm->me == 0) + utils::logmesg(lmp,fmt::format("Lattice spacing in x,y,z = " + "{:.8g} {:.8g} {:.8g}\n", + xlattice,ylattice,zlattice)); } /* ---------------------------------------------------------------------- */ diff --git a/src/min.cpp b/src/min.cpp index 5207e98abe..b14137f689 100644 --- a/src/min.cpp +++ b/src/min.cpp @@ -113,18 +113,13 @@ Min::~Min() void Min::init() { if (lmp->kokkos && !kokkosable) - error->all(FLERR,"Must use a Kokkos-enabled min style (e.g. min_style cg/kk) " - "with Kokkos minimize"); + error->all(FLERR,"Must use a Kokkos-enabled min style " + "(e.g. min_style cg/kk) with Kokkos minimize"); // create fix needed for storing atom-based quantities // will delete it at end of run - char **fixarg = new char*[3]; - fixarg[0] = (char *) "MINIMIZE"; - fixarg[1] = (char *) "all"; - fixarg[2] = (char *) "MINIMIZE"; - modify->add_fix(3,fixarg); - delete [] fixarg; + modify->add_fix("MINIMIZE all MINIMIZE"); fix_minimize = (FixMinimize *) modify->fix[modify->nfix-1]; // clear out extra global and per-atom dof @@ -210,8 +205,8 @@ void Min::init() void Min::setup(int flag) { if (comm->me == 0 && screen) { - fprintf(screen,"Setting up %s style minimization ...\n", - update->minimize_style); + fmt::print(screen,"Setting up {} style minimization ...\n", + update->minimize_style); if (flag) { fmt::print(screen," Unit style : {}\n", update->unit_style); fmt::print(screen," Current step : {}\n", update->ntimestep); diff --git a/src/modify.cpp b/src/modify.cpp index f7fd18d55c..4c7e798b3b 100644 --- a/src/modify.cpp +++ b/src/modify.cpp @@ -13,6 +13,7 @@ #include "modify.h" #include +#include #include "style_compute.h" #include "style_fix.h" #include "atom.h" @@ -836,18 +837,17 @@ void Modify::add_fix(int narg, char **arg, int trysuffix) int match = 0; if (strcmp(arg[2],fix[ifix]->style) == 0) match = 1; if (!match && trysuffix && lmp->suffix_enable) { - char estyle[256]; if (lmp->suffix) { - sprintf(estyle,"%s/%s",arg[2],lmp->suffix); - if (strcmp(estyle,fix[ifix]->style) == 0) match = 1; + std::string estyle = arg[2] + std::string("/") + lmp->suffix; + if (estyle == fix[ifix]->style) match = 1; } if (lmp->suffix2) { - sprintf(estyle,"%s/%s",arg[2],lmp->suffix2); - if (strcmp(estyle,fix[ifix]->style) == 0) match = 1; + std::string estyle = arg[2] + std::string("/") + lmp->suffix2; + if (estyle == fix[ifix]->style) match = 1; } } - if (!match) error->all(FLERR, - "Replacing a fix, but new style != old style"); + if (!match) + error->all(FLERR,"Replacing a fix, but new style != old style"); if (fix[ifix]->igroup != igroup && comm->me == 0) error->warning(FLERR,"Replacing a fix, but new group != old group"); @@ -870,26 +870,24 @@ void Modify::add_fix(int narg, char **arg, int trysuffix) if (trysuffix && lmp->suffix_enable) { if (lmp->suffix) { - int n = strlen(arg[2])+strlen(lmp->suffix)+2; - char *estyle = new char[n]; - sprintf(estyle,"%s/%s",arg[2],lmp->suffix); + std::string estyle = arg[2] + std::string("/") + lmp->suffix; if (fix_map->find(estyle) != fix_map->end()) { FixCreator fix_creator = (*fix_map)[estyle]; fix[ifix] = fix_creator(lmp,narg,arg); delete[] fix[ifix]->style; - fix[ifix]->style = estyle; - } else delete[] estyle; + fix[ifix]->style = new char[estyle.size()+1]; + strcpy(fix[ifix]->style,estyle.c_str()); + } } if (fix[ifix] == NULL && lmp->suffix2) { - int n = strlen(arg[2])+strlen(lmp->suffix2)+2; - char *estyle = new char[n]; - sprintf(estyle,"%s/%s",arg[2],lmp->suffix2); + std::string estyle = arg[2] + std::string("/") + lmp->suffix2; if (fix_map->find(estyle) != fix_map->end()) { FixCreator fix_creator = (*fix_map)[estyle]; fix[ifix] = fix_creator(lmp,narg,arg); delete[] fix[ifix]->style; - fix[ifix]->style = estyle; - } else delete[] estyle; + fix[ifix]->style = new char[estyle.size()+1]; + strcpy(fix[ifix]->style,estyle.c_str()); + } } } @@ -910,16 +908,10 @@ void Modify::add_fix(int narg, char **arg, int trysuffix) fix[ifix]->restart(state_restart_global[i]); used_restart_global[i] = 1; fix[ifix]->restart_reset = 1; - if (comm->me == 0) { - if (screen) - fprintf(screen,"Resetting global fix info from restart file:\n"); - if (logfile) - fprintf(logfile,"Resetting global fix info from restart file:\n"); - if (screen) fprintf(screen," fix style: %s, fix ID: %s\n", - fix[ifix]->style,fix[ifix]->id); - if (logfile) fprintf(logfile," fix style: %s, fix ID: %s\n", - fix[ifix]->style,fix[ifix]->id); - } + if (comm->me == 0) + utils::logmesg(lmp,fmt::format("Resetting global fix info from restart file:\n" + " fix style: {}, fix ID: {}\n", + fix[ifix]->style,fix[ifix]->id)); } // check if Fix is in restart_peratom list @@ -932,16 +924,10 @@ void Modify::add_fix(int narg, char **arg, int trysuffix) for (int j = 0; j < atom->nlocal; j++) fix[ifix]->unpack_restart(j,index_restart_peratom[i]); fix[ifix]->restart_reset = 1; - if (comm->me == 0) { - if (screen) - fprintf(screen,"Resetting peratom fix info from restart file:\n"); - if (logfile) - fprintf(logfile,"Resetting peratom fix info from restart file:\n"); - if (screen) fprintf(screen," fix style: %s, fix ID: %s\n", - fix[ifix]->style,fix[ifix]->id); - if (logfile) fprintf(logfile," fix style: %s, fix ID: %s\n", - fix[ifix]->style,fix[ifix]->id); - } + if (comm->me == 0) + utils::logmesg(lmp,fmt::format("Resetting peratom fix info from restart file:\n" + " fix style: {}, fix ID: {}\n", + fix[ifix]->style,fix[ifix]->id)); } // increment nfix (if new) @@ -955,6 +941,23 @@ void Modify::add_fix(int narg, char **arg, int trysuffix) fix[ifix]->post_constructor(); } +/* ---------------------------------------------------------------------- + convenience function to allow adding a fix from a single string +------------------------------------------------------------------------- */ + +void Modify::add_fix(const std::string &fixcmd, int trysuffix) +{ + std::vector args = utils::split_words(fixcmd); + char **newarg = new char*[args.size()]; + int i=0; + for (const auto &arg : args) { + newarg[i++] = (char *)arg.c_str(); + } + add_fix(args.size(),newarg,trysuffix); + delete[] newarg; +} + + /* ---------------------------------------------------------------------- replace replaceID fix with a new fix this is used by callers to preserve ordering of fixes @@ -1028,7 +1031,7 @@ void Modify::modify_fix(int narg, char **arg) Atom class must update indices in its list of callbacks to fixes ------------------------------------------------------------------------- */ -void Modify::delete_fix(const char *id) +void Modify::delete_fix(const std::string &id) { int ifix = find_fix(id); if (ifix < 0) error->all(FLERR,"Could not find fix ID to delete"); @@ -1052,14 +1055,12 @@ void Modify::delete_fix(int ifix) return index of fix or -1 if not found ------------------------------------------------------------------------- */ -int Modify::find_fix(const char *id) +int Modify::find_fix(const std::string &id) { - if (id == NULL) return -1; - int ifix; - for (ifix = 0; ifix < nfix; ifix++) - if (strcmp(id,fix[ifix]->id) == 0) break; - if (ifix == nfix) return -1; - return ifix; + if (id.empty()) return -1; + for (int ifix = 0; ifix < nfix; ifix++) + if (id == fix[ifix]->id) return ifix; + return -1; } /* ---------------------------------------------------------------------- @@ -1164,7 +1165,7 @@ int Modify::check_rigid_list_overlap(int *select) int n = 0; for (int ifix = 0; ifix < nfix; ifix++) { - if (strncmp("rigid",fix[ifix]->style,5) == 0) { + if (utils::strmatch(fix[ifix]->style,"^rigid")) { const int * const body = (const int *)fix[ifix]->extract("body",dim); if ((body == NULL) || (dim != 1)) break; @@ -1209,26 +1210,24 @@ void Modify::add_compute(int narg, char **arg, int trysuffix) if (trysuffix && lmp->suffix_enable) { if (lmp->suffix) { - int n = strlen(arg[2])+strlen(lmp->suffix)+2; - char *estyle = new char[n]; - sprintf(estyle,"%s/%s",arg[2],lmp->suffix); + std::string estyle = arg[2] + std::string("/") + lmp->suffix; if (compute_map->find(estyle) != compute_map->end()) { ComputeCreator compute_creator = (*compute_map)[estyle]; compute[ncompute] = compute_creator(lmp,narg,arg); delete[] compute[ncompute]->style; - compute[ncompute]->style = estyle; - } else delete[] estyle; + compute[ncompute]->style = new char[estyle.size()+1]; + strcpy(compute[ncompute]->style,estyle.c_str()); + } } if (compute[ncompute] == NULL && lmp->suffix2) { - int n = strlen(arg[2])+strlen(lmp->suffix2)+2; - char *estyle = new char[n]; - sprintf(estyle,"%s/%s",arg[2],lmp->suffix2); + std::string estyle = arg[2] + std::string("/") + lmp->suffix2; if (compute_map->find(estyle) != compute_map->end()) { ComputeCreator compute_creator = (*compute_map)[estyle]; compute[ncompute] = compute_creator(lmp,narg,arg); delete[] compute[ncompute]->style; - compute[ncompute]->style = estyle; - } else delete[] estyle; + compute[ncompute]->style = new char[estyle.size()+1]; + strcpy(compute[ncompute]->style,estyle.c_str()); + } } } @@ -1244,6 +1243,23 @@ void Modify::add_compute(int narg, char **arg, int trysuffix) ncompute++; } +/* ---------------------------------------------------------------------- + convenience function to allow adding a compute from a single string +------------------------------------------------------------------------- */ + +void Modify::add_compute(const std::string &computecmd, int trysuffix) +{ + std::vector args = utils::split_words(computecmd); + char **newarg = new char*[args.size()]; + int i=0; + for (const auto &arg : args) { + newarg[i++] = (char *)arg.c_str(); + } + add_compute(args.size(),newarg,trysuffix); + delete[] newarg; +} + + /* ---------------------------------------------------------------------- one instance per compute in style_compute.h ------------------------------------------------------------------------- */ @@ -1277,7 +1293,7 @@ void Modify::modify_compute(int narg, char **arg) delete a Compute from list of Computes ------------------------------------------------------------------------- */ -void Modify::delete_compute(const char *id) +void Modify::delete_compute(const std::string &id) { int icompute = find_compute(id); if (icompute < 0) error->all(FLERR,"Could not find compute ID to delete"); @@ -1294,14 +1310,12 @@ void Modify::delete_compute(const char *id) return index of compute or -1 if not found ------------------------------------------------------------------------- */ -int Modify::find_compute(const char *id) +int Modify::find_compute(const std::string &id) { - if(id==NULL) return -1; - int icompute; - for (icompute = 0; icompute < ncompute; icompute++) - if (strcmp(id,compute[icompute]->id) == 0) break; - if (icompute == ncompute) return -1; - return icompute; + if(id.empty()) return -1; + for (int icompute = 0; icompute < ncompute; icompute++) + if (id == compute[icompute]->id) return icompute; + return -1; } /* ---------------------------------------------------------------------- @@ -1509,21 +1523,13 @@ void Modify::restart_deallocate(int flag) for (i = 0; i < nfix_restart_global; i++) if (used_restart_global[i] == 0) break; if (i == nfix_restart_global) { - if (screen) - fprintf(screen,"All restart file global fix info " - "was re-assigned\n"); - if (logfile) - fprintf(logfile,"All restart file global fix info " - "was re-assigned\n"); + utils::logmesg(lmp,"All restart file global fix info was re-assigned\n"); } else { - if (screen) fprintf(screen,"Unused restart file global fix info:\n"); - if (logfile) fprintf(logfile,"Unused restart file global fix info:\n"); + utils::logmesg(lmp,"Unused restart file global fix info:\n"); for (i = 0; i < nfix_restart_global; i++) { if (used_restart_global[i]) continue; - if (screen) fprintf(screen," fix style: %s, fix ID: %s\n", - style_restart_global[i],id_restart_global[i]); - if (logfile) fprintf(logfile," fix style: %s, fix ID: %s\n", - style_restart_global[i],id_restart_global[i]); + utils::logmesg(lmp,fmt::format(" fix style: {}, fix ID: {}\n", + style_restart_global[i],id_restart_global[i])); } } } @@ -1545,21 +1551,13 @@ void Modify::restart_deallocate(int flag) for (i = 0; i < nfix_restart_peratom; i++) if (used_restart_peratom[i] == 0) break; if (i == nfix_restart_peratom) { - if (screen) - fprintf(screen,"All restart file peratom fix info " - "was re-assigned\n"); - if (logfile) - fprintf(logfile,"All restart file peratom fix info " - "was re-assigned\n"); + utils::logmesg(lmp,"All restart file peratom fix info was re-assigned\n"); } else { - if (screen) fprintf(screen,"Unused restart file peratom fix info:\n"); - if (logfile) fprintf(logfile,"Unused restart file peratom fix info:\n"); + utils::logmesg(lmp,"Unused restart file peratom fix info:\n"); for (i = 0; i < nfix_restart_peratom; i++) { if (used_restart_peratom[i]) continue; - if (screen) fprintf(screen," fix style: %s, fix ID: %s\n", - style_restart_peratom[i],id_restart_peratom[i]); - if (logfile) fprintf(logfile," fix style: %s, fix ID: %s\n", - style_restart_peratom[i],id_restart_peratom[i]); + utils::logmesg(lmp,fmt::format(" fix style: {}, fix ID: {}\n", + style_restart_peratom[i],id_restart_peratom[i])); } } } diff --git a/src/modify.h b/src/modify.h index 0b809d4d6a..05eebc7e14 100644 --- a/src/modify.h +++ b/src/modify.h @@ -96,11 +96,12 @@ class Modify : protected Pointers { virtual int min_reset_ref(); void add_fix(int, char **, int trysuffix=1); + void add_fix(const std::string &, int trysuffix=1); void replace_fix(const char *, int, char **, int trysuffix=1); void modify_fix(int, char **); - void delete_fix(const char *); + void delete_fix(const std::string &); void delete_fix(int); - int find_fix(const char *); + int find_fix(const std::string &); int find_fix_by_style(const char *); int check_package(const char *); int check_rigid_group_overlap(int); @@ -108,9 +109,10 @@ class Modify : protected Pointers { int check_rigid_list_overlap(int *); void add_compute(int, char **, int trysuffix=1); + void add_compute(const std::string &, int trysuffix=1); void modify_compute(int, char **); - void delete_compute(const char *); - int find_compute(const char *); + void delete_compute(const std::string &); + int find_compute(const std::string &); void clearstep_compute(); void addstep_compute(bigint); diff --git a/src/molecule.cpp b/src/molecule.cpp index 0dc6bd9f0f..9864ca4f4a 100644 --- a/src/molecule.cpp +++ b/src/molecule.cpp @@ -146,24 +146,17 @@ Molecule::Molecule(LAMMPS *lmp, int narg, char **arg, int &index) : // stats - if (me == 0) { - if (screen) - fprintf(screen,"Read molecule template %s:\n %d molecules\n" - " %d atoms with max type %d\n %d bonds with max type %d\n" - " %d angles with max type %d\n %d dihedrals with max type %d\n" - " %d impropers with max type %d\n", - id,nmolecules,natoms,ntypes, - nbonds,nbondtypes,nangles,nangletypes, - ndihedrals,ndihedraltypes,nimpropers,nimpropertypes); - if (logfile) - fprintf(logfile,"Read molecule template %s:\n %d molecules\n" - " %d atoms with max type %d\n %d bonds with max type %d\n" - " %d angles with max type %d\n %d dihedrals with max type %d\n" - " %d impropers with max type %d\n", - id,nmolecules,natoms,ntypes, - nbonds,nbondtypes,nangles,nangletypes, - ndihedrals,ndihedraltypes,nimpropers,nimpropertypes); - } + if (me == 0) + utils::logmesg(lmp,fmt::format("Read molecule template {}:\n" + " {} molecules\n" + " {} atoms with max type {}\n" + " {} bonds with max type {}\n" + " {} angles with max type {}\n" + " {} dihedrals with max type {}\n" + " {} impropers with max type {}\n", + id,nmolecules,natoms,ntypes, + nbonds,nbondtypes,nangles,nangletypes, + ndihedrals,ndihedraltypes,nimpropers,nimpropertypes)); } /* ---------------------------------------------------------------------- */ diff --git a/src/neighbor.cpp b/src/neighbor.cpp index 5783c24d2d..258646f8a9 100644 --- a/src/neighbor.cpp +++ b/src/neighbor.cpp @@ -47,6 +47,7 @@ #include "memory.h" #include "error.h" #include "utils.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace NeighConst; @@ -1437,9 +1438,8 @@ void Neighbor::init_topology() void Neighbor::print_pairwise_info() { - int i,m; + int i; NeighRequest *rq; - FILE *out; const double cutghost = MAX(cutneighmax,comm->cutghostuser); @@ -1461,111 +1461,91 @@ void Neighbor::print_pairwise_info() else nperpetual++; } - for (m = 0; m < 2; m++) { - if (m == 0) out = screen; - else out = logfile; + std::string out = "Neighbor list info ...\n"; + out += fmt::format(" update every {} steps, delay {} steps, check {}\n", + every,delay,dist_check ? "yes" : "no"); + out += fmt::format(" max neighbors/atom: {}, page size: {}\n", + oneatom, pgsize); + out += fmt::format(" master list distance cutoff = {:.8g}\n",cutneighmax); + out += fmt::format(" ghost atom cutoff = {:.8g}\n",cutghost); + if (style != Neighbor::NSQ) + out += fmt::format(" binsize = {:.8g}, bins = {:g} {:g} {:g}\n",binsize, + ceil(bbox[0]/binsize), ceil(bbox[1]/binsize), + ceil(bbox[2]/binsize)); - if (out) { - fprintf(out,"Neighbor list info ...\n"); - fprintf(out," update every %d steps, delay %d steps, check %s\n", - every,delay,dist_check ? "yes" : "no"); - fprintf(out," max neighbors/atom: %d, page size: %d\n", - oneatom, pgsize); - fprintf(out," master list distance cutoff = %g\n",cutneighmax); - fprintf(out," ghost atom cutoff = %g\n",cutghost); - if (style != Neighbor::NSQ) - fprintf(out," binsize = %g, bins = %g %g %g\n",binsize, - ceil(bbox[0]/binsize), ceil(bbox[1]/binsize), - ceil(bbox[2]/binsize)); + out += fmt::format(" {} neighbor lists, perpetual/occasional/extra = {} {} {}\n", + nlist,nperpetual,noccasional,nextra); - fprintf(out," %d neighbor lists, " - "perpetual/occasional/extra = %d %d %d\n", - nlist,nperpetual,noccasional,nextra); - - for (i = 0; i < nlist; i++) { - rq = requests[i]; - if (rq->pair) { - char *pname = force->pair_match_ptr((Pair *) rq->requestor); - fprintf(out," (%d) pair %s",i+1,pname); - } else if (rq->fix) { - fprintf(out," (%d) fix %s",i+1,((Fix *) rq->requestor)->style); - } else if (rq->compute) { - fprintf(out," (%d) compute %s",i+1, - ((Compute *) rq->requestor)->style); - } else if (rq->command) { - fprintf(out," (%d) command %s",i+1,rq->command_style); - } else if (rq->neigh) { - fprintf(out," (%d) neighbor class addition",i+1); - } - - if (rq->occasional) fprintf(out,", occasional"); - else fprintf(out,", perpetual"); - - // order these to get single output of most relevant - - if (rq->copy) - fprintf(out,", copy from (%d)",rq->copylist+1); - else if (rq->halffull) - fprintf(out,", half/full from (%d)",rq->halffulllist+1); - else if (rq->skip) - fprintf(out,", skip from (%d)",rq->skiplist+1); - - fprintf(out,"\n"); - - // list of neigh list attributes - - fprintf(out," attributes: "); - if (rq->half) fprintf(out,"half"); - else if (rq->full) fprintf(out,"full"); - - if (rq->newton == 0) { - if (force->newton_pair) fprintf(out,", newton on"); - else fprintf(out,", newton off"); - } else if (rq->newton == 1) fprintf(out,", newton on"); - else if (rq->newton == 2) fprintf(out,", newton off"); - - if (rq->ghost) fprintf(out,", ghost"); - if (rq->size) fprintf(out,", size"); - if (rq->history) fprintf(out,", history"); - if (rq->granonesided) fprintf(out,", onesided"); - if (rq->respamiddle) fprintf(out,", respa outer/middle/inner"); - else if (rq->respainner) fprintf(out,", respa outer/inner"); - if (rq->bond) fprintf(out,", bond"); - if (rq->omp) fprintf(out,", omp"); - if (rq->intel) fprintf(out,", intel"); - if (rq->kokkos_device) fprintf(out,", kokkos_device"); - if (rq->kokkos_host) fprintf(out,", kokkos_host"); - if (rq->ssa) fprintf(out,", ssa"); - if (rq->cut) fprintf(out,", cut %g",rq->cutoff); - if (rq->off2on) fprintf(out,", off2on"); - fprintf(out,"\n"); - - fprintf(out," "); - if (lists[i]->pair_method == 0) fprintf(out,"pair build: none\n"); - else fprintf(out,"pair build: %s\n",pairnames[lists[i]->pair_method-1]); - - fprintf(out," "); - if (lists[i]->stencil_method == 0) fprintf(out,"stencil: none\n"); - else fprintf(out,"stencil: %s\n", - stencilnames[lists[i]->stencil_method-1]); - - fprintf(out," "); - if (lists[i]->bin_method == 0) fprintf(out,"bin: none\n"); - else fprintf(out,"bin: %s\n",binnames[lists[i]->bin_method-1]); - } - - /* - fprintf(out," %d stencil methods\n",nstencil); - for (i = 0; i < nstencil; i++) - fprintf(out," (%d) %s\n", - i+1,stencilnames[neigh_stencil[i]->istyle-1]); - - fprintf(out," %d bin methods\n",nbin); - for (i = 0; i < nbin; i++) - fprintf(out," (%d) %s\n",i+1,binnames[neigh_bin[i]->istyle-1]); - */ + for (i = 0; i < nlist; i++) { + rq = requests[i]; + if (rq->pair) { + char *pname = force->pair_match_ptr((Pair *) rq->requestor); + out += fmt::format(" ({}) pair {}",i+1,pname); + } else if (rq->fix) { + out += fmt::format(" ({}) fix {}",i+1,((Fix *) rq->requestor)->style); + } else if (rq->compute) { + out += fmt::format(" ({}) compute {}",i+1,((Compute *) rq->requestor)->style); + } else if (rq->command) { + out += fmt::format(" ({}) command {}",i+1,rq->command_style); + } else if (rq->neigh) { + out += fmt::format(" ({}) neighbor class addition",i+1); } + + if (rq->occasional) out += ", occasional"; + else out += ", perpetual"; + + // order these to get single output of most relevant + + if (rq->copy) + out += fmt::format(", copy from ({})",rq->copylist+1); + else if (rq->halffull) + out += fmt::format(", half/full from ({})",rq->halffulllist+1); + else if (rq->skip) + out += fmt::format(", skip from ({})",rq->skiplist+1); + out += "\n"; + + // list of neigh list attributes + + out += " attributes: "; + if (rq->half) out += "half"; + else if (rq->full) out += "full"; + + if (rq->newton == 0) { + if (force->newton_pair) out += ", newton on"; + else out += ", newton off"; + } else if (rq->newton == 1) out += ", newton on"; + else if (rq->newton == 2) out += ", newton off"; + + if (rq->ghost) out += ", ghost"; + if (rq->size) out += ", size"; + if (rq->history) out += ", history"; + if (rq->granonesided) out += ", onesided"; + if (rq->respamiddle) out += ", respa outer/middle/inner"; + else if (rq->respainner) out += ", respa outer/inner"; + if (rq->bond) out += ", bond"; + if (rq->omp) out += ", omp"; + if (rq->intel) out += ", intel"; + if (rq->kokkos_device) out += ", kokkos_device"; + if (rq->kokkos_host) out += ", kokkos_host"; + if (rq->ssa) out += ", ssa"; + if (rq->cut) out += fmt::format(", cut {}",rq->cutoff); + if (rq->off2on) out += ", off2on"; + out += "\n"; + + out += " "; + if (lists[i]->pair_method == 0) out += "pair build: none\n"; + else out += fmt::format("pair build: {}\n",pairnames[lists[i]->pair_method-1]); + + out += " "; + if (lists[i]->stencil_method == 0) out += "stencil: none\n"; + else out += fmt::format("stencil: {}\n",stencilnames[lists[i]->stencil_method-1]); + + out += " "; + if (lists[i]->bin_method == 0) out += "bin: none\n"; + else out += fmt::format("bin: {}\n",binnames[lists[i]->bin_method-1]); + } + utils::logmesg(lmp,out); } /* ---------------------------------------------------------------------- diff --git a/src/ntopo_improper_partial.cpp b/src/ntopo_improper_partial.cpp index f2afc68387..c4c6ec3177 100644 --- a/src/ntopo_improper_partial.cpp +++ b/src/ntopo_improper_partial.cpp @@ -97,10 +97,7 @@ void NTopoImproperPartial::build() int all; MPI_Allreduce(&nmissing,&all,1,MPI_INT,MPI_SUM,world); - if (all) { - char str[128]; - sprintf(str, - "Improper atoms missing at step " BIGINT_FORMAT,update->ntimestep); - if (me == 0) error->warning(FLERR,str); - } + if (all && me == 0) + error->warning(FLERR,fmt::format("Improper atoms missing at step {}", + update->ntimestep)); } diff --git a/src/output.cpp b/src/output.cpp index ee3d5b3996..42d73f2c31 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -46,28 +46,13 @@ Output::Output(LAMMPS *lmp) : Pointers(lmp) { // create default computes for temp,pressure,pe - char **newarg = new char*[4]; - newarg[0] = (char *) "thermo_temp"; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "temp"; - modify->add_compute(3,newarg); - - newarg[0] = (char *) "thermo_press"; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pressure"; - newarg[3] = (char *) "thermo_temp"; - modify->add_compute(4,newarg); - - newarg[0] = (char *) "thermo_pe"; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "pe"; - modify->add_compute(3,newarg); - - delete [] newarg; + modify->add_compute("thermo_temp all temp"); + modify->add_compute("thermo_press all pressure thermo_temp"); + modify->add_compute("thermo_pe all pe"); // create default Thermo class - newarg = new char*[1]; + char **newarg = new char*[1]; newarg[0] = (char *) "one"; thermo = new Thermo(lmp,1,newarg); delete [] newarg; diff --git a/src/pair.cpp b/src/pair.cpp index c18b84a8ed..432680b324 100644 --- a/src/pair.cpp +++ b/src/pair.cpp @@ -66,6 +66,7 @@ Pair::Pair(LAMMPS *lmp) : Pointers(lmp) no_virial_fdotr_compute = 0; writedata = 0; ghostneigh = 0; + unit_convert_flag = utils::NOCONVERT; nextra = 0; pvector = NULL; diff --git a/src/pair.h b/src/pair.h index d0aee8cd7f..0664e97462 100644 --- a/src/pair.h +++ b/src/pair.h @@ -53,6 +53,7 @@ class Pair : protected Pointers { int respa_enable; // 1 if inner/middle/outer rRESPA routines int one_coeff; // 1 if allows only one coeff * * call int manybody_flag; // 1 if a manybody potential + int unit_convert_flag; // value != 0 indicates support for unit conversion. int no_virial_fdotr_compute; // 1 if does not invoke virial_fdotr_compute() int writedata; // 1 if writes coeffs to data file int ghostneigh; // 1 if pair style needs neighbors of ghosts diff --git a/src/pair_table.cpp b/src/pair_table.cpp index 312420c354..36eced6d3f 100644 --- a/src/pair_table.cpp +++ b/src/pair_table.cpp @@ -44,6 +44,7 @@ PairTable::PairTable(LAMMPS *lmp) : Pair(lmp) { ntables = 0; tables = NULL; + unit_convert_flag = utils::get_supported_conversions(utils::ENERGY); } /* ---------------------------------------------------------------------- */ @@ -69,7 +70,6 @@ void PairTable::compute(int eflag, int vflag) int i,j,ii,jj,inum,jnum,itype,jtype,itable; double xtmp,ytmp,ztmp,delx,dely,delz,evdwl,fpair; double rsq,factor_lj,fraction,value,a,b; - char estr[128]; int *ilist,*jlist,*numneigh,**firstneigh; Table *tb; @@ -115,37 +115,28 @@ void PairTable::compute(int eflag, int vflag) if (rsq < cutsq[itype][jtype]) { tb = &tables[tabindex[itype][jtype]]; - if (rsq < tb->innersq) { - sprintf(estr,"Pair distance < table inner cutoff: " - "ijtype %d %d dist %g",itype,jtype,sqrt(rsq)); - error->one(FLERR,estr); - } - + if (rsq < tb->innersq) + error->one(FLERR,fmt::format("Pair distance < table inner cutoff: " + "ijtype {} {} dist {}",itype,jtype,sqrt(rsq))); if (tabstyle == LOOKUP) { itable = static_cast ((rsq - tb->innersq) * tb->invdelta); - if (itable >= tlm1) { - sprintf(estr,"Pair distance > table outer cutoff: " - "ijtype %d %d dist %g",itype,jtype,sqrt(rsq)); - error->one(FLERR,estr); - } + if (itable >= tlm1) + error->one(FLERR,fmt::format("Pair distance > table outer cutoff: " + "ijtype {} {} dist {}",itype,jtype,sqrt(rsq))); fpair = factor_lj * tb->f[itable]; } else if (tabstyle == LINEAR) { itable = static_cast ((rsq - tb->innersq) * tb->invdelta); - if (itable >= tlm1) { - sprintf(estr,"Pair distance > table outer cutoff: " - "ijtype %d %d dist %g",itype,jtype,sqrt(rsq)); - error->one(FLERR,estr); - } + if (itable >= tlm1) + error->one(FLERR,fmt::format("Pair distance > table outer cutoff: " + "ijtype {} {} dist {}",itype,jtype,sqrt(rsq))); fraction = (rsq - tb->rsq[itable]) * tb->invdelta; value = tb->f[itable] + fraction*tb->df[itable]; fpair = factor_lj * value; } else if (tabstyle == SPLINE) { itable = static_cast ((rsq - tb->innersq) * tb->invdelta); - if (itable >= tlm1) { - sprintf(estr,"Pair distance > table outer cutoff: " - "ijtype %d %d dist %g",itype,jtype,sqrt(rsq)); - error->one(FLERR,estr); - } + if (itable >= tlm1) + error->one(FLERR,fmt::format("Pair distance > table outer cutoff: " + "ijtype {} {} dist {}",itype,jtype,sqrt(rsq))); b = (rsq - tb->rsq[itable]) * tb->invdelta; a = 1.0 - b; value = a * tb->f[itable] + b * tb->f[itable+1] + @@ -358,9 +349,14 @@ double PairTable::init_one(int i, int j) void PairTable::read_table(Table *tb, char *file, char *keyword) { - TableFileReader reader(lmp, file, "pair"); + TableFileReader reader(lmp, file, "pair", unit_convert_flag); - char * line = reader.find_section_start(keyword); + // transparently convert units for supported conversions + + int unit_convert = reader.get_unit_convert(); + double conversion_factor = utils::get_conversion_factor(utils::ENERGY, + unit_convert); + char *line = reader.find_section_start(keyword); if (!line) { error->one(FLERR,"Did not find keyword in table file"); @@ -370,7 +366,7 @@ void PairTable::read_table(Table *tb, char *file, char *keyword) // allocate table arrays for file values line = reader.next_line(); - param_extract(tb,line); + param_extract(tb, line); memory->create(tb->rfile,tb->ninput,"pair:rfile"); memory->create(tb->efile,tb->ninput,"pair:efile"); memory->create(tb->ffile,tb->ninput,"pair:ffile"); @@ -404,8 +400,8 @@ void PairTable::read_table(Table *tb, char *file, char *keyword) ValueTokenizer values(line); values.next_int(); rfile = values.next_double(); - tb->efile[i] = values.next_double(); - tb->ffile[i] = values.next_double(); + tb->efile[i] = conversion_factor * values.next_double(); + tb->ffile[i] = conversion_factor * values.next_double(); } catch (TokenizerException & e) { ++cerror; } @@ -461,29 +457,26 @@ void PairTable::read_table(Table *tb, char *file, char *keyword) } } - if (ferror) { - std::string str = fmt::format("{} of {} force values in table are inconsistent with -dE/dr.\n" - " Should only be flagged at inflection points",ferror,tb->ninput); - error->warning(FLERR,str.c_str()); - } + if (ferror) + error->warning(FLERR,fmt::format("{} of {} force values in table are " + "inconsistent with -dE/dr.\n Should " + "only be flagged at inflection points", + ferror,tb->ninput)); // warn if re-computed distance values differ from file values - if (rerror) { - char str[128]; - sprintf(str,"%d of %d distance values in table with relative error\n" - " over %g to re-computed values",rerror,tb->ninput,EPSILONR); - error->warning(FLERR,str); - } + if (rerror) + error->warning(FLERR,fmt::format("{} of {} distance values in table with " + "relative error\n over {} to " + "re-computed values", + rerror,tb->ninput,EPSILONR)); // warn if data was read incompletely, e.g. columns were missing - if (cerror) { - char str[128]; - sprintf(str,"%d of %d lines in table were incomplete\n" - " or could not be parsed completely",cerror,tb->ninput); - error->warning(FLERR,str); - } + if (cerror) + error->warning(FLERR,fmt::format("{} of {} lines in table were " + "incomplete\n or could not be parsed " + "completely",cerror,tb->ninput)); } /* ---------------------------------------------------------------------- @@ -1039,11 +1032,15 @@ void *PairTable::extract(const char *str, int &dim) if (strcmp(str,"cut_coul") != 0) return NULL; if (ntables == 0) error->all(FLERR,"All pair coeffs are not set"); - double cut_coul = tables[0].cut; - for (int m = 1; m < ntables; m++) - if (tables[m].cut != cut_coul) - error->all(FLERR, - "Pair table cutoffs must all be equal to use with KSpace"); - dim = 0; - return &tables[0].cut; + // only check for cutoff consistency if claiming to be KSpace compatible + + if (ewaldflag || pppmflag || msmflag || dispersionflag || tip4pflag) { + double cut_coul = tables[0].cut; + for (int m = 1; m < ntables; m++) + if (tables[m].cut != cut_coul) + error->all(FLERR, + "Pair table cutoffs must all be equal to use with KSpace"); + dim = 0; + return &tables[0].cut; + } else return NULL; } diff --git a/src/potential_file_reader.cpp b/src/potential_file_reader.cpp index 1cc77351a9..47283fd574 100644 --- a/src/potential_file_reader.cpp +++ b/src/potential_file_reader.cpp @@ -31,11 +31,13 @@ using namespace LAMMPS_NS; PotentialFileReader::PotentialFileReader(LAMMPS *lmp, const std::string &filename, - const std::string &potential_name) : + const std::string &potential_name, + const int auto_convert) : Pointers(lmp), reader(nullptr), filename(filename), - filetype(potential_name + " potential") + filetype(potential_name + " potential"), + unit_convert(auto_convert) { if (comm->me != 0) { error->one(FLERR, "FileReader should only be called by proc 0!"); @@ -143,7 +145,7 @@ std::string PotentialFileReader::next_string() { return ""; } -TextFileReader * PotentialFileReader::open_potential(const std::string& path) { +TextFileReader *PotentialFileReader::open_potential(const std::string &path) { std::string filepath = utils::get_potential_file_path(path); if (!filepath.empty()) { @@ -151,15 +153,30 @@ TextFileReader * PotentialFileReader::open_potential(const std::string& path) { std::string date = utils::get_potential_date(filepath, filetype); std::string units = utils::get_potential_units(filepath, filetype); - if (!date.empty()) { - utils::logmesg(lmp, fmt::format("Reading potential file {} with DATE: {}\n", filename, date)); - } + if (!date.empty()) + utils::logmesg(lmp, fmt::format("Reading {} file {} with DATE: {}\n", + filetype, filename, date)); - if (!units.empty() && (units != unit_style)) { - lmp->error->one(FLERR, fmt::format("Potential file {} requires {} units " - "but {} units are in use",filename, units, unit_style)); + if (units.empty()) { + unit_convert = utils::NOCONVERT; + } else { + if (units == unit_style) { + unit_convert = utils::NOCONVERT; + } else { + if ((units == "metal") && (unit_style == "real") && (unit_convert & utils::METAL2REAL)) { + unit_convert = utils::METAL2REAL; + } else if ((units == "real") && (unit_style == "metal") && (unit_convert & utils::REAL2METAL)) { + unit_convert = utils::REAL2METAL; + } else { + lmp->error->one(FLERR, fmt::format("{} file {} requires {} units " + "but {} units are in use", filetype, + filename, units, unit_style)); + } + } } - + if (unit_convert != utils::NOCONVERT) + lmp->error->warning(FLERR, fmt::format("Converting {} in {} units to {} " + "units", filetype, units, unit_style)); return new TextFileReader(filepath, filetype); } return nullptr; diff --git a/src/potential_file_reader.h b/src/potential_file_reader.h index a73f5fdbaa..9094d3957a 100644 --- a/src/potential_file_reader.h +++ b/src/potential_file_reader.h @@ -28,22 +28,25 @@ namespace LAMMPS_NS { class PotentialFileReader : protected Pointers { protected: - TextFileReader * reader; + TextFileReader *reader; std::string filename; std::string filetype; + int unit_convert; - TextFileReader * open_potential(const std::string& path); + TextFileReader *open_potential(const std::string& path); public: - PotentialFileReader(class LAMMPS *lmp, const std::string &filename, const std::string &potential_name); + PotentialFileReader(class LAMMPS *lmp, const std::string &filename, + const std::string &potential_name, + const int auto_convert = 0); virtual ~PotentialFileReader(); void ignore_comments(bool value); void skip_line(); - char * next_line(int nparams = 0); - void next_dvector(double * list, int n); - ValueTokenizer next_values(int nparams, const std::string & separators = TOKENIZER_DEFAULT_SEPARATORS); + char *next_line(int nparams = 0); + void next_dvector(double *list, int n); + ValueTokenizer next_values(int nparams, const std::string &separators = TOKENIZER_DEFAULT_SEPARATORS); // convenience functions double next_double(); @@ -51,6 +54,9 @@ namespace LAMMPS_NS tagint next_tagint(); bigint next_bigint(); std::string next_string(); + + // unit conversion info + int get_unit_convert() const { return unit_convert; } }; } // namespace LAMMPS_NS diff --git a/src/read_data.cpp b/src/read_data.cpp index 1ccbccb835..244ce12625 100644 --- a/src/read_data.cpp +++ b/src/read_data.cpp @@ -897,7 +897,7 @@ void ReadData::command(int narg, char **arg) MPI_Barrier(world); if (comm->me == 0) - utils::logmesg(lmp,fmt::format(" read_data CPU = {:.3f} secs\n", + utils::logmesg(lmp,fmt::format(" read_data CPU = {:.3f} seconds\n", MPI_Wtime()-time1)); } @@ -1157,11 +1157,8 @@ void ReadData::header(int firstpass) parse_keyword(1); for (n = 0; n < NSECTIONS; n++) if (strcmp(keyword,section_keywords[n]) == 0) break; - if (n == NSECTIONS) { - char str[128]; - sprintf(str,"Unknown identifier in data file: %s",keyword); - error->all(FLERR,str); - } + if (n == NSECTIONS) + error->all(FLERR,fmt::format("Unknown identifier in data file: {}",keyword)); // error checks on header values // must be consistent with atom style and other header values diff --git a/src/read_dump.cpp b/src/read_dump.cpp index 99e9486679..0426323a21 100644 --- a/src/read_dump.cpp +++ b/src/read_dump.cpp @@ -289,13 +289,9 @@ bigint ReadDump::seek(bigint nrequest, int exact) for (ifile = 0; ifile < nfile; ifile++) { ntimestep = -1; if (multiproc) { - char *ptr = strchr(files[ifile],'%'); - char *multiname = new char[strlen(files[ifile]) + 16]; - *ptr = '\0'; - sprintf(multiname,"%s%d%s",files[ifile],0,ptr+1); - *ptr = '%'; - readers[0]->open_file(multiname); - delete [] multiname; + std::string multiname = files[ifile]; + multiname.replace(multiname.find("%"),1,"0"); + readers[0]->open_file(multiname.c_str()); } else readers[0]->open_file(files[ifile]); while (1) { @@ -337,13 +333,9 @@ bigint ReadDump::seek(bigint nrequest, int exact) if (multiproc && filereader) { for (int i = 0; i < nreader; i++) { if (me == 0 && i == 0) continue; // proc 0, reader 0 already found it - char *ptr = strchr(files[currentfile],'%'); - char *multiname = new char[strlen(files[currentfile]) + 16]; - *ptr = '\0'; - sprintf(multiname,"%s%d%s",files[currentfile],firstfile+i,ptr+1); - *ptr = '%'; - readers[i]->open_file(multiname); - delete [] multiname; + std::string multiname = files[currentfile]; + multiname.replace(multiname.find("%"),1,fmt::format("{}",firstfile+i)); + readers[i]->open_file(multiname.c_str()); bigint step; while (1) { @@ -389,13 +381,9 @@ bigint ReadDump::next(bigint ncurrent, bigint nlast, int nevery, int nskip) ntimestep = -1; if (ifile != currentfile) { if (multiproc) { - char *ptr = strchr(files[ifile],'%'); - char *multiname = new char[strlen(files[ifile]) + 16]; - *ptr = '\0'; - sprintf(multiname,"%s%d%s",files[ifile],0,ptr+1); - *ptr = '%'; - readers[0]->open_file(multiname); - delete [] multiname; + std::string multiname = files[ifile]; + multiname.replace(multiname.find("%"),1,"0"); + readers[0]->open_file(multiname.c_str()); } else readers[0]->open_file(files[ifile]); } @@ -447,13 +435,9 @@ bigint ReadDump::next(bigint ncurrent, bigint nlast, int nevery, int nskip) if (multiproc && filereader) { for (int i = 0; i < nreader; i++) { if (me == 0 && i == 0) continue; - char *ptr = strchr(files[currentfile],'%'); - char *multiname = new char[strlen(files[currentfile]) + 16]; - *ptr = '\0'; - sprintf(multiname,"%s%d%s",files[currentfile],firstfile+i,ptr+1); - *ptr = '%'; - readers[i]->open_file(multiname); - delete [] multiname; + std::string multiname = files[currentfile]; + multiname.replace(multiname.find("%"),1,fmt::format("{}",firstfile+i)); + readers[i]->open_file(multiname.c_str()); bigint step; while (1) { diff --git a/src/read_restart.cpp b/src/read_restart.cpp index ade751fdef..c4631619e1 100644 --- a/src/read_restart.cpp +++ b/src/read_restart.cpp @@ -104,19 +104,14 @@ void ReadRestart::command(int narg, char **arg) if (me == 0) { if (screen) fprintf(screen,"Reading restart file ...\n"); - char *hfile; + std::string hfile = file; if (multiproc) { - hfile = new char[strlen(file) + 16]; - char *ptr = strchr(file,'%'); - *ptr = '\0'; - sprintf(hfile,"%s%s%s",file,"base",ptr+1); - *ptr = '%'; - } else hfile = file; - fp = fopen(hfile,"rb"); + hfile.replace(hfile.find("%"),1,"base"); + } + fp = fopen(hfile.c_str(),"rb"); if (fp == NULL) error->one(FLERR,fmt::format("Cannot open restart file {}: {}", hfile, utils::getsyserror())); - if (multiproc) delete [] hfile; } // read magic string, endian flag, format revision @@ -272,14 +267,10 @@ void ReadRestart::command(int narg, char **arg) else if (nprocs <= multiproc_file) { - char *procfile = new char[strlen(file) + 16]; - char *ptr = strchr(file,'%'); - for (int iproc = me; iproc < multiproc_file; iproc += nprocs) { - *ptr = '\0'; - sprintf(procfile,"%s%d%s",file,iproc,ptr+1); - *ptr = '%'; - fp = fopen(procfile,"rb"); + std::string procfile = file; + procfile.replace(procfile.find("%"),1,fmt::format("{}",iproc)); + fp = fopen(procfile.c_str(),"rb"); if (fp == NULL) error->one(FLERR,fmt::format("Cannot open restart file {}: {}", procfile, utils::getsyserror())); @@ -309,8 +300,6 @@ void ReadRestart::command(int narg, char **arg) fclose(fp); fp = NULL; } - - delete [] procfile; } // input of multiple native files with procs > files @@ -343,16 +332,12 @@ void ReadRestart::command(int narg, char **arg) MPI_Comm_split(world,icluster,0,&clustercomm); if (filereader) { - char *procfile = new char[strlen(file) + 16]; - char *ptr = strchr(file,'%'); - *ptr = '\0'; - sprintf(procfile,"%s%d%s",file,icluster,ptr+1); - *ptr = '%'; - fp = fopen(procfile,"rb"); + std::string procfile = file; + procfile.replace(procfile.find("%"),1,fmt::format("{}",icluster)); + fp = fopen(procfile.c_str(),"rb"); if (fp == NULL) error->one(FLERR,fmt::format("Cannot open restart file {}: {}", procfile, utils::getsyserror())); - delete [] procfile; } int flag,procsperfile; @@ -438,19 +423,9 @@ void ReadRestart::command(int narg, char **arg) // create a temporary fix to hold and migrate extra atom info // necessary b/c irregular will migrate atoms - if (nextra) { - char cextra[8],fixextra[8]; - sprintf(cextra,"%d",nextra); - sprintf(fixextra,"%d",modify->nfix_restart_peratom); - char **newarg = new char*[5]; - newarg[0] = (char *) "_read_restart"; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "READ_RESTART"; - newarg[3] = cextra; - newarg[4] = fixextra; - modify->add_fix(5,newarg); - delete [] newarg; - } + if (nextra) + modify->add_fix(fmt::format("_read_restart all READ_RESTART {} {}", + nextra,modify->nfix_restart_peratom)); // move atoms to new processors via irregular() // turn sorting on in migrate_atoms() to avoid non-reproducible restarts @@ -534,14 +509,10 @@ void ReadRestart::command(int narg, char **arg) // total time MPI_Barrier(world); - double time2 = MPI_Wtime(); - if (comm->me == 0) { - if (screen) - fprintf(screen," read_restart CPU = %g secs\n",time2-time1); - if (logfile) - fprintf(logfile," read_restart CPU = %g secs\n",time2-time1); - } + if (comm->me == 0) + utils::logmesg(lmp,fmt::format(" read_restart CPU = {:.3f} seconds\n", + MPI_Wtime()-time1)); } /* ---------------------------------------------------------------------- @@ -618,10 +589,9 @@ void ReadRestart::file_search(char *inpfile, char *outfile) // create outfile with maxint substituted for "*" // use original inpfile, not pattern, since need to retain "%" in filename - ptr = strchr(inpfile,'*'); - *ptr = '\0'; - sprintf(outfile,"%s" BIGINT_FORMAT "%s",inpfile,maxnum,ptr+1); - *ptr = '*'; + std::string newoutfile = inpfile; + newoutfile.replace(newoutfile.find("*"),1,fmt::format("{}",maxnum)); + strcpy(outfile,newoutfile.c_str()); // clean up @@ -826,12 +796,8 @@ void ReadRestart::header() for (int i = 0; i < nargcopy; i++) argcopy[i] = read_string(); atom->create_avec(style,nargcopy,argcopy,1); - if (comm->me ==0) { - if (screen) fprintf(screen," restoring atom style %s from " - "restart\n", style); - if (logfile) fprintf(logfile," restoring atom style %s from " - "restart\n", style); - } + if (comm->me ==0) + utils::logmesg(lmp,fmt::format(" restoring atom style {} from restart\n",style)); for (int i = 0; i < nargcopy; i++) delete [] argcopy[i]; delete [] argcopy; delete [] style; @@ -963,22 +929,16 @@ void ReadRestart::force_fields() style = read_string(); force->create_pair(style,1); delete [] style; - if (comm->me ==0) { - if (screen) fprintf(screen," restoring pair style %s from " - "restart\n", force->pair_style); - if (logfile) fprintf(logfile," restoring pair style %s from " - "restart\n", force->pair_style); - } + if (comm->me ==0) + utils::logmesg(lmp,fmt::format(" restoring pair style {} from " + "restart\n", force->pair_style)); force->pair->read_restart(fp); } else if (flag == NO_PAIR) { style = read_string(); - if (comm->me ==0) { - if (screen) fprintf(screen," pair style %s stores no " - "restart info\n", style); - if (logfile) fprintf(logfile," pair style %s stores no " - "restart info\n", style); - } + if (comm->me ==0) + utils::logmesg(lmp,fmt::format(" pair style {} stores no " + "restart info\n", style)); force->create_pair("none",0); force->pair_restart = style; @@ -986,48 +946,36 @@ void ReadRestart::force_fields() style = read_string(); force->create_bond(style,1); delete [] style; - if (comm->me ==0) { - if (screen) fprintf(screen," restoring bond style %s from " - "restart\n", force->bond_style); - if (logfile) fprintf(logfile," restoring bond style %s from " - "restart\n", force->bond_style); - } + if (comm->me ==0) + utils::logmesg(lmp,fmt::format(" restoring bond style {} from " + "restart\n", force->bond_style)); force->bond->read_restart(fp); } else if (flag == ANGLE) { style = read_string(); force->create_angle(style,1); delete [] style; - if (comm->me ==0) { - if (screen) fprintf(screen," restoring angle style %s from " - "restart\n", force->angle_style); - if (logfile) fprintf(logfile," restoring angle style %s from " - "restart\n", force->angle_style); - } + if (comm->me ==0) + utils::logmesg(lmp,fmt::format(" restoring angle style {} from " + "restart\n", force->angle_style)); force->angle->read_restart(fp); } else if (flag == DIHEDRAL) { style = read_string(); force->create_dihedral(style,1); delete [] style; - if (comm->me ==0) { - if (screen) fprintf(screen," restoring dihedral style %s from " - "restart\n", force->dihedral_style); - if (logfile) fprintf(logfile," restoring dihedral style %s from " - "restart\n", force->dihedral_style); - } + if (comm->me ==0) + utils::logmesg(lmp,fmt::format(" restoring dihedral style {} from " + "restart\n", force->dihedral_style)); force->dihedral->read_restart(fp); } else if (flag == IMPROPER) { style = read_string(); force->create_improper(style,1); delete [] style; - if (comm->me ==0) { - if (screen) fprintf(screen," restoring improper style %s from " - "restart\n", force->improper_style); - if (logfile) fprintf(logfile," restoring improper style %s from " - "restart\n", force->improper_style); - } + if (comm->me ==0) + utils::logmesg(lmp,fmt::format(" restoring improper style {} from " + "restart\n", force->improper_style)); force->improper->read_restart(fp); } else error->all(FLERR, diff --git a/src/replicate.cpp b/src/replicate.cpp index bd4be44e53..d265a9e3e5 100644 --- a/src/replicate.cpp +++ b/src/replicate.cpp @@ -777,12 +777,8 @@ void Replicate::command(int narg, char **arg) // total time MPI_Barrier(world); - double time2 = MPI_Wtime(); - if (me == 0) { - if (screen) - fprintf(screen," replicate CPU = %g secs\n",time2-time1); - if (logfile) - fprintf(logfile," replicate CPU = %g secs\n",time2-time1); - } + if (me == 0) + utils::logmesg(lmp,fmt::format(" replicate CPU = {:.3f} seconds\n", + MPI_Wtime()-time1)); } diff --git a/src/reset_ids.cpp b/src/reset_ids.cpp index b8255cd273..671ba7940f 100644 --- a/src/reset_ids.cpp +++ b/src/reset_ids.cpp @@ -24,6 +24,7 @@ #include "memory.h" #include "error.h" #include "utils.h" +#include "fmt/format.h" using namespace LAMMPS_NS; @@ -252,12 +253,9 @@ void ResetIDs::command(int narg, char **arg) int all; MPI_Allreduce(&badcount,&all,1,MPI_INT,MPI_SUM,world); - if (all) { - char str[128]; - sprintf(str,"Reset_ids missing %d bond topology atom IDs - " - "use comm_modify cutoff",all); - error->all(FLERR,str); - } + if (all) + error->all(FLERR,fmt::format("Reset_ids missing {} bond topology atom IDs - " + "use comm_modify cutoff",all)); // reset IDs and atom map for owned atoms diff --git a/src/respa.cpp b/src/respa.cpp index 8a94b18736..f894333e39 100644 --- a/src/respa.cpp +++ b/src/respa.cpp @@ -299,22 +299,11 @@ void Respa::init() // create fix needed for storing atom-based respa level forces // will delete it at end of run - - char **fixarg = new char*[5]; - fixarg[0] = (char *) "RESPA"; - fixarg[1] = (char *) "all"; - fixarg[2] = (char *) "RESPA"; - fixarg[3] = new char[8]; - sprintf(fixarg[3],"%d",nlevels); // if supported, we also store torques on a per-level basis - if (atom->torque_flag) { - fixarg[4] = (char *) "torque"; - modify->add_fix(5,fixarg); - } else { - modify->add_fix(4,fixarg); - } - delete [] fixarg[3]; - delete [] fixarg; + + std::string cmd = fmt::format("RESPA all RESPA {}",nlevels); + if (atom->torque_flag) modify->add_fix(cmd + " torque"); + else modify->add_fix(cmd); fix_respa = (FixRespa *) modify->fix[modify->nfix-1]; // insure respa inner/middle/outer is using Pair class that supports it diff --git a/src/special.cpp b/src/special.cpp index 3b2969e427..af770ea29e 100644 --- a/src/special.cpp +++ b/src/special.cpp @@ -63,8 +63,8 @@ void Special::build() const double * const special_lj = force->special_lj; const double * const special_coul = force->special_coul; fmt::print(screen,"Finding 1-2 1-3 1-4 neighbors ...\n" - " special bond factors lj: {:<10g} {:<10g} {:<10g}\n" - " special bond factors coul: {:<10g} {:<10g} {:<10g}\n", + " special bond factors lj: {:<8g} {:<8g} {:<8g}\n" + " special bond factors coul: {:<8g} {:<8g} {:<8g}\n", special_lj[1],special_lj[2],special_lj[3], special_coul[1],special_coul[2],special_coul[3]); } @@ -1314,6 +1314,6 @@ void Special::fix_alteration() void Special::timer_output(double time1) { if (comm->me == 0) - utils::logmesg(lmp,fmt::format(" special bonds CPU = {:<.3g} secs\n", + utils::logmesg(lmp,fmt::format(" special bonds CPU = {:.3f} seconds\n", MPI_Wtime()-time1)); } diff --git a/src/table_file_reader.cpp b/src/table_file_reader.cpp index 2f3317cb2a..525db24961 100644 --- a/src/table_file_reader.cpp +++ b/src/table_file_reader.cpp @@ -27,17 +27,18 @@ using namespace LAMMPS_NS; TableFileReader::TableFileReader(LAMMPS *lmp, - const std::string &filename, - const std::string &type) : - PotentialFileReader(lmp, filename, type + " table") + const std::string &filename, + const std::string &type, + const int auto_convert) : + PotentialFileReader(lmp, filename, type + " table", auto_convert) { } TableFileReader::~TableFileReader() { } -char * TableFileReader::find_section_start(const std::string & keyword) { - char * line = nullptr; +char *TableFileReader::find_section_start(const std::string & keyword) { + char *line = nullptr; while ((line = reader->next_line())) { ValueTokenizer values(line); std::string word = values.next_string(); diff --git a/src/table_file_reader.h b/src/table_file_reader.h index 209c649346..962ddf4209 100644 --- a/src/table_file_reader.h +++ b/src/table_file_reader.h @@ -24,10 +24,11 @@ namespace LAMMPS_NS { class TableFileReader : public PotentialFileReader { public: - TableFileReader(class LAMMPS *lmp, const std::string &filename, const std::string & type); + TableFileReader(class LAMMPS *lmp, const std::string &filename, + const std::string &type, const int auto_convert = 0); virtual ~TableFileReader(); - char * find_section_start(const std::string & keyword); + char *find_section_start(const std::string &keyword); }; } // namespace LAMMPS_NS diff --git a/src/thermo.cpp b/src/thermo.cpp index 339b641bb2..dddfb8b21c 100644 --- a/src/thermo.cpp +++ b/src/thermo.cpp @@ -45,6 +45,7 @@ #include "error.h" #include "math_const.h" #include "utils.h" +#include "fmt/format.h" using namespace LAMMPS_NS; using namespace MathConst; @@ -315,8 +316,8 @@ void Thermo::header() std::string hdr; for (int i = 0; i < nfield; i++) hdr += keyword[i] + std::string(" "); - hdr += "\n"; - if (me == 0) utils::logmesg(lmp,hdr); + + if (me == 0) utils::logmesg(lmp,hdr+"\n"); } /* ---------------------------------------------------------------------- */ @@ -423,21 +424,15 @@ bigint Thermo::lost_check() // error message - if (lostflag == Thermo::ERROR) { - char str[64]; - sprintf(str, - "Lost atoms: original " BIGINT_FORMAT " current " BIGINT_FORMAT, - atom->natoms,ntotal); - error->all(FLERR,str); - } + if (lostflag == Thermo::ERROR) + error->all(FLERR,fmt::format("Lost atoms: original {} current {}", + atom->natoms,ntotal)); // warning message - char str[64]; - sprintf(str, - "Lost atoms: original " BIGINT_FORMAT " current " BIGINT_FORMAT, - atom->natoms,ntotal); - if (me == 0) error->warning(FLERR,str,0); + if (me == 0) + error->warning(FLERR,fmt::format("Lost atoms: original {} current {}", + atom->natoms,ntotal),0); // reset total atom count @@ -489,7 +484,7 @@ void Thermo::modify_params(int narg, char **arg) icompute = modify->find_compute(id_compute[index_press_vector]); if (icompute < 0) error->all(FLERR, "Pressure ID for thermo does not exist"); - } else icompute = modify->find_compute((char *) "thermo_press"); + } else icompute = modify->find_compute("thermo_press"); modify->compute[icompute]->reset_extra_compute_fix(arg[iarg+1]); @@ -1062,7 +1057,7 @@ int Thermo::add_variable(const char *id) customize a new keyword by adding to if statement ------------------------------------------------------------------------- */ -int Thermo::evaluate_keyword(char *word, double *answer) +int Thermo::evaluate_keyword(const char *word, double *answer) { // turn off normflag if natoms = 0 to avoid divide by 0 // normflag must be set for lo-level thermo routines that may be invoked diff --git a/src/thermo.h b/src/thermo.h index f2384e0ac3..def8cead65 100644 --- a/src/thermo.h +++ b/src/thermo.h @@ -39,7 +39,7 @@ class Thermo : protected Pointers { void modify_params(int, char **); void header(); void compute(int); - int evaluate_keyword(char *, double *); + int evaluate_keyword(const char *, double *); private: char *line; diff --git a/src/update.cpp b/src/update.cpp index c82e2bcf96..65242b8639 100644 --- a/src/update.cpp +++ b/src/update.cpp @@ -309,18 +309,14 @@ void Update::create_integrate(int narg, char **arg, int trysuffix) int sflag; new_integrate(arg[0],narg-1,&arg[1],trysuffix,sflag); + std::string estyle = arg[0]; if (sflag) { - char estyle[256]; - if (sflag == 1) snprintf(estyle,256,"%s/%s",arg[0],lmp->suffix); - else snprintf(estyle,256,"%s/%s",arg[0],lmp->suffix2); - int n = strlen(estyle) + 1; - integrate_style = new char[n]; - strcpy(integrate_style,estyle); - } else { - int n = strlen(arg[0]) + 1; - integrate_style = new char[n]; - strcpy(integrate_style,arg[0]); + estyle += "/"; + if (sflag == 1) estyle += lmp->suffix; + else estyle += lmp->suffix2; } + integrate_style = new char[estyle.size()+1]; + strcpy(integrate_style,estyle.c_str()); } /* ---------------------------------------------------------------------- @@ -333,8 +329,7 @@ void Update::new_integrate(char *style, int narg, char **arg, if (trysuffix && lmp->suffix_enable) { if (lmp->suffix) { sflag = 1; - char estyle[256]; - snprintf(estyle,256,"%s/%s",style,lmp->suffix); + std::string estyle = style + std::string("/") + lmp->suffix; if (integrate_map->find(estyle) != integrate_map->end()) { IntegrateCreator integrate_creator = (*integrate_map)[estyle]; integrate = integrate_creator(lmp, narg, arg); @@ -344,8 +339,7 @@ void Update::new_integrate(char *style, int narg, char **arg, if (lmp->suffix2) { sflag = 2; - char estyle[256]; - snprintf(estyle,256,"%s/%s",style,lmp->suffix2); + std::string estyle = style + std::string("/") + lmp->suffix2; if (integrate_map->find(estyle) != integrate_map->end()) { IntegrateCreator integrate_creator = (*integrate_map)[estyle]; integrate = integrate_creator(lmp, narg, arg); @@ -386,18 +380,14 @@ void Update::create_minimize(int narg, char **arg, int trysuffix) int sflag; new_minimize(arg[0],narg-1,&arg[1],trysuffix,sflag); + std::string estyle = arg[0]; if (sflag) { - char estyle[256]; - if (sflag == 1) snprintf(estyle,256,"%s/%s",arg[0],lmp->suffix); - else snprintf(estyle,256,"%s/%s",arg[0],lmp->suffix2); - int n = strlen(estyle) + 1; - minimize_style = new char[n]; - strcpy(minimize_style,estyle); - } else { - int n = strlen(arg[0]) + 1; - minimize_style = new char[n]; - strcpy(minimize_style,arg[0]); + estyle += "/"; + if (sflag == 1) estyle += lmp->suffix; + else estyle += lmp->suffix2; } + minimize_style = new char[estyle.size()+1]; + strcpy(minimize_style,estyle.c_str()); } /* ---------------------------------------------------------------------- @@ -410,8 +400,7 @@ void Update::new_minimize(char *style, int /* narg */, char ** /* arg */, if (trysuffix && lmp->suffix_enable) { if (lmp->suffix) { sflag = 1; - char estyle[256]; - snprintf(estyle,256,"%s/%s",style,lmp->suffix); + std::string estyle = style + std::string("/") + lmp->suffix; if (minimize_map->find(estyle) != minimize_map->end()) { MinimizeCreator minimize_creator = (*minimize_map)[estyle]; minimize = minimize_creator(lmp); @@ -421,8 +410,7 @@ void Update::new_minimize(char *style, int /* narg */, char ** /* arg */, if (lmp->suffix2) { sflag = 2; - char estyle[256]; - snprintf(estyle,256,"%s/%s",style,lmp->suffix2); + std::string estyle = style + std::string("/") + lmp->suffix2; if (minimize_map->find(estyle) != minimize_map->end()) { MinimizeCreator minimize_creator = (*minimize_map)[estyle]; minimize = minimize_creator(lmp); diff --git a/src/utils.cpp b/src/utils.cpp index ae4575980f..296915981a 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -121,11 +121,10 @@ static const char *guesspath(char *buf, int len, FILE *fp) memset(buf,0,len); #if defined(__linux__) - char procpath[32]; int fd = fileno(fp); - snprintf(procpath,32,"/proc/self/fd/%d",fd); // get pathname from /proc or copy (unknown) - if (readlink(procpath,buf,len-1) <= 0) strcpy(buf,"(unknown)"); + if (readlink(fmt::format("/proc/self/fd/{}",fd).c_str(),buf,len-1) <= 0) + strcpy(buf,"(unknown)"); #else strcpy(buf,"(unknown)"); #endif @@ -550,9 +549,9 @@ bool utils::is_double(const std::string & str) { std::string utils::path_basename(const std::string & path) { #if defined(_WIN32) - size_t start = path.find_last_of('/\\'); + size_t start = path.find_last_of("/\\"); #else - size_t start = path.find_last_of('/'); + size_t start = path.find_last_of("/"); #endif if (start == std::string::npos) { @@ -663,6 +662,36 @@ std::string utils::get_potential_units(const std::string & path, const std::stri return ""; } +/* ---------------------------------------------------------------------- + return bitmask of supported conversions for a given property +------------------------------------------------------------------------- */ +int utils::get_supported_conversions(const int property) +{ + if (property == ENERGY) { + return METAL2REAL | REAL2METAL; + } + return NOCONVERT; +} + +/* ---------------------------------------------------------------------- + return conversion factor for a given property and conversion setting + return 0.0 if unknown. +------------------------------------------------------------------------- */ + +double utils::get_conversion_factor(const int property, const int conversion) +{ + if (property == ENERGY) { + if (conversion == NOCONVERT) { + return 1.0; + } else if (conversion == METAL2REAL) { + return 23.060549; + } else if (conversion == REAL2METAL) { + return 1.0/23.060549; + } + } + return 0.0; +} + /* ------------------------------------------------------------------ */ extern "C" { diff --git a/src/utils.h b/src/utils.h index e43be03a87..047f6be296 100644 --- a/src/utils.h +++ b/src/utils.h @@ -255,6 +255,24 @@ namespace LAMMPS_NS { * \return UNITS field if present */ std::string get_potential_units(const std::string & path, const std::string & potential_name); + + enum { NOCONVERT = 0, METAL2REAL = 1, REAL2METAL = 1<<1 }; + enum { UNKNOWN = 0, ENERGY }; + + /** + * \brief Return bitmask of available conversion factors for a given propert + * \param property property to be converted + * \return bitmask indicating available conversions + */ + int get_supported_conversions(const int property); + + /** + * \brief Return unit conversion factor for given property and selected from/to units + * \param property property to be converted + * \param conversion constant indicating the conversion + * \return conversion factor + */ + double get_conversion_factor(const int property, const int conversion); } } diff --git a/src/variable.cpp b/src/variable.cpp index 7c9f7fc057..35eb0781b2 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -5073,24 +5073,16 @@ VarReader::VarReader(LAMMPS *lmp, char *name, char *file, int flag) : if (style == ATOMFILE) { if (atom->map_style == 0) - error->all(FLERR, - "Cannot use atomfile-style variable unless atom map exists"); + error->all(FLERR,"Cannot use atomfile-style " + "variable unless an atom map exists"); - int n = strlen(name) + strlen("_VARIABLE_STORE") + 1; - id_fix = new char[n]; - strcpy(id_fix,name); - strcat(id_fix,"_VARIABLE_STORE"); + std::string cmd = name + std::string("_VARIABLE_STORE"); + id_fix = new char[cmd.size()+1]; + strcpy(id_fix,cmd.c_str()); - char **newarg = new char*[6]; - newarg[0] = id_fix; - newarg[1] = (char *) "all"; - newarg[2] = (char *) "STORE"; - newarg[3] = (char *) "peratom"; - newarg[4] = (char *) "0"; - newarg[5] = (char *) "1"; - modify->add_fix(6,newarg); + cmd += " all STORE peratom 0 1"; + modify->add_fix(cmd); fixstore = (FixStore *) modify->fix[modify->nfix-1]; - delete [] newarg; buffer = new char[CHUNK*MAXLINE]; } diff --git a/src/version.h b/src/version.h index f444ce25be..be4aa33149 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define LAMMPS_VERSION "15 Jun 2020" +#define LAMMPS_VERSION "30 Jun 2020" diff --git a/tools/README b/tools/README index 2a6f28caf0..bed062f918 100644 --- a/tools/README +++ b/tools/README @@ -17,6 +17,7 @@ binary2txt convert a LAMMPS dump file from binary to ASCII text ch2lmp convert CHARMM files to LAMMPS input chain create a data file of bead-spring chains cmake tools and scripts for use with CMake +coding_standard python scripts to detect and fix some LAMMPS conventions colvars post-process output of the fix colvars command createatoms generate lattices of atoms within a geometry drude create Drude core/electron atom pairs in a data file @@ -31,6 +32,7 @@ kate add-ons to Kate editor for editing LAMMPS input scripts lmp2arc convert LAMMPS output to Accelrys Insight format lmp2cfg convert LAMMPS output to CFG files for AtomEye viz matlab MatLab scripts for post-processing LAMMPS output +mesont Tools for use with the USER-MESONT package micelle2d create a data file of small lipid chains in solvent moltemplate Instructions for installing the Moltemplate builder program msi2lmp use Accelrys Insight code to setup LAMMPS input @@ -40,8 +42,10 @@ pymol_asphere convert LAMMPS output of ellipsoids to PyMol format python Python scripts for post-processing LAMMPS output reax Tools for analyzing output of ReaxFF simulations replica tool to reorder LAMMPS replica trajectories according to temperature +singularity Singularity container descriptions suitable for LAMMPS development smd convert Smooth Mach Dynamics triangles to VTK spin perform a cubic polynomial interpolation of a GNEB MEP +valgrind suppression files for use with valgrind's memcheck tool vim add-ons to VIM editor for editing LAMMPS input scripts xmgrace a collection of scripts to generate xmgrace plots diff --git a/tools/coding_standard/README b/tools/coding_standard/README new file mode 100644 index 0000000000..d0cd2872df --- /dev/null +++ b/tools/coding_standard/README @@ -0,0 +1,5 @@ +These Python scripts help to detect whether files in the repository +conform to LAMMPS coding conventions or not, and can fix those issues, too. + +permissions.py detects if sources have executable permissions and scripts have not +whitespace.py (currently) detects trailing whitespace diff --git a/tools/coding_standard/permissions.py b/tools/coding_standard/permissions.py index 0b999db5b2..266e92d30c 100644 --- a/tools/coding_standard/permissions.py +++ b/tools/coding_standard/permissions.py @@ -10,7 +10,6 @@ import argparse import stat DEFAULT_CONFIG = """ -permission: "rw-r--r--" recursive: true include: - cmake/** @@ -36,39 +35,14 @@ patterns: - "requirements.txt" """ -def check_permission(path, mask): +def has_executable_bit(path): st = os.stat(path) - return bool(stat.S_IMODE(st.st_mode) == mask) + return bool(st.st_mode & (stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)) -def generate_permission_mask(line): - assert(len(line) == 9) - mask = 0 - # USER - if line[0] == "r": - mask |= stat.S_IRUSR - if line[1] == "w": - mask |= stat.S_IWUSR - if line[2] == "x": - mask |= stat.S_IXUSR - - # GROUP - if line[3] == "r": - mask |= stat.S_IRGRP - if line[4] == "w": - mask |= stat.S_IWGRP - if line[5] == "x": - mask |= stat.S_IXGRP - - # OTHER - if line[6] == "r": - mask |= stat.S_IROTH - if line[7] == "w": - mask |= stat.S_IWOTH - if line[8] == "x": - mask |= stat.S_IXOTH - - return mask +def get_non_exec_mask(path): + st = os.stat(path) + return st.st_mode & ~(stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) def check_folder(directory, config, fix=False, verbose=False): success = True @@ -79,23 +53,20 @@ def check_folder(directory, config, fix=False, verbose=False): path = os.path.join(directory, base_path, pattern) files += glob.glob(path, recursive=config['recursive']) - mask = generate_permission_mask(config['permission']) - for f in files: path = os.path.normpath(f) if verbose: print("Checking file:", path) - ok = check_permission(path, mask) - - if not ok: + if has_executable_bit(path): print("[Error] Wrong file permissions @ {}".format(path)) if fix: if os.access(path, os.W_OK): - print("Changing permissions of file {} to '{}'".format(path, config['permission'])) - os.chmod(path, mask) + print("Removing executable bit of file {}".format(path)) + new_mask = get_non_exec_mask(path) + os.chmod(path, new_mask) else: print("[Error] Can not write permissions of file {}".format(path)) success = False diff --git a/tools/singularity/ubuntu18.04_amd_rocm.def b/tools/singularity/ubuntu18.04_amd_rocm.def index df7d5be062..4c58f690aa 100644 --- a/tools/singularity/ubuntu18.04_amd_rocm.def +++ b/tools/singularity/ubuntu18.04_amd_rocm.def @@ -1,5 +1,5 @@ BootStrap: docker -From: rocm/dev-ubuntu-18.04 +From: ubuntu:18.04 %environment export PATH=$PATH:/opt/rocm/bin:/opt/rocm/profiler/bin:/opt/rocm/opencl/bin/x86_64 @@ -8,7 +8,24 @@ From: rocm/dev-ubuntu-18.04 export DEBIAN_FRONTEND=noninteractive apt-get update apt-get upgrade --no-install-recommends -y + + apt-get install -y --no-install-recommends curl libnuma-dev gnupg + + curl -sL http://repo.radeon.com/rocm/apt/debian/rocm.gpg.key | apt-key add - + printf "deb [arch=amd64] http://repo.radeon.com/rocm/apt/debian/ xenial main" > /etc/apt/sources.list.d/rocm.list + + apt-get update + apt-get install --no-install-recommends -y \ + kmod \ + file \ + sudo \ + libelf1 \ + rocm-dev \ + rocm-libs \ + build-essential + apt-get install --no-install-recommends -y software-properties-common + apt-get install --no-install-recommends -y \ bc \ build-essential \ @@ -54,7 +71,6 @@ From: rocm/dev-ubuntu-18.04 python3-pkg-resources \ python3-setuptools \ python3-virtualenv \ - rocm-libs \ rsync \ ssh \ vim-nox \ @@ -65,11 +81,12 @@ From: rocm/dev-ubuntu-18.04 valgrind \ gdb + export PATH=$PATH:/opt/rocm/bin:/opt/rocm/profiler/bin:/opt/rocm/opencl/bin/x86_64 - git clone -b master-rocm-3.3 https://github.com/ROCmSoftwarePlatform/hipCUB.git + git clone -b master-rocm-3.5 https://github.com/ROCmSoftwarePlatform/hipCUB.git mkdir hipCUB/build cd hipCUB/build - CXX=hcc cmake -D BUILD_TEST=off .. + CXX=hipcc cmake -D BUILD_TEST=off .. make -j4 make package make install diff --git a/tools/valgrind/README b/tools/valgrind/README new file mode 100644 index 0000000000..012eab1b65 --- /dev/null +++ b/tools/valgrind/README @@ -0,0 +1,15 @@ +These files contain additional suppressions for LAMMPS when using valgrind's +memcheck tool to search for memory access violations and memory leaks. +These will suppress known false positives and thus help to focus finding +and fixing real issues. When using CMake, these are automatically included +when running "ctest -T memcheck". To manually add them to do a memory check +on running LAMMPS, use a command line like following: + +valgrind --show-leak-kinds=all --track-origins=yes \ + --suppressions=/path/to/lammps/tools/valgrind/OpenMP.supp \ + --suppressions=/path/to/lammps/tools/valgrind/OpenMPI.supp \ + --suppressions=/path/to/lammps/tools/valgrind/Python3.supp \ + lmp -in in.melt + +Last update: 2020-06-24 + diff --git a/unittest/force-styles/pair_style.cpp b/unittest/force-styles/pair_style.cpp index 9354ad7f03..9913a5dd2e 100644 --- a/unittest/force-styles/pair_style.cpp +++ b/unittest/force-styles/pair_style.cpp @@ -571,7 +571,7 @@ TEST(PairStyle, plain) if (!verbose) ::testing::internal::CaptureStdout(); cleanup_lammps(lmp, test_config); lmp = init_lammps(argc, argv, test_config, false); - lmp->input->one("run_style respa 2 1 inner 1 4.0 5.0 outer 2"); + lmp->input->one("run_style respa 2 1 inner 1 4.8 5.5 outer 2"); run_lammps(lmp); if (!verbose) ::testing::internal::GetCapturedStdout(); @@ -579,7 +579,7 @@ TEST(PairStyle, plain) // coul/long styles do not use tabulation in compute_inner() // and compute_middle() so we get a significant deviation. pair = lmp->force->pair; - if (pair->ncoultablebits) epsilon *= 1.0e6; + if (pair->ncoultablebits) epsilon *= 5.0e6; f = lmp->atom->f; tag = lmp->atom->tag; @@ -909,7 +909,7 @@ TEST(PairStyle, opt) char **argv = (char **)args; int argc = sizeof(args) / sizeof(char *); - if (!verbose) ::testing::internal::CaptureStdout(); + ::testing::internal::CaptureStdout(); LAMMPS *lmp = init_lammps(argc, argv, test_config); std::string output = ::testing::internal::GetCapturedStdout(); @@ -1007,6 +1007,9 @@ TEST(PairStyle, single) char **argv = (char **)args; int argc = sizeof(args) / sizeof(char *); + // need to add this dependency + test_config.prerequisites.push_back(std::make_pair("atom", "full")); + // create a LAMMPS instance with standard settings to detect the number of atom types if (!verbose) ::testing::internal::CaptureStdout(); LAMMPS *lmp = init_lammps(argc, argv, test_config); @@ -1018,8 +1021,10 @@ TEST(PairStyle, single) for (auto prerequisite : test_config.prerequisites) { std::cerr << prerequisite.first << "_style " << prerequisite.second << "\n"; } + test_config.prerequisites.pop_back(); GTEST_SKIP(); } + test_config.prerequisites.pop_back(); // gather some information and skip if unsupported int ntypes = lmp->atom->ntypes; diff --git a/unittest/force-styles/tests/atomic-pair-eam.yaml b/unittest/force-styles/tests/atomic-pair-eam.yaml index c54a3ef1ae..d88c2c16f1 100644 --- a/unittest/force-styles/tests/atomic-pair-eam.yaml +++ b/unittest/force-styles/tests/atomic-pair-eam.yaml @@ -1,7 +1,7 @@ --- -lammps_version: 5 May 2020 -date_generated: Fri May 15 23:19:20 202 -epsilon: 5.0e-12 +lammps_version: 15 Jun 2020 +date_generated: Thu Jun 25 12:25:55 202 +epsilon: 6e-12 prerequisites: ! | pair eam pre_commands: ! | @@ -10,81 +10,82 @@ post_commands: ! "" input_file: in.metal pair_style: eam pair_coeff: ! | - 1 1 Ni_u3.eam + 1 1 Al_jnp.eam 2 2 Cu_u3.eam +extract: ! "" natoms: 32 -init_vdwl: -119.530487743563 +init_vdwl: -368.582927487109 init_coul: 0 -init_stress: ! |2- - 4.8826272345202817e+01 4.5850488601145123e+01 4.1343857791628459e+01 4.4988644962998467e+00 -4.9951074981736998e-01 -2.1768789288131187e+00 +init_stress: ! |- + -3.9250135569982547e+02 -4.6446788990491922e+02 -4.1339651642483534e+02 1.9400736722937047e+01 1.1111963280257109e+00 1.2102392154667630e+01 init_forces: ! |2 - 29 8.0800296830781970e-01 2.3879075266467829e+00 -8.3048670580586403e-02 - 4 2.7343534029869865e-01 -2.9878342106756367e-01 -1.2265223367116376e+00 - 8 -1.4720323385487724e+00 -1.4228179264986509e+00 9.6490960676696425e-01 - 13 -6.5176153773352563e-01 8.5767931224231297e-01 -1.0911744305807993e+00 - 15 -7.3903169091302345e-01 7.5680244318270884e-01 -7.2708235694598555e-01 - 3 -8.8972662160783789e-01 3.8990091972163423e+00 -1.0661156728781842e+00 - 10 -7.8846939852443865e-01 -3.8705457047816734e+00 -2.4629929283458956e+00 - 11 -9.8435494678902746e-01 -7.0900821618683274e-01 8.7706624584090875e-01 - 16 2.4583295121993398e+00 -2.1972676866087717e+00 8.3284121924556553e-01 - 21 4.0030874815543029e+00 1.0711165397007254e+00 2.4473954375123813e-01 - 26 -1.3811106600228646e+00 -3.5588639228797661e+00 2.8632910127148117e+00 - 7 -1.6363024522676575e+00 2.1007504896592857e+00 -3.9914508545625160e-01 - 9 5.7947847523538809e-01 -1.0536323905325453e+00 -6.4053794186990365e-01 - 12 1.1287163019780053e+00 -2.0776211837684415e+00 -2.0233323652665197e-01 - 2 -4.1490810252266974e-01 -1.6223974813453232e+00 9.8899266934997998e-01 - 18 -2.9490223023424624e+00 -6.7264893552133265e-01 -1.3875167298795910e+00 - 19 -3.1847050581559415e+00 -1.8169235559519932e+00 8.0598800871995424e-01 - 24 2.6007360409657871e+00 1.8259122746264185e+00 1.8348671705526824e+00 - 6 9.3578152728737196e-01 4.2423394202927650e-01 -1.1063087875863249e-01 - 20 4.8971016839265114e-01 3.9218805807784085e-01 -7.3184770760670148e-01 - 22 1.8086294180444197e-02 -2.0048898956069334e+00 -2.5326361122481866e-01 - 25 1.5827181697200143e+00 3.6148366642417934e-01 -1.0499794196925945e+00 - 5 1.7730142843252130e+00 3.4084808701534719e+00 7.4953511407886242e-01 - 27 1.1415770912387406e+00 3.1938755741801723e-02 1.8323119673595856e-01 - 28 1.1504782845312334e-01 1.3053527012833483e+00 1.6722391212961463e+00 - 1 -6.4076239230307086e-03 1.4271865784071405e+00 5.0439174022242561e-01 - 14 1.2901780857744278e+00 -2.0966095595276873e-01 1.5801785995295483e+00 - 17 9.9925856969280202e-01 2.8118162051561075e+00 -1.7641749946493385e-01 - 23 1.0999852359764739e+00 2.9307377042640232e+00 -1.8605350165432875e+00 - 30 -9.9030220835307969e-01 -5.9609338894221275e-01 -1.8459334541555570e+00 - 31 -3.9990682938968608e-01 -2.4015626569287210e+00 1.6801191688208930e+00 - 32 -4.8091016044865871e+00 -1.4798789422382359e+00 -4.6731344040392714e-01 -run_vdwl: -119.870792403123 + 1 3.8702196239123237e+00 3.2087381358567679e+00 -3.2785146725168746e+00 + 2 1.5399659055502801e+00 5.3765327929110125e+00 1.5740005508928423e+00 + 3 9.6731722224674677e-01 -1.3144867798433710e+01 -9.0231732944261689e-01 + 4 -2.5073370343027146e+00 -5.2079180074533618e+00 -5.8913203171674402e+00 + 5 -2.8515169765266575e+00 7.6648779774003719e+00 -1.6135262802376316e+00 + 6 2.0428463056677254e-01 5.1885731021366555e+00 -5.9322347514392992e-01 + 7 -9.7176119399525651e-01 3.5285494740740462e+00 3.2284411698905560e+00 + 8 7.5364432092290201e-01 -5.2936287201396057e+00 -6.2408220629962896e+00 + 9 -5.8493861425957814e+00 -3.7463543270548563e+00 -3.9409131835960420e+00 + 10 -1.8023712766215385e+00 3.7006913245199451e+00 -3.8897352514951287e+00 + 11 3.5323555367973203e-01 -1.1327469434419406e+01 6.7182457803171030e+00 + 12 -4.4655507115633153e+00 -4.1270694194866087e+00 4.6918435871989708e+00 + 13 4.4725135751254337e+00 -3.8312677334791485e+00 -2.6917694312049267e-01 + 14 -2.7336352778320090e+00 7.7812926164057377e+00 2.4973630791939097e+00 + 15 1.8398608400295208e-01 5.9059792700196434e+00 -9.9161720399808750e+00 + 16 5.8469261701364097e+00 -2.2571985010582432e+00 2.9857327422767823e+00 + 17 2.7560211432940238e+00 4.9207971970570350e+00 2.9070576476805532e+00 + 18 -1.4813870095597501e+00 -1.7378482556644488e+00 -1.6058192501275290e+00 + 19 1.4804205290003427e+00 -1.2245161773643600e+01 4.9726493930925530e-01 + 20 -3.6615637886242993e+00 -4.8732204205525411e+00 5.2596344008240576e+00 + 21 -1.3508123203296574e+00 1.0609703405450992e+01 2.7016894640855278e+00 + 22 -3.5308456248307213e-01 -1.2267881896396968e+01 3.8041687814180614e-01 + 23 2.1268575998905277e+00 -9.8195553504983524e-01 -5.0711605404266065e+00 + 24 6.0440647757301482e+00 -3.8588578230300516e+00 7.2719736140423983e+00 + 25 8.4455109296650068e+00 7.0624962219255796e+00 -3.1806612774968732e+00 + 26 -3.0905548748191465e+00 -7.7229205387362132e-01 5.3313905785014661e+00 + 27 -2.9657410879726704e+00 -8.6651631017774271e+00 -6.7853125584804292e+00 + 28 4.9373045778342588e+00 6.6292206752376668e+00 4.6463544925063864e+00 + 29 -6.7596568116029587e+00 1.1854971416292608e+01 -3.1889511538178256e-01 + 30 -3.1599376372205530e+00 1.2411259590817497e+01 -3.3705452712364457e+00 + 31 -4.7553805255326909e+00 2.0807423151380857e+00 9.7968713347921295e+00 + 32 4.7774045900242150e+00 -3.5862707137302143e+00 -3.6201646908067486e+00 +run_vdwl: -373.391968845895 run_coul: 0 -run_stress: ! |2- - 4.7751995066352151e+01 4.4830156042194794e+01 4.0389886435910626e+01 4.2184912902327492e+00 -5.6543256799494823e-01 -2.0752485517795161e+00 +run_stress: ! |- + -3.9486584521928387e+02 -4.6496789731502832e+02 -4.1710147439166667e+02 1.8213412417226081e+01 7.6724894655338038e-01 1.2094096020348012e+01 run_forces: ! |2 - 29 7.5690592801898815e-01 2.3151863977187501e+00 -5.6022314357905889e-02 - 4 2.6331390998279414e-01 -2.7131757020660047e-01 -1.2171723766818878e+00 - 8 -1.4819123498210278e+00 -1.3892127647468901e+00 9.4351114037722761e-01 - 13 -6.7030752430639429e-01 8.1027363373017303e-01 -1.0419798308062822e+00 - 15 -7.2914425790656268e-01 7.3381515730032987e-01 -7.0649536261355972e-01 - 3 -8.2862609949331145e-01 3.6488186893647363e+00 -1.0624581553334507e+00 - 10 -6.1483994156789068e-01 -3.7021751622708732e+00 -2.3234131680128005e+00 - 11 -9.5907408526990645e-01 -7.3338326161574841e-01 8.4459514391866075e-01 - 16 2.2537479937597746e+00 -2.1115143339299585e+00 7.8862148815663591e-01 - 21 3.8499378367182593e+00 9.5004430642537196e-01 2.6813205101176563e-01 - 26 -1.2549911173346853e+00 -3.3303513611819771e+00 2.7419485545991917e+00 - 7 -1.5803819585422452e+00 2.0775725635516813e+00 -4.1643485965418925e-01 - 9 5.9616913379864100e-01 -1.0900041633317910e+00 -6.6263113823586650e-01 - 12 1.1188274327648378e+00 -1.9856343707557884e+00 -1.8931698797528046e-01 - 2 -4.1672554481721213e-01 -1.6030271664710254e+00 9.7652355703236493e-01 - 18 -2.8528759296970057e+00 -6.4627753964043022e-01 -1.3476345322887988e+00 - 19 -3.0612708341260451e+00 -1.7499039144402915e+00 7.5685549599560620e-01 - 24 2.4838924866176000e+00 1.7760409543710471e+00 1.7927340588029941e+00 - 6 9.3519811444520051e-01 4.3790210252755352e-01 -1.1115261874946925e-01 - 20 4.7860017665455917e-01 4.0873358602741239e-01 -7.2787329983734494e-01 - 22 4.5683760799552345e-02 -1.9499040012633670e+00 -2.4911444772283134e-01 - 25 1.5498059277046197e+00 3.7493980878195188e-01 -1.0267705215988105e+00 - 5 1.6772659871839077e+00 3.2412248124601644e+00 7.8861775101712162e-01 - 27 1.1181252050394743e+00 2.1210906682851027e-02 1.5259049481566841e-01 - 28 8.6158085875367885e-02 1.2958084369079632e+00 1.6341119769792032e+00 - 1 -6.8020837225162042e-02 1.3929213106632692e+00 4.9572035003963544e-01 - 14 1.2851416793310484e+00 -1.0078910089733506e-01 1.4693455274495928e+00 - 17 9.8653851440129303e-01 2.7301368714775602e+00 -1.8133160965911002e-01 - 23 1.0757192308685777e+00 2.8092242654474213e+00 -1.7775969588994822e+00 - 30 -9.5705266545383005e-01 -5.7810207051480700e-01 -1.7663162149693394e+00 - 31 -4.2417243253557779e-01 -2.3534705046561171e+00 1.6411799159456588e+00 - 32 -4.6616358258676422e+00 -1.4287865175152361e+00 -4.3077310874491803e-01 + 1 3.6065103849698468e+00 3.3850045614133313e+00 -3.2099404138931509e+00 + 2 1.5272319527263032e+00 5.1159618338839312e+00 1.4386822600144664e+00 + 3 8.8889124738965819e-01 -1.2549265126891074e+01 -7.6286300397645501e-01 + 4 -2.5149887025851170e+00 -5.1630477798481431e+00 -5.7927560583461730e+00 + 5 -2.7577319227243340e+00 7.7337372091606680e+00 -1.6161053768722711e+00 + 6 2.9829137219780122e-01 4.9518159754562241e+00 -6.3319133869634869e-01 + 7 -8.7309179105028933e-01 3.7242971801706921e+00 3.1667500872407377e+00 + 8 7.4988511941705449e-01 -5.2345536588071093e+00 -6.0694489025295839e+00 + 9 -5.6748652076461674e+00 -3.6155005353015062e+00 -3.8960205269343655e+00 + 10 -1.6985487726687425e+00 3.3586465595352220e+00 -3.9313302972889002e+00 + 11 3.0645290480830667e-01 -1.1180223984570517e+01 6.5832137421124841e+00 + 12 -4.4891921700259347e+00 -4.1479969157235592e+00 4.6314455848790201e+00 + 13 4.3217028924633345e+00 -3.6856204342214225e+00 -3.0397864454481671e-01 + 14 -2.5849914165064707e+00 7.5606403552491512e+00 2.3174690493053731e+00 + 15 1.1796272962339260e-01 5.7288100295841362e+00 -9.7607016326972875e+00 + 16 5.7880766878601184e+00 -2.4198072924490344e+00 3.0510124864170507e+00 + 17 2.6948634470285198e+00 4.9491285704784493e+00 2.8470505948516216e+00 + 18 -1.3885896269097586e+00 -1.7319937370042313e+00 -1.4698594584039826e+00 + 19 1.3993184597149559e+00 -1.1797240539240345e+01 4.4955145029402199e-01 + 20 -3.6118153030811628e+00 -4.8252169436385737e+00 5.1301467326003083e+00 + 21 -1.3245618504864409e+00 1.0413638773882035e+01 2.6136063969881485e+00 + 22 -3.6531531607881618e-01 -1.2221686471408907e+01 3.4297492050272915e-01 + 23 2.1591154306811964e+00 -8.2020156536698485e-01 -4.8505116467228593e+00 + 24 5.8317944566991562e+00 -3.8285931693697965e+00 7.1438153964941415e+00 + 25 8.3117675961796262e+00 7.0110643410721547e+00 -3.1321086296777607e+00 + 26 -2.9593072762047514e+00 -7.3717349777411822e-01 5.3317823136164311e+00 + 27 -2.8851089719214054e+00 -8.5425149524249182e+00 -6.6688154620289835e+00 + 28 4.7313345552457529e+00 6.4894520960745865e+00 4.4358188230989617e+00 + 29 -6.6981970679986764e+00 1.1511660045027716e+01 -2.4612864290481729e-01 + 30 -2.9580050013088863e+00 1.2189750141569847e+01 -3.2455167441500565e+00 + 31 -4.5434783129378946e+00 1.9394948274115587e+00 9.6218495408600599e+00 + 32 4.5945894731298162e+00 -3.5624658959294715e+00 -3.5158925996077341e+00 ... diff --git a/unittest/force-styles/tests/atomic-pair-eam_alloy_real.yaml b/unittest/force-styles/tests/atomic-pair-eam_alloy_real.yaml new file mode 100644 index 0000000000..e61665aaa1 --- /dev/null +++ b/unittest/force-styles/tests/atomic-pair-eam_alloy_real.yaml @@ -0,0 +1,90 @@ +--- +lammps_version: 15 Jun 2020 +date_generated: Thu Jun 25 11:40:47 202 +epsilon: 7.5e-12 +prerequisites: ! | + pair eam/alloy +pre_commands: ! | + variable units index real +post_commands: ! "" +input_file: in.metal +pair_style: eam/alloy +pair_coeff: ! | + * * CuNi.eam.alloy Cu Ni +extract: ! "" +natoms: 32 +init_vdwl: -2737.69103243003 +init_coul: 0 +init_stress: ! |2- + 1.1764167914492630e+03 1.1205980824873152e+03 1.0864455580994877e+03 8.1647231129875934e+01 -2.5037139879631205e+01 -6.3600641311729632e+01 +init_forces: ! |2 + 1 5.2672451511791571e+00 2.9722735284353401e+01 1.1075184641021506e+01 + 2 -1.0636773406463684e+01 -4.4073764067943728e+01 2.0771028937481248e+01 + 3 -2.2965537069495454e+01 9.7562921273648755e+01 -2.4642335703402438e+01 + 4 7.4656490760559127e+00 -5.4658324632906563e-01 -2.4960279603333927e+01 + 5 3.1230848773422942e+01 6.4617845424874886e+01 2.1933694652888928e+01 + 6 2.1832213719963605e+01 1.1143486075604935e+01 -3.4239959293183455e+00 + 7 -2.9357107589496898e+01 4.2158182777227005e+01 -8.5586094830391737e+00 + 8 -3.6073223340439661e+01 -2.4215275768396296e+01 2.9725386697629890e+01 + 9 1.4987399784928266e+01 -2.7061834122202470e+01 -1.3299771204450476e+01 + 10 -1.2413956598774377e+01 -7.6775514871436584e+01 -5.4742781546994578e+01 + 11 -2.1067380701478477e+01 -1.6615953683959319e+01 1.8476258567375464e+01 + 12 1.9461184824514678e+01 -3.8109085731939743e+01 -5.3661246617685698e+00 + 13 -1.4482196622742837e+01 1.5568716854391997e+01 -2.4158915065964425e+01 + 14 3.2825757431900875e+01 -1.1627824476982159e+01 3.5262711606238248e+01 + 15 -1.8746762621101752e+01 8.1538251436098452e+00 -1.0644311994127357e+01 + 16 4.8624977409645190e+01 -4.4113270120576303e+01 1.8303261804100114e+01 + 17 2.2698244093478909e+01 6.6392356130851752e+01 -7.1977884622409611e+00 + 18 -6.7980771356824789e+01 -1.4937345732539860e+01 -3.2011413553574002e+01 + 19 -7.8000063810705043e+01 -3.3213815725148109e+01 2.0380659433340828e+01 + 20 1.3799086550197625e+01 1.3483094603013749e+01 -2.1521630948739766e+01 + 21 8.5316643556023976e+01 1.4311382265670481e+01 1.3218228731927237e+00 + 22 3.1576126714640402e+00 -3.4015985036776200e+01 -8.2959114388958923e+00 + 23 1.9744512575830672e+01 6.1755929602595728e+01 -3.8176255063513352e+01 + 24 5.2798113388347907e+01 4.7195292661174186e+01 3.7832549147780398e+01 + 25 2.7490207016385277e+01 1.5425133021820687e+00 -2.2503456988828329e+01 + 26 -2.1990208289852045e+01 -7.4941647823295114e+01 6.1475112414163846e+01 + 27 2.5616643621116541e+01 -2.0334701161446000e+00 2.8572235129465353e+00 + 28 -4.7832347888405167e+00 2.6723575502863220e+01 3.5294244672040442e+01 + 29 2.6981880708270644e+01 4.4677369269953125e+01 -9.1942728940884999e-01 + 30 -1.7901630000432533e+01 -2.7359294215609250e+01 -3.9336329099287354e+01 + 31 -1.2722584214735921e+00 -5.4089290760926374e+01 3.1561919199814422e+01 + 32 -1.0162711573460452e+02 -2.1279270671809893e+01 -6.5117201231268016e+00 +run_vdwl: 13786.8231164129 +run_coul: 0 +run_stress: ! |2- + 1.5453045758769309e+04 1.4324564159674526e+04 2.0339719265203345e+04 -4.3703985097767185e+02 -2.4828700331963573e+03 2.6371860977250676e+03 +run_forces: ! |2 + 1 -4.1235070358044659e+03 -1.6712537087260623e+02 1.0285277274671844e+02 + 2 -1.7134569288200260e+03 5.6109874495911663e+02 1.5833880163322256e+03 + 3 7.0660491674313107e+02 1.9980947258587582e+02 3.5478310177110990e+02 + 4 -1.5805950092619389e+02 -6.3394860464940950e+02 -8.2522020103607213e+02 + 5 3.9405888405680394e+03 -3.4696561240376559e+03 -1.8565396295835055e+03 + 6 4.1907332132232949e+02 4.0962894944175537e+02 1.0986647025780044e+03 + 7 -9.6645970600745068e+02 -3.5911787935573295e+02 -2.2384719111997448e+01 + 8 1.0265438581270025e+03 2.0808489842263230e+03 2.0164534268299593e+02 + 9 1.1337966507234397e+02 -5.0396233184209956e+02 3.8179698908837855e+02 + 10 1.2342073717320160e+02 9.5758334207234370e+01 6.8799216904595795e+01 + 11 -1.5320242612327118e+02 7.0895437874334675e+01 2.8604566716136226e+00 + 12 8.6000100331177282e+02 -1.3442535831934245e+02 -6.4193775682228159e+02 + 13 -2.4471242994052943e+02 -5.4264102607261088e+02 5.7696771921238769e+02 + 14 -3.9018569969952148e+02 3.0656573620303129e+03 1.5177932576921341e+02 + 15 -4.7634536416264723e+02 -1.2625516023855293e+03 -1.7806430239510228e+03 + 16 -2.8401490184979775e+03 1.5282109260061861e+03 -2.2214870113522261e+03 + 17 -1.2156159328353674e+03 -4.3257815608068495e+02 -2.1345521131783940e+02 + 18 3.0311750850899062e+02 3.4429089555337708e+02 -7.3709708806569222e+02 + 19 1.2045122218993047e+03 -9.7593750646130388e+02 5.4415371253339413e+02 + 20 -1.1696081099779099e+02 -8.3225560965709064e+01 -7.0457470193504179e+01 + 21 2.0598989260724796e+01 2.2356469079280821e+01 -7.9554177550795458e+01 + 22 -2.9312564165082662e+01 -5.9822361803205673e+01 -8.0777528003415412e+01 + 23 1.1532179753142320e+02 7.6103559438211744e+02 -5.6029347839975208e+02 + 24 -1.3770034997569367e+03 -2.7507426940749701e+02 3.3464942960699559e+03 + 25 5.1243904877931982e+02 -2.7117746030264681e+02 3.9984232018060953e+02 + 26 1.0172211816330174e+03 -9.5258495026629555e+02 -3.7013789400208352e+03 + 27 -9.3684148116059225e+02 4.9006556088962600e+02 4.5089073710681248e+02 + 28 2.6547988549156657e+03 5.0325157403920872e+02 5.1846329264498263e+03 + 29 1.3361686744155916e+03 2.5910193784510094e-01 1.0501345350932172e+03 + 30 4.1083282961451692e+02 6.3716214702023012e+02 -3.1059177937091031e+03 + 31 2.2436377537176742e+02 -5.0079917535823097e+02 6.8158392999295370e+02 + 32 -2.4717482535028790e+02 -1.4570181605226207e+02 -2.8412607206596493e+02 +... diff --git a/unittest/force-styles/tests/atomic-pair-eam_cd_real.yaml b/unittest/force-styles/tests/atomic-pair-eam_cd_real.yaml new file mode 100644 index 0000000000..0ba4eb2736 --- /dev/null +++ b/unittest/force-styles/tests/atomic-pair-eam_cd_real.yaml @@ -0,0 +1,91 @@ +--- +lammps_version: 15 Jun 2020 +date_generated: Thu Jun 25 15:30:51 202 +epsilon: 5e-12 +prerequisites: ! | + pair eam/cd +pre_commands: ! | + variable units index real +post_commands: ! | + change_box all x final 0 10 y final 0 10 z final 0 10 +input_file: in.metal +pair_style: eam/cd +pair_coeff: ! | + * * FeCr.cdeam Fe Cr +extract: ! "" +natoms: 32 +init_vdwl: -1785.33573859861 +init_coul: 0 +init_stress: ! |2- + 6.8043301174259739e+02 6.7297960563391212e+02 5.1465006825793432e+02 1.8121853680469485e+02 -2.1539743820861840e+01 1.9524563154151586e+01 +init_forces: ! |2 + 8 -5.7350284149741624e+00 -3.5278567560873412e+01 -1.2945450320411185e+01 + 11 -1.8097851375135637e+01 -1.4526564839671716e+01 1.4745586739847019e+00 + 13 1.1989580066351607e+01 1.5624364891748142e+01 -9.7439139691488030e+00 + 18 -9.0623448888489833e+01 -3.6012980670109037e+01 -4.4206358603667979e+01 + 29 3.4315696679075806e+01 8.0626370079554022e+01 -8.5024543289523695e+00 + 4 9.8106599747837144e+00 -2.2423551582732831e+01 -2.2394700365566653e+01 + 9 -9.7103731975151177e+00 -6.9064607099453728e+00 -2.1661283927312738e+00 + 15 -1.7792920650091148e+01 3.5590552950398063e+01 -2.5723318396810825e+01 + 22 -6.5675672460417749e+00 -4.7649450274482049e+01 1.9724013269199872e+00 + 25 5.9273822696594358e+01 3.4630131644829056e+01 -2.9728016814706639e+00 + 3 -2.1730644235860989e+01 2.5556005146056687e+01 -1.3958230488587832e+01 + 10 -6.4920942773028782e+00 -2.5683534959198733e+00 -1.6573064725963313e+01 + 16 5.4866106162193525e+01 -2.6559412741299443e+01 -1.9741676495697597e+01 + 21 3.5877005997488176e+01 4.1948795376449915e+01 2.6549358660124593e+01 + 26 -3.5041054144373000e+01 -3.8690624501424864e+01 2.3990991622029867e+01 + 7 -2.5368323752589127e+01 2.9810504132177154e+01 -1.2638531317689472e+01 + 12 3.6951069676944783e+01 -2.1917541992301505e+01 -1.3427277677714791e+01 + 17 1.0715624362332361e+01 4.5671651640165596e+00 2.1824770610292802e+01 + 30 -1.1158262405262283e+01 1.5645450981201234e+01 -1.6793195768740460e+01 + 2 -2.1575934430928174e+00 -4.8375617933428616e+00 1.1868004064201370e+01 + 19 -5.6881035489195945e+01 -7.2486978424465079e+01 8.5346400279864998e+00 + 24 1.0635249022606776e+02 4.8261805685832684e+01 5.3930408354403887e+01 + 27 4.5450128358507476e+00 8.5625984164024569e+00 1.8060331715170475e+00 + 6 -1.2960045695799433e+01 1.4917602053253173e+01 -1.1634623653327418e+01 + 20 1.2523060387800900e+01 -1.1092095621986928e+01 7.3361549932744214e+00 + 31 -1.9746718194509153e+01 -3.1423401701143103e+01 5.6625794900273178e+01 + 5 -1.7188199887458431e+01 1.3020595354001873e+01 1.1713947051593561e+01 + 28 -8.4196479821767927e+00 5.9390977389974946e+00 2.9015171484281339e+00 + 32 -6.0270099286644097e+01 -3.5352975667087023e+01 -1.5579017839726889e+01 + 1 8.7363936089779717e+00 -4.0061891709735753e-01 -5.2750678284773072e+00 + 14 1.1426402460118315e+01 -9.4966708566757614e+00 3.1977067658213787e+01 + 23 2.8557983431932612e+01 4.2922771735639678e+01 -8.2298364085589899e+00 +run_vdwl: 50833.2095623296 +run_coul: 0 +run_stress: ! |2- + 1.1422757276809528e+06 6.4698538309370587e+05 4.1051148563743639e+05 9.5363304679864508e+04 -1.8362039585635712e+05 -1.1661012466179539e+05 +run_forces: ! |2 + 8 -7.4661838460394447e+03 -1.1211419092422286e+03 -9.9785680647352237e+03 + 11 -1.2156739748086065e+03 -2.5965260670035150e+03 1.0931787195989891e+03 + 13 1.8896681608362815e+00 4.8691607259253615e+00 -1.2350445460364599e+00 + 18 9.6833281561496918e+01 2.3040573196963848e+02 -5.8045206738908905e+02 + 29 -1.1522875720670490e+04 2.1859177429597104e+04 6.6026924351739190e+03 + 4 8.2866585144562814e+03 2.1987889627894292e+03 -7.3269584596262430e+03 + 9 -4.6751202227701178e+04 -4.5455389599126109e+04 6.9310666457731364e+04 + 15 -1.7479956445491218e+03 -1.6324715355756180e+03 -3.8088738011660148e+03 + 22 5.9705595976766408e+05 -7.3498559170154767e+04 -2.8830207944910129e+05 + 25 -6.2964336519821500e+05 1.0487031227925362e+06 -4.2163928496550000e+05 + 3 -3.9919676312365680e+05 -2.9469092131577781e+05 4.7182000013219666e+04 + 10 1.7089467526999904e+03 1.5998419382683467e+03 3.7660701226776023e+03 + 16 -6.0049578751180682e+05 6.0547722741760917e+04 2.7117954880042706e+05 + 21 -6.4190745440347127e+03 -5.4746193210828164e+02 9.9912667127815421e+03 + 26 -1.2400361710263705e+02 -1.6482646184110337e+02 -1.3181023673232635e+03 + 7 -4.4527084366605749e+01 1.2083311421562247e+02 1.4090365320304585e+02 + 12 -9.1471177123676614e+02 8.8769239275791806e+03 2.4590954021189188e+02 + 17 1.0955176820986494e+06 -7.3097457868150948e+05 3.0732902700087230e+05 + 30 -8.8479117293965359e+00 3.9144652621120715e+00 -2.5741472917180555e+00 + 2 -7.6357102464059466e+01 1.1233035238477746e+03 -6.8826275473684859e+02 + 19 1.7252084357421222e+03 -1.1971214382248461e+03 9.6479329686047180e+01 + 24 -9.4115440774054568e+03 1.4868082917729369e+04 9.5344712883688553e+03 + 27 -2.0206241875051235e+03 8.9736344917421525e+02 2.7371544379914644e+02 + 6 -8.7269440254898427e+00 -4.2871068258170384e+00 -2.8071174977249303e+01 + 20 1.3147736477952498e+04 4.5528169367928713e+03 1.4550409304372299e+04 + 31 1.6062724190796675e+02 -3.5009702848199751e+01 1.5780906691469211e+01 + 5 4.6327746018426421e+02 -4.2009134275606988e+02 -2.3788165159758432e+03 + 28 1.2720985720833841e+02 1.6004798320652958e+02 1.3546485540637436e+03 + 32 -1.5462086679694039e+03 -9.9085693678647149e+03 -6.7979735229861799e+03 + 1 -6.8825417922686677e+02 -6.9446834170851020e+01 -8.7132365430256550e+02 + 14 3.2489354130384271e+01 -1.8199012589513091e+00 -1.2103425811994843e+01 + 23 9.7820842419642543e+02 -3.4289927091667496e+03 1.0679111325906679e+03 +... diff --git a/unittest/force-styles/tests/atomic-pair-eam_fs_real.yaml b/unittest/force-styles/tests/atomic-pair-eam_fs_real.yaml new file mode 100644 index 0000000000..daf966bac7 --- /dev/null +++ b/unittest/force-styles/tests/atomic-pair-eam_fs_real.yaml @@ -0,0 +1,90 @@ +--- +lammps_version: 15 Jun 2020 +date_generated: Thu Jun 25 11:40:47 202 +epsilon: 7.5e-12 +prerequisites: ! | + pair eam/fs +pre_commands: ! | + variable units index real +post_commands: ! "" +input_file: in.metal +pair_style: eam/fs +pair_coeff: ! | + * * AlFe_mm.eam.fs Al Fe +extract: ! "" +natoms: 32 +init_vdwl: -2496.58372622189 +init_coul: 0 +init_stress: ! |2- + 2.3033019789741047e+03 2.1157417403923514e+03 2.0201355767290902e+03 1.3625967475024967e+02 -4.9118825128592029e+01 8.0062189596557349e+00 +init_forces: ! |2 + 1 3.2793593861926894e+01 6.4571740367787598e+01 -2.1289279778598913e+00 + 2 -1.2829292312064029e+01 -5.4533055036423278e+01 1.8187434445669542e+01 + 3 -2.4856613953429456e+01 1.0514866674084597e+02 -2.3296287600437509e+01 + 4 5.3912586948208610e+00 -1.9207748493955110e+00 -3.0737420829610784e+01 + 5 2.2876420006755072e+01 1.3823836581860232e+02 2.7754672239203551e+01 + 6 3.2990987866655288e+01 4.7389376657311274e+01 4.1925550028130715e-01 + 7 -5.3127337737189976e+01 7.9068725922500050e+01 3.3313480295224882e+00 + 8 -3.3776815354713030e+01 -3.1883796291469537e+01 3.1197870995948911e+01 + 9 -1.6142958936642351e+01 -5.6081173595531077e+01 -3.9752773026105103e+01 + 10 -2.3444945461170079e+01 -8.6264628791048494e+01 -9.7382848626466640e+01 + 11 -3.7845977091330013e+01 -8.9150810223199585e+01 5.7663720237686718e+01 + 12 3.0195173959030388e+00 -8.0980830765493238e+01 1.3208578723692574e+01 + 13 1.4074145069219668e+00 1.6274921833661661e+01 -3.2622589971920675e+01 + 14 3.4107233289225746e+01 -9.9470010392150936e+00 3.5127602437573628e+01 + 15 -2.5283377148309391e+01 1.4403149632708308e+01 -4.5870071592016277e+00 + 16 1.1347792324200792e+02 -8.2148516354961487e+01 3.6846638005266399e+01 + 17 3.9601805292343890e+01 1.0338789002649486e+02 1.9982264609004446e+01 + 18 -7.0147350906383394e+01 -1.9416536628860054e+01 -3.1061364649276509e+01 + 19 -8.0113796208824880e+01 -3.6203470152188125e+01 1.7073669110420070e+01 + 20 1.9118534843395143e+01 1.8040139592039122e+01 -2.5670655740910352e+01 + 21 1.0678029830913370e+02 8.4131852942169118e+01 2.5233622309511127e+01 + 22 -6.1256398451879237e+00 -4.5897733307809965e+01 -7.6777005140719412e+00 + 23 3.5851086965813614e+01 7.2727642790340141e+01 -8.3728640107852527e+01 + 24 5.7040471090952735e+01 5.0540340852012491e+01 3.9578738566151387e+01 + 25 3.4502137563453971e+01 1.0646154765045129e+01 -2.2629894541123310e+01 + 26 -4.8073017653735285e+01 -1.0752340517338715e+02 1.1113490074292022e+02 + 27 1.1423747645119571e+01 -2.4217562070846903e+01 -1.6319043178767714e+01 + 28 -8.1060220093085604e+00 2.0590140270631622e+01 3.1642408010462596e+01 + 29 2.6452264513660189e+01 5.1030856603567926e+01 -4.1657860341522763e+00 + 30 -2.3924536059677859e+01 -2.6294734320754202e+01 -3.9690770192486717e+01 + 31 -2.4704253734618757e+00 -5.6516273903220871e+01 2.5013410902961631e+01 + 32 -1.1056658903666158e+02 -6.7209662311912936e+01 -3.1944424716033090e+01 +run_vdwl: 40769.6664263014 +run_coul: 0 +run_stress: ! |2- + 4.7822449917558428e+04 3.8552602066320171e+04 1.0546475946402764e+05 -4.7097209744561578e+03 -1.9235871974750171e+04 2.4588761490836405e+03 +run_forces: ! |2 + 1 -1.9097605102340134e+04 2.7546194107357201e+03 8.3909985474391324e+03 + 2 -3.5418672604851995e+03 1.1917117809027379e+03 2.9638609715428606e+03 + 3 1.4645939207614488e+03 1.8470227268074846e+03 9.0546066503794027e+03 + 4 1.5171875398835888e+02 2.3348543217598845e+00 8.5754083947278403e+01 + 5 1.5255670556575355e+04 -9.9590105126572107e+03 -1.0489498857223289e+04 + 6 2.7818209314374612e+03 -8.6014157651635051e+03 -1.2889694687254105e+03 + 7 -8.8128660207662542e+03 1.1138472916664317e+04 -2.0399367408224349e+04 + 8 3.5529460324474094e+03 5.5566000158222214e+03 -1.8769853546433067e+04 + 9 4.8136177248632850e+02 -1.1761544007856573e+03 -2.7017533689432776e+02 + 10 1.6535310540000773e+02 1.3432168572003422e+02 1.1963005448873733e+02 + 11 -1.5594213178910303e+02 1.2778619884218003e+02 1.4189480288867410e+01 + 12 7.3411513010218300e+02 1.4480425185204228e+02 -4.6079278035527182e+02 + 13 -6.0663163395447373e+02 -4.8726527419793723e+02 7.3735693469161799e+02 + 14 -4.5176376406928503e+03 6.1391055620710058e+03 -4.1085739464480804e+02 + 15 1.1925775244422684e+03 1.1292242217644371e+03 -1.5125109545597138e+03 + 16 -7.2703161457054946e+01 8.3339390002686059e+02 1.9248938430089464e+02 + 17 -1.7348561999525100e+03 -7.2757358517488842e+02 -3.8426231743637675e+02 + 18 4.1035400691422291e+02 6.4564583234886231e+02 -1.4428957831120297e+03 + 19 1.9940148697028328e+03 -1.7448505231999620e+03 1.0608439981185611e+03 + 20 -1.2838394344544284e+02 -8.5097194257357614e+01 -4.9610165903643058e+01 + 21 3.8616135702960577e+01 1.0718282306571462e+01 -1.3278179744236820e+02 + 22 -2.4718543372782243e+01 -6.0165634334580901e+01 -7.0468964014220731e+01 + 23 9.0747440529556144e+01 8.5311078702801672e+02 -6.4721686266285906e+02 + 24 -7.7063686156537606e+03 -9.4345142528371957e+02 1.9053020187898885e+04 + 25 1.1857089833982384e+03 -1.5931029976786810e+03 6.4196001788860428e+02 + 26 1.2336392110879744e+03 -5.8839681071744899e+03 -1.3144430058575494e+04 + 27 -1.5957637891149948e+03 3.9143843166377701e+02 1.1708001522772088e+03 + 28 8.2009942698852374e+03 -4.3380266610733242e+03 3.2623123387198881e+04 + 29 3.1967940813541386e+03 2.8352472875132717e+03 1.8573222150564190e+04 + 30 5.4696070166386935e+03 4.6916524743124671e+02 -2.5807628896134785e+04 + 31 5.3597116724411387e+02 -5.7446986383635567e+02 7.3443567691364683e+02 + 32 -1.4126086707422027e+02 -3.0171449004871839e+01 -1.3497108559674118e+02 +... diff --git a/unittest/force-styles/tests/atomic-pair-eam_real.yaml b/unittest/force-styles/tests/atomic-pair-eam_real.yaml new file mode 100644 index 0000000000..5f15f52b27 --- /dev/null +++ b/unittest/force-styles/tests/atomic-pair-eam_real.yaml @@ -0,0 +1,91 @@ +--- +lammps_version: 15 Jun 2020 +date_generated: Thu Jun 25 12:25:09 202 +epsilon: 5e-12 +prerequisites: ! | + pair eam +pre_commands: ! | + variable units index real +post_commands: ! "" +input_file: in.metal +pair_style: eam +pair_coeff: ! | + 1 1 Al_jnp.eam + 2 2 Cu_u3.eam +extract: ! "" +natoms: 32 +init_vdwl: -8499.72465987996 +init_coul: 0 +init_stress: ! |- + -9.0512967456822462e+03 -1.0710884534079007e+04 -9.5331506234442222e+03 4.4739163983538219e+02 2.5624797371055561e+01 2.7908780729992691e+02 +init_forces: ! |2 + 1 8.9249389277991696e+01 7.3995263010093637e+01 -7.5604348252794324e+01 + 2 3.5512459223271605e+01 1.2398579792103124e+02 3.6297316829891393e+01 + 3 2.2306866202164997e+01 -3.0312786796430260e+02 -2.0807932989160598e+01 + 4 -5.7820568539052488e+01 -1.2009744839886056e+02 -1.3585708084873534e+02 + 5 -6.5757546961524824e+01 1.7675629417686210e+02 -3.7208801848207692e+01 + 6 4.7109157331319356e+00 1.1965134426190438e+02 -1.3680059016506990e+01 + 7 -2.2409346630426118e+01 8.1370288045808721e+01 7.4449625791878475e+01 + 8 1.7379451791214294e+01 -1.2207398448858665e+02 -1.4391678298400700e+02 + 9 -1.3489005576125101e+02 -8.6392987530410579e+01 -9.0879621575062515e+01 + 10 -4.1563671140723542e+01 8.5339973622967136e+01 -8.9699430364130762e+01 + 11 8.1458057941736399e+00 -2.6121766393843103e+02 1.5492643601104581e+02 + 12 -1.0297805099599069e+02 -9.5172486574472472e+01 1.0819648894293765e+02 + 13 1.0313861845234526e+02 -8.8351137300014869e+01 -6.2073680865003409e+00 + 14 -6.3039130272573630e+01 1.7944087966396282e+02 5.7590563658541996e+01 + 15 4.2428201054682049e+00 1.3619512434927216e+02 -2.2867237122040885e+02 + 16 1.3483332744581298e+02 -5.2052236636380158e+01 6.8852636204178111e+01 + 17 6.3555360619967850e+01 1.1347628488179642e+02 6.7038345330162159e+01 + 18 -3.4161597721916095e+01 -4.0075734854314526e+01 -3.7031073502709120e+01 + 19 3.4139310149618382e+01 -2.8238015309403517e+02 1.1467202498923120e+01 + 20 -8.4437671164196360e+01 -1.1237913829595249e+02 1.2129005682228879e+02 + 21 -3.1150473702765758e+01 2.4466558525686946e+02 6.2302442269328033e+01 + 22 -8.1423238542844469e+00 -2.8290409159807524e+02 8.7726220588161485e+00 + 23 4.9046503898297907e+01 -2.2644433731837914e+01 -1.1694374612937432e+02 + 24 1.3937945191989905e+02 -8.8987379912017815e+01 1.6769570385333179e+02 + 25 1.9475811862357543e+02 1.6286504018802961e+02 -7.3347795242119290e+01 + 26 -7.1269892127955814e+01 -1.7809478750663267e+01 1.2294479367367137e+02 + 27 -6.8391617680507068e+01 -1.9982341830153047e+02 -1.5647303273515331e+02 + 28 1.1385695414507123e+02 1.5287346821313133e+02 1.0714748544581370e+02 + 29 -1.5588139712715383e+02 2.7338214923901506e+02 -7.3538964341222570e+00 + 30 -7.2869896720068823e+01 2.8621045994576667e+02 -7.7726624384066369e+01 + 31 -1.0966168562269243e+02 4.7983060114615256e+01 2.2592123146266931e+02 + 32 1.1016957264107833e+02 -8.2701371521240517e+01 -8.3482985240418913e+01 +run_vdwl: 36279.0101522508 +run_coul: 0 +run_stress: ! |2- + 6.8617284985816324e+04 5.8840338251294852e+04 4.9173412724151705e+04 -8.7320720548068912e+03 -1.4804674260124822e+04 1.4286081929042008e+04 +run_forces: ! |2 + 1 -1.8801881199148622e+04 -2.2952295535468311e+03 7.7538322152248875e+03 + 2 -4.1204309984197471e+03 3.9974180085520034e+03 4.3473920721632103e+03 + 3 -5.3203316436746388e+02 -2.0904013776410811e+03 -2.1889617008630403e+03 + 4 4.2748949639632571e+02 -9.0574308491180966e+02 -3.1452289507637983e+02 + 5 9.6209046948319392e+03 -8.2581113904265112e+03 -1.0446350545430003e+04 + 6 8.9357703719184465e+03 -2.1627075238994030e+03 -2.7910760895159028e+03 + 7 -1.6771483557857286e+04 1.6311574435610137e+04 2.9013646076183518e+03 + 8 4.9281165530366775e+02 -1.9418868071717516e+03 -1.6251488823914694e+03 + 9 -5.8575452704647057e+02 6.4867039915392695e+02 -1.1994332775824771e+03 + 10 -7.5002177028330408e+00 1.3371970267938212e+02 1.7086029496424015e+02 + 11 -7.4112330774614770e+02 4.9496307880222747e+02 -2.7399350083367693e+02 + 12 9.4442081296446895e+02 5.5726294596568221e+02 -4.7445042822603352e+02 + 13 -2.9823453070251580e+03 -1.1243383556731744e+03 2.0393260589681713e+03 + 14 1.4690379110331942e+03 6.8718012562597205e+03 7.4104265907919626e+02 + 15 2.9352021540986340e+02 -6.8464019908249000e+01 -1.5697867591332192e+03 + 16 -1.1187452835505692e+03 -5.0942719099587237e+02 6.1184598184252911e+02 + 17 -1.7474509810876432e+03 -6.0457148035539185e+03 -1.6485264046696952e+03 + 18 4.4607104164218515e+02 3.4893057128796488e+02 -1.0683802675857635e+03 + 19 2.6846560299595676e+03 -1.9604404111237366e+03 7.5179155996129294e+00 + 20 3.1467440677843548e+01 -1.9394341540596807e+02 -1.5452870297451850e+02 + 21 -4.8572604737843960e+01 -5.2368368433832117e+01 5.2006926244007140e+01 + 22 -3.1057917866565361e+02 -3.6203364410569662e+02 -1.9818927476283253e+02 + 23 -3.2519516257159461e+02 1.7981634008567576e+03 -1.0689607287023916e+03 + 24 3.7024818762000746e+02 -1.0714406761271573e+03 -4.7575775136755749e+02 + 25 1.5037085122623180e+03 6.9844106766958621e+03 3.2093828527254896e+03 + 26 1.3948771623559989e+04 -1.2357848450183317e+04 -1.9266918517779788e+04 + 27 -2.3736463612225989e+03 1.7097162179598547e+03 9.9541308990791049e+02 + 28 8.2302550220349713e+03 -1.5285255401371217e+03 1.6767520845541083e+04 + 29 1.2644427071475491e+03 3.0966783186225307e+03 1.2562218506756633e+03 + 30 -6.1186918063631140e+02 3.2678985634373731e+02 3.1389427530946418e+03 + 31 3.6223572246865723e+02 -3.9937104153443983e+02 7.4861364047401173e+02 + 32 5.2799586554934969e+01 4.7896785990086791e+01 2.3701962771752182e+01 +... diff --git a/unittest/force-styles/tests/manybody-pair-nb3b_harmonic.yaml b/unittest/force-styles/tests/manybody-pair-nb3b_harmonic.yaml index f8a77743f6..8ddc442310 100644 --- a/unittest/force-styles/tests/manybody-pair-nb3b_harmonic.yaml +++ b/unittest/force-styles/tests/manybody-pair-nb3b_harmonic.yaml @@ -1,14 +1,17 @@ --- -lammps_version: 5 May 2020 -date_generated: Wed May 27 06:42:57 202 -epsilon: 1.0e-12 +lammps_version: 15 Jun 2020 +date_generated: Mon Jun 29 13:21:51 202 +epsilon: 1e-12 prerequisites: ! | pair nb3b/harmonic pre_commands: ! | variable newton_pair delete variable newton_pair index on + variable units delete + variable units index real post_commands: ! | - change_box all x final 0 4.2 y final 0 4.2 z final 0 4.2 + change_box all x final 0 4.2 y final 0 4.2 z final 0 4.2 + velocity all scale 100.0 input_file: in.manybody pair_style: nb3b/harmonic pair_coeff: ! | @@ -18,139 +21,139 @@ natoms: 64 init_vdwl: 2654.82155652424 init_coul: 0 init_stress: ! |- - -5.1017158429026651e+01 -1.3611903256981696e+01 6.4629061686009067e+01 -8.7135857294938191e+01 -1.1070515375917164e+02 7.5452837495497633e+01 + -5.1017158429026708e+01 -1.3611903256981552e+01 6.4629061686009067e+01 -8.7135857294937580e+01 -1.1070515375917185e+02 7.5452837495497562e+01 init_forces: ! |2 - 1 -1.0877972789090633e+01 2.7818609977822151e+00 5.3286346737471801e-01 - 2 2.3844946347198697e+00 3.8120293270515626e+00 -1.7852915817427366e+01 - 3 -5.5060972496922012e+01 -1.4649767245154461e+01 -8.0050176965474122e+01 - 4 1.7259636030947714e+01 9.3366797180178907e+00 1.5880959275683665e+01 + 1 -1.0877972789090633e+01 2.7818609977822115e+00 5.3286346737471402e-01 + 2 2.3844946347198643e+00 3.8120293270515857e+00 -1.7852915817427341e+01 + 3 -5.5060972496921963e+01 -1.4649767245154461e+01 -8.0050176965474009e+01 + 4 1.7259636030947703e+01 9.3366797180178764e+00 1.5880959275683665e+01 5 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 - 6 1.7794992633465359e+01 -5.3419222655618320e+01 1.6321598833864002e+01 - 7 -6.7476300345434893e+01 6.2036681257356090e+00 -7.5139089756926083e+01 - 8 -2.4916802467563383e+02 3.9421473842157511e+00 -3.9134655098942254e+01 - 9 -4.2488750688310093e+00 4.0608847565742447e+00 -1.2332028245418186e+01 - 10 -5.6132393889097036e+00 1.7823276348533055e+00 1.2023878783019342e+00 - 11 2.7495846047096700e+02 3.6847059220182459e+01 -3.5747872835095954e+01 - 12 -8.5777111027672873e+01 -6.6703893761473649e+00 3.6593219992613264e+01 - 13 2.8150260504826656e+00 4.6881843084850182e+01 -2.8703190101594132e+00 - 14 4.3310482261409405e+01 5.7711396678423561e+01 5.5582267493210210e+01 + 6 1.7794992633465419e+01 -5.3419222655618618e+01 1.6321598833863909e+01 + 7 -6.7476300345423340e+01 6.2036681257305277e+00 -7.5139089756916974e+01 + 8 -2.4916802467563477e+02 3.9421473842150050e+00 -3.9134655098942197e+01 + 9 -4.2488750688310146e+00 4.0608847565742368e+00 -1.2332028245418179e+01 + 10 -5.6132393889096601e+00 1.7823276348532602e+00 1.2023878783018827e+00 + 11 2.7495846047096711e+02 3.6847059220182388e+01 -3.5747872835096082e+01 + 12 -8.5777111027672959e+01 -6.6703893761473418e+00 3.6593219992613299e+01 + 13 2.8150260504829605e+00 4.6881843084849855e+01 -2.8703190101594780e+00 + 14 4.3310482261409398e+01 5.7711396678423561e+01 5.5582267493210239e+01 15 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 - 16 1.2606972666826963e+00 -2.9949919839800152e+01 -3.8329654261193085e+01 - 17 -5.6603372959879501e+01 4.4199755708912090e+00 1.6646523859302970e+01 - 18 2.9145047807552785e+01 -3.8254292709284357e+01 -7.8685029062057863e+00 - 19 -3.9052132885118897e+02 -3.4874531498136278e+01 2.4335359036689007e+02 - 20 3.0523826465323211e+01 -2.7070245767455226e+01 5.8408159705563616e+00 + 16 1.2606972666821876e+00 -2.9949919839796344e+01 -3.8329654261188118e+01 + 17 -5.6603372959879628e+01 4.4199755708913484e+00 1.6646523859303024e+01 + 18 2.9145047807552785e+01 -3.8254292709284357e+01 -7.8685029062057987e+00 + 19 -3.9052132885118920e+02 -3.4874531498136022e+01 2.4335359036689030e+02 + 20 3.0523826465323282e+01 -2.7070245767455212e+01 5.8408159705563483e+00 21 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 22 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 - 23 7.4409325483379803e+01 -6.1338064797828309e+01 -4.0331673797102184e+01 + 23 7.4409325483379916e+01 -6.1338064797828324e+01 -4.0331673797102226e+01 24 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 - 25 -1.5434301681368330e+01 -1.8496773706788222e+01 -4.1692996127143651e+00 - 26 -7.2440757908713049e-01 -1.5411185566412183e+01 3.6729264463045794e+00 - 27 1.4857759801010695e+02 -8.7246598153787403e+01 3.5575180405196285e+00 - 28 1.1863298792067371e+02 8.2702860857456869e+01 1.5436298352562847e+00 - 29 4.7621783523283590e+01 2.8039369004096750e+00 2.7605524532590053e+01 - 30 2.8830156773978769e+02 -3.2784354352079447e+01 1.0018854518372478e+01 + 25 -1.5434301681368334e+01 -1.8496773706788261e+01 -4.1692996127144077e+00 + 26 -7.2440757908713937e-01 -1.5411185566412181e+01 3.6729264463045856e+00 + 27 1.4857759801010724e+02 -8.7246598153787659e+01 3.5575180405192732e+00 + 28 1.1863298792067371e+02 8.2702860857456841e+01 1.5436298352562812e+00 + 29 4.7621783523283653e+01 2.8039369004096772e+00 2.7605524532590049e+01 + 30 2.8830156773978769e+02 -3.2784354352079447e+01 1.0018854518372489e+01 31 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 32 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 - 33 -5.8839244877108614e+00 4.3985789859461818e+01 2.3192635019620489e+01 - 34 -8.7966629741582576e+00 -3.7772557274042633e+00 -5.0822108474305443e+00 - 35 -1.1045699552194318e+02 -2.5865892104728207e+01 -3.3353488725325462e+01 - 36 -3.9928053482362905e+01 -3.7650338080860749e+01 -8.6463197758339003e+00 + 33 -5.8839244877086143e+00 4.3985789859458791e+01 2.3192635019619907e+01 + 34 -8.7966629741582505e+00 -3.7772557274042629e+00 -5.0822108474305479e+00 + 35 -1.1045699552194318e+02 -2.5865892104728044e+01 -3.3353488725325391e+01 + 36 -3.9928053482362998e+01 -3.7650338080860742e+01 -8.6463197758338932e+00 37 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 - 38 3.7625199613228766e-01 -5.9409197479738708e+01 1.1096821440484145e+01 + 38 3.7625199613237004e-01 -5.9409197479738559e+01 1.1096821440484220e+01 39 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 - 40 -4.2079999725616096e+02 1.5030064155408525e+01 2.9502576524714826e+01 - 41 -7.1831348401232091e+00 2.3501863961013282e+01 3.3211487338838609e+01 - 42 -5.4333378031078610e+00 -3.8222885761439054e+00 5.2740780894998984e-01 + 40 -4.2079999725616096e+02 1.5030064155408574e+01 2.9502576524714936e+01 + 41 -7.1831348401232287e+00 2.3501863961013250e+01 3.3211487338838566e+01 + 42 -5.4333378031078574e+00 -3.8222885761439134e+00 5.2740780894998363e-01 43 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 - 44 6.3343303260433999e+01 4.9488759873343774e+01 5.0212324296502423e+01 - 45 4.2425954317559700e+02 5.6875319339115556e+01 -2.5998498159230604e+02 - 46 1.5374524942979843e+02 -2.4634003877741762e+01 -5.9674041391425958e-01 + 44 6.3343303260434006e+01 4.9488759873343746e+01 5.0212324296502395e+01 + 45 4.2425954317559712e+02 5.6875319339115613e+01 -2.5998498159230616e+02 + 46 1.5374524942979843e+02 -2.4634003877741691e+01 -5.9674041391425869e-01 47 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 48 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 - 49 2.4664457425766684e-01 8.5221588811519311e-03 7.1570435255873655e+00 - 50 -2.9771445332463109e+01 -1.3053973386895201e+00 9.5074220439575612e+00 - 51 -1.8696262048502865e+02 -3.0046250420275893e+01 -1.9739208373694105e+01 - 52 -2.3539906256917567e+02 8.1697006804398669e+01 -1.1372898509058719e+02 + 49 2.4664457425767483e-01 8.5221588811448257e-03 7.1570435255873699e+00 + 50 -2.9771445332463266e+01 -1.3053973386896178e+00 9.5074220439575896e+00 + 51 -1.8696262048502857e+02 -3.0046250420275893e+01 -1.9739208373694158e+01 + 52 -2.3539906256917558e+02 8.1697006804398626e+01 -1.1372898509058722e+02 53 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 54 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 - 55 -9.9888474306294608e+00 -6.3056149949578383e+01 -3.8789913572864435e+01 - 56 -1.5108125115180235e+02 8.7451440758083976e+01 6.2279587307098822e+01 - 57 -2.4707820063785416e+01 8.1430106606145536e+00 3.7927211164970971e+00 - 58 -7.9324636824924024e+00 1.1055979589866887e+00 -1.1979321661997941e+01 - 59 8.8647131566710783e+01 3.8727979707847247e+01 4.8159748997763351e+01 - 60 2.3037697796149806e+02 -4.6916609535445453e+00 9.6808251082403842e+01 - 61 8.6364330939177634e+01 1.4895642916188269e+01 9.8020771081533500e+00 - 62 4.1476164742574909e+01 -9.7738882325904193e+00 2.2124574239200477e+01 + 55 -9.9888474306294714e+00 -6.3056149949578362e+01 -3.8789913572864407e+01 + 56 -1.5108125115180263e+02 8.7451440758084161e+01 6.2279587307099106e+01 + 57 -2.4707820063785420e+01 8.1430106606145536e+00 3.7927211164970944e+00 + 58 -7.9324636824924042e+00 1.1055979589866993e+00 -1.1979321661997956e+01 + 59 8.8647131566696885e+01 3.8727979707853429e+01 4.8159748997752480e+01 + 60 2.3037697796149948e+02 -4.6916609535455187e+00 9.6808251082401242e+01 + 61 8.6364330939177592e+01 1.4895642916188271e+01 9.8020771081532168e+00 + 62 4.1476164742574909e+01 -9.7738882325904157e+00 2.2124574239200474e+01 63 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 64 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 -run_vdwl: 2586.23310804073 +run_vdwl: 2496.16387090594 run_coul: 0 run_stress: ! |- - -4.6723183908900717e+02 1.7852419684221977e+02 2.8870764224678692e+02 -7.3768673952427577e+01 8.1285715133964914e+01 -2.2175376931373922e+01 + -3.1050965336040292e+01 -6.3663930994022884e+01 9.4714896330062999e+01 -1.1897654655567628e+02 -6.4811369677402881e+00 1.2347862730997569e+02 run_forces: ! |2 - 1 -1.1750670180272866e+00 1.3131514736699824e+01 -3.8826576290188388e+00 - 2 2.3357180987384143e+00 2.6172640820169175e+01 -1.3859108643114411e+00 - 3 6.0695590546373353e+01 2.0642136613920513e+01 5.4996351260125280e+00 - 4 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 1 -6.6214436114187141e+00 6.8003032240472616e-01 8.1610480878961345e-01 + 2 6.8952756210409225e+00 6.9800495995491607e+00 -2.1085653305920978e+01 + 3 -2.5923266064876653e+01 -7.2254055664041772e-01 -6.8249224259047452e+01 + 4 1.7514735996364870e+01 9.1382329672789950e+00 1.4609547038415045e+01 5 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 - 6 2.4546655526930735e+01 -3.1101905626646428e+01 3.8841426269193406e+01 - 7 -4.9616838878159811e+01 -1.0992414702422360e+01 4.8515728874677269e+00 - 8 -5.6453384170560540e+01 4.7672434067033826e+00 -1.9612102502967304e+00 - 9 -1.8392638626001174e+00 1.1828167793968992e+01 -2.0356506218224546e+01 - 10 -8.6013994200124220e+00 -1.0417698459793890e+01 5.4845710971785913e+00 - 11 6.0381617656756774e+01 -1.6620349247888100e+01 2.2225135196909434e+01 - 12 5.0979659960037345e+01 -2.2641974764565148e+01 8.6466127914636193e+00 + 6 1.8311337599848436e+01 -5.2737007463348519e+01 1.6786691829845285e+01 + 7 -7.5126152872375002e+01 3.9208090425206592e+00 -7.8501700045948425e+01 + 8 -1.7883231274220702e+02 1.2382156266165076e+01 -5.9370199178248981e+01 + 9 5.5713719759234035e+00 5.2160432479756871e+00 -7.2308807479301063e+00 + 10 -8.8969852437999064e-01 -1.4444413139727268e+00 1.1573923441213608e+01 + 11 1.4439507123610309e+02 -4.2519782552988204e+01 -3.4698021577236396e+01 + 12 -7.9891827746142440e+01 -1.3089531661279894e+01 3.3544238612989560e+01 13 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 - 14 9.6203506994347148e+00 2.0490558201590559e+01 3.8564561780893207e+00 + 14 1.5112474793527387e+01 3.7694869755527407e+01 3.7356461110106324e+01 15 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 - 16 4.2696341100597985e+00 -6.4394247758381127e+01 -2.3287529910455991e+00 - 17 -1.7809619943717419e+01 -1.9261779466882487e+00 2.6614972406661607e+01 - 18 -3.0062559069631483e+01 -4.6813849188661194e+01 2.0071390221802680e+01 - 19 2.2231227996316667e+00 5.5240594291246383e+00 -4.0911170180556759e+01 - 20 1.2156858565323886e+02 3.9830629488572413e+01 3.7706116674646424e+01 + 16 8.2461187714168827e-01 -3.3645319303810005e+01 -3.7521462215646530e+01 + 17 -6.1699650496788180e+01 1.2415735742737171e+01 1.3686739582320218e+01 + 18 2.8937858224261120e+01 -3.2763761650136210e+01 -2.1828920543524459e+00 + 19 7.5423787139990210e+01 1.5671749716356253e+01 -7.2118194981816799e+01 + 20 3.1376794755628680e+01 -3.1236998918287441e+01 7.5194815218724624e+00 21 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 - 22 -1.6364437371629357e+01 3.2268779082011257e+01 -2.5552249817970370e+01 - 23 -8.3597998911963472e+01 -1.7654897749235602e+01 7.1337191308940682e+00 + 22 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 23 6.8299963765568918e+01 -5.5707235162344126e+01 -3.8157782755725137e+01 24 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 - 25 1.8771431821434961e+00 3.7184795487210792e+01 -6.1577014025376728e+00 - 26 -2.3472845707924179e+00 -4.2517776291726975e+01 1.4877047560362083e+01 - 27 9.9311610633439727e+01 5.8342547785154601e+01 6.2490107493557900e+01 - 28 8.1997428592624331e+01 4.9305082539955812e+01 -3.1924492771504966e+01 - 29 1.5755014250094833e+01 1.6333818401948033e+01 2.0837131374062341e+01 - 30 4.6444961759604695e+01 2.9380895149140301e+01 -1.2549027721695549e+02 + 25 -1.4057244393584686e+01 -2.0289162180649946e+01 -6.8170959892909968e+00 + 26 -2.0187519714808841e+00 -1.7816926619477194e+01 3.6965530794144814e+00 + 27 1.3550009286410088e+02 -6.7838442433020745e+01 4.3133759785537102e+01 + 28 9.6888228678225971e+01 8.8823964822113297e+01 -5.0921310684595458e+00 + 29 5.0758136978827828e+01 -8.8983484466933565e+00 2.4899348744763654e+00 + 30 2.4524050422835563e+02 -1.3660139575889508e+01 -5.9330622488468725e+00 31 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 32 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 - 33 -5.5005500969351843e+01 -4.4888400262284573e+00 -7.9881718186484276e+00 - 34 1.2391358513429662e+01 4.2205224695342682e+00 -8.7307512727212266e+00 - 35 -6.8048459171953510e+01 -5.0746781744565169e+01 1.6313940341424583e+01 - 36 1.7865132435199360e+00 -4.6549184761244362e+01 -1.8272256554692827e+00 + 33 -5.9389712314058594e+00 5.1469485825476355e+01 1.5282542616314375e+01 + 34 -4.5946066700985710e+00 -4.4047708825320973e+00 -2.5896753139020205e+00 + 35 -7.6885241750207925e+01 -3.7858402496175358e+00 -1.0416208866746173e+01 + 36 -4.3251004252238630e+01 -3.0812732079587814e+01 1.5493207265310204e+01 37 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 - 38 2.9421387114598204e+01 -4.2086146965794974e+01 1.6800774864890816e+01 + 38 1.5022834606957978e+00 -6.0344797002288928e+01 9.7293521036630022e+00 39 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 - 40 -3.8166935284463143e+01 4.1676208829419494e+01 -7.1239426844135672e+00 - 41 8.9777269850365204e-01 4.4289814981844543e+01 2.5485173899838237e+01 - 42 1.1863601054760339e+01 -5.5963639046028719e+00 -2.6542953642884349e+01 - 43 -1.4318530885017411e+01 2.2057393766498969e+01 4.4372607097293105e+01 - 44 1.4461973377279693e+02 -4.1284603574668154e+01 3.8323143295598186e+01 - 45 1.2862655952927490e+01 5.8051830292127509e+00 5.6062109819492129e+01 - 46 3.9950844327128916e+00 1.0816632720372052e+01 2.7359382513314188e+01 + 40 -2.7902725378002401e+02 1.1520394360420082e+02 7.6029058865840060e+00 + 41 1.9875813960392859e+00 2.5898055298981063e+01 2.5255670110917048e+01 + 42 -1.2584608623742763e+00 -5.6180254661161735e+00 4.3355672941135257e+00 + 43 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 44 6.1017414877125326e+01 2.3847994346393680e+01 4.3262891796747915e+01 + 45 -5.7359830701947253e+01 3.4172133537980798e+01 8.2107294758634893e+01 + 46 1.1199817492468900e+02 -2.3757850899635525e+01 1.5384138774546539e+01 47 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 - 48 -8.2471941292632351e+00 7.2384082709877987e+01 7.6275073773084081e+00 - 49 7.0874669396804322e+00 1.0710819490993529e+01 6.8487083926871106e+00 - 50 -1.3702452391153543e+01 -3.1315676795828317e+01 -2.9390721004259010e+01 - 51 -5.1841862825969486e+01 -6.5229295766089322e+01 6.4345194792685618e+01 - 52 -1.0076730856559496e+02 -3.1323724404286470e+01 -2.7740629900930994e+01 + 48 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 49 -6.7826664559677354e+00 -1.8594048126803564e-01 5.8956046460290992e+00 + 50 -1.9821181472416256e+01 -1.8120466552580972e+00 4.4346376430197623e+00 + 51 -1.4173233779399769e+02 -4.2613815950203332e+01 -1.2166481368092634e+00 + 52 -1.8872790570220141e+02 8.0898507623818261e+01 -1.1989280050987685e+02 53 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 54 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 - 55 -1.1783270126548655e+02 -1.9472584883618183e-01 -3.6574242640823016e+01 - 56 -5.3306408717222062e+01 -4.8054342798707381e+01 -3.9204734285983008e+01 - 57 -1.1225984573690962e+01 2.0902821304606945e+01 -1.0842828823499091e+00 - 58 -1.5639600973783883e+01 3.7055729017065011e+00 -1.9828404272923528e+01 - 59 5.4139156830996429e+00 5.9778757589813964e+01 -2.3883800709664158e+01 - 60 4.0289832362530653e+01 -4.1876270741423269e+00 -1.8019718733793713e+01 - 61 -2.9803789778276474e+01 -1.2846624364406747e+00 -5.0425625243893258e+01 - 62 8.0660338957777533e-01 5.4686577469802673e+00 -1.3547627168270241e+01 - 63 -8.5708358255591914e+00 -3.0150178540572348e+01 -1.4967860711132145e+01 - 64 9.0239994663437773e-01 5.5410990098449542e-01 4.1571851677482030e+00 + 55 -6.3070794314782628e+00 -3.9493489491808347e+01 -3.5654394269934343e+01 + 56 -1.5536342282055168e+02 6.8759186611823679e+01 1.9484632984497214e+01 + 57 -1.6311185567740008e+01 5.5975547175367124e+00 -1.4425077069506711e+00 + 58 -6.4235602672067103e+00 2.6970192907549695e+00 -1.0923186469627634e+01 + 59 9.2546558740452369e+01 4.2666948660770792e+01 4.7533444080031025e+01 + 60 1.4559994425694987e+02 -3.5129424621390534e+01 1.1583916891031559e+02 + 61 5.9875382725562169e+01 6.8646156842044093e+00 2.3254650701763939e+00 + 62 3.9267471066687051e+01 -1.0670715066325148e+01 1.9913762076436925e+01 + 63 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 + 64 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 ... diff --git a/unittest/force-styles/tests/pair_table_beck.txt b/unittest/force-styles/tests/pair_table_beck.txt index 279c3a4ec8..f1fa321b95 100644 --- a/unittest/force-styles/tests/pair_table_beck.txt +++ b/unittest/force-styles/tests/pair_table_beck.txt @@ -1,3 +1,4 @@ +# DATE: 2020-06-25 UNITS: metal # Pair potential beck for atom types 1 1: i,r,energy,force beck_1_1 diff --git a/unittest/formats/CMakeLists.txt b/unittest/formats/CMakeLists.txt index aaf6731855..bf4300ff2e 100644 --- a/unittest/formats/CMakeLists.txt +++ b/unittest/formats/CMakeLists.txt @@ -3,6 +3,11 @@ add_executable(test_atom_styles test_atom_styles.cpp) target_link_libraries(test_atom_styles PRIVATE lammps GTest::GMock GTest::GTest) add_test(NAME AtomStyles COMMAND test_atom_styles WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +add_executable(test_pair_unit_convert test_pair_unit_convert.cpp) +target_link_libraries(test_pair_unit_convert PRIVATE lammps GTest::GMock GTest::GTest) +add_test(NAME PairUnitConvert COMMAND test_pair_unit_convert WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +set_tests_properties(PairUnitConvert PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") + add_executable(test_potential_file_reader test_potential_file_reader.cpp) target_link_libraries(test_potential_file_reader PRIVATE lammps GTest::GMock GTest::GTest) add_test(NAME PotentialFileReader COMMAND test_potential_file_reader WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/unittest/formats/test_pair_unit_convert.cpp b/unittest/formats/test_pair_unit_convert.cpp new file mode 100644 index 0000000000..6c4b38397d --- /dev/null +++ b/unittest/formats/test_pair_unit_convert.cpp @@ -0,0 +1,992 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#include "atom.h" +#include "force.h" +#include "info.h" +#include "input.h" +#include "lammps.h" +#include "output.h" +#include "pair.h" +#include "thermo.h" +#include "utils.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +#include +#include +#include + +// whether to print verbose output (i.e. not capturing LAMMPS screen output). +bool verbose = false; + +using LAMMPS_NS::utils::split_words; + +namespace LAMMPS_NS { +using ::testing::Eq; + +// eV to kcal/mol conversion constant (CODATA 2018) +const double ev_convert = utils::get_conversion_factor(utils::ENERGY, utils::METAL2REAL); +// 1atm in bar +const double p_convert = 1.01325; +// relative error for comparing numbers +// cannot use smaller value due to lack of consistency +// of data in update.cpp. could be 1.0e-12 +const double rel_error = 5.0e-7; + +class PairUnitConvertTest : public ::testing::Test { +protected: + LAMMPS *lmp; + Info *info; + double fold[4][3]; + + void SetUp() override + { + const char *args[] = {"PairUnitConvertTest", "-log", "none", "-echo", "screen", "-nocite"}; + char **argv = (char **)args; + int argc = sizeof(args) / sizeof(char *); + if (!verbose) ::testing::internal::CaptureStdout(); + lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); + if (!verbose) ::testing::internal::GetCapturedStdout(); + ASSERT_NE(lmp, nullptr); + if (!verbose) ::testing::internal::CaptureStdout(); + info = new Info(lmp); + lmp->input->one("units metal"); + lmp->input->one("dimension 3"); + lmp->input->one("region box block -4 4 -4 4 -4 4"); + lmp->input->one("create_box 2 box"); + lmp->input->one("create_atoms 1 single -1.1 1.2 0.0 units box"); + lmp->input->one("create_atoms 1 single -1.2 -1.1 0.0 units box"); + lmp->input->one("create_atoms 2 single 0.9 1.0 0.0 units box"); + lmp->input->one("create_atoms 2 single 1.0 -0.9 0.0 units box"); + lmp->input->one("pair_style zero 4.0"); + lmp->input->one("pair_coeff * *"); + lmp->input->one("mass * 1.0"); + lmp->input->one("write_data test_pair_unit_convert.data nocoeff"); + lmp->input->one("clear"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + } + + void TearDown() override + { + if (!verbose) ::testing::internal::CaptureStdout(); + delete info; + delete lmp; + if (!verbose) ::testing::internal::GetCapturedStdout(); + remove("test_pair_unit_convert.data"); + } +}; + +TEST_F(PairUnitConvertTest, zero) +{ + // check if the prerequisite pair style is available + if (!info->has_style("pair", "zero")) GTEST_SKIP(); + + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("units metal"); + lmp->input->one("read_data test_pair_unit_convert.data"); + lmp->input->one("pair_style zero 6.0"); + lmp->input->one("pair_coeff * *"); + lmp->input->one("run 0 post no"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + // copy pressure, energy, and force from first step + double pold; + lmp->output->thermo->evaluate_keyword("press", &pold); + double eold = lmp->force->pair->eng_vdwl + lmp->force->pair->eng_coul; + double **f = lmp->atom->f; + for (int i = 0; i < 4; ++i) + for (int j = 0; j < 3; ++j) + fold[i][j] = f[i][j]; + + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("clear"); + lmp->input->one("units real"); + lmp->input->one("read_data test_pair_unit_convert.data"); + lmp->input->one("pair_style zero 6.0"); + lmp->input->one("pair_coeff * *"); + lmp->input->one("run 0 post no"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + double pnew; + lmp->output->thermo->evaluate_keyword("press", &pnew); + EXPECT_NEAR(pold, p_convert * pnew, fabs(pnew * rel_error)); + double enew = lmp->force->pair->eng_vdwl + lmp->force->pair->eng_coul; + EXPECT_NEAR(ev_convert * eold, enew, fabs(enew * rel_error)); + + f = lmp->atom->f; + for (int i = 0; i < 4; ++i) + for (int j = 0; j < 3; ++j) + EXPECT_NEAR(ev_convert * fold[i][j], f[i][j], fabs(f[i][j] * rel_error)); +} + +TEST_F(PairUnitConvertTest, lj_cut) +{ + // check if the prerequisite pair style is available + if (!info->has_style("pair", "lj/cut")) GTEST_SKIP(); + + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("units metal"); + lmp->input->one("read_data test_pair_unit_convert.data"); + lmp->input->one("pair_style lj/cut 6.0"); + lmp->input->one("pair_coeff * * 0.01014286346782117 2.0"); + remove("test.table.metal"); + lmp->input->one("pair_write 1 1 1000 r 0.1 6.0 test.table.metal lj_1_1"); + lmp->input->one("pair_write 1 2 1000 r 0.1 6.0 test.table.metal lj_1_2"); + lmp->input->one("pair_write 2 2 1000 r 0.1 6.0 test.table.metal lj_2_2"); + lmp->input->one("run 0 post no"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + // copy pressure, energy, and force from first step + double pold; + lmp->output->thermo->evaluate_keyword("press", &pold); + double eold = lmp->force->pair->eng_vdwl + lmp->force->pair->eng_coul; + double **f = lmp->atom->f; + for (int i = 0; i < 4; ++i) + for (int j = 0; j < 3; ++j) + fold[i][j] = f[i][j]; + + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("clear"); + lmp->input->one("units real"); + lmp->input->one("read_data test_pair_unit_convert.data"); + lmp->input->one("pair_style lj/cut 6.0"); + lmp->input->one("pair_coeff * * 0.2339 2.0"); + remove("test.table.real"); + lmp->input->one("pair_write 1 1 1000 r 0.1 6.0 test.table.real lj_1_1"); + lmp->input->one("pair_write 1 2 1000 r 0.1 6.0 test.table.real lj_1_2"); + lmp->input->one("pair_write 2 2 1000 r 0.1 6.0 test.table.real lj_2_2"); + lmp->input->one("run 0 post no"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + double pnew; + lmp->output->thermo->evaluate_keyword("press", &pnew); + EXPECT_NEAR(pold, p_convert * pnew, fabs(pnew * rel_error)); + double enew = lmp->force->pair->eng_vdwl + lmp->force->pair->eng_coul; + EXPECT_NEAR(ev_convert * eold, enew, fabs(enew * rel_error)); + + f = lmp->atom->f; + for (int i = 0; i < 4; ++i) + for (int j = 0; j < 3; ++j) + EXPECT_NEAR(ev_convert * fold[i][j], f[i][j], fabs(f[i][j] * rel_error)); +} + +TEST_F(PairUnitConvertTest, eam) +{ + // check if the prerequisite pair style is available + if (!info->has_style("pair", "eam")) GTEST_SKIP(); + + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("units metal"); + lmp->input->one("read_data test_pair_unit_convert.data"); + lmp->input->one("pair_style eam"); + lmp->input->one("pair_coeff * * Cu_u3.eam"); + lmp->input->one("run 0 post no"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + // copy pressure, energy, and force from first step + double pold; + lmp->output->thermo->evaluate_keyword("press", &pold); + double eold = lmp->force->pair->eng_vdwl + lmp->force->pair->eng_coul; + double **f = lmp->atom->f; + for (int i = 0; i < 4; ++i) + for (int j = 0; j < 3; ++j) + fold[i][j] = f[i][j]; + + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("clear"); + lmp->input->one("units real"); + lmp->input->one("read_data test_pair_unit_convert.data"); + lmp->input->one("pair_style eam"); + lmp->input->one("pair_coeff * * Cu_u3.eam"); + lmp->input->one("run 0 post no"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + double pnew; + lmp->output->thermo->evaluate_keyword("press", &pnew); + EXPECT_NEAR(pold, p_convert * pnew, fabs(pnew * rel_error)); + double enew = lmp->force->pair->eng_vdwl + lmp->force->pair->eng_coul; + EXPECT_NEAR(ev_convert * eold, enew, fabs(enew * rel_error)); + + f = lmp->atom->f; + for (int i = 0; i < 4; ++i) + for (int j = 0; j < 3; ++j) + EXPECT_NEAR(ev_convert * fold[i][j], f[i][j], fabs(f[i][j] * rel_error)); +} + +TEST_F(PairUnitConvertTest, eam_alloy) +{ + // check if the prerequisite pair style is available + if (!info->has_style("pair", "eam/alloy")) GTEST_SKIP(); + + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("units metal"); + lmp->input->one("read_data test_pair_unit_convert.data"); + lmp->input->one("pair_style eam/alloy"); + lmp->input->one("pair_coeff * * AlCu.eam.alloy Al Cu"); + lmp->input->one("run 0 post no"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + // copy pressure, energy, and force from first step + double pold; + lmp->output->thermo->evaluate_keyword("press", &pold); + double eold = lmp->force->pair->eng_vdwl + lmp->force->pair->eng_coul; + double **f = lmp->atom->f; + for (int i = 0; i < 4; ++i) + for (int j = 0; j < 3; ++j) + fold[i][j] = f[i][j]; + + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("clear"); + lmp->input->one("units real"); + lmp->input->one("read_data test_pair_unit_convert.data"); + lmp->input->one("pair_style eam/alloy"); + lmp->input->one("pair_coeff * * AlCu.eam.alloy Al Cu"); + lmp->input->one("run 0 post no"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + double pnew; + lmp->output->thermo->evaluate_keyword("press", &pnew); + EXPECT_NEAR(pold, p_convert * pnew, fabs(pnew * rel_error)); + double enew = lmp->force->pair->eng_vdwl + lmp->force->pair->eng_coul; + EXPECT_NEAR(ev_convert * eold, enew, fabs(enew * rel_error)); + + f = lmp->atom->f; + for (int i = 0; i < 4; ++i) + for (int j = 0; j < 3; ++j) + EXPECT_NEAR(ev_convert * fold[i][j], f[i][j], fabs(f[i][j] * rel_error)); +} + +TEST_F(PairUnitConvertTest, eam_fs) +{ + // check if the prerequisite pair style is available + if (!info->has_style("pair", "eam/fs")) GTEST_SKIP(); + + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("units metal"); + lmp->input->one("read_data test_pair_unit_convert.data"); + lmp->input->one("pair_style eam/fs"); + lmp->input->one("pair_coeff * * FeP_mm.eam.fs Fe P"); + lmp->input->one("run 0 post no"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + // copy pressure, energy, and force from first step + double pold; + lmp->output->thermo->evaluate_keyword("press", &pold); + double eold = lmp->force->pair->eng_vdwl + lmp->force->pair->eng_coul; + double **f = lmp->atom->f; + for (int i = 0; i < 4; ++i) + for (int j = 0; j < 3; ++j) + fold[i][j] = f[i][j]; + + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("clear"); + lmp->input->one("units real"); + lmp->input->one("read_data test_pair_unit_convert.data"); + lmp->input->one("pair_style eam/fs"); + lmp->input->one("pair_coeff * * FeP_mm.eam.fs Fe P"); + lmp->input->one("run 0 post no"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + double pnew; + lmp->output->thermo->evaluate_keyword("press", &pnew); + EXPECT_NEAR(pold, p_convert * pnew, fabs(pnew * rel_error)); + double enew = lmp->force->pair->eng_vdwl + lmp->force->pair->eng_coul; + EXPECT_NEAR(ev_convert * eold, enew, fabs(enew * rel_error)); + + f = lmp->atom->f; + for (int i = 0; i < 4; ++i) + for (int j = 0; j < 3; ++j) + EXPECT_NEAR(ev_convert * fold[i][j], f[i][j], fabs(f[i][j] * rel_error)); +} + +TEST_F(PairUnitConvertTest, eam_cd) +{ + // check if the prerequisite pair style is available + if (!info->has_style("pair", "eam/cd")) GTEST_SKIP(); + + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("units metal"); + lmp->input->one("read_data test_pair_unit_convert.data"); + lmp->input->one("pair_style eam/cd"); + lmp->input->one("pair_coeff * * FeCr.cdeam Cr Fe"); + lmp->input->one("run 0 post no"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + // copy pressure, energy, and force from first step + double pold; + lmp->output->thermo->evaluate_keyword("press", &pold); + double eold = lmp->force->pair->eng_vdwl + lmp->force->pair->eng_coul; + double **f = lmp->atom->f; + for (int i = 0; i < 4; ++i) + for (int j = 0; j < 3; ++j) + fold[i][j] = f[i][j]; + + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("clear"); + lmp->input->one("units real"); + lmp->input->one("read_data test_pair_unit_convert.data"); + lmp->input->one("pair_style eam/cd"); + lmp->input->one("pair_coeff * * FeCr.cdeam Cr Fe"); + lmp->input->one("run 0 post no"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + double pnew; + lmp->output->thermo->evaluate_keyword("press", &pnew); + EXPECT_NEAR(pold, p_convert * pnew, fabs(pnew * rel_error)); + double enew = lmp->force->pair->eng_vdwl + lmp->force->pair->eng_coul; + EXPECT_NEAR(ev_convert * eold, enew, fabs(enew * rel_error)); + + f = lmp->atom->f; + for (int i = 0; i < 4; ++i) + for (int j = 0; j < 3; ++j) + EXPECT_NEAR(ev_convert * fold[i][j], f[i][j], fabs(f[i][j] * rel_error)); +} + +TEST_F(PairUnitConvertTest, eim) +{ + // check if the prerequisite pair style is available + if (!info->has_style("pair", "eim")) GTEST_SKIP(); + + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("units metal"); + lmp->input->one("read_data test_pair_unit_convert.data"); + lmp->input->one("pair_style eim"); + lmp->input->one("pair_coeff * * Na Cl ffield.eim Na Cl"); + lmp->input->one("run 0 post no"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + // copy pressure, energy, and force from first step + double pold; + lmp->output->thermo->evaluate_keyword("press", &pold); + double eold = lmp->force->pair->eng_vdwl + lmp->force->pair->eng_coul; + double **f = lmp->atom->f; + for (int i = 0; i < 4; ++i) + for (int j = 0; j < 3; ++j) + fold[i][j] = f[i][j]; + + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("clear"); + lmp->input->one("units real"); + lmp->input->one("read_data test_pair_unit_convert.data"); + lmp->input->one("pair_style eim"); + lmp->input->one("pair_coeff * * Na Cl ffield.eim Na Cl"); + lmp->input->one("run 0 post no"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + double pnew; + lmp->output->thermo->evaluate_keyword("press", &pnew); + EXPECT_NEAR(pold, p_convert * pnew, fabs(pnew * rel_error)); + double enew = lmp->force->pair->eng_vdwl + lmp->force->pair->eng_coul; + EXPECT_NEAR(ev_convert * eold, enew, fabs(enew * rel_error)); + + f = lmp->atom->f; + for (int i = 0; i < 4; ++i) + for (int j = 0; j < 3; ++j) + EXPECT_NEAR(ev_convert * fold[i][j], f[i][j], fabs(f[i][j] * rel_error)); +} + +TEST_F(PairUnitConvertTest, gw) +{ + // check if the prerequisite pair style is available + if (!info->has_style("pair", "gw")) GTEST_SKIP(); + + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("units metal"); + lmp->input->one("read_data test_pair_unit_convert.data"); + lmp->input->one("pair_style gw"); + lmp->input->one("pair_coeff * * SiC.gw Si C"); + lmp->input->one("run 0 post no"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + // copy pressure, energy, and force from first step + double pold; + lmp->output->thermo->evaluate_keyword("press", &pold); + double eold = lmp->force->pair->eng_vdwl + lmp->force->pair->eng_coul; + double **f = lmp->atom->f; + for (int i = 0; i < 4; ++i) + for (int j = 0; j < 3; ++j) + fold[i][j] = f[i][j]; + + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("clear"); + lmp->input->one("units real"); + lmp->input->one("read_data test_pair_unit_convert.data"); + lmp->input->one("pair_style gw"); + lmp->input->one("pair_coeff * * SiC.gw Si C"); + lmp->input->one("run 0 post no"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + double pnew; + lmp->output->thermo->evaluate_keyword("press", &pnew); + EXPECT_NEAR(pold, p_convert * pnew, fabs(pnew * rel_error)); + double enew = lmp->force->pair->eng_vdwl + lmp->force->pair->eng_coul; + EXPECT_NEAR(ev_convert * eold, enew, fabs(enew * rel_error)); + + f = lmp->atom->f; + for (int i = 0; i < 4; ++i) + for (int j = 0; j < 3; ++j) + EXPECT_NEAR(ev_convert * fold[i][j], f[i][j], fabs(f[i][j] * rel_error)); +} + +TEST_F(PairUnitConvertTest, gw_zbl) +{ + // check if the prerequisite pair style is available + if (!info->has_style("pair", "gw/zbl")) GTEST_SKIP(); + + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("units metal"); + lmp->input->one("read_data test_pair_unit_convert.data"); + lmp->input->one("pair_style gw/zbl"); + lmp->input->one("pair_coeff * * SiC.gw.zbl Si C"); + lmp->input->one("run 0 post no"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + // copy pressure, energy, and force from first step + double pold; + lmp->output->thermo->evaluate_keyword("press", &pold); + double eold = lmp->force->pair->eng_vdwl + lmp->force->pair->eng_coul; + double **f = lmp->atom->f; + for (int i = 0; i < 4; ++i) + for (int j = 0; j < 3; ++j) + fold[i][j] = f[i][j]; + + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("clear"); + lmp->input->one("units real"); + lmp->input->one("read_data test_pair_unit_convert.data"); + lmp->input->one("pair_style gw/zbl"); + lmp->input->one("pair_coeff * * SiC.gw.zbl Si C"); + lmp->input->one("run 0 post no"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + double pnew; + lmp->output->thermo->evaluate_keyword("press", &pnew); + EXPECT_NEAR(pold, p_convert * pnew, fabs(pnew * rel_error)); + double enew = lmp->force->pair->eng_vdwl + lmp->force->pair->eng_coul; + EXPECT_NEAR(ev_convert * eold, enew, fabs(enew * rel_error)); + + f = lmp->atom->f; + for (int i = 0; i < 4; ++i) + for (int j = 0; j < 3; ++j) + EXPECT_NEAR(ev_convert * fold[i][j], f[i][j], fabs(f[i][j] * rel_error)); +} + +TEST_F(PairUnitConvertTest, nb3b_harmonic) +{ + // check if the prerequisite pair style is available + if (!info->has_style("pair", "nb3b/harmonic")) GTEST_SKIP(); + + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("units metal"); + lmp->input->one("read_data test_pair_unit_convert.data"); + lmp->input->one("pair_style nb3b/harmonic"); + lmp->input->one("pair_coeff * * MOH.nb3b.harmonic M O"); + lmp->input->one("run 0 post no"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + // copy pressure, energy, and force from first step + double pold; + lmp->output->thermo->evaluate_keyword("press", &pold); + double eold = lmp->force->pair->eng_vdwl + lmp->force->pair->eng_coul; + double **f = lmp->atom->f; + for (int i = 0; i < 4; ++i) + for (int j = 0; j < 3; ++j) + fold[i][j] = f[i][j]; + + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("clear"); + lmp->input->one("units real"); + lmp->input->one("read_data test_pair_unit_convert.data"); + lmp->input->one("pair_style nb3b/harmonic"); + lmp->input->one("pair_coeff * * MOH.nb3b.harmonic M O"); + lmp->input->one("run 0 post no"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + double pnew; + lmp->output->thermo->evaluate_keyword("press", &pnew); + EXPECT_NEAR(pold, p_convert * pnew, fabs(pnew * rel_error)); + double enew = lmp->force->pair->eng_vdwl + lmp->force->pair->eng_coul; + EXPECT_NEAR(ev_convert * eold, enew, fabs(enew * rel_error)); + + f = lmp->atom->f; + for (int i = 0; i < 4; ++i) + for (int j = 0; j < 3; ++j) + EXPECT_NEAR(ev_convert * fold[i][j], f[i][j], fabs(f[i][j] * rel_error)); +} + +TEST_F(PairUnitConvertTest, sw) +{ + // check if the prerequisite pair style is available + if (!info->has_style("pair", "sw")) GTEST_SKIP(); + + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("units metal"); + lmp->input->one("read_data test_pair_unit_convert.data"); + lmp->input->one("pair_style sw"); + lmp->input->one("pair_coeff * * GaN.sw Ga N"); + lmp->input->one("run 0 post no"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + // copy pressure, energy, and force from first step + double pold; + lmp->output->thermo->evaluate_keyword("press", &pold); + double eold = lmp->force->pair->eng_vdwl + lmp->force->pair->eng_coul; + double **f = lmp->atom->f; + for (int i = 0; i < 4; ++i) + for (int j = 0; j < 3; ++j) + fold[i][j] = f[i][j]; + + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("clear"); + lmp->input->one("units real"); + lmp->input->one("read_data test_pair_unit_convert.data"); + lmp->input->one("pair_style sw"); + lmp->input->one("pair_coeff * * GaN.sw Ga N"); + lmp->input->one("run 0 post no"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + double pnew; + lmp->output->thermo->evaluate_keyword("press", &pnew); + EXPECT_NEAR(pold, p_convert * pnew, fabs(pnew * rel_error)); + double enew = lmp->force->pair->eng_vdwl + lmp->force->pair->eng_coul; + EXPECT_NEAR(ev_convert * eold, enew, fabs(enew * rel_error)); + + f = lmp->atom->f; + for (int i = 0; i < 4; ++i) + for (int j = 0; j < 3; ++j) + EXPECT_NEAR(ev_convert * fold[i][j], f[i][j], fabs(f[i][j] * rel_error)); +} + +TEST_F(PairUnitConvertTest, table_metal2real) +{ + // check if the prerequisite pair style is available + if (!info->has_style("pair", "table")) GTEST_SKIP(); + + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("units metal"); + lmp->input->one("read_data test_pair_unit_convert.data"); + lmp->input->one("pair_style table linear 1000"); + lmp->input->one("pair_coeff 1 1 test.table.metal lj_1_1"); + lmp->input->one("pair_coeff 1 2 test.table.metal lj_1_2"); + lmp->input->one("pair_coeff 2 2 test.table.metal lj_2_2"); + lmp->input->one("run 0 post no"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + // copy pressure, energy, and force from first step + double pold; + lmp->output->thermo->evaluate_keyword("press", &pold); + double eold = lmp->force->pair->eng_vdwl + lmp->force->pair->eng_coul; + double **f = lmp->atom->f; + for (int i = 0; i < 4; ++i) + for (int j = 0; j < 3; ++j) + fold[i][j] = f[i][j]; + + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("clear"); + lmp->input->one("units real"); + lmp->input->one("read_data test_pair_unit_convert.data"); + lmp->input->one("pair_style table linear 1000"); + lmp->input->one("pair_coeff 1 1 test.table.metal lj_1_1"); + lmp->input->one("pair_coeff 1 2 test.table.metal lj_1_2"); + lmp->input->one("pair_coeff 2 2 test.table.metal lj_2_2"); + lmp->input->one("run 0 post no"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + double pnew; + lmp->output->thermo->evaluate_keyword("press", &pnew); + EXPECT_NEAR(pold, p_convert * pnew, fabs(pnew * rel_error)); + double enew = lmp->force->pair->eng_vdwl + lmp->force->pair->eng_coul; + EXPECT_NEAR(ev_convert * eold, enew, fabs(enew * rel_error)); + + f = lmp->atom->f; + for (int i = 0; i < 4; ++i) + for (int j = 0; j < 3; ++j) + EXPECT_NEAR(ev_convert * fold[i][j], f[i][j], fabs(f[i][j] * rel_error)); +} + +TEST_F(PairUnitConvertTest, table_real2metal) +{ + // check if the prerequisite pair style is available + if (!info->has_style("pair", "table")) GTEST_SKIP(); + + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("units real"); + lmp->input->one("read_data test_pair_unit_convert.data"); + lmp->input->one("pair_style table linear 1000"); + lmp->input->one("pair_coeff 1 1 test.table.real lj_1_1"); + lmp->input->one("pair_coeff 1 2 test.table.real lj_1_2"); + lmp->input->one("pair_coeff 2 2 test.table.real lj_2_2"); + lmp->input->one("run 0 post no"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + // copy pressure, energy, and force from first step + double pold; + lmp->output->thermo->evaluate_keyword("press", &pold); + double eold = lmp->force->pair->eng_vdwl + lmp->force->pair->eng_coul; + double **f = lmp->atom->f; + for (int i = 0; i < 4; ++i) + for (int j = 0; j < 3; ++j) + fold[i][j] = f[i][j]; + + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("clear"); + lmp->input->one("units metal"); + lmp->input->one("read_data test_pair_unit_convert.data"); + lmp->input->one("pair_style table linear 1000"); + lmp->input->one("pair_coeff 1 1 test.table.real lj_1_1"); + lmp->input->one("pair_coeff 1 2 test.table.real lj_1_2"); + lmp->input->one("pair_coeff 2 2 test.table.real lj_2_2"); + lmp->input->one("run 0 post no"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + double pnew; + lmp->output->thermo->evaluate_keyword("press", &pnew); + EXPECT_NEAR(pold, 1.0/p_convert * pnew, fabs(pnew * rel_error)); + double enew = lmp->force->pair->eng_vdwl + lmp->force->pair->eng_coul; + EXPECT_NEAR(1.0/ev_convert * eold, enew, fabs(enew * rel_error)); + + f = lmp->atom->f; + for (int i = 0; i < 4; ++i) + for (int j = 0; j < 3; ++j) + EXPECT_NEAR(1.0/ev_convert * fold[i][j], f[i][j], + fabs(f[i][j] * rel_error)); +} + +TEST_F(PairUnitConvertTest, tersoff) +{ + // check if the prerequisite pair style is available + if (!info->has_style("pair", "tersoff")) GTEST_SKIP(); + + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("units metal"); + lmp->input->one("read_data test_pair_unit_convert.data"); + lmp->input->one("pair_style tersoff"); + lmp->input->one("pair_coeff * * SiC.tersoff Si C"); + lmp->input->one("run 0 post no"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + // copy pressure, energy, and force from first step + double pold; + lmp->output->thermo->evaluate_keyword("press", &pold); + double eold = lmp->force->pair->eng_vdwl + lmp->force->pair->eng_coul; + double **f = lmp->atom->f; + for (int i = 0; i < 4; ++i) + for (int j = 0; j < 3; ++j) + fold[i][j] = f[i][j]; + + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("clear"); + lmp->input->one("units real"); + lmp->input->one("read_data test_pair_unit_convert.data"); + lmp->input->one("pair_style tersoff"); + lmp->input->one("pair_coeff * * SiC.tersoff Si C"); + lmp->input->one("run 0 post no"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + double pnew; + lmp->output->thermo->evaluate_keyword("press", &pnew); + EXPECT_NEAR(pold, p_convert * pnew, fabs(pnew * rel_error)); + double enew = lmp->force->pair->eng_vdwl + lmp->force->pair->eng_coul; + EXPECT_NEAR(ev_convert * eold, enew, fabs(enew * rel_error)); + + f = lmp->atom->f; + for (int i = 0; i < 4; ++i) + for (int j = 0; j < 3; ++j) + EXPECT_NEAR(ev_convert * fold[i][j], f[i][j], fabs(f[i][j] * rel_error)); +} + +TEST_F(PairUnitConvertTest, tersoff_mod) +{ + // check if the prerequisite pair style is available + if (!info->has_style("pair", "tersoff/mod")) GTEST_SKIP(); + + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("units metal"); + lmp->input->one("read_data test_pair_unit_convert.data"); + lmp->input->one("pair_style tersoff/mod"); + lmp->input->one("pair_coeff * * Si.tersoff.mod Si Si"); + lmp->input->one("run 0 post no"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + // copy pressure, energy, and force from first step + double pold; + lmp->output->thermo->evaluate_keyword("press", &pold); + double eold = lmp->force->pair->eng_vdwl + lmp->force->pair->eng_coul; + double **f = lmp->atom->f; + for (int i = 0; i < 4; ++i) + for (int j = 0; j < 3; ++j) + fold[i][j] = f[i][j]; + + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("clear"); + lmp->input->one("units real"); + lmp->input->one("read_data test_pair_unit_convert.data"); + lmp->input->one("pair_style tersoff/mod"); + lmp->input->one("pair_coeff * * Si.tersoff.mod Si Si"); + lmp->input->one("run 0 post no"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + double pnew; + lmp->output->thermo->evaluate_keyword("press", &pnew); + EXPECT_NEAR(pold, p_convert * pnew, fabs(pnew * rel_error)); + double enew = lmp->force->pair->eng_vdwl + lmp->force->pair->eng_coul; + EXPECT_NEAR(ev_convert * eold, enew, fabs(enew * rel_error)); + + f = lmp->atom->f; + for (int i = 0; i < 4; ++i) + for (int j = 0; j < 3; ++j) + EXPECT_NEAR(ev_convert * fold[i][j], f[i][j], fabs(f[i][j] * rel_error)); +} + +TEST_F(PairUnitConvertTest, tersoff_mod_c) +{ + // check if the prerequisite pair style is available + if (!info->has_style("pair", "tersoff/mod/c")) GTEST_SKIP(); + + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("units metal"); + lmp->input->one("read_data test_pair_unit_convert.data"); + lmp->input->one("pair_style tersoff/mod/c"); + lmp->input->one("pair_coeff * * Si.tersoff.modc Si Si"); + lmp->input->one("run 0 post no"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + // copy pressure, energy, and force from first step + double pold; + lmp->output->thermo->evaluate_keyword("press", &pold); + double eold = lmp->force->pair->eng_vdwl + lmp->force->pair->eng_coul; + double **f = lmp->atom->f; + for (int i = 0; i < 4; ++i) + for (int j = 0; j < 3; ++j) + fold[i][j] = f[i][j]; + + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("clear"); + lmp->input->one("units real"); + lmp->input->one("read_data test_pair_unit_convert.data"); + lmp->input->one("pair_style tersoff/mod/c"); + lmp->input->one("pair_coeff * * Si.tersoff.modc Si Si"); + lmp->input->one("run 0 post no"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + double pnew; + lmp->output->thermo->evaluate_keyword("press", &pnew); + EXPECT_NEAR(pold, p_convert * pnew, fabs(pnew * rel_error)); + double enew = lmp->force->pair->eng_vdwl + lmp->force->pair->eng_coul; + EXPECT_NEAR(ev_convert * eold, enew, fabs(enew * rel_error)); + + f = lmp->atom->f; + for (int i = 0; i < 4; ++i) + for (int j = 0; j < 3; ++j) + EXPECT_NEAR(ev_convert * fold[i][j], f[i][j], fabs(f[i][j] * rel_error)); +} + +TEST_F(PairUnitConvertTest, tersoff_table) +{ + // check if the prerequisite pair style is available + if (!info->has_style("pair", "tersoff/table")) GTEST_SKIP(); + + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("units metal"); + lmp->input->one("read_data test_pair_unit_convert.data"); + lmp->input->one("pair_style tersoff/table"); + lmp->input->one("pair_coeff * * SiC.tersoff Si C"); + lmp->input->one("run 0 post no"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + // copy pressure, energy, and force from first step + double pold; + lmp->output->thermo->evaluate_keyword("press", &pold); + double eold = lmp->force->pair->eng_vdwl + lmp->force->pair->eng_coul; + double **f = lmp->atom->f; + for (int i = 0; i < 4; ++i) + for (int j = 0; j < 3; ++j) + fold[i][j] = f[i][j]; + + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("clear"); + lmp->input->one("units real"); + lmp->input->one("read_data test_pair_unit_convert.data"); + lmp->input->one("pair_style tersoff/table"); + lmp->input->one("pair_coeff * * SiC.tersoff Si C"); + lmp->input->one("run 0 post no"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + double pnew; + lmp->output->thermo->evaluate_keyword("press", &pnew); + EXPECT_NEAR(pold, p_convert * pnew, fabs(pnew * rel_error)); + double enew = lmp->force->pair->eng_vdwl + lmp->force->pair->eng_coul; + EXPECT_NEAR(ev_convert * eold, enew, fabs(enew * rel_error)); + + f = lmp->atom->f; + for (int i = 0; i < 4; ++i) + for (int j = 0; j < 3; ++j) + EXPECT_NEAR(ev_convert * fold[i][j], f[i][j], fabs(f[i][j] * rel_error)); +} + +TEST_F(PairUnitConvertTest, tersoff_zbl) +{ + // check if the prerequisite pair style is available + if (!info->has_style("pair", "tersoff/zbl")) GTEST_SKIP(); + + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("units metal"); + lmp->input->one("read_data test_pair_unit_convert.data"); + lmp->input->one("pair_style tersoff/zbl"); + lmp->input->one("pair_coeff * * SiC.tersoff.zbl Si C"); + lmp->input->one("run 0 post no"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + // copy pressure, energy, and force from first step + double pold; + lmp->output->thermo->evaluate_keyword("press", &pold); + double eold = lmp->force->pair->eng_vdwl + lmp->force->pair->eng_coul; + double **f = lmp->atom->f; + for (int i = 0; i < 4; ++i) + for (int j = 0; j < 3; ++j) + fold[i][j] = f[i][j]; + + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("clear"); + lmp->input->one("units real"); + lmp->input->one("read_data test_pair_unit_convert.data"); + lmp->input->one("pair_style tersoff/zbl"); + lmp->input->one("pair_coeff * * SiC.tersoff.zbl Si C"); + lmp->input->one("run 0 post no"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + double pnew; + lmp->output->thermo->evaluate_keyword("press", &pnew); + EXPECT_NEAR(pold, p_convert * pnew, fabs(pnew * rel_error)); + double enew = lmp->force->pair->eng_vdwl + lmp->force->pair->eng_coul; + EXPECT_NEAR(ev_convert * eold, enew, fabs(enew * rel_error)); + + f = lmp->atom->f; + for (int i = 0; i < 4; ++i) + for (int j = 0; j < 3; ++j) + EXPECT_NEAR(ev_convert * fold[i][j], f[i][j], fabs(f[i][j] * rel_error)); +} + +TEST_F(PairUnitConvertTest, tersoff_zbl_omp) +{ + // check if the prerequisite pair style is available + if (!info->has_style("pair", "tersoff/zbl/omp")) GTEST_SKIP(); + + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("package omp 4"); + lmp->input->one("units metal"); + lmp->input->one("read_data test_pair_unit_convert.data"); + lmp->input->one("pair_style tersoff/zbl/omp"); + lmp->input->one("pair_coeff * * SiC.tersoff.zbl Si C"); + lmp->input->one("run 0 post no"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + // copy pressure, energy, and force from first step + double pold; + lmp->output->thermo->evaluate_keyword("press", &pold); + double eold = lmp->force->pair->eng_vdwl + lmp->force->pair->eng_coul; + double **f = lmp->atom->f; + for (int i = 0; i < 4; ++i) + for (int j = 0; j < 3; ++j) + fold[i][j] = f[i][j]; + + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("clear"); + lmp->input->one("package omp 4"); + lmp->input->one("units real"); + lmp->input->one("read_data test_pair_unit_convert.data"); + lmp->input->one("pair_style tersoff/zbl/omp"); + lmp->input->one("pair_coeff * * SiC.tersoff.zbl Si C"); + lmp->input->one("run 0 post no"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + double pnew; + lmp->output->thermo->evaluate_keyword("press", &pnew); + EXPECT_NEAR(pold, p_convert * pnew, fabs(pnew * rel_error)); + double enew = lmp->force->pair->eng_vdwl + lmp->force->pair->eng_coul; + EXPECT_NEAR(ev_convert * eold, enew, fabs(enew * rel_error)); + + f = lmp->atom->f; + for (int i = 0; i < 4; ++i) + for (int j = 0; j < 3; ++j) + EXPECT_NEAR(ev_convert * fold[i][j], f[i][j], fabs(f[i][j] * rel_error)); +} + +TEST_F(PairUnitConvertTest, vashishta) +{ + // check if the prerequisite pair style is available + if (!info->has_style("pair", "vashishta")) GTEST_SKIP(); + + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("units metal"); + lmp->input->one("read_data test_pair_unit_convert.data"); + lmp->input->one("pair_style vashishta"); + lmp->input->one("pair_coeff * * SiC.vashishta Si C"); + lmp->input->one("run 0 post no"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + // copy pressure, energy, and force from first step + double pold; + lmp->output->thermo->evaluate_keyword("press", &pold); + double eold = lmp->force->pair->eng_vdwl + lmp->force->pair->eng_coul; + double **f = lmp->atom->f; + for (int i = 0; i < 4; ++i) + for (int j = 0; j < 3; ++j) + fold[i][j] = f[i][j]; + + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("clear"); + lmp->input->one("units real"); + lmp->input->one("read_data test_pair_unit_convert.data"); + lmp->input->one("pair_style vashishta"); + lmp->input->one("pair_coeff * * SiC.vashishta Si C"); + lmp->input->one("run 0 post no"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + double pnew; + lmp->output->thermo->evaluate_keyword("press", &pnew); + EXPECT_NEAR(pold, p_convert * pnew, fabs(pnew * rel_error)); + double enew = lmp->force->pair->eng_vdwl + lmp->force->pair->eng_coul; + EXPECT_NEAR(ev_convert * eold, enew, fabs(enew * rel_error)); + + f = lmp->atom->f; + for (int i = 0; i < 4; ++i) + for (int j = 0; j < 3; ++j) + EXPECT_NEAR(ev_convert * fold[i][j], f[i][j], fabs(f[i][j] * rel_error)); +} + +} // namespace LAMMPS_NS + +int main(int argc, char **argv) +{ + MPI_Init(&argc, &argv); + ::testing::InitGoogleMock(&argc, argv); + + // handle arguments passed via environment variable + if (const char *var = getenv("TEST_ARGS")) { + std::vector env = split_words(var); + for (auto arg : env) { + if (arg == "-v") { + verbose = true; + } + } + } + if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true; + + int rv = RUN_ALL_TESTS(); + MPI_Finalize(); + remove("test.table.metal"); + remove("test.table.real"); + return rv; +} diff --git a/unittest/formats/test_potential_file_reader.cpp b/unittest/formats/test_potential_file_reader.cpp index 54dc26e4dc..b3795b22b2 100644 --- a/unittest/formats/test_potential_file_reader.cpp +++ b/unittest/formats/test_potential_file_reader.cpp @@ -23,6 +23,7 @@ #include "MANYBODY/pair_tersoff_mod_c.h" #include "MANYBODY/pair_tersoff_zbl.h" #include "MANYBODY/pair_vashishta.h" +#include "USER-MISC/pair_tersoff_table.h" #include "input.h" #include "lammps.h" #include "potential_file_reader.h" @@ -50,6 +51,7 @@ const int LAMMPS_NS::PairGW::NPARAMS_PER_LINE; const int LAMMPS_NS::PairGWZBL::NPARAMS_PER_LINE; const int LAMMPS_NS::PairNb3bHarmonic::NPARAMS_PER_LINE; const int LAMMPS_NS::PairVashishta::NPARAMS_PER_LINE; +const int LAMMPS_NS::PairTersoffTable::NPARAMS_PER_LINE; class PotentialFileReaderTest : public ::testing::Test { protected: @@ -74,7 +76,7 @@ protected: } }; -TEST_F(PotentialFileReaderTest, Si) +TEST_F(PotentialFileReaderTest, Sw) { if (!verbose) ::testing::internal::CaptureStdout(); lmp->input->one("units metal"); @@ -140,6 +142,17 @@ TEST_F(PotentialFileReaderTest, TersoffModC) ASSERT_EQ(utils::count_words(line), PairTersoffMODC::NPARAMS_PER_LINE); } +TEST_F(PotentialFileReaderTest, TersoffTable) +{ + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("units metal"); + PotentialFileReader reader(lmp, "Si.tersoff", "TersoffTable"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + auto line = reader.next_line(PairTersoffTable::NPARAMS_PER_LINE); + ASSERT_EQ(utils::count_words(line), PairTersoffTable::NPARAMS_PER_LINE); +} + TEST_F(PotentialFileReaderTest, TersoffZBL) { if (!verbose) ::testing::internal::CaptureStdout(); @@ -176,7 +189,7 @@ TEST_F(PotentialFileReaderTest, GWZBL) TEST_F(PotentialFileReaderTest, Nb3bHarmonic) { if (!verbose) ::testing::internal::CaptureStdout(); - lmp->input->one("units metal"); + lmp->input->one("units real"); PotentialFileReader reader(lmp, "MOH.nb3b.harmonic", "NB3B Harmonic"); if (!verbose) ::testing::internal::GetCapturedStdout(); @@ -195,6 +208,49 @@ TEST_F(PotentialFileReaderTest, Vashishta) ASSERT_EQ(utils::count_words(line), PairVashishta::NPARAMS_PER_LINE); } +TEST_F(PotentialFileReaderTest, UnitConvert) +{ + PotentialFileReader *reader; + int unit_convert, flag; + + if (!verbose) ::testing::internal::CaptureStdout(); + lmp->input->one("units metal"); + reader = new PotentialFileReader(lmp, "Si.sw", "Stillinger-Weber"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + unit_convert = reader->get_unit_convert(); + ASSERT_EQ(unit_convert, 0); + delete reader; + + if (!verbose) ::testing::internal::CaptureStdout(); + flag = utils::get_supported_conversions(utils::UNKNOWN); + reader = new PotentialFileReader(lmp, "Si.sw", "Stillinger-Weber", flag); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + unit_convert = reader->get_unit_convert(); + ASSERT_EQ(unit_convert, 0); + delete reader; + + if (!verbose) ::testing::internal::CaptureStdout(); + flag = utils::get_supported_conversions(utils::ENERGY); + reader = new PotentialFileReader(lmp, "Si.sw", "Stillinger-Weber", flag); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + unit_convert = reader->get_unit_convert(); + ASSERT_EQ(unit_convert, 0); + delete reader; + + if (!verbose) ::testing::internal::CaptureStdout(); + flag = utils::get_supported_conversions(utils::ENERGY); + lmp->input->one("units real"); + reader = new PotentialFileReader(lmp, "Si.sw", "Stillinger-Weber", flag); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + unit_convert = reader->get_unit_convert(); + ASSERT_EQ(unit_convert, utils::METAL2REAL); + delete reader; +} + int main(int argc, char **argv) { MPI_Init(&argc, &argv); diff --git a/unittest/utils/test_utils.cpp b/unittest/utils/test_utils.cpp index c1312e7725..c4b4042bf9 100644 --- a/unittest/utils/test_utils.cpp +++ b/unittest/utils/test_utils.cpp @@ -341,3 +341,25 @@ TEST(Utils, potential_file) remove("ctest1.txt"); remove("ctest2.txt"); } + +TEST(Utils, unit_conversion) +{ + double factor; + int flag; + + flag = utils::get_supported_conversions(utils::UNKNOWN); + ASSERT_EQ(flag, utils::NOCONVERT); + flag = utils::get_supported_conversions(utils::ENERGY); + ASSERT_EQ(flag, utils::METAL2REAL | utils::REAL2METAL); + + factor = utils::get_conversion_factor(utils::UNKNOWN, 1 << 30 - 1); + ASSERT_DOUBLE_EQ(factor, 0.0); + factor = utils::get_conversion_factor(utils::UNKNOWN, utils::NOCONVERT); + ASSERT_DOUBLE_EQ(factor, 0.0); + factor = utils::get_conversion_factor(utils::ENERGY, utils::NOCONVERT); + ASSERT_DOUBLE_EQ(factor, 1.0); + factor = utils::get_conversion_factor(utils::ENERGY, utils::METAL2REAL); + ASSERT_DOUBLE_EQ(factor, 23.060549); + factor = utils::get_conversion_factor(utils::ENERGY, utils::REAL2METAL); + ASSERT_DOUBLE_EQ(factor, 1.0 / 23.060549); +}