Nektar++
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 // Permission is hereby granted, free of charge, to any person obtaining a
14 // copy of this software and associated documentation files (the "Software"),
15 // to deal in the Software without restriction, including without limitation
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 // and/or sell copies of the Software, and to permit persons to whom the
18 // Software is furnished to do so, subject to the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be included
21 // in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 // DEALINGS IN THE SOFTWARE.
30 //
31 // Description: Generates a Nektar++ info XML file.
32 //
33 ////////////////////////////////////////////////////////////////////////////////
34 
35 #include <set>
36 #include <string>
37 using namespace std;
38 
39 #include <boost/core/ignore_unused.hpp>
40 #include <boost/format.hpp>
41 
44 
45 #include "OutputInfo.h"
46 
47 namespace Nektar
48 {
49 namespace FieldUtils
50 {
51 
52 ModuleKey OutputInfo::m_className =
54  OutputInfo::create,
55  "Writes an Info file.");
56 
57 OutputInfo::OutputInfo(FieldSharedPtr f) : OutputModule(f)
58 {
59  m_config["nparts"] = ConfigOption(
60  false, "NotSet",
61  "Number of partitions over which to create the info file");
62 }
63 
65 {
66 }
67 
68 void OutputInfo::Process(po::variables_map &vm)
69 {
70  boost::ignore_unused(vm);
71 
72  // Extract the output filename and extension
73  string filename = m_config["outfile"].as<string>();
74 
75  // partition mesh
76  ASSERTL0(m_config["nparts"].as<string>().compare("NotSet") != 0,
77  "Need to specify nparts for info output");
78  int nparts = m_config["nparts"].as<int>();
79 
80  // Input/output file
81  LibUtilities::CommSharedPtr c = m_f->m_comm;
82  std::shared_ptr<LibUtilities::FieldIOXml> fldXml =
83  std::static_pointer_cast<LibUtilities::FieldIOXml>(
85 
86  // open file and setup meta data.
87  fs::path pinfilename(filename);
88  std::vector<std::string> filenames;
89  std::vector<std::vector<unsigned int> > ElementIDs;
90 
91  for (int p = 0; p < nparts; ++p)
92  {
93  boost::format pad("P%1$07d.%2$s");
94  pad % p % "fld";
95  std::string s = pad.str();
96 
97  fs::path fullpath = pinfilename / s;
98  string fname = LibUtilities::PortablePath(fullpath);
99  if(!fs::exists(fname))
100  {
101  continue;
102  }
105 
106  std::vector<LibUtilities::FieldDefinitionsSharedPtr> fielddefs;
107  std::vector<unsigned int> PartElmtIDs;
108 
109  // read in header of partition if it exists
110  fldXml->ImportFieldDefs(dataSource,fielddefs,false);
111 
112  // create ElmenetIDs list then use
113  for(int i = 0; i < fielddefs.size(); ++i)
114  {
115  for(int j = 0; j < fielddefs[i]->m_elementIDs.size(); ++j)
116  {
117  PartElmtIDs.push_back(fielddefs[i]->m_elementIDs[j]);
118  }
119  }
120 
121  ElementIDs.push_back(PartElmtIDs);
122  filenames.push_back(s);
123  }
124 
125  // Write the Info.xml file
126  string infofile =
127  LibUtilities::PortablePath(pinfilename / fs::path("Info.xml"));
128 
129  fldXml->WriteMultiFldFileIDs(infofile,filenames, ElementIDs);
130 }
131 
132 }
133 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
std::map< std::string, ConfigOption > m_config
List of configuration values.
Represents a command-line configuration option.
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition: Comm.h:53
STL namespace.
std::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:762
FieldIOFactory & GetFieldIOFactory()
Returns the FieldIO factory.
Definition: FieldIO.cpp:72
virtual void Process(po::variables_map &vm)
Write fld to output file.
Definition: OutputInfo.cpp:68
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
Definition: NekFactory.hpp:144
std::pair< ModuleType, std::string > ModuleKey
std::shared_ptr< DataSource > DataSourceSharedPtr
Definition: FieldIO.h:79
static DataSourceSharedPtr create(const std::string &fn)
Create a new XML data source based on the filename.
Definition: FieldIOXml.h:92
std::string PortablePath(const boost::filesystem::path &path)
create portable path on different platforms for boost::filesystem path
Definition: FileSystem.cpp:41
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:199
Abstract base class for output modules.
ModuleFactory & GetModuleFactory()
FieldSharedPtr m_f
Field object.