Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
OutputInfo.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: OutputInfo.cpp
4 //
5 // For more information, please see: http://www.nektar.info/
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10 // Department of Aeronautics, Imperial College London (UK), and Scientific
11 // Computing and Imaging Institute, University of Utah (USA).
12 //
13 // License for the specific language governing rights and limitations under
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 //
32 // Description: Generates a Nektar++ info XML file.
33 //
34 ////////////////////////////////////////////////////////////////////////////////
35 
36 #include <set>
37 #include <string>
38 using namespace std;
39 
40 #include "OutputInfo.h"
41 
44 #include <boost/format.hpp>
45 
46 namespace Nektar
47 {
48 namespace FieldUtils
49 {
50 
51 ModuleKey OutputInfo::m_className =
53  OutputInfo::create,
54  "Writes an Info file.");
55 
56 OutputInfo::OutputInfo(FieldSharedPtr f) : OutputModule(f)
57 {
58 }
59 
61 {
62 }
63 
64 void OutputInfo::Process(po::variables_map &vm)
65 {
66  // Extract the output filename and extension
67  string filename = m_config["outfile"].as<string>();
68  int i;
69 
70  if (m_f->m_verbose)
71  {
72  cout << "OutputInfo: Writing Info file..." << endl;
73  }
74 
75  // partition mesh
76  ASSERTL0(vm.count("nprocs") > 0,
77  "--nprocs nust be specified with info output");
78 
79  int nprocs = vm["nprocs"].as<int>();
80 
81  LibUtilities::CommSharedPtr vComm = boost::shared_ptr<FieldConvertComm>(
82  new FieldConvertComm(0, NULL, nprocs, 0));
83  vComm->SplitComm(1, nprocs);
84 
85  // define new session with psuedo parallel communicator
86  string xml_ending = "xml";
87  string xml_gz_ending = "xml.gz";
88 
89  std::vector<std::string> files;
90  // load .xml ending
91  for (int i = 0; i < m_f->m_inputfiles[xml_ending].size(); ++i)
92  {
93  files.push_back(m_f->m_inputfiles[xml_ending][i]);
94  }
95 
96  // load any .xml.gz endings
97  for (int j = 0; j < m_f->m_inputfiles[xml_gz_ending].size(); ++j)
98  {
99  files.push_back(m_f->m_inputfiles[xml_gz_ending][j]);
100  }
101 
103  boost::shared_ptr<LibUtilities::SessionReader>(
104  new LibUtilities::SessionReader(0, 0, files, vComm));
105  vSession->SetUpXmlDoc();
106 
107  // Default partitioner to use is Metis. Use Scotch as default
108  // if it is installed. Override default with command-line flags
109  // if they are set.
110  string vPartitionerName = "Metis";
111  if (LibUtilities::GetMeshPartitionFactory().ModuleExists("Scotch"))
112  {
113  vPartitionerName = "Scotch";
114  }
115  if (vSession->DefinesCmdLineArgument("use-metis"))
116  {
117  vPartitionerName = "Metis";
118  }
119  if (vSession->DefinesCmdLineArgument("use-scotch"))
120  {
121  vPartitionerName = "Scotch";
122  }
123 
124  LibUtilities::MeshPartitionSharedPtr vMeshPartition =
126  vSession);
127 
128  vMeshPartition->PartitionMesh(nprocs, true);
129 
130  // get hold of local partition ids
131  std::vector<std::vector<unsigned int> > ElementIDs(nprocs);
132 
133  // Populate the list of element ID lists from all processes
134  for (i = 0; i < nprocs; ++i)
135  {
136  std::vector<unsigned int> tmp;
137  vMeshPartition->GetElementIDs(i, tmp);
138  ElementIDs[i] = tmp;
139  }
140 
141  // Set up output names
142  std::vector<std::string> filenames;
143  for (int i = 0; i < nprocs; ++i)
144  {
145  boost::format pad("P%1$07d.fld");
146  pad % i;
147  filenames.push_back(pad.str());
148  }
149 
150  // Write the output file
151  LibUtilities::CommSharedPtr c = m_f->m_session ? m_f->m_session->GetComm() :
153  boost::shared_ptr<LibUtilities::FieldIOXml> fldXml =
154  boost::static_pointer_cast<LibUtilities::FieldIOXml>(
156  fldXml->WriteMultiFldFileIDs(filename, filenames, ElementIDs);
157 }
158 }
159 }
map< string, ConfigOption > m_config
List of configuration values.
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:198
tBaseSharedPtr CreateInstance(tKey idKey BOOST_PP_COMMA_IF(MAX_PARAM) BOOST_PP_ENUM_BINARY_PARAMS(MAX_PARAM, tParam, x))
Create an instance of the class referred to by idKey.
Definition: NekFactory.hpp:162
boost::shared_ptr< MeshPartition > MeshPartitionSharedPtr
STL namespace.
pair< ModuleType, string > ModuleKey
FieldIOFactory & GetFieldIOFactory()
Returns the FieldIO factory.
Definition: FieldIO.cpp:74
boost::shared_ptr< SessionReader > SessionReaderSharedPtr
Definition: MeshPartition.h:51
CommFactory & GetCommFactory()
Definition: Comm.cpp:61
virtual void Process(po::variables_map &vm)
Write fld to output file.
Definition: OutputInfo.cpp:64
boost::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition: Comm.h:55
boost::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:767
void WriteMultiFldFileIDs(const std::string &outfile, const std::vector< std::string > fileNames, std::vector< std::vector< unsigned int > > &elementList, const FieldMetaDataMap &fieldinfomap=NullFieldMetaDataMap)
Write out a file containing element ID to partition mapping.
Definition: FieldIOXml.cpp:380
Reads and parses information from a Nektar++ XML session file.
MeshPartitionFactory & GetMeshPartitionFactory()
Abstract base class for output modules.
ModuleFactory & GetModuleFactory()
FieldSharedPtr m_f
Field object.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:215