diff --git a/.gitmodules b/.gitmodules index 8322ca2..40297e5 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ -[submodule "bmi"] - path = bmi - url = https://github.com/csdms/bmi.git +[submodule "cpp/bmi-cxx"] + path = cpp/bmi-cxx + url = https://github.com/csdms/bmi-cxx.git +[submodule "cpp/bmi-c"] + path = cpp/bmi-c + url = https://github.com/csdms/bmi-c.git diff --git a/.travis.yml b/.travis.yml index d744035..ac19be2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,7 @@ matrix: dist: xenial python: '3.6' install: + - pip install -U pip - pip install -r requirements.txt - python setup.py install - docker pull ewatercycle/walrus-grpc4bmi:v0.3.1 @@ -46,26 +47,28 @@ matrix: before_install: - git submodule update --init - sudo apt-get update - - sudo apt-get install -y build-essential autoconf libtool pkg-config + - sudo apt-get install -y build-essential autoconf libtool pkg-config libunwind-dev - | if [[ ! -f /usr/local/bin/protoc || ! -f /usr/local/bin/grpc_cpp_plugin ]]; then - git clone -b v1.25.0 https://github.com/grpc/grpc + git clone -b v1.27.2 https://github.com/grpc/grpc cd grpc git submodule update --init --recursive - cd third_party/protobuf - ./autogen.sh - ./configure - sudo make -j4 install - cd ../.. + wget -q -O cmake-linux.sh https://github.com/Kitware/CMake/releases/download/v3.16.5/cmake-3.16.5-Linux-x86_64.sh + sudo sh cmake-linux.sh -- --skip-license --prefix=/usr/local + rm cmake-linux.sh + mkdir cmake/build + cd cmake/build + /usr/local/bin/cmake ../.. -DgRPC_INSTALL=ON -DgRPC_SSL_PROVIDER=package -DgRPC_BUILD_TESTS=OFF -DBUILD_SHARED_LIBS=ON sudo make -j4 install + sudo ldconfig cd ${TRAVIS_BUILD_DIR} else echo "using cached builds of protobuf and grpc" fi script: - mkdir -p ${TRAVIS_BUILD_DIR}/cpp/build && cd ${TRAVIS_BUILD_DIR}/cpp/build - - cmake .. - - make + - /usr/local/bin/cmake .. + - make VERBOSE=1 - ctest -V cache: directories: diff --git a/bmi b/bmi deleted file mode 160000 index 5647424..0000000 --- a/bmi +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 564742460b7eb7792904b2e488f0356d79c1f3c2 diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index ed5d4f8..327cac3 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -33,9 +33,8 @@ set(GRPC_SRC_FILES ${CMAKE_CURRENT_BINARY_DIR}/bmi.pb.cc ${CMAKE_CURRENT_BINARY_ set(GRPC_HDR_FILES ${CMAKE_CURRENT_BINARY_DIR}/bmi.pb.h ${CMAKE_CURRENT_BINARY_DIR}/bmi.grpc.pb.h) link_libraries(${PROTOBUF_LIBRARY} ${GRPCPP_UNSECURE} ${GRPC} ${BMIC}) include_directories(${CMAKE_SOURCE_DIR}) -include_directories(${CMAKE_SOURCE_DIR}/../bmi) include_directories(${CMAKE_CURRENT_BINARY_DIR}) -add_library (grpc4bmi SHARED ${CMAKE_SOURCE_DIR}/../bmi/bmi.h ${CMAKE_SOURCE_DIR}/../bmi/bmi.hxx bmi_cpp_extension.h bmi_cpp_extension.cc +add_library (grpc4bmi SHARED bmi-c/bmi.h bmi-cxx/bmi.hxx bmi_cpp_extension.h bmi_cpp_extension.cc bmi_c_wrapper.h bmi_c_wrapper.cc bmi_grpc_server.cc bmi_grpc_server.h ${GRPC_SRC_FILES} ${GRPC_HDR_FILES}) set_target_properties(grpc4bmi PROPERTIES PUBLIC_HEADER "bmi_cpp_extension.h;bmi_c_wrapper.h;bmi_grpc_server.h;${GRPC_HDR_FILES}") add_subdirectory (test) diff --git a/cpp/bmi-c b/cpp/bmi-c new file mode 160000 index 0000000..9b5b34d --- /dev/null +++ b/cpp/bmi-c @@ -0,0 +1 @@ +Subproject commit 9b5b34d7c43a7d8732dc2b245b102bcb505946cf diff --git a/cpp/bmi-cxx b/cpp/bmi-cxx new file mode 160000 index 0000000..46cec3d --- /dev/null +++ b/cpp/bmi-cxx @@ -0,0 +1 @@ +Subproject commit 46cec3de7ce624d9f1f4cffcf00bcf64d27b8d17 diff --git a/cpp/bmi_c_wrapper.cc b/cpp/bmi_c_wrapper.cc index cfb7071..7d6bcc0 100644 --- a/cpp/bmi_c_wrapper.cc +++ b/cpp/bmi_c_wrapper.cc @@ -7,15 +7,15 @@ BmiCWrapper::~BmiCWrapper(){} void checkStatus(int status) { - if(status == BMI_FAILURE) + if(status == bmi::BMI_FAILURE) { throw std::runtime_error("BMI failure from C intercepted"); } } -void BmiCWrapper::Initialize(const char* configfile) +void BmiCWrapper::Initialize(std::string configfile) { - checkStatus(this->model->initialize(this->model->self, const_cast(configfile))); + checkStatus(this->model->initialize(this->model->self, const_cast(configfile.c_str()))); } void BmiCWrapper::Update() @@ -23,12 +23,12 @@ void BmiCWrapper::Update() double curtime, timestep; checkStatus(this->model->get_current_time(this->model->self, &curtime)); checkStatus(this->model->get_time_step(this->model->self, ×tep)); - checkStatus(this->model->update(this->model->self, curtime + timestep)); + checkStatus(this->model->update(this->model->self)); } void BmiCWrapper::UpdateUntil(double time) { - checkStatus(this->model->update(this->model->self, time)); + checkStatus(this->model->update_until(this->model->self, time)); } void BmiCWrapper::Finalize() @@ -36,69 +36,81 @@ void BmiCWrapper::Finalize() checkStatus(this->model->finalize(this->model->self)); } -void BmiCWrapper::GetComponentName(char* const dest) +std::string BmiCWrapper::GetComponentName() { + char* dest; checkStatus(this->model->get_component_name(this->model->self, dest)); + return dest; } -int BmiCWrapper::GetInputVarNameCount() +int BmiCWrapper::GetInputItemCount() { int dest; checkStatus(this->model->get_input_item_count(this->model->self, &dest)); return dest; } -int BmiCWrapper::GetOutputVarNameCount() +int BmiCWrapper::GetOutputItemCount() { int dest; checkStatus(this->model->get_output_item_count(this->model->self, &dest)); return dest; } -void BmiCWrapper::GetInputVarNames(char** dest) +std::vector BmiCWrapper::GetInputVarNames() { + char** dest; checkStatus(this->model->get_input_var_names(this->model->self, dest)); + // TODO convert dest to vector of strings } -void BmiCWrapper::GetOutputVarNames(char** dest) +std::vector BmiCWrapper::GetOutputVarNames() { + char** dest; checkStatus(this->model->get_output_var_names(this->model->self, dest)); + // TODO convert dest to vector of strings } -int BmiCWrapper::GetVarGrid(const char* name) +int BmiCWrapper::GetVarGrid(std::string name) { int dest; - checkStatus(this->model->get_var_grid(this->model->self, const_cast(name), &dest)); + checkStatus(this->model->get_var_grid(this->model->self, const_cast(name.c_str()), &dest)); return dest; } -void BmiCWrapper::GetVarType(const char* name, char* vtype) +std::string BmiCWrapper::GetVarType(std::string name) { - checkStatus(this->model->get_var_type(this->model->self, const_cast(name), vtype)); + char* vtype; + checkStatus(this->model->get_var_type(this->model->self, const_cast(name.c_str()), vtype)); + return vtype; } -int BmiCWrapper::GetVarItemsize(const char* name) +int BmiCWrapper::GetVarItemsize(std::string name) { int dest; - checkStatus(this->model->get_var_itemsize(this->model->self, const_cast(name), &dest)); + checkStatus(this->model->get_var_itemsize(this->model->self, const_cast(name.c_str()), &dest)); return dest; } -void BmiCWrapper::GetVarUnits(const char* name, char* const dest) +std::string BmiCWrapper::GetVarUnits(std::string name) { - checkStatus(this->model->get_var_units(this->model->self, const_cast(name), dest)); + char* dest; + checkStatus(this->model->get_var_units(this->model->self, const_cast(name.c_str()), dest)); + return dest; } -int BmiCWrapper::GetVarNbytes(const char* name) +int BmiCWrapper::GetVarNbytes(std::string name) { int dest; - checkStatus(this->model->get_var_nbytes(this->model->self, const_cast(name), &dest)); + checkStatus(this->model->get_var_nbytes(this->model->self, const_cast(name.c_str()), &dest)); return dest; } -void BmiCWrapper::GetVarLocation(const char* name, char* location) +std::string BmiCWrapper::GetVarLocation(std::string name) { - checkStatus(this->model->get_var_location(this->model->self, const_cast(name), location)); + char* location; + checkStatus(this->model->get_var_location(this->model->self, const_cast(name.c_str()), location)); + return location; } double BmiCWrapper::GetCurrentTime() @@ -122,9 +134,11 @@ double BmiCWrapper::GetEndTime() return dest; } -void BmiCWrapper::GetTimeUnits(char* dest) +std::string BmiCWrapper::GetTimeUnits() { + char* dest; checkStatus(this->model->get_time_units(this->model->self, dest)); + return dest; } double BmiCWrapper::GetTimeStep() @@ -134,32 +148,31 @@ double BmiCWrapper::GetTimeStep() return dest; } -void BmiCWrapper::GetValue(const char* name, void* dest) +void BmiCWrapper::GetValue(std::string name, void* dest) { - checkStatus(this->model->get_value(this->model->self, const_cast(name), dest)); + checkStatus(this->model->get_value(this->model->self, const_cast(name.c_str()), dest)); } -void* BmiCWrapper::GetValuePtr(const char* name) +void* BmiCWrapper::GetValuePtr(std::string name) { void* dest; - checkStatus(this->model->get_value_ptr(this->model->self, const_cast(name), &dest)); + checkStatus(this->model->get_value_ptr(this->model->self, const_cast(name.c_str()), &dest)); return dest; } -void* BmiCWrapper::GetValueAtIndices(const char* name, void* dest, int* pts, int numpts) +void BmiCWrapper::GetValueAtIndices(std::string name, void* dest, int* pts, int numpts) { - checkStatus(this->model->get_value_at_indices(this->model->self, const_cast(name), dest, const_cast(pts), numpts)); - return dest; // Is this the idea? + checkStatus(this->model->get_value_at_indices(this->model->self, const_cast(name.c_str()), dest, const_cast(pts), numpts)); } -void BmiCWrapper::SetValue(const char* name, void* src) +void BmiCWrapper::SetValue(std::string name, void* src) { - checkStatus(this->model->set_value(this->model->self, const_cast(name), src)); + checkStatus(this->model->set_value(this->model->self, const_cast(name.c_str()), src)); } -void BmiCWrapper::SetValueAtIndices(const char* name, void* values, int* pts, int numpts) +void BmiCWrapper::SetValueAtIndices(std::string name, int* pts, int numpts, void* values) { - checkStatus(this->model->set_value_at_indices(this->model->self, const_cast(name), values, pts, numpts)); + checkStatus(this->model->set_value_at_indices(this->model->self, const_cast(name.c_str()), pts, numpts, values)); } int BmiCWrapper::GetGridSize(int id) @@ -176,9 +189,11 @@ int BmiCWrapper::GetGridRank(int id) return dest; } -void BmiCWrapper::GetGridType(int id, char* dest) +std::string BmiCWrapper::GetGridType(int id) { + char* dest; checkStatus(this->model->get_grid_type(this->model->self, id, dest)); + return dest; } void BmiCWrapper::GetGridShape(int id, int* dest) diff --git a/cpp/bmi_c_wrapper.h b/cpp/bmi_c_wrapper.h index 08428e5..31cc5e4 100644 --- a/cpp/bmi_c_wrapper.h +++ b/cpp/bmi_c_wrapper.h @@ -1,10 +1,15 @@ #ifndef BMI_C_WRAPPER_H_INCLUDED #define BMI_C_WRAPPER_H_INCLUDED +#include +#include + #ifndef BMI_INCLUDED #define BMI_INCLUDED -#include "bmi.h" -#include "bmi.hxx" +#include "bmi-c/bmi.h" +#undef BMI_SUCCESS +#undef BMI_FAILURE +#include "bmi-cxx/bmi.hxx" #endif typedef Bmi BMIModel; @@ -16,45 +21,45 @@ class BmiCWrapper: public bmi::Bmi ~BmiCWrapper(); // Model control functions. - virtual void Initialize(const char *config_file) override; + virtual void Initialize(std::string config_file) override; virtual void Update() override; virtual void UpdateUntil(double time) override; virtual void Finalize() override; // Model information functions. - virtual void GetComponentName(char * const name) override; - virtual int GetInputVarNameCount(void) override; - virtual int GetOutputVarNameCount(void) override; - virtual void GetInputVarNames(char **names) override; - virtual void GetOutputVarNames(char **names) override; + virtual std::string GetComponentName() override; + virtual int GetInputItemCount(void) override; + virtual int GetOutputItemCount(void) override; + virtual std::vector GetInputVarNames() override; + virtual std::vector GetOutputVarNames() override; // Variable information functions - virtual int GetVarGrid(const char *name) override; - virtual void GetVarType(const char *name, char *vtype) override; - virtual void GetVarUnits (const char *name, char *units) override; - virtual int GetVarItemsize(const char *name) override; - virtual int GetVarNbytes(const char *name) override; - virtual void GetVarLocation(const char *name, char *location) override; + virtual int GetVarGrid(std::string name) override; + virtual std::string GetVarType(std::string name) override; + virtual std::string GetVarUnits (std::string name) override; + virtual int GetVarItemsize(std::string name) override; + virtual int GetVarNbytes(std::string name) override; + virtual std::string GetVarLocation(std::string name) override; virtual double GetCurrentTime(void) override; virtual double GetStartTime(void) override; virtual double GetEndTime(void) override; - virtual void GetTimeUnits(char *units) override; + virtual std::string GetTimeUnits() override; virtual double GetTimeStep(void) override; // Variable getters - virtual void GetValue(const char *name, void *dest) override; - virtual void *GetValuePtr(const char *name) override; - virtual void *GetValueAtIndices(const char *name, void *dest, int *inds, int count) override; + virtual void GetValue(std::string name, void *dest) override; + virtual void *GetValuePtr(std::string name) override; + virtual void GetValueAtIndices(std::string name, void *dest, int *inds, int count) override; // Variable setters - virtual void SetValue(const char *name, void *values) override; - virtual void SetValueAtIndices(const char *name, void *values, int *inds, int count) override; + virtual void SetValue(std::string name, void *values) override; + virtual void SetValueAtIndices(std::string name, int *inds, int count, void *values) override; // Grid information functions virtual int GetGridRank(const int grid) override; virtual int GetGridSize(const int grid) override; - virtual void GetGridType(const int grid, char *gtype) override; + virtual std::string GetGridType(const int grid) override; virtual void GetGridShape(const int grid, int *shape) override; virtual void GetGridSpacing(const int grid, double *spacing) override; diff --git a/cpp/bmi_cpp_extension.cc b/cpp/bmi_cpp_extension.cc index 95fa4c9..386a0bc 100644 --- a/cpp/bmi_cpp_extension.cc +++ b/cpp/bmi_cpp_extension.cc @@ -6,208 +6,115 @@ BmiCppExtension::BmiCppExtension(){} BmiCppExtension::~BmiCppExtension(){} -void BmiCppExtension::Initialize(const char* configfile) +void BmiCppExtension::GetValue(std::string name, void *dest) { - this->Initialize(std::string(configfile)); -} - -void BmiCppExtension::GetComponentName(char* dest) -{ - std::string s = this->GetComponentName(); - strncpy(dest, s.c_str(), s.size()); - dest[s.size()] = '\0'; -} - -int BmiCppExtension::GetInputVarNameCount() -{ - return this->GetInputVarNames().size(); -} - -int BmiCppExtension::GetOutputVarNameCount() -{ - return this->GetOutputVarNames().size(); -} - -void BmiCppExtension::GetInputVarNames(char** dest) -{ - std::vector src = this->GetInputVarNames(); - for(std::vector::size_type i = 0; i < src.size(); i++) - { - strncpy(dest[i], src[i].c_str(), src[i].size()); - dest[i][src[i].size()] = '\0'; - } -} - -void BmiCppExtension::GetOutputVarNames(char** dest) -{ - std::vector src = this->GetOutputVarNames(); - for(std::vector::size_type i = 0; i < src.size(); i++) - { - strncpy(dest[i], src[i].c_str(), src[i].size()); - dest[i][src[i].size()] = '\0'; - } -} - -void BmiCppExtension::GetVarType(const char* name, char* dest) -{ - std::string type = this->GetVarType(std::string(name)); - strncpy(dest, type.c_str(), type.size()); - dest[type.size()] = '\0'; -} - -int BmiCppExtension::GetVarItemsize(const char* name) -{ - return this->GetVarItemsize(std::string(name)); -} - -int BmiCppExtension::GetVarGrid(const char* name) -{ - return this->GetVarGrid(std::string(name)); -} - -void BmiCppExtension::GetVarUnits(const char* name, char* dest) -{ - std::string units = this->GetVarUnits(std::string(name)); - strncpy(dest, units.c_str(), units.size()); - dest[units.size()] = '\0'; -} - -int BmiCppExtension::GetVarNbytes(const char* name) -{ - return this->GetVarNbytes(std::string(name)); -} - -void BmiCppExtension::GetVarLocation(const char *name, char *dest) -{ - std::string loc = this->GetVarLocation(std::string(name)); - strncpy(dest, loc.c_str(), loc.size()); - dest[loc.size()] = '\0'; -} - -void BmiCppExtension::GetTimeUnits(char* dest) -{ - std::string units = this->GetTimeUnits(); - strncpy(dest, units.c_str(), units.size()); - dest[units.size()] = '\0'; -} - -void BmiCppExtension::GetValue(const char* name, void* dest) -{ - char type = this->FindType(std::string(name)); + char type = this->FindType(name); if(type == 'i') { - std::vector vals = this->GetValueInt(std::string(name)); + std::vector vals = this->GetValueInt(name); memcpy(dest, static_cast(vals.data()), vals.size()*sizeof(int)); } if(type == 'f') { - std::vector vals = this->GetValueFloat(std::string(name)); + std::vector vals = this->GetValueFloat(name); memcpy(dest, static_cast(vals.data()), vals.size()*sizeof(float)); } if(type == 'd') { - std::vector vals = this->GetValueDouble(std::string(name)); + std::vector vals = this->GetValueDouble(name); memcpy(dest, vals.data(), vals.size()*sizeof(double)); } } -void* BmiCppExtension::GetValuePtr(const char* name) +void* BmiCppExtension::GetValuePtr(std::string name) { - char type = this->FindType(std::string(name)); + char type = this->FindType(name); if(type == 'i') { - return static_cast(this->GetValueIntPtr(std::string(name))); + return static_cast(this->GetValueIntPtr(name)); } if(type == 'f') { - return static_cast(this->GetValueFloatPtr(std::string(name))); + return static_cast(this->GetValueFloatPtr(name)); } if(type == 'd') { - return static_cast(this->GetValueDoublePtr(std::string(name))); + return static_cast(this->GetValueDoublePtr(name)); } return NULL; } -void* BmiCppExtension::GetValueAtIndices(const char* name, void* dest, int* pts, int numpts) +void BmiCppExtension::GetValueAtIndices(std::string name, void* dest, int* pts, int numpts) { - char type = this->FindType(std::string(name)); + char type = this->FindType(name); std::vector indices; indices.assign(pts, pts + numpts); if(type == 'i') { - std::vector vals = this->GetValueIntAtIndices(std::string(name), indices); + std::vector vals = this->GetValueIntAtIndices(name, indices); memcpy(dest, static_cast(vals.data()), vals.size()*sizeof(int)); } if(type == 'f') { - std::vector vals = this->GetValueFloatAtIndices(std::string(name), indices); + std::vector vals = this->GetValueFloatAtIndices(name, indices); memcpy(dest, static_cast(vals.data()), vals.size()*sizeof(float)); } if(type == 'd') { - std::vector vals = this->GetValueDoubleAtIndices(std::string(name), indices); + std::vector vals = this->GetValueDoubleAtIndices(name, indices); memcpy(dest, static_cast(vals.data()), vals.size()*sizeof(double)); } - return dest; } -void BmiCppExtension::SetValue(const char* name, void* src) +void BmiCppExtension::SetValue(std::string name, void* src) { - char type = this->FindType(std::string(name)); + char type = this->FindType(name); int nbytes = this->GetVarNbytes(name); if(type == 'i') { std::vector vals; vals.assign(static_cast(src), static_cast(src) + nbytes / sizeof(int)); - this->SetValueInt(std::string(name), vals); + this->SetValueInt(name, vals); } if(type == 'f') { std::vector vals; vals.assign(static_cast(src), static_cast(src) + nbytes / sizeof(float)); - this->SetValueFloat(std::string(name), vals); + this->SetValueFloat(name, vals); } if(type == 'd') { std::vector vals; vals.assign(static_cast(src), static_cast(src) + nbytes / sizeof(double)); - this->SetValueDouble(std::string(name), vals); + this->SetValueDouble(name, vals); } } -void BmiCppExtension::SetValueAtIndices(const char* name, void* src, int* pts, int numpts) +void BmiCppExtension::SetValueAtIndices(std::string name, int* pts, int numpts, void* src) { - char type = this->FindType(std::string(name)); + char type = this->FindType(name); std::vector indices(pts, pts + numpts); if(type == 'i') { std::vector vals; vals.assign(static_cast(src), static_cast(src) + numpts); - this->SetValueIntAtIndices(std::string(name), indices, vals); + this->SetValueIntAtIndices(name, indices, vals); } if(type == 'f') { std::vector vals; vals.assign(static_cast(src), static_cast(src) + numpts); - this->SetValueFloatAtIndices(std::string(name), indices, vals); + this->SetValueFloatAtIndices(name, indices, vals); } if(type == 'd') { std::vector vals; vals.assign(static_cast(src), static_cast(src) + numpts); - this->SetValueDoubleAtIndices(std::string(name), indices, vals); + this->SetValueDoubleAtIndices(name, indices, vals); } } -void BmiCppExtension::GetGridType(int id, char* dest) -{ - std::string type = this->GetGridType(id); - strncpy(dest, type.c_str(), type.size()); - dest[type.size()] = '\0'; -} - void BmiCppExtension::GetGridShape(int id, int* dest) { std::vector shape = this->GetGridShape(id); @@ -268,7 +175,7 @@ void BmiCppExtension::GetGridNodesPerFace(int grid, int *dest) memcpy(dest, x.data(), x.size()*sizeof(double)); } -char BmiCppExtension::FindType(const std::string& varname) const +char BmiCppExtension::FindType(const std::string varname) { std::string vartype = this->GetVarType(varname); std::transform(vartype.begin(), vartype.end(), vartype.begin(), ::tolower); diff --git a/cpp/bmi_cpp_extension.h b/cpp/bmi_cpp_extension.h index 1016cca..9b0e26c 100644 --- a/cpp/bmi_cpp_extension.h +++ b/cpp/bmi_cpp_extension.h @@ -7,8 +7,7 @@ #ifndef BMI_INCLUDED #define BMI_INCLUDED -#include "bmi.h" -#include "bmi.hxx" +#include "bmi-cxx/bmi.hxx" #endif class BmiCppExtension: public bmi::Bmi @@ -17,21 +16,7 @@ class BmiCppExtension: public bmi::Bmi BmiCppExtension(); virtual ~BmiCppExtension(); - virtual void Initialize (const std::string& configfile) = 0; - virtual std::string GetComponentName() const = 0; - virtual std::vector GetInputVarNames() const = 0; - virtual std::vector GetOutputVarNames() const = 0; - - virtual int GetVarGrid(const std::string& name) const = 0; - virtual std::string GetVarType(const std::string& name) const = 0; - virtual int GetVarItemsize(const std::string& name) const = 0; - virtual std::string GetVarUnits(const std::string& name) const = 0; - virtual int GetVarNbytes(const std::string& name) const = 0; - virtual std::string GetVarLocation(const std::string& name) const = 0; - virtual std::string GetTimeUnits() const = 0; - - virtual std::string GetGridType(int id) const = 0; virtual std::vector GetGridShape(int id) const = 0; virtual std::vector GetGridSpacing(int id) const = 0; virtual std::vector GetGridOrigin(int id) const = 0; @@ -45,63 +30,40 @@ class BmiCppExtension: public bmi::Bmi virtual std::vector GetGridFaceNodes(int id) const = 0; virtual std::vector GetGridNodesPerFace(int id) const = 0; - template std::vector GetValue(const std::string& name) + template std::vector GetValue(const std::string name) { - std::vector result(this->GetVarNbytes(name.c_str())/sizeof(T)); - this->GetValue(name.c_str(), (void*)result.data()); + std::vector result(this->GetVarNbytes(name)/sizeof(T)); + this->GetValue(name, (void*)result.data()); return result; } template T* GetValuePtr(const std::string& name) { - return static_cast(this->GetValuePtr(name.c_str())); + return static_cast(this->GetValuePtr(name)); } template std::vector GetValueAtIndices(std::string name, std::vector& indices) { std::vector result(indices.size()); - this->GetValueAtIndices(name.c_str(), (void*)result.data(), indices.data(), indices.size()); + this->GetValueAtIndices(name, (void*)result.data(), indices.data(), indices.size()); return result; } template void SetValue(std::string name, const std::vector& src) { - this->SetValue(name.c_str(), static_cast(src.data())); + this->SetValue(name, static_cast(src.data())); } template void SetValueAtIndices(std::string name, const std::vector& values, std::vector& indices) { - this->SetValueAtIndices(name.c_str(), static_cast(values.data()), indices.data(), indices.size()); + this->SetValueAtIndices(name, indices.data(), indices.size(), static_cast(values.data())); } - // Model control functions. - virtual void Initialize(const char *config_file) override; - - // Model information functions. - virtual void GetComponentName(char * const name) override; - virtual int GetInputVarNameCount() override; - virtual int GetOutputVarNameCount() override; - virtual void GetInputVarNames(char **names) override; - virtual void GetOutputVarNames(char **names) override; - - // Variable information functions - virtual int GetVarGrid(const char *name) override; - virtual void GetVarType(const char *name, char *vtype) override; - virtual void GetVarUnits (const char *name, char *units) override; - virtual int GetVarItemsize(const char *name) override; - virtual int GetVarNbytes(const char *name) override; - virtual void GetVarLocation(const char *name, char *location) override; - - virtual void GetTimeUnits(char *units) override; - // Variable getters - virtual void GetValue(const char *name, void *dest) override; - virtual void *GetValuePtr(const char *name) override; - virtual void *GetValueAtIndices(const char *name, void *dest, int *inds, int count) override; + virtual void GetValue(std::string name, void *dest) override; + virtual void *GetValuePtr(std::string name) override; + virtual void GetValueAtIndices(std::string name, void *dest, int *inds, int count) override; // Variable setters - virtual void SetValue(const char *name, void *values) override; - virtual void SetValueAtIndices(const char *name, void *values, int *inds, int count) override; - - // Grid information functions - virtual void GetGridType(int grid, char *gtype) override; + virtual void SetValue(std::string name, void *src) override; + virtual void SetValueAtIndices(std::string name, int *inds, int count, void *src) override; virtual void GetGridShape(int grid, int *shape) override; virtual void GetGridSpacing(int grid, double *spacing) override; @@ -140,7 +102,7 @@ class BmiCppExtension: public bmi::Bmi private: - char FindType(const std::string& name) const; + char FindType(const std::string name); }; #endif /*BMI_CPP_EXTENSION_H_INCLUDED*/ diff --git a/cpp/bmi_grpc_server.cc b/cpp/bmi_grpc_server.cc index f55cb08..d267f09 100644 --- a/cpp/bmi_grpc_server.cc +++ b/cpp/bmi_grpc_server.cc @@ -36,6 +36,19 @@ grpc::Status BmiGRPCService::update(grpc::ServerContext *context, const bmi::Emp return grpc::Status::OK; } +grpc::Status BmiGRPCService::updateUntil(grpc::ServerContext *context, const bmi::GetTimeResponse *request, bmi::Empty *response) +{ + try + { + this->bmi->UpdateUntil(request->time()); + } + catch (const std::exception &e) + { + return BmiGRPCService::handle_exception(e); + } + return grpc::Status::OK; +} + grpc::Status BmiGRPCService::finalize(grpc::ServerContext *context, const bmi::Empty *request, bmi::Empty *response) { try @@ -53,9 +66,34 @@ grpc::Status BmiGRPCService::getComponentName(grpc::ServerContext *context, cons { try { - char name[BMI_MAX_COMPONENT_NAME]; - this->bmi->GetComponentName(name); - response->set_name(std::string(name)); + std::string name = this->bmi->GetComponentName(); + response->set_name(name); + } + catch (const std::exception &e) + { + return BmiGRPCService::handle_exception(e); + } + return grpc::Status::OK; +} + +grpc::Status BmiGRPCService::getInputItemCount(grpc::ServerContext *context, const bmi::Empty *request, bmi::GetCountResponse *response) +{ + try + { + response->set_count(this->bmi->GetInputItemCount()); + } + catch (const std::exception &e) + { + return BmiGRPCService::handle_exception(e); + } + return grpc::Status::OK; +} + +grpc::Status BmiGRPCService::getOutputItemCount(grpc::ServerContext *context, const bmi::Empty *request, bmi::GetCountResponse *response) +{ + try + { + response->set_count(this->bmi->GetOutputItemCount()); } catch (const std::exception &e) { @@ -66,61 +104,35 @@ grpc::Status BmiGRPCService::getComponentName(grpc::ServerContext *context, cons grpc::Status BmiGRPCService::getInputVarNames(grpc::ServerContext *context, const bmi::Empty *request, bmi::GetVarNamesResponse *response) { - char **input_var_names; - char *data; try { - int count = this->bmi->GetInputVarNameCount(); - input_var_names = (char **)malloc(sizeof(char *) * count); - data = (char *)malloc(sizeof(char) * count * BMI_MAX_VAR_NAME); - for (int i = 0; i < count; i++) + std::vector input_var_names = this->bmi->GetInputVarNames(); + for (int i = 0; i < input_var_names.size(); i++) { - input_var_names[i] = data + i * BMI_MAX_VAR_NAME; - } - this->bmi->GetInputVarNames(input_var_names); - for (int i = 0; i < count; i++) - { - response->add_names(std::string(input_var_names[i])); + response->add_names(input_var_names[i]); } } catch (const std::exception &e) { - free(data); - free(input_var_names); return BmiGRPCService::handle_exception(e); } - free(data); - free(input_var_names); return grpc::Status::OK; } grpc::Status BmiGRPCService::getOutputVarNames(grpc::ServerContext *context, const bmi::Empty *request, bmi::GetVarNamesResponse *response) { - char **output_var_names; - char *data; try { - int count = this->bmi->GetOutputVarNameCount(); - output_var_names = (char **)malloc(sizeof(char *) * count); - data = (char *)malloc(sizeof(char) * count * BMI_MAX_VAR_NAME); - for (int i = 0; i < count; i++) - { - output_var_names[i] = data + i * BMI_MAX_VAR_NAME; - } - this->bmi->GetOutputVarNames(output_var_names); - for (int i = 0; i < count; i++) + std::vector output_var_names = this->bmi->GetOutputVarNames(); + for (int i = 0; i < output_var_names.size(); i++) { response->add_names(std::string(output_var_names[i])); } } catch (const std::exception &e) { - free(data); - free(output_var_names); return BmiGRPCService::handle_exception(e); } - free(data); - free(output_var_names); return grpc::Status::OK; } @@ -128,9 +140,8 @@ grpc::Status BmiGRPCService::getTimeUnits(grpc::ServerContext *context, const bm { try { - char units[BMI_MAX_UNITS_NAME]; - this->bmi->GetTimeUnits(units); - response->set_units(std::string(units)); + std::string units = this->bmi->GetTimeUnits(); + response->set_units(units); } catch (const std::exception &e) { @@ -208,9 +219,8 @@ grpc::Status BmiGRPCService::getVarType(grpc::ServerContext *context, const bmi: { try { - char type[BMI_MAX_VAR_NAME]; - this->bmi->GetVarType(request->name().c_str(), type); - response->set_type(std::string(type)); + std::string type = this->bmi->GetVarType(request->name()); + response->set_type(type); } catch (const std::exception &e) { @@ -236,10 +246,9 @@ grpc::Status BmiGRPCService::getVarLocation(grpc::ServerContext *context, const { try { - char loc[4]; - this->bmi->GetVarLocation(request->name().c_str(), loc); + std::string loc = this->bmi->GetVarLocation(request->name()); bmi::GetVarLocationResponse::Location loce; - bmi::GetVarLocationResponse::Location_Parse(std::string(loc), &loce); + bmi::GetVarLocationResponse::Location_Parse(loc, &loce); response->set_location(loce); } catch (const std::exception &e) @@ -254,9 +263,8 @@ grpc::Status BmiGRPCService::getVarUnits(grpc::ServerContext *context, const bmi { try { - char units[BMI_MAX_UNITS_NAME]; - this->bmi->GetVarUnits(request->name().c_str(), units); - response->set_units(std::string(units)); + std::string units = this->bmi->GetVarUnits(request->name()); + response->set_units(units); } catch (const std::exception &e) { @@ -322,7 +330,6 @@ grpc::Status BmiGRPCService::getValuePtr(grpc::ServerContext *context, const bmi grpc::Status BmiGRPCService::getValueAtIndices(grpc::ServerContext *context, const bmi::GetValueAtIndicesRequest *request, bmi::GetValueAtIndicesResponse *response) { - int status = BMI_FAILURE; std::vector indices(request->indices().begin(), request->indices().end()); try { @@ -358,7 +365,6 @@ grpc::Status BmiGRPCService::getValueAtIndices(grpc::ServerContext *context, con grpc::Status BmiGRPCService::setValue(grpc::ServerContext *context, const bmi::SetValueRequest *request, bmi::Empty *response) { - int status = BMI_FAILURE; try { char typechar = this->find_type(request->name()); @@ -406,7 +412,7 @@ grpc::Status BmiGRPCService::setValueAtIndices(grpc::ServerContext *context, con { values = (void*)request->values_double().values().data(); } - this->bmi->SetValueAtIndices(request->name().c_str(), values, indices.data(), indices.size()); + this->bmi->SetValueAtIndices(request->name().c_str(), indices.data(), indices.size(), values); } catch (const std::exception &e) { @@ -432,9 +438,8 @@ grpc::Status BmiGRPCService::getGridType(grpc::ServerContext *context, const bmi { try { - char type[BMI_MAX_VAR_NAME]; - this->bmi->GetGridType(request->grid_id(), type); - response->set_type(std::string(type)); + std::string type = this->bmi->GetGridType(request->grid_id()); + response->set_type(type); } catch (const std::exception &e) { @@ -588,7 +593,7 @@ grpc::Status BmiGRPCService::getGridZ(grpc::ServerContext *context, const bmi::G return grpc::Status::OK; } -grpc::Status BmiGRPCService::getGridNodeCount(grpc::ServerContext *context, const bmi::GridRequest *request, bmi::GetGridElementCountResponse *response) +grpc::Status BmiGRPCService::getGridNodeCount(grpc::ServerContext *context, const bmi::GridRequest *request, bmi::GetCountResponse *response) { try { @@ -601,7 +606,7 @@ grpc::Status BmiGRPCService::getGridNodeCount(grpc::ServerContext *context, cons return grpc::Status::OK; } -grpc::Status BmiGRPCService::getGridEdgeCount(grpc::ServerContext *context, const bmi::GridRequest *request, bmi::GetGridElementCountResponse *response) +grpc::Status BmiGRPCService::getGridEdgeCount(grpc::ServerContext *context, const bmi::GridRequest *request, bmi::GetCountResponse *response) { try { @@ -614,7 +619,7 @@ grpc::Status BmiGRPCService::getGridEdgeCount(grpc::ServerContext *context, cons return grpc::Status::OK; } -grpc::Status BmiGRPCService::getGridFaceCount(grpc::ServerContext *context, const bmi::GridRequest *request, bmi::GetGridElementCountResponse *response) +grpc::Status BmiGRPCService::getGridFaceCount(grpc::ServerContext *context, const bmi::GridRequest *request, bmi::GetCountResponse *response) { try { @@ -635,8 +640,8 @@ grpc::Status BmiGRPCService::getGridEdgeNodes(grpc::ServerContext *context, cons int size = 2*(this->bmi->GetGridEdgeCount(request->grid_id())); vals = (int *)malloc(size * sizeof(int)); this->bmi->GetGridEdgeNodes(request->grid_id(), vals); - response->mutable_links()->Resize(size, 0); - std::copy(vals, vals + size, response->mutable_links()->begin()); + response->mutable_edge_nodes()->Resize(size, 0); + std::copy(vals, vals + size, response->mutable_edge_nodes()->begin()); } catch (const std::exception &e) { @@ -663,8 +668,8 @@ grpc::Status BmiGRPCService::getGridFaceNodes(grpc::ServerContext *context, cons } vals = (int *)malloc(size * sizeof(int)); this->bmi->GetGridFaceNodes(request->grid_id(), vals); - response->mutable_links()->Resize(size, 0); - std::copy(vals, vals + size, response->mutable_links()->begin()); + response->mutable_face_nodes()->Resize(size, 0); + std::copy(vals, vals + size, response->mutable_face_nodes()->begin()); } catch (const std::exception &e) { @@ -677,6 +682,36 @@ grpc::Status BmiGRPCService::getGridFaceNodes(grpc::ServerContext *context, cons return grpc::Status::OK; } +grpc::Status BmiGRPCService::getGridFaceEdges(grpc::ServerContext *context, const bmi::GridRequest *request, bmi::GetGridFaceEdgesResponse *response) +{ + int *vals; + int *faceedges; + try + { + int face_count = this->bmi->GetGridFaceCount(request->grid_id()); + faceedges = (int *)malloc(face_count * sizeof(int)); + this->bmi->GetGridNodesPerFace(request->grid_id(), faceedges); + int size = 0; + for(int i = 0; i < face_count; ++i) + { + size += faceedges[i]; + } + vals = (int *)malloc(size * sizeof(int)); + this->bmi->GetGridFaceEdges(request->grid_id(), vals); + response->mutable_face_edges()->Resize(size, 0); + std::copy(vals, vals + size, response->mutable_face_edges()->begin()); + } + catch (const std::exception &e) + { + free(faceedges); + free(vals); + return BmiGRPCService::handle_exception(e); + } + free(faceedges); + free(vals); + return grpc::Status::OK; +} + grpc::Status BmiGRPCService::getGridNodesPerFace(grpc::ServerContext *context, const bmi::GridRequest *request, bmi::GetGridNodesPerFaceResponse *response) { int *vals; @@ -685,8 +720,8 @@ grpc::Status BmiGRPCService::getGridNodesPerFace(grpc::ServerContext *context, c int size = this->bmi->GetGridFaceCount(request->grid_id()); vals = (int *)malloc(size * sizeof(int)); this->bmi->GetGridNodesPerFace(request->grid_id(), vals); - response->mutable_links()->Resize(size, 0); - std::copy(vals, vals + size, response->mutable_links()->begin()); + response->mutable_nodes_per_face()->Resize(size, 0); + std::copy(vals, vals + size, response->mutable_nodes_per_face()->begin()); } catch (const std::exception &e) { @@ -700,8 +735,7 @@ grpc::Status BmiGRPCService::getGridNodesPerFace(grpc::ServerContext *context, c char BmiGRPCService::find_type(const std::string &varname) const { std::locale loc; - char type[BMI_MAX_VAR_NAME]; - this->bmi->GetVarType(varname.c_str(), type); + std::string type = this->bmi->GetVarType(varname); std::string vartype(type); std::transform(vartype.begin(), vartype.end(), vartype.begin(), ::tolower); std::vector inttypes = {"int", "int16", "int32", "int64"}; @@ -730,8 +764,7 @@ void BmiGRPCService::get_grid_dimensions(int grid_id, int *vec3d) const int rank = this->bmi->GetGridRank(grid_id); int *shape = (int *)malloc(rank * sizeof(int)); this->bmi->GetGridShape(grid_id, shape); - char type[BMI_MAX_VAR_NAME]; - this->bmi->GetGridType(grid_id, type); + std::string type = this->bmi->GetGridType(grid_id); std::string typestr(type); if (typestr == "uniform_rectilinear" or typestr == "rectilinear") { diff --git a/cpp/bmi_grpc_server.h b/cpp/bmi_grpc_server.h index 6da9eb1..4b517d3 100644 --- a/cpp/bmi_grpc_server.h +++ b/cpp/bmi_grpc_server.h @@ -2,14 +2,13 @@ #define BMI_GRPC_SERVER_H_INCLUDED #include "bmi.grpc.pb.h" -#ifndef BMI_INCLUDED -#define BMI_INCLUDED -#include "bmi.h" -#include "bmi.hxx" -#endif +#include "bmi-c/bmi.h" +#undef BMI_SUCCESS +#undef BMI_FAILURE +#include "bmi-cxx/bmi.hxx" -typedef Bmi BMIModel; typedef bmi::Bmi BmiClass; +typedef Bmi BmiModel; using bmi::BmiService; @@ -20,8 +19,11 @@ class BmiGRPCService final: public BmiService::Service ~BmiGRPCService(); grpc::Status initialize(grpc::ServerContext* context, const bmi::InitializeRequest* request, bmi::Empty* response) override; grpc::Status update(grpc::ServerContext* context, const bmi::Empty* request, bmi::Empty* response) override; + grpc::Status updateUntil(grpc::ServerContext* context, const bmi::GetTimeResponse* request, bmi::Empty* response) override; grpc::Status finalize(grpc::ServerContext* context, const bmi::Empty* request, bmi::Empty* response) override; grpc::Status getComponentName(grpc::ServerContext* context, const bmi::Empty* request, bmi::GetComponentNameResponse* response) override; + grpc::Status getInputItemCount(grpc::ServerContext* context, const bmi::Empty* request, bmi::GetCountResponse* response) override; + grpc::Status getOutputItemCount(grpc::ServerContext* context, const bmi::Empty* request, bmi::GetCountResponse* response) override; grpc::Status getInputVarNames(grpc::ServerContext* context, const bmi::Empty* request, bmi::GetVarNamesResponse* response) override; grpc::Status getOutputVarNames(grpc::ServerContext* context, const bmi::Empty* request, bmi::GetVarNamesResponse* response) override; grpc::Status getTimeUnits(grpc::ServerContext* context, const bmi::Empty* request, bmi::GetTimeUnitsResponse* response) override; @@ -50,11 +52,12 @@ class BmiGRPCService final: public BmiService::Service grpc::Status getGridX(grpc::ServerContext* context, const bmi::GridRequest* request, bmi::GetGridPointsResponse* response) override; grpc::Status getGridY(grpc::ServerContext* context, const bmi::GridRequest* request, bmi::GetGridPointsResponse* response) override; grpc::Status getGridZ(grpc::ServerContext* context, const bmi::GridRequest* request, bmi::GetGridPointsResponse* response) override; - grpc::Status getGridNodeCount(grpc::ServerContext* context, const bmi::GridRequest* request, bmi::GetGridElementCountResponse* response) override; - grpc::Status getGridEdgeCount(grpc::ServerContext* context, const bmi::GridRequest* request, bmi::GetGridElementCountResponse* response) override; - grpc::Status getGridFaceCount(grpc::ServerContext* context, const bmi::GridRequest* request, bmi::GetGridElementCountResponse* response) override; + grpc::Status getGridNodeCount(grpc::ServerContext* context, const bmi::GridRequest* request, bmi::GetCountResponse* response) override; + grpc::Status getGridEdgeCount(grpc::ServerContext* context, const bmi::GridRequest* request, bmi::GetCountResponse* response) override; + grpc::Status getGridFaceCount(grpc::ServerContext* context, const bmi::GridRequest* request, bmi::GetCountResponse* response) override; grpc::Status getGridEdgeNodes(grpc::ServerContext* context, const bmi::GridRequest* request, bmi::GetGridEdgeNodesResponse* response) override; grpc::Status getGridFaceNodes(grpc::ServerContext* context, const bmi::GridRequest* request, bmi::GetGridFaceNodesResponse* response) override; + grpc::Status getGridFaceEdges(grpc::ServerContext* context, const bmi::GridRequest* request, bmi::GetGridFaceEdgesResponse* response) override; grpc::Status getGridNodesPerFace(grpc::ServerContext* context, const bmi::GridRequest* request, bmi::GetGridNodesPerFaceResponse* response) override; private: BmiClass* const bmi; @@ -64,7 +67,7 @@ class BmiGRPCService final: public BmiService::Service static grpc::Status handle_exception(const std::exception&); }; -void run_bmi_server(BMIModel* model, int argc, char* argv[]); +void run_bmi_server(Bmi* model, int argc, char* argv[]); void run_bmi_server(BmiClass* model, int argc, char* argv[]); #endif diff --git a/cpp/test/CMakeLists.txt b/cpp/test/CMakeLists.txt index 0b454b2..b3da077 100644 --- a/cpp/test/CMakeLists.txt +++ b/cpp/test/CMakeLists.txt @@ -10,9 +10,9 @@ include (CTest) add_test(NAME test_cpp_extension_initialize COMMAND test_cpp_extension initialize) add_test(NAME test_cpp_extension_component_name COMMAND test_cpp_extension component_name) -add_test(NAME test_cpp_extension_input_var_count COMMAND test_cpp_extension input_var_count) +add_test(NAME test_cpp_extension_input_item_count COMMAND test_cpp_extension input_item_count) add_test(NAME test_cpp_extension_input_vars COMMAND test_cpp_extension input_vars) -add_test(NAME test_cpp_extension_output_var_count COMMAND test_cpp_extension output_var_count) +add_test(NAME test_cpp_extension_output_var_count COMMAND test_cpp_extension output_item_count) add_test(NAME test_cpp_extension_output_vars COMMAND test_cpp_extension output_vars) add_test(NAME test_cpp_extension_var_grid COMMAND test_cpp_extension var_grid) add_test(NAME test_cpp_extension_var_type COMMAND test_cpp_extension var_type) @@ -31,9 +31,9 @@ add_test(NAME test_cpp_extension_finalize COMMAND test_cpp_extension finalize) add_test(NAME test_service_initialize COMMAND test_bmi_service initialize) add_test(NAME test_service_component_name COMMAND test_bmi_service component_name) -add_test(NAME test_service_input_var_count COMMAND test_bmi_service input_var_count) +add_test(NAME test_service_input_item_count COMMAND test_bmi_service input_item_count) add_test(NAME test_service_input_vars COMMAND test_bmi_service input_vars) -add_test(NAME test_service_output_var_count COMMAND test_bmi_service output_var_count) +add_test(NAME test_service_output_var_count COMMAND test_bmi_service output_item_count) add_test(NAME test_service_output_vars COMMAND test_bmi_service output_vars) add_test(NAME test_service_var_grid COMMAND test_bmi_service var_grid) add_test(NAME test_var_grid_unknownvar COMMAND test_bmi_service var_grid_unknownvar) diff --git a/cpp/test/bmi_test_extension.cc b/cpp/test/bmi_test_extension.cc index 52bd22b..828cf4d 100644 --- a/cpp/test/bmi_test_extension.cc +++ b/cpp/test/bmi_test_extension.cc @@ -37,22 +37,32 @@ void BmiTestExtension::Finalize(){} BmiTestExtension::~BmiTestExtension(){} -void BmiTestExtension::Initialize(const std::string& configfile) +void BmiTestExtension::Initialize(std::string configfile) { std::cout<<"initializing with "< BmiTestExtension::GetInputVarNames() const +int BmiTestExtension::GetInputItemCount() +{ + return this->input_vars.size(); +} + +int BmiTestExtension::GetOutputItemCount() +{ + return this->output_vars.size(); +} + +std::vector BmiTestExtension::GetInputVarNames() { return this->input_vars; } -std::vector BmiTestExtension::GetOutputVarNames() const +std::vector BmiTestExtension::GetOutputVarNames() { return this->output_vars; } @@ -62,7 +72,7 @@ bool BmiTestExtension::has_var(std::string name) const return std::find(this->input_vars.begin(), this->input_vars.end(), name) != this->input_vars.end() or std::find(this->output_vars.begin(), this->output_vars.end(), name) != this->output_vars.end(); } -int BmiTestExtension::GetVarGrid(const std::string& name) const +int BmiTestExtension::GetVarGrid(std::string name) { if(this->has_var(name)) { @@ -71,7 +81,7 @@ int BmiTestExtension::GetVarGrid(const std::string& name) const throw std::invalid_argument("unknown variable: " + name); } -std::string BmiTestExtension::GetVarType(const std::string& name) const +std::string BmiTestExtension::GetVarType(std::string name) { if(this->has_var(name)) { @@ -80,7 +90,7 @@ std::string BmiTestExtension::GetVarType(const std::string& name) const throw std::invalid_argument("unknown variable: " + name); } -int BmiTestExtension::GetVarItemsize(const std::string& name) const +int BmiTestExtension::GetVarItemsize(std::string name) { if(this->has_var(name)) { @@ -89,7 +99,7 @@ int BmiTestExtension::GetVarItemsize(const std::string& name) const throw std::invalid_argument("unknown variable: " + name); } -std::string BmiTestExtension::GetVarUnits(const std::string& name) const +std::string BmiTestExtension::GetVarUnits(std::string name) { if(name == "water level") { @@ -102,7 +112,7 @@ std::string BmiTestExtension::GetVarUnits(const std::string& name) const throw std::invalid_argument("unknown variable: " + name); } -int BmiTestExtension::GetVarNbytes(const std::string& name) const +int BmiTestExtension::GetVarNbytes(std::string name) { if(this->has_var(name)) { @@ -111,7 +121,7 @@ int BmiTestExtension::GetVarNbytes(const std::string& name) const throw std::invalid_argument("unknown variable: " + name); } -std::string BmiTestExtension::GetVarLocation(const std::string& name) const +std::string BmiTestExtension::GetVarLocation(std::string name) { if(name == "water level") { @@ -139,7 +149,7 @@ double BmiTestExtension::GetEndTime() return 100; } -std::string BmiTestExtension::GetTimeUnits() const +std::string BmiTestExtension::GetTimeUnits() { return "days since 1981-08-29 06:00:00"; } @@ -167,7 +177,7 @@ int BmiTestExtension::GetGridSize(int id) throw std::invalid_argument("unknown grid id argument"); } -std::string BmiTestExtension::GetGridType(int id) const +std::string BmiTestExtension::GetGridType(int id) { if(id == this->grid_id) { diff --git a/cpp/test/bmi_test_extension.h b/cpp/test/bmi_test_extension.h index ff158a8..9e56968 100644 --- a/cpp/test/bmi_test_extension.h +++ b/cpp/test/bmi_test_extension.h @@ -10,30 +10,32 @@ class BmiTestExtension: public BmiCppExtension BmiTestExtension(const std::vector&, const std::vector&); virtual ~BmiTestExtension(); - void Initialize(const std::string& configfile) override; + void Initialize(std::string configfile) override; void Update() override; void UpdateUntil(double time) override; void Finalize() override; - std::string GetComponentName() const override; - std::vector GetInputVarNames() const override; - std::vector GetOutputVarNames() const override; - - int GetVarGrid(const std::string& name) const override; - std::string GetVarType(const std::string& name) const override; - int GetVarItemsize(const std::string& name) const override; - std::string GetVarUnits(const std::string& name) const override; - int GetVarNbytes(const std::string& name) const override; - std::string GetVarLocation(const std::string& name) const override; + std::string GetComponentName() override; + int GetInputItemCount() override; + int GetOutputItemCount() override; + std::vector GetInputVarNames() override; + std::vector GetOutputVarNames() override; + + int GetVarGrid(std::string name) override; + std::string GetVarType(std::string name) override; + int GetVarItemsize(std::string name) override; + std::string GetVarUnits(std::string name) override; + int GetVarNbytes(std::string name) override; + std::string GetVarLocation(std::string name) override; double GetCurrentTime() override; double GetStartTime() override; double GetEndTime() override; - std::string GetTimeUnits() const override; + std::string GetTimeUnits() override; double GetTimeStep() override; int GetGridRank(int id) override; int GetGridSize(int id) override; - std::string GetGridType(int id) const override; + std::string GetGridType(int id) override; std::vector GetGridShape(int id) const override; std::vector GetGridSpacing(int id) const override; std::vector GetGridOrigin(int id) const override; diff --git a/cpp/test/test_bmi_cpp_extension.cc b/cpp/test/test_bmi_cpp_extension.cc index 519f6f0..6a79a14 100644 --- a/cpp/test/test_bmi_cpp_extension.cc +++ b/cpp/test/test_bmi_cpp_extension.cc @@ -13,152 +13,122 @@ void test_initialize(bmi::Bmi* b) void test_component_name(bmi::Bmi* b) { - char component_name_char[BMI_MAX_COMPONENT_NAME]; - b->GetComponentName(component_name_char); - std::string check_string(component_name_char, strlen(component_name_char)); - std::string component_name_string = static_cast(b)->GetComponentName(); + std::string check_string = b->GetComponentName(); + std::string component_name_string = static_cast(b)->GetComponentName(); assert(check_string == component_name_string); } -void test_input_var_count(bmi::Bmi* b) +void test_input_item_count(bmi::Bmi* b) { - int count = b->GetInputVarNameCount(); - std::vector input_vars = static_cast(b)->GetInputVarNames(); + int count = b->GetInputItemCount(); + std::vector input_vars = static_cast(b)->GetInputVarNames(); assert(input_vars.size() == count); } void test_input_vars(bmi::Bmi* b) { - int count = b->GetInputVarNameCount(); - char** names = (char**) malloc(sizeof(char*)*count); - for(int i = 0; i < count; i++) - { - names[i] = (char*) malloc(sizeof(char)*BMI_MAX_VAR_NAME); - } - b->GetInputVarNames(names); - std::vector input_vars = static_cast(b)->GetInputVarNames(); + std::vector names = b->GetInputVarNames(); + std::vector input_vars = static_cast(b)->GetInputVarNames(); for(std::vector::size_type i = 0; i < input_vars.size(); i++) { - std::string check_string(names[i], strlen(names[i])); - assert(input_vars[i] == check_string); - } - for(int i = 0; i < count; i++) - { - free(names[i]); + assert(input_vars[i] == names[i]); } - free(names); } -void test_output_var_count(bmi::Bmi* b) +void test_output_item_count(bmi::Bmi* b) { - int count = b->GetOutputVarNameCount(); - std::vector output_vars = static_cast(b)->GetOutputVarNames(); + int count = b->GetOutputItemCount(); + std::vector output_vars = static_cast(b)->GetOutputVarNames(); assert(output_vars.size() == count); } void test_output_vars(bmi::Bmi* b) { - int count = b->GetOutputVarNameCount(); - char** names = (char**) malloc(sizeof(char*)*count); - for(int i = 0; i < count; i++) - { - names[i] = (char*) malloc(sizeof(char)*BMI_MAX_VAR_NAME); - } - b->GetOutputVarNames(names); - std::vector output_vars = static_cast(b)->GetOutputVarNames(); + std::vector names = b->GetOutputVarNames(); + std::vector output_vars = static_cast(b)->GetOutputVarNames(); for(std::vector::size_type i = 0; i < output_vars.size(); i++) { - std::string check_string(names[i], strlen(names[i])); - assert(output_vars[i] == check_string); - } - for(int i = 0; i < count; i++) - { - free(names[i]); + assert(output_vars[i] == names[i]); } - free(names); } void test_var_grid(bmi::Bmi* b) { - std::vector output_vars = static_cast(b)->GetOutputVarNames(); + std::vector output_vars = static_cast(b)->GetOutputVarNames(); for(std::vector::const_iterator it = output_vars.begin(); it != output_vars.end(); ++it) { int id = b->GetVarGrid(it->c_str()); - assert(static_cast(b)->GetVarGrid(*it) == id); + assert(static_cast(b)->GetVarGrid(*it) == id); } - std::vector input_vars = static_cast(b)->GetInputVarNames(); + std::vector input_vars = static_cast(b)->GetInputVarNames(); for(std::vector::const_iterator it = input_vars.begin(); it != input_vars.end(); ++it) { int id = b->GetVarGrid(it->c_str()); - assert(static_cast(b)->GetVarGrid(*it) == id); + assert(static_cast(b)->GetVarGrid(*it) == id); } } void test_var_type(bmi::Bmi* b) { - std::vector output_vars = static_cast(b)->GetOutputVarNames(); + std::vector output_vars = static_cast(b)->GetOutputVarNames(); for(std::vector::const_iterator it = output_vars.begin(); it != output_vars.end(); ++it) { - char type[BMI_MAX_VAR_NAME]; - b->GetVarType(it->c_str(), type); - assert(static_cast(b)->GetVarType(*it) == std::string(type, strlen(type))); + std::string type = b->GetVarType(it->c_str()); + assert(static_cast(b)->GetVarType(*it) == type); } - std::vector input_vars = static_cast(b)->GetInputVarNames(); + std::vector input_vars = static_cast(b)->GetInputVarNames(); for(std::vector::const_iterator it = input_vars.begin(); it != input_vars.end(); ++it) { - char type[BMI_MAX_VAR_NAME]; - b->GetVarType(it->c_str(), type); - assert(static_cast(b)->GetVarType(*it) == std::string(type, strlen(type))); + std::string type = b->GetVarType(it->c_str()); + assert(static_cast(b)->GetVarType(*it) == type); } } void test_var_itemsize(bmi::Bmi* b) { - std::vector output_vars = static_cast(b)->GetOutputVarNames(); + std::vector output_vars = static_cast(b)->GetOutputVarNames(); for(std::vector::const_iterator it = output_vars.begin(); it != output_vars.end(); ++it) { int size = b->GetVarItemsize(it->c_str()); - assert(static_cast(b)->GetVarItemsize(*it) == size); + assert(static_cast(b)->GetVarItemsize(*it) == size); } - std::vector input_vars = static_cast(b)->GetInputVarNames(); + std::vector input_vars = static_cast(b)->GetInputVarNames(); for(std::vector::const_iterator it = input_vars.begin(); it != input_vars.end(); ++it) { int size = b->GetVarItemsize(it->c_str()); - assert(static_cast(b)->GetVarItemsize(*it) == size); + assert(static_cast(b)->GetVarItemsize(*it) == size); } } void test_var_nbytes(bmi::Bmi* b) { - std::vector output_vars = static_cast(b)->GetOutputVarNames(); + std::vector output_vars = static_cast(b)->GetOutputVarNames(); for(std::vector::const_iterator it = output_vars.begin(); it != output_vars.end(); ++it) { - int size = b->GetVarNbytes(it->c_str()); - assert(static_cast(b)->GetVarNbytes(*it) == size); + int size = b->GetVarNbytes(*it); + assert(static_cast(b)->GetVarNbytes(*it) == size); } - std::vector input_vars = static_cast(b)->GetInputVarNames(); + std::vector input_vars = static_cast(b)->GetInputVarNames(); for(std::vector::const_iterator it = input_vars.begin(); it != input_vars.end(); ++it) { - int size = b->GetVarNbytes(it->c_str()); - assert(static_cast(b)->GetVarNbytes(*it) == size); + int size = b->GetVarNbytes(*it); + assert(static_cast(b)->GetVarNbytes(*it) == size); } } void test_var_units(bmi::Bmi* b) { - std::vector output_vars = static_cast(b)->GetOutputVarNames(); + std::vector output_vars = static_cast(b)->GetOutputVarNames(); for(std::vector::const_iterator it = output_vars.begin(); it != output_vars.end(); ++it) { - char units[BMI_MAX_UNITS_NAME]; - b->GetVarUnits(it->c_str(), units); - assert(static_cast(b)->GetVarUnits(*it) == std::string(units, strlen(units))); + std::string units = b->GetVarUnits(*it); + assert(static_cast(b)->GetVarUnits(*it) == units); } - std::vector input_vars = static_cast(b)->GetInputVarNames(); + std::vector input_vars = static_cast(b)->GetInputVarNames(); for(std::vector::const_iterator it = input_vars.begin(); it != input_vars.end(); ++it) { - char units[BMI_MAX_UNITS_NAME]; - b->GetVarUnits(it->c_str(), units); - assert(static_cast(b)->GetVarUnits(*it) == std::string(units, strlen(units))); + std::string units = b->GetVarUnits(*it); + assert(static_cast(b)->GetVarUnits(*it) == units); } } @@ -190,23 +160,22 @@ void test_time_step(bmi::Bmi* b) void test_time_units(bmi::Bmi* b) { - char unit[BMI_MAX_UNITS_NAME]; - b->GetTimeUnits(unit); - assert(std::string(unit, strlen(unit)) == static_cast(b)->GetTimeUnits()); + std::string unit = b->GetTimeUnits(); + assert(unit == static_cast(b)->GetTimeUnits()); } void test_get_values(bmi::Bmi* b) { - std::vector output_vars = static_cast(b)->GetOutputVarNames(); + std::vector output_vars = static_cast(b)->GetOutputVarNames(); for(std::vector::const_iterator it = output_vars.begin(); it != output_vars.end(); ++it) { - if(static_cast(b)->GetVarType(*it) != "double") + if(static_cast(b)->GetVarType(*it) != "double") { continue; } - int nbytes = b->GetVarNbytes(it->c_str()); + int nbytes = b->GetVarNbytes(*it); void* vals = (void*) malloc(nbytes); - b->GetValue(it->c_str(), vals); + b->GetValue(*it, vals); std::vector vals_vec((double*)vals, (double*)vals + nbytes/sizeof(double)); std::vector vals_check = static_cast(b)->GetValue(*it); assert(vals_vec == vals_check); @@ -217,17 +186,17 @@ void test_get_values(bmi::Bmi* b) void test_get_values_at_indices(bmi::Bmi* b) { std::vectorindices = {1, 3, 5, 7}; - std::vector output_vars = static_cast(b)->GetOutputVarNames(); + std::vector output_vars = static_cast(b)->GetOutputVarNames(); for(std::vector::const_iterator it = output_vars.begin(); it != output_vars.end(); ++it) { - if(static_cast(b)->GetVarType(*it) != "double") + if(static_cast(b)->GetVarType(*it) != "double") { continue; } - int nbytes = b->GetVarItemsize(it->c_str()); + int nbytes = b->GetVarItemsize(*it); nbytes *= indices.size(); void* vals = (void*) malloc(nbytes); - b->GetValueAtIndices(it->c_str(), vals, indices.data(), indices.size()); + b->GetValueAtIndices(*it, vals, indices.data(), indices.size()); std::vector vals_vec((double*)vals, (double*)vals + nbytes/sizeof(double)); assert(vals_vec == static_cast(b)->GetValueAtIndices(*it, indices)); free(vals); @@ -236,14 +205,14 @@ void test_get_values_at_indices(bmi::Bmi* b) void test_get_value_ptr(bmi::Bmi* b) { - std::vector output_vars = static_cast(b)->GetOutputVarNames(); + std::vector output_vars = static_cast(b)->GetOutputVarNames(); for(std::vector::const_iterator it = output_vars.begin(); it != output_vars.end(); ++it) { - if(static_cast(b)->GetVarType(*it) != "double") + if(static_cast(b)->GetVarType(*it) != "double") { continue; } - void* p = b->GetValuePtr(it->c_str()); + void* p = b->GetValuePtr(*it); assert(p == static_cast(b)->GetValuePtr(*it)); } @@ -269,17 +238,17 @@ int main(int argc, char* argv[]) { test_component_name(bmi); } - else if(testfunc == "input_var_count") + else if(testfunc == "input_item_count") { - test_input_var_count(bmi); + test_input_item_count(bmi); } else if(testfunc == "input_vars") { test_input_vars(bmi); } - else if(testfunc == "output_var_count") + else if(testfunc == "output_item_count") { - test_output_var_count(bmi); + test_output_item_count(bmi); } else if(testfunc == "output_vars") { diff --git a/cpp/test/test_bmi_grpc_server.cc b/cpp/test/test_bmi_grpc_server.cc index ecfd888..13f91bc 100644 --- a/cpp/test/test_bmi_grpc_server.cc +++ b/cpp/test/test_bmi_grpc_server.cc @@ -17,42 +17,29 @@ std::vector get_bmi_varnames(BmiClass* b, int selector=SELECT_ALL) int output_count = 0; if((selector & SELECT_INPUT) > 0) { - input_count = b->GetInputVarNameCount(); + input_count = b->GetInputItemCount(); count += input_count; } if((selector & SELECT_OUTPUT) > 0) { - output_count = b->GetOutputVarNameCount(); + output_count = b->GetOutputItemCount(); count += output_count; } if(count == 0) { return std::vector(); } - char** names = (char**) malloc(sizeof(char*)*count); - for(int i = 0; i < count; i++) - { - names[i] = (char*) malloc(sizeof(char)*BMI_MAX_VAR_NAME); - } - if((selector & SELECT_INPUT) > 0) + if(selector == SELECT_INPUT) { - b->GetInputVarNames(names); + return b->GetInputVarNames(); } - if((selector & SELECT_OUTPUT) > 0) + if(selector == SELECT_OUTPUT) { - b->GetOutputVarNames(names + input_count); - } - std::vector result(count); - for(std::vector::size_type i = 0; i < result.size(); ++i) - { - result[i] = std::string(names[i]); - free(names[i]); - } - free(names); - for(int i=0;i < result.size(); ++i) - { - std::cerr<<"THE VARIABLE NAME "<GetOutputVarNames(); } + std::vector result(b->GetInputVarNames()); + std::vector onames = b->GetOutputVarNames(); + result.insert(result.end(), onames.begin(), onames.end()); return result; } @@ -86,9 +73,7 @@ void test_initialize(BmiGRPCService* s, BmiClass* b) void test_component_name(BmiGRPCService* s, BmiClass* b) { - char component_name_char[BMI_MAX_COMPONENT_NAME]; - b->GetComponentName(component_name_char); - std::string check_string(component_name_char, strlen(component_name_char)); + std::string check_string = b->GetComponentName(); bmi::Empty* request = new bmi::Empty(); bmi::GetComponentNameResponse* response = new bmi::GetComponentNameResponse(); s->getComponentName(NULL, request, response); @@ -97,9 +82,9 @@ void test_component_name(BmiGRPCService* s, BmiClass* b) delete response; } -void test_input_var_count(BmiGRPCService* s, BmiClass* b) +void test_input_item_count(BmiGRPCService* s, BmiClass* b) { - int count = b->GetInputVarNameCount(); + int count = b->GetInputItemCount(); bmi::Empty* request = new bmi::Empty(); bmi::GetVarNamesResponse* response = new bmi::GetVarNamesResponse(); s->getInputVarNames(NULL, request, response); @@ -110,13 +95,8 @@ void test_input_var_count(BmiGRPCService* s, BmiClass* b) void test_input_vars(BmiGRPCService* s, BmiClass* b) { - int count = b->GetInputVarNameCount(); - char** names = (char**) malloc(sizeof(char*)*count); - for(int i = 0; i < count; i++) - { - names[i] = (char*) malloc(sizeof(char)*BMI_MAX_VAR_NAME); - } - b->GetInputVarNames(names); + int count = b->GetInputItemCount(); + std::vector names = b->GetInputVarNames(); bmi::Empty* request = new bmi::Empty(); bmi::GetVarNamesResponse* response = new bmi::GetVarNamesResponse(); s->getInputVarNames(NULL, request, response); @@ -124,18 +104,13 @@ void test_input_vars(BmiGRPCService* s, BmiClass* b) { assert(std::string(names[i]) == response->names()[i]); } - for(int i = 0; i < count; i++) - { - free(names[i]); - } - free(names); delete request; delete response; } -void test_output_var_count(BmiGRPCService* s, BmiClass* b) +void test_output_item_count(BmiGRPCService* s, BmiClass* b) { - int count = b->GetOutputVarNameCount(); + int count = b->GetOutputItemCount(); bmi::Empty* request = new bmi::Empty(); bmi::GetVarNamesResponse* response = new bmi::GetVarNamesResponse(); s->getOutputVarNames(NULL, request, response); @@ -146,13 +121,8 @@ void test_output_var_count(BmiGRPCService* s, BmiClass* b) void test_output_vars(BmiGRPCService* s, BmiClass* b) { - int count = b->GetOutputVarNameCount(); - char** names = (char**) malloc(sizeof(char*)*count); - for(int i = 0; i < count; i++) - { - names[i] = (char*) malloc(sizeof(char)*BMI_MAX_VAR_NAME); - } - b->GetOutputVarNames(names); + int count = b->GetOutputItemCount(); + std::vector names = b->GetOutputVarNames(); bmi::Empty* request = new bmi::Empty(); bmi::GetVarNamesResponse* response = new bmi::GetVarNamesResponse(); s->getOutputVarNames(NULL, request, response); @@ -160,11 +130,6 @@ void test_output_vars(BmiGRPCService* s, BmiClass* b) { assert(std::string(names[i]) == response->names()[i]); } - for(int i = 0; i < count; i++) - { - free(names[i]); - } - free(names); delete request; delete response; } @@ -208,8 +173,7 @@ void test_var_type(BmiGRPCService* s, BmiClass* b) bmi::GetVarTypeResponse* response = new bmi::GetVarTypeResponse(); for(std::vector::size_type i = 0; i < names.size(); ++i) { - char type[BMI_MAX_VAR_NAME]; - b->GetVarType(names[i].c_str(), type); + std::string type = b->GetVarType(names[i]); request->set_name(names[i]); s->getVarType(NULL, request, response); assert(std::string(type) == response->type()); @@ -242,8 +206,7 @@ void test_var_location(BmiGRPCService* s, BmiClass* b) bmi::GetVarLocationResponse* response = new bmi::GetVarLocationResponse(); for(std::vector::size_type i = 0; i < names.size(); ++i) { - char expected_loc_char[4]; - b->GetVarLocation(names[i].c_str(), expected_loc_char); + std::string expected_loc_char = b->GetVarLocation(names[i]); request->set_name(names[i]); s->getVarLocation(NULL, request, response); bmi::GetVarLocationResponse::Location expected_location; @@ -277,11 +240,10 @@ void test_var_units(BmiGRPCService* s, BmiClass* b) bmi::GetVarUnitsResponse* response = new bmi::GetVarUnitsResponse(); for(std::vector::size_type i = 0; i < names.size(); ++i) { - char type[BMI_MAX_VAR_NAME]; - b->GetVarUnits(names[i].c_str(), type); + std::string units = b->GetVarUnits(names[i]); request->set_name(names[i]); s->getVarUnits(NULL, request, response); - assert(std::string(type) == response->units()); + assert(units == response->units()); } delete request; delete response; @@ -333,12 +295,11 @@ void test_time_step(BmiGRPCService* s, BmiClass* b) void test_time_units(BmiGRPCService* s, BmiClass* b) { - char unit[BMI_MAX_UNITS_NAME]; - b->GetTimeUnits(unit); + std::string unit = b->GetTimeUnits(); bmi::Empty* request = new bmi::Empty(); bmi::GetTimeUnitsResponse* response = new bmi::GetTimeUnitsResponse(); s->getTimeUnits(NULL, request, response); - assert(response->units() == std::string(unit)); + assert(response->units() == unit); delete request; delete response; } @@ -346,19 +307,19 @@ void test_time_units(BmiGRPCService* s, BmiClass* b) void test_get_values(BmiGRPCService* s, BmiClass* b) { std::vector output_vars = get_bmi_varnames(b, SELECT_OUTPUT); - char type[BMI_MAX_VAR_NAME]; + std::string type; bmi::GetVarRequest* request = new bmi::GetVarRequest(); bmi::GetValueResponse* response = new bmi::GetValueResponse(); for(std::vector::iterator it = output_vars.begin(); it != output_vars.end(); ++it) { - b->GetVarType(it->c_str(), type); + type = b->GetVarType(*it); if(std::string(type) != "double") { continue; } - int nbytes = b->GetVarNbytes(it->c_str()); + int nbytes = b->GetVarNbytes(*it); void* vals = malloc(nbytes); - b->GetValue(it->c_str(), vals); + b->GetValue(*it, vals); request->set_name(*it); s->getValue(NULL, request, response); for(int i = 0; i < response->mutable_values_double()->values_size(); ++i) @@ -375,7 +336,7 @@ void test_get_values_at_indices(BmiGRPCService* s, BmiClass* b) { std::vectorindices = {1, 3, 5, 7}; std::vector output_vars = get_bmi_varnames(b, SELECT_OUTPUT); - char type[BMI_MAX_VAR_NAME]; + std::string type; bmi::GetValueAtIndicesRequest* request = new bmi::GetValueAtIndicesRequest(); for(std::vector::const_iterator it = indices.begin(); it != indices.end(); ++it) { @@ -385,12 +346,12 @@ void test_get_values_at_indices(BmiGRPCService* s, BmiClass* b) void* vals = malloc(indices.size() * sizeof(double)); for(std::vector::iterator it = output_vars.begin(); it != output_vars.end(); ++it) { - b->GetVarType(it->c_str(), type); + type = b->GetVarType(*it); if(std::string(type) != "double") { continue; } - b->GetValueAtIndices(it->c_str(), vals, indices.data(), indices.size()); + b->GetValueAtIndices(*it, vals, indices.data(), indices.size()); request->set_name(*it); s->getValueAtIndices(NULL, request, response); for(int i = 0; i < response->mutable_values_double()->values_size(); ++i) @@ -421,17 +382,17 @@ void test_set_values(BmiGRPCService* s, BmiClass* b) { std::vector input_vars = get_bmi_varnames(b, SELECT_INPUT); std::vector output_vars = get_bmi_varnames(b, SELECT_OUTPUT); - char type[BMI_MAX_VAR_NAME]; + std::string type; bmi::SetValueRequest* request = new bmi::SetValueRequest(); bmi::Empty* response = new bmi::Empty(); for(std::vector::iterator it = input_vars.begin(); it != input_vars.end(); ++it) { - b->GetVarType(it->c_str(), type); + type = b->GetVarType(*it); if(std::string(type) != "double") { continue; } - int nbytes = b->GetVarNbytes(it->c_str()); + int nbytes = b->GetVarNbytes(*it); std::vectorvals(nbytes / sizeof(double)); request->set_name(*it); request->mutable_values_double()->clear_values(); @@ -444,7 +405,7 @@ void test_set_values(BmiGRPCService* s, BmiClass* b) if(std::find(output_vars.begin(), output_vars.end(), *it) != output_vars.end()) { void* check_vals = malloc(nbytes); - b->GetValue(it->c_str(), check_vals); + b->GetValue(*it, check_vals); for(std::vector::size_type i = 0; i < vals.size(); ++i) { assert(vals[i] == *(static_cast(check_vals) + i)); @@ -461,7 +422,7 @@ void test_set_values_at_indices(BmiGRPCService* s, BmiClass* b) std::vectorindices = {0, 2, 4, 6}; std::vector input_vars = get_bmi_varnames(b, SELECT_INPUT); std::vector output_vars = get_bmi_varnames(b, SELECT_OUTPUT); - char type[BMI_MAX_VAR_NAME]; + std::string type; bmi::SetValueAtIndicesRequest* request = new bmi::SetValueAtIndicesRequest(); for(std::vector::const_iterator it = indices.begin(); it != indices.end(); ++it) { @@ -470,7 +431,7 @@ void test_set_values_at_indices(BmiGRPCService* s, BmiClass* b) bmi::Empty* response = new bmi::Empty(); for(std::vector::iterator it = input_vars.begin(); it != input_vars.end(); ++it) { - b->GetVarType(it->c_str(), type); + type = b->GetVarType(*it); if(std::string(type) != "double") { continue; @@ -563,8 +524,7 @@ void test_get_grid_type(BmiGRPCService* s, BmiClass* b) bmi::GetGridTypeResponse* response = new bmi::GetGridTypeResponse(); for(std::vector::const_iterator it = grids.begin(); it != grids.end(); ++it) { - char type[BMI_MAX_VAR_NAME]; - b->GetGridType(*it, type); + std::string type = b->GetGridType(*it); request->set_grid_id(*it); s->getGridType(NULL, request, response); std::string typegrpc = response->type(); @@ -599,17 +559,17 @@ int main(int argc, char* argv[]) { test_component_name(bmi_service, bmi); } - else if(testfunc == "input_var_count") + else if(testfunc == "input_item_count") { - test_input_var_count(bmi_service, bmi); + test_input_item_count(bmi_service, bmi); } else if(testfunc == "input_vars") { test_input_vars(bmi_service, bmi); } - else if(testfunc == "output_var_count") + else if(testfunc == "output_item_count") { - test_output_var_count(bmi_service, bmi); + test_output_item_count(bmi_service, bmi); } else if(testfunc == "output_vars") { diff --git a/docs/server/Cpp.rst b/docs/server/Cpp.rst index 94dbbb2..fe8dd49 100644 --- a/docs/server/Cpp.rst +++ b/docs/server/Cpp.rst @@ -10,8 +10,15 @@ For native programming languages it is necessary to install and compile the C++ .. code-block:: sh git clone -b $(curl -L https://grpc.io/release) --depth=1 https://github.com/grpc/grpc - cd grpc && git submodule update --init --recursive - sudo make install && cd third_party/protobuf && sudo make install + cd grpc + git submodule update --init --recursive + wget -q -O cmake-linux.sh https://github.com/Kitware/CMake/releases/download/v3.16.5/cmake-3.16.5-Linux-x86_64.sh + sudo sh cmake-linux.sh -- --skip-license --prefix=/usr/local + rm cmake-linux.sh + mkdir cmake/build && cd cmake/build + /usr/local/bin/cmake ../.. -DgRPC_INSTALL=ON -DgRPC_SSL_PROVIDER=package -DgRPC_BUILD_TESTS=OFF -DBUILD_SHARED_LIBS=ON + sudo make -j4 install + sudo ldconfig You will also need to compile grpc4bmi diff --git a/grpc4bmi/bmi_grpc_client.py b/grpc4bmi/bmi_grpc_client.py index 030223c..5a30dc0 100644 --- a/grpc4bmi/bmi_grpc_client.py +++ b/grpc4bmi/bmi_grpc_client.py @@ -102,6 +102,12 @@ def update(self): except grpc.RpcError as e: handle_error(e) + def update_until(self, time: float) -> None: + try: + self.stub.updateUntil(bmi_pb2.GetTimeResponse(time=time)) + except grpc.RpcError as e: + handle_error(e) + def finalize(self): try: self.stub.finalize(bmi_pb2.Empty()) @@ -114,6 +120,18 @@ def get_component_name(self): except grpc.RpcError as e: handle_error(e) + def get_input_item_count(self) -> int: + try: + return self.stub.getInputItemCount(bmi_pb2.Empty()).count + except grpc.RpcError as e: + handle_error(e) + + def get_output_item_count(self) -> int: + try: + return self.stub.getOutputItemCount(bmi_pb2.Empty()).count + except grpc.RpcError as e: + handle_error(e) + def get_input_var_names(self): try: return tuple([str(s) for s in self.stub.getInputVarNames(bmi_pb2.Empty()).names]) @@ -345,7 +363,7 @@ def get_grid_face_count(self, grid: int) -> int: def get_grid_edge_nodes(self, grid: int, edge_nodes: np.ndarray) -> np.ndarray: try: - links = self.stub.getGridEdgeNodes(bmi_pb2.GridRequest(grid_id=grid)).links + links = self.stub.getGridEdgeNodes(bmi_pb2.GridRequest(grid_id=grid)).edge_nodes numpy.copyto(src=links, dst=edge_nodes) return edge_nodes except grpc.RpcError as e: @@ -353,15 +371,23 @@ def get_grid_edge_nodes(self, grid: int, edge_nodes: np.ndarray) -> np.ndarray: def get_grid_face_nodes(self, grid: int, face_nodes: np.ndarray) -> np.ndarray: try: - links = self.stub.getGridFaceNodes(bmi_pb2.GridRequest(grid_id=grid)).links + links = self.stub.getGridFaceNodes(bmi_pb2.GridRequest(grid_id=grid)).face_nodes numpy.copyto(src=links, dst=face_nodes) return face_nodes except grpc.RpcError as e: handle_error(e) + def get_grid_face_edges(self, grid: int, face_edges: np.ndarray) -> np.ndarray: + try: + links = self.stub.getGridFaceEdges(bmi_pb2.GridRequest(grid_id=grid)).face_edges + numpy.copyto(src=links, dst=face_edges) + return face_edges + except grpc.RpcError as e: + handle_error(e) + def get_grid_nodes_per_face(self, grid: int, nodes_per_face: np.ndarray) -> np.ndarray: try: - links = self.stub.getGridNodesPerFace(bmi_pb2.GridRequest(grid_id=grid)).links + links = self.stub.getGridNodesPerFace(bmi_pb2.GridRequest(grid_id=grid)).nodes_per_face numpy.copyto(src=links, dst=nodes_per_face) return nodes_per_face except grpc.RpcError as e: diff --git a/grpc4bmi/bmi_grpc_server.py b/grpc4bmi/bmi_grpc_server.py index a1bc790..f9903a0 100644 --- a/grpc4bmi/bmi_grpc_server.py +++ b/grpc4bmi/bmi_grpc_server.py @@ -66,6 +66,13 @@ def update(self, request, context): except Exception as e: self.exception_handler(e, context) + def updateUntil(self, request, context): + try: + self.bmi_model_.update_until(request.time) + return bmi_pb2.Empty() + except Exception as e: + self.exception_handler(e, context) + def finalize(self, request, context): try: self.bmi_model_.finalize() @@ -79,6 +86,18 @@ def getComponentName(self, request, context): except Exception as e: self.exception_handler(e, context) + def getInputItemCount(self, request, context): + try: + return bmi_pb2.GetCountResponse(count=self.bmi_model_.get_input_item_count()) + except Exception as e: + self.exception_handler(e, context) + + def getOutputItemCount(self, request, context): + try: + return bmi_pb2.GetCountResponse(count=self.bmi_model_.get_output_item_count()) + except Exception as e: + self.exception_handler(e, context) + def getInputVarNames(self, request, context): try: return bmi_pb2.GetVarNamesResponse(names=self.bmi_model_.get_input_var_names()) @@ -281,19 +300,19 @@ def getGridZ(self, request, context): def getGridNodeCount(self, request, context): try: - return bmi_pb2.GetGridElementCountResponse(count=self.bmi_model_.get_grid_node_count(request.grid_id)) + return bmi_pb2.GetCountResponse(count=self.bmi_model_.get_grid_node_count(request.grid_id)) except Exception as e: self.exception_handler(e, context) def getGridEdgeCount(self, request, context): try: - return bmi_pb2.GetGridElementCountResponse(count=self.bmi_model_.get_grid_edge_count(request.grid_id)) + return bmi_pb2.GetCountResponse(count=self.bmi_model_.get_grid_edge_count(request.grid_id)) except Exception as e: self.exception_handler(e, context) def getGridFaceCount(self, request, context): try: - return bmi_pb2.GetGridElementCountResponse(count=self.bmi_model_.get_grid_face_count(request.grid_id)) + return bmi_pb2.GetCountResponse(count=self.bmi_model_.get_grid_face_count(request.grid_id)) except Exception as e: self.exception_handler(e, context) @@ -302,7 +321,7 @@ def getGridEdgeNodes(self, request, context): size = 2 * self.bmi_model_.get_grid_edge_count(request.grid_id) links = numpy.empty(size, dtype=numpy.int64) links = self.bmi_model_.get_grid_edge_nodes(request.grid_id, links) - return bmi_pb2.GetGridEdgeNodesResponse(links=links) + return bmi_pb2.GetGridEdgeNodesResponse(edge_nodes=links) except Exception as e: self.exception_handler(e, context) @@ -317,14 +336,24 @@ def getGridFaceNodes(self, request, context): size = numpy.sum(nodes_per_face) links = numpy.empty(size, dtype=numpy.int64) links = self.bmi_model_.get_grid_face_nodes(request.grid_id, links) - return bmi_pb2.GetGridFaceNodesResponse(links=links) + return bmi_pb2.GetGridFaceNodesResponse(face_nodes=links) + except Exception as e: + self.exception_handler(e, context) + + def getGridFaceEdges(self, request, context): + try: + nodes_per_face = self._get_grid_nodes_per_face(request.grid_id) + size = numpy.sum(nodes_per_face) + face_edges = numpy.empty(size, dtype=numpy.int64) + face_edges = self.bmi_model_.get_grid_face_edges(request.grid_id, face_edges) + return bmi_pb2.GetGridFaceEdgesResponse(face_edges=face_edges) except Exception as e: self.exception_handler(e, context) def getGridNodesPerFace(self, request, context): try: - links = self._get_grid_nodes_per_face(request.grid_id) - return bmi_pb2.GetGridNodesPerFaceResponse(links=links) + nodes_per_face = self._get_grid_nodes_per_face(request.grid_id) + return bmi_pb2.GetGridNodesPerFaceResponse(nodes_per_face=nodes_per_face) except Exception as e: self.exception_handler(e, context) diff --git a/grpc4bmi/bmi_pb2.py b/grpc4bmi/bmi_pb2.py index f76a8ca..6b6f9c4 100644 --- a/grpc4bmi/bmi_pb2.py +++ b/grpc4bmi/bmi_pb2.py @@ -2,8 +2,6 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # source: grpc4bmi/bmi.proto -import sys -_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) from google.protobuf import descriptor as _descriptor from google.protobuf import message as _message from google.protobuf import reflection as _reflection @@ -20,7 +18,7 @@ package='bmi', syntax='proto3', serialized_options=None, - serialized_pb=_b('\n\x12grpc4bmi/bmi.proto\x12\x03\x62mi\"\x07\n\x05\x45mpty\"(\n\x11InitializeRequest\x12\x13\n\x0b\x63onfig_file\x18\x01 \x01(\t\"(\n\x18GetComponentNameResponse\x12\x0c\n\x04name\x18\x01 \x01(\t\"$\n\x13GetVarNamesResponse\x12\r\n\x05names\x18\x01 \x03(\t\"%\n\x14GetTimeUnitsResponse\x12\r\n\x05units\x18\x01 \x01(\t\"\'\n\x13GetTimeStepResponse\x12\x10\n\x08interval\x18\x01 \x01(\x01\"\x1f\n\x0fGetTimeResponse\x12\x0c\n\x04time\x18\x01 \x01(\x01\"\x1d\n\rGetVarRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\"%\n\x12GetVarGridResponse\x12\x0f\n\x07grid_id\x18\x01 \x01(\x05\"\"\n\x12GetVarTypeResponse\x12\x0c\n\x04type\x18\x01 \x01(\t\"&\n\x16GetVarItemSizeResponse\x12\x0c\n\x04size\x18\x01 \x01(\x03\"$\n\x13GetVarUnitsResponse\x12\r\n\x05units\x18\x01 \x01(\t\"&\n\x14GetVarNBytesResponse\x12\x0e\n\x06nbytes\x18\x01 \x01(\x03\"z\n\x16GetVarLocationResponse\x12\x36\n\x08location\x18\x01 \x01(\x0e\x32$.bmi.GetVarLocationResponse.Location\"(\n\x08Location\x12\x08\n\x04NODE\x10\x00\x12\x08\n\x04\x45\x44GE\x10\x01\x12\x08\n\x04\x46\x41\x43\x45\x10\x02\"%\n\x0fIntArrayMessage\x12\x12\n\x06values\x18\x01 \x03(\x03\x42\x02\x10\x01\"\'\n\x11\x46loatArrayMessage\x12\x12\n\x06values\x18\x01 \x03(\x02\x42\x02\x10\x01\"(\n\x12\x44oubleArrayMessage\x12\x12\n\x06values\x18\x01 \x03(\x01\x42\x02\x10\x01\"\xaa\x01\n\x10GetValueResponse\x12*\n\nvalues_int\x18\x01 \x01(\x0b\x32\x14.bmi.IntArrayMessageH\x00\x12.\n\x0cvalues_float\x18\x02 \x01(\x0b\x32\x16.bmi.FloatArrayMessageH\x00\x12\x30\n\rvalues_double\x18\x03 \x01(\x0b\x32\x17.bmi.DoubleArrayMessageH\x00\x42\x08\n\x06values\"=\n\x18GetValueAtIndicesRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x13\n\x07indices\x18\x02 \x03(\x03\x42\x02\x10\x01\"\xb3\x01\n\x19GetValueAtIndicesResponse\x12*\n\nvalues_int\x18\x01 \x01(\x0b\x32\x14.bmi.IntArrayMessageH\x00\x12.\n\x0cvalues_float\x18\x02 \x01(\x0b\x32\x16.bmi.FloatArrayMessageH\x00\x12\x30\n\rvalues_double\x18\x03 \x01(\x0b\x32\x17.bmi.DoubleArrayMessageH\x00\x42\x08\n\x06values\"\xb7\x01\n\x0fSetValueRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\x12*\n\nvalues_int\x18\x02 \x01(\x0b\x32\x14.bmi.IntArrayMessageH\x00\x12.\n\x0cvalues_float\x18\x03 \x01(\x0b\x32\x16.bmi.FloatArrayMessageH\x00\x12\x30\n\rvalues_double\x18\x04 \x01(\x0b\x32\x17.bmi.DoubleArrayMessageH\x00\x42\x08\n\x06values\"/\n\x12SetValuePtrRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0b\n\x03ref\x18\x02 \x01(\x03\"\xd5\x01\n\x18SetValueAtIndicesRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x13\n\x07indices\x18\x02 \x03(\x03\x42\x02\x10\x01\x12*\n\nvalues_int\x18\x03 \x01(\x0b\x32\x14.bmi.IntArrayMessageH\x00\x12.\n\x0cvalues_float\x18\x04 \x01(\x0b\x32\x16.bmi.FloatArrayMessageH\x00\x12\x30\n\rvalues_double\x18\x05 \x01(\x0b\x32\x17.bmi.DoubleArrayMessageH\x00\x42\x08\n\x06values\"\x1e\n\x0bGridRequest\x12\x0f\n\x07grid_id\x18\x01 \x01(\x03\"#\n\x13GetGridSizeResponse\x12\x0c\n\x04size\x18\x01 \x01(\x03\"#\n\x13GetGridRankResponse\x12\x0c\n\x04rank\x18\x01 \x01(\x03\"#\n\x13GetGridTypeResponse\x12\x0c\n\x04type\x18\x01 \x01(\t\")\n\x14GetGridShapeResponse\x12\x11\n\x05shape\x18\x01 \x03(\x03\x42\x02\x10\x01\"-\n\x16GetGridSpacingResponse\x12\x13\n\x07spacing\x18\x01 \x03(\x01\x42\x02\x10\x01\"+\n\x15GetGridOriginResponse\x12\x12\n\x06origin\x18\x01 \x03(\x01\x42\x02\x10\x01\"0\n\x15GetGridPointsResponse\x12\x17\n\x0b\x63oordinates\x18\x01 \x03(\x01\x42\x02\x10\x01\",\n\x1bGetGridElementCountResponse\x12\r\n\x05\x63ount\x18\x01 \x01(\x03\"-\n\x18GetGridEdgeNodesResponse\x12\x11\n\x05links\x18\x01 \x03(\x03\x42\x02\x10\x01\"-\n\x18GetGridFaceNodesResponse\x12\x11\n\x05links\x18\x01 \x03(\x03\x42\x02\x10\x01\"0\n\x1bGetGridNodesPerFaceResponse\x12\x11\n\x05links\x18\x01 \x03(\x03\x42\x02\x10\x01\x32\xbc\x11\n\nBmiService\x12\x32\n\ninitialize\x12\x16.bmi.InitializeRequest\x1a\n.bmi.Empty\"\x00\x12\"\n\x06update\x12\n.bmi.Empty\x1a\n.bmi.Empty\"\x00\x12$\n\x08\x66inalize\x12\n.bmi.Empty\x1a\n.bmi.Empty\"\x00\x12?\n\x10getComponentName\x12\n.bmi.Empty\x1a\x1d.bmi.GetComponentNameResponse\"\x00\x12:\n\x10getInputVarNames\x12\n.bmi.Empty\x1a\x18.bmi.GetVarNamesResponse\"\x00\x12;\n\x11getOutputVarNames\x12\n.bmi.Empty\x1a\x18.bmi.GetVarNamesResponse\"\x00\x12\x37\n\x0cgetTimeUnits\x12\n.bmi.Empty\x1a\x19.bmi.GetTimeUnitsResponse\"\x00\x12\x35\n\x0bgetTimeStep\x12\n.bmi.Empty\x1a\x18.bmi.GetTimeStepResponse\"\x00\x12\x34\n\x0egetCurrentTime\x12\n.bmi.Empty\x1a\x14.bmi.GetTimeResponse\"\x00\x12\x32\n\x0cgetStartTime\x12\n.bmi.Empty\x1a\x14.bmi.GetTimeResponse\"\x00\x12\x30\n\ngetEndTime\x12\n.bmi.Empty\x1a\x14.bmi.GetTimeResponse\"\x00\x12;\n\ngetVarGrid\x12\x12.bmi.GetVarRequest\x1a\x17.bmi.GetVarGridResponse\"\x00\x12;\n\ngetVarType\x12\x12.bmi.GetVarRequest\x1a\x17.bmi.GetVarTypeResponse\"\x00\x12\x43\n\x0egetVarItemSize\x12\x12.bmi.GetVarRequest\x1a\x1b.bmi.GetVarItemSizeResponse\"\x00\x12=\n\x0bgetVarUnits\x12\x12.bmi.GetVarRequest\x1a\x18.bmi.GetVarUnitsResponse\"\x00\x12?\n\x0cgetVarNBytes\x12\x12.bmi.GetVarRequest\x1a\x19.bmi.GetVarNBytesResponse\"\x00\x12\x43\n\x0egetVarLocation\x12\x12.bmi.GetVarRequest\x1a\x1b.bmi.GetVarLocationResponse\"\x00\x12\x37\n\x08getValue\x12\x12.bmi.GetVarRequest\x1a\x15.bmi.GetValueResponse\"\x00\x12T\n\x11getValueAtIndices\x12\x1d.bmi.GetValueAtIndicesRequest\x1a\x1e.bmi.GetValueAtIndicesResponse\"\x00\x12.\n\x08setValue\x12\x14.bmi.SetValueRequest\x1a\n.bmi.Empty\"\x00\x12@\n\x11setValueAtIndices\x12\x1d.bmi.SetValueAtIndicesRequest\x1a\n.bmi.Empty\"\x00\x12;\n\x0bgetGridSize\x12\x10.bmi.GridRequest\x1a\x18.bmi.GetGridSizeResponse\"\x00\x12;\n\x0bgetGridType\x12\x10.bmi.GridRequest\x1a\x18.bmi.GetGridTypeResponse\"\x00\x12;\n\x0bgetGridRank\x12\x10.bmi.GridRequest\x1a\x18.bmi.GetGridRankResponse\"\x00\x12=\n\x0cgetGridShape\x12\x10.bmi.GridRequest\x1a\x19.bmi.GetGridShapeResponse\"\x00\x12\x41\n\x0egetGridSpacing\x12\x10.bmi.GridRequest\x1a\x1b.bmi.GetGridSpacingResponse\"\x00\x12?\n\rgetGridOrigin\x12\x10.bmi.GridRequest\x1a\x1a.bmi.GetGridOriginResponse\"\x00\x12:\n\x08getGridX\x12\x10.bmi.GridRequest\x1a\x1a.bmi.GetGridPointsResponse\"\x00\x12:\n\x08getGridY\x12\x10.bmi.GridRequest\x1a\x1a.bmi.GetGridPointsResponse\"\x00\x12:\n\x08getGridZ\x12\x10.bmi.GridRequest\x1a\x1a.bmi.GetGridPointsResponse\"\x00\x12H\n\x10getGridNodeCount\x12\x10.bmi.GridRequest\x1a .bmi.GetGridElementCountResponse\"\x00\x12H\n\x10getGridEdgeCount\x12\x10.bmi.GridRequest\x1a .bmi.GetGridElementCountResponse\"\x00\x12H\n\x10getGridFaceCount\x12\x10.bmi.GridRequest\x1a .bmi.GetGridElementCountResponse\"\x00\x12\x45\n\x10getGridEdgeNodes\x12\x10.bmi.GridRequest\x1a\x1d.bmi.GetGridEdgeNodesResponse\"\x00\x12\x45\n\x10getGridFaceNodes\x12\x10.bmi.GridRequest\x1a\x1d.bmi.GetGridFaceNodesResponse\"\x00\x12K\n\x13getGridNodesPerFace\x12\x10.bmi.GridRequest\x1a .bmi.GetGridNodesPerFaceResponse\"\x00\x62\x06proto3') + serialized_pb=b'\n\x12grpc4bmi/bmi.proto\x12\x03\x62mi\"\x07\n\x05\x45mpty\"(\n\x11InitializeRequest\x12\x13\n\x0b\x63onfig_file\x18\x01 \x01(\t\"(\n\x18GetComponentNameResponse\x12\x0c\n\x04name\x18\x01 \x01(\t\"$\n\x13GetVarNamesResponse\x12\r\n\x05names\x18\x01 \x03(\t\"%\n\x14GetTimeUnitsResponse\x12\r\n\x05units\x18\x01 \x01(\t\"\'\n\x13GetTimeStepResponse\x12\x10\n\x08interval\x18\x01 \x01(\x01\"\x1f\n\x0fGetTimeResponse\x12\x0c\n\x04time\x18\x01 \x01(\x01\"\x1d\n\rGetVarRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\"%\n\x12GetVarGridResponse\x12\x0f\n\x07grid_id\x18\x01 \x01(\x05\"\"\n\x12GetVarTypeResponse\x12\x0c\n\x04type\x18\x01 \x01(\t\"&\n\x16GetVarItemSizeResponse\x12\x0c\n\x04size\x18\x01 \x01(\x03\"$\n\x13GetVarUnitsResponse\x12\r\n\x05units\x18\x01 \x01(\t\"&\n\x14GetVarNBytesResponse\x12\x0e\n\x06nbytes\x18\x01 \x01(\x03\"z\n\x16GetVarLocationResponse\x12\x36\n\x08location\x18\x01 \x01(\x0e\x32$.bmi.GetVarLocationResponse.Location\"(\n\x08Location\x12\x08\n\x04NODE\x10\x00\x12\x08\n\x04\x45\x44GE\x10\x01\x12\x08\n\x04\x46\x41\x43\x45\x10\x02\"%\n\x0fIntArrayMessage\x12\x12\n\x06values\x18\x01 \x03(\x03\x42\x02\x10\x01\"\'\n\x11\x46loatArrayMessage\x12\x12\n\x06values\x18\x01 \x03(\x02\x42\x02\x10\x01\"(\n\x12\x44oubleArrayMessage\x12\x12\n\x06values\x18\x01 \x03(\x01\x42\x02\x10\x01\"\xaa\x01\n\x10GetValueResponse\x12*\n\nvalues_int\x18\x01 \x01(\x0b\x32\x14.bmi.IntArrayMessageH\x00\x12.\n\x0cvalues_float\x18\x02 \x01(\x0b\x32\x16.bmi.FloatArrayMessageH\x00\x12\x30\n\rvalues_double\x18\x03 \x01(\x0b\x32\x17.bmi.DoubleArrayMessageH\x00\x42\x08\n\x06values\"=\n\x18GetValueAtIndicesRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x13\n\x07indices\x18\x02 \x03(\x03\x42\x02\x10\x01\"\xb3\x01\n\x19GetValueAtIndicesResponse\x12*\n\nvalues_int\x18\x01 \x01(\x0b\x32\x14.bmi.IntArrayMessageH\x00\x12.\n\x0cvalues_float\x18\x02 \x01(\x0b\x32\x16.bmi.FloatArrayMessageH\x00\x12\x30\n\rvalues_double\x18\x03 \x01(\x0b\x32\x17.bmi.DoubleArrayMessageH\x00\x42\x08\n\x06values\"\xb7\x01\n\x0fSetValueRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\x12*\n\nvalues_int\x18\x02 \x01(\x0b\x32\x14.bmi.IntArrayMessageH\x00\x12.\n\x0cvalues_float\x18\x03 \x01(\x0b\x32\x16.bmi.FloatArrayMessageH\x00\x12\x30\n\rvalues_double\x18\x04 \x01(\x0b\x32\x17.bmi.DoubleArrayMessageH\x00\x42\x08\n\x06values\"/\n\x12SetValuePtrRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0b\n\x03ref\x18\x02 \x01(\x03\"\xd5\x01\n\x18SetValueAtIndicesRequest\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x13\n\x07indices\x18\x02 \x03(\x03\x42\x02\x10\x01\x12*\n\nvalues_int\x18\x03 \x01(\x0b\x32\x14.bmi.IntArrayMessageH\x00\x12.\n\x0cvalues_float\x18\x04 \x01(\x0b\x32\x16.bmi.FloatArrayMessageH\x00\x12\x30\n\rvalues_double\x18\x05 \x01(\x0b\x32\x17.bmi.DoubleArrayMessageH\x00\x42\x08\n\x06values\"\x1e\n\x0bGridRequest\x12\x0f\n\x07grid_id\x18\x01 \x01(\x03\"#\n\x13GetGridSizeResponse\x12\x0c\n\x04size\x18\x01 \x01(\x03\"#\n\x13GetGridRankResponse\x12\x0c\n\x04rank\x18\x01 \x01(\x03\"#\n\x13GetGridTypeResponse\x12\x0c\n\x04type\x18\x01 \x01(\t\")\n\x14GetGridShapeResponse\x12\x11\n\x05shape\x18\x01 \x03(\x03\x42\x02\x10\x01\"-\n\x16GetGridSpacingResponse\x12\x13\n\x07spacing\x18\x01 \x03(\x01\x42\x02\x10\x01\"+\n\x15GetGridOriginResponse\x12\x12\n\x06origin\x18\x01 \x03(\x01\x42\x02\x10\x01\"0\n\x15GetGridPointsResponse\x12\x17\n\x0b\x63oordinates\x18\x01 \x03(\x01\x42\x02\x10\x01\"!\n\x10GetCountResponse\x12\r\n\x05\x63ount\x18\x01 \x01(\x03\"2\n\x18GetGridEdgeNodesResponse\x12\x16\n\nedge_nodes\x18\x01 \x03(\x03\x42\x02\x10\x01\"2\n\x18GetGridFaceEdgesResponse\x12\x16\n\nface_edges\x18\x01 \x03(\x03\x42\x02\x10\x01\"2\n\x18GetGridFaceNodesResponse\x12\x16\n\nface_nodes\x18\x01 \x03(\x03\x42\x02\x10\x01\"9\n\x1bGetGridNodesPerFaceResponse\x12\x1a\n\x0enodes_per_face\x18\x01 \x03(\x03\x42\x02\x10\x01\x32\x8a\x13\n\nBmiService\x12\x32\n\ninitialize\x12\x16.bmi.InitializeRequest\x1a\n.bmi.Empty\"\x00\x12\"\n\x06update\x12\n.bmi.Empty\x1a\n.bmi.Empty\"\x00\x12\x31\n\x0bupdateUntil\x12\x14.bmi.GetTimeResponse\x1a\n.bmi.Empty\"\x00\x12$\n\x08\x66inalize\x12\n.bmi.Empty\x1a\n.bmi.Empty\"\x00\x12?\n\x10getComponentName\x12\n.bmi.Empty\x1a\x1d.bmi.GetComponentNameResponse\"\x00\x12\x38\n\x11getInputItemCount\x12\n.bmi.Empty\x1a\x15.bmi.GetCountResponse\"\x00\x12\x39\n\x12getOutputItemCount\x12\n.bmi.Empty\x1a\x15.bmi.GetCountResponse\"\x00\x12:\n\x10getInputVarNames\x12\n.bmi.Empty\x1a\x18.bmi.GetVarNamesResponse\"\x00\x12;\n\x11getOutputVarNames\x12\n.bmi.Empty\x1a\x18.bmi.GetVarNamesResponse\"\x00\x12\x37\n\x0cgetTimeUnits\x12\n.bmi.Empty\x1a\x19.bmi.GetTimeUnitsResponse\"\x00\x12\x35\n\x0bgetTimeStep\x12\n.bmi.Empty\x1a\x18.bmi.GetTimeStepResponse\"\x00\x12\x34\n\x0egetCurrentTime\x12\n.bmi.Empty\x1a\x14.bmi.GetTimeResponse\"\x00\x12\x32\n\x0cgetStartTime\x12\n.bmi.Empty\x1a\x14.bmi.GetTimeResponse\"\x00\x12\x30\n\ngetEndTime\x12\n.bmi.Empty\x1a\x14.bmi.GetTimeResponse\"\x00\x12;\n\ngetVarGrid\x12\x12.bmi.GetVarRequest\x1a\x17.bmi.GetVarGridResponse\"\x00\x12;\n\ngetVarType\x12\x12.bmi.GetVarRequest\x1a\x17.bmi.GetVarTypeResponse\"\x00\x12\x43\n\x0egetVarItemSize\x12\x12.bmi.GetVarRequest\x1a\x1b.bmi.GetVarItemSizeResponse\"\x00\x12=\n\x0bgetVarUnits\x12\x12.bmi.GetVarRequest\x1a\x18.bmi.GetVarUnitsResponse\"\x00\x12?\n\x0cgetVarNBytes\x12\x12.bmi.GetVarRequest\x1a\x19.bmi.GetVarNBytesResponse\"\x00\x12\x43\n\x0egetVarLocation\x12\x12.bmi.GetVarRequest\x1a\x1b.bmi.GetVarLocationResponse\"\x00\x12\x37\n\x08getValue\x12\x12.bmi.GetVarRequest\x1a\x15.bmi.GetValueResponse\"\x00\x12T\n\x11getValueAtIndices\x12\x1d.bmi.GetValueAtIndicesRequest\x1a\x1e.bmi.GetValueAtIndicesResponse\"\x00\x12.\n\x08setValue\x12\x14.bmi.SetValueRequest\x1a\n.bmi.Empty\"\x00\x12@\n\x11setValueAtIndices\x12\x1d.bmi.SetValueAtIndicesRequest\x1a\n.bmi.Empty\"\x00\x12;\n\x0bgetGridSize\x12\x10.bmi.GridRequest\x1a\x18.bmi.GetGridSizeResponse\"\x00\x12;\n\x0bgetGridType\x12\x10.bmi.GridRequest\x1a\x18.bmi.GetGridTypeResponse\"\x00\x12;\n\x0bgetGridRank\x12\x10.bmi.GridRequest\x1a\x18.bmi.GetGridRankResponse\"\x00\x12=\n\x0cgetGridShape\x12\x10.bmi.GridRequest\x1a\x19.bmi.GetGridShapeResponse\"\x00\x12\x41\n\x0egetGridSpacing\x12\x10.bmi.GridRequest\x1a\x1b.bmi.GetGridSpacingResponse\"\x00\x12?\n\rgetGridOrigin\x12\x10.bmi.GridRequest\x1a\x1a.bmi.GetGridOriginResponse\"\x00\x12:\n\x08getGridX\x12\x10.bmi.GridRequest\x1a\x1a.bmi.GetGridPointsResponse\"\x00\x12:\n\x08getGridY\x12\x10.bmi.GridRequest\x1a\x1a.bmi.GetGridPointsResponse\"\x00\x12:\n\x08getGridZ\x12\x10.bmi.GridRequest\x1a\x1a.bmi.GetGridPointsResponse\"\x00\x12=\n\x10getGridNodeCount\x12\x10.bmi.GridRequest\x1a\x15.bmi.GetCountResponse\"\x00\x12=\n\x10getGridEdgeCount\x12\x10.bmi.GridRequest\x1a\x15.bmi.GetCountResponse\"\x00\x12=\n\x10getGridFaceCount\x12\x10.bmi.GridRequest\x1a\x15.bmi.GetCountResponse\"\x00\x12\x45\n\x10getGridEdgeNodes\x12\x10.bmi.GridRequest\x1a\x1d.bmi.GetGridEdgeNodesResponse\"\x00\x12\x45\n\x10getGridFaceNodes\x12\x10.bmi.GridRequest\x1a\x1d.bmi.GetGridFaceNodesResponse\"\x00\x12\x45\n\x10getGridFaceEdges\x12\x10.bmi.GridRequest\x1a\x1d.bmi.GetGridFaceEdgesResponse\"\x00\x12K\n\x13getGridNodesPerFace\x12\x10.bmi.GridRequest\x1a .bmi.GetGridNodesPerFaceResponse\"\x00\x62\x06proto3' ) @@ -86,7 +84,7 @@ _descriptor.FieldDescriptor( name='config_file', full_name='bmi.InitializeRequest.config_file', index=0, number=1, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), + has_default_value=False, default_value=b"".decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, serialized_options=None, file=DESCRIPTOR), @@ -117,7 +115,7 @@ _descriptor.FieldDescriptor( name='name', full_name='bmi.GetComponentNameResponse.name', index=0, number=1, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), + has_default_value=False, default_value=b"".decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, serialized_options=None, file=DESCRIPTOR), @@ -179,7 +177,7 @@ _descriptor.FieldDescriptor( name='units', full_name='bmi.GetTimeUnitsResponse.units', index=0, number=1, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), + has_default_value=False, default_value=b"".decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, serialized_options=None, file=DESCRIPTOR), @@ -272,7 +270,7 @@ _descriptor.FieldDescriptor( name='name', full_name='bmi.GetVarRequest.name', index=0, number=1, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), + has_default_value=False, default_value=b"".decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, serialized_options=None, file=DESCRIPTOR), @@ -334,7 +332,7 @@ _descriptor.FieldDescriptor( name='type', full_name='bmi.GetVarTypeResponse.type', index=0, number=1, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), + has_default_value=False, default_value=b"".decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, serialized_options=None, file=DESCRIPTOR), @@ -396,7 +394,7 @@ _descriptor.FieldDescriptor( name='units', full_name='bmi.GetVarUnitsResponse.units', index=0, number=1, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), + has_default_value=False, default_value=b"".decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, serialized_options=None, file=DESCRIPTOR), @@ -493,7 +491,7 @@ has_default_value=False, default_value=[], message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, - serialized_options=_b('\020\001'), file=DESCRIPTOR), + serialized_options=b'\020\001', file=DESCRIPTOR), ], extensions=[ ], @@ -524,7 +522,7 @@ has_default_value=False, default_value=[], message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, - serialized_options=_b('\020\001'), file=DESCRIPTOR), + serialized_options=b'\020\001', file=DESCRIPTOR), ], extensions=[ ], @@ -555,7 +553,7 @@ has_default_value=False, default_value=[], message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, - serialized_options=_b('\020\001'), file=DESCRIPTOR), + serialized_options=b'\020\001', file=DESCRIPTOR), ], extensions=[ ], @@ -631,7 +629,7 @@ _descriptor.FieldDescriptor( name='name', full_name='bmi.GetValueAtIndicesRequest.name', index=0, number=1, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), + has_default_value=False, default_value=b"".decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, serialized_options=None, file=DESCRIPTOR), @@ -641,7 +639,7 @@ has_default_value=False, default_value=[], message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, - serialized_options=_b('\020\001'), file=DESCRIPTOR), + serialized_options=b'\020\001', file=DESCRIPTOR), ], extensions=[ ], @@ -717,7 +715,7 @@ _descriptor.FieldDescriptor( name='name', full_name='bmi.SetValueRequest.name', index=0, number=1, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), + has_default_value=False, default_value=b"".decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, serialized_options=None, file=DESCRIPTOR), @@ -772,7 +770,7 @@ _descriptor.FieldDescriptor( name='name', full_name='bmi.SetValuePtrRequest.name', index=0, number=1, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), + has_default_value=False, default_value=b"".decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, serialized_options=None, file=DESCRIPTOR), @@ -810,7 +808,7 @@ _descriptor.FieldDescriptor( name='name', full_name='bmi.SetValueAtIndicesRequest.name', index=0, number=1, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), + has_default_value=False, default_value=b"".decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, serialized_options=None, file=DESCRIPTOR), @@ -820,7 +818,7 @@ has_default_value=False, default_value=[], message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, - serialized_options=_b('\020\001'), file=DESCRIPTOR), + serialized_options=b'\020\001', file=DESCRIPTOR), _descriptor.FieldDescriptor( name='values_int', full_name='bmi.SetValueAtIndicesRequest.values_int', index=2, number=3, type=11, cpp_type=10, label=1, @@ -965,7 +963,7 @@ _descriptor.FieldDescriptor( name='type', full_name='bmi.GetGridTypeResponse.type', index=0, number=1, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), + has_default_value=False, default_value=b"".decode('utf-8'), message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, serialized_options=None, file=DESCRIPTOR), @@ -999,7 +997,7 @@ has_default_value=False, default_value=[], message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, - serialized_options=_b('\020\001'), file=DESCRIPTOR), + serialized_options=b'\020\001', file=DESCRIPTOR), ], extensions=[ ], @@ -1030,7 +1028,7 @@ has_default_value=False, default_value=[], message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, - serialized_options=_b('\020\001'), file=DESCRIPTOR), + serialized_options=b'\020\001', file=DESCRIPTOR), ], extensions=[ ], @@ -1061,7 +1059,7 @@ has_default_value=False, default_value=[], message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, - serialized_options=_b('\020\001'), file=DESCRIPTOR), + serialized_options=b'\020\001', file=DESCRIPTOR), ], extensions=[ ], @@ -1092,7 +1090,7 @@ has_default_value=False, default_value=[], message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, - serialized_options=_b('\020\001'), file=DESCRIPTOR), + serialized_options=b'\020\001', file=DESCRIPTOR), ], extensions=[ ], @@ -1110,15 +1108,15 @@ ) -_GETGRIDELEMENTCOUNTRESPONSE = _descriptor.Descriptor( - name='GetGridElementCountResponse', - full_name='bmi.GetGridElementCountResponse', +_GETCOUNTRESPONSE = _descriptor.Descriptor( + name='GetCountResponse', + full_name='bmi.GetCountResponse', filename=None, file=DESCRIPTOR, containing_type=None, fields=[ _descriptor.FieldDescriptor( - name='count', full_name='bmi.GetGridElementCountResponse.count', index=0, + name='count', full_name='bmi.GetCountResponse.count', index=0, number=1, type=3, cpp_type=2, label=1, has_default_value=False, default_value=0, message_type=None, enum_type=None, containing_type=None, @@ -1137,7 +1135,7 @@ oneofs=[ ], serialized_start=1938, - serialized_end=1982, + serialized_end=1971, ) @@ -1149,12 +1147,12 @@ containing_type=None, fields=[ _descriptor.FieldDescriptor( - name='links', full_name='bmi.GetGridEdgeNodesResponse.links', index=0, + name='edge_nodes', full_name='bmi.GetGridEdgeNodesResponse.edge_nodes', index=0, number=1, type=3, cpp_type=2, label=3, has_default_value=False, default_value=[], message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, - serialized_options=_b('\020\001'), file=DESCRIPTOR), + serialized_options=b'\020\001', file=DESCRIPTOR), ], extensions=[ ], @@ -1167,8 +1165,39 @@ extension_ranges=[], oneofs=[ ], - serialized_start=1984, - serialized_end=2029, + serialized_start=1973, + serialized_end=2023, +) + + +_GETGRIDFACEEDGESRESPONSE = _descriptor.Descriptor( + name='GetGridFaceEdgesResponse', + full_name='bmi.GetGridFaceEdgesResponse', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='face_edges', full_name='bmi.GetGridFaceEdgesResponse.face_edges', index=0, + number=1, type=3, cpp_type=2, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=b'\020\001', file=DESCRIPTOR), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=2025, + serialized_end=2075, ) @@ -1180,12 +1209,12 @@ containing_type=None, fields=[ _descriptor.FieldDescriptor( - name='links', full_name='bmi.GetGridFaceNodesResponse.links', index=0, + name='face_nodes', full_name='bmi.GetGridFaceNodesResponse.face_nodes', index=0, number=1, type=3, cpp_type=2, label=3, has_default_value=False, default_value=[], message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, - serialized_options=_b('\020\001'), file=DESCRIPTOR), + serialized_options=b'\020\001', file=DESCRIPTOR), ], extensions=[ ], @@ -1198,8 +1227,8 @@ extension_ranges=[], oneofs=[ ], - serialized_start=2031, - serialized_end=2076, + serialized_start=2077, + serialized_end=2127, ) @@ -1211,12 +1240,12 @@ containing_type=None, fields=[ _descriptor.FieldDescriptor( - name='links', full_name='bmi.GetGridNodesPerFaceResponse.links', index=0, + name='nodes_per_face', full_name='bmi.GetGridNodesPerFaceResponse.nodes_per_face', index=0, number=1, type=3, cpp_type=2, label=3, has_default_value=False, default_value=[], message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, - serialized_options=_b('\020\001'), file=DESCRIPTOR), + serialized_options=b'\020\001', file=DESCRIPTOR), ], extensions=[ ], @@ -1229,8 +1258,8 @@ extension_ranges=[], oneofs=[ ], - serialized_start=2078, - serialized_end=2126, + serialized_start=2129, + serialized_end=2186, ) _GETVARLOCATIONRESPONSE.fields_by_name['location'].enum_type = _GETVARLOCATIONRESPONSE_LOCATION @@ -1314,8 +1343,9 @@ DESCRIPTOR.message_types_by_name['GetGridSpacingResponse'] = _GETGRIDSPACINGRESPONSE DESCRIPTOR.message_types_by_name['GetGridOriginResponse'] = _GETGRIDORIGINRESPONSE DESCRIPTOR.message_types_by_name['GetGridPointsResponse'] = _GETGRIDPOINTSRESPONSE -DESCRIPTOR.message_types_by_name['GetGridElementCountResponse'] = _GETGRIDELEMENTCOUNTRESPONSE +DESCRIPTOR.message_types_by_name['GetCountResponse'] = _GETCOUNTRESPONSE DESCRIPTOR.message_types_by_name['GetGridEdgeNodesResponse'] = _GETGRIDEDGENODESRESPONSE +DESCRIPTOR.message_types_by_name['GetGridFaceEdgesResponse'] = _GETGRIDFACEEDGESRESPONSE DESCRIPTOR.message_types_by_name['GetGridFaceNodesResponse'] = _GETGRIDFACENODESRESPONSE DESCRIPTOR.message_types_by_name['GetGridNodesPerFaceResponse'] = _GETGRIDNODESPERFACERESPONSE _sym_db.RegisterFileDescriptor(DESCRIPTOR) @@ -1537,12 +1567,12 @@ }) _sym_db.RegisterMessage(GetGridPointsResponse) -GetGridElementCountResponse = _reflection.GeneratedProtocolMessageType('GetGridElementCountResponse', (_message.Message,), { - 'DESCRIPTOR' : _GETGRIDELEMENTCOUNTRESPONSE, +GetCountResponse = _reflection.GeneratedProtocolMessageType('GetCountResponse', (_message.Message,), { + 'DESCRIPTOR' : _GETCOUNTRESPONSE, '__module__' : 'grpc4bmi.bmi_pb2' - # @@protoc_insertion_point(class_scope:bmi.GetGridElementCountResponse) + # @@protoc_insertion_point(class_scope:bmi.GetCountResponse) }) -_sym_db.RegisterMessage(GetGridElementCountResponse) +_sym_db.RegisterMessage(GetCountResponse) GetGridEdgeNodesResponse = _reflection.GeneratedProtocolMessageType('GetGridEdgeNodesResponse', (_message.Message,), { 'DESCRIPTOR' : _GETGRIDEDGENODESRESPONSE, @@ -1551,6 +1581,13 @@ }) _sym_db.RegisterMessage(GetGridEdgeNodesResponse) +GetGridFaceEdgesResponse = _reflection.GeneratedProtocolMessageType('GetGridFaceEdgesResponse', (_message.Message,), { + 'DESCRIPTOR' : _GETGRIDFACEEDGESRESPONSE, + '__module__' : 'grpc4bmi.bmi_pb2' + # @@protoc_insertion_point(class_scope:bmi.GetGridFaceEdgesResponse) + }) +_sym_db.RegisterMessage(GetGridFaceEdgesResponse) + GetGridFaceNodesResponse = _reflection.GeneratedProtocolMessageType('GetGridFaceNodesResponse', (_message.Message,), { 'DESCRIPTOR' : _GETGRIDFACENODESRESPONSE, '__module__' : 'grpc4bmi.bmi_pb2' @@ -1575,9 +1612,10 @@ _GETGRIDSPACINGRESPONSE.fields_by_name['spacing']._options = None _GETGRIDORIGINRESPONSE.fields_by_name['origin']._options = None _GETGRIDPOINTSRESPONSE.fields_by_name['coordinates']._options = None -_GETGRIDEDGENODESRESPONSE.fields_by_name['links']._options = None -_GETGRIDFACENODESRESPONSE.fields_by_name['links']._options = None -_GETGRIDNODESPERFACERESPONSE.fields_by_name['links']._options = None +_GETGRIDEDGENODESRESPONSE.fields_by_name['edge_nodes']._options = None +_GETGRIDFACEEDGESRESPONSE.fields_by_name['face_edges']._options = None +_GETGRIDFACENODESRESPONSE.fields_by_name['face_nodes']._options = None +_GETGRIDNODESPERFACERESPONSE.fields_by_name['nodes_per_face']._options = None _BMISERVICE = _descriptor.ServiceDescriptor( name='BmiService', @@ -1585,8 +1623,8 @@ file=DESCRIPTOR, index=0, serialized_options=None, - serialized_start=2129, - serialized_end=4365, + serialized_start=2189, + serialized_end=4631, methods=[ _descriptor.MethodDescriptor( name='initialize', @@ -1606,10 +1644,19 @@ output_type=_EMPTY, serialized_options=None, ), + _descriptor.MethodDescriptor( + name='updateUntil', + full_name='bmi.BmiService.updateUntil', + index=2, + containing_service=None, + input_type=_GETTIMERESPONSE, + output_type=_EMPTY, + serialized_options=None, + ), _descriptor.MethodDescriptor( name='finalize', full_name='bmi.BmiService.finalize', - index=2, + index=3, containing_service=None, input_type=_EMPTY, output_type=_EMPTY, @@ -1618,16 +1665,34 @@ _descriptor.MethodDescriptor( name='getComponentName', full_name='bmi.BmiService.getComponentName', - index=3, + index=4, containing_service=None, input_type=_EMPTY, output_type=_GETCOMPONENTNAMERESPONSE, serialized_options=None, ), + _descriptor.MethodDescriptor( + name='getInputItemCount', + full_name='bmi.BmiService.getInputItemCount', + index=5, + containing_service=None, + input_type=_EMPTY, + output_type=_GETCOUNTRESPONSE, + serialized_options=None, + ), + _descriptor.MethodDescriptor( + name='getOutputItemCount', + full_name='bmi.BmiService.getOutputItemCount', + index=6, + containing_service=None, + input_type=_EMPTY, + output_type=_GETCOUNTRESPONSE, + serialized_options=None, + ), _descriptor.MethodDescriptor( name='getInputVarNames', full_name='bmi.BmiService.getInputVarNames', - index=4, + index=7, containing_service=None, input_type=_EMPTY, output_type=_GETVARNAMESRESPONSE, @@ -1636,7 +1701,7 @@ _descriptor.MethodDescriptor( name='getOutputVarNames', full_name='bmi.BmiService.getOutputVarNames', - index=5, + index=8, containing_service=None, input_type=_EMPTY, output_type=_GETVARNAMESRESPONSE, @@ -1645,7 +1710,7 @@ _descriptor.MethodDescriptor( name='getTimeUnits', full_name='bmi.BmiService.getTimeUnits', - index=6, + index=9, containing_service=None, input_type=_EMPTY, output_type=_GETTIMEUNITSRESPONSE, @@ -1654,7 +1719,7 @@ _descriptor.MethodDescriptor( name='getTimeStep', full_name='bmi.BmiService.getTimeStep', - index=7, + index=10, containing_service=None, input_type=_EMPTY, output_type=_GETTIMESTEPRESPONSE, @@ -1663,7 +1728,7 @@ _descriptor.MethodDescriptor( name='getCurrentTime', full_name='bmi.BmiService.getCurrentTime', - index=8, + index=11, containing_service=None, input_type=_EMPTY, output_type=_GETTIMERESPONSE, @@ -1672,7 +1737,7 @@ _descriptor.MethodDescriptor( name='getStartTime', full_name='bmi.BmiService.getStartTime', - index=9, + index=12, containing_service=None, input_type=_EMPTY, output_type=_GETTIMERESPONSE, @@ -1681,7 +1746,7 @@ _descriptor.MethodDescriptor( name='getEndTime', full_name='bmi.BmiService.getEndTime', - index=10, + index=13, containing_service=None, input_type=_EMPTY, output_type=_GETTIMERESPONSE, @@ -1690,7 +1755,7 @@ _descriptor.MethodDescriptor( name='getVarGrid', full_name='bmi.BmiService.getVarGrid', - index=11, + index=14, containing_service=None, input_type=_GETVARREQUEST, output_type=_GETVARGRIDRESPONSE, @@ -1699,7 +1764,7 @@ _descriptor.MethodDescriptor( name='getVarType', full_name='bmi.BmiService.getVarType', - index=12, + index=15, containing_service=None, input_type=_GETVARREQUEST, output_type=_GETVARTYPERESPONSE, @@ -1708,7 +1773,7 @@ _descriptor.MethodDescriptor( name='getVarItemSize', full_name='bmi.BmiService.getVarItemSize', - index=13, + index=16, containing_service=None, input_type=_GETVARREQUEST, output_type=_GETVARITEMSIZERESPONSE, @@ -1717,7 +1782,7 @@ _descriptor.MethodDescriptor( name='getVarUnits', full_name='bmi.BmiService.getVarUnits', - index=14, + index=17, containing_service=None, input_type=_GETVARREQUEST, output_type=_GETVARUNITSRESPONSE, @@ -1726,7 +1791,7 @@ _descriptor.MethodDescriptor( name='getVarNBytes', full_name='bmi.BmiService.getVarNBytes', - index=15, + index=18, containing_service=None, input_type=_GETVARREQUEST, output_type=_GETVARNBYTESRESPONSE, @@ -1735,7 +1800,7 @@ _descriptor.MethodDescriptor( name='getVarLocation', full_name='bmi.BmiService.getVarLocation', - index=16, + index=19, containing_service=None, input_type=_GETVARREQUEST, output_type=_GETVARLOCATIONRESPONSE, @@ -1744,7 +1809,7 @@ _descriptor.MethodDescriptor( name='getValue', full_name='bmi.BmiService.getValue', - index=17, + index=20, containing_service=None, input_type=_GETVARREQUEST, output_type=_GETVALUERESPONSE, @@ -1753,7 +1818,7 @@ _descriptor.MethodDescriptor( name='getValueAtIndices', full_name='bmi.BmiService.getValueAtIndices', - index=18, + index=21, containing_service=None, input_type=_GETVALUEATINDICESREQUEST, output_type=_GETVALUEATINDICESRESPONSE, @@ -1762,7 +1827,7 @@ _descriptor.MethodDescriptor( name='setValue', full_name='bmi.BmiService.setValue', - index=19, + index=22, containing_service=None, input_type=_SETVALUEREQUEST, output_type=_EMPTY, @@ -1771,7 +1836,7 @@ _descriptor.MethodDescriptor( name='setValueAtIndices', full_name='bmi.BmiService.setValueAtIndices', - index=20, + index=23, containing_service=None, input_type=_SETVALUEATINDICESREQUEST, output_type=_EMPTY, @@ -1780,7 +1845,7 @@ _descriptor.MethodDescriptor( name='getGridSize', full_name='bmi.BmiService.getGridSize', - index=21, + index=24, containing_service=None, input_type=_GRIDREQUEST, output_type=_GETGRIDSIZERESPONSE, @@ -1789,7 +1854,7 @@ _descriptor.MethodDescriptor( name='getGridType', full_name='bmi.BmiService.getGridType', - index=22, + index=25, containing_service=None, input_type=_GRIDREQUEST, output_type=_GETGRIDTYPERESPONSE, @@ -1798,7 +1863,7 @@ _descriptor.MethodDescriptor( name='getGridRank', full_name='bmi.BmiService.getGridRank', - index=23, + index=26, containing_service=None, input_type=_GRIDREQUEST, output_type=_GETGRIDRANKRESPONSE, @@ -1807,7 +1872,7 @@ _descriptor.MethodDescriptor( name='getGridShape', full_name='bmi.BmiService.getGridShape', - index=24, + index=27, containing_service=None, input_type=_GRIDREQUEST, output_type=_GETGRIDSHAPERESPONSE, @@ -1816,7 +1881,7 @@ _descriptor.MethodDescriptor( name='getGridSpacing', full_name='bmi.BmiService.getGridSpacing', - index=25, + index=28, containing_service=None, input_type=_GRIDREQUEST, output_type=_GETGRIDSPACINGRESPONSE, @@ -1825,7 +1890,7 @@ _descriptor.MethodDescriptor( name='getGridOrigin', full_name='bmi.BmiService.getGridOrigin', - index=26, + index=29, containing_service=None, input_type=_GRIDREQUEST, output_type=_GETGRIDORIGINRESPONSE, @@ -1834,7 +1899,7 @@ _descriptor.MethodDescriptor( name='getGridX', full_name='bmi.BmiService.getGridX', - index=27, + index=30, containing_service=None, input_type=_GRIDREQUEST, output_type=_GETGRIDPOINTSRESPONSE, @@ -1843,7 +1908,7 @@ _descriptor.MethodDescriptor( name='getGridY', full_name='bmi.BmiService.getGridY', - index=28, + index=31, containing_service=None, input_type=_GRIDREQUEST, output_type=_GETGRIDPOINTSRESPONSE, @@ -1852,7 +1917,7 @@ _descriptor.MethodDescriptor( name='getGridZ', full_name='bmi.BmiService.getGridZ', - index=29, + index=32, containing_service=None, input_type=_GRIDREQUEST, output_type=_GETGRIDPOINTSRESPONSE, @@ -1861,34 +1926,34 @@ _descriptor.MethodDescriptor( name='getGridNodeCount', full_name='bmi.BmiService.getGridNodeCount', - index=30, + index=33, containing_service=None, input_type=_GRIDREQUEST, - output_type=_GETGRIDELEMENTCOUNTRESPONSE, + output_type=_GETCOUNTRESPONSE, serialized_options=None, ), _descriptor.MethodDescriptor( name='getGridEdgeCount', full_name='bmi.BmiService.getGridEdgeCount', - index=31, + index=34, containing_service=None, input_type=_GRIDREQUEST, - output_type=_GETGRIDELEMENTCOUNTRESPONSE, + output_type=_GETCOUNTRESPONSE, serialized_options=None, ), _descriptor.MethodDescriptor( name='getGridFaceCount', full_name='bmi.BmiService.getGridFaceCount', - index=32, + index=35, containing_service=None, input_type=_GRIDREQUEST, - output_type=_GETGRIDELEMENTCOUNTRESPONSE, + output_type=_GETCOUNTRESPONSE, serialized_options=None, ), _descriptor.MethodDescriptor( name='getGridEdgeNodes', full_name='bmi.BmiService.getGridEdgeNodes', - index=33, + index=36, containing_service=None, input_type=_GRIDREQUEST, output_type=_GETGRIDEDGENODESRESPONSE, @@ -1897,16 +1962,25 @@ _descriptor.MethodDescriptor( name='getGridFaceNodes', full_name='bmi.BmiService.getGridFaceNodes', - index=34, + index=37, containing_service=None, input_type=_GRIDREQUEST, output_type=_GETGRIDFACENODESRESPONSE, serialized_options=None, ), + _descriptor.MethodDescriptor( + name='getGridFaceEdges', + full_name='bmi.BmiService.getGridFaceEdges', + index=38, + containing_service=None, + input_type=_GRIDREQUEST, + output_type=_GETGRIDFACEEDGESRESPONSE, + serialized_options=None, + ), _descriptor.MethodDescriptor( name='getGridNodesPerFace', full_name='bmi.BmiService.getGridNodesPerFace', - index=35, + index=39, containing_service=None, input_type=_GRIDREQUEST, output_type=_GETGRIDNODESPERFACERESPONSE, diff --git a/grpc4bmi/bmi_pb2_grpc.py b/grpc4bmi/bmi_pb2_grpc.py index da55027..9db5fc7 100644 --- a/grpc4bmi/bmi_pb2_grpc.py +++ b/grpc4bmi/bmi_pb2_grpc.py @@ -24,6 +24,11 @@ def __init__(self, channel): request_serializer=grpc4bmi_dot_bmi__pb2.Empty.SerializeToString, response_deserializer=grpc4bmi_dot_bmi__pb2.Empty.FromString, ) + self.updateUntil = channel.unary_unary( + '/bmi.BmiService/updateUntil', + request_serializer=grpc4bmi_dot_bmi__pb2.GetTimeResponse.SerializeToString, + response_deserializer=grpc4bmi_dot_bmi__pb2.Empty.FromString, + ) self.finalize = channel.unary_unary( '/bmi.BmiService/finalize', request_serializer=grpc4bmi_dot_bmi__pb2.Empty.SerializeToString, @@ -34,6 +39,16 @@ def __init__(self, channel): request_serializer=grpc4bmi_dot_bmi__pb2.Empty.SerializeToString, response_deserializer=grpc4bmi_dot_bmi__pb2.GetComponentNameResponse.FromString, ) + self.getInputItemCount = channel.unary_unary( + '/bmi.BmiService/getInputItemCount', + request_serializer=grpc4bmi_dot_bmi__pb2.Empty.SerializeToString, + response_deserializer=grpc4bmi_dot_bmi__pb2.GetCountResponse.FromString, + ) + self.getOutputItemCount = channel.unary_unary( + '/bmi.BmiService/getOutputItemCount', + request_serializer=grpc4bmi_dot_bmi__pb2.Empty.SerializeToString, + response_deserializer=grpc4bmi_dot_bmi__pb2.GetCountResponse.FromString, + ) self.getInputVarNames = channel.unary_unary( '/bmi.BmiService/getInputVarNames', request_serializer=grpc4bmi_dot_bmi__pb2.Empty.SerializeToString, @@ -167,17 +182,17 @@ def __init__(self, channel): self.getGridNodeCount = channel.unary_unary( '/bmi.BmiService/getGridNodeCount', request_serializer=grpc4bmi_dot_bmi__pb2.GridRequest.SerializeToString, - response_deserializer=grpc4bmi_dot_bmi__pb2.GetGridElementCountResponse.FromString, + response_deserializer=grpc4bmi_dot_bmi__pb2.GetCountResponse.FromString, ) self.getGridEdgeCount = channel.unary_unary( '/bmi.BmiService/getGridEdgeCount', request_serializer=grpc4bmi_dot_bmi__pb2.GridRequest.SerializeToString, - response_deserializer=grpc4bmi_dot_bmi__pb2.GetGridElementCountResponse.FromString, + response_deserializer=grpc4bmi_dot_bmi__pb2.GetCountResponse.FromString, ) self.getGridFaceCount = channel.unary_unary( '/bmi.BmiService/getGridFaceCount', request_serializer=grpc4bmi_dot_bmi__pb2.GridRequest.SerializeToString, - response_deserializer=grpc4bmi_dot_bmi__pb2.GetGridElementCountResponse.FromString, + response_deserializer=grpc4bmi_dot_bmi__pb2.GetCountResponse.FromString, ) self.getGridEdgeNodes = channel.unary_unary( '/bmi.BmiService/getGridEdgeNodes', @@ -189,6 +204,11 @@ def __init__(self, channel): request_serializer=grpc4bmi_dot_bmi__pb2.GridRequest.SerializeToString, response_deserializer=grpc4bmi_dot_bmi__pb2.GetGridFaceNodesResponse.FromString, ) + self.getGridFaceEdges = channel.unary_unary( + '/bmi.BmiService/getGridFaceEdges', + request_serializer=grpc4bmi_dot_bmi__pb2.GridRequest.SerializeToString, + response_deserializer=grpc4bmi_dot_bmi__pb2.GetGridFaceEdgesResponse.FromString, + ) self.getGridNodesPerFace = channel.unary_unary( '/bmi.BmiService/getGridNodesPerFace', request_serializer=grpc4bmi_dot_bmi__pb2.GridRequest.SerializeToString, @@ -214,6 +234,13 @@ def update(self, request, context): context.set_details('Method not implemented!') raise NotImplementedError('Method not implemented!') + def updateUntil(self, request, context): + # missing associated documentation comment in .proto file + pass + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + def finalize(self, request, context): # missing associated documentation comment in .proto file pass @@ -228,6 +255,20 @@ def getComponentName(self, request, context): context.set_details('Method not implemented!') raise NotImplementedError('Method not implemented!') + def getInputItemCount(self, request, context): + # missing associated documentation comment in .proto file + pass + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def getOutputItemCount(self, request, context): + # missing associated documentation comment in .proto file + pass + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + def getInputVarNames(self, request, context): # missing associated documentation comment in .proto file pass @@ -445,6 +486,13 @@ def getGridFaceNodes(self, request, context): context.set_details('Method not implemented!') raise NotImplementedError('Method not implemented!') + def getGridFaceEdges(self, request, context): + # missing associated documentation comment in .proto file + pass + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + def getGridNodesPerFace(self, request, context): # missing associated documentation comment in .proto file pass @@ -465,6 +513,11 @@ def add_BmiServiceServicer_to_server(servicer, server): request_deserializer=grpc4bmi_dot_bmi__pb2.Empty.FromString, response_serializer=grpc4bmi_dot_bmi__pb2.Empty.SerializeToString, ), + 'updateUntil': grpc.unary_unary_rpc_method_handler( + servicer.updateUntil, + request_deserializer=grpc4bmi_dot_bmi__pb2.GetTimeResponse.FromString, + response_serializer=grpc4bmi_dot_bmi__pb2.Empty.SerializeToString, + ), 'finalize': grpc.unary_unary_rpc_method_handler( servicer.finalize, request_deserializer=grpc4bmi_dot_bmi__pb2.Empty.FromString, @@ -475,6 +528,16 @@ def add_BmiServiceServicer_to_server(servicer, server): request_deserializer=grpc4bmi_dot_bmi__pb2.Empty.FromString, response_serializer=grpc4bmi_dot_bmi__pb2.GetComponentNameResponse.SerializeToString, ), + 'getInputItemCount': grpc.unary_unary_rpc_method_handler( + servicer.getInputItemCount, + request_deserializer=grpc4bmi_dot_bmi__pb2.Empty.FromString, + response_serializer=grpc4bmi_dot_bmi__pb2.GetCountResponse.SerializeToString, + ), + 'getOutputItemCount': grpc.unary_unary_rpc_method_handler( + servicer.getOutputItemCount, + request_deserializer=grpc4bmi_dot_bmi__pb2.Empty.FromString, + response_serializer=grpc4bmi_dot_bmi__pb2.GetCountResponse.SerializeToString, + ), 'getInputVarNames': grpc.unary_unary_rpc_method_handler( servicer.getInputVarNames, request_deserializer=grpc4bmi_dot_bmi__pb2.Empty.FromString, @@ -608,17 +671,17 @@ def add_BmiServiceServicer_to_server(servicer, server): 'getGridNodeCount': grpc.unary_unary_rpc_method_handler( servicer.getGridNodeCount, request_deserializer=grpc4bmi_dot_bmi__pb2.GridRequest.FromString, - response_serializer=grpc4bmi_dot_bmi__pb2.GetGridElementCountResponse.SerializeToString, + response_serializer=grpc4bmi_dot_bmi__pb2.GetCountResponse.SerializeToString, ), 'getGridEdgeCount': grpc.unary_unary_rpc_method_handler( servicer.getGridEdgeCount, request_deserializer=grpc4bmi_dot_bmi__pb2.GridRequest.FromString, - response_serializer=grpc4bmi_dot_bmi__pb2.GetGridElementCountResponse.SerializeToString, + response_serializer=grpc4bmi_dot_bmi__pb2.GetCountResponse.SerializeToString, ), 'getGridFaceCount': grpc.unary_unary_rpc_method_handler( servicer.getGridFaceCount, request_deserializer=grpc4bmi_dot_bmi__pb2.GridRequest.FromString, - response_serializer=grpc4bmi_dot_bmi__pb2.GetGridElementCountResponse.SerializeToString, + response_serializer=grpc4bmi_dot_bmi__pb2.GetCountResponse.SerializeToString, ), 'getGridEdgeNodes': grpc.unary_unary_rpc_method_handler( servicer.getGridEdgeNodes, @@ -630,6 +693,11 @@ def add_BmiServiceServicer_to_server(servicer, server): request_deserializer=grpc4bmi_dot_bmi__pb2.GridRequest.FromString, response_serializer=grpc4bmi_dot_bmi__pb2.GetGridFaceNodesResponse.SerializeToString, ), + 'getGridFaceEdges': grpc.unary_unary_rpc_method_handler( + servicer.getGridFaceEdges, + request_deserializer=grpc4bmi_dot_bmi__pb2.GridRequest.FromString, + response_serializer=grpc4bmi_dot_bmi__pb2.GetGridFaceEdgesResponse.SerializeToString, + ), 'getGridNodesPerFace': grpc.unary_unary_rpc_method_handler( servicer.getGridNodesPerFace, request_deserializer=grpc4bmi_dot_bmi__pb2.GridRequest.FromString, diff --git a/proto/grpc4bmi/bmi.proto b/proto/grpc4bmi/bmi.proto index cda31fa..62dc393 100644 --- a/proto/grpc4bmi/bmi.proto +++ b/proto/grpc4bmi/bmi.proto @@ -180,33 +180,41 @@ message GetGridPointsResponse repeated double coordinates = 1 [packed = true]; } -message GetGridElementCountResponse +message GetCountResponse { int64 count = 1; } message GetGridEdgeNodesResponse { - repeated int64 links = 1 [packed = true]; + repeated int64 edge_nodes = 1 [packed = true]; +} + +message GetGridFaceEdgesResponse +{ + repeated int64 face_edges = 1 [packed = true]; } message GetGridFaceNodesResponse { - repeated int64 links = 1 [packed = true]; + repeated int64 face_nodes = 1 [packed = true]; } message GetGridNodesPerFaceResponse { - repeated int64 links = 1 [packed = true]; + repeated int64 nodes_per_face = 1 [packed = true]; } service BmiService { rpc initialize(InitializeRequest) returns(Empty) {} rpc update(Empty) returns(Empty) {} + rpc updateUntil(GetTimeResponse) returns(Empty) {} rpc finalize(Empty) returns(Empty) {} rpc getComponentName(Empty) returns(GetComponentNameResponse) {} + rpc getInputItemCount(Empty) returns(GetCountResponse) {} + rpc getOutputItemCount(Empty) returns(GetCountResponse) {} rpc getInputVarNames(Empty) returns(GetVarNamesResponse) {} rpc getOutputVarNames(Empty) returns(GetVarNamesResponse) {} @@ -238,10 +246,11 @@ service BmiService { rpc getGridX(GridRequest) returns(GetGridPointsResponse) {} rpc getGridY(GridRequest) returns(GetGridPointsResponse) {} rpc getGridZ(GridRequest) returns(GetGridPointsResponse) {} - rpc getGridNodeCount(GridRequest) returns(GetGridElementCountResponse) {} - rpc getGridEdgeCount(GridRequest) returns(GetGridElementCountResponse) {} - rpc getGridFaceCount(GridRequest) returns(GetGridElementCountResponse) {} + rpc getGridNodeCount(GridRequest) returns(GetCountResponse) {} + rpc getGridEdgeCount(GridRequest) returns(GetCountResponse) {} + rpc getGridFaceCount(GridRequest) returns(GetCountResponse) {} rpc getGridEdgeNodes(GridRequest) returns(GetGridEdgeNodesResponse) {} rpc getGridFaceNodes(GridRequest) returns(GetGridFaceNodesResponse) {} + rpc getGridFaceEdges(GridRequest) returns(GetGridFaceEdgesResponse) {} rpc getGridNodesPerFace(GridRequest) returns(GetGridNodesPerFaceResponse) {} } diff --git a/requirements.txt b/requirements.txt index 318b35a..09e9eeb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -16,3 +16,4 @@ sphinx_rtd_theme nbconvert ipykernel nbformat +grpcio-tools==1.27.2 \ No newline at end of file diff --git a/setup.py b/setup.py index a8c2af7..a68fa51 100644 --- a/setup.py +++ b/setup.py @@ -25,9 +25,9 @@ def read(fname): "run-bmi-server = grpc4bmi.run_server:main" ]}, install_requires=[ - "grpcio>=1.18.0", - "grpcio-reflection>=1.18.0", - "grpcio-status>=1.18.0", + "grpcio==1.27.2", + "grpcio-reflection==1.27.2", + "grpcio-status==1.27.2", "googleapis-common-protos>=1.5.5", "protobuf", "numpy", diff --git a/test/fake_models.py b/test/fake_models.py index f78193e..b379ab8 100644 --- a/test/fake_models.py +++ b/test/fake_models.py @@ -19,12 +19,21 @@ def initialize(self, filename): def update(self): raise self.exc + def update_until(self, time: float) -> None: + raise self.exc + def finalize(self): raise self.exc def get_component_name(self): raise self.exc + def get_input_item_count(self) -> int: + raise self.exc + + def get_output_item_count(self) -> int: + raise self.exc + def get_input_var_names(self): raise self.exc @@ -124,6 +133,9 @@ def get_grid_face_nodes(self, grid: int, face_nodes: np.ndarray) -> np.ndarray: def get_grid_nodes_per_face(self, grid: int, nodes_per_face: np.ndarray) -> np.ndarray: raise self.exc + def get_grid_face_edges(self, grid: int, face_edges: np.ndarray) -> np.ndarray: + raise self.exc + class GridModel(FailingModel): def __init__(self): @@ -273,15 +285,16 @@ def get_grid_z(self, grid: int, z: np.ndarray) -> np.ndarray: class UnstructuredGridBmiModel(GridModel): + # Uses grid example at https://bmi.readthedocs.io/en/latest/model_grids.html#unstructured-grids # Grid shape: - # 0 - # /|\ - # / | \ - # 3 | 1 - # \ | / - # \| / - # 2 - # + # 3-----\ + # / \ \ + # 0 \ \---5 + # \ 2--/ / + # \ / / + # \ / / + # 1---\ / + # 4 def get_grid_type(self, grid): return 'unstructured' @@ -289,38 +302,42 @@ def get_grid_shape(self, grid, dest): raise NotImplementedError('Do not know what shape is') def get_grid_size(self, grid): - return 4 + return 6 def get_grid_rank(self, grid: int) -> int: return 2 def get_grid_node_count(self, grid: int) -> int: - return 4 + return 6 def get_grid_edge_count(self, grid: int) -> int: - return 5 + return 8 def get_grid_face_count(self, grid: int) -> int: - return 2 + return 3 def get_grid_edge_nodes(self, grid: int, edge_nodes: np.ndarray) -> np.ndarray: - numpy.copyto(src=(0, 3, 3, 1, 2, 1, 1, 0, 2, 0), dst=edge_nodes) + numpy.copyto(src=(0, 1, 1, 2, 2, 3, 3, 0, 1, 4, 4, 5, 5, 2, 5, 3), dst=edge_nodes) return edge_nodes def get_grid_face_nodes(self, grid: int, face_nodes: np.ndarray) -> np.ndarray: - numpy.copyto(src=(0, 3, 2, 0, 2, 1), dst=face_nodes) + numpy.copyto(src=(0, 1, 2, 3, 1, 4, 5, 2, 2, 5, 3), dst=face_nodes) return face_nodes + def get_grid_face_edges(self, grid: int, face_edges: np.ndarray) -> np.ndarray: + numpy.copyto(src=(0, 1, 2, 3, 4, 5, 6, 1, 6, 7, 2), dst=face_edges) + return face_edges + def get_grid_nodes_per_face(self, grid: int, nodes_per_face: np.ndarray) -> np.ndarray: - numpy.copyto(src=(3, 3,), dst=nodes_per_face) + numpy.copyto(src=(4, 4, 3), dst=nodes_per_face) return nodes_per_face def get_grid_x(self, grid: int, x: np.ndarray) -> np.ndarray: - numpy.copyto(src=[0.1, 0.2, 0.3, 0.4], dst=x) + numpy.copyto(src=[0., 1., 2., 1., 3., 4.], dst=x) return x def get_grid_y(self, grid: int, y: np.ndarray) -> np.ndarray: - numpy.copyto(src=[1.1, 1.2, 1.3, 1.4], dst=y) + numpy.copyto(src=[3., 1., 2., 4., 0., 3.], dst=y) return y def get_grid_z(self, grid: int, z: np.ndarray) -> np.ndarray: diff --git a/test/test_client.py b/test/test_client.py index 5835945..60e810e 100644 --- a/test/test_client.py +++ b/test/test_client.py @@ -74,9 +74,26 @@ def test_component_name(): del client -def test_varnames(): +def test_input_item_count(): + client, local = make_bmi_classes() + assert client.get_input_item_count() == local.get_input_item_count() + del client + + +def test_output_item_count(): + client, local = make_bmi_classes() + assert client.get_output_item_count() == local.get_output_item_count() + del client + + +def test_input_var_names(): client, local = make_bmi_classes() assert client.get_input_var_names() == local.get_input_var_names() + del client + + +def test_output_var_names(): + client, local = make_bmi_classes() assert client.get_output_var_names() == local.get_output_var_names() del client @@ -96,6 +113,15 @@ def test_update(): del client +def test_update_until(): + client, local = make_bmi_classes(True) + until = local.get_start_time() + local.get_time_step() + local.get_time_step() + client.update_until(until) + assert client.get_current_time() == until + client.finalize() + del client + + def test_get_time_unit(): client, local = make_bmi_classes() assert client.get_time_units() == local.get_time_units() @@ -277,8 +303,11 @@ def test_get_grid_origin(): @pytest.mark.parametrize("client_method,client_request", [ ('initialize', ('config.ini',)), ('update', ()), + ('update_until', (42,)), ('finalize', ()), ('get_component_name', ()), + ('get_input_item_count', ()), + ('get_output_item_count', ()), ('get_input_var_names', ()), ('get_output_var_names', ()), ('get_time_units', ()), @@ -310,6 +339,7 @@ def test_get_grid_origin(): ('get_grid_face_count', (42,)), ('get_grid_edge_nodes', (42, numpy.empty(0))), ('get_grid_face_nodes', (42, numpy.empty(0))), + ('get_grid_face_edges', (42, numpy.empty(0))), ('get_grid_nodes_per_face', (42, numpy.empty(0))), ]) def test_method_exception(client_method, client_request): @@ -503,7 +533,7 @@ def test_get_grid_shape(self, bmiclient): assert 'Do not know what shape is' in str(excinfo.value) def test_grid_size(self, bmiclient): - assert bmiclient.get_grid_size(0) == 4 + assert bmiclient.get_grid_size(0) == 6 def test_grid_rank(self, bmiclient): assert bmiclient.get_grid_rank(0) == 2 @@ -511,50 +541,58 @@ def test_grid_rank(self, bmiclient): def test_get_grid_node_count(self, bmiclient): result = bmiclient.get_grid_node_count(0) - assert result == 4 + assert result == 6 def test_get_grid_edge_count(self, bmiclient): result = bmiclient.get_grid_edge_count(0) - assert result == 5 + assert result == 8 def test_get_grid_face_count(self, bmiclient): result = bmiclient.get_grid_face_count(0) - assert result == 2 + assert result == 3 def test_get_grid_edge_nodes(self, bmiclient): - placeholder = numpy.empty(10, dtype=numpy.int) + placeholder = numpy.empty(16, dtype=numpy.int) result = bmiclient.get_grid_edge_nodes(0, placeholder) - expected = (0, 3, 3, 1, 2, 1, 1, 0, 2, 0) + expected = (0, 1, 1, 2, 2, 3, 3, 0, 1, 4, 4, 5, 5, 2, 5, 3) numpy.testing.assert_allclose(result, expected) def test_grid_face_nodes(self, bmiclient): - placeholder = numpy.empty(6, dtype=numpy.int) + placeholder = numpy.empty(11, dtype=numpy.int) result = bmiclient.get_grid_face_nodes(0, placeholder) - expected = (0, 3, 2, 0, 2, 1) + expected = (0, 1, 2, 3, 1, 4, 5, 2, 2, 5, 3) + numpy.testing.assert_allclose(result, expected) + + def test_grid_face_edges(self, bmiclient): + placeholder = numpy.empty(11, dtype=numpy.int) + + result = bmiclient.get_grid_face_edges(0, placeholder) + + expected = (0, 1, 2, 3, 4, 5, 6, 1, 6, 7, 2) numpy.testing.assert_allclose(result, expected) def test_grid_nodes_per_face(self, bmiclient): - placeholder = numpy.empty(2, dtype=numpy.int) + placeholder = numpy.empty(3, dtype=numpy.int) result = bmiclient.get_grid_nodes_per_face(0, placeholder) - expected = (3, 3,) + expected = (4, 4, 3) numpy.testing.assert_allclose(result, expected) def test_grid_x(self, bmiclient): - result = bmiclient.get_grid_x(0, numpy.empty(4)) - expected = [0.1, 0.2, 0.3, 0.4] + result = bmiclient.get_grid_x(0, numpy.empty(6)) + expected = [0., 1., 2., 1., 3., 4.] numpy.testing.assert_allclose(result, expected) def test_grid_y(self, bmiclient): - result = bmiclient.get_grid_y(0, numpy.empty(4)) - expected = [1.1, 1.2, 1.3, 1.4] + result = bmiclient.get_grid_y(0, numpy.empty(6)) + expected = [3., 1., 2., 4., 0., 3.] numpy.testing.assert_allclose(result, expected) def test_grid_z(self, bmiclient): diff --git a/test/test_server.py b/test/test_server.py index afdf0a9..24b71ab 100644 --- a/test/test_server.py +++ b/test/test_server.py @@ -83,9 +83,14 @@ def test_component_name(): del server -def test_varnames(): +def test_input_var_names(): server, local = make_bmi_classes() assert server.getInputVarNames(None, None).names == list(local.get_input_var_names()) + del server + + +def test_output_var_names(): + server, local = make_bmi_classes() assert server.getOutputVarNames(None, None).names == list(local.get_output_var_names()) del server @@ -312,8 +317,11 @@ def test_get_grid_origin(): @pytest.mark.parametrize("server_method,server_request", [ ('initialize', bmi_pb2.InitializeRequest(config_file='/data/config.ini')), ('update', bmi_pb2.Empty()), + ('updateUntil', bmi_pb2.GetTimeResponse(time=42)), ('finalize', bmi_pb2.Empty()), ('getComponentName', bmi_pb2.Empty()), + ('getInputItemCount', bmi_pb2.Empty()), + ('getOutputItemCount', bmi_pb2.Empty()), ('getInputVarNames', bmi_pb2.Empty()), ('getOutputVarNames', bmi_pb2.Empty()), ('getTimeUnits', bmi_pb2.Empty()), @@ -346,6 +354,7 @@ def test_get_grid_origin(): ('getGridFaceCount', bmi_pb2.GridRequest(grid_id=42)), ('getGridEdgeNodes', bmi_pb2.GridRequest(grid_id=42)), ('getGridFaceNodes', bmi_pb2.GridRequest(grid_id=42)), + ('getGridFaceEdges', bmi_pb2.GridRequest(grid_id=42)), ('getGridNodesPerFace', bmi_pb2.GridRequest(grid_id=42)), ]) def test_method_exceptions_with_stacktrace(server_method, server_request): @@ -407,7 +416,7 @@ def test_grid_node_count(): result = server.getGridNodeCount(request, None).count - assert result == 4 + assert result == 6 def test_grid_edge_count(): @@ -417,7 +426,7 @@ def test_grid_edge_count(): result = server.getGridEdgeCount(request, None).count - assert result == 5 + assert result == 8 def test_grid_face_count(): @@ -427,7 +436,7 @@ def test_grid_face_count(): result = server.getGridFaceCount(request, None).count - assert result == 2 + assert result == 3 def test_get_grid_edge_nodes(): @@ -435,9 +444,9 @@ def test_get_grid_edge_nodes(): server = BmiServer(model, True) grid_id, request = make_grid_request(model) - result = server.getGridEdgeNodes(request, None).links + result = server.getGridEdgeNodes(request, None).edge_nodes - expected = (0, 3, 3, 1, 2, 1, 1, 0, 2, 0) + expected = (0, 1, 1, 2, 2, 3, 3, 0, 1, 4, 4, 5, 5, 2, 5, 3) numpy.testing.assert_allclose(result, expected) @@ -446,9 +455,20 @@ def test_get_grid_face_nodes(): server = BmiServer(model, True) grid_id, request = make_grid_request(model) - result = server.getGridFaceNodes(request, None).links + result = server.getGridFaceNodes(request, None).face_nodes + + expected = (0, 1, 2, 3, 1, 4, 5, 2, 2, 5, 3) + numpy.testing.assert_allclose(result, expected) + + +def test_get_grid_face_edges(): + model = UnstructuredGridBmiModel() + server = BmiServer(model, True) + grid_id, request = make_grid_request(model) + + result = server.getGridFaceEdges(request, None).face_edges - expected = (0, 3, 2, 0, 2, 1) + expected = (0, 1, 2, 3, 4, 5, 6, 1, 6, 7, 2) numpy.testing.assert_allclose(result, expected) @@ -457,6 +477,6 @@ def test_get_grid_nodes_per_face(): server = BmiServer(model, True) grid_id, request = make_grid_request(model) - result = server.getGridNodesPerFace(request, None).links + result = server.getGridNodesPerFace(request, None).nodes_per_face - numpy.testing.assert_allclose(result, (3, 3,)) + numpy.testing.assert_allclose(result, (4, 4, 3)) diff --git a/test/test_singularity.py b/test/test_singularity.py index c3f7505..39732e2 100644 --- a/test/test_singularity.py +++ b/test/test_singularity.py @@ -1,5 +1,6 @@ from textwrap import dedent +from os import environ import pytest from nbconvert.preprocessors import ExecutePreprocessor from nbformat.v4 import new_notebook, new_code_cell @@ -48,6 +49,7 @@ def notebook(): return new_notebook(cells=cells) +@pytest.mark.skipif(environ.get('TRAVIS', 'false') == 'true', reason="Does not work on Travis-CI") def test_from_notebook(notebook, tmp_path): ep = ExecutePreprocessor(timeout=600, kernel_name='python3') ep.preprocess(notebook, {'metadata': {'path': tmp_path}})