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>
57 AcousticSystem::AcousticSystem(
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 for (
int i = 0; i < nvariables; ++i)
247 for (
int i = 0; i < nvariables; ++i)
250 m_fields[i]->ExtractTracePhys(inarray[i], Fwd[i]);
255 for (
int n = 0; n <
m_fields[0]->GetBndConditions().size(); ++n)
257 std::string userDefStr =
258 m_fields[0]->GetBndConditions()[n]->GetUserDefined();
260 if (!userDefStr.empty())
263 if (boost::iequals(userDefStr,
"Wall"))
267 else if (boost::iequals(userDefStr,
"WhiteNoise"))
271 else if (boost::iequals(userDefStr,
"RiemannInvariantBC"))
275 else if (boost::iequals(userDefStr,
"TimeDependent"))
277 for (
int i = 0; i < nvariables; ++i)
280 m_fields[i]->EvaluateBoundaryConditions(time, varName);
285 string errmsg =
"Unrecognised boundary condition: ";
286 errmsg += userDefStr;
292 for (
int i = 0; i < nvariables; ++i)
295 m_fields[i]->EvaluateBoundaryConditions(time, varName);
299 cnt +=
m_fields[0]->GetBndCondExpansions()[n]->GetExpSize();
310 int nVariables = physarray.size();
316 int id1, id2, nBCEdgePts;
317 int eMax =
m_fields[0]->GetBndCondExpansions()[bcRegion]->GetExpSize();
319 for (
int e = 0; e < eMax; ++e)
322 ->GetBndCondExpansions()[bcRegion]
325 id1 =
m_fields[0]->GetBndCondExpansions()[bcRegion]->GetPhys_Offset(e);
326 id2 =
m_fields[0]->GetTrace()->GetPhys_Offset(traceBndMap[cnt + e]);
339 Vmath::Smul(nBCEdgePts, -2.0, &tmp[0], 1, &tmp[0], 1);
345 &Fwd[
m_iu + i][id2], 1, &Fwd[
m_iu + i][id2], 1);
349 for (
int i = 0; i < nVariables; ++i)
353 ->GetBndCondExpansions()[bcRegion]
354 ->UpdatePhys())[id1],
368 boost::ignore_unused(Fwd);
370 int id1, id2, nBCEdgePts;
371 int nVariables = physarray.size();
375 if (
m_rng.count(bcRegion) == 0)
377 m_rng[bcRegion] = boost::mt19937(bcRegion);
381 m_fields[0]->GetBndConditions()[bcRegion]->GetBoundaryConditionType() ==
383 "WhiteNoise BCs must be Dirichlet type BCs");
386 std::static_pointer_cast<SpatialDomains::DirichletBoundaryCondition>(
387 m_fields[0]->GetBndConditions()[bcRegion])
388 ->m_dirichletCondition;
392 "sigma must be greater than zero");
399 boost::normal_distribution<> dist(0, sigma);
403 int eMax =
m_fields[0]->GetBndCondExpansions()[bcRegion]->GetExpSize();
404 for (
int e = 0; e < eMax; ++e)
407 ->GetBndCondExpansions()[bcRegion]
410 id1 =
m_fields[0]->GetBndCondExpansions()[bcRegion]->GetPhys_Offset(e);
411 id2 =
m_fields[0]->GetTrace()->GetPhys_Offset(traceBndMap[cnt + e]);
414 for (
int i = 0; i < nVariables; ++i)
424 for (
int i = 0; i < nBCEdgePts; ++i)
441 for (
int i = 0; i < nBCEdgePts; ++i)
445 (
sqrt(BfFwd[0][id2 + i]) * BfFwd[1][id2 + i]);
455 for (
int i = 0; i < nVariables; ++i)
459 ->GetBndCondExpansions()[bcRegion]
460 ->UpdatePhys())[id1],
475 boost::ignore_unused(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;
634 bcRegion <
m_fields[0]->GetBndConditions().size(); ++bcRegion)
645 ->GetBndCondExpansions()[bcRegion]
648 id2 =
m_fields[0]->GetTrace()->GetPhys_Offset(
649 m_fields[0]->GetTraceMap()->GetBndCondIDToGlobalTraceID(
655 cnt +=
m_fields[0]->GetBndCondExpansions()[bcRegion]->GetExpSize();
#define ASSERTL0(condition, msg)
SolverUtils::CouplingSharedPtr m_coupling
NekDouble m_whiteNoiseBC_p
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_ExtraFldOutput(std::vector< Array< OneD, NekDouble >> &fieldcoeffs, std::vector< std::string > &variables)
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 Array< OneD, NekDouble > v_GetMaxStdVelocity(const NekDouble SpeedSoundFactor)
Compute the advection velocity in the standard space for each element of the expansion.
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...
SolverUtils::AdvectionSharedPtr m_advection
virtual ~AcousticSystem()
Destructor.
void DoOdeRhs(const Array< OneD, const Array< OneD, NekDouble >> &inarray, Array< OneD, Array< OneD, NekDouble >> &outarray, const NekDouble time)
Compute the right-hand side.
virtual void v_InitObject()
Initialization object for the AcousticSystem class.
int m_ip
indices of the fields
virtual bool v_PreIntegrate(int step)
v_PreIntegrate
virtual void v_AddLinTerm(const Array< OneD, const Array< OneD, NekDouble >> &inarray, Array< OneD, Array< OneD, NekDouble >> &outarray)
std::map< int, boost::mt19937 > m_rng
Array< OneD, Array< OneD, NekDouble > > m_bfFwdBwd
Array< OneD, Array< OneD, NekDouble > > m_bf
virtual void v_WallBC(int bcRegion, int cnt, Array< OneD, Array< OneD, NekDouble >> &Fwd, Array< OneD, Array< OneD, NekDouble >> &physarray)
Wall boundary conditions for the AcousticSystem equations.
void SetBoundaryConditions(Array< OneD, Array< OneD, NekDouble >> &physarray, NekDouble time)
Apply the Boundary Conditions to the AcousticSystem equations.
virtual void v_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.
std::vector< SolverUtils::ForcingSharedPtr > m_forcing
void UpdateBasefieldFwdBwd()
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
const Array< OneD, const Array< OneD, NekDouble > > & GetBasefieldFwdBwd()
Get the baseflow field.
NekDouble m_whiteNoiseBC_lastUpdate
NekDouble Evaluate() const
A base class for PDEs which include an advection component.
virtual SOLVER_UTILS_EXPORT void v_InitObject()
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)