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 = GetModuleFactory().RegisterCreatorFunction(
53  ModuleKey(eOutputModule, "info"), OutputInfo::create,
54  "Writes an Info file.");
55 
56 OutputInfo::OutputInfo(FieldSharedPtr f) : OutputModule(f)
57 {
58  m_config["nparts"] =
59  ConfigOption(false, "NotSet",
60  "Number of partitions over which to create the info file");
61 }
62 
64 {
65 }
66 
67 void OutputInfo::v_Process(po::variables_map &vm)
68 {
69  boost::ignore_unused(vm);
70 
71  // Extract the output filename and extension
72  string filename = m_config["outfile"].as<string>();
73 
74  // partition mesh
75  ASSERTL0(m_config["nparts"].as<string>().compare("NotSet") != 0,
76  "Need to specify nparts for info output");
77  int nparts = m_config["nparts"].as<int>();
78 
79  // Input/output file
80  LibUtilities::CommSharedPtr c = m_f->m_comm;
81  std::shared_ptr<LibUtilities::FieldIOXml> fldXml =
82  std::static_pointer_cast<LibUtilities::FieldIOXml>(
83  LibUtilities::GetFieldIOFactory().CreateInstance("Xml", c, true));
84 
85  // open file and setup meta data.
86  fs::path pinfilename(filename);
87  std::vector<std::string> filenames;
88  std::vector<std::vector<unsigned int>> ElementIDs;
89 
90  for (int p = 0; p < nparts; ++p)
91  {
92  boost::format pad("P%1$07d.%2$s");
93  pad % p % "fld";
94  std::string s = pad.str();
95 
96  fs::path fullpath = pinfilename / s;
97  string fname = LibUtilities::PortablePath(fullpath);
98  if (!fs::exists(fname))
99  {
100  continue;
101  }
104 
105  std::vector<LibUtilities::FieldDefinitionsSharedPtr> fielddefs;
106  std::vector<unsigned int> PartElmtIDs;
107 
108  // read in header of partition if it exists
109  fldXml->ImportFieldDefs(dataSource, fielddefs, false);
110 
111  // create ElmenetIDs list then use
112  for (int i = 0; i < fielddefs.size(); ++i)
113  {
114  for (int j = 0; j < fielddefs[i]->m_elementIDs.size(); ++j)
115  {
116  PartElmtIDs.push_back(fielddefs[i]->m_elementIDs[j]);
117  }
118  }
119 
120  ElementIDs.push_back(PartElmtIDs);
121  filenames.push_back(s);
122  }
123 
124  // Write the Info.xml file
125  string infofile =
126  LibUtilities::PortablePath(pinfilename / fs::path("Info.xml"));
127 
128  fldXml->WriteMultiFldFileIDs(infofile, filenames, ElementIDs);
129 }
130 
131 } // namespace FieldUtils
132 } // namespace Nektar
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:215
FieldSharedPtr m_f
Field object.
Definition: Module.h:234
std::map< std::string, ConfigOption > m_config
List of configuration values.
Definition: Module.h:263
virtual void v_Process(po::variables_map &vm) override
Write fld to output file.
Definition: OutputInfo.cpp:67
Abstract base class for output modules.
Definition: Module.h:307
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:198
static DataSourceSharedPtr create(const std::string &fn)
Create a new XML data source based on the filename.
Definition: FieldIOXml.h:94
std::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:991
std::pair< ModuleType, std::string > ModuleKey
Definition: Module.h:317
ModuleFactory & GetModuleFactory()
Definition: Module.cpp:49
std::shared_ptr< DataSource > DataSourceSharedPtr
Definition: FieldIO.h:90
std::string PortablePath(const boost::filesystem::path &path)
create portable path on different platforms for boost::filesystem path
Definition: FileSystem.cpp:45
FieldIOFactory & GetFieldIOFactory()
Returns the FieldIO factory.
Definition: FieldIO.cpp:72
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition: Comm.h:54
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
Represents a command-line configuration option.
Definition: Module.h:131