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  OutputPts::create,
56  "Writes a pts file."),
58  OutputPts::create,
59  "Writes a csv file."),
60 };
61 
62 OutputPts::OutputPts(FieldSharedPtr f) : OutputFileBase(f)
63 {
64 }
65 
67 {
68 }
69 
70 void OutputPts::v_OutputFromPts(po::variables_map &vm)
71 {
72  boost::ignore_unused(vm);
73 
74  // Extract the output filename and extension
75  string filename = m_config["outfile"].as<string>();
76 
77  if (boost::filesystem::path(filename).extension() == ".csv")
78  {
79  LibUtilities::CsvIO csvIO(m_f->m_comm);
80  csvIO.Write(filename, m_f->m_fieldPts);
81  }
82  else
83  {
84  LibUtilities::PtsIO ptsIO(m_f->m_comm);
85  ptsIO.Write(filename, m_f->m_fieldPts);
86  }
87 }
88 
89 void OutputPts::v_OutputFromExp(po::variables_map &vm)
90 {
91  Array<OneD, Array<OneD, NekDouble>> tmp(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)] = m_f->m_exp[i]->GetPhys();
118  }
120  m_f->m_exp[0]->GetCoordim(0), m_f->m_variables, tmp);
121 
122  v_OutputFromPts(vm);
123 }
124 
125 void OutputPts::v_OutputFromData(po::variables_map &vm)
126 {
127  boost::ignore_unused(vm);
128  NEKERROR(ErrorUtil::efatal, "OutputPts can't write using only FieldData.");
129 }
130 
131 fs::path OutputPts::v_GetPath(std::string &filename, po::variables_map &vm)
132 {
133  boost::ignore_unused(vm);
134  return fs::path(filename);
135 }
136 
137 fs::path OutputPts::v_GetFullOutName(std::string &filename,
138  po::variables_map &vm)
139 {
140  boost::ignore_unused(vm);
141  return fs::path(filename);
142 }
143 
144 } // namespace FieldUtils
145 } // namespace Nektar
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
Definition: ErrorUtil.hpp:209
FieldSharedPtr m_f
Field object.
Definition: Module.h:234
std::map< std::string, ConfigOption > m_config
List of configuration values.
Definition: Module.h:263
Converter from fld to vtk.
virtual fs::path v_GetPath(std::string &filename, po::variables_map &vm) override
Definition: OutputPts.cpp:131
virtual void v_OutputFromExp(po::variables_map &vm) override
Write from m_exp to output file.
Definition: OutputPts.cpp:89
virtual void v_OutputFromPts(po::variables_map &vm) override
Write from pts to output file.
Definition: OutputPts.cpp:70
virtual fs::path v_GetFullOutName(std::string &filename, po::variables_map &vm) override
Definition: OutputPts.cpp:137
virtual void v_OutputFromData(po::variables_map &vm) override
Write from data to output file.
Definition: OutputPts.cpp:125
void Write(const std::string &outFile, const PtsFieldSharedPtr &ptsField, const bool backup=false)
Save a pts field to a file.
Definition: CsvIO.cpp:70
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:198
void Write(const std::string &outFile, const PtsFieldSharedPtr &ptsField, const bool backup=false)
Save a pts field to a file.
Definition: PtsIO.cpp:132
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
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
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2