39#include <boost/lexical_cast.hpp>
57 "Interpolates a set of points to another, requires fromfld and "
58 "fromxml to be defined, a line, plane or block of points can be "
65 ConfigOption(
false,
"NotSet",
"Pts file to which interpolate field");
67 "Specify a line of N points using "
68 "line=N,x0,y0,z0,z1,y1,z1");
71 "Specify a plane of N1 x N2 points using "
72 "plane=N1,N2,x0,y0,z0,z1,y1,z1,x2,y2,z2,x3,y3,z3");
75 "Specify a rectangular box of N1 x N2 x N3 points "
76 "using a box of points limited by box="
77 "N1,N2,N3,xmin,xmax,ymin,ymax,zmin,zmax");
80 ConfigOption(
false,
"-10000000",
"Lower bound for interpolation value");
82 ConfigOption(
false,
"10000000",
"Upper bound for interpolation value");
84 ConfigOption(
false,
"0",
"Default value if point is outside domain");
88 "Parameters p0 and q to determine pressure coefficients");
98 "Should have a PtsField for ProcessInterpPtsToPts.");
99 ASSERTL0(
m_f->m_comm->GetSpaceComm()->GetSize() == 1,
100 "ProcessInterpPtsToPts not implemented in parallel.");
109 int nfields =
m_f->m_variables.size();
110 for (
int j = 0; j < nfields; ++j)
113 m_f->m_fieldPts->AddField(newPts,
m_f->m_variables[j]);
123 if (!boost::iequals(
m_config[
"cp"].as<string>(),
"NotSet"))
130 [[maybe_unused]] po::variables_map &vm)
132 int rank =
m_f->m_comm->GetSpaceComm()->GetRank();
133 int nprocs =
m_f->m_comm->GetSpaceComm()->GetSize();
135 if (
m_config[
"topts"].as<string>().compare(
"NotSet") != 0)
137 string inFile =
m_config[
"topts"].as<
string>();
139 if (fs::path(inFile).extension() ==
".pts")
145 ptsIO->Import(inFile,
m_f->m_fieldPts);
147 else if (fs::path(inFile).extension() ==
".csv")
153 csvIO->Import(inFile,
m_f->m_fieldPts);
157 ASSERTL0(
false,
"unknown topts file type");
160 else if (
m_config[
"line"].as<string>().compare(
"NotSet") != 0)
162 vector<NekDouble> values;
165 "Failed to interpret line string");
167 ASSERTL0(values.size() > 2,
"line string should contain 2*Dim+1 values "
168 "N,x0,y0,z0,x1,y1,z1");
171 ASSERTL0(std::modf(values[0], &tmp) == 0.0,
"N is not an integer");
172 ASSERTL0(values[0] > 1,
"N is not a valid number");
174 int dim = (values.size() - 1) / 2;
175 int npts = values[0];
178 int ptsPerProc = npts / nprocs;
179 int extraPts = (rank < nprocs - 1) ? 0 : npts % nprocs;
180 int locPts = ptsPerProc + extraPts;
181 int start = rank * ptsPerProc;
182 int end = start + locPts;
186 for (
int i = 0; i < dim; ++i)
189 delta[i] = (values[dim + i + 1] - values[i + 1]) / (npts - 1);
192 for (
int i = 0, cntLoc = 0; i < npts; ++i)
194 if (i >= start && i < end)
196 for (
int n = 0; n < dim; ++n)
198 pts[n][cntLoc] = values[n + 1] + i * delta[n];
209 m_f->m_fieldPts->SetPointsPerEdge(ppe);
211 else if (
m_config[
"plane"].as<string>().compare(
"NotSet") != 0)
213 vector<NekDouble> values;
216 "Failed to interpret plane string");
219 "plane string should contain 4 Dim+2 values "
220 "N1,N2,x0,y0,z0,x1,y1,z1,x2,y2,z2,x3,y3,z3");
223 ASSERTL0(std::modf(values[0], &tmp) == 0.0,
"N1 is not an integer");
224 ASSERTL0(std::modf(values[1], &tmp) == 0.0,
"N2 is not an integer");
226 ASSERTL0(values[0] > 1,
"N1 is not a valid number");
227 ASSERTL0(values[1] > 1,
"N2 is not a valid number");
229 int dim = (values.size() - 2) / 4;
235 int totpts = npts[0] * npts[1];
238 int ptsPerProc = totpts / nprocs;
239 int extraPts = (rank < nprocs - 1) ? 0 : totpts % nprocs;
240 int locPts = ptsPerProc + extraPts;
241 int start = rank * ptsPerProc;
242 int end = start + locPts;
247 for (
int i = 0; i < dim; ++i)
250 delta1[i] = (values[2 + 1 * dim + i] - values[2 + 0 * dim + i]) /
252 delta2[i] = (values[2 + 2 * dim + i] - values[2 + 3 * dim + i]) /
256 for (
int j = 0, cnt = 0, cntLoc = 0; j < npts[1]; ++j)
258 for (
int i = 0; i < npts[0]; ++i, ++cnt)
260 if (cnt >= start && cnt < end)
262 for (
int n = 0; n < dim; ++n)
265 (values[2 + n] + i * delta1[n]) *
267 (values[2 + 3 * dim + n] + i * delta2[n]) *
276 ppe.push_back(npts[0]);
277 ppe.push_back(npts[1]);
281 m_f->m_fieldPts->SetPointsPerEdge(ppe);
283 else if (
m_config[
"box"].as<string>().compare(
"NotSet") != 0)
285 vector<NekDouble> values;
288 "Failed to interpret box string");
290 ASSERTL0(values.size() == 9,
"box string should contain 9 values "
291 "N1,N2,N3,xmin,xmax,ymin,ymax,zmin,zmax");
299 int totpts = npts[0] * npts[1] * npts[2];
305 int ptsPerProc = totpts / nprocs;
306 int extraPts = (rank < nprocs - 1) ? 0 : totpts % nprocs;
307 int locPts = ptsPerProc + extraPts;
308 int start = rank * ptsPerProc;
309 int end = start + locPts;
311 for (
int i = 0; i < dim; ++i)
314 delta[i] = (values[4 + 2 * i] - values[3 + 2 * i]) / (npts[i] - 1);
317 for (
int k = 0, cnt = 0, cntLoc = 0; k < npts[2]; ++k)
319 for (
int j = 0; j < npts[1]; ++j)
321 for (
int i = 0; i < npts[0]; ++i, ++cnt)
323 if (cnt >= start && cnt < end)
325 pts[0][cntLoc] = values[3] + i * delta[0];
326 pts[1][cntLoc] = values[5] + j * delta[1];
327 pts[2][cntLoc] = values[7] + k * delta[2];
335 ppe.push_back(npts[0]);
336 ppe.push_back(npts[1]);
337 ppe.push_back(npts[2]);
341 m_f->m_fieldPts->SetPointsPerEdge(ppe);
342 vector<NekDouble> boxdim;
343 boxdim.assign(&values[3], &values[3] + 6);
344 m_f->m_fieldPts->SetBoxSize(boxdim);
349 "ProcessInterpPtsToPts requires line, plane or box option.");
358 ASSERTL0(toPts->GetNFields() >= fromPts->GetNFields(),
359 "ptField has too few fields");
361 int nfields = fromPts->GetNFields();
364 if (
m_f->m_comm->GetRank() == 0)
370 if (
m_f->m_comm->GetRank() == 0)
375 for (
int f = 0; f < nfields; ++f)
377 for (
int i = 0; i < toPts->GetNpoints(); ++i)
379 if (toPts->GetPointVal(f, i) > clamp_up)
381 toPts->SetPointVal(f, i, clamp_up);
383 else if (toPts->GetPointVal(f, i) < clamp_low)
385 toPts->SetPointVal(f, i, clamp_low);
394 int dim = pts->GetDim();
395 int nq1 = pts->GetNpoints();
401 vector<NekDouble> values;
403 "Failed to interpret cp string");
405 ASSERTL0(values.size() == 2,
"cp string should contain 2 values "
406 "p0 and q (=1/2 rho u^2)");
409 qinv = 1.0 / values[1];
411 for (
int i = 0; i < pts->GetNFields(); ++i)
413 if (boost::iequals(pts->GetFieldName(i),
"p"))
418 if (boost::iequals(pts->GetFieldName(i),
"u") ||
419 boost::iequals(pts->GetFieldName(i),
"v") ||
420 boost::iequals(pts->GetFieldName(i),
"w"))
430 WARNINGL0(
false,
"Did not find velocity components for Cp0");
435 WARNINGL0(
false,
"Failed to find 'p' field to determine cp0");
441 for (f = 0; f < 2; ++f)
446 for (r = 0; r < nq1; r++)
450 data[0][r] = qinv * (pts->GetPointVal(dim + pfield, r) - p0);
455 for (
int i = 0; i < velid.size(); ++i)
457 q += 0.5 * pts->GetPointVal(dim + velid[i], r) *
458 pts->GetPointVal(dim + velid[i], r);
461 qinv * (pts->GetPointVal(dim + pfield, r) +
q - p0);
468 pts->AddField(data[0],
"Cp");
469 m_f->m_variables.push_back(
"Cp");
472 pts->AddField(data[1],
"Cp0");
473 m_f->m_variables.push_back(
"Cp0");
479 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., NekDouble tolerance=NekConstants::kFindDistanceMin)
Interpolate from an expansion to an expansion.
FieldSharedPtr m_f
Field object.
std::map< std::string, ConfigOption > m_config
List of configuration values.
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() override
ProcessInterpPtsToPts(FieldSharedPtr f)
void PrintProgressbar(const int position, const int goal) const
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)
Represents a command-line configuration option.