From f5ebfbf90b8b1df82e0dbbd7324a52b1d4e5bab6 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 19 Mar 2022 16:39:09 -0400 Subject: [PATCH 01/11] refactor thermo output processing and add new yaml thermo style --- doc/src/thermo.rst | 22 ++- doc/src/thermo_modify.rst | 179 ++++++++--------- doc/src/thermo_style.rst | 39 +++- src/finish.cpp | 98 ++++------ src/fix_nh.cpp | 2 - src/output.cpp | 49 +++-- src/thermo.cpp | 400 +++++++++++++++++++------------------- src/thermo.h | 23 +-- 8 files changed, 397 insertions(+), 415 deletions(-) diff --git a/doc/src/thermo.rst b/doc/src/thermo.rst index 154fd59431..5621b554c8 100644 --- a/doc/src/thermo.rst +++ b/doc/src/thermo.rst @@ -32,18 +32,20 @@ The content and format of what is printed is controlled by the :doc:`thermo_style ` and :doc:`thermo_modify ` commands. -Instead of a numeric value, N can be specified as an :doc:`equal-style variable `, which should be specified as v_name, where -name is the variable name. In this case, the variable is evaluated at -the beginning of a run to determine the next timestep at which -thermodynamic info will be written out. On that timestep, the -variable will be evaluated again to determine the next timestep, etc. -Thus the variable should return timestep values. See the stagger() -and logfreq() and stride() math functions for :doc:`equal-style variables `, as examples of useful functions to use in -this context. Other similar math functions could easily be added as -options for :doc:`equal-style variables `. +Instead of a numeric value, N can be specified as an :doc:`equal-style +variable `, which should be specified as v_name, where name is +the variable name. In this case, the variable is evaluated at the +beginning of a run to determine the next timestep at which thermodynamic +info will be written out. On that timestep, the variable will be +evaluated again to determine the next timestep, etc. Thus the variable +should return timestep values. See the stagger() and logfreq() and +stride() math functions for :doc:`equal-style variables `, as +examples of useful functions to use in this context. Other similar math +functions could easily be added as options for :doc:`equal-style +variables `. For example, the following commands will output thermodynamic info at -timesteps 0,10,20,30,100,200,300,1000,2000,etc: +timesteps 0, 10, 20, 30, 100, 200, 300, 1000, 2000, *etc*: .. code-block:: LAMMPS diff --git a/doc/src/thermo_modify.rst b/doc/src/thermo_modify.rst index 31de925492..e209dd937b 100644 --- a/doc/src/thermo_modify.rst +++ b/doc/src/thermo_modify.rst @@ -20,7 +20,7 @@ Syntax *warn* value = *ignore* or *reset* or *default* or a number *norm* value = *yes* or *no* *flush* value = *yes* or *no* - *line* value = *one* or *multi* + *line* value = *one* or *multi* or *yaml* *format* values = *line* string, *int* string, *float* string, M string, or *none* string = C-style format string M = integer from 1 to N, where N = # of quantities being output @@ -36,35 +36,35 @@ Examples thermo_modify temp myTemp format 3 %15.8g thermo_modify temp myTemp format line "%ld %g %g %15.8g" thermo_modify line multi format float %g + themos_modify line yaml format none Description """"""""""" -Set options for how thermodynamic information is computed and printed -by LAMMPS. +Set options for how thermodynamic information is computed and printed by +LAMMPS. .. note:: - These options apply to the currently defined thermo style. When + These options apply to the *currently defined* thermo style. When you specify a :doc:`thermo_style ` command, all - thermodynamic settings are restored to their default values, including - those previously reset by a thermo_modify command. Thus if your input - script specifies a thermo_style command, you should use the - thermo_modify command after it. + thermodynamic settings are restored to their default values, + including those previously reset by a thermo_modify command. Thus if + your input script specifies a thermo_style command, you should use + the thermo_modify command **after** it. -The *lost* keyword determines whether LAMMPS checks for lost atoms -each time it computes thermodynamics and what it does if atoms are -lost. An atom can be "lost" if it moves across a non-periodic -simulation box :doc:`boundary ` or if it moves more than a box -length outside the simulation domain (or more than a processor -sub-domain length) before reneighboring occurs. The latter case is -typically due to bad dynamics, e.g. too large a timestep or huge -forces and velocities. If the value is *ignore*, LAMMPS does not -check for lost atoms. If the value is *error* or *warn*, LAMMPS -checks and either issues an error or warning. The code will exit with -an error and continue with a warning. A warning will only be issued -once, the first time an atom is lost. This can be a useful debugging -option. +The *lost* keyword determines whether LAMMPS checks for lost atoms each +time it computes thermodynamics and what it does if atoms are lost. An +atom can be "lost" if it moves across a non-periodic simulation box +:doc:`boundary ` or if it moves more than a box length outside +the simulation domain (or more than a processor sub-domain length) +before reneighboring occurs. The latter case is typically due to bad +dynamics, e.g. too large a timestep or huge forces and velocities. If +the value is *ignore*, LAMMPS does not check for lost atoms. If the +value is *error* or *warn*, LAMMPS checks and either issues an error or +warning. The code will exit with an error and continue with a warning. +A warning will only be issued once, the first time an atom is lost. +This can be a useful debugging option. The *lost/bond* keyword determines whether LAMMPS throws an error or not if an atom in a bonded interaction (bond, angle, etc) cannot be @@ -109,55 +109,55 @@ will be reset to zero, and with the value *default*, the counter is reset and the limit set to 100. An example usage of either *reset* or *default* would be to re-enable warnings that were disabled or have reached the limit during equilibration, where the warnings would be -acceptable while the system is still adjusting, but then change -to all warnings for the production run, where they would indicate -problems that would require a closer look at what is causing them. +acceptable while the system is still adjusting, but then change to all +warnings for the production run, where they would indicate problems that +would require a closer look at what is causing them. The *norm* keyword determines whether various thermodynamic output values are normalized by the number of atoms or not, depending on whether it is set to *yes* or *no*\ . Different unit styles have -different defaults for this setting (see below). Even if *norm* is -set to *yes*, a value is only normalized if it is an "extensive" -quantity, meaning that it scales with the number of atoms in the -system. For the thermo keywords described by the page for the -:doc:`thermo_style ` command, all energy-related keywords -are extensive, such as *pe* or *ebond* or *enthalpy*\ . Other keywords -such as *temp* or *press* are "intensive" meaning their value is -independent (in a statistical sense) of the number of atoms in the -system and thus are never normalized. For thermodynamic output values -extracted from fixes and computes in a :doc:`thermo_style custom ` command, the page for the individual -:doc:`fix ` or :doc:`compute ` lists whether the value is -"extensive" or "intensive" and thus whether it is normalized. -Thermodynamic output values calculated by a variable formula are -assumed to be "intensive" and thus are never normalized. You can -always include a divide by the number of atoms in the variable formula -if this is not the case. +different defaults for this setting (see below). Even if *norm* is set +to *yes*, a value is only normalized if it is an "extensive" quantity, +meaning that it scales with the number of atoms in the system. For the +thermo keywords described by the page for the :doc:`thermo_style +` command, all energy-related keywords are extensive, such +as *pe* or *ebond* or *enthalpy*\ . Other keywords such as *temp* or +*press* are "intensive" meaning their value is independent (in a +statistical sense) of the number of atoms in the system and thus are +never normalized. For thermodynamic output values extracted from fixes +and computes in a :doc:`thermo_style custom ` command, the +page for the individual :doc:`fix ` or :doc:`compute ` +lists whether the value is "extensive" or "intensive" and thus whether +it is normalized. Thermodynamic output values calculated by a variable +formula are assumed to be "intensive" and thus are never normalized. +You can always include a divide by the number of atoms in the variable +formula if this is not the case. The *flush* keyword invokes a flush operation after thermodynamic info is written to the screen and log file. This insures the output is updated and not buffered (by the application) even if LAMMPS halts -before the simulation completes. Please note that this does not -affect buffering by the OS or devices, so you may still lose data -in case the simulation stops due to a hardware failure. +before the simulation completes. Please note that this does not affect +buffering by the OS or devices, so you may still lose data in case the +simulation stops due to a hardware failure. -The *line* keyword determines whether thermodynamics will be output as -a series of numeric values on one line or in a multi-line format with -3 quantities with text strings per line and a dashed-line header -containing the timestep and CPU time. This modify option overrides -the *one* and *multi* thermo_style settings. +The *line* keyword determines whether thermodynamics will be output as a +series of numeric values on one line ("one"), in a multi-line format +with 3 quantities with text strings per line and a dashed-line header +containing the timestep and CPU time ("multi"), or in a YAML format +block ("yaml"). This modify option overrides the *one*, *multi*, or +*yaml* thermo_style settings. -The *format* keyword can be used to change the default numeric format -of any of quantities the :doc:`thermo_style ` command -outputs. All the specified format strings are C-style formats, -e.g. as used by the C/C++ printf() command. The *line* keyword takes -a single argument which is the format string for the entire line of -thermo output, with N fields, which you must enclose in quotes if it -is more than one field. The *int* and *float* keywords take a single -format argument and are applied to all integer or floating-point -quantities output. The setting for *M string* also takes a single -format argument which is used for the Mth value output in each line, -e.g. the fifth column is output in high precision for "format 5 -%20.15g". +The *format* keyword can be used to change the default numeric format of +any of quantities the :doc:`thermo_style ` command +outputs. All the specified format strings are C-style formats, e.g. as +used by the C/C++ printf() command. The *line* keyword takes a single +argument which is the format string for the entire line of thermo +output, with N fields, which you must enclose in quotes if it is more +than one field. The *int* and *float* keywords take a single format +argument and are applied to all integer or floating-point quantities +output. The setting for *M string* also takes a single format argument +which is used for the Mth value output in each line, e.g. the fifth +column is output in high precision for "format 5 %20.15g". The *format* keyword can be used multiple times. The precedence is that for each value in a line of output, the *M* format (if specified) @@ -168,46 +168,46 @@ settings, reverting all values to their default format. .. note:: - The thermo output values *step* and *atoms* are stored - internally as 8-byte signed integers, rather than the usual 4-byte - signed integers. When specifying the *format int* option you can use - a "%d"-style format identifier in the format string and LAMMPS will - convert this to the corresponding 8-byte form when it is applied to - those keywords. However, when specifying the *line* option or *format - M string* option for *step* and *natoms*, you should specify a format + The thermo output values *step* and *atoms* are stored internally as + 8-byte signed integers, rather than the usual 4-byte signed integers. + When specifying the *format int* option you can use a "%d"-style + format identifier in the format string and LAMMPS will convert this + to the corresponding 8-byte form when it is applied to those + keywords. However, when specifying the *line* option or *format M + string* option for *step* and *natoms*, you should specify a format string appropriate for an 8-byte signed integer, e.g. one with "%ld". -The *temp* keyword is used to determine how thermodynamic temperature -is calculated, which is used by all thermo quantities that require a +The *temp* keyword is used to determine how thermodynamic temperature is +calculated, which is used by all thermo quantities that require a temperature ("temp", "press", "ke", "etotal", "enthalpy", "pxx", etc). The specified compute ID must have been previously defined by the user via the :doc:`compute ` command and it must be a style of compute that calculates a temperature. As described in the :doc:`thermo_style ` command, thermo output uses a default -compute for temperature with ID = *thermo_temp*. This option allows -the user to override the default. +compute for temperature with ID = *thermo_temp*. This option allows the +user to override the default. The *press* keyword is used to determine how thermodynamic pressure is calculated, which is used by all thermo quantities that require a pressure ("press", "enthalpy", "pxx", etc). The specified compute ID -must have been previously defined by the user via the -:doc:`compute ` command and it must be a style of compute that -calculates a pressure. As described in the -:doc:`thermo_style ` command, thermo output uses a default -compute for pressure with ID = *thermo_press*. This option allows the -user to override the default. +must have been previously defined by the user via the :doc:`compute +` command and it must be a style of compute that calculates a +pressure. As described in the :doc:`thermo_style ` +command, thermo output uses a default compute for pressure with ID = +*thermo_press*. This option allows the user to override the default. .. note:: If both the *temp* and *press* keywords are used in a single - thermo_modify command (or in two separate commands), then the order in - which the keywords are specified is important. Note that a :doc:`pressure compute ` defines its own temperature compute as - an argument when it is specified. The *temp* keyword will override - this (for the pressure compute being used by thermodynamics), but only - if the *temp* keyword comes after the *press* keyword. If the *temp* - keyword comes before the *press* keyword, then the new pressure - compute specified by the *press* keyword will be unaffected by the - *temp* setting. + thermo_modify command (or in two separate commands), then the order + in which the keywords are specified is important. Note that a + :doc:`pressure compute ` defines its own + temperature compute as an argument when it is specified. The *temp* + keyword will override this (for the pressure compute being used by + thermodynamics), but only if the *temp* keyword comes after the + *press* keyword. If the *temp* keyword comes before the *press* + keyword, then the new pressure compute specified by the *press* + keyword will be unaffected by the *temp* setting. Restrictions """""""""""" @@ -225,7 +225,8 @@ The option defaults are lost = error, warn = 100, norm = yes for unit style of *lj*, norm = no for unit style of *real* and *metal*, flush = no, and temp/press = compute IDs defined by thermo_style. -The defaults for the line and format options depend on the thermo -style. For styles "one" and "custom", the line and format defaults -are "one", "%8d", and "%12.8g". For style "multi", the line and -format defaults are "multi", "%8d", and "%14.4f". +The defaults for the line and format options depend on the thermo style. +For styles "one" and "custom", the line and format defaults are "one", +"%10d", and "%12.8g". For style "multi", the line and format defaults +are "multi", "%14d", and "%14.4f". For style "yaml", the line and format +defaults are "%d" and "%.15g". diff --git a/doc/src/thermo_style.rst b/doc/src/thermo_style.rst index a04504b1a6..e2d5bcb58d 100644 --- a/doc/src/thermo_style.rst +++ b/doc/src/thermo_style.rst @@ -10,13 +10,14 @@ Syntax thermo_style style args -* style = *one* or *multi* or *custom* +* style = *one* or *multi* *yaml* or *custom* * args = list of arguments for a particular style .. parsed-literal:: *one* args = none *multi* args = none + *yaml* args = none *custom* args = list of keywords possible keywords = step, elapsed, elaplong, dt, time, cpu, tpcpu, spcpu, cpuremain, part, timeremain, @@ -92,6 +93,8 @@ Examples .. code-block:: LAMMPS thermo_style multi + thermo_style yaml + thermo_style one thermo_style custom step temp pe etotal press vol thermo_style custom step temp etotal c_myTemp v_abc thermo_style custom step temp etotal c_myTemp[*] v_abc @@ -99,18 +102,42 @@ Examples Description """"""""""" -Set the style and content for printing thermodynamic data to the -screen and log file. +Set the style and content for printing thermodynamic data to the screen +and log files. -Style *one* prints a one-line summary of thermodynamic info that is -the equivalent of "thermo_style custom step temp epair emol etotal -press". The line contains only numeric values. +Style *one* prints a single line of thermodynamic info that is the +equivalent of "thermo_style custom step temp epair emol etotal press". +The line contains only numeric values. Style *multi* prints a multiple-line listing of thermodynamic info that is the equivalent of "thermo_style custom etotal ke temp pe ebond eangle edihed eimp evdwl ecoul elong press". The listing contains numeric values and a string ID for each quantity. +Style *yaml* is similar to style *one* but prints the output in `YAML +`_ format which can be easily read by a variety of +script languages and data handling packages. Since LAMMPS may print +other output before, after, or in between thermodynamic output, the +YAML format content needs to be separated from the rest. All YAML +format thermodynamic output can be matched with a regular expression +and can thus be extracted with commands like ``egrep`` as follows: + +.. code-block:: sh + + egrep '^(keywords:|data:$|---$|\.\.\.$| - \[)' log.lammps > log.yaml + +A typical block of YAML format output looks like this: + +.. code-block:: yaml + + --- + keywords: [Step, Temp, KinEng, PotEng, E_bond, E_angle, E_dihed, E_impro, E_vdwl, E_coul, E_long, Press, Volume, ] + data: + - [0, 1.44000000000001, 2.15993250000001, -6.77336805323422, 0, 0, 0, 0, -6.77336805323422, 0, 0, -5.01970725908556, 37905.7095475006, ] + - [50, 0.740091517740786, 1.11010258482128, -5.73150426762886, 0, 0, 0, 0, -5.73150426762886, 0, 0, 0.335273324523691, 37905.7095475006, ] + - [100, 0.757453103239936, 1.13614414924569, -5.75850548601596, 0, 0, 0, 0, -5.75850548601596, 0, 0, 0.207261053624723, 37905.7095475006, ] + ... + Style *custom* is the most general setting and allows you to specify which of the keywords listed above you want printed on each thermodynamic timestep. Note that the keywords c_ID, f_ID, v_name are diff --git a/src/finish.cpp b/src/finish.cpp index f3dbc83498..35be03dca7 100644 --- a/src/finish.cpp +++ b/src/finish.cpp @@ -27,6 +27,8 @@ #include "neigh_list.h" #include "neigh_request.h" #include "neighbor.h" // IWYU pragma: keep +#include "output.h" +#include "thermo.h" #include "timer.h" // IWYU pragma: keep #include "universe.h" #include "update.h" @@ -121,10 +123,10 @@ void Finish::end(int flag) if (time_loop > 0.0) cpu_loop = cpu_loop/time_loop*100.0; if (me == 0) { + output->thermo->footer(); int ntasks = nprocs * nthreads; - utils::logmesg(lmp,"Loop time of {:.6g} on {} procs for " - "{} steps with {} atoms\n\n",time_loop, - ntasks,update->nsteps,atom->natoms); + utils::logmesg(lmp,"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 @@ -142,8 +144,7 @@ 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; - utils::logmesg(lmp,"Performance: {:.3f} tau/day, {:.3f} " - "timesteps/s\n",tau_day,step_t); + utils::logmesg(lmp,"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; @@ -161,15 +162,15 @@ void Finish::end(int flag) if (timeflag) { if (lmp->kokkos) { - utils::logmesg(lmp,"{:.1f}% CPU use with {} MPI tasks x {} OpenMP " - "threads\n",cpu_loop,nprocs,lmp->kokkos->nthreads); + utils::logmesg(lmp,"{:.1f}% CPU use with {} MPI tasks x {} OpenMP threads\n", + cpu_loop,nprocs,lmp->kokkos->nthreads); } else { #if defined(_OPENMP) - utils::logmesg(lmp,"{:.1f}% CPU use with {} MPI tasks x {} OpenMP " - "threads\n",cpu_loop,nprocs,nthreads); + utils::logmesg(lmp,"{:.1f}% CPU use with {} MPI tasks x {} OpenMP threads\n", + cpu_loop,nprocs,nthreads); #else - utils::logmesg(lmp,"{:.1f}% CPU use with {} MPI tasks " - "x no OpenMP threads\n",cpu_loop,nprocs); + utils::logmesg(lmp,"{:.1f}% CPU use with {} MPI tasks x no OpenMP threads\n", + cpu_loop,nprocs); #endif } } @@ -192,8 +193,7 @@ void Finish::end(int flag) if (me == 0) { std::string mesg = "\nMinimization stats:\n"; - mesg += fmt::format(" Stopping criterion = {}\n", - update->minimize->stopstr); + 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, @@ -222,33 +222,27 @@ void Finish::end(int flag) time = timer->get_wall(Timer::DEPHASE); MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); time = tmp/nprocs; - if (me == 0) utils::logmesg(lmp," Dephase time (%) = {} ({})\n", - time,time/time_loop*100.0); + if (me == 0) utils::logmesg(lmp," 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) utils::logmesg(lmp," Dynamics time (%) = {} ({})\n", - time,time/time_loop*100.0); + if (me == 0) utils::logmesg(lmp," 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) utils::logmesg(lmp," Quench time (%) = {} ({})\n", - time,time/time_loop*100.0); + if (me == 0) utils::logmesg(lmp," 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) utils::logmesg(lmp," Comm time (%) = {} ({})\n", - time,time/time_loop*100.0); + if (me == 0) utils::logmesg(lmp," 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) utils::logmesg(lmp," Output time (%) = {} ({})\n", - time,time/time_loop*100.0); + if (me == 0) utils::logmesg(lmp," 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) utils::logmesg(lmp," Other time (%) = {} ({})\n", - time,time/time_loop*100.0); + if (me == 0) utils::logmesg(lmp," Other time (%) = {} ({})\n",time,time/time_loop*100.0); } // TAD stats @@ -259,33 +253,27 @@ void Finish::end(int flag) time = timer->get_wall(Timer::NEB); MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); time = tmp/nprocs; - if (me == 0) utils::logmesg(lmp," NEB time (%) = {} ({})\n", - time,time/time_loop*100.0); + if (me == 0) utils::logmesg(lmp," 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) utils::logmesg(lmp," Dynamics time (%) = {} ({})\n", - time,time/time_loop*100.0); + if (me == 0) utils::logmesg(lmp," 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) utils::logmesg(lmp," Quench time (%) = {} ({})\n", - time,time/time_loop*100.0); + if (me == 0) utils::logmesg(lmp," 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) utils::logmesg(lmp," Comm time (%) = {} ({})\n", - time,time/time_loop*100.0); + if (me == 0) utils::logmesg(lmp," 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) utils::logmesg(lmp," Output time (%) = {} ({})\n", - time,time/time_loop*100.0); + if (me == 0) utils::logmesg(lmp," 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) utils::logmesg(lmp," Other time (%) = {} ({})\n", - time,time/time_loop*100.0); + if (me == 0) utils::logmesg(lmp," Other time (%) = {} ({})\n",time,time/time_loop*100.0); } // HYPER stats @@ -296,18 +284,15 @@ void Finish::end(int flag) time = timer->get_wall(Timer::DYNAMICS); MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); time = tmp/nprocs; - if (me == 0) utils::logmesg(lmp," Dynamics time (%) = {} ({})\n", - time,time/time_loop*100.0); + if (me == 0) utils::logmesg(lmp," 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) utils::logmesg(lmp," Quench time (%) = {} ({})\n", - time,time/time_loop*100.0); + if (me == 0) utils::logmesg(lmp," 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) utils::logmesg(lmp," Other time (%) = {} ({})\n", - time,time/time_loop*100.0); + if (me == 0) utils::logmesg(lmp," Other time (%) = {} ({})\n",time,time/time_loop*100.0); } // further timing breakdowns @@ -326,28 +311,20 @@ void Finish::end(int flag) "------------------------------------------------------\n"); } - mpi_timings("Pair",timer,Timer::PAIR, world,nprocs, - nthreads,me,time_loop,screen,logfile); + mpi_timings("Pair",timer,Timer::PAIR, world,nprocs,nthreads,me,time_loop,screen,logfile); if (atom->molecular != Atom::ATOMIC) - mpi_timings("Bond",timer,Timer::BOND,world,nprocs, - nthreads,me,time_loop,screen,logfile); + mpi_timings("Bond",timer,Timer::BOND,world,nprocs,nthreads,me,time_loop,screen,logfile); if (force->kspace) - mpi_timings("Kspace",timer,Timer::KSPACE,world,nprocs, - nthreads,me,time_loop,screen,logfile); + mpi_timings("Kspace",timer,Timer::KSPACE,world,nprocs,nthreads,me,time_loop,screen,logfile); - mpi_timings("Neigh",timer,Timer::NEIGH,world,nprocs, - nthreads,me,time_loop,screen,logfile); - mpi_timings("Comm",timer,Timer::COMM,world,nprocs, - nthreads,me,time_loop,screen,logfile); - mpi_timings("Output",timer,Timer::OUTPUT,world,nprocs, - nthreads,me,time_loop,screen,logfile); - mpi_timings("Modify",timer,Timer::MODIFY,world,nprocs, - nthreads,me,time_loop,screen,logfile); + mpi_timings("Neigh",timer,Timer::NEIGH,world,nprocs,nthreads,me,time_loop,screen,logfile); + mpi_timings("Comm",timer,Timer::COMM,world,nprocs,nthreads,me,time_loop,screen,logfile); + mpi_timings("Output",timer,Timer::OUTPUT,world,nprocs,nthreads,me,time_loop,screen,logfile); + mpi_timings("Modify",timer,Timer::MODIFY,world,nprocs,nthreads,me,time_loop,screen,logfile); if (timer->has_sync()) - mpi_timings("Sync",timer,Timer::SYNC,world,nprocs, - nthreads,me,time_loop,screen,logfile); + mpi_timings("Sync",timer,Timer::SYNC,world,nprocs,nthreads,me,time_loop,screen,logfile); time = time_other; MPI_Allreduce(&time,&tmp,1,MPI_DOUBLE,MPI_SUM,world); @@ -580,8 +557,7 @@ void Finish::end(int flag) if (atom->natoms > 0) mesg += fmt::format("Ave neighs/atom = {:.8}\n",nall/atom->natoms); if ((atom->molecular != Atom::ATOMIC) && (atom->natoms > 0)) - mesg += fmt::format("Ave special neighs/atom = {:.8}\n", - nspec_all/atom->natoms); + mesg += fmt::format("Ave special neighs/atom = {:.8}\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); diff --git a/src/fix_nh.cpp b/src/fix_nh.cpp index 91be322d82..28c0cafc60 100644 --- a/src/fix_nh.cpp +++ b/src/fix_nh.cpp @@ -93,8 +93,6 @@ FixNH::FixNH(LAMMPS *lmp, int narg, char **arg) : tcomputeflag = 0; pcomputeflag = 0; - id_temp = nullptr; - id_press = nullptr; // turn on tilt factor scaling, whenever applicable diff --git a/src/output.cpp b/src/output.cpp index a3c79d4cda..7a1eaaf807 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -69,7 +69,7 @@ Output::Output(LAMMPS *lmp) : Pointers(lmp) char **newarg = new char*[1]; newarg[0] = (char *) "one"; thermo = new Thermo(lmp,1,newarg); - delete [] newarg; + delete[] newarg; thermo_every = 0; var_thermo = nullptr; @@ -110,7 +110,7 @@ Output::Output(LAMMPS *lmp) : Pointers(lmp) Output::~Output() { if (thermo) delete thermo; - delete [] var_thermo; + delete[] var_thermo; memory->destroy(mode_dump); memory->destroy(every_dump); @@ -118,17 +118,17 @@ Output::~Output() memory->destroy(next_dump); memory->destroy(next_time_dump); memory->destroy(last_dump); - for (int i = 0; i < ndump; i++) delete [] var_dump[i]; + for (int i = 0; i < ndump; i++) delete[] var_dump[i]; memory->sfree(var_dump); memory->destroy(ivar_dump); for (int i = 0; i < ndump; i++) delete dump[i]; memory->sfree(dump); - delete [] restart1; - delete [] restart2a; - delete [] restart2b; - delete [] var_restart_single; - delete [] var_restart_double; + delete[] restart1; + delete[] restart2a; + delete[] restart2b; + delete[] var_restart_single; + delete[] var_restart_double; delete restart; delete dump_map; @@ -545,8 +545,7 @@ void Output::calculate_next_dump(int which, int idump, bigint ntimestep) } nextdump = ntimestep + - static_cast ((nexttime - tcurrent - EPSDT*update->dt) / - update->dt) + 1; + static_cast ((nexttime - tcurrent - EPSDT*update->dt) / update->dt) + 1; // if delta is too small to reach next timestep, use multiple of delta @@ -557,8 +556,7 @@ void Output::calculate_next_dump(int which, int idump, bigint ntimestep) ((tnext - nexttime) / every_time_dump[idump]); nexttime = nexttime + (multiple+1)*every_time_dump[idump]; nextdump = ntimestep + - static_cast ((nexttime - tcurrent - EPSDT*update->dt) / - update->dt) + 1; + static_cast ((nexttime - tcurrent - EPSDT*update->dt) / update->dt) + 1; } } else { @@ -575,8 +573,7 @@ void Output::calculate_next_dump(int which, int idump, bigint ntimestep) error->all(FLERR,"Dump every/time variable returned a bad time"); nextdump = ntimestep + - static_cast ((nexttime - tcurrent - EPSDT*update->dt) / - update->dt) + 1; + static_cast ((nexttime - tcurrent - EPSDT*update->dt) / update->dt) + 1; if (nextdump <= ntimestep) error->all(FLERR,"Dump every/time variable too small for next timestep"); } @@ -825,7 +822,7 @@ void Output::delete_dump(char *id) if (idump == ndump) error->all(FLERR,"Could not find undump ID"); delete dump[idump]; - delete [] var_dump[idump]; + delete[] var_dump[idump]; // move other dumps down in list one slot @@ -869,7 +866,7 @@ void Output::set_thermo(int narg, char **arg) // always reset var_thermo, so it is possible to switch back from // variable spaced thermo outputs to constant spaced ones. - delete [] var_thermo; + delete[] var_thermo; var_thermo = nullptr; if (utils::strmatch(arg[0],"^v_")) { @@ -929,12 +926,12 @@ void Output::create_restart(int narg, char **arg) delete restart; restart = nullptr; - delete [] restart1; - delete [] restart2a; - delete [] restart2b; + delete[] restart1; + delete[] restart2a; + delete[] restart2b; restart1 = restart2a = restart2b = nullptr; - delete [] var_restart_single; - delete [] var_restart_double; + delete[] var_restart_single; + delete[] var_restart_double; var_restart_single = var_restart_double = nullptr; return; @@ -950,13 +947,13 @@ void Output::create_restart(int narg, char **arg) restart_flag = restart_flag_single = 1; if (varflag) { - delete [] var_restart_single; + delete[] var_restart_single; var_restart_single = utils::strdup(arg[0]+2); restart_every_single = 0; } else restart_every_single = every; int n = strlen(arg[1]) + 3; - delete [] restart1; + delete[] restart1; restart1 = new char[n]; strcpy(restart1,arg[1]); if (strchr(restart1,'*') == nullptr) strcat(restart1,".*"); @@ -966,13 +963,13 @@ void Output::create_restart(int narg, char **arg) restart_flag = restart_flag_double = 1; if (varflag) { - delete [] var_restart_double; + delete[] var_restart_double; var_restart_double = utils::strdup(arg[0]+2); restart_every_double = 0; } else restart_every_double = every; - delete [] restart2a; - delete [] restart2b; + delete[] restart2a; + delete[] restart2b; restart_toggle = 0; restart2a = utils::strdup(arg[1]); restart2b = utils::strdup(arg[2]); diff --git a/src/thermo.cpp b/src/thermo.cpp index f95b665e4e..63a33f6d45 100644 --- a/src/thermo.cpp +++ b/src/thermo.cpp @@ -52,7 +52,7 @@ using namespace LAMMPS_NS; using namespace MathConst; -// customize a new keyword by adding to this list: +// CUSTOMIZATION: add a new keyword by adding it to this list: // step, elapsed, elaplong, dt, time, cpu, tpcpu, spcpu, cpuremain, // part, timeremain @@ -66,54 +66,65 @@ using namespace MathConst; // fmax, fnorm, nbuild, ndanger // cella, cellb, cellc, cellalpha, cellbeta, cellgamma -// customize a new thermo style by adding a DEFINE to this list -// also insure allocation of line string is correct in constructor +// CUSTOMIZATION: add a new thermo style by adding a constant to the enumerator, +// define a new string constant with the keywords and provide default formats. -#define ONE "step temp epair emol etotal press" -#define MULTI "etotal ke temp pe ebond eangle edihed eimp evdwl ecoul elong press" +enum{ ONELINE, MULTILINE, YAMLLINE }; +// style "one" +static constexpr char ONE[] = "step temp epair emol etotal press"; +#define FORMAT_FLOAT_ONE_DEFAULT "%12.8g" +#define FORMAT_INT_ONE_DEFAULT "%10d" +// style "multi" +static constexpr char MULTI[] = "etotal ke temp pe ebond eangle edihed eimp evdwl ecoul elong press"; +#define FORMAT_FLOAT_MULTI_DEFAULT "%14.4f" +#define FORMAT_INT_MULTI_DEFAULT "%14d" +// style "yaml" +static constexpr char YAML[] = "step temp ke pe ebond eangle edihed eimp evdwl ecoul elong press"; +#define FORMAT_FLOAT_YAML_DEFAULT "%.15g" +#define FORMAT_INT_YAML_DEFAULT "%d" -enum{ONELINE,MULTILINE}; -enum{SCALAR,VECTOR,ARRAY}; +#define FORMAT_MULTI_HEADER "------------ Step {:14} ----- CPU = {:12.7g} (sec) -------------" +enum{ SCALAR, VECTOR, ARRAY }; +static constexpr char id_temp[] = "thermo_temp"; +static constexpr char id_press[] = "thermo_press"; +static constexpr char id_pe[] = "thermo_pe"; + +static char fmtbuf[512]; #define DELTA 8 /* ---------------------------------------------------------------------- */ -Thermo::Thermo(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) +Thermo::Thermo(LAMMPS *_lmp, int narg, char **arg) : + Pointers(_lmp), style(nullptr), vtype(nullptr), field2index(nullptr), argindex1(nullptr), + argindex2(nullptr), temperature(nullptr), pressure(nullptr), pe(nullptr) { - MPI_Comm_rank(world,&me); - style = utils::strdup(arg[0]); // set thermo_modify defaults + lineflag = ONELINE; modified = 0; normuserflag = 0; - lineflag = ONELINE; lostflag = lostbond = Thermo::ERROR; lostbefore = warnbefore = 0; flushflag = 0; // set style and corresponding lineflag // custom style builds its own line of keywords, including wildcard expansion - // customize a new thermo style by adding to if statement - // allocate line string used for 3 tasks - // concat of custom style args - // one-time thermo output of header line - // each line of numeric thermo output - // 256 = extra for ONE or MULTI string or multi formatting - // 64 = max per-arg chars in header or numeric output + // CUSTOMIZATION: add a new thermo style by adding it to the if statement + // set line string with default keywords if not custom style. if (strcmp(style,"one") == 0) { - line = new char[256+6*64]; - memset(line,0,256+6*64); - strcpy(line,ONE); + line = ONE; + lineflag = ONELINE; } else if (strcmp(style,"multi") == 0) { - line = new char[256+12*64]; - memset(line,0,256+12*64); - strcpy(line,MULTI); + line = MULTI; lineflag = MULTILINE; + } else if (strcmp(style,"yaml") == 0) { + line = YAML; + lineflag = YAMLLINE; } else if (strcmp(style,"custom") == 0) { if (narg == 1) error->all(FLERR,"Illegal thermo style custom command"); @@ -125,35 +136,23 @@ Thermo::Thermo(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) int nvalues = utils::expand_args(FLERR,narg-1,&arg[1],0,earg,lmp); if (earg != &arg[1]) expand = 1; - line = new char[256+nvalues*64]; - line[0] = '\0'; + line.clear(); for (int iarg = 0; iarg < nvalues; iarg++) { - strcat(line,earg[iarg]); - strcat(line," "); + line += earg[iarg]; + line += ' '; } - line[strlen(line)-1] = '\0'; // if wildcard expansion occurred, free earg memory from exapnd_args() if (expand) { - for (int i = 0; i < nvalues; i++) delete [] earg[i]; + for (int i = 0; i < nvalues; i++) delete[] earg[i]; memory->sfree(earg); } } else error->all(FLERR,"Illegal thermo style command"); - // ptrs, flags, IDs for compute objects thermo may use or create - - temperature = nullptr; - pressure = nullptr; - pe = nullptr; - index_temp = index_press_scalar = index_press_vector = index_pe = -1; - id_temp = (char *) "thermo_temp"; - id_press = (char *) "thermo_press"; - id_pe = (char *) "thermo_pe"; - // count fields in line // allocate per-field memory // process line of keywords @@ -161,50 +160,20 @@ Thermo::Thermo(LAMMPS *lmp, int narg, char **arg) : Pointers(lmp) nfield_initial = utils::trim_and_count_words(line); allocate(); parse_fields(line); - - // format strings - - char *bigint_format = (char *) BIGINT_FORMAT; - char *fformat_multi = (char *) "---------------- Step %%8%s ----- " - "CPU = %%11.4f (sec) ----------------"; - - sprintf(format_multi,fformat_multi,&bigint_format[1]); - format_float_one_def = (char *) "%12.8g"; - format_float_multi_def = (char *) "%14.4f"; - format_int_one_def = (char *) "%8d"; - format_int_multi_def = (char *) "%14d"; - sprintf(format_bigint_one_def,"%%8%s",&bigint_format[1]); - sprintf(format_bigint_multi_def,"%%14%s",&bigint_format[1]); - - format_line_user = nullptr; - format_float_user = nullptr; - format_int_user = nullptr; - format_bigint_user = nullptr; } /* ---------------------------------------------------------------------- */ Thermo::~Thermo() { - delete [] style; - delete [] line; - + delete[] style; deallocate(); - - // format strings - - delete [] format_line_user; - delete [] format_float_user; - delete [] format_int_user; - delete [] format_bigint_user; } /* ---------------------------------------------------------------------- */ void Thermo::init() { - int i,n; - // set normvalue to default setting unless user has specified it if (normuserflag) normvalue = normuser; @@ -222,52 +191,66 @@ void Thermo::init() // include keyword if lineflag = MULTILINE // add '/n' every 3 values if lineflag = MULTILINE // add trailing '/n' to last value + // add YAML list item prefix for lineflag = YAMLLINE - ValueTokenizer * format_line = nullptr; - if (format_line_user) { - format_line = new ValueTokenizer(format_line_user); - } + ValueTokenizer *format_line = nullptr; + if (format_line_user.size()) format_line = new ValueTokenizer(format_line_user); - const char *ptr = nullptr; - std::string format_line_user_def; - for (i = 0; i < nfield; i++) { + std::string format_this, format_line_user_def; + for (int i = 0; i < nfield; i++) { - format[i][0] = '\0'; - if (lineflag == MULTILINE && i % 3 == 0) strcat(format[i],"\n"); + format[i].clear(); + format_this.clear(); + format_line_user_def.clear(); - if (format_line_user) { - format_line_user_def = format_line->next_string(); - } + if ((lineflag == MULTILINE) && ((i % 3) == 0)) format[i] += "\n"; + if ((lineflag == YAMLLINE) && (i == 0)) format[i] += " - ["; + if (format_line) format_line_user_def = format_line->next_string(); - if (format_column_user[i]) ptr = format_column_user[i]; + if (format_column_user[i].size()) format_this = format_column_user[i]; else if (vtype[i] == FLOAT) { - if (format_float_user) ptr = format_float_user; - else if (format_line_user) ptr = format_line_user_def.c_str(); - else if (lineflag == ONELINE) ptr = format_float_one_def; - else if (lineflag == MULTILINE) ptr = format_float_multi_def; - } else if (vtype[i] == INT) { - if (format_int_user) ptr = format_int_user; - else if (format_line_user) ptr = format_line_user_def.c_str(); - else if (lineflag == ONELINE) ptr = format_int_one_def; - else if (lineflag == MULTILINE) ptr = format_int_multi_def; - } else if (vtype[i] == BIGINT) { - if (format_bigint_user) ptr = format_bigint_user; - else if (format_line_user) ptr = format_line_user_def.c_str(); - else if (lineflag == ONELINE) ptr = format_bigint_one_def; - else if (lineflag == MULTILINE) ptr = format_bigint_multi_def; + if (format_float_user.size()) format_this = format_float_user; + else if (format_line_user_def.size()) format_this = format_line_user_def; + else if (lineflag == ONELINE) format_this = FORMAT_FLOAT_ONE_DEFAULT; + else if (lineflag == MULTILINE) format_this = FORMAT_FLOAT_MULTI_DEFAULT; + else if (lineflag == YAMLLINE) format_this = FORMAT_FLOAT_YAML_DEFAULT; + } else if ((vtype[i] == INT) || (vtype[i] == BIGINT)) { + if (format_int_user.size()) { + if (vtype[i] == INT) + format_this = format_int_user; + else + format_this = format_bigint_user; + } else if (format_line_user_def.size()) { + format_this = format_line_user_def; + } else { + if (lineflag == ONELINE) format_this = FORMAT_INT_ONE_DEFAULT; + else if (lineflag == MULTILINE) format_this = FORMAT_INT_MULTI_DEFAULT; + else format_this = FORMAT_INT_YAML_DEFAULT; + if (vtype[i] == BIGINT) { + // replace "d" in int format with bigint format specifier + auto found = format_this.find('%'); + found = format_this.find('d', found); + format_this = format_this.replace(found, 1, std::string(BIGINT_FORMAT).substr(1)); + } + } } - n = strlen(format[i]); - if (lineflag == ONELINE) sprintf(&format[i][n],"%s ",ptr); - else sprintf(&format[i][n],"%-8s = %s ",keyword[i],ptr); + if (lineflag == ONELINE) format[i] += format_this + " "; + else if (lineflag == YAMLLINE) format[i] += format_this + ", "; + else format[i] += fmt::format("{:<8} = {} ",keyword[i],format_this); } - strcat(format[nfield-1],"\n"); + + // chop off trailing blank or add closing bracket if needed and then add newline + if (lineflag == ONELINE) format[nfield-1].resize(format[nfield-1].size()-1); + else if (lineflag == MULTILINE) format[nfield-1].resize(format[nfield-1].size()-1); + else if (lineflag == YAMLLINE) format[nfield-1] += ']'; + format[nfield-1] += '\n'; delete format_line; // find current ptr for each Compute ID - for (i = 0; i < ncompute; i++) { + for (int i = 0; i < ncompute; i++) { computes[i] = modify->get_compute_by_id(id_compute[i]); if (!computes[i]) error->all(FLERR,"Could not find thermo compute with ID {}",id_compute[i]); } @@ -275,7 +258,7 @@ void Thermo::init() // find current ptr for each Fix ID // check that fix frequency is acceptable with thermo output frequency - for (i = 0; i < nfix; i++) { + for (int i = 0; i < nfix; i++) { fixes[i] = modify->get_fix_by_id(id_fix[i]); if (!fixes[i]) error->all(FLERR,"Could not find thermo fix ID {}",id_fix[i]); @@ -285,12 +268,9 @@ void Thermo::init() // find current ptr for each Variable ID - int ivariable; - for (i = 0; i < nvariable; i++) { - ivariable = input->variable->find(id_variable[i]); - if (ivariable < 0) - error->all(FLERR,"Could not find thermo variable name"); - variables[i] = ivariable; + for (int i = 0; i < nvariable; i++) { + variables[i] = input->variable->find(id_variable[i]); + if (variables[i] < 0) error->all(FLERR,"Could not find thermo variable {}",id_variable[i]); } // set ptrs to keyword-specific Compute objects @@ -301,16 +281,53 @@ void Thermo::init() if (index_pe >= 0) pe = computes[index_pe]; } -/* ---------------------------------------------------------------------- */ +/* ---------------------------------------------------------------------- + Print thermo style header text + if thermo style "multi": + nothing + + if thermo style "one": + ... + each column head is centered with default formatting + width should match the width of the default format string + + if thermo style "yaml": + --- + keywords: [ , , ...] + data: + + ---------------------------------------------------------------------- */ void Thermo::header() { if (lineflag == MULTILINE) return; std::string hdr; - for (int i = 0; i < nfield; i++) hdr += keyword[i] + std::string(" "); + if (lineflag == YAMLLINE) hdr = "---\nkeywords: ["; + for (int i = 0; i < nfield; i++) { + if (lineflag == ONELINE) { + if (vtype[i] == FLOAT) + hdr += fmt::format("{:^12} ", keyword[i]); + else if ((vtype[i] == INT) || (vtype[i] == BIGINT)) + hdr += fmt::format("{:^10} ", keyword[i]); + } else if (lineflag == YAMLLINE) { + hdr += keyword[i]; + hdr += ", "; + } + } + if (lineflag == YAMLLINE) + hdr += "]\ndata:"; + else + hdr.resize(hdr.size()-1); // chop off trailing blank - if (me == 0) utils::logmesg(lmp,hdr+"\n"); + if (comm->me == 0) utils::logmesg(lmp,hdr+"\n"); +} + +/* ---------------------------------------------------------------------- */ + +void Thermo::footer() +{ + if (lineflag == YAMLLINE) utils::logmesg(lmp,"...\n"); } /* ---------------------------------------------------------------------- */ @@ -351,29 +368,33 @@ void Thermo::compute(int flag) // if lineflag = MULTILINE, prepend step/cpu header line - int loc = 0; + line.clear(); if (lineflag == MULTILINE) { double cpu; if (flag) cpu = timer->elapsed(Timer::TOTAL); else cpu = 0.0; - loc = sprintf(&line[loc],format_multi,ntimestep,cpu); + line += fmt::format(FORMAT_MULTI_HEADER, ntimestep, cpu); } // add each thermo value to line with its specific format for (ifield = 0; ifield < nfield; ifield++) { (this->*vfunc[ifield])(); - if (vtype[ifield] == FLOAT) - loc += sprintf(&line[loc],format[ifield],dvalue); - else if (vtype[ifield] == INT) - loc += sprintf(&line[loc],format[ifield],ivalue); - else if (vtype[ifield] == BIGINT) - loc += sprintf(&line[loc],format[ifield],bivalue); + if (vtype[ifield] == FLOAT) { + snprintf(fmtbuf, sizeof(fmtbuf), format[ifield].c_str(), dvalue); + line += fmtbuf; + } else if (vtype[ifield] == INT) { + snprintf(fmtbuf, sizeof(fmtbuf), format[ifield].c_str(), ivalue); + line += fmtbuf; + } else if (vtype[ifield] == BIGINT) { + snprintf(fmtbuf, sizeof(fmtbuf), format[ifield].c_str(), bivalue); + line += fmtbuf; + } } // print line to screen and logfile - if (me == 0) { + if (comm->me == 0) { utils::logmesg(lmp,line); if (flushflag) utils::flush_buffers(lmp); } @@ -432,14 +453,12 @@ bigint Thermo::lost_check() // error message if (lostflag == Thermo::ERROR) - error->all(FLERR,"Lost atoms: original {} current {}", - atom->natoms,ntotal[0]); + error->all(FLERR,"Lost atoms: original {} current {}",atom->natoms,ntotal[0]); // warning message - if (me == 0) - error->warning(FLERR,"Lost atoms: original {} current {}", - atom->natoms,ntotal[0]); + if (comm->me == 0) + error->warning(FLERR,"Lost atoms: original {} current {}",atom->natoms,ntotal[0]); // reset total atom count @@ -498,11 +517,11 @@ void Thermo::modify_params(int narg, char **arg) error->all(FLERR,"Thermo style does not use press"); if (index_press_scalar >= 0) { - delete [] id_compute[index_press_scalar]; + delete[] id_compute[index_press_scalar]; id_compute[index_press_scalar] = utils::strdup(arg[iarg+1]); } if (index_press_vector >= 0) { - delete [] id_compute[index_press_vector]; + delete[] id_compute[index_press_vector]; id_compute[index_press_vector] = utils::strdup(arg[iarg+1]); } @@ -560,6 +579,7 @@ void Thermo::modify_params(int narg, char **arg) if (iarg+2 > narg) error->all(FLERR,"Illegal thermo_modify command"); if (strcmp(arg[iarg+1],"one") == 0) lineflag = ONELINE; else if (strcmp(arg[iarg+1],"multi") == 0) lineflag = MULTILINE; + else if (strcmp(arg[iarg+1],"yaml") == 0) lineflag = YAMLLINE; else error->all(FLERR,"Illegal thermo_modify command"); iarg += 2; @@ -567,18 +587,12 @@ void Thermo::modify_params(int narg, char **arg) if (iarg+2 > narg) error->all(FLERR,"Illegal thermo_modify command"); if (strcmp(arg[iarg+1],"none") == 0) { - delete [] format_line_user; - delete [] format_int_user; - delete [] format_bigint_user; - delete [] format_float_user; - format_line_user = nullptr; - format_int_user = nullptr; - format_bigint_user = nullptr; - format_float_user = nullptr; - for (int i = 0; i < nfield_initial+1; i++) { - delete [] format_column_user[i]; - format_column_user[i] = nullptr; - } + format_line_user.clear(); + format_int_user.clear(); + format_bigint_user.clear(); + format_float_user.clear(); + for (int i = 0; i < nfield_initial+1; ++i) + format_column_user[i].clear(); iarg += 2; continue; } @@ -586,33 +600,22 @@ void Thermo::modify_params(int narg, char **arg) if (iarg+3 > narg) error->all(FLERR,"Illegal thermo_modify command"); if (strcmp(arg[iarg+1],"line") == 0) { - delete [] format_line_user; - format_line_user = utils::strdup(arg[iarg+2]); + format_line_user = arg[iarg+2]; } else if (strcmp(arg[iarg+1],"int") == 0) { - if (format_int_user) delete [] format_int_user; - format_int_user = utils::strdup(arg[iarg+2]); - if (format_bigint_user) delete [] format_bigint_user; + format_int_user = arg[iarg+2]; // replace "d" in format_int_user with bigint format specifier - char *ptr = strchr(format_int_user,'d'); - if (ptr == nullptr) - error->all(FLERR, - "Thermo_modify int format does not contain d character"); - - *ptr = '\0'; - std::string fnew = fmt::format("{}{}{}",format_int_user, - std::string(BIGINT_FORMAT).substr(1), - ptr+1); - format_bigint_user = utils::strdup(fnew); - *ptr = 'd'; + auto found = format_int_user.find('%'); + found = format_int_user.find('d', found); + if (found == std::string::npos) + error->all(FLERR,"Thermo_modify int format does not contain a d conversion character"); + format_bigint_user = format_int_user.replace(found, 1, std::string(BIGINT_FORMAT).substr(1)); } else if (strcmp(arg[iarg+1],"float") == 0) { - if (format_float_user) delete [] format_float_user; - format_float_user = utils::strdup(arg[iarg+2]); + format_float_user = arg[iarg+2]; } else { int i = utils::inumeric(FLERR,arg[iarg+1],false,lmp) - 1; if (i < 0 || i >= nfield_initial+1) error->all(FLERR,"Illegal thermo_modify command"); - if (format_column_user[i]) delete [] format_column_user[i]; - format_column_user[i] = utils::strdup(arg[iarg+2]); + format_column_user[i] = arg[iarg+2]; } iarg += 3; @@ -628,18 +631,20 @@ void Thermo::allocate() { // n = specified fields + Volume field (added at run time) - int n = nfield_initial + 1; + const int n = nfield_initial + 1; + + keyword.resize(n); + format.resize(n); + format_column_user.resize(n); + for (int i = 0; i < n; i++) { + keyword[i].clear(); + format[i].clear(); + format_column_user[i].clear(); + } - keyword = new char*[n]; - for (int i = 0; i < n; i++) keyword[i] = nullptr; vfunc = new FnPtr[n]; vtype = new int[n]; - format = new char*[n]; - for (int i = 0; i < n; i++) format[i] = new char[32]; - format_column_user = new char*[n]; - for (int i = 0; i < n; i++) format_column_user[i] = nullptr; - field2index = new int[n]; argindex1 = new int[n]; argindex2 = new int[n]; @@ -666,34 +671,25 @@ void Thermo::allocate() void Thermo::deallocate() { - int n = nfield_initial + 1; + delete[] vfunc; + delete[] vtype; - for (int i = 0; i < n; i++) delete [] keyword[i]; - delete [] keyword; - delete [] vfunc; - delete [] vtype; + delete[] field2index; + delete[] argindex1; + delete[] argindex2; - for (int i = 0; i < n; i++) delete [] format[i]; - delete [] format; - for (int i = 0; i < n; i++) delete [] format_column_user[i]; - delete [] format_column_user; + for (int i = 0; i < ncompute; i++) delete[] id_compute[i]; + delete[] id_compute; + delete[] compute_which; + delete[] computes; - delete [] field2index; - delete [] argindex1; - delete [] argindex2; + for (int i = 0; i < nfix; i++) delete[] id_fix[i]; + delete[] id_fix; + delete[] fixes; - for (int i = 0; i < ncompute; i++) delete [] id_compute[i]; - delete [] id_compute; - delete [] compute_which; - delete [] computes; - - for (int i = 0; i < nfix; i++) delete [] id_fix[i]; - delete [] id_fix; - delete [] fixes; - - for (int i = 0; i < nvariable; i++) delete [] id_variable[i]; - delete [] id_variable; - delete [] variables; + for (int i = 0; i < nvariable; i++) delete[] id_variable[i]; + delete[] id_variable; + delete[] variables; } /* ---------------------------------------------------------------------- @@ -701,11 +697,11 @@ void Thermo::deallocate() set compute flags (temp, press, pe, etc) ------------------------------------------------------------------------- */ -void Thermo::parse_fields(char *str) +void Thermo::parse_fields(const std::string &str) { nfield = 0; - // customize a new keyword by adding to if statement + // CUSTOMIZATION: add a new thermo keyword by adding it to the if statements ValueTokenizer keywords(str); while (keywords.has_next()) { @@ -983,8 +979,7 @@ void Thermo::parse_fields(char *str) void Thermo::addfield(const char *key, FnPtr func, int typeflag) { - delete[] keyword[nfield]; - keyword[nfield] = utils::strdup(key); + keyword[nfield] = key; vfunc[nfield] = func; vtype[nfield] = typeflag; nfield++; @@ -1037,7 +1032,7 @@ int Thermo::add_variable(const char *id) called when a variable is evaluated by Variable class return value as double in answer return 0 if str is recognized keyword, 1 if unrecognized - customize a new keyword by adding to if statement + CUSTOMIZATION: add a new keyword by adding a suitable if statement ------------------------------------------------------------------------- */ int Thermo::evaluate_keyword(const char *word, double *answer) @@ -1067,15 +1062,13 @@ int Thermo::evaluate_keyword(const char *word, double *answer) } else if (strcmp(word,"elapsed") == 0) { if (update->whichflag == 0) - error->all(FLERR, - "This variable thermo keyword cannot be used between runs"); + error->all(FLERR,"This variable thermo keyword cannot be used between runs"); compute_elapsed(); dvalue = bivalue; } else if (strcmp(word,"elaplong") == 0) { if (update->whichflag == 0) - error->all(FLERR, - "This variable thermo keyword cannot be used between runs"); + error->all(FLERR,"This variable thermo keyword cannot be used between runs"); compute_elapsed_long(); dvalue = bivalue; @@ -1577,7 +1570,7 @@ void Thermo::compute_variable() called by compute() or evaluate_keyword() compute will have already been called set ivalue/dvalue/bivalue if value is int/double/bigint - customize a new keyword by adding a method + CUSTOMIZATION: add a new thermo keyword by adding a new method ------------------------------------------------------------------------- */ void Thermo::compute_step() @@ -2215,4 +2208,3 @@ void Thermo::compute_cellgamma() dvalue = acos(cosgamma)*180.0/MY_PI; } } - diff --git a/src/thermo.h b/src/thermo.h index 9eca4df18b..2f69b501c0 100644 --- a/src/thermo.h +++ b/src/thermo.h @@ -39,26 +39,16 @@ class Thermo : protected Pointers { bigint lost_check(); void modify_params(int, char **); void header(); + void footer(); void compute(int); int evaluate_keyword(const char *, double *); private: - char *line; - char **keyword; - int *vtype; - int nfield, nfield_initial; - int me; - - char **format; - char *format_line_user; - char *format_float_user, *format_int_user, *format_bigint_user; - char **format_column_user; - - char *format_float_one_def, *format_float_multi_def; - char *format_int_one_def, *format_int_multi_def; - char format_multi[128]; - char format_bigint_one_def[8], format_bigint_multi_def[8]; + int *vtype; + std::string line; + std::vector keyword, format, format_column_user; + std::string format_line_user, format_float_user, format_int_user, format_bigint_user; int normvalue; // use this for normflag unless natoms = 0 int normuserflag; // 0 if user has not set, 1 if has @@ -88,7 +78,6 @@ class Thermo : protected Pointers { // id = ID of Compute objects // Compute * = ptrs to the Compute objects int index_temp, index_press_scalar, index_press_vector, index_pe; - char *id_temp, *id_press, *id_pe; class Compute *temperature, *pressure, *pe; int ncompute; // # of Compute objects called by thermo @@ -109,7 +98,7 @@ class Thermo : protected Pointers { void allocate(); void deallocate(); - void parse_fields(char *); + void parse_fields(const std::string &); int add_compute(const char *, int); int add_fix(const char *); int add_variable(const char *); From a4d2062865bd2f107b9e6b4f49f72ef76c3756ec Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 19 Mar 2022 18:01:12 -0400 Subject: [PATCH 02/11] reduce redundant code with helper functions and simplify by using std::string --- src/thermo.cpp | 532 +++++++++++++++++++------------------------------ src/thermo.h | 7 +- 2 files changed, 214 insertions(+), 325 deletions(-) diff --git a/src/thermo.cpp b/src/thermo.cpp index 63a33f6d45..722bb90873 100644 --- a/src/thermo.cpp +++ b/src/thermo.cpp @@ -1025,6 +1025,81 @@ int Thermo::add_variable(const char *id) id_variable[nvariable] = utils::strdup(id); nvariable++; return nvariable-1; + +/* ---------------------------------------------------------------------- + check whether temperature compute is defined, available, and current +------------------------------------------------------------------------- */ + +void Thermo::check_temp(const std::string &keyword) +{ + if (!temperature) + error->all(FLERR, "Thermo keyword {} in variable requires thermo to use/init temperature", + keyword); + if (update->whichflag == 0) { + if (temperature->invoked_scalar != update->ntimestep) + error->all(FLERR, "Compute {} {} used in variable thermo keyword between runs is not current", + temperature->style, temperature->id); + } else if (!(temperature->invoked_flag & Compute::INVOKED_SCALAR)) { + temperature->compute_scalar(); + temperature->invoked_flag |= Compute::INVOKED_SCALAR; + } +} + +/* ---------------------------------------------------------------------- + check whether potential energy compute is defined, available, and current +------------------------------------------------------------------------- */ + +void Thermo::check_pe(const std::string &keyword) +{ + if (update->eflag_global != update->ntimestep) + error->all(FLERR, "Energy was not tallied on needed timestep"); + if (!pe) + error->all(FLERR, "Thermo keyword {} in variable requires thermo to use/init potential energy", + keyword); + if (update->whichflag == 0) { + if (pe->invoked_scalar != update->ntimestep) + error->all(FLERR, "Compute {} {} used in variable thermo keyword between runs is not current", + pe->style, pe->id); + } else { + pe->compute_scalar(); + pe->invoked_flag |= Compute::INVOKED_SCALAR; + } +} + +/* ---------------------------------------------------------------------- + check whether scalar pressure compute is defined, available, and current +------------------------------------------------------------------------- */ + +void Thermo::check_press_scalar(const std::string &keyword) +{ + if (!pressure) + error->all(FLERR, "Thermo keyword {} in variable requires thermo to use/init press", keyword); + if (update->whichflag == 0) { + if (pressure->invoked_scalar != update->ntimestep) + error->all(FLERR, "Compute {} {} used in variable thermo keyword between runs is not current", + pressure->style, pressure->id); + } else if (!(pressure->invoked_flag & Compute::INVOKED_SCALAR)) { + pressure->compute_scalar(); + pressure->invoked_flag |= Compute::INVOKED_SCALAR; + } +} + +/* ---------------------------------------------------------------------- + check whether pressure tensor compute is defined, available, and current +------------------------------------------------------------------------- */ + +void Thermo::check_press_vector(const std::string &keyword) +{ + if (!pressure) + error->all(FLERR, "Thermo keyword {} in variable requires thermo to use/init press", keyword); + if (update->whichflag == 0) { + if (pressure->invoked_vector != update->ntimestep) + error->all(FLERR, "Compute {} {} used in variable thermo keyword between runs is not current", + pressure->style, pressure->id); + } else if (!(pressure->invoked_flag & Compute::INVOKED_VECTOR)) { + pressure->compute_vector(); + pressure->invoked_flag |= Compute::INVOKED_VECTOR; + } } /* ---------------------------------------------------------------------- @@ -1035,14 +1110,16 @@ int Thermo::add_variable(const char *id) CUSTOMIZATION: add a new keyword by adding a suitable if statement ------------------------------------------------------------------------- */ -int Thermo::evaluate_keyword(const char *word, double *answer) +int Thermo::evaluate_keyword(const std::string &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 natoms = atom->natoms; - if (natoms == 0) normflag = 0; - else normflag = normvalue; + if (natoms == 0) + normflag = 0; + else + normflag = normvalue; // invoke a lo-level thermo routine to compute the variable value // if keyword requires a compute, error if thermo doesn't use the compute @@ -1056,435 +1133,242 @@ int Thermo::evaluate_keyword(const char *word, double *answer) // because evdwl/etc may have set invoked_flag w/out // actually invoking pe->compute_scalar() - if (strcmp(word,"step") == 0) { + if (word == "step") { compute_step(); dvalue = bivalue; - } else if (strcmp(word,"elapsed") == 0) { + } else if (word == "elapsed") { if (update->whichflag == 0) - error->all(FLERR,"This variable thermo keyword cannot be used between runs"); + error->all(FLERR, "This variable thermo keyword cannot be used between runs"); compute_elapsed(); dvalue = bivalue; - } else if (strcmp(word,"elaplong") == 0) { + } else if (word == "elaplong") { if (update->whichflag == 0) - error->all(FLERR,"This variable thermo keyword cannot be used between runs"); + error->all(FLERR, "This variable thermo keyword cannot be used between runs"); compute_elapsed_long(); dvalue = bivalue; - } else if (strcmp(word,"dt") == 0) { + } else if (word == "dt") { compute_dt(); - } else if (strcmp(word,"time") == 0) { + } else if (word == "time") { compute_time(); - } else if (strcmp(word,"cpu") == 0) { + } else if (word == "cpu") { if (update->whichflag == 0) - error->all(FLERR, - "This variable thermo keyword cannot be used between runs"); + error->all(FLERR, "This variable thermo keyword cannot be used between runs"); compute_cpu(); - } else if (strcmp(word,"tpcpu") == 0) { + } else if (word == "tpcpu") { if (update->whichflag == 0) - error->all(FLERR, - "This variable thermo keyword cannot be used between runs"); + error->all(FLERR, "This variable thermo keyword cannot be used between runs"); compute_tpcpu(); - } else if (strcmp(word,"spcpu") == 0) { + } else if (word == "spcpu") { if (update->whichflag == 0) - error->all(FLERR, - "This variable thermo keyword cannot be used between runs"); + error->all(FLERR, "This variable thermo keyword cannot be used between runs"); compute_spcpu(); - } else if (strcmp(word,"cpuremain") == 0) { + } else if (word == "cpuremain") { if (update->whichflag == 0) - error->all(FLERR, - "This variable thermo keyword cannot be used between runs"); + error->all(FLERR, "This variable thermo keyword cannot be used between runs"); compute_cpuremain(); - } else if (strcmp(word,"part") == 0) { + } else if (word == "part") { compute_part(); dvalue = ivalue; - } else if (strcmp(word,"timeremain") == 0) { + } else if (word == "timeremain") { compute_timeremain(); - - } else if (strcmp(word,"atoms") == 0) { + } else if (word == "atoms") { compute_atoms(); dvalue = bivalue; - } else if (strcmp(word,"bonds") == 0) { + } else if (word == "bonds") { compute_bonds(); dvalue = bivalue; - } else if (strcmp(word,"angles") == 0) { + } else if (word == "angles") { compute_angles(); dvalue = bivalue; - } else if (strcmp(word,"dihedrals") == 0) { + } else if (word == "dihedrals") { compute_dihedrals(); dvalue = bivalue; - } else if (strcmp(word,"impropers") == 0) { + } else if (word == "impropers") { compute_impropers(); dvalue = bivalue; - } else if (strcmp(word,"temp") == 0) { - if (!temperature) - error->all(FLERR,"Thermo keyword in variable requires " - "thermo to use/init temp"); - if (update->whichflag == 0) { - if (temperature->invoked_scalar != update->ntimestep) - error->all(FLERR,"Compute used in variable thermo keyword between runs " - "is not current"); - } else if (!(temperature->invoked_flag & Compute::INVOKED_SCALAR)) { - temperature->compute_scalar(); - temperature->invoked_flag |= Compute::INVOKED_SCALAR; - } + } else if (word == "temp") { + check_temp(word); compute_temp(); - } else if (strcmp(word,"press") == 0) { - if (!pressure) - error->all(FLERR,"Thermo keyword in variable requires " - "thermo to use/init press"); - if (update->whichflag == 0) { - if (pressure->invoked_scalar != update->ntimestep) - error->all(FLERR,"Compute used in variable thermo keyword between runs " - "is not current"); - } else if (!(pressure->invoked_flag & Compute::INVOKED_SCALAR)) { - pressure->compute_scalar(); - pressure->invoked_flag |= Compute::INVOKED_SCALAR; - } + } else if (word == "press") { + check_press_scalar(word); compute_press(); - } else if (strcmp(word,"pe") == 0) { - if (!pe) - error->all(FLERR, - "Thermo keyword in variable requires thermo to use/init pe"); - if (update->whichflag == 0) { - if (pe->invoked_scalar != update->ntimestep) - error->all(FLERR,"Compute used in variable thermo keyword between runs " - "is not current"); - } else { - pe->compute_scalar(); - pe->invoked_flag |= Compute::INVOKED_SCALAR; - } + } else if (word == "pe") { + check_pe(word); compute_pe(); - } else if (strcmp(word,"ke") == 0) { - if (!temperature) - error->all(FLERR,"Thermo keyword in variable requires " - "thermo to use/init temp"); - if (update->whichflag == 0) { - if (temperature->invoked_scalar != update->ntimestep) - error->all(FLERR,"Compute used in variable thermo keyword between runs " - "is not current"); - } else if (!(temperature->invoked_flag & Compute::INVOKED_SCALAR)) { - temperature->compute_scalar(); - temperature->invoked_flag |= Compute::INVOKED_SCALAR; - } + } else if (word == "ke") { + check_temp(word); compute_ke(); - } else if (strcmp(word,"etotal") == 0) { - if (!pe) - error->all(FLERR, - "Thermo keyword in variable requires thermo to use/init pe"); - if (update->whichflag == 0) { - if (pe->invoked_scalar != update->ntimestep) - error->all(FLERR,"Compute used in variable thermo keyword between runs " - "is not current"); - } else { - pe->compute_scalar(); - pe->invoked_flag |= Compute::INVOKED_SCALAR; - } - if (!temperature) - error->all(FLERR,"Thermo keyword in variable requires " - "thermo to use/init temp"); - if (update->whichflag == 0) { - if (temperature->invoked_scalar != update->ntimestep) - error->all(FLERR,"Compute used in variable thermo keyword between runs " - "is not current"); - } else if (!(temperature->invoked_flag & Compute::INVOKED_SCALAR)) { - temperature->compute_scalar(); - temperature->invoked_flag |= Compute::INVOKED_SCALAR; - } + } else if (word == "etotal") { + check_pe(word); + check_temp(word); compute_etotal(); - } else if (strcmp(word,"evdwl") == 0) { - if (update->eflag_global != update->ntimestep) - error->all(FLERR,"Energy was not tallied on needed timestep"); - if (!pe) - error->all(FLERR, - "Thermo keyword in variable requires thermo to use/init pe"); - pe->invoked_flag |= Compute::INVOKED_SCALAR; + } else if (word == "evdwl") { + check_pe(word); compute_evdwl(); - } else if (strcmp(word,"ecoul") == 0) { - if (update->eflag_global != update->ntimestep) - error->all(FLERR,"Energy was not tallied on needed timestep"); - if (!pe) - error->all(FLERR, - "Thermo keyword in variable requires thermo to use/init pe"); - pe->invoked_flag |= Compute::INVOKED_SCALAR; + } else if (word == "ecoul") { + check_pe(word); compute_ecoul(); - } else if (strcmp(word,"epair") == 0) { - if (update->eflag_global != update->ntimestep) - error->all(FLERR,"Energy was not tallied on needed timestep"); - if (!pe) - error->all(FLERR, - "Thermo keyword in variable requires thermo to use/init pe"); - pe->invoked_flag |= Compute::INVOKED_SCALAR; + } else if (word == "epair") { + check_pe(word); compute_epair(); - } else if (strcmp(word,"ebond") == 0) { - if (update->eflag_global != update->ntimestep) - error->all(FLERR,"Energy was not tallied on needed timestep"); - if (!pe) - error->all(FLERR, - "Thermo keyword in variable requires thermo to use/init pe"); - pe->invoked_flag |= Compute::INVOKED_SCALAR; + } else if (word == "ebond") { + check_pe(word); compute_ebond(); - } else if (strcmp(word,"eangle") == 0) { - if (update->eflag_global != update->ntimestep) - error->all(FLERR,"Energy was not tallied on needed timestep"); - if (!pe) - error->all(FLERR, - "Thermo keyword in variable requires thermo to use/init pe"); - pe->invoked_flag |= Compute::INVOKED_SCALAR; + } else if (word == "eangle") { + check_pe(word); compute_eangle(); - } else if (strcmp(word,"edihed") == 0) { - if (update->eflag_global != update->ntimestep) - error->all(FLERR,"Energy was not tallied on needed timestep"); - if (!pe) - error->all(FLERR, - "Thermo keyword in variable requires thermo to use/init pe"); - pe->invoked_flag |= Compute::INVOKED_SCALAR; + } else if (word == "edihed") { + check_pe(word); compute_edihed(); - } else if (strcmp(word,"eimp") == 0) { - if (update->eflag_global != update->ntimestep) - error->all(FLERR,"Energy was not tallied on needed timestep"); - if (!pe) - error->all(FLERR, - "Thermo keyword in variable requires thermo to use/init pe"); - pe->invoked_flag |= Compute::INVOKED_SCALAR; + } else if (word == "eimp") { + check_pe(word); compute_eimp(); - } else if (strcmp(word,"emol") == 0) { - if (update->eflag_global != update->ntimestep) - error->all(FLERR,"Energy was not tallied on needed timestep"); - if (!pe) - error->all(FLERR, - "Thermo keyword in variable requires thermo to use/init pe"); - pe->invoked_flag |= Compute::INVOKED_SCALAR; + } else if (word == "emol") { + check_pe(word); compute_emol(); - } else if (strcmp(word,"elong") == 0) { - if (update->eflag_global != update->ntimestep) - error->all(FLERR,"Energy was not tallied on needed timestep"); - if (!pe) - error->all(FLERR, - "Thermo keyword in variable requires thermo to use/init pe"); - pe->invoked_flag |= Compute::INVOKED_SCALAR; + } else if (word == "elong") { + check_pe(word); compute_elong(); - } else if (strcmp(word,"etail") == 0) { + } else if (word == "etail") { if (update->eflag_global != update->ntimestep) - error->all(FLERR,"Energy was not tallied on needed timestep"); + error->all(FLERR, "Energy was not tallied on needed timestep"); compute_etail(); - } else if (strcmp(word,"enthalpy") == 0) { - if (!pe) - error->all(FLERR, - "Thermo keyword in variable requires thermo to use/init pe"); - if (update->whichflag == 0) { - if (pe->invoked_scalar != update->ntimestep) - error->all(FLERR,"Compute used in variable thermo keyword between runs " - "is not current"); - } else { - pe->compute_scalar(); - pe->invoked_flag |= Compute::INVOKED_SCALAR; - } - if (!temperature) - error->all(FLERR,"Thermo keyword in variable requires " - "thermo to use/init temp"); - if (update->whichflag == 0) { - if (temperature->invoked_scalar != update->ntimestep) - error->all(FLERR,"Compute used in variable thermo keyword between runs " - "is not current"); - } else if (!(temperature->invoked_flag & Compute::INVOKED_SCALAR)) { - temperature->compute_scalar(); - temperature->invoked_flag |= Compute::INVOKED_SCALAR; - } - if (!pressure) - error->all(FLERR,"Thermo keyword in variable requires " - "thermo to use/init press"); - if (update->whichflag == 0) { - if (pressure->invoked_scalar != update->ntimestep) - error->all(FLERR,"Compute used in variable thermo keyword between runs " - "is not current"); - } else if (!(pressure->invoked_flag & Compute::INVOKED_SCALAR)) { - pressure->compute_scalar(); - pressure->invoked_flag |= Compute::INVOKED_SCALAR; - } + } else if (word == "enthalpy") { + check_pe(word); + check_temp(word); + check_press_scalar(word); compute_enthalpy(); - } else if (strcmp(word,"ecouple") == 0) compute_ecouple(); + } else if (word == "ecouple") + compute_ecouple(); - else if (strcmp(word,"econserve") == 0) { - if (!pe) - error->all(FLERR, - "Thermo keyword in variable requires thermo to use/init pe"); - if (update->whichflag == 0) { - if (pe->invoked_scalar != update->ntimestep) - error->all(FLERR,"Compute used in variable thermo keyword between runs " - "is not current"); - } else { - pe->compute_scalar(); - pe->invoked_flag |= Compute::INVOKED_SCALAR; - } - if (!temperature) - error->all(FLERR,"Thermo keyword in variable requires " - "thermo to use/init temp"); - if (update->whichflag == 0) { - if (temperature->invoked_scalar != update->ntimestep) - error->all(FLERR,"Compute used in variable thermo keyword between runs " - "is not current"); - } else if (!(temperature->invoked_flag & Compute::INVOKED_SCALAR)) { - temperature->compute_scalar(); - temperature->invoked_flag |= Compute::INVOKED_SCALAR; - } + else if (word == "econserve") { + check_pe(word); + check_temp(word); compute_econserve(); - } else if (strcmp(word,"vol") == 0) compute_vol(); - else if (strcmp(word,"density") == 0) compute_density(); - else if (strcmp(word,"lx") == 0) compute_lx(); - else if (strcmp(word,"ly") == 0) compute_ly(); - else if (strcmp(word,"lz") == 0) compute_lz(); + } else if (word == "vol") + compute_vol(); + else if (word == "density") + compute_density(); + else if (word == "lx") + compute_lx(); + else if (word == "ly") + compute_ly(); + else if (word == "lz") + compute_lz(); - else if (strcmp(word,"xlo") == 0) compute_xlo(); - else if (strcmp(word,"xhi") == 0) compute_xhi(); - else if (strcmp(word,"ylo") == 0) compute_ylo(); - else if (strcmp(word,"yhi") == 0) compute_yhi(); - else if (strcmp(word,"zlo") == 0) compute_zlo(); - else if (strcmp(word,"zhi") == 0) compute_zhi(); + else if (word == "xlo") + compute_xlo(); + else if (word == "xhi") + compute_xhi(); + else if (word == "ylo") + compute_ylo(); + else if (word == "yhi") + compute_yhi(); + else if (word == "zlo") + compute_zlo(); + else if (word == "zhi") + compute_zhi(); - else if (strcmp(word,"xy") == 0) compute_xy(); - else if (strcmp(word,"xz") == 0) compute_xz(); - else if (strcmp(word,"yz") == 0) compute_yz(); + else if (word == "xy") + compute_xy(); + else if (word == "xz") + compute_xz(); + else if (word == "yz") + compute_yz(); - else if (strcmp(word,"xlat") == 0) compute_xlat(); - else if (strcmp(word,"ylat") == 0) compute_ylat(); - else if (strcmp(word,"zlat") == 0) compute_zlat(); + else if (word == "xlat") + compute_xlat(); + else if (word == "ylat") + compute_ylat(); + else if (word == "zlat") + compute_zlat(); - else if (strcmp(word,"pxx") == 0) { - if (!pressure) - error->all(FLERR,"Thermo keyword in variable requires " - "thermo to use/init press"); - if (update->whichflag == 0) { - if (pressure->invoked_vector != update->ntimestep) - error->all(FLERR,"Compute used in variable thermo keyword between runs " - "is not current"); - } else if (!(pressure->invoked_flag & Compute::INVOKED_VECTOR)) { - pressure->compute_vector(); - pressure->invoked_flag |= Compute::INVOKED_VECTOR; - } + else if (word == "pxx") { + check_press_vector(word); compute_pxx(); - } else if (strcmp(word,"pyy") == 0) { - if (!pressure) - error->all(FLERR,"Thermo keyword in variable requires " - "thermo to use/init press"); - if (update->whichflag == 0) { - if (pressure->invoked_vector != update->ntimestep) - error->all(FLERR,"Compute used in variable thermo keyword between runs " - "is not current"); - } else if (!(pressure->invoked_flag & Compute::INVOKED_VECTOR)) { - pressure->compute_vector(); - pressure->invoked_flag |= Compute::INVOKED_VECTOR; - } + } else if (word == "pyy") { + check_press_vector(word); compute_pyy(); - } else if (strcmp(word,"pzz") == 0) { - if (!pressure) - error->all(FLERR,"Thermo keyword in variable requires " - "thermo to use/init press"); - if (update->whichflag == 0) { - if (pressure->invoked_vector != update->ntimestep) - error->all(FLERR,"Compute used in variable thermo keyword between runs " - "is not current"); - } else if (!(pressure->invoked_flag & Compute::INVOKED_VECTOR)) { - pressure->compute_vector(); - pressure->invoked_flag |= Compute::INVOKED_VECTOR; - } + } else if (word == "pzz") { + check_press_vector(word); compute_pzz(); - } else if (strcmp(word,"pxy") == 0) { - if (!pressure) - error->all(FLERR,"Thermo keyword in variable requires " - "thermo to use/init press"); - if (update->whichflag == 0) { - if (pressure->invoked_vector != update->ntimestep) - error->all(FLERR,"Compute used in variable thermo keyword between runs " - "is not current"); - } else if (!(pressure->invoked_flag & Compute::INVOKED_VECTOR)) { - pressure->compute_vector(); - pressure->invoked_flag |= Compute::INVOKED_VECTOR; - } + } else if (word == "pxy") { + check_press_vector(word); compute_pxy(); - } else if (strcmp(word,"pxz") == 0) { - if (!pressure) - error->all(FLERR,"Thermo keyword in variable requires " - "thermo to use/init press"); - if (update->whichflag == 0) { - if (pressure->invoked_vector != update->ntimestep) - error->all(FLERR,"Compute used in variable thermo keyword between runs " - "is not current"); - } else if (!(pressure->invoked_flag & Compute::INVOKED_VECTOR)) { - pressure->compute_vector(); - pressure->invoked_flag |= Compute::INVOKED_VECTOR; - } + } else if (word == "pxz") { + check_press_vector(word); compute_pxz(); - } else if (strcmp(word,"pyz") == 0) { - if (!pressure) - error->all(FLERR,"Thermo keyword in variable requires " - "thermo to use/init press"); - if (update->whichflag == 0) { - if (pressure->invoked_vector != update->ntimestep) - error->all(FLERR,"Compute used in variable thermo keyword between runs " - "is not current"); - } else if (!(pressure->invoked_flag & Compute::INVOKED_VECTOR)) { - pressure->compute_vector(); - pressure->invoked_flag |= Compute::INVOKED_VECTOR; - } + } else if (word == "pyz") { + check_press_vector(word); compute_pyz(); } - else if (strcmp(word,"fmax") == 0) compute_fmax(); - else if (strcmp(word,"fnorm") == 0) compute_fnorm(); + else if (word == "fmax") + compute_fmax(); + else if (word == "fnorm") + compute_fnorm(); - else if (strcmp(word,"nbuild") == 0) { + else if (word == "nbuild") { compute_nbuild(); dvalue = bivalue; - } else if (strcmp(word,"ndanger") == 0) { + } else if (word == "ndanger") { compute_ndanger(); dvalue = bivalue; } - else if (strcmp(word,"cella") == 0) compute_cella(); - else if (strcmp(word,"cellb") == 0) compute_cellb(); - else if (strcmp(word,"cellc") == 0) compute_cellc(); - else if (strcmp(word,"cellalpha") == 0) compute_cellalpha(); - else if (strcmp(word,"cellbeta") == 0) compute_cellbeta(); - else if (strcmp(word,"cellgamma") == 0) compute_cellgamma(); + else if (word == "cella") + compute_cella(); + else if (word == "cellb") + compute_cellb(); + else if (word == "cellc") + compute_cellc(); + else if (word == "cellalpha") + compute_cellalpha(); + else if (word == "cellbeta") + compute_cellbeta(); + else if (word == "cellgamma") + compute_cellgamma(); - else return 1; + else + return 1; *answer = dvalue; return 0; diff --git a/src/thermo.h b/src/thermo.h index 2f69b501c0..b0a2309312 100644 --- a/src/thermo.h +++ b/src/thermo.h @@ -41,7 +41,7 @@ class Thermo : protected Pointers { void header(); void footer(); void compute(int); - int evaluate_keyword(const char *, double *); + int evaluate_keyword(const std::string &, double *); private: int nfield, nfield_initial; @@ -103,6 +103,11 @@ class Thermo : protected Pointers { int add_fix(const char *); int add_variable(const char *); + void check_temp(const std::string &); + void check_pe(const std::string &); + void check_press_scalar(const std::string &); + void check_press_vector(const std::string &); + typedef void (Thermo::*FnPtr)(); void addfield(const char *, FnPtr, int); FnPtr *vfunc; // list of ptrs to functions From 74103b141ab39e123a43b367ce553309bbbc6ab7 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 19 Mar 2022 18:01:34 -0400 Subject: [PATCH 03/11] enable and apply clang-format --- src/thermo.cpp | 740 ++++++++++++++++++++++++++----------------------- 1 file changed, 396 insertions(+), 344 deletions(-) diff --git a/src/thermo.cpp b/src/thermo.cpp index 722bb90873..649b45f18b 100644 --- a/src/thermo.cpp +++ b/src/thermo.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -69,23 +68,24 @@ using namespace MathConst; // CUSTOMIZATION: add a new thermo style by adding a constant to the enumerator, // define a new string constant with the keywords and provide default formats. -enum{ ONELINE, MULTILINE, YAMLLINE }; +enum { ONELINE, MULTILINE, YAMLLINE }; // style "one" static constexpr char ONE[] = "step temp epair emol etotal press"; -#define FORMAT_FLOAT_ONE_DEFAULT "%12.8g" -#define FORMAT_INT_ONE_DEFAULT "%10d" +#define FORMAT_FLOAT_ONE_DEFAULT "%12.8g" +#define FORMAT_INT_ONE_DEFAULT "%10d" // style "multi" -static constexpr char MULTI[] = "etotal ke temp pe ebond eangle edihed eimp evdwl ecoul elong press"; -#define FORMAT_FLOAT_MULTI_DEFAULT "%14.4f" -#define FORMAT_INT_MULTI_DEFAULT "%14d" +static constexpr char MULTI[] = + "etotal ke temp pe ebond eangle edihed eimp evdwl ecoul elong press"; +#define FORMAT_FLOAT_MULTI_DEFAULT "%14.4f" +#define FORMAT_INT_MULTI_DEFAULT "%14d" // style "yaml" static constexpr char YAML[] = "step temp ke pe ebond eangle edihed eimp evdwl ecoul elong press"; -#define FORMAT_FLOAT_YAML_DEFAULT "%.15g" -#define FORMAT_INT_YAML_DEFAULT "%d" +#define FORMAT_FLOAT_YAML_DEFAULT "%.15g" +#define FORMAT_INT_YAML_DEFAULT "%d" #define FORMAT_MULTI_HEADER "------------ Step {:14} ----- CPU = {:12.7g} (sec) -------------" -enum{ SCALAR, VECTOR, ARRAY }; +enum { SCALAR, VECTOR, ARRAY }; static constexpr char id_temp[] = "thermo_temp"; static constexpr char id_press[] = "thermo_press"; @@ -97,8 +97,8 @@ static char fmtbuf[512]; /* ---------------------------------------------------------------------- */ Thermo::Thermo(LAMMPS *_lmp, int narg, char **arg) : - Pointers(_lmp), style(nullptr), vtype(nullptr), field2index(nullptr), argindex1(nullptr), - argindex2(nullptr), temperature(nullptr), pressure(nullptr), pe(nullptr) + Pointers(_lmp), style(nullptr), vtype(nullptr), field2index(nullptr), argindex1(nullptr), + argindex2(nullptr), temperature(nullptr), pressure(nullptr), pe(nullptr) { style = utils::strdup(arg[0]); @@ -116,24 +116,24 @@ Thermo::Thermo(LAMMPS *_lmp, int narg, char **arg) : // CUSTOMIZATION: add a new thermo style by adding it to the if statement // set line string with default keywords if not custom style. - if (strcmp(style,"one") == 0) { + if (strcmp(style, "one") == 0) { line = ONE; lineflag = ONELINE; - } else if (strcmp(style,"multi") == 0) { + } else if (strcmp(style, "multi") == 0) { line = MULTI; lineflag = MULTILINE; - } else if (strcmp(style,"yaml") == 0) { + } else if (strcmp(style, "yaml") == 0) { line = YAML; lineflag = YAMLLINE; - } else if (strcmp(style,"custom") == 0) { - if (narg == 1) error->all(FLERR,"Illegal thermo style custom command"); + } else if (strcmp(style, "custom") == 0) { + if (narg == 1) error->all(FLERR, "Illegal thermo style custom command"); // expand args if any have wildcard character "*" int expand = 0; char **earg; - int nvalues = utils::expand_args(FLERR,narg-1,&arg[1],0,earg,lmp); + int nvalues = utils::expand_args(FLERR, narg - 1, &arg[1], 0, earg, lmp); if (earg != &arg[1]) expand = 1; line.clear(); @@ -149,7 +149,8 @@ Thermo::Thermo(LAMMPS *_lmp, int narg, char **arg) : memory->sfree(earg); } - } else error->all(FLERR,"Illegal thermo style command"); + } else + error->all(FLERR, "Illegal thermo style command"); index_temp = index_press_scalar = index_press_vector = index_pe = -1; @@ -176,16 +177,19 @@ void Thermo::init() { // set normvalue to default setting unless user has specified it - if (normuserflag) normvalue = normuser; - else if (strcmp(update->unit_style,"lj") == 0) normvalue = 1; - else normvalue = 0; + if (normuserflag) + normvalue = normuser; + else if (strcmp(update->unit_style, "lj") == 0) + normvalue = 1; + else + normvalue = 0; // add Volume field if volume changes and not style = custom // this check must come after domain init, so box_change is set nfield = nfield_initial; - if (domain->box_change && strcmp(style,"custom") != 0) - addfield("Volume",&Thermo::compute_vol,FLOAT); + if (domain->box_change && strcmp(style, "custom") != 0) + addfield("Volume", &Thermo::compute_vol, FLOAT); // set format string for each field // include keyword if lineflag = MULTILINE @@ -207,13 +211,19 @@ void Thermo::init() if ((lineflag == YAMLLINE) && (i == 0)) format[i] += " - ["; if (format_line) format_line_user_def = format_line->next_string(); - if (format_column_user[i].size()) format_this = format_column_user[i]; + if (format_column_user[i].size()) + format_this = format_column_user[i]; else if (vtype[i] == FLOAT) { - if (format_float_user.size()) format_this = format_float_user; - else if (format_line_user_def.size()) format_this = format_line_user_def; - else if (lineflag == ONELINE) format_this = FORMAT_FLOAT_ONE_DEFAULT; - else if (lineflag == MULTILINE) format_this = FORMAT_FLOAT_MULTI_DEFAULT; - else if (lineflag == YAMLLINE) format_this = FORMAT_FLOAT_YAML_DEFAULT; + if (format_float_user.size()) + format_this = format_float_user; + else if (format_line_user_def.size()) + format_this = format_line_user_def; + else if (lineflag == ONELINE) + format_this = FORMAT_FLOAT_ONE_DEFAULT; + else if (lineflag == MULTILINE) + format_this = FORMAT_FLOAT_MULTI_DEFAULT; + else if (lineflag == YAMLLINE) + format_this = FORMAT_FLOAT_YAML_DEFAULT; } else if ((vtype[i] == INT) || (vtype[i] == BIGINT)) { if (format_int_user.size()) { if (vtype[i] == INT) @@ -223,9 +233,12 @@ void Thermo::init() } else if (format_line_user_def.size()) { format_this = format_line_user_def; } else { - if (lineflag == ONELINE) format_this = FORMAT_INT_ONE_DEFAULT; - else if (lineflag == MULTILINE) format_this = FORMAT_INT_MULTI_DEFAULT; - else format_this = FORMAT_INT_YAML_DEFAULT; + if (lineflag == ONELINE) + format_this = FORMAT_INT_ONE_DEFAULT; + else if (lineflag == MULTILINE) + format_this = FORMAT_INT_MULTI_DEFAULT; + else + format_this = FORMAT_INT_YAML_DEFAULT; if (vtype[i] == BIGINT) { // replace "d" in int format with bigint format specifier auto found = format_this.find('%'); @@ -235,16 +248,22 @@ void Thermo::init() } } - if (lineflag == ONELINE) format[i] += format_this + " "; - else if (lineflag == YAMLLINE) format[i] += format_this + ", "; - else format[i] += fmt::format("{:<8} = {} ",keyword[i],format_this); + if (lineflag == ONELINE) + format[i] += format_this + " "; + else if (lineflag == YAMLLINE) + format[i] += format_this + ", "; + else + format[i] += fmt::format("{:<8} = {} ", keyword[i], format_this); } // chop off trailing blank or add closing bracket if needed and then add newline - if (lineflag == ONELINE) format[nfield-1].resize(format[nfield-1].size()-1); - else if (lineflag == MULTILINE) format[nfield-1].resize(format[nfield-1].size()-1); - else if (lineflag == YAMLLINE) format[nfield-1] += ']'; - format[nfield-1] += '\n'; + if (lineflag == ONELINE) + format[nfield - 1].resize(format[nfield - 1].size() - 1); + else if (lineflag == MULTILINE) + format[nfield - 1].resize(format[nfield - 1].size() - 1); + else if (lineflag == YAMLLINE) + format[nfield - 1] += ']'; + format[nfield - 1] += '\n'; delete format_line; @@ -252,7 +271,7 @@ void Thermo::init() for (int i = 0; i < ncompute; i++) { computes[i] = modify->get_compute_by_id(id_compute[i]); - if (!computes[i]) error->all(FLERR,"Could not find thermo compute with ID {}",id_compute[i]); + if (!computes[i]) error->all(FLERR, "Could not find thermo compute with ID {}", id_compute[i]); } // find current ptr for each Fix ID @@ -260,17 +279,17 @@ void Thermo::init() for (int i = 0; i < nfix; i++) { fixes[i] = modify->get_fix_by_id(id_fix[i]); - if (!fixes[i]) error->all(FLERR,"Could not find thermo fix ID {}",id_fix[i]); + if (!fixes[i]) error->all(FLERR, "Could not find thermo fix ID {}", id_fix[i]); if (output->thermo_every % fixes[i]->global_freq) - error->all(FLERR,"Thermo and fix {} not computed at compatible times",id_fix[i]); + error->all(FLERR, "Thermo and fix {} not computed at compatible times", id_fix[i]); } // find current ptr for each Variable ID for (int i = 0; i < nvariable; i++) { variables[i] = input->variable->find(id_variable[i]); - if (variables[i] < 0) error->all(FLERR,"Could not find thermo variable {}",id_variable[i]); + if (variables[i] < 0) error->all(FLERR, "Could not find thermo variable {}", id_variable[i]); } // set ptrs to keyword-specific Compute objects @@ -316,18 +335,18 @@ void Thermo::header() } } if (lineflag == YAMLLINE) - hdr += "]\ndata:"; + hdr += "]\ndata:"; else - hdr.resize(hdr.size()-1); // chop off trailing blank + hdr.resize(hdr.size() - 1); // chop off trailing blank - if (comm->me == 0) utils::logmesg(lmp,hdr+"\n"); + if (comm->me == 0) utils::logmesg(lmp, hdr + "\n"); } /* ---------------------------------------------------------------------- */ void Thermo::footer() { - if (lineflag == YAMLLINE) utils::logmesg(lmp,"...\n"); + if (lineflag == YAMLLINE) utils::logmesg(lmp, "...\n"); } /* ---------------------------------------------------------------------- */ @@ -343,8 +362,10 @@ void Thermo::compute(int flag) // turn off normflag if natoms = 0 to avoid divide by 0 natoms = atom->natoms = lost_check(); - if (natoms == 0) normflag = 0; - else normflag = normvalue; + if (natoms == 0) + normflag = 0; + else + normflag = normvalue; // invoke Compute methods needed for thermo keywords @@ -371,8 +392,10 @@ void Thermo::compute(int flag) line.clear(); if (lineflag == MULTILINE) { double cpu; - if (flag) cpu = timer->elapsed(Timer::TOTAL); - else cpu = 0.0; + if (flag) + cpu = timer->elapsed(Timer::TOTAL); + else + cpu = 0.0; line += fmt::format(FORMAT_MULTI_HEADER, ntimestep, cpu); } @@ -395,7 +418,7 @@ void Thermo::compute(int flag) // print line to screen and logfile if (comm->me == 0) { - utils::logmesg(lmp,line); + utils::logmesg(lmp, line); if (flushflag) utils::flush_buffers(lmp); } @@ -424,41 +447,39 @@ bigint Thermo::lost_check() { // ntotal = current # of atoms, and Error class warnings - bigint nlocal[2], ntotal[2] = {0,0}; + bigint nlocal[2], ntotal[2] = {0, 0}; nlocal[0] = atom->nlocal; nlocal[1] = error->get_numwarn(); - MPI_Allreduce(nlocal,ntotal,2,MPI_LMP_BIGINT,MPI_SUM,world); - if (ntotal[0] < 0) - error->all(FLERR,"Too many total atoms"); + MPI_Allreduce(nlocal, ntotal, 2, MPI_LMP_BIGINT, MPI_SUM, world); + if (ntotal[0] < 0) error->all(FLERR, "Too many total atoms"); // print notification, if future warnings will be ignored bigint maxwarn = error->get_maxwarn(); if ((maxwarn > 0) && (warnbefore == 0) && (ntotal[1] > maxwarn)) { warnbefore = 1; if (comm->me == 0) - error->message(FLERR,"WARNING: Too many warnings: {} vs {}. All " - "future warnings will be suppressed",ntotal[1],maxwarn); + error->message(FLERR, + "WARNING: Too many warnings: {} vs {}. All future warnings will be suppressed", + ntotal[1], maxwarn); } - error->set_allwarn(MIN(MAXSMALLINT,ntotal[1])); + error->set_allwarn(MIN(MAXSMALLINT, ntotal[1])); // no lost atoms, nothing else to do. if (ntotal[0] == atom->natoms) return ntotal[0]; // if not checking or already warned, just return if (lostflag == Thermo::IGNORE) return ntotal[0]; - if (lostflag == Thermo::WARN && lostbefore == 1) { - return ntotal[0]; - } + if (lostflag == Thermo::WARN && lostbefore == 1) { return ntotal[0]; } // error message if (lostflag == Thermo::ERROR) - error->all(FLERR,"Lost atoms: original {} current {}",atom->natoms,ntotal[0]); + error->all(FLERR, "Lost atoms: original {} current {}", atom->natoms, ntotal[0]); // warning message if (comm->me == 0) - error->warning(FLERR,"Lost atoms: original {} current {}",atom->natoms,ntotal[0]); + error->warning(FLERR, "Lost atoms: original {} current {}", atom->natoms, ntotal[0]); // reset total atom count @@ -473,26 +494,26 @@ bigint Thermo::lost_check() void Thermo::modify_params(int narg, char **arg) { - if (narg == 0) error->all(FLERR,"Illegal thermo_modify command"); + if (narg == 0) error->all(FLERR, "Illegal thermo_modify command"); modified = 1; int iarg = 0; while (iarg < narg) { - if (strcmp(arg[iarg],"temp") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal thermo_modify command"); - if (index_temp < 0) error->all(FLERR,"Thermo style does not use temp"); + if (strcmp(arg[iarg], "temp") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal thermo_modify command"); + if (index_temp < 0) error->all(FLERR, "Thermo style does not use temp"); delete[] id_compute[index_temp]; - id_compute[index_temp] = utils::strdup(arg[iarg+1]); + id_compute[index_temp] = utils::strdup(arg[iarg + 1]); - temperature = modify->get_compute_by_id(arg[iarg+1]); + temperature = modify->get_compute_by_id(arg[iarg + 1]); if (!temperature) - error->all(FLERR,"Could not find thermo_modify temperature compute {}",arg[iarg+1]); + error->all(FLERR, "Could not find thermo_modify temperature compute {}", arg[iarg + 1]); if (temperature->tempflag == 0) - error->all(FLERR,"Thermo_modify compute {} does not compute temperature",arg[iarg+1]); + error->all(FLERR, "Thermo_modify compute {} does not compute temperature", arg[iarg + 1]); if (temperature->igroup != 0 && comm->me == 0) - error->warning(FLERR,"Temperature for thermo pressure is not for group all"); + error->warning(FLERR, "Temperature for thermo pressure is not for group all"); // reset id_temp of pressure to new temperature ID // either pressure currently being used by thermo or "thermo_press" @@ -500,126 +521,144 @@ void Thermo::modify_params(int narg, char **arg) Compute *pcompute; if (index_press_scalar >= 0) { pcompute = modify->get_compute_by_id(id_compute[index_press_scalar]); - if (!pcompute) error->all(FLERR, "Pressure compute {} for thermo output does not exist", - id_compute[index_press_scalar]); + if (!pcompute) + error->all(FLERR, "Pressure compute {} for thermo output does not exist", + id_compute[index_press_scalar]); } else if (index_press_vector >= 0) { pcompute = modify->get_compute_by_id(id_compute[index_press_vector]); - if (!pcompute) error->all(FLERR,"Pressure compute {} for thermo output does not exist", - id_compute[index_press_vector]); - } else pcompute = modify->get_compute_by_id("thermo_press"); + if (!pcompute) + error->all(FLERR, "Pressure compute {} for thermo output does not exist", + id_compute[index_press_vector]); + } else + pcompute = modify->get_compute_by_id("thermo_press"); - pcompute->reset_extra_compute_fix(arg[iarg+1]); + pcompute->reset_extra_compute_fix(arg[iarg + 1]); iarg += 2; - } else if (strcmp(arg[iarg],"press") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal thermo_modify command"); + } else if (strcmp(arg[iarg], "press") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal thermo_modify command"); if (index_press_scalar < 0 && index_press_vector < 0) - error->all(FLERR,"Thermo style does not use press"); + error->all(FLERR, "Thermo style does not use press"); if (index_press_scalar >= 0) { delete[] id_compute[index_press_scalar]; - id_compute[index_press_scalar] = utils::strdup(arg[iarg+1]); + id_compute[index_press_scalar] = utils::strdup(arg[iarg + 1]); } if (index_press_vector >= 0) { delete[] id_compute[index_press_vector]; - id_compute[index_press_vector] = utils::strdup(arg[iarg+1]); + id_compute[index_press_vector] = utils::strdup(arg[iarg + 1]); } - pressure = modify->get_compute_by_id(arg[iarg+1]); + pressure = modify->get_compute_by_id(arg[iarg + 1]); if (!pressure) - error->all(FLERR,"Could not find thermo_modify pressure compute {}",arg[iarg+1]); + error->all(FLERR, "Could not find thermo_modify pressure compute {}", arg[iarg + 1]); if (pressure->pressflag == 0) - error->all(FLERR,"Thermo_modify compute {} does not compute pressure",arg[iarg+1]); + error->all(FLERR, "Thermo_modify compute {} does not compute pressure", arg[iarg + 1]); iarg += 2; - } else if (strcmp(arg[iarg],"lost") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal thermo_modify command"); - if (strcmp(arg[iarg+1],"ignore") == 0) lostflag = Thermo::IGNORE; - else if (strcmp(arg[iarg+1],"warn") == 0) lostflag = Thermo::WARN; - else if (strcmp(arg[iarg+1],"error") == 0) lostflag = Thermo::ERROR; - else error->all(FLERR,"Illegal thermo_modify command"); + } else if (strcmp(arg[iarg], "lost") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal thermo_modify command"); + if (strcmp(arg[iarg + 1], "ignore") == 0) + lostflag = Thermo::IGNORE; + else if (strcmp(arg[iarg + 1], "warn") == 0) + lostflag = Thermo::WARN; + else if (strcmp(arg[iarg + 1], "error") == 0) + lostflag = Thermo::ERROR; + else + error->all(FLERR, "Illegal thermo_modify command"); iarg += 2; - } else if (strcmp(arg[iarg],"lost/bond") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal thermo_modify command"); - if (strcmp(arg[iarg+1],"ignore") == 0) lostbond = Thermo::IGNORE; - else if (strcmp(arg[iarg+1],"warn") == 0) lostbond = Thermo::WARN; - else if (strcmp(arg[iarg+1],"error") == 0) lostbond = Thermo::ERROR; - else error->all(FLERR,"Illegal thermo_modify command"); + } else if (strcmp(arg[iarg], "lost/bond") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal thermo_modify command"); + if (strcmp(arg[iarg + 1], "ignore") == 0) + lostbond = Thermo::IGNORE; + else if (strcmp(arg[iarg + 1], "warn") == 0) + lostbond = Thermo::WARN; + else if (strcmp(arg[iarg + 1], "error") == 0) + lostbond = Thermo::ERROR; + else + error->all(FLERR, "Illegal thermo_modify command"); iarg += 2; - } else if (strcmp(arg[iarg],"warn") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal thermo_modify command"); - if (strcmp(arg[iarg+1],"ignore") == 0) error->set_maxwarn(-1); - else if (strcmp(arg[iarg+1],"always") == 0) error->set_maxwarn(0); - else if (strcmp(arg[iarg+1],"reset") == 0) { + } else if (strcmp(arg[iarg], "warn") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal thermo_modify command"); + if (strcmp(arg[iarg + 1], "ignore") == 0) + error->set_maxwarn(-1); + else if (strcmp(arg[iarg + 1], "always") == 0) + error->set_maxwarn(0); + else if (strcmp(arg[iarg + 1], "reset") == 0) { error->set_numwarn(0); warnbefore = 0; - } else if (strcmp(arg[iarg+1],"default") == 0) { + } else if (strcmp(arg[iarg + 1], "default") == 0) { warnbefore = 0; error->set_numwarn(0); error->set_maxwarn(100); - } else error->set_maxwarn(utils::inumeric(FLERR,arg[iarg+1],false,lmp)); + } else + error->set_maxwarn(utils::inumeric(FLERR, arg[iarg + 1], false, lmp)); iarg += 2; - } else if (strcmp(arg[iarg],"norm") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal thermo_modify command"); + } else if (strcmp(arg[iarg], "norm") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal thermo_modify command"); normuserflag = 1; - normuser = utils::logical(FLERR,arg[iarg+1],false,lmp); + normuser = utils::logical(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else if (strcmp(arg[iarg],"flush") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal thermo_modify command"); - flushflag = utils::logical(FLERR,arg[iarg+1],false,lmp); + } else if (strcmp(arg[iarg], "flush") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal thermo_modify command"); + flushflag = utils::logical(FLERR, arg[iarg + 1], false, lmp); iarg += 2; - } else if (strcmp(arg[iarg],"line") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal thermo_modify command"); - if (strcmp(arg[iarg+1],"one") == 0) lineflag = ONELINE; - else if (strcmp(arg[iarg+1],"multi") == 0) lineflag = MULTILINE; - else if (strcmp(arg[iarg+1],"yaml") == 0) lineflag = YAMLLINE; - else error->all(FLERR,"Illegal thermo_modify command"); + } else if (strcmp(arg[iarg], "line") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal thermo_modify command"); + if (strcmp(arg[iarg + 1], "one") == 0) + lineflag = ONELINE; + else if (strcmp(arg[iarg + 1], "multi") == 0) + lineflag = MULTILINE; + else if (strcmp(arg[iarg + 1], "yaml") == 0) + lineflag = YAMLLINE; + else + error->all(FLERR, "Illegal thermo_modify command"); iarg += 2; - } else if (strcmp(arg[iarg],"format") == 0) { - if (iarg+2 > narg) error->all(FLERR,"Illegal thermo_modify command"); + } else if (strcmp(arg[iarg], "format") == 0) { + if (iarg + 2 > narg) error->all(FLERR, "Illegal thermo_modify command"); - if (strcmp(arg[iarg+1],"none") == 0) { + if (strcmp(arg[iarg + 1], "none") == 0) { format_line_user.clear(); format_int_user.clear(); format_bigint_user.clear(); format_float_user.clear(); - for (int i = 0; i < nfield_initial+1; ++i) - format_column_user[i].clear(); + for (int i = 0; i < nfield_initial + 1; ++i) format_column_user[i].clear(); iarg += 2; continue; } - if (iarg+3 > narg) error->all(FLERR,"Illegal thermo_modify command"); + if (iarg + 3 > narg) error->all(FLERR, "Illegal thermo_modify command"); - if (strcmp(arg[iarg+1],"line") == 0) { - format_line_user = arg[iarg+2]; - } else if (strcmp(arg[iarg+1],"int") == 0) { - format_int_user = arg[iarg+2]; + if (strcmp(arg[iarg + 1], "line") == 0) { + format_line_user = arg[iarg + 2]; + } else if (strcmp(arg[iarg + 1], "int") == 0) { + format_int_user = arg[iarg + 2]; // replace "d" in format_int_user with bigint format specifier auto found = format_int_user.find('%'); found = format_int_user.find('d', found); if (found == std::string::npos) - error->all(FLERR,"Thermo_modify int format does not contain a d conversion character"); - format_bigint_user = format_int_user.replace(found, 1, std::string(BIGINT_FORMAT).substr(1)); - } else if (strcmp(arg[iarg+1],"float") == 0) { - format_float_user = arg[iarg+2]; + error->all(FLERR, "Thermo_modify int format does not contain a d conversion character"); + format_bigint_user = + format_int_user.replace(found, 1, std::string(BIGINT_FORMAT).substr(1)); + } else if (strcmp(arg[iarg + 1], "float") == 0) { + format_float_user = arg[iarg + 2]; } else { - int i = utils::inumeric(FLERR,arg[iarg+1],false,lmp) - 1; - if (i < 0 || i >= nfield_initial+1) - error->all(FLERR,"Illegal thermo_modify command"); - format_column_user[i] = arg[iarg+2]; + int i = utils::inumeric(FLERR, arg[iarg + 1], false, lmp) - 1; + if (i < 0 || i >= nfield_initial + 1) error->all(FLERR, "Illegal thermo_modify command"); + format_column_user[i] = arg[iarg + 2]; } iarg += 3; - } else error->all(FLERR,"Illegal thermo_modify command"); + } else + error->all(FLERR, "Illegal thermo_modify command"); } } @@ -652,16 +691,16 @@ void Thermo::allocate() // factor of 3 is max number of computes a single field can add ncompute = 0; - id_compute = new char*[3*n]; - compute_which = new int[3*n]; - computes = new Compute*[3*n]; + id_compute = new char *[3 * n]; + compute_which = new int[3 * n]; + computes = new Compute *[3 * n]; nfix = 0; - id_fix = new char*[n]; - fixes = new Fix*[n]; + id_fix = new char *[n]; + fixes = new Fix *[n]; nvariable = 0; - id_variable = new char*[n]; + id_variable = new char *[n]; variables = new int[n]; } @@ -708,179 +747,179 @@ void Thermo::parse_fields(const std::string &str) std::string word = keywords.next_string(); if (word == "step") { - addfield("Step",&Thermo::compute_step,BIGINT); + addfield("Step", &Thermo::compute_step, BIGINT); } else if (word == "elapsed") { - addfield("Elapsed",&Thermo::compute_elapsed,BIGINT); + addfield("Elapsed", &Thermo::compute_elapsed, BIGINT); } else if (word == "elaplong") { - addfield("Elaplong",&Thermo::compute_elapsed_long,BIGINT); + addfield("Elaplong", &Thermo::compute_elapsed_long, BIGINT); } else if (word == "dt") { - addfield("Dt",&Thermo::compute_dt,FLOAT); + addfield("Dt", &Thermo::compute_dt, FLOAT); } else if (word == "time") { - addfield("Time",&Thermo::compute_time,FLOAT); + addfield("Time", &Thermo::compute_time, FLOAT); } else if (word == "cpu") { - addfield("CPU",&Thermo::compute_cpu,FLOAT); + addfield("CPU", &Thermo::compute_cpu, FLOAT); } else if (word == "tpcpu") { - addfield("T/CPU",&Thermo::compute_tpcpu,FLOAT); + addfield("T/CPU", &Thermo::compute_tpcpu, FLOAT); } else if (word == "spcpu") { - addfield("S/CPU",&Thermo::compute_spcpu,FLOAT); + addfield("S/CPU", &Thermo::compute_spcpu, FLOAT); } else if (word == "cpuremain") { - addfield("CPULeft",&Thermo::compute_cpuremain,FLOAT); + addfield("CPULeft", &Thermo::compute_cpuremain, FLOAT); } else if (word == "part") { - addfield("Part",&Thermo::compute_part,INT); + addfield("Part", &Thermo::compute_part, INT); } else if (word == "timeremain") { - addfield("TimeoutLeft",&Thermo::compute_timeremain,FLOAT); + addfield("TimeoutLeft", &Thermo::compute_timeremain, FLOAT); } else if (word == "atoms") { - addfield("Atoms",&Thermo::compute_atoms,BIGINT); + addfield("Atoms", &Thermo::compute_atoms, BIGINT); } else if (word == "temp") { - addfield("Temp",&Thermo::compute_temp,FLOAT); - index_temp = add_compute(id_temp,SCALAR); + addfield("Temp", &Thermo::compute_temp, FLOAT); + index_temp = add_compute(id_temp, SCALAR); } else if (word == "press") { - addfield("Press",&Thermo::compute_press,FLOAT); - index_press_scalar = add_compute(id_press,SCALAR); + addfield("Press", &Thermo::compute_press, FLOAT); + index_press_scalar = add_compute(id_press, SCALAR); } else if (word == "pe") { - addfield("PotEng",&Thermo::compute_pe,FLOAT); - index_pe = add_compute(id_pe,SCALAR); + addfield("PotEng", &Thermo::compute_pe, FLOAT); + index_pe = add_compute(id_pe, SCALAR); } else if (word == "ke") { - addfield("KinEng",&Thermo::compute_ke,FLOAT); - index_temp = add_compute(id_temp,SCALAR); + addfield("KinEng", &Thermo::compute_ke, FLOAT); + index_temp = add_compute(id_temp, SCALAR); } else if (word == "etotal") { - addfield("TotEng",&Thermo::compute_etotal,FLOAT); - index_temp = add_compute(id_temp,SCALAR); - index_pe = add_compute(id_pe,SCALAR); + addfield("TotEng", &Thermo::compute_etotal, FLOAT); + index_temp = add_compute(id_temp, SCALAR); + index_pe = add_compute(id_pe, SCALAR); } else if (word == "evdwl") { - addfield("E_vdwl",&Thermo::compute_evdwl,FLOAT); - index_pe = add_compute(id_pe,SCALAR); + addfield("E_vdwl", &Thermo::compute_evdwl, FLOAT); + index_pe = add_compute(id_pe, SCALAR); } else if (word == "ecoul") { - addfield("E_coul",&Thermo::compute_ecoul,FLOAT); - index_pe = add_compute(id_pe,SCALAR); + addfield("E_coul", &Thermo::compute_ecoul, FLOAT); + index_pe = add_compute(id_pe, SCALAR); } else if (word == "epair") { - addfield("E_pair",&Thermo::compute_epair,FLOAT); - index_pe = add_compute(id_pe,SCALAR); + addfield("E_pair", &Thermo::compute_epair, FLOAT); + index_pe = add_compute(id_pe, SCALAR); } else if (word == "ebond") { - addfield("E_bond",&Thermo::compute_ebond,FLOAT); - index_pe = add_compute(id_pe,SCALAR); + addfield("E_bond", &Thermo::compute_ebond, FLOAT); + index_pe = add_compute(id_pe, SCALAR); } else if (word == "eangle") { - addfield("E_angle",&Thermo::compute_eangle,FLOAT); - index_pe = add_compute(id_pe,SCALAR); + addfield("E_angle", &Thermo::compute_eangle, FLOAT); + index_pe = add_compute(id_pe, SCALAR); } else if (word == "edihed") { - addfield("E_dihed",&Thermo::compute_edihed,FLOAT); - index_pe = add_compute(id_pe,SCALAR); + addfield("E_dihed", &Thermo::compute_edihed, FLOAT); + index_pe = add_compute(id_pe, SCALAR); } else if (word == "eimp") { - addfield("E_impro",&Thermo::compute_eimp,FLOAT); - index_pe = add_compute(id_pe,SCALAR); + addfield("E_impro", &Thermo::compute_eimp, FLOAT); + index_pe = add_compute(id_pe, SCALAR); } else if (word == "emol") { - addfield("E_mol",&Thermo::compute_emol,FLOAT); - index_pe = add_compute(id_pe,SCALAR); + addfield("E_mol", &Thermo::compute_emol, FLOAT); + index_pe = add_compute(id_pe, SCALAR); } else if (word == "elong") { - addfield("E_long",&Thermo::compute_elong,FLOAT); - index_pe = add_compute(id_pe,SCALAR); + addfield("E_long", &Thermo::compute_elong, FLOAT); + index_pe = add_compute(id_pe, SCALAR); } else if (word == "etail") { - addfield("E_tail",&Thermo::compute_etail,FLOAT); - index_pe = add_compute(id_pe,SCALAR); + addfield("E_tail", &Thermo::compute_etail, FLOAT); + index_pe = add_compute(id_pe, SCALAR); } else if (word == "enthalpy") { - addfield("Enthalpy",&Thermo::compute_enthalpy,FLOAT); - index_temp = add_compute(id_temp,SCALAR); - index_press_scalar = add_compute(id_press,SCALAR); - index_pe = add_compute(id_pe,SCALAR); + addfield("Enthalpy", &Thermo::compute_enthalpy, FLOAT); + index_temp = add_compute(id_temp, SCALAR); + index_press_scalar = add_compute(id_press, SCALAR); + index_pe = add_compute(id_pe, SCALAR); } else if (word == "ecouple") { - addfield("Ecouple",&Thermo::compute_ecouple,FLOAT); - index_pe = add_compute(id_pe,SCALAR); + addfield("Ecouple", &Thermo::compute_ecouple, FLOAT); + index_pe = add_compute(id_pe, SCALAR); } else if (word == "econserve") { - addfield("Econserve",&Thermo::compute_econserve,FLOAT); - index_temp = add_compute(id_temp,SCALAR); - index_pe = add_compute(id_pe,SCALAR); + addfield("Econserve", &Thermo::compute_econserve, FLOAT); + index_temp = add_compute(id_temp, SCALAR); + index_pe = add_compute(id_pe, SCALAR); } else if (word == "vol") { - addfield("Volume",&Thermo::compute_vol,FLOAT); + addfield("Volume", &Thermo::compute_vol, FLOAT); } else if (word == "density") { - addfield("Density",&Thermo::compute_density,FLOAT); + addfield("Density", &Thermo::compute_density, FLOAT); } else if (word == "lx") { - addfield("Lx",&Thermo::compute_lx,FLOAT); + addfield("Lx", &Thermo::compute_lx, FLOAT); } else if (word == "ly") { - addfield("Ly",&Thermo::compute_ly,FLOAT); + addfield("Ly", &Thermo::compute_ly, FLOAT); } else if (word == "lz") { - addfield("Lz",&Thermo::compute_lz,FLOAT); + addfield("Lz", &Thermo::compute_lz, FLOAT); } else if (word == "xlo") { - addfield("Xlo",&Thermo::compute_xlo,FLOAT); + addfield("Xlo", &Thermo::compute_xlo, FLOAT); } else if (word == "xhi") { - addfield("Xhi",&Thermo::compute_xhi,FLOAT); + addfield("Xhi", &Thermo::compute_xhi, FLOAT); } else if (word == "ylo") { - addfield("Ylo",&Thermo::compute_ylo,FLOAT); + addfield("Ylo", &Thermo::compute_ylo, FLOAT); } else if (word == "yhi") { - addfield("Yhi",&Thermo::compute_yhi,FLOAT); + addfield("Yhi", &Thermo::compute_yhi, FLOAT); } else if (word == "zlo") { - addfield("Zlo",&Thermo::compute_zlo,FLOAT); + addfield("Zlo", &Thermo::compute_zlo, FLOAT); } else if (word == "zhi") { - addfield("Zhi",&Thermo::compute_zhi,FLOAT); + addfield("Zhi", &Thermo::compute_zhi, FLOAT); } else if (word == "xy") { - addfield("Xy",&Thermo::compute_xy,FLOAT); + addfield("Xy", &Thermo::compute_xy, FLOAT); } else if (word == "xz") { - addfield("Xz",&Thermo::compute_xz,FLOAT); + addfield("Xz", &Thermo::compute_xz, FLOAT); } else if (word == "yz") { - addfield("Yz",&Thermo::compute_yz,FLOAT); + addfield("Yz", &Thermo::compute_yz, FLOAT); } else if (word == "xlat") { - addfield("Xlat",&Thermo::compute_xlat,FLOAT); + addfield("Xlat", &Thermo::compute_xlat, FLOAT); } else if (word == "ylat") { - addfield("Ylat",&Thermo::compute_ylat,FLOAT); + addfield("Ylat", &Thermo::compute_ylat, FLOAT); } else if (word == "zlat") { - addfield("Zlat",&Thermo::compute_zlat,FLOAT); + addfield("Zlat", &Thermo::compute_zlat, FLOAT); } else if (word == "bonds") { - addfield("Bonds",&Thermo::compute_bonds,BIGINT); + addfield("Bonds", &Thermo::compute_bonds, BIGINT); } else if (word == "angles") { - addfield("Angles",&Thermo::compute_angles,BIGINT); + addfield("Angles", &Thermo::compute_angles, BIGINT); } else if (word == "dihedrals") { - addfield("Diheds",&Thermo::compute_dihedrals,BIGINT); + addfield("Diheds", &Thermo::compute_dihedrals, BIGINT); } else if (word == "impropers") { - addfield("Impros",&Thermo::compute_impropers,BIGINT); + addfield("Impros", &Thermo::compute_impropers, BIGINT); } else if (word == "pxx") { - addfield("Pxx",&Thermo::compute_pxx,FLOAT); - index_press_vector = add_compute(id_press,VECTOR); + addfield("Pxx", &Thermo::compute_pxx, FLOAT); + index_press_vector = add_compute(id_press, VECTOR); } else if (word == "pyy") { - addfield("Pyy",&Thermo::compute_pyy,FLOAT); - index_press_vector = add_compute(id_press,VECTOR); + addfield("Pyy", &Thermo::compute_pyy, FLOAT); + index_press_vector = add_compute(id_press, VECTOR); } else if (word == "pzz") { - addfield("Pzz",&Thermo::compute_pzz,FLOAT); - index_press_vector = add_compute(id_press,VECTOR); + addfield("Pzz", &Thermo::compute_pzz, FLOAT); + index_press_vector = add_compute(id_press, VECTOR); } else if (word == "pxy") { - addfield("Pxy",&Thermo::compute_pxy,FLOAT); - index_press_vector = add_compute(id_press,VECTOR); + addfield("Pxy", &Thermo::compute_pxy, FLOAT); + index_press_vector = add_compute(id_press, VECTOR); } else if (word == "pxz") { - addfield("Pxz",&Thermo::compute_pxz,FLOAT); - index_press_vector = add_compute(id_press,VECTOR); + addfield("Pxz", &Thermo::compute_pxz, FLOAT); + index_press_vector = add_compute(id_press, VECTOR); } else if (word == "pyz") { - addfield("Pyz",&Thermo::compute_pyz,FLOAT); - index_press_vector = add_compute(id_press,VECTOR); + addfield("Pyz", &Thermo::compute_pyz, FLOAT); + index_press_vector = add_compute(id_press, VECTOR); } else if (word == "fmax") { - addfield("Fmax",&Thermo::compute_fmax,FLOAT); + addfield("Fmax", &Thermo::compute_fmax, FLOAT); } else if (word == "fnorm") { - addfield("Fnorm",&Thermo::compute_fnorm,FLOAT); + addfield("Fnorm", &Thermo::compute_fnorm, FLOAT); } else if (word == "nbuild") { - addfield("Nbuild",&Thermo::compute_nbuild,BIGINT); + addfield("Nbuild", &Thermo::compute_nbuild, BIGINT); } else if (word == "ndanger") { - addfield("Ndanger",&Thermo::compute_ndanger,BIGINT); + addfield("Ndanger", &Thermo::compute_ndanger, BIGINT); } else if (word == "cella") { - addfield("Cella",&Thermo::compute_cella,FLOAT); + addfield("Cella", &Thermo::compute_cella, FLOAT); } else if (word == "cellb") { - addfield("Cellb",&Thermo::compute_cellb,FLOAT); + addfield("Cellb", &Thermo::compute_cellb, FLOAT); } else if (word == "cellc") { - addfield("Cellc",&Thermo::compute_cellc,FLOAT); + addfield("Cellc", &Thermo::compute_cellc, FLOAT); } else if (word == "cellalpha") { - addfield("CellAlpha",&Thermo::compute_cellalpha,FLOAT); + addfield("CellAlpha", &Thermo::compute_cellalpha, FLOAT); } else if (word == "cellbeta") { - addfield("CellBeta",&Thermo::compute_cellbeta,FLOAT); + addfield("CellBeta", &Thermo::compute_cellbeta, FLOAT); } else if (word == "cellgamma") { - addfield("CellGamma",&Thermo::compute_cellgamma,FLOAT); + addfield("CellGamma", &Thermo::compute_cellgamma, FLOAT); // compute value = c_ID, fix value = f_ID, variable value = v_ID // count trailing [] and store int arguments @@ -888,10 +927,9 @@ void Thermo::parse_fields(const std::string &str) } else { ArgInfo argi(word); - if ((argi.get_type() == ArgInfo::UNKNOWN) - || (argi.get_type() == ArgInfo::NONE) - || (argi.get_dim() > 2)) - error->all(FLERR,"Unknown keyword '{}' in thermo_style custom command",word); + if ((argi.get_type() == ArgInfo::UNKNOWN) || (argi.get_type() == ArgInfo::NONE) || + (argi.get_dim() > 2)) + error->all(FLERR, "Unknown keyword '{}' in thermo_style custom command", word); // process zero or one or two trailing brackets // argindex1,argindex2 = int inside each bracket pair, 0 if no bracket @@ -902,24 +940,22 @@ void Thermo::parse_fields(const std::string &str) if (argi.get_type() == ArgInfo::COMPUTE) { auto icompute = modify->get_compute_by_id(argi.get_name()); if (!icompute) - error->all(FLERR,"Could not find thermo custom compute ID: {}", argi.get_name()); + error->all(FLERR, "Could not find thermo custom compute ID: {}", argi.get_name()); if (argindex1[nfield] == 0 && icompute->scalar_flag == 0) - error->all(FLERR,"Thermo compute does not compute scalar"); + error->all(FLERR, "Thermo compute does not compute scalar"); if (argindex1[nfield] > 0 && argindex2[nfield] == 0) { if (icompute->vector_flag == 0) - error->all(FLERR,"Thermo compute does not compute vector"); - if (argindex1[nfield] > icompute->size_vector && - icompute->size_vector_variable == 0) - error->all(FLERR,"Thermo compute vector is accessed out-of-range"); + error->all(FLERR, "Thermo compute does not compute vector"); + if (argindex1[nfield] > icompute->size_vector && icompute->size_vector_variable == 0) + error->all(FLERR, "Thermo compute vector is accessed out-of-range"); } if (argindex1[nfield] > 0 && argindex2[nfield] > 0) { - if (icompute->array_flag == 0) - error->all(FLERR,"Thermo compute does not compute array"); + if (icompute->array_flag == 0) error->all(FLERR, "Thermo compute does not compute array"); if (argindex1[nfield] > icompute->size_array_rows && icompute->size_array_rows_variable == 0) - error->all(FLERR,"Thermo compute array is accessed out-of-range"); + error->all(FLERR, "Thermo compute array is accessed out-of-range"); if (argindex2[nfield] > icompute->size_array_cols) - error->all(FLERR,"Thermo compute array is accessed out-of-range"); + error->all(FLERR, "Thermo compute array is accessed out-of-range"); } if (argindex1[nfield] == 0) @@ -932,24 +968,20 @@ void Thermo::parse_fields(const std::string &str) } else if (argi.get_type() == ArgInfo::FIX) { auto ifix = modify->get_fix_by_id(argi.get_name()); - if (!ifix) error->all(FLERR,"Could not find thermo custom fix ID: {}", argi.get_name()); + if (!ifix) error->all(FLERR, "Could not find thermo custom fix ID: {}", argi.get_name()); if (argindex1[nfield] == 0 && ifix->scalar_flag == 0) - error->all(FLERR,"Thermo fix does not compute scalar"); + error->all(FLERR, "Thermo fix does not compute scalar"); if (argindex1[nfield] > 0 && argindex2[nfield] == 0) { - if (ifix->vector_flag == 0) - error->all(FLERR,"Thermo fix does not compute vector"); - if (argindex1[nfield] > ifix->size_vector && - ifix->size_vector_variable == 0) - error->all(FLERR,"Thermo fix vector is accessed out-of-range"); + if (ifix->vector_flag == 0) error->all(FLERR, "Thermo fix does not compute vector"); + if (argindex1[nfield] > ifix->size_vector && ifix->size_vector_variable == 0) + error->all(FLERR, "Thermo fix vector is accessed out-of-range"); } if (argindex1[nfield] > 0 && argindex2[nfield] > 0) { - if (ifix->array_flag == 0) - error->all(FLERR,"Thermo fix does not compute array"); - if (argindex1[nfield] > ifix->size_array_rows && - ifix->size_array_rows_variable == 0) - error->all(FLERR,"Thermo fix array is accessed out-of-range"); + if (ifix->array_flag == 0) error->all(FLERR, "Thermo fix does not compute array"); + if (argindex1[nfield] > ifix->size_array_rows && ifix->size_array_rows_variable == 0) + error->all(FLERR, "Thermo fix array is accessed out-of-range"); if (argindex2[nfield] > ifix->size_array_cols) - error->all(FLERR,"Thermo fix array is accessed out-of-range"); + error->all(FLERR, "Thermo fix array is accessed out-of-range"); } field2index[nfield] = add_fix(argi.get_name()); @@ -958,13 +990,12 @@ void Thermo::parse_fields(const std::string &str) } else if (argi.get_type() == ArgInfo::VARIABLE) { int n = input->variable->find(argi.get_name()); if (n < 0) - error->all(FLERR,"Could not find thermo custom variable name: {}", argi.get_name()); + error->all(FLERR, "Could not find thermo custom variable name: {}", argi.get_name()); if (argindex1[nfield] == 0 && input->variable->equalstyle(n) == 0) - error->all(FLERR,"Thermo custom variable is not equal-style variable"); + error->all(FLERR, "Thermo custom variable is not equal-style variable"); if (argindex1[nfield] && input->variable->vectorstyle(n) == 0) - error->all(FLERR,"Thermo custom variable is not vector-style variable"); - if (argindex2[nfield]) - error->all(FLERR,"Thermo custom variable cannot have two indices"); + error->all(FLERR, "Thermo custom variable is not vector-style variable"); + if (argindex2[nfield]) error->all(FLERR, "Thermo custom variable cannot have two indices"); field2index[nfield] = add_variable(argi.get_name()); addfield(word.c_str(), &Thermo::compute_variable, FLOAT); @@ -995,14 +1026,13 @@ int Thermo::add_compute(const char *id, int which) { int icompute; for (icompute = 0; icompute < ncompute; icompute++) - if ((strcmp(id,id_compute[icompute]) == 0) && - which == compute_which[icompute]) break; + if ((strcmp(id, id_compute[icompute]) == 0) && which == compute_which[icompute]) break; if (icompute < ncompute) return icompute; id_compute[ncompute] = utils::strdup(id); compute_which[ncompute] = which; ncompute++; - return ncompute-1; + return ncompute - 1; } /* ---------------------------------------------------------------------- @@ -1013,7 +1043,7 @@ int Thermo::add_fix(const char *id) { id_fix[nfix] = utils::strdup(id); nfix++; - return nfix-1; + return nfix - 1; } /* ---------------------------------------------------------------------- @@ -1024,7 +1054,8 @@ int Thermo::add_variable(const char *id) { id_variable[nvariable] = utils::strdup(id); nvariable++; - return nvariable-1; + return nvariable - 1; +} /* ---------------------------------------------------------------------- check whether temperature compute is defined, available, and current @@ -1393,18 +1424,23 @@ void Thermo::compute_compute() dvalue = compute->scalar; if (normflag && compute->extscalar) dvalue /= natoms; } else if (compute_which[m] == VECTOR) { - if (compute->size_vector_variable && argindex1[ifield] > - compute->size_vector) dvalue = 0.0; - else dvalue = compute->vector[argindex1[ifield]-1]; + if (compute->size_vector_variable && argindex1[ifield] > compute->size_vector) + dvalue = 0.0; + else + dvalue = compute->vector[argindex1[ifield] - 1]; if (normflag) { - if (compute->extvector == 0) return; - else if (compute->extvector == 1) dvalue /= natoms; - else if (compute->extlist[argindex1[ifield]-1]) dvalue /= natoms; + if (compute->extvector == 0) + return; + else if (compute->extvector == 1) + dvalue /= natoms; + else if (compute->extlist[argindex1[ifield] - 1]) + dvalue /= natoms; } } else { - if (compute->size_array_rows_variable && argindex1[ifield] > - compute->size_array_rows) dvalue = 0.0; - else dvalue = compute->array[argindex1[ifield]-1][argindex2[ifield]-1]; + if (compute->size_array_rows_variable && argindex1[ifield] > compute->size_array_rows) + dvalue = 0.0; + else + dvalue = compute->array[argindex1[ifield] - 1][argindex2[ifield] - 1]; if (normflag && compute->extarray) dvalue /= natoms; } } @@ -1420,14 +1456,17 @@ void Thermo::compute_fix() dvalue = fix->compute_scalar(); if (normflag && fix->extscalar) dvalue /= natoms; } else if (argindex2[ifield] == 0) { - dvalue = fix->compute_vector(argindex1[ifield]-1); + dvalue = fix->compute_vector(argindex1[ifield] - 1); if (normflag) { - if (fix->extvector == 0) return; - else if (fix->extvector == 1) dvalue /= natoms; - else if (fix->extlist[argindex1[ifield]-1]) dvalue /= natoms; + if (fix->extvector == 0) + return; + else if (fix->extvector == 1) + dvalue /= natoms; + else if (fix->extlist[argindex1[ifield] - 1]) + dvalue /= natoms; } } else { - dvalue = fix->compute_array(argindex1[ifield]-1,argindex2[ifield]-1); + dvalue = fix->compute_array(argindex1[ifield] - 1, argindex2[ifield] - 1); if (normflag && fix->extarray) dvalue /= natoms; } } @@ -1442,10 +1481,11 @@ void Thermo::compute_variable() dvalue = input->variable->compute_equal(variables[field2index[ifield]]); else { double *varvec; - int nvec = - input->variable->compute_vector(variables[field2index[ifield]],&varvec); - if (nvec < iarg) dvalue = 0.0; - else dvalue = varvec[iarg-1]; + int nvec = input->variable->compute_vector(variables[field2index[ifield]], &varvec); + if (nvec < iarg) + dvalue = 0.0; + else + dvalue = varvec[iarg - 1]; } } @@ -1487,15 +1527,17 @@ void Thermo::compute_dt() void Thermo::compute_time() { - dvalue = update->atime + (update->ntimestep-update->atimestep)*update->dt; + dvalue = update->atime + (update->ntimestep - update->atimestep) * update->dt; } /* ---------------------------------------------------------------------- */ void Thermo::compute_cpu() { - if (firststep == 0) dvalue = 0.0; - else dvalue = timer->elapsed(Timer::TOTAL); + if (firststep == 0) + dvalue = 0.0; + else + dvalue = timer->elapsed(Timer::TOTAL); } /* ---------------------------------------------------------------------- */ @@ -1512,8 +1554,10 @@ void Thermo::compute_tpcpu() new_cpu = timer->elapsed(Timer::TOTAL); double cpu_diff = new_cpu - last_tpcpu; double time_diff = new_time - last_time; - if (time_diff > 0.0 && cpu_diff > 0.0) dvalue = time_diff/cpu_diff; - else dvalue = 0.0; + if (time_diff > 0.0 && cpu_diff > 0.0) + dvalue = time_diff / cpu_diff; + else + dvalue = 0.0; } last_time = new_time; @@ -1534,8 +1578,10 @@ void Thermo::compute_spcpu() new_cpu = timer->elapsed(Timer::TOTAL); double cpu_diff = new_cpu - last_spcpu; int step_diff = new_step - last_step; - if (cpu_diff > 0.0) dvalue = step_diff/cpu_diff; - else dvalue = 0.0; + if (cpu_diff > 0.0) + dvalue = step_diff / cpu_diff; + else + dvalue = 0.0; } last_step = new_step; @@ -1546,10 +1592,11 @@ void Thermo::compute_spcpu() void Thermo::compute_cpuremain() { - if (firststep == 0) dvalue = 0.0; - else dvalue = timer->elapsed(Timer::TOTAL) * - (update->laststep - update->ntimestep) / - (update->ntimestep - update->firststep); + if (firststep == 0) + dvalue = 0.0; + else + dvalue = timer->elapsed(Timer::TOTAL) * (update->laststep - update->ntimestep) / + (update->ntimestep - update->firststep); } /* ---------------------------------------------------------------------- */ @@ -1637,7 +1684,7 @@ void Thermo::compute_evdwl() { double tmp = 0.0; if (force->pair) tmp += force->pair->eng_vdwl; - MPI_Allreduce(&tmp,&dvalue,1,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(&tmp, &dvalue, 1, MPI_DOUBLE, MPI_SUM, world); if (force->pair && force->pair->tail_flag) { double volume = domain->xprd * domain->yprd * domain->zprd; @@ -1653,7 +1700,7 @@ void Thermo::compute_ecoul() { double tmp = 0.0; if (force->pair) tmp += force->pair->eng_coul; - MPI_Allreduce(&tmp,&dvalue,1,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(&tmp, &dvalue, 1, MPI_DOUBLE, MPI_SUM, world); if (normflag) dvalue /= natoms; } @@ -1663,7 +1710,7 @@ void Thermo::compute_epair() { double tmp = 0.0; if (force->pair) tmp += force->pair->eng_vdwl + force->pair->eng_coul; - MPI_Allreduce(&tmp,&dvalue,1,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(&tmp, &dvalue, 1, MPI_DOUBLE, MPI_SUM, world); if (force->kspace) dvalue += force->kspace->energy; if (force->pair && force->pair->tail_flag) { @@ -1680,9 +1727,10 @@ void Thermo::compute_ebond() { if (force->bond) { double tmp = force->bond->energy; - MPI_Allreduce(&tmp,&dvalue,1,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(&tmp, &dvalue, 1, MPI_DOUBLE, MPI_SUM, world); if (normflag) dvalue /= natoms; - } else dvalue = 0.0; + } else + dvalue = 0.0; } /* ---------------------------------------------------------------------- */ @@ -1691,9 +1739,10 @@ void Thermo::compute_eangle() { if (force->angle) { double tmp = force->angle->energy; - MPI_Allreduce(&tmp,&dvalue,1,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(&tmp, &dvalue, 1, MPI_DOUBLE, MPI_SUM, world); if (normflag) dvalue /= natoms; - } else dvalue = 0.0; + } else + dvalue = 0.0; } /* ---------------------------------------------------------------------- */ @@ -1702,9 +1751,10 @@ void Thermo::compute_edihed() { if (force->dihedral) { double tmp = force->dihedral->energy; - MPI_Allreduce(&tmp,&dvalue,1,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(&tmp, &dvalue, 1, MPI_DOUBLE, MPI_SUM, world); if (normflag) dvalue /= natoms; - } else dvalue = 0.0; + } else + dvalue = 0.0; } /* ---------------------------------------------------------------------- */ @@ -1713,9 +1763,10 @@ void Thermo::compute_eimp() { if (force->improper) { double tmp = force->improper->energy; - MPI_Allreduce(&tmp,&dvalue,1,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(&tmp, &dvalue, 1, MPI_DOUBLE, MPI_SUM, world); if (normflag) dvalue /= natoms; - } else dvalue = 0.0; + } else + dvalue = 0.0; } /* ---------------------------------------------------------------------- */ @@ -1728,9 +1779,10 @@ void Thermo::compute_emol() if (force->angle) tmp += force->angle->energy; if (force->dihedral) tmp += force->dihedral->energy; if (force->improper) tmp += force->improper->energy; - MPI_Allreduce(&tmp,&dvalue,1,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(&tmp, &dvalue, 1, MPI_DOUBLE, MPI_SUM, world); if (normflag) dvalue /= natoms; - } else dvalue = 0.0; + } else + dvalue = 0.0; } /* ---------------------------------------------------------------------- */ @@ -1740,7 +1792,8 @@ void Thermo::compute_elong() if (force->kspace) { dvalue = force->kspace->energy; if (normflag) dvalue /= natoms; - } else dvalue = 0.0; + } else + dvalue = 0.0; } /* ---------------------------------------------------------------------- */ @@ -1751,7 +1804,8 @@ void Thermo::compute_etail() double volume = domain->xprd * domain->yprd * domain->zprd; dvalue = force->pair->etail / volume; if (normflag) dvalue /= natoms; - } else dvalue = 0.0; + } else + dvalue = 0.0; } /* ---------------------------------------------------------------------- */ @@ -1768,10 +1822,9 @@ void Thermo::compute_enthalpy() compute_press(); double ptmp = dvalue; - dvalue = etmp + ptmp*vtmp/(force->nktv2p); + dvalue = etmp + ptmp * vtmp / (force->nktv2p); } - /* ---------------------------------------------------------------------- */ void Thermo::compute_vol() @@ -1788,7 +1841,7 @@ void Thermo::compute_density() { double mass = group->mass(0); compute_vol(); - dvalue = force->mv2d * mass/dvalue; + dvalue = force->mv2d * mass / dvalue; } /* ---------------------------------------------------------------------- */ @@ -1975,12 +2028,12 @@ void Thermo::compute_fmax() double max = 0.0; for (int i = 0; i < nlocal; i++) { - max = MAX(max,fabs(f[i][0])); - max = MAX(max,fabs(f[i][1])); - max = MAX(max,fabs(f[i][2])); + max = MAX(max, fabs(f[i][0])); + max = MAX(max, fabs(f[i][1])); + max = MAX(max, fabs(f[i][2])); } double maxall; - MPI_Allreduce(&max,&maxall,1,MPI_DOUBLE,MPI_MAX,world); + MPI_Allreduce(&max, &maxall, 1, MPI_DOUBLE, MPI_MAX, world); dvalue = maxall; } @@ -1992,10 +2045,9 @@ void Thermo::compute_fnorm() int nlocal = atom->nlocal; double dot = 0.0; - for (int i = 0; i < nlocal; i++) - dot += f[i][0]*f[i][0] + f[i][1]*f[i][1] + f[i][2]*f[i][2]; + for (int i = 0; i < nlocal; i++) dot += f[i][0] * f[i][0] + f[i][1] * f[i][1] + f[i][2] * f[i][2]; double dotall; - MPI_Allreduce(&dot,&dotall,1,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(&dot, &dotall, 1, MPI_DOUBLE, MPI_SUM, world); dvalue = sqrt(dotall); } @@ -2027,8 +2079,8 @@ void Thermo::compute_cellb() if (!domain->triclinic) dvalue = domain->yprd; else { - double* h = domain->h; - dvalue = sqrt(h[1]*h[1]+h[5]*h[5]); + double *h = domain->h; + dvalue = sqrt(h[1] * h[1] + h[5] * h[5]); } } @@ -2039,8 +2091,8 @@ void Thermo::compute_cellc() if (!domain->triclinic) dvalue = domain->zprd; else { - double* h = domain->h; - dvalue = sqrt(h[2]*h[2]+h[3]*h[3]+h[4]*h[4]); + double *h = domain->h; + dvalue = sqrt(h[2] * h[2] + h[3] * h[3] + h[4] * h[4]); } } @@ -2054,10 +2106,10 @@ void Thermo::compute_cellalpha() // Cos(alpha) = (xy.xz + ly.yz)/(b.c) - double* h = domain->h; - double cosalpha = (h[5]*h[4]+h[1]*h[3])/ - sqrt((h[1]*h[1]+h[5]*h[5])*(h[2]*h[2]+h[3]*h[3]+h[4]*h[4])); - dvalue = acos(cosalpha)*180.0/MY_PI; + double *h = domain->h; + double cosalpha = (h[5] * h[4] + h[1] * h[3]) / + sqrt((h[1] * h[1] + h[5] * h[5]) * (h[2] * h[2] + h[3] * h[3] + h[4] * h[4])); + dvalue = acos(cosalpha) * 180.0 / MY_PI; } } @@ -2071,9 +2123,9 @@ void Thermo::compute_cellbeta() // Cos(beta) = xz/c - double* h = domain->h; - double cosbeta = h[4]/sqrt(h[2]*h[2]+h[3]*h[3]+h[4]*h[4]); - dvalue = acos(cosbeta)*180.0/MY_PI; + double *h = domain->h; + double cosbeta = h[4] / sqrt(h[2] * h[2] + h[3] * h[3] + h[4] * h[4]); + dvalue = acos(cosbeta) * 180.0 / MY_PI; } } @@ -2087,8 +2139,8 @@ void Thermo::compute_cellgamma() // Cos(gamma) = xy/b - double* h = domain->h; - double cosgamma = h[5]/sqrt(h[1]*h[1]+h[5]*h[5]); - dvalue = acos(cosgamma)*180.0/MY_PI; + double *h = domain->h; + double cosgamma = h[5] / sqrt(h[1] * h[1] + h[5] * h[5]); + dvalue = acos(cosgamma) * 180.0 / MY_PI; } } From c70b0b39ac571bd276d6407f5481c2da333da3d9 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 19 Mar 2022 18:06:56 -0400 Subject: [PATCH 04/11] update documentation for modifying LAMMPS to reflect changes to Thermo class --- doc/src/Modify_thermo.rst | 67 ++++++++++++++++++++++++++----------- doc/src/Modify_variable.rst | 19 ++++++----- 2 files changed, 57 insertions(+), 29 deletions(-) diff --git a/doc/src/Modify_thermo.rst b/doc/src/Modify_thermo.rst index ea09e30c1d..522a806613 100644 --- a/doc/src/Modify_thermo.rst +++ b/doc/src/Modify_thermo.rst @@ -1,27 +1,54 @@ Thermodynamic output options ============================ -There is one class that computes and prints thermodynamic information -to the screen and log file; see the file thermo.cpp. +The ``Thermo`` class computes and prints thermodynamic information to +the screen and log file; see the files ``thermo.cpp`` and ``thermo.h``. -There are two styles defined in thermo.cpp: "one" and "multi". There -is also a flexible "custom" style which allows the user to explicitly -list keywords for quantities to print when thermodynamic info is -output. See the :doc:`thermo_style ` command for a list -of defined quantities. +There are four styles defined in ``thermo.cpp``: "one", "multi", "yaml", +and "custom". The "custom" style allows the user to explicitly list +keywords for individual quantities to print when thermodynamic output is +generated. The others have a fixed list of keywords. See the +:doc:`thermo_style ` command for a list of available +quantities. The formatting of the "custom" style defaults to the "one" +style, but can be adapted using :doc:`thermo_modify line `. -The thermo styles (one, multi, etc) are simply lists of keywords. -Adding a new style thus only requires defining a new list of keywords. -Search for the word "customize" with references to "thermo style" in -thermo.cpp to see the two locations where code will need to be added. +The thermo styles (one, multi, etc) are defined by lists of keywords +with associated formats for integer and floating point numbers and +identified but an enumerator constant. Adding a new style thus mostly +requires defining a new list of keywords and the associated formats and +then inserting the required output processing where the enumerators are +identified. Search for the word "CUSTOMIZATION" with references to +"thermo style" in the ``thermo.cpp`` file to see the locations where +code will need to be added. The member function ``Thermo::header()`` +prints output at the very beginning of a thermodynamic output block and +can be used to print column headers or other front matter. The member +function ``Thermo::footer()`` prints output at the end of a +thermodynamic output block. The formatting of the output is done by +assembling a "line" (which may span multiple lines if the style inserts +newline characters ("\n" as in the "multi" style). -New keywords can also be added to thermo.cpp to compute new quantities -for output. Search for the word "customize" with references to -"keyword" in thermo.cpp to see the several locations where code will -need to be added. +New thermodynamic keywords can also be added to ``thermo.cpp`` to +compute new quantities for output. Search for the word "CUSTOMIZATION" +with references to "keyword" in ``thermo.cpp`` to see the several +locations where code will need to be added. Effectively, you need to +define a member function that computes the property, add an if statement +in ``Thermo::parse_fields()`` where the corresponding header string for +the keyword and the function pointer is registered by calling the +``Thermo::addfield()`` method, and add an if statement in +``Thermo::evaluate_keyword()`` which is called from the ``Variable`` +class when a thermo keyword is encountered. -Note that the :doc:`thermo_style custom ` command already allows -for thermo output of quantities calculated by :doc:`fixes `, -:doc:`computes `, and :doc:`variables `. Thus, it may -be simpler to compute what you wish via one of those constructs, than -by adding a new keyword to the thermo command. +.. note:: + + The third argument to ``Thermo::addfield()`` is a flag indicating + whether the function for the keyword computes a floating point + (FLOAT), regular integer (INT), or big integer (BIGINT) value. This + information is used for formatting the thermodynamic output. Inside + the function the result must then be stored either in the ``dvalue``, + ``ivalue`` or ``bivalue`` member variable, respectively. + +Since the :doc:`thermo_style custom ` command allows to +use output of quantities calculated by :doc:`fixes `, +:doc:`computes `, and :doc:`variables `, it may often +be simpler to compute what you wish via one of those constructs, rather +than by adding a new keyword to the thermo_style command. diff --git a/doc/src/Modify_variable.rst b/doc/src/Modify_variable.rst index ded76af9da..915ed5fcf3 100644 --- a/doc/src/Modify_variable.rst +++ b/doc/src/Modify_variable.rst @@ -1,8 +1,8 @@ Variable options ================ -There is one class that computes and stores :doc:`variable ` -information in LAMMPS; see the file variable.cpp. The value +The ``Variable`` class computes and stores :doc:`variable ` +information in LAMMPS; see the file ``variable.cpp``. The value associated with a variable can be periodically printed to the screen via the :doc:`print `, :doc:`fix print `, or :doc:`thermo_style custom ` commands. Variables of style @@ -19,21 +19,22 @@ of arguments: compute values = c_mytemp[0], c_thermo_press[3], ... Adding keywords for the :doc:`thermo_style custom ` -command (which can then be accessed by variables) is discussed on the -:doc:`Modify thermo ` doc page. +command (which can then be accessed by variables) is discussed in the +:doc:`Modify thermo ` documentation. Adding a new math function of one or two arguments can be done by -editing one section of the Variable::evaluate() method. Search for +editing one section of the ``Variable::evaluate()`` method. Search for the word "customize" to find the appropriate location. Adding a new group function can be done by editing one section of the -Variable::evaluate() method. Search for the word "customize" to find -the appropriate location. You may need to add a new method to the -Group class as well (see the group.cpp file). +``Variable::evaluate()`` method. Search for the word "customize" to +find the appropriate location. You may need to add a new method to the +Group class as well (see the ``group.cpp`` file). Accessing a new atom-based vector can be done by editing one section of the Variable::evaluate() method. Search for the word "customize" to find the appropriate location. Adding new :doc:`compute styles ` (whose calculated values can -then be accessed by variables) is discussed on the :doc:`Modify compute ` doc page. +then be accessed by variables) is discussed in the :doc:`Modify compute +` documentation. From 294dd2778a6d2d0e8046f3ba61c8a38631c13428 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 19 Mar 2022 20:19:52 -0400 Subject: [PATCH 05/11] update thermo style yaml docs and examples for reading and parsing --- doc/src/Howto_structured_data.rst | 55 ++++++++++++++++++++++++++++++- doc/src/thermo_style.rst | 15 +++------ 2 files changed, 58 insertions(+), 12 deletions(-) diff --git a/doc/src/Howto_structured_data.rst b/doc/src/Howto_structured_data.rst index b7778622de..56a1778ece 100644 --- a/doc/src/Howto_structured_data.rst +++ b/doc/src/Howto_structured_data.rst @@ -21,7 +21,8 @@ YAML print """--- timestep: $(step) pe: $(pe) - ke: $(ke)""" file current_state.yaml screen no + ke: $(ke) + ...""" file current_state.yaml screen no .. code-block:: yaml :caption: current_state.yaml @@ -51,6 +52,58 @@ JSON "ke": 2.4962152903997174569 } +YAML format thermo_style output +=============================== + +.. versionadded:: 24Mar2022 + +LAMMPS supports the thermo style "yaml" and for "custom" style +thermodynamic output the format can be changed to YAML with +:doc:`thermo_modify line yaml `. This will produce a +block of output in a compact YAML format - one "document" per run - of +the following style: + +.. code-block:: yaml + + --- + keywords: [Step, Temp, E_pair, E_mol, TotEng, Press, ] + data: + - [100, 0.757453103239935, -5.7585054860159, 0, -4.62236133677021, 0.207261053624721, ] + - [110, 0.759322359337036, -5.7614668389562, 0, -4.62251889318624, 0.194314975399602, ] + - [120, 0.759372342462676, -5.76149365656489, 0, -4.62247073844943, 0.191600048851267, ] + - [130, 0.756833027516501, -5.75777334823494, 0, -4.62255928350835, 0.208792327853067, ] + ... + +This data can be extracted and parsed from a log file using python with: + +.. code-block:: python + + import re, yaml + + docs = "" + with open("log.lammps") as f: + for line in f: + m = re.search(r"^(keywords:.*$|data:$|---$|\.\.\.$| - \[.*\]$)", line) + if m: docs += m.group(0) + '\n' + + thermo = list(yaml.load_all(docs, Loader=yaml.SafeLoader)) + + print("Number of runs: ", len(thermo)) + print(thermo[1]['keywords'][4], ' = ', thermo[1]['data'][2][4]) + +After loading the YAML data, `thermo` is a list containing a dictionary +for each "run" where the tag "keywords" maps to the list of thermo +header strings and the tag "data" has a list of lists where the outer +list represents the lines of output and the inner list the values of the +columns matching the header keywords for that step. The second print() +command for example will print the header string for the fifth keyword +of the second run and the corresponding value for the third output line +of that run: + +.. parsed-literal:: + + Number of runs: 2 + TotEng = -4.62140097780047 Writing continuous data during a simulation =========================================== diff --git a/doc/src/thermo_style.rst b/doc/src/thermo_style.rst index e2d5bcb58d..ff0e41ffb0 100644 --- a/doc/src/thermo_style.rst +++ b/doc/src/thermo_style.rst @@ -114,6 +114,8 @@ that is the equivalent of "thermo_style custom etotal ke temp pe ebond eangle edihed eimp evdwl ecoul elong press". The listing contains numeric values and a string ID for each quantity. +.. versionadded:: 24Mar2022 + Style *yaml* is similar to style *one* but prints the output in `YAML `_ format which can be easily read by a variety of script languages and data handling packages. Since LAMMPS may print @@ -126,17 +128,8 @@ and can thus be extracted with commands like ``egrep`` as follows: egrep '^(keywords:|data:$|---$|\.\.\.$| - \[)' log.lammps > log.yaml -A typical block of YAML format output looks like this: - -.. code-block:: yaml - - --- - keywords: [Step, Temp, KinEng, PotEng, E_bond, E_angle, E_dihed, E_impro, E_vdwl, E_coul, E_long, Press, Volume, ] - data: - - [0, 1.44000000000001, 2.15993250000001, -6.77336805323422, 0, 0, 0, 0, -6.77336805323422, 0, 0, -5.01970725908556, 37905.7095475006, ] - - [50, 0.740091517740786, 1.11010258482128, -5.73150426762886, 0, 0, 0, 0, -5.73150426762886, 0, 0, 0.335273324523691, 37905.7095475006, ] - - [100, 0.757453103239936, 1.13614414924569, -5.75850548601596, 0, 0, 0, 0, -5.75850548601596, 0, 0, 0.207261053624723, 37905.7095475006, ] - ... +Information about processing such YAML files is in the :doc:`structured +data output howto `. Style *custom* is the most general setting and allows you to specify which of the keywords listed above you want printed on each From 1b7da77a4a81b747d098b77985b72a04069dc3bd Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 19 Mar 2022 20:20:30 -0400 Subject: [PATCH 06/11] update some more version change timestamps --- doc/src/Python_install.rst | 2 +- doc/src/fix_lb_fluid.rst | 4 +++- src/library.cpp | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/doc/src/Python_install.rst b/doc/src/Python_install.rst index aaeeec18f1..e5431a4a81 100644 --- a/doc/src/Python_install.rst +++ b/doc/src/Python_install.rst @@ -187,7 +187,7 @@ folder that the dynamic loader searches or inside of the installed folders are searched by default by Python or the LAMMPS Python package. - .. versionchanged:: TBD + .. versionchanged:: 24Mar2022 .. note:: diff --git a/doc/src/fix_lb_fluid.rst b/doc/src/fix_lb_fluid.rst index e2ca5f0fc7..d0de406156 100644 --- a/doc/src/fix_lb_fluid.rst +++ b/doc/src/fix_lb_fluid.rst @@ -63,8 +63,10 @@ Examples Description """"""""""" +.. versionchanged:: 24Mar2022 + Implement a lattice-Boltzmann fluid on a uniform mesh covering the -LAMMPS simulation domain. Note that this fix was updated in 2021 and is +LAMMPS simulation domain. Note that this fix was updated in 2022 and is not backward compatible with the previous version. If you need the previous version, please download an older version of LAMMPS. The MD particles described by *group-ID* apply a velocity dependent force to diff --git a/src/library.cpp b/src/library.cpp index ace9905451..c2ae52a809 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -405,7 +405,7 @@ after calling Py_Finalize(). This function can be called to explicitly clear the Python environment in case it is safe to do so. -.. versionadded:: TBD +.. versionadded:: 20Sep2021 *See also* :cpp:func:`lammps_mpi_finalize`, :cpp:func:`lammps_kokkos_finalize` From d539dcd8d41e20f0ac3945b59f6fcf8bd61e7c83 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sat, 19 Mar 2022 20:54:50 -0400 Subject: [PATCH 07/11] repair collateral damage to NETCDF package from Thermo class refactor --- src/NETCDF/dump_netcdf.cpp | 24 ++++++++++++------------ src/NETCDF/dump_netcdf_mpiio.cpp | 16 ++++++++-------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/NETCDF/dump_netcdf.cpp b/src/NETCDF/dump_netcdf.cpp index 137d6368c2..d68da35b0b 100644 --- a/src/NETCDF/dump_netcdf.cpp +++ b/src/NETCDF/dump_netcdf.cpp @@ -335,7 +335,7 @@ void DumpNetCDF::openfile() if (thermo) { Thermo *th = output->thermo; for (int i = 0; i < th->nfield; i++) { - NCERRX( nc_inq_varid(ncid, th->keyword[i], &thermovar[i]), th->keyword[i] ); + NCERRX( nc_inq_varid(ncid, th->keyword[i].c_str(), &thermovar[i]), th->keyword[i].c_str() ); } } @@ -448,18 +448,18 @@ void DumpNetCDF::openfile() Thermo *th = output->thermo; for (int i = 0; i < th->nfield; i++) { if (th->vtype[i] == Thermo::FLOAT) { - NCERRX( nc_def_var(ncid, th->keyword[i], type_nc_real, 1, dims, - &thermovar[i]), th->keyword[i] ); + NCERRX( nc_def_var(ncid, th->keyword[i].c_str(), type_nc_real, 1, dims, + &thermovar[i]), th->keyword[i].c_str() ); } else if (th->vtype[i] == Thermo::INT) { - NCERRX( nc_def_var(ncid, th->keyword[i], NC_INT, 1, dims, - &thermovar[i]), th->keyword[i] ); + NCERRX( nc_def_var(ncid, th->keyword[i].c_str(), NC_INT, 1, dims, + &thermovar[i]), th->keyword[i].c_str() ); } else if (th->vtype[i] == Thermo::BIGINT) { #if defined(LAMMPS_SMALLBIG) || defined(LAMMPS_BIGBIG) - NCERRX( nc_def_var(ncid, th->keyword[i], NC_INT64, 1, dims, - &thermovar[i]), th->keyword[i] ); + NCERRX( nc_def_var(ncid, th->keyword[i].c_str(), NC_INT64, 1, dims, + &thermovar[i]), th->keyword[i].c_str() ); #else - NCERRX( nc_def_var(ncid, th->keyword[i], NC_LONG, 1, dims, - &thermovar[i]), th->keyword[i] ); + NCERRX( nc_def_var(ncid, th->keyword[i].c_str(), NC_LONG, 1, dims, + &thermovar[i]), th->keyword[i].c_str() ); #endif } } @@ -625,13 +625,13 @@ void DumpNetCDF::write() if (th->vtype[i] == Thermo::FLOAT) { NCERRX( nc_put_var1_double(ncid, thermovar[i], start, &th->dvalue), - th->keyword[i] ); + th->keyword[i].c_str() ); } else if (th->vtype[i] == Thermo::INT) { NCERRX( nc_put_var1_int(ncid, thermovar[i], start, &th->ivalue), - th->keyword[i] ); + th->keyword[i].c_str() ); } else if (th->vtype[i] == Thermo::BIGINT) { NCERRX( nc_put_var1_bigint(ncid, thermovar[i], start, &th->bivalue), - th->keyword[i] ); + th->keyword[i].c_str() ); } } } diff --git a/src/NETCDF/dump_netcdf_mpiio.cpp b/src/NETCDF/dump_netcdf_mpiio.cpp index a1c9d20e61..ac281d26a3 100644 --- a/src/NETCDF/dump_netcdf_mpiio.cpp +++ b/src/NETCDF/dump_netcdf_mpiio.cpp @@ -332,7 +332,7 @@ void DumpNetCDFMPIIO::openfile() if (thermo) { Thermo *th = output->thermo; for (int i = 0; i < th->nfield; i++) { - NCERRX( ncmpi_inq_varid(ncid, th->keyword[i], &thermovar[i]), th->keyword[i] ); + NCERRX( ncmpi_inq_varid(ncid, th->keyword[i].c_str(), &thermovar[i]), th->keyword[i].c_str() ); } } @@ -436,14 +436,14 @@ void DumpNetCDFMPIIO::openfile() Thermo *th = output->thermo; for (int i = 0; i < th->nfield; i++) { if (th->vtype[i] == Thermo::FLOAT) { - NCERRX( ncmpi_def_var(ncid, th->keyword[i], type_nc_real, 1, dims, &thermovar[i]), th->keyword[i] ); + NCERRX( ncmpi_def_var(ncid, th->keyword[i].c_str(), type_nc_real, 1, dims, &thermovar[i]), th->keyword[i].c_str() ); } else if (th->vtype[i] == Thermo::INT) { - NCERRX( ncmpi_def_var(ncid, th->keyword[i], NC_INT, 1, dims, &thermovar[i]), th->keyword[i] ); + NCERRX( ncmpi_def_var(ncid, th->keyword[i].c_str(), NC_INT, 1, dims, &thermovar[i]), th->keyword[i].c_str() ); } else if (th->vtype[i] == Thermo::BIGINT) { #if defined(LAMMPS_SMALLBIG) || defined(LAMMPS_BIGBIG) - NCERRX( ncmpi_def_var(ncid, th->keyword[i], NC_INT64, 1, dims, &thermovar[i]), th->keyword[i] ); + NCERRX( ncmpi_def_var(ncid, th->keyword[i].c_str(), NC_INT64, 1, dims, &thermovar[i]), th->keyword[i].c_str() ); #else - NCERRX( ncmpi_def_var(ncid, th->keyword[i], NC_LONG, 1, dims, &thermovar[i]), th->keyword[i] ); + NCERRX( ncmpi_def_var(ncid, th->keyword[i].c_str(), NC_LONG, 1, dims, &thermovar[i]), th->keyword[i].c_str() ); #endif } } @@ -612,13 +612,13 @@ void DumpNetCDFMPIIO::write() if (th->vtype[i] == Thermo::FLOAT) { NCERRX( ncmpi_put_var1_double(ncid, thermovar[i], start, &th->dvalue), - th->keyword[i] ); + th->keyword[i].c_str() ); } else if (th->vtype[i] == Thermo::INT) { NCERRX( ncmpi_put_var1_int(ncid, thermovar[i], start, &th->ivalue), - th->keyword[i] ); + th->keyword[i].c_str() ); } else if (th->vtype[i] == Thermo::BIGINT) { NCERRX( ncmpi_put_var1_bigint(ncid, thermovar[i], start, &th->bivalue), - th->keyword[i] ); + th->keyword[i].c_str() ); } } } From 356555418dfc8ab20099c9d44a230912738d2aa1 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Sun, 20 Mar 2022 00:41:26 -0400 Subject: [PATCH 08/11] remove dead code --- src/EXTRA-MOLECULE/bond_fene_nm.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/EXTRA-MOLECULE/bond_fene_nm.cpp b/src/EXTRA-MOLECULE/bond_fene_nm.cpp index ea5c491de7..839217df78 100644 --- a/src/EXTRA-MOLECULE/bond_fene_nm.cpp +++ b/src/EXTRA-MOLECULE/bond_fene_nm.cpp @@ -46,10 +46,10 @@ void BondFENENM::compute(int eflag, int vflag) { int i1, i2, n, type; double delx, dely, delz, ebond, fbond; - double rsq, r0sq, rlogarg, sr6; + double rsq, r0sq, rlogarg; double r; - ebond = sr6 = 0.0; + ebond = 0.0; ev_init(eflag, vflag); double **x = atom->x; From 6c30bdf08226c6118c020d2847db66cdb238431a Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 21 Mar 2022 14:34:14 -0400 Subject: [PATCH 09/11] add missing reaxff files to purge list --- src/Purge.list | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Purge.list b/src/Purge.list index 00a2269ec8..6753476ec5 100644 --- a/src/Purge.list +++ b/src/Purge.list @@ -79,6 +79,8 @@ reaxc_multi_body_omp.cpp reaxc_nonbonded_omp.cpp reaxc_torsion_angles_omp.cpp reaxc_valence_angles_omp.cpp +fix_qeq_reax.cpp +fix_qeq_reax.h fix_reaxc.cpp fix_reaxc.h fix_reaxc_bonds.cpp From 4c1a6d7ecfd2fc9bf9bb7f94d0362c9b65a999d1 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 21 Mar 2022 14:44:07 -0400 Subject: [PATCH 10/11] tweak settings for thermo style "one" --- src/thermo.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/thermo.cpp b/src/thermo.cpp index 649b45f18b..dbeabd5fb1 100644 --- a/src/thermo.cpp +++ b/src/thermo.cpp @@ -71,8 +71,8 @@ using namespace MathConst; enum { ONELINE, MULTILINE, YAMLLINE }; // style "one" static constexpr char ONE[] = "step temp epair emol etotal press"; -#define FORMAT_FLOAT_ONE_DEFAULT "%12.8g" -#define FORMAT_INT_ONE_DEFAULT "%10d" +#define FORMAT_FLOAT_ONE_DEFAULT "% -12.8g" +#define FORMAT_INT_ONE_DEFAULT "%10d " // style "multi" static constexpr char MULTI[] = "etotal ke temp pe ebond eangle edihed eimp evdwl ecoul elong press"; @@ -328,7 +328,7 @@ void Thermo::header() if (vtype[i] == FLOAT) hdr += fmt::format("{:^12} ", keyword[i]); else if ((vtype[i] == INT) || (vtype[i] == BIGINT)) - hdr += fmt::format("{:^10} ", keyword[i]); + hdr += fmt::format("{:^11} ", keyword[i]); } else if (lineflag == YAMLLINE) { hdr += keyword[i]; hdr += ", "; From 8954ac4f20826a03bc2c5f344cc0658e8831b866 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 21 Mar 2022 17:12:43 -0400 Subject: [PATCH 11/11] correct/simplify for GPU device specialization --- src/KOKKOS/pair_dpd_fdt_energy_kokkos.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/KOKKOS/pair_dpd_fdt_energy_kokkos.cpp b/src/KOKKOS/pair_dpd_fdt_energy_kokkos.cpp index c95c02b767..123467865a 100644 --- a/src/KOKKOS/pair_dpd_fdt_energy_kokkos.cpp +++ b/src/KOKKOS/pair_dpd_fdt_energy_kokkos.cpp @@ -115,9 +115,8 @@ void PairDPDfdtEnergyKokkos::init_style() neighflag = lmp->kokkos->neighflag; auto request = neighbor->find_request(this); - request->set_kokkos_host(std::is_same::value && - !std::is_same::value); - request->set_kokkos_device(std::is_same::value); + request->set_kokkos_host(0); + request->set_kokkos_device(1); if (neighflag == FULL) request->enable_full(); #ifdef DPD_USE_RAN_MARS