20using namespace navier;
24 int element_subdivisions = 1;
26 real_t kinvis = 1.0 / 1600.0;
27 real_t t_final = 10 * 1e-3;
31 bool visualization =
false;
32 bool checkres =
false;
41 u(0) = sin(xi) * cos(yi) * cos(zi);
42 u(1) = -cos(xi) * sin(yi) * cos(zi);
46class QuantitiesOfInterest
49 QuantitiesOfInterest(
ParMesh *pmesh)
60 one_gf.ProjectCoefficient(onecoeff);
62 volume = mass_lf->operator()(one_gf);
73 for (
int i = 0; i < fes->
GetNE(); i++)
89 real_t vel2 = velx(j) * velx(j) + vely(j) * vely(j)
96 real_t global_integral = 0.0;
104 return 0.5 * global_integral / volume;
107 ~QuantitiesOfInterest() {
delete mass_lf; };
144 for (
int e = 0; e < fes->
GetNE(); ++e)
148 u.GetSubVector(v_dofs, loc_data);
156 for (
int dof = 0; dof < elndofs; ++dof)
160 tr->SetIntPoint(&ip);
167 MultAtB(loc_data_mat, dshape, grad_hat);
171 Mult(grad_hat, Jinv, grad);
173 real_t q_val = 0.5 * (
sq(grad(0, 0)) +
sq(grad(1, 1)) +
sq(grad(2, 2)))
174 + grad(0, 1) * grad(1, 0) + grad(0, 2) * grad(2, 0)
175 + grad(1, 2) * grad(2, 1);
181 for (
int j = 0; j < dofs.
Size(); j++)
185 zones_per_vdof[ldof]++;
194 gcomm.
Bcast(zones_per_vdof);
201 for (
int i = 0; i < q.
Size(); i++)
203 const int nz = zones_per_vdof[i];
211int main(
int argc,
char *argv[])
219 "--element-subdivisions",
220 "Number of 1d uniform subdivisions for each element.");
224 "Order (degree) of the finite elements.");
225 args.
AddOption(&
ctx.dt,
"-dt",
"--time-step",
"Time step.");
226 args.
AddOption(&
ctx.t_final,
"-tf",
"--final-time",
"Final time.");
232 "Enable partial assembly.");
238 "Enable numerical integration rules.");
243 "--no-visualization",
244 "Enable or disable GLVis visualization.");
251 "Enable or disable checking of the result. Returns -1 on failure.");
266 Mesh orig_mesh(
"../../data/periodic-cube.mesh");
275 int nel = mesh.
GetNE();
278 mfem::out <<
"Number of elements: " << nel << std::endl;
281 auto *pmesh =
new ParMesh(MPI_COMM_WORLD, mesh);
297 bool last_step =
false;
299 flowsolver.
Setup(dt);
309 QuantitiesOfInterest kin_energy(pmesh);
327 real_t ke = kin_energy.ComputeKineticEnergy(*u_gf);
329 std::string fname =
"tgv_out_p_" + std::to_string(
ctx.order) +
".txt";
334 int nel1d =
static_cast<int>(std::round(pow(nel, 1.0 / 3.0)));
336 printf(
"%11s %11s %11s %11s %11s\n",
"Time",
"dt",
"u_inf",
"p_inf",
"ke");
337 printf(
"%.5E %.5E %.5E %.5E %.5E\n",
t, dt, u_inf, p_inf, ke);
339 f = fopen(fname.c_str(),
"w");
340 fprintf(
f,
"3D Taylor Green Vortex\n");
341 fprintf(
f,
"order = %d\n",
ctx.order);
342 fprintf(
f,
"grid = %d x %d x %d\n", nel1d, nel1d, nel1d);
343 fprintf(
f,
"dofs per component = %d\n", ngridpts);
344 fprintf(
f,
"=================================================\n");
345 fprintf(
f,
" time kinetic energy\n");
346 fprintf(
f,
"%20.16e %20.16e\n",
t, ke);
351 for (
int step = 0; !last_step; ++step)
353 if (
t + dt >= t_final - dt / 2)
358 flowsolver.
Step(
t, dt, step);
360 if ((step + 1) % 100 == 0 || last_step)
373 ke = kin_energy.ComputeKineticEnergy(*u_gf);
376 printf(
"%.5E %.5E %.5E %.5E %.5E\n",
t, dt, u_inf, p_inf, ke);
377 fprintf(
f,
"%20.16e %20.16e\n",
t, ke);
389 real_t ke_expected = 1.25e-1;
390 if (fabs(ke - ke_expected) > tol)
394 mfem::out <<
"Result has a larger error than expected."
void SetSize(int nsize)
Change the logical size of the array, keep existing entries.
int Size() const
Return the logical size of the array.
@ ClosedUniform
Nodes: x_i = i/(n-1), i=0,...,n-1.
A coefficient that is constant across space and time.
virtual void RegisterField(const std::string &field_name, GridFunction *gf)
Add a grid function to the collection.
void SetCycle(int c)
Set time cycle (for time-dependent simulations)
void SetTime(real_t t)
Set physical time (for time-dependent simulations)
Data type dense matrix using column-major storage.
void SetSize(int s)
Change the size of the DenseMatrix to s x s.
Class for domain integration .
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
ElementTransformation * GetElementTransformation(int i) const
Returns ElementTransformation for the i-th element.
DofTransformation * GetElementVDofs(int i, Array< int > &vdofs) const
Returns indices of degrees of freedom for the i'th element. The returned indices are offsets into an ...
virtual const FiniteElement * GetFE(int i) const
Returns pointer to the FiniteElement in the FiniteElementCollection associated with i'th element in t...
int GetNE() const
Returns number of elements in the mesh.
int GetVSize() const
Return the number of vector dofs, i.e. GetNDofs() x GetVDim().
int GetVDim() const
Returns vector dimension.
Abstract class for all finite elements.
int GetOrder() const
Returns the order of the finite element. In the case of anisotropic orders, returns the maximum order...
int GetDim() const
Returns the reference space dimension for the finite element.
const IntegrationRule & GetNodes() const
Get a const reference to the nodes of the element.
virtual void CalcDShape(const IntegrationPoint &ip, DenseMatrix &dshape) const =0
Evaluate the gradients of all shape functions of a scalar finite element in reference space at the gi...
Geometry::Type GetGeomType() const
Returns the Geometry::Type of the reference element.
int GetDof() const
Returns the number of degrees of freedom in the finite element.
Class for grid function - Vector with associated FE space.
void GetValues(int i, const IntegrationRule &ir, Vector &vals, int vdim=1) const
FiniteElementSpace * FESpace()
Communicator performing operations within groups defined by a GroupTopology with arbitrary-size data ...
void Reduce(T *ldata, void(*Op)(OpData< T >)) const
Reduce within each group where the master is the root.
static void Sum(OpData< T >)
Reduce operation Sum, instantiated for int and double.
void Bcast(T *ldata, int layout) const
Broadcast within each group where the master is the root.
Arbitrary order H1-conforming (continuous) finite elements.
static void Init()
Initialize hypre by calling HYPRE_Init() and set default options. After calling Hypre::Init(),...
Class for integration point with weight.
Class for an integration rule - an Array of IntegrationPoint.
int GetNPoints() const
Returns the number of the points in the integration rule.
IntegrationPoint & IntPoint(int i)
Returns a reference to the i-th integration point.
const IntegrationRule & Get(int GeomType, int Order)
Returns an integration rule for given GeomType and Order.
void EnsureNodes()
Make sure that the mesh has valid nodes, i.e. its geometry is described by a vector finite element gr...
void Clear()
Clear the contents of the Mesh.
int GetNE() const
Returns number of elements.
int Dimension() const
Dimension of the reference space used within the elements.
static Mesh MakeRefined(Mesh &orig_mesh, int ref_factor, int ref_type)
Create a refined (by any factor) version of orig_mesh.
void GetNodes(Vector &node_coord) const
static bool Root()
Return true if the rank in MPI_COMM_WORLD is zero.
static void Init(int &argc, char **&argv, int required=default_thread_required, int *provided=nullptr)
Singleton creation with Mpi::Init(argc, argv).
int Height() const
Get the height (size of output) of the Operator. Synonym with NumRows().
int Width() const
Get the width (size of input) of the Operator. Synonym with NumCols().
void Parse()
Parse the command-line options. Note that this function expects all the options provided through the ...
void PrintUsage(std::ostream &out) const
Print the usage message.
void PrintOptions(std::ostream &out) const
Print the options.
void AddOption(bool *var, const char *enable_short_name, const char *enable_long_name, const char *disable_short_name, const char *disable_long_name, const char *description, bool required=false)
Add a boolean option and set 'var' to receive the value. Enable/disable tags are used to set the bool...
bool Good() const
Return true if the command line options were parsed successfully.
Abstract parallel finite element space.
HYPRE_BigInt GlobalVSize() const
GroupCommunicator & GroupComm()
Return a reference to the internal GroupCommunicator (on VDofs)
Class for parallel grid function.
ParFiniteElementSpace * ParFESpace() const
void ProjectCoefficient(Coefficient &coeff) override
Project coeff Coefficient to this GridFunction. The projection computation depends on the choice of t...
Class for parallel meshes.
Helper class for ParaView visualization data.
void SetHighOrderOutput(bool high_order_output_)
void SetLevelsOfDetail(int levels_of_detail_)
virtual void Save() override
void SetDataFormat(VTKFormat fmt)
A general vector function coefficient.
real_t Normlinf() const
Returns the l_infinity norm of the vector.
int Size() const
Returns the size of the vector.
void SetSize(int s)
Resize the vector to size s.
real_t * GetData() const
Return a pointer to the beginning of the Vector data.
Transient incompressible Navier Stokes solver in a split scheme formulation.
void Setup(real_t dt)
Initialize forms, solvers and preconditioners.
ParGridFunction * GetCurrentPressure()
Return a pointer to the current pressure ParGridFunction.
void PrintTimingData()
Print timing summary of the solving routine.
void EnablePA(bool pa)
Enable partial assembly for every operator.
ParGridFunction * GetCurrentVelocity()
Return a pointer to the current velocity ParGridFunction.
void Step(real_t &time, real_t dt, int cur_step, bool provisional=false)
Compute solution at the next time step t+dt.
void ComputeCurl3D(ParGridFunction &u, ParGridFunction &cu)
Compute for .
real_t infinity()
Define a shortcut for std::numeric_limits<double>::infinity()
real_t u(const Vector &xvec)
void Mult(const Table &A, const Table &B, Table &C)
C = A * B (as boolean matrices)
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
real_t GlobalLpNorm(const real_t p, real_t loc_norm, MPI_Comm comm)
Compute a global Lp norm from the local Lp norms computed by each processor.
ComplexDenseMatrix * MultAtB(const ComplexDenseMatrix &A, const ComplexDenseMatrix &B)
Multiply the complex conjugate transpose of a matrix A with a matrix B. A^H*B.
std::function< real_t(const Vector &)> f(real_t mass_coeff)
IntegrationRules IntRules(0, Quadrature1D::GaussLegendre)
A global object with all integration rules (defined in intrules.cpp)
void vel_tgv(const Vector &x, real_t t, Vector &u)
void ComputeQCriterion(ParGridFunction &u, ParGridFunction &q)
struct s_NavierContext ctx
Helper struct to convert a C++ type to an MPI type.