1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "MEDFileData.hxx"
21 #include "MEDFileMesh.hxx"
22 #include "MEDFileField.hxx"
24 #include "MEDCouplingUMesh.hxx"
26 #include "RenumberingFactory.hxx"
35 using namespace ParaMEDMEM;
36 using namespace MED_RENUMBER;
38 int main(int argc, char** argv)
40 double t_begin,t_read_st,t_compute_graph,t_family,t_field;
44 cerr << "Usage : " << argv[0]
45 << " filename_in meshname method[BOOST/METIS] filename_out" << endl << endl;
48 string filename_in = argv[1];
49 string meshname = argv[2];
50 string type_renum = argv[3];
51 string filename_out = argv[4];
53 if(type_renum!="METIS" && type_renum!="BOOST")
55 cout << "The method has to be METIS or BOOST!" << endl;
58 // Reading file structure
59 cout << "Reading : " << flush;
60 MEDCouplingAutoRefCountObjectPtr<MEDFileData> fd=MEDFileData::New(filename_in.c_str());
61 MEDFileMesh *m=fd->getMeshes()->getMeshWithName(meshname.c_str());
62 MEDFileUMesh *mc=dynamic_cast<MEDFileUMesh *>(m);
65 std::ostringstream oss; oss << "In file \"" << filename_in << "\" the mesh name \"" << meshname<< "\" exists but is not unstructured !";
66 throw INTERP_KERNEL::Exception(oss.str().c_str());
69 cout << (t_read_st-t_begin)/(double) CLOCKS_PER_SEC << "s" << endl << flush;
71 MEDCouplingAutoRefCountObjectPtr<MEDCouplingUMesh> workMesh=mc->getMeshAtLevel(0);
72 std::vector<int> code=workMesh->getDistributionOfTypes();
73 cout << "Building the graph : " << flush;
74 DataArrayInt *neighb=0,*neighbI=0;
75 workMesh->computeNeighborsOfCells(neighb,neighbI);
76 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> neighbSafe(neighb),neighbISafe(neighbI);
77 const int *graph=neighbSafe->begin();
78 const int *graph_index=neighbISafe->begin();
79 // Compute permutation iperm->new2old perm->old2new
80 vector<int> iperm,perm;
81 Renumbering *renumb=RenumberingFactory(type_renum);
82 renumb->renumber(graph,graph_index,workMesh->getNumberOfCells(),iperm,perm);
84 iperm.clear();//erase new2old, we are using only old 2 new
85 t_compute_graph=clock();
86 cout << " : " << (t_compute_graph-t_read_st)/(double) CLOCKS_PER_SEC << "s" << endl;
89 cout << "Reordering connectivity & families and writing : " << flush;
90 workMesh->renumberCells(&perm[0],false);
91 mc->setMeshAtLevel(0,workMesh);
92 const DataArrayInt *famField=mc->getFamilyFieldAtLevel(0);
95 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> famField2=famField->renumber(&perm[0]);
96 mc->setFamilyFieldArr(0,famField2);
98 mc->write(filename_out.c_str(),2);
100 cout << " : " << (t_family-t_compute_graph)/(double) CLOCKS_PER_SEC << "s" << endl << flush;
102 cout << "Reordering fields and writing : " << flush;
103 MEDFileFields *fs=fd->getFields();
104 MEDCouplingAutoRefCountObjectPtr<DataArrayInt> o2n=DataArrayInt::New();
105 o2n->useArray(&perm[0],false,CPP_DEALLOC,perm.size(),1);
106 fs->renumberEntitiesLyingOnMesh(meshname.c_str(),code,code,o2n);
107 fs->write(filename_out.c_str(),0);
109 cout << " : " << (t_field-t_family)/(double) CLOCKS_PER_SEC << "s" << endl << flush;