39 #include <boost/core/ignore_unused.hpp>
40 #include <boost/lexical_cast.hpp>
41 #include <boost/math/special_functions/fpclassify.hpp>
57 ModuleKey ProcessInterpPtsToPts::className =
60 ProcessInterpPtsToPts::create,
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 "
68 false,
"NotSet",
"Pts file to which interpolate field");
70 false,
"NotSet",
"Specify a line of N points using "
71 "line=N,x0,y0,z0,z1,y1,z1");
73 false,
"NotSet",
"Specify a plane of N1 x N2 points using "
74 "plane=N1,N2,x0,y0,z0,z1,y1,z1,x2,y2,z2,x3,y3,z3");
76 false,
"NotSet",
"Specify a rectangular box of N1 x N2 x N3 points "
77 "using a box of points limited by box="
78 "N1,N2,N3,xmin,xmax,ymin,ymax,zmin,zmax");
81 ConfigOption(
false,
"-10000000",
"Lower bound for interpolation value");
83 ConfigOption(
false,
"10000000",
"Upper bound for interpolation value");
85 ConfigOption(
false,
"0",
"Default value if point is outside domain");
89 "Parameters p0 and q to determine pressure coefficients");
99 "Should have a PtsField for ProcessInterpPtsToPts.");
101 "ProcessInterpPtsToPts not implemented in parallel.");
110 int nfields =
m_f->m_variables.size();
111 for (
int j = 0; j < nfields; ++j)
114 m_f->m_fieldPts->AddField(newPts,
m_f->m_variables[j]);
122 clamp_up, def_value);
124 if (!boost::iequals(
m_config[
"cp"].as<string>(),
"NotSet"))
132 boost::ignore_unused(vm);
134 int rank =
m_f->m_comm->GetRank();
135 int nprocs =
m_f->m_comm->GetSize();
137 if (
m_config[
"topts"].as<string>().compare(
"NotSet") != 0)
139 string inFile =
m_config[
"topts"].as<
string>();
141 if (boost::filesystem::path(inFile).extension() ==
".pts")
146 ptsIO->Import(inFile,
m_f->m_fieldPts);
148 else if (boost::filesystem::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;
164 m_config[
"line"].as<string>(), values),
165 "Failed to interpret line string");
168 "line string should contain 2*Dim+1 values "
169 "N,x0,y0,z0,x1,y1,z1");
172 ASSERTL0(std::modf(values[0], &tmp) == 0.0,
"N is not an integer");
173 ASSERTL0(values[0] > 1,
"N is not a valid number");
175 int dim = (values.size() - 1) / 2;
176 int npts = values[0];
179 int ptsPerProc = npts / nprocs;
180 int extraPts = (rank < nprocs - 1) ? 0: npts % nprocs;
181 int locPts = ptsPerProc + extraPts;
182 int start = rank * ptsPerProc;
183 int end = start + locPts;
187 for (
int i = 0; i < dim; ++i)
190 delta[i] = (values[dim + i + 1] - values[ i + 1]) / (npts - 1);
195 for (
int i = 0, cntLoc = 0; i < npts; ++i)
197 if (i >= start && i < end)
199 for (
int n = 0; n < dim; ++n)
201 pts[n][cntLoc] = values[n+1] + i * delta[n];
213 m_f->m_fieldPts->SetPointsPerEdge(ppe);
215 else if (
m_config[
"plane"].as<string>().compare(
"NotSet") != 0)
217 vector<NekDouble> values;
219 m_config[
"plane"].as<string>(), values),
220 "Failed to interpret plane string");
223 "plane string should contain 4 Dim+2 values "
224 "N1,N2,x0,y0,z0,x1,y1,z1,x2,y2,z2,x3,y3,z3");
227 ASSERTL0(std::modf(values[0], &tmp) == 0.0,
"N1 is not an integer");
228 ASSERTL0(std::modf(values[1], &tmp) == 0.0,
"N2 is not an integer");
230 ASSERTL0(values[0] > 1,
"N1 is not a valid number");
231 ASSERTL0(values[1] > 1,
"N2 is not a valid number");
233 int dim = (values.size() - 2) / 4;
239 int totpts = npts[0] * npts[1];
242 int ptsPerProc = totpts / nprocs;
243 int extraPts = (rank < nprocs - 1) ? 0: totpts % nprocs;
244 int locPts = ptsPerProc + extraPts;
245 int start = rank * ptsPerProc;
246 int end = start + locPts;
251 for (
int i = 0; i < dim; ++i)
254 delta1[i] = (values[2+1*dim + i] - values[2+0*dim + i])/(npts[0]-1);
255 delta2[i] = (values[2+2*dim + i] - values[2+3*dim + i])/(npts[0]-1);
258 for (
int j = 0, cnt = 0, cntLoc = 0; j < npts[1]; ++j)
260 for (
int i = 0; i < npts[0]; ++i, ++cnt)
262 if (cnt >= start && cnt < end)
264 for (
int n = 0; n < dim; ++n)
267 (values[2+n] + i * delta1[n]) *
269 (values[2 + 3*dim + n] + i * delta2[n]) *
278 ppe.push_back(npts[0]);
279 ppe.push_back(npts[1]);
284 m_f->m_fieldPts->SetPointsPerEdge(ppe);
286 else if (
m_config[
"box"].as<string>().compare(
"NotSet") != 0)
288 vector<NekDouble> values;
290 m_config[
"box"].as<string>(), values),
291 "Failed to interpret box string");
294 "box string should contain 9 values "
295 "N1,N2,N3,xmin,xmax,ymin,ymax,zmin,zmax");
303 int totpts = npts[0]*npts[1]*npts[2];
309 int ptsPerProc = totpts / nprocs;
310 int extraPts = (rank < nprocs - 1) ? 0: totpts % nprocs;
311 int locPts = ptsPerProc + extraPts;
312 int start = rank * ptsPerProc;
313 int end = start + locPts;
315 for (
int i = 0; i < dim; ++i)
318 delta[i] = (values[4 + 2*i] - values[3 + 2*i]) / (npts[i] - 1);
323 for (
int k = 0, cnt = 0, cntLoc = 0; k < npts[2]; ++k)
325 for (
int j = 0; j < npts[1]; ++j)
327 for (
int i = 0; i < npts[0]; ++i, ++cnt)
329 if (cnt >= start && cnt < end)
331 pts[0][cntLoc] = values[3] + i * delta[0];
332 pts[1][cntLoc] = values[5] + j * delta[1];
333 pts[2][cntLoc] = values[7] + k * delta[2];
341 ppe.push_back(npts[0]);
342 ppe.push_back(npts[1]);
343 ppe.push_back(npts[2]);
348 m_f->m_fieldPts->SetPointsPerEdge(ppe);
349 vector<NekDouble> boxdim;
350 boxdim.assign(&values[3], &values[3] + 6);
351 m_f->m_fieldPts->SetBoxSize(boxdim);
356 "ProcessInterpPtsToPts requires line, plane or box option.");
367 boost::ignore_unused(def_value);
369 ASSERTL0(toPts->GetNFields() >= fromPts->GetNFields(),
370 "ptField has too few fields");
372 int nfields = fromPts->GetNFields();
375 if (
m_f->m_comm->GetRank() == 0)
381 if (
m_f->m_comm->GetRank() == 0)
386 for (
int f = 0; f < nfields; ++f)
388 for (
int i = 0; i < toPts->GetNpoints(); ++i)
390 if (toPts->GetPointVal(f, i) > clamp_up)
392 toPts->SetPointVal(f, i, clamp_up);
394 else if (toPts->GetPointVal(f, i) < clamp_low)
396 toPts->SetPointVal(f, i, clamp_low);
405 int dim = pts->GetDim();
406 int nq1 = pts->GetNpoints();
412 vector<NekDouble> values;
414 m_config[
"cp"].as<string>(),values),
415 "Failed to interpret cp string");
418 "cp string should contain 2 values "
419 "p0 and q (=1/2 rho u^2)");
422 qinv = 1.0/values[1];
424 for(
int i = 0; i < pts->GetNFields(); ++i)
426 if(boost::iequals(pts->GetFieldName(i),
"p"))
431 if(boost::iequals(pts->GetFieldName(i),
"u")||
432 boost::iequals(pts->GetFieldName(i),
"v")||
433 boost::iequals(pts->GetFieldName(i),
"w"))
443 WARNINGL0(
false,
"Did not find velocity components for Cp0");
448 WARNINGL0(
false,
"Failed to find 'p' field to determine cp0");
454 for (f = 0; f < 2; ++f)
459 for (r = 0; r < nq1; r++)
463 data[0][r] = qinv*(pts->GetPointVal(dim + pfield, r) - p0);
468 for(
int i = 0; i < velid.size(); ++i)
470 q += 0.5*pts->GetPointVal(dim + velid[i], r)*
471 pts->GetPointVal(dim + velid[i], r);
473 data[1][r] = qinv*(pts->GetPointVal(dim + pfield, r)+q - p0);
480 pts->AddField(data[0],
"Cp");
481 m_f->m_variables.push_back(
"Cp");
484 pts->AddField(data[1],
"Cp0");
485 m_f->m_variables.push_back(
"Cp0");
491 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 std::vector< MultiRegions::ExpListSharedPtr > expInField, std::vector< MultiRegions::ExpListSharedPtr > &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()
void CreateFieldPts(po::variables_map &vm)
void InterpolatePtsToPts(LibUtilities::PtsFieldSharedPtr &fromPts, LibUtilities::PtsFieldSharedPtr &toPts, NekDouble clamp_low, NekDouble clamp_up, NekDouble def_value)
void PrintProgressbar(const int position, const int goal) const
virtual void Process(po::variables_map &vm)
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
The above copyright notice and this permission notice shall be included.
Represents a command-line configuration option.