Nektar++
InputFld.cpp
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////////////
2//
3// File: InputFld.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: Reads a Nektar++ FLD file.
32//
33////////////////////////////////////////////////////////////////////////////////
34
35#include <iostream>
36#include <string>
37using namespace std;
38
39#include "InputFld.h"
40using namespace Nektar;
41
42namespace Nektar::FieldUtils
43{
44
47 ModuleKey(eInputModule, "fld"), InputFld::create, "Reads Fld file."),
50 "Reads checkpoint file."),
53 "Reads restart file."),
56 "Reads stability base-flow file.")};
57
58/**
59 * @brief Set up InputFld object.
60 *
61 */
63{
64 m_allowedFiles.insert("fld");
65 m_allowedFiles.insert("chk");
66 m_allowedFiles.insert("rst");
67 m_allowedFiles.insert("bse");
68}
69
70/**
71 *
72 */
74{
75}
76
77/**
78 *
79 */
80void InputFld::v_Process([[maybe_unused]] po::variables_map &vm)
81{
82 int i;
83 string fileName = m_config["infile"].as<string>();
84
85 LibUtilities::FieldIOSharedPtr fld = m_f->FieldIOForFile(fileName);
86
87 int oldSize = m_f->m_fielddef.size();
88 if (m_f->m_graph)
89 {
90 // Determine IDs of elements in the domain
91 vector<int> IDs;
92 auto domain = m_f->m_graph->GetDomain();
93 for (int d = 0; d < domain.size(); ++d)
94 {
95 for (auto &compIter : domain[d])
96 {
97 for (auto &x : compIter.second->m_geomVec)
98 {
99 IDs.push_back(x->GetGlobalID());
100 }
101 }
102 }
103
104 if (!IDs.size())
105 {
106 return;
107 }
108
109 // Move to an array to match FieldIO interface
110 Array<OneD, int> ElementGIDs(IDs.size(), IDs.data());
111
112 fld->Import(fileName, m_f->m_fielddef, m_f->m_data,
113 m_f->m_fieldMetaDataMap, ElementGIDs);
114 }
115 else // load all data.
116 {
117 fld->Import(fileName, m_f->m_fielddef, m_f->m_data,
118 m_f->m_fieldMetaDataMap);
119 }
120
121 // save field names
122 for (i = 0; i < m_f->m_fielddef[oldSize]->m_fields.size(); ++i)
123 {
124 // check for multiple fld files
125 auto it = find(m_f->m_variables.begin(), m_f->m_variables.end(),
126 m_f->m_fielddef[oldSize]->m_fields[i]);
127
128 if (it == m_f->m_variables.end())
129 {
130 m_f->m_variables.push_back(m_f->m_fielddef[oldSize]->m_fields[i]);
131 }
132 }
133}
134} // namespace Nektar::FieldUtils
InputFld(FieldSharedPtr f)
Set up InputFld object.
Definition: InputFld.cpp:62
static ModuleKey m_className[]
ModuleKey for class.
Definition: InputFld.h:58
static ModuleSharedPtr create(FieldSharedPtr f)
Creates an instance of this class.
Definition: InputFld.h:53
void v_Process(po::variables_map &vm) override
Definition: InputFld.cpp:80
Abstract base class for input modules.
Definition: Module.h:287
std::set< std::string > m_allowedFiles
List of allowed file formats.
Definition: Module.h:274
FieldSharedPtr m_f
Field object.
Definition: Module.h:239
std::map< std::string, ConfigOption > m_config
List of configuration values.
Definition: Module.h:272
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:197
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
InputIterator find(InputIterator first, InputIterator last, InputIterator startingpoint, const EqualityComparable &value)
Definition: StdRegions.hpp:447
std::vector< double > d(NPUPPER *NPUPPER)