Nektar++
Static Public Member Functions | Static Public Attributes | Protected Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
Nektar::SolverUtils::ForcingMovingReferenceFrame Class Reference

#include <ForcingMovingReferenceFrame.h>

Inheritance diagram for Nektar::SolverUtils::ForcingMovingReferenceFrame:
[legend]

Static Public Member Functions

static SOLVER_UTILS_EXPORT ForcingSharedPtr create (const LibUtilities::SessionReaderSharedPtr &pSession, const std::weak_ptr< EquationSystem > &pEquation, const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const unsigned int &pNumForcingFields, const TiXmlElement *pForce)
 Creates an instance of this class. More...
 
- Static Public Member Functions inherited from Nektar::SolverUtils::Forcing
static SOLVER_UTILS_EXPORT std::vector< ForcingSharedPtrLoad (const LibUtilities::SessionReaderSharedPtr &pSession, const std::weak_ptr< EquationSystem > &pEquation, const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const unsigned int &pNumForcingFields=0)
 

Static Public Attributes

static std::string classNameBody
 Name of the class. More...
 

Protected Member Functions

virtual SOLVER_UTILS_EXPORT void v_InitObject (const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const unsigned int &pNumForcingFields, const TiXmlElement *pForce) override
 Initialise the forcing module. More...
 
virtual SOLVER_UTILS_EXPORT void v_Apply (const Array< OneD, MultiRegions::ExpListSharedPtr > &fields, const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray, const NekDouble &time) override
 Adds the body force, -Omega X u. More...
 
virtual SOLVER_UTILS_EXPORT void v_PreApply (const Array< OneD, MultiRegions::ExpListSharedPtr > &fields, const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray, const NekDouble &time) override
 
- Protected Member Functions inherited from Nektar::SolverUtils::Forcing
SOLVER_UTILS_EXPORT Forcing (const LibUtilities::SessionReaderSharedPtr &pSession, const std::weak_ptr< EquationSystem > &pEquation)
 Constructor. More...
 
virtual SOLVER_UTILS_EXPORT void v_InitObject (const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const unsigned int &pNumForcingFields, const TiXmlElement *pForce)=0
 
virtual SOLVER_UTILS_EXPORT void v_Apply (const Array< OneD, MultiRegions::ExpListSharedPtr > &fields, const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray, const NekDouble &time)=0
 
virtual SOLVER_UTILS_EXPORT void v_PreApply (const Array< OneD, MultiRegions::ExpListSharedPtr > &fields, const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray, const NekDouble &time)
 
virtual SOLVER_UTILS_EXPORT void v_ApplyCoeff (const Array< OneD, MultiRegions::ExpListSharedPtr > &fields, const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray, const NekDouble &time)
 
SOLVER_UTILS_EXPORT SessionFunctionSharedPtr GetFunction (const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const LibUtilities::SessionReaderSharedPtr &pSession, std::string pName, bool pCache=false)
 Get a SessionFunction by name. More...
 
SOLVER_UTILS_EXPORT void EvaluateTimeFunction (LibUtilities::SessionReaderSharedPtr pSession, std::string pFieldName, Array< OneD, NekDouble > &pArray, const std::string &pFunctionName, NekDouble pTime=NekDouble(0))
 
SOLVER_UTILS_EXPORT void EvaluateTimeFunction (const NekDouble pTime, const LibUtilities::EquationSharedPtr &pEqn, Array< OneD, NekDouble > &pArray)
 

Private Member Functions

 ForcingMovingReferenceFrame (const LibUtilities::SessionReaderSharedPtr &pSession, const std::weak_ptr< EquationSystem > &pEquation)
 
virtual ~ForcingMovingReferenceFrame (void)
 
void Update (const NekDouble &time)
 Updates the forcing array with the current required forcing. More...
 
void UpdateTheta (const NekDouble &time)
 
void CheckForRestartTheta (const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, Array< OneD, NekDouble > &theta)
 
void addRotation (int npoints, const Array< OneD, Array< OneD, NekDouble > > &inarray0, NekDouble angVelScale, const Array< OneD, Array< OneD, NekDouble > > &inarray1, Array< OneD, Array< OneD, NekDouble > > &outarray)
 outarray = inarray0 + angVelScale Omega x inarray1 More...
 

Private Attributes

std::string m_funcName
 
std::string m_velFuncName
 
std::string m_omegaFuncName
 
std::map< int, LibUtilities::EquationSharedPtrm_frameFunction
 
std::map< int, LibUtilities::EquationSharedPtrm_velFunction
 
std::map< int, LibUtilities::EquationSharedPtrm_omegaFunction
 
std::map< int, bool > m_hasVel
 
std::map< int, bool > m_hasOmega
 
std::map< int, NekDoublem_velXYZ
 
std::map< int, NekDoublem_velxyz
 
std::map< int, NekDoublem_omegaXYZ
 
std::map< int, NekDoublem_omegaxyz
 
Array< OneD, Array< OneD, NekDouble > > m_coords
 
Array< OneD, NekDoublem_pivotPoint
 
Array< OneD, NekDoublem_theta
 
bn::ublas::matrix< NekDoublem_ProjMatX
 
bn::ublas::matrix< NekDoublem_ProjMatY
 
