Commit ab202415 authored by Kilian Lackhove's avatar Kilian Lackhove
Browse files

Interpolator: use shared pointers for PtsFields

parent bfd79831
......@@ -41,16 +41,17 @@ namespace Nektar
namespace LibUtilities
{
Interpolator::Interpolator(const PtsField &inField, PtsField &outField) :
Interpolator::Interpolator(const PtsFieldSharedPtr inField, PtsFieldSharedPtr &outField) :
m_inField(inField),
m_outField(outField),
m_method(ePtsNoMethod),
m_dim(3)
{
ASSERTL0(inField.GetNFields() == outField.GetNFields(), "number of fields does not match");
ASSERTL0(inField->GetNFields() == outField->GetNFields(), "number of fields does not match");
}
/**
* @brief Compute the weights for an interpolation of the field values to physical points
*
......@@ -62,7 +63,7 @@ Interpolator::Interpolator(const PtsField &inField, PtsField &outField) :
*/
void Interpolator::CalcWeights(PtsInterpMethod method, short int coordId, NekDouble width)
{
int nOutPts = m_outField.GetNpoints();
int nOutPts = m_outField->GetNpoints();
int lastProg = 0;
NekDouble sigma = width * 0.4246609001;;
......@@ -75,12 +76,12 @@ void Interpolator::CalcWeights(PtsInterpMethod method, short int coordId, NekDou
m_neighInds = Array<OneD, Array<OneD, unsigned int> >(nOutPts);
std::vector<PtsPoint > inPoints;
for (int i = 0; i < m_inField.GetNpoints(); ++i)
for (int i = 0; i < m_inField->GetNpoints(); ++i)
{
Array<OneD, NekDouble> coords(m_dim);
for (int j = 0; j < m_dim; ++j)
{
coords[j] = m_inField.GetPointVal(j,i);
coords[j] = m_inField->GetPointVal(j,i);
}
inPoints.push_back(PtsPoint(i, coords, 1E30));
}
......@@ -92,7 +93,7 @@ void Interpolator::CalcWeights(PtsInterpMethod method, short int coordId, NekDou
Array<OneD, NekDouble> tmp(m_dim);
for (int j = 0; j < m_dim; ++j)
{
tmp[j] = m_outField.GetPointVal(j,i);
tmp[j] = m_outField->GetPointVal(j,i);
}
PtsPoint searchPt(i, tmp, 1E30);
......@@ -103,7 +104,7 @@ void Interpolator::CalcWeights(PtsInterpMethod method, short int coordId, NekDou
coordId = 0;
}
if (m_outField.GetNpoints() <= 2)
if (m_outField->GetNpoints() <= 2)
{
CalcW_Linear(searchPt, coordId);
}
......@@ -156,9 +157,9 @@ void Interpolator::Interpolate(
ASSERTL1(m_weights[0].num_elements() == m_neighInds[0].num_elements(),
"weights / neighInds mismatch")
int nFields = m_outField.GetNFields();
int nOutPts = m_outField.GetNpoints();
int inDim = m_inField.GetDim();
int nFields = m_outField->GetNFields();
int nOutPts = m_outField->GetNpoints();
int inDim = m_inField->GetDim();
// interpolate points and transform
for (int i = 0; i < nFields; ++i)
......@@ -170,9 +171,9 @@ void Interpolator::Interpolate(
for (int k = 0; k < nPts; ++k)
{
unsigned int nIdx = m_neighInds[j][k];
val += m_weights[j][k] * m_inField.GetPointVal(inDim + i, nIdx);
val += m_weights[j][k] * m_inField->GetPointVal(inDim + i, nIdx);
}
m_outField.SetPointVal(i,j, val);
m_outField->SetPointVal(i,j, val);
}
}
}
......@@ -184,15 +185,15 @@ int Interpolator::GetDim() const
}
void Interpolator::GetInField(PtsField &inField) const
PtsFieldSharedPtr Interpolator::GetInField() const
{
inField = m_inField;
return m_inField;
}
void Interpolator::GetOutField(PtsField &outField) const
PtsFieldSharedPtr Interpolator::GetOutField() const
{
outField = m_outField;
return m_outField;
}
......@@ -354,7 +355,7 @@ void Interpolator::CalcW_Shepard(const PtsPoint &searchPt)
// find nearest neighbours
vector<PtsPoint > neighbourPts;
int numPts = pow(float(2), m_dim);
numPts = min(numPts, int(m_inField.GetNpoints() / 2));
numPts = min(numPts, int(m_inField->GetNpoints() / 2));
FindNNeighbours(searchPt, neighbourPts, numPts);
m_neighInds[searchPt.idx] = Array<OneD, unsigned int> (numPts);
......
......@@ -130,7 +130,7 @@ class Interpolator
{
public:
LIB_UTILITIES_EXPORT Interpolator(const PtsField &inField, PtsField &outField);
LIB_UTILITIES_EXPORT Interpolator(const PtsFieldSharedPtr inField, PtsFieldSharedPtr &outField);
LIB_UTILITIES_EXPORT void CalcWeights(
PtsInterpMethod method,
......@@ -144,9 +144,9 @@ class Interpolator
LIB_UTILITIES_EXPORT int GetDim() const;
LIB_UTILITIES_EXPORT void GetInField(PtsField &inField) const;
LIB_UTILITIES_EXPORT PtsFieldSharedPtr GetInField() const;
LIB_UTILITIES_EXPORT void GetOutField(PtsField &outField) const;
LIB_UTILITIES_EXPORT PtsFieldSharedPtr GetOutField() const;
LIB_UTILITIES_EXPORT void GetWeights(
Array<OneD, Array<OneD, float> > &weights,
......@@ -167,8 +167,8 @@ class Interpolator
private:
PtsField m_inField;
PtsField m_outField;
PtsFieldSharedPtr m_inField;
PtsFieldSharedPtr m_outField;
int m_dim;
/// Interpolation Method
......@@ -207,8 +207,8 @@ class Interpolator
const unsigned int numPts = 1);
};
// typedef boost::shared_ptr<Interpolator> InterpolatorSharedPtr;
// static InterpolatorSharedPtr NullInterpolator;
typedef boost::shared_ptr<Interpolator> InterpolatorSharedPtr;
static InterpolatorSharedPtr NullInterpolator;
}
......
......@@ -97,7 +97,9 @@ void ProcessInterpPointDataToFld::Process(po::variables_map &vm)
intFields[i] = Array<OneD, NekDouble>(totpoints);
}
m_f->m_exp[0]->GetCoords(intFields[0],intFields[1],intFields[2]);
LibUtilities::PtsField outPts(3, intFields);
LibUtilities::PtsFieldSharedPtr outPts =
MemoryManager<LibUtilities::PtsField>::
AllocateSharedPtr(3, intFields);
int coord_id = m_config["interpcoord"].as<int>();
ASSERTL0(coord_id <= m_f->m_fieldPts->GetDim() - 1,
......@@ -111,8 +113,7 @@ void ProcessInterpPointDataToFld::Process(po::variables_map &vm)
cout << "Interpolating: ";
}
LibUtilities::PtsField inPts = *(m_f->m_fieldPts);
LibUtilities::Interpolator Interp(inPts, outPts);
LibUtilities::Interpolator Interp(m_f->m_fieldPts, outPts);
Interp.Interpolate(Nektar::LibUtilities::ePtsShepard, coord_id, 0.0);
cout << " done" << endl;
......@@ -121,7 +122,7 @@ void ProcessInterpPointDataToFld::Process(po::variables_map &vm)
{
for(j = 0; j < nFields; ++j)
{
m_f->m_exp[j]->SetPhys(i, outPts.GetPointVal(j,i));
m_f->m_exp[j]->SetPhys(i, outPts->GetPointVal(j,i));
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment