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)
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)
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."
int GetNPoints() const
Returns the number of the points in the integration rule.
Abstract class for all finite elements.
void PrintTimingData()
Print timing summary of the solving routine.
int Size() const
Return the logical size of the array.
Class for domain integration L(v) := (f, v)
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().
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 GetDim() const
Returns the reference space dimension for the finite element.
Class for an integration rule - an Array of IntegrationPoint.
Class for grid function - Vector with associated FE space.
void Bcast(T *ldata, int layout) const
Broadcast within each group where the master is the root.
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 SetSize(int s)
Resize the vector to size s.
Helper class for ParaView visualization data.
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.
void GetSubVector(const Array< int > &dofs, Vector &elemvect) const
Extract entries listed in dofs to the output Vector elemvect.
int GetOrder() const
Returns the order of the finite element. In the case of anisotropic orders, returns the maximum order...
Data type dense matrix using column-major storage.
int Size() const
Returns the size of the vector.
int GetNE() const
Returns number of elements.
Abstract parallel finite element space.
double Normlinf() const
Returns the l_infinity norm of the vector.
virtual void ProjectCoefficient(Coefficient &coeff)
Project coeff Coefficient to this GridFunction. The projection computation depends on the choice of t...
double * GetData() const
Return a pointer to the beginning of the Vector data.
void Setup(double dt)
Initialize forms, solvers and preconditioners.
Geometry::Type GetGeomType() const
Returns the Geometry::Type of the reference element.
int GetNE() const
Returns number of elements in the mesh.
IntegrationPoint & IntPoint(int i)
Returns a reference to the i-th integration point.
void ComputeCurl3D(ParGridFunction &u, ParGridFunction &cu)
Compute for .
HYPRE_BigInt GlobalVSize() const
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.
DofTransformation * GetElementVDofs(int i, Array< int > &vdofs) const
Returns indexes of degrees of freedom in array dofs for i'th element.
double f(const Vector &xvec)
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 Height() const
Get the height (size of output) of the Operator. Synonym with NumRows().
struct s_NavierContext ctx
ParGridFunction * GetCurrentPressure()
Return a pointer to the current pressure ParGridFunction.
const IntegrationRule & GetNodes() const
Get a const reference to the nodes of the element.
void EnablePA(bool pa)
Enable partial assembly for every operator.
void SetHighOrderOutput(bool high_order_output_)
static void Init()
Singleton creation with Mpi::Init();.
void GetValues(int i, const IntegrationRule &ir, Vector &vals, int vdim=1) const
int GetVDim() const
Returns vector dimension.
FiniteElementSpace * FESpace()
void PrintUsage(std::ostream &out) const
Print the usage message.
void SetTime(double t)
Set physical time (for time-dependent simulations)
static bool Root()
Return true if the rank in MPI_COMM_WORLD is zero.
A general vector function coefficient.
ElementTransformation * GetElementTransformation(int i) const
Returns ElementTransformation for the i-th element.
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.
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...
int GetDof() const
Returns the number of degrees of freedom in the finite element.
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)
ParGridFunction * GetCurrentVelocity()
Return a pointer to the current velocity ParGridFunction.
Class for integration point with weight.
virtual const FiniteElement * GetFE(int i) const
Returns pointer to the FiniteElement in the FiniteElementCollection associated with i'th element in t...
void PrintOptions(std::ostream &out) const
Print the options.
double infinity()
Define a shortcut for std::numeric_limits<double>::infinity()
void SetLevelsOfDetail(int levels_of_detail_)
void Clear()
Clear the contents of the Mesh.
Nodes: x_i = i/(n-1), i=0,...,n-1.
void GetNodes(Vector &node_coord) const
Arbitrary order H1-conforming (continuous) finite elements.
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.
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
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.
IntegrationRules IntRules(0, Quadrature1D::GaussLegendre)
A global object with all integration rules (defined in intrules.cpp)
ParFiniteElementSpace * ParFESpace() const
bool Good() const
Return true if the command line options were parsed successfully.