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;
229 rng->doZrange =
true;
233 rng->doYrange =
true;
237 rng->doXrange =
true;
242 ASSERTL0(
false,
"too many values specfied in range");
254 Array<OneD,int> ElementGIDs(expansions.size());
255 SpatialDomains::ExpansionMap::const_iterator expIt;
258 for (expIt = expansions.begin(); expIt != expansions.end();
261 ElementGIDs[i++] = expIt->second->m_geomShPtr->GetGlobalID();
264 string fromfld =
m_config[
"fromfld"].as<
string>();
270 int NumHomogeneousDir =
m_fromField->m_fielddef[0]->m_numHomogeneousDir;
276 int nfields =
m_fromField->m_fielddef[0]->m_fields.size();
281 m_f->m_exp.resize(nfields);
284 for(i = 1; i < nfields; ++i)
290 for(
int j = 0; j < nfields; ++j)
292 for (i = 0; i <
m_fromField->m_fielddef.size(); i++)
302 m_f->m_fieldPts->m_fields.push_back(
m_fromField->m_fielddef[0]->m_fields[j]);
306 if(
m_fromField->m_session->GetComm()->GetRank() == 0)
308 cout <<
"Interpolating [" << flush;
316 clamp_low, clamp_up, def_value);
318 if(
m_fromField->m_session->GetComm()->GetRank() == 0)
326 vector<MultiRegions::ExpListSharedPtr> &field0,
327 Array<
OneD, Array<OneD, NekDouble> > &pts,
332 int expdim = field0[0]->GetCoordim(0);
334 Array<OneD, NekDouble> coords(expdim), Lcoords(expdim);
335 int nq1 = pts[0].num_elements();
338 static int intpts = 0;
341 m_f->m_data.resize(field0.size());
343 for (f = 0; f < field0.size(); ++f)
345 m_f->m_data[f].resize(nq1);
348 for (r = 0; r < nq1; r++)
350 coords[0] = pts[0][r];
351 coords[1] = pts[1][r];
354 coords[2] = pts[2][r];
358 elmtid = field0[0]->GetExpIndex(coords, Lcoords, 1e-3);
362 offset = field0[0]->GetPhys_Offset(field0[0]->
363 GetOffset_Elmt_Id(elmtid));
365 for (f = 0; f < field0.size(); ++f)
368 value = field0[f]->GetExp(elmtid)->
369 StdPhysEvaluate(Lcoords, field0[f]->GetPhys() +offset);
371 if ((boost::math::isnan)(value))
373 ASSERTL0(
false,
"new value is not a number");
377 value = (value > clamp_up)? clamp_up :
378 ((value < clamp_low)? clamp_low :
381 m_f->m_data[f][r] = value;
387 for (f = 0; f < field0.size(); ++f)
389 m_f->m_data[f][r] = def_value;
393 if (intpts%1000 == 0)