bn::ublas::matrix< NekDoublem_ProjMatZ
 
bool m_hasRotation
 
bool m_isH1d
 
bool m_hasPlane0
 
bool m_isH2d
 
NekInt m_spacedim
 

Friends

class MemoryManager< ForcingMovingReferenceFrame >
 

Additional Inherited Members

- Public Member Functions inherited from Nektar::SolverUtils::Forcing
virtual SOLVER_UTILS_EXPORT ~Forcing ()
 
SOLVER_UTILS_EXPORT void InitObject (const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const unsigned int &pNumForcingFields, const TiXmlElement *pForce)
 Initialise the forcing object. More...
 
SOLVER_UTILS_EXPORT void Apply (const Array< OneD, MultiRegions::ExpListSharedPtr > &fields, const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray, const NekDouble &time)
 Apply the forcing. More...
 
SOLVER_UTILS_EXPORT void PreApply (const Array< OneD, MultiRegions::ExpListSharedPtr > &fields, const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray, const NekDouble &time)
 Change the advection velocity before applying the forcing. For example, subtracting the frame velocity from the advection velocity in the MovingRefercenceFrame. More...
 
SOLVER_UTILS_EXPORT void ApplyCoeff (const Array< OneD, MultiRegions::ExpListSharedPtr > &fields, const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray, const NekDouble &time)
 Apply the forcing. More...
 
SOLVER_UTILS_EXPORT const Array< OneD, const Array< OneD, NekDouble > > & GetForces ()
 
SOLVER_UTILS_EXPORT Array< OneD, Array< OneD, NekDouble > > & UpdateForces ()
 
- Protected Attributes inherited from Nektar::SolverUtils::Forcing
LibUtilities::SessionReaderSharedPtr m_session
 Session reader. More...
 
const std::weak_ptr< EquationSystemm_equ
 Weak pointer to equation system using this forcing. More...
 
Array< OneD, Array< OneD, NekDouble > > m_Forcing
 Evaluated forcing function. More...
 
int m_NumVariable
 Number of variables. More...
 
std::map< std::string, SolverUtils::SessionFunctionSharedPtrm_sessionFunctions
 Map of known SessionFunctions. More...
 

Detailed Description

Definition at line 60 of file ForcingMovingReferenceFrame.h.

Constructor & Destructor Documentation

◆ ForcingMovingReferenceFrame()

Nektar::SolverUtils::ForcingMovingReferenceFrame::ForcingMovingReferenceFrame ( const LibUtilities::SessionReaderSharedPtr pSession,
const std::weak_ptr< EquationSystem > &  pEquation 
)
private
Parameters
pSession
pEquation

Definition at line 68 of file ForcingMovingReferenceFrame.cpp.

71 : Forcing(pSession, pEquation)
72{
73}
SOLVER_UTILS_EXPORT Forcing(const LibUtilities::SessionReaderSharedPtr &pSession, const std::weak_ptr< EquationSystem > &pEquation)
Constructor.
Definition: Forcing.cpp:50

◆ ~ForcingMovingReferenceFrame()

virtual Nektar::SolverUtils::ForcingMovingReferenceFrame::~ForcingMovingReferenceFrame ( void  )
inlineprivatevirtual

Definition at line 156 of file ForcingMovingReferenceFrame.h.

156{};

Member Function Documentation

◆ addRotation()

void Nektar::SolverUtils::ForcingMovingReferenceFrame::addRotation ( int  npoints,
const Array< OneD, Array< OneD, NekDouble > > &  inarray0,
NekDouble  angVelScale,
const Array< OneD, Array< OneD, NekDouble > > &  inarray1,
Array< OneD, Array< OneD, NekDouble > > &  outarray 
)
private

outarray = inarray0 + angVelScale Omega x inarray1

Definition at line 434 of file ForcingMovingReferenceFrame.cpp.

439{
440 ASSERTL0(&inarray1 != &outarray, "inarray1 and outarray "
441 "should not be the same.");
442
443 // TODO: In case of having support for all three components of Omega,
444 // they should be transformed into the rotating frame first!
445
446 // In case that the inarray0 and outarry are different, to avoid using
447 // un-initialized array, copy the array first
448 if (&inarray0 != &outarray)
449 {
450 ASSERTL0(inarray0.size() == outarray.size(),
451 "inarray0 and outarray must have same dimentions");
452 for (int i = 0; i < inarray0.size(); ++i)
453 {
454 Vmath::Vcopy(nPnts, inarray0[i], 1, outarray[i], 1);
455 }
456 }
457
458 if (m_spacedim >= 2 && m_hasOmega[2])
459 {
460 NekDouble cp = m_omegaxyz[2] * angVelScale;
461 NekDouble cm = -1. * cp;
462
463 Vmath::Svtvp(nPnts, cm, inarray1[1], 1, outarray[0], 1, outarray[0], 1);
464 Vmath::Svtvp(nPnts, cp, inarray1[0], 1, outarray[1], 1, outarray[1], 1);
465 }
466
467 if (m_spacedim == 3 && m_hasOmega[0])
468 {
469 NekDouble cp = m_omegaxyz[0] * angVelScale;
470 NekDouble cm = -1. * cp;
471
472 Vmath::Svtvp(nPnts, cp, inarray1[1], 1, outarray[2], 1, outarray[2], 1);
473 Vmath::Svtvp(nPnts, cm, inarray1[2], 1, outarray[1], 1, outarray[1], 1);
474 }
475
476 if (m_spacedim == 3 && m_hasOmega[1])
477 {
478 NekDouble cp = m_omegaxyz[1] * angVelScale;
479 NekDouble cm = -1. * cp;
480
481 Vmath::Svtvp(nPnts, cp, inarray1[2], 1, outarray[0], 1, outarray[0], 1);
482 Vmath::Svtvp(nPnts, cm, inarray1[0], 1, outarray[2], 1, outarray[2], 1);
483 }
484}
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:215
double NekDouble
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
Definition: Vmath.cpp:617
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1191

