Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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"
42 #include <boost/format.hpp>
43 
44 namespace Nektar
45 {
46 namespace Utilities
47 {
48 
49 ModuleKey OutputInfo::m_className = GetModuleFactory().RegisterCreatorFunction(
50  ModuleKey(eOutputModule, "info"), OutputInfo::create,
51  "Writes an Info file.");
52 
53 OutputInfo::OutputInfo(FieldSharedPtr f) : OutputModule(f)
54 {
55 }
56 
58 {
59 }
60 
61 void OutputInfo::Process(po::variables_map &vm)
62 {
63  // Extract the output filename and extension
64  string filename = m_config["outfile"].as<string>();
65  int i;
66 
67  if (m_f->m_verbose)
68  {
69  cout << "OutputInfo: Writing Info file..." << endl;
70  }
71 
72  // partition mesh
73  ASSERTL0(vm.count("nprocs") > 0,
74  "--nprocs nust be specified with info output");
75 
76  int nprocs = vm["nprocs"].as<int>();
77 
78  LibUtilities::CommSharedPtr vComm = boost::shared_ptr<FieldConvertComm>(
79  new FieldConvertComm(0, NULL, nprocs,0));
80  vComm->SplitComm(1,nprocs);
81 
82  // define new session with psuedo parallel communicator
83  string xml_ending = "xml";
84  string xml_gz_ending = "xml.gz";
85 
86  std::vector<std::string> files;
87  // load .xml ending
88  for (int i = 0; i < m_f->m_inputfiles[xml_ending].size(); ++i)
89  {
90  files.push_back(m_f->m_inputfiles[xml_ending][i]);
91  }
92 
93  // load any .xml.gz endings
94  for (int j =0; j < m_f->m_inputfiles[xml_gz_ending].size(); ++j)
95  {
96  files.push_back(m_f->m_inputfiles[xml_gz_ending][j]);
97  }
98 
100  boost::shared_ptr<LibUtilities::SessionReader>(
101  new LibUtilities::SessionReader(0,0,files,vComm));
102  vSession->SetUpXmlDoc();
103 
104  // Default partitioner to use is Metis. Use Scotch as default
105  // if it is installed. Override default with command-line flags
106  // if they are set.
107  string vPartitionerName = "Metis";
108  if (LibUtilities::GetMeshPartitionFactory().ModuleExists("Scotch"))
109  {
110  vPartitionerName = "Scotch";
111  }
112  if (vSession->DefinesCmdLineArgument("use-metis"))
113  {
114  vPartitionerName = "Metis";
115  }
116  if (vSession->DefinesCmdLineArgument("use-scotch"))
117  {
118  vPartitionerName = "Scotch";
119  }
120 
121  LibUtilities::MeshPartitionSharedPtr vMeshPartition =
123  vPartitionerName, vSession);
124 
125  vMeshPartition->PartitionMesh(nprocs, true);
126 
127  // get hold of local partition ids
128  std::vector<std::vector<unsigned int> > ElementIDs(nprocs);
129 
130  // Populate the list of element ID lists from all processes
131  for (i = 0; i < nprocs; ++i)
132  {
133  std::vector<unsigned int> tmp;
134  vMeshPartition->GetElementIDs(i,tmp);
135  ElementIDs[i] = tmp;
136  }
137 
138  // Set up output names
139  std::vector<std::string> filenames;
140  for(int i = 0; i < nprocs; ++i)
141  {
142  boost::format pad("P%1$07d.fld");
143  pad % i;
144  filenames.push_back(pad.str());
145  }
146 
147  // Write the output file
148  m_f->m_fld->WriteMultiFldFileIDs(filename,filenames, ElementIDs);
149 }
150 
151 }
152 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:188
pair< ModuleType, string > ModuleKey
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
Abstract base class for output modules.
virtual void Process()=0
boost::shared_ptr< MeshPartition > MeshPartitionSharedPtr
map< string, ConfigOption > m_config
List of configuration values.
STL namespace.
boost::shared_ptr< SessionReader > SessionReaderSharedPtr
Definition: MeshPartition.h:51
FieldSharedPtr m_f
Field object.
boost::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition: Comm.h:53
boost::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:698
Reads and parses information from a Nektar++ XML session file.
MeshPartitionFactory & GetMeshPartitionFactory()
ModuleFactory & GetModuleFactory()
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:215