const std::vector<int>& value ):
_index( DataArrayInt::New() ), _value( DataArrayInt::New() )
{
+ _index->reserve( index.size() );
_index->insertAtTheEnd( index.begin(), index.end() );
+ _value->reserve( value.size() );
_value->insertAtTheEnd( value.begin(), value.end() );
}
{
return ((MEDCouplingSkyLineArray*)this)->_value;
}
+
+std::string MEDCouplingSkyLineArray::simpleRepr() const
+{
+ std::ostringstream oss;
+ oss << "MEDCouplingSkyLineArray" << std::endl;
+ oss << " Nb of items: " << getNumberOf() << std::endl;
+ oss << " Nb of values: " << getLength() << std::endl;
+ oss << " Index:" << std::endl;
+ oss << " ";
+ const int * i = _index->begin();
+ for ( ; i != _index->end(); ++i )
+ oss << *i << " ";
+ oss << std::endl;
+ oss << " Value:" << std::endl;
+ oss << " ";
+ const int * v = _value->begin();
+ int cnt = 0;
+ for ( i = _index->begin(); v != _value->end(); ++v, ++cnt )
+ {
+ if ( cnt == *i )
+ {
+ oss << "| ";
+ ++i;
+ }
+ oss << *v << " ";
+ }
+ oss << std::endl;
+
+ return oss.str();
+}
DataArrayInt* getIndexArray() const;
DataArrayInt* getValueArray() const;
+
+ std::string simpleRepr() const;
};
}
# endif
const ParaMEDMEM::DataArrayInt* index;
const ParaMEDMEM::DataArrayInt* conn;
- conn=this->getNodalConnectivity();
+ conn=this->getNodalConnectivity(); // it includes a type as the 1st element!!!
index=this->getNodalConnectivityIndex();
int nbCells=this->getNumberOfCells();
const int* index_ptr=index->getConstPointer();
const int* conn_ptr=conn->getConstPointer();
- //creating graph arcs (cell to cell relations)
- //arcs are stored in terms of (index,value) notation
- // 0 3 5 6 6
- // 1 2 3 2 3 3
- // means 6 arcs (0,1), (0,2), (0,3), (1,2), (1,3), (2,3)
- // in present version arcs are not doubled but reflexive (1,1) arcs are present for each cell
+ //creating graph arcs (cell to cell relations)
+ //arcs are stored in terms of (index,value) notation
+ // 0 3 5 6 6
+ // 1 2 3 2 3 3
+ // means 6 arcs (0,1), (0,2), (0,3), (1,2), (1,3), (2,3)
+ // in present version arcs are not doubled but reflexive (1,1) arcs are present for each cell
- //warning here one node have less than or equal effective number of cell with it
- //but cell could have more than effective nodes
- //because other equals nodes in other domain (with other global inode)
+ //warning here one node have less than or equal effective number of cell with it
+ //but cell could have more than effective nodes
+ //because other equals nodes in other domain (with other global inode)
std::vector <int> cell2cell_index(nbCells+1,0);
std::vector <int> cell2cell;
cell2cell.reserve(3*nbCells);
for (int icell=0; icell<nbCells;icell++)
- {
- std::map<int,int > counter;
- for (int iconn=index_ptr[icell]; iconn<index_ptr[icell+1];iconn++)
{
- int inode=conn_ptr[iconn];
- for (int iconnr=indexr_ptr[inode]; iconnr<indexr_ptr[inode+1];iconnr++)
- {
- int icell2=revConn_ptr[iconnr];
- std::map<int,int>::iterator iter=counter.find(icell2);
- if (iter!=counter.end()) (iter->second)++;
- else counter.insert(std::make_pair(icell2,1));
- }
+ std::map<int,int > counter;
+ for (int iconn=index_ptr[icell]+1; iconn<index_ptr[icell+1];iconn++)
+ {
+ int inode=conn_ptr[iconn];
+ for (int iconnr=indexr_ptr[inode]; iconnr<indexr_ptr[inode+1];iconnr++)
+ {
+ int icell2=revConn_ptr[iconnr];
+ std::map<int,int>::iterator iter=counter.find(icell2);
+ if (iter!=counter.end()) (iter->second)++;
+ else counter.insert(std::make_pair(icell2,1));
+ }
+ }
+ for (std::map<int,int>::const_iterator iter=counter.begin();
+ iter!=counter.end(); iter++)
+ if (iter->second >= meshDim)
+ {
+ cell2cell_index[icell+1]++;
+ cell2cell.push_back(iter->first);
+ }
}
- for (std::map<int,int>::const_iterator iter=counter.begin();
- iter!=counter.end(); iter++)
- if (iter->second >= meshDim)
- {
- cell2cell_index[icell+1]++;
- cell2cell.push_back(iter->first);
- }
- }
indexr->decrRef();
revConn->decrRef();
cell2cell_index[0]=0;
for (int icell=0; icell<nbCells;icell++)
cell2cell_index[icell+1]=cell2cell_index[icell]+cell2cell_index[icell+1];
- //filling up index and value to create skylinearray structure
+ //filling up index and value to create skylinearray structure
MEDCouplingSkyLineArray* array=new MEDCouplingSkyLineArray(cell2cell_index,cell2cell);
return array;
}
self.assertTrue( value.isEqual( sla2.getValueArray() ))
self.assertEqual( 4, sla2.getNumberOf() )
self.assertEqual( 6, sla2.getLength() )
+
+ indexVec = ivec(); indexVec.reserve( len( index ))
+ for i in index: indexVec.push_back( i[0] )
+ valueVec = ivec(); valueVec.reserve( len( value ))
+ for i in value: valueVec.push_back( i[0] )
+ sla3 = MEDCouplingSkyLineArray( indexVec, valueVec )
+ self.assertTrue( index.isEqual( sla3.getIndexArray() ))
+ self.assertTrue( value.isEqual( sla3.getValueArray() ))
+ self.assertEqual( 4, sla3.getNumberOf() )
+ self.assertEqual( 6, sla3.getLength() )
+
+ pass
+
+ def testMEDCouplingUMeshgenerateGraph(self):
+ # cartesian mesh 3x3
+ arr=DataArrayDouble(4) ; arr.iota()
+ c=MEDCouplingCMesh() ; c.setCoords(arr,arr)
+ m=c.buildUnstructured()
+ graph = m.generateGraph()
+ # 0 1 2
+ # 3 4 5
+ # 6 7 8
+ valRef=[ 0,1,3,
+ 0,1,2,4,
+ 1,2,5,
+ 0,3,4,6,
+ 1,3,4,5,7,
+ 2,4,5,8,
+ 3,6,7,
+ 4,6,7,8,
+ 5,7,8]
+ self.assertEqual(valRef,list(graph.getValueArray().getValues()));
+
+ indRef=[0, 3, 7, 10, 14, 19, 23, 26, 30, 33]
+ self.assertEqual(indRef,list(graph.getIndexArray().getValues()));
pass
pass
//
static bool AreAlmostEqual(const std::vector<double>& v1, const std::vector<double>& v2, double eps);
};
-}
-namespace ParaMEDMEM
-{
+
class MEDCouplingSkyLineArray
{
public:
int getLength() const;
DataArrayInt* getIndexArray() const;
DataArrayInt* getValueArray() const;
+ %extend
+ {
+ std::string __str__() const throw(INTERP_KERNEL::Exception)
+ {
+ return self->simpleRepr();
+ }
+ }
};
}
return new MEDPartitioner(filedata,ndomains,library,creates_boundary_faces, create_joints, mesure_memory);
}
-MEDPARTITIONER::MEDPartitioner::MEDPartitioner(const std::string& filename, int ndomains, const std::string& library,bool creates_boundary_faces, bool create_joints, bool mesure_memory)
+MEDPARTITIONER::MEDPartitioner::MEDPartitioner(const std::string& filename, int ndomains, const std::string& library,bool creates_boundary_faces, bool create_joints, bool mesure_memory):
+ _input_collection( 0 ), _output_collection( 0 ), _new_topology( 0 )
{
MyGlobals::_World_Size=1;
MyGlobals::_Rank=0;
parallelizer.evaluateMemory();
}
-MEDPARTITIONER::MEDPartitioner::MEDPartitioner(const ParaMEDMEM::MEDFileData* filedata, int ndomains, const std::string& library,bool creates_boundary_faces, bool create_joints, bool mesure_memory)
+MEDPARTITIONER::MEDPartitioner::MEDPartitioner(const ParaMEDMEM::MEDFileData* filedata, int ndomains, const std::string& library,bool creates_boundary_faces, bool create_joints, bool mesure_memory):
+ _input_collection( 0 ), _output_collection( 0 ), _new_topology( 0 )
{
MyGlobals::_World_Size=1;
MyGlobals::_Rank=0;
parallelizer.evaluateMemory();
}
+MEDPARTITIONER::MEDPartitioner::~MEDPartitioner()
+{
+ delete _input_collection; _input_collection = 0;
+ delete _output_collection; _output_collection = 0;
+ delete _new_topology; _new_topology = 0;
+}
+
void MEDPARTITIONER::MEDPartitioner::createPartitionCollection(int ndomains, const std::string& library,bool creates_boundary_faces, bool create_joints, bool mesure_memory)
{
- ParallelTopology* aPT = (ParallelTopology*) _input_collection->getTopology();
- std::auto_ptr< Topology > new_topo;
+ //ParallelTopology* aPT = (ParallelTopology*) _input_collection->getTopology();
if (library == "metis")
- new_topo.reset( _input_collection->createPartition(ndomains,MEDPARTITIONER::Graph::METIS));
+ _new_topology = _input_collection->createPartition(ndomains,MEDPARTITIONER::Graph::METIS);
else
- new_topo.reset(_input_collection->createPartition(ndomains,MEDPARTITIONER::Graph::SCOTCH));
- _output_collection=new MeshCollection(*_input_collection,new_topo.get(),false,false);
+ _new_topology = _input_collection->createPartition(ndomains,MEDPARTITIONER::Graph::SCOTCH);
+ _output_collection=new MeshCollection(*_input_collection,_new_topology,false,false);
_output_collection->filterFaceOnCell();
}
#ifndef __MEDPARTITIONER_MEDPARTITIONER_HXX__
#define __MEDPARTITIONER_MEDPARTITIONER_HXX__
-#include "MEDFileData.hxx"
-#include "MEDCouplingSkyLineArray.hxx"
#include "MEDPARTITIONER_Graph.hxx"
#include <map>
{
class DataArrayInt;
class MEDFileData;
+ class MEDCouplingSkyLineArray;
}
namespace MEDPARTITIONER
void Write(const std::string& filename);
ParaMEDMEM::MEDFileData* getMEDFileData();
MEDPARTITIONER::Graph* Graph(ParaMEDMEM::MEDCouplingSkyLineArray* graph, Graph::splitter_type split=Graph::METIS, int* edgeweight=0);
+ ~MEDPartitioner();
+
private:
MEDPartitioner(const std::string& filename, int ndomains, const std::string& library,bool creates_boundary_faces, bool create_joints, bool mesure_memory);
MEDPartitioner(const ParaMEDMEM::MEDFileData* filedata, int ndomains, const std::string& library,bool creates_boundary_faces, bool create_joints, bool mesure_memory);
+ ParaMEDMEM::MEDFileData *convertToMEDFileData(MeshCollection* meshcollection);
void createPartitionCollection(int ndomains, const std::string& library,bool creates_boundary_faces, bool create_joints, bool mesure_memory);
+
+ private:
MeshCollection* _input_collection;
MeshCollection* _output_collection;
+ Topology* _new_topology;
};
}
#endif
}
else
{
- finalMeshName=(_collection->getMesh())[idomain]->getName();
+ finalMeshName=(_collection->getMesh())[idomain]->getName();
}
cellMesh->setName(finalMeshName);
mfm->setMeshAtLevel( 0, cellMesh );
-
+
faceMesh->checkCoherency();
if (faceMesh->getNumberOfCells()>0)
{
faceMesh->tryToShareSameCoordsPermute(*cellMesh, 1e-10);
+ faceMesh->setName(finalMeshName);
mfm->setMeshAtLevel( -1, faceMesh );
}
}
mfm->setJoints( joints );
}
+
+ return mfm;
}
ParaMEDMEM::MEDCouplingFieldDouble* MeshCollectionDriver::getField(std::string key, std::string description, ParaMEDMEM::DataArrayDouble* data, ParaMEDMEM::MEDFileMesh* mfm, int idomain) const
class MEDPartitioner
{
public:
- static MEDPartitioner *New(const std::string& filename, int ndomains=1, const std::string& library="metis",bool creates_boundary_faces=false, bool create_joints=false, bool mesure_memory=false) throw(INTERP_KERNEL::Exception);
- static MEDPartitioner *New(const ParaMEDMEM::MEDFileData* filedata, int ndomains=1, const std::string& library="metis",bool creates_boundary_faces=false, bool create_joints=false, bool mesure_memory=false) throw(INTERP_KERNEL::Exception);
- void Write(const std::string& filename) throw(INTERP_KERNEL::Exception);
- ParaMEDMEM::MEDFileData* getMEDFileData() throw(INTERP_KERNEL::Exception);
- MEDPARTITIONER::Graph* Graph(ParaMEDMEM::MEDCouplingSkyLineArray* graph, Graph::splitter_type split=Graph::METIS, int* edgeweight=0) throw(INTERP_KERNEL::Exception);
+ static MEDPartitioner *New(const std::string& filename, int ndomains=1, const std::string& library="metis",bool creates_boundary_faces=false, bool create_joints=false, bool mesure_memory=false) throw(INTERP_KERNEL::Exception);
+ static MEDPartitioner *New(const ParaMEDMEM::MEDFileData* filedata, int ndomains=1, const std::string& library="metis",bool creates_boundary_faces=false, bool create_joints=false, bool mesure_memory=false) throw(INTERP_KERNEL::Exception);
+ void Write(const std::string& filename) throw(INTERP_KERNEL::Exception);
+ ParaMEDMEM::MEDFileData* getMEDFileData() throw(INTERP_KERNEL::Exception);
+ MEDPARTITIONER::Graph* Graph(ParaMEDMEM::MEDCouplingSkyLineArray* graph, Graph::splitter_type split=Graph::METIS, int* edgeweight=0) throw(INTERP_KERNEL::Exception);
%extend
{
MEDPartitioner(const std::string& filename, int ndomains=1, const std::string& library="metis",bool creates_boundary_faces=false, bool create_joints=false, bool mesure_memory=false) throw(INTERP_KERNEL::Exception)
- {
- return MEDPartitioner::New(filename,ndomains,library,creates_boundary_faces, create_joints, mesure_memory);
- }
+ {
+ return MEDPartitioner::New(filename,ndomains,library,creates_boundary_faces, create_joints, mesure_memory);
+ }
MEDPartitioner(const ParaMEDMEM::MEDFileData* fileData, int ndomains=1, const std::string& library="metis",bool creates_boundary_faces=false, bool create_joints=false, bool mesure_memory=false) throw(INTERP_KERNEL::Exception)
- {
- return MEDPartitioner::New(fileData,ndomains,library,creates_boundary_faces, create_joints, mesure_memory);
- }
+ {
+ return MEDPartitioner::New(fileData,ndomains,library,creates_boundary_faces, create_joints, mesure_memory);
+ }
}
};
namespace MEDPARTITIONER
-{
+{
class Graph
{
public:
virtual void partGraph(int ndomain, const std::string& options_string="", ParaDomainSelector *sel=0) throw(INTERP_KERNEL::Exception);
};
-};
\ No newline at end of file
+};