Skip to content

Commit

Permalink
Passing general attributes through RFI
Browse files Browse the repository at this point in the history
  • Loading branch information
llaniewski committed Jun 24, 2024
1 parent 26c5da5 commit a3ccf75
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 30 deletions.
4 changes: 2 additions & 2 deletions example/particle/3d/shear1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</Geometry>
<Model>
<Param name="VelocityX" value="1m/s" zone="topwall"/>
<RemoteForceInterface integrator="LAMMPS">
<RemoteForceInterface integrator="LAMMPS" radius="3/m">
units cgs
boundary p f f
newton off # required off for tangential history
Expand All @@ -37,7 +37,7 @@
region pack block -1 1 0 1 -1 1

# Insert particles
fix part_1 particle_group particletemplate/sphere 17891 atom_type 1 density constant 1.0 radius constant 0.1
fix part_1 particle_group particletemplate/sphere 17891 atom_type 1 density constant 1.0 radius constant ${radius}
fix dist particle_group particledistribution/discrete 18143 1 part_1 1
fix ins particle_group insert/pack seed 100003 distributiontemplate dist maxattempt 500 insert_every once overlapcheck yes all_in yes region pack volumefraction_region 0.30000 check_dist_from_subdomain_border no
run 1
Expand Down
55 changes: 30 additions & 25 deletions src/Handlers/acRemoteForceInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ int acRemoteForceInterface::Init () {

int acRemoteForceInterface::ConnectRemoteForceInterface(std::string integrator_) {
output("Connecting RFI to %s\n",integrator_.c_str());
pugi::xml_attribute attr;
double units[3];
units[0] = solver->units.alt("1m");
units[1] = solver->units.alt("1s");
Expand All @@ -25,7 +24,6 @@ int acRemoteForceInterface::ConnectRemoteForceInterface(std::string integrator_)
solver->lattice->RFI.CanCopeWithUnits(false);

solver->lattice->RFI.setVar("output", solver->info.outpath);


std::string element_content;
int node_children = 0;
Expand All @@ -44,24 +42,40 @@ int acRemoteForceInterface::ConnectRemoteForceInterface(std::string integrator_)
}
}
if (node_children > 0) solver->lattice->RFI.setVar("content", element_content);

bool stats = false;
std::string stats_prefix = solver->info.outpath;
stats_prefix = stats_prefix + "_RFI";
int stats_iter = 200;

attr = node.attribute("stats");
if (attr) stats = attr.as_bool();
attr = node.attribute("stats_iter");
if (attr) {
stats_iter = solver->units.alt(attr.value());
stats = true;
}
attr = node.attribute("stats_prefix");
if (attr) {
stats_prefix = attr.value();
stats = true;
bool use_box = true;


for (pugi::xml_attribute attr = node.first_attribute(); attr; attr = attr.next_attribute()) {
std::string attr_name = attr.name();
if (attr_name == "integrator") {
// ignore
} else if (attr_name == "stats") {
stats = attr.as_bool();
} else if (attr_name == "stats_iter") {
stats_iter = solver->units.alt(attr.value());
stats = true;
} else if (attr_name == "stats_prefix") {
stats_prefix = attr.value();
stats = true;
} else if (attr_name == "use_box") {
use_box = attr.as_bool();
} else if (attr_name == "omega") {
solver->lattice->RFI_omega = attr.as_bool();
} else if (attr_name == "torque") {
solver->lattice->RFI_torque = attr.as_bool();
} else {
double val = solver->units.alt(attr.value());
char str[STRING_LEN];
sprintf(str, "%.15lg", val);
solver->lattice->RFI.setVar(attr.name(), str);
}
}

if (stats) {
output("Asking for stats on RFI ( %s every %d it)\n", stats_prefix.c_str(), stats_iter);
solver->lattice->RFI.enableStats(stats_prefix.c_str(), stats_iter);
Expand All @@ -74,10 +88,6 @@ int acRemoteForceInterface::ConnectRemoteForceInterface(std::string integrator_)
}
integrator = integrator_;

bool use_box = true;
attr = node.attribute("use_box");
if (attr) use_box = attr.as_bool();

if (use_box) {
lbRegion reg = solver->lattice->region;
double px = solver->lattice->px;
Expand All @@ -92,15 +102,10 @@ int acRemoteForceInterface::ConnectRemoteForceInterface(std::string integrator_)
pz + reg.dz + reg.nz + PART_MAR_BOX);
}

attr = node.attribute("omega");
if (attr) solver->lattice->RFI_omega = attr.as_bool();
attr = node.attribute("torque");
if (attr) solver->lattice->RFI_torque = attr.as_bool();

MPI_Barrier(MPMD.local);
solver->lattice->RFI.Connect(MPMD.work,inter.work);

return 0;
return 0;
}


Expand Down
5 changes: 5 additions & 0 deletions src/RemoteForceInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ class RemoteForceInterface {
void setUnits(rfi_real_t meter, rfi_real_t second, rfi_real_t kilogram);
void setVar(const vars_name_t& name, const vars_value_t& value);
bool hasVar(const vars_name_t& name) { return vars.find(name) != vars.end(); };
std::vector<vars_name_t> listVars() {
std::vector<vars_name_t> names;
for (auto it : vars) names.push_back(it.first);
return names;
}
const vars_value_t& getVar(const vars_name_t& name) { return vars[name]; };
inline rfi_real_t& RawData(size_t i, int j) {
if (STORAGE == ArrayOfStructures) {
Expand Down
21 changes: 18 additions & 3 deletions src/lammps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,26 @@ int main(int argc, char* argv[]) {
MPI_Abort(MPI_COMM_WORLD, 1);
exit(1);
}
fprintf(fp, "variable timestep equal %.15lg\n", RFI.auto_timestep);
if (RFI.hasVar("output")) {
fprintf(fp, "variable output string %s\n", RFI.getVar("output").c_str());
const std::vector<std::string> var_names = RFI.listVars();
for (const auto& v : var_names) {
if (v == "content") continue;
auto& value = RFI.getVar(v);
bool is_numeric = false;
if (v != "output") {
double val;
int ret, len;
ret = sscanf(value.c_str(),"%lf%n", &val, &len);
if ((ret > 0) && (len == value.size())) {
is_numeric = true;
fprintf(fp, "variable %s equal %.15lg\n", v.c_str(), val);
}
}
if (!is_numeric) fprintf(fp, "variable %s string %s\n", v.c_str(), value.c_str());
}
fprintf(fp, "variable timestep equal %.15lg\n", RFI.auto_timestep);
fprintf(fp, "\n");
fprintf(fp, "%s\n", RFI.getVar("content").c_str());
fprintf(fp, "\n");
fclose(fp);
}
} else {
Expand Down

0 comments on commit a3ccf75

Please sign in to comment.