Back to index

salome-med  6.5.0
MEDSPLITTER_API.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00028 #include "MEDSPLITTER_API.hxx"
00029 
00030 #include <string>
00031 #include "MEDMEM_define.hxx"
00032 #include "MEDMEM_Mesh.hxx"
00033 #include "MEDMEM_Family.hxx"
00034 #include "MEDSPLITTER_Graph.hxx"
00035 #include "MEDSPLITTER_MESHCollection.hxx"
00036 #include "MEDSPLITTER_Topology.hxx"
00037 #include "MEDSPLITTER_ParaDomainSelector.hxx"
00038 
00039 using namespace std;
00056 int medsplitter(const char* inputfilename, 
00057                 const char* mesh,
00058                 const char* outputfilename,  
00059                 int is_distributed,
00060                 int nbdomains,
00061                 int method,
00062                 int meshonly,
00063                 int plainmaster,
00064                 int createboundaryfaces,
00065                 int familysplitting,
00066                 int emptygroups)
00067 {                        
00068 
00069   //Pointer to the initial collection
00070   MEDSPLITTER::MESHCollection* collection; 
00071 
00072   // Loading the mesh collection
00073   string input(inputfilename);
00074 
00075   if (is_distributed ==0)
00076   {
00077     string meshname (mesh);
00078     collection=new MEDSPLITTER::MESHCollection(input,meshname);
00079   }
00080   else
00081     collection = new MEDSPLITTER::MESHCollection(input);
00082 
00083   // Creating the graph and partitioning it
00084   MEDSPLITTER::Topology* new_topo;
00085   if (method==0)
00086     new_topo = collection->createPartition(nbdomains,MEDSPLITTER::Graph::METIS);
00087   else
00088     new_topo = collection->createPartition(nbdomains,MEDSPLITTER::Graph::SCOTCH);
00089   
00090   // Creating a new mesh collection from the partitioning 
00091   MEDSPLITTER::MESHCollection new_collection(*collection, new_topo, familysplitting, emptygroups);
00092  
00093   //Writing the output files (master + MED files)
00094   if (plainmaster)
00095     new_collection.setDriverType(MEDSPLITTER::MedAscii);
00096   new_collection.setSubdomainBoundaryCreates(createboundaryfaces);
00097   string output(outputfilename);
00098   new_collection.write(output);
00099 
00100   // Casting the fields on the new collection
00101   if (meshonly!=0)
00102     new_collection.castAllFields(*collection);
00103   delete collection;
00104 
00105   return 0;
00106 }
00107 
00108 
00120 int medsplitter_para(const char* inputfilename, 
00121                      const char* outputfilename,  
00122                      const int   nprocs,
00123                      const int   method,
00124                      const       bool create_boundary_faces,
00125                      const       bool family_splitting)
00126 {
00127   // Parallelizer
00128   MEDSPLITTER::ParaDomainSelector parallelizer;
00129 
00130   // Loading the mesh collection
00131   MEDSPLITTER::MESHCollection collection (inputfilename, parallelizer);
00132 
00133   // Creating the graph and partitioning it   
00134   auto_ptr<MEDSPLITTER::Topology> new_topo;
00135   if (method==0)
00136     new_topo.reset( collection.createPartition(nprocs,MEDSPLITTER::Graph::METIS));
00137   else
00138     new_topo.reset( collection.createPartition(nprocs,MEDSPLITTER::Graph::SCOTCH));
00139 
00140   // Creating a new mesh collection from the partitioning 
00141   MEDSPLITTER::MESHCollection new_collection(collection, new_topo.get(),family_splitting);
00142   new_collection.setSubdomainBoundaryCreates(create_boundary_faces);
00143 
00144   //Writing the output files (master + MED files)
00145   string output(outputfilename);
00146   new_collection.write(output);
00147 
00148   return 0;
00149 }