39#include <boost/version.hpp>
40#if BOOST_VERSION >= 106900 && BOOST_VERSION < 107000
41#define BOOST_ALLOW_DEPRECATED_HEADERS
44#include <boost/core/ignore_unused.hpp>
45#include <boost/random/normal_distribution.hpp>
46#include <boost/random/variate_generator.hpp>
61 m_ip(-1), m_irho(-1), m_iu(1), m_conservative(false)
74 "Only Projection=DisContinuous supported by the AcousticSystem class.");
100 if (
m_session->DefinesElement(
"Nektar/Coupling"))
102 TiXmlElement *vCoupling =
m_session->GetElement(
"Nektar/Coupling");
104 ASSERTL0(vCoupling->Attribute(
"TYPE"),
105 "Missing TYPE attribute in Coupling");
106 string vType = vCoupling->Attribute(
"TYPE");
108 "TYPE attribute must be non-empty in Coupling");
134 int numForceFields = 0;
137 numForceFields += x->GetForces().size();
139 vector<string> varNames;
142 for (
int i = 0; i <
m_fields.size(); ++i)
144 varNames.push_back(
m_session->GetVariable(i));
145 phys[i] =
m_fields[i]->UpdatePhys();
147 for (
int i = 0; i <
m_bfNames.size(); ++i)
156 for (
int i = 0; i < x->GetForces().size(); ++i)
160 varNames.push_back(
"F_" + boost::lexical_cast<string>(f) +
"_" +
190 int nVariables = inarray.size();
198 for (
int i = 0; i < nVariables; ++i)
219 int nvariables = inarray.size();
223 if (inarray != outarray)
225 for (
int i = 0; i < nvariables; ++i)
250 for (
int i = 0; i < nvariables; ++i)
253 m_fields[i]->ExtractTracePhys(inarray[i], Fwd[i]);
258 for (
int n = 0; n <
m_fields[0]->GetBndConditions().size(); ++n)
260 std::string userDefStr =
261 m_fields[0]->GetBndConditions()[n]->GetUserDefined();
263 if (!userDefStr.empty())
266 if (boost::iequals(userDefStr,
"Wall"))
268 WallBC(n, cnt, Fwd, inarray);
270 else if (boost::iequals(userDefStr,
"WhiteNoise"))
274 else if (boost::iequals(userDefStr,
"RiemannInvariantBC"))
278 else if (boost::iequals(userDefStr,
"TimeDependent"))
280 for (
int i = 0; i < nvariables; ++i)
283 m_fields[i]->EvaluateBoundaryConditions(time, varName);
288 string errmsg =
"Unrecognised boundary condition: ";
289 errmsg += userDefStr;
295 for (
int i = 0; i < nvariables; ++i)
298 m_fields[i]->EvaluateBoundaryConditions(time, varName);
302 cnt +=
m_fields[0]->GetBndCondExpansions()[n]->GetExpSize();
313 int nVariables = physarray.size();
319 int id1, id2, nBCEdgePts;
320 int eMax =
m_fields[0]->GetBndCondExpansions()[bcRegion]->GetExpSize();
322 for (
int e = 0; e < eMax; ++e)
325 ->GetBndCondExpansions()[bcRegion]
328 id1 =
m_fields[0]->GetBndCondExpansions()[bcRegion]->GetPhys_Offset(e);
329 id2 =
m_fields[0]->GetTrace()->GetPhys_Offset(traceBndMap[cnt + e]);
342 Vmath::Smul(nBCEdgePts, -2.0, &tmp[0], 1, &tmp[0], 1);
348 &Fwd[
m_iu + i][id2], 1, &Fwd[
m_iu + i][id2], 1);
352 for (
int i = 0; i < nVariables; ++i)
356 ->GetBndCondExpansions()[bcRegion]
357 ->UpdatePhys())[id1],
371 boost::ignore_unused(Fwd);
373 int id1, id2, nBCEdgePts;
374 int nVariables = physarray.size();
378 if (
m_rng.count(bcRegion) == 0)
380 m_rng[bcRegion] = boost::mt19937(bcRegion);
384 m_fields[0]->GetBndConditions()[bcRegion]->GetBoundaryConditionType() ==
386 "WhiteNoise BCs must be Dirichlet type BCs");
389 std::static_pointer_cast<SpatialDomains::DirichletBoundaryCondition>(
390 m_fields[0]->GetBndConditions()[bcRegion])
391 ->m_dirichletCondition;
395 "sigma must be greater than zero");
402 boost::normal_distribution<> dist(0, sigma);
406 int eMax =
m_fields[0]->GetBndCondExpansions()[bcRegion]->GetExpSize();
407 for (
int e = 0; e < eMax; ++e)
410 ->GetBndCondExpansions()[bcRegion]
413 id1 =
m_fields[0]->GetBndCondExpansions()[bcRegion]->GetPhys_Offset(e);
414 id2 =
m_fields[0]->GetTrace()->GetPhys_Offset(traceBndMap[cnt + e]);
417 for (
int i = 0; i < nVariables; ++i)
427 for (
int i = 0; i < nBCEdgePts; ++i)
444 for (
int i = 0; i < nBCEdgePts; ++i)
448 (
sqrt(BfFwd[0][id2 + i]) * BfFwd[1][id2 + i]);
458 for (
int i = 0; i < nVariables; ++i)
462 ->GetBndCondExpansions()[bcRegion]
463 ->UpdatePhys())[id1],
478 boost::ignore_unused(SpeedSoundFactor);
479 int nElm =
m_fields[0]->GetExpSize();
489 for (
int el = 0; el < nElm; ++el)
491 ptsKeys =
m_fields[0]->GetExp(el)->GetPointsKeys();
495 m_fields[0]->GetExp(el)->GetGeom()->GetMetricInfo();
501 ->GetDerivFactors(ptsKeys);
503 int nq =
m_fields[0]->GetExp(el)->GetTotPoints();
510 for (
int j = 0; j < nq; ++j)
515 velocity[i][j] =
m_bf[i + 2][cnt + j] + c;
525 Vmath::Vmul(nq, gmat[i], 1, velocity[0], 1, stdVelocity[i], 1);
529 1, stdVelocity[i], 1, stdVelocity[i], 1);
537 Vmath::Smul(nq, gmat[i][0], velocity[0], 1, stdVelocity[i], 1);
541 1, stdVelocity[i], 1, stdVelocity[i], 1);
547 for (
int i = 0; i < nq; ++i)
552 pntVelocity += stdVelocity[j][i] * stdVelocity[j][i];
554 pntVelocity =
sqrt(pntVelocity);
556 if (pntVelocity > stdV[el])
558 stdV[el] = pntVelocity;
570 std::vector<std::string> &variables)
572 for (
int i = 0; i <
m_bfNames.size(); i++)
577 fieldcoeffs.push_back(tmpC);
583 for (
int i = 0; i < x->GetForces().size(); ++i)
585 variables.push_back(
"F_" + boost::lexical_cast<string>(f) +
"_" +
588 m_fields[0]->FwdTrans(x->GetForces()[i], tmpC);
589 fieldcoeffs.push_back(tmpC);
623 for (
int i = 0; i <
m_bfNames.size(); i++)
636 for (
int bcRegion = 0; bcRegion <
m_fields[0]->GetBndConditions().size();
648 ->GetBndCondExpansions()[bcRegion]
651 id2 =
m_fields[0]->GetTrace()->GetPhys_Offset(
652 m_fields[0]->GetTraceMap()->GetBndCondIDToGlobalTraceID(cnt +
658 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.
virtual void v_Output() override
virtual 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
virtual 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
virtual ~AcousticSystem()
Destructor.
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
virtual 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
void SetBoundaryConditions(Array< OneD, Array< OneD, NekDouble > > &physarray, NekDouble time)
Apply the Boundary Conditions to the AcousticSystem equations.
virtual bool v_PreIntegrate(int step) override
v_PreIntegrate
NekDouble Evaluate() const
A base class for PDEs which include an advection component.
virtual SOLVER_UTILS_EXPORT void v_InitObject(bool DeclareField=true) override
Init object for UnsteadySystem class.
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
The above copyright notice and this permission notice shall be included.
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)