From 130b3095352c9a3742ea8755c2219258b1832cd7 Mon Sep 17 00:00:00 2001 From: Lionel Untereiner Date: Fri, 4 Aug 2023 17:19:47 +0200 Subject: [PATCH] start work on data object repository --- src/CMakeLists.txt | 6 ++ src/ETPRepository.cpp | 50 +++++++++++++++++ src/ETPRepository.hpp | 53 ++++++++++++++++++ src/EpcDocumentRepository.cpp | 33 +++++++++++ src/EpcDocumentRepository.hpp | 52 ++++++++++++++++++ src/RESQMLDataObjectRepository.cpp | 36 ++++++++++++ src/RESQMLDataObjectRepository.hpp | 68 +++++++++++++++++++++++ tests/CMakeLists.txt | 1 + tests/testRESQMLDataObjectRepository.cpp | 70 ++++++++++++++++++++++++ 9 files changed, 369 insertions(+) create mode 100644 src/ETPRepository.cpp create mode 100644 src/ETPRepository.hpp create mode 100644 src/EpcDocumentRepository.cpp create mode 100644 src/EpcDocumentRepository.hpp create mode 100644 src/RESQMLDataObjectRepository.cpp create mode 100644 src/RESQMLDataObjectRepository.hpp create mode 100644 tests/testRESQMLDataObjectRepository.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0f8756e..0f35738 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -27,6 +27,9 @@ set(componentHeaders RESQMLWriterInterface.hpp RESQMLMeshGenerator.hpp RESQMLUtilities.hpp + RESQMLDataObjectRepository.hpp + EpcDocumentRepository.hpp + ETPRepository.hpp ) # @@ -37,6 +40,9 @@ set(componentSources RESQMLWriterInterface.cpp RESQMLMeshGenerator.cpp RESQMLOutput.cpp + RESQMLDataObjectRepository.cpp + EpcDocumentRepository.cpp + ETPRepository.cpp ) # diff --git a/src/ETPRepository.cpp b/src/ETPRepository.cpp new file mode 100644 index 0000000..077aa26 --- /dev/null +++ b/src/ETPRepository.cpp @@ -0,0 +1,50 @@ + +#include "mesh/generators/RESQML/ETPRepository.hpp" + +namespace geosx +{ + +using namespace dataRepository; + +ETPRepository::ETPRepository( string const & name, + dataRepository::Group * const parent ) + : RESQMLDataObjectRepository( name, parent ) +{ + enableLogLevelInput(); + + registerWrapper( viewKeyStruct:ipConnectionString(), &m_ipConnection ). + setInputFlag( InputFlags::REQUIRED ). + setRestartFlags( RestartFlags::NO_WRITE ). + setDescription( "IP from the ETP Server" ); + + registerWrapper( viewKeyStruct::portConnectionInt(), &m_portConnection ). + setInputFlag( InputFlags::REQUIRED ). + setRestartFlags( RestartFlags::NO_WRITE ). + setDescription( "PORT from the ETP Server" ); + + registerWrapper( viewKeyStruct::authConnectionString(), &m_authConnection ). + setInputFlag( InputFlags::REQUIRED ). + setRestartFlags( RestartFlags::NO_WRITE ). + setDescription( "Authentification for the connection to the ETP Server" ); +} + +void ETPRepository::postProcessInput() +{ + boost::uuids::random_generator gen; + ETP_NS::InitializationParameters initializationParams(gen(), ip_connection, port_connection); + + m_session = ETP_NS::ClientSessionLaunchers::createWsClientSession(&initializationParams, "/", auth_connection); + m_session->setCoreProtocolHandlers(std::make_shared(session.get(), repository)); + m_session->setDiscoveryProtocolHandlers(std::make_shared(session.get(), repository)); + auto storeHandlers = std::make_shared(session.get(), repository); + session->setStoreProtocolHandlers(storeHandlers); + session->setDataArrayProtocolHandlers(std::make_shared(session.get())); + + repository->setHdfProxyFactory(new ETP_NS::FesapiHdfProxyFactory(session.get())); + + std::thread sessionThread(&ETP_NS::PlainClientSession::run, session); + sessionThread.detach(); + while (!storeHandlers->isDone()) {} +} + +} // end namespace geosx \ No newline at end of file diff --git a/src/ETPRepository.hpp b/src/ETPRepository.hpp new file mode 100644 index 0000000..1d054f8 --- /dev/null +++ b/src/ETPRepository.hpp @@ -0,0 +1,53 @@ +#ifndef GEOSX_MESH_GENERATORS_RESQML_ETPREPOSITORY_HPP +#define GEOSX_MESH_GENERATORS_RESQML_ETPREPOSITORY_HPP + +#include "mesh/generators/RESQML/RESQMLDataObjectRepository.hpp" + +#include + +namespace geosx +{ + +class ETPRepository : public RESQMLDataObjectRepository +{ +public: + + /** + * @brief Constructor. + * @param[in] name name of the object + * @param[in] parent the parent Group pointer + */ + ETPRepository( const string & name, + Group * const parent ); + + +protected: + + ///@cond DO_NOT_DOCUMENT + struct viewKeyStruct + { + constexpr static char const * ipConnectionString() { return "ip"; } + constexpr static char const * portConnectionInt() { return "port"; } + constexpr static char const * authConnectionString() { return "auth_connection"; } + }; + /// @endcond + + void postProcessInput() override; + +private: + /// ETP Session + std::shared_ptr m_session; + + /// + string m_ipConnection; + + /// + integer m_portConnection; + + /// + string m_authConnection; +}; + +} // end namespace geosx + +#endif /* GEOSX_MESH_GENERATORS_RESQML_ETPREPOSITORY_HPP */ \ No newline at end of file diff --git a/src/EpcDocumentRepository.cpp b/src/EpcDocumentRepository.cpp new file mode 100644 index 0000000..121d24e --- /dev/null +++ b/src/EpcDocumentRepository.cpp @@ -0,0 +1,33 @@ + +#include "mesh/generators/RESQML/EpcDocumentRepository.hpp" + +namespace geosx +{ + +using namespace dataRepository; + +EpcDocumentRepository::EpcDocumentRepository( string const & name, + Group * const parent ) + : RESQMLDataObjectRepository( name, parent ) +{ + enableLogLevelInput(); + + registerWrapper( viewKeyStruct::filePathString(), &m_filePath ). + setInputFlag( InputFlags::REQUIRED ). + setRestartFlags( RestartFlags::NO_WRITE ). + setDescription( "Path to the mesh file" ); +} + +void EpcDocumentRepository::postProcessInput() +{ + GEOSX_LOG_RANK_0( GEOSX_FMT( "Reading: {}", m_filePath) ); + COMMON_NS::EpcDocument pck(m_filePath); + std::string message = pck.deserializePartiallyInto(*m_repository); + pck.close(); + + GEOSX_LOG_RANK_0( GEOSX_FMT( "Deserilization message: {}", message) ); +} + +REGISTER_CATALOG_ENTRY( RESQMLDataObjectRepository, EpcDocumentRepository, string const &, Group * const ) + +} // end namespace geosx \ No newline at end of file diff --git a/src/EpcDocumentRepository.hpp b/src/EpcDocumentRepository.hpp new file mode 100644 index 0000000..9e7e859 --- /dev/null +++ b/src/EpcDocumentRepository.hpp @@ -0,0 +1,52 @@ +#ifndef GEOSX_MESH_GENERATORS_RESQML_EPCDOCUMENTREPOSITORY_HPP +#define GEOSX_MESH_GENERATORS_RESQML_EPCDOCUMENTREPOSITORY_HPP + +#include "mesh/generators/RESQML/RESQMLDataObjectRepository.hpp" + +#include "fesapi/common/EpcDocument.h" + +namespace geosx +{ + +class EpcDocumentRepository : public RESQMLDataObjectRepository +{ +public: + + /** + * @brief Constructor. + * @param[in] name name of the object + * @param[in] parent the parent Group pointer + */ + explicit EpcDocumentRepository( const string & name, + Group * const parent ); + + + /** + * @brief Return the name of the RESQMLDataObjectRepository in object catalog. + * @return string that contains the catalog name of the RESQMLDataObjectRepository + */ + static string catalogName() { return "EpcDocumentRepository"; } + + string getCatalogName() override { return catalogName(); } + + virtual void test() = 0; + +protected: + + ///@cond DO_NOT_DOCUMENT + struct viewKeyStruct + { + constexpr static char const * filePathString() { return "file"; } + }; + /// @endcond + + void postProcessInput() override; + +private: + /// Path to the epc file + Path m_filePath; +}; + +} // end namespace geosx + +#endif /* GEOSX_MESH_GENERATORS_RESQML_EPCDOCUMENTREPOSITORY_HPP */ \ No newline at end of file diff --git a/src/RESQMLDataObjectRepository.cpp b/src/RESQMLDataObjectRepository.cpp new file mode 100644 index 0000000..a1da641 --- /dev/null +++ b/src/RESQMLDataObjectRepository.cpp @@ -0,0 +1,36 @@ + +#include "RESQMLDataObjectRepository.hpp" + +namespace geosx +{ + +using namespace dataRepository; + +RESQMLDataObjectRepository::RESQMLDataObjectRepository(string const & name, + dataRepository::Group * const parent) : + MeshGeneratorBase( name, parent ) +{ + setInputFlags(InputFlags::OPTIONAL_NONUNIQUE); + + // This enables logLevel filtering + enableLogLevelInput(); +} + +// Group * RESQMLDataObjectRepository::createChild( string const & childKey, string const & childName ) +// { +// // RESQML DataObject Repositories generally don't have child XML nodes, must override this method to enable +// // GEOSX_THROW( GEOSX_FMT( "RESQMLDataObjectRepository '{}': invalid child XML node '{}' of type {}", getName(), childName, childKey ), +// // InputError ); +// std::unique_ptr< RESQMLDataObjectRepository > task = RESQMLDataObjectRepository::CatalogInterface::factory( childKey, childName, this ); +// return &this->registerGroup< RESQMLDataObjectRepository >( childName, std::move( task ) ); + +// } + +RESQMLDataObjectRepository::CatalogInterface::CatalogType & RESQMLDataObjectRepository::getCatalog() +{ + static RESQMLDataObjectRepository::CatalogInterface::CatalogType catalog; + return catalog; +} + + +} // end namespace geosx \ No newline at end of file diff --git a/src/RESQMLDataObjectRepository.hpp b/src/RESQMLDataObjectRepository.hpp new file mode 100644 index 0000000..e408950 --- /dev/null +++ b/src/RESQMLDataObjectRepository.hpp @@ -0,0 +1,68 @@ + +#ifndef GEOSX_MESH_GENERATORS_RESQML_RESQMLDATAOBJECTREPOSITORY_HPP +#define GEOSX_MESH_GENERATORS_RESQML_RESQMLDATAOBJECTREPOSITORY_HPP + +#include "mesh/generators/MeshGeneratorBase.hpp" + +#include "fesapi/common/DataObjectRepository.h" + +namespace geosx +{ + +class RESQMLDataObjectRepository : public MeshGeneratorBase +{ +public: + + /** + * @brief Default constructor. + */ + RESQMLDataObjectRepository() = delete; + + + /** + * @brief Main constructor for RESQMLDataObjectRepository base class. + * @param[in] name of the RESQMLDataObjectRepository object + * @param[in] parent the parent Group pointer for the RESQMLDataObjectRepository object + */ + explicit RESQMLDataObjectRepository( string const & name, + Group * const parent ); + + // /** + // * @brief Return the name of the MeshGenerator in object catalog. + // * @return string that contains the catalog name of the MeshGenerator + // */ + // static string catalogName() { return "RESQMLDataObjectRepository"; } + + /// using alias for templated Catalog meshGenerator type + using CatalogInterface = dataRepository::CatalogInterface< RESQMLDataObjectRepository, string const &, Group * const >; + + /** + * @brief Accessor for the singleton Catalog object + * @return a static reference to the Catalog object + */ + static CatalogInterface::CatalogType & getCatalog(); + + /** + * @brief function to return the catalog name of the derived class + * @return a string that contains the catalog name of the derived class + */ + virtual string getCatalogName() = 0; + // /** + // * @brief Create a new object as a child of this group. + // * @param childKey the catalog key of the new object to create + // * @param childName the name of the new object in the repository + // * @return the group child + // */ + // virtual Group * createChild( string const & childKey, string const & childName ) override; + + +protected: + + /// RESQML DataObject Repository + common::DataObjectRepository * m_repository; + +}; + +} // end namespace + +#endif /* GEOSX_MESH_GENERATORS_RESQML_RESQMLDATAOBJECTREPOSITORY_HPP */ \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 8f3e23e..5a44fae 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -12,6 +12,7 @@ endif() set(myNewComponentTests testRESQMLImport.cpp + testRESQMLDataObjectRepository.cpp ) # diff --git a/tests/testRESQMLDataObjectRepository.cpp b/tests/testRESQMLDataObjectRepository.cpp new file mode 100644 index 0000000..4eb0f85 --- /dev/null +++ b/tests/testRESQMLDataObjectRepository.cpp @@ -0,0 +1,70 @@ +#include "codingUtilities/UnitTestUtilities.hpp" +#include "dataRepository/xmlWrapper.hpp" +#include "mainInterface/ProblemManager.hpp" +#include "mainInterface/GeosxState.hpp" +#include "mainInterface/initialization.hpp" +#include "mesh/generators/RESQML/RESQMLDataObjectRepository.hpp" + +// special CMake-generated include +#include "tests/meshDirName.hpp" + +// TPL includes +#include +#include + +using namespace geosx; +using namespace geosx::testing; +using namespace geosx::dataRepository; + + +void TestEpcDocument( string const & epcFilePath) +{ + string const epcNode = GEOSX_FMT( + "" + " " + " " + " " + "", + epcFilePath); + xmlWrapper::xmlDocument xmlDocument; + xmlWrapper::xmlResult xmlResult = xmlDocument.load_buffer( epcNode.c_str(), epcNode.size() ); + + ASSERT_TRUE( xmlResult ); + + xmlWrapper::xmlNode xmlProblemNode = xmlDocument.child( dataRepository::keys::ProblemManager ); + ProblemManager & problemManager = getGlobalState().getProblemManager(); + problemManager.processInputFileRecursive( xmlProblemNode ); + + problemManager.printDataHierarchy(3); + + // Open DataObject Repository levels + // RESQMLDataObjectRepository & repo = problemManager.getGroup< RESQMLDataObjectRepository >( problemManager.groupKeys.resqmlDataObjectRepository ); + + // repo.test(); + // repo.processInputFileRecursive( xmlMeshNode ); + // repo.postProcessInputRecursive(); + // DomainPartition domain( "domain", &root ); + // meshManager.generateMeshes( domain ); + + // validate( domain.getMeshBody( "mesh" ).getGroup< CellBlockManagerABC >( keys::cellManager ) ); +} + +TEST( EpcDocument, sizes ) +{ + + string const test_epc = testMeshDir + "/test.epc"; + TestEpcDocument( test_epc ); +} + +int main( int argc, char * * argv ) +{ + ::testing::InitGoogleTest( &argc, argv ); + + geosx::GeosxState state( geosx::basicSetup( argc, argv ) ); + + int const result = RUN_ALL_TESTS(); + + geosx::basicCleanup(); + + return result; +}