39#include <boost/version.hpp>
40#if BOOST_VERSION >= 106900 && BOOST_VERSION < 107000
41#define BOOST_ALLOW_DEPRECATED_HEADERS
44#include <boost/random/normal_distribution.hpp>
45#include <boost/random/variate_generator.hpp>
60 m_ip(-1), m_irho(-1), m_iu(1), m_conservative(false)
73 "Only Projection=DisContinuous supported by the AcousticSystem class.");
99 if (
m_session->DefinesElement(
"Nektar/Coupling"))
101 TiXmlElement *vCoupling =
m_session->GetElement(
"Nektar/Coupling");
103 ASSERTL0(vCoupling->Attribute(
"TYPE"),
104 "Missing TYPE attribute in Coupling");
105 string vType = vCoupling->Attribute(
"TYPE");
107 "TYPE attribute must be non-empty in Coupling");
133 int numForceFields = 0;
136 numForceFields += x->GetForces().size();
138 vector<string> varNames;
141 for (
int i = 0; i <
m_fields.size(); ++i)
143 varNames.push_back(
m_session->GetVariable(i));
144 phys[i] =
m_fields[i]->UpdatePhys();
146 for (
int i = 0; i <
m_bfNames.size(); ++i)
155 for (
int i = 0; i < x->GetForces().size(); ++i)
159 varNames.push_back(
"F_" + boost::lexical_cast<string>(f) +
"_" +
189 int nVariables = inarray.size();
197 for (
int i = 0; i < nVariables; ++i)
218 int nvariables = inarray.size();
222 if (inarray != outarray)
224 for (
int i = 0; i < nvariables; ++i)
249 for (
int i = 0; i < nvariables; ++i)
252 m_fields[i]->ExtractTracePhys(inarray[i], Fwd[i]);
257 for (
int n = 0; n <
m_fields[0]->GetBndConditions().size(); ++n)
259 std::string userDefStr =
260 m_fields[0]->GetBndConditions()[n]->GetUserDefined();
262 if (!userDefStr.empty())
265 if (boost::iequals(userDefStr,
"Wall"))
267 WallBC(n, cnt, Fwd, inarray);
269 else if (boost::iequals(userDefStr,
"WhiteNoise"))
273 else if (boost::iequals(userDefStr,
"RiemannInvariantBC"))
277 else if (boost::iequals(userDefStr,
"TimeDependent"))
279 for (
int i = 0; i < nvariables; ++i)
282 m_fields[i]->EvaluateBoundaryConditions(time, varName);
287 string errmsg =
"Unrecognised boundary condition: ";
288 errmsg += userDefStr;
294 for (
int i = 0; i < nvariables; ++i)
297 m_fields[i]->EvaluateBoundaryConditions(time, varName);
301 cnt +=
m_fields[0]->GetBndCondExpansions()[n]->GetExpSize();
312 int nVariables = physarray.size();
318 int id1, id2, nBCEdgePts;
319 int eMax =
m_fields[0]->GetBndCondExpansions()[bcRegion]->GetExpSize();
321 for (
int e = 0; e < eMax; ++e)
324 ->GetBndCondExpansions()[bcRegion]
327 id1 =
m_fields[0]->GetBndCondExpansions()[bcRegion]->GetPhys_Offset(e);
328 id2 =
m_fields[0]->GetTrace()->GetPhys_Offset(traceBndMap[cnt + e]);
341 Vmath::Smul(nBCEdgePts, -2.0, &tmp[0], 1, &tmp[0], 1);
347 &Fwd[
m_iu + i][id2], 1, &Fwd[
m_iu + i][id2], 1);
351 for (
int i = 0; i < nVariables; ++i)
355 ->GetBndCondExpansions()[bcRegion]
356 ->UpdatePhys())[id1],
366 int bcRegion,
int cnt,
371 int id1, id2, nBCEdgePts;
372 int nVariables = physarray.size();
376 if (
m_rng.count(bcRegion) == 0)
378 m_rng[bcRegion] = boost::mt19937(bcRegion);
382 m_fields[0]->GetBndConditions()[bcRegion]->GetBoundaryConditionType() ==
384 "WhiteNoise BCs must be Dirichlet type BCs");
387 std::static_pointer_cast<SpatialDomains::DirichletBoundaryCondition>(
388 m_fields[0]->GetBndConditions()[bcRegion])
389 ->m_dirichletCondition;
393 "sigma must be greater than zero");
400 boost::normal_distribution<> dist(0, sigma);
404 int eMax =
m_fields[0]->GetBndCondExpansions()[bcRegion]->GetExpSize();
405 for (
int e = 0; e < eMax; ++e)
408 ->GetBndCondExpansions()[bcRegion]
411 id1 =
m_fields[0]->GetBndCondExpansions()[bcRegion]->GetPhys_Offset(e);
412 id2 =
m_fields[0]->GetTrace()->GetPhys_Offset(traceBndMap[cnt + e]);
415 for (
int i = 0; i < nVariables; ++i)
425 for (
int i = 0; i < nBCEdgePts; ++i)
442 for (
int i = 0; i < nBCEdgePts; ++i)
446 (
sqrt(BfFwd[0][id2 + i]) * BfFwd[1][id2 + i]);
456 for (
int i = 0; i < nVariables; ++i)
460 ->GetBndCondExpansions()[bcRegion]
461 ->UpdatePhys())[id1],
474 [[maybe_unused]]
const NekDouble SpeedSoundFactor)
476 int nElm =
m_fields[0]->GetExpSize();
486 for (
int el = 0; el < nElm; ++el)
488 ptsKeys =
m_fields[0]->GetExp(el)->GetPointsKeys();
492 m_fields[0]->GetExp(el)->GetGeom()->GetMetricInfo();
498 ->GetDerivFactors(ptsKeys);
500 int nq =
m_fields[0]->GetExp(el)->GetTotPoints();
507 for (
int j = 0; j < nq; ++j)
512 velocity[i][j] =
m_bf[i + 2][cnt + j] + c;
522 Vmath::Vmul(nq, gmat[i], 1, velocity[0], 1, stdVelocity[i], 1);
526 1, stdVelocity[i], 1, stdVelocity[i], 1);
534 Vmath::Smul(nq, gmat[i][0], velocity[0], 1, stdVelocity[i], 1);
538 1, stdVelocity[i], 1, stdVelocity[i], 1);
544 for (
int i = 0; i < nq; ++i)
549 pntVelocity += stdVelocity[j][i] * stdVelocity[j][i];
551 pntVelocity =
sqrt(pntVelocity);
553 if (pntVelocity > stdV[el])
555 stdV[el] = pntVelocity;
567 std::vector<std::string> &variables)
569 for (
int i = 0; i <
m_bfNames.size(); i++)
574 fieldcoeffs.push_back(tmpC);
580 for (
int i = 0; i < x->GetForces().size(); ++i)
582 variables.push_back(
"F_" + boost::lexical_cast<string>(f) +
"_" +
585 m_fields[0]->FwdTrans(x->GetForces()[i], tmpC);
586 fieldcoeffs.push_back(tmpC);
620 for (
int i = 0; i <
m_bfNames.size(); i++)
633 for (
int bcRegion = 0; bcRegion <
m_fields[0]->GetBndConditions().size();
645 ->GetBndCondExpansions()[bcRegion]
648 id2 =
m_fields[0]->GetTrace()->GetPhys_Offset(
649 m_fields[0]->GetTraceMap()->GetBndCondIDToGlobalTraceID(cnt +
655 cnt +=
m_fields[0]->GetBndCondExpansions()[bcRegion]->GetExpSize();
#define ASSERTL0(condition, msg)
SolverUtils::CouplingSharedPtr m_coupling
NekDouble m_whiteNoiseBC_p
void DoOdeRhs(const Array< OneD, const Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray, const NekDouble time)
Compute the right-hand side.
const Array< OneD, const Array< OneD, NekDouble > > & GetVecLocs()
Get the locations of the components of the directed fields within the fields array.
const Array< OneD, const Array< OneD, NekDouble > > & GetNormals()
Get the normal vectors.
Array< OneD, NekDouble > v_GetMaxStdVelocity(const NekDouble SpeedSoundFactor) override
Compute the advection velocity in the standard space for each element of the expansion.
std::vector< std::string > m_bfNames
Array< OneD, Array< OneD, NekDouble > > m_vecLocs
void CopyBoundaryTrace(const Array< OneD, NekDouble > &Fwd, Array< OneD, NekDouble > &Bwd)
bool m_conservative
we are dealing with a conservative formualtion
void v_ExtraFldOutput(std::vector< Array< OneD, NekDouble > > &fieldcoeffs, std::vector< std::string > &variables) override
virtual void v_RiemannInvariantBC(int bcRegion, int cnt, Array< OneD, Array< OneD, NekDouble > > &Fwd, Array< OneD, Array< OneD, NekDouble > > &BfFwd, Array< OneD, Array< OneD, NekDouble > > &physarray)=0
SolverUtils::AdvectionSharedPtr m_advection
void WallBC(int bcRegion, int cnt, Array< OneD, Array< OneD, NekDouble > > &Fwd, Array< OneD, Array< OneD, NekDouble > > &physarray)
Wall boundary conditions for the AcousticSystem equations.
AcousticSystem(const LibUtilities::SessionReaderSharedPtr &pSession, const SpatialDomains::MeshGraphSharedPtr &pGraph)
Initialises UnsteadySystem class members.
void WhiteNoiseBC(int bcRegion, int cnt, Array< OneD, Array< OneD, NekDouble > > &Fwd, Array< OneD, Array< OneD, NekDouble > > &BfFwd, Array< OneD, Array< OneD, NekDouble > > &physarray)
Wall boundary conditions for the AcousticSystem equations.
int m_ip
indices of the fields
std::map< int, boost::mt19937 > m_rng
Array< OneD, Array< OneD, NekDouble > > m_bfFwdBwd
void DoOdeProjection(const Array< OneD, const Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray, const NekDouble time)
Compute the projection and call the method for imposing the boundary conditions in case of discontinu...
Array< OneD, Array< OneD, NekDouble > > m_bf
void v_InitObject(bool DeclareFields=true) override
Initialization object for the AcousticSystem class.
std::vector< SolverUtils::ForcingSharedPtr > m_forcing
void UpdateBasefieldFwdBwd()
const Array< OneD, const Array< OneD, NekDouble > > & GetBasefieldFwdBwd()
Get the baseflow field.
virtual void v_AddLinTerm(const Array< OneD, const Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray)
NekDouble m_whiteNoiseBC_lastUpdate
~AcousticSystem() override
Destructor.
void SetBoundaryConditions(Array< OneD, Array< OneD, NekDouble > > &physarray, NekDouble time)
Apply the Boundary Conditions to the AcousticSystem equations.
bool v_PreIntegrate(int step) override
v_PreIntegrate
NekDouble Evaluate() const
A base class for PDEs which include an advection component.
SOLVER_UTILS_EXPORT void v_InitObject(bool DeclareField=true) override
Initialisation object for EquationSystem.
int m_spacedim
Spatial dimension (>= expansion dim).
NekDouble m_time
Current time of simulation.
SOLVER_UTILS_EXPORT int GetTraceTotPoints()
Array< OneD, MultiRegions::ExpListSharedPtr > m_fields
Array holding all dependent variables.
SOLVER_UTILS_EXPORT int GetExpSize()
LibUtilities::SessionReaderSharedPtr m_session
The session reader.
Array< OneD, Array< OneD, NekDouble > > m_traceNormals
Array holding trace normals for DG simulations in the forwards direction.
SOLVER_UTILS_EXPORT int GetNcoeffs()
enum MultiRegions::ProjectionType m_projectionType
Type of projection; e.g continuous or discontinuous.
SOLVER_UTILS_EXPORT SessionFunctionSharedPtr GetFunction(std::string name, const MultiRegions::ExpListSharedPtr &field=MultiRegions::NullExpListSharedPtr, bool cache=false)
Get a SessionFunction by name.
SOLVER_UTILS_EXPORT int GetTotPoints()
virtual SOLVER_UTILS_EXPORT void v_Output(void)
static SOLVER_UTILS_EXPORT std::vector< ForcingSharedPtr > Load(const LibUtilities::SessionReaderSharedPtr &pSession, const std::weak_ptr< EquationSystem > &pEquation, const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const unsigned int &pNumForcingFields=0)
Base class for unsteady solvers.
virtual SOLVER_UTILS_EXPORT bool v_PreIntegrate(int step)
bool m_homoInitialFwd
Flag to determine if simulation should start in homogeneous forward transformed state.
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::vector< PointsKey > PointsKeyVector
static const NekDouble kNekZeroTol
CouplingFactory & GetCouplingFactory()
Declaration of the Coupling factory singleton.
std::shared_ptr< GeomFactors > GeomFactorsSharedPtr
Pointer to a GeomFactors object.
@ eDeformed
Geometry is curved or has non-constant factors.
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
void Vmul(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Multiply vector z = x*y.
void Svtvp(int n, const T alpha, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Svtvp (scalar times vector plus vector): z = alpha*x + y.
void Neg(int n, T *x, const int incx)
Negate x = -x.
void Vvtvp(int n, const T *w, const int incw, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
vvtvp (vector times vector plus vector): z = w*x + y
void Smul(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha*x.
void Fill(int n, const T alpha, T *x, const int incx)
Fill a vector with a constant value.
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
scalarT< T > sqrt(scalarT< T > in)