changed: move files out of Stokes folder
they can be (and are) used for other apps git-svn-id: http://svn.sintef.no/trondheim/IFEM/trunk@2066 e10b68d5-8a6e-419e-a041-bce267b0401d
This commit is contained in:
50
Apps/Common/CMakeLists.txt
Normal file
50
Apps/Common/CMakeLists.txt
Normal file
@@ -0,0 +1,50 @@
|
||||
PROJECT(CommonIFEM)
|
||||
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
|
||||
|
||||
IF (NOT IFEM_CONFIGURED)
|
||||
# Required defines
|
||||
SET(CMAKE_CXX_FLAGS "-DReal=double -DPROFILE_LEVEL=3")
|
||||
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DINDEX_CHECK=2")
|
||||
IF(VERBOSE_DEBUG GREATER 0)
|
||||
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DINT_DEBUG=${VERBOSE_DEBUG}")
|
||||
ENDIF(VERBOSE_DEBUG GREATER 0)
|
||||
|
||||
IF(NOT CMAKE_BUILD_TYPE)
|
||||
SET(CMAKE_BUILD_TYPE Release)
|
||||
ENDIF(NOT CMAKE_BUILD_TYPE)
|
||||
|
||||
IF(NOT IFEM_BUILD_TYPE)
|
||||
SET(IFEM_BUILD_TYPE ${CMAKE_BUILD_TYPE})
|
||||
ENDIF(NOT IFEM_BUILD_TYPE)
|
||||
IF(${CMAKE_BUILD_TYPE} MATCHES "Release-MPI")
|
||||
SET(CMAKE_BUILD_TYPE Release)
|
||||
ELSEIF(${CMAKE_BUILD_TYPE} MATCHES "Debug-MPI")
|
||||
SET(CMAKE_BUILD_TYPE Debug)
|
||||
ELSEIF(${CMAKE_BUILD_TYPE} MATCHES "Nopt")
|
||||
SET(CMAKE_BUILD_TYPE Debug)
|
||||
ENDIF(${CMAKE_BUILD_TYPE} MATCHES "Release-MPI")
|
||||
|
||||
# Add local modules
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
|
||||
${PROJECT_SOURCE_DIR}/../../cmake/Modules
|
||||
$ENV{HOME}/cmake/Modules)
|
||||
|
||||
# Required packages
|
||||
FIND_PACKAGE(IFEM REQUIRED)
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${IFEM_CXX_FLAGS}")
|
||||
INCLUDE_DIRECTORIES(${IFEM_INCLUDES})
|
||||
|
||||
IF(NOT WIN32)
|
||||
# Emit position-independent code, suitable for dynamic linking
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
|
||||
# Enable all warnings
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
|
||||
ENDIF(NOT WIN32)
|
||||
ENDIF(NOT IFEM_CONFIGURED)
|
||||
|
||||
SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
|
||||
|
||||
# Common Navier-Stokes application sources
|
||||
ADD_LIBRARY(CommonIFEM STATIC
|
||||
StabilizationUtils.C)
|
||||
43
Apps/Common/ISolver.h
Normal file
43
Apps/Common/ISolver.h
Normal file
@@ -0,0 +1,43 @@
|
||||
//==============================================================================
|
||||
//!
|
||||
//! \file ISolver.h
|
||||
//!
|
||||
//! \date Oct 14 2012
|
||||
//!
|
||||
//! \author Arne Morten Kvarving / SINTEF
|
||||
//!
|
||||
//! \brief Abstract simulation solver interface
|
||||
//!
|
||||
//==============================================================================
|
||||
|
||||
#include "TimeStep.h"
|
||||
|
||||
|
||||
/*!
|
||||
\brief Abstract solver interface. To be realized through the SIMSolver template
|
||||
*/
|
||||
class ISolver {
|
||||
public:
|
||||
//! \brief Opens a new VTF-file and writes the model geometry to it.
|
||||
//! \param[in] fileName File name used to construct the VTF-file name from
|
||||
virtual bool saveModel(char* fileName, int& nBlock) = 0;
|
||||
|
||||
//! \brief Saves the converged results to VTF file of a given time step.
|
||||
//! \param[in] iStep Time step identifier
|
||||
//! \param[in] time Current time step info
|
||||
//! \param[in] nBlock Running VTF block counter
|
||||
virtual bool saveStep(const TimeStep& tp, int& nBlock) = 0;
|
||||
|
||||
//! \brief Advances the time step one step forward.
|
||||
//! \param[in] tp Time step structure to advance
|
||||
//! \return True if new solution step is to be performed
|
||||
virtual bool advanceStep(TimeStep& tp) = 0;
|
||||
|
||||
//! \brief Computes the solution for the current time step.
|
||||
//! \param[in] tp Time step structure to advance
|
||||
//! \return True on success
|
||||
virtual bool solveStep(TimeStep& tp) = 0;
|
||||
|
||||
//! \brief Returns a const reference to the time stepping parameters.
|
||||
const TimeStep& getTimePrm() const = 0;
|
||||
};
|
||||
101
Apps/Common/SIMCoupled.h
Normal file
101
Apps/Common/SIMCoupled.h
Normal file
@@ -0,0 +1,101 @@
|
||||
//==============================================================================
|
||||
//!
|
||||
//! \file SIMCoupled.h
|
||||
//!
|
||||
//! \date Oct 12 2012
|
||||
//!
|
||||
//! \author Arne Morten Kvarving / SINTEF
|
||||
//!
|
||||
//! \brief Coupled SIM class template
|
||||
//==============================================================================
|
||||
#ifndef SIM_COUPLED_H_
|
||||
#define SIM_COUPLED_H_
|
||||
|
||||
template<class T1, class T2>
|
||||
class SIMCoupled
|
||||
{
|
||||
public:
|
||||
//! \brief Constructor
|
||||
//! \param[in] s1 Reference to spline FE model for the first simulator
|
||||
//! \param[in] s2 Reference to spline FE model for the second simulator
|
||||
SIMCoupled(T1& s1, T2& s2) : S1(s1), S2(s2)
|
||||
{
|
||||
}
|
||||
|
||||
//! \brief Destructor
|
||||
virtual ~SIMCoupled()
|
||||
{
|
||||
}
|
||||
|
||||
//! \brief Sets up field dependencies.
|
||||
virtual void setupDependencies() = 0;
|
||||
|
||||
//! \brief Advances the time step one step forward.
|
||||
virtual bool advanceStep(TimeStep& tp)
|
||||
{
|
||||
return S2.advanceStep(tp) && S1.advanceStep(tp);
|
||||
}
|
||||
|
||||
//! \brief Computes the solution for the current time step.
|
||||
virtual bool solveStep(TimeStep& tp)
|
||||
{
|
||||
return S1.solveStep(tp) && S2.solveStep(tp);
|
||||
}
|
||||
|
||||
//! \brief Saves the converged results to VTF-file of a given time step.
|
||||
//! \param[in] tp Time step identifier
|
||||
virtual bool saveStep(const TimeStep& tp, int& nBlock)
|
||||
{
|
||||
return S2.saveStep(tp, nBlock) &&
|
||||
S1.saveStep(tp, nBlock);
|
||||
}
|
||||
|
||||
//! \brief Opens a new VTF-file and writes the model geometry to it.
|
||||
//! \param[in] fileName File name used to construct the VTF-file name from
|
||||
virtual bool saveModel(char* fileName, int& nBlock)
|
||||
{
|
||||
if (!S1.saveModel(fileName, nBlock))
|
||||
return false;
|
||||
|
||||
S2.setVTF(S1.getVTF());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//! \brief Returns a const reference to the time stepping parameters.
|
||||
const TimeStep& getTimePrm() const
|
||||
{
|
||||
return S1.getTimePrm();
|
||||
}
|
||||
|
||||
//! \brief Registers a dependency on a field from another SIM object.
|
||||
//! \param[in] sim The SIM object holding the field we depend on
|
||||
//! \param[in] name Name of field we depend on
|
||||
//! \param[in] nvc Number of components in field
|
||||
//! \param[in] patches The geometry the field is defined over
|
||||
//! \param[in] diffBasis Different basis for the SIM class and the field
|
||||
virtual void registerDependency(SIMdependency* sim, const std::string& name,
|
||||
short int nvc,
|
||||
const SIMdependency::PatchVec& patches,
|
||||
bool diffBasis = false)
|
||||
{
|
||||
S1.registerDependency(sim, name, nvc, patches, diffBasis);
|
||||
S2.registerDependency(sim, name, nvc, patches, diffBasis);
|
||||
}
|
||||
//! \brief Registers a dependency on a field from another SIM object.
|
||||
//! \param[in] sim The SIM object holding the field we depend on
|
||||
//! \param[in] name Name of field we depend on
|
||||
//! \param[in] nvc Number of components in field
|
||||
void registerDependency(SIMdependency* sim, const std::string& name,
|
||||
short int nvc = 1)
|
||||
{
|
||||
S1.registerDependency(sim, name, nvc);
|
||||
S2.registerDependency(sim, name, nvc);
|
||||
}
|
||||
|
||||
protected:
|
||||
T1& S1; //!< First substep
|
||||
T2& S2; //!< Second substep
|
||||
};
|
||||
|
||||
#endif
|
||||
69
Apps/Common/SIMSolver.h
Normal file
69
Apps/Common/SIMSolver.h
Normal file
@@ -0,0 +1,69 @@
|
||||
//==============================================================================
|
||||
//!
|
||||
//! \file SIMSolver.h
|
||||
//!
|
||||
//! \date Oct 12 2012
|
||||
//!
|
||||
//! \author Arne Morten Kvarving / SINTEF
|
||||
//!
|
||||
//! \brief SIM solver class template
|
||||
//==============================================================================
|
||||
#ifndef SIM_SOLVER_H_
|
||||
#define SIM_SOLVER_H_
|
||||
|
||||
#include "DataExporter.h"
|
||||
#include "TimeStep.h"
|
||||
|
||||
/*!
|
||||
\brief Solver interface. This template can be instanced over any type
|
||||
implementing the ISolver interface. It provides a time stepping
|
||||
loop with data output.
|
||||
*/
|
||||
template<class T1>
|
||||
class SIMSolver
|
||||
{
|
||||
public:
|
||||
//! \brief Constructor
|
||||
//! \param[in] s1 Pointer to model solver simulator
|
||||
SIMSolver(T1& s1) : S1(s1)
|
||||
{
|
||||
}
|
||||
|
||||
//! \brief Destructor
|
||||
virtual ~SIMSolver()
|
||||
{
|
||||
}
|
||||
|
||||
//! \brief Solves the problem up to the final time.
|
||||
virtual bool solveProblem(char* infile, DataExporter* exporter = NULL)
|
||||
{
|
||||
// Save initial step to VTF
|
||||
TimeStep tp = S1.getTimePrm();
|
||||
|
||||
// Save FE model to VTF file for visualization
|
||||
int nBlock;
|
||||
if (!S1.saveModel(infile, nBlock))
|
||||
return 3;
|
||||
|
||||
// Save initial step
|
||||
if (!S1.saveStep(tp, nBlock))
|
||||
return false;
|
||||
|
||||
// Solve for each time step up to final time
|
||||
for (int iStep = 1; S1.advanceStep(tp); iStep++)
|
||||
{
|
||||
if (!S1.solveStep(tp))
|
||||
return false;
|
||||
if (!S1.saveStep(tp, nBlock))
|
||||
return false;
|
||||
if (exporter)
|
||||
exporter->dumpTimeLevel(&tp);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
protected:
|
||||
T1& S1; //!< Solver
|
||||
};
|
||||
|
||||
#endif
|
||||
55
Apps/Common/StabilizationUtils.C
Normal file
55
Apps/Common/StabilizationUtils.C
Normal file
@@ -0,0 +1,55 @@
|
||||
#include "StabilizationUtils.h"
|
||||
#include "Vec3Oper.h"
|
||||
|
||||
namespace StabilizationUtils {
|
||||
|
||||
double getElementSize(const std::vector<Vec3>& XC, int nsd)
|
||||
{
|
||||
double h;
|
||||
if (nsd == 2) {
|
||||
h = (XC[0]-XC[1]).length();
|
||||
h = std::min(h, (XC[1]-XC[3]).length());
|
||||
h = std::min(h, (XC[3]-XC[2]).length());
|
||||
h = std::min(h, (XC[2]-XC[0]).length());
|
||||
} else {
|
||||
static const int comps[][2] = {{0,1}, {1,5}, {5,4}, {4,0},
|
||||
{2,3}, {3,7}, {7,6}, {6,2},
|
||||
{0,4}, {4,6}, {2,0},
|
||||
{5,7}, {3,1}};
|
||||
h = 1e8;
|
||||
for (size_t i=0; i < sizeof(comps)/(2*sizeof(int));++i)
|
||||
h = std::min(h, (XC[comps[i][0]]-XC[comps[i][1]]).length());
|
||||
}
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
|
||||
double getTauPt(double dt, double mu, const Vector& U, const Matrix& G)
|
||||
{
|
||||
double Ct = 2.0;
|
||||
double Cl = 36.0;
|
||||
|
||||
double Gnorm2 = 0.0;
|
||||
for (size_t i = 1;i <= G.rows();i++)
|
||||
for (size_t j = 1;j <= G.cols();j++)
|
||||
Gnorm2 += G(i,j)*G(i,j);
|
||||
|
||||
return 1.0/sqrt( Ct/pow(dt,2) + U.dot(G*U) + Cl*mu*Gnorm2);
|
||||
}
|
||||
|
||||
|
||||
bool getTauNSPt(double dt, double mu, const Vector& U, const Matrix& G, double & tauM, double& tauC)
|
||||
{
|
||||
tauM = getTauPt(dt,mu,U,G);
|
||||
|
||||
double Gtrace = 0.0;
|
||||
for (size_t i = 1;i <= G.rows();i++)
|
||||
Gtrace += G(i,i);
|
||||
|
||||
tauC = 1.0/(tauM*Gtrace);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
34
Apps/Common/StabilizationUtils.h
Normal file
34
Apps/Common/StabilizationUtils.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef STABILIZATIONUTILS_H_
|
||||
#define STABILIZATIONUTILS_H_
|
||||
|
||||
#include <vector>
|
||||
#include "Vec3.h"
|
||||
#include "MatVec.h"
|
||||
|
||||
namespace StabilizationUtils {
|
||||
//! \brief Returns characteristic element size
|
||||
//! \param XC The element corner coordinates
|
||||
//! \details The size is taken as the shortest edge length
|
||||
double getElementSize(const std::vector<Vec3>& XC, int nsd);
|
||||
|
||||
//! \brief Returns stabilization parameters for convecction-diffusion equation
|
||||
//! \param[in] dt The timestep size
|
||||
//! \param[in] mu Diffusion/viscosity parameter
|
||||
//! \param[in] U Velocity vector
|
||||
//! \param[in] G G matrix
|
||||
//! \details Stabilization parameter in integration point
|
||||
double getTauPt(double dt, double mu, const Vector& U, const Matrix& G);
|
||||
|
||||
//! \brief Computes stabilization parameters for Navier-Stokes equations
|
||||
//! \param[in] dt The timestep size
|
||||
//! \param[in] mu Diffusion/viscosity parameter
|
||||
//! \param[in] U Velocity vector
|
||||
//! \param[in] G The G matrix
|
||||
//! \param[out] tauM Stabilization parameter for momentum
|
||||
//! \param[out] tauC Stabilization parameter for continuity
|
||||
//! \details Stabilization parameters in integration point
|
||||
bool getTauNSPt(double dt, double mu, const Vector& U, const Matrix& G,
|
||||
double& tauM, double& tauC);
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user