39#include <boost/core/ignore_unused.hpp>
40#include <boost/lexical_cast.hpp>
41#include <boost/math/special_functions/fpclassify.hpp>
61 "Interpolates a set of points to another, requires fromfld and "
62 "fromxml to be defined, a line, plane or block of points can be "
69 ConfigOption(
false,
"NotSet",
"Pts file to which interpolate field");
71 "Specify a line of N points using "
72 "line=N,x0,y0,z0,z1,y1,z1");
75 "Specify a plane of N1 x N2 points using "
76 "plane=N1,N2,x0,y0,z0,z1,y1,z1,x2,y2,z2,x3,y3,z3");
79 "Specify a rectangular box of N1 x N2 x N3 points "
80 "using a box of points limited by box="
81 "N1,N2,N3,xmin,xmax,ymin,ymax,zmin,zmax");
84 ConfigOption(
false,
"-10000000",
"Lower bound for interpolation value");
86 ConfigOption(
false,
"10000000",
"Upper bound for interpolation value");
88 ConfigOption(
false,
"0",
"Default value if point is outside domain");
92 "Parameters p0 and q to determine pressure coefficients");
102 "Should have a PtsField for ProcessInterpPtsToPts.");
103 ASSERTL0(
m_f->m_comm->GetSpaceComm()->GetSize() == 1,
104 "ProcessInterpPtsToPts not implemented in parallel.");
113 int nfields =
m_f->m_variables.size();
114 for (
int j = 0; j < nfields; ++j)
117 m_f->m_fieldPts->AddField(newPts,
m_f->m_variables[j]);
127 if (!boost::iequals(
m_config[
"cp"].as<string>(),
"NotSet"))
135 boost::ignore_unused(vm);
137 int rank =
m_f->m_comm->GetSpaceComm()->GetRank();
138 int nprocs =
m_f->m_comm->GetSpaceComm()->GetSize();
140 if (
m_config[
"topts"].as<string>().compare(
"NotSet") != 0)
142 string inFile =
m_config[
"topts"].as<
string>();
144 if (boost::filesystem::path(inFile).extension() ==
".pts")
150 ptsIO->Import(inFile,
m_f->m_fieldPts);
152 else if (boost::filesystem::path(inFile).extension() ==
".csv")
158 csvIO->Import(inFile,
m_f->m_fieldPts);
162 ASSERTL0(
false,
"unknown topts file type");
165 else if (
m_config[
"line"].as<string>().compare(
"NotSet") != 0)
167 vector<NekDouble> values;
170 "Failed to interpret line string");
172 ASSERTL0(values.size() > 2,
"line string should contain 2*Dim+1 values "
173 "N,x0,y0,z0,x1,y1,z1");
176 ASSERTL0(std::modf(values[0], &tmp) == 0.0,
"N is not an integer");
177 ASSERTL0(values[0] > 1,
"N is not a valid number");
179 int dim = (values.size() - 1) / 2;
180 int npts = values[0];
183 int ptsPerProc = npts / nprocs;
184 int extraPts = (rank < nprocs - 1) ? 0 : npts % nprocs;
185 int locPts = ptsPerProc + extraPts;
186 int start = rank * ptsPerProc;
187 int end = start + locPts;
191 for (
int i = 0; i < dim; ++i)
194 delta[i] = (values[dim + i + 1] - values[i + 1]) / (npts - 1);
197 for (
int i = 0, cntLoc = 0; i < npts; ++i)
199 if (i >= start && i < end)
201 for (
int n = 0; n < dim; ++n)
203 pts[n][cntLoc] = values[n + 1] + i * delta[n];
214 m_f->m_fieldPts->SetPointsPerEdge(ppe);
216 else if (
m_config[
"plane"].as<string>().compare(
"NotSet") != 0)
218 vector<NekDouble> values;
221 "Failed to interpret plane string");
224 "plane string should contain 4 Dim+2 values "
225 "N1,N2,x0,y0,z0,x1,y1,z1,x2,y2,z2,x3,y3,z3");
228 ASSERTL0(std::modf(values[0], &tmp) == 0.0,
"N1 is not an integer");
229 ASSERTL0(std::modf(values[1], &tmp) == 0.0,
"N2 is not an integer");
231 ASSERTL0(values[0] > 1,
"N1 is not a valid number");
232 ASSERTL0(values[1] > 1,
"N2 is not a valid number");
234 int dim = (values.size() - 2) / 4;
240 int totpts = npts[0] * npts[1];
243 int ptsPerProc = totpts / nprocs;
244 int extraPts = (rank < nprocs - 1) ? 0 : totpts % nprocs;
245 int locPts = ptsPerProc + extraPts;
246 int start = rank * ptsPerProc;
247 int end = start + locPts;
252 for (
int i = 0; i < dim; ++i)
255 delta1[i] = (values[2 + 1 * dim + i] - values[2 + 0 * dim + i]) /
257 delta2[i] = (values[2 + 2 * dim + i] - values[2 + 3 * dim + i]) /
261 for (
int j = 0, cnt = 0, cntLoc = 0; j < npts[1]; ++j)
263 for (
int i = 0; i < npts[0]; ++i, ++cnt)
265 if (cnt >= start && cnt < end)
267 for (
int n = 0; n < dim; ++n)
270 (values[2 + n] + i * delta1[n]) *
272 (values[2 + 3 * dim + n] + i * delta2[n]) *
281 ppe.push_back(npts[0]);
282 ppe.push_back(npts[1]);
286 m_f->m_fieldPts->SetPointsPerEdge(ppe);
288 else if (
m_config[
"box"].as<string>().compare(
"NotSet") != 0)
290 vector<NekDouble> values;
293 "Failed to interpret box string");
295 ASSERTL0(values.size() == 9,
"box string should contain 9 values "
296 "N1,N2,N3,xmin,xmax,ymin,ymax,zmin,zmax");
304 int totpts = npts[0] * npts[1] * npts[2];
310 int ptsPerProc = totpts / nprocs;
311 int extraPts = (rank < nprocs - 1) ? 0 : totpts % nprocs;
312 int locPts = ptsPerProc + extraPts;
313 int start = rank * ptsPerProc;
314 int end = start + locPts;
316 for (
int i = 0; i < dim; ++i)
319 delta[i] = (values[4 + 2 * i] - values[3 + 2 * i]) / (npts[i] - 1);
322 for (
int k = 0, cnt = 0, cntLoc = 0; k < npts[2]; ++k)
324 for (
int j = 0; j < npts[1]; ++j)
326 for (
int i = 0; i < npts[0]; ++i, ++cnt)
328 if (cnt >= start && cnt < end)
330 pts[0][cntLoc] = values[3] + i * delta[0];
331 pts[1][cntLoc] = values[5] + j * delta[1];
332 pts[2][cntLoc] = values[7] + k * delta[2];
340 ppe.push_back(npts[0]);
341 ppe.push_back(npts[1]);
342 ppe.push_back(npts[2]);
346 m_f->m_fieldPts->SetPointsPerEdge(ppe);
347 vector<NekDouble> boxdim;
348 boxdim.assign(&values[3], &values[3] + 6);
349 m_f->m_fieldPts->SetBoxSize(boxdim);
354 "ProcessInterpPtsToPts requires line, plane or box option.");
363 boost::ignore_unused(def_value);
365 ASSERTL0(toPts->GetNFields() >= fromPts->GetNFields(),
366 "ptField has too few fields");
368 int nfields = fromPts->GetNFields();
371 if (
m_f->m_comm->GetRank() == 0)
377 if (
m_f->m_comm->GetRank() == 0)
382 for (
int f = 0; f < nfields; ++f)
384 for (
int i = 0; i < toPts->GetNpoints(); ++i)
386 if (toPts->GetPointVal(f, i) > clamp_up)
388 toPts->SetPointVal(f, i, clamp_up);
390 else if (toPts->GetPointVal(f, i) < clamp_low)
392 toPts->SetPointVal(f, i, clamp_low);
401 int dim = pts->GetDim();
402 int nq1 = pts->GetNpoints();
408 vector<NekDouble> values;
410 "Failed to interpret cp string");
412 ASSERTL0(values.size() == 2,
"cp string should contain 2 values "
413 "p0 and q (=1/2 rho u^2)");
416 qinv = 1.0 / values[1];
418 for (
int i = 0; i < pts->GetNFields(); ++i)
420 if (boost::iequals(pts->GetFieldName(i),
"p"))
425 if (boost::iequals(pts->GetFieldName(i),
"u") ||
426 boost::iequals(pts->GetFieldName(i),
"v") ||
427 boost::iequals(pts->GetFieldName(i),
"w"))
437 WARNINGL0(
false,
"Did not find velocity components for Cp0");
442 WARNINGL0(
false,
"Failed to find 'p' field to determine cp0");
448 for (f = 0; f < 2; ++f)
453 for (r = 0; r < nq1; r++)
457 data[0][r] = qinv * (pts->GetPointVal(dim + pfield, r) - p0);
462 for (
int i = 0; i < velid.size(); ++i)
464 q += 0.5 * pts->GetPointVal(dim + velid[i], r) *
465 pts->GetPointVal(dim + velid[i], r);
468 qinv * (pts->GetPointVal(dim + pfield, r) +
q - p0);
475 pts->AddField(data[0],
"Cp");
476 m_f->m_variables.push_back(
"Cp");
479 pts->AddField(data[1],
"Cp0");
480 m_f->m_variables.push_back(
"Cp0");
486 const int goal)
const
#define ASSERTL0(condition, msg)
#define WARNINGL0(condition, msg)
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.
std::map< std::string, ConfigOption > m_config
List of configuration values.
virtual ~ProcessInterpPtsToPts()
static ModuleKey className
void CreateFieldPts(po::variables_map &vm)
void InterpolatePtsToPts(LibUtilities::PtsFieldSharedPtr &fromPts, LibUtilities::PtsFieldSharedPtr &toPts, NekDouble clamp_low, NekDouble clamp_up, NekDouble def_value)
static std::shared_ptr< Module > create(FieldSharedPtr f)
Creates an instance of this class.
ProcessInterpPtsToPts(FieldSharedPtr f)
void PrintProgressbar(const int position, const int goal) const
virtual void v_Process(po::variables_map &vm) override
Write mesh to output file.
Abstract base class for processing modules.
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.
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
static bool GenerateVector(const std::string &str, std::vector< T > &out)
Takes a comma-separated string and converts it to entries in a vector.
std::shared_ptr< Field > FieldSharedPtr
std::pair< ModuleType, std::string > ModuleKey
ModuleFactory & GetModuleFactory()
int PrintProgressbar(const int position, const int goal, const std::string message, int lastprogress=-1)
Prints a progressbar.
std::shared_ptr< PtsField > PtsFieldSharedPtr
std::shared_ptr< CsvIO > CsvIOSharedPtr
static PtsFieldSharedPtr NullPtsField
std::shared_ptr< PtsIO > PtsIOSharedPtr
std::vector< double > q(NPUPPER *NPUPPER)
The above copyright notice and this permission notice shall be included.
Represents a command-line configuration option.