References ASSERTL0, m_hasOmega, m_omegaxyz, m_spacedim, Vmath::Svtvp(), and Vmath::Vcopy().

Referenced by v_Apply(), and v_PreApply().

◆ CheckForRestartTheta()

void Nektar::SolverUtils::ForcingMovingReferenceFrame::CheckForRestartTheta ( const Array< OneD, MultiRegions::ExpListSharedPtr > &  pFields,
Array< OneD, NekDouble > &  theta 
)
private

Definition at line 542 of file ForcingMovingReferenceFrame.cpp.

545{
546 std::map<std::string, std::string> fieldMetaDataMap;
547
548 // initialize theta to zero
549 for (auto &t : theta)
550 {
551 t = 0.0;
552 }
553
554 if (m_session->DefinesFunction("InitialConditions"))
555 {
556 for (int i = 0; i < pFields.size(); ++i)
557 {
559
560 vType = m_session->GetFunctionType("InitialConditions",
561 m_session->GetVariable(i));
562
564 {
565 std::string filename = m_session->GetFunctionFilename(
566 "InitialConditions", m_session->GetVariable(i));
567
568 fs::path pfilename(filename);
569
570 // redefine path for parallel file which is in directory
571 if (fs::is_directory(pfilename))
572 {
573 fs::path metafile("Info.xml");
574 fs::path fullpath = pfilename / metafile;
575 filename = LibUtilities::PortablePath(fullpath);
576 }
579 fld->ImportFieldMetaData(filename, fieldMetaDataMap);
580
581 // check to see if theta is defined
582 if (fieldMetaDataMap != LibUtilities::NullFieldMetaDataMap)
583 {
584 std::vector<std::string> vSuffix = {"_x", "_y", "_z"};
585
586 for (int j = 0; j < 3; ++j)
587 {
588 std::string sTheta = "Theta" + vSuffix[j];
589 auto iter = fieldMetaDataMap.find(sTheta);
590 if (iter != fieldMetaDataMap.end())
591 {
592 theta[j] =
593 boost::lexical_cast<NekDouble>(iter->second);
594 }
595 }
596
597 break;
598 }
599
600 break;
601 }
602 }
603 }
604}
static std::shared_ptr< FieldIO > CreateForFile(const LibUtilities::SessionReaderSharedPtr session, const std::string &filename)
Construct a FieldIO object for a given input filename.
Definition: FieldIO.cpp:226
LibUtilities::SessionReaderSharedPtr m_session
Session reader.
Definition: Forcing.h:117
std::shared_ptr< FieldIO > FieldIOSharedPtr
Definition: FieldIO.h:327
std::string PortablePath(const boost::filesystem::path &path)
create portable path on different platforms for boost::filesystem path
Definition: FileSystem.cpp:45
static FieldMetaDataMap NullFieldMetaDataMap
Definition: FieldIO.h:53

References Nektar::LibUtilities::FieldIO::CreateForFile(), Nektar::LibUtilities::eFunctionTypeFile, Nektar::SolverUtils::Forcing::m_session, Nektar::LibUtilities::NullFieldMetaDataMap, and Nektar::LibUtilities::PortablePath().

Referenced by v_InitObject().

◆ create()

static SOLVER_UTILS_EXPORT ForcingSharedPtr Nektar::SolverUtils::ForcingMovingReferenceFrame::create ( const LibUtilities::SessionReaderSharedPtr pSession,
const std::weak_ptr< EquationSystem > &  pEquation,
const Array< OneD, MultiRegions::ExpListSharedPtr > &  pFields,
const unsigned int &  pNumForcingFields,
const TiXmlElement *  pForce 
)
inlinestatic

Creates an instance of this class.

Definition at line 67 of file ForcingMovingReferenceFrame.h.

72 {
75 pSession, pEquation);
76 p->InitObject(pFields, pNumForcingFields, pForce);
77 return p;
78 }
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
SOLVER_UTILS_EXPORT typedef std::shared_ptr< Forcing > ForcingSharedPtr
A shared pointer to an EquationSystem object.
Definition: Forcing.h:55

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), Nektar::SolverUtils::ForcingSharedPtr, and CellMLToNektar.cellml_metadata::p.

◆ Update()

void Nektar::SolverUtils::ForcingMovingReferenceFrame::Update ( const NekDouble time)
private

Updates the forcing array with the current required forcing.

Parameters
pFields
time

