Commit ecf1a048 authored by Dave Moxey's avatar Dave Moxey

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
......
This diff is collapsed.
......@@ -33,78 +33,80 @@
//
///////////////////////////////////////////////////////////////////////////////
#ifndef NEKTAR_SOLVERS_DRIVERARNOLDI_H
#define NEKTAR_SOLVERS_DRIVERARNOLDI_H
#ifndef NEKTAR_SOLVERUTILS_DRIVERARNOLDI_H
#define NEKTAR_SOLVERUTILS_DRIVERARNOLDI_H
#include <Auxiliary/Driver.h>
#include <SolverUtils/Driver.h>
namespace Nektar
{
/// Base class for the development of solvers.
class DriverArnoldi: public Driver
namespace SolverUtils
{
public:
friend class MemoryManager<DriverArnoldi>;
/// Base class for the development of solvers.
class DriverArnoldi: public Driver
{
public:
friend class MemoryManager<DriverArnoldi>;
void ArnoldiSummary(std::ostream &out);
protected:
int m_kdim; /// Dimension of Krylov subspace
int m_nvec; /// Number of vectors to test
int m_nits; /// Maxmum number of iterations
NekDouble m_evtol;/// Tolerance of iteratiosn
NekDouble m_period;/// Period of time stepping algorithm
bool m_timeSteppingAlgorithm; /// underlying operator is time stepping
SOLVER_UTILS_EXPORT void ArnoldiSummary(std::ostream &out);
protected:
int m_kdim; /// Dimension of Krylov subspace
int m_nvec; /// Number of vectors to test
int m_nits; /// Maxmum number of iterations
NekDouble m_evtol;/// Tolerance of iteratiosn
NekDouble m_period;/// Period of time stepping algorithm
bool m_timeSteppingAlgorithm; /// underlying operator is time stepping
int m_infosteps; /// interval to dump information if required.
int m_infosteps; /// interval to dump information if required.
int m_nfields;
NekDouble m_realShift;
NekDouble m_imagShift;
int m_nfields;
NekDouble m_realShift;
NekDouble m_imagShift;
Array<OneD, NekDouble> m_real_evl;
Array<OneD, NekDouble> m_imag_evl;
Array<OneD, NekDouble> m_real_evl;
Array<OneD, NekDouble> m_imag_evl;
/// Constructor
DriverArnoldi(const LibUtilities::SessionReaderSharedPtr pSession);
/// Constructor
DriverArnoldi(const LibUtilities::SessionReaderSharedPtr pSession);
/// Destructor
virtual ~DriverArnoldi();
/// Destructor
virtual ~DriverArnoldi();
/// Copy Arnoldi storage to fields.
void CopyArnoldiArrayToField(Array<OneD, NekDouble> &array);
/// Copy Arnoldi storage to fields.
void CopyArnoldiArrayToField(Array<OneD, NekDouble> &array);
/// Copy fields to Arnoldi storage.
void CopyFieldToArnoldiArray(Array<OneD, NekDouble> &array);
/// Copy fields to Arnoldi storage.
void CopyFieldToArnoldiArray(Array<OneD, NekDouble> &array);
///Copy the forward field to the adjoint system in transient growth calculations
void CopyFwdToAdj();
///Copy the forward field to the adjoint system in transient growth calculations
void CopyFwdToAdj();
// write coefficients to file.
void WriteFld(std::string file, Array<OneD, Array<OneD, NekDouble> > coeffs);
// write coefficients to file.
void WriteFld(std::string file, Array<OneD, Array<OneD, NekDouble> > coeffs);
void WriteFld(std::string file, Array<OneD, NekDouble> coeffs);
void WriteFld(std::string file, Array<OneD, NekDouble> coeffs);
void WriteEvs(ostream &evlout, const int k,
const NekDouble real, const NekDouble imag,
NekDouble resid = NekConstants::kNekUnsetDouble);
void WriteEvs(ostream &evlout, const int k,
const NekDouble real, const NekDouble imag,
NekDouble resid = NekConstants::kNekUnsetDouble);
virtual void v_InitObject(ostream &out = cout);
virtual void v_InitObject(ostream &out = cout);
virtual Array<OneD, NekDouble> v_GetRealEvl(void)
{
return m_real_evl;
}
virtual Array<OneD, NekDouble> v_GetRealEvl(void)
{
return m_real_evl;
}
virtual Array<OneD, NekDouble> v_GetImagEvl(void)
{
return m_imag_evl;
}
virtual Array<OneD, NekDouble> v_GetImagEvl(void)
{
return m_imag_evl;
}
};
};
}
} //end of namespace
#endif //NEKTAR_SOLVERS_DRIVER_ARNOLDI_H
#endif //NEKTAR_SOLVERUTILS_DRIVERARNOLDI_H
This diff is collapsed.
......@@ -33,61 +33,63 @@
//
///////////////////////////////////////////////////////////////////////////////
#ifndef NEKTAR_SOLVERS_DRIVERARPACK_H
#define NEKTAR_SOLVERS_DRIVERARPACK_H
#ifndef NEKTAR_SOLVERUTILS_DRIVERARPACK_H
#define NEKTAR_SOLVERUTILS_DRIVERARPACK_H
#include <LibUtilities/LinearAlgebra/Arpack.hpp>
#include <Auxiliary/DriverArnoldi.h>
#include <SolverUtils/DriverArnoldi.h>
namespace Nektar
{
/// Base class for the development of solvers.
class DriverArpack: public DriverArnoldi
namespace SolverUtils
{
public:
friend class MemoryManager<DriverArpack>;
/// Base class for the development of solvers.
class DriverArpack: public DriverArnoldi
{
public:
friend class MemoryManager<DriverArpack>;
/// Creates an instance of this class
static DriverSharedPtr create(const LibUtilities::SessionReaderSharedPtr& pSession) {
DriverSharedPtr p = MemoryManager<DriverArpack>::AllocateSharedPtr(pSession);
p->InitObject();
return p;
}
/// Creates an instance of this class
static DriverSharedPtr create(const LibUtilities::SessionReaderSharedPtr& pSession) {
DriverSharedPtr p = MemoryManager<DriverArpack>::AllocateSharedPtr(pSession);
p->InitObject();
return p;
}
///Name of the class