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  cout << "OutputPts: Writing file..." << endl;
68  }
69 
70  fs::path writefile(filename);
71  int writepts = 1;
72  if (fs::exists(writefile) && (vm.count("forceoutput") == 0))
73  {
74  LibUtilities::CommSharedPtr comm = m_f->m_session->GetComm();
75  int rank = comm->GetRank();
76  writepts = 0; // set to zero for reduce all to be correct.
77 
78  if (rank == 0)
79  {
80  string answer;
81  cout << "Did you wish to overwrite " << filename << " (y/n)? ";
82  getline(cin, answer);
83  if (answer.compare("y") == 0)
84  {
85  writepts = 1;
86  }
87  else
88  {
89  cout << "Not writing file " << filename
90  << " because it already exists" << endl;
91  }
92  }
93 
94  comm->AllReduce(writepts, LibUtilities::ReduceSum);
95  }
96 
97  if (writepts)
98  {
99  LibUtilities::PtsIO ptsIO(m_f->m_session->GetComm());
101  m_f->m_graph->GetMeshDimension() +
102  m_f->m_fielddef[0]->m_fields.size());
103 
104  switch (m_f->m_graph->GetMeshDimension())
105  {
106  case 1:
107  tmp[0] = Array<OneD, NekDouble>(m_f->m_exp[0]->GetTotPoints());
108  m_f->m_exp[0]->GetCoords(tmp[0]);
109  break;
110 
111  case 2:
112  tmp[1] = Array<OneD, NekDouble>(m_f->m_exp[0]->GetTotPoints());
113  tmp[0] = Array<OneD, NekDouble>(m_f->m_exp[0]->GetTotPoints());
114  m_f->m_exp[0]->GetCoords(tmp[0], tmp[1]);
115  break;
116 
117  case 3:
118  tmp[2] = Array<OneD, NekDouble>(m_f->m_exp[0]->GetTotPoints());
119  tmp[1] = Array<OneD, NekDouble>(m_f->m_exp[0]->GetTotPoints());
120  tmp[0] = Array<OneD, NekDouble>(m_f->m_exp[0]->GetTotPoints());
121  m_f->m_exp[0]->GetCoords(tmp[0], tmp[1], tmp[2]);
122  break;
123  }
124 
125  for (int i = 0; i < m_f->m_fielddef[0]->m_fields.size(); ++i)
126  {
127  tmp[i + m_f->m_graph->GetMeshDimension()] =
128  m_f->m_exp[i]->GetPhys();
129  }
132  m_f->m_graph->GetMeshDimension(),
133  m_f->m_fielddef[0]->m_fields,
134  tmp);
135  ptsIO.Write(filename, tmpPts);
136  }
137 }
138 }
139 }
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:695
ModuleFactory & GetModuleFactory()
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:215