Definition at line 297 of file ForcingMovingReferenceFrame.cpp.

298{
299 // compute the velociites whos functions are provided in inertial frame
300 for (auto it : m_velFunction)
301 {
302 m_velXYZ[it.first] = it.second->Evaluate(0., 0., 0., time);
303 }
304 for (auto it : m_omegaFunction)
305 {
306 m_omegaXYZ[it.first] = it.second->Evaluate(0., 0., 0., time);
307 }
308 // include the effect of rotation
309 if (m_hasRotation)
310 {
311 UpdateTheta(time);
312
313 // transform the translation velocities to the moving frame
314 bn::ublas::vector<NekDouble> v0 = bn::ublas::zero_vector<NekDouble>(3);
315 bn::ublas::vector<NekDouble> v1 = bn::ublas::zero_vector<NekDouble>(3);
316 for (int i = 0; i < m_spacedim; ++i)
317 {
318 v0(i) = m_velXYZ[i];
319 }
320 v1 = bn::ublas::prec_prod(m_ProjMatZ, v0);
321 for (int i = 0; i < 3; ++i)
322 {
323 m_velxyz[i] = v1(i);
324 }
325
326 // transform the angular velocities to moving frame
327 v0 = bn::ublas::zero_vector<NekDouble>(3);
328 v1 = bn::ublas::zero_vector<NekDouble>(3);
329 for (auto it : m_omegaXYZ)
330 {
331 v0(it.first) = it.second;
332 }
333 v1 = bn::ublas::prec_prod(m_ProjMatZ, v0);
334 for (int i = 0; i < 3; ++i)
335 {
336 m_omegaxyz[i] = v1(i);
337 }
338 }
339 else
340 {
341 // for translation only,
342 for (int i = 0; i < m_spacedim; ++i)
343 {
344 m_velxyz[i] = m_velXYZ[i];
345 }
346 }
347
348 // set the velocities and rotation matrix for enforcement of boundary
349 // conditions in the Incompressible Naveri-Stokes
350 Array<OneD, NekDouble> vel(6, 0.0);
351 // save the linear and angular velocities to be used in enforcing bc
352 for (int i = 0; i < 3; ++i)
353 {
354 vel[i] = m_velxyz[i];
355 vel[i + 3] = m_omegaxyz[i];
356 }
357
358 auto equ = m_equ.lock();
359 ASSERTL0(equ, "Weak pointer to the equation system is expired");
360 auto FluidEq = std::dynamic_pointer_cast<FluidInterface>(equ);
361 // update the frame velocities
362 FluidEq->SetMovingFrameVelocities(vel);
363 // update the projection matrix
364 FluidEq->SetMovingFrameProjectionMat(m_ProjMatZ);
365 // update the frame angle (with respect to the inertial frame)
366 // this angle is used to update the meta data,
367 // on the other hand, for boundary conditions the projection matrix is used
368 FluidEq->SetMovingFrameAngles(m_theta);
369}
const std::weak_ptr< EquationSystem > m_equ
Weak pointer to equation system using this forcing.
Definition: Forcing.h:119
std::map< int, LibUtilities::EquationSharedPtr > m_omegaFunction
std::map< int, LibUtilities::EquationSharedPtr > m_velFunction

References ASSERTL0, Nektar::SolverUtils::Forcing::m_equ, m_hasRotation, m_omegaFunction, m_omegaXYZ, m_omegaxyz, m_ProjMatZ, m_spacedim, m_theta, m_velFunction, m_velXYZ, m_velxyz, and UpdateTheta().

Referenced by v_PreApply().

◆ UpdateTheta()

void Nektar::SolverUtils::ForcingMovingReferenceFrame::UpdateTheta ( const NekDouble time)
private

Definition at line 371 of file ForcingMovingReferenceFrame.cpp.

372{
373
374 NekDouble dt = m_session->GetParameter("TimeStep");
375 NekDouble t1 = time + dt;
376 std::map<int, NekDouble> Omega;
377
378 // Calculate angular velocities at dt
379 // TODO: Generalize to the case with a general 3D rotation support
380 for (int i = 0; i < 3; ++i)
381 {
382 if (m_hasOmega[i])
383 {
384 Omega[i] = 0.5 * (m_omegaXYZ[i] +
385 m_omegaFunction[i]->Evaluate(0., 0., 0., t1));
386 }
387 }
388
389 // Using the Omega_z
390 m_theta[2] += (Omega[2] * dt);
391
392 // update the rotation matrix
393 {
394 NekDouble sn, cs;
395 sn = sin(m_theta[2]);
396 cs = cos(m_theta[2]);
397
398 m_ProjMatZ(0, 0) = cs;
399 m_ProjMatZ(0, 1) = sn;
400 m_ProjMatZ(1, 0) = -sn;
401 m_ProjMatZ(1, 1) = cs;
402 m_ProjMatZ(2, 2) = 1.0;
403 }
404}
const NekDouble Omega

References m_hasOmega, m_omegaFunction, m_omegaXYZ, m_ProjMatZ, Nektar::SolverUtils::Forcing::m_session, m_theta, and Omega.

Referenced by Update().

◆ v_Apply()

