Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OutputPts.cpp
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // File: OutputPts.cpp
4 //
5 // For more information, please see: http://www.nektar.info/
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2016 Kilian Lackhove
10 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
11 // Department of Aeronautics, Imperial College London (UK), and Scientific
12 // Computing and Imaging Institute, University of Utah (USA).
13 //
14 // License for the specific language governing rights and limitations under
15 // Permission is hereby granted, free of charge, to any person obtaining a
16 // copy of this software and associated documentation files (the "Software"),
17 // to deal in the Software without restriction, including without limitation
18 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
19 // and/or sell copies of the Software, and to permit persons to whom the
20 // Software is furnished to do so, subject to the following conditions:
21 //
22 // The above copyright notice and this permission notice shall be included
23 // in all copies or substantial portions of the Software.
24 //
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
26 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
28 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
30 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
31 // DEALINGS IN THE SOFTWARE.
32 //
33 // Description: pts file format output.
34 //
35 ////////////////////////////////////////////////////////////////////////////////
36 
37 #include <set>
38 #include <string>
39 using namespace std;
40 
41 #include "OutputPts.h"
43 
44 namespace Nektar
45 {
46 namespace Utilities
47 {
48 
49 ModuleKey OutputPts::m_className = GetModuleFactory().RegisterCreatorFunction(
50  ModuleKey(eOutputModule, "pts"), OutputPts::create, "Writes a pts file.");
51 
52 OutputPts::OutputPts(FieldSharedPtr f) : OutputModule(f)
53 {
54 }
55 
57 {
58 }
59 
60 void OutputPts::Process(po::variables_map &vm)
61 {
62  // Extract the output filename and extension
63  string filename = m_config["outfile"].as<string>();
64 
65  if (m_f->m_verbose)
66  {
67  if(m_f->m_comm->TreatAsRankZero())
68  {
69  cout << "OutputPts: Writing file..." << endl;
70  }
71  }
72 
73  fs::path writefile(filename);
74  int writepts = 1;
75  if (fs::exists(writefile) && (vm.count("forceoutput") == 0))
76  {
77  LibUtilities::CommSharedPtr comm = m_f->m_session->GetComm();
78  int rank = comm->GetRank();
79  writepts = 0; // set to zero for reduce all to be correct.
80 
81  if (rank == 0)
82  {
83  string answer;
84  cout << "Did you wish to overwrite " << filename << " (y/n)? ";
85  getline(cin, answer);
86  if (answer.compare("y") == 0)
87  {
88  writepts = 1;
89  }
90  else
91  {
92  cout << "Not writing file " << filename
93  << " because it already exists" << endl;
94  }
95  }
96 
97  comm->AllReduce(writepts, LibUtilities::ReduceSum);
98  }
99 
100  if (writepts)
101  {
102  LibUtilities::PtsIO ptsIO(m_f->m_session->GetComm());
104  m_f->m_graph->GetMeshDimension() +
105  m_f->m_fielddef[0]->m_fields.size());
106 
107  switch (m_f->m_graph->GetMeshDimension())
108  {
109  case 1:
110  tmp[0] = Array<OneD, NekDouble>(m_f->m_exp[0]->GetTotPoints());
111  m_f->m_exp[0]->GetCoords(tmp[0]);
112  break;
113 
114  case 2:
115  tmp[1] = Array<OneD, NekDouble>(m_f->m_exp[0]->GetTotPoints());
116  tmp[0] = Array<OneD, NekDouble>(m_f->m_exp[0]->GetTotPoints());
117  m_f->m_exp[0]->GetCoords(tmp[0], tmp[1]);
118  break;
119 
120  case 3:
121  tmp[2] = Array<OneD, NekDouble>(m_f->m_exp[0]->GetTotPoints());
122  tmp[1] = Array<OneD, NekDouble>(m_f->m_exp[0]->GetTotPoints());
123  tmp[0] = Array<OneD, NekDouble>(m_f->m_exp[0]->GetTotPoints());
124  m_f->m_exp[0]->GetCoords(tmp[0], tmp[1], tmp[2]);
125  break;
126  }
127 
128  for (int i = 0; i < m_f->m_fielddef[0]->m_fields.size(); ++i)
129  {
130  tmp[i + m_f->m_graph->GetMeshDimension()] =
131  m_f->m_exp[i]->GetPhys();
132  }
135  m_f->m_graph->GetMeshDimension(),
136  m_f->m_fielddef[0]->m_fields,
137  tmp);
138  ptsIO.Write(filename, tmpPts);
139  }
140 }
141 }
142 }
pair< ModuleType, string > ModuleKey
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
Abstract base class for output modules.
virtual void Process()=0
map< string, ConfigOption > m_config
List of configuration values.
STL namespace.
FieldSharedPtr m_f
Field object.
boost::shared_ptr< PtsField > PtsFieldSharedPtr
Definition: PtsField.h:262
boost::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition: Comm.h:53
boost::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:698
ModuleFactory & GetModuleFactory()
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:215