43 #include <boost/math/special_functions/fpclassify.hpp>
48 ModuleKey ProcessInterpPoints::className =
51 ProcessInterpPoints::create,
52 "Interpolates a set of points to another, requires fromfld and "
53 "fromxml to be defined, a line or plane of points can be "
62 "Xml file from which to interpolate field");
65 "Need to specify fromxml=file.xml");
69 "Fld file from which to interpolate field");
72 "Need to specify fromfld=file.fld ");
76 "Lower bound for interpolation value");
79 "Upper bound for interpolation value");
82 "Default value if point is outside domain");
85 "Specify a line of N points using "
86 "line=N,x0,y0,z0,z1,y1,z1");
90 "Specify a plane of N1 x N1 points using "
91 "plane=N1,N2,x0,y0,z0,z1,y1,z1,x2,y2,z2,x3,"
104 cout <<
"Processing point interpolation" << endl;
112 if(
m_config[
"line"].as<string>().compare(
"NotSet") != 0)
114 string help =
m_config[
"line"].as<
string>();
115 vector<NekDouble> values;
117 m_config[
"line"].as<string>().c_str(),values),
118 "Failed to interpret line string");
121 "line string should contain 2Dim+1 values "
122 "N,x0,y0,z0,x1,y1,z1");
126 dim =
m_f->m_fieldPts->m_ptsDim = (values.size()-1)/2;
128 int npts = values[0];
129 m_f->m_fieldPts->m_npts.push_back(values[0]);
132 m_f->m_fieldPts->m_pts = Array<OneD, Array<OneD, NekDouble> > (
m_f->m_fieldPts->m_ptsDim);
134 for(
int i = 0; i < dim; ++i)
136 m_f->m_fieldPts->m_pts[i] = Array<OneD,NekDouble>(
npts);
139 for(
int i = 0; i <
npts; ++i)
141 m_f->m_fieldPts->m_pts[0][i] = values[1]
142 + i/((
NekDouble)(npts-1))*(values[dim+1] - values[1]);
145 m_f->m_fieldPts->m_pts[1][i] = values[2]
146 + i/((
NekDouble)(npts-1))*(values[dim+2] - values[2]);
150 m_f->m_fieldPts->m_pts[2][i] = values[3]
151 + i/((
NekDouble)(npts-1))*(values[dim+3] - values[3]);
156 else if(
m_config[
"plane"].as<string>().compare(
"NotSet") != 0)
158 string help =
m_config[
"plane"].as<
string>();
159 vector<NekDouble> values;
161 m_config[
"plane"].as<string>().c_str(),values),
162 "Failed to interpret plane string");
165 "line string should contain 2Dim+1 values "
166 "N,x0,y0,z0,x1,y1,z1");
170 dim =
m_f->m_fieldPts->m_ptsDim = (values.size()-1)/4;
172 int npts1 = values[0];
173 int npts2 = values[1];
174 m_f->m_fieldPts->m_npts.push_back(npts1);
175 m_f->m_fieldPts->m_npts.push_back(npts2);
178 m_f->m_fieldPts->m_pts = Array<OneD, Array<OneD, NekDouble> > (
m_f->m_fieldPts->m_ptsDim);
180 for(
int i = 0; i < dim; ++i)
182 m_f->m_fieldPts->m_pts[i] = Array<OneD,NekDouble>(npts1*npts2);
185 for(
int j = 0; j < npts2; ++j)
187 for(
int i = 0; i < npts1; ++i)
189 m_f->m_fieldPts->m_pts[0][i+j*npts1] =
190 (values[2] + i/((
NekDouble)(npts1-1))*(values[dim+2] - values[2]))*(1.0-j/((
NekDouble)(npts2-1))) +
191 (values[3*dim+2] + i/((
NekDouble)(npts1-1))*(values[2*dim+2] - values[3*dim+2]))*(j/((
NekDouble)(npts2-1)));
194 m_f->m_fieldPts->m_pts[1][i+j*npts1] =
195 (values[3] + i/((
NekDouble)(npts1-1))*(values[dim+3] - values[3]))*(1.0-j/((
NekDouble)(npts2-1))) +
196 (values[3*dim+3] + i/((
NekDouble)(npts1-1))*(values[2*dim+3] - values[3*dim+3]))*(j/((
NekDouble)(npts2-1)));
200 m_f->m_fieldPts->m_pts[2][i+j*npts1] =
201 (values[4] + i/((
NekDouble)(npts1-1))*(values[dim+4] - values[4]))*(1.0-j/((
NekDouble)(npts2-1))) +
202 (values[3*dim+4] + i/((
NekDouble)(npts1-1))*(values[2*dim+4] - values[3*dim+4]))*(j/((
NekDouble)(npts2-1)));
213 std::vector<std::string> files;
215 files.push_back(
m_config[
"fromxml"].as<string>());
222 int coordim =
m_f->m_fieldPts->m_ptsDim;
223 int npts =
m_f->m_fieldPts->m_pts[0].num_elements();
224 Array<OneD, Array<OneD, NekDouble> > coords =
m_f->m_fieldPts->m_pts;
226 rng->m_checkShape =
false;
230 rng->m_doZrange =
true;
234 rng->m_doYrange =
true;
238 rng->m_doXrange =
true;
243 ASSERTL0(
false,
"too many values specfied in range");
255 Array<OneD,int> ElementGIDs(expansions.size());
256 SpatialDomains::ExpansionMap::const_iterator expIt;
259 for (expIt = expansions.begin(); expIt != expansions.end();
262 ElementGIDs[i++] = expIt->second->m_geomShPtr->GetGlobalID();
265 string fromfld =
m_config[
"fromfld"].as<
string>();
271 int NumHomogeneousDir =
m_fromField->m_fielddef[0]->m_numHomogeneousDir;
277 int nfields =
m_fromField->m_fielddef[0]->m_fields.size();
282 m_f->m_exp.resize(nfields);
285 for(i = 1; i < nfields; ++i)
291 for(
int j = 0; j < nfields; ++j)
293 for (i = 0; i <
m_fromField->m_fielddef.size(); i++)
303 m_f->m_fieldPts->m_fields.push_back(
m_fromField->m_fielddef[0]->m_fields[j]);
307 if(
m_fromField->m_session->GetComm()->GetRank() == 0)
309 cout <<
"Interpolating [" << flush;
317 clamp_low, clamp_up, def_value);
319 if(
m_fromField->m_session->GetComm()->GetRank() == 0)
327 vector<MultiRegions::ExpListSharedPtr> &field0,
328 Array<
OneD, Array<OneD, NekDouble> > &pts,
333 int expdim = field0[0]->GetCoordim(0);
335 Array<OneD, NekDouble> coords(expdim), Lcoords(expdim);
336 int nq1 = pts[0].num_elements();
339 static int intpts = 0;
342 m_f->m_data.resize(field0.size());
344 for (f = 0; f < field0.size(); ++f)
346 m_f->m_data[f].resize(nq1);
349 for (r = 0; r < nq1; r++)
351 coords[0] = pts[0][r];
352 coords[1] = pts[1][r];
355 coords[2] = pts[2][r];
359 elmtid = field0[0]->GetExpIndex(coords, Lcoords, 1e-3);
363 offset = field0[0]->GetPhys_Offset(field0[0]->
364 GetOffset_Elmt_Id(elmtid));
366 for (f = 0; f < field0.size(); ++f)
369 value = field0[f]->GetExp(elmtid)->
370 StdPhysEvaluate(Lcoords, field0[f]->GetPhys() +offset);
372 if ((boost::math::isnan)(value))
374 ASSERTL0(
false,
"new value is not a number");
378 value = (value > clamp_up)? clamp_up :
379 ((value < clamp_low)? clamp_low :
382 m_f->m_data[f][r] = value;
388 for (f = 0; f < field0.size(); ++f)
390 m_f->m_data[f][r] = def_value;
394 if (intpts%1000 == 0)