Commit f5a52ef0 authored by Chris Cantwell's avatar Chris Cantwell
Browse files

Added Checkpoint filter.

Updated solvers to include new checkpoint filter.
Updated XML format of filter input.
Now pass session reader to filters.
Fixed filters for parallel execution.
Changed default legacy checkpoint interval to zero to allow replacement with
new filter.
Closes ticket #66.


git-svn-id: https://gforge.sci.utah.edu/svn/nektar/trunk@3672 305cdda6-5ce1-45b3-a98d-dfc68c8b3305
parent 3bc4fce7
......@@ -735,6 +735,10 @@ namespace Nektar
}
pNektar->LinkEndChild(vConditions);
}
if (pSession->DefinesElement("Nektar/Filters"))
{
pNektar->LinkEndChild(new TiXmlElement(*pSession->GetElement("Nektar/Filters")));
}
// @todo: Extract subset of history points within this partition.
if (pSession->DefinesElement("Nektar/History"))
{
......
......@@ -1590,25 +1590,22 @@ namespace Nektar
TiXmlElement *filter = filters->FirstChildElement("FILTER");
while (filter)
{
std::map<std::string, std::string> vParams;
ASSERTL0(filter->Attribute("TYPE"),
"Missing attribute 'TYPE' for filter.");
std::string typeStr = filter->Attribute("TYPE");
TiXmlElement *type = filter->FirstChildElement("TYPE");
ASSERTL0(type, "No type specified for filter.");
ASSERTL0(type->GetText(), "Empty type string specified.");
std::string typeStr = type->GetText();
std::map<std::string, std::string> vParams;
TiXmlElement *param = filter->FirstChildElement("PARAM");
while (param)
{
TiXmlElement *name = param->FirstChildElement("NAME");
ASSERTL0(name, "No name specified for parameter.");
ASSERTL0(name->GetText(), "Empty name string for param.");
std::string nameStr = name->GetText();
TiXmlElement *value = param->FirstChildElement("VALUE");
ASSERTL0(value, "No value specified for parameter.");
ASSERTL0(value->GetText(), "Empty value string for param.");
std::string valueStr = value->GetText();
ASSERTL0(param->Attribute("NAME"),
"Missing attribute 'NAME' for parameter in filter "
+ typeStr + "'.");
std::string nameStr = param->Attribute("NAME");
ASSERTL0(param->GetText(), "Empty value string for param.");
std::string valueStr = param->GetText();
vParams[nameStr] = valueStr;
......
......@@ -17,6 +17,7 @@ SET(ADRSolverSource
../Auxiliary/DriverModifiedArnoldi.cpp
../Auxiliary/Filters/Filter.cpp
../Auxiliary/Filters/FilterThresholdMax.cpp
../Auxiliary/Filters/FilterCheckpoint.cpp
../Auxiliary/UnsteadySystem.cpp
../Auxiliary/EquationSystem.cpp)
......
......@@ -493,7 +493,7 @@ namespace Nektar
m_session->LoadParameter("Time", m_time, 0.0);
m_session->LoadParameter("TimeStep", m_timestep, 0.01);
m_session->LoadParameter("NumSteps", m_steps, 0);
m_session->LoadParameter("IO_CheckSteps", m_checksteps, m_steps);
m_session->LoadParameter("IO_CheckSteps", m_checksteps, 0);
m_session->LoadParameter("FinTime", m_fintime, 0);
m_session->LoadParameter("NumQuadPointsError", m_NumQuadPointsError, 0);
......@@ -1018,7 +1018,7 @@ namespace Nektar
}
}
if(dumpInitialConditions)
if(dumpInitialConditions && m_checksteps)
{
Checkpoint_Output(0);
}
......
/*
* Filter.cpp
*
* Created on: 24 Feb 2012
* Author: cc
*/
///////////////////////////////////////////////////////////////////////////////
//
// File Filter.cpp
//
// For more information, please see: http://www.nektar.info
//
// The MIT License
//
// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
// Department of Aeronautics, Imperial College London (UK), and Scientific
// Computing and Imaging Institute, University of Utah (USA).
//
// License for the specific language governing rights and limitations under
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// Description: Base class for filters.
//
///////////////////////////////////////////////////////////////////////////////
#include <Auxiliary/Filters/Filter.h>
......@@ -18,14 +46,13 @@ namespace Nektar
}
Filter::Filter()
Filter::Filter(const LibUtilities::SessionReaderSharedPtr& pSession) :
m_session(pSession)
{
}
Filter::~Filter()
{
}
}
/*
* Filter.h
*
* Created on: 24 Feb 2012
* Author: cc
*/
///////////////////////////////////////////////////////////////////////////////
//
// File Filter.h
//
// For more information, please see: http://www.nektar.info
//
// The MIT License
//
// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
// Department of Aeronautics, Imperial College London (UK), and Scientific
// Computing and Imaging Institute, University of Utah (USA).
//
// License for the specific language governing rights and limitations under
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// Description: Base class for filters.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef FILTER_H_
#define FILTER_H_
......@@ -23,6 +51,7 @@ namespace Nektar
/// the Driver class.
typedef LibUtilities::NekFactory<
std::string, Filter,
const LibUtilities::SessionReaderSharedPtr&,
const std::map<std::string, std::string>&
> FilterFactory;
FilterFactory& GetFilterFactory();
......@@ -30,7 +59,7 @@ namespace Nektar
class Filter
{
public:
Filter();
Filter(const LibUtilities::SessionReaderSharedPtr& pSession);
~Filter();
inline void Initialise(const Array<OneD, const MultiRegions::ExpListSharedPtr> &pFields, const NekDouble &time);
......@@ -39,11 +68,12 @@ namespace Nektar
inline bool IsTimeDependent();
protected:
LibUtilities::SessionReaderSharedPtr m_session;
virtual void v_Initialise(const Array<OneD, const MultiRegions::ExpListSharedPtr> &pFields, const NekDouble &time) = 0;
virtual void v_Update(const Array<OneD, const MultiRegions::ExpListSharedPtr> &pFields, const NekDouble &time) = 0;
virtual void v_Finalise(const Array<OneD, const MultiRegions::ExpListSharedPtr> &pFields, const NekDouble &time) = 0;
virtual bool v_IsTimeDependent() = 0;
};
inline void Filter::Initialise(const Array<OneD, const MultiRegions::ExpListSharedPtr> &pFields, const NekDouble &time)
......
///////////////////////////////////////////////////////////////////////////////
//
// File FilterCheckpoint.cpp
//
// For more information, please see: http://www.nektar.info
//
// The MIT License
//
// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
// Department of Aeronautics, Imperial College London (UK), and Scientific
// Computing and Imaging Institute, University of Utah (USA).
//
// License for the specific language governing rights and limitations under
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// Description: Outputs solution fields during time-stepping.
//
///////////////////////////////////////////////////////////////////////////////
#include <Auxiliary/Filters/FilterCheckpoint.h>
namespace Nektar
{
std::string FilterCheckpoint::className = GetFilterFactory().RegisterCreatorFunction("Checkpoint", FilterCheckpoint::create);
FilterCheckpoint::FilterCheckpoint(
const LibUtilities::SessionReaderSharedPtr &pSession,
const std::map<std::string, std::string> &pParams) :
Filter(pSession)
{
if (pParams.find("OutputFile") == pParams.end())
{
m_outputFile = m_session->GetSessionName();
}
else
{
ASSERTL0(!(pParams.find("OutputFile")->second.empty()),
"Missing parameter 'OutputFile'.");
m_outputFile = pParams.find("OutputFile")->second;
}
ASSERTL0(pParams.find("OutputFrequency") != pParams.end(),
"Missing parameter 'OutputFrequency'.");
m_outputFrequency = atoi(pParams.find("OutputFrequency")->second.c_str());
m_outputIndex = 0;
m_index = 0;
}
FilterCheckpoint::~FilterCheckpoint()
{
}
void FilterCheckpoint::v_Initialise(const Array<OneD, const MultiRegions::ExpListSharedPtr> &pFields, const NekDouble &time)
{
m_index = 0;
m_outputIndex = 0;
}
void FilterCheckpoint::v_Update(const Array<OneD, const MultiRegions::ExpListSharedPtr> &pFields, const NekDouble &time)
{
m_index++;
if (m_index % m_outputFrequency > 0)
{
return;
}
std::stringstream vOutputFilename;
vOutputFilename << m_outputFile << "_" << m_outputIndex;
if (m_session->GetComm()->GetSize() > 1)
{
vOutputFilename << "_P" << m_session->GetComm()->GetRank();
}
vOutputFilename << ".chk";
SpatialDomains::MeshGraphSharedPtr vGraph = pFields[0]->GetGraph();
std::vector<SpatialDomains::FieldDefinitionsSharedPtr> FieldDef
= pFields[0]->GetFieldDefinitions();
std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
// copy Data into FieldData and set variable
for(int j = 0; j < pFields.num_elements(); ++j)
{
for(int i = 0; i < FieldDef.size(); ++i)
{
// Could do a search here to find correct variable
FieldDef[i]->m_fields.push_back(m_session->GetVariable(j));
pFields[0]->AppendFieldData(FieldDef[i], FieldData[i], pFields[j]->UpdateCoeffs());
}
}
vGraph->Write(vOutputFilename.str(),FieldDef,FieldData);
m_outputIndex++;
}
void FilterCheckpoint::v_Finalise(const Array<OneD, const MultiRegions::ExpListSharedPtr> &pFields, const NekDouble &time)
{
}
bool FilterCheckpoint::v_IsTimeDependent()
{
return true;
}
}
///////////////////////////////////////////////////////////////////////////////
//
// File FilterCheckpoint.h
//
// For more information, please see: http://www.nektar.info
//
// The MIT License
//
// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
// Department of Aeronautics, Imperial College London (UK), and Scientific
// Computing and Imaging Institute, University of Utah (USA).
//
// License for the specific language governing rights and limitations under
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// Description: Outputs solution fields during time-stepping.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef FILTERCHECKPOINT_H_
#define FILTERCHECKPOINT_H_
#include <Auxiliary/Filters/Filter.h>
namespace Nektar
{
class FilterCheckpoint : public Filter
{
public:
friend class MemoryManager<FilterCheckpoint>;
/// Creates an instance of this class
static FilterSharedPtr create(
const LibUtilities::SessionReaderSharedPtr &pSession,
const std::map<std::string, std::string> &pParams) {
FilterSharedPtr p = MemoryManager<FilterCheckpoint>::AllocateSharedPtr(pSession, pParams);
//p->InitObject();
return p;
}
///Name of the class
static std::string className;
FilterCheckpoint(
const LibUtilities::SessionReaderSharedPtr &pSession,
const std::map<std::string, std::string> &pParams);
~FilterCheckpoint();
protected:
virtual void v_Initialise(const Array<OneD, const MultiRegions::ExpListSharedPtr> &pFields, const NekDouble &time);
virtual void v_Update(const Array<OneD, const MultiRegions::ExpListSharedPtr> &pFields, const NekDouble &time);
virtual void v_Finalise(const Array<OneD, const MultiRegions::ExpListSharedPtr> &pFields, const NekDouble &time);
virtual bool v_IsTimeDependent();
private:
unsigned int m_index;
unsigned int m_outputIndex;
unsigned int m_outputFrequency;
std::string m_outputFile;
};
}
#endif /* FILTERCHECKPOINT_H_ */
/*
* FilterThresholdMax.cpp
*
* Created on: 24 Feb 2012
* Author: cc
*/
///////////////////////////////////////////////////////////////////////////////
//
// File FilterThresholdMax.cpp
//
// For more information, please see: http://www.nektar.info
//
// The MIT License
//
// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
// Department of Aeronautics, Imperial College London (UK), and Scientific
// Computing and Imaging Institute, University of Utah (USA).
//
// License for the specific language governing rights and limitations under
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// Description: Outputs time when solution first exceeds a threshold value.
//
///////////////////////////////////////////////////////////////////////////////
#include <Auxiliary/Filters/FilterThresholdMax.h>
......@@ -11,8 +39,10 @@ namespace Nektar
{
std::string FilterThresholdMax::className = GetFilterFactory().RegisterCreatorFunction("ThresholdMax", FilterThresholdMax::create);
FilterThresholdMax::FilterThresholdMax(const std::map<std::string, std::string> &pParams) :
Filter()
FilterThresholdMax::FilterThresholdMax(
const LibUtilities::SessionReaderSharedPtr &pSession,
const std::map<std::string, std::string> &pParams) :
Filter(pSession)
{
ASSERTL0(pParams.find("ThresholdValue") != pParams.end(),
"Missing parameter 'ThresholdValue'.");
......@@ -51,6 +81,14 @@ namespace Nektar
void FilterThresholdMax::v_Finalise(const Array<OneD, const MultiRegions::ExpListSharedPtr> &pFields, const NekDouble &time)
{
std::stringstream vOutputFilename;
vOutputFilename << m_outputFile;
if (m_session->GetComm()->GetSize() > 1)
{
vOutputFilename << "_P" << m_session->GetComm()->GetRank();
}
vOutputFilename << ".fld";
SpatialDomains::MeshGraphSharedPtr vGraph = pFields[0]->GetGraph();
std::vector<SpatialDomains::FieldDefinitionsSharedPtr> FieldDef
......@@ -68,7 +106,7 @@ namespace Nektar
pFields[0]->AppendFieldData(FieldDef[i], FieldData[i], vCoeffs);
}
vGraph->Write(m_outputFile,FieldDef,FieldData);
vGraph->Write(vOutputFilename.str(),FieldDef,FieldData);
}
......
/*
* FilterThresholdMax.h
*
* Created on: 24 Feb 2012
* Author: cc
*/
///////////////////////////////////////////////////////////////////////////////
//
// File FilterThresholdMax.h
//
// For more information, please see: http://www.nektar.info
//
// The MIT License
//
// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
// Department of Aeronautics, Imperial College London (UK), and Scientific
// Computing and Imaging Institute, University of Utah (USA).
//
// License for the specific language governing rights and limitations under
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// Description: Outputs time when solution first exceeds a threshold value.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef FILTERTHRESHOLDMAX_H_
#define FILTERTHRESHOLDMAX_H_
......@@ -19,8 +47,10 @@ namespace Nektar
friend class MemoryManager<FilterThresholdMax>;
/// Creates an instance of this class
static FilterSharedPtr create(const std::map<std::string, std::string> &pParams) {
FilterSharedPtr p = MemoryManager<FilterThresholdMax>::AllocateSharedPtr(pParams);
static FilterSharedPtr create(
const LibUtilities::SessionReaderSharedPtr &pSession,
const std::map<std::string, std::string> &pParams) {
FilterSharedPtr p = MemoryManager<FilterThresholdMax>::AllocateSharedPtr(pSession, pParams);
//p->InitObject();
return p;
}
......@@ -28,7 +58,9 @@ namespace Nektar
///Name of the class
static std::string className;
FilterThresholdMax(const std::map<std::string, std::string> &pParams);
FilterThresholdMax(
const LibUtilities::SessionReaderSharedPtr &pSession,
const std::map<std::string, std::string> &pParams);
~FilterThresholdMax();
protected:
......
......@@ -107,7 +107,7 @@ namespace Nektar
LibUtilities::FilterMap f = m_session->GetFilters();
for (x = f.begin(); x != f.end(); ++x)
{
m_filters.push_back(GetFilterFactory().CreateInstance(x->first, x->second));
m_filters.push_back(GetFilterFactory().CreateInstance(x->first, m_session, x->second));
}
}
......@@ -457,7 +457,7 @@ namespace Nektar
// Transform data if needed
if((m_historysteps && m_historyList.size() > 0 && !((n+1)%m_historysteps))
|| (n&&(!((n+1)%m_checksteps))))
|| (m_checksteps&&n&&(!((n+1)%m_checksteps))))
{
for (i = 0; i < m_intVariables.size(); ++i)
{
......@@ -480,7 +480,7 @@ namespace Nektar
}
// Write out checkpoint files.
if(n&&(!((n+1)%m_checksteps)))
if(m_checksteps&&n&&(!((n+1)%m_checksteps)))
{
Checkpoint_Output(nchk++);
}
......
......@@ -18,6 +18,7 @@ SET(CardiacEPSolverSource
../Auxiliary/DriverStandard.cpp
../Auxiliary/Filters/Filter.cpp
../Auxiliary/Filters/FilterThresholdMax.cpp
../Auxiliary/Filters/FilterCheckpoint.cpp
)
ADD_SOLVER_EXECUTABLE(CardiacEPSolver solvers-extra
......
......@@ -7,6 +7,7 @@ SET(ImageWarpingSolverSource
../Auxiliary/DriverModifiedArnoldi.cpp
../Auxiliary/Filters/Filter.cpp
../Auxiliary/Filters/FilterThresholdMax.cpp
../Auxiliary/Filters/FilterCheckpoint.cpp