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/core/ignore_unused.hpp>
39#include <boost/geometry.hpp>
40#include <boost/math/special_functions/fpclassify.hpp>
41
47
49
50using namespace std;
51
52namespace bg = boost::geometry;
53namespace bgi = boost::geometry::index;
54
55namespace Nektar
56{
57namespace FieldUtils
58{
59
62 ModuleKey(eProcessModule, "interppointdatatofld"),
64 "Interpolates given discrete data using a finite difference "
65 "approximation to a fld file given a xml file");
66
68 : ProcessModule(f)
69{
70 m_config["frompts"] = ConfigOption(
71 false, "NotSet", "Pts file from which to interpolate field");
72
73 m_config["interpcoord"] =
74 ConfigOption(false, "-1", "coordinate id to use for interpolation");
75}
76
78{
79}
80
81void ProcessInterpPointDataToFld::v_Process(po::variables_map &vm)
82{
83 m_f->SetUpExp(vm);
84
85 int i, j;
87 // Load pts file
88 ASSERTL0(m_config["frompts"].as<string>().compare("NotSet") != 0,
89 "ProcessInterpPointDataToFld requires frompts parameter");
90 string inFile = m_config["frompts"].as<string>().c_str();
91
92 int totpoints = m_f->m_exp[0]->GetTotPoints();
93
95 for (int i = 0; i < 3; ++i)
96 {
97 intFields[i] = Array<OneD, NekDouble>(totpoints, 0.);
98 }
99 m_f->m_exp[0]->GetCoords(intFields[0], intFields[1], intFields[2]);
100
101 if (boost::filesystem::path(inFile).extension() == ".pts")
102 {
105
106 ptsIO->Import(inFile, fieldPts);
107 }
108 else if (boost::filesystem::path(inFile).extension() == ".csv")
109 {
112
115
116 NekDouble vmax, vmin, margin = 0.1;
117 vmax = intFields[0][Vmath::Imax(totpoints, intFields[0], 1)];
118 vmin = intFields[0][Vmath::Imin(totpoints, intFields[0], 1)];
119 Range->m_xmax = (vmax - vmin) * margin + vmax;
120 Range->m_xmin = -(vmax - vmin) * margin + vmin;
121
122 vmax = intFields[1][Vmath::Imax(totpoints, intFields[1], 1)];
123 vmin = intFields[1][Vmath::Imin(totpoints, intFields[1], 1)];
124 Range->m_ymax = (vmax - vmin) * margin + vmax;
125 Range->m_ymin = -(vmax - vmin) * margin + vmin;
126
127 vmax = intFields[2][Vmath::Imax(totpoints, intFields[2], 1)];
128 vmin = intFields[2][Vmath::Imin(totpoints, intFields[2], 1)];
129 Range->m_zmax = (vmax - vmin) * margin + vmax;
130 Range->m_zmin = -(vmax - vmin) * margin + vmin;
131
132 csvIO->Import(inFile, fieldPts, LibUtilities::NullFieldMetaDataMap,
133 Range);
134 }
135 else
136 {
137 ASSERTL0(false, "unknown frompts file type");
138 }
139
140 int nFields = fieldPts->GetNFields();
141 ASSERTL0(nFields > 0, "No field values provided in input");
142
143 // Define new expansions.
144 ASSERTL0(
145 m_f->m_numHomogeneousDir == 0,
146 "ProcessInterpPointDataToFld does not support homogeneous expansion");
147
148 m_f->m_exp.resize(nFields);
149 for (i = 1; i < nFields; ++i)
150 {
151 m_f->m_exp[i] = m_f->AppendExpList(m_f->m_numHomogeneousDir);
152 }
153
154 Array<OneD, Array<OneD, NekDouble>> intFields1(3 + nFields);
155
156 for (int i = 0; i < 3; ++i)
157 {
158 intFields1[i] = intFields[i];
159 }
160
161 // Declare space for interpolated fields
162 for (int i = 3; i < 3 + nFields; ++i)
163 {
164 intFields1[i] = Array<OneD, NekDouble>(totpoints);
165 }
166
169
170 int coord_id = m_config["interpcoord"].as<int>();
171 ASSERTL0(coord_id <= static_cast<int>(outPts->GetDim()) - 1,
172 "interpcoord is bigger than the Pts files dimension");
173
175 LibUtilities::eNoMethod, coord_id);
176
177 if (m_f->m_verbose && m_f->m_comm->TreatAsRankZero())
178 {
179 interp.SetProgressCallback(
181 }
182 interp.Interpolate(fieldPts, outPts);
183 if (m_f->m_verbose && m_f->m_comm->TreatAsRankZero())
184 {
185 cout << endl;
186 }
187
188 for (i = 0; i < totpoints; ++i)
189 {
190 for (j = 0; j < nFields; ++j)
191 {
192 m_f->m_exp[j]->SetPhys(i, outPts->GetPointVal(3 + j, i));
193 }
194 }
195 // forward transform fields
196 for (i = 0; i < nFields; ++i)
197 {
198 m_f->m_exp[i]->FwdTransLocalElmt(m_f->m_exp[i]->GetPhys(),
199 m_f->m_exp[i]->UpdateCoeffs());
200 }
201
202 // save field names
203 for (int j = 0; j < fieldPts->GetNFields(); ++j)
204 {
205 m_f->m_variables.push_back(fieldPts->GetFieldName(j));
206 }
207}
208} // namespace FieldUtils
209} // namespace Nektar
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:215
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:234
std::map< std::string, ConfigOption > m_config
List of configuration values.
Definition: Module.h:263
virtual 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:292
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:198
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
static FieldMetaDataMap NullFieldMetaDataMap
Definition: FieldIO.h:53
std::shared_ptr< PtsField > PtsFieldSharedPtr
Definition: PtsField.h:190
std::shared_ptr< DomainRange > DomainRangeShPtr
Definition: DomainRange.h:66
std::shared_ptr< CsvIO > CsvIOSharedPtr
Definition: CsvIO.h:80
std::shared_ptr< PtsIO > PtsIOSharedPtr
Definition: PtsIO.h:96
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
double NekDouble
int Imax(int n, const T *x, const int incx)
Return the index of the maximum element in x.
Definition: Vmath.cpp:913
int Imin(int n, const T *x, const int incx)
Return the index of the minimum element in x.
Definition: Vmath.cpp:1018
Represents a command-line configuration option.
Definition: Module.h:131