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");
63 "Fld file form which to interpolate field");
66 "Lower bound for interpolation value");
68 "Upper bound for interpolation value");
70 "Default value if point is outside domain");
81 if(
m_f->m_comm->TreatAsRankZero())
83 cout <<
"ProcessInterpField: Interpolating field..." << endl;
89 std::vector<std::string> files;
92 files.push_back(
m_config[
"fromxml"].as<string>());
100 int coordim =
m_f->m_exp[0]->GetCoordim(0);
101 int npts =
m_f->m_exp[0]->GetTotPoints();
105 for(
int i = 0; i < coordim; ++i)
110 for(
int i = coordim; i < 3; ++i)
115 m_f->m_exp[0]->GetCoords(coords[0],coords[1],coords[2]);
117 rng->m_checkShape =
false;
121 rng->m_doZrange =
true;
125 rng->m_doYrange =
true;
129 rng->m_doXrange =
true;
134 ASSERTL0(
false,
"too many values specfied in range");
147 if(!expansions.size())
153 SpatialDomains::ExpansionMap::const_iterator expIt;
156 for (expIt = expansions.begin(); expIt != expansions.end();
159 ElementGIDs[i++] = expIt->second->m_geomShPtr->GetGlobalID();
162 string fromfld =
m_config[
"fromfld"].as<
string>();
168 int NumHomogeneousDir =
m_fromField->m_fielddef[0]->m_numHomogeneousDir;
174 int nfields =
m_fromField->m_fielddef[0]->m_fields.size();
179 m_f->m_exp.resize(nfields);
182 for(i = 1; i < nfields; ++i)
184 m_f->m_exp[i] =
m_f->AppendExpList(NumHomogeneousDir);
190 for(
int j = 0; j < nfields; ++j)
192 for (i = 0; i <
m_fromField->m_fielddef.size(); i++)
205 int nq1 =
m_f->m_exp[0]->GetTotPoints();
213 m_f->m_exp[0]->GetCoords(x1, y1);
215 else if (coordim == 3)
217 m_f->m_exp[0]->GetCoords(x1, y1, z1);
220 if(
m_f->m_session->GetComm()->TreatAsRankZero())
222 cout <<
"Interpolating [" << flush;
230 x1, y1, z1, clamp_low, clamp_up,def_value);
232 if(
m_f->m_session->GetComm()->TreatAsRankZero())
239 std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef
240 =
m_f->m_exp[0]->GetFieldDefinitions();
241 std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
243 for (
int j = 0; j < nfields; ++j)
245 m_f->m_exp[j]->FwdTrans(
m_f->m_exp[j]->GetPhys(),
246 m_f->m_exp[j]->UpdateCoeffs());
247 for (i = 0; i < FieldDef.size(); ++i)
249 FieldDef[i]->m_fields.push_back(
m_fromField->m_fielddef[0]->m_fields[j]);
250 m_f->m_exp[j]->AppendFieldData(FieldDef[i], FieldData[i]);
254 m_f->m_fielddef = FieldDef;
255 m_f->m_data = FieldData;
259 vector<MultiRegions::ExpListSharedPtr> &field0,
260 vector<MultiRegions::ExpListSharedPtr> &field1,
268 int expdim = field0[0]->GetCoordim(0);
271 int nq1 = field1[0]->GetTotPoints();
274 static int intpts = 0;
276 ASSERTL0(field0.size() == field1.size(),
277 "Input field dimension must be same as output dimension");
279 for (r = 0; r < nq1; r++)
289 elmtid = field0[0]->GetExpIndex(coords, Lcoords, 1e-3,
true);
293 offset = field0[0]->GetPhys_Offset(field0[0]->
294 GetOffset_Elmt_Id(elmtid));
296 for (f = 0; f < field1.size(); ++f)
299 value = field0[f]->GetExp(elmtid)->
300 StdPhysEvaluate(Lcoords, field0[f]->GetPhys() +offset);
302 if ((boost::math::isnan)(value))
304 ASSERTL0(
false,
"new value is not a number");
312 else if( value < clamp_low)
317 field1[f]->UpdatePhys()[r] = value;
323 for (f = 0; f < field1.size(); ++f)
325 field1[f]->UpdatePhys()[r] = def_value;
329 if (intpts%1000 == 0)
#define ASSERTL0(condition, msg)
virtual ~ProcessInterpField()
pair< ModuleType, string > ModuleKey
static Array< OneD, NekDouble > NullNekDouble1DArray
static boost::shared_ptr< MeshGraph > Read(const LibUtilities::SessionReaderSharedPtr &pSession, DomainRangeShPtr &rng=NullDomainRangeShPtr)
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
T Vmax(int n, const T *x, const int incx)
Return the maximum element in x – called vmax to avoid conflict with max.
void InterpolateField(vector< MultiRegions::ExpListSharedPtr > &field0, vector< MultiRegions::ExpListSharedPtr > &field1, Array< OneD, NekDouble > x, Array< OneD, NekDouble > y, Array< OneD, NekDouble > z, NekDouble clamp_low, NekDouble clamp_up, NekDouble def_value)
T Vmin(int n, const T *x, const int incx)
Return the minimum element in x - called vmin to avoid conflict with min.
map< string, ConfigOption > m_config
List of configuration values.
FieldSharedPtr m_f
Field object.
static SessionReaderSharedPtr CreateInstance(int argc, char *argv[])
Creates an instance of the SessionReader class.
FieldSharedPtr m_fromField
boost::shared_ptr< DomainRange > DomainRangeShPtr
boost::shared_ptr< Field > FieldSharedPtr
Represents a command-line configuration option.
static FieldMetaDataMap NullFieldMetaDataMap
std::map< int, ExpansionShPtr > ExpansionMap
ModuleFactory & GetModuleFactory()
Abstract base class for processing modules.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, tDescription pDesc="")
Register a class with the factory.