From 945d69d1773111a3283cd9ce0c1fc68b9b984480 Mon Sep 17 00:00:00 2001 From: Ovidiu Mircescu Date: Thu, 11 Aug 2016 16:48:38 +0200 Subject: [PATCH] Add a visualization component. --- CMakeLists.txt | 1 + idl/CMakeLists.txt | 28 ++ idl/PARAVIS.idl | 28 ++ resources/PARAVISCatalog.xml.in | 51 ++++ src/Insitu/CMakeLists.txt | 43 +-- .../VisualizationComponent/CMakeLists.txt | 67 +++++ .../VisualizationComponent.cxx | 261 ++++++++++++++++++ .../VisualizationComponent.hxx | 51 ++++ .../VisualizationLibrary/CMakeLists.txt | 42 +++ .../{ => VisualizationLibrary}/visu.cxx | 8 - .../{ => VisualizationLibrary}/visu.hxx | 0 11 files changed, 531 insertions(+), 49 deletions(-) create mode 100644 idl/CMakeLists.txt create mode 100644 idl/PARAVIS.idl create mode 100644 src/Insitu/VisualizationComponent/CMakeLists.txt create mode 100644 src/Insitu/VisualizationComponent/VisualizationComponent.cxx create mode 100644 src/Insitu/VisualizationComponent/VisualizationComponent.hxx create mode 100644 src/Insitu/VisualizationLibrary/CMakeLists.txt rename src/Insitu/{ => VisualizationLibrary}/visu.cxx (95%) rename src/Insitu/{ => VisualizationLibrary}/visu.hxx (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 48719435..c4667a0a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -274,6 +274,7 @@ IF(SALOME_BUILD_TESTS AND NOT SALOME_LIGHT_ONLY) ENDIF() ADD_SUBDIRECTORY(bin) ADD_SUBDIRECTORY(examples) +ADD_SUBDIRECTORY(idl) # Header configuration # ==================== diff --git a/idl/CMakeLists.txt b/idl/CMakeLists.txt new file mode 100644 index 00000000..4f6a89e5 --- /dev/null +++ b/idl/CMakeLists.txt @@ -0,0 +1,28 @@ + +INCLUDE(UseOmniORB) # Provided by KERNEL + +INCLUDE_DIRECTORIES( + ${OMNIORB_INCLUDE_DIR} + ${KERNEL_INCLUDE_DIRS} + ${PROJECT_BINARY_DIR}/idl +) + +SET(SalomeIDLPARAVIS_IDLSOURCES + PARAVIS.idl + +) + +SET(_idl_include_dirs + ${KERNEL_ROOT_DIR}/idl/salome + ${MED_ROOT_DIR}/idl/salome + +) + +SET(_idl_link_flags + ${KERNEL_SalomeIDLKernel} + ${MED_SalomeIDLMED} + +) + +OMNIORB_ADD_MODULE(SalomeIDLPARAVIS "${SalomeIDLPARAVIS_IDLSOURCES}" "${_idl_include_dirs}" "${_idl_link_flags}") +INSTALL(TARGETS SalomeIDLPARAVIS EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS}) diff --git a/idl/PARAVIS.idl b/idl/PARAVIS.idl new file mode 100644 index 00000000..cc89534e --- /dev/null +++ b/idl/PARAVIS.idl @@ -0,0 +1,28 @@ + +#ifndef _PARAVIS_IDL_ +#define _PARAVIS_IDL_ + +#include "SALOME_Exception.idl" +#include "SALOME_Component.idl" +#include "SALOME_Comm.idl" + + +#include "MEDCouplingCorbaServant.idl" +#include "SALOME_MPIObject.idl" +#include "ParaMEDCouplingCorbaServant.idl" + +module PARAVIS_ORB +{ +typedef sequence stringvec; +typedef sequence dblevec; +typedef sequence intvec; +typedef Engines::dataref dataref; + + interface VisualizationComponent: Engines::MPIObject, Engines::EngineComponent + { + void Visualize(in SALOME_MED::ParaMEDCouplingFieldDoubleCorbaInterface field,in string path_python_file) raises (SALOME::SALOME_Exception); + }; + +}; + +#endif diff --git a/resources/PARAVISCatalog.xml.in b/resources/PARAVISCatalog.xml.in index df256d70..c10b27ef 100644 --- a/resources/PARAVISCatalog.xml.in +++ b/resources/PARAVISCatalog.xml.in @@ -59,5 +59,56 @@ + + + + VisualizationComponent + VisualizationComponent + Data + EDF-RD + @SALOMEPARAVIS_VERSION@ + + 0 + SO + + + + VisualizationComponent + + + + + + Visualize + EDF-RD + 1.0 + + 0 + + + + field + +SALOME_MED/ParaMEDCouplingFieldDoubleCorbaInterface + + + + + path_python_file + + string + + + + + + + + + + + + + diff --git a/src/Insitu/CMakeLists.txt b/src/Insitu/CMakeLists.txt index 62d1db06..1bc1057f 100644 --- a/src/Insitu/CMakeLists.txt +++ b/src/Insitu/CMakeLists.txt @@ -1,42 +1,3 @@ - -SET(BUILD_SHARED_LIBS TRUE) -INCLUDE_DIRECTORIES( - ${MEDCOUPLING_INCLUDE_DIRS} - ${MPI_INCLUDE_PATH} - ${PARAVIS_INCLUDE_DIRS} - ${CMAKE_CURRENT_SOURCE_DIR}/../Plugins/MEDReader/IO/ -) - - -SET(_link_LIBRARIES - ${MEDCoupling_medcoupling} - ${MEDCoupling_interpkernel} - ${MPI_LIBRARIES} - ${VTK_LIBRARIES} - ${PARAVIS_MEDLoaderForPV} - #${MEDLoaderForPV} - ${MEDCoupling_medloader} - ${MEDFILE_C_LIBRARIES} - vtkPVCatalyst - vtkPVPythonCatalyst -) - -SET(_lib_HEADERS - visu.hxx -) - -SET(_lib_SOURCES - visu.cxx -) - -ADD_LIBRARY(visulib ${_lib_SOURCES}) -TARGET_LINK_LIBRARIES(visulib ${_link_LIBRARIES} ) - -INSTALL(TARGETS visulib - RUNTIME DESTINATION lib/salome - LIBRARY DESTINATION lib/salome - ARCHIVE DESTINATION lib/salome - ) -INSTALL(FILES ${_lib_HEADERS} DESTINATION include/salome ) - +ADD_SUBDIRECTORY(VisualizationComponent) +ADD_SUBDIRECTORY(VisualizationLibrary) diff --git a/src/Insitu/VisualizationComponent/CMakeLists.txt b/src/Insitu/VisualizationComponent/CMakeLists.txt new file mode 100644 index 00000000..d3344fa0 --- /dev/null +++ b/src/Insitu/VisualizationComponent/CMakeLists.txt @@ -0,0 +1,67 @@ + +# --- options --- +# additional include directories +INCLUDE_DIRECTORIES( + ${KERNEL_INCLUDE_DIRS} + ${OMNIORB_INCLUDE_DIR} + ${PROJECT_BINARY_DIR} + ${PROJECT_BINARY_DIR}/idl + ${CMAKE_CURRENT_SOURCE_DIR}/../VisualizationLibrary +) + +# --- definitions --- +ADD_DEFINITIONS( + ${OMNIORB_DEFINITIONS} +) + +# find additional libraries +FIND_LIBRARY( _userlib_visulib visulib PATH /home/I35256/salome/install/V7_main_git/modules/install/PARAVIS_master/lib/salome) +#FIND_LIBRARY( _userlib_MEDLoaderForPV MEDLoaderForPV PATH /home/I35256/salome/install/V7_main_git/modules/install/PARAVIS_master/lib/salome) + + +# libraries to link to +SET(_link_LIBRARIES + ${OMNIORB_LIBRARIES} + ${KERNEL_SalomeIDLKernel} + ${KERNEL_OpUtil} + ${KERNEL_SalomeContainer} + SalomeIDLPARAVIS + ${KERNEL_SalomeMPIContainer} + #${_userlib_visulib} + #${_userlib_MEDLoaderForPV} + ${PARAVIS_MEDLoaderForPV} + ${PARAVIS_visulib} + ${MED_SalomeIDLMED} + ${MED_med} + ${MED_medcouplingcorba} + ${MED_medcouplingclient} + + ${MED_paramedmemcompo} + ${MED_paramedcouplingcorba} +) + +# --- headers --- + +# header files / no moc processing + +SET(PARAVIS_HEADERS + VisualizationComponent.hxx +) + +# --- sources --- + +# sources / static +SET(PARAVIS_SOURCES + VisualizationComponent.cxx + +) + +# --- rules --- + +ADD_LIBRARY(VisualizationComponentEngine ${PARAVIS_SOURCES}) +TARGET_LINK_LIBRARIES(VisualizationComponentEngine ${_link_LIBRARIES} ) +#SET_TARGET_PROPERTIES( VisualizationComponentEngine PROPERTIES INSTALL_RPATH /home/I35256/salome/install/V7_main_git/modules/install/PARAVIS_master/lib/salome) + +INSTALL(TARGETS VisualizationComponentEngine EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS}) + +INSTALL(FILES ${PARAVIS_HEADERS} DESTINATION ${SALOME_INSTALL_HEADERS}) diff --git a/src/Insitu/VisualizationComponent/VisualizationComponent.cxx b/src/Insitu/VisualizationComponent/VisualizationComponent.cxx new file mode 100644 index 00000000..0a9446ba --- /dev/null +++ b/src/Insitu/VisualizationComponent/VisualizationComponent.cxx @@ -0,0 +1,261 @@ + +#include "VisualizationComponent.hxx" +#include +#include +#include +#include +#include +#include "Utils_CorbaException.hxx" +#include +#include + +typedef struct +{ + bool exception; + std::string msg; +} exception_st; + +//DEFS + +#include "visu.hxx" +#include "MEDCouplingFieldDoubleClient.hxx" +#include "ParaMEDCouplingFieldDoubleServant.hxx" +#include "omniORB4/poa.h" + +//ENDDEF + + +using namespace std; + +//! Constructor for component "VisualizationComponent" instance +/*! + * + */ +VisualizationComponent_i::VisualizationComponent_i(CORBA::ORB_ptr orb, + PortableServer::POA_ptr poa, + PortableServer::ObjectId * contId, + const char *instanceName, + const char *interfaceName, + bool regist) + : Engines_Component_i(orb, poa, contId, instanceName, interfaceName, + false, regist) +{ + _thisObj = this ; + _id = _poa->activate_object(_thisObj); +} + +VisualizationComponent_i::VisualizationComponent_i(CORBA::ORB_ptr orb, + PortableServer::POA_ptr poa, + Engines::Container_ptr container, + const char *instanceName, + const char *interfaceName, + bool regist) + : Engines_Component_i(orb, poa, container, instanceName, interfaceName, + false, regist) +{ + _thisObj = this ; + _id = _poa->activate_object(_thisObj); +} + +//! Destructor for component "VisualizationComponent" instance +VisualizationComponent_i::~VisualizationComponent_i() +{ +} + + +void * th_Visualize(void * s) +{ + std::ostringstream msg; + exception_st *est = new exception_st; + est->exception = false; + + thread_Visualize_struct *st = (thread_Visualize_struct *)s; + + try + { + + PARAVIS_ORB::VisualizationComponent_var compo = PARAVIS_ORB::VisualizationComponent::_narrow((*(st->tior))[st->ip]); + compo->Visualize(st->field,st->path_python_file); + } + catch(const SALOME::SALOME_Exception &ex) + { + est->exception = true; + est->msg = ex.details.text; + } + catch(const CORBA::Exception &ex) + { + est->exception = true; + msg << "CORBA::Exception: " << ex; + est->msg = msg.str(); + } + + delete st; + return ((void*)est); +} + +void VisualizationComponent_i::Visualize(SALOME_MED::ParaMEDCouplingFieldDoubleCorbaInterface_ptr field,const char* path_python_file) +{ + beginService("VisualizationComponent_i::Visualize"); + void *ret_th; + pthread_t *th; + exception_st *est; + + try + { + // Run the service in every MPI process + if(_numproc == 0) + { + th = new pthread_t[_nbproc]; + for(int ip=1;ip<_nbproc;ip++) + { + thread_Visualize_struct *st = new thread_Visualize_struct; + st->ip = ip; + st->tior = _tior; + st->field = field; +st->path_python_file = path_python_file; + pthread_create(&(th[ip]),NULL,th_Visualize,(void*)st); + } + } + +//BODY + +const MEDCoupling::MEDCouplingFieldDouble * local_field(NULL); +int nb_fields = field->tior()->length(); +if(nb_fields == _nbproc) +{ + SALOME_MED::ParaMEDCouplingFieldDoubleCorbaInterface_ptr local_corba_field = + SALOME_MED::ParaMEDCouplingFieldDoubleCorbaInterface::_narrow((*(field->tior()))[_numproc]); + + + PortableServer::ServantBase *ret; + try { + ret=PortableServer::POA::_the_root_poa()->reference_to_servant(local_corba_field); + std::cerr << "Servant succeeded!" << std::endl; + MEDCoupling::ParaMEDCouplingFieldDoubleServant* servant_field = + dynamic_cast(ret); + if(servant_field != NULL) + { + std::cerr << "In-situ configuration!" << std::endl; + // same container, same mpi proc, use the pointer directly. + local_field = servant_field->getPointer(); + ret->_remove_ref(); + } + } + catch(...){ + // different container - need to make a copy of the field. + ret = NULL; + std::cerr << "Co-processing configuration!" << std::endl; + local_field = MEDCoupling::MEDCouplingFieldDoubleClient::New(local_corba_field); + } +} +else if(nb_fields < _nbproc) +{ + if(_numproc < nb_fields) + { + SALOME_MED::ParaMEDCouplingFieldDoubleCorbaInterface_ptr local_corba_field = + SALOME_MED::ParaMEDCouplingFieldDoubleCorbaInterface::_narrow((*(field->tior()))[_numproc]); + local_field = MEDCoupling::MEDCouplingFieldDoubleClient::New(local_corba_field); + } +} +else //nb_fields > _nbproc +{ + int q = nb_fields / _nbproc; // int division + int r = nb_fields - q * _nbproc; + int start, end; + + if(_numproc < r) + { + // get one more field to process + start = _numproc * (q + 1); + end = start + q + 1; + } + else + { + start = r * (q + 1) + (_numproc - r) * q; + end = start + q; + } + + std::cerr << "Proc n° " << _numproc << ". Merge fields from " << start << " to " << end << std::endl; + + std::vector fieldsToProcess; + for(int i = start; i < end; i++) + { + SALOME_MED::ParaMEDCouplingFieldDoubleCorbaInterface_ptr local_corba_field = + SALOME_MED::ParaMEDCouplingFieldDoubleCorbaInterface::_narrow((*(field->tior()))[i]); + fieldsToProcess.push_back(MEDCoupling::MEDCouplingFieldDoubleClient::New(local_corba_field)); + } + + local_field = MEDCoupling::MEDCouplingFieldDouble::MergeFields(fieldsToProcess); +} + +Visualization v; +v.run(const_cast(local_field), path_python_file); + +//ENDBODY + if(_numproc == 0) + { + for(int ip=1;ip<_nbproc;ip++) + { + pthread_join(th[ip],&ret_th); + est = (exception_st*)ret_th; + if(est->exception) + { + std::ostringstream msg; + msg << "[" << ip << "] " << est->msg; + delete est; + delete[] th; + THROW_SALOME_CORBA_EXCEPTION(msg.str().c_str(),SALOME::INTERNAL_ERROR); + } + delete est; + } + delete[] th; + } + } + catch ( const SALOME_Exception & ex) + { + THROW_SALOME_CORBA_EXCEPTION(CORBA::string_dup(ex.what()), SALOME::INTERNAL_ERROR); + } + catch ( const SALOME::SALOME_Exception & ex) + { + throw; + } + catch ( const std::exception& ex) + { + THROW_SALOME_CORBA_EXCEPTION(CORBA::string_dup(ex.what()), SALOME::INTERNAL_ERROR); + } + catch (...) + { + THROW_SALOME_CORBA_EXCEPTION("unknown exception", SALOME::INTERNAL_ERROR); + } + endService("VisualizationComponent_i::Visualize"); +} + + + +extern "C" +{ + PortableServer::ObjectId * VisualizationComponentEngine_factory( CORBA::ORB_ptr orb, + PortableServer::POA_ptr poa, + PortableServer::ObjectId * contId, + const char *instanceName, + const char *interfaceName) + { + MESSAGE("PortableServer::ObjectId * VisualizationComponentEngine_factory()"); + int is_mpi_container; + bool regist; + int numproc; + + MPI_Initialized(&is_mpi_container); + if (!is_mpi_container) + { + int argc = 0; + char ** argv = NULL; + MPI_Init(&argc, &argv); + } + + MPI_Comm_rank( MPI_COMM_WORLD, &numproc ); + regist = ( numproc == 0 ); + VisualizationComponent_i * myEngine = new VisualizationComponent_i(orb, poa, contId, instanceName, interfaceName, regist); + return myEngine->getId() ; + } +} diff --git a/src/Insitu/VisualizationComponent/VisualizationComponent.hxx b/src/Insitu/VisualizationComponent/VisualizationComponent.hxx new file mode 100644 index 00000000..d3b65d87 --- /dev/null +++ b/src/Insitu/VisualizationComponent/VisualizationComponent.hxx @@ -0,0 +1,51 @@ + +#ifndef _VisualizationComponent_HXX_ +#define _VisualizationComponent_HXX_ + +#include +#include "Superv_Component_i.hxx" +#include "PARAVIS.hh" +#include "MPIObject_i.hxx" + +//COMPODEFS + + +void * th_Visualize(void * s); +typedef struct { + int ip; // mpi process id + Engines::IORTab* tior; + SALOME_MED::ParaMEDCouplingFieldDoubleCorbaInterface_ptr field; +const char* path_python_file; +} thread_Visualize_struct; + + +//ENDDEF + +class VisualizationComponent_i: public virtual POA_PARAVIS_ORB::VisualizationComponent, + + public virtual MPIObject_i, + public virtual Engines_Component_i +{ + public: + VisualizationComponent_i(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, + PortableServer::ObjectId * contId, + const char *instanceName, const char *interfaceName, + bool regist = true); + VisualizationComponent_i(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, + Engines::Container_ptr container, + const char *instanceName, const char *interfaceName, + bool regist = true); + virtual ~VisualizationComponent_i(); + void Visualize(SALOME_MED::ParaMEDCouplingFieldDoubleCorbaInterface_ptr field,const char* path_python_file); +}; + +extern "C" +{ + PortableServer::ObjectId * VisualizationComponentEngine_factory( CORBA::ORB_ptr orb, + PortableServer::POA_ptr poa, + PortableServer::ObjectId * contId, + const char *instanceName, + const char *interfaceName); +} +#endif + diff --git a/src/Insitu/VisualizationLibrary/CMakeLists.txt b/src/Insitu/VisualizationLibrary/CMakeLists.txt new file mode 100644 index 00000000..5ff03098 --- /dev/null +++ b/src/Insitu/VisualizationLibrary/CMakeLists.txt @@ -0,0 +1,42 @@ + +SET(BUILD_SHARED_LIBS TRUE) +INCLUDE_DIRECTORIES( + ${MEDCOUPLING_INCLUDE_DIRS} + ${MPI_INCLUDE_PATH} + ${PARAVIS_INCLUDE_DIRS} + ${CMAKE_CURRENT_SOURCE_DIR}/../../Plugins/MEDReader/IO/ +) + + +SET(_link_LIBRARIES + ${MEDCoupling_medcoupling} + ${MEDCoupling_interpkernel} + ${MPI_LIBRARIES} + ${VTK_LIBRARIES} + ${PARAVIS_MEDLoaderForPV} + #${MEDLoaderForPV} + ${MEDCoupling_medloader} + ${MEDFILE_C_LIBRARIES} + vtkPVCatalyst + vtkPVPythonCatalyst +) + +SET(_lib_HEADERS + visu.hxx +) + +SET(_lib_SOURCES + visu.cxx +) + +ADD_LIBRARY(visulib ${_lib_SOURCES}) +TARGET_LINK_LIBRARIES(visulib ${_link_LIBRARIES} ) + +INSTALL(TARGETS visulib + RUNTIME DESTINATION lib/salome + LIBRARY DESTINATION lib/salome + ARCHIVE DESTINATION lib/salome + ) +INSTALL(FILES ${_lib_HEADERS} DESTINATION include/salome ) + + diff --git a/src/Insitu/visu.cxx b/src/Insitu/VisualizationLibrary/visu.cxx similarity index 95% rename from src/Insitu/visu.cxx rename to src/Insitu/VisualizationLibrary/visu.cxx index 9c85828f..282ac207 100755 --- a/src/Insitu/visu.cxx +++ b/src/Insitu/VisualizationLibrary/visu.cxx @@ -145,14 +145,6 @@ void Visualization::run(MEDCoupling::MEDCouplingFieldDouble* field, const std::s int proc_id; MPI_Comm_rank(MPI_COMM_WORLD,&proc_id); - if( field == NULL) - { - std::cerr << "Description n° " << proc_id << ": NULL pointer" << std::endl; - } - std::cerr << "Description n° " << proc_id << ":" - << field->getDescription() << std::endl; - - vtkDataSet *VTKGrid = 0; ConvertToVTK(field, VTKGrid); diff --git a/src/Insitu/visu.hxx b/src/Insitu/VisualizationLibrary/visu.hxx similarity index 100% rename from src/Insitu/visu.hxx rename to src/Insitu/VisualizationLibrary/visu.hxx -- 2.39.2