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>
38using namespace std;
39
43
44#include "OutputPts.h"
45
46namespace Nektar::FieldUtils
47{
48
52 "Writes a pts file."),
55 "Writes a csv file."),
56};
57
59{
60}
61
63{
64}
65
66void OutputPts::v_OutputFromPts([[maybe_unused]] po::variables_map &vm)
67{
68 // Extract the output filename and extension
69 string filename = m_config["outfile"].as<string>();
70
71 if (fs::path(filename).extension() == ".csv")
72 {
73 LibUtilities::CsvIO csvIO(m_f->m_comm);
74 csvIO.Write(filename, m_f->m_fieldPts);
75 }
76 else
77 {
78 LibUtilities::PtsIO ptsIO(m_f->m_comm);
79 ptsIO.Write(filename, m_f->m_fieldPts);
80 }
81}
82
83void OutputPts::v_OutputFromExp(po::variables_map &vm)
84{
85 Array<OneD, Array<OneD, NekDouble>> tmp(m_f->m_exp[0]->GetCoordim(0) +
86 m_f->m_variables.size());
87
88 switch (m_f->m_exp[0]->GetCoordim(0))
89 {
90 case 1:
91 tmp[0] = Array<OneD, NekDouble>(m_f->m_exp[0]->GetTotPoints());
92 m_f->m_exp[0]->GetCoords(tmp[0]);
93 break;
94
95 case 2:
96 tmp[1] = Array<OneD, NekDouble>(m_f->m_exp[0]->GetTotPoints());
97 tmp[0] = Array<OneD, NekDouble>(m_f->m_exp[0]->GetTotPoints());
98 m_f->m_exp[0]->GetCoords(tmp[0], tmp[1]);
99 break;
100
101 case 3:
102 tmp[2] = Array<OneD, NekDouble>(m_f->m_exp[0]->GetTotPoints());
103 tmp[1] = Array<OneD, NekDouble>(m_f->m_exp[0]->GetTotPoints());
104 tmp[0] = Array<OneD, NekDouble>(m_f->m_exp[0]->GetTotPoints());
105 m_f->m_exp[0]->GetCoords(tmp[0], tmp[1], tmp[2]);
106 break;
107 }
108
109 for (int i = 0; i < m_f->m_variables.size(); ++i)
110 {
111 tmp[i + m_f->m_exp[0]->GetCoordim(0)] = m_f->m_exp[i]->GetPhys();
112 }
114 m_f->m_exp[0]->GetCoordim(0), m_f->m_variables, tmp);
115
116 v_OutputFromPts(vm);
117}
118
119void OutputPts::v_OutputFromData([[maybe_unused]] po::variables_map &vm)
120{
121 NEKERROR(ErrorUtil::efatal, "OutputPts can't write using only FieldData.");
122}
123
124fs::path OutputPts::v_GetPath(std::string &filename,
125 [[maybe_unused]] po::variables_map &vm)
126{
127 return fs::path(filename);
128}
129
130fs::path OutputPts::v_GetFullOutName(std::string &filename,
131 [[maybe_unused]] po::variables_map &vm)
132{
133 return fs::path(filename);
134}
135
136} // namespace Nektar::FieldUtils
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
Definition: ErrorUtil.hpp:202
FieldSharedPtr m_f
Field object.
Definition: Module.h:239
std::map< std::string, ConfigOption > m_config
List of configuration values.
Definition: Module.h:272
Converter from fld to vtk.
fs::path v_GetPath(std::string &filename, po::variables_map &vm) override
Definition: OutputPts.cpp:124
static std::shared_ptr< Module > create(FieldSharedPtr f)
Creates an instance of this class.
Definition: OutputPts.h:49
void v_OutputFromExp(po::variables_map &vm) override
Write from m_exp to output file.
Definition: OutputPts.cpp:83
OutputPts(FieldSharedPtr f)
Definition: OutputPts.cpp:58
void v_OutputFromPts(po::variables_map &vm) override
Write from pts to output file.
Definition: OutputPts.cpp:66
fs::path v_GetFullOutName(std::string &filename, po::variables_map &vm) override
Definition: OutputPts.cpp:130
void v_OutputFromData(po::variables_map &vm) override
Write from data to output file.
Definition: OutputPts.cpp:119
static ModuleKey m_className[]
Definition: OutputPts.h:53
void Write(const std::string &outFile, const PtsFieldSharedPtr &ptsField, const bool backup=false)
Save a pts field to a file.
Definition: CsvIO.cpp:68
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
void Write(const std::string &outFile, const PtsFieldSharedPtr &ptsField, const bool backup=false)
Save a pts field to a file.
Definition: PtsIO.cpp:130
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:1026
std::pair< ModuleType, std::string > ModuleKey
Definition: Module.h:180
ModuleFactory & GetModuleFactory()
Definition: Module.cpp:47
STL namespace.