1 // Copyright (C) 2007-2015 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, or (at your option) any later version.
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 MEDCoupling;
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 MCAuto<MEDFileData> fd(MEDFileData::New(filename_in));
61 MEDFileMesh *m=fd->getMeshes()->getMeshWithName(meshname);
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 MCAuto<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 MCAuto<DataArrayInt> neighbSafe(neighb),neighbISafe(neighbI),ipermSafe,permSafe;
77 const int *graph=neighbSafe->begin();
78 const int *graph_index=neighbISafe->begin();
79 // Compute permutation iperm->new2old perm->old2new
80 DataArrayInt *iperm(0),*perm(0);
81 Renumbering *renumb=RenumberingFactory(type_renum);
82 renumb->renumber(graph,graph_index,workMesh->getNumberOfCells(),iperm,perm);
83 ipermSafe=iperm; permSafe=perm;
85 ipermSafe=0;//erase new2old, we are using only old 2 new
86 t_compute_graph=clock();
87 cout << " : " << (t_compute_graph-t_read_st)/(double) CLOCKS_PER_SEC << "s" << endl;
90 cout << "Reordering connectivity & families and writing : " << flush;
91 workMesh->renumberCells(perm->begin(),false);
92 mc->setMeshAtLevel(0,workMesh);
93 const DataArrayInt *famField=mc->getFamilyFieldAtLevel(0);
96 MCAuto<DataArrayInt> famField2=famField->renumber(perm->begin());
97 mc->setFamilyFieldArr(0,famField2);
99 mc->write(filename_out,2);
101 cout << " : " << (t_family-t_compute_graph)/(double) CLOCKS_PER_SEC << "s" << endl << flush;
103 cout << "Reordering fields and writing : " << flush;
104 MEDFileFields *fs=fd->getFields();
107 for(int i=0;i<fs->getNumberOfFields();i++)
109 MEDFileFieldMultiTS *fmts=dynamic_cast<MEDFileFieldMultiTS *>(fs->getFieldAtPos(i));
111 if(fmts->getMeshName()==meshname)
113 for(int j=0;j<fmts->getNumberOfTS();j++)
115 MEDFileField1TS *f1ts=dynamic_cast<MEDFileField1TS*>(fmts->getTimeStepAtPos(j));
117 DataArrayDouble *arr=f1ts->getUndergroundDataArray();
118 arr->renumberInPlace(perm->begin());
122 fs->write(filename_out,0);
123 //fs->renumberEntitiesLyingOnMesh(meshname,code,code,o2n); bugged
126 cout << " : " << (t_field-t_family)/(double) CLOCKS_PER_SEC << "s" << endl << flush;