Nektar++
ProcessInterpPointDataToFld.cpp
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////////////
2//
3// File: ProcessInterpPointDataToFld.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: Interpolate, using finite different approximation,
32// given data to a fld file
33//
34////////////////////////////////////////////////////////////////////////////////
35#include <iostream>
36#include <string>
37
38#include <boost/geometry.hpp>
39
45
47
48using namespace std;
49
50namespace bg = boost::geometry;
51namespace bgi = boost::geometry::index;
52
53namespace Nektar::FieldUtils
54{
55
58 ModuleKey(eProcessModule, "interppointdatatofld"),
60 "Interpolates given discrete data using a finite difference "
61 "approximation to a fld file given a xml file");
62
64 : ProcessModule(f)
65{
66 m_config["frompts"] = ConfigOption(
67 false, "NotSet", "Pts file from which to interpolate field");
68
69 m_config["interpcoord"] =
70 ConfigOption(false, "-1", "coordinate id to use for interpolation");
71}
72
74{
75}
76
77void ProcessInterpPointDataToFld::v_Process(po::variables_map &vm)
78{
79 m_f->SetUpExp(vm);
80
81 int i, j;
83 // Load pts file
84 ASSERTL0(m_config["frompts"].as<string>().compare("NotSet") != 0,
85 "ProcessInterpPointDataToFld requires frompts parameter");
86 string inFile = m_config["frompts"].as<string>().c_str();
87
88 int totpoints = m_f->m_exp[0]->GetTotPoints();
89
91 for (int i = 0; i < 3; ++i)
92 {
93 intFields[i] = Array<OneD, NekDouble>(totpoints, 0.);
94 }
95 m_f->m_exp[0]->GetCoords(intFields[0], intFields[1], intFields[2]);
96
97 if (fs::path(inFile).extension() == ".pts")
98 {
101
102 ptsIO->Import(inFile, fieldPts);
103 }
104 else if (fs::path(inFile).extension() == ".csv")
105 {
108
111
112 NekDouble vmax, vmin, margin = 0.1;
113 vmax = intFields[0][Vmath::Imax(totpoints, intFields[0], 1)];
114 vmin = intFields[0][Vmath::Imin(totpoints, intFields[0], 1)];
115 Range->m_xmax = (vmax - vmin) * margin + vmax;
116 Range->m_xmin = -(vmax - vmin) * margin + vmin;
117
118 vmax = intFields[1][Vmath::Imax(totpoints, intFields[1], 1)];
119 vmin = intFields[1][Vmath::Imin(totpoints, intFields[1], 1)];
120 Range->m_ymax = (vmax - vmin) * margin + vmax;
121 Range->m_ymin = -(vmax - vmin) * margin + vmin;
122
123 vmax = intFields[2][Vmath::Imax(totpoints, intFields[2], 1)];
124 vmin = intFields[2][Vmath::Imin(totpoints, intFields[2], 1)];
125 Range->m_zmax = (vmax - vmin) * margin + vmax;
126 Range->m_zmin = -(vmax - vmin) * margin + vmin;
127
128 csvIO->Import(inFile, fieldPts, LibUtilities::NullFieldMetaDataMap,
129 Range);
130 }
131 else
132 {
133 ASSERTL0(false, "unknown frompts file type");
134 }
135
136 int nFields = fieldPts->GetNFields();
137 ASSERTL0(nFields > 0, "No field values provided in input");
138
139 // Define new expansions.
140 ASSERTL0(
141 m_f->m_numHomogeneousDir == 0,
142 "ProcessInterpPointDataToFld does not support homogeneous expansion");
143
144 m_f->m_exp.resize(nFields);
145 for (i = 1; i < nFields; ++i)
146 {
147 m_f->m_exp[i] = m_f->AppendExpList(m_f->m_numHomogeneousDir);
148 }
149
150 Array<OneD, Array<OneD, NekDouble>> intFields1(3 + nFields);
151
152 for (int i = 0; i < 3; ++i)
153 {
154 intFields1[i] = intFields[i];
155 }
156
157 // Declare space for interpolated fields
158 for (int i = 3; i < 3 + nFields; ++i)
159 {
160 intFields1[i] = Array<OneD, NekDouble>(totpoints);
161 }
162
165
166 int coord_id = m_config["interpcoord"].as<int>();
167 ASSERTL0(coord_id <= static_cast<int>(outPts->GetDim()) - 1,
168 "interpcoord is bigger than the Pts files dimension");
169
171 LibUtilities::eNoMethod, coord_id);
172
173 if (m_f->m_verbose && m_f->m_comm->TreatAsRankZero())
174 {
175 interp.SetProgressCallback(
177 }
178 interp.Interpolate(fieldPts, outPts);
179 if (m_f->m_verbose && m_f->m_comm->TreatAsRankZero())
180 {
181 cout << endl;
182 }
183
184 for (i = 0; i < totpoints; ++i)
185 {
186 for (j = 0; j < nFields; ++j)
187 {
188 m_f->m_exp[j]->SetPhys(i, outPts->GetPointVal(3 + j, i));
189 }
190 }
191 // forward transform fields
192 for (i = 0; i < nFields; ++i)
193 {
194 m_f->m_exp[i]->FwdTransLocalElmt(m_f->m_exp[i]->GetPhys(),
195 m_f->m_exp[i]->UpdateCoeffs());
196 }
197
198 // save field names
199 for (int j = 0; j < fieldPts->GetNFields(); ++j)
200 {
201 m_f->m_variables.push_back(fieldPts->GetFieldName(j));
202 }
203}
204} // namespace Nektar::FieldUtils
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
A class that contains algorithms for interpolation between pts fields, expansions and different meshe...
FIELD_UTILS_EXPORT void Interpolate(const T expInField, T &expOutField, NekDouble def_value=0.0)
Interpolate from an expansion to an expansion.
FieldSharedPtr m_f
Field object.
Definition: Module.h:239
std::map< std::string, ConfigOption > m_config
List of configuration values.
Definition: Module.h:272
void v_Process(po::variables_map &vm) override
Write mesh to output file.
void PrintProgressbar(const int position, const int goal) const
static std::shared_ptr< Module > create(FieldSharedPtr f)
Creates an instance of this class.
Abstract base class for processing modules.
Definition: Module.h:301
void SetProgressCallback(FuncPointerT func, ObjectPointerT obj)
sets a callback funtion which gets called every time the interpolation progresses
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:197
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:990
std::pair< ModuleType, std::string > ModuleKey
Definition: Module.h:180
ModuleFactory & GetModuleFactory()
Definition: Module.cpp:47
static FieldMetaDataMap NullFieldMetaDataMap
Definition: FieldIO.h:51
std::shared_ptr< PtsField > PtsFieldSharedPtr
Definition: PtsField.h:184
std::shared_ptr< DomainRange > DomainRangeShPtr
Definition: DomainRange.h:64
std::shared_ptr< CsvIO > CsvIOSharedPtr
Definition: CsvIO.h:74
std::shared_ptr< PtsIO > PtsIOSharedPtr
Definition: PtsIO.h:90
double NekDouble
int Imax(int n, const T *x, const int incx)
Return the index of the maximum element in x.
Definition: Vmath.hpp:623
int Imin(int n, const T *x, const int incx)
Return the index of the minimum element in x.
Definition: Vmath.hpp:704
Represents a command-line configuration option.
Definition: Module.h:129