@@ -33,7 +33,7 @@ static constexpr int DELTA = 1048576;
3333/* ---------------------------------------------------------------------- */
3434
3535DumpExtXYZ::DumpExtXYZ (LAMMPS *lmp, int narg, char **arg) :
36- DumpXYZ(lmp, narg, arg), properties_string(nullptr )
36+ DumpXYZ(lmp, narg, arg), properties_string(nullptr ), thermo_string( nullptr )
3737{
3838 // style specific customizable settings
3939 with_vel = 1 ;
@@ -65,6 +65,7 @@ DumpExtXYZ::DumpExtXYZ(LAMMPS *lmp, int narg, char **arg) :
6565DumpExtXYZ::~DumpExtXYZ ()
6666{
6767 delete[] properties_string;
68+ delete[] thermo_string;
6869}
6970
7071/* ---------------------------------------------------------------------- */
@@ -135,37 +136,56 @@ int DumpExtXYZ::modify_param(int narg, char **arg)
135136
136137/* ---------------------------------------------------------------------- */
137138
139+ int DumpExtXYZ::count ()
140+ {
141+ // Dump::count() is called for all processes before writing the header.
142+ // We must update the thermodynamic data in the header here, since we are
143+ // calling computes that may perform communication. We only include data
144+ // from computes that were already invoked to avoid XXX not tallied errors.
145+
146+ delete[] thermo_string;
147+ std::string thermo_buf;
148+
149+ if (time_flag) thermo_buf += fmt::format (" Time={:.6f}" , compute_time ());
150+ thermo_buf += fmt::format (" pbc=\" {} {} {}\" " , domain->xperiodic ? " T" : " F" ,
151+ domain->yperiodic ? " T" : " F" , domain->zperiodic ? " T" : " F" );
152+ thermo_buf +=
153+ fmt::format (" Lattice=\" {:g} {:g} {:g} {:g} {:g} {:g} {:g} {:g} {:g}\" " , domain->xprd , 0 ., 0 .,
154+ domain->xy , domain->yprd , 0 ., domain->xz , domain->yz , domain->zprd );
155+
156+ if (output && output->thermo ) {
157+ auto *pe = output->thermo ->pe ;
158+ if (pe && (pe->invoked_scalar == update->ntimestep ))
159+ thermo_buf += fmt::format (" Potential_energy={}" , pe->compute_scalar ());
160+
161+ auto *temp = output->thermo ->temperature ;
162+ if (temp && (temp->invoked_scalar == update->ntimestep ))
163+ thermo_buf += fmt::format (" Temperature={}" , temp->compute_scalar ());
164+
165+ auto *press = output->thermo ->pressure ;
166+ if (press && (press->invoked_vector == update->ntimestep )) {
167+ press->compute_vector ();
168+ thermo_buf +=
169+ fmt::format (" Stress=\" {} {} {} {} {} {} {} {} {}\" " , press->vector [0 ], press->vector [3 ],
170+ press->vector [4 ], press->vector [3 ], press->vector [1 ], press->vector [5 ],
171+ press->vector [4 ], press->vector [5 ], press->vector [2 ]);
172+ }
173+ }
174+ thermo_string = utils::strdup (thermo_buf);
175+
176+ // perform real count() function in parent
177+ return DumpXYZ::count ();
178+ }
179+
180+ /* ---------------------------------------------------------------------- */
181+
138182void DumpExtXYZ::write_header (bigint n)
139183{
140184 if (me == 0 ) {
141185 if (!fp)
142186 error->one (FLERR, Error::NOLASTLINE, " Must not use 'run pre no' after creating a new dump" );
143187
144- std::string header = fmt::format (" {}\n Timestep={}" , n, update->ntimestep );
145- if (time_flag) header += fmt::format (" Time={:.6f}" , compute_time ());
146- header += fmt::format (" pbc=\" {} {} {}\" " , domain->xperiodic ? " T" : " F" ,
147- domain->yperiodic ? " T" : " F" , domain->zperiodic ? " T" : " F" );
148- header +=
149- fmt::format (" Lattice=\" {:g} {:g} {:g} {:g} {:g} {:g} {:g} {:g} {:g}\" " , domain->xprd , 0 .,
150- 0 ., domain->xy , domain->yprd , 0 ., domain->xz , domain->yz , domain->zprd );
151-
152- if (output && output->thermo ) {
153- auto *pe = output->thermo ->pe ;
154- if (pe) header += fmt::format (" Potential_energy={}" , pe->compute_scalar ());
155-
156- auto *temp = output->thermo ->temperature ;
157- if (temp) header += fmt::format (" Temperature={}" , temp->compute_scalar ());
158-
159- auto *press = output->thermo ->pressure ;
160- if (press) {
161- press->compute_vector ();
162- header +=
163- fmt::format (" Stress=\" {} {} {} {} {} {} {} {} {}\" " , press->vector [0 ],
164- press->vector [3 ], press->vector [4 ], press->vector [3 ], press->vector [1 ],
165- press->vector [5 ], press->vector [4 ], press->vector [5 ], press->vector [2 ]);
166- }
167- }
168-
188+ auto header = fmt::format (" {}\n Timestep={}{}" , n, update->ntimestep , thermo_string);
169189 header += fmt::format (" Properties={}" , properties_string);
170190 utils::print (fp, header + " \n " );
171191 }
0 commit comments