Nektar++
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) 2017 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 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 //
32 // Description: pts file format output.
33 //
34 ////////////////////////////////////////////////////////////////////////////////
35 
36 #include <set>
37 #include <string>
38 using namespace std;
39 
40 #include <boost/core/ignore_unused.hpp>
41 
45 
46 #include "OutputPts.h"
47 
48 namespace Nektar
49 {
50 namespace FieldUtils
51 {
52 
53 ModuleKey OutputPts::m_className[5] = {
55  ModuleKey(eOutputModule, "pts"), OutputPts::create, "Writes a pts file."),
57  ModuleKey(eOutputModule, "csv"), OutputPts::create, "Writes a csv file."),
58 };
59 
60 
61 OutputPts::OutputPts(FieldSharedPtr f) : OutputFileBase(f)
62 {
63 }
64 
66 {
67 }
68 
69 void OutputPts::OutputFromPts(po::variables_map &vm)
70 {
71  boost::ignore_unused(vm);
72 
73  // Extract the output filename and extension
74  string filename = m_config["outfile"].as<string>();
75 
76  if (boost::filesystem::path(filename).extension() == ".csv")
77  {
78  LibUtilities::CsvIO csvIO(m_f->m_comm);
79  csvIO.Write(filename, m_f->m_fieldPts);
80  }
81  else
82  {
83  LibUtilities::PtsIO ptsIO(m_f->m_comm);
84  ptsIO.Write(filename, m_f->m_fieldPts);
85  }
86 }
87 
88 void OutputPts::OutputFromExp(po::variables_map &vm)
89 {
91  m_f->m_exp[0]->GetCoordim(0) +
92  m_f->m_variables.size());
93 
94  switch (m_f->m_exp[0]->GetCoordim(0))
95  {
96  case 1:
97  tmp[0] = Array<OneD, NekDouble>(m_f->m_exp[0]->GetTotPoints());
98  m_f->m_exp[0]->GetCoords(tmp[0]);
99  break;
100 
101  case 2:
102  tmp[1] = Array<OneD, NekDouble>(m_f->m_exp[0]->GetTotPoints());
103  tmp[0] = Array<OneD, NekDouble>(m_f->m_exp[0]->GetTotPoints());
104  m_f->m_exp[0]->GetCoords(tmp[0], tmp[1]);
105  break;
106 
107  case 3:
108  tmp[2] = Array<OneD, NekDouble>(m_f->m_exp[0]->GetTotPoints());
109  tmp[1] = Array<OneD, NekDouble>(m_f->m_exp[0]->GetTotPoints());
110  tmp[0] = Array<OneD, NekDouble>(m_f->m_exp[0]->GetTotPoints());
111  m_f->m_exp[0]->GetCoords(tmp[0], tmp[1], tmp[2]);
112  break;
113  }
114 
115  for (int i = 0; i < m_f->m_variables.size(); ++i)
116  {
117  tmp[i + m_f->m_exp[0]->GetCoordim(0)] =
118  m_f->m_exp[i]->GetPhys();
119  }
120  m_f->m_fieldPts =
122  m_f->m_exp[0]->GetCoordim(0),
123  m_f->m_variables,
124  tmp);
125 
126  OutputFromPts(vm);
127 }
128 
129 void OutputPts::OutputFromData(po::variables_map &vm)
130 {
131  boost::ignore_unused(vm);
133  "OutputPts can't write using only FieldData.");
134 }
135 
136 fs::path OutputPts::GetPath(std::string &filename,
137  po::variables_map &vm)
138 {
139  boost::ignore_unused(vm);
140  return fs::path(filename);
141 }
142 
143 fs::path OutputPts::GetFullOutName(std::string &filename,
144  po::variables_map &vm)
145 {
146  boost::ignore_unused(vm);
147  return fs::path(filename);
148 }
149 
150 }
151 }
152 
virtual void OutputFromExp(po::variables_map &vm)
Write from m_exp to output file.
Definition: OutputPts.cpp:88
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mod...
Definition: ErrorUtil.hpp:209
std::map< std::string, ConfigOption > m_config
List of configuration values.
virtual fs::path GetFullOutName(std::string &filename, po::variables_map &vm)
Definition: OutputPts.cpp:143
Converter from fld to vtk.
STL namespace.
virtual void OutputFromData(po::variables_map &vm)
Write from data to output file.
Definition: OutputPts.cpp:129
void Write(const std::string &outFile, const PtsFieldSharedPtr &ptsField, const bool backup=false)
Save a pts field to a file.
Definition: CsvIO.cpp:71
std::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:762
virtual fs::path GetPath(std::string &filename, po::variables_map &vm)
Definition: OutputPts.cpp:136
virtual void OutputFromPts(po::variables_map &vm)
Write from pts to output file.
Definition: OutputPts.cpp:69
void Write(const std::string &outFile, const PtsFieldSharedPtr &ptsField, const bool backup=false)
Save a pts field to a file.
Definition: PtsIO.cpp:135
std::pair< ModuleType, std::string > ModuleKey
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:199
ModuleFactory & GetModuleFactory()
FieldSharedPtr m_f
Field object.