Commit 3445ade7 authored by Chris Cantwell's avatar Chris Cantwell

Merge branch 'feature/FilterAverageField' of /opt/gitlab/repositories/nektar

parents 106091f3 0289a96f
......@@ -19,6 +19,7 @@ SET(SOLVER_UTILS_SOURCES
EquationSystem.cpp
Filters/Filter.cpp
Filters/FilterAeroForces.cpp
Filters/FilterAverageFields.cpp
Filters/FilterCheckpoint.cpp
Filters/FilterHistoryPoints.cpp
Filters/FilterModalEnergy.cpp
......@@ -54,6 +55,7 @@ SET(SOLVER_UTILS_HEADERS
EquationSystem.h
Filters/Filter.h
Filters/FilterAeroForces.h
Filters/FilterAverageFields.h
Filters/FilterCheckpoint.h
Filters/FilterHistoryPoints.h
Filters/FilterModalEnergy.h
......
///////////////////////////////////////////////////////////////////////////////
//
// File FilterAverageField.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: Average solution fields during time-stepping.
//
///////////////////////////////////////////////////////////////////////////////
#include <SolverUtils/Filters/FilterAverageFields.h>
namespace Nektar
{
namespace SolverUtils
{
std::string FilterAverageFields::className = GetFilterFactory().RegisterCreatorFunction("AverageFields", FilterAverageFields::create);
FilterAverageFields::FilterAverageFields(
const LibUtilities::SessionReaderSharedPtr &pSession,
const std::map<std::string, std::string> &pParams) :
Filter(pSession)
{
if (pParams.find("OutputFile") == pParams.end())
{
string outname = m_session->GetSessionName() + "_avg.fld";
m_outputFile = outname;
}
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_numAverages = 0;
m_index = 0;
m_fld = MemoryManager<LibUtilities::FieldIO>::AllocateSharedPtr(pSession->GetComm());
}
FilterAverageFields::~FilterAverageFields()
{
}
void FilterAverageFields::v_Initialise(const Array<OneD, const MultiRegions::ExpListSharedPtr> &pFields, const NekDouble &time)
{
m_avgFields = Array<OneD, Array<OneD, NekDouble> >(pFields.num_elements());
for(int n =0; n < pFields.num_elements(); ++n)
{
m_avgFields[n] = Array<OneD, NekDouble>(pFields[n]->GetNcoeffs(),0.0);
}
m_avgFieldMetaData["InitialTime"] = boost::lexical_cast<std::string>(time);
}
void FilterAverageFields::v_Update(const Array<OneD, const MultiRegions::ExpListSharedPtr> &pFields, const NekDouble &time)
{
m_index++;
if (m_index % m_outputFrequency > 0)
{
return;
}
for(int n = 0; n < pFields.num_elements(); ++n)
{
Vmath::Vadd(m_avgFields[n].num_elements(),
pFields[n]->GetCoeffs(),1,m_avgFields[n],1,
m_avgFields[n],1);
}
m_numAverages += 1;
// update FinalTime here since this is when last field will be added.
m_avgFieldMetaData["FinalTime"] = boost::lexical_cast<std::string>(time);
}
void FilterAverageFields::v_Finalise(const Array<OneD, const MultiRegions::ExpListSharedPtr> &pFields, const NekDouble &time)
{
for(int n = 0; n < m_avgFields.num_elements(); ++n)
{
Vmath::Smul(m_avgFields[n].num_elements(), 1.0/m_numAverages,m_avgFields[n],1,m_avgFields[n],1);
}
std::vector<LibUtilities::FieldDefinitionsSharedPtr> FieldDef
= pFields[0]->GetFieldDefinitions();
std::vector<std::vector<NekDouble> > FieldData(FieldDef.size());
Array<OneD, NekDouble> fieldcoeffs;
int ncoeffs = pFields[0]->GetNcoeffs();
// copy Data into FieldData and set variable
for(int j = 0; j < pFields.num_elements(); ++j)
{
// check to see if field is same order a zeroth field
if(m_avgFields[j].num_elements() == ncoeffs)
{
fieldcoeffs = m_avgFields[j];
}
else
{
fieldcoeffs = Array<OneD,NekDouble>(ncoeffs);
pFields[0]->ExtractCoeffsToCoeffs(pFields[j],m_avgFields[j],fieldcoeffs);
}
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], fieldcoeffs);
}
}
m_avgFieldMetaData["NumberOfFieldDumps"] = boost::lexical_cast<std::string>(m_numAverages);
m_fld->Write(m_outputFile,FieldDef,FieldData,m_avgFieldMetaData);
}
bool FilterAverageFields::v_IsTimeDependent()
{
return true;
}
}
}
///////////////////////////////////////////////////////////////////////////////
//
// File FilterAverageFields.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: Average solution fields during time-stepping.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef NEKTAR_SOLVERUTILS_FILTERS_FILTERAVERAGEFIELDS_H
#define NEKTAR_SOLVERUTILS_FILTERS_FILTERAVERAGEFIELDS_H
#include <SolverUtils/Filters/Filter.h>
namespace Nektar
{
namespace SolverUtils
{
class FilterAverageFields : public Filter
{
public:
friend class MemoryManager<FilterAverageFields>;
/// Creates an instance of this class
static FilterSharedPtr create(
const LibUtilities::SessionReaderSharedPtr &pSession,
const std::map<std::string, std::string> &pParams) {
FilterSharedPtr p = MemoryManager<FilterAverageFields>::AllocateSharedPtr(pSession, pParams);
return p;
}
///Name of the class
static std::string className;
SOLVER_UTILS_EXPORT FilterAverageFields(
const LibUtilities::SessionReaderSharedPtr &pSession,
const std::map<std::string, std::string> &pParams);
SOLVER_UTILS_EXPORT ~FilterAverageFields();
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_numAverages;
unsigned int m_outputFrequency;
unsigned int m_index;
std::string m_outputFile;
LibUtilities::FieldIOSharedPtr m_fld;
LibUtilities::FieldMetaDataMap m_avgFieldMetaData;
Array<OneD, Array<OneD, NekDouble> > m_avgFields;
};
}
}
#endif /* NEKTAR_SOLVERUTILS_FILTERS_FILTERCHECKPOINT_H */
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