Unverified Commit fc216edf authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

simplify create/delete_atoms/bonds

parent ef190962
Loading
Loading
Loading
Loading
+6 −13
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include "create_bonds.h"
#include <mpi.h>
#include <cstring>
#include <string>
#include "atom.h"
#include "domain.h"
#include "force.h"
@@ -30,6 +31,8 @@
#include "group.h"
#include "special.h"
#include "error.h"
#include "utils.h"
#include "fmt/format.h"

using namespace LAMMPS_NS;

@@ -318,19 +321,9 @@ void CreateBonds::many()

  bigint nadd_bonds = atom->nbonds - nbonds_previous;

  if (comm->me == 0) {
    if (screen) {
      fprintf(screen,"Added " BIGINT_FORMAT
              " bonds, new total = " BIGINT_FORMAT "\n",
              nadd_bonds,atom->nbonds);
    }

    if (logfile) {
      fprintf(logfile,"Added " BIGINT_FORMAT
              " bonds, new total = " BIGINT_FORMAT "\n",
              nadd_bonds,atom->nbonds);
    }
  }
  if (comm->me == 0)
    utils::logmesg(lmp,fmt::format("Added {} bonds, new total = {}\n",
                                   nadd_bonds,atom->nbonds));
}

/* ---------------------------------------------------------------------- */
+19 −46
Original line number Diff line number Diff line
@@ -34,8 +34,11 @@
#include "random_mars.h"
#include "memory.h"
#include "error.h"
#include "utils.h"
#include "fmt/format.h"

#include <map>
#include <string>

using namespace LAMMPS_NS;

