Commit ecf1a048 authored by Dave Moxey's avatar Dave Moxey
Browse files

Moved solvers/Auxiliary to a new library, SolverUtils.

git-svn-id: https://gforge.sci.utah.edu/svn/nektar/trunk@3840 305cdda6-5ce1-45b3-a98d-dfc68c8b3305
parent 8faae8fd
......@@ -232,7 +232,7 @@ ENDIF( NEKTAR_USE_PRECOMPILED_HEADERS )
# Build active components
IF (NEKTAR_BUILD_LIBRARY)
SET(NEKTAR++_LIBRARIES LibUtilities StdRegions SpatialDomains LocalRegions
SET(NEKTAR++_LIBRARIES SolverUtils LibUtilities StdRegions SpatialDomains LocalRegions
MultiRegions)
INCLUDE_DIRECTORIES(library)
ADD_SUBDIRECTORY(library)
......
......@@ -145,7 +145,7 @@ IF(NEKTAR_RELEASE_WITH_DEBUG_INFO_LIBRARIES)
INCLUDE(${NEKTAR_RELEASE_WITH_DEBUG_INFO_LIBRARIES})
ENDIF(NEKTAR_RELEASE_WITH_DEBUG_INFO_LIBRARIES)
SET(NEKTAR++_LIBRARIES MultiRegions LocalRegions SpatialDomains StdRegions LibUtilities)
SET(NEKTAR++_LIBRARIES SolverUtils MultiRegions LocalRegions SpatialDomains StdRegions LibUtilities)
MARK_AS_ADVANCED(NEKTAR_RELEASE_LIBRARIES)
MARK_AS_ADVANCED(NEKTAR_DEBUG_LIBRARIES)
......
SET(LibrarySubDirs LibUtilities LocalRegions MultiRegions SpatialDomains
StdRegions)
StdRegions SolverUtils)
SET(UnitTestSubDirs UnitTests)
SET(DemoSubDirs Demos)
SET(TimingsSubDirs Timings)
......
SET(SOLVER_UTILS_SOURCES
Driver.cpp
DriverArnoldi.cpp
DriverModifiedArnoldi.cpp
DriverStandard.cpp
EquationSystem.cpp
Filters/Filter.cpp
Filters/FilterCheckpoint.cpp
Filters/FilterHistoryPoints.cpp
Filters/FilterThresholdMax.cpp
UnsteadySystem.cpp
)
SET(SOLVER_UTILS_HEADERS
Driver.h
DriverArnoldi.h
DriverModifiedArnoldi.h
DriverStandard.h
EquationSystem.h
Filters/Filter.h
Filters/FilterCheckpoint.h
Filters/FilterHistoryPoints.h
Filters/FilterThresholdMax.h
SolverUtils.hpp
UnsteadySystem.h
)
IF (NEKTAR_USE_ARPACK)
SET(SOLVER_UTILS_SOURCES ${SOLVER_UTILS_SOURCES}
DriverArpack.cpp)
SET(SOLVER_UTILS_HEADERS ${SOLVER_UTILS_HEADERS}
DriverArpack.h)
ENDIF (NEKTAR_USE_ARPACK)
ADD_DEFINITIONS(-DSOLVER_UTILS_EXPORT)
ADD_NEKTAR_LIBRARY(SolverUtils lib ${NEKTAR_LIBRARY_TYPE} ${SOLVER_UTILS_SOURCES} ${SOLVER_UTILS_HEADERS})
TARGET_LINK_LIBRARIES(SolverUtils
optimized LibUtilities debug LibUtilities-g
optimized SpatialDomains debug SpatialDomains-g
optimized StdRegions debug StdRegions-g
optimized MultiRegions debug MultiRegions-g
optimized LocalRegions debug LocalRegions-g
optimized ${TINYXML_LIB} debug ${TINYXML_LIB}
${Boost_THREAD_LIBRARY}
${Boost_DATE_TIME_LIBRARY}
)
SET_LAPACK_LINK_LIBRARIES(SolverUtils)
INSTALL(FILES ${SOLVER_UTILS_HEADERS} DESTINATION ${NEKTAR_INCLUDE_DIR}/SolverUtils COMPONENT dev)
......@@ -33,123 +33,124 @@
//
///////////////////////////////////////////////////////////////////////////////
#include <Auxiliary/Driver.h>
#include <SolverUtils/Driver.h>
namespace Nektar
{
std::string Driver::evolutionOperatorLookupIds[5] = {
namespace SolverUtils
{
std::string Driver::evolutionOperatorLookupIds[5] = {
LibUtilities::SessionReader::RegisterEnumValue("EvolutionOperator","Nonlinear" ,eNonlinear),
LibUtilities::SessionReader::RegisterEnumValue("EvolutionOperator","Direct" ,eDirect),
LibUtilities::SessionReader::RegisterEnumValue("EvolutionOperator","Adjoint" ,eAdjoint),
LibUtilities::SessionReader::RegisterEnumValue("EvolutionOperator","TransientGrowth",eTransientGrowth),
LibUtilities::SessionReader::RegisterEnumValue("EvolutionOperator","SkewSymmetric",eSkewSymmetric)
};
std::string Driver::evolutionOperatorDef = LibUtilities::SessionReader::RegisterDefaultSolverInfo("EvolutionOperator","Nonlinear");
std::string Driver::driverDefault = LibUtilities::SessionReader::RegisterDefaultSolverInfo("Driver","Standard");
LibUtilities::SessionReader::RegisterEnumValue("EvolutionOperator","SkewSymmetric",eSkewSymmetric)
};
std::string Driver::evolutionOperatorDef = LibUtilities::SessionReader::RegisterDefaultSolverInfo("EvolutionOperator","Nonlinear");
std::string Driver::driverDefault = LibUtilities::SessionReader::RegisterDefaultSolverInfo("Driver","Standard");
DriverFactory& GetDriverFactory()
{
typedef Loki::SingletonHolder<DriverFactory,
Loki::CreateUsingNew,
Loki::NoDestroy > Type;
return Type::Instance();
}
{
typedef Loki::SingletonHolder<DriverFactory,
Loki::CreateUsingNew,
Loki::NoDestroy > Type;
return Type::Instance();
}
/**
*
*/
Driver::Driver(const LibUtilities::SessionReaderSharedPtr pSession)
: m_comm(pSession->GetComm()),
m_session(pSession)
{
}
/**
*
*/
Driver::Driver(const LibUtilities::SessionReaderSharedPtr pSession)
: m_comm(pSession->GetComm()),
m_session(pSession)
{
}
Driver::~Driver()
Driver::~Driver()
{
}
{
}
/**
*
*/
void Driver::v_InitObject(ostream &out)
{
try
/**
*
*/
void Driver::v_InitObject(ostream &out)
{
// Retrieve the equation system to solve.
ASSERTL0(m_session->DefinesSolverInfo("EqType"),
"EqType SolverInfo tag must be defined.");
std::string vEquation = m_session->GetSolverInfo("EqType");
if (m_session->DefinesSolverInfo("SolverType"))
try
{
vEquation = m_session->GetSolverInfo("SolverType");
}
// Retrieve the equation system to solve.
ASSERTL0(m_session->DefinesSolverInfo("EqType"),
"EqType SolverInfo tag must be defined.");
std::string vEquation = m_session->GetSolverInfo("EqType");
if (m_session->DefinesSolverInfo("SolverType"))
{
vEquation = m_session->GetSolverInfo("SolverType");
}
// Check such a module exists for this equation.
ASSERTL0(GetEquationSystemFactory().ModuleExists(vEquation),
"EquationSystem '" + vEquation + "' is not defined.\n"
"Ensure equation name is correct and module is compiled.\n");
// Check such a module exists for this equation.
ASSERTL0(GetEquationSystemFactory().ModuleExists(vEquation),
"EquationSystem '" + vEquation + "' is not defined.\n"
"Ensure equation name is correct and module is compiled.\n");
// Retrieve the type of evolution operator to use
/// @todo At the moment this is Navier-Stokes specific - generalise?
m_EvolutionOperator = m_session->GetSolverInfoAsEnum<EvolutionOperatorType>("EvolutionOperator");
// Retrieve the type of evolution operator to use
/// @todo At the moment this is Navier-Stokes specific - generalise?
m_EvolutionOperator = m_session->GetSolverInfoAsEnum<EvolutionOperatorType>("EvolutionOperator");
m_nequ = (m_EvolutionOperator == eTransientGrowth ? 2 : 1);
m_equ = Array<OneD, EquationSystemSharedPtr>(m_nequ);
m_nequ = (m_EvolutionOperator == eTransientGrowth ? 2 : 1);
m_equ = Array<OneD, EquationSystemSharedPtr>(m_nequ);
// Set the AdvectiveType tag and create EquationSystem objects.
switch (m_EvolutionOperator)
{
case eNonlinear:
m_session->SetTag("AdvectiveType","Convective");
m_equ[0] = GetEquationSystemFactory().CreateInstance(vEquation, m_session);
break;
case eDirect:
m_session->SetTag("AdvectiveType","Linearised");
m_equ[0] = GetEquationSystemFactory().CreateInstance(vEquation, m_session);
break;
case eAdjoint:
m_session->SetTag("AdvectiveType","Adjoint");
m_equ[0] = GetEquationSystemFactory().CreateInstance(vEquation, m_session);
break;
case eTransientGrowth:
//forward timestepping
m_session->SetTag("AdvectiveType","Linearised");
m_equ[0] = GetEquationSystemFactory().CreateInstance(vEquation, m_session);
// Set the AdvectiveType tag and create EquationSystem objects.
switch (m_EvolutionOperator)
{
case eNonlinear:
m_session->SetTag("AdvectiveType","Convective");
m_equ[0] = GetEquationSystemFactory().CreateInstance(vEquation, m_session);
break;
case eDirect:
m_session->SetTag("AdvectiveType","Linearised");
m_equ[0] = GetEquationSystemFactory().CreateInstance(vEquation, m_session);
break;
case eAdjoint:
m_session->SetTag("AdvectiveType","Adjoint");
m_equ[0] = GetEquationSystemFactory().CreateInstance(vEquation, m_session);
break;
case eTransientGrowth:
//forward timestepping
m_session->SetTag("AdvectiveType","Linearised");
m_equ[0] = GetEquationSystemFactory().CreateInstance(vEquation, m_session);
//backward timestepping
m_session->SetTag("AdvectiveType","Adjoint");
m_equ[1] = GetEquationSystemFactory().CreateInstance(vEquation, m_session);
break;
case eSkewSymmetric:
m_session->SetTag("AdvectiveType","SkewSymmetric");
m_equ[0] = GetEquationSystemFactory().CreateInstance(vEquation, m_session);
break;
default:
ASSERTL0(false, "Unrecognised evolution operator.");
//backward timestepping
m_session->SetTag("AdvectiveType","Adjoint");
m_equ[1] = GetEquationSystemFactory().CreateInstance(vEquation, m_session);
break;
case eSkewSymmetric:
m_session->SetTag("AdvectiveType","SkewSymmetric");
m_equ[0] = GetEquationSystemFactory().CreateInstance(vEquation, m_session);
break;
default:
ASSERTL0(false, "Unrecognised evolution operator.");
}
}
catch (int e)
{
ASSERTL0(e == -1, "No such class class defined.");
out << "An error occurred during driver initialisation." << endl;
}
}
catch (int e)
Array<OneD, NekDouble> Driver::v_GetRealEvl(void)
{
ASSERTL0(e == -1, "No such class class defined.");
out << "An error occurred during driver initialisation." << endl;
ASSERTL0(false,"This routine is not valid in this class");
return NullNekDouble1DArray;
}
}
Array<OneD, NekDouble> Driver::v_GetRealEvl(void)
{
ASSERTL0(false,"This routine is not valid in this class");
return NullNekDouble1DArray;
}
Array<OneD, NekDouble> Driver::v_GetImagEvl(void)
{
ASSERTL0(false,"This routine is not valid in this class");
return NullNekDouble1DArray;
}
Array<OneD, NekDouble> Driver::v_GetImagEvl(void)
{
ASSERTL0(false,"This routine is not valid in this class");
return NullNekDouble1DArray;
}
}
}
......@@ -33,121 +33,113 @@
//
///////////////////////////////////////////////////////////////////////////////
#ifndef NEKTAR_SOLVERS_DRIVER_H
#define NEKTAR_SOLVERS_DRIVER_H
#ifndef SOLVERUTILS_DRIVER_H
#define SOLVERUTILS_DRIVER_H
#include <LibUtilities/Communication/Comm.h>
#include <LibUtilities/BasicUtils/SessionReader.h>
#include <LibUtilities/BasicUtils/NekFactory.hpp>
#include <LibUtilities/BasicUtils/SharedArray.hpp>
#include <Auxiliary/EquationSystem.h>
#include <SolverUtils/SolverUtils.hpp>
#include <SolverUtils/EquationSystem.h>
namespace Nektar
{
class Driver;
/// A shared pointer to a Driver object
typedef boost::shared_ptr<Driver> DriverSharedPtr;
namespace SolverUtils
{
class Driver;
/// Datatype of the NekFactory used to instantiate classes derived from
/// the Driver class.
typedef LibUtilities::NekFactory<
std::string, Driver,
const LibUtilities::SessionReaderSharedPtr&
/// A shared pointer to a Driver object
typedef boost::shared_ptr<Driver> DriverSharedPtr;
/// Datatype of the NekFactory used to instantiate classes derived from
/// the Driver class.
typedef LibUtilities::NekFactory<
std::string, Driver,
const LibUtilities::SessionReaderSharedPtr&
> DriverFactory;
DriverFactory& GetDriverFactory();
enum EvolutionOperatorType
{
eNonlinear,
eDirect,
eAdjoint,
eTransientGrowth,
eSkewSymmetric
};
/// Base class for the development of solvers.
class Driver
{
public:
/// Destructor
virtual ~Driver();
DriverFactory& GetDriverFactory();
/// Base class for the development of solvers.
class Driver
{
public:
/// Destructor
virtual ~Driver();
/// Initialise Object
inline void InitObject(ostream &out = cout);
/// Initialise Object
SOLVER_UTILS_EXPORT inline void InitObject(ostream &out = cout);
/// Execute driver
inline void Execute(ostream &out = cout);
/// Execute driver
SOLVER_UTILS_EXPORT inline void Execute(ostream &out = cout);
inline Array<OneD, EquationSystemSharedPtr> GetEqu();
SOLVER_UTILS_EXPORT inline Array<OneD, EquationSystemSharedPtr> GetEqu();
Array<OneD, NekDouble> GetRealEvl(void);
Array<OneD, NekDouble> GetImagEvl(void);
SOLVER_UTILS_EXPORT Array<OneD, NekDouble> GetRealEvl(void);
SOLVER_UTILS_EXPORT Array<OneD, NekDouble> GetImagEvl(void);
protected:
/// Communication object
LibUtilities::CommSharedPtr m_comm;
protected:
/// Communication object
LibUtilities::CommSharedPtr m_comm;
/// Session reader object
LibUtilities::SessionReaderSharedPtr m_session;
/// Session reader object
LibUtilities::SessionReaderSharedPtr m_session;
/// Equation system to solve
Array<OneD, EquationSystemSharedPtr> m_equ;
/// Equation system to solve
Array<OneD, EquationSystemSharedPtr> m_equ;
///number of equations
int m_nequ;
///number of equations
int m_nequ;
///Evolution Operator
enum EvolutionOperatorType m_EvolutionOperator;
///Evolution Operator
enum EvolutionOperatorType m_EvolutionOperator;
/// Initialises EquationSystem class members.
Driver(const LibUtilities::SessionReaderSharedPtr pSession);
/// Initialises EquationSystem class members.
Driver(const LibUtilities::SessionReaderSharedPtr pSession);
virtual void v_InitObject(ostream &out = cout);
virtual void v_InitObject(ostream &out = cout);
/// Virtual function for solve implementation.
virtual void v_Execute(ostream &out = cout) = 0;
/// Virtual function for solve implementation.
virtual void v_Execute(ostream &out = cout) = 0;
virtual Array<OneD, NekDouble> v_GetRealEvl(void);
virtual Array<OneD, NekDouble> v_GetImagEvl(void);
virtual Array<OneD, NekDouble> v_GetRealEvl(void);
virtual Array<OneD, NekDouble> v_GetImagEvl(void);
static std::string evolutionOperatorLookupIds[];
static std::string evolutionOperatorDef;
static std::string driverDefault;
static std::string evolutionOperatorLookupIds[];
static std::string evolutionOperatorDef;
static std::string driverDefault;
};
};
inline void Driver::InitObject(ostream &out)
{
v_InitObject(out);
}
inline void Driver::InitObject(ostream &out)
{
v_InitObject(out);
}
inline void Driver::Execute(ostream &out)
{
v_Execute(out);
}
inline Array<OneD, EquationSystemSharedPtr> Driver::GetEqu()
{
return m_equ;
}
inline void Driver::Execute(ostream &out)
{
v_Execute(out);
}
inline Array<OneD, EquationSystemSharedPtr> Driver::GetEqu()
{
return m_equ;
}
inline Array<OneD, NekDouble> Driver::GetRealEvl()
{
return v_GetRealEvl();
}
inline Array<OneD, NekDouble> Driver::GetRealEvl()
{
return v_GetRealEvl();
}
inline Array<OneD, NekDouble> Driver::GetImagEvl()
{
return v_GetImagEvl();
inline Array<OneD, NekDouble> Driver::GetImagEvl()
{
return v_GetImagEvl();
}
}
} //end of namespace
#endif //NEKTAR_SOLVERS_AUXILIARY_ADRBASE_H
......
///////////////////////////////////////////////////////////////////////////////
//
// File DriverArnoldi.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 Driver class for the stability solver
//
///////////////////////////////////////////////////////////////////////////////
#include <iomanip>
#include <SolverUtils/DriverArnoldi.h>
namespace Nektar
{
namespace SolverUtils
{
/**
*
*/
DriverArnoldi::DriverArnoldi(const LibUtilities::SessionReaderSharedPtr pSession)
: Driver(pSession)
{
m_session->LoadParameter("IO_InfoSteps", m_infosteps, 1);
};
/**
*
*/
DriverArnoldi::~DriverArnoldi()
{
};
/**
*
*/
void DriverArnoldi::v_InitObject(ostream &out)
{
Driver::v_InitObject(out);
m_session->MatchSolverInfo("SolverType","VelocityCorrectionScheme",m_timeSteppingAlgorithm, false);
if(m_timeSteppingAlgorithm)
{
m_period = m_session->GetParameter("TimeStep")* m_session->GetParameter("NumSteps");
m_nfields = m_equ[0]->UpdateFields().num_elements() - 1;
if(m_session->DefinesSolverInfo("SingleMode") && m_session->GetSolverInfo("SingleMode")=="ModifiedBasis")
{
for(int i = 0; i < m_nfields; ++i)
{
m_equ[0]->UpdateFields()[i]->SetWaveSpace(true);
}
}
}
else
{
m_period = 1.0;
ASSERTL0(m_session->DefinesFunction("BodyForce"),"A BodyForce section needs to be defined for this solver type");
m_nfields = m_equ[0]->UpdateFields().num_elements();
for(int i = 0; i < m_nfields; ++i)
{
m_equ[0]->UpdateForces()[i]->SetWaveSpace(true);
}
}
/*
if(m_session->DefinesSolverInfo("SingleMode")==false)
{
for(int i = 0; i < m_nfields; ++i)
{
m_equ[0]->UpdateFields()[i]->SetWaveSpace(true);
}
}*/
m_session->LoadParameter("kdim", m_kdim, 16);
m_session->LoadParameter("nvec", m_nvec, 2);
m_session->LoadParameter("nits", m_nits, 500);
m_session->LoadParameter("evtol", m_evtol, 1e-06);
m_session->LoadParameter("realShift", m_realShift, 0.0);
m_equ[0]->SetLambda(m_realShift);
m_session->LoadParameter("imagShift", m_imagShift, 0.0);