void Nektar::SolverUtils::ForcingMovingReferenceFrame::v_Apply ( const Array< OneD, MultiRegions::ExpListSharedPtr > &  fields,
const Array< OneD, Array< OneD, NekDouble > > &  inarray,
Array< OneD, Array< OneD, NekDouble > > &  outarray,
const NekDouble time 
)
overrideprotectedvirtual

Adds the body force, -Omega X u.

Parameters
fields
inarray
outarray
time

Implements Nektar::SolverUtils::Forcing.

Definition at line 413 of file ForcingMovingReferenceFrame.cpp.

417{
418 boost::ignore_unused(time);
419 // If there is no rotation, body force is zero,
420 // nothing needs to be done here.
421 if (!m_hasRotation)
422 {
423 return;
424 }
425 // frame velocities are already updated in pre_Apply
426 int npoints = fields[0]->GetNpoints();
427 boost::ignore_unused(npoints);
428 addRotation(npoints, outarray, -1., inarray, outarray);
429}
void addRotation(int npoints, const Array< OneD, Array< OneD, NekDouble > > &inarray0, NekDouble angVelScale, const Array< OneD, Array< OneD, NekDouble > > &inarray1, Array< OneD, Array< OneD, NekDouble > > &outarray)
outarray = inarray0 + angVelScale Omega x inarray1

References addRotation(), and m_hasRotation.

◆ v_InitObject()

void Nektar::SolverUtils::ForcingMovingReferenceFrame::v_InitObject ( const Array< OneD, MultiRegions::ExpListSharedPtr > &  pFields,
const unsigned int &  pNumForcingFields,
const TiXmlElement *  pForce 
)
overrideprotectedvirtual

Initialise the forcing module.

Parameters
pFields
pNumForcingFields
pForce

Implements Nektar::SolverUtils::Forcing.

Definition at line 81 of file ForcingMovingReferenceFrame.cpp.

