From a6944e8a83d9a34b1e79475352fbca4a5719a244 Mon Sep 17 00:00:00 2001 From: ageay Date: Thu, 4 Apr 2013 10:41:42 +0000 Subject: [PATCH] MEDMEM suppression --- src/RENUMBER/CMakeLists.txt | 5 +- src/RENUMBER/Makefile.am | 8 +- src/RENUMBER/RenumberingFactory.hxx | 7 +- src/RENUMBER/renumbering.cxx | 352 ++++------------------------ 4 files changed, 58 insertions(+), 314 deletions(-) diff --git a/src/RENUMBER/CMakeLists.txt b/src/RENUMBER/CMakeLists.txt index fc48b2695..befd5a395 100644 --- a/src/RENUMBER/CMakeLists.txt +++ b/src/RENUMBER/CMakeLists.txt @@ -22,7 +22,8 @@ INCLUDE_DIRECTORIES( ${METIS_INCLUDE_DIRS} ${MED3_INCLUDE_DIRS} ${HDF5_INCLUDE_DIRS} - ${CMAKE_CURRENT_SOURCE_DIR}/../MEDMEM + ${CMAKE_CURRENT_SOURCE_DIR}/../MEDLoader + ${CMAKE_CURRENT_SOURCE_DIR}/../MEDCoupling ${CMAKE_CURRENT_SOURCE_DIR}/../INTERP_KERNEL ${CMAKE_CURRENT_SOURCE_DIR}/../INTERP_KERNEL/Bases ${CMAKE_CURRENT_SOURCE_DIR}/../INTERP_KERNEL/Geometric2D @@ -45,7 +46,7 @@ SET(renumber_SOURCES renumbering.cxx ) -SET(renumbercpp_LDFLAGS medmem) +SET(renumbercpp_LDFLAGS medloader) SET(renumber_DEFINITIONS "${HDF5_DEFINITIONS} ${MED3_DEFINITIONS} ${BOOST_DEFINITIONS} ${PLATFORM_DEFINITIONS}") IF(MED_ENABLE_METIS) diff --git a/src/RENUMBER/Makefile.am b/src/RENUMBER/Makefile.am index d6eaefb04..ce20cfd8c 100644 --- a/src/RENUMBER/Makefile.am +++ b/src/RENUMBER/Makefile.am @@ -16,8 +16,6 @@ # # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -# MED MEDMEM : MED files in memory - include $(top_srcdir)/adm_local/unix/make_common_starter.am # this directory must be recompiled before Test folder @@ -53,13 +51,13 @@ endif librenumber_la_CPPFLAGS= $(MED3_INCLUDES) $(HDF5_INCLUDES) @CXXTMPDPTHFLAGS@ \ $(BOOST_CPPFLAGS) \ - -I$(srcdir)/../MEDMEM -I$(srcdir)/../INTERP_KERNEL/Bases \ + -I$(srcdir)/../MEDLoader -I$(srcdir)/../MEDCoupling -I$(srcdir)/../INTERP_KERNEL/Bases \ -I$(srcdir)/../INTERP_KERNEL/GaussPoints \ -I$(srcdir)/../INTERP_KERNEL librenumber_la_LDFLAGS= #libmedsplitter_la_LDFLAGS= $(MED3_LIBS_C_ONLY) $(HDF5_LIBS) $(STDLIB) \ -# ../MEDMEM/libmedmem.la +# ../MEDLoader/libmedloader.la if MED_ENABLE_METIS librenumber_la_CPPFLAGS+= $(METIS_CPPFLAGS) @@ -75,7 +73,7 @@ if MED_ENABLE_KERNEL endif librenumber_la_LDFLAGS+= $(MED3_LIBS_C_ONLY) $(HDF5_LIBS) $(STDLIB) \ - ../MEDMEM/libmedmem.la ../INTERP_KERNEL/libinterpkernel.la + ../MEDLoader/libmedloader.la ../MEDCoupling/libmedcoupling.la ../INTERP_KERNEL/libinterpkernel.la # Executables targets bin_PROGRAMS= renumber diff --git a/src/RENUMBER/RenumberingFactory.hxx b/src/RENUMBER/RenumberingFactory.hxx index 7006d730a..1e1bde8f9 100644 --- a/src/RENUMBER/RenumberingFactory.hxx +++ b/src/RENUMBER/RenumberingFactory.hxx @@ -17,13 +17,14 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -#ifndef RENUMBERINGFACTORY_HXX_ -#define RENUMBERINGFACTORY_HXX_ +#ifndef __RENUMBERINGFACTORY_HXX__ +#define __RENUMBERINGFACTORY_HXX__ -#include #include "RENUMBERDefines.hxx" #include "RENUMBER_Renumbering.hxx" +#include + namespace MED_RENUMBER { RENUMBER_EXPORT Renumbering* RenumberingFactory(const std::string& s); diff --git a/src/RENUMBER/renumbering.cxx b/src/RENUMBER/renumbering.cxx index d520f4db6..765fb7f8f 100644 --- a/src/RENUMBER/renumbering.cxx +++ b/src/RENUMBER/renumbering.cxx @@ -17,180 +17,27 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -#include -#include -#include -#include +#include "MEDFileData.hxx" +#include "MEDFileMesh.hxx" +#include "MEDFileField.hxx" -#include "MEDMEM_Family.hxx" -#include "MEDMEM_Mesh.hxx" -#include "MEDMEM_Meshing.hxx" -#include "MEDMEM_MedMeshDriver.hxx" -#include "MEDMEM_Connectivity.hxx" -#include "MEDMEM_Field.hxx" -#include "MEDMEM_DriversDef.hxx" -#include "MEDMEM_MedFileBrowser.hxx" -#include "MEDMEM_MedMeshDriver.hxx" +#include "MEDCouplingUMesh.hxx" #include "RenumberingFactory.hxx" #include -using namespace MEDMEM; +#include +#include +#include +#include + using namespace std; -using namespace MED_EN; +using namespace ParaMEDMEM; using namespace MED_RENUMBER; -void computeNeighbour(const MESH* mesh,const medGeometryElement& Type, vector >& neighbour, int& ntot,int& nb_cell) -{ - CONNECTIVITY* conn = (CONNECTIVITY*)mesh->getConnectivityptr(); - conn->calculateFullDescendingConnectivity(MED_CELL); - const int* rev_conn=mesh->getReverseConnectivity(MED_EN::MED_DESCENDING, MED_EN::MED_CELL); - const int* rev_conn_index=mesh->getReverseConnectivityIndex(MED_EN::MED_DESCENDING, MED_EN::MED_CELL); - int nb_face= mesh->getNumberOfElements(MED_FACE,MED_ALL_ELEMENTS); - int nb_edge = mesh->getNumberOfElements(MED_EDGE,MED_ALL_ELEMENTS); - nb_cell= mesh->getNumberOfElements(MED_CELL,Type); - - int nb_constituent; - if(mesh->getMeshDimension()==2) - nb_constituent = nb_edge; - else if (mesh->getMeshDimension()==3) - nb_constituent = nb_face; - else - throw MEDEXCEPTION("Wrong dimension"); - - neighbour.resize(nb_cell,(list)0); - ntot=0; - for(int i=0;i& iperm) -{ - /*if(Type==MED_POLYHEDRA) - { - int *conn_face_index_init=(int*)mesh.getPolyhedronFacesIndex(); - int *conn_index_init=(int*)mesh.getPolyhedronIndex(MED_FULL_INTERLACE); - int *conn_init=(int*)mesh.getPolyhedronConnectivity(MED_FULL_INTERLACE); - - int *conn_index_renum=new int[nb_cell+1]; - int *conn_face_index_renum=new int[conn_index_init[nb_cell]]; - int *conn_renum=new int[conn_face_index_init[conn_index_init[nb_cell]-1]-1]; - - int i_cell,i_face,i_conn; - int iter_face=0; - int iter_conn=0; - int i2; - conn_index_renum[0]=1; - conn_face_index_renum[0]=1; - for(i_cell=0;i_cellsetNodal(conn_renum,MED_CELL,Type,conn_index_renum); - delete[] conn_renum; - delete[] conn_index_renum; - } -} - -void changeFamily(MESH* mesh, const medGeometryElement& Type, const vector& perm) -{ - int nb_families=mesh->getNumberOfFamilies(MED_CELL); - for (int i=0;igetFamily(MED_CELL,i+1); - if (!family->isOnAllElements()) - { - int nb_elem=family->getNumberOfElements(Type); - int *number=(int *)family->getNumber(Type); - for(int j=0;j mesh_names,f_names; - nb_mesh=med_struct.getNumberOfMeshes(); - nb_fields=med_struct.getNumberOfFields(); - mesh_names=med_struct.getMeshNames(); - f_names=med_struct.getFieldNames(); - if(nb_mesh!=1) - { - cout << "There are many meshes in the file" << endl; return -1; } - if(mesh_names[0].c_str()!=meshname) - { - cout << "Mesh name does not match" << endl; - return -1; - } - vector field_names; - vector iternumber; - vector ordernumber; - vector types; - int nb_fields_tot=0; - for (int ifield = 0; ifield < nb_fields; ifield++) + // Reading file structure + cout << "Reading : " << flush; + MEDCouplingAutoRefCountObjectPtr fd=MEDFileData::New(filename_in); + MEDFileMesh *m=fd->getMeshes()->getMeshWithName(meshname.c_str()); + MEDFileUMesh *mc=dynamic_cast(m); + if(!mc) { - vector dtit=med_struct.getFieldIteration(f_names[ifield]); - for (vector::const_iterator iter =dtit.begin(); iter!=dtit.end(); iter++) - { - field_names.push_back(f_names[ifield]); - iternumber.push_back(iter->dt); - ordernumber.push_back(iter->it); - ++nb_fields_tot; - if(med_struct.getFieldType(f_names[ifield])==MED_EN::MED_REEL64) - types.push_back(1); - else - types.push_back(0); - - } + std::ostringstream oss; oss << "In file \"" << filename_in << "\" the mesh name \"" << meshname<< "\" exists but is not unstructured !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); } t_read_st=clock(); - + cout << (t_read_st-t_begin)/(double) CLOCKS_PER_SEC << "s" << endl << flush; // Reading mesh - MESH myMesh; - myMesh.setName(meshname); - MED_MESH_RDONLY_DRIVER *drv22=new MED_MESH_RDONLY_DRIVER(filename_in,&myMesh); - drv22->desactivateFacesComputation(); - int newDrv=myMesh.addDriver(*drv22); - delete drv22; - myMesh.read(newDrv); - int nb_type=myMesh.getNumberOfTypes(MED_CELL); - if (nb_type!=1) - { - cout << "Mesh must have only one type of cell" << endl; - return -1; - } - const medGeometryElement *Types = myMesh.getTypes(MED_CELL); - medGeometryElement Type=Types[0]; - - t_read_mesh=clock(); - MESH* workMesh=new MESH(myMesh); - cout << "Building the graph "; - cout.flush(); - int ntot,nb_cell; - vector > neighbour; - computeNeighbour(workMesh,Type,neighbour,ntot,nb_cell); - int* graph=new int[ntot]; - int* graph_index=new int[nb_cell+1]; - graph_index[0]=1; - int count=0; - for(int i=0;i::const_iterator it=neighbour[i].begin();it!=neighbour[i].end();++it) - { - graph[count]=*it; - ++count; - } - graph_index[i+1]=count+1; - } - - - // Compute permutation + MEDCouplingAutoRefCountObjectPtr workMesh=mc->getMeshAtLevel(0); + std::vector code=workMesh->getDistributionOfTypes(); + cout << "Building the graph : " << flush; + DataArrayInt *neighb=0,*neighbI=0; + workMesh->computeNeighborsOfCells(neighb,neighbI); + MEDCouplingAutoRefCountObjectPtr neighbSafe(neighb),neighbISafe(neighbI); + const int *graph=neighbSafe->begin(); + const int *graph_index=neighbISafe->begin(); + // Compute permutation iperm->new2old perm->old2new vector iperm,perm; - Renumbering* renumb= RenumberingFactory(type_renum); + Renumbering *renumb=RenumberingFactory(type_renum); renumb->renumber(graph,graph_index,nb_cell,iperm,perm); delete renumb; - delete workMesh; t_compute_graph=clock(); - cout << " : " << (t_compute_graph-t_read_mesh)/(double) CLOCKS_PER_SEC << "s" << endl; + cout << " : " << (t_compute_graph-t_read_st)/(double) CLOCKS_PER_SEC << "s" << endl; cout.flush(); - // Connectivity - cout << "Computing connectivity"; - cout.flush(); - MESH meshRenum(myMesh); - changeConnectivity(meshRenum,Type,nb_cell,iperm); - t_connectiv=clock(); - cout << " : " << (t_connectiv-t_compute_graph)/(double) CLOCKS_PER_SEC << "s" << endl; - cout.flush(); - - // Familles - cout << "Computing families "; - cout.flush(); - changeFamily(&meshRenum,Type,perm); - int drv3=meshRenum.addDriver(MED_DRIVER,filename_out,meshRenum.getName()); - meshRenum.write(drv3); - t_family=clock(); - cout << " : " << (t_family-t_connectiv)/(double) CLOCKS_PER_SEC << "s" << endl; - cout.flush(); - - // Fields - cout << "Computing fields "; - cout.flush(); - bool exist_type; - for(int ifield=0;ifieldrenumberCells(&perm[0],false); + mc->setMeshAtLevel(0,workMesh); + const DataArrayInt *famField=mc->getFamilyFieldAtLevel(0); + if(famField) { - exist_type=false; - FIELD myField(MED_DRIVER,filename_in,field_names[ifield],iternumber[ifield],ordernumber[ifield]); - FIELD newField(myField); - const SUPPORT* mySupport=newField.getSupport(); - const medGeometryElement *typesOfSupport = mySupport->getTypes(); - for(int t=0;tgetNumberOfTypes();++t) - { - if(typesOfSupport[t]==Type) - { - exist_type=true; - break; - } - } - if(exist_type) - { - for(int i=0;igetNumberOfElements(Type);++i) - { - for(int j=0;j famField2=famField->renumber(&perm[0]); + mc->setFamilyFieldArr(0,famField2); } + mc->write(filename_out.c_str(),2); + t_family=clock(); + cout << " : " << (t_family-t_compute_graph)/(double) CLOCKS_PER_SEC << "s" << endl << flush; + // Fields + cout << "Reordering fields and writing : " << flush; + MEDFileFields *fs=fd->getFields(); + fs->renumberEntitiesLyingOnMesh(meshname.c_str(),code,code,&perm[0]); + fs->write(); t_field=clock(); - cout << " : " << (t_field-t_family)/(double) CLOCKS_PER_SEC << "s" << endl; - cout.flush(); - - delete[] graph_index; - delete[] graph; - + cout << " : " << (t_field-t_family)/(double) CLOCKS_PER_SEC << "s" << endl << flush; return 0; } -- 2.39.2