61 #include "../common/mfem-common.hpp"
70 int main(
int argc,
char *argv[])
72 #ifdef HYPRE_USING_CUDA
73 cout <<
"\nAs of mfem-4.3 and hypre-2.22.0 (July 2021) this miniapp\n"
74 <<
"is NOT supported with the CUDA version of hypre.\n\n";
80 MPI_Init(&argc, &argv);
81 MPI_Comm_size(MPI_COMM_WORLD, &num_procs);
82 MPI_Comm_rank(MPI_COMM_WORLD, &myid);
85 const char *mesh_file =
"../../data/inline-quad.mesh";
87 bool visualization =
true;
88 int ser_ref_levels = 0;
89 int level_set_type = 1;
92 bool include_cut_cell =
false;
95 args.
AddOption(&mesh_file,
"-m",
"--mesh",
98 "Finite element order (polynomial degree) or -1 for"
99 " isoparametric space.");
100 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
101 "--no-visualization",
102 "Enable or disable GLVis visualization.");
103 args.
AddOption(&ser_ref_levels,
"-rs",
"--refine-serial",
104 "Number of times to refine the mesh uniformly in serial.");
105 args.
AddOption(&level_set_type,
"-lst",
"--level-set-type",
107 args.
AddOption(&ho_terms,
"-ho",
"--high-order",
108 "Additional high-order terms to include");
109 args.
AddOption(&alpha,
"-alpha",
"--alpha",
110 "Nitsche penalty parameter (~1 for 2D, ~10 for 3D).");
111 args.
AddOption(&include_cut_cell,
"-cut",
"--cut",
"-no-cut-cell",
113 "Include or not include elements cut by true boundary.");
130 if (myid == 0) { device.
Print(); }
133 Mesh mesh(mesh_file, 1, 1);
138 ParMesh pmesh(MPI_COMM_WORLD, mesh);
143 if (order < 1) { order = 1; }
157 int nodes_cnt = vxyz.
Size()/
dim;
158 if (level_set_type == 3)
160 for (
int i = 0; i < nodes_cnt; i++)
163 vxyz(i+nodes_cnt) = (1.+1.e-4)*vxyz(i+nodes_cnt)-1.e-4;
171 cout <<
"Number of finite element unknowns: " << gtsize << endl;
199 for (
int i = 0; i < elem_marker_gf.
Size(); i++)
201 elem_marker_gf(i) = (double)elem_marker[i];
207 "Element Flags", 0, 0,
s,
s,
"Rjmpc");
219 for (
int i = 0; i < sb_dofs.
Size(); i++)
221 face_dofs(sb_dofs[i]) = 1.0;
227 "Shifted Face Dofs", 0,
s,
s,
s,
"Rjmp");
246 if (level_set_type == 4)
252 filter->
Filter(dist_fun_level_coef, filt_gf);
262 "Input Level Set", 0, 2*
s,
s,
s,
"Rjmm");
285 "Distance Vector",
s,
s,
s,
s,
"Rjmmpcvv", 1);
293 bool inactive_elements =
false;
294 for (
int i = 0; i < pmesh.
GetNE(); i++)
296 if (!include_cut_cell &&
297 (elem_marker[i] == ShiftedFaceMarker::SBElementType::OUTSIDE ||
298 elem_marker[i] == ShiftedFaceMarker::SBElementType::CUT))
301 inactive_elements =
true;
303 if (include_cut_cell &&
304 elem_marker[i] == ShiftedFaceMarker::SBElementType::OUTSIDE)
307 inactive_elements =
true;
310 bool inactive_elements_global;
311 MPI_Allreduce(&inactive_elements, &inactive_elements_global, 1, MPI_C_BOOL,
312 MPI_LOR, MPI_COMM_WORLD);
313 if (inactive_elements_global) { ess_elem.
Append(0); }
320 if (level_set_type == 1 || level_set_type == 4)
324 else if (level_set_type == 2)
328 else if (level_set_type == 3)
332 else { MFEM_ABORT(
"RHS function not set for level set type.\n"); }
337 if (level_set_type == 1 || level_set_type == 4)
341 else if (level_set_type == 2)
345 else if (level_set_type == 3)
351 MFEM_ABORT(
"Dirichlet velocity function not set for level set type.\n");
363 ho_terms), ess_shift_bdr);
380 ho_terms), ess_shift_bdr);
407 ofstream mesh_ofs(
"diffusion.mesh");
408 mesh_ofs.precision(8);
410 ofstream sol_ofs(
"diffusion.gf");
411 sol_ofs.precision(8);
434 "Solution",
s, 0,
s,
s,
"Rj");
438 if (level_set_type == 2 || level_set_type == 3)
443 for (
int i = 0; i < nodes_cnt; i++)
446 pxyz(1) = vxyz(i+nodes_cnt);
447 double exact_val = 0.;
448 if (level_set_type == 2)
452 else if (level_set_type == 3)
456 err(i) = std::fabs(x(i) - exact_val);
465 "Error", 2*
s, 0,
s,
s,
"Rj");
471 std::cout <<
"Global L2 error: " << global_error << endl;
int Size() const
Return the logical size of the array.
Class for domain integration L(v) := (f, v)
double rhs_fun_circle(const Vector &x)
f for the Poisson problem (-nabla^2 u = f).
void ExchangeFaceNbrData()
void SetCycle(int c)
Set time cycle (for time-dependent simulations)
Base class for vector Coefficients that optionally depend on time and space.
A coefficient that is constant across space and time.
Helper class for ParaView visualization data.
Pointer to an Operator of a specified type.
HYPRE_BigInt GlobalTrueVSize() const
Coefficient defined by a GridFunction. This coefficient is mesh dependent.
int Size() const
Returns the size of the vector.
int GetNE() const
Returns number of elements.
void Print(std::ostream &out=mfem::out)
Print the configuration of the MFEM virtual device object.
virtual void ProjectDiscCoefficient(VectorCoefficient &coeff)
Project a discontinuous vector coefficient as a grid function on a continuous finite element space...
void MarkElements(Array< int > &elem_marker) const
Mark all the elements in the mesh using the SBElementType.
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 void SetAttributes()
double dirichlet_velocity_xy_exponent(const Vector &x)
double dirichlet_velocity_circle(const Vector &x)
Boundary conditions.
The BoomerAMG solver in hypre.
virtual void RegisterField(const std::string &field_name, GridFunction *gf)
Add a grid function to the collection.
void ExchangeFaceNbrData()
void SetPrintLevel(int print_lvl)
void Parse()
Parse the command-line options. Note that this function expects all the options provided through the ...
int Append(const T &el)
Append element 'el' to array, resize if necessary.
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
void ListShiftedFaceDofs(const Array< int > &elem_marker, Array< int > &sface_dof_list) const
void ListEssentialTDofs(const Array< int > &elem_marker, const Array< int > &sface_dof_list, Array< int > &ess_tdof_list, Array< int > &ess_shift_bdr) const
void SetMaxIter(int max_it)
T Max() const
Find the maximal element in the array, using the comparison operator < for class T.
Distance vector to the zero level-set.
Level set coefficient - +1 inside the domain, -1 outside, 0 at the boundary.
void SetNodalFESpace(FiniteElementSpace *nfes)
void PrintUsage(std::ostream &out) const
Print the usage message.
void SetTime(double t)
Set physical time (for time-dependent simulations)
double rhs_fun_xy_sinusoidal(const Vector &x)
void SetRelTol(double rtol)
OutStream err(std::cerr)
Global stream used by the library for standard error output. Initially it uses the same std::streambu...
virtual void Mult(const Vector &b, Vector &x) const
Operator application: y=A(x).
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...
virtual void ComputeVectorDistance(Coefficient &zero_level_set, ParGridFunction &distance)
double rhs_fun_xy_exponent(const Vector &x)
void SaveAsOne(const char *fname, int precision=16) const
double dirichlet_velocity_xy_sinusoidal(const Vector &x)
virtual double ComputeL2Error(Coefficient *exsol[], const IntegrationRule *irs[]=NULL) const
virtual void SetOperator(const Operator &op)
Also calls SetOperator for the preconditioner if there is one.
void PrintOptions(std::ostream &out) const
Print the options.
void SetLevelsOfDetail(int levels_of_detail_)
void Clear()
Clear the contents of the Mesh.
A general function coefficient.
void SetAttribute(int i, int attr)
Set the attribute of element i.
void VisualizeField(socketstream &sock, const char *vishost, int visport, GridFunction &gf, const char *title, int x, int y, int w, int h, const char *keys, bool vec)
void GetNodes(Vector &node_coord) const
Vector coefficient defined by a vector GridFunction.
void PrintAsOne(std::ostream &out=mfem::out) const
virtual void SetPreconditioner(Solver &pr)
This should be called before SetOperator.
Arbitrary order H1-conforming (continuous) finite elements.
virtual void Save() override
void SetNodes(const Vector &node_coord)
Class for parallel grid function.
void SetNodalGridFunction(GridFunction *nodes, bool make_owner=false)
The MFEM Device class abstracts hardware devices such as GPUs, as well as programming models such as ...
Class for parallel meshes.
Array< int > attributes
A list of all unique element attributes used by the Mesh.
void Filter(ParGridFunction &func, ParGridFunction &ffield)
Arbitrary order "L2-conforming" discontinuous finite elements.
double AvgElementSize(ParMesh &pmesh)
bool Good() const
Return true if the command line options were parsed successfully.