50 using namespace navier;
52 struct s_NavierContext
54 int ser_ref_levels = 1;
56 double kinvis = 1.0 / 40.0;
57 double t_final = 10 * 0.001;
59 double reference_pressure = 0.0;
60 double reynolds = 1.0 / kinvis;
61 double lam = 0.5 * reynolds
62 - sqrt(0.25 * reynolds * reynolds + 4.0 * M_PI * M_PI);
65 bool visualization =
false;
66 bool checkres =
false;
74 u(0) = 1.0 - exp(
ctx.lam * xi) * cos(2.0 * M_PI * yi);
75 u(1) =
ctx.lam / (2.0 * M_PI) * exp(
ctx.lam * xi) * sin(2.0 * M_PI * yi);
82 return 0.5 * (1.0 - exp(2.0 *
ctx.lam * xi)) +
ctx.reference_pressure;
85 int main(
int argc,
char *argv[])
93 "Number of times to refine the mesh uniformly in serial.");
97 "Order (degree) of the finite elements.");
98 args.
AddOption(&
ctx.dt,
"-dt",
"--time-step",
"Time step.");
99 args.
AddOption(&
ctx.t_final,
"-tf",
"--final-time",
"Final time.");
105 "Enable partial assembly.");
111 "Enable numerical integration rules.");
116 "--no-visualization",
117 "Enable or disable GLVis visualization.");
124 "Enable or disable checking of the result. Returns -1 on failure.");
146 for (
int i = 0; i <
ctx.ser_ref_levels; ++i)
153 std::cout <<
"Number of elements: " << mesh.
GetNE() << std::endl;
156 auto *pmesh =
new ParMesh(MPI_COMM_WORLD, mesh);
179 double t_final =
ctx.t_final;
180 bool last_step =
false;
182 flowsolver.
Setup(dt);
193 double cfl_max = 0.8;
194 double cfl_tol = 1e-4;
196 for (
int step = 0; !last_step; ++step)
198 if (t + dt >= t_final - dt / 2)
204 flowsolver.
Step(t, dt, step,
true);
210 double cfl = flowsolver.
ComputeCFL(*u_next_gf, dt);
212 double error_est = cfl / (cfl_max + cfl_tol);
213 if (error_est >= 1.0)
219 <<
"Step reached maximum CFL, retrying with smaller step size..."
231 double fac_safety = 2.0;
232 double eta = pow(1.0 / (fac_safety * error_est), 1.0 / (1.0 + 3.0));
233 double fac_min = 0.1;
234 double fac_max = 1.4;
235 dt = dt * std::min(fac_max, std::max(fac_min, eta));
244 u_excoeff.SetTime(t);
248 p_ex_gf.ProjectCoefficient(p_excoeff);
256 printf(
"%5s %8s %8s %8s %11s %11s\n",
263 printf(
"%5.2d %8.2E %.2E %.2E %.5E %.5E err\n",
274 if (
ctx.visualization)
279 sol_sock.precision(8);
282 sol_sock <<
"solution\n" << *pmesh << *u_ic << std::flush;
292 if (err_u > tol_u || err_p > tol_p)
296 mfem::out <<
"Result has a larger error than expected."
int WorldSize() const
Return MPI_COMM_WORLD's size.
void PrintTimingData()
Print timing summary of the solving routine.
Class for grid function - Vector with associated FE space.
void vel_kovasznay(const Vector &x, double t, Vector &u)
double pres_kovasznay(const Vector &x, double t)
Coefficient defined by a GridFunction. This coefficient is mesh dependent.
int GetNE() const
Returns number of elements.
virtual void ProjectCoefficient(Coefficient &coeff)
Project coeff Coefficient to this GridFunction. The projection computation depends on the choice of t...
void Setup(double dt)
Initialize forms, solvers and preconditioners.
void MeanZero(ParGridFunction &v)
Remove the mean from a ParGridFunction.
A simple convenience class that calls MPI_Init() at construction and MPI_Finalize() at destruction...
void Parse()
Parse the command-line options. Note that this function expects all the options provided through the ...
double ComputeCFL(ParGridFunction &u, double dt)
Compute CFL.
struct s_NavierContext ctx
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
ParGridFunction * GetCurrentPressure()
Return a pointer to the current pressure ParGridFunction.
bool Root() const
Return true if WorldRank() == 0.
void EnablePA(bool pa)
Enable partial assembly for every operator.
void AddVelDirichletBC(VectorCoefficient *coeff, Array< int > &attr)
Add a Dirichlet boundary condition to the velocity field.
void PrintUsage(std::ostream &out) const
Print the usage message.
void SetTime(double t)
Set the time for time dependent coefficients.
A general vector function coefficient.
int WorldRank() const
Return MPI_COMM_WORLD's rank.
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...
static Mesh MakeCartesian2D(int nx, int ny, Element::Type type, bool generate_edges=false, double sx=1.0, double sy=1.0, bool sfc_ordering=true)
ParGridFunction * GetCurrentVelocity()
Return a pointer to the current velocity ParGridFunction.
virtual double ComputeL2Error(Coefficient *exsol[], const IntegrationRule *irs[]=NULL) const
void UpdateTimestepHistory(double dt)
Rotate entries in the time step and solution history arrays.
ParGridFunction * GetProvisionalVelocity()
Return a pointer to the provisional velocity ParGridFunction.
void PrintOptions(std::ostream &out) const
Print the options.
void Clear()
Clear the contents of the Mesh.
A general function coefficient.
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.
double u(const Vector &xvec)
Class for parallel grid function.
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
Class for parallel meshes.
Transient incompressible Navier Stokes solver in a split scheme formulation.
ParFiniteElementSpace * ParFESpace() const
bool Good() const
Return true if the command line options were parsed successfully.