43 #include <boost/math/special_functions/fpclassify.hpp>
52 ProcessInterpField::create,
53 "Interpolates one field to another, requires fromxml, "
54 "fromfld to be defined");
61 "Xml file form which to interpolate field");
64 "Need to specify fromxml=file.xml");
67 "Fld file form which to interpolate field");
70 "Need to specify fromfld=file.fld ");
73 "Lower bound for interpolation value");
75 "Upper bound for interpolation value");
77 "Default value if point is outside domain");
89 cout <<
"Processing interpolation" << endl;
94 std::vector<std::string> files;
97 files.push_back(
m_config[
"fromxml"].as<string>());
105 int coordim =
m_f->m_exp[0]->GetCoordim(0);
106 int npts =
m_f->m_exp[0]->GetTotPoints();
107 Array<OneD, Array<OneD, NekDouble> > coords(3);
110 for(
int i = 0; i < coordim; ++i)
112 coords[i] = Array<OneD, NekDouble>(
npts);
115 for(
int i = coordim; i < 3; ++i)
120 m_f->m_exp[0]->GetCoords(coords[0],coords[1],coords[2]);
125 rng->doZrange =
true;
129 rng->doYrange =
true;
133 rng->doXrange =
true;
138 ASSERTL0(
false,
"too many values specfied in range");
151 if(!expansions.size())
156 Array<OneD,int> ElementGIDs(expansions.size());
157 SpatialDomains::ExpansionMap::const_iterator expIt;
160 for (expIt = expansions.begin(); expIt != expansions.end();
163 ElementGIDs[i++] = expIt->second->m_geomShPtr->GetGlobalID();
166 string fromfld =
m_config[
"fromfld"].as<
string>();
172 int NumHomogeneousDir =
m_fromField->m_fielddef[0]->m_numHomogeneousDir;
178 int nfields =
m_fromField->m_fielddef[0]->m_fields.size();
183 m_f->m_exp.resize(nfields);
186 for(i = 1; i < nfields; ++i)
188 m_f->m_exp[i] =
m_f->AppendExpList(NumHomogeneousDir);
194 for(
int j = 0; j < nfields; ++j)
196 for (i = 0; i <
m_fromField->m_fielddef.size(); i++)
209 int nq1 =
m_f->m_exp[0]->GetTotPoints();
211 Array<OneD, NekDouble> x1(nq1);
212 Array<OneD, NekDouble> y1(nq1);
213 Array<OneD, NekDouble> z1(nq1);
217 m_f->m_exp[0]->GetCoords(x1, y1);
219 else if (coordim == 3)
221 m_f->m_exp[0]->GetCoords(x1, y1, z1);
224 if(
m_f->m_session->GetComm()->TreatAsRankZero())
226 cout <<
"Interpolating [" << flush;
234 x1, y1, z1, clamp_low, clamp_up,def_value);
236 if(
m_f->m_session->GetComm()->TreatAsRankZero())
243 std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef
244 =
m_f->m_exp[0]->GetFieldDefinitions();
245 std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
247 for (
int j = 0; j < nfields; ++j)
249 m_f->m_exp[j]->FwdTrans(
m_f->m_exp[j]->GetPhys(),
250 m_f->m_exp[j]->UpdateCoeffs());
251 for (i = 0; i < FieldDef.size(); ++i)
253 FieldDef[i]->m_fields.push_back(
m_fromField->m_fielddef[0]->m_fields[j]);
254 m_f->m_exp[j]->AppendFieldData(FieldDef[i], FieldData[i]);
258 m_f->m_fielddef = FieldDef;
259 m_f->m_data = FieldData;
263 vector<MultiRegions::ExpListSharedPtr> &field0,
264 vector<MultiRegions::ExpListSharedPtr> &field1,
265 Array<OneD, NekDouble> x,
266 Array<OneD, NekDouble> y,
267 Array<OneD, NekDouble> z,
272 int expdim = field0[0]->GetCoordim(0);
274 Array<OneD, NekDouble> coords(expdim), Lcoords(expdim);
275 int nq1 = field1[0]->GetTotPoints();
278 static int intpts = 0;
280 ASSERTL0(field0.size() == field1.size(),
281 "Input field dimension must be same as output dimension");
283 for (r = 0; r < nq1; r++)
293 elmtid = field0[0]->GetExpIndex(coords, Lcoords, 1e-3,
true);
297 offset = field0[0]->GetPhys_Offset(field0[0]->
298 GetOffset_Elmt_Id(elmtid));
300 for (f = 0; f < field1.size(); ++f)
303 value = field0[f]->GetExp(elmtid)->
304 StdPhysEvaluate(Lcoords, field0[f]->GetPhys() +offset);
306 if ((boost::math::isnan)(value))
308 ASSERTL0(
false,
"new value is not a number");
312 value = (value > clamp_up)? clamp_up :
313 ((value < clamp_low)? clamp_low :
316 field1[f]->UpdatePhys()[r] = value;
322 for (f = 0; f < field1.size(); ++f)
324 field1[f]->UpdatePhys()[r] = def_value;
328 if (intpts%1000 == 0)