84{
85 boost::ignore_unused(pNumForcingFields);
86 m_session->MatchSolverInfo("Homogeneous", "1D", m_isH1d, false);
87 m_session->MatchSolverInfo("Homogeneous", "2D", m_isH2d, false);
88 bool singleMode, halfMode;
89 m_session->MatchSolverInfo("ModeType", "SingleMode", singleMode, false);
90 m_session->MatchSolverInfo("ModeType", "HalfMode", halfMode, false);
91 if (singleMode || halfMode)
92 {
93 m_isH1d = false;
94 }
95
96 int npoints = pFields[0]->GetNpoints();
97 int expdim = m_isH2d ? 1 : pFields[0]->GetGraph()->GetMeshDimension();
98 m_spacedim = expdim + (m_isH1d ? 1 : 0) + (m_isH2d ? 2 : 0);
100
101 m_hasPlane0 = true;
102 if (m_isH1d)
103 {
104 m_hasPlane0 = pFields[0]->GetZIDs()[0] == 0;
105 }
106
107 // linear velocities
108 const TiXmlElement *funcNameElmt;
109
110 funcNameElmt = pForce->FirstChildElement("LinearVelocity");
111 ASSERTL0(funcNameElmt, "Requires LinearVelocity tag specifying function "
112 "name which prescribes velocity of the moving "
113 "frame.");
114
115 m_velFuncName = funcNameElmt->GetText();
116 ASSERTL0(m_session->DefinesFunction(m_velFuncName),
117 "Function '" + m_velFuncName + "' is not defined in the session.");
118
119 // angular velocities
120 // Initiate the rotation to false, will be updated later if rotation defined
121 m_hasRotation = false;
122 funcNameElmt = pForce->FirstChildElement("AngularVelocity");
123 if (funcNameElmt)
124 {
125 m_omegaFuncName = funcNameElmt->GetText();
126 ASSERTL0(m_session->DefinesFunction(m_omegaFuncName),
127 "Function '" + m_omegaFuncName +
128 "' is not defined in the session.");
129 m_hasRotation = true;
130 }
131
132 // initiate the linear velocity values in both local and inertial frames
133 for (int i = 0; i < 3; ++i)
134 {
135 m_velXYZ[i] = 0.;
136 m_velxyz[i] = 0.;
137 }
138
139 // initiate the angular velocity values in both local and inertial frames
140 for (int i = 0; i < 3; ++i)
141 {
142 m_omegaXYZ[i] = 0;
143 m_omegaxyz[i] = 0;
144 }
145
146 // initiate the available frame velocities all to false
147 // this will be updated after reading the frame velocities and checking
148 // for the rotation
149 for (int i = 0; i < 3; ++i)
150 {
151 m_hasVel[i] = false;
152 m_hasOmega[i] = false;
153 }
154
155 // initiate the rotation angle to zero
156 // m_theta = {theta_X, theta_Y, theta_Z}
157 m_theta = Array<OneD, NekDouble>(3, 0.0);
158
159 // initialize theta from the metadata of restart file or zero
161
162 // Initialize theta with the data from NS class
163 // This ensure correct moving coordinate orientation with respect to the
164 // stationary inertial frame when we restart the simulation
165 auto equ = m_equ.lock();
166 ASSERTL0(equ, "Weak pointer to the equation system is expired");
167 auto FluidEq = std::dynamic_pointer_cast<FluidInterface>(equ);
168 // Set the angles
169 FluidEq->SetMovingFrameAngles(m_theta);
170
171 // initiate the rotation matrix to zero,
172 // Note that the rotation matrix is assumed for the rotation around z axis
173 // TODO: Generalize this for the 3D case with possiblity of rotation around
174 // each of axis. Probabley we only can support rotation around one axis. In
175 // that case the generalization means the user can provide Omega for one of
176 // x, y or z axis. Not sure how complicated to consider a general axis of
177 // rotation
178 //
179 // Note that these rotation matrices should be extrinsic rotations
180 m_ProjMatX = bn::ublas::zero_matrix<NekDouble>(3, 3);
181 m_ProjMatY = bn::ublas::zero_matrix<NekDouble>(3, 3);
182 m_ProjMatZ = bn::ublas::zero_matrix<NekDouble>(3, 3);
183 // populate the rotation matrix R(z)
184 {
185 NekDouble sn, cs;
186 sn = sin(m_theta[2]);
187 cs = cos(m_theta[2]);
188
189 m_ProjMatZ(0, 0) = cs;
190 m_ProjMatZ(0, 1) = sn;
191 m_ProjMatZ(1, 0) = -1. * sn;
192 m_ProjMatZ(1, 1) = cs;
193 m_ProjMatZ(2, 2) = 1.0;
194 }
195
196 // frame linear velocity
197 for (int i = 0; i < m_spacedim; ++i)
198 {
199 std::string s_FieldStr = m_session->GetVariable(i);
200
201 if (m_session->DefinesFunction(m_velFuncName, s_FieldStr))
202 {
203 m_velFunction[i] =
204 m_session->GetFunction(m_velFuncName, s_FieldStr);
205 m_hasVel[i] = true;
206 }
207 }
208 if (expdim == 1)
209 {
210 return;
211 }
212
213 // initialize the poivot coordinate with a default at origin
214 m_pivotPoint = Array<OneD, NekDouble>(3, 0.0);
215 if (m_hasRotation)
216 {
217 // frame angular velocity
218 std::vector<std::string> angularVar = {"Omega_x", "Omega_y", "Omega_z"};
219 for (int i = 0; i < 3; ++i)
220 {
221 std::string s_FieldStr = angularVar[i];
222 if (m_session->DefinesFunction(m_omegaFuncName, s_FieldStr))
223 {
224 // m_hasRotation = true;
225 m_omegaFunction[i] =
226 m_session->GetFunction(m_omegaFuncName, s_FieldStr);
227 m_hasOmega[i] = true;
228 // m_hasVel[m_spacedim+i]=true;
229 }
230 }
231
232 // for now only support Omega_z
233 // TODO: add the support for general rotation
234 for (int i = 0; i < 2; ++i)
235 {
236 ASSERTL0(!m_hasOmega[i], "Currently only Omega_z is supported");
237 }
238
239 // Reading the pivot point coordinate for rotation
240 const TiXmlElement *pivotElmt = pForce->FirstChildElement("PivotPoint");
241 // if not defined, zero would be the default
242 if (pivotElmt)
243 {
244 std::stringstream pivotPointStream;
245 std::string pivotPointStr = pivotElmt->GetText();
246 pivotPointStream.str(pivotPointStr);
247
248 for (int j = 0; j < m_spacedim; ++j)
249 {
250 pivotPointStream >> pivotPointStr;
251 if (!pivotPointStr.empty())
252 {
253 LibUtilities::Equation equ(m_session->GetInterpreter(),
254 pivotPointStr);
255 m_pivotPoint[j] = equ.Evaluate();
256 }
257 }
258 }
259
260 m_coords = Array<OneD, Array<OneD, NekDouble>>(3);
261 for (int j = 0; j < m_spacedim; ++j)
262 {
263 m_coords[j] = Array<OneD, NekDouble>(npoints);
264 }
265 pFields[0]->GetCoords(m_coords[0], m_coords[1], m_coords[2]);
266 // move the origin to the pivot point
267 for (int i = 0; i < m_spacedim; ++i)
268 {
269 Vmath::Sadd(npoints, -m_pivotPoint[i], m_coords[i], 1, m_coords[i],
270 1);
271 }
272
273 // account for the effect of rotation
274 // Omega_X results in having v and w even if not defined by user
275 // Omega_Y results in having u and w even if not defined by user
276 // Omega_Z results in having u and v even if not defined by user
277 //
278 for (int i = 0; i < 3; ++i)
279 {
280 int j = (i + 1) % 3;
281 int k = (i + 2) % 3;
282
283 if (m_hasOmega[i])
284 {
285 m_hasVel[j] = true;
286 m_hasVel[k] = true;
287 }
288 }
289 }
290}
int m_NumVariable
Number of variables.
Definition: Forcing.h:123
void CheckForRestartTheta(const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, Array< OneD, NekDouble > &theta)
void Sadd(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Add scalar y = alpha + x.
Definition: Vmath.cpp:379

References ASSERTL0, CheckForRestartTheta(), Nektar::LibUtilities::Equation::Evaluate(), m_coords, Nektar::SolverUtils::Forcing::m_equ, m_hasOmega, m_hasPlane0, m_hasRotation, m_hasVel, m_isH1d, m_isH2d, Nektar::SolverUtils::Forcing::m_NumVariable, m_omegaFuncName, m_omegaFunction, m_omegaXYZ, m_omegaxyz, m_pivotPoint, m_ProjMatX, m_ProjMatY, m_ProjMatZ, Nektar::SolverUtils::Forcing::m_session, m_spacedim, m_theta, m_velFuncName, m_velFunction, m_velXYZ, m_velxyz, and Vmath::Sadd().

◆ v_PreApply()

void Nektar::SolverUtils::ForcingMovingReferenceFrame::v_PreApply ( const Array< OneD, MultiRegions::ExpListSharedPtr > &  fields,
const Array< OneD, Array< OneD, NekDouble > > &  inarray,
Array< OneD, Array< OneD, NekDouble > > &  outarray,
const NekDouble time 
)
overrideprotectedvirtual

Reimplemented from Nektar::SolverUtils::Forcing.

Definition at line 486 of file ForcingMovingReferenceFrame.cpp.

490{
491 Update(time);
492 int npoints = fields[0]->GetNpoints();
493 if (m_isH2d && fields[0]->GetWaveSpace())
494 {
495 for (int i = 0; i < m_spacedim; ++i)
496 {
497 if (m_hasVel[i])
498 {
499 Array<OneD, NekDouble> tmpphys(npoints, -m_velxyz[i]);
500 Array<OneD, NekDouble> tmpcoef(npoints);
501 fields[0]->HomogeneousFwdTrans(npoints, tmpphys, tmpcoef);
502 Vmath::Vadd(npoints, tmpcoef, 1, inarray[i], 1, outarray[i], 1);
503 }
504 else if (&inarray != &outarray)
505 {
506 Vmath::Vcopy(npoints, inarray[i], 1, outarray[i], 1);
507 }
508 }
509 }
510 else
511 {
512 int npoints0 = npoints;
513 if (m_isH1d && fields[0]->GetWaveSpace())
514 {
515 npoints0 = m_hasPlane0 ? fields[0]->GetPlane(0)->GetNpoints() : 0;
516 }
517 for (int i = 0; i < m_spacedim; ++i)
518 {
519 if (m_hasVel[i])
520 {
521 Vmath::Sadd(npoints0, -m_velxyz[i], inarray[i], 1, outarray[i],
522 1);
523 if (&inarray != &outarray && npoints != npoints0)
524 {
525 Array<OneD, NekDouble> tmp = outarray[i] + npoints0;
526 Vmath::Vcopy(npoints - npoints0, inarray[i] + npoints0, 1,
527 tmp, 1);
528 }
529 }
530 else if (&inarray != &outarray)
531 {
532 Vmath::Vcopy(npoints, inarray[i], 1, outarray[i], 1);
533 }
534 }
535 if (m_hasRotation)
536 {
537 addRotation(npoints0, outarray, -1., m_coords, outarray);
538 }
539 }
540}
void Update(const NekDouble &time)
Updates the forcing array with the current required forcing.
void Vadd(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Add vector z = x+y.
Definition: Vmath.cpp:354

References addRotation(), m_coords, m_hasPlane0, m_hasRotation, m_hasVel, m_isH1d, m_isH2d, m_spacedim, m_velxyz, Vmath::Sadd(), Update(), Vmath::Vadd(), and Vmath::Vcopy().

Friends And Related Function Documentation

◆ MemoryManager< ForcingMovingReferenceFrame >

Definition at line 1 of file ForcingMovingReferenceFrame.h.

Member Data Documentation

◆ classNameBody

std::string Nektar::SolverUtils::ForcingMovingReferenceFrame::classNameBody
static
Initial value:
=
"MovingReferenceFrame", ForcingMovingReferenceFrame::create,
"Moving Frame")
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:198
static SOLVER_UTILS_EXPORT ForcingSharedPtr create(const LibUtilities::SessionReaderSharedPtr &pSession, const std::weak_ptr< EquationSystem > &pEquation, const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const unsigned int &pNumForcingFields, const TiXmlElement *pForce)
Creates an instance of this class.
ForcingFactory & GetForcingFactory()
Declaration of the forcing factory singleton.
Definition: Forcing.cpp:44

Name of the class.

Definition at line 81 of file ForcingMovingReferenceFrame.h.

◆ m_coords

Array<OneD, Array<OneD, NekDouble> > Nektar::SolverUtils::ForcingMovingReferenceFrame::m_coords
private

Definition at line 132 of file ForcingMovingReferenceFrame.h.

Referenced by v_InitObject(), and v_PreApply().

◆ m_frameFunction

std::map<int, LibUtilities::EquationSharedPtr> Nektar::SolverUtils::ForcingMovingReferenceFrame::m_frameFunction
private

Definition at line 109 of file ForcingMovingReferenceFrame.h.

◆ m_funcName

std::string Nektar::SolverUtils::ForcingMovingReferenceFrame::m_funcName
private

Definition at line 104 of file ForcingMovingReferenceFrame.h.

◆ m_hasOmega

std::map<int, bool> Nektar::SolverUtils::ForcingMovingReferenceFrame::m_hasOmega
private

Definition at line 118 of file ForcingMovingReferenceFrame.h.

Referenced by addRotation(), UpdateTheta(), and v_InitObject().

◆ m_hasPlane0

bool Nektar::SolverUtils::ForcingMovingReferenceFrame::m_hasPlane0
private

Definition at line 148 of file ForcingMovingReferenceFrame.h.

Referenced by v_InitObject(), and v_PreApply().

◆ m_hasRotation

bool Nektar::SolverUtils::ForcingMovingReferenceFrame::m_hasRotation
private

Definition at line 146 of file ForcingMovingReferenceFrame.h.

Referenced by Update(), v_Apply(), v_InitObject(), and v_PreApply().

◆ m_hasVel

std::map<int, bool> Nektar::SolverUtils::ForcingMovingReferenceFrame::m_hasVel
private

Definition at line 117 of file ForcingMovingReferenceFrame.h.

Referenced by v_InitObject(), and v_PreApply().

◆ m_isH1d

bool Nektar::SolverUtils::ForcingMovingReferenceFrame::m_isH1d
private

Definition at line 147 of file ForcingMovingReferenceFrame.h.

Referenced by v_InitObject(), and v_PreApply().

◆ m_isH2d

bool Nektar::SolverUtils::ForcingMovingReferenceFrame::m_isH2d
private

Definition at line 149 of file ForcingMovingReferenceFrame.h.

Referenced by v_InitObject(), and v_PreApply().

◆ m_omegaFuncName

std::string Nektar::SolverUtils::ForcingMovingReferenceFrame::m_omegaFuncName
private

Definition at line 106 of file ForcingMovingReferenceFrame.h.

Referenced by v_InitObject().

◆ m_omegaFunction

std::map<int, LibUtilities::EquationSharedPtr> Nektar::SolverUtils::ForcingMovingReferenceFrame::m_omegaFunction
private

Definition at line 111 of file ForcingMovingReferenceFrame.h.

Referenced by Update(), UpdateTheta(), and v_InitObject().

◆ m_omegaXYZ

std::map<int, NekDouble> Nektar::SolverUtils::ForcingMovingReferenceFrame::m_omegaXYZ
private

Definition at line 127 of file ForcingMovingReferenceFrame.h.

Referenced by Update(), UpdateTheta(), and v_InitObject().

◆ m_omegaxyz

std::map<int, NekDouble> Nektar::SolverUtils::ForcingMovingReferenceFrame::m_omegaxyz
private

Definition at line 130 of file ForcingMovingReferenceFrame.h.

Referenced by addRotation(), Update(), and v_InitObject().

◆ m_pivotPoint

Array<OneD, NekDouble> Nektar::SolverUtils::ForcingMovingReferenceFrame::m_pivotPoint
private

Definition at line 135 of file ForcingMovingReferenceFrame.h.

Referenced by v_InitObject().

◆ m_ProjMatX

bn::ublas::matrix<NekDouble> Nektar::SolverUtils::ForcingMovingReferenceFrame::m_ProjMatX
private

Definition at line 142 of file ForcingMovingReferenceFrame.h.

Referenced by v_InitObject().

◆ m_ProjMatY

bn::ublas::matrix<NekDouble> Nektar::SolverUtils::ForcingMovingReferenceFrame::m_ProjMatY
private

Definition at line 143 of file ForcingMovingReferenceFrame.h.

Referenced by v_InitObject().

◆ m_ProjMatZ

bn::ublas::matrix<NekDouble> Nektar::SolverUtils::ForcingMovingReferenceFrame::m_ProjMatZ
private

Definition at line 144 of file ForcingMovingReferenceFrame.h.

Referenced by Update(), UpdateTheta(), and v_InitObject().

◆ m_spacedim

NekInt Nektar::SolverUtils::ForcingMovingReferenceFrame::m_spacedim
private

Definition at line 150 of file ForcingMovingReferenceFrame.h.

Referenced by addRotation(), Update(), v_InitObject(), and v_PreApply().

◆ m_theta

Array<OneD, NekDouble> Nektar::SolverUtils::ForcingMovingReferenceFrame::m_theta
private

Definition at line 138 of file ForcingMovingReferenceFrame.h.

Referenced by Update(), UpdateTheta(), and v_InitObject().

◆ m_velFuncName

std::string Nektar::SolverUtils::ForcingMovingReferenceFrame::m_velFuncName
private

Definition at line 105 of file ForcingMovingReferenceFrame.h.

Referenced by v_InitObject().

◆ m_velFunction

std::map<int, LibUtilities::EquationSharedPtr> Nektar::SolverUtils::ForcingMovingReferenceFrame::m_velFunction
private

Definition at line 110 of file ForcingMovingReferenceFrame.h.

Referenced by Update(), and v_InitObject().

◆ m_velXYZ

std::map<int, NekDouble> Nektar::SolverUtils::ForcingMovingReferenceFrame::m_velXYZ
private

Definition at line 121 of file ForcingMovingReferenceFrame.h.

Referenced by Update(), and v_InitObject().

◆ m_velxyz

std::map<int, NekDouble> Nektar::SolverUtils::ForcingMovingReferenceFrame::m_velxyz
private

Definition at line 124 of file ForcingMovingReferenceFrame.h.

Referenced by Update(), v_InitObject(), and v_PreApply().