Skip to content

Commit a3ccf75

Browse files
committed
Passing general attributes through RFI
1 parent 26c5da5 commit a3ccf75

File tree

4 files changed

+55
-30
lines changed

4 files changed

+55
-30
lines changed

example/particle/3d/shear1.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
</Geometry>
1414
<Model>
1515
<Param name="VelocityX" value="1m/s" zone="topwall"/>
16-
<RemoteForceInterface integrator="LAMMPS">
16+
<RemoteForceInterface integrator="LAMMPS" radius="3/m">
1717
units cgs
1818
boundary p f f
1919
newton off # required off for tangential history
@@ -37,7 +37,7 @@
3737
region pack block -1 1 0 1 -1 1
3838

3939
# Insert particles
40-
fix part_1 particle_group particletemplate/sphere 17891 atom_type 1 density constant 1.0 radius constant 0.1
40+
fix part_1 particle_group particletemplate/sphere 17891 atom_type 1 density constant 1.0 radius constant ${radius}
4141
fix dist particle_group particledistribution/discrete 18143 1 part_1 1
4242
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
4343
run 1

src/Handlers/acRemoteForceInterface.cpp

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ int acRemoteForceInterface::Init () {
1515

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

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

3028
std::string element_content;
3129
int node_children = 0;
@@ -44,24 +42,40 @@ int acRemoteForceInterface::ConnectRemoteForceInterface(std::string integrator_)
4442
}
4543
}
4644
if (node_children > 0) solver->lattice->RFI.setVar("content", element_content);
45+
4746
bool stats = false;
4847
std::string stats_prefix = solver->info.outpath;
4948
stats_prefix = stats_prefix + "_RFI";
5049
int stats_iter = 200;
51-
52-
attr = node.attribute("stats");
53-
if (attr) stats = attr.as_bool();
54-
attr = node.attribute("stats_iter");
55-
if (attr) {
56-
stats_iter = solver->units.alt(attr.value());
57-
stats = true;
58-
}
59-
attr = node.attribute("stats_prefix");
60-
if (attr) {
61-
stats_prefix = attr.value();
62-
stats = true;
50+
bool use_box = true;
51+
52+
53+
for (pugi::xml_attribute attr = node.first_attribute(); attr; attr = attr.next_attribute()) {
54+
std::string attr_name = attr.name();
55+
if (attr_name == "integrator") {
56+
// ignore
57+
} else if (attr_name == "stats") {
58+
stats = attr.as_bool();
59+
} else if (attr_name == "stats_iter") {
60+
stats_iter = solver->units.alt(attr.value());
61+
stats = true;
62+
} else if (attr_name == "stats_prefix") {
63+
stats_prefix = attr.value();
64+
stats = true;
65+
} else if (attr_name == "use_box") {
66+
use_box = attr.as_bool();
67+
} else if (attr_name == "omega") {
68+
solver->lattice->RFI_omega = attr.as_bool();
69+
} else if (attr_name == "torque") {
70+
solver->lattice->RFI_torque = attr.as_bool();
71+
} else {
72+
double val = solver->units.alt(attr.value());
73+
char str[STRING_LEN];
74+
sprintf(str, "%.15lg", val);
75+
solver->lattice->RFI.setVar(attr.name(), str);
76+
}
6377
}
64-
78+
6579
if (stats) {
6680
output("Asking for stats on RFI ( %s every %d it)\n", stats_prefix.c_str(), stats_iter);
6781
solver->lattice->RFI.enableStats(stats_prefix.c_str(), stats_iter);
@@ -74,10 +88,6 @@ int acRemoteForceInterface::ConnectRemoteForceInterface(std::string integrator_)
7488
}
7589
integrator = integrator_;
7690

77-
bool use_box = true;
78-
attr = node.attribute("use_box");
79-
if (attr) use_box = attr.as_bool();
80-
8191
if (use_box) {
8292
lbRegion reg = solver->lattice->region;
8393
double px = solver->lattice->px;
@@ -92,15 +102,10 @@ int acRemoteForceInterface::ConnectRemoteForceInterface(std::string integrator_)
92102
pz + reg.dz + reg.nz + PART_MAR_BOX);
93103
}
94104

95-
attr = node.attribute("omega");
96-
if (attr) solver->lattice->RFI_omega = attr.as_bool();
97-
attr = node.attribute("torque");
98-
if (attr) solver->lattice->RFI_torque = attr.as_bool();
99-
100105
MPI_Barrier(MPMD.local);
101106
solver->lattice->RFI.Connect(MPMD.work,inter.work);
102107

103-
return 0;
108+
return 0;
104109
}
105110

106111

src/RemoteForceInterface.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ class RemoteForceInterface {
151151
void setUnits(rfi_real_t meter, rfi_real_t second, rfi_real_t kilogram);
152152
void setVar(const vars_name_t& name, const vars_value_t& value);
153153
bool hasVar(const vars_name_t& name) { return vars.find(name) != vars.end(); };
154+
std::vector<vars_name_t> listVars() {
155+
std::vector<vars_name_t> names;
156+
for (auto it : vars) names.push_back(it.first);
157+
return names;
158+
}
154159
const vars_value_t& getVar(const vars_name_t& name) { return vars[name]; };
155160
inline rfi_real_t& RawData(size_t i, int j) {
156161
if (STORAGE == ArrayOfStructures) {

src/lammps.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,26 @@ int main(int argc, char* argv[]) {
121121
MPI_Abort(MPI_COMM_WORLD, 1);
122122
exit(1);
123123
}
124-
fprintf(fp, "variable timestep equal %.15lg\n", RFI.auto_timestep);
125-
if (RFI.hasVar("output")) {
126-
fprintf(fp, "variable output string %s\n", RFI.getVar("output").c_str());
124+
const std::vector<std::string> var_names = RFI.listVars();
125+
for (const auto& v : var_names) {
126+
if (v == "content") continue;
127+
auto& value = RFI.getVar(v);
128+
bool is_numeric = false;
129+
if (v != "output") {
130+
double val;
131+
int ret, len;
132+
ret = sscanf(value.c_str(),"%lf%n", &val, &len);
133+
if ((ret > 0) && (len == value.size())) {
134+
is_numeric = true;
135+
fprintf(fp, "variable %s equal %.15lg\n", v.c_str(), val);
136+
}
137+
}
138+
if (!is_numeric) fprintf(fp, "variable %s string %s\n", v.c_str(), value.c_str());
127139
}
140+
fprintf(fp, "variable timestep equal %.15lg\n", RFI.auto_timestep);
141+
fprintf(fp, "\n");
128142
fprintf(fp, "%s\n", RFI.getVar("content").c_str());
143+
fprintf(fp, "\n");
129144
fclose(fp);
130145
}
131146
} else {

0 commit comments

Comments
 (0)