Nektar++
OutputFld.cpp
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////////////
2//
3// File: OutputFld.cpp
4//
5// For more information, please see: http://www.nektar.info/
6//
7// The MIT License
8//
9// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10// Department of Aeronautics, Imperial College London (UK), and Scientific
11// Computing and Imaging Institute, University of Utah (USA).
12//
13// Permission is hereby granted, free of charge, to any person obtaining a
14// copy of this software and associated documentation files (the "Software"),
15// to deal in the Software without restriction, including without limitation
16// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17// and/or sell copies of the Software, and to permit persons to whom the
18// Software is furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included
21// in all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29// DEALINGS IN THE SOFTWARE.
30//
31// Description: FLD file format output.
32//
33////////////////////////////////////////////////////////////////////////////////
34
35#include <set>
36#include <string>
37using namespace std;
38
39#include <boost/format.hpp>
40
42
43#include "OutputFld.h"
44
45namespace Nektar::FieldUtils
46{
47
51 "Writes a Fld file."),
54 "Writes a Fld file."),
55};
56
58{
59 m_config["format"] =
60 ConfigOption(false, "Xml", "Output format of field file");
61}
62
64{
65}
66
67void OutputFld::v_OutputFromPts([[maybe_unused]] po::variables_map &vm)
68{
69 NEKERROR(ErrorUtil::efatal, "OutputFld can't write using Pts information.");
70}
71
72void OutputFld::v_OutputFromExp([[maybe_unused]] po::variables_map &vm)
73{
74 ASSERTL0(m_f->m_variables.size(), "OutputFld: need input data.")
75
76 // Extract the output filename and extension
77 string filename = m_config["outfile"].as<string>();
78
79 // Set up FieldIO object.
82 m_f->m_comm, true);
83
84 int i, j, s;
85 int nfields = m_f->m_variables.size();
86 int nstrips;
87 m_f->m_session->LoadParameter("Strip_Z", nstrips, 1);
88
89 if (m_f->m_exp[0]->GetNumElmts() != 0)
90 {
91 std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef =
92 m_f->m_exp[0]->GetFieldDefinitions();
93 std::vector<std::vector<NekDouble>> FieldData(FieldDef.size());
94 for (s = 0; s < nstrips; ++s)
95 {
96 for (j = 0; j < nfields; ++j)
97 {
98 for (i = 0; i < FieldDef.size() / nstrips; ++i)
99 {
100 int n = s * FieldDef.size() / nstrips + i;
101
102 FieldDef[n]->m_fields.push_back(m_f->m_variables[j]);
103 m_f->m_exp[s * nfields + j]->AppendFieldData(
104 FieldDef[n], FieldData[n],
105 m_f->m_exp[s * nfields + j]->UpdateCoeffs());
106 }
107 }
108 }
109 fld->Write(filename, FieldDef, FieldData, m_f->m_fieldMetaDataMap,
110 false);
111 }
112 else
113 {
114 std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef =
115 std::vector<LibUtilities::FieldDefinitionsSharedPtr>();
116 std::vector<std::vector<NekDouble>> FieldData =
117 std::vector<std::vector<NekDouble>>();
118 fld->Write(filename, FieldDef, FieldData, m_f->m_fieldMetaDataMap);
119 }
120}
121
122void OutputFld::v_OutputFromData([[maybe_unused]] po::variables_map &vm)
123{
124 // Extract the output filename and extension
125 string filename = m_config["outfile"].as<string>();
126 // Set up FieldIO object.
129 m_f->m_comm, true);
130
131 fld->Write(filename, m_f->m_fielddef, m_f->m_data, m_f->m_fieldMetaDataMap);
132}
133
134fs::path OutputFld::v_GetPath(std::string &filename,
135 [[maybe_unused]] po::variables_map &vm)
136{
137 return fs::path(filename);
138}
139
140fs::path OutputFld::v_GetFullOutName(std::string &filename,
141 [[maybe_unused]] po::variables_map &vm)
142{
143 int nprocs = m_f->m_comm->GetSpaceComm()->GetSize();
144 fs::path specPath(filename), fulloutname;
145 if (nprocs == 1)
146 {
147 fulloutname = specPath;
148 }
149 else
150 {
151 // Guess at filename that might belong to this process.
152 boost::format pad("P%1$07d.%2$s");
153 pad % m_f->m_comm->GetSpaceComm()->GetRank() % "fld";
154
155 // Generate full path name
156 fs::path poutfile(pad.str());
157 fulloutname = specPath / poutfile;
158 }
159 return fulloutname;
160}
161
163{
164 std::string iofmt("Xml");
165 if (m_f->m_session)
166 {
167 if (m_f->m_session->DefinesSolverInfo("IOFormat"))
168 {
169 iofmt = m_f->m_session->GetSolverInfo("IOFormat");
170 }
171 if (m_f->m_session->DefinesCmdLineArgument("io-format"))
172 {
173 iofmt =
174 m_f->m_session->GetCmdLineArgument<std::string>("io-format");
175 }
176 }
177 if (m_config["format"].m_beenSet)
178 {
179 iofmt = m_config["format"].as<string>();
180 }
181 return iofmt;
182}
183
184} // namespace Nektar::FieldUtils
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
#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.
static ModuleKey m_className[]
Definition: OutputFld.h:53
OutputFld(FieldSharedPtr f)
Definition: OutputFld.cpp:57
void v_OutputFromData(po::variables_map &vm) override
Write from data to output file.
Definition: OutputFld.cpp:122
void v_OutputFromExp(po::variables_map &vm) override
Write from m_exp to output file.
Definition: OutputFld.cpp:72
static std::shared_ptr< Module > create(FieldSharedPtr f)
Creates an instance of this class.
Definition: OutputFld.h:49
fs::path v_GetPath(std::string &filename, po::variables_map &vm) override
Definition: OutputFld.cpp:134
void v_OutputFromPts(po::variables_map &vm) override
Write from pts to output file.
Definition: OutputFld.cpp:67
fs::path v_GetFullOutName(std::string &filename, po::variables_map &vm) override
Definition: OutputFld.cpp:140
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:197
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
Definition: NekFactory.hpp:143
std::shared_ptr< Field > FieldSharedPtr
Definition: Field.hpp:990
std::pair< ModuleType, std::string > ModuleKey
Definition: Module.h:180
ModuleFactory & GetModuleFactory()
Definition: Module.cpp:47
std::shared_ptr< FieldIO > FieldIOSharedPtr
Definition: FieldIO.h:322
FieldIOFactory & GetFieldIOFactory()
Returns the FieldIO factory.
Definition: FieldIO.cpp:70
Represents a command-line configuration option.
Definition: Module.h:129