1 // Copyright (C) 2007-2012 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
21 * API for the MEDSPLITTER tool
23 * API has a C binding so that it can be used
24 * in a C/C++ program and it can easily be wrapped
25 * in a Fortran program
28 #include "MEDSPLITTER_API.hxx"
31 #include "MEDMEM_define.hxx"
32 #include "MEDMEM_Mesh.hxx"
33 #include "MEDMEM_Family.hxx"
34 #include "MEDSPLITTER_Graph.hxx"
35 #include "MEDSPLITTER_MESHCollection.hxx"
36 #include "MEDSPLITTER_Topology.hxx"
37 #include "MEDSPLITTER_ParaDomainSelector.hxx"
41 * MEDSPLITTER high-level API
43 * \param inputfilename name of the input file
44 * \param mesh name of the input mesh (only used for the sequential input file case)
45 * \param outputfilename name out the master output file
46 * \param is_distributed sequential input (0) or distributed input (1)
47 * \param nbdomains number of subdomains
48 * \param method METIS(0) or SCOTCH(1)
49 * \param meshonly projects mesh and fields (0) or only the mesh (1)
50 * \param plainmaster creates a plain masterfile (1) instead of an XML file (0),
51 * \param createboundaryfaces creates the necessary faces so that face joints are created
52 * \param familysplitting preserves the family names (1) instead of focusing on the groups (0)
53 * \param emptygroups creates empty groups in zones that do not contain a group from the original domain
56 int medsplitter(const char* inputfilename,
58 const char* outputfilename,
64 int createboundaryfaces,
69 //Pointer to the initial collection
70 MEDSPLITTER::MESHCollection* collection;
72 // Loading the mesh collection
73 string input(inputfilename);
75 if (is_distributed ==0)
77 string meshname (mesh);
78 collection=new MEDSPLITTER::MESHCollection(input,meshname);
81 collection = new MEDSPLITTER::MESHCollection(input);
83 // Creating the graph and partitioning it
84 MEDSPLITTER::Topology* new_topo;
86 new_topo = collection->createPartition(nbdomains,MEDSPLITTER::Graph::METIS);
88 new_topo = collection->createPartition(nbdomains,MEDSPLITTER::Graph::SCOTCH);
90 // Creating a new mesh collection from the partitioning
91 MEDSPLITTER::MESHCollection new_collection(*collection, new_topo, familysplitting, emptygroups);
93 //Writing the output files (master + MED files)
95 new_collection.setDriverType(MEDSPLITTER::MedAscii);
96 new_collection.setSubdomainBoundaryCreates(createboundaryfaces);
97 string output(outputfilename);
98 new_collection.write(output);
100 // Casting the fields on the new collection
102 new_collection.castAllFields(*collection);
110 * Parallel MEDSPLITTER high-level API
112 * \param inputfilename name of the input distributed MED file
113 * \param outputfilename name out the master output file
114 * \param nprocs number of subdomains
115 * \param method METIS(0) or SCOTCH(1)
116 * \param create_boundary_faces creates the necessary faces so that faces joints are created in the output files
117 * \param family_splitting preserves the family names instead of focusing on the groups
120 int medsplitter_para(const char* inputfilename,
121 const char* outputfilename,
124 const bool create_boundary_faces,
125 const bool family_splitting)
128 MEDSPLITTER::ParaDomainSelector parallelizer;
130 // Loading the mesh collection
131 MEDSPLITTER::MESHCollection collection (inputfilename, parallelizer);
133 // Creating the graph and partitioning it
134 auto_ptr<MEDSPLITTER::Topology> new_topo;
136 new_topo.reset( collection.createPartition(nprocs,MEDSPLITTER::Graph::METIS));
138 new_topo.reset( collection.createPartition(nprocs,MEDSPLITTER::Graph::SCOTCH));
140 // Creating a new mesh collection from the partitioning
141 MEDSPLITTER::MESHCollection new_collection(collection, new_topo.get(),family_splitting);
142 new_collection.setSubdomainBoundaryCreates(create_boundary_faces);
144 //Writing the output files (master + MED files)
145 string output(outputfilename);
146 new_collection.write(output);