From d39354d569fbd09c5b036d94e8907d5eb361548f Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Sun, 18 Aug 2024 13:20:40 -0600 Subject: [PATCH 01/19] docs: proposal for pdf title page customization --- doc/utils/sphinx-config/conf.py.in | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/doc/utils/sphinx-config/conf.py.in b/doc/utils/sphinx-config/conf.py.in index cc003ffa48..8eca64b9e2 100644 --- a/doc/utils/sphinx-config/conf.py.in +++ b/doc/utils/sphinx-config/conf.py.in @@ -299,6 +299,7 @@ latex_elements = { # Additional stuff for the LaTeX preamble. 'preamble': r''' +\usepackage{xcolor} \setcounter{tocdepth}{2} \renewcommand{\sfdefault}{ptm} % Use Times New Roman font for \textrm \renewcommand{\sfdefault}{phv} % Use Helvetica font for \textsf @@ -343,7 +344,14 @@ latex_elements = { \renewcommand*\l@subsection{\@dottedtocline{2}{4.6em}{4.5em}} } \makeatother -''' +''', +'maketitle': r''' +\pagecolor{black} +\color{white} +\sphinxmaketitle +\nopagecolor +\color{black} +''', } # Grouping the document tree into LaTeX files. List of tuples From 4c6beb548e4799c9f7a4ba2e212c44b66be4428c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 19 Aug 2024 16:26:38 -0400 Subject: [PATCH 02/19] white on black title. Make page 1 show up in PDF sidebar --- doc/src/Manual.rst | 7 ++++++- doc/utils/sphinx-config/conf.py.in | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/doc/src/Manual.rst b/doc/src/Manual.rst index 33a54cf7aa..17e61c97be 100644 --- a/doc/src/Manual.rst +++ b/doc/src/Manual.rst @@ -2,7 +2,12 @@ LAMMPS Documentation (|version| version) ######################################## -**About LAMMPS and this manual** +.. toctree:: + :caption: About LAMMPS + +**************************** +About LAMMPS and this manual +**************************** LAMMPS stands for **L**\ arge-scale **A**\ tomic/**M**\ olecular **M**\ assively **P**\ arallel **S**\ imulator. diff --git a/doc/utils/sphinx-config/conf.py.in b/doc/utils/sphinx-config/conf.py.in index a29ba618ae..f6db25bea8 100644 --- a/doc/utils/sphinx-config/conf.py.in +++ b/doc/utils/sphinx-config/conf.py.in @@ -301,6 +301,7 @@ latex_elements = { 'preamble': r''' \usepackage{xcolor} \setcounter{tocdepth}{2} +\setcounter{part}{-1} \renewcommand{\sfdefault}{ptm} % Use Times New Roman font for \textrm \renewcommand{\sfdefault}{phv} % Use Helvetica font for \textsf \usepackage[columns=1]{idxlayout} % create index with only one column @@ -339,6 +340,7 @@ latex_elements = { % Make ToC number fields wider to accommodate sections with >= 100 subsections % or >= 10 subsections with >= 10 subsubsections \makeatletter +% reset chapter counter for each part \@addtoreset{chapter}{part} \renewcommand*{\sphinxtableofcontentshook}{% \renewcommand*\l@section{\@dottedtocline{1}{1.5em}{3.1em}} From 085dec4d3c0d75f73b92a6041a5b0a14d7879e24 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 20 Aug 2024 00:02:17 -0400 Subject: [PATCH 03/19] Use drop down list to select raw or smooth plot or both. Fix plot color. --- tools/lammps-gui/chartviewer.cpp | 85 +++++++++++++++++++++++--------- tools/lammps-gui/chartviewer.h | 9 ++-- 2 files changed, 68 insertions(+), 26 deletions(-) diff --git a/tools/lammps-gui/chartviewer.cpp b/tools/lammps-gui/chartviewer.cpp index 750777af2d..8d5c3f3d56 100644 --- a/tools/lammps-gui/chartviewer.cpp +++ b/tools/lammps-gui/chartviewer.cpp @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -57,17 +56,23 @@ ChartWindow::ChartWindow(const QString &_filename, QWidget *parent) : auto *dummy = new QPushButton(QIcon(), ""); dummy->hide(); - smooth = new QCheckBox("Show smooth graph"); - smooth->setCheckState(Qt::Unchecked); + do_raw = true; + do_smooth = true; + smooth = new QComboBox; + smooth->addItem("Raw"); + smooth->addItem("Smooth"); + smooth->addItem("Both"); + smooth->setCurrentIndex(2); + smooth->show(); window = new QSpinBox; - window->setRange(5, 100); + window->setRange(5, 999); window->setValue(10); - window->setEnabled(false); + window->setEnabled(true); window->setToolTip("Smoothing Window Size"); order = new QSpinBox; - order->setRange(1, 10); + order->setRange(1, 20); order->setValue(4); - order->setEnabled(false); + order->setEnabled(true); order->setToolTip("Smoothing Order"); auto *normal = new QPushButton(QIcon(":/icons/gtk-zoom-fit.png"), ""); @@ -78,12 +83,12 @@ ChartWindow::ChartWindow(const QString &_filename, QWidget *parent) : top->addSpacerItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum)); top->addWidget(dummy); top->addWidget(smooth); + top->addWidget(new QLabel(" Smooth:")); top->addWidget(window); top->addWidget(order); - top->addWidget(new QLabel(" ")); + top->addWidget(new QLabel(" ")); top->addWidget(normal); - top->addWidget(new QLabel(" ")); - top->addWidget(new QLabel("Select data:")); + top->addWidget(new QLabel(" Data:")); top->addWidget(columns); saveAsAct = file->addAction("&Save Graph As...", this, &ChartWindow::saveAs); saveAsAct->setIcon(QIcon(":/icons/document-save-as.png")); @@ -107,7 +112,7 @@ ChartWindow::ChartWindow(const QString &_filename, QWidget *parent) : layout->addLayout(top); setLayout(layout); - connect(smooth, &QPushButton::released, this, &ChartWindow::update_smooth); + connect(smooth, SIGNAL(currentIndexChanged(int)), this, SLOT(select_smooth(int))); connect(window, &QAbstractSpinBox::editingFinished, this, &ChartWindow::update_smooth); connect(order, &QAbstractSpinBox::editingFinished, this, &ChartWindow::update_smooth); connect(window, QOverload::of(&QSpinBox::valueChanged), this, &ChartWindow::update_smooth); @@ -174,8 +179,11 @@ void ChartWindow::quit() void ChartWindow::reset_zoom() { - int choice = columns->currentData().toInt() - 1; - if ((choice >= 0) && (choice < charts.size())) charts[choice]->reset_zoom(); + int choice = columns->currentData().toInt(); + if ((choice >= 0) && (choice < charts.size())) { + charts[choice]->update_smooth(); + charts[choice]->reset_zoom(); + } } void ChartWindow::stop_run() @@ -186,17 +194,35 @@ void ChartWindow::stop_run() if (main) main->stop_run(); } -void ChartWindow::update_smooth() +void ChartWindow::select_smooth(int) { - bool do_smooth = smooth->isChecked(); + switch (smooth->currentIndex()) { + case 0: + do_raw = true; + do_smooth = false; + break; + case 1: + do_raw = false; + do_smooth = true; + break; + case 2: // fallthrough + default: + do_raw = true; + do_smooth = true; + break; + } window->setEnabled(do_smooth); order->setEnabled(do_smooth); + update_smooth(); +} +void ChartWindow::update_smooth() +{ int wval = window->value(); int oval = order->value(); for (auto &c : charts) - c->smooth_param(do_smooth, wval, oval); + c->smooth_param(do_raw, do_smooth, wval, oval); } void ChartWindow::saveAs() @@ -358,14 +384,11 @@ bool ChartWindow::eventFilter(QObject *watched, QEvent *event) ChartViewer::ChartViewer(const QString &title, int _index, QWidget *parent) : QChartView(parent), last_step(-1), index(_index), window(10), order(4), chart(new QChart), series(new QLineSeries), smooth(nullptr), xaxis(new QValueAxis), yaxis(new QValueAxis), - do_smooth(false) + do_raw(true), do_smooth(true) { chart->legend()->hide(); chart->addAxis(xaxis, Qt::AlignBottom); chart->addAxis(yaxis, Qt::AlignLeft); - chart->addSeries(series); - series->attachAxis(xaxis); - series->attachAxis(yaxis); xaxis->setTitleText("Time step"); xaxis->setTickCount(5); xaxis->setLabelFormat("%d"); @@ -379,6 +402,7 @@ ChartViewer::ChartViewer(const QString &title, int _index, QWidget *parent) : setChart(chart); setRubberBand(QChartView::RectangleRubberBand); last_update = QTime::currentTime(); + update_smooth(); } /* -------------------------------------------------------------------- */ @@ -425,8 +449,8 @@ void ChartViewer::add_data(int step, double data) // update the chart display only after at least updchart milliseconds have passed if (last_update.msecsTo(QTime::currentTime()) > settings.value("updchart", "500").toInt()) { last_update = QTime::currentTime(); - reset_zoom(); update_smooth(); + reset_zoom(); } } } @@ -489,8 +513,12 @@ void ChartViewer::reset_zoom() /* -------------------------------------------------------------------- */ -void ChartViewer::smooth_param(bool _do_smooth, int _window, int _order) +void ChartViewer::smooth_param(bool _do_raw, bool _do_smooth, int _window, int _order) { + // turn off raw plot + if (!_do_raw) { + if (do_raw) chart->removeSeries(series); + } // turn off smooth plot if (!_do_smooth) { if (smooth) { @@ -499,6 +527,7 @@ void ChartViewer::smooth_param(bool _do_smooth, int _window, int _order) smooth = nullptr; } } + do_raw = _do_raw; do_smooth = _do_smooth; window = _window; order = _order; @@ -513,10 +542,22 @@ static QList calc_sgsmooth(const QList &input, const int windo void ChartViewer::update_smooth() { + auto allseries = chart->series(); + if (do_raw) { + // add raw data if not in chart + if (!allseries.contains(series)) { + series->setPen(QPen(QBrush(QColor(100, 150, 255)), 3, Qt::SolidLine, Qt::RoundCap)); + chart->addSeries(series); + series->attachAxis(xaxis); + series->attachAxis(yaxis); + } + } + if (do_smooth) { if (series->count() > (2 * window)) { if (!smooth) { smooth = new QLineSeries; + smooth->setPen(QPen(QBrush(QColor(255, 125, 125)), 3, Qt::SolidLine, Qt::RoundCap)); chart->addSeries(smooth); smooth->attachAxis(xaxis); smooth->attachAxis(yaxis); diff --git a/tools/lammps-gui/chartviewer.h b/tools/lammps-gui/chartviewer.h index 58f65ba215..28915d24e3 100644 --- a/tools/lammps-gui/chartviewer.h +++ b/tools/lammps-gui/chartviewer.h @@ -25,7 +25,6 @@ class QCloseEvent; class QEvent; class QMenuBar; class QMenu; -class QCheckBox; class QSpinBox; namespace QtCharts { class ChartViewer; @@ -51,6 +50,7 @@ private slots: void quit(); void reset_zoom(); void stop_run(); + void select_smooth(int selection); void update_smooth(); void saveAs(); @@ -65,12 +65,13 @@ protected: bool eventFilter(QObject *watched, QEvent *event) override; private: + bool do_raw, do_smooth; QMenuBar *menu; QMenu *file; QComboBox *columns; QAction *saveAsAct, *exportCsvAct, *exportDatAct, *exportYamlAct; QAction *closeAct, *stopAct, *quitAct; - QCheckBox *smooth; + QComboBox *smooth; QSpinBox *window, *order; QString filename; @@ -94,7 +95,7 @@ public: void add_data(int step, double data); void reset_zoom(); - void smooth_param(bool _do_smooth, int _window, int _order); + void smooth_param(bool _do_raw, bool _do_smooth, int _window, int _order); void update_smooth(); int get_index() const { return index; }; @@ -111,7 +112,7 @@ private: QValueAxis *xaxis; QValueAxis *yaxis; QTime last_update; - bool do_smooth; + bool do_raw, do_smooth; }; } // namespace QtCharts #endif From 1809115c6474c85ad422c55168a4e08c07784eef Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 20 Aug 2024 00:12:29 -0400 Subject: [PATCH 04/19] avoid uninitialized access to next_thermo and next_restart from reset_dt() --- src/output.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/output.cpp b/src/output.cpp index f6da696293..60d84e715d 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -77,7 +77,7 @@ Output::Output(LAMMPS *lmp) : Pointers(lmp) ndump = 0; max_dump = 0; any_time_dumps = 0; - next_dump_any = next_time_dump_any = MAXBIGINT; + next_thermo = next_restart = next_dump_any = next_time_dump_any = MAXBIGINT; mode_dump = nullptr; every_dump = nullptr; every_time_dump = nullptr; From 8cfd856296eaaae50ee44a6a4152a29e6894864e Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 20 Aug 2024 00:50:24 -0400 Subject: [PATCH 05/19] plug small memory leak --- src/pair_hybrid_scaled.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pair_hybrid_scaled.cpp b/src/pair_hybrid_scaled.cpp index e897c784c7..2cacacfd8e 100644 --- a/src/pair_hybrid_scaled.cpp +++ b/src/pair_hybrid_scaled.cpp @@ -276,6 +276,7 @@ void PairHybridScaled::settings(int narg, char **arg) // allocate list of sub-styles as big as possibly needed if no extra args styles = new Pair *[narg]; + delete[] cutmax_style; cutmax_style = new double[narg]; memset(cutmax_style, 0.0, narg * sizeof(double)); keywords = new char *[narg]; From 02752ddf6a7ea316013f67c4a14d3625ee250cca Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 20 Aug 2024 01:15:53 -0400 Subject: [PATCH 06/19] don't leak memory when throwing an exception --- src/text_file_reader.cpp | 11 ++++++++++- unittest/commands/test_groups.cpp | 1 + unittest/formats/test_file_operations.cpp | 1 + unittest/formats/test_text_file_reader.cpp | 10 ++++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/text_file_reader.cpp b/src/text_file_reader.cpp index 3cff7880a9..bc274e42fa 100644 --- a/src/text_file_reader.cpp +++ b/src/text_file_reader.cpp @@ -48,6 +48,7 @@ TextFileReader::TextFileReader(const std::string &filename, const std::string &f fp = fopen(filename.c_str(), "r"); if (fp == nullptr) { + delete[] line; throw FileReaderException( fmt::format("cannot open {} file {}: {}", filetype, filename, utils::getsyserror())); } @@ -74,7 +75,11 @@ TextFileReader::TextFileReader(FILE *fp, std::string filetype) : filetype(std::move(filetype)), closefp(false), line(nullptr), fp(fp), ignore_comments(true) { set_bufsize(1024); - if (fp == nullptr) throw FileReaderException("Invalid file descriptor"); + if (fp == nullptr) { + delete[] line; + line = nullptr; + throw FileReaderException("Invalid file descriptor"); + } } /** Closes the file */ @@ -90,6 +95,8 @@ TextFileReader::~TextFileReader() void TextFileReader::set_bufsize(int newsize) { if (newsize < 100) { + delete[] line; + line = nullptr; throw FileReaderException( fmt::format("line buffer size {} for {} file too small, must be > 100", newsize, filetype)); } @@ -112,6 +119,8 @@ void TextFileReader::skip_line() char *ptr = fgets(line, bufsize, fp); if (ptr == nullptr) { // EOF + delete[] line; + line = nullptr; throw EOFException(fmt::format("Missing line in {} file!", filetype)); } } diff --git a/unittest/commands/test_groups.cpp b/unittest/commands/test_groups.cpp index 4035a4a4d4..6900c527e0 100644 --- a/unittest/commands/test_groups.cpp +++ b/unittest/commands/test_groups.cpp @@ -229,6 +229,7 @@ TEST_F(GroupTest, SelectRestart) command("group five subtract all half xxx");); TEST_FAILURE(".*ERROR: Group ID xxx does not exist.*", command("group five intersect half top xxx");); + delete[] flags; } TEST_F(GroupTest, Molecular) diff --git a/unittest/formats/test_file_operations.cpp b/unittest/formats/test_file_operations.cpp index cd08650bf8..cd3b7dce68 100644 --- a/unittest/formats/test_file_operations.cpp +++ b/unittest/formats/test_file_operations.cpp @@ -232,6 +232,7 @@ TEST_F(FileOperationsTest, read_lines_from_file) rv = utils::read_lines_from_file(fp, 2, MAX_BUF_SIZE / 2, buf, me, world); ASSERT_EQ(rv, 1); delete[] buf; + if (me == 0) fclose(fp); } TEST_F(FileOperationsTest, logmesg) diff --git a/unittest/formats/test_text_file_reader.cpp b/unittest/formats/test_text_file_reader.cpp index 687f6539f0..3fae7ef231 100644 --- a/unittest/formats/test_text_file_reader.cpp +++ b/unittest/formats/test_text_file_reader.cpp @@ -87,6 +87,16 @@ TEST_F(TextFileReaderTest, nofp) ASSERT_THROW({ TextFileReader reader(nullptr, "test"); }, FileReaderException); } +TEST_F(TextFileReaderTest, buffer) +{ + test_files(); + auto *reader = new TextFileReader("text_reader_two.file", "test"); + reader->set_bufsize(4096); + auto *line = reader->next_line(); + ASSERT_THROW({ reader->set_bufsize(20); }, FileReaderException); + delete reader; +} + TEST_F(TextFileReaderTest, usefp) { test_files(); From 80ea7ac12080edda6c147a537a5e5a115cbb07b1 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 20 Aug 2024 01:26:48 -0400 Subject: [PATCH 07/19] plug another memory leak --- src/molecule.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/molecule.cpp b/src/molecule.cpp index 617402d605..e7656acbbc 100644 --- a/src/molecule.cpp +++ b/src/molecule.cpp @@ -2059,6 +2059,7 @@ void Molecule::deallocate() memory->destroy(type); memory->destroy(molecule); memory->destroy(q); + memory->destroy(mu); memory->destroy(radius); memory->destroy(rmass); From 2b485a3f62e77c5b4038630c750fd91af28bfa33 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 20 Aug 2024 04:10:15 -0400 Subject: [PATCH 08/19] be more paranoid about cleaning up --- src/text_file_reader.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/text_file_reader.cpp b/src/text_file_reader.cpp index bc274e42fa..715e82ab32 100644 --- a/src/text_file_reader.cpp +++ b/src/text_file_reader.cpp @@ -86,7 +86,10 @@ TextFileReader::TextFileReader(FILE *fp, std::string filetype) : TextFileReader::~TextFileReader() { - if (closefp) fclose(fp); + if (closefp) { + if (fp) fclose(fp); + fp = nullptr; + } delete[] line; } @@ -97,6 +100,10 @@ void TextFileReader::set_bufsize(int newsize) if (newsize < 100) { delete[] line; line = nullptr; + if (closefp) { + fclose(fp); + fp = nullptr; + } throw FileReaderException( fmt::format("line buffer size {} for {} file too small, must be > 100", newsize, filetype)); } @@ -116,11 +123,16 @@ void TextFileReader::rewind() void TextFileReader::skip_line() { + if (!line) return; char *ptr = fgets(line, bufsize, fp); if (ptr == nullptr) { // EOF delete[] line; line = nullptr; + if (closefp) { + fclose(fp); + fp = nullptr; + } throw EOFException(fmt::format("Missing line in {} file!", filetype)); } } @@ -145,6 +157,7 @@ char *TextFileReader::next_line(int nparams) int n = 0; int nwords = 0; + if (!line) return nullptr; char *ptr = fgets(line, bufsize, fp); if (ptr == nullptr) { From 19d6227220a4af9c8be28dd04f91e5d249eb43c6 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 20 Aug 2024 09:19:58 -0400 Subject: [PATCH 09/19] plug memory leaks in testers --- src/FEP/pair_morse_soft.cpp | 2 +- src/FEP/pair_morse_soft.h | 2 +- unittest/c-library/test_library_open.cpp | 1 + unittest/fortran/wrap_get_thermo.cpp | 17 +++++++++++++---- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/FEP/pair_morse_soft.cpp b/src/FEP/pair_morse_soft.cpp index d9be7e136d..e2cb92e303 100644 --- a/src/FEP/pair_morse_soft.cpp +++ b/src/FEP/pair_morse_soft.cpp @@ -35,7 +35,7 @@ using namespace MathSpecial; PairMorseSoft::~PairMorseSoft() { - if (allocated) { memory->destroy(lambda); } + if (allocated) memory->destroy(lambda); } /* ---------------------------------------------------------------------- */ diff --git a/src/FEP/pair_morse_soft.h b/src/FEP/pair_morse_soft.h index 0c12fbafde..9f4dcbd024 100644 --- a/src/FEP/pair_morse_soft.h +++ b/src/FEP/pair_morse_soft.h @@ -30,7 +30,7 @@ namespace LAMMPS_NS { class PairMorseSoft : public PairMorse { public: PairMorseSoft(class LAMMPS *lmp) : - PairMorse(lmp), lambda(nullptr), nlambda(0), shift_range(1.0){}; + PairMorse(lmp), lambda(nullptr), nlambda(0), shift_range(1.0) {}; ~PairMorseSoft() override; void compute(int, int) override; diff --git a/unittest/c-library/test_library_open.cpp b/unittest/c-library/test_library_open.cpp index 6f2ea9ac33..61ef080b9a 100644 --- a/unittest/c-library/test_library_open.cpp +++ b/unittest/c-library/test_library_open.cpp @@ -256,4 +256,5 @@ TEST(lammps_open_no_mpi, lammps_error) lammps_error(handle, 0, "test_warning"); output = ::testing::internal::GetCapturedStdout(); EXPECT_THAT(output, HasSubstr("WARNING: test_warning")); + lammps_close(handle); } diff --git a/unittest/fortran/wrap_get_thermo.cpp b/unittest/fortran/wrap_get_thermo.cpp index e18697ba9b..3a2b810858 100644 --- a/unittest/fortran/wrap_get_thermo.cpp +++ b/unittest/fortran/wrap_get_thermo.cpp @@ -85,10 +85,19 @@ TEST_F(LAMMPS_thermo, last_thermo) f_lammps_last_thermo_setup(); EXPECT_EQ(f_lammps_last_thermo_step(), 15); EXPECT_EQ(f_lammps_last_thermo_num(), 6); - EXPECT_STREQ(f_lammps_last_thermo_string(1), "Step"); - EXPECT_STREQ(f_lammps_last_thermo_string(2), "Temp"); - EXPECT_STREQ(f_lammps_last_thermo_string(3), "E_pair"); - EXPECT_STREQ(f_lammps_last_thermo_string(6), "Press"); + char *thermostr; + thermostr = (char *)f_lammps_last_thermo_string(1); + EXPECT_STREQ(thermostr, "Step"); + free(thermostr); + thermostr = (char *)f_lammps_last_thermo_string(2); + EXPECT_STREQ(thermostr, "Temp"); + free(thermostr); + thermostr = (char *)f_lammps_last_thermo_string(3); + EXPECT_STREQ(thermostr, "E_pair"); + free(thermostr); + thermostr = (char *)f_lammps_last_thermo_string(6); + EXPECT_STREQ(thermostr, "Press"); + free(thermostr); #if defined(LAMMPS_SMALLSMALL) EXPECT_EQ(f_lammps_last_thermo_type(1), multitype::LAMMPS_INT); #else From 5665f29e033c095dbf1b20fe1dcf54be01948dd7 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 20 Aug 2024 09:31:57 -0400 Subject: [PATCH 10/19] move to proper place --- src/pair_hybrid_scaled.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pair_hybrid_scaled.cpp b/src/pair_hybrid_scaled.cpp index 2cacacfd8e..e4ccc0a3ca 100644 --- a/src/pair_hybrid_scaled.cpp +++ b/src/pair_hybrid_scaled.cpp @@ -254,6 +254,7 @@ void PairHybridScaled::settings(int narg, char **arg) delete[] special_coul[m]; } delete[] styles; + delete[] cutmax_style; delete[] keywords; delete[] multiple; delete[] special_lj; @@ -276,7 +277,6 @@ void PairHybridScaled::settings(int narg, char **arg) // allocate list of sub-styles as big as possibly needed if no extra args styles = new Pair *[narg]; - delete[] cutmax_style; cutmax_style = new double[narg]; memset(cutmax_style, 0.0, narg * sizeof(double)); keywords = new char *[narg]; From 72a7634dec102a35890db2aa8ae7d04f5627c374 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 20 Aug 2024 16:31:32 -0400 Subject: [PATCH 11/19] use custom title page --- doc/utils/sphinx-config/conf.py.in | 41 ++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/doc/utils/sphinx-config/conf.py.in b/doc/utils/sphinx-config/conf.py.in index f6db25bea8..27194d4454 100644 --- a/doc/utils/sphinx-config/conf.py.in +++ b/doc/utils/sphinx-config/conf.py.in @@ -336,6 +336,41 @@ latex_elements = { \DeclareMathSymbol{\Psi}{\mathalpha}{extraops}{"09} \DeclareMathSymbol{\Omega}{\mathalpha}{extraops}{"0A} +% customized titlepage +\newcommand{\custommaketitle}{% + \hypersetup{pageanchor=false}% avoid duplicate destination warnings + \begin{titlepage}% + \let\footnotesize\small + \let\footnoterule\relax + \noindent\rule{\textwidth}{1pt}\par + \begingroup % for PDF information dictionary + \def\endgraf{ }\def\and{\& }% + \pdfstringdefDisableCommands{\def\\{, }}% overwrite hyperref setup + \hypersetup{pdfauthor={\@author}, pdftitle={\@title}}% + \endgroup + \begin{center}% + \sphinxlogo + \vfill + {\Huge LAMMPS Documentation \par} + {\LARGE Release 27Jun2024 \par} + \vfill\vfill + {\LARGE + \begin{tabular}[t]{c} + The LAMMPS Developers\\ +\\ + \Large{developers@lammps.org}$^*$\\ + \end{tabular}\kern-\tabcolsep + \par} + \end{center}%\par + \begin{center} +\normalsize{${}^*$ see \hyperref[https://www.lammps.org/authors.html]{https://www.lammps.org/authors.html} for details} +\end{center} + \end{titlepage}% + \setcounter{footnote}{0}% + \clearpage +} + + \renewcommand{\AA}{\mbox{\textrm{\r{A}}}} % Make ToC number fields wider to accommodate sections with >= 100 subsections % or >= 10 subsections with >= 10 subsubsections @@ -349,11 +384,7 @@ latex_elements = { \makeatother ''', 'maketitle': r''' -\pagecolor{black} -\color{white} -\sphinxmaketitle -\nopagecolor -\color{black} +\custommaketitle ''', } From 77f19f1dc9f5d5a11282f84e0513e398e00bfd81 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 20 Aug 2024 21:12:14 -0400 Subject: [PATCH 12/19] small tweak to license text --- doc/src/Intro_opensource.rst | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/doc/src/Intro_opensource.rst b/doc/src/Intro_opensource.rst index fba0a78189..8de0e412f3 100644 --- a/doc/src/Intro_opensource.rst +++ b/doc/src/Intro_opensource.rst @@ -34,18 +34,20 @@ choose, including for commercial purposes. (2) If you **distribute** a modified version of LAMMPS, it must remain open-source, meaning you are required to distribute **all** of it under -the terms of the GPL. You should clearly annotate such a modified code -as a derivative version of LAMMPS. +the terms of the GPLv2. You should **clearly** annotate such a modified +code as a derivative version of LAMMPS. This is best done by changing +the name (example: LIGGGHTS is such a modified and extended version of +LAMMPS). (3) If you release any code that includes or uses LAMMPS source code, -then it must also be open-sourced, meaning you distribute it under -the terms of the GPL. You may write code that interfaces LAMMPS to -a differently licensed library. In that case the code that provides -the interface must be licensed GPL, but not necessarily that library +then it must also be open-sourced, meaning you distribute it under the +terms of the GPLv2. You may write code that interfaces LAMMPS to a +differently licensed library. In that case the code that provides the +interface must be licensed GPLv2, but not necessarily that library unless you are distributing binaries that require the library to run. -(4) If you give LAMMPS files to someone else, the GPL LICENSE file and -source file headers (including the copyright and GPL notices) should +(4) If you give LAMMPS files to someone else, the GPLv2 LICENSE file and +source file headers (including the copyright and GPLv2 notices) should remain part of the code. From 6db454a5e2b404a20204f5ebb59569b2ae850bfc Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 20 Aug 2024 22:37:25 -0400 Subject: [PATCH 13/19] tweak title page some more --- doc/utils/sphinx-config/conf.py.in | 94 ++++++++++++++++-------------- 1 file changed, 49 insertions(+), 45 deletions(-) diff --git a/doc/utils/sphinx-config/conf.py.in b/doc/utils/sphinx-config/conf.py.in index 27194d4454..2256676734 100644 --- a/doc/utils/sphinx-config/conf.py.in +++ b/doc/utils/sphinx-config/conf.py.in @@ -90,6 +90,16 @@ def get_lammps_version(): end_pos = line.find('"', start_pos) return line[start_pos:end_pos] +def get_lammps_update(): + import os + script_dir = os.path.dirname(os.path.realpath(__file__)) + with open(os.path.join(LAMMPS_SOURCE_DIR, 'version.h'), 'r') as f: + line = f.readline() + line = f.readline() + start_pos = line.find('"')+1 + end_pos = line.find('"', start_pos) + return line[start_pos:end_pos] + def get_git_info(): import subprocess,time @@ -290,6 +300,13 @@ rst_prolog = r""" # -- Options for LaTeX output --------------------------------------------- +latex_engine = 'pdflatex' +if (get_lammps_update() == 'Development') or (get_lammps_update() == 'Maintenance'): + lammpsversion = format("\\newcommand{\\lammpsversion}{Git: %s}\n" \ + % (get_git_info())) +else: + lammpsversion = format("\\newcommand{\\lammpsversion}{Release %s %s}\n" \ + % (get_lammps_version(), get_lammps_update())) latex_elements = { # The paper size ('letterpaper' or 'a4paper'). #'papersize': 'letterpaper', @@ -299,7 +316,6 @@ latex_elements = { # Additional stuff for the LaTeX preamble. 'preamble': r''' -\usepackage{xcolor} \setcounter{tocdepth}{2} \setcounter{part}{-1} \renewcommand{\sfdefault}{ptm} % Use Times New Roman font for \textrm @@ -336,41 +352,6 @@ latex_elements = { \DeclareMathSymbol{\Psi}{\mathalpha}{extraops}{"09} \DeclareMathSymbol{\Omega}{\mathalpha}{extraops}{"0A} -% customized titlepage -\newcommand{\custommaketitle}{% - \hypersetup{pageanchor=false}% avoid duplicate destination warnings - \begin{titlepage}% - \let\footnotesize\small - \let\footnoterule\relax - \noindent\rule{\textwidth}{1pt}\par - \begingroup % for PDF information dictionary - \def\endgraf{ }\def\and{\& }% - \pdfstringdefDisableCommands{\def\\{, }}% overwrite hyperref setup - \hypersetup{pdfauthor={\@author}, pdftitle={\@title}}% - \endgroup - \begin{center}% - \sphinxlogo - \vfill - {\Huge LAMMPS Documentation \par} - {\LARGE Release 27Jun2024 \par} - \vfill\vfill - {\LARGE - \begin{tabular}[t]{c} - The LAMMPS Developers\\ -\\ - \Large{developers@lammps.org}$^*$\\ - \end{tabular}\kern-\tabcolsep - \par} - \end{center}%\par - \begin{center} -\normalsize{${}^*$ see \hyperref[https://www.lammps.org/authors.html]{https://www.lammps.org/authors.html} for details} -\end{center} - \end{titlepage}% - \setcounter{footnote}{0}% - \clearpage -} - - \renewcommand{\AA}{\mbox{\textrm{\r{A}}}} % Make ToC number fields wider to accommodate sections with >= 100 subsections % or >= 10 subsections with >= 10 subsubsections @@ -383,8 +364,37 @@ latex_elements = { } \makeatother ''', -'maketitle': r''' -\custommaketitle +'maketitle': lammpsversion + r''' +% customized titlepage +{% + \hypersetup{pageanchor=false}% avoid duplicate destination warnings + \begin{titlepage}% + \sffamily\bfseries + \begingroup % for PDF information dictionary + \def\endgraf{ }\def\and{\& }% + \pdfstringdefDisableCommands{\def\\{, }}% overwrite hyperref setup + \hypersetup{pdfauthor={The LAMMPS Developers}, pdftitle={LAMMPS Documentation}}% + \endgroup + \noindent\rule{\textwidth}{4pt}\par + \begin{center}% + \sphinxlogo + \vfill + {\Huge LAMMPS Documentation \par} + \vfill + {\LARGE \lammpsversion \par} + \vfill + {\LARGE The LAMMPS Developers \par} + {\Large developers@lammps.org $^*$ \par} + \vfill\vfill\vfill + {\normalsize ${}^*$ see + \sphinxhref{https://www.lammps.org/authors.html}{https://www.lammps.org/authors.html} + for details \par} + \end{center} + \noindent\rule{\textwidth}{4pt}\par + \end{titlepage}% + \setcounter{footnote}{0}% + \clearpage +} ''', } @@ -405,19 +415,13 @@ latex_documents = [ # the title page. latex_logo = "_static/lammps-logo-large.jpg" -# For "manual" documents, if this is true, then toplevel headings are parts, -# not chapters. -#latex_use_parts = False latex_toplevel_sectioning = 'part' + # If true, show page references after internal links. #latex_show_pagerefs = False # If true, show URL addresses after external links. latex_show_urls = 'no' -# latex_show_urls = 'footnote' - -# Documents to append as an appendix to all manuals. -#latex_appendices = [] # If false, no module index is generated. latex_domain_indices = False From 64e7e7234ea874f6667a2a5a84a244bd85e7eead Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 20 Aug 2024 22:55:03 -0400 Subject: [PATCH 14/19] work around unavailable git info for PDF title --- doc/utils/sphinx-config/conf.py.in | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/doc/utils/sphinx-config/conf.py.in b/doc/utils/sphinx-config/conf.py.in index 2256676734..e39cacf0c2 100644 --- a/doc/utils/sphinx-config/conf.py.in +++ b/doc/utils/sphinx-config/conf.py.in @@ -107,10 +107,10 @@ def get_git_info(): try: gitinfo = subprocess.run(['git','describe'],stdout=subprocess.PIPE,stderr=subprocess.PIPE) if gitinfo.returncode == 0: - git_n_date = gitinfo.stdout.decode().replace('_',' ').replace('patch ','') + git_n_date = gitinfo.stdout.decode().replace('_',' ').replace('patch ','').replace('stable ','') except: pass - return git_n_date + return git_n_date.strip() def get_git_commit(): import subprocess,time @@ -302,8 +302,11 @@ rst_prolog = r""" latex_engine = 'pdflatex' if (get_lammps_update() == 'Development') or (get_lammps_update() == 'Maintenance'): - lammpsversion = format("\\newcommand{\\lammpsversion}{Git: %s}\n" \ - % (get_git_info())) + if get_git_info() == '': + lammpsversion = format("\\newcommand{\\lammpsversion}{Development %s %s}\n" \ + % (get_lammps_version(), get_lammps_update())) + else: + lammpsversion = format("\\newcommand{\\lammpsversion}{Git: %s}\n" % (get_git_info())) else: lammpsversion = format("\\newcommand{\\lammpsversion}{Release %s %s}\n" \ % (get_lammps_version(), get_lammps_update())) From b65c92e2bbf7a69eb4cce0dc320a919b30ad0b28 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 20 Aug 2024 23:40:02 -0400 Subject: [PATCH 15/19] fix syntax error --- doc/utils/sphinx-config/conf.py.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/utils/sphinx-config/conf.py.in b/doc/utils/sphinx-config/conf.py.in index e39cacf0c2..ca8c7c3523 100644 --- a/doc/utils/sphinx-config/conf.py.in +++ b/doc/utils/sphinx-config/conf.py.in @@ -305,7 +305,7 @@ if (get_lammps_update() == 'Development') or (get_lammps_update() == 'Maintenanc if get_git_info() == '': lammpsversion = format("\\newcommand{\\lammpsversion}{Development %s %s}\n" \ % (get_lammps_version(), get_lammps_update())) - else: + else: lammpsversion = format("\\newcommand{\\lammpsversion}{Git: %s}\n" % (get_git_info())) else: lammpsversion = format("\\newcommand{\\lammpsversion}{Release %s %s}\n" \ From 2746ec609fda5e99b30213d1864d68f9cdbc7811 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 20 Aug 2024 23:55:35 -0400 Subject: [PATCH 16/19] remove unused argument --- tools/lammps-gui/imageviewer.cpp | 2 +- tools/lammps-gui/imageviewer.h | 3 +-- tools/lammps-gui/lammpsgui.cpp | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/tools/lammps-gui/imageviewer.cpp b/tools/lammps-gui/imageviewer.cpp index 67f6dd0e48..ff96967498 100644 --- a/tools/lammps-gui/imageviewer.cpp +++ b/tools/lammps-gui/imageviewer.cpp @@ -133,7 +133,7 @@ static int get_pte_from_mass(double mass) static const QString blank(" "); -ImageViewer::ImageViewer(const QString &fileName, LammpsWrapper *_lammps, QString title, QWidget *parent) : +ImageViewer::ImageViewer(const QString &fileName, LammpsWrapper *_lammps, QWidget *parent) : QDialog(parent), menuBar(new QMenuBar), imageLabel(new QLabel), scrollArea(new QScrollArea), saveAsAct(nullptr), copyAct(nullptr), cmdAct(nullptr), zoomInAct(nullptr), zoomOutAct(nullptr), normalSizeAct(nullptr), lammps(_lammps), group("all"), filename(fileName), useelements(false), diff --git a/tools/lammps-gui/imageviewer.h b/tools/lammps-gui/imageviewer.h index aa2ade2bd9..8e72cea7bf 100644 --- a/tools/lammps-gui/imageviewer.h +++ b/tools/lammps-gui/imageviewer.h @@ -34,8 +34,7 @@ class ImageViewer : public QDialog { Q_OBJECT public: - explicit ImageViewer(const QString &fileName, LammpsWrapper *_lammps, QString title = "", - QWidget *parent = nullptr); + explicit ImageViewer(const QString &fileName, LammpsWrapper *_lammps, QWidget *parent = nullptr); private slots: void saveAs(); diff --git a/tools/lammps-gui/lammpsgui.cpp b/tools/lammps-gui/lammpsgui.cpp index d39e569e3a..32b23c9d12 100644 --- a/tools/lammps-gui/lammpsgui.cpp +++ b/tools/lammps-gui/lammpsgui.cpp @@ -823,8 +823,7 @@ void LammpsGui::inspect_file(const QString &fileName) dataviewer->show(); ilist->data = dataviewer; QFile(infodata).remove(); - auto *inspect_image = new ImageViewer( - fileName, &lammps, QString("LAMMPS-GUI: Image for %1").arg(shortName)); + auto *inspect_image = new ImageViewer(fileName, &lammps); inspect_image->setFont(font()); inspect_image->show(); ilist->image = inspect_image; From e3333bc19dea33ce9ddf66be337140321a3a4531 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 21 Aug 2024 00:01:04 -0400 Subject: [PATCH 17/19] tweak no-git version output --- doc/utils/sphinx-config/conf.py.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/utils/sphinx-config/conf.py.in b/doc/utils/sphinx-config/conf.py.in index ca8c7c3523..31e073c755 100644 --- a/doc/utils/sphinx-config/conf.py.in +++ b/doc/utils/sphinx-config/conf.py.in @@ -303,8 +303,8 @@ rst_prolog = r""" latex_engine = 'pdflatex' if (get_lammps_update() == 'Development') or (get_lammps_update() == 'Maintenance'): if get_git_info() == '': - lammpsversion = format("\\newcommand{\\lammpsversion}{Development %s %s}\n" \ - % (get_lammps_version(), get_lammps_update())) + lammpsversion = format("\\newcommand{\\lammpsversion}{%s %s}\n" \ + % (get_lammps_update(), get_lammps_version())) else: lammpsversion = format("\\newcommand{\\lammpsversion}{Git: %s}\n" % (get_git_info())) else: From cdbec96e0703dab98f16e61d0c6d115baea91844 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 21 Aug 2024 09:00:11 -0400 Subject: [PATCH 18/19] enable and apply clang-format --- src/group.cpp | 727 +++++++++++++++++++++++++------------------------- 1 file changed, 368 insertions(+), 359 deletions(-) diff --git a/src/group.cpp b/src/group.cpp index baf9f377ff..909e741c6b 100644 --- a/src/group.cpp +++ b/src/group.cpp @@ -1,4 +1,3 @@ -// clang-format off /* ---------------------------------------------------------------------- LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator https://www.lammps.org/, Sandia National Laboratories @@ -20,18 +19,18 @@ #include "domain.h" #include "dump.h" #include "error.h" +#include "exceptions.h" #include "fix.h" #include "force.h" #include "input.h" -#include "math_extra.h" #include "math_eigen.h" +#include "math_extra.h" #include "memory.h" #include "modify.h" #include "output.h" #include "region.h" #include "tokenizer.h" #include "variable.h" -#include "exceptions.h" #include #include @@ -43,8 +42,8 @@ using namespace LAMMPS_NS; static constexpr int MAX_GROUP = 32; static constexpr double EPSILON = 1.0e-6; -enum{NONE,TYPE,MOLECULE,ID}; -enum{LT,LE,GT,GE,EQ,NEQ,BETWEEN}; +enum { NONE, TYPE, MOLECULE, ID }; +enum { LT, LE, GT, GE, EQ, NEQ, BETWEEN }; static constexpr double BIG = 1.0e20; @@ -54,9 +53,9 @@ static constexpr double BIG = 1.0e20; Group::Group(LAMMPS *lmp) : Pointers(lmp) { - MPI_Comm_rank(world,&me); + MPI_Comm_rank(world, &me); - names = new char*[MAX_GROUP]; + names = new char *[MAX_GROUP]; bitmask = new int[MAX_GROUP]; inversemask = new int[MAX_GROUP]; dynamic = new int[MAX_GROUP]; @@ -78,11 +77,11 @@ Group::Group(LAMMPS *lmp) : Pointers(lmp) Group::~Group() { - for (int i = 0; i < MAX_GROUP; i++) delete [] names[i]; - delete [] names; - delete [] bitmask; - delete [] inversemask; - delete [] dynamic; + for (int i = 0; i < MAX_GROUP; i++) delete[] names[i]; + delete[] names; + delete[] bitmask; + delete[] inversemask; + delete[] dynamic; } /* ---------------------------------------------------------------------- @@ -93,39 +92,37 @@ void Group::assign(int narg, char **arg) { int i; - if (domain->box_exist == 0) - error->all(FLERR,"Group command before simulation box is defined"); + if (domain->box_exist == 0) error->all(FLERR, "Group command before simulation box is defined"); if (narg < 2) utils::missing_cmd_args(FLERR, "group", error); // delete the group if not being used elsewhere // clear mask of each atom assigned to this group - if (strcmp(arg[1],"delete") == 0) { - if (narg != 2) error->all(FLERR,"Illegal group delete command: too many arguments"); + if (strcmp(arg[1], "delete") == 0) { + if (narg != 2) error->all(FLERR, "Illegal group delete command: too many arguments"); int igroup = find(arg[0]); - if (igroup == -1) error->all(FLERR,"Could not find group delete group ID {}",arg[0]); - if (igroup == 0) error->all(FLERR,"Cannot delete group all"); + if (igroup == -1) error->all(FLERR, "Could not find group delete group ID {}", arg[0]); + if (igroup == 0) error->all(FLERR, "Cannot delete group all"); for (const auto &i : modify->get_fix_list()) if (i->igroup == igroup) - error->all(FLERR,"Cannot delete group {} currently used by fix ID {}",arg[0],i->id); + error->all(FLERR, "Cannot delete group {} currently used by fix ID {}", arg[0], i->id); for (const auto &i : modify->get_compute_list()) if (i->igroup == igroup) - error->all(FLERR,"Cannot delete group {} currently used by compute ID {}",arg[0],i->id); + error->all(FLERR, "Cannot delete group {} currently used by compute ID {}", arg[0], i->id); for (const auto &i : output->get_dump_list()) if (i->igroup == igroup) - error->all(FLERR,"Cannot delete group {} currently used by dump ID {}",arg[0],i->id); - if (atom->firstgroupname && strcmp(arg[0],atom->firstgroupname) == 0) - error->all(FLERR,"Cannot delete group {} currently used by atom_modify first",arg[0]); + error->all(FLERR, "Cannot delete group {} currently used by dump ID {}", arg[0], i->id); + if (atom->firstgroupname && strcmp(arg[0], atom->firstgroupname) == 0) + error->all(FLERR, "Cannot delete group {} currently used by atom_modify first", arg[0]); int *mask = atom->mask; int nlocal = atom->nlocal; int bits = inversemask[igroup]; for (i = 0; i < nlocal; i++) mask[i] &= bits; - if (dynamic[igroup]) - modify->delete_fix(std::string("GROUP_") + names[igroup]); + if (dynamic[igroup]) modify->delete_fix(std::string("GROUP_") + names[igroup]); - delete [] names[igroup]; + delete[] names[igroup]; names[igroup] = nullptr; dynamic[igroup] = 0; ngroup--; @@ -135,10 +132,10 @@ void Group::assign(int narg, char **arg) // clear the group - if (strcmp(arg[1],"clear") == 0) { + if (strcmp(arg[1], "clear") == 0) { int igroup = find(arg[0]); - if (igroup == -1) error->all (FLERR,"Could not find group clear group ID {}",arg[0]); - if (igroup == 0) error->all (FLERR,"Cannot clear group all"); + if (igroup == -1) error->all(FLERR, "Could not find group clear group ID {}", arg[0]); + if (igroup == 0) error->all(FLERR, "Cannot clear group all"); int *mask = atom->mask; int nlocal = atom->nlocal; @@ -155,7 +152,7 @@ void Group::assign(int narg, char **arg) bool created = false; if (igroup == -1) { - if (ngroup == MAX_GROUP) error->all(FLERR,"Too many groups (max {})", MAX_GROUP); + if (ngroup == MAX_GROUP) error->all(FLERR, "Too many groups (max {})", MAX_GROUP); igroup = find_unused(); names[igroup] = utils::strdup(arg[0]); ngroup++; @@ -171,81 +168,96 @@ void Group::assign(int narg, char **arg) // style = region // add to group if atom is in region - if (strcmp(arg[1],"region") == 0) { + if (strcmp(arg[1], "region") == 0) { - if (narg != 3) error->all(FLERR,"Illegal group region command"); + if (narg != 3) error->all(FLERR, "Illegal group region command"); auto region = domain->get_region_by_id(arg[2]); - if (!region) error->all(FLERR,"Region {} for group region does not exist", arg[2]); + if (!region) error->all(FLERR, "Region {} for group region does not exist", arg[2]); region->init(); region->prematch(); for (i = 0; i < nlocal; i++) - if (region->match(x[i][0],x[i][1],x[i][2])) - mask[i] |= bit; + if (region->match(x[i][0], x[i][1], x[i][2])) mask[i] |= bit; - // create an empty group + // create an empty group - } else if (strcmp(arg[1],"empty") == 0) { + } else if (strcmp(arg[1], "empty") == 0) { - if (narg != 2) error->all(FLERR,"Illegal group empty command"); + if (narg != 2) error->all(FLERR, "Illegal group empty command"); // nothing else to do here - // style = type, molecule, id - // add to group if atom matches type/molecule/id or condition + // style = type, molecule, id + // add to group if atom matches type/molecule/id or condition - } else if (strcmp(arg[1],"type") == 0 || strcmp(arg[1],"molecule") == 0 || - strcmp(arg[1],"id") == 0) { + } else if (strcmp(arg[1], "type") == 0 || strcmp(arg[1], "molecule") == 0 || + strcmp(arg[1], "id") == 0) { - if (narg < 3) utils::missing_cmd_args(FLERR, std::string("group ")+arg[1], error); + if (narg < 3) utils::missing_cmd_args(FLERR, std::string("group ") + arg[1], error); - int category=NONE; - if (strcmp(arg[1],"type") == 0) category = TYPE; - else if (strcmp(arg[1],"molecule") == 0) category = MOLECULE; - else if (strcmp(arg[1],"id") == 0) category = ID; + int category = NONE; + if (strcmp(arg[1], "type") == 0) + category = TYPE; + else if (strcmp(arg[1], "molecule") == 0) + category = MOLECULE; + else if (strcmp(arg[1], "id") == 0) + category = ID; if ((category == MOLECULE) && (!atom->molecule_flag)) - error->all(FLERR,"Group molecule command requires atom attribute molecule"); + error->all(FLERR, "Group molecule command requires atom attribute molecule"); if ((category == ID) && (!atom->tag_enable)) - error->all(FLERR,"Group id command requires atom IDs"); + error->all(FLERR, "Group id command requires atom IDs"); // args = logical condition if (narg > 3 && - (strcmp(arg[2],"<") == 0 || strcmp(arg[2],">") == 0 || - strcmp(arg[2],"<=") == 0 || strcmp(arg[2],">=") == 0 || - strcmp(arg[2],"==") == 0 || strcmp(arg[2],"!=") == 0 || - strcmp(arg[2],"<>") == 0)) { + (strcmp(arg[2], "<") == 0 || strcmp(arg[2], ">") == 0 || strcmp(arg[2], "<=") == 0 || + strcmp(arg[2], ">=") == 0 || strcmp(arg[2], "==") == 0 || strcmp(arg[2], "!=") == 0 || + strcmp(arg[2], "<>") == 0)) { int condition = -1; - if (strcmp(arg[2],"<") == 0) condition = LT; - else if (strcmp(arg[2],"<=") == 0) condition = LE; - else if (strcmp(arg[2],">") == 0) condition = GT; - else if (strcmp(arg[2],">=") == 0) condition = GE; - else if (strcmp(arg[2],"==") == 0) condition = EQ; - else if (strcmp(arg[2],"!=") == 0) condition = NEQ; - else if (strcmp(arg[2],"<>") == 0) condition = BETWEEN; - else error->all(FLERR,"Illegal group command"); + if (strcmp(arg[2], "<") == 0) + condition = LT; + else if (strcmp(arg[2], "<=") == 0) + condition = LE; + else if (strcmp(arg[2], ">") == 0) + condition = GT; + else if (strcmp(arg[2], ">=") == 0) + condition = GE; + else if (strcmp(arg[2], "==") == 0) + condition = EQ; + else if (strcmp(arg[2], "!=") == 0) + condition = NEQ; + else if (strcmp(arg[2], "<>") == 0) + condition = BETWEEN; + else + error->all(FLERR, "Illegal group command"); - tagint bound1,bound2; + tagint bound1, bound2; if (category == TYPE) bound1 = (tagint) utils::expand_type_int(FLERR, arg[3], Atom::ATOM, lmp); - else bound1 = utils::tnumeric(FLERR, arg[3], false, lmp); + else + bound1 = utils::tnumeric(FLERR, arg[3], false, lmp); bound2 = -1; if (condition == BETWEEN) { - if (narg != 5) error->all(FLERR,"Illegal group command"); + if (narg != 5) error->all(FLERR, "Illegal group command"); if (category == TYPE) bound2 = (tagint) utils::expand_type_int(FLERR, arg[4], Atom::ATOM, lmp); - else bound2 = utils::tnumeric(FLERR, arg[4], false, lmp); - } else if (narg != 4) error->all(FLERR,"Illegal group command"); + else + bound2 = utils::tnumeric(FLERR, arg[4], false, lmp); + } else if (narg != 4) + error->all(FLERR, "Illegal group command"); int *attribute = nullptr; tagint *tattribute = nullptr; - if (category == TYPE) attribute = atom->type; - else if (category == MOLECULE) tattribute = atom->molecule; - else if (category == ID) tattribute = atom->tag; + if (category == TYPE) + attribute = atom->type; + else if (category == MOLECULE) + tattribute = atom->molecule; + else if (category == ID) + tattribute = atom->tag; // add to group if meets condition @@ -270,8 +282,7 @@ void Group::assign(int narg, char **arg) if (attribute[i] != bound1) mask[i] |= bit; } else if (condition == BETWEEN) { for (i = 0; i < nlocal; i++) - if (attribute[i] >= bound1 && attribute[i] <= bound2) - mask[i] |= bit; + if (attribute[i] >= bound1 && attribute[i] <= bound2) mask[i] |= bit; } } else { if (condition == LT) { @@ -294,22 +305,24 @@ void Group::assign(int narg, char **arg) if (tattribute[i] != bound1) mask[i] |= bit; } else if (condition == BETWEEN) { for (i = 0; i < nlocal; i++) - if (tattribute[i] >= bound1 && tattribute[i] <= bound2) - mask[i] |= bit; + if (tattribute[i] >= bound1 && tattribute[i] <= bound2) mask[i] |= bit; } } - // args = list of values + // args = list of values } else { int *attribute = nullptr; tagint *tattribute = nullptr; - if (category == TYPE) attribute = atom->type; - else if (category == MOLECULE) tattribute = atom->molecule; - else if (category == ID) tattribute = atom->tag; + if (category == TYPE) + attribute = atom->type; + else if (category == MOLECULE) + tattribute = atom->molecule; + else if (category == ID) + tattribute = atom->tag; char *typestr = nullptr; - tagint start,stop,delta; + tagint start, stop, delta; for (int iarg = 2; iarg < narg; iarg++) { delta = 1; @@ -320,21 +333,21 @@ void Group::assign(int narg, char **arg) } if (typestr == nullptr) { try { - ValueTokenizer values(arg[iarg],":"); + ValueTokenizer values(arg[iarg], ":"); start = values.next_tagint(); - if (utils::strmatch(arg[iarg],"^-?\\d+$")) { + if (utils::strmatch(arg[iarg], "^-?\\d+$")) { stop = start; - } else if (utils::strmatch(arg[iarg],"^-?\\d+:-?\\d+$")) { + } else if (utils::strmatch(arg[iarg], "^-?\\d+:-?\\d+$")) { stop = values.next_tagint(); - } else if (utils::strmatch(arg[iarg],"^-?\\d+:-?\\d+:\\d+$")) { + } else if (utils::strmatch(arg[iarg], "^-?\\d+:-?\\d+:\\d+$")) { stop = values.next_tagint(); delta = values.next_tagint(); - } else throw TokenizerException("Syntax error",""); + } else + throw TokenizerException("Syntax error", ""); } catch (TokenizerException &e) { - error->all(FLERR,"Incorrect range string '{}': {}",arg[iarg],e.what()); + error->all(FLERR, "Incorrect range string '{}': {}", arg[iarg], e.what()); } - if (delta < 1) - error->all(FLERR,"Illegal range increment value"); + if (delta < 1) error->all(FLERR, "Illegal range increment value"); } // add to group if attribute matches value or sequence @@ -342,33 +355,35 @@ void Group::assign(int narg, char **arg) if (attribute) { for (i = 0; i < nlocal; i++) if (attribute[i] >= start && attribute[i] <= stop && - (attribute[i]-start) % delta == 0) mask[i] |= bit; + (attribute[i] - start) % delta == 0) + mask[i] |= bit; } else { for (i = 0; i < nlocal; i++) if (tattribute[i] >= start && tattribute[i] <= stop && - (tattribute[i]-start) % delta == 0) mask[i] |= bit; + (tattribute[i] - start) % delta == 0) + mask[i] |= bit; } } delete[] typestr; } - // style = variable - // add to group if atom-atyle variable is non-zero + // style = variable + // add to group if atom-atyle variable is non-zero - } else if (strcmp(arg[1],"variable") == 0) { + } else if (strcmp(arg[1], "variable") == 0) { int ivar = input->variable->find(arg[2]); - if (ivar < 0) error->all(FLERR,"Variable name {} for group does not exist",arg[2]); + if (ivar < 0) error->all(FLERR, "Variable name {} for group does not exist", arg[2]); if (!input->variable->atomstyle(ivar)) - error->all(FLERR,"Variable {} for group is invalid style",arg[2]); + error->all(FLERR, "Variable {} for group is invalid style", arg[2]); double *aflag; // aflag = evaluation of per-atom variable - memory->create(aflag,nlocal,"group:aflag"); - input->variable->compute_atom(ivar,0,aflag,1,0); + memory->create(aflag, nlocal, "group:aflag"); + input->variable->compute_atom(ivar, 0, aflag, 1, 0); // add to group if per-atom variable evaluated to non-zero @@ -377,34 +392,35 @@ void Group::assign(int narg, char **arg) memory->destroy(aflag); - // style = include + // style = include - } else if (strcmp(arg[1],"include") == 0) { + } else if (strcmp(arg[1], "include") == 0) { - if (narg != 3) error->all(FLERR,"Illegal group include command"); - if (strcmp(arg[2],"molecule") == 0) { + if (narg != 3) error->all(FLERR, "Illegal group include command"); + if (strcmp(arg[2], "molecule") == 0) { if (!atom->molecule_flag) - error->all(FLERR,"Group include molecule command requires atom attribute molecule"); + error->all(FLERR, "Group include molecule command requires atom attribute molecule"); - add_molecules(igroup,bit); + add_molecules(igroup, bit); - } else error->all(FLERR,"Unknown group include keyword {}",arg[2]); + } else + error->all(FLERR, "Unknown group include keyword {}", arg[2]); - // style = subtract + // style = subtract - } else if (strcmp(arg[1],"subtract") == 0) { + } else if (strcmp(arg[1], "subtract") == 0) { if (narg < 4) utils::missing_cmd_args(FLERR, "group subtract", error); - int length = narg-2; + int length = narg - 2; std::vector list(length); int jgroup; for (int iarg = 2; iarg < narg; iarg++) { jgroup = find(arg[iarg]); - if (jgroup == -1) error->all(FLERR,"Group ID {} does not exist", arg[iarg]); - if (dynamic[jgroup]) error->all(FLERR,"Cannot subtract dynamic groups"); - list[iarg-2] = jgroup; + if (jgroup == -1) error->all(FLERR, "Group ID {} does not exist", arg[iarg]); + if (dynamic[jgroup]) error->all(FLERR, "Cannot subtract dynamic groups"); + list[iarg - 2] = jgroup; } // add to group if in 1st group in list @@ -425,21 +441,21 @@ void Group::assign(int narg, char **arg) if (mask[i] & otherbit) mask[i] &= inverse; } - // style = union + // style = union - } else if (strcmp(arg[1],"union") == 0) { + } else if (strcmp(arg[1], "union") == 0) { if (narg < 3) utils::missing_cmd_args(FLERR, "group union", error); - int length = narg-2; + int length = narg - 2; std::vector list(length); int jgroup; for (int iarg = 2; iarg < narg; iarg++) { jgroup = find(arg[iarg]); - if (jgroup == -1) error->all(FLERR,"Group ID {} does not exist",arg[iarg]); - if (dynamic[jgroup]) error->all(FLERR,"Cannot union groups from a dynamic group"); - list[iarg-2] = jgroup; + if (jgroup == -1) error->all(FLERR, "Group ID {} does not exist", arg[iarg]); + if (dynamic[jgroup]) error->all(FLERR, "Cannot union groups from a dynamic group"); + list[iarg - 2] = jgroup; } // add to group if in any other group in list @@ -452,27 +468,26 @@ void Group::assign(int narg, char **arg) if (mask[i] & otherbit) mask[i] |= bit; } - // style = intersect + // style = intersect - } else if (strcmp(arg[1],"intersect") == 0) { + } else if (strcmp(arg[1], "intersect") == 0) { if (narg < 4) utils::missing_cmd_args(FLERR, "group intersect", error); - int length = narg-2; + int length = narg - 2; std::vector list(length); int jgroup; for (int iarg = 2; iarg < narg; iarg++) { jgroup = find(arg[iarg]); - if (jgroup == -1) error->all(FLERR,"Group ID {} does not exist",arg[iarg]); - if (dynamic[jgroup]) - error->all(FLERR,"Cannot intersect groups using a dynamic group"); - list[iarg-2] = jgroup; + if (jgroup == -1) error->all(FLERR, "Group ID {} does not exist", arg[iarg]); + if (dynamic[jgroup]) error->all(FLERR, "Cannot intersect groups using a dynamic group"); + list[iarg - 2] = jgroup; } // add to group if in all groups in list - int otherbit,ok,ilist; + int otherbit, ok, ilist; for (i = 0; i < nlocal; i++) { ok = 1; @@ -483,50 +498,48 @@ void Group::assign(int narg, char **arg) if (ok) mask[i] |= bit; } - // style = dynamic - // create a new FixGroup to dynamically determine atoms in group + // style = dynamic + // create a new FixGroup to dynamically determine atoms in group - } else if (strcmp(arg[1],"dynamic") == 0) { + } else if (strcmp(arg[1], "dynamic") == 0) { - if (narg < 4) error->all(FLERR,"Illegal group command"); - if (strcmp(arg[0],arg[2]) == 0) - error->all(FLERR,"Group dynamic cannot reference itself"); + if (narg < 4) error->all(FLERR, "Illegal group command"); + if (strcmp(arg[0], arg[2]) == 0) error->all(FLERR, "Group dynamic cannot reference itself"); if (find(arg[2]) < 0) - error->all(FLERR,"Group dynamic parent group {} does not exist", arg[2]); - if (igroup == 0) error->all(FLERR,"Group all cannot be made dynamic"); + error->all(FLERR, "Group dynamic parent group {} does not exist", arg[2]); + if (igroup == 0) error->all(FLERR, "Group all cannot be made dynamic"); // if group is already dynamic, delete existing FixGroup - if (dynamic[igroup]) - modify->delete_fix(std::string("GROUP_") + names[igroup]); + if (dynamic[igroup]) modify->delete_fix(std::string("GROUP_") + names[igroup]); dynamic[igroup] = 1; std::string fixcmd = "GROUP_"; - fixcmd += fmt::format("{} {} GROUP",names[igroup],arg[2]); + fixcmd += fmt::format("{} {} GROUP", names[igroup], arg[2]); for (i = 3; i < narg; i++) fixcmd += std::string(" ") + arg[i]; modify->add_fix(fixcmd); - // style = static - // remove dynamic FixGroup if necessary + // style = static + // remove dynamic FixGroup if necessary - } else if (strcmp(arg[1],"static") == 0) { + } else if (strcmp(arg[1], "static") == 0) { - if (narg != 2) error->all(FLERR,"Illegal group static command"); + if (narg != 2) error->all(FLERR, "Illegal group static command"); - if (dynamic[igroup]) - modify->delete_fix(std::string("GROUP_") + names[igroup]); + if (dynamic[igroup]) modify->delete_fix(std::string("GROUP_") + names[igroup]); dynamic[igroup] = 0; - // not a valid group style + // not a valid group style - } else error->all(FLERR,"Unknown group command keyword: {}",arg[1]); + } else + error->all(FLERR, "Unknown group command keyword: {}", arg[1]); - } catch (LAMMPSException & e) { + } catch (LAMMPSException &e) { // undo created group in case of an error if (created) { - delete [] names[igroup]; + delete[] names[igroup]; names[igroup] = nullptr; ngroup--; } @@ -537,17 +550,18 @@ void Group::assign(int narg, char **arg) int n; n = 0; - for (i = 0; i < nlocal; i++) if (mask[i] & bit) n++; + for (i = 0; i < nlocal; i++) + if (mask[i] & bit) n++; double rlocal = n; double all; - MPI_Allreduce(&rlocal,&all,1,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(&rlocal, &all, 1, MPI_DOUBLE, MPI_SUM, world); if (me == 0) { if (dynamic[igroup]) - utils::logmesg(lmp,"dynamic group {} defined\n",names[igroup]); + utils::logmesg(lmp, "dynamic group {} defined\n", names[igroup]); else - utils::logmesg(lmp,"{:.15g} atoms in group {}\n",all,names[igroup]); + utils::logmesg(lmp, "{:.15g} atoms in group {}\n", all, names[igroup]); } } @@ -558,12 +572,10 @@ void Group::assign(int narg, char **arg) void Group::assign(const std::string &groupcmd) { auto args = utils::split_words(groupcmd); - std::vector newarg(args.size()); - int i=0; - for (const auto &arg : args) { - newarg[i++] = (char *)arg.c_str(); - } - assign(args.size(),newarg.data()); + std::vector newarg(args.size()); + int i = 0; + for (const auto &arg : args) { newarg[i++] = (char *) arg.c_str(); } + assign(args.size(), newarg.data()); } /* ---------------------------------------------------------------------- @@ -580,7 +592,7 @@ void Group::create(const std::string &name, int *flag) int igroup = find(name); if (igroup == -1) { - if (ngroup == MAX_GROUP) error->all(FLERR,"Too many groups (max {})", MAX_GROUP); + if (ngroup == MAX_GROUP) error->all(FLERR, "Too many groups (max {})", MAX_GROUP); igroup = find_unused(); names[igroup] = utils::strdup(name); ngroup++; @@ -617,7 +629,7 @@ int Group::find_or_create(const char *name) int igroup = find(name); if (igroup >= 0) return igroup; - if (ngroup == MAX_GROUP) error->all(FLERR,"Too many groups (max {})", MAX_GROUP); + if (ngroup == MAX_GROUP) error->all(FLERR, "Too many groups (max {})", MAX_GROUP); igroup = find_unused(); names[igroup] = utils::strdup(name); ngroup++; @@ -646,7 +658,7 @@ void Group::add_molecules(int /*igroup*/, int bit) { // hash = unique molecule IDs of atoms already in group - hash = new std::map(); + hash = new std::map(); tagint *molecule = atom->molecule; int *mask = atom->mask; @@ -663,14 +675,14 @@ void Group::add_molecules(int /*igroup*/, int bit) int n = hash->size(); tagint *list; - memory->create(list,n,"group:list"); + memory->create(list, n, "group:list"); n = 0; - std::map::iterator pos; + std::map::iterator pos; for (pos = hash->begin(); pos != hash->end(); ++pos) list[n++] = pos->first; molbit = bit; - comm->ring(n,sizeof(tagint),list,1,molring,nullptr,(void *)this); + comm->ring(n, sizeof(tagint), list, 1, molring, nullptr, (void *) this); delete hash; memory->destroy(list); @@ -687,7 +699,7 @@ void Group::molring(int n, char *cbuf, void *ptr) { auto gptr = (Group *) ptr; auto list = (tagint *) cbuf; - std::map *hash = gptr->hash; + std::map *hash = gptr->hash; int nlocal = gptr->atom->nlocal; tagint *molecule = gptr->atom->molecule; int *mask = gptr->atom->mask; @@ -707,7 +719,7 @@ void Group::molring(int n, char *cbuf, void *ptr) void Group::write_restart(FILE *fp) { - fwrite(&ngroup,sizeof(int),1,fp); + fwrite(&ngroup, sizeof(int), 1, fp); // use count to not change restart format with deleted groups // remove this on next major release @@ -715,11 +727,13 @@ void Group::write_restart(FILE *fp) int n; int count = 0; for (int i = 0; i < MAX_GROUP; i++) { - if (names[i]) n = strlen(names[i]) + 1; - else n = 0; - fwrite(&n,sizeof(int),1,fp); + if (names[i]) + n = strlen(names[i]) + 1; + else + n = 0; + fwrite(&n, sizeof(int), 1, fp); if (n) { - fwrite(names[i],sizeof(char),n,fp); + fwrite(names[i], sizeof(char), n, fp); count++; } if (count == ngroup) break; @@ -733,15 +747,15 @@ void Group::write_restart(FILE *fp) void Group::read_restart(FILE *fp) { - int i,n; + int i, n; // delete existing group names // atom masks will be overwritten by reading of restart file - for (i = 0; i < MAX_GROUP; i++) delete [] names[i]; + for (i = 0; i < MAX_GROUP; i++) delete[] names[i]; - if (me == 0) utils::sfread(FLERR,&ngroup,sizeof(int),1,fp,nullptr,error); - MPI_Bcast(&ngroup,1,MPI_INT,0,world); + if (me == 0) utils::sfread(FLERR, &ngroup, sizeof(int), 1, fp, nullptr, error); + MPI_Bcast(&ngroup, 1, MPI_INT, 0, world); // use count to not change restart format with deleted groups // remove this on next major release @@ -752,14 +766,15 @@ void Group::read_restart(FILE *fp) names[i] = nullptr; continue; } - if (me == 0) utils::sfread(FLERR,&n,sizeof(int),1,fp,nullptr,error); - MPI_Bcast(&n,1,MPI_INT,0,world); + if (me == 0) utils::sfread(FLERR, &n, sizeof(int), 1, fp, nullptr, error); + MPI_Bcast(&n, 1, MPI_INT, 0, world); if (n) { names[i] = new char[n]; - if (me == 0) utils::sfread(FLERR,names[i],sizeof(char),n,fp,nullptr,error); - MPI_Bcast(names[i],n,MPI_CHAR,0,world); + if (me == 0) utils::sfread(FLERR, names[i], sizeof(char), n, fp, nullptr, error); + MPI_Bcast(names[i], n, MPI_CHAR, 0, world); count++; - } else names[i] = nullptr; + } else + names[i] = nullptr; } } @@ -775,7 +790,7 @@ bigint Group::count_all() { bigint nme = atom->nlocal; bigint nall; - MPI_Allreduce(&nme,&nall,1,MPI_LMP_BIGINT,MPI_SUM,world); + MPI_Allreduce(&nme, &nall, 1, MPI_LMP_BIGINT, MPI_SUM, world); return nall; } @@ -796,7 +811,7 @@ bigint Group::count(int igroup) bigint nsingle = n; bigint nall; - MPI_Allreduce(&nsingle,&nall,1,MPI_LMP_BIGINT,MPI_SUM,world); + MPI_Allreduce(&nsingle, &nall, 1, MPI_LMP_BIGINT, MPI_SUM, world); return nall; } @@ -815,11 +830,11 @@ bigint Group::count(int igroup, Region *region) int n = 0; for (int i = 0; i < nlocal; i++) - if (mask[i] & groupbit && region->match(x[i][0],x[i][1],x[i][2])) n++; + if (mask[i] & groupbit && region->match(x[i][0], x[i][1], x[i][2])) n++; bigint nsingle = n; bigint nall; - MPI_Allreduce(&nsingle,&nall,1,MPI_LMP_BIGINT,MPI_SUM,world); + MPI_Allreduce(&nsingle, &nall, 1, MPI_LMP_BIGINT, MPI_SUM, world); return nall; } @@ -849,7 +864,7 @@ double Group::mass(int igroup) } double all; - MPI_Allreduce(&one,&all,1,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(&one, &all, 1, MPI_DOUBLE, MPI_SUM, world); return all; } @@ -874,16 +889,14 @@ double Group::mass(int igroup, Region *region) if (rmass) { for (int i = 0; i < nlocal; i++) - if (mask[i] & groupbit && region->match(x[i][0],x[i][1],x[i][2])) - one += rmass[i]; + if (mask[i] & groupbit && region->match(x[i][0], x[i][1], x[i][2])) one += rmass[i]; } else { for (int i = 0; i < nlocal; i++) - if (mask[i] & groupbit && region->match(x[i][0],x[i][1],x[i][2])) - one += mass[type[i]]; + if (mask[i] & groupbit && region->match(x[i][0], x[i][1], x[i][2])) one += mass[type[i]]; } double all; - MPI_Allreduce(&one,&all,1,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(&one, &all, 1, MPI_DOUBLE, MPI_SUM, world); return all; } @@ -904,7 +917,7 @@ double Group::charge(int igroup) if (mask[i] & groupbit) qone += q[i]; double qall; - MPI_Allreduce(&qone,&qall,1,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(&qone, &qall, 1, MPI_DOUBLE, MPI_SUM, world); return qall; } @@ -924,11 +937,10 @@ double Group::charge(int igroup, Region *region) double qone = 0.0; for (int i = 0; i < nlocal; i++) - if (mask[i] & groupbit && region->match(x[i][0],x[i][1],x[i][2])) - qone += q[i]; + if (mask[i] & groupbit && region->match(x[i][0], x[i][1], x[i][2])) qone += q[i]; double qall; - MPI_Allreduce(&qone,&qall,1,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(&qone, &qall, 1, MPI_DOUBLE, MPI_SUM, world); return qall; } @@ -951,12 +963,12 @@ void Group::bounds(int igroup, double *minmax) for (int i = 0; i < nlocal; i++) { if (mask[i] & groupbit) { - extent[0] = MIN(extent[0],x[i][0]); - extent[1] = MAX(extent[1],x[i][0]); - extent[2] = MIN(extent[2],x[i][1]); - extent[3] = MAX(extent[3],x[i][1]); - extent[4] = MIN(extent[4],x[i][2]); - extent[5] = MAX(extent[5],x[i][2]); + extent[0] = MIN(extent[0], x[i][0]); + extent[1] = MAX(extent[1], x[i][0]); + extent[2] = MIN(extent[2], x[i][1]); + extent[3] = MAX(extent[3], x[i][1]); + extent[4] = MIN(extent[4], x[i][2]); + extent[5] = MAX(extent[5], x[i][2]); } } @@ -968,7 +980,7 @@ void Group::bounds(int igroup, double *minmax) extent[2] = -extent[2]; extent[4] = -extent[4]; - MPI_Allreduce(extent,minmax,6,MPI_DOUBLE,MPI_MAX,world); + MPI_Allreduce(extent, minmax, 6, MPI_DOUBLE, MPI_MAX, world); minmax[0] = -minmax[0]; minmax[2] = -minmax[2]; @@ -994,13 +1006,13 @@ void Group::bounds(int igroup, double *minmax, Region *region) int nlocal = atom->nlocal; for (int i = 0; i < nlocal; i++) { - if (mask[i] & groupbit && region->match(x[i][0],x[i][1],x[i][2])) { - extent[0] = MIN(extent[0],x[i][0]); - extent[1] = MAX(extent[1],x[i][0]); - extent[2] = MIN(extent[2],x[i][1]); - extent[3] = MAX(extent[3],x[i][1]); - extent[4] = MIN(extent[4],x[i][2]); - extent[5] = MAX(extent[5],x[i][2]); + if (mask[i] & groupbit && region->match(x[i][0], x[i][1], x[i][2])) { + extent[0] = MIN(extent[0], x[i][0]); + extent[1] = MAX(extent[1], x[i][0]); + extent[2] = MIN(extent[2], x[i][1]); + extent[3] = MAX(extent[3], x[i][1]); + extent[4] = MIN(extent[4], x[i][2]); + extent[5] = MAX(extent[5], x[i][2]); } } @@ -1012,7 +1024,7 @@ void Group::bounds(int igroup, double *minmax, Region *region) extent[2] = -extent[2]; extent[4] = -extent[4]; - MPI_Allreduce(extent,minmax,6,MPI_DOUBLE,MPI_MAX,world); + MPI_Allreduce(extent, minmax, 6, MPI_DOUBLE, MPI_MAX, world); minmax[0] = -minmax[0]; minmax[2] = -minmax[2]; @@ -1048,7 +1060,7 @@ void Group::xcm(int igroup, double masstotal, double *cm) for (int i = 0; i < nlocal; i++) if (mask[i] & groupbit) { massone = rmass[i]; - domain->unmap(x[i],image[i],unwrap); + domain->unmap(x[i], image[i], unwrap); cmone[0] += unwrap[0] * massone; cmone[1] += unwrap[1] * massone; cmone[2] += unwrap[2] * massone; @@ -1057,14 +1069,14 @@ void Group::xcm(int igroup, double masstotal, double *cm) for (int i = 0; i < nlocal; i++) if (mask[i] & groupbit) { massone = mass[type[i]]; - domain->unmap(x[i],image[i],unwrap); + domain->unmap(x[i], image[i], unwrap); cmone[0] += unwrap[0] * massone; cmone[1] += unwrap[1] * massone; cmone[2] += unwrap[2] * massone; } } - MPI_Allreduce(cmone,cm,3,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(cmone, cm, 3, MPI_DOUBLE, MPI_SUM, world); if (masstotal > 0.0) { cm[0] /= masstotal; cm[1] /= masstotal; @@ -1100,25 +1112,25 @@ void Group::xcm(int igroup, double masstotal, double *cm, Region *region) if (rmass) { for (int i = 0; i < nlocal; i++) - if (mask[i] & groupbit && region->match(x[i][0],x[i][1],x[i][2])) { + if (mask[i] & groupbit && region->match(x[i][0], x[i][1], x[i][2])) { massone = rmass[i]; - domain->unmap(x[i],image[i],unwrap); + domain->unmap(x[i], image[i], unwrap); cmone[0] += unwrap[0] * massone; cmone[1] += unwrap[1] * massone; cmone[2] += unwrap[2] * massone; } } else { for (int i = 0; i < nlocal; i++) - if (mask[i] & groupbit && region->match(x[i][0],x[i][1],x[i][2])) { + if (mask[i] & groupbit && region->match(x[i][0], x[i][1], x[i][2])) { massone = mass[type[i]]; - domain->unmap(x[i],image[i],unwrap); + domain->unmap(x[i], image[i], unwrap); cmone[0] += unwrap[0] * massone; cmone[1] += unwrap[1] * massone; cmone[2] += unwrap[2] * massone; } } - MPI_Allreduce(cmone,cm,3,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(cmone, cm, 3, MPI_DOUBLE, MPI_SUM, world); if (masstotal > 0.0) { cm[0] /= masstotal; cm[1] /= masstotal; @@ -1143,28 +1155,28 @@ void Group::vcm(int igroup, double masstotal, double *cm) double *rmass = atom->rmass; int nlocal = atom->nlocal; - double p[3],massone; + double p[3], massone; p[0] = p[1] = p[2] = 0.0; if (rmass) { for (int i = 0; i < nlocal; i++) if (mask[i] & groupbit) { massone = rmass[i]; - p[0] += v[i][0]*massone; - p[1] += v[i][1]*massone; - p[2] += v[i][2]*massone; + p[0] += v[i][0] * massone; + p[1] += v[i][1] * massone; + p[2] += v[i][2] * massone; } } else { for (int i = 0; i < nlocal; i++) if (mask[i] & groupbit) { massone = mass[type[i]]; - p[0] += v[i][0]*massone; - p[1] += v[i][1]*massone; - p[2] += v[i][2]*massone; + p[0] += v[i][0] * massone; + p[1] += v[i][1] * massone; + p[2] += v[i][2] * massone; } } - MPI_Allreduce(p,cm,3,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(p, cm, 3, MPI_DOUBLE, MPI_SUM, world); if (masstotal > 0.0) { cm[0] /= masstotal; cm[1] /= masstotal; @@ -1191,28 +1203,28 @@ void Group::vcm(int igroup, double masstotal, double *cm, Region *region) double *rmass = atom->rmass; int nlocal = atom->nlocal; - double p[3],massone; + double p[3], massone; p[0] = p[1] = p[2] = 0.0; if (rmass) { for (int i = 0; i < nlocal; i++) - if (mask[i] & groupbit && region->match(x[i][0],x[i][1],x[i][2])) { + if (mask[i] & groupbit && region->match(x[i][0], x[i][1], x[i][2])) { massone = rmass[i]; - p[0] += v[i][0]*massone; - p[1] += v[i][1]*massone; - p[2] += v[i][2]*massone; + p[0] += v[i][0] * massone; + p[1] += v[i][1] * massone; + p[2] += v[i][2] * massone; } } else { for (int i = 0; i < nlocal; i++) - if (mask[i] & groupbit && region->match(x[i][0],x[i][1],x[i][2])) { + if (mask[i] & groupbit && region->match(x[i][0], x[i][1], x[i][2])) { massone = mass[type[i]]; - p[0] += v[i][0]*massone; - p[1] += v[i][1]*massone; - p[2] += v[i][2]*massone; + p[0] += v[i][0] * massone; + p[1] += v[i][1] * massone; + p[2] += v[i][2] * massone; } } - MPI_Allreduce(p,cm,3,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(p, cm, 3, MPI_DOUBLE, MPI_SUM, world); if (masstotal > 0.0) { cm[0] /= masstotal; cm[1] /= masstotal; @@ -1242,7 +1254,7 @@ void Group::fcm(int igroup, double *cm) flocal[2] += f[i][2]; } - MPI_Allreduce(flocal,cm,3,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(flocal, cm, 3, MPI_DOUBLE, MPI_SUM, world); } /* ---------------------------------------------------------------------- @@ -1263,13 +1275,13 @@ void Group::fcm(int igroup, double *cm, Region *region) flocal[0] = flocal[1] = flocal[2] = 0.0; for (int i = 0; i < nlocal; i++) - if (mask[i] & groupbit && region->match(x[i][0],x[i][1],x[i][2])) { + if (mask[i] & groupbit && region->match(x[i][0], x[i][1], x[i][2])) { flocal[0] += f[i][0]; flocal[1] += f[i][1]; flocal[2] += f[i][2]; } - MPI_Allreduce(flocal,cm,3,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(flocal, cm, 3, MPI_DOUBLE, MPI_SUM, world); } /* ---------------------------------------------------------------------- @@ -1292,17 +1304,15 @@ double Group::ke(int igroup) if (rmass) { for (int i = 0; i < nlocal; i++) if (mask[i] & groupbit) - one += (v[i][0]*v[i][0] + v[i][1]*v[i][1] + v[i][2]*v[i][2]) * - rmass[i]; + one += (v[i][0] * v[i][0] + v[i][1] * v[i][1] + v[i][2] * v[i][2]) * rmass[i]; } else { for (int i = 0; i < nlocal; i++) if (mask[i] & groupbit) - one += (v[i][0]*v[i][0] + v[i][1]*v[i][1] + v[i][2]*v[i][2]) * - mass[type[i]]; + one += (v[i][0] * v[i][0] + v[i][1] * v[i][1] + v[i][2] * v[i][2]) * mass[type[i]]; } double all; - MPI_Allreduce(&one,&all,1,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(&one, &all, 1, MPI_DOUBLE, MPI_SUM, world); all *= 0.5 * force->mvv2e; return all; } @@ -1328,18 +1338,16 @@ double Group::ke(int igroup, Region *region) if (rmass) { for (int i = 0; i < nlocal; i++) - if (mask[i] & groupbit && region->match(x[i][0],x[i][1],x[i][2])) - one += (v[i][0]*v[i][0] + v[i][1]*v[i][1] + v[i][2]*v[i][2]) * - rmass[i]; + if (mask[i] & groupbit && region->match(x[i][0], x[i][1], x[i][2])) + one += (v[i][0] * v[i][0] + v[i][1] * v[i][1] + v[i][2] * v[i][2]) * rmass[i]; } else { for (int i = 0; i < nlocal; i++) - if (mask[i] & groupbit && region->match(x[i][0],x[i][1],x[i][2])) - one += (v[i][0]*v[i][0] + v[i][1]*v[i][1] + v[i][2]*v[i][2]) * - mass[type[i]]; + if (mask[i] & groupbit && region->match(x[i][0], x[i][1], x[i][2])) + one += (v[i][0] * v[i][0] + v[i][1] * v[i][1] + v[i][2] * v[i][2]) * mass[type[i]]; } double all; - MPI_Allreduce(&one,&all,1,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(&one, &all, 1, MPI_DOUBLE, MPI_SUM, world); all *= 0.5 * force->mvv2e; return all; } @@ -1362,24 +1370,26 @@ double Group::gyration(int igroup, double masstotal, double *cm) double *rmass = atom->rmass; int nlocal = atom->nlocal; - double dx,dy,dz,massone; + double dx, dy, dz, massone; double unwrap[3]; double rg = 0.0; for (int i = 0; i < nlocal; i++) if (mask[i] & groupbit) { - domain->unmap(x[i],image[i],unwrap); + domain->unmap(x[i], image[i], unwrap); dx = unwrap[0] - cm[0]; dy = unwrap[1] - cm[1]; dz = unwrap[2] - cm[2]; - if (rmass) massone = rmass[i]; - else massone = mass[type[i]]; - rg += (dx*dx + dy*dy + dz*dz) * massone; + if (rmass) + massone = rmass[i]; + else + massone = mass[type[i]]; + rg += (dx * dx + dy * dy + dz * dz) * massone; } double rg_all; - MPI_Allreduce(&rg,&rg_all,1,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(&rg, &rg_all, 1, MPI_DOUBLE, MPI_SUM, world); - if (masstotal > 0.0) return sqrt(rg_all/masstotal); + if (masstotal > 0.0) return sqrt(rg_all / masstotal); return 0.0; } @@ -1402,24 +1412,26 @@ double Group::gyration(int igroup, double masstotal, double *cm, Region *region) double *rmass = atom->rmass; int nlocal = atom->nlocal; - double dx,dy,dz,massone; + double dx, dy, dz, massone; double unwrap[3]; double rg = 0.0; for (int i = 0; i < nlocal; i++) - if (mask[i] & groupbit && region->match(x[i][0],x[i][1],x[i][2])) { - domain->unmap(x[i],image[i],unwrap); + if (mask[i] & groupbit && region->match(x[i][0], x[i][1], x[i][2])) { + domain->unmap(x[i], image[i], unwrap); dx = unwrap[0] - cm[0]; dy = unwrap[1] - cm[1]; dz = unwrap[2] - cm[2]; - if (rmass) massone = rmass[i]; - else massone = mass[type[i]]; - rg += (dx*dx + dy*dy + dz*dz) * massone; + if (rmass) + massone = rmass[i]; + else + massone = mass[type[i]]; + rg += (dx * dx + dy * dy + dz * dz) * massone; } double rg_all; - MPI_Allreduce(&rg,&rg_all,1,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(&rg, &rg_all, 1, MPI_DOUBLE, MPI_SUM, world); - if (masstotal > 0.0) return sqrt(rg_all/masstotal); + if (masstotal > 0.0) return sqrt(rg_all / masstotal); return 0.0; } @@ -1442,7 +1454,7 @@ void Group::angmom(int igroup, double *cm, double *lmom) double *rmass = atom->rmass; int nlocal = atom->nlocal; - double dx,dy,dz,massone; + double dx, dy, dz, massone; double unwrap[3]; double p[3]; @@ -1450,18 +1462,20 @@ void Group::angmom(int igroup, double *cm, double *lmom) for (int i = 0; i < nlocal; i++) if (mask[i] & groupbit) { - domain->unmap(x[i],image[i],unwrap); + domain->unmap(x[i], image[i], unwrap); dx = unwrap[0] - cm[0]; dy = unwrap[1] - cm[1]; dz = unwrap[2] - cm[2]; - if (rmass) massone = rmass[i]; - else massone = mass[type[i]]; - p[0] += massone * (dy*v[i][2] - dz*v[i][1]); - p[1] += massone * (dz*v[i][0] - dx*v[i][2]); - p[2] += massone * (dx*v[i][1] - dy*v[i][0]); + if (rmass) + massone = rmass[i]; + else + massone = mass[type[i]]; + p[0] += massone * (dy * v[i][2] - dz * v[i][1]); + p[1] += massone * (dz * v[i][0] - dx * v[i][2]); + p[2] += massone * (dx * v[i][1] - dy * v[i][0]); } - MPI_Allreduce(p,lmom,3,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(p, lmom, 3, MPI_DOUBLE, MPI_SUM, world); } /* ---------------------------------------------------------------------- @@ -1484,26 +1498,28 @@ void Group::angmom(int igroup, double *cm, double *lmom, Region *region) double *rmass = atom->rmass; int nlocal = atom->nlocal; - double dx,dy,dz,massone; + double dx, dy, dz, massone; double unwrap[3]; double p[3]; p[0] = p[1] = p[2] = 0.0; for (int i = 0; i < nlocal; i++) - if (mask[i] & groupbit && region->match(x[i][0],x[i][1],x[i][2])) { - domain->unmap(x[i],image[i],unwrap); + if (mask[i] & groupbit && region->match(x[i][0], x[i][1], x[i][2])) { + domain->unmap(x[i], image[i], unwrap); dx = unwrap[0] - cm[0]; dy = unwrap[1] - cm[1]; dz = unwrap[2] - cm[2]; - if (rmass) massone = rmass[i]; - else massone = mass[type[i]]; - p[0] += massone * (dy*v[i][2] - dz*v[i][1]); - p[1] += massone * (dz*v[i][0] - dx*v[i][2]); - p[2] += massone * (dx*v[i][1] - dy*v[i][0]); + if (rmass) + massone = rmass[i]; + else + massone = mass[type[i]]; + p[0] += massone * (dy * v[i][2] - dz * v[i][1]); + p[1] += massone * (dz * v[i][0] - dx * v[i][2]); + p[2] += massone * (dx * v[i][1] - dy * v[i][0]); } - MPI_Allreduce(p,lmom,3,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(p, lmom, 3, MPI_DOUBLE, MPI_SUM, world); } /* ---------------------------------------------------------------------- @@ -1522,7 +1538,7 @@ void Group::torque(int igroup, double *cm, double *tq) imageint *image = atom->image; int nlocal = atom->nlocal; - double dx,dy,dz; + double dx, dy, dz; double unwrap[3]; double tlocal[3]; @@ -1530,16 +1546,16 @@ void Group::torque(int igroup, double *cm, double *tq) for (int i = 0; i < nlocal; i++) if (mask[i] & groupbit) { - domain->unmap(x[i],image[i],unwrap); + domain->unmap(x[i], image[i], unwrap); dx = unwrap[0] - cm[0]; dy = unwrap[1] - cm[1]; dz = unwrap[2] - cm[2]; - tlocal[0] += dy*f[i][2] - dz*f[i][1]; - tlocal[1] += dz*f[i][0] - dx*f[i][2]; - tlocal[2] += dx*f[i][1] - dy*f[i][0]; + tlocal[0] += dy * f[i][2] - dz * f[i][1]; + tlocal[1] += dz * f[i][0] - dx * f[i][2]; + tlocal[2] += dx * f[i][1] - dy * f[i][0]; } - MPI_Allreduce(tlocal,tq,3,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(tlocal, tq, 3, MPI_DOUBLE, MPI_SUM, world); } /* ---------------------------------------------------------------------- @@ -1559,24 +1575,24 @@ void Group::torque(int igroup, double *cm, double *tq, Region *region) imageint *image = atom->image; int nlocal = atom->nlocal; - double dx,dy,dz; + double dx, dy, dz; double unwrap[3]; double tlocal[3]; tlocal[0] = tlocal[1] = tlocal[2] = 0.0; for (int i = 0; i < nlocal; i++) - if (mask[i] & groupbit && region->match(x[i][0],x[i][1],x[i][2])) { - domain->unmap(x[i],image[i],unwrap); + if (mask[i] & groupbit && region->match(x[i][0], x[i][1], x[i][2])) { + domain->unmap(x[i], image[i], unwrap); dx = unwrap[0] - cm[0]; dy = unwrap[1] - cm[1]; dz = unwrap[2] - cm[2]; - tlocal[0] += dy*f[i][2] - dz*f[i][1]; - tlocal[1] += dz*f[i][0] - dx*f[i][2]; - tlocal[2] += dx*f[i][1] - dy*f[i][0]; + tlocal[0] += dy * f[i][2] - dz * f[i][1]; + tlocal[1] += dz * f[i][0] - dx * f[i][2]; + tlocal[2] += dx * f[i][1] - dy * f[i][0]; } - MPI_Allreduce(tlocal,tq,3,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(tlocal, tq, 3, MPI_DOUBLE, MPI_SUM, world); } /* ---------------------------------------------------------------------- @@ -1586,7 +1602,7 @@ void Group::torque(int igroup, double *cm, double *tq, Region *region) void Group::inertia(int igroup, double *cm, double itensor[3][3]) { - int i,j; + int i, j; int groupbit = bitmask[igroup]; @@ -1598,34 +1614,35 @@ void Group::inertia(int igroup, double *cm, double itensor[3][3]) double *rmass = atom->rmass; int nlocal = atom->nlocal; - double dx,dy,dz,massone; + double dx, dy, dz, massone; double unwrap[3]; double ione[3][3]; for (i = 0; i < 3; i++) - for (j = 0; j < 3; j++) - ione[i][j] = 0.0; + for (j = 0; j < 3; j++) ione[i][j] = 0.0; for (i = 0; i < nlocal; i++) if (mask[i] & groupbit) { - domain->unmap(x[i],image[i],unwrap); + domain->unmap(x[i], image[i], unwrap); dx = unwrap[0] - cm[0]; dy = unwrap[1] - cm[1]; dz = unwrap[2] - cm[2]; - if (rmass) massone = rmass[i]; - else massone = mass[type[i]]; - ione[0][0] += massone * (dy*dy + dz*dz); - ione[1][1] += massone * (dx*dx + dz*dz); - ione[2][2] += massone * (dx*dx + dy*dy); - ione[0][1] -= massone * dx*dy; - ione[1][2] -= massone * dy*dz; - ione[0][2] -= massone * dx*dz; + if (rmass) + massone = rmass[i]; + else + massone = mass[type[i]]; + ione[0][0] += massone * (dy * dy + dz * dz); + ione[1][1] += massone * (dx * dx + dz * dz); + ione[2][2] += massone * (dx * dx + dy * dy); + ione[0][1] -= massone * dx * dy; + ione[1][2] -= massone * dy * dz; + ione[0][2] -= massone * dx * dz; } ione[1][0] = ione[0][1]; ione[2][1] = ione[1][2]; ione[2][0] = ione[0][2]; - MPI_Allreduce(&ione[0][0],&itensor[0][0],9,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(&ione[0][0], &itensor[0][0], 9, MPI_DOUBLE, MPI_SUM, world); } /* ---------------------------------------------------------------------- @@ -1635,7 +1652,7 @@ void Group::inertia(int igroup, double *cm, double itensor[3][3]) void Group::inertia(int igroup, double *cm, double itensor[3][3], Region *region) { - int i,j; + int i, j; int groupbit = bitmask[igroup]; region->prematch(); @@ -1648,34 +1665,35 @@ void Group::inertia(int igroup, double *cm, double itensor[3][3], Region *region double *rmass = atom->rmass; int nlocal = atom->nlocal; - double dx,dy,dz,massone; + double dx, dy, dz, massone; double unwrap[3]; double ione[3][3]; for (i = 0; i < 3; i++) - for (j = 0; j < 3; j++) - ione[i][j] = 0.0; + for (j = 0; j < 3; j++) ione[i][j] = 0.0; for (i = 0; i < nlocal; i++) - if (mask[i] & groupbit && region->match(x[i][0],x[i][1],x[i][2])) { - domain->unmap(x[i],image[i],unwrap); + if (mask[i] & groupbit && region->match(x[i][0], x[i][1], x[i][2])) { + domain->unmap(x[i], image[i], unwrap); dx = unwrap[0] - cm[0]; dy = unwrap[1] - cm[1]; dz = unwrap[2] - cm[2]; - if (rmass) massone = rmass[i]; - else massone = mass[type[i]]; - ione[0][0] += massone * (dy*dy + dz*dz); - ione[1][1] += massone * (dx*dx + dz*dz); - ione[2][2] += massone * (dx*dx + dy*dy); - ione[0][1] -= massone * dx*dy; - ione[1][2] -= massone * dy*dz; - ione[0][2] -= massone * dx*dz; + if (rmass) + massone = rmass[i]; + else + massone = mass[type[i]]; + ione[0][0] += massone * (dy * dy + dz * dz); + ione[1][1] += massone * (dx * dx + dz * dz); + ione[2][2] += massone * (dx * dx + dy * dy); + ione[0][1] -= massone * dx * dy; + ione[1][2] -= massone * dy * dz; + ione[0][2] -= massone * dx * dz; } ione[1][0] = ione[0][1]; ione[2][1] = ione[1][2]; ione[2][0] = ione[0][2]; - MPI_Allreduce(&ione[0][0],&itensor[0][0],9,MPI_DOUBLE,MPI_SUM,world); + MPI_Allreduce(&ione[0][0], &itensor[0][0], 9, MPI_DOUBLE, MPI_SUM, world); } /* ---------------------------------------------------------------------- @@ -1684,17 +1702,16 @@ void Group::inertia(int igroup, double *cm, double itensor[3][3], Region *region void Group::omega(double *angmom, double inertia[3][3], double *w) { - double idiag[3],ex[3],ey[3],ez[3],cross[3]; - double evectors[3][3],inverse[3][3]; + double idiag[3], ex[3], ey[3], ez[3], cross[3]; + double evectors[3][3], inverse[3][3]; // determinant = triple product of rows of inertia matrix - double determinant = inertia[0][0]*inertia[1][1]*inertia[2][2] + - inertia[0][1]*inertia[1][2]*inertia[2][0] + - inertia[0][2]*inertia[1][0]*inertia[2][1] - - inertia[0][0]*inertia[1][2]*inertia[2][1] - - inertia[0][1]*inertia[1][0]*inertia[2][2] - - inertia[2][0]*inertia[1][1]*inertia[0][2]; + double determinant = inertia[0][0] * inertia[1][1] * inertia[2][2] + + inertia[0][1] * inertia[1][2] * inertia[2][0] + + inertia[0][2] * inertia[1][0] * inertia[2][1] - + inertia[0][0] * inertia[1][2] * inertia[2][1] - + inertia[0][1] * inertia[1][0] * inertia[2][2] - inertia[2][0] * inertia[1][1] * inertia[0][2]; // non-singular I matrix // use L = Iw, inverting I to solve for w @@ -1702,37 +1719,29 @@ void Group::omega(double *angmom, double inertia[3][3], double *w) if (determinant > EPSILON) { - inverse[0][0] = inertia[1][1]*inertia[2][2] - inertia[1][2]*inertia[2][1]; - inverse[0][1] = -(inertia[0][1]*inertia[2][2] - - inertia[0][2]*inertia[2][1]); - inverse[0][2] = inertia[0][1]*inertia[1][2] - inertia[0][2]*inertia[1][1]; + inverse[0][0] = inertia[1][1] * inertia[2][2] - inertia[1][2] * inertia[2][1]; + inverse[0][1] = -(inertia[0][1] * inertia[2][2] - inertia[0][2] * inertia[2][1]); + inverse[0][2] = inertia[0][1] * inertia[1][2] - inertia[0][2] * inertia[1][1]; - inverse[1][0] = -(inertia[1][0]*inertia[2][2] - - inertia[1][2]*inertia[2][0]); - inverse[1][1] = inertia[0][0]*inertia[2][2] - inertia[0][2]*inertia[2][0]; - inverse[1][2] = -(inertia[0][0]*inertia[1][2] - - inertia[0][2]*inertia[1][0]); + inverse[1][0] = -(inertia[1][0] * inertia[2][2] - inertia[1][2] * inertia[2][0]); + inverse[1][1] = inertia[0][0] * inertia[2][2] - inertia[0][2] * inertia[2][0]; + inverse[1][2] = -(inertia[0][0] * inertia[1][2] - inertia[0][2] * inertia[1][0]); - inverse[2][0] = inertia[1][0]*inertia[2][1] - inertia[1][1]*inertia[2][0]; - inverse[2][1] = -(inertia[0][0]*inertia[2][1] - - inertia[0][1]*inertia[2][0]); - inverse[2][2] = inertia[0][0]*inertia[1][1] - inertia[0][1]*inertia[1][0]; + inverse[2][0] = inertia[1][0] * inertia[2][1] - inertia[1][1] * inertia[2][0]; + inverse[2][1] = -(inertia[0][0] * inertia[2][1] - inertia[0][1] * inertia[2][0]); + inverse[2][2] = inertia[0][0] * inertia[1][1] - inertia[0][1] * inertia[1][0]; for (int i = 0; i < 3; i++) - for (int j = 0; j < 3; j++) - inverse[i][j] /= determinant; + for (int j = 0; j < 3; j++) inverse[i][j] /= determinant; - w[0] = inverse[0][0]*angmom[0] + inverse[0][1]*angmom[1] + - inverse[0][2]*angmom[2]; - w[1] = inverse[1][0]*angmom[0] + inverse[1][1]*angmom[1] + - inverse[1][2]*angmom[2]; - w[2] = inverse[2][0]*angmom[0] + inverse[2][1]*angmom[1] + - inverse[2][2]*angmom[2]; + w[0] = inverse[0][0] * angmom[0] + inverse[0][1] * angmom[1] + inverse[0][2] * angmom[2]; + w[1] = inverse[1][0] * angmom[0] + inverse[1][1] * angmom[1] + inverse[1][2] * angmom[2]; + w[2] = inverse[2][0] * angmom[0] + inverse[2][1] * angmom[1] + inverse[2][2] * angmom[2]; - // handle (nearly) singular I matrix - // typically due to 2-atom group or linear molecule - // use jacobi3() and angmom_to_omega() to calculate valid omega - // less exact answer than matrix inversion, due to iterative Jacobi method + // handle (nearly) singular I matrix + // typically due to 2-atom group or linear molecule + // use jacobi3() and angmom_to_omega() to calculate valid omega + // less exact answer than matrix inversion, due to iterative Jacobi method } else { int ierror = MathEigen::jacobi3(inertia, idiag, evectors); @@ -1751,21 +1760,21 @@ void Group::omega(double *angmom, double inertia[3][3], double *w) // enforce 3 evectors as a right-handed coordinate system // flip 3rd vector if needed - MathExtra::cross3(ex,ey,cross); - if (MathExtra::dot3(cross,ez) < 0.0) MathExtra::negate3(ez); + MathExtra::cross3(ex, ey, cross); + if (MathExtra::dot3(cross, ez) < 0.0) MathExtra::negate3(ez); // if any principal moment < scaled EPSILON, set to 0.0 double max; - max = MAX(idiag[0],idiag[1]); - max = MAX(max,idiag[2]); + max = MAX(idiag[0], idiag[1]); + max = MAX(max, idiag[2]); - if (idiag[0] < EPSILON*max) idiag[0] = 0.0; - if (idiag[1] < EPSILON*max) idiag[1] = 0.0; - if (idiag[2] < EPSILON*max) idiag[2] = 0.0; + if (idiag[0] < EPSILON * max) idiag[0] = 0.0; + if (idiag[1] < EPSILON * max) idiag[1] = 0.0; + if (idiag[2] < EPSILON * max) idiag[2] = 0.0; // calculate omega using diagonalized inertia matrix - MathExtra::angmom_to_omega(angmom,ex,ey,ez,idiag,w); + MathExtra::angmom_to_omega(angmom, ex, ey, ez, idiag, w); } } From 47b5b2dfa3e6dba0b248b59dfe87a3de6976e97c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 21 Aug 2024 10:34:20 -0400 Subject: [PATCH 19/19] throw error when trying to use neigh_modify exclude with dynamic groups --- doc/src/neigh_modify.rst | 2 ++ src/neighbor.cpp | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/doc/src/neigh_modify.rst b/doc/src/neigh_modify.rst index 63d7221c70..753990c93f 100644 --- a/doc/src/neigh_modify.rst +++ b/doc/src/neigh_modify.rst @@ -271,6 +271,8 @@ The value of the *page* setting must be at least 10x larger than the *one* setting. This ensures neighbor pages are not mostly empty space. +The *exclude group* setting is currently not compatible with dynamic groups. + Related commands """""""""""""""" diff --git a/src/neighbor.cpp b/src/neighbor.cpp index 072240b482..c43f86e7ed 100644 --- a/src/neighbor.cpp +++ b/src/neighbor.cpp @@ -2721,7 +2721,9 @@ void Neighbor::modify_params(int narg, char **arg) if (ex1_group[nex_group] == -1) error->all(FLERR, "Invalid exclude group keyword: group {} not found", arg[iarg+2]); if (ex2_group[nex_group] == -1) - error->all(FLERR, "Invalid exclude group keyword: group {} not found", arg[iarg+3]); + error->all(FLERR, "Invalid exclude group keyword: group {} not found", arg[iarg+3]); + if (group->dynamic[ex1_group[nex_group]] || group->dynamic[ex2_group[nex_group]]) + error->all(FLERR, "Neigh_modify exclude group is not compatible with dynamic groups"); nex_group++; iarg += 4; } else if (strcmp(arg[iarg+1],"molecule/inter") == 0 ||