From c66a21a11fed90a9536b758a162785908cfe87da Mon Sep 17 00:00:00 2001 From: vsr Date: Thu, 13 Dec 2012 10:43:47 +0000 Subject: [PATCH] Merge from V6_main 13/12/2012 --- CMakeLists.txt | 2 +- doc/doxygen/Makefile.am | 16 +- src/INTERP_KERNEL/CMakeLists.txt | 7 +- src/INTERP_KERNEL/CellModel.cxx | 4 +- .../ExprEval/InterpKernelExprParser.cxx | 4 +- .../ExprEval/InterpKernelFunction.cxx | 174 +++++++++ .../ExprEval/InterpKernelFunction.hxx | 72 ++++ .../ExprEval/InterpKernelValue.cxx | 102 +++++ .../ExprEval/InterpKernelValue.hxx | 24 ++ .../GaussPoints/InterpKernelGaussCoords.cxx | 4 +- .../InterpKernelGeo2DComposedEdge.cxx | 17 + .../InterpKernelGeo2DComposedEdge.hxx | 1 + .../InterpKernelGeo2DQuadraticPolygon.cxx | 243 +++++++++++- .../InterpKernelGeo2DQuadraticPolygon.hxx | 9 +- src/INTERP_KERNEL/Interpolation3D2D.txx | 17 +- src/INTERP_KERNEL/InterpolationCC.hxx | 2 +- src/INTERP_KERNEL/InterpolationCC.txx | 4 + src/INTERP_KERNEL/InterpolationCU.txx | 2 +- src/INTERP_KERNEL/TetraAffineTransform.cxx | 6 +- src/INTERP_KERNEL/VolSurfFormulae.hxx | 31 ++ src/INTERP_KERNEL/VolSurfUser.txx | 42 +- .../SingleElementPlanarTests.cxx | 4 + .../UnitTetra3D2DIntersectionTest.cxx | 6 +- src/MED/CMakeLists.txt | 1 + src/MEDCoupling/CMakeLists.txt | 1 + src/MEDCoupling/MEDCouplingCMesh.cxx | 8 + src/MEDCoupling/MEDCouplingField.cxx | 7 + src/MEDCoupling/MEDCouplingField.hxx | 2 + .../MEDCouplingFieldDiscretization.cxx | 175 ++++----- .../MEDCouplingFieldDiscretization.hxx | 35 +- src/MEDCoupling/MEDCouplingFieldDouble.cxx | 36 +- src/MEDCoupling/MEDCouplingFieldDouble.hxx | 2 +- src/MEDCoupling/MEDCouplingMemArray.cxx | 121 +++++- src/MEDCoupling/MEDCouplingMemArray.hxx | 13 +- src/MEDCoupling/MEDCouplingMesh.cxx | 12 + src/MEDCoupling/MEDCouplingMesh.hxx | 1 + src/MEDCoupling/MEDCouplingRefCountObject.cxx | 19 + src/MEDCoupling/MEDCouplingRefCountObject.hxx | 4 + src/MEDCoupling/MEDCouplingRemapper.cxx | 185 ++++++++- src/MEDCoupling/MEDCouplingRemapper.hxx | 9 +- src/MEDCoupling/MEDCouplingUMesh.cxx | 151 +++++--- src/MEDCoupling/MEDCouplingUMesh.hxx | 1 + src/MEDCoupling/Makefile.am | 2 +- .../Test/MEDCouplingBasicsTest1.cxx | 2 +- .../Test/MEDCouplingBasicsTest2.cxx | 1 + .../Test/MEDCouplingBasicsTest3.cxx | 8 +- .../Test/MEDCouplingBasicsTest4.cxx | 58 +-- .../Test/MEDCouplingBasicsTest5.cxx | 150 +++++++- .../Test/MEDCouplingBasicsTest5.hxx | 6 + src/MEDCoupling_Swig/MEDCouplingBasicsTest.py | 233 +++++++++-- src/MEDCoupling_Swig/MEDCouplingCommon.i | 154 ++++++-- .../MEDCouplingRemapperTest.py | 163 ++++++++ src/MEDCoupling_Swig/MEDCouplingTypemaps.i | 361 +++++++++++++++--- src/MEDLoader/MEDFileData.cxx | 1 - src/MEDLoader/MEDFileField.cxx | 235 +++++++----- src/MEDLoader/MEDFileField.hxx | 7 +- src/MEDLoader/MEDFileMesh.cxx | 6 +- src/MEDLoader/MEDFileMeshLL.cxx | 1 - src/MEDLoader/MEDLoader.cxx | 258 +++++++++---- src/MEDLoader/MEDLoader.hxx | 10 +- src/MEDLoader/Swig/MEDLoaderTest3.py | 150 ++++++++ src/MEDMEMCppTest/CMakeLists.txt | 1 + src/MEDOP/cmp/CMakeLists.txt | 2 +- src/MEDOP/doc/models/medop.xmi | 46 +-- src/MEDOP/doc/sphinx/CMakeLists.txt | 15 - src/MEDOP/doc/sphinx/Makefile.am | 26 +- .../sphinx/_static/{xmed.css => medop.css} | 0 src/MEDOP/doc/sphinx/conf.py.in | 12 +- src/MEDOP/doc/sphinx/index.rst | 40 +- ...-definitions.rst => medop-definitions.rst} | 0 ...ed-develguide.rst => medop-develguide.rst} | 194 ++++++---- ...ide.rst => medop-prototype-develguide.rst} | 0 ...-medmem.rst => medop-prototype-medmem.rst} | 2 +- ...rview.rst => medop-prototype-overview.rst} | 0 ...ed-references.rst => medop-references.rst} | 2 +- ...fications.rst => medop-specifications.rst} | 10 +- ...xmed-userguide.rst => medop-userguide.rst} | 33 +- ...s-2010.rst => medop-workingnotes-2010.rst} | 0 ...s-2011.rst => medop-workingnotes-2011.rst} | 2 +- ...s-2012.rst => medop-workingnotes-2012.rst} | 2 +- src/MEDOP/doc/sphinx/salomedoc.rst | 231 ----------- 81 files changed, 2997 insertions(+), 1003 deletions(-) rename src/MEDOP/doc/sphinx/_static/{xmed.css => medop.css} (100%) rename src/MEDOP/doc/sphinx/{xmed-definitions.rst => medop-definitions.rst} (100%) rename src/MEDOP/doc/sphinx/{xmed-develguide.rst => medop-develguide.rst} (78%) rename src/MEDOP/doc/sphinx/{xmed-prototype-develguide.rst => medop-prototype-develguide.rst} (100%) rename src/MEDOP/doc/sphinx/{xmed-prototype-medmem.rst => medop-prototype-medmem.rst} (99%) rename src/MEDOP/doc/sphinx/{xmed-prototype-overview.rst => medop-prototype-overview.rst} (100%) rename src/MEDOP/doc/sphinx/{xmed-references.rst => medop-references.rst} (96%) rename src/MEDOP/doc/sphinx/{xmed-specifications.rst => medop-specifications.rst} (99%) rename src/MEDOP/doc/sphinx/{xmed-userguide.rst => medop-userguide.rst} (97%) rename src/MEDOP/doc/sphinx/{xmed-workingnotes-2010.rst => medop-workingnotes-2010.rst} (100%) rename src/MEDOP/doc/sphinx/{xmed-workingnotes-2011.rst => medop-workingnotes-2011.rst} (99%) rename src/MEDOP/doc/sphinx/{xmed-workingnotes-2012.rst => medop-workingnotes-2012.rst} (98%) delete mode 100644 src/MEDOP/doc/sphinx/salomedoc.rst diff --git a/CMakeLists.txt b/CMakeLists.txt index a431ab0ba..39e1b2347 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,7 @@ IF(COMMAND cmake_policy) ENDIF(COMMAND cmake_policy) ENABLE_TESTING() -SET(VERSION "6.5.0") +SET(VERSION "7.0.0") SET(VERSION_DEV "1") SET(WITH_MEDMEMGUI "0") diff --git a/doc/doxygen/Makefile.am b/doc/doxygen/Makefile.am index af1299164..10599e26c 100644 --- a/doc/doxygen/Makefile.am +++ b/doc/doxygen/Makefile.am @@ -23,9 +23,18 @@ include $(top_srcdir)/adm_local/unix/make_common_starter.am DOX_INPUT_FILE = Doxyfile_med_user +DOX_EXTRA_FILES = medcouplingexamples.dox + guidocdir = $(docdir)/gui/MED guidoc_DATA = images/head.png +# documentation +html-local: $(DOXY_INPUT_FILE) $(DOX_EXTRA_FILES) + @doxygen $(DOX_INPUT_FILE) + +%.dox: %.doxy + @python $(srcdir)/BuildPyExamplesFromCPP.py $< $(top_builddir)/doc/doxygen + install-data-local : html-local @if test -d doc_ref_user; then \ $(INSTALL) -d $(DESTDIR)$(docdir)/gui/MED; \ @@ -41,7 +50,7 @@ uninstall-local: rm -rf $(DESTDIR)$(docdir)/gui/MED clean-local: - rm -rf doc_ref_user log_user + rm -rf doc_ref_user log_user $(DOX_EXTRA_FILES) EXTRA_DIST += figures \ main.dox \ @@ -70,5 +79,6 @@ EXTRA_DIST += figures \ static/footer.html \ static/doxygen.css \ images \ - BuildPyExamplesFromCPP.py \ - medcouplingexamples.doxy + BuildPyExamplesFromCPP.py + +EXTRA_DIST += $(DOX_EXTRA_FILES:%.dox=%.doxy) diff --git a/src/INTERP_KERNEL/CMakeLists.txt b/src/INTERP_KERNEL/CMakeLists.txt index 8d9d2463a..02d8637bd 100644 --- a/src/INTERP_KERNEL/CMakeLists.txt +++ b/src/INTERP_KERNEL/CMakeLists.txt @@ -65,8 +65,13 @@ INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/GaussPoints ) +SET(PLATFORM_MMAP) +IF(NOT WINDOWS) + SET(PLATFORM_MMAP "-D_POSIX_MAPPED_FILES") +ENDIF(NOT WINDOWS) + ADD_LIBRARY(interpkernel SHARED ${interpkernel_SOURCES}) -SET_TARGET_PROPERTIES(interpkernel PROPERTIES COMPILE_FLAGS "${PLATFORM_DEFINITIONS}") +SET_TARGET_PROPERTIES(interpkernel PROPERTIES COMPILE_FLAGS "${PLATFORM_DEFINITIONS} ${PLATFORM_MMAP}") TARGET_LINK_LIBRARIES(interpkernel ${PLATFORM_LIBS}) INSTALL(TARGETS interpkernel DESTINATION ${MED_salomelib_LIBS}) diff --git a/src/INTERP_KERNEL/CellModel.cxx b/src/INTERP_KERNEL/CellModel.cxx index 137810123..6a027a819 100644 --- a/src/INTERP_KERNEL/CellModel.cxx +++ b/src/INTERP_KERNEL/CellModel.cxx @@ -419,8 +419,8 @@ namespace INTERP_KERNEL else { sonNodalConn[0]=nodalConn[sonId]; - sonNodalConn[1]=nodalConn[(sonId+1)%lgth]; - sonNodalConn[2]=nodalConn[sonId+lgth]; + sonNodalConn[1]=nodalConn[(sonId+1)%(lgth/2)]; + sonNodalConn[2]=nodalConn[sonId+(lgth/2)]; return 3; } } diff --git a/src/INTERP_KERNEL/ExprEval/InterpKernelExprParser.cxx b/src/INTERP_KERNEL/ExprEval/InterpKernelExprParser.cxx index e75a2e5f4..a8d02a3b5 100644 --- a/src/INTERP_KERNEL/ExprEval/InterpKernelExprParser.cxx +++ b/src/INTERP_KERNEL/ExprEval/InterpKernelExprParser.cxx @@ -1009,7 +1009,7 @@ void ExprParser::compileX86_64LowLev(std::vector& ass) const void LeafExprVal::compileX86(std::vector& ass) const { ass.push_back("sub esp,8"); - int *b=(int *)&_value,*c=(int *)&_value; + const int *b=reinterpret_cast(&_value),*c=reinterpret_cast(&_value); c++; std::ostringstream oss; oss << std::hex; @@ -1025,7 +1025,7 @@ void LeafExprVal::compileX86(std::vector& ass) const void LeafExprVal::compileX86_64(std::vector& ass) const { ass.push_back("sub rsp,8"); - int *b=(int *)&_value,*c=(int *)&_value; + const int *b=reinterpret_cast(&_value),*c=reinterpret_cast(&_value); c++; std::ostringstream oss; oss << std::hex; diff --git a/src/INTERP_KERNEL/ExprEval/InterpKernelFunction.cxx b/src/INTERP_KERNEL/ExprEval/InterpKernelFunction.cxx index c8e4d5b8d..6e4f13e7b 100644 --- a/src/INTERP_KERNEL/ExprEval/InterpKernelFunction.cxx +++ b/src/INTERP_KERNEL/ExprEval/InterpKernelFunction.cxx @@ -37,6 +37,18 @@ const char SinFunction::REPR[]="sin"; const char TanFunction::REPR[]="tan"; +const char ACosFunction::REPR[]="acos"; + +const char ASinFunction::REPR[]="asin"; + +const char ATanFunction::REPR[]="atan"; + +const char CoshFunction::REPR[]="cosh"; + +const char SinhFunction::REPR[]="sinh"; + +const char TanhFunction::REPR[]="tanh"; + const char SqrtFunction::REPR[]="sqrt"; const char AbsFunction::REPR[]="abs"; @@ -95,6 +107,18 @@ Function *FunctionsFactory::buildUnaryFuncFromString(const char *type) throw(INT return new SinFunction; if(tmp==TanFunction::REPR) return new TanFunction; + if(tmp==ACosFunction::REPR) + return new ACosFunction; + if(tmp==ASinFunction::REPR) + return new ASinFunction; + if(tmp==ATanFunction::REPR) + return new ATanFunction; + if(tmp==CoshFunction::REPR) + return new CoshFunction; + if(tmp==SinhFunction::REPR) + return new SinhFunction; + if(tmp==TanhFunction::REPR) + return new TanhFunction; if(tmp==SqrtFunction::REPR) return new SqrtFunction; if(tmp==AbsFunction::REPR) @@ -312,6 +336,156 @@ bool TanFunction::isACall() const return true; } +ACosFunction::~ACosFunction() +{ +} + +void ACosFunction::operate(std::vector& stack) const throw(INTERP_KERNEL::Exception) +{ + Value *val=stack.back(); + val->acos(); +} + +void ACosFunction::operateX86(std::vector& asmb) const throw(INTERP_KERNEL::Exception) +{ + throw INTERP_KERNEL::Exception("Assembly Not implemented yet !"); +} + +const char *ACosFunction::getRepr() const +{ + return REPR; +} + +bool ACosFunction::isACall() const +{ + return true; +} + +ASinFunction::~ASinFunction() +{ +} + +void ASinFunction::operate(std::vector& stack) const throw(INTERP_KERNEL::Exception) +{ + Value *val=stack.back(); + val->asin(); +} + +void ASinFunction::operateX86(std::vector& asmb) const throw(INTERP_KERNEL::Exception) +{ + throw INTERP_KERNEL::Exception("Assembly Not implemented yet !"); +} + +const char *ASinFunction::getRepr() const +{ + return REPR; +} + +bool ASinFunction::isACall() const +{ + return true; +} + +ATanFunction::~ATanFunction() +{ +} + +void ATanFunction::operate(std::vector& stack) const throw(INTERP_KERNEL::Exception) +{ + Value *val=stack.back(); + val->atan(); +} + +void ATanFunction::operateX86(std::vector& asmb) const throw(INTERP_KERNEL::Exception) +{ + throw INTERP_KERNEL::Exception("Assembly Not implemented yet !"); +} + +const char *ATanFunction::getRepr() const +{ + return REPR; +} + +bool ATanFunction::isACall() const +{ + return true; +} + +CoshFunction::~CoshFunction() +{ +} + +void CoshFunction::operate(std::vector& stack) const throw(INTERP_KERNEL::Exception) +{ + Value *val=stack.back(); + val->cosh(); +} + +void CoshFunction::operateX86(std::vector& asmb) const throw(INTERP_KERNEL::Exception) +{ + throw INTERP_KERNEL::Exception("Assembly Not implemented yet !"); +} + +const char *CoshFunction::getRepr() const +{ + return REPR; +} + +bool CoshFunction::isACall() const +{ + return true; +} + +SinhFunction::~SinhFunction() +{ +} + +void SinhFunction::operate(std::vector& stack) const throw(INTERP_KERNEL::Exception) +{ + Value *val=stack.back(); + val->sinh(); +} + +void SinhFunction::operateX86(std::vector& asmb) const throw(INTERP_KERNEL::Exception) +{ + throw INTERP_KERNEL::Exception("Assembly Not implemented yet !"); +} + +const char *SinhFunction::getRepr() const +{ + return REPR; +} + +bool SinhFunction::isACall() const +{ + return true; +} + +TanhFunction::~TanhFunction() +{ +} + +void TanhFunction::operate(std::vector& stack) const throw(INTERP_KERNEL::Exception) +{ + Value *val=stack.back(); + val->tanh(); +} + +void TanhFunction::operateX86(std::vector& asmb) const throw(INTERP_KERNEL::Exception) +{ + throw INTERP_KERNEL::Exception("Assembly Not implemented yet !"); +} + +const char *TanhFunction::getRepr() const +{ + return REPR; +} + +bool TanhFunction::isACall() const +{ + return true; +} + SqrtFunction::~SqrtFunction() { } diff --git a/src/INTERP_KERNEL/ExprEval/InterpKernelFunction.hxx b/src/INTERP_KERNEL/ExprEval/InterpKernelFunction.hxx index f49c75943..b63382683 100644 --- a/src/INTERP_KERNEL/ExprEval/InterpKernelFunction.hxx +++ b/src/INTERP_KERNEL/ExprEval/InterpKernelFunction.hxx @@ -131,6 +131,78 @@ namespace INTERP_KERNEL static const char REPR[]; }; + class INTERPKERNEL_EXPORT ACosFunction : public UnaryFunction + { + public: + ~ACosFunction(); + void operate(std::vector& stack) const throw(INTERP_KERNEL::Exception); + void operateX86(std::vector& asmb) const throw(INTERP_KERNEL::Exception); + const char *getRepr() const; + bool isACall() const; + public: + static const char REPR[]; + }; + + class INTERPKERNEL_EXPORT ASinFunction : public UnaryFunction + { + public: + ~ASinFunction(); + void operate(std::vector& stack) const throw(INTERP_KERNEL::Exception); + void operateX86(std::vector& asmb) const throw(INTERP_KERNEL::Exception); + const char *getRepr() const; + bool isACall() const; + public: + static const char REPR[]; + }; + + class INTERPKERNEL_EXPORT ATanFunction : public UnaryFunction + { + public: + ~ATanFunction(); + void operate(std::vector& stack) const throw(INTERP_KERNEL::Exception); + void operateX86(std::vector& asmb) const throw(INTERP_KERNEL::Exception); + const char *getRepr() const; + bool isACall() const; + public: + static const char REPR[]; + }; + + class INTERPKERNEL_EXPORT CoshFunction : public UnaryFunction + { + public: + ~CoshFunction(); + void operate(std::vector& stack) const throw(INTERP_KERNEL::Exception); + void operateX86(std::vector& asmb) const throw(INTERP_KERNEL::Exception); + const char *getRepr() const; + bool isACall() const; + public: + static const char REPR[]; + }; + + class INTERPKERNEL_EXPORT SinhFunction : public UnaryFunction + { + public: + ~SinhFunction(); + void operate(std::vector& stack) const throw(INTERP_KERNEL::Exception); + void operateX86(std::vector& asmb) const throw(INTERP_KERNEL::Exception); + const char *getRepr() const; + bool isACall() const; + public: + static const char REPR[]; + }; + + class INTERPKERNEL_EXPORT TanhFunction : public UnaryFunction + { + public: + ~TanhFunction(); + void operate(std::vector& stack) const throw(INTERP_KERNEL::Exception); + void operateX86(std::vector& asmb) const throw(INTERP_KERNEL::Exception); + const char *getRepr() const; + bool isACall() const; + public: + static const char REPR[]; + }; + class INTERPKERNEL_EXPORT SqrtFunction : public UnaryFunction { public: diff --git a/src/INTERP_KERNEL/ExprEval/InterpKernelValue.cxx b/src/INTERP_KERNEL/ExprEval/InterpKernelValue.cxx index 6564cfd25..3a24ef6da 100644 --- a/src/INTERP_KERNEL/ExprEval/InterpKernelValue.cxx +++ b/src/INTERP_KERNEL/ExprEval/InterpKernelValue.cxx @@ -80,6 +80,36 @@ void ValueDouble::tan() throw(INTERP_KERNEL::Exception) _data=std::tan(_data); } +void ValueDouble::acos() throw(INTERP_KERNEL::Exception) +{ + _data=std::acos(_data); +} + +void ValueDouble::asin() throw(INTERP_KERNEL::Exception) +{ + _data=std::asin(_data); +} + +void ValueDouble::atan() throw(INTERP_KERNEL::Exception) +{ + _data=std::atan(_data); +} + +void ValueDouble::cosh() throw(INTERP_KERNEL::Exception) +{ + _data=std::cosh(_data); +} + +void ValueDouble::sinh() throw(INTERP_KERNEL::Exception) +{ + _data=std::sinh(_data); +} + +void ValueDouble::tanh() throw(INTERP_KERNEL::Exception) +{ + _data=std::tanh(_data); +} + void ValueDouble::abs() throw(INTERP_KERNEL::Exception) { if(_data<0.) @@ -229,6 +259,36 @@ void ValueUnit::tan() throw(INTERP_KERNEL::Exception) unsupportedOp(TanFunction::REPR); } +void ValueUnit::acos() throw(INTERP_KERNEL::Exception) +{ + unsupportedOp(ACosFunction::REPR); +} + +void ValueUnit::asin() throw(INTERP_KERNEL::Exception) +{ + unsupportedOp(ASinFunction::REPR); +} + +void ValueUnit::atan() throw(INTERP_KERNEL::Exception) +{ + unsupportedOp(ATanFunction::REPR); +} + +void ValueUnit::cosh() throw(INTERP_KERNEL::Exception) +{ + unsupportedOp(CoshFunction::REPR); +} + +void ValueUnit::sinh() throw(INTERP_KERNEL::Exception) +{ + unsupportedOp(SinhFunction::REPR); +} + +void ValueUnit::tanh() throw(INTERP_KERNEL::Exception) +{ + unsupportedOp(TanhFunction::REPR); +} + void ValueUnit::abs() throw(INTERP_KERNEL::Exception) { unsupportedOp(AbsFunction::REPR); @@ -395,6 +455,48 @@ void ValueDoubleExpr::tan() throw(INTERP_KERNEL::Exception) std::transform(_dest_data,_dest_data+_sz_dest_data,_dest_data,std::ptr_fun(std::tan)); } +void ValueDoubleExpr::acos() throw(INTERP_KERNEL::Exception) +{ + double *it=std::find_if(_dest_data,_dest_data+_sz_dest_data,std::bind2nd(std::less(),-1.)); + if(it!=_dest_data+_sz_dest_data) + throw INTERP_KERNEL::Exception("Trying to apply acos on < 1. value !"); + it=std::find_if(_dest_data,_dest_data+_sz_dest_data,std::bind2nd(std::greater(),1.)); + if(it!=_dest_data+_sz_dest_data) + throw INTERP_KERNEL::Exception("Trying to apply acos on > 1. value !"); + std::transform(_dest_data,_dest_data+_sz_dest_data,_dest_data,std::ptr_fun(std::acos)); +} + +void ValueDoubleExpr::asin() throw(INTERP_KERNEL::Exception) +{ + double *it=std::find_if(_dest_data,_dest_data+_sz_dest_data,std::bind2nd(std::less(),-1.)); + if(it!=_dest_data+_sz_dest_data) + throw INTERP_KERNEL::Exception("Trying to apply asin on < 1. value !"); + it=std::find_if(_dest_data,_dest_data+_sz_dest_data,std::bind2nd(std::greater(),1.)); + if(it!=_dest_data+_sz_dest_data) + throw INTERP_KERNEL::Exception("Trying to apply asin on > 1. value !"); + std::transform(_dest_data,_dest_data+_sz_dest_data,_dest_data,std::ptr_fun(std::asin)); +} + +void ValueDoubleExpr::atan() throw(INTERP_KERNEL::Exception) +{ + std::transform(_dest_data,_dest_data+_sz_dest_data,_dest_data,std::ptr_fun(std::atan)); +} + +void ValueDoubleExpr::cosh() throw(INTERP_KERNEL::Exception) +{ + std::transform(_dest_data,_dest_data+_sz_dest_data,_dest_data,std::ptr_fun(std::cosh)); +} + +void ValueDoubleExpr::sinh() throw(INTERP_KERNEL::Exception) +{ + std::transform(_dest_data,_dest_data+_sz_dest_data,_dest_data,std::ptr_fun(std::sinh)); +} + +void ValueDoubleExpr::tanh() throw(INTERP_KERNEL::Exception) +{ + std::transform(_dest_data,_dest_data+_sz_dest_data,_dest_data,std::ptr_fun(std::tanh)); +} + void ValueDoubleExpr::abs() throw(INTERP_KERNEL::Exception) { std::transform(_dest_data,_dest_data+_sz_dest_data,_dest_data,std::ptr_fun(fabs)); diff --git a/src/INTERP_KERNEL/ExprEval/InterpKernelValue.hxx b/src/INTERP_KERNEL/ExprEval/InterpKernelValue.hxx index 71d5bf0f0..36c484b04 100644 --- a/src/INTERP_KERNEL/ExprEval/InterpKernelValue.hxx +++ b/src/INTERP_KERNEL/ExprEval/InterpKernelValue.hxx @@ -41,6 +41,12 @@ namespace INTERP_KERNEL virtual void cos() throw(INTERP_KERNEL::Exception) = 0; virtual void sin() throw(INTERP_KERNEL::Exception) = 0; virtual void tan() throw(INTERP_KERNEL::Exception) = 0; + virtual void acos() throw(INTERP_KERNEL::Exception) = 0; + virtual void asin() throw(INTERP_KERNEL::Exception) = 0; + virtual void atan() throw(INTERP_KERNEL::Exception) = 0; + virtual void cosh() throw(INTERP_KERNEL::Exception) = 0; + virtual void sinh() throw(INTERP_KERNEL::Exception) = 0; + virtual void tanh() throw(INTERP_KERNEL::Exception) = 0; virtual void abs() throw(INTERP_KERNEL::Exception) = 0; virtual void exp() throw(INTERP_KERNEL::Exception) = 0; virtual void ln() throw(INTERP_KERNEL::Exception) = 0; @@ -74,6 +80,12 @@ namespace INTERP_KERNEL void cos() throw(INTERP_KERNEL::Exception); void sin() throw(INTERP_KERNEL::Exception); void tan() throw(INTERP_KERNEL::Exception); + void acos() throw(INTERP_KERNEL::Exception); + void asin() throw(INTERP_KERNEL::Exception); + void atan() throw(INTERP_KERNEL::Exception); + void cosh() throw(INTERP_KERNEL::Exception); + void sinh() throw(INTERP_KERNEL::Exception); + void tanh() throw(INTERP_KERNEL::Exception); void abs() throw(INTERP_KERNEL::Exception); void exp() throw(INTERP_KERNEL::Exception); void ln() throw(INTERP_KERNEL::Exception); @@ -112,6 +124,12 @@ namespace INTERP_KERNEL void cos() throw(INTERP_KERNEL::Exception); void sin() throw(INTERP_KERNEL::Exception); void tan() throw(INTERP_KERNEL::Exception); + void acos() throw(INTERP_KERNEL::Exception); + void asin() throw(INTERP_KERNEL::Exception); + void atan() throw(INTERP_KERNEL::Exception); + void cosh() throw(INTERP_KERNEL::Exception); + void sinh() throw(INTERP_KERNEL::Exception); + void tanh() throw(INTERP_KERNEL::Exception); void abs() throw(INTERP_KERNEL::Exception); void exp() throw(INTERP_KERNEL::Exception); void ln() throw(INTERP_KERNEL::Exception); @@ -152,6 +170,12 @@ namespace INTERP_KERNEL void cos() throw(INTERP_KERNEL::Exception); void sin() throw(INTERP_KERNEL::Exception); void tan() throw(INTERP_KERNEL::Exception); + void acos() throw(INTERP_KERNEL::Exception); + void asin() throw(INTERP_KERNEL::Exception); + void atan() throw(INTERP_KERNEL::Exception); + void cosh() throw(INTERP_KERNEL::Exception); + void sinh() throw(INTERP_KERNEL::Exception); + void tanh() throw(INTERP_KERNEL::Exception); void abs() throw(INTERP_KERNEL::Exception); void exp() throw(INTERP_KERNEL::Exception); void ln() throw(INTERP_KERNEL::Exception); diff --git a/src/INTERP_KERNEL/GaussPoints/InterpKernelGaussCoords.cxx b/src/INTERP_KERNEL/GaussPoints/InterpKernelGaussCoords.cxx index 57e9c936a..0fa9d7b5a 100644 --- a/src/INTERP_KERNEL/GaussPoints/InterpKernelGaussCoords.cxx +++ b/src/INTERP_KERNEL/GaussPoints/InterpKernelGaussCoords.cxx @@ -359,7 +359,7 @@ void GaussInfo::initLocalInfo() throw (INTERP_KERNEL::Exception) if(!aSatify) { - hexa8aInit(); + hexa8bInit(); aSatify = isSatisfy(); CHECK_MACRO; } @@ -373,7 +373,7 @@ void GaussInfo::initLocalInfo() throw (INTERP_KERNEL::Exception) if(!aSatify) { - hexa20aInit(); + hexa20bInit(); aSatify = isSatisfy(); CHECK_MACRO; } diff --git a/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DComposedEdge.cxx b/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DComposedEdge.cxx index ed800c1b8..960ce5183 100644 --- a/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DComposedEdge.cxx +++ b/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DComposedEdge.cxx @@ -136,6 +136,21 @@ void ComposedEdge::initLocations() const (*iter)->initLocations(); } +void ComposedEdge::initLocationsWithOther(const ComposedEdge& other) const +{ + std::set s1,s2; + for(std::list::const_iterator it1=_sub_edges.begin();it1!=_sub_edges.end();it1++) + s1.insert((*it1)->getPtr()); + for(std::list::const_iterator it2=other._sub_edges.begin();it2!=other._sub_edges.end();it2++) + s2.insert((*it2)->getPtr()); + initLocations(); + other.initLocations(); + std::vector s3; + std::set_intersection(s1.begin(),s1.end(),s2.begin(),s2.end(),std::back_insert_iterator< std::vector >(s3)); + for(std::vector::const_iterator it3=s3.begin();it3!=s3.end();it3++) + (*it3)->declareOn(); +} + ComposedEdge *ComposedEdge::clone() const { return new ComposedEdge(*this); @@ -256,6 +271,8 @@ void ComposedEdge::unApplyGlobalSimilarityExt(ComposedEdge& other, double xBary, (*iter)->unApplySimilarity(xBary,yBary,fact); for(std::list::iterator iter=_sub_edges.begin();iter!=_sub_edges.end();iter++) (*iter)->unApplySimilarity(xBary,yBary,fact); + for(std::list::iterator iter=other._sub_edges.begin();iter!=other._sub_edges.end();iter++) + (*iter)->unApplySimilarity(xBary,yBary,fact); } double ComposedEdge::normalizeExt(ComposedEdge *other, double& xBary, double& yBary) diff --git a/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DComposedEdge.hxx b/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DComposedEdge.hxx index 8fbf7bd2e..e3bf49f18 100644 --- a/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DComposedEdge.hxx +++ b/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DComposedEdge.hxx @@ -50,6 +50,7 @@ namespace INTERP_KERNEL bool presenceOfOn() const; bool presenceOfQuadraticEdge() const; void initLocations() const; + void initLocationsWithOther(const ComposedEdge& other) const; ComposedEdge *clone() const; bool isNodeIn(Node *n) const; double getArea() const; diff --git a/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DQuadraticPolygon.cxx b/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DQuadraticPolygon.cxx index 66e3a9b50..b0ee4f1c2 100644 --- a/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DQuadraticPolygon.cxx +++ b/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DQuadraticPolygon.cxx @@ -392,13 +392,37 @@ void QuadraticPolygon::appendSubEdgeFromCrudeDataArray(Edge *baseEdge, std::size */ void QuadraticPolygon::buildFromCrudeDataArray2(const std::map& mapp, bool isQuad, const int *nodalBg, const double *coords, const int *descBg, const int *descEnd, const std::vector >& intersectEdges, const INTERP_KERNEL::QuadraticPolygon& pol1, const int *descBg1, const int *descEnd1, const std::vector >& intersectEdges1, - const std::vector< std::vector >& colinear1) + const std::vector< std::vector >& colinear1, + std::map >& alreadyExistingIn2) { std::size_t nbOfSeg=std::distance(descBg,descEnd); for(std::size_t i=0;i0; int edgeId=abs(descBg[i])-1;//current edge id of pol2 + std::map >::const_iterator it1=alreadyExistingIn2.find(descBg[i]),it2=alreadyExistingIn2.find(-descBg[i]); + if(it1!=alreadyExistingIn2.end() || it2!=alreadyExistingIn2.end()) + { + bool sameDir=(it1!=alreadyExistingIn2.end()); + const std::vector& edgesAlreadyBuilt=sameDir?(*it1).second:(*it2).second; + if(sameDir) + { + for(std::vector::const_iterator it3=edgesAlreadyBuilt.begin();it3!=edgesAlreadyBuilt.end();it3++) + { + Edge *ee=(*it3)->getPtr(); ee->incrRef(); + pushBack(new ElementaryEdge(ee,(*it3)->getDirection())); + } + } + else + { + for(std::vector::const_reverse_iterator it4=edgesAlreadyBuilt.rbegin();it4!=edgesAlreadyBuilt.rend();it4++) + { + Edge *ee=(*it4)->getPtr(); ee->incrRef(); + pushBack(new ElementaryEdge(ee,!(*it4)->getDirection())); + } + } + continue; + } bool directos=colinear1[edgeId].empty(); std::vector > > idIns1; int offset1=0; @@ -420,7 +444,14 @@ void QuadraticPolygon::buildFromCrudeDataArray2(const std::map::const_reverse_iterator it5=_sub_edges.rbegin(); + for(std::size_t p=0;p > >::const_iterator it=idIns1.begin();it!=idIns1.end();it++) + for(std::vector > >::const_iterator it=idIns1.begin();it!=idIns1.end() && !found;it++) { int idIn1=(*it).first;//store if needed the cell id in 1 direct1=(*it).second.first; @@ -459,15 +490,69 @@ void QuadraticPolygon::buildFromCrudeDataArray2(const std::map reuse Edge instance of pol1 ElementaryEdge *e=pol1[offset1+(direct1?offset2:nbOfSubEdges1-offset2-1)]; Edge *ee=e->getPtr(); - ee->incrRef(); ee->declareOn(); - pushBack(new ElementaryEdge(ee,!(direct1^direction11))); + ee->incrRef(); + ElementaryEdge *e2=new ElementaryEdge(ee,!(direct1^direction11)); + pushBack(e2); + alreadyExistingIn2[descBg[i]].push_back(e2); + } + } + } + } +} + +/*! + * Method expected to be called on pol2. Every params not suffixed by numbered are supposed to refer to pol2 (this). + */ +void QuadraticPolygon::updateLocOfEdgeFromCrudeDataArray2(const int *descBg, const int *descEnd, const std::vector >& intersectEdges, const INTERP_KERNEL::QuadraticPolygon& pol1, const int *descBg1, const int *descEnd1, const std::vector >& intersectEdges1, const std::vector< std::vector >& colinear1) const +{ + std::size_t nbOfSeg=std::distance(descBg,descEnd); + for(std::size_t i=0;i0; + int edgeId=abs(descBg[i])-1;//current edge id of pol2 + const std::vector& c=colinear1[edgeId]; + if(c.empty()) + continue; + const std::vector& subEdge=intersectEdges[edgeId]; + std::size_t nbOfSubEdges=subEdge.size()/2; + // + std::size_t nbOfEdgesIn1=std::distance(descBg1,descEnd1); + int offset1=0; + for(std::size_t j=0;j0; + const std::vector& subEdge1PossiblyAlreadyIn1=intersectEdges1[idIn1]; + std::size_t nbOfSubEdges1=subEdge1PossiblyAlreadyIn1.size()/2; + int offset2=0; + bool found=false; + for(std::size_t kk=0;kkgetPtr()->declareOn(); + } } } + offset1+=intersectEdges1[edgeId1].size()/2;//offset1 is used to find the INTERP_KERNEL::Edge * instance into pol1 that will be part of edge into pol2 } } } @@ -505,17 +590,33 @@ void QuadraticPolygon::appendCrudeData(const std::map /*! * This method make the hypothesis that 'this' and 'other' are splited at the minimum into edges that are fully IN, OUT or ON. * This method returns newly created polygons in 'conn' and 'connI' and the corresponding ids ('idThis','idOther') are stored respectively into 'nbThis' and 'nbOther'. + * @param [in,out] edgesThis, parameter that keep informed the caller abount the edges in this not shared by the result of intersection of \a this with \a other + * @param [in,out] edgesBoundaryOther, parameter that strores all edges in result of intersection that are not */ -void QuadraticPolygon::buildPartitionsAbs(QuadraticPolygon& other, const std::map& mapp, int idThis, int idOther, int offset, std::vector& addCoordsQuadratic, std::vector& conn, std::vector& connI, std::vector& nbThis, std::vector& nbOther) +void QuadraticPolygon::buildPartitionsAbs(QuadraticPolygon& other, std::set& edgesThis, std::set& edgesBoundaryOther, const std::map& mapp, int idThis, int idOther, int offset, std::vector& addCoordsQuadratic, std::vector& conn, std::vector& connI, std::vector& nbThis, std::vector& nbOther) { double xBaryBB, yBaryBB; double fact=normalizeExt(&other, xBaryBB, yBaryBB); //Locate 'this' relative to 'other' - other.performLocatingOperation(*this); + other.performLocatingOperationSlow(*this); std::vector res=buildIntersectionPolygons(other,*this); for(std::vector::iterator it=res.begin();it!=res.end();it++) { (*it)->appendCrudeData(mapp,xBaryBB,yBaryBB,fact,offset,addCoordsQuadratic,conn,connI); + INTERP_KERNEL::IteratorOnComposedEdge it1(*it); + for(it1.first();!it1.finished();it1.next()) + { + Edge *e=it1.current()->getPtr(); + if(edgesThis.find(e)!=edgesThis.end()) + edgesThis.erase(e); + else + { + if(edgesBoundaryOther.find(e)!=edgesBoundaryOther.end()) + edgesBoundaryOther.erase(e); + else + edgesBoundaryOther.insert(e); + } + } nbThis.push_back(idThis); nbOther.push_back(idOther); delete *it; @@ -796,6 +897,16 @@ void QuadraticPolygon::performLocatingOperation(QuadraticPolygon& pol2) const } } +void QuadraticPolygon::performLocatingOperationSlow(QuadraticPolygon& pol2) const +{ + IteratorOnComposedEdge it(&pol2); + for(it.first();!it.finished();it.next()) + { + ElementaryEdge *cur=it.current(); + cur->locateFullyMySelfAbsolute(*this); + } +} + /*! * Given 2 polygons 'pol1' and 'pol2' (localized) the resulting polygons are returned. * @@ -829,7 +940,7 @@ std::vector QuadraticPolygon::buildIntersectionPolygons(cons std::list QuadraticPolygon::zipConsecutiveInSegments() const { std::list ret; - IteratorOnComposedEdge it((ComposedEdge *)this); + IteratorOnComposedEdge it(const_cast(this)); int nbOfTurns=recursiveSize(); int i=0; if(!it.goToNextInOn(false,i,nbOfTurns)) @@ -990,3 +1101,121 @@ std::list::iterator QuadraticPolygon::CheckInList(Node *n, s return iter; return iEnd; } + +void QuadraticPolygon::ComputeResidual(const QuadraticPolygon& pol1, const std::set& notUsedInPol1, const std::set& edgesInPol2OnBoundary, const std::map& mapp, int offset, int idThis, + std::vector& addCoordsQuadratic, std::vector& conn, std::vector& connI, std::vector& nb1, std::vector& nb2) +{ + pol1.initLocations(); + for(std::set::const_iterator it=notUsedInPol1.begin();it!=notUsedInPol1.end();it++) + { (*it)->initLocs(); (*it)->declareOn(); } + for(std::set::const_iterator it=edgesInPol2OnBoundary.begin();it!=edgesInPol2OnBoundary.end();it++) + { (*it)->initLocs(); (*it)->declareIn(); } + //// + std::set notUsedInPol1L(notUsedInPol1); + IteratorOnComposedEdge it(const_cast(&pol1)); + int sz=pol1.size(); + std::list pol1Zip; + if(pol1.size()==(int)notUsedInPol1.size() && edgesInPol2OnBoundary.empty()) + { + pol1.appendCrudeData(mapp,0.,0.,1.,offset,addCoordsQuadratic,conn,connI); nb1.push_back(idThis); nb2.push_back(-1); + return ; + } + while(!notUsedInPol1L.empty()) + { + for(int i=0;igetStartNode()->getLoc()!=IN_1 || it.current()->getLoc()!=FULL_ON_1);i++) + it.nextLoop(); + if(it.current()->getStartNode()->getLoc()!=IN_1 || it.current()->getLoc()!=FULL_ON_1) + throw INTERP_KERNEL::Exception("Presence of a target polygon fully included in source polygon ! The partition of this leads to a non simply connex cell (with hole) ! Impossible ! Such resulting cell cannot be stored in MED cell format !"); + QuadraticPolygon *tmp1=new QuadraticPolygon; + do + { + Edge *ee=it.current()->getPtr(); + if(ee->getLoc()==FULL_ON_1) + { + ee->incrRef(); notUsedInPol1L.erase(ee); + tmp1->pushBack(new ElementaryEdge(ee,it.current()->getDirection())); + } + it.nextLoop(); + } + while(it.current()->getStartNode()->getLoc()!=IN_1 && !notUsedInPol1L.empty()); + pol1Zip.push_back(tmp1); + } + //// + std::list retPolsUnderContruction; + std::list edgesInPol2OnBoundaryL(edgesInPol2OnBoundary.begin(),edgesInPol2OnBoundary.end()); + std::map > pol1ZipConsumed; + while(!pol1Zip.empty() || !edgesInPol2OnBoundaryL.empty()) + { + for(std::list::iterator it1=retPolsUnderContruction.begin();it1!=retPolsUnderContruction.end();) + { + if((*it1)->getStartNode()==(*it1)->getEndNode()) + { + it1++; + continue; + } + Node *curN=(*it1)->getEndNode(); + bool smthHappened=false; + for(std::list::iterator it2=edgesInPol2OnBoundaryL.begin();it2!=edgesInPol2OnBoundaryL.end();) + { + if(curN==(*it2)->getStartNode()) + { (*it2)->incrRef(); (*it1)->pushBack(new ElementaryEdge(*it2,true)); curN=(*it2)->getEndNode(); smthHappened=true; it2=edgesInPol2OnBoundaryL.erase(it2); } + else if(curN==(*it2)->getEndNode()) + { (*it2)->incrRef(); (*it1)->pushBack(new ElementaryEdge(*it2,false)); curN=(*it2)->getStartNode(); smthHappened=true; it2=edgesInPol2OnBoundaryL.erase(it2); } + else + it2++; + } + if(smthHappened) + { + for(std::list::iterator it3=pol1Zip.begin();it3!=pol1Zip.end();) + { + if(curN==(*it3)->getStartNode()) + { + for(std::list::const_iterator it4=(*it3)->_sub_edges.begin();it4!=(*it3)->_sub_edges.end();it4++) + { (*it4)->getPtr()->incrRef(); bool dir=(*it4)->getDirection(); (*it1)->pushBack(new ElementaryEdge((*it4)->getPtr(),dir)); } + smthHappened=true; + pol1ZipConsumed[*it1].push_back(*it3); + curN=(*it3)->getEndNode(); + it3=pol1Zip.erase(it3); + } + else + it3++; + } + } + if(!smthHappened) + { + for(std::list::const_iterator it5=(*it1)->_sub_edges.begin();it5!=(*it1)->_sub_edges.end();it5++) + { + Edge *ee=(*it5)->getPtr(); + if(edgesInPol2OnBoundary.find(ee)!=edgesInPol2OnBoundary.end()) + edgesInPol2OnBoundaryL.push_back(ee); + } + for(std::list::iterator it6=pol1ZipConsumed[*it1].begin();it6!=pol1ZipConsumed[*it1].end();it6++) + pol1Zip.push_front(*it6); + pol1ZipConsumed.erase(*it1); + delete *it1; + it1=retPolsUnderContruction.erase(it1); + } + } + if(!pol1Zip.empty()) + { + QuadraticPolygon *tmp=new QuadraticPolygon; + QuadraticPolygon *first=*(pol1Zip.begin()); + for(std::list::const_iterator it4=first->_sub_edges.begin();it4!=first->_sub_edges.end();it4++) + { (*it4)->getPtr()->incrRef(); bool dir=(*it4)->getDirection(); tmp->pushBack(new ElementaryEdge((*it4)->getPtr(),dir)); } + pol1ZipConsumed[tmp].push_back(first); + retPolsUnderContruction.push_back(tmp); + pol1Zip.erase(pol1Zip.begin()); + } + } + for(std::list::iterator it1=retPolsUnderContruction.begin();it1!=retPolsUnderContruction.end();it1++) + { + if((*it1)->getStartNode()==(*it1)->getEndNode()) + { + (*it1)->appendCrudeData(mapp,0.,0.,1.,offset,addCoordsQuadratic,conn,connI); nb1.push_back(idThis); nb2.push_back(-1); + for(std::list::iterator it6=pol1ZipConsumed[*it1].begin();it6!=pol1ZipConsumed[*it1].end();it6++) + delete *it6; + delete *it1; + it1=retPolsUnderContruction.erase(it1); + } + } +} diff --git a/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DQuadraticPolygon.hxx b/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DQuadraticPolygon.hxx index d98b20dcd..9f154aa22 100644 --- a/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DQuadraticPolygon.hxx +++ b/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DQuadraticPolygon.hxx @@ -62,12 +62,14 @@ namespace INTERP_KERNEL const int *descBg, const int *descEnd, const std::vector >& intersectEdges); void buildFromCrudeDataArray2(const std::map& mapp, bool isQuad, const int *nodalBg, const double *coords, const int *descBg, const int *descEnd, const std::vector >& intersectEdges, const INTERP_KERNEL::QuadraticPolygon& pol1, const int *descBg1, const int *descEnd1, const std::vector >& intersectEdges1, - const std::vector< std::vector >& colinear1); + const std::vector< std::vector >& colinear1, + std::map >& alreadyExistingIn2); + void updateLocOfEdgeFromCrudeDataArray2(const int *descBg, const int *descEnd, const std::vector >& intersectEdges, const INTERP_KERNEL::QuadraticPolygon& pol1, const int *descBg1, const int *descEnd1, const std::vector >& intersectEdges1, const std::vector< std::vector >& colinear1) const; void appendEdgeFromCrudeDataArray(std::size_t edgeId, const std::map& mapp, bool isQuad, const int *nodalBg, const double *coords, const int *descBg, const int *descEnd, const std::vector >& intersectEdges); void appendSubEdgeFromCrudeDataArray(Edge *baseEdge, std::size_t j, bool direct, int edgeId, const std::vector& subEdge, const std::map& mapp); void appendCrudeData(const std::map& mapp, double xBary, double yBary, double fact, int offset, std::vector& addCoordsQuadratic, std::vector& conn, std::vector& connI) const; - void buildPartitionsAbs(QuadraticPolygon& other, const std::map& mapp, int idThis, int idOther, int offset, + void buildPartitionsAbs(QuadraticPolygon& other, std::set& edgesThis, std::set& edgesBoundaryOther, const std::map& mapp, int idThis, int idOther, int offset, std::vector& addCoordsQuadratic, std::vector& conn, std::vector& connI, std::vector& nb1, std::vector& nb2); // double intersectWith(const QuadraticPolygon& other) const; @@ -78,9 +80,12 @@ namespace INTERP_KERNEL void intersectForPoint(const QuadraticPolygon& other, std::vector< int >& numberOfCreatedPointsPerEdge) const; public://Only public for tests reasons void performLocatingOperation(QuadraticPolygon& pol2) const; + void performLocatingOperationSlow(QuadraticPolygon& pol2) const; static void SplitPolygonsEachOther(QuadraticPolygon& pol1, QuadraticPolygon& pol2, int& nbOfSplits); std::vector buildIntersectionPolygons(const QuadraticPolygon& pol1, const QuadraticPolygon& pol2) const; bool amIAChanceToBeCompletedBy(const QuadraticPolygon& pol1Splitted, const QuadraticPolygon& pol2NotSplitted, bool& direction); + static void ComputeResidual(const QuadraticPolygon& pol1, const std::set& notUsedInPol1, const std::set& edgesInPol2OnBoundary, const std::map& mapp, int offset, int idThis, + std::vector& addCoordsQuadratic, std::vector& conn, std::vector& connI, std::vector& nb1, std::vector& nb2); protected: std::list zipConsecutiveInSegments() const; void dumpInXfigFile(std::ostream& stream, int resolution, const Bounds& box) const; diff --git a/src/INTERP_KERNEL/Interpolation3D2D.txx b/src/INTERP_KERNEL/Interpolation3D2D.txx index b971d8978..b780a5606 100644 --- a/src/INTERP_KERNEL/Interpolation3D2D.txx +++ b/src/INTERP_KERNEL/Interpolation3D2D.txx @@ -92,15 +92,18 @@ namespace INTERP_KERNEL switch(InterpolationOptions::getIntersectionType()) { case Triangulation: - intersector=new Polyhedron3D2DIntersectorP0P0(targetMesh, - srcMesh, - dimCaracteristic, - getPrecision(), - intersectFaces, - getSplittingPolicy()); + intersector=new Polyhedron3D2DIntersectorP0P0(targetMesh, + srcMesh, + dimCaracteristic, + getPrecision(), + intersectFaces, + getSplittingPolicy()); + break; + case PointLocator: + intersector=new PointLocator3DIntersectorP0P0(targetMesh,srcMesh,getPrecision()); break; default: - throw INTERP_KERNEL::Exception("Invalid 3D intersection type for P0P0 interp specified : must be Triangulation."); + throw INTERP_KERNEL::Exception("Invalid 3D to 2D intersection type for P0P0 interp specified : must be Triangulation or PointLocator."); } } else diff --git a/src/INTERP_KERNEL/InterpolationCC.hxx b/src/INTERP_KERNEL/InterpolationCC.hxx index 88bbc00a1..e3c409592 100644 --- a/src/INTERP_KERNEL/InterpolationCC.hxx +++ b/src/INTERP_KERNEL/InterpolationCC.hxx @@ -39,7 +39,7 @@ namespace INTERP_KERNEL // static const NumberingPolicy numPol=MyMeshType::My_numPol; public: InterpolationCC(); - //InterpolationCC(const InterpolationOptions& io); + InterpolationCC(const InterpolationOptions& io); template int interpolateMeshes(const MyMeshType& srcMesh, const MyMeshType& targetMesh, MatrixType& result, const char *method); diff --git a/src/INTERP_KERNEL/InterpolationCC.txx b/src/INTERP_KERNEL/InterpolationCC.txx index da4ec44f1..84a925986 100644 --- a/src/INTERP_KERNEL/InterpolationCC.txx +++ b/src/INTERP_KERNEL/InterpolationCC.txx @@ -40,6 +40,10 @@ namespace INTERP_KERNEL { } + InterpolationCC::InterpolationCC(const InterpolationOptions& io):Interpolation(io) + { + } + //================================================================================ /*! * \brief An 1D intersection result diff --git a/src/INTERP_KERNEL/InterpolationCU.txx b/src/INTERP_KERNEL/InterpolationCU.txx index f9528e185..af2cf5fae 100644 --- a/src/INTERP_KERNEL/InterpolationCU.txx +++ b/src/INTERP_KERNEL/InterpolationCU.txx @@ -148,7 +148,7 @@ namespace INTERP_KERNEL bool doItersect = true; for ( int j = 0; j < dim && doItersect; ++j ) doItersect = - bb[j*2] < src_coords[j][ src_nb_coords[0]-1 ] - eps && + bb[j*2] < src_coords[j][ src_nb_coords[j]-1 ] - eps && bb[j*2+1] > src_coords[j][0] + eps; if ( !doItersect ) continue; // no intersection diff --git a/src/INTERP_KERNEL/TetraAffineTransform.cxx b/src/INTERP_KERNEL/TetraAffineTransform.cxx index 5c8ac1b6e..0ca3f599e 100644 --- a/src/INTERP_KERNEL/TetraAffineTransform.cxx +++ b/src/INTERP_KERNEL/TetraAffineTransform.cxx @@ -253,9 +253,9 @@ namespace INTERP_KERNEL // form standard base vector i const double b[3] = { - int(i == 0), - int(i == 1), - int(i == 2) + double ( int(i == 0) ), + double ( int(i == 1) ), + double ( int(i == 2) ), }; LOG(6, "b = [" << b[0] << ", " << b[1] << ", " << b[2] << "]"); diff --git a/src/INTERP_KERNEL/VolSurfFormulae.hxx b/src/INTERP_KERNEL/VolSurfFormulae.hxx index b7ad4fdb5..c59737068 100644 --- a/src/INTERP_KERNEL/VolSurfFormulae.hxx +++ b/src/INTERP_KERNEL/VolSurfFormulae.hxx @@ -22,7 +22,10 @@ #define __VOLSURFFORMULAE_HXX__ #include "InterpolationUtils.hxx" +#include "InterpKernelException.hxx" +#include "InterpKernelGeo2DQuadraticPolygon.hxx" +#include #include namespace INTERP_KERNEL @@ -34,6 +37,9 @@ namespace INTERP_KERNEL int spaceDim); + inline double calculateAreaForQPolyg(const double **coords, int nbOfPtsInPolygs, + int spaceDim); + inline double calculateLgthForSeg2(const double *p1, const double *p2, int spaceDim) { if(spaceDim==1) @@ -199,6 +205,31 @@ namespace INTERP_KERNEL return ret; } + double calculateAreaForQPolyg(const double **coords, int nbOfPtsInPolygs, int spaceDim) + { + + if(nbOfPtsInPolygs%2==0) + { + if(spaceDim==2) + { + std::vector nodes(nbOfPtsInPolygs); + for(int i=0;igetArea(); + delete pol; + return -ret; + } + else + return calculateAreaForPolyg(coords,nbOfPtsInPolygs/2,spaceDim); + } + else + { + std::ostringstream oss; oss << "INTERP_KERNEL::calculateAreaForQPolyg : nb of points in quadratic polygon is " << nbOfPtsInPolygs << " should be even !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + // ========================== // Calculate Volume for Tetra // ========================== diff --git a/src/INTERP_KERNEL/VolSurfUser.txx b/src/INTERP_KERNEL/VolSurfUser.txx index 5e4f6129d..adfb96552 100644 --- a/src/INTERP_KERNEL/VolSurfUser.txx +++ b/src/INTERP_KERNEL/VolSurfUser.txx @@ -42,8 +42,6 @@ namespace INTERP_KERNEL return INTERP_KERNEL::calculateLgthForSeg2(coords+(SPACEDIM*N1),coords+(SPACEDIM*N2),SPACEDIM); } case INTERP_KERNEL::NORM_TRI3 : - case INTERP_KERNEL::NORM_TRI6 : - case INTERP_KERNEL::NORM_TRI7 : { int N1 = OTT::coo2C(connec[0]); int N2 = OTT::coo2C(connec[1]); @@ -56,9 +54,20 @@ namespace INTERP_KERNEL } break; + case INTERP_KERNEL::NORM_TRI6 : + case INTERP_KERNEL::NORM_TRI7 : + { + const double *pts[6]; + pts[0] = coords+SPACEDIM*OTT::coo2C(connec[0]); + pts[1] = coords+SPACEDIM*OTT::coo2C(connec[1]); + pts[2] = coords+SPACEDIM*OTT::coo2C(connec[2]); + pts[3] = coords+SPACEDIM*OTT::coo2C(connec[3]); + pts[4] = coords+SPACEDIM*OTT::coo2C(connec[4]); + pts[5] = coords+SPACEDIM*OTT::coo2C(connec[5]); + return INTERP_KERNEL::calculateAreaForQPolyg(pts,6,SPACEDIM); + } + break; case INTERP_KERNEL::NORM_QUAD4 : - case INTERP_KERNEL::NORM_QUAD8 : - case INTERP_KERNEL::NORM_QUAD9 : { int N1 = OTT::coo2C(connec[0]); int N2 = OTT::coo2C(connec[1]); @@ -72,7 +81,21 @@ namespace INTERP_KERNEL SPACEDIM); } break; - + case INTERP_KERNEL::NORM_QUAD8 : + case INTERP_KERNEL::NORM_QUAD9 : + { + const double *pts[8]; + pts[0] = coords+SPACEDIM*OTT::coo2C(connec[0]); + pts[1] = coords+SPACEDIM*OTT::coo2C(connec[1]); + pts[2] = coords+SPACEDIM*OTT::coo2C(connec[2]); + pts[3] = coords+SPACEDIM*OTT::coo2C(connec[3]); + pts[4] = coords+SPACEDIM*OTT::coo2C(connec[4]); + pts[5] = coords+SPACEDIM*OTT::coo2C(connec[5]); + pts[6] = coords+SPACEDIM*OTT::coo2C(connec[6]); + pts[7] = coords+SPACEDIM*OTT::coo2C(connec[7]); + return INTERP_KERNEL::calculateAreaForQPolyg(pts,8,SPACEDIM); + } + break; case INTERP_KERNEL::NORM_POLYGON : { const double **pts=new const double *[lgth]; @@ -83,6 +106,15 @@ namespace INTERP_KERNEL return val; } break; + case INTERP_KERNEL::NORM_QPOLYG : + { + const double **pts=new const double *[lgth]; + for(int inod=0;inod::coo2C(connec[inod]); + double val=INTERP_KERNEL::calculateAreaForQPolyg(pts,lgth,SPACEDIM); + delete [] pts; + return val; + } case INTERP_KERNEL::NORM_TETRA4 : case INTERP_KERNEL::NORM_TETRA10 : { diff --git a/src/INTERP_KERNELTest/SingleElementPlanarTests.cxx b/src/INTERP_KERNELTest/SingleElementPlanarTests.cxx index a8b13882e..64e07e045 100644 --- a/src/INTERP_KERNELTest/SingleElementPlanarTests.cxx +++ b/src/INTERP_KERNELTest/SingleElementPlanarTests.cxx @@ -230,6 +230,9 @@ namespace INTERP_TEST void SingleElementPlanarTests::identicalSquares() { INTERP_KERNEL::PolygonAlgorithms<2> intersector (_Epsilon, _Precision);; + /* + ////////////////// TEST DESACTIVATED by A. GEAY because memory fault : + // conditional jump INTERP_KERNEL::PolygonAlgorithms<2>::intersectConvexPolygons(double const*, double const*, int, int) (PolygonAlgorithms.txx:629) std::deque< double > actual_result = intersector.intersectConvexPolygons(_square1,_square1,4,4); std::deque< double > expected_result; @@ -240,6 +243,7 @@ namespace INTERP_TEST CPPUNIT_ASSERT_MESSAGE("Identical squares test failed (CONVEX)", (INTERP_KERNEL::checkEqualPolygons,2>(&actual_result, &expected_result, _Epsilon))); + */ } void SingleElementPlanarTests::identicalSquares_Triangulation() { diff --git a/src/INTERP_KERNELTest/UnitTetra3D2DIntersectionTest.cxx b/src/INTERP_KERNELTest/UnitTetra3D2DIntersectionTest.cxx index 366d40ca6..b4511ea1c 100644 --- a/src/INTERP_KERNELTest/UnitTetra3D2DIntersectionTest.cxx +++ b/src/INTERP_KERNELTest/UnitTetra3D2DIntersectionTest.cxx @@ -74,7 +74,7 @@ namespace INTERP_TEST precision, listOfTetraFacesTreated, listOfTetraFacesColinear); - + delete targetTetra; CPPUNIT_ASSERT_DOUBLES_EQUAL(40.,surface,precision); CPPUNIT_ASSERT_EQUAL(4,(int)listOfTetraFacesTreated.size()); @@ -120,7 +120,7 @@ namespace INTERP_TEST precision, listOfTetraFacesTreated, listOfTetraFacesColinear); - + delete targetTetra; CPPUNIT_ASSERT_DOUBLES_EQUAL(40.,surface,precision); CPPUNIT_ASSERT_EQUAL(4,(int)listOfTetraFacesTreated.size()); @@ -165,7 +165,7 @@ namespace INTERP_TEST precision, listOfTetraFacesTreated, listOfTetraFacesColinear); - + delete targetTetra; CPPUNIT_ASSERT_DOUBLES_EQUAL(2.5,surface,precision); CPPUNIT_ASSERT_EQUAL(0,(int)listOfTetraFacesTreated.size()); diff --git a/src/MED/CMakeLists.txt b/src/MED/CMakeLists.txt index 0fdffb561..e3898153e 100644 --- a/src/MED/CMakeLists.txt +++ b/src/MED/CMakeLists.txt @@ -24,6 +24,7 @@ INCLUDE_DIRECTORIES( ${PTHREAD_INCLUDE_DIRS} ${XDR_INCLUDE_DIRS} ${KERNEL_ROOT_DIR}/include/salome + ${CMAKE_CURRENT_BINARY_DIR}/../.. ${CMAKE_CURRENT_BINARY_DIR}/../../idl ${CMAKE_CURRENT_SOURCE_DIR}/../MEDMEM_I ${CMAKE_CURRENT_SOURCE_DIR}/../MEDMEM diff --git a/src/MEDCoupling/CMakeLists.txt b/src/MEDCoupling/CMakeLists.txt index e2513eb99..ad1c6fa2b 100644 --- a/src/MEDCoupling/CMakeLists.txt +++ b/src/MEDCoupling/CMakeLists.txt @@ -21,6 +21,7 @@ ADD_SUBDIRECTORY(Test) INCLUDE_DIRECTORIES( + ${CMAKE_CURRENT_BINARY_DIR}/../.. ${CMAKE_CURRENT_SOURCE_DIR}/../INTERP_KERNEL ${CMAKE_CURRENT_SOURCE_DIR}/../INTERP_KERNEL/Bases ${CMAKE_CURRENT_SOURCE_DIR}/../INTERP_KERNEL/Geometric2D diff --git a/src/MEDCoupling/MEDCouplingCMesh.cxx b/src/MEDCoupling/MEDCouplingCMesh.cxx index bd6233b93..2276b4d28 100644 --- a/src/MEDCoupling/MEDCouplingCMesh.cxx +++ b/src/MEDCoupling/MEDCouplingCMesh.cxx @@ -519,6 +519,8 @@ DataArrayDouble *MEDCouplingCMesh::getCoordsAt(int i) throw(INTERP_KERNEL::Excep void MEDCouplingCMesh::setCoordsAt(int i, const DataArrayDouble *arr) throw(INTERP_KERNEL::Exception) { + if(arr) + arr->checkNbOfComps(1,"MEDCouplingCMesh::setCoordsAt"); DataArrayDouble **thisArr[3]={&_x_array,&_y_array,&_z_array}; if(i<0 || i>2) throw INTERP_KERNEL::Exception("Invalid rank specified must be 0 or 1 or 2."); @@ -535,6 +537,12 @@ void MEDCouplingCMesh::setCoordsAt(int i, const DataArrayDouble *arr) throw(INTE void MEDCouplingCMesh::setCoords(const DataArrayDouble *coordsX, const DataArrayDouble *coordsY, const DataArrayDouble *coordsZ) { + if(coordsX) + coordsX->checkNbOfComps(1,"MEDCouplingCMesh::setCoords : coordsX"); + if(coordsY) + coordsY->checkNbOfComps(1,"MEDCouplingCMesh::setCoords : coordsY"); + if(coordsZ) + coordsZ->checkNbOfComps(1,"MEDCouplingCMesh::setCoords : coordsZ"); if(_x_array) _x_array->decrRef(); _x_array=const_cast(coordsX); diff --git a/src/MEDCoupling/MEDCouplingField.cxx b/src/MEDCoupling/MEDCouplingField.cxx index 08eb6970b..805b4a7c5 100644 --- a/src/MEDCoupling/MEDCouplingField.cxx +++ b/src/MEDCoupling/MEDCouplingField.cxx @@ -260,6 +260,13 @@ int MEDCouplingField::getGaussLocalizationIdOfOneType(INTERP_KERNEL::NormalizedC return _type->getGaussLocalizationIdOfOneType(type); } +std::set MEDCouplingField::getGaussLocalizationIdsOfOneType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception) +{ + if(!_mesh) + throw INTERP_KERNEL::Exception("Mesh has to be set before calling getGaussLocalizationIdsOfOneType method !"); + return _type->getGaussLocalizationIdsOfOneType(type); +} + /*! * This method returns number of Gauss localization available. Implicitely all ids in [0,getNbOfGaussLocalization()) is a valid Gauss localisation id. * This method throws an exception if there is no mesh, invalid FieldDescription (different from Gauss) diff --git a/src/MEDCoupling/MEDCouplingField.hxx b/src/MEDCoupling/MEDCouplingField.hxx index 439743ad5..69e6752ee 100644 --- a/src/MEDCoupling/MEDCouplingField.hxx +++ b/src/MEDCoupling/MEDCouplingField.hxx @@ -65,6 +65,7 @@ namespace ParaMEDMEM DataArrayInt *computeTupleIdsToSelectFromCellIds(const int *startCellIds, const int *endCellIds) const; const MEDCouplingFieldDiscretization *getDiscretization() const { return _type; } MEDCouplingFieldDiscretization *getDiscretization() { return _type; } + void setDiscretization(MEDCouplingFieldDiscretization *newDisc) { _type=newDisc; } int getNumberOfTuplesExpected() const throw(INTERP_KERNEL::Exception); int getNumberOfMeshPlacesExpected() const throw(INTERP_KERNEL::Exception); // Gauss point specific methods @@ -75,6 +76,7 @@ namespace ParaMEDMEM void clearGaussLocalizations(); MEDCouplingGaussLocalization& getGaussLocalization(int locId) throw(INTERP_KERNEL::Exception); int getGaussLocalizationIdOfOneType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception); + std::set getGaussLocalizationIdsOfOneType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception); int getNbOfGaussLocalization() const throw(INTERP_KERNEL::Exception); int getGaussLocalizationIdOfOneCell(int cellId) const throw(INTERP_KERNEL::Exception); void getCellIdsHavingGaussLocalization(int locId, std::vector& cellIds) const throw(INTERP_KERNEL::Exception); diff --git a/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx b/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx index 2739ca421..80b9d6a63 100644 --- a/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDiscretization.cxx @@ -113,6 +113,14 @@ bool MEDCouplingFieldDiscretization::isEqualWithoutConsideringStr(const MEDCoupl return isEqual(other,eps); } +/*! + * For all field discretization excepted GaussPts the [ \a startCellIds, \a endCellIds ) has no impact on the cloned instance. + */ +MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretization::clonePart(const int *startCellIds, const int *endCellIds) const +{ + return clone(); +} + /*! * Excepted for MEDCouplingFieldDiscretizationPerCell no underlying TimeLabel object : nothing to do in generally. */ @@ -281,16 +289,21 @@ int MEDCouplingFieldDiscretization::getGaussLocalizationIdOfOneType(INTERP_KERNE throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !"); } +std::set MEDCouplingFieldDiscretization::getGaussLocalizationIdsOfOneType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception) +{ + throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !"); +} + void MEDCouplingFieldDiscretization::getCellIdsHavingGaussLocalization(int locId, std::vector& cellIds) const throw(INTERP_KERNEL::Exception) { throw INTERP_KERNEL::Exception("Invalid method for the corresponding field discretization : available only for GaussPoint discretization !"); } -void MEDCouplingFieldDiscretization::renumberEntitiesFromO2NArr(double eps, const int *old2NewPtr, DataArrayDouble *arr, const char *msg) +void MEDCouplingFieldDiscretization::RenumberEntitiesFromO2NArr(double eps, const int *old2NewPtr, int newNbOfEntity, DataArrayDouble *arr, const char *msg) { int oldNbOfElems=arr->getNumberOfTuples(); int nbOfComp=arr->getNumberOfComponents(); - int newNbOfTuples=(*std::max_element(old2NewPtr,old2NewPtr+oldNbOfElems))+1; + int newNbOfTuples=newNbOfEntity; DataArrayDouble *arrCpy=arr->deepCpy(); const double *ptSrc=arrCpy->getConstPointer(); arr->reAlloc(newNbOfTuples); @@ -324,7 +337,7 @@ void MEDCouplingFieldDiscretization::renumberEntitiesFromO2NArr(double eps, cons arrCpy->decrRef(); } -void MEDCouplingFieldDiscretization::renumberEntitiesFromN2OArr(const int *new2OldPtr, int new2OldSz, DataArrayDouble *arr, const char *msg) +void MEDCouplingFieldDiscretization::RenumberEntitiesFromN2OArr(const int *new2OldPtr, int new2OldSz, DataArrayDouble *arr, const char *msg) { int nbOfComp=arr->getNumberOfComponents(); DataArrayDouble *arrCpy=arr->deepCpy(); @@ -482,18 +495,18 @@ DataArrayDouble *MEDCouplingFieldDiscretizationP0::getValueOnMulti(const DataArr /*! * Nothing to do. It's not a bug. */ -void MEDCouplingFieldDiscretizationP0::renumberValuesOnNodes(double , const int *, DataArrayDouble *) const +void MEDCouplingFieldDiscretizationP0::renumberValuesOnNodes(double , const int *, int newNbOfNodes, DataArrayDouble *) const { } -void MEDCouplingFieldDiscretizationP0::renumberValuesOnCells(double epsOnVals, const MEDCouplingMesh *mesh, const int *old2New, DataArrayDouble *arr) const +void MEDCouplingFieldDiscretizationP0::renumberValuesOnCells(double epsOnVals, const MEDCouplingMesh *mesh, const int *old2New, int newSz, DataArrayDouble *arr) const { - renumberEntitiesFromO2NArr(epsOnVals,old2New,arr,"Cell"); + RenumberEntitiesFromO2NArr(epsOnVals,old2New,newSz,arr,"Cell"); } void MEDCouplingFieldDiscretizationP0::renumberValuesOnCellsR(const MEDCouplingMesh *mesh, const int *new2old, int newSz, DataArrayDouble *arr) const { - renumberEntitiesFromN2OArr(new2old,newSz,arr,"Cell"); + RenumberEntitiesFromN2OArr(new2old,newSz,arr,"Cell"); } /*! @@ -607,15 +620,15 @@ DataArrayInt *MEDCouplingFieldDiscretizationOnNodes::computeTupleIdsToSelectFrom return umesh2->computeFetchedNodeIds(); } -void MEDCouplingFieldDiscretizationOnNodes::renumberValuesOnNodes(double epsOnVals, const int *old2NewPtr, DataArrayDouble *arr) const +void MEDCouplingFieldDiscretizationOnNodes::renumberValuesOnNodes(double epsOnVals, const int *old2NewPtr, int newNbOfNodes, DataArrayDouble *arr) const { - renumberEntitiesFromO2NArr(epsOnVals,old2NewPtr,arr,"Node"); + RenumberEntitiesFromO2NArr(epsOnVals,old2NewPtr,newNbOfNodes,arr,"Node"); } /*! * Nothing to do it's not a bug. */ -void MEDCouplingFieldDiscretizationOnNodes::renumberValuesOnCells(double epsOnVals, const MEDCouplingMesh *mesh, const int *old2New, DataArrayDouble *arr) const +void MEDCouplingFieldDiscretizationOnNodes::renumberValuesOnCells(double epsOnVals, const MEDCouplingMesh *mesh, const int *old2New, int newSz, DataArrayDouble *arr) const { } @@ -748,11 +761,16 @@ MEDCouplingFieldDiscretizationPerCell::~MEDCouplingFieldDiscretizationPerCell() _discr_per_cell->decrRef(); } -MEDCouplingFieldDiscretizationPerCell::MEDCouplingFieldDiscretizationPerCell(const MEDCouplingFieldDiscretizationPerCell& other):_discr_per_cell(0) +MEDCouplingFieldDiscretizationPerCell::MEDCouplingFieldDiscretizationPerCell(const MEDCouplingFieldDiscretizationPerCell& other, const int *startCellIds, const int *endCellIds):_discr_per_cell(0) { DataArrayInt *arr=other._discr_per_cell; if(arr) - _discr_per_cell=arr->deepCpy(); + { + if(startCellIds==0 && endCellIds==0) + _discr_per_cell=arr->deepCpy(); + else + _discr_per_cell=arr->selectByTupleIdSafe(startCellIds,endCellIds); + } } void MEDCouplingFieldDiscretizationPerCell::updateTime() const @@ -849,7 +867,7 @@ MEDCouplingFieldDiscretizationGauss::MEDCouplingFieldDiscretizationGauss() { } -MEDCouplingFieldDiscretizationGauss::MEDCouplingFieldDiscretizationGauss(const MEDCouplingFieldDiscretizationGauss& other):MEDCouplingFieldDiscretizationPerCell(other),_loc(other._loc) +MEDCouplingFieldDiscretizationGauss::MEDCouplingFieldDiscretizationGauss(const MEDCouplingFieldDiscretizationGauss& other, const int *startCellIds, const int *endCellIds):MEDCouplingFieldDiscretizationPerCell(other,startCellIds,endCellIds),_loc(other._loc) { } @@ -905,6 +923,11 @@ MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretizationGauss::clone() con return new MEDCouplingFieldDiscretizationGauss(*this); } +MEDCouplingFieldDiscretization *MEDCouplingFieldDiscretizationGauss::clonePart(const int *startCellIds, const int *endCellIds) const +{ + return new MEDCouplingFieldDiscretizationGauss(*this,startCellIds,endCellIds); +} + std::string MEDCouplingFieldDiscretizationGauss::getStringRepr() const { std::ostringstream oss; oss << REPR << "." << std::endl; @@ -951,13 +974,25 @@ int MEDCouplingFieldDiscretizationGauss::getNumberOfMeshPlaces(const MEDCoupling DataArrayInt *MEDCouplingFieldDiscretizationGauss::getOffsetArr(const MEDCouplingMesh *mesh) const { int nbOfTuples=mesh->getNumberOfCells(); - DataArrayInt *ret=DataArrayInt::New(); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); ret->alloc(nbOfTuples+1,1); int *retPtr=ret->getPointer(); const int *start=_discr_per_cell->getConstPointer(); + if(_discr_per_cell->getNumberOfTuples()!=nbOfTuples) + throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::getOffsetArr : mismatch between the mesh and the discretization ids array length !"); + int maxPossible=(int)_loc.size(); retPtr[0]=0; for(int i=0;i=0 && *startincrRef(); return ret; } @@ -999,7 +1034,7 @@ DataArrayDouble *MEDCouplingFieldDiscretizationGauss::getLocalizationOfDiscValue DataArrayDouble *ret=DataArrayDouble::New(); int spaceDim=mesh->getSpaceDimension(); ret->alloc(nbOfTuples,spaceDim); - std::vector< std::vector > locIds; + std::vector< int > locIds; std::vector parts=splitIntoSingleGaussDicrPerCellType(locIds); std::vector< MEDCouplingAutoRefCountObjectPtr > parts2(parts.size()); std::copy(parts.begin(),parts.end(),parts2.begin()); @@ -1013,21 +1048,17 @@ DataArrayDouble *MEDCouplingFieldDiscretizationGauss::getLocalizationOfDiscValue for(std::size_t i=0;i::const_iterator it=locIds[i].begin();it!=locIds[i].end();it++) - { - const MEDCouplingGaussLocalization& cli=_loc[*it];//curLocInfo - INTERP_KERNEL::NormalizedCellType typ=cli.getType(); - const std::vector& wg=cli.getWeights(); - calculator.addGaussInfo(typ,INTERP_KERNEL::CellModel::GetCellModel(typ).getDimension(), + // + const MEDCouplingGaussLocalization& cli=_loc[locIds[i]];//curLocInfo + INTERP_KERNEL::NormalizedCellType typ=cli.getType(); + const std::vector& wg=cli.getWeights(); + calculator.addGaussInfo(typ,INTERP_KERNEL::CellModel::GetCellModel(typ).getDimension(), &cli.getGaussCoords()[0],(int)wg.size(),&cli.getRefCoords()[0], INTERP_KERNEL::CellModel::GetCellModel(typ).getNumberOfNodes()); - } + // int nbt=parts2[i]->getNumberOfTuples(); for(const int *w=parts2[i]->getConstPointer();w!=parts2[i]->getConstPointer()+nbt;w++) - { - const MEDCouplingGaussLocalization& cli=_loc[*w]; - calculator.calculateCoords(cli.getType(),coords,spaceDim,conn+connI[*w]+1,valsToFill+spaceDim*(ptrOffsets[*w])); - } + calculator.calculateCoords(cli.getType(),coords,spaceDim,conn+connI[*w]+1,valsToFill+spaceDim*(ptrOffsets[*w])); } ret->copyStringInfoFrom(*umesh->getCoords()); return ret; @@ -1196,7 +1227,7 @@ DataArrayInt *MEDCouplingFieldDiscretizationGauss::computeTupleIdsToSelectFromCe int *retPtr=nbOfNodesPerCell->getPointer(); const int *pt=_discr_per_cell->getConstPointer(); int nbMaxOfLocId=(int)_loc.size(); - for(int i=0;i=0 && *pt ret=getGaussLocalizationIdsOfOneType(type); + if(ret.empty()) + throw INTERP_KERNEL::Exception("No gauss discretization found for the specified type !"); + if(ret.size()>1) + throw INTERP_KERNEL::Exception("Several gauss discretizations have been found for the specified type !"); + return *ret.begin(); +} + +std::set MEDCouplingFieldDiscretizationGauss::getGaussLocalizationIdsOfOneType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception) { if(!_discr_per_cell) throw INTERP_KERNEL::Exception("No Gauss localization still set !"); @@ -1311,11 +1352,7 @@ int MEDCouplingFieldDiscretizationGauss::getGaussLocalizationIdOfOneType(INTERP_ for(std::vector::const_iterator iter=_loc.begin();iter!=_loc.end();iter++,id++) if((*iter).getType()==type) ret.insert(id); - if(ret.empty()) - throw INTERP_KERNEL::Exception("No gauss discretization found for the specified type !"); - if(ret.size()>1) - throw INTERP_KERNEL::Exception("Several gauss discretizations have been found for the specified type !"); - return *ret.begin(); + return ret; } void MEDCouplingFieldDiscretizationGauss::getCellIdsHavingGaussLocalization(int locId, std::vector& cellIds) const throw(INTERP_KERNEL::Exception) @@ -1383,8 +1420,8 @@ void MEDCouplingFieldDiscretizationGauss::zipGaussLocalizations() { const int *start=_discr_per_cell->getConstPointer(); int nbOfTuples=_discr_per_cell->getNumberOfTuples(); - int *tmp=new int[_loc.size()]; - std::fill(tmp,tmp+_loc.size(),-2); + INTERP_KERNEL::AutoPtr tmp=new int[_loc.size()]; + std::fill((int *)tmp,(int *)tmp+_loc.size(),-2); for(const int *w=start;w!=start+nbOfTuples;w++) if(*w>=0) tmp[*w]=1; @@ -1393,19 +1430,16 @@ void MEDCouplingFieldDiscretizationGauss::zipGaussLocalizations() if(tmp[i]!=-2) tmp[i]=fid++; if(fid==(int)_loc.size()) - {//no zip needed - delete [] tmp; - return; - } + return; // zip needed int *start2=_discr_per_cell->getPointer(); for(int *w2=start2;w2!=start2+nbOfTuples;w2++) - *w2=tmp[*w2]; + if(*w2>=0) + *w2=tmp[*w2]; std::vector tmpLoc; for(int i=0;i<(int)_loc.size();i++) if(tmp[i]!=-2) tmpLoc.push_back(_loc[tmp[i]]); - delete [] tmp; _loc=tmpLoc; } @@ -1419,56 +1453,11 @@ void MEDCouplingFieldDiscretizationGauss::zipGaussLocalizations() * * If no descretization is set in 'this' and exception will be thrown. */ -std::vector MEDCouplingFieldDiscretizationGauss::splitIntoSingleGaussDicrPerCellType(std::vector< std::vector >& locIds) const throw(INTERP_KERNEL::Exception) +std::vector MEDCouplingFieldDiscretizationGauss::splitIntoSingleGaussDicrPerCellType(std::vector& locIds) const throw(INTERP_KERNEL::Exception) { if(!_discr_per_cell) throw INTERP_KERNEL::Exception("MEDCouplingFieldDiscretizationGauss::splitIntoSingleGaussDicrPerCellType : no descretization set !"); - locIds.clear(); - std::vector ret; - const int *discrPerCell=_discr_per_cell->getConstPointer(); - MEDCouplingAutoRefCountObjectPtr ret2=_discr_per_cell->getIdsNotEqual(-1); - int nbOfTuplesSet=ret2->getNumberOfTuples(); - std::list idsRemaining(ret2->getConstPointer(),ret2->getConstPointer()+nbOfTuplesSet); - std::list::iterator it=idsRemaining.begin(); - while(it!=idsRemaining.end()) - { - std::vector ids; - std::set curLocIds; - std::set curCellTypes; - while(it!=idsRemaining.end()) - { - int curDiscrId=discrPerCell[*it]; - INTERP_KERNEL::NormalizedCellType typ=_loc[curDiscrId].getType(); - if(curCellTypes.find(typ)!=curCellTypes.end()) - { - if(curLocIds.find(curDiscrId)!=curLocIds.end()) - { - curLocIds.insert(curDiscrId); - curCellTypes.insert(typ); - ids.push_back(*it); - it=idsRemaining.erase(it); - } - else - it++; - } - else - { - curLocIds.insert(curDiscrId); - curCellTypes.insert(typ); - ids.push_back(*it); - it=idsRemaining.erase(it); - } - } - it=idsRemaining.begin(); - ret.resize(ret.size()+1); - DataArrayInt *part=DataArrayInt::New(); - part->alloc((int)ids.size(),1); - std::copy(ids.begin(),ids.end(),part->getPointer()); - ret.back()=part; - locIds.resize(locIds.size()+1); - locIds.back().insert(locIds.back().end(),curLocIds.begin(),curLocIds.end()); - } - return ret; + return _discr_per_cell->partitionByDifferentValues(locIds); } MEDCouplingFieldDiscretizationGaussNE::MEDCouplingFieldDiscretizationGaussNE() @@ -1661,11 +1650,11 @@ DataArrayInt *MEDCouplingFieldDiscretizationGaussNE::computeTupleIdsToSelectFrom /*! * No implementation needed ! */ -void MEDCouplingFieldDiscretizationGaussNE::renumberValuesOnNodes(double , const int *, DataArrayDouble *) const +void MEDCouplingFieldDiscretizationGaussNE::renumberValuesOnNodes(double , const int *, int newNbOfNodes, DataArrayDouble *) const { } -void MEDCouplingFieldDiscretizationGaussNE::renumberValuesOnCells(double epsOnVals, const MEDCouplingMesh *mesh, const int *old2New, DataArrayDouble *arr) const +void MEDCouplingFieldDiscretizationGaussNE::renumberValuesOnCells(double epsOnVals, const MEDCouplingMesh *mesh, const int *old2New, int newSz, DataArrayDouble *arr) const { throw INTERP_KERNEL::Exception("Not implemented yet !"); } @@ -1774,7 +1763,7 @@ DataArrayDouble *MEDCouplingFieldDiscretizationKriging::computeVectorOfCoefficie { MEDCouplingAutoRefCountObjectPtr coords=getLocalizationOfDiscValues(mesh); int nbOfPts=coords->getNumberOfTuples(); - int dimension=coords->getNumberOfComponents(); + //int dimension=coords->getNumberOfComponents(); MEDCouplingAutoRefCountObjectPtr matrix=coords->buildEuclidianDistanceDenseMatrix(); operateOnDenseMatrix(mesh->getSpaceDimension(),nbOfPts*nbOfPts,matrix->getPointer()); // Drift diff --git a/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx b/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx index df43d9527..6efe4aae1 100644 --- a/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx +++ b/src/MEDCoupling/MEDCouplingFieldDiscretization.hxx @@ -29,6 +29,7 @@ #include "MEDCouplingGaussLocalization.hxx" #include "MEDCouplingAutoRefCountObjectPtr.hxx" +#include #include namespace ParaMEDMEM @@ -51,6 +52,7 @@ namespace ParaMEDMEM virtual bool isEqualIfNotWhy(const MEDCouplingFieldDiscretization *other, double eps, std::string& reason) const = 0; virtual bool isEqualWithoutConsideringStr(const MEDCouplingFieldDiscretization *other, double eps) const; virtual MEDCouplingFieldDiscretization *clone() const = 0; + virtual MEDCouplingFieldDiscretization *clonePart(const int *startCellIds, const int *endCellIds) const; virtual std::string getStringRepr() const = 0; virtual const char *getRepr() const = 0; virtual int getNumberOfTuples(const MEDCouplingMesh *mesh) const = 0; @@ -74,8 +76,8 @@ namespace ParaMEDMEM virtual DataArrayDouble *getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, int nbOfPoints) const = 0; virtual DataArrayInt *computeTupleIdsToSelectFromCellIds(const MEDCouplingMesh *mesh, const int *startCellIds, const int *endCellIds) const = 0; virtual MEDCouplingMesh *buildSubMeshData(const MEDCouplingMesh *mesh, const int *start, const int *end, DataArrayInt *&di) const = 0; - virtual void renumberValuesOnNodes(double epsOnVals, const int *old2New, DataArrayDouble *arr) const = 0; - virtual void renumberValuesOnCells(double epsOnVals, const MEDCouplingMesh *mesh, const int *old2New, DataArrayDouble *arr) const = 0; + virtual void renumberValuesOnNodes(double epsOnVals, const int *old2New, int newNbOfNodes, DataArrayDouble *arr) const = 0; + virtual void renumberValuesOnCells(double epsOnVals, const MEDCouplingMesh *mesh, const int *old2New, int newSz, DataArrayDouble *arr) const = 0; virtual void renumberValuesOnCellsR(const MEDCouplingMesh *mesh, const int *new2old, int newSz, DataArrayDouble *arr) const = 0; virtual void getSerializationIntArray(DataArrayInt *& arr) const; virtual void getTinySerializationIntInformation(std::vector& tinyInfo) const; @@ -91,13 +93,14 @@ namespace ParaMEDMEM virtual int getNbOfGaussLocalization() const throw(INTERP_KERNEL::Exception); virtual int getGaussLocalizationIdOfOneCell(int cellId) const throw(INTERP_KERNEL::Exception); virtual int getGaussLocalizationIdOfOneType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception); + virtual std::set getGaussLocalizationIdsOfOneType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception); virtual void getCellIdsHavingGaussLocalization(int locId, std::vector& cellIds) const throw(INTERP_KERNEL::Exception); virtual const MEDCouplingGaussLocalization& getGaussLocalization(int locId) const throw(INTERP_KERNEL::Exception); virtual ~MEDCouplingFieldDiscretization(); protected: MEDCouplingFieldDiscretization(); - static void renumberEntitiesFromO2NArr(double epsOnVals, const int *old2NewPtr, DataArrayDouble *arr, const char *msg); - static void renumberEntitiesFromN2OArr(const int *new2OldPtr, int new2OldSz, DataArrayDouble *arr, const char *msg); + static void RenumberEntitiesFromO2NArr(double epsOnVals, const int *old2NewPtr, int newNbOfEntity, DataArrayDouble *arr, const char *msg); + static void RenumberEntitiesFromN2OArr(const int *new2OldPtr, int new2OldSz, DataArrayDouble *arr, const char *msg); protected: double _precision; static const double DFLT_PRECISION; @@ -125,8 +128,8 @@ namespace ParaMEDMEM void getValueOn(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, double *res) const; void getValueOnPos(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, int i, int j, int k, double *res) const; DataArrayDouble *getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, int nbOfPoints) const; - void renumberValuesOnNodes(double epsOnVals, const int *old2New, DataArrayDouble *arr) const; - void renumberValuesOnCells(double epsOnVals, const MEDCouplingMesh *mesh, const int *old2New, DataArrayDouble *arr) const; + void renumberValuesOnNodes(double epsOnVals, const int *old2New, int newNbOfNodes, DataArrayDouble *arr) const; + void renumberValuesOnCells(double epsOnVals, const MEDCouplingMesh *mesh, const int *old2New, int newSz, DataArrayDouble *arr) const; void renumberValuesOnCellsR(const MEDCouplingMesh *mesh, const int *new2old, int newSz, DataArrayDouble *arr) const; MEDCouplingMesh *buildSubMeshData(const MEDCouplingMesh *mesh, const int *start, const int *end, DataArrayInt *&di) const; DataArrayInt *computeTupleIdsToSelectFromCellIds(const MEDCouplingMesh *mesh, const int *startCellIds, const int *endCellIds) const; @@ -149,8 +152,8 @@ namespace ParaMEDMEM void checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArrayDouble *da) const throw(INTERP_KERNEL::Exception); MEDCouplingMesh *buildSubMeshData(const MEDCouplingMesh *mesh, const int *start, const int *end, DataArrayInt *&di) const; DataArrayInt *computeTupleIdsToSelectFromCellIds(const MEDCouplingMesh *mesh, const int *startCellIds, const int *endCellIds) const; - void renumberValuesOnNodes(double epsOnVals, const int *old2New, DataArrayDouble *arr) const; - void renumberValuesOnCells(double epsOnVals, const MEDCouplingMesh *mesh, const int *old2New, DataArrayDouble *arr) const; + void renumberValuesOnNodes(double epsOnVals, const int *old2New, int newNbOfNodes, DataArrayDouble *arr) const; + void renumberValuesOnCells(double epsOnVals, const MEDCouplingMesh *mesh, const int *old2New, int newSz, DataArrayDouble *arr) const; void renumberValuesOnCellsR(const MEDCouplingMesh *mesh, const int *new2old, int newSz, DataArrayDouble *arr) const; public: void getValueOnPos(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, int i, int j, int k, double *res) const; @@ -185,7 +188,7 @@ namespace ParaMEDMEM const DataArrayInt *getArrayOfDiscIds() const; protected: MEDCouplingFieldDiscretizationPerCell(); - MEDCouplingFieldDiscretizationPerCell(const MEDCouplingFieldDiscretizationPerCell& other); + MEDCouplingFieldDiscretizationPerCell(const MEDCouplingFieldDiscretizationPerCell& other, const int *startCellIds, const int *endCellIds); ~MEDCouplingFieldDiscretizationPerCell(); void updateTime() const; void checkCoherencyBetween(const MEDCouplingMesh *mesh, const DataArrayDouble *da) const throw(INTERP_KERNEL::Exception); @@ -208,6 +211,7 @@ namespace ParaMEDMEM bool isEqualIfNotWhy(const MEDCouplingFieldDiscretization *other, double eps, std::string& reason) const; bool isEqualWithoutConsideringStr(const MEDCouplingFieldDiscretization *other, double eps) const; MEDCouplingFieldDiscretization *clone() const; + MEDCouplingFieldDiscretization *clonePart(const int *startCellIds, const int *endCellIds) const; std::string getStringRepr() const; const char *getRepr() const; int getNumberOfTuples(const MEDCouplingMesh *mesh) const; @@ -232,8 +236,8 @@ namespace ParaMEDMEM DataArrayDouble *getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, int nbOfPoints) const; MEDCouplingMesh *buildSubMeshData(const MEDCouplingMesh *mesh, const int *start, const int *end, DataArrayInt *&di) const; DataArrayInt *computeTupleIdsToSelectFromCellIds(const MEDCouplingMesh *mesh, const int *startCellIds, const int *endCellIds) const; - void renumberValuesOnNodes(double epsOnVals, const int *old2New, DataArrayDouble *arr) const; - void renumberValuesOnCells(double epsOnVals, const MEDCouplingMesh *mesh, const int *old2New, DataArrayDouble *arr) const; + void renumberValuesOnNodes(double epsOnVals, const int *old2New, int newNbOfNodes, DataArrayDouble *arr) const; + void renumberValuesOnCells(double epsOnVals, const MEDCouplingMesh *mesh, const int *old2New, int newSz, DataArrayDouble *arr) const; void renumberValuesOnCellsR(const MEDCouplingMesh *mesh, const int *new2old, int newSz, DataArrayDouble *arr) const; void setGaussLocalizationOnType(const MEDCouplingMesh *m, INTERP_KERNEL::NormalizedCellType type, const std::vector& refCoo, const std::vector& gsCoo, const std::vector& wg) throw(INTERP_KERNEL::Exception); @@ -244,12 +248,13 @@ namespace ParaMEDMEM int getNbOfGaussLocalization() const throw(INTERP_KERNEL::Exception); int getGaussLocalizationIdOfOneCell(int cellId) const throw(INTERP_KERNEL::Exception); int getGaussLocalizationIdOfOneType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception); + std::set getGaussLocalizationIdsOfOneType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception); void getCellIdsHavingGaussLocalization(int locId, std::vector& cellIds) const throw(INTERP_KERNEL::Exception); const MEDCouplingGaussLocalization& getGaussLocalization(int locId) const throw(INTERP_KERNEL::Exception); - std::vector splitIntoSingleGaussDicrPerCellType(std::vector< std::vector >& locIds) const throw(INTERP_KERNEL::Exception); + std::vector splitIntoSingleGaussDicrPerCellType(std::vector< int >& locIds) const throw(INTERP_KERNEL::Exception); DataArrayInt *buildNbOfGaussPointPerCellField() const throw(INTERP_KERNEL::Exception); protected: - MEDCouplingFieldDiscretizationGauss(const MEDCouplingFieldDiscretizationGauss& other); + MEDCouplingFieldDiscretizationGauss(const MEDCouplingFieldDiscretizationGauss& other, const int *startCellIds=0, const int *endCellIds=0); void zipGaussLocalizations(); int getOffsetOfCell(int cellId) const throw(INTERP_KERNEL::Exception); void checkLocalizationId(int locId) const throw(INTERP_KERNEL::Exception); @@ -289,8 +294,8 @@ namespace ParaMEDMEM DataArrayDouble *getValueOnMulti(const DataArrayDouble *arr, const MEDCouplingMesh *mesh, const double *loc, int nbOfPoints) const; MEDCouplingMesh *buildSubMeshData(const MEDCouplingMesh *mesh, const int *start, const int *end, DataArrayInt *&di) const; DataArrayInt *computeTupleIdsToSelectFromCellIds(const MEDCouplingMesh *mesh, const int *startCellIds, const int *endCellIds) const; - void renumberValuesOnNodes(double epsOnVals, const int *old2New, DataArrayDouble *arr) const; - void renumberValuesOnCells(double epsOnVals, const MEDCouplingMesh *mesh, const int *old2New, DataArrayDouble *arr) const; + void renumberValuesOnNodes(double epsOnVals, const int *old2New, int newNbOfNodes, DataArrayDouble *arr) const; + void renumberValuesOnCells(double epsOnVals, const MEDCouplingMesh *mesh, const int *old2New, int newSz, DataArrayDouble *arr) const; void renumberValuesOnCellsR(const MEDCouplingMesh *mesh, const int *new2old, int newSz, DataArrayDouble *arr) const; protected: MEDCouplingFieldDiscretizationGaussNE(const MEDCouplingFieldDiscretizationGaussNE& other); diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.cxx b/src/MEDCoupling/MEDCouplingFieldDouble.cxx index 170cf2ecb..36c10e825 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.cxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.cxx @@ -345,8 +345,9 @@ void MEDCouplingFieldDouble::renumberNodes(const int *old2NewBg) throw(INTERP_KE throw INTERP_KERNEL::Exception("Invalid mesh to apply renumberNodes on it !"); int nbOfNodes=meshC->getNumberOfNodes(); MEDCouplingAutoRefCountObjectPtr meshC2((MEDCouplingPointSet *)meshC->deepCpy()); - renumberNodesWithoutMesh(old2NewBg); - meshC2->renumberNodes(old2NewBg,*std::max_element(old2NewBg,old2NewBg+nbOfNodes)+1); + int newNbOfNodes=*std::max_element(old2NewBg,old2NewBg+nbOfNodes)+1; + renumberNodesWithoutMesh(old2NewBg,newNbOfNodes); + meshC2->renumberNodes(old2NewBg,newNbOfNodes); setMesh(meshC2); } @@ -355,13 +356,13 @@ void MEDCouplingFieldDouble::renumberNodes(const int *old2NewBg) throw(INTERP_KE * This method performs half job of MEDCouplingFieldDouble::renumberNodes. That is to say no permutation of cells is done on underlying mesh. * That is to say, the field content is changed by this method. */ -void MEDCouplingFieldDouble::renumberNodesWithoutMesh(const int *old2NewBg, double eps) throw(INTERP_KERNEL::Exception) +void MEDCouplingFieldDouble::renumberNodesWithoutMesh(const int *old2NewBg, int newNbOfNodes, double eps) throw(INTERP_KERNEL::Exception) { std::vector arrays; _time_discr->getArrays(arrays); for(std::vector::const_iterator iter=arrays.begin();iter!=arrays.end();iter++) if(*iter) - _type->renumberValuesOnNodes(eps,old2NewBg,*iter); + _type->renumberValuesOnNodes(eps,old2NewBg,newNbOfNodes,*iter); } /*! @@ -435,11 +436,13 @@ MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildSubPart(const DataArrayInt MEDCouplingFieldDouble *MEDCouplingFieldDouble::buildSubPart(const int *partBg, const int *partEnd) const throw(INTERP_KERNEL::Exception) { DataArrayInt *arrSelect; - MEDCouplingMesh *m=_type->buildSubMeshData(_mesh,partBg,partEnd,arrSelect); + MEDCouplingAutoRefCountObjectPtr m=_type->buildSubMeshData(_mesh,partBg,partEnd,arrSelect); MEDCouplingAutoRefCountObjectPtr arrSelect2(arrSelect); MEDCouplingFieldDouble *ret=clone(false);//quick shallow copy. + const MEDCouplingFieldDiscretization *disc=getDiscretization(); + if(disc) + ret->setDiscretization(disc->clonePart(partBg,partEnd)); ret->setMesh(m); - m->decrRef(); std::vector arrays; _time_discr->getArrays(arrays); std::vector arrs; @@ -1196,18 +1199,13 @@ void MEDCouplingFieldDouble::changeUnderlyingMesh(const MEDCouplingMesh *other, { if(_mesh==0 || other==0) throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::changeUnderlyingMesh : is expected to operate on not null meshes !"); - DataArrayInt *cellCor,*nodeCor; + DataArrayInt *cellCor=0,*nodeCor=0; other->checkGeoEquivalWith(_mesh,levOfCheck,prec,cellCor,nodeCor); + MEDCouplingAutoRefCountObjectPtr cellCor2(cellCor),nodeCor2(nodeCor); if(cellCor) - { - renumberCellsWithoutMesh(cellCor->getConstPointer(),false); - cellCor->decrRef(); - } + renumberCellsWithoutMesh(cellCor->getConstPointer(),false); if(nodeCor) - { - renumberNodesWithoutMesh(nodeCor->getConstPointer()); - nodeCor->decrRef(); - } + renumberNodesWithoutMesh(nodeCor->getConstPointer(),_mesh->getNumberOfNodes()); setMesh(const_cast(other)); } @@ -1247,7 +1245,7 @@ bool MEDCouplingFieldDouble::mergeNodes(double eps, double epsOnVals) throw(INTE _time_discr->getArrays(arrays); for(std::vector::const_iterator iter=arrays.begin();iter!=arrays.end();iter++) if(*iter) - _type->renumberValuesOnNodes(epsOnVals,arr->getConstPointer(),*iter); + _type->renumberValuesOnNodes(epsOnVals,arr->getConstPointer(),meshC2->getNumberOfNodes(),*iter); setMesh(meshC2); return true; } @@ -1272,7 +1270,7 @@ bool MEDCouplingFieldDouble::mergeNodes2(double eps, double epsOnVals) throw(INT _time_discr->getArrays(arrays); for(std::vector::const_iterator iter=arrays.begin();iter!=arrays.end();iter++) if(*iter) - _type->renumberValuesOnNodes(epsOnVals,arr->getConstPointer(),*iter); + _type->renumberValuesOnNodes(epsOnVals,arr->getConstPointer(),meshC2->getNumberOfNodes(),*iter); setMesh(meshC2); return true; } @@ -1296,7 +1294,7 @@ bool MEDCouplingFieldDouble::zipCoords(double epsOnVals) throw(INTERP_KERNEL::Ex _time_discr->getArrays(arrays); for(std::vector::const_iterator iter=arrays.begin();iter!=arrays.end();iter++) if(*iter) - _type->renumberValuesOnNodes(epsOnVals,arr->getConstPointer(),*iter); + _type->renumberValuesOnNodes(epsOnVals,arr->getConstPointer(),meshC2->getNumberOfNodes(),*iter); setMesh(meshC2); return true; } @@ -1322,7 +1320,7 @@ bool MEDCouplingFieldDouble::zipConnectivity(int compType, double epsOnVals) thr _time_discr->getArrays(arrays); for(std::vector::const_iterator iter=arrays.begin();iter!=arrays.end();iter++) if(*iter) - _type->renumberValuesOnCells(epsOnVals,meshC,arr->getConstPointer(),*iter); + _type->renumberValuesOnCells(epsOnVals,meshC,arr->getConstPointer(),meshC2->getNumberOfCells(),*iter); setMesh(meshC2); return true; } diff --git a/src/MEDCoupling/MEDCouplingFieldDouble.hxx b/src/MEDCoupling/MEDCouplingFieldDouble.hxx index 3eac19dce..45a553b6b 100644 --- a/src/MEDCoupling/MEDCouplingFieldDouble.hxx +++ b/src/MEDCoupling/MEDCouplingFieldDouble.hxx @@ -51,7 +51,7 @@ namespace ParaMEDMEM void renumberCells(const int *old2NewBg, bool check=true) throw(INTERP_KERNEL::Exception); void renumberCellsWithoutMesh(const int *old2NewBg, bool check=true) throw(INTERP_KERNEL::Exception); void renumberNodes(const int *old2NewBg) throw(INTERP_KERNEL::Exception); - void renumberNodesWithoutMesh(const int *old2NewBg, double eps=1e-15) throw(INTERP_KERNEL::Exception); + void renumberNodesWithoutMesh(const int *old2NewBg, int newNbOfNodes, double eps=1e-15) throw(INTERP_KERNEL::Exception); DataArrayInt *getIdsInRange(double vmin, double vmax) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *buildSubPart(const DataArrayInt *part) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *buildSubPart(const int *partBg, const int *partEnd) const throw(INTERP_KERNEL::Exception); diff --git a/src/MEDCoupling/MEDCouplingMemArray.cxx b/src/MEDCoupling/MEDCouplingMemArray.cxx index a112e3eda..9081b8ecb 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.cxx +++ b/src/MEDCoupling/MEDCouplingMemArray.cxx @@ -28,6 +28,7 @@ #include #include #include +#include #include typedef double (*MYFUNCPTR)(double); @@ -68,10 +69,9 @@ void DataArrayDouble::findCommonTuplesAlg(const double *bbox, int nbNodes, int l } template -void DataArrayDouble::findTupleIdsNearTuplesAlg(const BBTree& myTree, const double *pos, int nbOfTuples, double eps, - std::vector& c, std::vector& cI) const +void DataArrayDouble::FindTupleIdsNearTuplesAlg(const BBTree& myTree, const double *pos, int nbOfTuples, double eps, + std::vector& c, std::vector& cI) { - const double *coordsPtr=getConstPointer(); for(int i=0;i intersectingElems; @@ -171,6 +171,13 @@ void DataArray::reprWithoutNameStream(std::ostream& stream) const stream << "\n"; } +std::string DataArray::cppRepr(const char *varName) const throw(INTERP_KERNEL::Exception) +{ + std::ostringstream ret; + reprCppStream(varName,ret); + return ret.str(); +} + void DataArray::setInfoOnComponents(const std::vector& info) throw(INTERP_KERNEL::Exception) { if(getNumberOfComponents()!=(int)info.size()) @@ -720,6 +727,24 @@ void DataArrayDouble::reprZipWithoutNameStream(std::ostream& stream) const _mem.reprZip(getNumberOfComponents(),stream); } +void DataArrayDouble::reprCppStream(const char *varName, std::ostream& stream) const +{ + int nbTuples=getNumberOfTuples(),nbComp=getNumberOfComponents(); + const double *data=getConstPointer(); + stream.precision(17); + stream << "DataArrayDouble *" << varName << "=DataArrayDouble::New();" << std::endl; + if(nbTuples*nbComp>=1) + { + stream << "const double " << varName << "Data[" << nbTuples*nbComp << "]={"; + std::copy(data,data+nbTuples*nbComp-1,std::ostream_iterator(stream,",")); + stream << data[nbTuples*nbComp-1] << "};" << std::endl; + stream << varName << "->useArray(" << varName << "Data,false,CPP_DEALLOC," << nbTuples << "," << nbComp << ");" << std::endl; + } + else + stream << varName << "->alloc(" << nbTuples << "," << nbComp << ");" << std::endl; + stream << varName << "->setName(\"" << getName() << "\");" << std::endl; +} + bool DataArrayDouble::isEqualIfNotWhy(const DataArrayDouble& other, double prec, std::string& reason) const { if(!areInfoEqualsIfNotWhy(other,reason)) @@ -1739,19 +1764,19 @@ void DataArrayDouble::computeTupleIdsNearTuples(const DataArrayDouble *other, do case 3: { BBTree<3,int> myTree(bbox->getConstPointer(),0,0,getNumberOfTuples(),eps/10); - findTupleIdsNearTuplesAlg<3>(myTree,other->getConstPointer(),nbOfTuplesOther,eps,c,cI); + FindTupleIdsNearTuplesAlg<3>(myTree,other->getConstPointer(),nbOfTuplesOther,eps,c,cI); break; } case 2: { BBTree<2,int> myTree(bbox->getConstPointer(),0,0,getNumberOfTuples(),eps/10); - findTupleIdsNearTuplesAlg<2>(myTree,other->getConstPointer(),nbOfTuplesOther,eps,c,cI); + FindTupleIdsNearTuplesAlg<2>(myTree,other->getConstPointer(),nbOfTuplesOther,eps,c,cI); break; } case 1: { BBTree<1,int> myTree(bbox->getConstPointer(),0,0,getNumberOfTuples(),eps/10); - findTupleIdsNearTuplesAlg<1>(myTree,other->getConstPointer(),nbOfTuplesOther,eps,c,cI); + FindTupleIdsNearTuplesAlg<1>(myTree,other->getConstPointer(),nbOfTuplesOther,eps,c,cI); break; } default: @@ -3553,6 +3578,23 @@ void DataArrayInt::reprZipWithoutNameStream(std::ostream& stream) const _mem.reprZip(getNumberOfComponents(),stream); } +void DataArrayInt::reprCppStream(const char *varName, std::ostream& stream) const +{ + int nbTuples=getNumberOfTuples(),nbComp=getNumberOfComponents(); + const int *data=getConstPointer(); + stream << "DataArrayInt *" << varName << "=DataArrayInt::New();" << std::endl; + if(nbTuples*nbComp>=1) + { + stream << "const int " << varName << "Data[" << nbTuples*nbComp << "]={"; + std::copy(data,data+nbTuples*nbComp-1,std::ostream_iterator(stream,",")); + stream << data[nbTuples*nbComp-1] << "};" << std::endl; + stream << varName << "->useArray(" << varName << "Data,false,CPP_DEALLOC," << nbTuples << "," << nbComp << ");" << std::endl; + } + else + stream << varName << "->alloc(" << nbTuples << "," << nbComp << ");" << std::endl; + stream << varName << "->setName(\"" << getName() << "\");" << std::endl; +} + /*! * This method expects a number of components equal to 1. * This method sweeps all the values (tuples) in 'this' (it should be allocated) and for each value v is replaced by @@ -3891,7 +3933,7 @@ DataArrayInt *DataArrayInt::renumberR(const int *new2Old) const } /*! - * Idem DataArrayDouble::renumber method except that the number of tuples is reduced. + * Idem DataArrayInt::renumber method except that the number of tuples is reduced. * That is to say that it is expected that newNbOfTuplegetNumberOfTuples(). * ['old2New','old2New'+getNumberOfTuples()) defines a range containing old to new array. For every negative value in ['old2NewBg','old2New'getNumberOfTuples()) the corresponding tuple is * omitted. @@ -5468,6 +5510,30 @@ DataArrayInt *DataArrayInt::buildIntersection(const DataArrayInt *other) const t return BuildIntersection(arrs); } +/*! + * This method can be applied on allocated with one component DataArrayInt instance. + * This method is typically relevant for sorted arrays. All consecutive duplicated items in \a this will appear only once in returned DataArrayInt instance. + * Example : if \a this contains [1,2,2,3,3,3,3,4,5,5,7,7,7,19] the returned array will contain [1,2,3,4,5,7,19] + * + * \return a newly allocated array that contain the result of the unique operation applied on \a this. + * \throw if \a this is not allocated or if \a this has not exactly one component. + */ +DataArrayInt *DataArrayInt::buildUnique() const throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + if(getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("DataArrayInt::buildUnique : only single component allowed !"); + int nbOfTuples=getNumberOfTuples(); + MEDCouplingAutoRefCountObjectPtr tmp=deepCpy(); + int *data=tmp->getPointer(); + int *last=std::unique(data,data+nbOfTuples); + MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); + ret->alloc(std::distance(data,last),1); + std::copy(data,last,ret->getPointer()); + ret->incrRef(); + return ret; +} + /*! * This method could be usefull for returned DataArrayInt marked as index. Some methods that generate such DataArrayInt instances: * - ParaMEDMEM::MEDCouplingUMesh::buildDescendingConnectivity @@ -5729,13 +5795,50 @@ DataArrayInt *DataArrayInt::duplicateEachTupleNTimes(int nbTimes) const throw(IN } /*! - * This method returns all different values found in 'this'. + * This method returns all different values found in \a this. This method throws if \a this has not been allocated. + * But the number of components can be different from one. */ std::set DataArrayInt::getDifferentValues() const throw(INTERP_KERNEL::Exception) { checkAllocated(); std::set ret; - ret.insert(getConstPointer(),getConstPointer()+getNbOfElems()); + ret.insert(begin(),end()); + return ret; +} + +/*! + * This method is a refinement of DataArrayInt::getDifferentValues because it returns not only different values in \a this but also, for each of + * them it tells which tuple id have this id. + * This method works only on arrays with one component (if it is not the case call DataArrayInt::rearrange(1) ). + * This method returns two arrays having same size. + * The instances of DataArrayInt in the returned vector have be specially allocated and computed by this method. Each of them should be dealt by the caller of this method. + * Example : if this is equal to [1,0,1,2,0,2,2,-3,2] -> differentIds=[-3,0,1,2] and returned array will be equal to [[7],[1,4],[0,2],[3,5,6,8]] + */ +std::vector DataArrayInt::partitionByDifferentValues(std::vector& differentIds) const throw(INTERP_KERNEL::Exception) +{ + checkAllocated(); + if(getNumberOfComponents()!=1) + throw INTERP_KERNEL::Exception("DataArrayInt::partitionByDifferentValues : this should have only one component !"); + int id=0; + std::map m,m2,m3; + for(const int *w=begin();w!=end();w++) + m[*w]++; + differentIds.resize(m.size()); + std::vector ret(m.size()); + std::vector retPtr(m.size()); + for(std::map::const_iterator it=m.begin();it!=m.end();it++,id++) + { + m2[(*it).first]=id; + ret[id]=DataArrayInt::New(); + ret[id]->alloc((*it).second,1); + retPtr[id]=ret[id]->getPointer(); + differentIds[id]=(*it).first; + } + id=0; + for(const int *w=begin();w!=end();w++,id++) + { + retPtr[m2[*w]][m3[*w]++]=id; + } return ret; } diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index 675a563ec..6b8b5853f 100644 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -98,6 +98,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT bool areInfoEqualsIfNotWhy(const DataArray& other, std::string& reason) const; MEDCOUPLING_EXPORT bool areInfoEquals(const DataArray& other) const; MEDCOUPLING_EXPORT void reprWithoutNameStream(std::ostream& stream) const; + MEDCOUPLING_EXPORT std::string cppRepr(const char *varName) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT std::string getName() const { return _name; } MEDCOUPLING_EXPORT const std::vector &getInfoOnComponents() const { return _info_on_compo; } MEDCOUPLING_EXPORT std::vector &getInfoOnComponents() { return _info_on_compo; } @@ -112,8 +113,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT int getNumberOfTuples() const { return _nb_of_tuples; } MEDCOUPLING_EXPORT int getNbOfElems() const { return ((int)_info_on_compo.size())*_nb_of_tuples; } MEDCOUPLING_EXPORT void checkNbOfTuples(int nbOfTuples, const char *msg) const throw(INTERP_KERNEL::Exception); - MEDCOUPLING_EXPORT -void checkNbOfComps(int nbOfCompo, const char *msg) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT void checkNbOfComps(int nbOfCompo, const char *msg) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void checkNbOfTuplesAndComp(const DataArray& other, const char *msg) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void checkNbOfTuplesAndComp(int nbOfTuples, int nbOfCompo, const char *msg) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void checkNbOfElems(int nbOfElems, const char *msg) const throw(INTERP_KERNEL::Exception); @@ -122,6 +122,7 @@ void checkNbOfComps(int nbOfCompo, const char *msg) const throw(INTERP_KERNEL::E MEDCOUPLING_EXPORT static int GetPosOfItemGivenBESRelativeNoThrow(int value, int begin, int end, int step) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT static std::string GetVarNameFromInfo(const std::string& info) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT static std::string GetUnitFromInfo(const std::string& info) throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT virtual void reprCppStream(const char *varName, std::ostream& stream) const = 0; protected: DataArray():_nb_of_tuples(-1) { } protected: @@ -170,6 +171,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void reprZipStream(std::ostream& stream) const; MEDCOUPLING_EXPORT void reprWithoutNameStream(std::ostream& stream) const; MEDCOUPLING_EXPORT void reprZipWithoutNameStream(std::ostream& stream) const; + MEDCOUPLING_EXPORT void reprCppStream(const char *varName, std::ostream& stream) const; MEDCOUPLING_EXPORT bool isEqual(const DataArrayDouble& other, double prec) const; MEDCOUPLING_EXPORT bool isEqualIfNotWhy(const DataArrayDouble& other, double prec, std::string& reason) const; MEDCOUPLING_EXPORT bool isEqualWithoutConsideringStr(const DataArrayDouble& other, double prec) const; @@ -292,8 +294,8 @@ namespace ParaMEDMEM template void findCommonTuplesAlg(const double *bbox, int nbNodes, int limitNodeId, double prec, std::vector& c, std::vector& cI) const; template - void findTupleIdsNearTuplesAlg(const BBTree& myTree, const double *pos, int nbOfTuples, double eps, - std::vector& c, std::vector& cI) const; + static void FindTupleIdsNearTuplesAlg(const BBTree& myTree, const double *pos, int nbOfTuples, double eps, + std::vector& c, std::vector& cI); private: DataArrayDouble() { } private: @@ -365,6 +367,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT void reprZipStream(std::ostream& stream) const; MEDCOUPLING_EXPORT void reprWithoutNameStream(std::ostream& stream) const; MEDCOUPLING_EXPORT void reprZipWithoutNameStream(std::ostream& stream) const; + MEDCOUPLING_EXPORT void reprCppStream(const char *varName, std::ostream& stream) const; MEDCOUPLING_EXPORT void transformWithIndArr(const int *indArrBg, const int *indArrEnd) throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *transformWithIndArrR(const int *indArrBg, const int *indArrEnd) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void splitByValueRange(const int *arrBg, const int *arrEnd, @@ -455,6 +458,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT DataArrayInt *buildSubstraction(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *buildUnion(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *buildIntersection(const DataArrayInt *other) const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT DataArrayInt *buildUnique() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *deltaShiftIndex() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void computeOffsets() throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void computeOffsets2() throw(INTERP_KERNEL::Exception); @@ -463,6 +467,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT DataArrayInt *findIdInRangeForEachTuple(const DataArrayInt *ranges) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT DataArrayInt *duplicateEachTupleNTimes(int nbTimes) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT std::set getDifferentValues() const throw(INTERP_KERNEL::Exception); + MEDCOUPLING_EXPORT std::vector partitionByDifferentValues(std::vector& differentIds) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT void useArray(const int *array, bool ownership, DeallocType type, int nbOfTuple, int nbOfCompo); MEDCOUPLING_EXPORT void useExternalArrayWithRWAccess(const int *array, int nbOfTuple, int nbOfCompo); MEDCOUPLING_EXPORT void writeOnPlace(int id, int element0, const int *others, int sizeOfOthers) { _mem.writeOnPlace(id,element0,others,sizeOfOthers); } diff --git a/src/MEDCoupling/MEDCouplingMesh.cxx b/src/MEDCoupling/MEDCouplingMesh.cxx index d226fd90d..e0a9c7883 100644 --- a/src/MEDCoupling/MEDCouplingMesh.cxx +++ b/src/MEDCoupling/MEDCouplingMesh.cxx @@ -392,6 +392,18 @@ int MEDCouplingMesh::GetDimensionOfGeometricType(INTERP_KERNEL::NormalizedCellTy return (int) cm.getDimension(); } +/*! + * \param [in] type the geometric type for which the representation is asked. + * \return the string representation corresponding to the input geometric type \a type. + * + * \throw if type is equal to \c INTERP_KERNEL::NORM_ERROR or to an unexisting geometric type. + */ +const char *MEDCouplingMesh::GetReprOfGeometricType(INTERP_KERNEL::NormalizedCellType type) throw(INTERP_KERNEL::Exception) +{ + const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(type); + return cm.getRepr(); +} + void MEDCouplingMesh::getCellsContainingPoint(const double *pos, double eps, std::vector& elts) const { int ret=getCellContainingPoint(pos,eps); diff --git a/src/MEDCoupling/MEDCouplingMesh.hxx b/src/MEDCoupling/MEDCouplingMesh.hxx index 988ab77e9..2febf8c6b 100644 --- a/src/MEDCoupling/MEDCouplingMesh.hxx +++ b/src/MEDCoupling/MEDCouplingMesh.hxx @@ -118,6 +118,7 @@ namespace ParaMEDMEM static MEDCouplingMesh *MergeMeshes(const MEDCouplingMesh *mesh1, const MEDCouplingMesh *mesh2) throw(INTERP_KERNEL::Exception); static MEDCouplingMesh *MergeMeshes(std::vector& meshes) throw(INTERP_KERNEL::Exception); static int GetDimensionOfGeometricType(INTERP_KERNEL::NormalizedCellType type) throw(INTERP_KERNEL::Exception); + static const char *GetReprOfGeometricType(INTERP_KERNEL::NormalizedCellType type) throw(INTERP_KERNEL::Exception); //serialisation-unserialization virtual void getTinySerializationInformation(std::vector& tinyInfoD, std::vector& tinyInfo, std::vector& littleStrings) const = 0; virtual void resizeForUnserialization(const std::vector& tinyInfo, DataArrayInt *a1, DataArrayDouble *a2, std::vector& littleStrings) const = 0; diff --git a/src/MEDCoupling/MEDCouplingRefCountObject.cxx b/src/MEDCoupling/MEDCouplingRefCountObject.cxx index af387699b..e55612456 100644 --- a/src/MEDCoupling/MEDCouplingRefCountObject.cxx +++ b/src/MEDCoupling/MEDCouplingRefCountObject.cxx @@ -19,9 +19,28 @@ // Author : Anthony Geay (CEA/DEN) #include "MEDCouplingRefCountObject.hxx" +#include "MED_version.h" using namespace ParaMEDMEM; +const char *ParaMEDMEM::MEDCouplingVersionStr() +{ + return SALOMEMED_VERSION_STR; +} + +int ParaMEDMEM::MEDCouplingVersion() +{ + return SALOMEMED_VERSION; +} + +void ParaMEDMEM::MEDCouplingVersionMajMinRel(int& maj, int& minor, int& releas) +{ + int ver=SALOMEMED_VERSION; + maj=(ver & 0xFF0000) >> 16; + minor=(ver & 0xFF00) >> 8; + releas=(ver & 0xFF); +} + RefCountObject::RefCountObject():_cnt(1) { } diff --git a/src/MEDCoupling/MEDCouplingRefCountObject.hxx b/src/MEDCoupling/MEDCouplingRefCountObject.hxx index f9084503e..c6eb6825a 100644 --- a/src/MEDCoupling/MEDCouplingRefCountObject.hxx +++ b/src/MEDCoupling/MEDCouplingRefCountObject.hxx @@ -50,6 +50,10 @@ namespace ParaMEDMEM typedef bool (*FunctionToEvaluate)(const double *pos, double *res); + MEDCOUPLING_EXPORT const char *MEDCouplingVersionStr(); + MEDCOUPLING_EXPORT int MEDCouplingVersion(); + MEDCOUPLING_EXPORT void MEDCouplingVersionMajMinRel(int& maj, int& minor, int& releas); + class MEDCOUPLING_EXPORT RefCountObject { protected: diff --git a/src/MEDCoupling/MEDCouplingRemapper.cxx b/src/MEDCoupling/MEDCouplingRemapper.cxx index 0ef48eec7..8a489b139 100644 --- a/src/MEDCoupling/MEDCouplingRemapper.cxx +++ b/src/MEDCoupling/MEDCouplingRemapper.cxx @@ -24,7 +24,9 @@ #include "MEDCouplingFieldTemplate.hxx" #include "MEDCouplingFieldDiscretization.hxx" #include "MEDCouplingExtrudedMesh.hxx" +#include "MEDCouplingCMesh.hxx" #include "MEDCouplingNormalizedUnstructuredMesh.txx" +#include "MEDCouplingNormalizedCartesianMesh.txx" #include "Interpolation1D.txx" #include "Interpolation2DCurve.hxx" @@ -33,6 +35,8 @@ #include "Interpolation3DSurf.hxx" #include "Interpolation2D1D.txx" #include "Interpolation3D2D.txx" +#include "InterpolationCU.txx" +#include "InterpolationCC.txx" using namespace ParaMEDMEM; @@ -55,6 +59,12 @@ int MEDCouplingRemapper::prepare(const MEDCouplingMesh *srcMesh, const MEDCoupli { case 85://Unstructured-Unstructured return prepareUU(method); + case 87://Unstructured-Cartesian + return prepareUC(method); + case 117://Cartesian-Unstructured + return prepareCU(method); + case 119://Cartesian-Cartesian + return prepareCC(method); case 136://Extruded-Extruded return prepareEE(method); default: @@ -232,7 +242,7 @@ int MEDCouplingRemapper::prepareUU(const char *method) throw(INTERP_KERNEL::Exce INTERP_KERNEL::Interpolation3D interpolation(*this); std::vector > matrixTmp; nbCols=interpolation.interpolateMeshes(target_mesh_wrapper,source_mesh_wrapper,matrixTmp,method); - reverseMatrix(matrixTmp,nbCols,_matrix); + ReverseMatrix(matrixTmp,nbCols,_matrix); nbCols=matrixTmp.size(); } else if(srcMeshDim==2 && trgMeshDim==1 && srcSpaceDim==2) @@ -251,7 +261,7 @@ int MEDCouplingRemapper::prepareUU(const char *method) throw(INTERP_KERNEL::Exce INTERP_KERNEL::Interpolation2D1D interpolation(*this); std::vector > matrixTmp; nbCols=interpolation.interpolateMeshes(target_mesh_wrapper,source_mesh_wrapper,matrixTmp,method); - reverseMatrix(matrixTmp,nbCols,_matrix); + ReverseMatrix(matrixTmp,nbCols,_matrix); nbCols=matrixTmp.size(); INTERP_KERNEL::Interpolation2D1D::DuplicateFacesType duplicateFaces=interpolation.retrieveDuplicateFaces(); if(!duplicateFaces.empty()) @@ -275,7 +285,7 @@ int MEDCouplingRemapper::prepareUU(const char *method) throw(INTERP_KERNEL::Exce INTERP_KERNEL::Interpolation2D interpolation(*this); std::vector > matrixTmp; nbCols=interpolation.interpolateMeshes(target_mesh_wrapper,source_mesh_wrapper,matrixTmp,method); - reverseMatrix(matrixTmp,nbCols,_matrix); + ReverseMatrix(matrixTmp,nbCols,_matrix); nbCols=matrixTmp.size(); } else @@ -322,7 +332,7 @@ int MEDCouplingRemapper::prepareUU(const char *method) throw(INTERP_KERNEL::Exce INTERP_KERNEL::Interpolation3D2D interpolation(*this); std::vector > matrixTmp; nbCols=interpolation.interpolateMeshes(target_mesh_wrapper,source_mesh_wrapper,matrixTmp,method); - reverseMatrix(matrixTmp,nbCols,_matrix); + ReverseMatrix(matrixTmp,nbCols,_matrix); nbCols=matrixTmp.size(); INTERP_KERNEL::Interpolation3D2D::DuplicateFacesType duplicateFaces=interpolation.retrieveDuplicateFaces(); if(!duplicateFaces.empty()) @@ -426,6 +436,163 @@ int MEDCouplingRemapper::prepareEE(const char *method) throw(INTERP_KERNEL::Exce return 1; } +int MEDCouplingRemapper::prepareUC(const char *method) throw(INTERP_KERNEL::Exception) +{ + std::string methodCpp(method); + if(methodCpp!="P0P0") + throw INTERP_KERNEL::Exception("MEDCouplingRemapper::prepareUC : only P0P0 interpolation supported for the moment !"); + INTERP_KERNEL::Interpolation::checkAndSplitInterpolationMethod(method,_src_method,_target_method); + MEDCouplingUMesh *src_mesh=static_cast(_src_mesh); + MEDCouplingCMesh *target_mesh=static_cast(_target_mesh); + const int srcMeshDim=src_mesh->getMeshDimension(); + const int srcSpceDim=src_mesh->getSpaceDimension(); + const int trgMeshDim=target_mesh->getMeshDimension(); + if(srcMeshDim!=srcSpceDim || srcMeshDim!=trgMeshDim) + throw INTERP_KERNEL::Exception("MEDCouplingRemapper::prepareUC : space dim of src unstructured should be equal to mesh dim of src unstructured and should be equal also equal to trg cartesian dimension !"); + std::vector > res; + switch(srcMeshDim) + { + case 1: + { + MEDCouplingNormalizedCartesianMesh<1> targetWrapper(target_mesh); + MEDCouplingNormalizedUnstructuredMesh<1,1> sourceWrapper(src_mesh); + INTERP_KERNEL::InterpolationCU myInterpolator(*this); + myInterpolator.interpolateMeshes(targetWrapper,sourceWrapper,res,"P0P0"); + break; + } + case 2: + { + MEDCouplingNormalizedCartesianMesh<2> targetWrapper(target_mesh); + MEDCouplingNormalizedUnstructuredMesh<2,2> sourceWrapper(src_mesh); + INTERP_KERNEL::InterpolationCU myInterpolator(*this); + myInterpolator.interpolateMeshes(targetWrapper,sourceWrapper,res,"P0P0"); + break; + } + case 3: + { + MEDCouplingNormalizedCartesianMesh<3> targetWrapper(target_mesh); + MEDCouplingNormalizedUnstructuredMesh<3,3> sourceWrapper(src_mesh); + INTERP_KERNEL::InterpolationCU myInterpolator(*this); + myInterpolator.interpolateMeshes(targetWrapper,sourceWrapper,res,"P0P0"); + break; + } + default: + throw INTERP_KERNEL::Exception("MEDCouplingRemapper::prepareUC : only dimension 1 2 or 3 supported !"); + } + ReverseMatrix(res,target_mesh->getNumberOfCells(),_matrix); + nullifiedTinyCoeffInCrudeMatrixAbs(0.); + // + _deno_multiply.clear(); + _deno_multiply.resize(_matrix.size()); + _deno_reverse_multiply.clear(); + _deno_reverse_multiply.resize(src_mesh->getNumberOfCells()); + declareAsNew(); + return 1; +} + +int MEDCouplingRemapper::prepareCU(const char *method) throw(INTERP_KERNEL::Exception) +{ + std::string methodCpp(method); + if(methodCpp!="P0P0") + throw INTERP_KERNEL::Exception("MEDCouplingRemapper::prepareCU : only P0P0 interpolation supported for the moment !"); + INTERP_KERNEL::Interpolation::checkAndSplitInterpolationMethod(method,_src_method,_target_method); + MEDCouplingCMesh *src_mesh=static_cast(_src_mesh); + MEDCouplingUMesh *target_mesh=static_cast(_target_mesh); + const int srcMeshDim=src_mesh->getMeshDimension(); + const int trgMeshDim=target_mesh->getMeshDimension(); + const int trgSpceDim=target_mesh->getSpaceDimension(); + if(trgMeshDim!=trgSpceDim || trgMeshDim!=srcMeshDim) + throw INTERP_KERNEL::Exception("MEDCouplingRemapper::prepareCU : space dim of target unstructured should be equal to mesh dim of target unstructured and should be equal also equal to source cartesian dimension !"); + switch(srcMeshDim) + { + case 1: + { + MEDCouplingNormalizedCartesianMesh<1> sourceWrapper(src_mesh); + MEDCouplingNormalizedUnstructuredMesh<1,1> targetWrapper(target_mesh); + INTERP_KERNEL::InterpolationCU myInterpolator(*this); + myInterpolator.interpolateMeshes(sourceWrapper,targetWrapper,_matrix,"P0P0"); + break; + } + case 2: + { + MEDCouplingNormalizedCartesianMesh<2> sourceWrapper(src_mesh); + MEDCouplingNormalizedUnstructuredMesh<2,2> targetWrapper(target_mesh); + INTERP_KERNEL::InterpolationCU myInterpolator(*this); + myInterpolator.interpolateMeshes(sourceWrapper,targetWrapper,_matrix,"P0P0"); + break; + } + case 3: + { + MEDCouplingNormalizedCartesianMesh<3> sourceWrapper(src_mesh); + MEDCouplingNormalizedUnstructuredMesh<3,3> targetWrapper(target_mesh); + INTERP_KERNEL::InterpolationCU myInterpolator(*this); + myInterpolator.interpolateMeshes(sourceWrapper,targetWrapper,_matrix,"P0P0"); + break; + } + default: + throw INTERP_KERNEL::Exception("MEDCouplingRemapper::prepareCU : only dimension 1 2 or 3 supported !"); + } + nullifiedTinyCoeffInCrudeMatrixAbs(0.); + // + _deno_multiply.clear(); + _deno_multiply.resize(_matrix.size()); + _deno_reverse_multiply.clear(); + _deno_reverse_multiply.resize(src_mesh->getNumberOfCells()); + declareAsNew(); + return 1; +} + +int MEDCouplingRemapper::prepareCC(const char *method) throw(INTERP_KERNEL::Exception) +{ + std::string methodCpp(method); + if(methodCpp!="P0P0") + throw INTERP_KERNEL::Exception("MEDCouplingRemapper::prepareCC : only P0P0 interpolation supported for the moment !"); + INTERP_KERNEL::Interpolation::checkAndSplitInterpolationMethod(method,_src_method,_target_method); + MEDCouplingCMesh *src_mesh=static_cast(_src_mesh); + MEDCouplingCMesh *target_mesh=static_cast(_target_mesh); + const int srcMeshDim=src_mesh->getMeshDimension(); + const int trgMeshDim=target_mesh->getMeshDimension(); + if(trgMeshDim!=srcMeshDim) + throw INTERP_KERNEL::Exception("MEDCouplingRemapper::prepareCC : dim of target cartesian should be equal to dim of source cartesian dimension !"); + switch(srcMeshDim) + { + case 1: + { + MEDCouplingNormalizedCartesianMesh<1> sourceWrapper(src_mesh); + MEDCouplingNormalizedCartesianMesh<1> targetWrapper(target_mesh); + INTERP_KERNEL::InterpolationCC myInterpolator(*this); + myInterpolator.interpolateMeshes(sourceWrapper,targetWrapper,_matrix,"P0P0"); + break; + } + case 2: + { + MEDCouplingNormalizedCartesianMesh<2> sourceWrapper(src_mesh); + MEDCouplingNormalizedCartesianMesh<2> targetWrapper(target_mesh); + INTERP_KERNEL::InterpolationCC myInterpolator(*this); + myInterpolator.interpolateMeshes(sourceWrapper,targetWrapper,_matrix,"P0P0"); + break; + } + case 3: + { + MEDCouplingNormalizedCartesianMesh<3> sourceWrapper(src_mesh); + MEDCouplingNormalizedCartesianMesh<3> targetWrapper(target_mesh); + INTERP_KERNEL::InterpolationCC myInterpolator(*this); + myInterpolator.interpolateMeshes(sourceWrapper,targetWrapper,_matrix,"P0P0"); + break; + } + default: + throw INTERP_KERNEL::Exception("MEDCouplingRemapper::prepareCC : only dimension 1 2 or 3 supported !"); + } + nullifiedTinyCoeffInCrudeMatrixAbs(0.); + // + _deno_multiply.clear(); + _deno_multiply.resize(_matrix.size()); + _deno_reverse_multiply.clear(); + _deno_reverse_multiply.resize(src_mesh->getNumberOfCells()); + declareAsNew(); + return 1; +} + void MEDCouplingRemapper::updateTime() const { } @@ -494,7 +661,7 @@ void MEDCouplingRemapper::computeDenoFromScratch(NatureOfField nat, const MEDCou { case ConservativeVolumic: { - computeRowSumAndColSum(_matrix,_deno_multiply,_deno_reverse_multiply); + ComputeRowSumAndColSum(_matrix,_deno_multiply,_deno_reverse_multiply); break; } case Integral: @@ -526,7 +693,7 @@ void MEDCouplingRemapper::computeDenoFromScratch(NatureOfField nat, const MEDCou } case IntegralGlobConstraint: { - computeColSumAndRowSum(_matrix,_deno_multiply,_deno_reverse_multiply); + ComputeColSumAndRowSum(_matrix,_deno_multiply,_deno_reverse_multiply); break; } case RevIntegral: @@ -607,7 +774,7 @@ void MEDCouplingRemapper::computeReverseProduct(const double *inputPointer, int std::fill(resPointer+idx*inputNbOfCompo,resPointer+(idx+1)*inputNbOfCompo,dftValue); } -void MEDCouplingRemapper::reverseMatrix(const std::vector >& matIn, int nbColsMatIn, std::vector >& matOut) +void MEDCouplingRemapper::ReverseMatrix(const std::vector >& matIn, int nbColsMatIn, std::vector >& matOut) { matOut.resize(nbColsMatIn); int id=0; @@ -616,7 +783,7 @@ void MEDCouplingRemapper::reverseMatrix(const std::vector > matOut[(*iter2).first][id]=(*iter2).second; } -void MEDCouplingRemapper::computeRowSumAndColSum(const std::vector >& matrixDeno, +void MEDCouplingRemapper::ComputeRowSumAndColSum(const std::vector >& matrixDeno, std::vector >& deno, std::vector >& denoReverse) { std::map values; @@ -640,7 +807,7 @@ void MEDCouplingRemapper::computeRowSumAndColSum(const std::vector >& matrixDeno, +void MEDCouplingRemapper::ComputeColSumAndRowSum(const std::vector >& matrixDeno, std::vector >& deno, std::vector >& denoReverse) { std::map values; diff --git a/src/MEDCoupling/MEDCouplingRemapper.hxx b/src/MEDCoupling/MEDCouplingRemapper.hxx index c2005df8e..41948c2fb 100644 --- a/src/MEDCoupling/MEDCouplingRemapper.hxx +++ b/src/MEDCoupling/MEDCouplingRemapper.hxx @@ -65,6 +65,9 @@ namespace ParaMEDMEM private: int prepareUU(const char *method) throw(INTERP_KERNEL::Exception); int prepareEE(const char *method) throw(INTERP_KERNEL::Exception); + int prepareUC(const char *method) throw(INTERP_KERNEL::Exception); + int prepareCU(const char *method) throw(INTERP_KERNEL::Exception); + int prepareCC(const char *method) throw(INTERP_KERNEL::Exception); void updateTime() const; void releaseData(bool matrixSuppression); void transferUnderground(const MEDCouplingFieldDouble *srcField, MEDCouplingFieldDouble *targetField, bool isDftVal, double dftValue) throw(INTERP_KERNEL::Exception); @@ -76,11 +79,11 @@ namespace ParaMEDMEM const std::vector< std::map >& m2D, const int *corrCellIdSrc, int nbOf2DCellsSrc, int nbOf1DCellsSrc, const int *corrCellIdTrg); - static void reverseMatrix(const std::vector >& matIn, int nbColsMatIn, + static void ReverseMatrix(const std::vector >& matIn, int nbColsMatIn, std::vector >& matOut); - static void computeRowSumAndColSum(const std::vector >& matrixDeno, + static void ComputeRowSumAndColSum(const std::vector >& matrixDeno, std::vector >& deno, std::vector >& denoReverse); - static void computeColSumAndRowSum(const std::vector >& matrixDeno, + static void ComputeColSumAndRowSum(const std::vector >& matrixDeno, std::vector >& deno, std::vector >& denoReverse); private: MEDCouplingMesh *_src_mesh; diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index d8f87ad56..dae38283f 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -1062,7 +1062,6 @@ void MEDCouplingUMesh::simplifyPolyhedra(double eps) throw(INTERP_KERNEL::Except throw INTERP_KERNEL::Exception("MEDCouplingUMesh::simplifyPolyhedra : works on meshdimension 3 and spaceDimension 3 !"); MEDCouplingAutoRefCountObjectPtr coords=getCoords()->deepCpy(); coords->recenterForMaxPrecision(eps); - const double *coordsPtr=coords->getConstPointer(); // int nbOfCells=getNumberOfCells(); const int *conn=_nodal_connec->getConstPointer(); @@ -1612,7 +1611,6 @@ bool MEDCouplingUMesh::areCellsIncludedIn2(const MEDCouplingUMesh *other, DataAr } int thisNbCells=getNumberOfCells(); int otherNbCells=other->getNumberOfCells(); - int nbOfCells=mesh->getNumberOfCells(); MEDCouplingAutoRefCountObjectPtr arr2=DataArrayInt::New(); arr2->alloc(otherNbCells,1); arr2->fillWithZero(); @@ -1794,9 +1792,7 @@ void MEDCouplingUMesh::setPartOfMySelf(const int *cellIdsBg, const int *cellIdsE } int nbOfCells=getNumberOfCells(); bool easyAssign=true; - const int *conn=_nodal_connec->getConstPointer(); const int *connI=_nodal_connec_index->getConstPointer(); - const int *connOther=otherOnSameCoordsThanThis._nodal_connec->getConstPointer(); const int *connIOther=otherOnSameCoordsThanThis._nodal_connec_index->getConstPointer(); for(const int *it=cellIdsBg;it!=cellIdsEnd && easyAssign;it++,connIOther++) { @@ -1845,9 +1841,7 @@ void MEDCouplingUMesh::setPartOfMySelf2(int start, int end, int step, const MEDC } int nbOfCells=getNumberOfCells(); bool easyAssign=true; - const int *conn=_nodal_connec->getConstPointer(); const int *connI=_nodal_connec_index->getConstPointer(); - const int *connOther=otherOnSameCoordsThanThis._nodal_connec->getConstPointer(); const int *connIOther=otherOnSameCoordsThanThis._nodal_connec_index->getConstPointer(); int it=start; for(int i=0;igetConstPointer(); const int *pt=_nodal_connec->getConstPointer(); - return (INTERP_KERNEL::NormalizedCellType) pt[ptI[cellId]]; + if(cellId>=0 && cellId<_nodal_connec_index->getNbOfElems()-1) + return (INTERP_KERNEL::NormalizedCellType) pt[ptI[cellId]]; + else + { + std::ostringstream oss; oss << "MEDCouplingUMesh::getTypeOfCell : Requesting type of cell #" << cellId << " but it should be in [0," << _nodal_connec_index->getNbOfElems()-1 << ") !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } } /*! @@ -2604,6 +2604,27 @@ std::string MEDCouplingUMesh::advancedRepr() const return ret.str(); } +/*! + * This method returns a C++ code that is a dump of \a this. + * This method will throw if this is not fully defined. + */ +std::string MEDCouplingUMesh::cppRepr() const throw(INTERP_KERNEL::Exception) +{ + static const char coordsName[]="coords"; + static const char connName[]="conn"; + static const char connIName[]="connI"; + checkFullyDefined(); + std::ostringstream ret; ret << "// coordinates" << std::endl; + _coords->reprCppStream(coordsName,ret); ret << std::endl << "// connectivity" << std::endl; + _nodal_connec->reprCppStream(connName,ret); ret << std::endl; + _nodal_connec_index->reprCppStream(connIName,ret); ret << std::endl; + ret << "MEDCouplingUMesh *mesh=MEDCouplingUMesh::New(\"" << getName() << "\"," << getMeshDimension() << ");" << std::endl; + ret << "mesh->setCoords(" << coordsName << ");" << std::endl; + ret << "mesh->setConnectivity(" << connName << "," << connIName << ",true);" << std::endl; + ret << coordsName << "->decrRef(); " << connName << "->decrRef(); " << connIName << "->decrRef();" << std::endl; + return ret.str(); +} + std::string MEDCouplingUMesh::reprConnectivityOfThis() const { std::ostringstream ret; @@ -3341,10 +3362,10 @@ MEDCouplingUMesh *MEDCouplingUMesh::buildSlice3DSurf(const double *origin, const { checkFullyDefined(); if(getMeshDimension()!=2 || getSpaceDimension()!=3) - throw INTERP_KERNEL::Exception("MEDCouplingUMesh::buildSlice3D works on umeshes with meshdim equal to 2 and spaceDim equal to 3 !"); + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::buildSlice3DSurf works on umeshes with meshdim equal to 2 and spaceDim equal to 3 !"); MEDCouplingAutoRefCountObjectPtr candidates=getCellIdsCrossingPlane(origin,vec,eps); if(candidates->empty()) - throw INTERP_KERNEL::Exception("MEDCouplingUMesh::buildSlice3D : No 3D cells in this intercepts the specified plane considering bounding boxes !"); + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::buildSlice3DSurf : No 3D surf cells in this intercepts the specified plane considering bounding boxes !"); std::vector nodes; std::vector cellIds1D; MEDCouplingAutoRefCountObjectPtr subMesh=static_cast(buildPartOfMySelf(candidates->begin(),candidates->end(),false)); @@ -5220,10 +5241,17 @@ DataArrayInt *MEDCouplingUMesh::checkTypeConsistencyAndContig(const std::vector< } /*! - * This method makes the hypothesis that 'this' is sorted by type. If not an exception will be thrown. - * This method is the opposite of MEDCouplingUMesh::checkTypeConsistencyAndContig method. Given a list of cells in 'profile' it returns a list of profiles sorted by geo type. - * This method has 1 input 'profile' and 2 outputs 'code' and 'idsPerType'. - * @throw if 'profile' has not exactly one component. It throws too, if 'profile' contains some values not in [0,getNumberOfCells()) or if 'this' is not fully defined + * This method makes the hypothesis that \at this is sorted by type. If not an exception will be thrown. + * This method is the opposite of MEDCouplingUMesh::checkTypeConsistencyAndContig method. Given a list of cells in \a profile it returns a list of sub-profiles sorted by geo type. + * The result is put in the array \a idsPerType. In the returned parameter \a code, foreach i \a code[3*i+2] refers (if different from -1) to a location into the \a idsPerType. + * This method has 1 input \a profile and 3 outputs \a code' \a idsInPflPerType and \a idsPerType. + * + * @param [out] code is a vector of size 3*n where n is the number of different geometric type in \a this \b reduced to the profile \a profile. \a code has exactly the same semantic than in MEDCouplingUMesh::checkTypeConsistencyAndContig method. + * @param [out] idsInPflPerType is a vector of size of different geometric type in the subpart defined by \a profile of \a this ( equal to \a code.size()/3). For each i, + * \a idsInPflPerType[i] stores the tuple ids in \a profile that correspond to the geometric type code[3*i+0] + * @param [out] idsPerType is a vector of size of different sub profiles needed to be defined to represent the profile \a profile for a given geometric type. + * This vector can be empty in case of all geometric type cells are fully covered in ascending in the given input \a profile. + * @throw if \a profile has not exactly one component. It throws too, if \a profile contains some values not in [0,getNumberOfCells()) or if 'this' is not fully defined */ void MEDCouplingUMesh::splitProfilePerType(const DataArrayInt *profile, std::vector& code, std::vector& idsInPflPerType, std::vector& idsPerType) const throw(INTERP_KERNEL::Exception) { @@ -5641,32 +5669,45 @@ DataArrayInt *MEDCouplingUMesh::convertCellArrayPerGeoType(const DataArrayInt *d /*! * This method reduced number of cells of this by keeping cells whose type is different from 'type' and if type=='type' + * This method \b works \b for mesh sorted by type. * cells whose ids is in 'idsPerGeoType' array. * This method conserves coords and name of mesh. */ MEDCouplingUMesh *MEDCouplingUMesh::keepSpecifiedCells(INTERP_KERNEL::NormalizedCellType type, const int *idsPerGeoTypeBg, const int *idsPerGeoTypeEnd) const { - std::vector idsTokeep; - int nbOfCells=getNumberOfCells(); - int j=0; - for(int i=0;i code=getDistributionOfTypes(); + std::size_t nOfTypesInThis=code.size()/3; + int sz=0,szOfType=0; + for(std::size_t i=0;i=szOfType) { - if(std::find(idsPerGeoTypeBg,idsPerGeoTypeEnd,j)!=idsPerGeoTypeEnd) - idsTokeep.push_back(i); - j++; + std::ostringstream oss; oss << "MEDCouplingUMesh::keepSpecifiedCells : Request on type " << type << " at place #" << std::distance(idsPerGeoTypeBg,work) << " value " << *work; + oss << ". It should be in [0," << szOfType << ") !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); } - MEDCouplingPointSet *ret=buildPartOfMySelf(&idsTokeep[0],&idsTokeep[0]+idsTokeep.size(),true); - MEDCouplingUMesh *ret2=dynamic_cast(ret); - if(!ret2) + MEDCouplingAutoRefCountObjectPtr idsTokeep=DataArrayInt::New(); idsTokeep->alloc(sz+(int)std::distance(idsPerGeoTypeBg,idsPerGeoTypeEnd),1); + int *idsPtr=idsTokeep->getPointer(); + int offset=0; + for(std::size_t i=0;idecrRef(); - return 0; + if(code[3*i]!=type) + for(int j=0;j(),offset)); + offset+=code[3*i+1]; } - ret2->copyTinyInfoFrom(this); - return ret2; + MEDCouplingAutoRefCountObjectPtr ret=static_cast(buildPartOfMySelf(idsTokeep->begin(),idsTokeep->end(),true)); + ret->copyTinyInfoFrom(this); + ret->incrRef(); + return ret; } /*! @@ -6570,7 +6611,7 @@ void MEDCouplingUMesh::writeVTKLL(std::ostream& ofs, const std::string& cellData MEDCouplingAutoRefCountObjectPtr connectivity=DataArrayInt::New(); connectivity->alloc(_nodal_connec->getNumberOfTuples()-nbOfCells,1); int *w1=faceoffsets->getPointer(),*w2=types->getPointer(),*w3=offsets->getPointer(),*w4=connectivity->getPointer(); int szFaceOffsets=0,szConn=0; - for(int i=0;iwriteVTK(ofs,8,"Int32","faces"); @@ -6707,24 +6748,35 @@ void MEDCouplingUMesh::BuildIntersecting2DCellsFromEdges(double eps, const MEDCo MEDCouplingUMeshBuildQPFromMesh3(coo1,offset1,coo2,offset2,addCoords,desc1+descIndx1[i],desc1+descIndx1[i+1],intesctEdges1,/* output */mapp,mappRev); pol1.buildFromCrudeDataArray(mappRev,cm.isQuadratic(),conn1+connI1[i]+1,coo1, desc1+descIndx1[i],desc1+descIndx1[i+1],intesctEdges1); - std::vector crTmp,crITmp; - crITmp.push_back(crI.back()); - for(std::vector::const_iterator it2=candidates2.begin();it2!=candidates2.end();it2++) + // + std::set edges1;// store all edges of pol1 that are NOT consumed by intersect cells. If any after iteration over candidates2 -> a part of pol1 should appear in result + std::set edgesBoundary2;// store all edges that are on boundary of (pol2 intersect pol1) minus edges on pol1. + INTERP_KERNEL::IteratorOnComposedEdge it1(&pol1); + for(it1.first();!it1.finished();it1.next()) + edges1.insert(it1.current()->getPtr()); + // + std::map > edgesIn2ForShare; + std::vector pol2s(candidates2.size()); + int ii=0; + for(std::vector::const_iterator it2=candidates2.begin();it2!=candidates2.end();it2++,ii++) { - INTERP_KERNEL::QuadraticPolygon pol2; - pol1.initLocations(); - MEDCouplingUMeshBuildQPFromMesh3(coo1,offset1,coo2,offset2,addCoords,desc2+descIndx2[*it2],desc2+descIndx2[*it2+1],intesctEdges2,/* output */mapp,mappRev); INTERP_KERNEL::NormalizedCellType typ2=(INTERP_KERNEL::NormalizedCellType)conn2[connI2[*it2]]; const INTERP_KERNEL::CellModel& cm2=INTERP_KERNEL::CellModel::GetCellModel(typ2); - pol2.buildFromCrudeDataArray2(mappRev,cm2.isQuadratic(),conn2+connI2[*it2]+1,coo2,desc2+descIndx2[*it2],desc2+descIndx2[*it2+1],intesctEdges2, - pol1,desc1+descIndx1[i],desc1+descIndx1[i+1],intesctEdges1,colinear2); + MEDCouplingUMeshBuildQPFromMesh3(coo1,offset1,coo2,offset2,addCoords,desc2+descIndx2[*it2],desc2+descIndx2[*it2+1],intesctEdges2,/* output */mapp,mappRev); + pol2s[ii].buildFromCrudeDataArray2(mappRev,cm2.isQuadratic(),conn2+connI2[*it2]+1,coo2,desc2+descIndx2[*it2],desc2+descIndx2[*it2+1],intesctEdges2, + pol1,desc1+descIndx1[i],desc1+descIndx1[i+1],intesctEdges1,colinear2,edgesIn2ForShare); + } + ii=0; + for(std::vector::const_iterator it2=candidates2.begin();it2!=candidates2.end();it2++,ii++) + { + pol1.initLocationsWithOther(pol2s[ii]); + pol2s[ii].updateLocOfEdgeFromCrudeDataArray2(desc2+descIndx2[*it2],desc2+descIndx2[*it2+1],intesctEdges2,pol1,desc1+descIndx1[i],desc1+descIndx1[i+1],intesctEdges1,colinear2); //MEDCouplingUMeshAssignOnLoc(pol1,pol2,desc1+descIndx1[i],desc1+descIndx1[i+1],intesctEdges1,desc2+descIndx2[*it2],desc2+descIndx2[*it2+1],intesctEdges2,colinear2); - pol1.buildPartitionsAbs(pol2,mapp,i,*it2,offset3,addCoordsQuadratic,cr,crI,cNb1,cNb2); + pol1.buildPartitionsAbs(pol2s[ii],edges1,edgesBoundary2,mapp,i,*it2,offset3,addCoordsQuadratic,cr,crI,cNb1,cNb2); } - if(!crTmp.empty()) + if(!edges1.empty()) { - cr.insert(cr.end(),crTmp.begin(),crTmp.end()); - crI.insert(crI.end(),crITmp.begin()+1,crITmp.end()); + INTERP_KERNEL::QuadraticPolygon::ComputeResidual(pol1,edges1,edgesBoundary2,mapp,offset3,i,addCoordsQuadratic,cr,crI,cNb1,cNb2); } for(std::map::const_iterator it=mappRev.begin();it!=mappRev.end();it++) (*it).second->decrRef(); @@ -7096,6 +7148,8 @@ bool MEDCouplingUMesh::BuildConvexEnvelopOf2DCellJarvis(const double *coords, co return true; } } + else + throw INTERP_KERNEL::Exception("MEDCouplingUMesh::BuildConvexEnvelopOf2DCellJarvis : invalid 2D cell connectivity !"); } else throw INTERP_KERNEL::Exception("MEDCouplingUMesh::BuildConvexEnvelopOf2DCellJarvis : invalid 2D cell connectivity !"); @@ -7501,7 +7555,6 @@ MEDCouplingUMesh *MEDCouplingUMesh::buildSpreadZonesWithPoly() const throw(INTER int spaceDim=getSpaceDimension(); if(mdim!=spaceDim) throw INTERP_KERNEL::Exception("MEDCouplingUMesh::buildSpreadZonesWithPoly : meshdimension and spacedimension do not match !"); - int nbCells=getNumberOfCells(); std::vector partition=partitionBySpreadZone(); std::vector< MEDCouplingAutoRefCountObjectPtr > partitionAuto; partitionAuto.reserve(partition.size()); std::copy(partition.begin(),partition.end(),std::back_insert_iterator > >(partitionAuto)); diff --git a/src/MEDCoupling/MEDCouplingUMesh.hxx b/src/MEDCoupling/MEDCouplingUMesh.hxx index eb28c5a30..7da64ee50 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.hxx +++ b/src/MEDCoupling/MEDCouplingUMesh.hxx @@ -74,6 +74,7 @@ namespace ParaMEDMEM MEDCOUPLING_EXPORT DataArrayInt *getCellIdsFullyIncludedInNodeIds(const int *partBg, const int *partEnd) const; MEDCOUPLING_EXPORT std::string simpleRepr() const; MEDCOUPLING_EXPORT std::string advancedRepr() const; + MEDCOUPLING_EXPORT std::string cppRepr() const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT std::string reprConnectivityOfThis() const; MEDCOUPLING_EXPORT MEDCouplingUMesh *buildSetInstanceFromThis(int spaceDim) const throw(INTERP_KERNEL::Exception); MEDCOUPLING_EXPORT int getNumberOfNodesInCell(int cellId) const; diff --git a/src/MEDCoupling/Makefile.am b/src/MEDCoupling/Makefile.am index 77b16226d..2434ecf7d 100644 --- a/src/MEDCoupling/Makefile.am +++ b/src/MEDCoupling/Makefile.am @@ -56,7 +56,7 @@ dist_libmedcoupling_la_SOURCES = \ libmedcoupling_la_LDFLAGS= libmedcoupling_la_CPPFLAGS= @CXXTMPDPTHFLAGS@ \ - -I$(srcdir) -I$(srcdir)/../INTERP_KERNEL/Bases \ + -I$(top_builddir) -I$(srcdir) -I$(srcdir)/../INTERP_KERNEL/Bases \ -I$(srcdir)/../INTERP_KERNEL -I$(srcdir)/../INTERP_KERNEL/Geometric2D \ -I$(srcdir)/../INTERP_KERNEL/ExprEval -I$(srcdir)/../INTERP_KERNEL/GaussPoints diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest1.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest1.cxx index b1b83ca9e..9a55bea57 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest1.cxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest1.cxx @@ -106,7 +106,7 @@ void MEDCouplingBasicsTest1::testArray3() DataArrayDouble *arr4=DataArrayDouble::New(); arr4->alloc(7,2); double *tmp2=arr4->getPointer(); - const int arr4Ref[14]={0.8,10.8,1.9,11.9,2.1,12.1,3.2,13.2,4.3,14.3,5.4,15.4,6.5,16.5}; + const double arr4Ref[14]={0.8,10.8,1.9,11.9,2.1,12.1,3.2,13.2,4.3,14.3,5.4,15.4,6.5,16.5}; std::copy(arr4Ref,arr4Ref+14,tmp2); CPPUNIT_ASSERT_EQUAL(7,arr4->getNumberOfTuples()); CPPUNIT_ASSERT_EQUAL(2,arr4->getNumberOfComponents()); diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx index 89cf9818f..f6953bbd8 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest2.cxx @@ -53,6 +53,7 @@ void MEDCouplingBasicsTest2::testGaussPointField1() CPPUNIT_ASSERT_EQUAL(5,f->getNumberOfMeshPlacesExpected()); CPPUNIT_ASSERT_EQUAL(0,f->getNbOfGaussLocalization()); f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_TRI3,_refCoo1,_gsCoo1,_wg1); + f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_TRI3,_refCoo1,_gsCoo1,_wg1); // not a bug only to check that it works well CPPUNIT_ASSERT_THROW(f->setGaussLocalizationOnType(INTERP_KERNEL::NORM_QUAD4,_refCoo1,_gsCoo1,_wg1),INTERP_KERNEL::Exception); CPPUNIT_ASSERT_EQUAL(1,f->getNbOfGaussLocalization()); const double refCoo2[8]={ 0.,0., 1.,0., 1.,1., 0.,1. }; diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest3.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest3.cxx index ce2fc84ec..fcc86c4ac 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest3.cxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest3.cxx @@ -1388,9 +1388,9 @@ void MEDCouplingBasicsTest3::testExtrudedMesh5() DataArrayDouble *d=DataArrayDouble::New(); d->alloc(13,1); d->iota(); - MEDCouplingCMesh *e=MEDCouplingCMesh::New(); - e->setCoordsAt(0,d); - MEDCouplingUMesh *f=e->buildUnstructured(); + MEDCouplingCMesh *ee=MEDCouplingCMesh::New(); + ee->setCoordsAt(0,d); + MEDCouplingUMesh *f=ee->buildUnstructured(); DataArrayDouble *g=f->getCoords()->applyFunc(2,"3.5*IVec+x/6*3.14159265359*JVec"); CPPUNIT_ASSERT_THROW(f->getCoords()->applyFunc(2,"3.5*IVec+x/6*3.14159265359*KVec"),INTERP_KERNEL::Exception); // KVec refers to component #2 and there is only 2 components ! DataArrayDouble *h=g->fromPolarToCart(); @@ -1425,7 +1425,7 @@ void MEDCouplingBasicsTest3::testExtrudedMesh5() h->decrRef(); g->decrRef(); f->decrRef(); - e->decrRef(); + ee->decrRef(); d->decrRef(); c->decrRef(); b->decrRef(); diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx index f781b061a..e422be808 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest4.cxx @@ -2020,22 +2020,22 @@ void MEDCouplingBasicsTest4::testIntersect2DMeshesTmp1() // End of construction of input meshes m1bis and m2 -> start of specific part of the test DataArrayInt *d1=0,*d2=0; MEDCouplingUMesh *m3=MEDCouplingUMesh::Intersect2DMeshes(m1bis,m2,1e-10,d1,d2); - const int expected1[5]={0,1,1,2,2}; - const int expected2[5]={0,0,1,1,2}; - CPPUNIT_ASSERT_EQUAL(5,d1->getNumberOfTuples()); - CPPUNIT_ASSERT_EQUAL(5,d2->getNumberOfTuples()); - CPPUNIT_ASSERT_EQUAL(5,m3->getNumberOfCells()); + const int expected1[8]={0,0,1,1,1,2,2,2}; + const int expected2[8]={0,-1,0,1,-1,1,2,-1}; + CPPUNIT_ASSERT_EQUAL(8,d1->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(8,d2->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(8,m3->getNumberOfCells()); CPPUNIT_ASSERT_EQUAL(22,m3->getNumberOfNodes()); CPPUNIT_ASSERT_EQUAL(2,m3->getSpaceDimension()); - CPPUNIT_ASSERT(std::equal(expected1,expected1+5,d1->getConstPointer())); - CPPUNIT_ASSERT(std::equal(expected2,expected2+5,d2->getConstPointer())); - const int expected3[25]={5,17,1,16,12,5,18,1,17,13,5,19,2,18,13,5,20,2,19,14,5,21,3,20,14}; - const int expected4[6]={0,5,10,15,20,25}; + CPPUNIT_ASSERT(std::equal(expected1,expected1+8,d1->getConstPointer())); + CPPUNIT_ASSERT(std::equal(expected2,expected2+8,d2->getConstPointer())); + const int expected3[44]={5,17,1,16,12,5,16,0,4,5,17,12,5,18,1,17,13,5,19,2,18,13,5,17,5,6,19,13,5,20,2,19,14,5,21,3,20,14,5,19,6,7,21,14}; + const int expected4[9]={0,5,12,17,22,28,33,38,44}; const double expected5[44]={-1.0,2.0,1.0,2.0,2.0,2.0,4.0,2.0,-1.0,4.0,1.0,4.0,2.0,4.0,4.0,4.0,-0.5,-1.5,1.5,-1.5,2.5,-1.5,4.5,-1.5,-0.5,2.5,1.5,2.5,2.5,2.5,4.5,2.5,-0.5,2.0,1.0,2.5,1.5,2.0,2.0,2.5,2.5,2.0,4.0,2.5}; - CPPUNIT_ASSERT_EQUAL(25,m3->getNodalConnectivity()->getNumberOfTuples()); - CPPUNIT_ASSERT_EQUAL(6,m3->getNodalConnectivityIndex()->getNumberOfTuples()); - CPPUNIT_ASSERT(std::equal(expected3,expected3+25,m3->getNodalConnectivity()->getConstPointer())); - CPPUNIT_ASSERT(std::equal(expected4,expected4+6,m3->getNodalConnectivityIndex()->getConstPointer())); + CPPUNIT_ASSERT_EQUAL(44,m3->getNodalConnectivity()->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(9,m3->getNodalConnectivityIndex()->getNumberOfTuples()); + CPPUNIT_ASSERT(std::equal(expected3,expected3+44,m3->getNodalConnectivity()->getConstPointer())); + CPPUNIT_ASSERT(std::equal(expected4,expected4+9,m3->getNodalConnectivityIndex()->getConstPointer())); for(int i=0;i<44;i++) CPPUNIT_ASSERT_DOUBLES_EQUAL(expected5[i],m3->getCoords()->getIJ(0,i),1e-12); d1->decrRef(); @@ -2187,23 +2187,23 @@ void MEDCouplingBasicsTest4::testIntersect2DMeshesTmp3() DataArrayInt *d1=0,*d2=0; MEDCouplingUMesh *m3=MEDCouplingUMesh::Intersect2DMeshes(m1,m2,1e-10,d1,d2); m3->unPolyze(); - const int expected1[12]={0,1,1,2,3,3,4,5,5,6,7,7}; - const int expected2[12]={0,0,1,2,2,3,4,4,5,6,6,7}; - CPPUNIT_ASSERT_EQUAL(12,d1->getNumberOfTuples()); - CPPUNIT_ASSERT_EQUAL(12,d2->getNumberOfTuples()); - CPPUNIT_ASSERT_EQUAL(12,m3->getNumberOfCells()); - CPPUNIT_ASSERT_EQUAL(88,m3->getNumberOfNodes()); + const int expected1[16]={0,1,1,1,2,3,3,3,4,5,5,5,6,7,7,7}; + const int expected2[16]={0,0,1,-1,2,2,3,-1,4,4,5,-1,6,6,7,-1}; + CPPUNIT_ASSERT_EQUAL(16,d1->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(16,d2->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(16,m3->getNumberOfCells()); + CPPUNIT_ASSERT_EQUAL(104,m3->getNumberOfNodes()); CPPUNIT_ASSERT_EQUAL(2,m3->getSpaceDimension()); - CPPUNIT_ASSERT(std::equal(expected1,expected1+12,d1->getConstPointer())); - CPPUNIT_ASSERT(std::equal(expected2,expected2+12,d2->getConstPointer())); - const int expected3[100]={6,28,1,25,44,45,46,8,26,1,28,27,47,48,49,50,8,40,2,26,27,51,52,53,54,6,28,25,5,55,56,57,8,28,5,32,31,58,59,60,61,8,32,6,41,31,62,63,64,65,6,25,37,5,66,67,68,8,32,5,37,36,69,70,71,72,8,42,6,32,36,73,74,75,76,6,1,37,25,77,78,79,8,37,1,26,38,80,81,82,83,8,26,2,43,38,84,85,86,87}; - const int expected4[13]={0,7,16,25,32,41,50,57,66,75,82,91,100}; - const double expected5[176]={0.,0.,1.,0.,1.5,0.,0.,1.,0.,1.5,-1.,0.,-1.5,0.,0.,-1.,0.,-1.5,0.5,0.,1.25,0.,0.7071067811865476,0.7071067811865476,1.0606601717798214,1.0606601717798214,0.,0.5,0.,1.25,-0.7071067811865476,0.7071067811865476,-1.0606601717798214,1.0606601717798214,-0.5,0.,-1.25,0.,-0.7071067811865476,-0.7071067811865476,-1.0606601717798214,-1.0606601717798214,0.,-0.5,0.,-1.25,0.7071067811865476,-0.7071067811865476,1.0606601717798214,-1.0606601717798214,0.,0.,1.1,0.,1.1,1.,0.,1.,1.7,0.,1.7,1.,-1.1,1.,-1.1,0.,-1.7,0.,-1.7,1.,-1.7,-1.,-1.1,-1.,0.,-1.,1.1,-1.,1.7,-1.,1.118033988749895,1.,-1.118033988749895,1.,-1.118033988749895,-1.,1.118033988749895,-1.,0.7071067811865477,0.7071067811865476,0.5,0.,0.,0.5,1.05,0.,0.7071067811865475,0.7071067811865477,0.55,1.,1.1,0.5,1.4012585384440737,0.535233134659635,1.3,0.,1.1,0.5,1.1090169943749475,1.,0.,0.5,-0.5,0.,-0.7071067811865477,0.7071067811865476,-0.7071067811865475,0.7071067811865477,-1.05,0.,-1.1,0.5,-0.55,1.,-1.3,0.,-1.4012585384440737,0.5352331346596344,-1.1090169943749475,1.,-1.1,0.5,0.,-0.5,-0.7071067811865475,-0.7071067811865477,-0.5,0.,-1.05,0.,-0.7071067811865478,-0.7071067811865475,-0.55,-1.,-1.1,-0.5,-1.4012585384440732,-0.5352331346596354,-1.3,0.,-1.1,-0.5,-1.1090169943749475,-1.,0.7071067811865475,-0.7071067811865477,0.,-0.5,0.5,0.,0.7071067811865477,-0.7071067811865475,1.05,0.,1.1,-0.5,0.55,-1.,1.3,0.,1.4012585384440737,-0.535233134659635,1.1090169943749475,-1.,1.1,-0.5}; - CPPUNIT_ASSERT_EQUAL(100,m3->getNodalConnectivity()->getNumberOfTuples()); - CPPUNIT_ASSERT_EQUAL(13,m3->getNodalConnectivityIndex()->getNumberOfTuples()); - CPPUNIT_ASSERT(std::equal(expected3,expected3+100,m3->getNodalConnectivity()->getConstPointer())); - CPPUNIT_ASSERT(std::equal(expected4,expected4+13,m3->getNodalConnectivityIndex()->getConstPointer())); - for(int i=0;i<176;i++) + CPPUNIT_ASSERT(std::equal(expected1,expected1+16,d1->getConstPointer())); + CPPUNIT_ASSERT(std::equal(expected2,expected2+16,d2->getConstPointer())); + const int expected3[136]={6,28,1,25,44,45,46,8,26,1,28,27,47,48,49,50,8,40,2,26,27,51,52,53,54,8,28,4,40,27,55,56,57,58,6,28,25,5,59,60,61,8,28,5,32,31,62,63,64,65,8,32,6,41,31,66,67,68,69,8,41,4,28,31,70,71,72,73,6,25,37,5,74,75,76,8,32,5,37,36,77,78,79,80,8,42,6,32,36,81,82,83,84,8,37,8,42,36,85,86,87,88,6,1,37,25,89,90,91,8,37,1,26,38,92,93,94,95,8,26,2,43,38,96,97,98,99,8,43,8,37,38,100,101,102,103}; + const int expected4[17]={0,7,16,25,34,41,50,59,68,75,84,93,102,109,118,127,136}; + const double expected5[208]={0.,0.,1.,0.,1.5,0.,0.,1.,0.,1.5,-1.,0.,-1.5,0.,0.,-1.,0.,-1.5,0.5,0.,1.25,0.,0.7071067811865476,0.7071067811865476,1.0606601717798214,1.0606601717798214,0.,0.5,0.,1.25,-0.7071067811865476,0.7071067811865476,-1.0606601717798214,1.0606601717798214,-0.5,0.,-1.25,0.,-0.7071067811865476,-0.7071067811865476,-1.0606601717798214,-1.0606601717798214,0.,-0.5,0.,-1.25,0.7071067811865476,-0.7071067811865476,1.0606601717798214,-1.0606601717798214,0.,0.,1.1,0.,1.1,1.,0.,1.,1.7,0.,1.7,1.,-1.1,1.,-1.1,0.,-1.7,0.,-1.7,1.,-1.7,-1.,-1.1,-1.,0.,-1.,1.1,-1.,1.7,-1.,1.118033988749895,1.,-1.118033988749895,1.,-1.118033988749895,-1.,1.118033988749895,-1.,0.7071067811865477,0.7071067811865476,0.5,0.,0.,0.5,1.05,0.,0.7071067811865475,0.7071067811865477,0.55,1.,1.1,0.5,1.4012585384440737,0.535233134659635,1.3,0.,1.1,0.5,1.1090169943749475,1.,0.,1.25,0.6123724356957946,1.369306393762915,1.1090169943749475,1.,0.55,1.,0.,0.5,-0.5,0.,-0.7071067811865477,0.7071067811865476,-0.7071067811865475,0.7071067811865477,-1.05,0.,-1.1,0.5,-0.55,1.,-1.3,0.,-1.4012585384440737,0.5352331346596344,-1.1090169943749475,1.,-1.1,0.5,-0.6123724356957941,1.3693063937629155,0.,1.25,-0.55,1.,-1.1090169943749475,1.,0.,-0.5,-0.7071067811865475,-0.7071067811865477,-0.5,0.,-1.05,0.,-0.7071067811865478,-0.7071067811865475,-0.55,-1.,-1.1,-0.5,-1.4012585384440734,-0.5352331346596354,-1.3,0.,-1.1,-0.5,-1.1090169943749475,-1.,0.,-1.25,-0.6123724356957945,-1.369306393762915,-1.1090169943749475,-1.,-0.55,-1.,0.7071067811865475,-0.7071067811865477,0.,-0.5,0.5,0.,0.7071067811865477,-0.7071067811865475,1.05,0.,1.1,-0.5,0.55,-1.,1.3,0.,1.4012585384440737,-0.535233134659635,1.1090169943749475,-1.,1.1,-0.5,0.6123724356957946,-1.369306393762915,0.,-1.25,0.55,-1.,1.1090169943749475,-1.0}; + CPPUNIT_ASSERT_EQUAL(136,m3->getNodalConnectivity()->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(17,m3->getNodalConnectivityIndex()->getNumberOfTuples()); + CPPUNIT_ASSERT(std::equal(expected3,expected3+136,m3->getNodalConnectivity()->getConstPointer())); + CPPUNIT_ASSERT(std::equal(expected4,expected4+17,m3->getNodalConnectivityIndex()->getConstPointer())); + for(int i=0;i<208;i++) CPPUNIT_ASSERT_DOUBLES_EQUAL(expected5[i],m3->getCoords()->getIJ(0,i),1e-12); d1->decrRef(); d2->decrRef(); diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest5.cxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest5.cxx index 5e0d2a253..9e98601c0 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest5.cxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest5.cxx @@ -126,23 +126,23 @@ void MEDCouplingBasicsTest5::testIntersect2DMeshesTmp4() DataArrayInt *d1=0,*d2=0; MEDCouplingUMesh *m3=MEDCouplingUMesh::Intersect2DMeshes(m2,m1,1e-10,d1,d2); m3->unPolyze(); - const int expected1[12]={0,0,1,2,2,3,4,4,5,6,6,7}; - const int expected2[12]={0,1,1,2,3,3,4,5,5,6,7,7}; - CPPUNIT_ASSERT_EQUAL(12,d1->getNumberOfTuples()); - CPPUNIT_ASSERT_EQUAL(12,d2->getNumberOfTuples()); - CPPUNIT_ASSERT_EQUAL(12,m3->getNumberOfCells()); - CPPUNIT_ASSERT_EQUAL(88,m3->getNumberOfNodes()); + const int expected1[16]={0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7}; + const int expected2[16]={0,1,1,-1,2,3,3,-1,4,5,5,-1,6,7,7,-1}; + CPPUNIT_ASSERT_EQUAL(16,d1->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(16,d2->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(16,m3->getNumberOfCells()); + CPPUNIT_ASSERT_EQUAL(104,m3->getNumberOfNodes()); CPPUNIT_ASSERT_EQUAL(2,m3->getSpaceDimension()); - CPPUNIT_ASSERT(std::equal(expected1,expected1+12,d1->getConstPointer())); - CPPUNIT_ASSERT(std::equal(expected2,expected2+12,d2->getConstPointer())); - const int expected3[100]={6,16,15,18,44,45,46,8,18,2,1,16,47,48,49,50,8,17,1,2,40,51,52,53,54,6,18,15,20,55,56,57,8,20,7,6,18,58,59,60,61,8,41,6,7,21,62,63,64,65,6,20,15,22,66,67,68,8,22,11,7,20,69,70,71,72,8,21,7,11,42,73,74,75,76,6,22,15,16,77,78,79,8,16,1,13,22,80,81,82,83,8,43,13,1,17,84,85,86,87}; - const int expected4[13]={0,7,16,25,32,41,50,57,66,75,82,91,100}; - const double expected5[176]={0.,0.,1.1,0.,1.1,1.,0.,1.,1.7,0.,1.7,1.,-1.1,1.,-1.1,0.,-1.7,0.,-1.7,1.,-1.7,-1.,-1.1,-1.,0.,-1.,1.1,-1.,1.7,-1.,0.,0.,1.,0.,1.5,0.,0.,1.,0.,1.5,-1.,0.,-1.5,0.,0.,-1.,0.,-1.5,0.5,0.,1.25,0.,0.7071067811865476,0.7071067811865476,1.0606601717798214,1.0606601717798214,0.,0.5,0.,1.25,-0.7071067811865476,0.7071067811865476,-1.0606601717798214,1.0606601717798214,-0.5,0.,-1.25,0.,-0.7071067811865476,-0.7071067811865476,-1.0606601717798214,-1.0606601717798214,0.,-0.5,0.,-1.25,0.7071067811865476,-0.7071067811865476,1.0606601717798214,-1.0606601717798214,1.1180339887498951,1.,-1.1180339887498951,1.,-1.1180339887498951,-1.,1.1180339887498951,-1.,0.5,0.,0.,0.5,0.7071067811865477,0.7071067811865476,0.55,1.,1.1,0.5,1.05,0.,0.7071067811865477,0.7071067811865477,1.3,0.,1.1,0.5,1.1090169943749475,1.,1.4012585384440737,0.535233134659635,0.,0.5,-0.5,0.,-0.7071067811865477,0.7071067811865476,-1.05,0.,-1.1,0.5,-0.55,1.,-0.7071067811865477,0.7071067811865477,-1.1090169943749475,1.,-1.1,0.5,-1.3,0.,-1.4012585384440737,0.5352331346596344,-0.5,0.,0.,-0.5,-0.7071067811865475,-0.7071067811865477,-0.55,-1.,-1.1,-0.5,-1.05,0.,-0.7071067811865479,-0.7071067811865476,-1.3,0.,-1.1,-0.5,-1.1090169943749475,-1.,-1.4012585384440734,-0.5352331346596354,0.,-0.5,0.5,0.,0.7071067811865475,-0.7071067811865477,1.05,0.,1.1,-0.5,0.55,-1.,0.7071067811865477,-0.7071067811865476,1.1090169943749475,-1.,1.1,-0.5,1.3,0.,1.4012585384440737,-0.535233134659635}; - CPPUNIT_ASSERT_EQUAL(100,m3->getNodalConnectivity()->getNumberOfTuples()); - CPPUNIT_ASSERT_EQUAL(13,m3->getNodalConnectivityIndex()->getNumberOfTuples()); - CPPUNIT_ASSERT(std::equal(expected3,expected3+100,m3->getNodalConnectivity()->getConstPointer())); - CPPUNIT_ASSERT(std::equal(expected4,expected4+13,m3->getNodalConnectivityIndex()->getConstPointer())); - for(int i=0;i<176;i++) + CPPUNIT_ASSERT(std::equal(expected1,expected1+16,d1->getConstPointer())); + CPPUNIT_ASSERT(std::equal(expected2,expected2+16,d2->getConstPointer())); + const int expected3[136]={6,16,15,18,44,45,46,8,18,2,1,16,47,48,49,50,8,17,1,2,40,51,52,53,54,8,40,5,4,17,55,56,57,58,6,18,15,20,59,60,61,8,20,7,6,18,62,63,64,65,8,41,6,7,21,66,67,68,69,8,21,8,9,41,70,71,72,73,6,20,15,22,74,75,76,8,22,11,7,20,77,78,79,80,8,21,7,11,42,81,82,83,84,8,42,10,8,21,85,86,87,88,6,22,15,16,89,90,91,8,16,1,13,22,92,93,94,95,8,43,13,1,17,96,97,98,99,8,17,4,14,43,100,101,102,103}; + const int expected4[17]={0,7,16,25,34,41,50,59,68,75,84,93,102,109,118,127,136}; + const double expected5[208]={0.,0.,1.1, 0.,1.1,1.,0.,1.,1.7,0.,1.7,1.,-1.1,1.,-1.1,0.,-1.7,0.,-1.7,1.,-1.7,-1.,-1.1,-1.,0.,-1.,1.1,-1.,1.7,-1.,0.,0.,1.,0.,1.5,0.,0.,1.,0.,1.5,-1.,0.,-1.5,0.,0.,-1.,0.,-1.5,0.5,0.,1.25,0.,0.7071067811865476,0.7071067811865476,1.0606601717798214,1.0606601717798214,0.,0.5,0.,1.25,-0.7071067811865476,0.7071067811865476,-1.0606601717798214,1.0606601717798214,-0.5,0.,-1.25,0.,-0.7071067811865476,-0.7071067811865476,-1.0606601717798214,-1.0606601717798214,0.,-0.5,0.,-1.25,0.7071067811865476,-0.7071067811865476,1.0606601717798214,-1.0606601717798214,1.1180339887498951,1.,-1.1180339887498951,1.,-1.1180339887498951,-1.,1.1180339887498951,-1.,0.5,0.,0.,0.5,0.7071067811865477,0.7071067811865476,0.55,1.,1.1,0.5,1.05,0.,0.7071067811865477,0.7071067811865475,1.3,0.,1.1,0.5,1.1090169943749475,1.,1.4012585384440737,0.535233134659635,1.4090169943749475,1.,1.7,0.5,1.6,0.,1.4012585384440737,0.535233134659635,0.,0.5,-0.5,0.,-0.7071067811865477,0.7071067811865476,-1.05,0.,-1.1,0.5,-0.55,1.,-0.7071067811865478,0.7071067811865475,-1.1090169943749475,1.,-1.1,0.5,-1.3,0.,-1.4012585384440737,0.5352331346596344,-1.6,0.,-1.7,0.5,-1.4090169943749475,1.,-1.4012585384440737,0.5352331346596344,-0.5,0.,0.,-0.5,-0.7071067811865475,-0.7071067811865477,-0.55,-1.,-1.1,-0.5,-1.05,0.,-0.7071067811865475,-0.7071067811865477,-1.3,0.,-1.1,-0.5,-1.1090169943749475,-1.,-1.4012585384440734,-0.5352331346596354,-1.4090169943749475,-1.,-1.7,-0.5,-1.6,0.,-1.4012585384440732,-0.5352331346596354,0.,-0.5,0.5,0.,0.7071067811865475,-0.7071067811865477,1.05,0.,1.1,-0.5,0.55,-1.,0.7071067811865475,-0.7071067811865477,1.1090169943749475,-1.,1.1,-0.5,1.3,0.,1.4012585384440737,-0.535233134659635,1.6,0.,1.7,-0.5,1.4090169943749475,-1.,1.4012585384440737,-0.535233134659635}; + CPPUNIT_ASSERT_EQUAL(136,m3->getNodalConnectivity()->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(17,m3->getNodalConnectivityIndex()->getNumberOfTuples()); + CPPUNIT_ASSERT(std::equal(expected3,expected3+136,m3->getNodalConnectivity()->getConstPointer())); + CPPUNIT_ASSERT(std::equal(expected4,expected4+17,m3->getNodalConnectivityIndex()->getConstPointer())); + for(int i=0;i<208;i++) CPPUNIT_ASSERT_DOUBLES_EQUAL(expected5[i],m3->getCoords()->getIJ(0,i),1e-12); d1->decrRef(); d2->decrRef(); @@ -1554,3 +1554,121 @@ void MEDCouplingBasicsTest5::testDuplicateEachTupleNTimes1() d4->decrRef(); d5->decrRef(); } + +void MEDCouplingBasicsTest5::testIntersect2DMeshesTmp5() +{ + // coordinates + DataArrayDouble *coords=DataArrayDouble::New(); + const double coordsData[376]={41,0,42,0,0,42,0,41,41.5,0,29.698484809834998,29.698484809834994,0,41.5,28.991378028648452,28.991378028648445,-42,0,-41,0,-29.698484809834994,29.698484809834998,-41.5,0,-28.991378028648445,28.991378028648452,0,-42,0,-41,-29.698484809835001,-29.698484809834994,0,-41.5,-28.991378028648455,-28.991378028648445,29.698484809834987,-29.698484809835001,28.991378028648441,-28.991378028648455,43,0,0,43,42.5,0,30.405591591021544,30.40559159102154,0,42.5,-43,0,-30.40559159102154,30.405591591021544,-42.5,0,0,-43,-30.405591591021551,-30.40559159102154,0,-42.5,30.405591591021537,-30.405591591021551,44,0,0,44,43.5,0,31.112698372208094,31.112698372208087,0,43.5,-44,0,-31.112698372208087,31.112698372208094,-43.5,0,0,-44,-31.112698372208097,-31.112698372208087,0,-43.5,31.112698372208083,-31.112698372208097,45,0,0,45,44.5,0,31.81980515339464,31.819805153394636,0,44.5,-45,0,-31.819805153394636,31.81980515339464,-44.5,0,0,-45,-31.819805153394647,-31.819805153394636,0,-44.5,31.819805153394629,-31.819805153394647,47,0,0,47,46,0,33.234018715767739,33.234018715767732,0,46,-47,0,-33.234018715767732,33.234018715767739,-46,0,0,-47,-33.234018715767739,-33.234018715767732,0,-46,33.234018715767725,-33.234018715767739,49,0,0,49,48,0,34.648232278140831,34.648232278140824,0,48,-49,0,-34.648232278140824,34.648232278140831,-48,0,0,-49,-34.648232278140839,-34.648232278140824,0,-48,34.648232278140817,-34.648232278140839,51,0,0,51,50,0,36.062445840513924,36.062445840513924,0,50,-51,0,-36.062445840513924,36.062445840513924,-50,0,0,-51,-36.062445840513931,-36.062445840513924,0,-50,36.062445840513917,-36.062445840513931,53,0,0,53,52,0,37.476659402887023,37.476659402887016,0,52,-53,0,-37.476659402887016,37.476659402887023,-52,0,0,-53,-37.47665940288703,-37.476659402887016,0,-52,37.476659402887009,-37.47665940288703,55,0,0,55,54,0,38.890872965260115,38.890872965260108,0,54,-55,0,-38.890872965260108,38.890872965260115,-54,0,0,-55,-38.890872965260122,-38.890872965260108,0,-54,38.890872965260101,-38.890872965260122,59,0,0,59,57,0,41.719300090006307,41.7193000900063,0,57,-59,0,-41.7193000900063,41.719300090006307,-57,0,0,-59,-41.719300090006314,-41.7193000900063,0,-57,41.719300090006293,-41.719300090006314,63,0,0,63,61,0,44.547727214752499,44.547727214752491,0,61,-63,0,-44.547727214752491,44.547727214752499,-61,0,0,-63,-44.547727214752506,-44.547727214752491,0,-61,44.547727214752484,-44.547727214752506,67,0,0,67,65,0,47.37615433949869,47.376154339498683,0,65,-67,0,-47.376154339498683,47.37615433949869,-65,0,0,-67,-47.376154339498697,-47.376154339498683,0,-65,47.376154339498676,-47.376154339498697,71,0,0,71,69,0,50.204581464244875,50.204581464244868,0,69,-71,0,-50.204581464244868,50.204581464244875,-69,0,0,-71,-50.204581464244889,-50.204581464244868,0,-69,50.20458146424486,-50.204581464244889,75,0,0,75,73,0,53.033008588991066,53.033008588991059,0,73,-75,0,-53.033008588991059,53.033008588991066,-73,0,0,-75,-53.033008588991073,-53.033008588991059,0,-73,53.033008588991052,-53.033008588991073,80,0,0,80,77.5,0,56.568542494923804,56.568542494923797,0,77.5,-80,0,-56.568542494923797,56.568542494923804,-77.5,0,0,-80,-56.568542494923818,-56.568542494923797,0,-77.5,56.56854249492379,-56.568542494923818}; + coords->useArray(coordsData,false,CPP_DEALLOC,188,2); + coords->setName(""); + DataArrayInt *conn=DataArrayInt::New(); + const int connData[540]={8,0,1,2,3,4,5,6,7,8,3,2,8,9,6,10,11,12,8,9,8,13,14,11,15,16,17,8,14,13,1,0,16,18,4,19,8,1,20,21,2,22,23,24,5,8,2,21,25,8,24,26,27,10,8,8,25,28,13,27,29,30,15,8,13,28,20,1,30,31,22,18,8,20,32,33,21,34,35,36,23,8,21,33,37,25,36,38,39,26,8,25,37,40,28,39,41,42,29,8,28,40,32,20,42,43,34,31,8,32,44,45,33,46,47,48,35,8,33,45,49,37,48,50,51,38,8,37,49,52,40,51,53,54,41,8,40,52,44,32,54,55,46,43,8,44,56,57,45,58,59,60,47,8,45,57,61,49,60,62,63,50,8,49,61,64,52,63,65,66,53,8,52,64,56,44,66,67,58,55,8,56,68,69,57,70,71,72,59,8,57,69,73,61,72,74,75,62,8,61,73,76,64,75,77,78,65,8,64,76,68,56,78,79,70,67,8,68,80,81,69,82,83,84,71,8,69,81,85,73,84,86,87,74,8,73,85,88,76,87,89,90,77,8,76,88,80,68,90,91,82,79,8,80,92,93,81,94,95,96,83,8,81,93,97,85,96,98,99,86,8,85,97,100,88,99,101,102,89,8,88,100,92,80,102,103,94,91,8,92,104,105,93,106,107,108,95,8,93,105,109,97,108,110,111,98,8,97,109,112,100,111,113,114,101,8,100,112,104,92,114,115,106,103,8,104,116,117,105,118,119,120,107,8,105,117,121,109,120,122,123,110,8,109,121,124,112,123,125,126,113,8,112,124,116,104,126,127,118,115,8,116,128,129,117,130,131,132,119,8,117,129,133,121,132,134,135,122,8,121,133,136,124,135,137,138,125,8,124,136,128,116,138,139,130,127,8,128,140,141,129,142,143,144,131,8,129,141,145,133,144,146,147,134,8,133,145,148,136,147,149,150,137,8,136,148,140,128,150,151,142,139,8,140,152,153,141,154,155,156,143,8,141,153,157,145,156,158,159,146,8,145,157,160,148,159,161,162,149,8,148,160,152,140,162,163,154,151,8,152,164,165,153,166,167,168,155,8,153,165,169,157,168,170,171,158,8,157,169,172,160,171,173,174,161,8,160,172,164,152,174,175,166,163,8,164,176,177,165,178,179,180,167,8,165,177,181,169,180,182,183,170,8,169,181,184,172,183,185,186,173,8,172,184,176,164,186,187,178,175}; + conn->useArray(connData,false,CPP_DEALLOC,540,1); + conn->setName(""); + DataArrayInt *connI=DataArrayInt::New(); + const int connIData[61]={0,9,18,27,36,45,54,63,72,81,90,99,108,117,126,135,144,153,162,171,180,189,198,207,216,225,234,243,252,261,270,279,288,297,306,315,324,333,342,351,360,369,378,387,396,405,414,423,432,441,450,459,468,477,486,495,504,513,522,531,540}; + connI->useArray(connIData,false,CPP_DEALLOC,61,1); + connI->setName(""); + // + MEDCouplingUMesh *m1=MEDCouplingUMesh::New("Fix",2); + m1->setCoords(coords); + m1->setConnectivity(conn,connI,true); + coords->decrRef(); conn->decrRef(); connI->decrRef(); + // + coords=DataArrayDouble::New(); + const double coordsData2[84]={46.5,-2.5,53.5,-2.5,53.5,2.5,46.5,2.5,50,-2.5,53.5,0,50,2.5,46.5,0,60.5,-2.5,60.5,2.5,57,-2.5,60.5,0,57,2.5,53.5,7.5,46.5,7.5,53.5,5,50,7.5,46.5,5,60.5,7.5,60.5,5,57,7.5,-2,47,2,47,2,53,-2,53,0,47,2,50,0,53,-2,50,6,47,6,53,4,47,6,50,4,53,2,59,-2,59,2,56,0,59,-2,56,6,59,6,56,4,59}; + coords->useArray(coordsData2,false,CPP_DEALLOC,42,2); + coords->setName(""); + // connectivity + conn=DataArrayInt::New(); + const int connData2[72]={8,0,1,2,3,4,5,6,7,8,1,8,9,2,10,11,12,5,8,3,2,13,14,6,15,16,17,8,2,9,18,13,12,19,20,15,8,21,22,23,24,25,26,27,28,8,22,29,30,23,31,32,33,26,8,24,23,34,35,27,36,37,38,8,23,30,39,34,33,40,41,36}; + conn->useArray(connData2,false,CPP_DEALLOC,72,1); + conn->setName(""); + connI=DataArrayInt::New(); + const int connIData2[9]={0,9,18,27,36,45,54,63,72}; + connI->useArray(connIData2,false,CPP_DEALLOC,9,1); + connI->setName(""); + MEDCouplingUMesh *m2=MEDCouplingUMesh::New("Mobile",2); + m2->setCoords(coords); + m2->setConnectivity(conn,connI,true); + coords->decrRef(); conn->decrRef(); connI->decrRef(); + // + DataArrayInt *d1=0,*d2=0; + MEDCouplingUMesh *m3=MEDCouplingUMesh::Intersect2DMeshes(m1,m2,1e-10,d1,d2); + CPPUNIT_ASSERT_EQUAL(105,m3->getNumberOfCells()); + CPPUNIT_ASSERT_EQUAL(105,d1->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(105,d2->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(704,m3->getNumberOfNodes()); + // + const double areaExpected[105]={-65.18804756198824,-65.18804756198824,-65.18804756198824,-65.18804756198824,-66.75884388878285,-66.75884388878285,-66.7588438887833,-66.75884388878308,-68.32964021557768,-68.32964021557768,-68.32964021557814,-68.32964021557791,-69.9004365423732,-69.9004365423732,-69.90043654237297,-69.90043654237297,-1.194568659706448,-1.0869994447159463,-142.2316939607081,-144.51326206513068,-144.5132620651309,-1.1945686597064424,-143.3186934054243,-5.002264310862817,-10.0261332846393,-3.9727823117092953,-7.290862524642649,-124.504404940456,-3.9727823117093237,-146.82366506060032,-150.79644737231024,-5.002264310862776,-145.79418306144626,-5.00208651738126,-10.054764051268958,-4.001067863263231,-8.027932154428669,-129.99378209314813,-4.001067863263216,-153.07856481622616,-157.0796326794898,-5.0020865173811915,-152.07754616210832,-5.001928880064381,-10.050590216368969,-4.00098721602491,-8.025810856794209,-136.28350081741684,-4.000987216024939,-159.36183077064402,-163.36281798667005,-5.0019288800643285,-158.36088910660442,-1.2991516319851801,-3.702636830195414,-3.7815130030068254,-6.265364371195623,-0.02516260900254963,-0.6553944641345026,-3.975752765070567,-7.368528340442765,-142.57249927881398,-0.02516260900254963,-3.9757527650706095,-165.64508791977525,-169.64600329384803,-1.299151631985167,-3.7026368301953885,-164.6442148316677,-10.00321285677458,-20.08414323176165,-8.001644468035863,-16.042954878437143,-304.0096070742277,-8.00164446803587,-350.1399180412005,-358.1415625092368,-10.003212856774468,-348.13834965246224,-3.794150313030109,-8.65049239704272,-0.02260276689354157,-0.5885167811200915,-370.2185414798688,-0.022602766893559393,-383.2517009710623,-383.2743037379555,-3.7941503130300576,-379.48015342492505,-408.40704496667513,-408.4070449666742,-408.4070449666742,-408.4070449666742,-433.53978619538975,-433.5397861953902,-433.5397861953911,-433.53978619539066,-458.67252742410983,-458.6725274241094,-458.67252742410983,-458.6725274241089,-608.6835766330232,-608.6835766330232,-608.6835766330232,-608.6835766330241}; + const int expected1[105]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,16,16,17,18,19,19,20,20,20,20,20,21,21,22,23,23,24,24,24,24,24,25,25,26,27,27,28,28,28,28,28,29,29,30,31,31,32,32,32,32,32,32,32,32,32,33,33,33,34,35,35,35,36,36,36,36,36,37,37,38,39,39,40,40,40,40,40,41,41,42,43,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59}; + const int expected2[105]={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,2,-1,-1,-1,0,-1,0,2,4,5,-1,4,-1,-1,0,-1,0,2,4,5,-1,4,-1,-1,0,-1,0,2,4,5,-1,4,-1,-1,0,-1,0,1,2,3,4,5,6,7,-1,4,6,-1,-1,0,1,-1,1,3,6,7,-1,6,-1,-1,1,-1,1,3,6,7,-1,6,-1,-1,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}; + MEDCouplingFieldDouble *f3f=m3->getMeasureField(ON_CELLS); + const double *f3=f3f->getArray()->getConstPointer(); + for(int i=0;i<105;i++) + { + CPPUNIT_ASSERT_DOUBLES_EQUAL(areaExpected[i],f3[i],1e-10); + CPPUNIT_ASSERT_EQUAL(expected1[i],d1->getIJ(i,0)); + CPPUNIT_ASSERT_EQUAL(expected2[i],d2->getIJ(i,0)); + } + // + f3f->decrRef(); + m3->decrRef(); + d1->decrRef(); + d2->decrRef(); + m2->decrRef(); + m1->decrRef(); +} + +void MEDCouplingBasicsTest5::testDAIBuildUnique1() +{ + DataArrayInt *d=DataArrayInt::New(); + const int dData[14]={1,2,2,3,3,3,3,4,5,5,7,7,7,19}; + d->useArray(dData,false,CPP_DEALLOC,14,1); + const int expectedData[7]={1,2,3,4,5,7,19}; + // + DataArrayInt *e=d->buildUnique(); + CPPUNIT_ASSERT_EQUAL(7,e->getNumberOfTuples()); + CPPUNIT_ASSERT_EQUAL(1,e->getNumberOfComponents()); + for(int i=0;i<7;i++) + CPPUNIT_ASSERT_EQUAL(expectedData[i],e->getIJ(i,0)); + // + e->decrRef(); + d->decrRef(); +} + +void MEDCouplingBasicsTest5::testDAIPartitionByDifferentValues1() +{ + const int data[9]={1,0,1,2,0,2,2,-3,2}; + const int expected1[4]={-3,0,1,2}; + const int expected2_0[1]={7}; + const int expected2_1[2]={1,4}; + const int expected2_2[2]={0,2}; + const int expected2_3[4]={3,5,6,8}; + DataArrayInt *d=DataArrayInt::New(); + d->useArray(data,false,CPP_DEALLOC,9,1); + std::vector f; + static const int nbOfOutputsExpected=4; + std::vector e=d->partitionByDifferentValues(f); + d->decrRef(); + CPPUNIT_ASSERT_EQUAL(nbOfOutputsExpected,(int)e.size()); + CPPUNIT_ASSERT_EQUAL(nbOfOutputsExpected,(int)f.size()); + for(int i=0;igetNbOfElems()); + CPPUNIT_ASSERT_EQUAL(2,e[1]->getNbOfElems()); + CPPUNIT_ASSERT_EQUAL(2,e[2]->getNbOfElems()); + CPPUNIT_ASSERT_EQUAL(4,e[3]->getNbOfElems()); + CPPUNIT_ASSERT_EQUAL(1,e[0]->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(1,e[1]->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(1,e[2]->getNumberOfComponents()); + CPPUNIT_ASSERT_EQUAL(1,e[3]->getNumberOfComponents()); + CPPUNIT_ASSERT(std::equal(expected2_0,expected2_0+1,e[0]->begin())); + CPPUNIT_ASSERT(std::equal(expected2_1,expected2_1+2,e[1]->begin())); + CPPUNIT_ASSERT(std::equal(expected2_2,expected2_2+2,e[2]->begin())); + CPPUNIT_ASSERT(std::equal(expected2_3,expected2_3+4,e[3]->begin())); + e[0]->decrRef(); e[1]->decrRef(); e[2]->decrRef(); e[3]->decrRef(); +} diff --git a/src/MEDCoupling/Test/MEDCouplingBasicsTest5.hxx b/src/MEDCoupling/Test/MEDCouplingBasicsTest5.hxx index 0bc8432f6..1ee856333 100644 --- a/src/MEDCoupling/Test/MEDCouplingBasicsTest5.hxx +++ b/src/MEDCoupling/Test/MEDCouplingBasicsTest5.hxx @@ -66,6 +66,9 @@ namespace ParaMEDMEM CPPUNIT_TEST( testUnPolyze3 ); CPPUNIT_TEST( testKrSpatialDiscretization1 ); CPPUNIT_TEST( testDuplicateEachTupleNTimes1 ); + CPPUNIT_TEST( testIntersect2DMeshesTmp5 ); + CPPUNIT_TEST( testDAIBuildUnique1 ); + CPPUNIT_TEST( testDAIPartitionByDifferentValues1 ); CPPUNIT_TEST_SUITE_END(); public: void testUMeshTessellate2D1(); @@ -98,6 +101,9 @@ namespace ParaMEDMEM void testUnPolyze3(); void testKrSpatialDiscretization1(); void testDuplicateEachTupleNTimes1(); + void testIntersect2DMeshesTmp5(); + void testDAIBuildUnique1(); + void testDAIPartitionByDifferentValues1(); }; } diff --git a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py index 4f63e6fd3..bc59a44de 100644 --- a/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingBasicsTest.py @@ -1993,6 +1993,7 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertEqual(5,f.getNumberOfMeshPlacesExpected()); self.assertEqual(0,f.getNbOfGaussLocalization()); f.setGaussLocalizationOnType(NORM_TRI3,_refCoo1,_gsCoo1,_wg1); + f.setGaussLocalizationOnType(NORM_TRI3,_refCoo1,_gsCoo1,_wg1); # not a bug only to check that it works well self.assertRaises(InterpKernelException,f.setGaussLocalizationOnType,NORM_QUAD4,_refCoo1,_gsCoo1,_wg1) self.assertEqual(1,f.getNbOfGaussLocalization()); refCoo2=[ 0.,0., 1.,0., 1.,1., 0.,1. ] @@ -8218,20 +8219,20 @@ class MEDCouplingBasicsTest(unittest.TestCase): m2.translate([0.5,0.5]) # m3,d1,d2=MEDCouplingUMesh.Intersect2DMeshes(m1bis,m2,1e-10) - expected1=[0,1,1,2,2] - expected2=[0,0,1,1,2] - self.assertEqual(5,d1.getNumberOfTuples()); - self.assertEqual(5,d2.getNumberOfTuples()); - self.assertEqual(5,m3.getNumberOfCells()); + expected1=[0,0,1,1,1,2,2,2] + expected2=[0,-1,0,1,-1,1,2,-1] + self.assertEqual(8,d1.getNumberOfTuples()); + self.assertEqual(8,d2.getNumberOfTuples()); + self.assertEqual(8,m3.getNumberOfCells()); self.assertEqual(22,m3.getNumberOfNodes()); self.assertEqual(2,m3.getSpaceDimension()); self.assertEqual(expected1,d1.getValues()); self.assertEqual(expected2,d2.getValues()); - expected3=[5,17,1,16,12,5,18,1,17,13,5,19,2,18,13,5,20,2,19,14,5,21,3,20,14] - expected4=[0,5,10,15,20,25] + expected3=[5,17,1,16,12,5,16,0,4,5,17,12,5,18,1,17,13,5,19,2,18,13,5,17,5,6,19,13,5,20,2,19,14,5,21,3,20,14,5,19,6,7,21,14] + expected4=[0,5,12,17,22,28,33,38,44] expected5=[-1.0,2.0,1.0,2.0,2.0,2.0,4.0,2.0,-1.0,4.0,1.0,4.0,2.0,4.0,4.0,4.0,-0.5,-1.5,1.5,-1.5,2.5,-1.5,4.5,-1.5,-0.5,2.5,1.5,2.5,2.5,2.5,4.5,2.5,-0.5,2.0,1.0,2.5,1.5,2.0,2.0,2.5,2.5,2.0,4.0,2.5] - self.assertEqual(25,m3.getNodalConnectivity().getNumberOfTuples()); - self.assertEqual(6,m3.getNodalConnectivityIndex().getNumberOfTuples()); + self.assertEqual(44,m3.getNodalConnectivity().getNumberOfTuples()); + self.assertEqual(9,m3.getNodalConnectivityIndex().getNumberOfTuples()); self.assertEqual(expected3,m3.getNodalConnectivity().getValues()); self.assertEqual(expected4,m3.getNodalConnectivityIndex().getValues()); for i in xrange(44): @@ -8345,23 +8346,23 @@ class MEDCouplingBasicsTest(unittest.TestCase): m3,d1,d2=MEDCouplingUMesh.Intersect2DMeshes(m1,m2,1e-10) m3.unPolyze() # - expected1=[0,1,1,2,3,3,4,5,5,6,7,7] - expected2=[0,0,1,2,2,3,4,4,5,6,6,7] - self.assertEqual(12,d1.getNumberOfTuples()); - self.assertEqual(12,d2.getNumberOfTuples()); - self.assertEqual(12,m3.getNumberOfCells()); - self.assertEqual(88,m3.getNumberOfNodes()); + expected1=[0,1,1,1,2,3,3,3,4,5,5,5,6,7,7,7] + expected2=[0,0,1,-1,2,2,3,-1,4,4,5,-1,6,6,7,-1] + self.assertEqual(16,d1.getNumberOfTuples()); + self.assertEqual(16,d2.getNumberOfTuples()); + self.assertEqual(16,m3.getNumberOfCells()); + self.assertEqual(104,m3.getNumberOfNodes()); self.assertEqual(2,m3.getSpaceDimension()); self.assertEqual(expected1,d1.getValues()); self.assertEqual(expected2,d2.getValues()); - expected3=[6,28,1,25,44,45,46,8,26,1,28,27,47,48,49,50,8,40,2,26,27,51,52,53,54,6,28,25,5,55,56,57,8,28,5,32,31,58,59,60,61,8,32,6,41,31,62,63,64,65,6,25,37,5,66,67,68,8,32,5,37,36,69,70,71,72,8,42,6,32,36,73,74,75,76,6,1,37,25,77,78,79,8,37,1,26,38,80,81,82,83,8,26,2,43,38,84,85,86,87] - expected4=[0,7,16,25,32,41,50,57,66,75,82,91,100] - expected5=[0.,0.,1.,0.,1.5,0.,0.,1.,0.,1.5,-1.,0.,-1.5,0.,0.,-1.,0.,-1.5,0.5,0.,1.25,0.,0.7071067811865476,0.7071067811865476,1.0606601717798214,1.0606601717798214,0.,0.5,0.,1.25,-0.7071067811865476,0.7071067811865476,-1.0606601717798214,1.0606601717798214,-0.5,0.,-1.25,0.,-0.7071067811865476,-0.7071067811865476,-1.0606601717798214,-1.0606601717798214,0.,-0.5,0.,-1.25,0.7071067811865476,-0.7071067811865476,1.0606601717798214,-1.0606601717798214,0.,0.,1.1,0.,1.1,1.,0.,1.,1.7,0.,1.7,1.,-1.1,1.,-1.1,0.,-1.7,0.,-1.7,1.,-1.7,-1.,-1.1,-1.,0.,-1.,1.1,-1.,1.7,-1.,1.118033988749895,1.,-1.118033988749895,1.,-1.118033988749895,-1.,1.118033988749895,-1.,0.7071067811865477,0.7071067811865476,0.5,0.,0.,0.5,1.05,0.,0.7071067811865475,0.7071067811865477,0.55,1.,1.1,0.5,1.4012585384440737,0.535233134659635,1.3,0.,1.1,0.5,1.1090169943749475,1.,0.,0.5,-0.5,0.,-0.7071067811865477,0.7071067811865476,-0.7071067811865475,0.7071067811865477,-1.05,0.,-1.1,0.5,-0.55,1.,-1.3,0.,-1.4012585384440737,0.5352331346596344,-1.1090169943749475,1.,-1.1,0.5,0.,-0.5,-0.7071067811865475,-0.7071067811865477,-0.5,0.,-1.05,0.,-0.7071067811865478,-0.7071067811865475,-0.55,-1.,-1.1,-0.5,-1.4012585384440732,-0.5352331346596354,-1.3,0.,-1.1,-0.5,-1.1090169943749475,-1.,0.7071067811865475,-0.7071067811865477,0.,-0.5,0.5,0.,0.7071067811865477,-0.7071067811865475,1.05,0.,1.1,-0.5,0.55,-1.,1.3,0.,1.4012585384440737,-0.535233134659635,1.1090169943749475,-1.,1.1,-0.5] - self.assertEqual(100,m3.getNodalConnectivity().getNumberOfTuples()); - self.assertEqual(13,m3.getNodalConnectivityIndex().getNumberOfTuples()); + expected3=[6,28,1,25,44,45,46,8,26,1,28,27,47,48,49,50,8,40,2,26,27,51,52,53,54,8,28,4,40,27,55,56,57,58,6,28,25,5,59,60,61,8,28,5,32,31,62,63,64,65,8,32,6,41,31,66,67,68,69,8,41,4,28,31,70,71,72,73,6,25,37,5,74,75,76,8,32,5,37,36,77,78,79,80,8,42,6,32,36,81,82,83,84,8,37,8,42,36,85,86,87,88,6,1,37,25,89,90,91,8,37,1,26,38,92,93,94,95,8,26,2,43,38,96,97,98,99,8,43,8,37,38,100,101,102,103] + expected4=[0,7,16,25,34,41,50,59,68,75,84,93,102,109,118,127,136] + expected5=[0.,0.,1.,0.,1.5,0.,0.,1.,0.,1.5,-1.,0.,-1.5,0.,0.,-1.,0.,-1.5,0.5,0.,1.25,0.,0.7071067811865476,0.7071067811865476,1.0606601717798214,1.0606601717798214,0.,0.5,0.,1.25,-0.7071067811865476,0.7071067811865476,-1.0606601717798214,1.0606601717798214,-0.5,0.,-1.25,0.,-0.7071067811865476,-0.7071067811865476,-1.0606601717798214,-1.0606601717798214,0.,-0.5,0.,-1.25,0.7071067811865476,-0.7071067811865476,1.0606601717798214,-1.0606601717798214,0.,0.,1.1,0.,1.1,1.,0.,1.,1.7,0.,1.7,1.,-1.1,1.,-1.1,0.,-1.7,0.,-1.7,1.,-1.7,-1.,-1.1,-1.,0.,-1.,1.1,-1.,1.7,-1.,1.118033988749895,1.,-1.118033988749895,1.,-1.118033988749895,-1.,1.118033988749895,-1.,0.7071067811865477,0.7071067811865476,0.5,0.,0.,0.5,1.05,0.,0.7071067811865475,0.7071067811865477,0.55,1.,1.1,0.5,1.4012585384440737,0.535233134659635,1.3,0.,1.1,0.5,1.1090169943749475,1.,0.,1.25,0.6123724356957946,1.369306393762915,1.1090169943749475,1.,0.55,1.,0.,0.5,-0.5,0.,-0.7071067811865477,0.7071067811865476,-0.7071067811865475,0.7071067811865477,-1.05,0.,-1.1,0.5,-0.55,1.,-1.3,0.,-1.4012585384440737,0.5352331346596344,-1.1090169943749475,1.,-1.1,0.5,-0.6123724356957941,1.3693063937629155,0.,1.25,-0.55,1.,-1.1090169943749475,1.,0.,-0.5,-0.7071067811865475,-0.7071067811865477,-0.5,0.,-1.05,0.,-0.7071067811865478,-0.7071067811865475,-0.55,-1.,-1.1,-0.5,-1.4012585384440734,-0.5352331346596354,-1.3,0.,-1.1,-0.5,-1.1090169943749475,-1.,0.,-1.25,-0.6123724356957945,-1.369306393762915,-1.1090169943749475,-1.,-0.55,-1.,0.7071067811865475,-0.7071067811865477,0.,-0.5,0.5,0.,0.7071067811865477,-0.7071067811865475,1.05,0.,1.1,-0.5,0.55,-1.,1.3,0.,1.4012585384440737,-0.535233134659635,1.1090169943749475,-1.,1.1,-0.5,0.6123724356957946,-1.369306393762915,0.,-1.25,0.55,-1.,1.1090169943749475,-1.0] + self.assertEqual(136,m3.getNodalConnectivity().getNumberOfTuples()); + self.assertEqual(17,m3.getNodalConnectivityIndex().getNumberOfTuples()); self.assertEqual(expected3,m3.getNodalConnectivity().getValues()); self.assertEqual(expected4,m3.getNodalConnectivityIndex().getValues()); - for i in xrange(176): + for i in xrange(208): self.assertAlmostEqual(expected5[i],m3.getCoords().getIJ(0,i),12); pass pass @@ -8445,23 +8446,23 @@ class MEDCouplingBasicsTest(unittest.TestCase): m3,d1,d2=MEDCouplingUMesh.Intersect2DMeshes(m2,m1,1e-10) m3.unPolyze() # - expected1=[0,0,1,2,2,3,4,4,5,6,6,7] - expected2=[0,1,1,2,3,3,4,5,5,6,7,7] - self.assertEqual(12,d1.getNumberOfTuples()); - self.assertEqual(12,d2.getNumberOfTuples()); - self.assertEqual(12,m3.getNumberOfCells()); - self.assertEqual(88,m3.getNumberOfNodes()); + expected1=[0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7] + expected2=[0,1,1,-1,2,3,3,-1,4,5,5,-1,6,7,7,-1] + self.assertEqual(16,d1.getNumberOfTuples()); + self.assertEqual(16,d2.getNumberOfTuples()); + self.assertEqual(16,m3.getNumberOfCells()); + self.assertEqual(104,m3.getNumberOfNodes()); self.assertEqual(2,m3.getSpaceDimension()); self.assertEqual(expected1,d1.getValues()); self.assertEqual(expected2,d2.getValues()); - expected3=[6,16,15,18,44,45,46,8,18,2,1,16,47,48,49,50,8,17,1,2,40,51,52,53,54,6,18,15,20,55,56,57,8,20,7,6,18,58,59,60,61,8,41,6,7,21,62,63,64,65,6,20,15,22,66,67,68,8,22,11,7,20,69,70,71,72,8,21,7,11,42,73,74,75,76,6,22,15,16,77,78,79,8,16,1,13,22,80,81,82,83,8,43,13,1,17,84,85,86,87] - expected4=[0,7,16,25,32,41,50,57,66,75,82,91,100] - expected5=[0.,0.,1.1,0.,1.1,1.,0.,1.,1.7,0.,1.7,1.,-1.1,1.,-1.1,0.,-1.7,0.,-1.7,1.,-1.7,-1.,-1.1,-1.,0.,-1.,1.1,-1.,1.7,-1.,0.,0.,1.,0.,1.5,0.,0.,1.,0.,1.5,-1.,0.,-1.5,0.,0.,-1.,0.,-1.5,0.5,0.,1.25,0.,0.7071067811865476,0.7071067811865476,1.0606601717798214,1.0606601717798214,0.,0.5,0.,1.25,-0.7071067811865476,0.7071067811865476,-1.0606601717798214,1.0606601717798214,-0.5,0.,-1.25,0.,-0.7071067811865476,-0.7071067811865476,-1.0606601717798214,-1.0606601717798214,0.,-0.5,0.,-1.25,0.7071067811865476,-0.7071067811865476,1.0606601717798214,-1.0606601717798214,1.1180339887498951,1.,-1.1180339887498951,1.,-1.1180339887498951,-1.,1.1180339887498951,-1.,0.5,0.,0.,0.5,0.7071067811865477,0.7071067811865476,0.55,1.,1.1,0.5,1.05,0.,0.7071067811865477,0.7071067811865477,1.3,0.,1.1,0.5,1.1090169943749475,1.,1.4012585384440737,0.535233134659635,0.,0.5,-0.5,0.,-0.7071067811865477,0.7071067811865476,-1.05,0.,-1.1,0.5,-0.55,1.,-0.7071067811865477,0.7071067811865477,-1.1090169943749475,1.,-1.1,0.5,-1.3,0.,-1.4012585384440737,0.5352331346596344,-0.5,0.,0.,-0.5,-0.7071067811865475,-0.7071067811865477,-0.55,-1.,-1.1,-0.5,-1.05,0.,-0.7071067811865479,-0.7071067811865476,-1.3,0.,-1.1,-0.5,-1.1090169943749475,-1.,-1.4012585384440734,-0.5352331346596354,0.,-0.5,0.5,0.,0.7071067811865475,-0.7071067811865477,1.05,0.,1.1,-0.5,0.55,-1.,0.7071067811865477,-0.7071067811865476,1.1090169943749475,-1.,1.1,-0.5,1.3,0.,1.4012585384440737,-0.535233134659635] - self.assertEqual(100,m3.getNodalConnectivity().getNumberOfTuples()); - self.assertEqual(13,m3.getNodalConnectivityIndex().getNumberOfTuples()); + expected3=[6,16,15,18,44,45,46,8,18,2,1,16,47,48,49,50,8,17,1,2,40,51,52,53,54,8,40,5,4,17,55,56,57,58,6,18,15,20,59,60,61,8,20,7,6,18,62,63,64,65,8,41,6,7,21,66,67,68,69,8,21,8,9,41,70,71,72,73,6,20,15,22,74,75,76,8,22,11,7,20,77,78,79,80,8,21,7,11,42,81,82,83,84,8,42,10,8,21,85,86,87,88,6,22,15,16,89,90,91,8,16,1,13,22,92,93,94,95,8,43,13,1,17,96,97,98,99,8,17,4,14,43,100,101,102,103] + expected4=[0,7,16,25,34,41,50,59,68,75,84,93,102,109,118,127,136] + expected5=[0.,0.,1.1, 0.,1.1,1.,0.,1.,1.7,0.,1.7,1.,-1.1,1.,-1.1,0.,-1.7,0.,-1.7,1.,-1.7,-1.,-1.1,-1.,0.,-1.,1.1,-1.,1.7,-1.,0.,0.,1.,0.,1.5,0.,0.,1.,0.,1.5,-1.,0.,-1.5,0.,0.,-1.,0.,-1.5,0.5,0.,1.25,0.,0.7071067811865476,0.7071067811865476,1.0606601717798214,1.0606601717798214,0.,0.5,0.,1.25,-0.7071067811865476,0.7071067811865476,-1.0606601717798214,1.0606601717798214,-0.5,0.,-1.25,0.,-0.7071067811865476,-0.7071067811865476,-1.0606601717798214,-1.0606601717798214,0.,-0.5,0.,-1.25,0.7071067811865476,-0.7071067811865476,1.0606601717798214,-1.0606601717798214,1.1180339887498951,1.,-1.1180339887498951,1.,-1.1180339887498951,-1.,1.1180339887498951,-1.,0.5,0.,0.,0.5,0.7071067811865477,0.7071067811865476,0.55,1.,1.1,0.5,1.05,0.,0.7071067811865477,0.7071067811865475,1.3,0.,1.1,0.5,1.1090169943749475,1.,1.4012585384440737,0.535233134659635,1.4090169943749475,1.,1.7,0.5,1.6,0.,1.4012585384440737,0.535233134659635,0.,0.5,-0.5,0.,-0.7071067811865477,0.7071067811865476,-1.05,0.,-1.1,0.5,-0.55,1.,-0.7071067811865478,0.7071067811865475,-1.1090169943749475,1.,-1.1,0.5,-1.3,0.,-1.4012585384440737,0.5352331346596344,-1.6,0.,-1.7,0.5,-1.4090169943749475,1.,-1.4012585384440737,0.5352331346596344,-0.5,0.,0.,-0.5,-0.7071067811865475,-0.7071067811865477,-0.55,-1.,-1.1,-0.5,-1.05,0.,-0.7071067811865475,-0.7071067811865477,-1.3,0.,-1.1,-0.5,-1.1090169943749475,-1.,-1.4012585384440734,-0.5352331346596354,-1.4090169943749475,-1.,-1.7,-0.5,-1.6,0.,-1.4012585384440732,-0.5352331346596354,0.,-0.5,0.5,0.,0.7071067811865475,-0.7071067811865477,1.05,0.,1.1,-0.5,0.55,-1.,0.7071067811865475,-0.7071067811865477,1.1090169943749475,-1.,1.1,-0.5,1.3,0.,1.4012585384440737,-0.535233134659635,1.6,0.,1.7,-0.5,1.4090169943749475,-1.,1.4012585384440737,-0.535233134659635] + self.assertEqual(136,m3.getNodalConnectivity().getNumberOfTuples()); + self.assertEqual(17,m3.getNodalConnectivityIndex().getNumberOfTuples()); self.assertEqual(expected3,m3.getNodalConnectivity().getValues()); self.assertEqual(expected4,m3.getNodalConnectivityIndex().getValues()); - for i in xrange(176): + for i in xrange(208): self.assertAlmostEqual(expected5[i],m3.getCoords().getIJ(0,i),12); pass pass @@ -9243,6 +9244,54 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertRaises(InterpKernelException,DataArrayDouble.New,vals,7,2); pass + def testSwigDADOp9(self): + l1=[(1.,2.,3),(4.,5.,6.),(7.,8.,9.),[10.,11.,12.]] + da1=DataArrayDouble(l1,4,3) + self.assertEqual(4,da1.getNumberOfTuples()); + self.assertEqual(3,da1.getNumberOfComponents()); + da2=DataArrayDouble(12) ; da2.iota(1.) ; da2.rearrange(3) + self.assertTrue(da2.isEqual(da1,1e-12)) + self.assertRaises(InterpKernelException,DataArrayDouble.New,l1,3,4); + da3=DataArrayDouble(l1,4) + self.assertTrue(da3.isEqual(da1,1e-12)) + self.assertRaises(InterpKernelException,DataArrayDouble.New,l1,3); + self.assertRaises(InterpKernelException,DataArrayDouble.New,l1,5); + l1=[(1.,2.,3),(4.,(5.),((6.))),(7.,8.,9.),[10.,11.,12.]] + da1=DataArrayDouble(l1,4,3) + self.assertEqual(4,da1.getNumberOfTuples()); + self.assertEqual(3,da1.getNumberOfComponents()); + da2=DataArrayDouble(12) ; da2.iota(1.) ; da2.rearrange(3) + self.assertTrue(da2.isEqual(da1,1e-12)) + self.assertRaises(InterpKernelException,DataArrayDouble.New,l1,3,4); + da3=DataArrayDouble(l1,4) + self.assertTrue(da3.isEqual(da1,1e-12)) + self.assertRaises(InterpKernelException,DataArrayDouble.New,l1,3); + self.assertRaises(InterpKernelException,DataArrayDouble.New,l1,5); + # + l1=[(1,2,3),(4,5,6),(7,8,9),[10,11,12]] + da1=DataArrayInt(l1,4,3) + self.assertEqual(4,da1.getNumberOfTuples()); + self.assertEqual(3,da1.getNumberOfComponents()); + da2=DataArrayInt(12) ; da2.iota(1) ; da2.rearrange(3) + self.assertTrue(da2.isEqual(da1)) + self.assertRaises(InterpKernelException,DataArrayInt.New,l1,3,4); + da3=DataArrayInt(l1,4) + self.assertTrue(da3.isEqual(da1)) + self.assertRaises(InterpKernelException,DataArrayInt.New,l1,3); + self.assertRaises(InterpKernelException,DataArrayInt.New,l1,5); + l1=[(1,[2],3),(4,[(5)],6),((([7])),8,9),[10,11,12]] + da1=DataArrayInt(l1,4,3) + self.assertEqual(4,da1.getNumberOfTuples()); + self.assertEqual(3,da1.getNumberOfComponents()); + da2=DataArrayInt(12) ; da2.iota(1) ; da2.rearrange(3) + self.assertTrue(da2.isEqual(da1)) + self.assertRaises(InterpKernelException,DataArrayInt.New,l1,3,4); + da3=DataArrayInt(l1,4) + self.assertTrue(da3.isEqual(da1)) + self.assertRaises(InterpKernelException,DataArrayInt.New,l1,3); + self.assertRaises(InterpKernelException,DataArrayInt.New,l1,5); + pass + def testRenumberNodesInConn1(self): mesh2DCoords=[-0.3,-0.3,0., 0.2,-0.3,0., 0.7,-0.3,0., -0.3,0.2,0., 0.2,0.2,0., 0.7,0.2,0., -0.3,0.7,0., 0.2,0.7,0., 0.7,0.7,0. ] mesh2DConn=[1,4,2, 4,5,2, 0,3,4,1, 6,7,4,3, 7,8,5,4] @@ -10230,6 +10279,124 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertEqual(d.getValues(),[1,2,0,1,2,0,1,2,0,1]) pass + def testIntersect2DMeshesTmp5(self): + coords=DataArrayDouble.New([41,0,42,0,0,42,0,41,41.5,0,29.698484809834998,29.698484809834994,0,41.5,28.991378028648452,28.991378028648445,-42,0,-41,0,-29.698484809834994,29.698484809834998,-41.5,0,-28.991378028648445,28.991378028648452,0,-42,0,-41,-29.698484809835001,-29.698484809834994,0,-41.5,-28.991378028648455,-28.991378028648445,29.698484809834987,-29.698484809835001,28.991378028648441,-28.991378028648455,43,0,0,43,42.5,0,30.405591591021544,30.40559159102154,0,42.5,-43,0,-30.40559159102154,30.405591591021544,-42.5,0,0,-43,-30.405591591021551,-30.40559159102154,0,-42.5,30.405591591021537,-30.405591591021551,44,0,0,44,43.5,0,31.112698372208094,31.112698372208087,0,43.5,-44,0,-31.112698372208087,31.112698372208094,-43.5,0,0,-44,-31.112698372208097,-31.112698372208087,0,-43.5,31.112698372208083,-31.112698372208097,45,0,0,45,44.5,0,31.81980515339464,31.819805153394636,0,44.5,-45,0,-31.819805153394636,31.81980515339464,-44.5,0,0,-45,-31.819805153394647,-31.819805153394636,0,-44.5,31.819805153394629,-31.819805153394647,47,0,0,47,46,0,33.234018715767739,33.234018715767732,0,46,-47,0,-33.234018715767732,33.234018715767739,-46,0,0,-47,-33.234018715767739,-33.234018715767732,0,-46,33.234018715767725,-33.234018715767739,49,0,0,49,48,0,34.648232278140831,34.648232278140824,0,48,-49,0,-34.648232278140824,34.648232278140831,-48,0,0,-49,-34.648232278140839,-34.648232278140824,0,-48,34.648232278140817,-34.648232278140839,51,0,0,51,50,0,36.062445840513924,36.062445840513924,0,50,-51,0,-36.062445840513924,36.062445840513924,-50,0,0,-51,-36.062445840513931,-36.062445840513924,0,-50,36.062445840513917,-36.062445840513931,53,0,0,53,52,0,37.476659402887023,37.476659402887016,0,52,-53,0,-37.476659402887016,37.476659402887023,-52,0,0,-53,-37.47665940288703,-37.476659402887016,0,-52,37.476659402887009,-37.47665940288703,55,0,0,55,54,0,38.890872965260115,38.890872965260108,0,54,-55,0,-38.890872965260108,38.890872965260115,-54,0,0,-55,-38.890872965260122,-38.890872965260108,0,-54,38.890872965260101,-38.890872965260122,59,0,0,59,57,0,41.719300090006307,41.7193000900063,0,57,-59,0,-41.7193000900063,41.719300090006307,-57,0,0,-59,-41.719300090006314,-41.7193000900063,0,-57,41.719300090006293,-41.719300090006314,63,0,0,63,61,0,44.547727214752499,44.547727214752491,0,61,-63,0,-44.547727214752491,44.547727214752499,-61,0,0,-63,-44.547727214752506,-44.547727214752491,0,-61,44.547727214752484,-44.547727214752506,67,0,0,67,65,0,47.37615433949869,47.376154339498683,0,65,-67,0,-47.376154339498683,47.37615433949869,-65,0,0,-67,-47.376154339498697,-47.376154339498683,0,-65,47.376154339498676,-47.376154339498697,71,0,0,71,69,0,50.204581464244875,50.204581464244868,0,69,-71,0,-50.204581464244868,50.204581464244875,-69,0,0,-71,-50.204581464244889,-50.204581464244868,0,-69,50.20458146424486,-50.204581464244889,75,0,0,75,73,0,53.033008588991066,53.033008588991059,0,73,-75,0,-53.033008588991059,53.033008588991066,-73,0,0,-75,-53.033008588991073,-53.033008588991059,0,-73,53.033008588991052,-53.033008588991073,80,0,0,80,77.5,0,56.568542494923804,56.568542494923797,0,77.5,-80,0,-56.568542494923797,56.568542494923804,-77.5,0,0,-80,-56.568542494923818,-56.568542494923797,0,-77.5,56.56854249492379,-56.568542494923818],188,2) + conn=DataArrayInt.New([8,0,1,2,3,4,5,6,7,8,3,2,8,9,6,10,11,12,8,9,8,13,14,11,15,16,17,8,14,13,1,0,16,18,4,19,8,1,20,21,2,22,23,24,5,8,2,21,25,8,24,26,27,10,8,8,25,28,13,27,29,30,15,8,13,28,20,1,30,31,22,18,8,20,32,33,21,34,35,36,23,8,21,33,37,25,36,38,39,26,8,25,37,40,28,39,41,42,29,8,28,40,32,20,42,43,34,31,8,32,44,45,33,46,47,48,35,8,33,45,49,37,48,50,51,38,8,37,49,52,40,51,53,54,41,8,40,52,44,32,54,55,46,43,8,44,56,57,45,58,59,60,47,8,45,57,61,49,60,62,63,50,8,49,61,64,52,63,65,66,53,8,52,64,56,44,66,67,58,55,8,56,68,69,57,70,71,72,59,8,57,69,73,61,72,74,75,62,8,61,73,76,64,75,77,78,65,8,64,76,68,56,78,79,70,67,8,68,80,81,69,82,83,84,71,8,69,81,85,73,84,86,87,74,8,73,85,88,76,87,89,90,77,8,76,88,80,68,90,91,82,79,8,80,92,93,81,94,95,96,83,8,81,93,97,85,96,98,99,86,8,85,97,100,88,99,101,102,89,8,88,100,92,80,102,103,94,91,8,92,104,105,93,106,107,108,95,8,93,105,109,97,108,110,111,98,8,97,109,112,100,111,113,114,101,8,100,112,104,92,114,115,106,103,8,104,116,117,105,118,119,120,107,8,105,117,121,109,120,122,123,110,8,109,121,124,112,123,125,126,113,8,112,124,116,104,126,127,118,115,8,116,128,129,117,130,131,132,119,8,117,129,133,121,132,134,135,122,8,121,133,136,124,135,137,138,125,8,124,136,128,116,138,139,130,127,8,128,140,141,129,142,143,144,131,8,129,141,145,133,144,146,147,134,8,133,145,148,136,147,149,150,137,8,136,148,140,128,150,151,142,139,8,140,152,153,141,154,155,156,143,8,141,153,157,145,156,158,159,146,8,145,157,160,148,159,161,162,149,8,148,160,152,140,162,163,154,151,8,152,164,165,153,166,167,168,155,8,153,165,169,157,168,170,171,158,8,157,169,172,160,171,173,174,161,8,160,172,164,152,174,175,166,163,8,164,176,177,165,178,179,180,167,8,165,177,181,169,180,182,183,170,8,169,181,184,172,183,185,186,173,8,172,184,176,164,186,187,178,175],540) + connI=DataArrayInt.New([0,9,18,27,36,45,54,63,72,81,90,99,108,117,126,135,144,153,162,171,180,189,198,207,216,225,234,243,252,261,270,279,288,297,306,315,324,333,342,351,360,369,378,387,396,405,414,423,432,441,450,459,468,477,486,495,504,513,522,531,540],61) + # + m1=MEDCouplingUMesh.New("Fix",2); + m1.setCoords(coords); + m1.setConnectivity(conn,connI,True); + # + coords=DataArrayDouble([46.5,-2.5,53.5,-2.5,53.5,2.5,46.5,2.5,50,-2.5,53.5,0,50,2.5,46.5,0,60.5,-2.5,60.5,2.5,57,-2.5,60.5,0,57,2.5,53.5,7.5,46.5,7.5,53.5,5,50,7.5,46.5,5,60.5,7.5,60.5,5,57,7.5,-2,47,2,47,2,53,-2,53,0,47,2,50,0,53,-2,50,6,47,6,53,4,47,6,50,4,53,2,59,-2,59,2,56,0,59,-2,56,6,59,6,56,4,59],42,2) + # connectivity + conn=DataArrayInt([8,0,1,2,3,4,5,6,7,8,1,8,9,2,10,11,12,5,8,3,2,13,14,6,15,16,17,8,2,9,18,13,12,19,20,15,8,21,22,23,24,25,26,27,28,8,22,29,30,23,31,32,33,26,8,24,23,34,35,27,36,37,38,8,23,30,39,34,33,40,41,36],72); + conn.setName(""); + connI=DataArrayInt([0,9,18,27,36,45,54,63,72],9) + m2=MEDCouplingUMesh.New("Mobile",2); + m2.setCoords(coords); + m2.setConnectivity(conn,connI,True); + # + m3,d1,d2=MEDCouplingUMesh.Intersect2DMeshes(m1,m2,1e-10); + self.assertEqual(105,m3.getNumberOfCells()); + self.assertEqual(105,d1.getNumberOfTuples()); + self.assertEqual(105,d2.getNumberOfTuples()); + self.assertEqual(704,m3.getNumberOfNodes()); + # + areaExpected=[-65.18804756198824,-65.18804756198824,-65.18804756198824,-65.18804756198824,-66.75884388878285,-66.75884388878285,-66.7588438887833,-66.75884388878308,-68.32964021557768,-68.32964021557768,-68.32964021557814,-68.32964021557791,-69.9004365423732,-69.9004365423732,-69.90043654237297,-69.90043654237297,-1.194568659706448,-1.0869994447159463,-142.2316939607081,-144.51326206513068,-144.5132620651309,-1.1945686597064424,-143.3186934054243,-5.002264310862817,-10.0261332846393,-3.9727823117092953,-7.290862524642649,-124.504404940456,-3.9727823117093237,-146.82366506060032,-150.79644737231024,-5.002264310862776,-145.79418306144626,-5.00208651738126,-10.054764051268958,-4.001067863263231,-8.027932154428669,-129.99378209314813,-4.001067863263216,-153.07856481622616,-157.0796326794898,-5.0020865173811915,-152.07754616210832,-5.001928880064381,-10.050590216368969,-4.00098721602491,-8.025810856794209,-136.28350081741684,-4.000987216024939,-159.36183077064402,-163.36281798667005,-5.0019288800643285,-158.36088910660442,-1.2991516319851801,-3.702636830195414,-3.7815130030068254,-6.265364371195623,-0.02516260900254963,-0.6553944641345026,-3.975752765070567,-7.368528340442765,-142.57249927881398,-0.02516260900254963,-3.9757527650706095,-165.64508791977525,-169.64600329384803,-1.299151631985167,-3.7026368301953885,-164.6442148316677,-10.00321285677458,-20.08414323176165,-8.001644468035863,-16.042954878437143,-304.0096070742277,-8.00164446803587,-350.1399180412005,-358.1415625092368,-10.003212856774468,-348.13834965246224,-3.794150313030109,-8.65049239704272,-0.02260276689354157,-0.5885167811200915,-370.2185414798688,-0.022602766893559393,-383.2517009710623,-383.2743037379555,-3.7941503130300576,-379.48015342492505,-408.40704496667513,-408.4070449666742,-408.4070449666742,-408.4070449666742,-433.53978619538975,-433.5397861953902,-433.5397861953911,-433.53978619539066,-458.67252742410983,-458.6725274241094,-458.67252742410983,-458.6725274241089,-608.6835766330232,-608.6835766330232,-608.6835766330232,-608.6835766330241] + expected1=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,16,16,17,18,19,19,20,20,20,20,20,21,21,22,23,23,24,24,24,24,24,25,25,26,27,27,28,28,28,28,28,29,29,30,31,31,32,32,32,32,32,32,32,32,32,33,33,33,34,35,35,35,36,36,36,36,36,37,37,38,39,39,40,40,40,40,40,41,41,42,43,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59] + expected2=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,2,-1,-1,-1,0,-1,0,2,4,5,-1,4,-1,-1,0,-1,0,2,4,5,-1,4,-1,-1,0,-1,0,2,4,5,-1,4,-1,-1,0,-1,0,1,2,3,4,5,6,7,-1,4,6,-1,-1,0,1,-1,1,3,6,7,-1,6,-1,-1,1,-1,1,3,6,7,-1,6,-1,-1,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1] + f3=m3.getMeasureField(ON_CELLS).getArray().getValues(); + for i in xrange(105): + self.assertAlmostEqual(areaExpected[i],f3[i],10) + pass + self.assertEqual(expected1,d1.getValues()) + self.assertEqual(expected2,d2.getValues()) + pass + + def testDAIBuildUnique1(self): + d=DataArrayInt([1,2,2,3,3,3,3,4,5,5,7,7,7,19]) + e=d.buildUnique() + self.assertTrue(e.isEqual(DataArrayInt([1,2,3,4,5,7,19]))) + pass + + def testDAIPartitionByDifferentValues1(self): + d=DataArrayInt([1,0,1,2,0,2,2,-3,2]) + expected=[[-3,[7]],[0,[1,4]],[1,[0,2]],[2,[3,5,6,8]]] + for i,elt in enumerate(zip(*d.partitionByDifferentValues())): + self.assertEqual(expected[i][0],elt[1]) + self.assertEqual(expected[i][1],elt[0].getValues()) + pass + pass + + def testFieldGaussMultiDiscPerType1(self): + coords=DataArrayDouble([0.,0.,0.,1.,1.,1.,1.,0.,0.,0.5,0.5,1.,1.,0.5,0.5,0.],8,2) + mQ8=MEDCouplingUMesh("",2) ; mQ8.setCoords(coords) + mQ8.allocateCells(1) + mQ8.insertNextCell(NORM_QUAD8,range(8)) + mQ8.finishInsertingCells() + mQ4=MEDCouplingUMesh("",2) ; mQ4.setCoords(coords) + mQ4.allocateCells(1) + mQ4.insertNextCell(NORM_QUAD4,range(4)) + mQ4.finishInsertingCells() + mT3=MEDCouplingUMesh("",2) ; mT3.setCoords(coords) + mT3.allocateCells(1) + mT3.insertNextCell(NORM_TRI3,range(3)) + mT3.finishInsertingCells() + + tr=[[0.,0.],[2.,0.], [0.,2.],[2.,2.],[4.,2.],[6.,2.],[8.,2.],[10.,2.],[12.,2.],[0.,4.],[2.,4.],[4.,4.],[6.,4.],[8.,4.],[10.,4.],[12.,4.],[14.,4.],[16.,4.],[18.,4.],[20.,4.],[22.,4.]] + ms=2*[mQ4]+7*[mQ8]+11*[mT3] + ms[:]=(elt.deepCpy() for elt in ms) + for m,t in zip(ms,tr): + d=m.getCoords() ; d+= t + pass + m=MEDCouplingUMesh.MergeUMeshes(ms) + f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,NO_TIME) + f.setMesh(m) + # throw because cell 0,1 are QUAD4 and cell 3 is QUAD8 + self.assertRaises(InterpKernelException,f.setGaussLocalizationOnCells,[0,1,3],[0.,0.,1.,0.,1.,1.,0.,1.],[0.3,0.3,0.7,0.7],[0.8,0.2]) + f.setGaussLocalizationOnCells([0,1],[0.,0.,1.,0.,1.,1.,0.,1.],[0.3,0.3,0.7,0.7],[0.8,0.2]) + f.setGaussLocalizationOnCells([3,2,5],[0.,0.,1.,0.,1.,1.,0.,1.,0.5,0.,1.,0.5,0.5,1.,0.,0.5],[0.3,0.3,0.7,0.7,0.9,0.9],[0.8,0.05,0.15]) + f.setGaussLocalizationOnCells([4,6,8,7],[0.,0.,1.,0.,1.,1.,0.,1.,0.5,0.,1.,0.5,0.5,1.,0.,0.5],[0.3,0.3,0.7,0.7,0.9,0.9,-0.1,0.3],[0.7,0.05,0.15,0.1]) + f.setGaussLocalizationOnCells([9,10,11,12,13],[0.,0.,1.,0.,1.,1.],[0.4,0.4],[1.]) + f.setGaussLocalizationOnCells([14,15,16,17,18,19],[0.,0.,1.,0.,1.,1.],[0.4,0.4,0.14,0.16],[0.22,0.78]) + self.assertEqual(46,f.getNumberOfTuplesExpected()) + vals=DataArrayDouble.New(46*3,1) ; vals.iota(7.7) ; vals.rearrange(3) + f.setArray(vals) + f.checkCoherency() + #f.getLocalizationOfDiscr() + self.assertRaises(InterpKernelException,f.getGaussLocalizationIdOfOneType,NORM_QUAD8) #throw because several loc + self.assertEqual([1,2],f.getGaussLocalizationIdsOfOneType(NORM_QUAD8)) + self.assertEqual([0,0,1,1,2,1,2,2,2,3,3,3,3,3,4,4,4,4,4,4],f.getDiscretization().getArrayOfDiscIds().getValues()) + fc=f[[1,2,3,8]] + fc.checkCoherency() + self.assertTrue(DataArrayDouble([13.7,14.7,15.7,16.7,17.7,18.7,19.7,20.7,21.7,22.7,23.7,24.7,25.7,26.7,27.7,28.7,29.7,30.7,31.7,32.7,33.7,34.7,35.7,36.7,82.7,83.7,84.7,85.7,86.7,87.7,88.7,89.7,90.7,91.7,92.7,93.7],12,3).isEqual(fc.getArray(),1e-10)) + fc.renumberCells([3,2,0,1]) + self.assertTrue(DataArrayDouble([28.7, 29.7, 30.7, 31.7, 32.7, 33.7, 34.7, 35.7, 36.7, 82.7, 83.7, 84.7, 85.7, 86.7, 87.7, 88.7, 89.7, 90.7, 91.7, 92.7, 93.7, 19.7, 20.7, 21.7, 22.7, 23.7, 24.7, 25.7, 26.7, 27.7, 13.7, 14.7, 15.7, 16.7, 17.7, 18.7],12,3).isEqual(fc.getArray(),1e-10)) + fc.getArray() + pass + + def testSwigRotate(self): + d=DataArrayDouble([1.,2.,3.,4.,6.,5.],2,3) + MEDCouplingPointSet.Rotate3DAlg([0.,0.,0.],[0.,1.,0.],1.5707963267948966,d) + self.assertTrue(d.isEqual(DataArrayDouble([3.,2.,-1.,5.,6.,-4.],2,3),1e-12)) + d=DataArrayDouble([1.,2.,3.,4.,6.,5.],3,2) + MEDCouplingPointSet.Rotate2DAlg([0.,0.],1.5707963267948966,d) + self.assertTrue(d.isEqual(DataArrayDouble([-2.,1.,-4.,3.,-5.,6.],3,2),1e-12)) + pass + + def testSwigCMeshProtection(self): + cm=MEDCouplingCMesh() + self.assertRaises(InterpKernelException,cm.setCoordsAt,0,DataArrayDouble([4.,4.5,6.,7.],2,2)) + self.assertRaises(InterpKernelException,cm.setCoords,DataArrayDouble([4.,4.5,6.,7.],2,2)) + pass + + def testSwigCellsInBoundingBox1(self): + m3D=MEDCouplingDataForTest.build3DExtrudedUMesh_1()[0] + self.assertTrue(m3D.getCellsInBoundingBox([(0,3),(0,3),(0,1)],-1e-12).isEqual(DataArrayInt([0,1,2,3,4,5]))) + self.assertRaises(InterpKernelException,m3D.getCellsInBoundingBox,[(0,3,0),(3,0,1)],-1e-12) + pass + def setUp(self): pass pass diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index 085293b0c..48c3ec0e3 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -78,6 +78,8 @@ using namespace INTERP_KERNEL; %feature("docstring"); %newobject ParaMEDMEM::MEDCouplingFieldDiscretization::getOffsetArr; +%newobject ParaMEDMEM::MEDCouplingFieldDiscretization::clone; +%newobject ParaMEDMEM::MEDCouplingFieldDiscretization::clonePart; %newobject ParaMEDMEM::MEDCouplingField::buildMeasureField; %newobject ParaMEDMEM::MEDCouplingField::getLocalizationOfDiscr; %newobject ParaMEDMEM::MEDCouplingField::computeTupleIdsToSelectFromCellIds; @@ -162,6 +164,7 @@ using namespace INTERP_KERNEL; %newobject ParaMEDMEM::DataArrayInt::buildUnion; %newobject ParaMEDMEM::DataArrayInt::buildSubstraction; %newobject ParaMEDMEM::DataArrayInt::buildIntersection; +%newobject ParaMEDMEM::DataArrayInt::buildUnique; %newobject ParaMEDMEM::DataArrayInt::deltaShiftIndex; %newobject ParaMEDMEM::DataArrayInt::buildExplicitArrByRanges; %newobject ParaMEDMEM::DataArrayInt::findRangeIdForEachTuple; @@ -328,6 +331,7 @@ using namespace INTERP_KERNEL; %feature("unref") MEDCouplingMultiFields "$this->decrRef();" %rename(assign) *::operator=; +%ignore ParaMEDMEM::MEDCouplingVersionMajMinRel; %ignore ParaMEDMEM::RefCountObject::decrRef; %ignore ParaMEDMEM::MemArray::operator=; %ignore ParaMEDMEM::MemArray::operator[]; @@ -439,6 +443,7 @@ namespace ParaMEDMEM virtual DataArrayInt *simplexize(int policy) throw(INTERP_KERNEL::Exception); static MEDCouplingMesh *MergeMeshes(const MEDCouplingMesh *mesh1, const MEDCouplingMesh *mesh2) throw(INTERP_KERNEL::Exception); static int GetDimensionOfGeometricType(INTERP_KERNEL::NormalizedCellType type) throw(INTERP_KERNEL::Exception); + static const char *GetReprOfGeometricType(INTERP_KERNEL::NormalizedCellType type) throw(INTERP_KERNEL::Exception); %extend { std::string __str__() const @@ -844,10 +849,53 @@ namespace ParaMEDMEM std::set ret=self->getDifferentValues(); return convertIntArrToPyList3(ret); } + + PyObject *partitionByDifferentValues() const throw(INTERP_KERNEL::Exception) + { + std::vector ret1; + std::vector ret0=self->partitionByDifferentValues(ret1); + std::size_t sz=ret0.size(); + PyObject *pyRet=PyTuple_New(2); + PyObject *pyRet0=PyList_New((int)sz); + PyObject *pyRet1=PyList_New((int)sz); + for(std::size_t i=0;i val2; + const int *inp=convertObjToPossibleCpp1_Safe(li,sw,sz,val1,val2); + return self->clonePart(inp,inp+sz); + } +} + +%extend ParaMEDMEM::MEDCouplingFieldDiscretizationPerCell +{ + PyObject *getArrayOfDiscIds() const + { + DataArrayInt *ret=const_cast(self->getArrayOfDiscIds()); + if(ret) + ret->incrRef(); + return SWIG_NewPointerObj(SWIG_as_voidptr(ret),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ); + } } %ignore ParaMEDMEM::DataArray::getInfoOnComponents; %ignore ParaMEDMEM::DataArrayInt::getDifferentValues; +%ignore ParaMEDMEM::DataArrayInt::partitionByDifferentValues; +%ignore ParaMEDMEM::MEDCouplingFieldDiscretizationPerCell::getArrayOfDiscIds; +%ignore ParaMEDMEM::MEDCouplingFieldDiscretization::clonePart; %include "MEDCouplingMemArray.hxx" %include "NormalizedUnstructuredMesh.hxx" @@ -1201,16 +1249,46 @@ namespace ParaMEDMEM for(int i=0;i c=convertPyToNewDblArr2(center,&sz); + int sw,nbNodes=0; + double val0; ParaMEDMEM::DataArrayDouble *val1=0; ParaMEDMEM::DataArrayDoubleTuple *val2=0; + std::vector val3; + const double *coo=convertObjToPossibleCpp5_Safe2(coords,sw,val0,val1,val2,val3, + "Rotate2DAlg",2,true,nbNodes); + if(sw!=2 && sw!=3) + throw INTERP_KERNEL::Exception("Invalid call to MEDCouplingPointSet::Rotate2DAlg : try another overload method !"); + ParaMEDMEM::MEDCouplingPointSet::Rotate2DAlg(c,angle,nbNodes,const_cast(coo)); + } + static void Rotate3DAlg(PyObject *center, PyObject *vect, double angle, int nbNodes, PyObject *coords) throw(INTERP_KERNEL::Exception) { int sz,sz2; INTERP_KERNEL::AutoPtr c=convertPyToNewDblArr2(center,&sz); INTERP_KERNEL::AutoPtr coo=convertPyToNewDblArr2(coords,&sz); - double *v=convertPyToNewDblArr2(vect,&sz2); + INTERP_KERNEL::AutoPtr v=convertPyToNewDblArr2(vect,&sz2); ParaMEDMEM::MEDCouplingPointSet::Rotate3DAlg(c,v,angle,nbNodes,coo); for(int i=0;i c=convertPyToNewDblArr2(center,&sz); + int sw,nbNodes=0; + double val0; ParaMEDMEM::DataArrayDouble *val1=0; ParaMEDMEM::DataArrayDoubleTuple *val2=0; + std::vector val3; + const double *coo=convertObjToPossibleCpp5_Safe2(coords,sw,val0,val1,val2,val3, + "Rotate3DAlg",3,true,nbNodes); + if(sw!=2 && sw!=3) + throw INTERP_KERNEL::Exception("Invalid call to MEDCouplingPointSet::Rotate3DAlg : try another overload method !"); + INTERP_KERNEL::AutoPtr v=convertPyToNewDblArr2(vect,&sz2); + ParaMEDMEM::MEDCouplingPointSet::Rotate3DAlg(c,v,angle,nbNodes,const_cast(coo)); + } } }; @@ -1352,6 +1430,7 @@ namespace ParaMEDMEM MEDCouplingFieldDouble *getWarpField() const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *getSkewField() const throw(INTERP_KERNEL::Exception); DataArrayInt *convexEnvelop2D() throw(INTERP_KERNEL::Exception); + std::string cppRepr() const throw(INTERP_KERNEL::Exception); static MEDCouplingUMesh *Build0DMeshFromCoords(DataArrayDouble *da) throw(INTERP_KERNEL::Exception); static MEDCouplingUMesh *MergeUMeshes(const MEDCouplingUMesh *mesh1, const MEDCouplingUMesh *mesh2) throw(INTERP_KERNEL::Exception); static MEDCouplingUMesh *MergeUMeshesOnSameCoords(const MEDCouplingUMesh *mesh1, const MEDCouplingUMesh *mesh2) throw(INTERP_KERNEL::Exception); @@ -2720,10 +2799,8 @@ namespace ParaMEDMEM if(nbOfCompo<0) throw INTERP_KERNEL::Exception("DataArrayDouble::New : should be a positive number of components !"); MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::New(); - double *tmp=new double[nbOfTuples*nbOfCompo]; - try { fillArrayWithPyListDbl(elt0,tmp,nbOfTuples*nbOfCompo,0.,true); } - catch(INTERP_KERNEL::Exception& e) { delete [] tmp; throw e; } - ret->useArray(tmp,true,CPP_DEALLOC,nbOfTuples,nbOfCompo); + std::vector tmp=fillArrayWithPyListDbl2(elt0,nbOfTuples,nbOfCompo); + ret->alloc(nbOfTuples,nbOfCompo); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); ret->incrRef(); return ret; } @@ -2733,10 +2810,9 @@ namespace ParaMEDMEM else {//DataArrayDouble.New([1.,3.,4.],3) MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::New(); - double *tmp=new double[nbOfTuples]; - try { fillArrayWithPyListDbl(elt0,tmp,nbOfTuples,0.,true); } - catch(INTERP_KERNEL::Exception& e) { delete [] tmp; throw e; } - ret->useArray(tmp,true,CPP_DEALLOC,nbOfTuples,1); + int tmpp1=-1; + std::vector tmp=fillArrayWithPyListDbl2(elt0,nbOfTuples,tmpp1); + ret->alloc(nbOfTuples,tmpp1); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); ret->incrRef(); return ret; } @@ -2746,16 +2822,10 @@ namespace ParaMEDMEM } else {// DataArrayDouble.New([1.,3.,4.]) - int szz=-1; - if(PyList_Check(elt0)) - szz=PyList_Size(elt0); - else - szz=PyTuple_Size(elt0); MEDCouplingAutoRefCountObjectPtr ret=DataArrayDouble::New(); - double *tmp=new double[szz]; - try { fillArrayWithPyListDbl(elt0,tmp,szz,0.,true); } - catch(INTERP_KERNEL::Exception& e) { delete [] tmp; throw e; } - ret->useArray(tmp,true,CPP_DEALLOC,szz,1); + int tmpp1=-1,tmpp2=-1; + std::vector tmp=fillArrayWithPyListDbl2(elt0,tmpp1,tmpp2); + ret->alloc(tmpp1,tmpp2); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); ret->incrRef(); return ret; } @@ -4440,10 +4510,8 @@ namespace ParaMEDMEM if(nbOfCompo<0) throw INTERP_KERNEL::Exception("DataArrayInt::New : should be a positive number of components !"); MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); - int *tmp=new int[nbOfTuples*nbOfCompo]; - try { fillArrayWithPyListInt(elt0,tmp,nbOfTuples*nbOfCompo,0,true); } - catch(INTERP_KERNEL::Exception& e) { delete [] tmp; throw e; } - ret->useArray(tmp,true,CPP_DEALLOC,nbOfTuples,nbOfCompo); + std::vector tmp=fillArrayWithPyListInt2(elt0,nbOfTuples,nbOfCompo); + ret->alloc(nbOfTuples,nbOfCompo); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); ret->incrRef(); return ret; } @@ -4453,10 +4521,9 @@ namespace ParaMEDMEM else {//DataArrayInt.New([1,3,4],3) MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); - int *tmp=new int[nbOfTuples]; - try { fillArrayWithPyListInt(elt0,tmp,nbOfTuples,0,true); } - catch(INTERP_KERNEL::Exception& e) { delete [] tmp; throw e; } - ret->useArray(tmp,true,CPP_DEALLOC,nbOfTuples,1); + int tmpp1=-1; + std::vector tmp=fillArrayWithPyListInt2(elt0,nbOfTuples,tmpp1); + ret->alloc(nbOfTuples,tmpp1); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); ret->incrRef(); return ret; } @@ -4466,16 +4533,10 @@ namespace ParaMEDMEM } else {// DataArrayInt.New([1,3,4]) - int szz=-1; - if(PyList_Check(elt0)) - szz=PyList_Size(elt0); - else - szz=PyTuple_Size(elt0); MEDCouplingAutoRefCountObjectPtr ret=DataArrayInt::New(); - int *tmp=new int[szz]; - try { fillArrayWithPyListInt(elt0,tmp,szz,0,true); } - catch(INTERP_KERNEL::Exception& e) { delete [] tmp; throw e; } - ret->useArray(tmp,true,CPP_DEALLOC,szz,1); + int tmpp1=-1,tmpp2=-1; + std::vector tmp=fillArrayWithPyListInt2(elt0,tmpp1,tmpp2); + ret->alloc(tmpp1,tmpp2); std::copy(tmp.begin(),tmp.end(),ret->getPointer()); ret->incrRef(); return ret; } @@ -4616,7 +4677,7 @@ namespace ParaMEDMEM return ret; } - void transformWithIndArr(PyObject *li) + void transformWithIndArr(PyObject *li) throw(INTERP_KERNEL::Exception) { void *da=0; int res1=SWIG_ConvertPtr(li,&da,SWIGTYPE_p_ParaMEDMEM__DataArrayInt, 0 | 0 ); @@ -6160,6 +6221,8 @@ namespace ParaMEDMEM int getNbOfGaussLocalization() const throw(INTERP_KERNEL::Exception); int getGaussLocalizationIdOfOneCell(int cellId) const throw(INTERP_KERNEL::Exception); const MEDCouplingGaussLocalization& getGaussLocalization(int locId) const throw(INTERP_KERNEL::Exception); + int getGaussLocalizationIdOfOneType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception); + void setDiscretization(MEDCouplingFieldDiscretization *newDisc); %extend { PyObject *getMesh() const throw(INTERP_KERNEL::Exception) { @@ -6177,6 +6240,12 @@ namespace ParaMEDMEM return convertFieldDiscretization(ret,SWIG_POINTER_OWN | 0 ); } + PyObject *getGaussLocalizationIdsOfOneType(INTERP_KERNEL::NormalizedCellType type) const throw(INTERP_KERNEL::Exception) + { + std::set ret=self->getGaussLocalizationIdsOfOneType(type); + return convertIntArrToPyList3(ret); + } + PyObject *isEqualIfNotWhy(const MEDCouplingField *other, double meshPrec, double valsPrec) const throw(INTERP_KERNEL::Exception) { std::string ret1; @@ -7057,6 +7126,19 @@ namespace ParaMEDMEM }; } +%inline %{ + PyObject *MEDCouplingVersionMajMinRel() + { + int tmp0=0,tmp1=0,tmp2=0; + MEDCouplingVersionMajMinRel(tmp0,tmp1,tmp2); + PyObject *res = PyList_New(3); + PyList_SetItem(res,0,SWIG_From_int(tmp0)); + PyList_SetItem(res,1,SWIG_From_int(tmp1)); + PyList_SetItem(res,2,SWIG_From_int(tmp2)); + return res; + } +%} + %pythoncode %{ import os __filename=os.environ.get('PYTHONSTARTUP') diff --git a/src/MEDCoupling_Swig/MEDCouplingRemapperTest.py b/src/MEDCoupling_Swig/MEDCouplingRemapperTest.py index 1e7727e3f..5c8042f5e 100644 --- a/src/MEDCoupling_Swig/MEDCouplingRemapperTest.py +++ b/src/MEDCoupling_Swig/MEDCouplingRemapperTest.py @@ -122,6 +122,169 @@ class MEDCouplingBasicsTest(unittest.TestCase): self.assertAlmostEqual(valuesExpected[i0],values[i0],12); pass pass + + def testPrepareUC(self): + # 1D + coords=DataArrayDouble([0.,0.5,0.7]) + src=MEDCouplingUMesh("",1) ; src.setCoords(coords) + src.allocateCells(2) ; src.insertNextCell(NORM_SEG2,[0,1]) ; src.insertNextCell(NORM_SEG2,[1,2]) ; src.finishInsertingCells() + trg=MEDCouplingCMesh() ; arr=DataArrayDouble([-0.7,-0.1,0.2,0.7,2.,2.3]) + trg.setCoordsAt(0,arr) + fieldSrc=MEDCouplingFieldDouble(ON_CELLS,NO_TIME) ; fieldSrc.setMesh(src) ; arrSrc=DataArrayDouble([10.,30.]) + fieldSrc.setNature(Integral) ; fieldSrc.setArray(arrSrc) + rem=MEDCouplingRemapper() + rem.prepare(src,trg,"P0P0") + trgField=rem.transferField(fieldSrc,-7.) + expected1=[-7.,4.,36.,-7.,-7.] + self.assertEqual(5,trgField.getArray().getNumberOfTuples()) + self.assertEqual(5,len(expected1)) + for i,val in enumerate(expected1): + self.assertAlmostEqual(expected1[i],trgField.getArray().getIJ(i,0),12); + pass + # 2D + coords=DataArrayDouble([0.,0.,0.,1.,1.,1.,1.,0.,0.5,-0.2],5,2) + src=MEDCouplingUMesh("",2) ; src.setCoords(coords) + src.allocateCells(2) ; src.insertNextCell(NORM_TRI3,[0,1,2]) ; src.insertNextCell(NORM_TRI3,[3,4,0]) ; src.finishInsertingCells() + trg=MEDCouplingCMesh() ; arr=DataArrayDouble([-0.7,-0.1,0.2,0.7,2.,2.3]) + trg.setCoordsAt(0,arr) ; trg.setCoordsAt(1,arr) + fieldSrc=MEDCouplingFieldDouble(ON_CELLS,NO_TIME) ; fieldSrc.setMesh(src) ; arrSrc=DataArrayDouble([10.,30.]) + fieldSrc.setNature(Integral) ; fieldSrc.setArray(arrSrc) + rem=MEDCouplingRemapper() + rem.prepare(src,trg,"P0P0") + trgField=rem.transferField(fieldSrc,-7.) + expected2=[-7.,-7.,7.35,0.15,-7.,-7.,2.8,14.85,5.25,-7.,-7.,2.,2.5,-7.,-7.,-7.,1.2,3.,0.9,-7.,-7.,-7.,-7.,-7.,-7.] + self.assertEqual(25,trgField.getArray().getNumberOfTuples()) + self.assertEqual(25,len(expected2)) + for i,val in enumerate(expected2): + self.assertAlmostEqual(expected2[i],trgField.getArray().getIJ(i,0),12); + pass + # 3D + coords=DataArrayDouble([0.,0.,0.,0.,1.,0.,1.,1.,0.,1.,0.,0.,0.5,-0.2,0.,0.1,0.8,1.,0.5,0.,1.],7,3) + src=MEDCouplingUMesh("",3) ; src.setCoords(coords) + src.allocateCells(2) ; src.insertNextCell(NORM_TETRA4,[0,1,2,5]) ; src.insertNextCell(NORM_TETRA4,[3,4,0,6]) ; src.finishInsertingCells() + trg=MEDCouplingCMesh() ; arr=DataArrayDouble([-0.7,-0.1,0.2,0.7,2.,2.3]) ; arr2=DataArrayDouble([-0.7,0.2,0.6,1.2,2.]) + trg.setCoordsAt(0,arr) ; trg.setCoordsAt(1,arr) ; trg.setCoordsAt(2,arr2) + src.checkCoherency2(1e-10) + trg.checkCoherency() + fieldSrc=MEDCouplingFieldDouble(ON_CELLS,NO_TIME) ; fieldSrc.setMesh(src) ; arrSrc=DataArrayDouble([10.,30.]) + fieldSrc.setNature(Integral) ; fieldSrc.setArray(arrSrc) + rem=MEDCouplingRemapper() + rem.prepare(src,trg,"P0P0") + trgField=rem.transferField(fieldSrc,-7.) + expected3=[-7.,-7.,2.925,0.015,-7.,-7.,0.9392,8.595,2.265,-7.,-7.,1.1008,1.1192,-7.,-7.,-7.,0.6392,1.6408,0.2808,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,0.81,-7.,-7.,-7.,0.1208,11.55,0.96,-7.,-7.,1.1752,0.6592,-7.,-7.,-7.,0.8512,1.7744,0.0192,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,1.92,-7.,-7.,-7.,0.12578571428571422,0.007314285714285673,-7.,-7.,-7.,0.3189253968253971,0.1879746031746033,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.,-7.] + self.assertEqual(100,trgField.getArray().getNumberOfTuples()) + self.assertEqual(100,len(expected3)) + for i,val in enumerate(expected3): + self.assertAlmostEqual(expected3[i],trgField.getArray().getIJ(i,0),12); + pass + pass + + def testPrepareCU(self): + # 1D + coords=DataArrayDouble([0.,0.5,0.7]) + trg=MEDCouplingUMesh("",1) ; trg.setCoords(coords) + trg.allocateCells(2) ; trg.insertNextCell(NORM_SEG2,[0,1]) ; trg.insertNextCell(NORM_SEG2,[1,2]) ; trg.finishInsertingCells() + src=MEDCouplingCMesh() ; arr=DataArrayDouble([-0.7,-0.1,0.2,0.7,2.,2.3]) + src.setCoordsAt(0,arr) + fieldSrc=MEDCouplingFieldDouble(ON_CELLS,NO_TIME) ; fieldSrc.setMesh(src) ; arrTrg=DataArrayDouble([10.,30.,40.,70.,80.]) + fieldSrc.setNature(Integral) ; fieldSrc.setArray(arrTrg) + rem=MEDCouplingRemapper() + rem.prepare(src,trg,"P0P0") + trgField=rem.transferField(fieldSrc,-7.) + expected1=[44.,16.] + self.assertEqual(2.,trgField.getArray().getNumberOfTuples()) + self.assertEqual(2,len(expected1)) + for i,val in enumerate(expected1): + self.assertAlmostEqual(expected1[i],trgField.getArray().getIJ(i,0),12); + pass + # 2D + coords=DataArrayDouble([0.,0.,0.,1.,1.,1.,1.,0.,0.5,-0.2],5,2) + trg=MEDCouplingUMesh("",2) ; trg.setCoords(coords) + trg.allocateCells(2) ; trg.insertNextCell(NORM_TRI3,[0,1,2]) ; trg.insertNextCell(NORM_TRI3,[3,4,0]) ; trg.finishInsertingCells() + src=MEDCouplingCMesh() ; arr=DataArrayDouble([-0.7,-0.1,0.2,0.7,2.,2.3]) + src.setCoordsAt(0,arr) ; src.setCoordsAt(1,arr) + fieldSrc=MEDCouplingFieldDouble(ON_CELLS,NO_TIME) ; fieldSrc.setMesh(src) ; arrSrc=DataArrayDouble([10.,30.,40.,70.,80.,110.,130.,140.,170.,180.,210.,230.,240.,270.,280.,310.,330.,340.,370.,380.,410.,430.,440.,470.,480.]) + fieldSrc.setNature(Integral) ; fieldSrc.setArray(arrSrc) + rem=MEDCouplingRemapper() + rem.prepare(src,trg,"P0P0") + trgField=rem.transferField(fieldSrc,-7.) + expected2=[441.3050624589086,68.69529914529915] + self.assertEqual(2,trgField.getArray().getNumberOfTuples()) + self.assertEqual(2,len(expected2)) + for i,val in enumerate(expected2): + self.assertAlmostEqual(expected2[i],trgField.getArray().getIJ(i,0),12); + pass + # 3D + coords=DataArrayDouble([0.,0.,0.,0.,1.,0.,1.,1.,0.,1.,0.,0.,0.5,-0.2,0.,0.1,0.8,1.,0.5,0.,1.],7,3) + trg=MEDCouplingUMesh("",3) ; trg.setCoords(coords) + trg.allocateCells(2) ; trg.insertNextCell(NORM_TETRA4,[0,1,2,5]) ; trg.insertNextCell(NORM_TETRA4,[3,4,0,6]) ; trg.finishInsertingCells() + src=MEDCouplingCMesh() ; arr=DataArrayDouble([-0.7,-0.1,0.2,0.7,2.,2.3]) ; arr2=DataArrayDouble([-0.7,0.2,0.6,1.2,2.]) + src.setCoordsAt(0,arr) ; src.setCoordsAt(1,arr) ; src.setCoordsAt(2,arr2) + trg.checkCoherency2(1e-10) + src.checkCoherency() + fieldSrc=MEDCouplingFieldDouble(ON_CELLS,NO_TIME) ; fieldSrc.setMesh(src) ; arrSrc=DataArrayDouble(100) ; arrSrc.iota(7.7) + fieldSrc.setNature(Integral) ; fieldSrc.setArray(arrSrc) + rem=MEDCouplingRemapper() + rem.prepare(src,trg,"P0P0") + trgField=rem.transferField(fieldSrc,-7.) + expected3=[39.635196634558845,12.13422356758468] + self.assertEqual(2,trgField.getArray().getNumberOfTuples()) + self.assertEqual(2,len(expected3)) + for i,val in enumerate(expected3): + self.assertAlmostEqual(expected3[i],trgField.getArray().getIJ(i,0),12); + pass + pass + + def testPrepareCC(self): + # 1D + src=MEDCouplingCMesh() ; arr=DataArrayDouble([-0.7,-0.1,0.2,0.7,2.,2.3]) + src.setCoordsAt(0,arr) + trg=MEDCouplingCMesh() ; arr=DataArrayDouble([-0.9,-0.1,0.15]) + trg.setCoordsAt(0,arr) + fieldSrc=MEDCouplingFieldDouble(ON_CELLS,NO_TIME) ; fieldSrc.setMesh(src) ; arrTrg=DataArrayDouble([10.,30.,40.,70.,80.]) + fieldSrc.setNature(Integral) ; fieldSrc.setArray(arrTrg) + rem=MEDCouplingRemapper() + rem.prepare(src,trg,"P0P0") + trgField=rem.transferField(fieldSrc,-7.) + expected1=[10.,25.] + self.assertEqual(2.,trgField.getArray().getNumberOfTuples()) + self.assertEqual(2,len(expected1)) + for i,val in enumerate(expected1): + self.assertAlmostEqual(expected1[i],trgField.getArray().getIJ(i,0),12); + pass + # 2D + src=MEDCouplingCMesh() ; arr=DataArrayDouble([-0.7,-0.1,0.2,0.7,2.,2.3]) + src.setCoordsAt(0,arr) ; src.setCoordsAt(1,arr) + trg=MEDCouplingCMesh() ; arr=DataArrayDouble([-0.9,-0.1,0.15]) + trg.setCoordsAt(0,arr) ; trg.setCoordsAt(1,arr) + fieldSrc=MEDCouplingFieldDouble(ON_CELLS,NO_TIME) ; fieldSrc.setMesh(src) ; arrSrc=DataArrayDouble([10.,30.,40.,70.,80.,110.,130.,140.,170.,180.,210.,230.,240.,270.,280.,310.,330.,340.,370.,380.,410.,430.,440.,470.,480.]) + fieldSrc.setNature(Integral) ; fieldSrc.setArray(arrSrc) + rem=MEDCouplingRemapper() + rem.prepare(src,trg,"P0P0") + trgField=rem.transferField(fieldSrc,-7.) + expected2=[10.,25.,91.66666666666666,90.27777777777777] + self.assertEqual(4,trgField.getArray().getNumberOfTuples()) + self.assertEqual(4,len(expected2)) + for i,val in enumerate(expected2): + self.assertAlmostEqual(expected2[i],trgField.getArray().getIJ(i,0),12); + pass + # 3D + src=MEDCouplingCMesh() ; arr=DataArrayDouble([-0.7,-0.1,0.2,0.7,2.,2.3]) + src.setCoordsAt(0,arr) ; src.setCoordsAt(1,arr) ; src.setCoordsAt(2,arr) + trg=MEDCouplingCMesh() ; arr=DataArrayDouble([-0.9,-0.1,0.15]) + trg.setCoordsAt(0,arr) ; trg.setCoordsAt(1,arr) ; trg.setCoordsAt(2,arr) + fieldSrc=MEDCouplingFieldDouble(ON_CELLS,NO_TIME) ; fieldSrc.setMesh(src) ; arrSrc=DataArrayDouble(125) ; arrSrc.iota(7.7) + fieldSrc.setNature(Integral) ; fieldSrc.setArray(arrSrc) ; fieldSrc.checkCoherency() + rem=MEDCouplingRemapper() + rem.prepare(src,trg,"P0P0") + trgField=rem.transferField(fieldSrc,-7.) + expected3=[7.7, 7.249999999999999, 10.583333333333332, 9.513888888888886, 27.25, 23.40277777777777, 26.180555555555546, 22.39583333333333] + self.assertEqual(8,trgField.getArray().getNumberOfTuples()) + self.assertEqual(8,len(expected3)) + for i,val in enumerate(expected3): + self.assertAlmostEqual(expected3[i],trgField.getArray().getIJ(i,0),12); + pass + pass def build2DSourceMesh_1(self): sourceCoords=[-0.3,-0.3, 0.7,-0.3, -0.3,0.7, 0.7,0.7] diff --git a/src/MEDCoupling_Swig/MEDCouplingTypemaps.i b/src/MEDCoupling_Swig/MEDCouplingTypemaps.i index 98aad204d..c16812429 100644 --- a/src/MEDCoupling_Swig/MEDCouplingTypemaps.i +++ b/src/MEDCoupling_Swig/MEDCouplingTypemaps.i @@ -346,7 +346,133 @@ static void convertPyToNewIntArr4(PyObject *pyLi, int recurseLev, int nbOfSubPar throw INTERP_KERNEL::Exception("convertPyToNewIntArr4 : not a list nor a tuple recursively !"); } +static void checkFillArrayWithPyList(int size1, int size2, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception) +{ + if(nbOfTuples==-1) + { + if(nbOfComp==-1) { nbOfTuples=size1; nbOfComp=size2; } + else { if(nbOfComp==size2) { nbOfTuples=size1; } else + { + std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components"; + oss << " whereas nb of components expected is " << nbOfComp << " !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } } + } + else + { + if(nbOfComp!=-1) + { + if((nbOfTuples!=size1 || nbOfComp!=size2)) + { + if(size2!=1 || size1!=nbOfComp*nbOfTuples) + { + std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components"; + oss << " whereas nb of tuples expected is " << nbOfTuples << " and number of components expected is " << nbOfComp << " !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + } + else + { + if(nbOfTuples==size1) + nbOfComp=size2; + else + { + std::ostringstream oss; oss << "fillArrayWithPyListDbl2 : mismatch between nb of elemts : Input has " << size1 << " tuples and " << size2 << " components"; + oss << " whereas nb of tuples expected is " << nbOfTuples << " !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + } +} + +static void fillArrayWithPyListInt3(PyObject *pyLi, int& nbOfElt, std::vector& ret) +{ + static const char MSG[]="fillArrayWithPyListInt3 : It appears that the input list or tuple is composed by elts having different sizes !"; + if(PyInt_Check(pyLi)) + { + long val=PyInt_AS_LONG(pyLi); + if(nbOfElt==-1) + nbOfElt=1; + else + if(nbOfElt!=1) + throw INTERP_KERNEL::Exception(MSG); + ret.push_back(val); + } + else if(PyList_Check(pyLi)) + { + int size=PyList_Size(pyLi); + int tmp=0; + for(int i=0;i fillArrayWithPyListInt2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception) +{ + std::vector ret; + int size1=-1,size2=-1; + if(PyList_Check(pyLi)) + { + size1=PyList_Size(pyLi); + for(int i=0;i fillArrayWithPyListInt2 + */ static void fillArrayWithPyListInt(PyObject *pyLi, int *arrToFill, int sizeOfArray, int dftVal, bool chckSize) throw(INTERP_KERNEL::Exception) { if(PyList_Check(pyLi)) @@ -492,6 +618,104 @@ static double *convertPyToNewDblArr2(PyObject *pyLi, int *size) throw(INTERP_KER throw INTERP_KERNEL::Exception("convertPyToNewDblArr2 : not a list"); } +static void fillArrayWithPyListDbl3(PyObject *pyLi, int& nbOfElt, std::vector& ret) +{ + static const char MSG[]="fillArrayWithPyListDbl3 : It appears that the input list or tuple is composed by elts having different sizes !"; + if(PyFloat_Check(pyLi)) + { + if(nbOfElt==-1) + nbOfElt=1; + else + if(nbOfElt!=1) + throw INTERP_KERNEL::Exception(MSG); + double val=PyFloat_AS_DOUBLE(pyLi); + ret.push_back(val); + } + else if(PyInt_Check(pyLi)) + { + long val0=PyInt_AS_LONG(pyLi); + double val=val0; + if(nbOfElt==-1) + nbOfElt=1; + else + if(nbOfElt!=1) + throw INTERP_KERNEL::Exception(MSG); + ret.push_back(val); + } + else if(PyList_Check(pyLi)) + { + int size=PyList_Size(pyLi); + int tmp=0; + for(int i=0;i fillArrayWithPyListDbl2(PyObject *pyLi, int& nbOfTuples, int& nbOfComp) throw(INTERP_KERNEL::Exception) +{ + std::vector ret; + int size1=-1,size2=-1; + if(PyList_Check(pyLi)) + { + size1=PyList_Size(pyLi); + for(int i=0;i fillArrayWithPyListDbl2 + */ static void fillArrayWithPyListDbl(PyObject *pyLi, double *arrToFill, int sizeOfArray, double dftVal, bool chckSize) throw(INTERP_KERNEL::Exception) { if(PyList_Check(pyLi)) @@ -557,7 +781,7 @@ static void fillArrayWithPyListDbl(PyObject *pyLi, double *arrToFill, int sizeOf return ; } else - throw INTERP_KERNEL::Exception("convertPyToNewIntArr : not a list"); + throw INTERP_KERNEL::Exception("fillArrayWithPyListDbl : not a list nor a tuple"); } //convertFromPyObjVectorOfObj(pyLi,SWIGTYPE_p_ParaMEDMEM__MEDCouplingUMesh,"MEDCouplingUMesh") @@ -586,7 +810,6 @@ static void convertFromPyObjVectorOfObj(PyObject *pyLi, swig_type_info *ty, cons for(int i=0;i ret=fillArrayWithPyListDbl2(value,tmp1,tmp2); + sw=4; + f=ret; + return &f[0]; } - return &f[0]; + catch(INTERP_KERNEL::Exception& e) { throw e; } } void *argp; int status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0); @@ -1409,3 +1594,83 @@ static const double *convertObjToPossibleCpp5_Safe2(PyObject *value, int& sw, do } throw INTERP_KERNEL::Exception("4 types accepted : integer, double, DataArrayDouble, DataArrayDoubleTuple"); } + +/*! + * if python int -> cpp int sw=1 + * if python list[int] -> cpp vector sw=2 + * if python tuple[int] -> cpp vector sw=2 + * if python DataArrayInt -> cpp DataArrayInt sw=3 + * if python DataArrayIntTuple -> cpp DataArrayIntTuple sw=4 + * + * switch between (int,vector,DataArrayInt) + */ +static const int *convertObjToPossibleCpp1_Safe(PyObject *value, int& sw, int& sz, int& iTyypp, std::vector& stdvecTyypp) throw(INTERP_KERNEL::Exception) +{ + sw=-1; + if(PyInt_Check(value)) + { + iTyypp=(int)PyInt_AS_LONG(value); + sw=1; sz=1; + return &iTyypp; + } + if(PyTuple_Check(value)) + { + int size=PyTuple_Size(value); + stdvecTyypp.resize(size); + for(int i=0;i(argp); + if(daIntTyypp) + { + sw=3; sz=daIntTyypp->getNbOfElems(); + return daIntTyypp->begin(); + } + else + { + sz=0; + return 0; + } + } + status=SWIG_ConvertPtr(value,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayIntTuple,0|0); + if(SWIG_IsOK(status)) + { + ParaMEDMEM::DataArrayIntTuple *daIntTuple=reinterpret_cast< ParaMEDMEM::DataArrayIntTuple * >(argp); + sw=4; sz=daIntTuple->getNumberOfCompo(); + return daIntTuple->getConstPointer(); + } + throw INTERP_KERNEL::Exception("5 types accepted : integer, tuple of integer, list of integer, DataArrayInt, DataArrayIntTuple"); +} diff --git a/src/MEDLoader/MEDFileData.cxx b/src/MEDLoader/MEDFileData.cxx index b18c3cb42..61f1429f3 100644 --- a/src/MEDLoader/MEDFileData.cxx +++ b/src/MEDLoader/MEDFileData.cxx @@ -129,7 +129,6 @@ bool MEDFileData::unPolyzeMeshes() throw(INTERP_KERNEL::Exception) MEDFileMeshes *ms=_meshes; if(!ms) return false; - bool ret=false; std::vector< MEDFileMesh * > meshesImpacted; std::vector< DataArrayInt * > renumParamsOfMeshImpacted;//same size as meshesImpacted std::vector< std::vector > oldCodeOfMeshImpacted,newCodeOfMeshImpacted;//same size as meshesImpacted diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index cf851c2e9..70d126a7d 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -254,18 +254,32 @@ void MEDFileFieldPerMeshPerTypePerDisc::assignFieldNoProfile(int& start, int off } /*! - * Leaf method of field with profile assignement. - * @param pflName input containing name of profile if any. 0 if no profile. - * @param multiTypePfl input containing the profile array \b including \b all \b types. This array is usefull only for GAUSS_NE. - * @param idsInPfl input containing the ids in the profile 'multiTypePfl' concerning the current geo type. + * Leaf method of field with profile assignement. This method is the most general one. No optimization is done here. + * \param [in] pflName input containing name of profile if any. 0 if no profile (except for GAUSS_PT where a no profile can hide a profile when splitted by loc_id). + * \param [in] multiTypePfl is the end user profile specified in high level API + * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type. + * \param [in] locIds is the profile needed to be created for MED file format. It can be null if all cells of current geometric type are fetched in \a multiTypePfl. + * \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points. + * \param [in] mesh is the mesh coming from the MEDFileMesh instance in correspondance with the MEDFileField. The mesh inside the \a field is simply ignored. */ -void MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile(int& start, const char *pflName, const DataArrayInt *multiTypePfl, const DataArrayInt *idsInPfl, const MEDCouplingFieldDouble *field, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception) +void MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile(int& start, const DataArrayInt *multiTypePfl, const DataArrayInt *idsInPfl, DataArrayInt *locIds, int nbOfEltsInWholeMesh, const MEDCouplingFieldDouble *field, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception) { - if(pflName) - _profile=pflName; - else - _profile.clear(); + _profile.clear(); _type=field->getTypeOfField(); + std::string pflName(multiTypePfl->getName()); + std::ostringstream oss; oss << pflName; + if(_type!=ON_NODES) { const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(getGeoType()); oss << "_" << cm.getRepr(); } else { oss << "_NODE"; } + if(locIds) + { + if(pflName.empty()) + throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : existing profile with empty name !"); + if(_type!=ON_GAUSS_PT) + { + locIds->setName(oss.str().c_str()); + glob.appendProfile(locIds); + _profile=oss.str(); + } + } const DataArrayDouble *da=field->getArray(); _start=start; switch(_type) @@ -288,7 +302,7 @@ void MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile(int& start, const cha { MEDCouplingAutoRefCountObjectPtr arr=field->getDiscretization()->getOffsetArr(mesh); MEDCouplingAutoRefCountObjectPtr arr2=arr->deltaShiftIndex(); - MEDCouplingAutoRefCountObjectPtr arr3=arr2->selectByTupleId(multiTypePfl->getConstPointer(),multiTypePfl->getConstPointer()+multiTypePfl->getNumberOfTuples()); + MEDCouplingAutoRefCountObjectPtr arr3=arr2->selectByTupleId(multiTypePfl->begin(),multiTypePfl->end()); arr3->computeOffsets2(); MEDCouplingAutoRefCountObjectPtr tmp=idsInPfl->buildExplicitArrByRanges(arr3); int trueNval=tmp->getNumberOfTuples(); @@ -299,7 +313,52 @@ void MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile(int& start, const cha } case ON_GAUSS_PT: { - throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : not implemented yet for profiles on gauss points !"); + const MEDCouplingFieldDiscretizationGauss *disc2=dynamic_cast(field->getDiscretization()); + if(!disc2) + throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !"); + const DataArrayInt *da1=disc2->getArrayOfDiscIds(); + const MEDCouplingGaussLocalization& gsLoc=field->getGaussLocalization(_loc_id); + MEDCouplingAutoRefCountObjectPtr da2=da1->selectByTupleId(idsInPfl->begin(),idsInPfl->end()); + MEDCouplingAutoRefCountObjectPtr da3=da2->getIdsEqual(_loc_id); + MEDCouplingAutoRefCountObjectPtr da4=idsInPfl->selectByTupleId(da3->begin(),da3->end()); + // + MEDCouplingAutoRefCountObjectPtr mesh2=mesh->buildPart(multiTypePfl->begin(),multiTypePfl->end()); + MEDCouplingAutoRefCountObjectPtr arr=disc2->getOffsetArr(mesh2); + // + MEDCouplingAutoRefCountObjectPtr tmp=DataArrayInt::New(); + int trueNval=0; + for(const int *pt=da4->begin();pt!=da4->end();pt++) + trueNval+=arr->getIJ(*pt+1,0)-arr->getIJ(*pt,0); + tmp->alloc(trueNval,1); + int *tmpPtr=tmp->getPointer(); + for(const int *pt=da4->begin();pt!=da4->end();pt++) + for(int j=arr->getIJ(*pt,0);jgetIJ(*pt+1,0);j++) + *tmpPtr++=j; + // + _nval=da4->getNumberOfTuples(); + getArray()->setContigPartOfSelectedValues(_start,da,tmp); + _end=_start+trueNval; + oss << "_loc_" << _loc_id; + if(locIds) + { + MEDCouplingAutoRefCountObjectPtr da5=locIds->selectByTupleId(da3->begin(),da3->end()); + da5->setName(oss.str().c_str()); + glob.appendProfile(da5); + _profile=oss.str(); + } + else + { + if(da3->getNumberOfTuples()!=nbOfEltsInWholeMesh || !da3->isIdentity()) + { + da3->setName(oss.str().c_str()); + glob.appendProfile(da3); + _profile=oss.str(); + } + } + std::ostringstream oss2; oss2 << "Loc_" << getName() << "_" << INTERP_KERNEL::CellModel::GetCellModel(getGeoType()).getRepr() << "_" << _loc_id; + _localization=oss2.str(); + glob.appendLoc(_localization.c_str(),getGeoType(),gsLoc.getRefCoords(),gsLoc.getGaussCoords(),gsLoc.getWeights()); + break; } default: throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerTypePerDisc::assignFieldProfile : not implemented yet for such discretization type of field !"); @@ -620,10 +679,10 @@ int MEDFileFieldPerMeshPerTypePerDisc::fillEltIdsFromCode(int offset, const std: _loc_id=offset; std::ostringstream oss; std::size_t nbOfType=codeOfMesh.size()/3; - std::size_t found=-1; + int found=-1; for(std::size_t i=0;igetNumberOfTuples() << " whereas the number of ids is set to " << _nval << " for this geometric type !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } - int offset=codeOfMesh[3*found+2]; + int offset2=codeOfMesh[3*found+2]; for(const int *pflId=pfl->begin();pflId!=pfl->end();pflId++) { if(*pflId_loc_id)==geoType && (*it)->_nval==nbMeshEntities) { if(!isPfl) - if((*it)->_profile.empty()) - break; - else - if(!(*it)->_profile.empty()) - { - const DataArrayInt *pfl=glob.getProfile((*it)->_profile.c_str()); - if(pfl->isEqualWithoutConsideringStr(*idsOfMeshElt)) - break; - } + { + if((*it)->_profile.empty()) + break; + else + if(!(*it)->_profile.empty()) + { + const DataArrayInt *pfl=glob.getProfile((*it)->_profile.c_str()); + if(pfl->isEqualWithoutConsideringStr(*idsOfMeshElt)) + break; + } + } } } if(it==entriesOnSameDisc.end()) @@ -865,28 +926,20 @@ void MEDFileFieldPerMeshPerType::assignFieldNoProfile(int& start, int offset, in _field_pm_pt_pd[*it]->assignFieldNoProfile(start,offset,nbOfCells,field,glob); } -void MEDFileFieldPerMeshPerType::assignFieldProfile(int& start, const DataArrayInt *multiTypePfl, const DataArrayInt *idsInPfl, DataArrayInt *locIds, const MEDCouplingFieldDouble *field, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception) +/*! + * This method is the most general one. No optimization is done here. + * \param [in] multiTypePfl is the end user profile specified in high level API + * \param [in] idsInPfl is the selection into the \a multiTypePfl whole profile that corresponds to the current geometric type. + * \param [in] locIds is the profile needed to be created for MED file format. It can be null if all cells of current geometric type are fetched in \a multiTypePfl. + * \b WARNING if not null the MED file profile can be subdivided again in case of Gauss points. + * \param [in] nbOfEltsInWholeMesh nb of elts of type \a this->_geo_type in \b WHOLE mesh + * \param [in] mesh is the mesh coming from the MEDFileMesh instance in correspondance with the MEDFileField. The mesh inside the \a field is simply ignored. + */ +void MEDFileFieldPerMeshPerType::assignFieldProfile(int& start, const DataArrayInt *multiTypePfl, const DataArrayInt *idsInPfl, DataArrayInt *locIds, int nbOfEltsInWholeMesh, const MEDCouplingFieldDouble *field, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception) { std::vector pos=addNewEntryIfNecessary(field,idsInPfl); - if(locIds) - { - // - std::string pflName(locIds->getName()); - if(pflName.empty()) - throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerType::assignFieldProfile : existing profile with empty name !"); - const INTERP_KERNEL::CellModel& cm=INTERP_KERNEL::CellModel::GetCellModel(_geo_type); - std::ostringstream oss; oss << pflName << "_" << cm.getRepr(); - locIds->setName(oss.str().c_str()); - glob.appendProfile(locIds); - // - for(std::vector::const_iterator it=pos.begin();it!=pos.end();it++) - _field_pm_pt_pd[*it]->assignFieldProfile(start,oss.str().c_str(),multiTypePfl,idsInPfl,field,mesh,glob); - } - else - { - for(std::vector::const_iterator it=pos.begin();it!=pos.end();it++) - _field_pm_pt_pd[*it]->assignFieldProfile(start,0,multiTypePfl,idsInPfl,field,mesh,glob); - } + for(std::vector::const_iterator it=pos.begin();it!=pos.end();it++) + _field_pm_pt_pd[*it]->assignFieldProfile(start,multiTypePfl,idsInPfl,locIds,nbOfEltsInWholeMesh,field,mesh,glob); } void MEDFileFieldPerMeshPerType::assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception) @@ -898,17 +951,11 @@ void MEDFileFieldPerMeshPerType::assignNodeFieldNoProfile(int& start, const MEDC void MEDFileFieldPerMeshPerType::assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception) { - std::string pflName(pfl->getName()); - if(pflName.empty()) - throw INTERP_KERNEL::Exception("MEDFileFieldPerMeshPerType::assignNodeFieldProfile : existing profile with empty name !"); - std::ostringstream oss; oss << pflName << "_NODE"; MEDCouplingAutoRefCountObjectPtr pfl2=pfl->deepCpy(); - pfl2->setName(oss.str().c_str()); - glob.appendProfile(pfl2); // _field_pm_pt_pd.resize(1); _field_pm_pt_pd[0]=MEDFileFieldPerMeshPerTypePerDisc::New(this,ON_NODES,-3); - _field_pm_pt_pd[0]->assignFieldProfile(start,oss.str().c_str(),pfl,pfl2,field,0,glob);//mesh is not requested so 0 is send. + _field_pm_pt_pd[0]->assignFieldProfile(start,pfl,pfl2,pfl2,-1,field,0,glob);//mesh is not requested so 0 is send. } std::vector MEDFileFieldPerMeshPerType::addNewEntryIfNecessary(const MEDCouplingFieldDouble *field, int offset, int nbOfCells) throw(INTERP_KERNEL::Exception) @@ -1043,7 +1090,7 @@ std::vector MEDFileFieldPerMeshPerType::addNewEntryIfNecessaryGauss(const M if(!disc2) throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : invalid call to this method ! Internal Error !"); const DataArrayInt *da=disc2->getArrayOfDiscIds(); - MEDCouplingAutoRefCountObjectPtr da2=da->selectByTupleId(subCells->getConstPointer(),subCells->getConstPointer()+subCells->getNumberOfTuples()); + MEDCouplingAutoRefCountObjectPtr da2=da->selectByTupleIdSafe(subCells->getConstPointer(),subCells->getConstPointer()+subCells->getNumberOfTuples()); std::set retTmp=da2->getDifferentValues(); if(retTmp.find(-1)!=retTmp.end()) throw INTERP_KERNEL::Exception("addNewEntryIfNecessaryGauss : some cells have no dicretization description !"); @@ -1403,24 +1450,6 @@ void MEDFileFieldPerMesh::copyTinyInfoFrom(const MEDCouplingMesh *mesh) throw(IN mesh->getTime(_mesh_iteration,_mesh_order); } -void MEDFileFieldPerMesh::assignFieldProfile(int& start, const DataArrayInt *multiTypePfl, const std::vector& code, const std::vector& idsInPflPerType, const std::vector& idsPerType, const MEDCouplingFieldDouble *field, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception) -{ - int nbOfTypes=code.size()/3; - bool isProfile=false; - for(int i=0;i& code, const MEDCouplingFieldDouble *field, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception) { int nbOfTypes=code.size()/3; @@ -1437,8 +1466,14 @@ void MEDFileFieldPerMesh::assignFieldNoProfileNoRenum(int& start, const std::vec /*! * This method is the most general one. No optimization is done here. + * \param [in] multiTypePfl is the end user profile specified in high level API + * \param [in] code is the code of \a mesh[multiTypePfl] mesh. It is of size of number of different geometric types into \a mesh[multiTypePfl]. + * \param [in] code2 is the code of the \b WHOLE mesh on the same level. So all types in \a code are in \a code2. + * \param [in] idsInPflPerType is the selection into the \a multiTypePfl whole profile that corresponds to the given geometric type. This vector is always 3 times smaller than \a code. + * \param [in] idsPerType is a vector containing the profiles needed to be created for MED file format. \b WARNING these processed MED file profiles can be subdivided again in case of Gauss points. + * \param [in] mesh is the mesh coming from the MEDFileMesh instance in correspondance with the MEDFileField. The mesh inside the \a field is simply ignored. */ -void MEDFileFieldPerMesh::assignFieldProfileGeneral(int& start, const DataArrayInt *multiTypePfl, const std::vector& code, const std::vector& idsInPflPerType, const std::vector& idsPerType, const MEDCouplingFieldDouble *field, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception) +void MEDFileFieldPerMesh::assignFieldProfile(int& start, const DataArrayInt *multiTypePfl, const std::vector& code, const std::vector& code2, const std::vector& idsInPflPerType, const std::vector& idsPerType, const MEDCouplingFieldDouble *field, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception) { int nbOfTypes=code.size()/3; for(int i=0;iassignFieldProfile(start,multiTypePfl,idsInPflPerType[i],pfl,field,mesh,glob); + int nbOfTupes2=code2.size()/3; + int found=0; + for(;foundassignFieldProfile(start,multiTypePfl,idsInPflPerType[i],pfl,code2[3*found+1],field,mesh,glob); } } @@ -1831,6 +1873,9 @@ void MEDFileFieldPerMesh::changeLocsRefsNamesGen(const std::vector< std::pairchangeLocsRefsNamesGen(mapOfModif); } +/*! + * \param [in] mesh is the whole mesh + */ MEDCouplingFieldDouble *MEDFileFieldPerMesh::getFieldOnMeshAtLevel(TypeOfField type, const MEDFileFieldGlobsReal *glob, const MEDCouplingMesh *mesh, bool& isPfl) const throw(INTERP_KERNEL::Exception) { if(_field_pm_pt.empty()) @@ -2006,7 +2051,8 @@ int MEDFileFieldPerMesh::addNewEntryIfNecessary(INTERP_KERNEL::NormalizedCellTyp } /*! - * 'dads' and 'locs' input parameters have the same number of elements. + * 'dads' and 'locs' input parameters have the same number of elements + * \param [in] mesh is \b NOT the global mesh, but the possibly reduced mesh. \a mesh parameter will be directly aggregated in the returned field */ MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField(TypeOfField type, const MEDFileFieldGlobsReal *glob, const std::vector< std::pair >& dads, const std::vector& locs, @@ -2047,6 +2093,7 @@ MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField(TypeOfField type, const * 'dads', 'locs' and 'geoTypes' input parameters have the same number of elements. * No check of this is performed. 'da' array contains an array in old2New style to be applyied to mesh to obtain the right support. * The order of cells in the returned field is those imposed by the profile. + * \param [in] mesh is the global mesh. */ MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField2(TypeOfField type, const MEDFileFieldGlobsReal *glob, const std::vector >& dads, const std::vector& locs, @@ -2059,11 +2106,10 @@ MEDCouplingFieldDouble *MEDFileFieldPerMesh::finishField2(TypeOfField type, cons if(nbOfTuples==mesh->getNumberOfCells()) return finishField(type,glob,dads,locs,mesh,isPfl); } - MEDCouplingAutoRefCountObjectPtr ret=finishField(type,glob,dads,locs,mesh,isPfl); - isPfl=true; MEDCouplingAutoRefCountObjectPtr m2=mesh->buildPart(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems()); m2->setName(mesh->getName()); - ret->setMesh(m2); + MEDCouplingAutoRefCountObjectPtr ret=finishField(type,glob,dads,locs,m2,isPfl); + isPfl=true; ret->incrRef(); return ret; } @@ -3420,18 +3466,14 @@ void MEDFileField1TSWithoutSDA::setFieldNoProfileSBT(const MEDCouplingFieldDoubl TypeOfField type=field->getTypeOfField(); std::vector dummy; int start=copyTinyInfoFrom(field); + int pos=addNewEntryIfNecessary(mesh); if(type!=ON_NODES) { std::vector code=MEDFileField1TSWithoutSDA::CheckSBTMesh(mesh); - // - int pos=addNewEntryIfNecessary(mesh); - _field_per_mesh[pos]->assignFieldProfile(start,0,code,dummy,dummy,field,0,glob);//mesh is set to 0 because no external mesh is needed to be sent because no profile. + _field_per_mesh[pos]->assignFieldNoProfileNoRenum(start,code,field,glob); } else - { - int pos=addNewEntryIfNecessary(mesh); - _field_per_mesh[pos]->assignNodeFieldNoProfile(start,field,glob); - } + _field_per_mesh[pos]->assignNodeFieldNoProfile(start,field,glob); } /*! @@ -3443,11 +3485,12 @@ void MEDFileField1TSWithoutSDA::setFieldProfile(const MEDCouplingFieldDouble *fi int start=copyTinyInfoFrom(field); std::vector idsInPflPerType; std::vector idsPerType; - std::vector code; + std::vector code,code2; MEDCouplingAutoRefCountObjectPtr m=mesh->getGenMeshAtLevel(meshDimRelToMax); if(type!=ON_NODES) { m->splitProfilePerType(profile,code,idsInPflPerType,idsPerType); + code2=m->getDistributionOfTypes(); // std::vector< MEDCouplingAutoRefCountObjectPtr > idsInPflPerType2(idsInPflPerType.size()); for(std::size_t i=0;iassignFieldProfile(start,profile,code,idsInPflPerType,idsPerType,field,m,glob); + _field_per_mesh[pos]->assignFieldProfile(start,profile,code,code2,idsInPflPerType,idsPerType,field,m,glob); } else { @@ -3498,6 +3541,9 @@ MEDCouplingFieldDouble *MEDFileField1TSWithoutSDA::getFieldAtTopLevel(TypeOfFiel return MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel(type,meshDimRelToMax,renumPol,glob,mm); } +/*! + * \param [in] mesh is the whole mesh. + */ MEDCouplingFieldDouble *MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel(TypeOfField type, int renumPol, const MEDFileFieldGlobsReal *glob, const MEDCouplingMesh *mesh, const DataArrayInt *cellRenum, const DataArrayInt *nodeRenum) const throw(INTERP_KERNEL::Exception) { static const char msg1[]="MEDFileField1TSWithoutSDA::getFieldOnMeshAtLevel : request for a renumbered field following mesh numbering whereas it is a profile field !"; @@ -3597,7 +3643,7 @@ DataArrayDouble *MEDFileField1TSWithoutSDA::getUndergroundDataArrayExt(std::vect } MEDFileField1TSWithoutSDA::MEDFileField1TSWithoutSDA(const char *fieldName, int csit, int fieldtype, int iteration, int order, - const std::vector& infos):_csit(csit),_field_type(fieldtype),_iteration(iteration),_order(order) + const std::vector& infos):_iteration(iteration),_order(order),_csit(csit),_field_type(fieldtype) { DataArrayDouble *arr=getOrCreateAndGetArray(); arr->setName(fieldName); @@ -3747,7 +3793,7 @@ void MEDFileField1TS::write(const char *fileName, int mode) const throw(INTERP_K } MEDFileField1TS::MEDFileField1TS(const char *fileName, const char *fieldName, int iteration, int order) throw(INTERP_KERNEL::Exception) -try:_content(MEDFileField1TSWithoutSDA::New(fieldName,-1,-1,iteration,order,std::vector())),MEDFileFieldGlobsReal(fileName) +try:MEDFileFieldGlobsReal(fileName),_content(MEDFileField1TSWithoutSDA::New(fieldName,-1,-1,iteration,order,std::vector())) { MEDFileUtilities::CheckFileForRead(fileName); MEDFileUtilities::AutoFid fid=MEDfileOpen(fileName,MED_ACC_RDONLY); @@ -4218,9 +4264,8 @@ MEDFileFieldMultiTSWithoutSDA::MEDFileFieldMultiTSWithoutSDA(med_idt fid, int fi try:_name("") { med_field_type typcha; - int nbstep2=-1; // - int ncomp=MEDfieldnComponent(fid,1); + int ncomp=MEDfieldnComponent(fid,fieldId+1); INTERP_KERNEL::AutoPtr comp=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE); INTERP_KERNEL::AutoPtr unit=MEDLoaderBase::buildEmptyString(ncomp*MED_SNAME_SIZE); INTERP_KERNEL::AutoPtr dtunit=MEDLoaderBase::buildEmptyString(MED_LNAME_SIZE); @@ -4539,12 +4584,12 @@ int MEDFileFieldMultiTSWithoutSDA::getPosOfTimeStep(int iteration, int order) co const MEDFileField1TSWithoutSDA *tmp(*it); if(tmp) { - int it,ord; - tmp->getTime(it,ord); - if(it==iteration && order==ord) + int it2,ord; + tmp->getTime(it2,ord); + if(it2==iteration && order==ord) return ret; else - oss << "(" << it << "," << ord << "), "; + oss << "(" << it2 << "," << ord << "), "; } } throw INTERP_KERNEL::Exception(oss.str().c_str()); @@ -4560,8 +4605,8 @@ int MEDFileFieldMultiTSWithoutSDA::getPosGivenTime(double time, double eps) cons const MEDFileField1TSWithoutSDA *tmp(*it); if(tmp) { - int it,ord; - double ti=tmp->getTime(it,ord); + int it2,ord; + double ti=tmp->getTime(it2,ord); if(fabs(time-ti)& dad, std::string& pfl, std::string& loc) const throw(INTERP_KERNEL::Exception); void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception); @@ -165,7 +165,7 @@ namespace ParaMEDMEM static MEDFileFieldPerMeshPerType *New(MEDFileFieldPerMesh *fath, INTERP_KERNEL::NormalizedCellType geoType) throw(INTERP_KERNEL::Exception); static MEDFileFieldPerMeshPerType *NewOnRead(med_idt fid, MEDFileFieldPerMesh *fath, TypeOfField type, INTERP_KERNEL::NormalizedCellType geoType) throw(INTERP_KERNEL::Exception); void assignFieldNoProfile(int& start, int offset, int nbOfCells, const MEDCouplingFieldDouble *field, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception); - void assignFieldProfile(int& start, const DataArrayInt *multiTypePfl, const DataArrayInt *idsInPfl, DataArrayInt *locIds, const MEDCouplingFieldDouble *field, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception); + void assignFieldProfile(int& start, const DataArrayInt *multiTypePfl, const DataArrayInt *idsInPfl, DataArrayInt *locIds, int nbOfEltsInWholeMesh, const MEDCouplingFieldDouble *field, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception); void assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception); void assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception); const MEDFileFieldPerMesh *getFather() const; @@ -219,8 +219,7 @@ namespace ParaMEDMEM static MEDFileFieldPerMesh *NewOnRead(med_idt fid, MEDFileField1TSWithoutSDA *fath, int meshCsit, int meshIteration, int meshOrder) throw(INTERP_KERNEL::Exception); void simpleRepr(int bkOffset,std::ostream& oss, int id) const; void copyTinyInfoFrom(const MEDCouplingMesh *mesh) throw(INTERP_KERNEL::Exception); - void assignFieldProfile(int& start, const DataArrayInt *multiTypePfl, const std::vector& code, const std::vector& idsInPflPerType, const std::vector& idsPerType, const MEDCouplingFieldDouble *field, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception); - void assignFieldProfileGeneral(int& start, const DataArrayInt *multiTypePfl, const std::vector& code, const std::vector& idsInPflPerType, const std::vector& idsPerType, const MEDCouplingFieldDouble *field, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception); + void assignFieldProfile(int& start, const DataArrayInt *multiTypePfl, const std::vector& code, const std::vector& code2, const std::vector& idsInPflPerType, const std::vector& idsPerType, const MEDCouplingFieldDouble *field, const MEDCouplingMesh *mesh, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception); void assignFieldNoProfileNoRenum(int& start, const std::vector& code, const MEDCouplingFieldDouble *field, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception); void assignNodeFieldNoProfile(int& start, const MEDCouplingFieldDouble *field, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception); void assignNodeFieldProfile(int& start, const DataArrayInt *pfl, const MEDCouplingFieldDouble *field, MEDFileFieldGlobsReal& glob) throw(INTERP_KERNEL::Exception); diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index 6f77ac217..5c5ccd8f8 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -217,8 +217,8 @@ std::vector MEDFileMesh::getFamiliesOnGroups(const std::vector grps=getGroupsNames(); oss << "\" !\nAvailable groups are :"; - std::copy(grps.begin(),grps.end(),std::ostream_iterator(oss," ")); + std::vector grps2=getGroupsNames(); oss << "\" !\nAvailable groups are :"; + std::copy(grps2.begin(),grps2.end(),std::ostream_iterator(oss," ")); throw INTERP_KERNEL::Exception(oss.str().c_str()); } fams.insert((*it2).second.begin(),(*it2).second.end()); @@ -2132,7 +2132,7 @@ bool MEDFileUMesh::unPolyze(std::vector& oldCode, std::vector& newCode std::vector< MEDCouplingAutoRefCountObjectPtr > memorySaverIfThrow;//same than renumCellsSplited only in case of throw int start=0; int end=0; - for(std::vector::const_reverse_iterator it=levs.rbegin();it!=levs.rend();it++) + for(std::vector::reverse_iterator it=levs.rbegin();it!=levs.rend();it++) { MEDCouplingAutoRefCountObjectPtr m=getMeshAtLevel(*it); std::vector code1=m->getDistributionOfTypes(); diff --git a/src/MEDLoader/MEDFileMeshLL.cxx b/src/MEDLoader/MEDFileMeshLL.cxx index 2c3c77d9b..cfb86ad46 100644 --- a/src/MEDLoader/MEDFileMeshLL.cxx +++ b/src/MEDLoader/MEDFileMeshLL.cxx @@ -652,7 +652,6 @@ void MEDFileUMeshSplitL1::eraseFamilyField() void MEDFileUMeshSplitL1::setGroupsFromScratch(const std::vector& ms, std::map& familyIds, std::map >& groups) throw(INTERP_KERNEL::Exception) { - int sz=ms.size(); std::vector< DataArrayInt * > corr; _m=MEDCouplingUMesh::FuseUMeshesOnSameCoords(ms,0,corr); std::vector< MEDCouplingAutoRefCountObjectPtr > corrMSafe(corr.begin(),corr.end()); diff --git a/src/MEDLoader/MEDLoader.cxx b/src/MEDLoader/MEDLoader.cxx index 60e8773ec..8fd883859 100644 --- a/src/MEDLoader/MEDLoader.cxx +++ b/src/MEDLoader/MEDLoader.cxx @@ -261,11 +261,11 @@ void MEDLoader::MEDConnOfOneElemType::releaseArray() delete [] _global; } -MEDLoader::MEDFieldDoublePerCellType::MEDFieldDoublePerCellType(INTERP_KERNEL::NormalizedCellType type, double *values, int ncomp, int ntuple, - const int *cellIdPerType, const char *locName):_ntuple(ntuple),_ncomp(ncomp),_values(values),_type(type) +MEDLoader::MEDFieldDoublePerCellType::MEDFieldDoublePerCellType(INTERP_KERNEL::NormalizedCellType type, double *values, int ncomp, int nGeoElt, int nbi, + const int *cellIdPerType, const char *locName):_ngeo_elt(nGeoElt),_nbi(nbi),_ncomp(ncomp),_values(values),_type(type) { if(cellIdPerType) - _cell_id_per_type.insert(_cell_id_per_type.end(),cellIdPerType,cellIdPerType+ntuple); + _cell_id_per_type.insert(_cell_id_per_type.end(),cellIdPerType,cellIdPerType+nGeoElt); if(locName) _loc_name=locName; } @@ -308,6 +308,7 @@ void MEDLoaderNS::fillGaussDataOnField(const char *fileName, const std::list::const_iterator iter=data.begin();iter!=data.end();iter++) { const std::string& loc=(*iter).getLocName(); @@ -329,7 +330,16 @@ void MEDLoaderNS::fillGaussDataOnField(const char *fileName, const std::list refcoo(nbPtPerCell*dim),gscoo(nbOfGaussPt*dim),w(nbOfGaussPt); MEDlocalizationRd(fid,(*iter).getLocName().c_str(),MED_FULL_INTERLACE,&refcoo[0],&gscoo[0],&w[0]); - f->setGaussLocalizationOnType((*iter).getType(),refcoo,gscoo,w); + if((*iter).getCellIdPerType().empty()) + f->setGaussLocalizationOnType((*iter).getType(),refcoo,gscoo,w); + else + { + MEDCouplingAutoRefCountObjectPtr pfl=DataArrayInt::New(); + pfl->alloc((*iter).getCellIdPerType().size(),1); + pfl->iota(offset); + f->setGaussLocalizationOnCells(pfl->begin(),pfl->end(),refcoo,gscoo,w); + } + offset+=(*iter).getNbOfGeoElt(); } MEDfileClose(fid); } @@ -1106,27 +1116,33 @@ void MEDLoaderNS::readFieldDoubleDataInMedFile(const char *fileName, const char { if(nbPdt>0) { - int profilesize,nbi; - int nval=MEDfieldnValueWithProfile(fid,fieldName,numdt,numo,tabEnt[typeOfOutField],tabType[typeOfOutField][j],1,MED_COMPACT_PFLMODE,pflname,&profilesize,locname,&nbi); - if(nval>0) + INTERP_KERNEL::AutoPtr pflDummy=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + INTERP_KERNEL::AutoPtr locDummy=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); + int nbProfiles=MEDfieldnProfile(fid,fieldName,numdt,numo,tabEnt[typeOfOutField],tabType[typeOfOutField][j],pflDummy,locDummy); + for(int kk=0;kk0) { - delete [] valr; - continue; + double *valr=new double[ncomp*nval*nbi]; + MEDfieldValueWithProfileRd(fid,fieldName,iteration,order,tabEnt[typeOfOutField],tabType[typeOfOutField][j],MED_COMPACT_PFLMODE, + pflname,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,(unsigned char*)valr); + std::string tmp(locname); + if((locname[0]!='\0' && (typeOfOutField!=ON_GAUSS_PT)) + || (locname[0]=='\0' && typeOfOutField==ON_GAUSS_PT)) + { + delete [] valr; + continue; + } + INTERP_KERNEL::AutoPtr pfl=0; + if(pflname[0]!='\0') + { + pfl=new int[nval]; + MEDprofileRd(fid,pflname,pfl); + } + field.push_back(MEDLoader::MEDFieldDoublePerCellType(typmai2[j],valr,ncomp,nval,nbi,pfl,locname)); } - INTERP_KERNEL::AutoPtr pfl=0; - if(pflname[0]!='\0') - { - pfl=new int[nval]; - MEDprofileRd(fid,pflname,pfl); - } - field.push_back(MEDLoader::MEDFieldDoublePerCellType(typmai2[j],valr,ncomp,nval*nbi,pfl,locname)); } } } @@ -1884,32 +1900,26 @@ ParaMEDMEM::MEDCouplingFieldDouble *MEDLoaderNS::readFieldDoubleLev2(const char throw INTERP_KERNEL::Exception(oss.str().c_str()); } //for profiles - ParaMEDMEM::MEDCouplingUMesh *newMesh=0; + MEDCouplingAutoRefCountObjectPtr newMesh; std::string mName(mesh->getName()); - for(std::list::const_iterator iter=fieldPerCellType.begin();iter!=fieldPerCellType.end();iter++) + if(typeOfOutField==ON_NODES) { - const std::vector& cellIds=(*iter).getCellIdPerType(); - if(!cellIds.empty()) + for(std::list::const_iterator iter=fieldPerCellType.begin();iter!=fieldPerCellType.end();iter++) { - std::vector ci(cellIds.size()); - std::transform(cellIds.begin(),cellIds.end(),ci.begin(),std::bind2nd(std::plus(),-1)); - ParaMEDMEM::MEDCouplingUMesh *mesh2=0; - if(typeOfOutField==ON_CELLS) + const std::vector& cellIds=(*iter).getCellIdPerType(); + if(!cellIds.empty()) { - if(newMesh) - mesh2=newMesh->keepSpecifiedCells((*iter).getType(),&ci[0],&ci[0]+ci.size()); - else - mesh2=mesh->keepSpecifiedCells((*iter).getType(),&ci[0],&ci[0]+ci.size()); - } - else if(typeOfOutField==ON_NODES) - { - DataArrayInt *da=0,*da2=0; - if(newMesh) + std::vector ci(cellIds.size()); + std::transform(cellIds.begin(),cellIds.end(),ci.begin(),std::bind2nd(std::plus(),-1)); + MEDCouplingAutoRefCountObjectPtr mesh2; + MEDCouplingAutoRefCountObjectPtr da,da2; + if((const ParaMEDMEM::MEDCouplingUMesh *)newMesh) { if((int)ci.size()!=newMesh->getNumberOfNodes()) { da=newMesh->getCellIdsFullyIncludedInNodeIds(&ci[0],&ci[ci.size()]); - mesh2=dynamic_cast(newMesh->buildPartAndReduceNodes(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems(),da2)); + DataArrayInt *tmpp=0; + mesh2=dynamic_cast(newMesh->buildPartAndReduceNodes(da->begin(),da->end(),tmpp)); da2=tmpp; } } else @@ -1917,7 +1927,8 @@ ParaMEDMEM::MEDCouplingFieldDouble *MEDLoaderNS::readFieldDoubleLev2(const char if((int)ci.size()!=mesh->getNumberOfNodes()) { da=mesh->getCellIdsFullyIncludedInNodeIds(&ci[0],&ci[ci.size()]); - mesh2=dynamic_cast(mesh->buildPartAndReduceNodes(da->getConstPointer(),da->getConstPointer()+da->getNbOfElems(),da2)); + DataArrayInt *tmpp=0; + mesh2=dynamic_cast(mesh->buildPartAndReduceNodes(da->begin(),da->end(),tmpp)); da2=tmpp; // int nnodes=mesh2->getNumberOfNodes(); MEDCouplingAutoRefCountObjectPtr da3=DataArrayInt::New(); @@ -1942,32 +1953,47 @@ ParaMEDMEM::MEDCouplingFieldDouble *MEDLoaderNS::readFieldDoubleLev2(const char mesh2->renumberNodes(da2->getConstPointer(),(int)ci.size()); } } - if(da) - da->decrRef(); - if(da2) - da2->decrRef(); + newMesh=mesh2; + } + } + } + else + { + newMesh=const_cast(static_cast(mesh)); mesh->incrRef(); + std::vector types; + for(std::list::const_iterator iter=fieldPerCellType.begin();iter!=fieldPerCellType.end();iter++) + if(std::find(types.begin(),types.end(),(*iter).getType())==types.end()) + types.push_back((*iter).getType()); + for(std::vector::const_iterator it=types.begin();it!=types.end();it++) + { + std::vector cids; + for(std::list::const_iterator iter=fieldPerCellType.begin();iter!=fieldPerCellType.end();iter++) + { + if((*iter).getType()==*it) + { + const std::vector& cellIds=(*iter).getCellIdPerType(); + if(!cellIds.empty()) + std::transform(cellIds.begin(),cellIds.end(),std::back_insert_iterator< std::vector >(cids),std::bind2nd(std::plus(),-1)); + } } - if(newMesh) - newMesh->decrRef(); - newMesh=mesh2; + if(!cids.empty()) + newMesh=newMesh->keepSpecifiedCells(*it,&cids[0],&cids[0]+cids.size()); } } // ParaMEDMEM::MEDCouplingFieldDouble *ret=ParaMEDMEM::MEDCouplingFieldDouble::New(typeOfOutField,ONE_TIME); ret->setName(fieldName); ret->setTime(time,iteration,order); - if(newMesh) + ParaMEDMEM::DataArrayDouble *arr=buildArrayFromRawData(fieldPerCellType,infos); + ret->setArray(arr); + arr->decrRef(); + if((const ParaMEDMEM::MEDCouplingUMesh *)newMesh) { newMesh->setName(mName.c_str());//retrieving mesh name to avoid renaming due to mesh restriction in case of profile. ret->setMesh(newMesh); - newMesh->decrRef(); } else ret->setMesh(mesh); - ParaMEDMEM::DataArrayDouble *arr=buildArrayFromRawData(fieldPerCellType,infos); - ret->setArray(arr); - arr->decrRef(); - // if(typeOfOutField==ON_GAUSS_PT) fillGaussDataOnField(fileName,fieldPerCellType,ret); if(cellRenum) @@ -2376,10 +2402,9 @@ void MEDLoaderNS::appendCellProfileField(const char *fileName, const ParaMEDMEM: std::ostringstream oss; oss << "Pfl" << f->getName() << "_" << number++; MEDLoaderBase::safeStrCpy(oss.str().c_str(),MED_NAME_SIZE,profileName,MEDLoader::_TOO_LONG_STR); const std::vector& ids=(*iter).getCellIdPerType(); - int *profile=new int [ids.size()]; - std::transform(ids.begin(),ids.end(),profile,std::bind2nd(std::plus(),1)); + INTERP_KERNEL::AutoPtr profile=new int [ids.size()]; + std::transform(ids.begin(),ids.end(),(int *)profile,std::bind2nd(std::plus(),1)); MEDprofileWr(fid,profileName,ids.size(),profile); - delete [] profile; MEDfieldValueWithProfileWr(fid,f->getName(),numdt,numo,dt,MED_CELL,typmai3[(int)(*iter).getType()],MED_COMPACT_PFLMODE,profileName, MED_NO_LOCALIZATION,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,(*iter).getNbOfTuple(),(const unsigned char*)pt); pt+=(*iter).getNbOfTuple()*nbComp; @@ -2405,10 +2430,9 @@ void MEDLoaderNS::appendNodeElementProfileField(const char *fileName, const Para std::ostringstream oss; oss << "Pfl" << f->getName() << "_" << number++; MEDLoaderBase::safeStrCpy(oss.str().c_str(),MED_NAME_SIZE,profileName,MEDLoader::_TOO_LONG_STR); const std::vector& ids=(*iter).getCellIdPerType(); - int *profile=new int [ids.size()]; - std::transform(ids.begin(),ids.end(),profile,std::bind2nd(std::plus(),1)); + INTERP_KERNEL::AutoPtr profile=new int [ids.size()]; + std::transform(ids.begin(),ids.end(),(int *)profile,std::bind2nd(std::plus(),1)); MEDprofileWr(fid,profileName,ids.size(),profile); - delete [] profile; int nbPtPerCell=(int)INTERP_KERNEL::CellModel::GetCellModel((*iter).getType()).getNumberOfNodes(); int nbOfEntity=f->getMesh()->getNumberOfCellsWithType((*iter).getType()); int nbOfValues=nbPtPerCell*nbOfEntity; @@ -2510,25 +2534,75 @@ void MEDLoaderNS::appendFieldDirectly(const char *fileName, const ParaMEDMEM::ME } case ParaMEDMEM::ON_GAUSS_PT: { + INTERP_KERNEL::AutoPtr profileName=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); std::list split; prepareCellFieldDoubleForWriting(f,0,split); - int idGp=0; + int idGp=0,offset=0,offset2=0; + const double *pt2=0; + INTERP_KERNEL::NormalizedCellType prevType=INTERP_KERNEL::NORM_ERROR; for(std::list::const_iterator iter=split.begin();iter!=split.end();iter++) { + if((*iter).getType()!=prevType) + { + offset=offset2; + prevType=(*iter).getType(); + } INTERP_KERNEL::AutoPtr nomGauss=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); std::ostringstream oss; oss << "GP_" << f->getName() << idGp++; MEDLoaderBase::safeStrCpy(oss.str().c_str(),MED_NAME_SIZE,nomGauss,MEDLoader::_TOO_LONG_STR); - int id=f->getGaussLocalizationIdOfOneType((*iter).getType()); + std::ostringstream ossPfl; + int id=-1,nbOfEntity=-1; + MEDCouplingAutoRefCountObjectPtr arrTmp; + if((*iter).getCellIdPerType().empty()) + { + id=f->getGaussLocalizationIdOfOneType((*iter).getType()); + nbOfEntity=f->getMesh()->getNumberOfCellsWithType((*iter).getType()); + } + else + { + id=f->getGaussLocalizationIdOfOneCell((*iter).getCellIdPerType()[0]+offset); + nbOfEntity=(int)(*iter).getCellIdPerType().size(); + ossPfl << "Pfl" << f->getName() << "_" << id; + MEDLoaderBase::safeStrCpy(ossPfl.str().c_str(),MED_NAME_SIZE,profileName,MEDLoader::_TOO_LONG_STR); + INTERP_KERNEL::AutoPtr profile=new int[(*iter).getCellIdPerType().size()]; + std::transform((*iter).getCellIdPerType().begin(),(*iter).getCellIdPerType().end(),(int *)profile,std::bind2nd(std::plus(),1)); + MEDprofileWr(fid,profileName,(*iter).getCellIdPerType().size(),profile); + // + MEDCouplingAutoRefCountObjectPtr da3=DataArrayInt::New(); + da3->useArray(const_cast(&((*iter).getCellIdPerType()[0])),false,CPP_DEALLOC,(int)(*iter).getCellIdPerType().size(),1); + MEDCouplingAutoRefCountObjectPtr da4=da3->deepCpy(); + da4->applyLin(1,offset); + // + const MEDCouplingFieldDiscretizationGauss *disc2=static_cast(f->getDiscretization()); + MEDCouplingAutoRefCountObjectPtr arr=disc2->getOffsetArr(f->getMesh()); + MEDCouplingAutoRefCountObjectPtr tmp=DataArrayInt::New(); + int trueNval=0; + for(const int *pt3=da4->begin();pt3!=da4->end();pt3++) + trueNval+=arr->getIJ(*pt3+1,0)-arr->getIJ(*pt3,0); + tmp->alloc(trueNval,1); + int *tmpPtr=tmp->getPointer(); + for(const int *pt3=da4->begin();pt3!=da4->end();pt3++) + for(int j=arr->getIJ(*pt3,0);jgetIJ(*pt3+1,0);j++) + *tmpPtr++=j; + arrTmp=f->getArray()->selectByTupleId(tmp->begin(),tmp->end()); + pt2=arrTmp->getConstPointer(); + } const MEDCouplingGaussLocalization& gl=f->getGaussLocalization(id); MEDlocalizationWr(fid,nomGauss,typmai3[(int)(*iter).getType()],mesh->getMeshDimension(),&gl.getRefCoords()[0],MED_FULL_INTERLACE, gl.getNumberOfGaussPt(),&gl.getGaussCoords()[0],&gl.getWeights()[0],MED_NO_INTERPOLATION, MED_NO_MESH_SUPPORT); - int nbOfEntity=f->getMesh()->getNumberOfCellsWithType((*iter).getType()); int nbOfValues=gl.getNumberOfGaussPt()*nbOfEntity; INTERP_KERNEL::AutoPtr fieldname=MEDLoaderBase::buildEmptyString(MED_NAME_SIZE); MEDLoaderBase::safeStrCpy(f->getName(),MED_NAME_SIZE,fieldname,MEDLoader::_TOO_LONG_STR); - MEDfieldValueWithProfileWr(fid,fieldname,numdt,numo,dt,MED_CELL,typmai3[(int)(*iter).getType()],MED_COMPACT_PFLMODE, - MED_ALLENTITIES_PROFILE,nomGauss,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,nbOfEntity,(const unsigned char*)pt); + if((*iter).getCellIdPerType().empty()) + { + MEDfieldValueWithProfileWr(fid,fieldname,numdt,numo,dt,MED_CELL,typmai3[(int)(*iter).getType()],MED_COMPACT_PFLMODE, + MED_ALLENTITIES_PROFILE,nomGauss,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,nbOfEntity,(const unsigned char*)pt); + } + else + MEDfieldValueWithProfileWr(fid,fieldname,numdt,numo,dt,MED_CELL,typmai3[(int)(*iter).getType()],MED_COMPACT_PFLMODE, + profileName,nomGauss,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,nbOfEntity,(const unsigned char*)pt2); pt+=nbOfValues*nbComp; + offset2+=(*iter).getNbOfGeoElt(); } break; } @@ -2577,12 +2651,56 @@ void MEDLoaderNS::prepareCellFieldDoubleForWriting(const ParaMEDMEM::MEDCoupling { curType=(INTERP_KERNEL::NormalizedCellType)conn[*pt]; const int *pt2=std::find_if(pt+1,connI+nbOfCells,ConnReaderML(conn,(int)curType)); - if(!cellIdsPerType) - split.push_back(MEDLoader::MEDFieldDoublePerCellType(curType,0,nbComp,pt2-pt,0,0)); + int szOfChunk=std::distance(pt,pt2); + if(f->getTypeOfField()!=ON_GAUSS_PT) + { + if(!cellIdsPerType) + split.push_back(MEDLoader::MEDFieldDoublePerCellType(curType,0,nbComp,szOfChunk,1,0,0)); + else + { + split.push_back(MEDLoader::MEDFieldDoublePerCellType(curType,0,nbComp,szOfChunk,1,wCellIdsPT,0)); + wCellIdsPT+=szOfChunk; + } + } else { - split.push_back(MEDLoader::MEDFieldDoublePerCellType(curType,0,nbComp,pt2-pt,wCellIdsPT,0)); - wCellIdsPT+=std::distance(pt,pt2); + const MEDCouplingFieldDiscretizationGauss *disc=static_cast(f->getDiscretization()); + const DataArrayInt *arr=disc->getArrayOfDiscIds(); + MEDCouplingAutoRefCountObjectPtr da,daTmp1; + if(!cellIdsPerType) + da=arr->selectByTupleId2(std::distance(connI,pt),std::distance(connI,pt2),1); + else + { + daTmp1=DataArrayInt::New(); + daTmp1->useArray(const_cast(cellIdsPerType),false,CPP_DEALLOC,szOfChunk,1); + MEDCouplingAutoRefCountObjectPtr daTmp2=daTmp1->deepCpy(); + daTmp2->applyLin(1,std::distance(connI,pt)); + da=arr->selectByTupleId(daTmp2->begin(),daTmp2->end()); + } + std::vector differentIds; + std::vector parts=da->partitionByDifferentValues(differentIds); + std::vector< MEDCouplingAutoRefCountObjectPtr > partsAuto(parts.size()); + int jj=0; + for(std::vector::const_iterator it=parts.begin();it!=parts.end();it++,jj++) + partsAuto[jj]=parts[jj]; + jj=0; + for(std::vector::const_iterator it=parts.begin();it!=parts.end();it++,jj++) + { + if(!cellIdsPerType) + { + if(parts[jj]->getNumberOfTuples()==szOfChunk && parts[jj]->isIdentity()) + split.push_back(MEDLoader::MEDFieldDoublePerCellType(curType,0,nbComp,szOfChunk,1,0,0)); + else + split.push_back(MEDLoader::MEDFieldDoublePerCellType(curType,0,nbComp,parts[jj]->getNumberOfTuples(),1,parts[jj]->getConstPointer(),0)); + } + else + { + MEDCouplingAutoRefCountObjectPtr tmp=daTmp1->selectByTupleId(parts[jj]->begin(),parts[jj]->end()); + split.push_back(MEDLoader::MEDFieldDoublePerCellType(curType,0,nbComp,tmp->getNumberOfTuples(),1,tmp->getConstPointer(),0)); + } + } + if(!cellIdsPerType) + wCellIdsPT+=szOfChunk; } pt=pt2; } @@ -2637,7 +2755,7 @@ void MEDLoaderNS::writeFieldTryingToFitExistingMesh(const char *fileName, const throw INTERP_KERNEL::Exception(oss.str().c_str()); } MEDCouplingAutoRefCountObjectPtr m=MEDLoader::ReadUMeshFromFile(fileName,f->getMesh()->getName(),f2); - MEDCouplingAutoRefCountObjectPtr m2=MEDCouplingUMesh::MergeUMeshes(m,(MEDCouplingUMesh *)f->getMesh()); + MEDCouplingAutoRefCountObjectPtr m2=MEDCouplingUMesh::MergeUMeshes(m,static_cast(f->getMesh())); bool areNodesMerged; int newNbOfNodes; MEDCouplingAutoRefCountObjectPtr da=m2->mergeNodes(MEDLoader::_EPS_FOR_NODE_COMP,areNodesMerged,newNbOfNodes); diff --git a/src/MEDLoader/MEDLoader.hxx b/src/MEDLoader/MEDLoader.hxx index 61536db38..7fd9f43b8 100644 --- a/src/MEDLoader/MEDLoader.hxx +++ b/src/MEDLoader/MEDLoader.hxx @@ -66,17 +66,19 @@ class MEDLOADER_EXPORT MEDLoader class MEDFieldDoublePerCellType { public: - MEDFieldDoublePerCellType(INTERP_KERNEL::NormalizedCellType type, double *values, int ncomp, int ntuple, const int *cellIdPerType, const char *locName); + MEDFieldDoublePerCellType(INTERP_KERNEL::NormalizedCellType type, double *values, int ncomp, int nGeoElt, int nbi, const int *cellIdPerType, const char *locName); INTERP_KERNEL::NormalizedCellType getType() const { return _type; } int getNbComp() const { return _ncomp; } - int getNbOfTuple() const { return _ntuple; } - int getNbOfValues() const { return _ncomp*_ntuple; } + int getNbOfGeoElt() const { return _ngeo_elt; } + int getNbOfTuple() const { return _nbi*_ngeo_elt; } + int getNbOfValues() const { return _ncomp*_nbi*_ngeo_elt; } double *getArray() const { return _values; } const std::string& getLocName() const { return _loc_name; } const std::vector& getCellIdPerType() const { return _cell_id_per_type; } void releaseArray(); private: - int _ntuple; + int _ngeo_elt; + int _nbi; int _ncomp; double *_values; std::string _loc_name; diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py index 1622b2980..194def721 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -1432,6 +1432,156 @@ class MEDLoaderTest(unittest.TestCase): # mfd.write(fname,2) pass + + def testGaussWriteOnPfl1(self): + fname="Pyfile49.med" + fname2="Pyfile50.med" + coords=DataArrayDouble([0.,0.,0.,1.,1.,1.,1.,0.,0.,0.5,0.5,1.,1.,0.5,0.5,0.],8,2) + mQ8=MEDCouplingUMesh("",2) ; mQ8.setCoords(coords) + mQ8.allocateCells(1) + mQ8.insertNextCell(NORM_QUAD8,range(8)) + mQ8.finishInsertingCells() + mQ4=MEDCouplingUMesh("",2) ; mQ4.setCoords(coords) + mQ4.allocateCells(1) + mQ4.insertNextCell(NORM_QUAD4,range(4)) + mQ4.finishInsertingCells() + mT3=MEDCouplingUMesh("",2) ; mT3.setCoords(coords) + mT3.allocateCells(1) + mT3.insertNextCell(NORM_TRI3,range(3)) + mT3.finishInsertingCells() + + tr=[[0.,4.],[2.,4.],[4.,4.],[6.,4.],[8.,4.],[10.,4.],[12.,4.],[14.,4.],[16.,4.],[18.,4.],[20.,4.],[0.,0.],[2.,0.], [0.,2.],[2.,2.],[4.,2.],[6.,2.],[8.,2.],[10.,2.],[12.,2.]] + ms=11*[mT3]+2*[mQ4]+7*[mQ8] + ms[:]=(elt.deepCpy() for elt in ms) + for m,t in zip(ms,tr): + d=m.getCoords() ; d+= t + pass + m=MEDCouplingUMesh.MergeUMeshes(ms) + m.setName("mesh") + m2=m[:13] ; m2.setName(m.getName()) + ### Use case 1 : Pfl on all tri3 and on all quad4. If we were on CELLS or GAUSS_NE no pfl were needed. But here 2 discs in tri3. + ### So here 2 pfls will be created (pfl_TRI3_loc_0 and pfl_TRI3_loc_1) + f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,ONE_TIME) + f.setMesh(m2) + f.setTime(4.5,1,2) + da=DataArrayDouble(34) ; da.iota(3.) + f.setArray(da) + f.setName("fieldCellOnPflWithoutPfl") + f.setGaussLocalizationOnCells([0,1,2,3,4,5,6,7,8],[0.,0.,1.,0.,1.,1.],[0.3,0.3,0.7,0.7],[0.8,0.2]) + f.setGaussLocalizationOnCells([9,10],[0.,0.,1.,0.,1.,1.],[0.3,0.3,0.7,0.7,0.8,0.8],[0.8,0.07,0.13]) + f.setGaussLocalizationOnCells([11,12],[0.,0.,1.,0.,1.,1.,0.,1.],[0.3,0.3,0.7,0.7,0.8,0.8,0.8,0.8,0.8,0.8],[0.8,0.07,0.1,0.01,0.02]) + f.checkCoherency() + # + mm=MEDFileUMesh() + mm.setMeshAtLevel(0,m) + mm.write(fname,2) + # + f1ts=MEDFileField1TS.New() + pfl=DataArrayInt(range(13)) ; pfl.setName("pfl") + f1ts.setFieldProfile(f,mm,0,pfl) + f1ts.write(fname,0) + # + self.assertEqual(f1ts.getPfls(),('pfl_NORM_TRI3_loc_0', 'pfl_NORM_TRI3_loc_1')) + self.assertEqual(f1ts.getPflsReallyUsed(),('pfl_NORM_TRI3_loc_0', 'pfl_NORM_TRI3_loc_1')) + da1=DataArrayInt([0,1,2,3,4,5,6,7,8]) ; da1.setName("pfl_NORM_TRI3_loc_0") + self.assertTrue(f1ts.getProfile("pfl_NORM_TRI3_loc_0").isEqual(da1)) + da1=DataArrayInt([9,10]) ; da1.setName("pfl_NORM_TRI3_loc_1") + self.assertTrue(f1ts.getProfile("pfl_NORM_TRI3_loc_1").isEqual(da1)) + self.assertEqual(f1ts.getLocs(),('Loc_fieldCellOnPflWithoutPfl_NORM_TRI3_0', 'Loc_fieldCellOnPflWithoutPfl_NORM_TRI3_1', 'Loc_fieldCellOnPflWithoutPfl_NORM_QUAD4_2')) + self.assertEqual(f1ts.getLocsReallyUsed(),('Loc_fieldCellOnPflWithoutPfl_NORM_TRI3_0', 'Loc_fieldCellOnPflWithoutPfl_NORM_TRI3_1', 'Loc_fieldCellOnPflWithoutPfl_NORM_QUAD4_2')) + # + dataRead=MEDFileData.New(fname) + mRead=dataRead.getMeshes()[0] + f1tsRead=dataRead.getFields()[0][0] + f1tsRead.getFieldOnMeshAtLevel(ON_GAUSS_PT,0,mRead) + f2=f1tsRead.getFieldOnMeshAtLevel(ON_GAUSS_PT,0,mRead) + self.assertTrue(f.isEqual(f2,1e-12,1e-12)) + f2_bis=MEDLoader.ReadFieldGauss(fname,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2]) + f2_bis.checkCoherency() + self.assertTrue(f.isEqual(f2_bis,1e-12,1e-12)) + # + MEDLoader.WriteField(fname2,f,True) + f2_ter=MEDLoader.ReadFieldGauss(fname2,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2]) + self.assertTrue(f.isEqual(f2_ter,1e-12,1e-12)) + ## Use case 2 : Pfl on part tri3 with 2 disc and on part quad8 with 1 disc + f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,ONE_TIME) + pfl=DataArrayInt([1,2,5,6,8,9,15,16,17,18]) ; pfl.setName("pfl2") + m2=m[pfl] ; m2.setName(m.getName()) + f.setMesh(m2) + f.setTime(4.5,1,2) + da=DataArrayDouble(35) ; da.iota(3.) + f.setArray(da) + f.setName("fieldCellOnPflWithoutPfl2") + f.setGaussLocalizationOnCells([0,1,3],[0.,0.,1.,0.,1.,1.],[0.3,0.3,0.7,0.7],[0.8,0.2]) + f.setGaussLocalizationOnCells([2,4,5],[0.,0.,1.,0.,1.,1.],[0.3,0.3,0.7,0.7,0.8,0.8],[0.8,0.07,0.13]) + f.setGaussLocalizationOnCells([6,7,8,9],[0.,0.,1.,0.,1.,1.,0.,1.,0.5,0.,1.,0.5,0.5,1.,0.,0.5],[0.3,0.3,0.7,0.7,0.8,0.8,0.8,0.8,0.8,0.8],[0.8,0.07,0.1,0.01,0.02]) + f.checkCoherency() + # + mm=MEDFileUMesh() + mm.setMeshAtLevel(0,m) + mm.write(fname,2) + f1ts=MEDFileField1TS.New() + f1ts.setFieldProfile(f,mm,0,pfl) + self.assertEqual(f1ts.getPfls(),('pfl2_NORM_TRI3_loc_0','pfl2_NORM_TRI3_loc_1','pfl2_NORM_QUAD8_loc_2')) + self.assertEqual(f1ts.getProfile("pfl2_NORM_TRI3_loc_0").getValues(),[1,2,6]) + self.assertEqual(f1ts.getProfile("pfl2_NORM_TRI3_loc_1").getValues(),[5,8,9]) + self.assertEqual(f1ts.getProfile("pfl2_NORM_QUAD8_loc_2").getValues(),[2,3,4,5]) + f1ts.write(fname,0) + dataRead=MEDFileData.New(fname) + mRead=dataRead.getMeshes()[0] + f1tsRead=dataRead.getFields()[0][0] + f1tsRead.getFieldOnMeshAtLevel(ON_GAUSS_PT,0,mRead) + f3=f1tsRead.getFieldOnMeshAtLevel(ON_GAUSS_PT,0,mRead) + f3.renumberCells([0,1,3,2,4,5,6,7,8,9]) + self.assertTrue(f.isEqual(f3,1e-12,1e-12)) + f3_bis=MEDLoader.ReadFieldGauss(fname,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2]) + f3_bis.renumberCells([0,1,3,2,4,5,6,7,8,9]) + self.assertTrue(f.isEqual(f3_bis,1e-12,1e-12)) + # + MEDLoader.WriteField(fname2,f,True) + f3_ter=MEDLoader.ReadFieldGauss(fname2,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2]) + f3_ter.renumberCells([0,1,3,2,4,5,6,7,8,9]) + self.assertTrue(f.isEqual(f3_ter,1e-12,1e-12)) + ## Use case 3 : no pfl but creation of pfls due to gauss pts + f=MEDCouplingFieldDouble.New(ON_GAUSS_PT,ONE_TIME) + f.setMesh(m) + f.setTime(4.5,1,2) + da=DataArrayDouble(60) ; da.iota(3.) + f.setArray(da) + f.setName("fieldCellWithoutPfl") + f.setGaussLocalizationOnCells([0,1,2,3,4,5,6,7,8],[0.,0.,1.,0.,1.,1.],[0.3,0.3,0.7,0.7],[0.8,0.2]) + f.setGaussLocalizationOnCells([9,10],[0.,0.,1.,0.,1.,1.],[0.3,0.3,0.7,0.7,0.8,0.8],[0.8,0.07,0.13]) + f.setGaussLocalizationOnCells([11,12],[0.,0.,1.,0.,1.,1.,0.,1.],[0.3,0.3,0.7,0.7,0.8,0.8,0.8,0.8,0.8,0.8],[0.8,0.07,0.1,0.01,0.02]) + f.setGaussLocalizationOnCells([13,14,15,17,18],[0.,0.,1.,0.,1.,1.,0.,1.,0.5,0.,1.,0.5,0.5,1.,0.,0.5],[0.3,0.3,0.7,0.7,0.8,0.8,0.8,0.8],[0.8,0.1,0.03,0.07]) + f.setGaussLocalizationOnCells([16,19],[0.,0.,1.,0.,1.,1.,0.,1.,0.5,0.,1.,0.5,0.5,1.,0.,0.5],[0.3,0.3,0.7,0.7,0.8,0.8],[0.8,0.1,0.1]) + f.checkCoherency() + mm=MEDFileUMesh() + mm.setMeshAtLevel(0,m) + f1ts=MEDFileField1TS.New() + f1ts.setFieldNoProfileSBT(f) + self.assertEqual(f1ts.getPfls(),('Pfl_fieldCellWithoutPfl_NORM_TRI3_0','Pfl_fieldCellWithoutPfl_NORM_TRI3_1','Pfl_fieldCellWithoutPfl_NORM_QUAD8_3','Pfl_fieldCellWithoutPfl_NORM_QUAD8_4')) + self.assertEqual(f1ts.getProfile("Pfl_fieldCellWithoutPfl_NORM_TRI3_0").getValues(),[0,1,2,3,4,5,6,7,8]) + self.assertEqual(f1ts.getProfile("Pfl_fieldCellWithoutPfl_NORM_TRI3_1").getValues(),[9,10]) + self.assertEqual(f1ts.getProfile("Pfl_fieldCellWithoutPfl_NORM_QUAD8_3").getValues(),[0,1,2,4,5]) + self.assertEqual(f1ts.getProfile("Pfl_fieldCellWithoutPfl_NORM_QUAD8_4").getValues(),[3,6]) + mm.write(fname,2) + f1ts.write(fname,0) + # + dataRead=MEDFileData.New(fname) + mRead=dataRead.getMeshes()[0] + f1tsRead=dataRead.getFields()[0][0] + f3=f1tsRead.getFieldOnMeshAtLevel(ON_GAUSS_PT,0,mRead) + f3.renumberCells([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,17,18,16,19]) + self.assertTrue(f.isEqual(f3,1e-12,1e-12)) + f3_bis=MEDLoader.ReadFieldGauss(fname,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2]) + f3_bis.renumberCells([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,17,18,16,19]) + self.assertTrue(f.isEqual(f3_bis,1e-12,1e-12)) + # + MEDLoader.WriteField(fname2,f,True) + f3_ter=MEDLoader.ReadFieldGauss(fname2,m.getName(),0,f.getName(),f.getTime()[1],f.getTime()[2]) + f3_ter.renumberCells([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,17,18,16,19]) + self.assertTrue(f.isEqual(f3_ter,1e-12,1e-12)) + pass pass unittest.main() diff --git a/src/MEDMEMCppTest/CMakeLists.txt b/src/MEDMEMCppTest/CMakeLists.txt index ad869500a..423cc0fb7 100644 --- a/src/MEDMEMCppTest/CMakeLists.txt +++ b/src/MEDMEMCppTest/CMakeLists.txt @@ -26,6 +26,7 @@ INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/../INTERP_KERNEL ${CMAKE_CURRENT_SOURCE_DIR}/../INTERP_KERNEL/Bases ${CMAKE_CURRENT_SOURCE_DIR}/../INTERP_KERNEL/GaussPoints + ${CMAKE_CURRENT_SOURCE_DIR}/../INTERP_KERNEL/Geometric2D ) SET(MEDMEMCppTest_SOURCES diff --git a/src/MEDOP/cmp/CMakeLists.txt b/src/MEDOP/cmp/CMakeLists.txt index 165ca2d82..8579b38e5 100644 --- a/src/MEDOP/cmp/CMakeLists.txt +++ b/src/MEDOP/cmp/CMakeLists.txt @@ -50,7 +50,7 @@ SET(COMMON_LIBS ${SalomeGenericObj} medcoupling interpkernel - ${MED3_LIBS} + ${MED3_LIBS_C_ONLY} ${HDF5_LIBS} ${OMNIORB_LIBS} ${PLATFORM_LIBS} diff --git a/src/MEDOP/doc/models/medop.xmi b/src/MEDOP/doc/models/medop.xmi index 01758265f..9422c56f0 100644 --- a/src/MEDOP/doc/models/medop.xmi +++ b/src/MEDOP/doc/models/medop.xmi @@ -1,5 +1,5 @@ - + umbrello uml modeller http://uml.sf.net @@ -151,39 +151,39 @@ - - - + + + - - - + + + - - - + + + - - + + - + @@ -199,23 +199,23 @@ - + - - - + + + - - - + + + @@ -223,7 +223,7 @@ - + @@ -258,7 +258,7 @@ - + @@ -291,7 +291,7 @@ - + diff --git a/src/MEDOP/doc/sphinx/CMakeLists.txt b/src/MEDOP/doc/sphinx/CMakeLists.txt index 54da68859..cd0b113f9 100644 --- a/src/MEDOP/doc/sphinx/CMakeLists.txt +++ b/src/MEDOP/doc/sphinx/CMakeLists.txt @@ -20,21 +20,6 @@ IF(SPHINX_STATUS) SET(srcdir ${CMAKE_CURRENT_SOURCE_DIR}) CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/conf.py.in ${CMAKE_CURRENT_BINARY_DIR}/conf.py @ONLY) - #FILE(GLOB MEDOP_DOC_RST "${CMAKE_CURRENT_SOURCE_DIR}/*.rst") - - #FOREACH(SRCFNAME ${MEDOP_DOC_RST}) - # GET_FILENAME_COMPONENT(FNAME ${SRCFNAME} NAME) - # CONFIGURE_FILE(${SRCFNAME} ${CMAKE_CURRENT_BINARY_DIR}/${FNAME} COPY_ONLY) - #ENDFOREACH(FNAME ${MEDOP_DOC_RST}) - - #FILE(MAKE_DIRECTORY _static) - #CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/_static/xmed.css ${CMAKE_CURRENT_BINARY_DIR}/_static/xmed.css COPY_ONLY) - - #FILE(GLOB MEDOP_DOC_PNG_RST "${CMAKE_CURRENT_SOURCE_DIR}/images/*.png") - #FOREACH(SRCFNAME ${MEDOP_DOC_PNG_RST}) - # GET_FILENAME_COMPONENT(FNAME ${SRCFNAME} NAME) - # CONFIGURE_FILE(${SRCFNAME} ${CMAKE_CURRENT_BINARY_DIR}/images/${FNAME} COPY_ONLY) - #ENDFOREACH(FNAME ${MEDOP_DOC_RST}) INSTALL(CODE "EXECUTE_PROCESS(COMMAND ${SPHINX_EXECUTABLE_TO_FIND} -c ${CMAKE_CURRENT_BINARY_DIR} -b html -d doctrees -D latex_paper_size=a4 ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/html)") diff --git a/src/MEDOP/doc/sphinx/Makefile.am b/src/MEDOP/doc/sphinx/Makefile.am index a28b03d44..2482d9030 100644 --- a/src/MEDOP/doc/sphinx/Makefile.am +++ b/src/MEDOP/doc/sphinx/Makefile.am @@ -71,27 +71,23 @@ html: RSTFILES= \ index.rst \ - xmed-specifications.rst \ - xmed-develguide.rst \ - xmed-userguide.rst + medop-specifications.rst \ + medop-develguide.rst \ + medop-userguide.rst # Files on the development of the prototype (version 2010) RSTFILES+=\ - xmed-prototype-overview.rst \ - xmed-prototype-develguide.rst \ - xmed-prototype-medmem.rst + medop-prototype-overview.rst \ + medop-prototype-develguide.rst \ + medop-prototype-medmem.rst # Files containing definitions and references RSTFILES+=\ - xmed-definitions.rst \ - xmed-references.rst \ - xmed-workingnotes-2010.rst \ - xmed-workingnotes-2011.rst \ - xmed-workingnotes-2012.rst - -# Files on annexe topics -RSTFILES+=\ - salomedoc.rst + medop-definitions.rst \ + medop-references.rst \ + medop-workingnotes-2010.rst \ + medop-workingnotes-2011.rst \ + medop-workingnotes-2012.rst EXTRA_DIST+= $(RSTFILES) diff --git a/src/MEDOP/doc/sphinx/_static/xmed.css b/src/MEDOP/doc/sphinx/_static/medop.css similarity index 100% rename from src/MEDOP/doc/sphinx/_static/xmed.css rename to src/MEDOP/doc/sphinx/_static/medop.css diff --git a/src/MEDOP/doc/sphinx/conf.py.in b/src/MEDOP/doc/sphinx/conf.py.in index 1127d1ba2..8259ef916 100644 --- a/src/MEDOP/doc/sphinx/conf.py.in +++ b/src/MEDOP/doc/sphinx/conf.py.in @@ -127,7 +127,7 @@ html_theme_options = { # The stylecheet file will be searched within the static path, while # the layout.html file will be searched within the template path # (Note that this parameter can't be used together with html_theme. Exclusive) -html_style = 'xmed.css' +html_style = 'medop.css' # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, @@ -170,7 +170,7 @@ html_copy_source = True #html_file_suffix = '' # Output file base name for HTML help builder. -htmlhelp_basename = 'xmeddoc' +htmlhelp_basename = 'medopdoc' # Options for LaTeX output @@ -185,10 +185,10 @@ latex_font_size = '10pt' # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, author, document class [howto/manual]). latex_documents = [ - ('index', 'xmed-alldoc.tex', 'Documentation du module XMED', 'G. Boulant', 'manual'), - ('xmed-specifications', 'xmed-specifications.tex', 'Module XMED - Specifications', 'G. Boulant', 'manual'), - ('xmed-develguide', 'xmed-develguide.tex', 'Module XMED - Guide de developpement', 'G. Boulant', 'manual'), - ('xmed-userguide', 'xmed-userguide.tex', 'Module XMED - Guide d\'utilisation', 'G. Boulant', 'manual') + ('index', 'medop-alldoc.tex', 'Documentation du module MED', 'G. Boulant', 'manual'), + ('medop-specifications', 'medop-specifications.tex', 'Module MED - Specifications', 'G. Boulant', 'manual'), + ('medop-develguide', 'medop-develguide.tex', 'Module MED - Guide de developpement', 'G. Boulant', 'manual'), + ('medop-userguide', 'medop-userguide.tex', 'Module MED - Guide d\'utilisation', 'G. Boulant', 'manual') ] # The name of an image file (relative to this directory) to place at the top of diff --git a/src/MEDOP/doc/sphinx/index.rst b/src/MEDOP/doc/sphinx/index.rst index 90fdc6b46..1989de788 100644 --- a/src/MEDOP/doc/sphinx/index.rst +++ b/src/MEDOP/doc/sphinx/index.rst @@ -1,12 +1,17 @@ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - Documentation du module XMED -%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%% + Documentation du module MED +%%%%%%%%%%%%%%%%%%%%%%%%%%%% -Le module SALOME nommé XMED (pour eXtension MED) est l'espace de -développement des fonctions de manipulation de champs dans SALOME. Le -contenu de ce module est amené à intégrer le module MED pour former la -future version en préparation pour la version SALOME 7 de 2012. +Le module SALOME MED (pour Modèle d'Echange de Données) fournit la +bibliothèque MEDCoupling (bibliothèque C++ dédiée à la manipulation de +maillages et de champs conformes au modèle MED), ainsi qu'une +interface graphique pour la réalisation des opérations de manipulation +les plus usuelles. + +.. warning:: La partie interface graphique du module MED (composant + logiciel dénommé MEDOP) doit être considérée comme un + prototype pour la version SALOME6. Documentation principale ======================== @@ -14,9 +19,9 @@ Documentation principale .. toctree:: :maxdepth: 1 - xmed-specifications.rst - xmed-develguide.rst - xmed-userguide.rst + medop-specifications.rst + medop-develguide.rst + medop-userguide.rst Documentation du prototype 2010 =============================== @@ -27,9 +32,9 @@ analyses de conception (maquette 2010 sur base MEDMEM) .. toctree:: :maxdepth: 1 - xmed-prototype-overview.rst - xmed-prototype-develguide.rst - xmed-prototype-medmem.rst + medop-prototype-overview.rst + medop-prototype-develguide.rst + medop-prototype-medmem.rst Documentation annexe ==================== @@ -37,8 +42,7 @@ Documentation annexe .. toctree:: :maxdepth: 1 - xmed-references.rst - xmed-workingnotes-2010.rst - xmed-workingnotes-2011.rst - xmed-workingnotes-2012.rst - salomedoc.rst + medop-references.rst + medop-workingnotes-2010.rst + medop-workingnotes-2011.rst + medop-workingnotes-2012.rst diff --git a/src/MEDOP/doc/sphinx/xmed-definitions.rst b/src/MEDOP/doc/sphinx/medop-definitions.rst similarity index 100% rename from src/MEDOP/doc/sphinx/xmed-definitions.rst rename to src/MEDOP/doc/sphinx/medop-definitions.rst diff --git a/src/MEDOP/doc/sphinx/xmed-develguide.rst b/src/MEDOP/doc/sphinx/medop-develguide.rst similarity index 78% rename from src/MEDOP/doc/sphinx/xmed-develguide.rst rename to src/MEDOP/doc/sphinx/medop-develguide.rst index be5d72bab..20d49c61a 100644 --- a/src/MEDOP/doc/sphinx/xmed-develguide.rst +++ b/src/MEDOP/doc/sphinx/medop-develguide.rst @@ -2,100 +2,60 @@ :keywords: maillage, champ, manipulation, med, développement :author: Guillaume Boulant -.. include:: xmed-definitions.rst +.. include:: medop-definitions.rst -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -Module XMED: Guide de développement -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +Module MED: Guide de développement du composant MEDOP +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -(|XMED_DEVELGUIDE_PDF|_) +Le composant logiciel MEDOP est un élément du module MED. Il fournit +une interface utilisateur pour la manipulation de maillages et de +champs, composée d'une interface texte (TUI) et d'une interface +graphique (GUI). L'interface graphique constitue l'interface graphique +du module MED. -Ce document est la documentation technique du module XMED. Il fournit -les instructions à suivre pour installer le module en vue d'un travail -de développement, puis décrit les éléments de conception qui -structurent le module. +Ce document est la documentation technique du composant MEDOP. Il +fournit les instructions à suivre pour installer le composant en vue +d'un travail de développement, puis décrit les éléments de conception. .. contents:: Sommaire :local: :backlinks: none -.. warning:: Ce document est en travaux. Tant que cet avis n'aura pas - disparu, veuillez en considérer le plan et le contenu encore - incomplets, temporaires et sujets à caution. - -Mise en place d'un espace de développement +Mise en place de l'espace de développement ========================================== -Gestion de configuration du module XMED ---------------------------------------- - -Les sources du module (répertoire ``xmed``) sont archivés en dépôt de -configuration dans une base git du projet NEPAL. Ils peuvent être -récupérés au moyen de la commande:: - - $ git clone git@cli70rw.der.edf.fr:xom/xmed.git - -Cette commande installe un répertoire ``xmed`` contenant l'ensemble -des sources du module XMED. - -Le module XMED a pour pré-requis logiciel la plateforme SALOME: - -* SALOME version 6.1.3 (au moins) à télécharger à l'URL - http://pal.der.edf.fr/pal/projets/pal/releases/V6_1_3 -* On peut également utiliser une version dérivée comme SALOME-MECA 2010.1 -* Installer la plate-forme choisie selon les instructions fournies. - -Le module XMED utilise également une bibliothèque interne au projet -NEPAL, appelée XSALOME, et qui fournit une extension aux fonctions de -SALOME pour un usage de développement (XSALOME signifie eXtension -SALOME). Les sources de cette bibliothèque doivent être récupérés au -moyen de la commande:: - - $ git clone git@cli70rw.der.edf.fr:xom/xsalome.git - -Cette commande installe un répertoire ``xsalome`` contenant l'ensemble -des sources de la bibliothèque XSALOME. - -.. note:: La bibliothèque XSALOME n'est pas un module SALOME mais une - simple bibliothèque de fonctions qui complète ou rend plus facile - d'utilisation les fonctions de SALOME. Elle NE DOIT EN AUCUN CAS - être intégrée à d'autres projets que les projets internes NEPAL ou - MAILLAGE. Il s'agit en effet d'une bibliothèque de transition qui - héberge des développements destinés à être reversés dans la - plate-forme SALOME. Le contenu et les interfaces de XSALOME ne peut - donc être garanti sur le long terme. - -Installation et lancement de l'application ------------------------------------------- +Gestion de configuration du composant MEDOP +------------------------------------------- -L'installation suppose qu'une version 6.1.3 de SALOME (ou plus) est -disponible et que le shell de travail est étendu avec l'environnement -de SALOME. En général, par des commandes de la forme:: +Le composant logiciel MEDOP est un package du module SALOME MED, +hébergé dans l'espace source au niveau du sous-répertoire +`src/MEDOP`. La gestion des fichiers sources est donc intégrée dans le +module SALOME MED. - $ . /where/is/salome/prerequis.sh - $ . /where/is/salome/envSalome.sh +Organisation des sources du composant MEDOP +------------------------------------------- -La compilation des modules xsalome et xmed suit le standard SALOME. La -bibliothèque xsalome est un prérequis à la compilation de xmed. Pour -cela, la variable d'environnement XSALOME_DIR doit être spécifiée pour -la configuration de la procédure de reconstruction de xmed:: - - $ export XSALOME_DIR= +Le répertoire source `src/MEDOP` distingue les sous-répertoires +suivants: -Aprés l'installation de xmed, il est possible de générer -automatiquement une application SALOME prête à l'emploi pour la -manipulation de champs:: +* cmp: package containing the SALOME components +* tui: package containing the python user interface +* gui: package containing the graphical user interface (the GUI part + of the MED module) +* res: resources files associated to the MEDOP package (icons, config + files, data files, ...) +* exe: additional executable programs that can be launched from the + MEDOP framework - $ /bin/salome/xmed/appligen/appligen.sh +Construction du composant MEDOP +------------------------------- -Cette commande génére un répertoire ``appli`` à l'emplacement où elle -est exécutée. Il reste à lancer l'application SALOME au moyen de la -commande:: - - $ ./appli/runAppli -k +Intégré à la construction du module MED. Le composant MEDOP dépend de +MEDCoupling et MEDLoader uniquement. -Exécution des tests unitaires ------------------------------ +Exécution des tests unitaires du composant MEDOP +------------------------------------------------ Les tests unitaires peuvent être exécutés au moyen de scripts python lancés depuis une session shell SALOME. Dans un nouveau shell, taper:: @@ -227,8 +187,8 @@ Ecrire un service CORBA qui retourne une structure CORBA: -ANNEXE: Bug en cours -==================== +ANNEXE A: Bug en cours +====================== TO FIX: @@ -237,3 +197,79 @@ TO FIX: reference correcte vers le maillage). * le script de test test_medoperation.py plante si le module xmed n'a pas été chargé avec des données chargées. + +ANNEXE B: Traçabilité avec le module XMED +========================================= + +Le module SALOME de nom XMED est l'espace de développement initial du +composant logiciel MEDOP, intégré aujourd'hui au module MED. Cette +annexe est la notice technique de ce module, qui reste disponible mais +qui n'est plus maintenu. + +Gestion de configuration du module XMED +--------------------------------------- + +Les sources du module (répertoire ``xmed``) sont archivés en dépôt de +configuration dans une base git du projet NEPAL. Ils peuvent être +récupérés au moyen de la commande:: + + $ git clone git@cli70rw.der.edf.fr:xom/xmed.git + +Cette commande installe un répertoire ``xmed`` contenant l'ensemble +des sources du module XMED. + +Le module XMED a pour pré-requis logiciel la plateforme SALOME: + +* SALOME version 6.1.3 (au moins) à télécharger à l'URL + http://pal.der.edf.fr/pal/projets/pal/releases/V6_1_3 +* On peut également utiliser une version dérivée comme SALOME-MECA 2010.1 +* Installer la plate-forme choisie selon les instructions fournies. + +Le module XMED utilise également une bibliothèque interne au projet +NEPAL, appelée XSALOME, et qui fournit une extension aux fonctions de +SALOME pour un usage de développement (XSALOME signifie eXtension +SALOME). Les sources de cette bibliothèque doivent être récupérés au +moyen de la commande:: + + $ git clone git@cli70rw.der.edf.fr:xom/xsalome.git + +Cette commande installe un répertoire ``xsalome`` contenant l'ensemble +des sources de la bibliothèque XSALOME. + +.. note:: La bibliothèque XSALOME n'est pas un module SALOME mais une + simple bibliothèque de fonctions qui complète ou rend plus facile + d'utilisation les fonctions de SALOME. Elle NE DOIT EN AUCUN CAS + être intégrée à d'autres projets que les projets internes NEPAL ou + MAILLAGE. Il s'agit en effet d'une bibliothèque de transition qui + héberge des développements destinés à être reversés dans la + plate-forme SALOME. Le contenu et les interfaces de XSALOME ne peut + donc être garanti sur le long terme. + +Installation et lancement de l'application +------------------------------------------ + +L'installation suppose qu'une version 6.1.3 de SALOME (ou plus) est +disponible et que le shell de travail est étendu avec l'environnement +de SALOME. En général, par des commandes de la forme:: + + $ . /where/is/salome/prerequis.sh + $ . /where/is/salome/envSalome.sh + +La compilation des modules xsalome et xmed suit le standard SALOME. La +bibliothèque xsalome est un prérequis à la compilation de xmed. Pour +cela, la variable d'environnement XSALOME_DIR doit être spécifiée pour +la configuration de la procédure de reconstruction de xmed:: + + $ export XSALOME_DIR= + +Aprés l'installation de xmed, il est possible de générer +automatiquement une application SALOME prête à l'emploi pour la +manipulation de champs:: + + $ /bin/salome/xmed/appligen/appligen.sh + +Cette commande génére un répertoire ``appli`` à l'emplacement où elle +est exécutée. Il reste à lancer l'application SALOME au moyen de la +commande:: + + $ ./appli/runAppli -k diff --git a/src/MEDOP/doc/sphinx/xmed-prototype-develguide.rst b/src/MEDOP/doc/sphinx/medop-prototype-develguide.rst similarity index 100% rename from src/MEDOP/doc/sphinx/xmed-prototype-develguide.rst rename to src/MEDOP/doc/sphinx/medop-prototype-develguide.rst diff --git a/src/MEDOP/doc/sphinx/xmed-prototype-medmem.rst b/src/MEDOP/doc/sphinx/medop-prototype-medmem.rst similarity index 99% rename from src/MEDOP/doc/sphinx/xmed-prototype-medmem.rst rename to src/MEDOP/doc/sphinx/medop-prototype-medmem.rst index da331c05e..2302f7b70 100644 --- a/src/MEDOP/doc/sphinx/xmed-prototype-medmem.rst +++ b/src/MEDOP/doc/sphinx/medop-prototype-medmem.rst @@ -2,7 +2,7 @@ :keywords: maillage, champ, MED, MEDMEM :author: Guillaume Boulant -.. include:: xmed-definitions.rst +.. include:: medop-definitions.rst %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Note de travail concernant l'utilisation de MEDMEM diff --git a/src/MEDOP/doc/sphinx/xmed-prototype-overview.rst b/src/MEDOP/doc/sphinx/medop-prototype-overview.rst similarity index 100% rename from src/MEDOP/doc/sphinx/xmed-prototype-overview.rst rename to src/MEDOP/doc/sphinx/medop-prototype-overview.rst diff --git a/src/MEDOP/doc/sphinx/xmed-references.rst b/src/MEDOP/doc/sphinx/medop-references.rst similarity index 96% rename from src/MEDOP/doc/sphinx/xmed-references.rst rename to src/MEDOP/doc/sphinx/medop-references.rst index 30d66ec7f..9be8cdc5f 100644 --- a/src/MEDOP/doc/sphinx/xmed-references.rst +++ b/src/MEDOP/doc/sphinx/medop-references.rst @@ -2,7 +2,7 @@ ANNEXE: Références documentaires %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -.. include:: xmed-definitions.rst +.. include:: medop-definitions.rst Documents de référence: diff --git a/src/MEDOP/doc/sphinx/xmed-specifications.rst b/src/MEDOP/doc/sphinx/medop-specifications.rst similarity index 99% rename from src/MEDOP/doc/sphinx/xmed-specifications.rst rename to src/MEDOP/doc/sphinx/medop-specifications.rst index 1f8cdabaf..09ca88cd2 100644 --- a/src/MEDOP/doc/sphinx/xmed-specifications.rst +++ b/src/MEDOP/doc/sphinx/medop-specifications.rst @@ -2,13 +2,11 @@ :keywords: maillage, champ, manipulation, med :author: Guillaume Boulant -.. include:: xmed-definitions.rst +.. include:: medop-definitions.rst -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -Module XMED: Spécifications fonctionnelles et techniques -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -(|XMED_SPECIFICATIONS_PDF|_) +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +Module MED: Spécifications fonctionnelles et techniques +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Ce texte présente les spécifications informatiques pour le développement d'un module de manipulation de champs qui répond à diff --git a/src/MEDOP/doc/sphinx/xmed-userguide.rst b/src/MEDOP/doc/sphinx/medop-userguide.rst similarity index 97% rename from src/MEDOP/doc/sphinx/xmed-userguide.rst rename to src/MEDOP/doc/sphinx/medop-userguide.rst index f35266013..bf00e8b1e 100644 --- a/src/MEDOP/doc/sphinx/xmed-userguide.rst +++ b/src/MEDOP/doc/sphinx/medop-userguide.rst @@ -2,30 +2,29 @@ :keywords: maillage, champ, manipulation, guide utilisateur :author: Guillaume Boulant -.. include:: xmed-definitions.rst +.. include:: medop-definitions.rst -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -Module XMED: Guide d'utilisation -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +Module MED: Guide d'utilisation de l'interface graphique +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -(|XMED_USERGUIDE_PDF|_) - -Ce document est un guide rapide pour l'utilisation du module MED. Il -montre comment utiliser le module sur la base de quelques exemples de -référence, inspirés des cas d'utilisation identifiés lors de l'analyse -des besoins en matière de manipulation de champs. +Ce document est un guide rapide pour l'utilisation de l'interface +graphique du module MED. Il montre comment utiliser le module sur la +base de quelques exemples de référence, inspirés des cas d'utilisation +identifiés lors de l'analyse des besoins en matière de manipulation de +champs. .. warning:: Le document est autonome, mais il est vivement conseillé de parcourir au préalable (ou en parallèle) :doc:`le document de - spécifications`, au moins pour fixer les + spécifications`, au moins pour fixer les concepts et la terminologie. .. contents:: Sommaire :local: :backlinks: none -Présentation générale du module XMED -==================================== +Présentation générale du module MED +=================================== L'ergonomie générale d'utilisation du module de manipulation de champs est inspirée des logiciels comme octave ou scilab. Elle associe une @@ -71,8 +70,8 @@ processus de la forme suivante: 5. Enregistrement d'une partie des champs produits dans un fichier med -Tour rapide des fonctions du module XMED -======================================== +Tour rapide des fonctions du module MED +======================================= Cette section présente des exemples d'utilisation du module XMED sous la forme de "storyboard", et illustre au passage les fonctions mises à @@ -656,8 +655,8 @@ carte de champ: .. _xmed.userguide.tui: -Utilisation de l'interface textuelle du moduel XMED (TUI) -========================================================= +Utilisation de l'interface textuelle du moduel MED (TUI) +======================================================== Toutes les opérations menées au moyen de l'interface graphique peuvent être réalisées (avec plus ou moins de facilité) avec l'interface diff --git a/src/MEDOP/doc/sphinx/xmed-workingnotes-2010.rst b/src/MEDOP/doc/sphinx/medop-workingnotes-2010.rst similarity index 100% rename from src/MEDOP/doc/sphinx/xmed-workingnotes-2010.rst rename to src/MEDOP/doc/sphinx/medop-workingnotes-2010.rst diff --git a/src/MEDOP/doc/sphinx/xmed-workingnotes-2011.rst b/src/MEDOP/doc/sphinx/medop-workingnotes-2011.rst similarity index 99% rename from src/MEDOP/doc/sphinx/xmed-workingnotes-2011.rst rename to src/MEDOP/doc/sphinx/medop-workingnotes-2011.rst index 8ba8b8068..2c38e64bb 100644 --- a/src/MEDOP/doc/sphinx/xmed-workingnotes-2011.rst +++ b/src/MEDOP/doc/sphinx/medop-workingnotes-2011.rst @@ -2,7 +2,7 @@ :keywords: maillage, champ, manipulation :author: Guillaume Boulant -.. include:: xmed-definitions.rst +.. include:: medop-definitions.rst %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ANNEXE: Note de travail concernant le chantier XMED 2011 diff --git a/src/MEDOP/doc/sphinx/xmed-workingnotes-2012.rst b/src/MEDOP/doc/sphinx/medop-workingnotes-2012.rst similarity index 98% rename from src/MEDOP/doc/sphinx/xmed-workingnotes-2012.rst rename to src/MEDOP/doc/sphinx/medop-workingnotes-2012.rst index 011190ef4..b6ecb6d37 100644 --- a/src/MEDOP/doc/sphinx/xmed-workingnotes-2012.rst +++ b/src/MEDOP/doc/sphinx/medop-workingnotes-2012.rst @@ -2,7 +2,7 @@ :keywords: maillage, champ, manipulation :author: Guillaume Boulant -.. include:: xmed-definitions.rst +.. include:: medop-definitions.rst %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ANNEXE: Note de travail concernant le chantier XMED 2012 diff --git a/src/MEDOP/doc/sphinx/salomedoc.rst b/src/MEDOP/doc/sphinx/salomedoc.rst deleted file mode 100644 index fc2f1fdc8..000000000 --- a/src/MEDOP/doc/sphinx/salomedoc.rst +++ /dev/null @@ -1,231 +0,0 @@ -.. meta:: - :keywords: SALOME, development - :author: Guillaume Boulant - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -Annexe : Règles de développement SALOME -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -Cette annexe est un recueil de techniques de développement spécifiques -à l'environnement SALOME et utilisées pour la mise au point du module -XMED. Elles sont a priori utilisables pour d'autres contexte de -développement dans SALOME. - -.. TODO: récupérer les fonctions génériques de VisuGUI_Tools.cxx -.. TODO: récupérer les fonctions génériques de SMESGGUI_utils.cxx - -.. contents:: Sommaire - :local: - :backlinks: none - -Récupérer la sélection dans l'arbre d'étude -=========================================== - -Dans une classe dérivée de ``SalomeApp_Module``, on peut utiliser un -code de la forme suivante: - -.. code-block:: cpp - - #include - #include - #include - #include - - // ... - - // Get the selected object in the study (SObject) - LightApp_SelectionMgr* aSelectionMgr = this->getApp()->selectionMgr(); - SALOME_ListIO aListIO; - aSelectionMgr->selectedObjects(aListIO); - - // Analyse the selection. There can be more than one item. - SALOME_ListIteratorOfListIO It (aListIO); - for (; It.More(); It.Next()) { - Handle(SALOME_InteractiveObject) anIO = It.Value(); - SALOMEDS::SObject_var aSObject = aStudy->FindObjectID(anIO->getEntry()); - - // Check if the selected object is relevant for the operation - // ... - - // Process the SObject if it's relevant - // ... - - } - -On peut noter qu'une variable ``aStudy`` est requise. Elle représente -l'étude SALOME sur laquelle s'oppère la sélection. L'étude active -(impliquée dans la sélection) peut être obtenue au moyen du -gestionnaire d'étude (voir :ref:`ci-dessous `). - -Réglage du curseur graphique -============================ - -Dans le cas où le traitement est long, il peut être intéressant -d'encadrer l'opération par un vérouillage du curseur de sélection: - -.. code-block:: cpp - - QApplication::setOverrideCursor(Qt::WaitCursor); - - // Do the job - // ... - - QApplication::restoreOverrideCursor(); - - -Les variables pour la gestion de l'étude -======================================== - -Les variables CORBA -------------------- - -Les variables CORBA comme le serveur de noms (naming service) et le -gestionnaire de cycle de vie des objets (LifeCycleCRORBA) sont -fréquement utilisés. Dans le contexte d'une application (classe de -type ``SalomeApp_Module``), il est possible de récupérer simplement -des instances de ces variables par les commandes suivantes: - -.. code-block:: cpp - - #include - #include - - CORBA::ORB_var orb = SalomeApp_Application::orb(); - SALOMEDSClient_StudyManager* studyMgr = SalomeApp_Application::studyMgr(); - SALOME_NamingService* namingService = SalomeApp_Application::namingService(); - SALOME_LifeCycleCORBA* lcc = SalomeApp_Application::lcc(); - -Pour un usage en dehors de l'application graphique (par exemple au -niveau du container), l'orb peut être obtenu par les mécanismes -standard d'omniORB: - -.. code-block:: cpp - - CORBA::ORB_var orb = CORBA::ORB_init(0,0); - -L'orb est par exemple utile à récupérer pour la sérialisation des -objets CORBA et la manipulation des références sous forme de chaîne de -caractères: - -.. code-block:: cpp - - // We suppose here that we have a CORBA object reference (object of - // type *_ptr or *_var), for example a SALOME_MED::MED object. - SALOME_MED::MED_ptr medObj = ... // anything to get this object - QString medIOR = orb->object_to_string(medObj); - - SALOME_MED::MED_ptr anOtherRefToMedObj = orb->string_to_object(medIOR) - -.. note: this serialization can be used to communicate between a GUI - and a component in a container, or between the C++ context and the - python context. - -.. _salomedoc_getActiveStudy: - -Récupérer l'étude active ------------------------- - -Le concept d'étude active est un concept GUI. Il désigne l'étude en -cours d'usage au niveau de l'interface graphique. - -.. note: Pour rappel, l'étude est un objet CORBA de type - ``SALOMEDS::Study`` qui héberge physiquement les ``SObject`` - pointant vers les données. L'arbre d'étude ("Object browser") est - une représentation graphique de cet objet. - -L'étude active peut être obtenue au moyen du gestionnaire -d'étude. Dans le corps d'une classe de type ``SalomeApp_Module``, ceci -peut se faire par un code de la forme suivante: - -.. code-block:: cpp - - #include "SALOMEconfig.h" - #include CORBA_SERVER_HEADER(SALOMEDS) - #include - #include - - // ... - - // Get the study id of the active study - SalomeApp_Study* appStudy = dynamic_cast (this->getApp()->activeStudy()); - _PTR(Study) aCStudy = appStudy->studyDS(); - int aStudyID = aCStudy->StudyId(); - - // Then get the study manager - SALOME_NamingService *aNamingService = SalomeApp_Application::namingService(); - CORBA::Object_var anObject = aNamingService->Resolve("/myStudyManager"); - SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow(anObject); - - // Finally, request the study manager for the study (SALOMEDS::Study) - SALOMEDS::Study_var aStudy = aStudyManager->GetStudyByID(aStudyID); - - -Communiquer avec la console python -================================== - -La console python désigne l'interpréteur embarqué dans l'interface -graphique de SALOME (GUI). Elle est également désignée comme -l'interface textuelle de SALOME (TUI) car elle permet de piloter -SALOME au moyen de commandes en syntaxe python. - -Le paragraphe montre comment communiquer avec cette interface texte -depuis le contexte C++ de l'interface graphique, en particulier pour -déclencher l'exécution de commandes. - -Le code se situe donc au sein d'une classe de type -``SalomeApp_Module`` (de laquelle hérite la partie graphique d'un -module SALOME, de nom ``GUI``). Cette classe possède une -méthode ``getApp()`` par laquelle on peut récupérer une instance de la -console python embarquée (this->getApp()->pythonConsole()). - -Le code suivant illustre l'envoie d'une commande python par ce -mécanisme. Dans cette exemple, on défini une variable ``id`` dans la -console python comme l'identifiant de l'étude active: - -.. code-block:: cpp - - #include - #include - #include - - PyConsole_Console * pyConsole = getApp()->pythonConsole(); - - QStringList commands; - commands+="import salome"; - commands+="id=salome.myStudyId"; - - QStringListIterator it(commands); - while (it.hasNext()) { - pyConsole->exec(it.next()); - } - -Dans ce deuxième exemple, on cherche à reconstituer dans le contexte -de la console python un pointer vers un objet med instancié dans le -contexte C++ de l'application graphique. Pour cela, on communique la -référence de l'objet sous la forme sérialisé (IOR pour un objet -CORBA): - -.. code-block:: cpp - - #include - #include - #include - #include - - // We suppose here that we have a CORBA object reference (object of - // type *_ptr or *_var), for example a SALOME_MED::MED object. - SALOME_MED::MED_ptr medObj = ... // anything to get this object - - // Get the IOR of this object - QString medIOR = SalomeApp_Application::orb()->object_to_string(medObj); - - PyConsole_Console * pyConsole = getApp()->pythonConsole(); - - QStringList commands; - commands+="import salome"; - commands+=QString("med=salome.orb.string_to_object(\"%1\")").arg(medIOR); - - QStringListIterator it(commands); - while (it.hasNext()) { - pyConsole->exec(it.next()); - } -- 2.39.2