@@ -176,53 +179,23 @@ void DeleteAtoms::command(int narg, char **arg)
  bigint ndelete_impropers = nimpropers_previous - atom->nimpropers;

  if (comm->me == 0) {
    if (screen) {
      fprintf(screen,"Deleted " BIGINT_FORMAT
              " atoms, new total = " BIGINT_FORMAT "\n",
    std::string mesg = fmt::format("Deleted {} atoms, new total = {}\n",
                                   ndelete,atom->natoms);
    if (bond_flag || mol_flag) {
      if (nbonds_previous)
          fprintf(screen,"Deleted " BIGINT_FORMAT
                  " bonds, new total = " BIGINT_FORMAT "\n",
        mesg += fmt::format("Deleted {} bonds, new total = {}\n",
                            ndelete_bonds,atom->nbonds);
      if (nangles_previous)
          fprintf(screen,"Deleted " BIGINT_FORMAT
                  " angles, new total = " BIGINT_FORMAT "\n",
        mesg += fmt::format("Deleted {} angles, new total = {}\n",
                            ndelete_angles,atom->nangles);
      if (ndihedrals_previous)
          fprintf(screen,"Deleted " BIGINT_FORMAT
                  " dihedrals, new total = " BIGINT_FORMAT "\n",
        mesg += fmt::format("Deleted {} dihedrals, new total = {}\n",
                            ndelete_dihedrals,atom->ndihedrals);
      if (nimpropers_previous)
          fprintf(screen,"Deleted " BIGINT_FORMAT
                  " impropers, new total = " BIGINT_FORMAT "\n",
        mesg += fmt::format("Deleted {} impropers, new total = {}\n",
                            ndelete_impropers,atom->nimpropers);
    }
    }

    if (logfile) {
      fprintf(logfile,"Deleted " BIGINT_FORMAT
              " atoms, new total = " BIGINT_FORMAT "\n",
              ndelete,atom->natoms);
      if (bond_flag || mol_flag) {
        if (nbonds_previous)
          fprintf(logfile,"Deleted " BIGINT_FORMAT
                  " bonds, new total = " BIGINT_FORMAT "\n",
                  ndelete_bonds,atom->nbonds);
        if (nangles_previous)
          fprintf(logfile,"Deleted " BIGINT_FORMAT
                  " angles, new total = " BIGINT_FORMAT "\n",
                  ndelete_angles,atom->nangles);
        if (ndihedrals_previous)
          fprintf(logfile,"Deleted " BIGINT_FORMAT
                  " dihedrals, new total = " BIGINT_FORMAT "\n",
                  ndelete_dihedrals,atom->ndihedrals);
        if (nimpropers_previous)
          fprintf(logfile,"Deleted " BIGINT_FORMAT
                  " impropers, new total = " BIGINT_FORMAT "\n",
                  ndelete_impropers,atom->nimpropers);
      }
    }
    utils::logmesg(lmp,mesg);
  }
}

+22 −44
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
#include <mpi.h>
#include <cstdlib>
#include <cstring>
#include <string>
#include "atom.h"
#include "atom_vec.h"
#include "domain.h"
@@ -23,6 +24,8 @@
#include "group.h"
#include "special.h"
#include "error.h"
#include "utils.h"
#include "fmt/format.h"

using namespace LAMMPS_NS;

@@ -535,50 +538,25 @@ void DeleteBonds::command(int narg, char **arg)
  }

  if (comm->me == 0) {
    if (atom->avec->bonds_allow) {
      if (screen) fprintf(screen,
                          "  " BIGINT_FORMAT " total bonds, " BIGINT_FORMAT
                          " turned on, " BIGINT_FORMAT " turned off\n",
                          atom->nbonds,bond_on,bond_off);
      if (logfile) fprintf(logfile,
                           "  " BIGINT_FORMAT " total bonds, " BIGINT_FORMAT
                           " turned on, " BIGINT_FORMAT " turned off\n",
                           atom->nbonds,bond_on,bond_off);
    }
    if (atom->avec->angles_allow) {
      if (screen) fprintf(screen,
                          "  " BIGINT_FORMAT " total angles, " BIGINT_FORMAT
                          " turned on, " BIGINT_FORMAT " turned off\n",
                          atom->nangles,angle_on,angle_off);
      if (logfile) fprintf(logfile,
                          "  " BIGINT_FORMAT " total angles, " BIGINT_FORMAT
                           " turned on, " BIGINT_FORMAT " turned off\n",
                           atom->nangles,angle_on,angle_off);
    }
    if (atom->avec->dihedrals_allow) {
      if (screen) fprintf(screen,
                          "  " BIGINT_FORMAT " total dihedrals, "
                          BIGINT_FORMAT " turned on, " BIGINT_FORMAT
                          " turned off\n",
                          atom->ndihedrals,dihedral_on,dihedral_off);
      if (logfile) fprintf(logfile,
                          "  " BIGINT_FORMAT " total dihedrals, "
                          BIGINT_FORMAT " turned on, " BIGINT_FORMAT
                          " turned off\n",
                          atom->ndihedrals,dihedral_on,dihedral_off);
    }
    if (atom->avec->impropers_allow) {
      if (screen) fprintf(screen,
                          "  " BIGINT_FORMAT " total impropers, "
                          BIGINT_FORMAT " turned on, " BIGINT_FORMAT
                          " turned off\n",
                          atom->nimpropers,improper_on,improper_off);
      if (logfile) fprintf(logfile,
                          "  " BIGINT_FORMAT " total impropers, "
                          BIGINT_FORMAT " turned on, " BIGINT_FORMAT
                          " turned off\n",
                          atom->nimpropers,improper_on,improper_off);
    }
    if (atom->avec->bonds_allow)
      utils::logmesg(lmp,fmt::format("  {} total bonds, "
                                     "{} turned on, {} turned off\n",
                                     atom->nbonds,bond_on,bond_off));

    if (atom->avec->angles_allow)
      utils::logmesg(lmp,fmt::format("  {} total angles, "
                                     "{} turned on, {} turned off\n",
                                     atom->nangles,angle_on,angle_off));

    if (atom->avec->dihedrals_allow)
      utils::logmesg(lmp,fmt::format("  {} total dihedrals, "
                                     "{} turned on, {} turned off\n",
                                     atom->ndihedrals,dihedral_on,dihedral_off));

    if (atom->avec->impropers_allow)
      utils::logmesg(lmp,fmt::format("  {} total impropers, "
                                     "{} turned on, {} turned off\n",
                                     atom->nimpropers,improper_on,improper_off));
  }

  // re-compute special list if requested