mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
* gRPC: Make names more consistent * gRPC: clean up case info and improve Python API for cases * gRPC: much more object oriented Python interface * Python: Make a proper pip-installable package * Update rips Python package to auto generate setup.py with version number * Python: add setup.py to gitignore * Python: Update Python RIPS interface * gRPC: Remove example client from cmake file and unit test * gRPC: Fix up unit test after merge and hide warnings * gRPC: fix up python client code
This commit is contained in:
@@ -57,6 +57,15 @@ ${CMAKE_CURRENT_LIST_DIR}/RimWellPathCompletions-Test.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimSummaryCaseCollection-Test.cpp
|
||||
)
|
||||
|
||||
if (RESINSIGHT_ENABLE_GRPC)
|
||||
list(APPEND GPRC_UNIT_TEST_SOURCE_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiaGrpcInterface-Test.cpp
|
||||
)
|
||||
list(APPEND SOURCE_GROUP_SOURCE_FILES
|
||||
${GRPC_UNIT_TEST_SOURCE_FILES}
|
||||
)
|
||||
endif(RESINSIGHT_ENABLE_GRPC)
|
||||
|
||||
list(APPEND CODE_HEADER_FILES
|
||||
${SOURCE_GROUP_HEADER_FILES}
|
||||
)
|
||||
|
||||
68
ApplicationCode/UnitTests/RiaGrpcInterface-Test.cpp
Normal file
68
ApplicationCode/UnitTests/RiaGrpcInterface-Test.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <grpc/grpc.h>
|
||||
#include <grpcpp/channel.h>
|
||||
#include <grpcpp/client_context.h>
|
||||
#include <grpcpp/create_channel.h>
|
||||
#include <grpcpp/security/credentials.h>
|
||||
#include <numeric>
|
||||
#include <memory>
|
||||
|
||||
#include "Properties.grpc.pb.h"
|
||||
|
||||
using grpc::Channel;
|
||||
using grpc::ClientContext;
|
||||
using grpc::ClientReader;
|
||||
using grpc::ClientReaderWriter;
|
||||
using grpc::ClientWriter;
|
||||
using grpc::Status;
|
||||
|
||||
class PropertiesClient
|
||||
{
|
||||
public:
|
||||
PropertiesClient(std::shared_ptr<Channel> channel)
|
||||
: m_stub(rips::Properties::NewStub(channel))
|
||||
{
|
||||
}
|
||||
Status GetActiveCellProperty(rips::PropertyType propType, const std::string& propertyName, int timeStep, std::vector<double>* results) const
|
||||
{
|
||||
rips::PropertyRequest request;
|
||||
rips::CaseRequest* requestCase = new rips::CaseRequest;
|
||||
requestCase->set_id(0);
|
||||
request.set_allocated_case_request(requestCase);
|
||||
request.set_grid_index(0);
|
||||
request.set_porosity_model(rips::PorosityModelType::MATRIX_MODEL);
|
||||
request.set_property_type(propType);
|
||||
request.set_property_name(propertyName);
|
||||
request.set_time_step(timeStep);
|
||||
rips::PropertyChunk resultArray;
|
||||
ClientContext context;
|
||||
|
||||
std::unique_ptr<ClientReader<rips::PropertyChunk>> reader = m_stub->GetActiveCellProperty(&context, request);
|
||||
while (reader->Read(&resultArray))
|
||||
{
|
||||
results->insert(results->end(), resultArray.values().begin(), resultArray.values().end());
|
||||
}
|
||||
return reader->Finish();
|
||||
}
|
||||
private:
|
||||
std::unique_ptr<rips::Properties::Stub> m_stub;
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(DISABLED_RiaGrpcInterface, SoilAverage)
|
||||
{
|
||||
PropertiesClient client(grpc::CreateChannel("localhost:50051", grpc::InsecureChannelCredentials()));
|
||||
|
||||
for (size_t i = 0; i < 10; ++i)
|
||||
{
|
||||
std::vector<double> results;
|
||||
Status status = client.GetActiveCellProperty(rips::PropertyType::DYNAMIC_NATIVE, "SOIL", i, &results);
|
||||
std::cout << "Number of results: " << results.size() << std::endl;
|
||||
double sum = std::accumulate(results.begin(), results.end(), 0.0);
|
||||
std::cout << "Avg: " << sum / static_cast<double>(results.size()) << std::endl;
|
||||
EXPECT_EQ(grpc::OK, status.error_code());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user