From a3ccf75485512387c32d1131e03b6227eecc10f9 Mon Sep 17 00:00:00 2001 From: L Laniewski-Wollk Date: Mon, 24 Jun 2024 12:11:38 +1000 Subject: [PATCH] Passing general attributes through RFI --- example/particle/3d/shear1.xml | 4 +- src/Handlers/acRemoteForceInterface.cpp | 55 ++++++++++++++----------- src/RemoteForceInterface.h | 5 +++ src/lammps.cpp | 21 ++++++++-- 4 files changed, 55 insertions(+), 30 deletions(-) diff --git a/example/particle/3d/shear1.xml b/example/particle/3d/shear1.xml index 1278dd94..000e9147 100644 --- a/example/particle/3d/shear1.xml +++ b/example/particle/3d/shear1.xml @@ -13,7 +13,7 @@ - + units cgs boundary p f f newton off # required off for tangential history @@ -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 diff --git a/src/Handlers/acRemoteForceInterface.cpp b/src/Handlers/acRemoteForceInterface.cpp index c1198245..ac644a59 100644 --- a/src/Handlers/acRemoteForceInterface.cpp +++ b/src/Handlers/acRemoteForceInterface.cpp @@ -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"); @@ -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; @@ -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); @@ -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; @@ -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; } diff --git a/src/RemoteForceInterface.h b/src/RemoteForceInterface.h index 1dc10912..9d561af5 100644 --- a/src/RemoteForceInterface.h +++ b/src/RemoteForceInterface.h @@ -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 listVars() { + std::vector 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) { diff --git a/src/lammps.cpp b/src/lammps.cpp index 13daf1f3..d57379ff 100644 --- a/src/lammps.cpp +++ b/src/lammps.cpp @@ -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 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 {