1 /* -*- c++ -*- ----------------------------------------------------------
2    LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
3    https://www.lammps.org/, Sandia National Laboratories
4    Steve Plimpton, sjplimp@sandia.gov
5 
6    Copyright (2003) Sandia Corporation.  Under the terms of Contract
7    DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
8    certain rights in this software.  This software is distributed under
9    the GNU General Public License.
10 
11    See the README file in the top-level LAMMPS directory.
12 ------------------------------------------------------------------------- */
13 
14 #ifndef LMP_MIN_H
15 #define LMP_MIN_H
16 
17 #include "pointers.h"    // IWYU pragma: export
18 
19 namespace LAMMPS_NS {
20 
21 class Min : protected Pointers {
22  public:
23   double einitial, efinal, eprevious;
24   double fnorm2_init, fnorminf_init, fnorm2_final, fnorminf_final;
25   double alpha_final;
26   int niter, neval;
27   int stop_condition;
28   char *stopstr;
29   int searchflag;    // 0 if damped dynamics, 1 if sub-cycles on local search
30 
31   Min(class LAMMPS *);
32   virtual ~Min();
33   virtual void init();
34   virtual void setup(int flag = 1);
35   virtual void setup_minimal(int);
36   virtual void run(int);
37   void cleanup();
38   int request(class Pair *, int, double);
memory_usage()39   virtual double memory_usage() { return 0; }
40   void modify_params(int, char **);
modify_param(int,char **)41   virtual int modify_param(int, char **) { return 0; }
42   virtual double fnorm_sqr();
43   virtual double fnorm_inf();
44   virtual double fnorm_max();
45 
46   enum { TWO, MAX, INF };
47 
48   // methods for spin minimizers
49   double total_torque();
50   double inf_torque();
51   double max_torque();
52 
init_style()53   virtual void init_style() {}
54   virtual void setup_style() = 0;
55   virtual void reset_vectors() = 0;
56   virtual int iterate(int) = 0;
57 
58   // possible return values of iterate() method
59   enum {
60     MAXITER,
61     MAXEVAL,
62     ETOL,
63     FTOL,
64     DOWNHILL,
65     ZEROALPHA,
66     ZEROFORCE,
67     ZEROQUAD,
68     TRSMALL,
69     INTERROR,
70     TIMEOUT,
71     MAXVDOTF
72   };
73 
74  protected:
75   int eflag, vflag;            // flags for energy/virial computation
76   int virial_style;            // compute virial explicitly or implicitly
77   int external_force_clear;    // clear forces locally or externally
78 
79   double dmax;      // max dist to move any atom in one step
80   int linestyle;    // 0 = backtrack, 1 = quadratic, 2 = forcezero
81                     // 3 = spin_cubic, 4 = spin_none
82 
83   int normstyle;    // TWO, MAX or INF flag for force norm evaluation
84 
85   double dtinit;    // store the default timestep
86 
87   // only for minimize style fire2
88   int delaystep;                 // minium steps of dynamics
89   double dtgrow, dtshrink;       // timestep increase, decrease
90   double alpha0, alphashrink;    // mixing velocities+forces coefficient
91   double tmax, tmin;             // timestep multiplicators max, min
92   int integrator;                // Newton integration: euler, leapfrog, verlet...
93   int halfstepback_flag;         // half step backward when v.f <= 0.0
94   int delaystep_start_flag;      // delay the initial dt_shrink
95   int max_vdotf_negatif;         // maximum iteration with v.f > 0.0
96 
97   int nelist_global, nelist_atom;    // # of PE,virial computes to check
98   int nvlist_global, nvlist_atom, ncvlist_atom;
99   class Compute **elist_global;    // lists of PE,virial Computes
100   class Compute **elist_atom;
101   class Compute **vlist_global;
102   class Compute **vlist_atom;
103   class Compute **cvlist_atom;
104 
105   int triclinic;    // 0 if domain is orthog, 1 if triclinic
106   int pairflag;
107   int torqueflag, extraflag;
108 
109   int pair_compute_flag;      // 0 if pair->compute is skipped
110   int kspace_compute_flag;    // 0 if kspace->compute is skipped
111 
112   int narray;                         // # of arrays stored by fix_minimize
113   class FixMinimize *fix_minimize;    // fix that stores auxiliary data
114 
115   class Compute *pe_compute;    // compute for potential energy
116   double ecurrent;              // current potential energy
117 
118   bigint ndoftotal;    // total dof for entire problem
119 
120   int nvec;        // local atomic dof = length of xvec
121   double *xvec;    // variables for atomic dof, as 1d vector
122   double *fvec;    // force vector for atomic dof, as 1d vector
123 
124   int nextra_global;    // # of extra global dof due to fixes
125   double *fextra;       // force vector for extra global dof
126                         // xextra is stored by fix
127 
128   int nextra_atom;           // # of extra per-atom variables
129   double **xextra_atom;      // ptr to the variable
130   double **fextra_atom;      // ptr to the force on the variable
131   int *extra_peratom;        // # of values in variable, e.g. 3 in x
132   int *extra_nlen;           // total local length of variable, e.g 3*nlocal
133   double *extra_max;         // max allowed change per iter for atom's var
134   class Pair **requestor;    // Pair that stores/manipulates the variable
135 
136   int kokkosable;    // 1 if this min style supports Kokkos
137 
138   int neigh_every, neigh_delay, neigh_dist_check;    // neighboring params
139 
140   virtual double energy_force(int);
141   virtual void force_clear();
142 
143   void ev_setup();
144   void ev_set(bigint);
145 
146   char *stopstrings(int);
147 };
148 
149 }    // namespace LAMMPS_NS
150 
151 #endif
152 
153 /* ERROR/WARNING messages:
154 
155 W: Using 'neigh_modify every 1 delay 0 check yes' setting during minimization
156 
157 UNDOCUMENTED
158 
159 E: Minimization could not find thermo_pe compute
160 
161 This compute is created by the thermo command.  It must have been
162 explicitly deleted by a uncompute command.
163 
164 E: Cannot use a damped dynamics min style with fix box/relax
165 
166 This is a current restriction in LAMMPS.  Use another minimizer
167 style.
168 
169 E: Cannot use a damped dynamics min style with per-atom DOF
170 
171 This is a current restriction in LAMMPS.  Use another minimizer
172 style.
173 
174 E: Cannot use hftn min style with fix box/relax
175 
176 UNDOCUMENTED
177 
178 E: Cannot use hftn min style with per-atom DOF
179 
180 UNDOCUMENTED
181 
182 E: Illegal ... command
183 
184 Self-explanatory.  Check the input script syntax and compare to the
185 documentation for the command.  You can use -echo screen as a
186 command-line option when running LAMMPS to see the offending line.
187 
188 U: Resetting reneighboring criteria during minimization
189 
190 Minimization requires that neigh_modify settings be delay = 0, every =
191 1, check = yes.  Since these settings were not in place, LAMMPS
192 changed them and will restore them to their original values after the
193 minimization.
194 
195 U: Energy due to X extra global DOFs will be included in minimizer energies
196 
197 When using fixes like box/relax, the potential energy used by the minimizer
198 is augmented by an additional energy provided by the fix. Thus the printed
199 converged energy may be different from the total potential energy.
200 
201 */
202