add support for region style plugins
This commit is contained in:
@ -14,6 +14,7 @@
|
||||
#include "plugin.h"
|
||||
|
||||
#include "comm.h"
|
||||
#include "domain.h"
|
||||
#include "error.h"
|
||||
#include "input.h"
|
||||
#include "force.h"
|
||||
@ -238,6 +239,16 @@ namespace LAMMPS_NS
|
||||
}
|
||||
(*fix_map)[plugin->name] = (Modify::FixCreator)plugin->creator.v2;
|
||||
|
||||
} else if (pstyle == "region") {
|
||||
auto region_map = lmp->domain->region_map;
|
||||
if (region_map->find(plugin->name) != region_map->end()) {
|
||||
if (lmp->comm->me == 0)
|
||||
lmp->error->warning(FLERR,fmt::format("Overriding built-in region "
|
||||
"style {} from plugin",
|
||||
plugin->name));
|
||||
}
|
||||
(*region_map)[plugin->name] = (Domain::RegionCreator)plugin->creator.v2;
|
||||
|
||||
} else if (pstyle == "command") {
|
||||
auto command_map = lmp->input->command_map;
|
||||
if (command_map->find(plugin->name) != command_map->end()) {
|
||||
@ -271,7 +282,7 @@ namespace LAMMPS_NS
|
||||
if ((strcmp(style,"pair") != 0) && (strcmp(style,"bond") != 0)
|
||||
&& (strcmp(style,"angle") != 0) && (strcmp(style,"dihedral") != 0)
|
||||
&& (strcmp(style,"improper") != 0) && (strcmp(style,"compute") != 0)
|
||||
&& (strcmp(style,"fix") != 0)
|
||||
&& (strcmp(style,"fix") != 0) && (strcmp(style,"region") != 0)
|
||||
&& (strcmp(style,"command") != 0)) {
|
||||
if (me == 0)
|
||||
utils::logmesg(lmp,fmt::format("Ignoring unload: {} is not a "
|
||||
@ -388,6 +399,16 @@ namespace LAMMPS_NS
|
||||
ifix >= 0; ifix = lmp->modify->find_fix_by_style(name))
|
||||
lmp->modify->delete_fix(ifix);
|
||||
|
||||
} else if (pstyle == "region") {
|
||||
|
||||
auto region_map = lmp->domain->region_map;
|
||||
auto found = region_map->find(name);
|
||||
if (found != region_map->end()) region_map->erase(name);
|
||||
|
||||
for (int iregion = lmp->domain->find_region_by_style(name);
|
||||
iregion >= 0; iregion = lmp->domain->find_region_by_style(name))
|
||||
lmp->domain->delete_region(iregion);
|
||||
|
||||
} else if (pstyle == "command") {
|
||||
|
||||
auto command_map = lmp->input->command_map;
|
||||
|
||||
@ -1816,8 +1816,18 @@ void Domain::delete_region(int narg, char **arg)
|
||||
int iregion = find_region(arg[0]);
|
||||
if (iregion == -1) error->all(FLERR,"Delete region ID does not exist");
|
||||
|
||||
delete_region(iregion);
|
||||
}
|
||||
|
||||
void Domain::delete_region(int iregion)
|
||||
{
|
||||
if ((iregion < 0) || (iregion >= nregion)) return;
|
||||
|
||||
// delete and move other Regions down in list one slot
|
||||
|
||||
delete regions[iregion];
|
||||
regions[iregion] = regions[nregion-1];
|
||||
for (int i = iregion+1; iregion < nregion; ++i)
|
||||
regions[i-1] = regions[i];
|
||||
nregion--;
|
||||
}
|
||||
|
||||
@ -1833,6 +1843,18 @@ int Domain::find_region(const std::string &name)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
return region index if name matches existing region style
|
||||
return -1 if no such region
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
int Domain::find_region_by_style(const std::string &name)
|
||||
{
|
||||
for (int iregion = 0; iregion < nregion; iregion++)
|
||||
if (name == regions[iregion]->style) return iregion;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
(re)set boundary settings
|
||||
flag = 0, called from the input script
|
||||
|
||||
@ -130,7 +130,9 @@ class Domain : protected Pointers {
|
||||
void set_lattice(int, char **);
|
||||
void add_region(int, char **);
|
||||
void delete_region(int, char **);
|
||||
void delete_region(int);
|
||||
int find_region(const std::string &);
|
||||
int find_region_by_style(const std::string &);
|
||||
void set_boundary(int, char **, int);
|
||||
void set_box(int, char **);
|
||||
void print_box(const std::string &);
|
||||
|
||||
Reference in New Issue
Block a user