Commit 2a4b9889 authored by Michael Turner's avatar Michael Turner
Browse files

Merge branch 'fix/varopti-memleak' into 'master'

Fix memory leak in variational optimiser, add small optimisations

See merge request !785
parents 0668c746 895438d0
......@@ -46,6 +46,7 @@ v4.4.1
when some part of the system fails (!756)
- Add manifold meshing option (!756)
- Fix issue with older rea input files (!765)
- Fix memory leak in variational optimiser, add small optimisations (!785)
**IncNavierStokesSolver**
- Fix an initialisation issue when using an additional advective field (!779)
......
......@@ -51,6 +51,10 @@ class NodeOptiJob;
class NodeOpti
{
// Typedef for derivative storage, we use boost::multi_array so we can pass
// this to functions easily
typedef boost::multi_array<NekDouble, 4> DerivArray;
public:
NodeOpti(NodeSharedPtr n, std::vector<ElUtilSharedPtr> e,
ResidualSharedPtr r,
......@@ -63,6 +67,27 @@ public:
{
m_data[e[i]->GetEl()->GetShapeType()].push_back(e[i]);
}
// Set up storage for GetFunctional to avoid reallocation on each call.
size_t storageCount = 0;
std::map<LibUtilities::ShapeType, std::vector<ElUtilSharedPtr> >
::iterator typeIt;
// Count total storage needed.
for (typeIt = m_data.begin(); typeIt != m_data.end(); typeIt++)
{
const int pts = m_derivUtils[typeIt->first]->pts;
const int nElmt = typeIt->second.size();
storageCount = std::max(storageCount,
3 * m_derivUtils[typeIt->first]->ptsStd *
typeIt->second.size());
m_derivs.insert(std::make_pair(
typeIt->first,
DerivArray(boost::extents[3][nElmt][3][pts])));
}
m_tmpStore.resize(storageCount);
}
virtual ~NodeOpti(){};
......@@ -82,6 +107,9 @@ protected:
boost::mutex mtx;
std::map<LibUtilities::ShapeType, std::vector<ElUtilSharedPtr> > m_data;
Array<OneD, NekDouble> m_grad;
std::vector<NekDouble> m_tmpStore;
boost::unordered_map<LibUtilities::ShapeType, DerivArray> m_derivs;
template <int DIM> int IsIndefinite();
......
......@@ -157,7 +157,11 @@ void ProcessVarOpti::Process()
}
ASSERTL0(fd, "failed to find order of mesh");
int intOrder = m_config["overint"].as<NekDouble>();
// Safety feature: limit over-integration order for high-order triangles
// over order 5.
int intOrder = m_config["overint"].as<int>();
intOrder = m_mesh->m_nummode + intOrder <= 11 ?
intOrder : 11 - m_mesh->m_nummode;
if (m_mesh->m_verbose)
{
......@@ -386,7 +390,7 @@ void ProcessVarOpti::Process()
t.Stop();
RemoveLinearCurvature();
//RemoveLinearCurvature();
if(m_mesh->m_verbose)
{
......
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