Skip to content

Commit

Permalink
Adding vars to RemoteForceInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
llaniewski committed May 20, 2024
1 parent 7270097 commit 576e678
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 9 deletions.
22 changes: 22 additions & 0 deletions src/Handlers/acRemoteForceInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
std::string acRemoteForceInterface::xmlname = "RemoteForceInterface";
#include "../HandlerFactory.h"

#include <sstream>

int acRemoteForceInterface::Init () {
Action::Init();
pugi::xml_attribute attr = node.attribute("integrator");
Expand All @@ -22,6 +24,26 @@ int acRemoteForceInterface::ConnectRemoteForceInterface(std::string integrator_)
solver->lattice->RFI.setUnits(units[0],units[1],units[2]);
solver->lattice->RFI.CanCopeWithUnits(false);

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

Check warning on line 27 in src/Handlers/acRemoteForceInterface.cpp

View check run for this annotation

Codecov / codecov/patch

src/Handlers/acRemoteForceInterface.cpp#L27

Added line #L27 was not covered by tests


std::string element_content;
int node_children = 0;
for (pugi::xml_node par = node.first_child(); par; par = par.next_sibling()) {
node_children ++;
if (node_children > 1) {
ERROR("Only a single element/CDATA allowed inside of a RemoteForceInterface xml element\n");
return -1;

Check warning on line 36 in src/Handlers/acRemoteForceInterface.cpp

View check run for this annotation

Codecov / codecov/patch

src/Handlers/acRemoteForceInterface.cpp#L32-L36

Added lines #L32 - L36 were not covered by tests
}
if ((par.type() == pugi::node_pcdata) || (par.type() == pugi::node_cdata)) {
element_content = par.value();

Check warning on line 39 in src/Handlers/acRemoteForceInterface.cpp

View check run for this annotation

Codecov / codecov/patch

src/Handlers/acRemoteForceInterface.cpp#L38-L39

Added lines #L38 - L39 were not covered by tests
} else {
std::stringstream ss;
par.print(ss);
element_content = ss.str();
}

Check warning on line 44 in src/Handlers/acRemoteForceInterface.cpp

View check run for this annotation

Codecov / codecov/patch

src/Handlers/acRemoteForceInterface.cpp#L41-L44

Added lines #L41 - L44 were not covered by tests
}
if (node_children > 0) solver->lattice->RFI.setVar("content", element_content);

Check warning on line 46 in src/Handlers/acRemoteForceInterface.cpp

View check run for this annotation

Codecov / codecov/patch

src/Handlers/acRemoteForceInterface.cpp#L46

Added line #L46 was not covered by tests
bool stats = false;
std::string stats_prefix = solver->info.outpath;
stats_prefix = stats_prefix + "_RFI";
Expand Down
9 changes: 9 additions & 0 deletions src/RemoteForceInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <stdio.h>
#include <vector>
#include <string>
#include <map>

namespace rfi {

Expand Down Expand Up @@ -94,6 +95,10 @@ class RemoteForceInterface {
std::vector< rfi_real_t > unit;
bool non_trivial_units;
bool can_cope_with_units;
typedef std::string vars_name_t;
typedef std::string vars_value_t;
typedef std::map< vars_name_t, vars_value_t > vars_t;
vars_t vars;
void ISendSizes();
void WSendSizes();
void ISendParticles();
Expand All @@ -114,6 +119,7 @@ class RemoteForceInterface {
public:
int particle_size;
std::string name;
rfi_real_t auto_timestep;
RemoteForceInterface();
~RemoteForceInterface();
void MakeTypes(bool,bool);
Expand Down Expand Up @@ -143,6 +149,9 @@ class RemoteForceInterface {
template <class T> inline std::vector<T> Exchange(std::vector<T> out);
template <class T> inline std::basic_string<T> Exchange(std::basic_string<T> out);
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(); };
const vars_value_t& getVar(const vars_name_t& name) { return vars[name]; };

Check warning on line 154 in src/RemoteForceInterface.h

View check run for this annotation

Codecov / codecov/patch

src/RemoteForceInterface.h#L153-L154

Added lines #L153 - L154 were not covered by tests
inline rfi_real_t& RawData(size_t i, int j) {
if (STORAGE == ArrayOfStructures) {
return tab[i*particle_size + j];
Expand Down
49 changes: 48 additions & 1 deletion src/RemoteForceInterface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

namespace rfi {

const int version = 0x000104;
const int version = 0x000105;

#define safe_MPI_Type_free(datatype) { if ((*datatype) != NULL) MPI_Type_free(datatype); }

Expand Down Expand Up @@ -117,6 +117,7 @@ RemoteForceInterface < TYPE, ROT, STORAGE, rfi_real_t, tab_allocator >::RemoteFo
base_units[0] = 1.0;
base_units[1] = 1.0;
base_units[2] = 1.0;
auto_timestep = 1.0;
non_trivial_units = false;
can_cope_with_units = true;
}
Expand Down Expand Up @@ -211,6 +212,15 @@ inline void RemoteForceInterface < TYPE, ROT, STORAGE, rfi_real_t, tab_allocator
non_trivial_units = true;
}

template < rfi_type_t TYPE, rfi_rot_t ROT, rfi_storage_t STORAGE, typename rfi_real_t, typename tab_allocator >
inline void RemoteForceInterface < TYPE, ROT, STORAGE, rfi_real_t, tab_allocator >::setVar(const vars_name_t& name, const vars_value_t& value) {
if (Connected()) {
ERROR("Vars can be set only before connection is established\n");
exit(-1);

Check warning on line 219 in src/RemoteForceInterface.hpp

View check run for this annotation

Codecov / codecov/patch

src/RemoteForceInterface.hpp#L216-L219

Added lines #L216 - L219 were not covered by tests
}
vars[name] = value;
}

Check warning on line 222 in src/RemoteForceInterface.hpp

View check run for this annotation

Codecov / codecov/patch

src/RemoteForceInterface.hpp#L221-L222

Added lines #L221 - L222 were not covered by tests

template < rfi_type_t TYPE, rfi_rot_t ROT, rfi_storage_t STORAGE, typename rfi_real_t, typename tab_allocator >
inline void RemoteForceInterface < TYPE, ROT, STORAGE, rfi_real_t, tab_allocator >::CanCopeWithUnits(bool ccwu_) {
if (Connected()) {
Expand Down Expand Up @@ -362,6 +372,43 @@ int RemoteForceInterface < TYPE, ROT, STORAGE, rfi_real_t, tab_allocator >::Nego
unit[RFI_DATA_FORCE+i] = kilogram*meter/(second*second);
unit[RFI_DATA_MOMENT+i] = kilogram*meter*meter/(second*second);
}
auto_timestep = 1.0/second;

Check warning on line 375 in src/RemoteForceInterface.hpp

View check run for this annotation

Codecov / codecov/patch

src/RemoteForceInterface.hpp#L375

Added line #L375 was not covered by tests
}

typedef std::vector<std::string::value_type> vars_pack_t;
vars_pack_t my_vars, other_vars;
for (vars_t::const_iterator it = vars.begin(); it != vars.end(); it++) {

Check warning on line 380 in src/RemoteForceInterface.hpp

View check run for this annotation

Codecov / codecov/patch

src/RemoteForceInterface.hpp#L380

Added line #L380 was not covered by tests
std::string v;
v = it->first;
for (std::string::const_iterator it2 = v.begin(); it2 != v.end(); it2++) my_vars.push_back(*it2);
my_vars.push_back(0);
v = it->second;
for (std::string::const_iterator it2 = v.begin(); it2 != v.end(); it2++) my_vars.push_back(*it2);
my_vars.push_back(0);

Check warning on line 387 in src/RemoteForceInterface.hpp

View check run for this annotation

Codecov / codecov/patch

src/RemoteForceInterface.hpp#L382-L387

Added lines #L382 - L387 were not covered by tests
}
other_vars = Exchange(my_vars);

Check warning on line 389 in src/RemoteForceInterface.hpp

View check run for this annotation

Codecov / codecov/patch

src/RemoteForceInterface.hpp#L389

Added line #L389 was not covered by tests
bool is_name = true;
std::string buf;
std::string name_buf;
std::string value_buf;
for (vars_pack_t::const_iterator it = other_vars.begin(); it != other_vars.end(); it++) {
if (*it == 0) {
if (is_name) {

Check warning on line 396 in src/RemoteForceInterface.hpp

View check run for this annotation

Codecov / codecov/patch

src/RemoteForceInterface.hpp#L394-L396

Added lines #L394 - L396 were not covered by tests
name_buf = buf;
is_name = false;
} else {
value_buf = buf;
is_name = true;
debug1("RFI: %s: Received: %s = %s\n",name.c_str(), name_buf.c_str(), value_buf.c_str());
if (vars.find(name_buf) != vars.end()) {
debug1("RFI: %s: Variable overwritten.", name.c_str());
}
vars[name_buf] = value_buf;

Check warning on line 406 in src/RemoteForceInterface.hpp

View check run for this annotation

Codecov / codecov/patch

src/RemoteForceInterface.hpp#L406

Added line #L406 was not covered by tests
}
buf.clear();
} else {
buf.push_back(*it);

Check warning on line 410 in src/RemoteForceInterface.hpp

View check run for this annotation

Codecov / codecov/patch

src/RemoteForceInterface.hpp#L410

Added line #L410 was not covered by tests
}
}
}

Expand Down
36 changes: 28 additions & 8 deletions src/simplepart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,11 @@ int main(int argc, char *argv[]) {
wsize.resize(RFI.Workers());
windex.resize(RFI.Workers());
Particles particles;
double dt = 0;
double dt = RFI.auto_timestep;

bool logging = false;
std::string logging_filename;
std::string logging_filename = "";
if (RFI.hasVar("output")) logging_filename = RFI.getVar("output") + "_SP_Log.csv";
int logging_iter = 1;
FILE* logging_f = NULL;
bool avg = false;
Expand All @@ -115,14 +116,33 @@ int main(int argc, char *argv[]) {
for (int i = 0; i < 3; i++) acc_vec[i] = 0.0;
acc_freq = 0.0;

if (argc != 2) {
if (argc < 1 || argc > 2) {
printf("Syntax: simplepart config.xml\n");
printf(" You can omit config.xml if configuration is provided by the force calculator (eg. TCLB xml)\n");
MPI_Abort(MPI_COMM_WORLD,1);
exit(1);
}
char * filename = argv[1];

char * filename = NULL;
if (argc > 1) {
filename = argv[1];
}
pugi::xml_document config;
pugi::xml_parse_result result = config.load_file(filename, pugi::parse_default | pugi::parse_comments);
pugi::xml_parse_result result;
if (filename != NULL) {
if (RFI.hasVar("content")) {
WARNING("Ignoring content (configuration) sent by calculator");
}
result = config.load_file(filename, pugi::parse_default | pugi::parse_comments);
} else {
if (RFI.hasVar("content")) {
result = config.load_string(RFI.getVar("content").c_str(), pugi::parse_default | pugi::parse_comments);
} else {
printf("No configuration provided (either xml file or content from force calculator\n");
MPI_Abort(MPI_COMM_WORLD,1);
exit(1);
}
}
if (!result) {
ERROR("Error while parsing %s: %s\n", filename, result.description());
return -1;
Expand Down Expand Up @@ -200,8 +220,8 @@ int main(int argc, char *argv[]) {
}
for (pugi::xml_attribute attr = node.first_attribute(); attr; attr = attr.next_attribute()) {
std::string attr_name = attr.name();
logging = true;
if (attr_name == "name") {
logging = true;
logging_filename = attr.value();
} else if (attr_name == "Iterations") {
logging_iter = attr.as_int();
Expand All @@ -221,8 +241,8 @@ int main(int argc, char *argv[]) {
return -1;
}
}
if (!logging) {
ERROR("Name not set in '%s' element", node.name());
if (logging && logging_filename == "") {
ERROR("Loggin file name not set in '%s' element", node.name());
return -1;
}
} else {
Expand Down

0 comments on commit 576e678

Please sign in to comment.