20 using namespace navier;
22 struct s_NavierContext
24 int element_subdivisions = 1;
26 double kinvis = 1.0 / 1600.0;
27 double 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);
46 class QuantitiesOfInterest
49 QuantitiesOfInterest(
ParMesh *pmesh)
54 onecoeff.constant = 1.0;
60 one_gf.ProjectCoefficient(onecoeff);
62 volume = mass_lf->operator()(one_gf);
73 for (
int i = 0; i < fes->
GetNE(); i++)
89 double vel2 = velx(j) * velx(j) + vely(j) * vely(j)
92 integ += ip.
weight * T->Weight() * vel2;
96 double 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)
167 MultAtB(loc_data_mat, dshape, grad_hat);
171 Mult(grad_hat, Jinv, grad);
173 double 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];
211 int 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);
296 double t_final =
ctx.t_final;
297 bool last_step =
false;
299 flowsolver.
Setup(dt);
309 QuantitiesOfInterest kin_energy(pmesh);
323 double u_inf_loc = u_gf->
Normlinf();
324 double p_inf_loc = p_gf->
Normlinf();
327 double 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 double ke_expected = 1.25e-1;
390 if (fabs(ke - ke_expected) > tol)
394 mfem::out <<
"Result has a larger error than expected." Abstract class for all finite elements.
void PrintTimingData()
Print timing summary of the solving routine.
Class for domain integration L(v) := (f, v)
static void Init()
Initialize hypre by calling HYPRE_Init() and set default options. After calling Hypre::Init(), hypre will be finalized automatically at program exit.
int GetNPoints() const
Returns the number of the points in the integration rule.
Class for an integration rule - an Array of IntegrationPoint.
Class for grid function - Vector with associated FE space.
void vel_tgv(const Vector &x, double t, Vector &u)
void SetCycle(int c)
Set time cycle (for time-dependent simulations)
const IntegrationRule & Get(int GeomType, int Order)
Returns an integration rule for given GeomType and Order.
void SetDataFormat(VTKFormat fmt)
A coefficient that is constant across space and time.
void PrintOptions(std::ostream &out) const
Print the options.
int Dimension() const
Dimension of the reference space used within the elements.
void Bcast(T *ldata, int layout) const
Broadcast within each group where the master is the root.
void SetSize(int s)
Resize the vector to size s.
Helper class for ParaView visualization data.
void PrintUsage(std::ostream &out) const
Print the usage message.
void Mult(const Table &A, const Table &B, Table &C)
C = A * B (as boolean matrices)
int Width() const
Get the width (size of input) of the Operator. Synonym with NumCols().
static Mesh MakeRefined(Mesh &orig_mesh, int ref_factor, int ref_type)
Create a refined (by any factor) version of orig_mesh.
int Size() const
Returns the size of the vector.
Data type dense matrix using column-major storage.
bool Good() const
Return true if the command line options were parsed successfully.
Abstract parallel finite element space.
virtual void ProjectCoefficient(Coefficient &coeff)
Project coeff Coefficient to this GridFunction. The projection computation depends on the choice of t...
virtual const FiniteElement * GetFE(int i) const
Returns pointer to the FiniteElement in the FiniteElementCollection associated with i'th element in t...
IntegrationRules IntRules(0, Quadrature1D::GaussLegendre)
A global object with all integration rules (defined in intrules.cpp)
void Setup(double dt)
Initialize forms, solvers and preconditioners.
std::function< double(const Vector &)> f(double mass_coeff)
Geometry::Type GetGeomType() const
Returns the Geometry::Type of the reference element.
IntegrationPoint & IntPoint(int i)
Returns a reference to the i-th integration point.
void ComputeCurl3D(ParGridFunction &u, ParGridFunction &cu)
Compute for .
Communicator performing operations within groups defined by a GroupTopology with arbitrary-size data ...
virtual void RegisterField(const std::string &field_name, GridFunction *gf)
Add a grid function to the collection.
void GetValues(int i, const IntegrationRule &ir, Vector &vals, int vdim=1) const
static void Sum(OpData< T >)
Reduce operation Sum, instantiated for int and double.
void Parse()
Parse the command-line options. Note that this function expects all the options provided through the ...
int main(int argc, char *argv[])
ParGridFunction * GetCurrentPressure()
Return a pointer to the current pressure ParGridFunction.
struct s_NavierContext ctx
void EnablePA(bool pa)
Enable partial assembly for every operator.
void SetHighOrderOutput(bool high_order_output_)
static void Init()
Singleton creation with Mpi::Init();.
FiniteElementSpace * FESpace()
void SetTime(double t)
Set physical time (for time-dependent simulations)
int GetNE() const
Returns number of elements in the mesh.
double * GetData() const
Return a pointer to the beginning of the Vector data.
static bool Root()
Return true if the rank in MPI_COMM_WORLD is zero.
int GetVDim() const
Returns vector dimension.
A general vector function coefficient.
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 ...
double GlobalLpNorm(const double p, double loc_norm, MPI_Comm comm)
Compute a global Lp norm from the local Lp norms computed by each processor.
int GetDim() const
Returns the reference space dimension for the finite element.
ComplexDenseMatrix * MultAtB(const ComplexDenseMatrix &A, const ComplexDenseMatrix &B)
Multiply the complex conjugate transpose of a matrix A with a matrix B. A^H*B.
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
HYPRE_BigInt GlobalVSize() const
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
ParFiniteElementSpace * ParFESpace() const
void ComputeQCriterion(ParGridFunction &u, ParGridFunction &q)
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...
void SetSize(int nsize)
Change the logical size of the array, keep existing entries.
GroupCommunicator & GroupComm()
Return a reference to the internal GroupCommunicator (on VDofs)
int GetDof() const
Returns the number of degrees of freedom in the finite element.
ParGridFunction * GetCurrentVelocity()
Return a pointer to the current velocity ParGridFunction.
int Height() const
Get the height (size of output) of the Operator. Synonym with NumRows().
int GetNE() const
Returns number of elements.
Class for integration point with weight.
void Reduce(T *ldata, void(*Op)(OpData< T >)) const
Reduce within each group where the master is the root.
int GetVSize() const
Return the number of vector dofs, i.e. GetNDofs() x GetVDim().
double infinity()
Define a shortcut for std::numeric_limits<double>::infinity()
int Size() const
Return the logical size of the array.
void SetLevelsOfDetail(int levels_of_detail_)
void Clear()
Clear the contents of the Mesh.
Nodes: x_i = i/(n-1), i=0,...,n-1.
Arbitrary order H1-conforming (continuous) finite elements.
void GetNodes(Vector &node_coord) const
void Step(double &time, double dt, int cur_step, bool provisional=false)
Compute solution at the next time step t+dt.
virtual void Save() override
double u(const Vector &xvec)
Class for parallel grid function.
void SetSize(int s)
Change the size of the DenseMatrix to s x s.
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...
Class for parallel meshes.
Transient incompressible Navier Stokes solver in a split scheme formulation.
double Normlinf() const
Returns the l_infinity norm of the vector.
int GetOrder() const
Returns the order of the finite element. In the case of anisotropic orders, returns the maximum order...
void EnsureNodes()
Make sure that the mesh has valid nodes, i.e. its geometry is described by a vector finite element gr...
ElementTransformation * GetElementTransformation(int i) const
Returns ElementTransformation for the i-th element.