Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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 FieldUtils
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_comm;
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_comm);
103  LibUtilities::PtsFieldSharedPtr fPts = m_f->m_fieldPts;
104  if(m_f->m_fieldPts == LibUtilities::NullPtsField)
105  {
107  m_f->m_exp[0]->GetCoordim(0) +
108  m_f->m_fielddef[0]->m_fields.size());
109 
110  switch (m_f->m_exp[0]->GetCoordim(0))
111  {
112  case 1:
113  tmp[0] = Array<OneD, NekDouble>(m_f->m_exp[0]->GetTotPoints());
114  m_f->m_exp[0]->GetCoords(tmp[0]);
115  break;
116 
117  case 2:
118  tmp[1] = Array<OneD, NekDouble>(m_f->m_exp[0]->GetTotPoints());
119  tmp[0] = Array<OneD, NekDouble>(m_f->m_exp[0]->GetTotPoints());
120  m_f->m_exp[0]->GetCoords(tmp[0], tmp[1]);
121  break;
122 
123  case 3:
124  tmp[2] = Array<OneD, NekDouble>(m_f->m_exp[0]->GetTotPoints());
125  tmp[1] = Array<OneD, NekDouble>(m_f->m_exp[0]->GetTotPoints());
126  tmp[0] = Array<OneD, NekDouble>(m_f->m_exp[0]->GetTotPoints());
127  m_f->m_exp[0]->GetCoords(tmp[0], tmp[1], tmp[2]);
128  break;
129  }
130 
131  for (int i = 0; i < m_f->m_fielddef[0]->m_fields.size(); ++i)
132  {
133  tmp[i + m_f->m_exp[0]->GetCoordim(0)] =
134  m_f->m_exp[i]->GetPhys();
135  }
136  fPts =
138  m_f->m_exp[0]->GetCoordim(0),
139  m_f->m_fielddef[0]->m_fields,
140  tmp);
141  }
142  ptsIO.Write(filename, fPts);
143  }
144 }
145 }
146 }
map< string, ConfigOption > m_config
List of configuration values.
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
STL namespace.
pair< ModuleType, string > ModuleKey
boost::shared_ptr< PtsField > PtsFieldSharedPtr
Definition: PtsField.h:178
boost::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition: Comm.h:55
boost::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:767
virtual void Process(po::variables_map &vm)
Write fld to output file.
Definition: OutputPts.cpp:60
static PtsFieldSharedPtr NullPtsField
Definition: PtsField.h:179
void Write(const string &outFile, const PtsFieldSharedPtr &ptsField, const bool backup=false)
Save a pts field to a file.
Definition: PtsIO.cpp:155
Abstract base class for output modules.
ModuleFactory & GetModuleFactory()
FieldSharedPtr m_f
Field object.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:215