100using namespace common;
104 const real_t sine = 0.25 * std::sin(4 * M_PI * x(0)) +
105 0.05 * std::sin(16 * M_PI * x(0));
106 return (x(1) >= sine + 0.5) ? -1.0 : 1.0;
114 const real_t xc = x(0) - 0.5;
115 const real_t yc = (
dim > 1) ? x(1) - 0.5 : 0.0;
116 const real_t zc = (
dim > 2) ? x(2) - 0.5 : 0.0;
117 const real_t r = sqrt(xc*xc + yc*yc + zc*zc);
119 return (r >=
radius) ? -1.0 : 1.0;
125 const real_t xc = x(0) - 0.5;
126 const real_t yc = (
dim > 1) ? x(1) - 0.5 : 0.0;
127 const real_t zc = (
dim > 2) ? x(2) - 0.5 : 0.0;
128 const real_t r = sqrt(xc*xc + yc*yc + zc*zc);
141 : dist(d), dx(dist.ParFESpace()->GetParMesh()->GetElementSize(0)) { }
152 else {
return dist.
GetValue(T, ip); }
159 const real_t period = 2.0 * M_PI;
162 real_t z = (xx.
Size()==3) ? xx[2]*period : 0.0;
164 return std::sin(x)*std::cos(y) +
165 std::sin(y)*std::cos(z) +
166 std::sin(z)*std::cos(x);
174 for (
int i=0; i<xx.
Size(); i++)
179 return lvec[0]*lvec[0]+lvec[1]*lvec[1]+lvec[2]*lvec[2]-R*R;
191 for (
int i=0; i<xx.
Size(); i++)
196 vals[0]=cos(lvec[0])*cos(lvec[1])-sin(lvec[2])*sin(lvec[0]);
197 vals[1]=-sin(lvec[0])*sin(lvec[1])+cos(lvec[1])*cos(lvec[2]);
200 vals[2]=-sin(lvec[1])*sin(lvec[2])+cos(lvec[2])*cos(lvec[0]);
206int main(
int argc,
char *argv[])
214 const char *mesh_file =
"../../data/inline-quad.mesh";
220 const char *device_config =
"cpu";
222 bool visualization =
true;
225 args.
AddOption(&mesh_file,
"-m",
"--mesh",
226 "Mesh file to use.");
227 args.
AddOption(&solver_type,
"-s",
"--solver",
231 "2: Rvachev scaling");
234 "0: Point source\n\t"
235 "1: Circle / sphere level set in 2D / 3D\n\t"
236 "2: 2D sine-looking level set\n\t"
237 "3: Gyroid level set in 2D or 3D\n\t"
238 "4: Combo of a doughnut and swiss cheese shapes in 3D.\n\t"
239 "5: Point source in MFEM mesh.");
240 args.
AddOption(&rs_levels,
"-rs",
"--refine-serial",
241 "Number of times to refine the mesh uniformly in serial.");
243 "Finite element order (polynomial degree) or -1 for"
244 " isoparametric space.");
245 args.
AddOption(&t_param,
"-t",
"--t-param",
246 "Diffusion time step (scaled internally scaled by dx*dx).");
247 args.
AddOption(&device_config,
"-d",
"--device",
248 "Device configuration string, see Device::Configure().");
249 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
250 "--no-visualization",
251 "Enable or disable GLVis visualization.");
252 args.
AddOption(&visport,
"-p",
"--send-port",
"Socket for GLVis.");
266 Device device(device_config);
267 if (myid == 0) { device.
Print(); }
270 Mesh mesh(mesh_file, 1, 1);
275 ParMesh pmesh(MPI_COMM_WORLD, mesh);
310 else { MFEM_ABORT(
"Unrecognized -problem option."); }
314 if (solver_type == 0)
319 ds->transform =
false;
321 ds->smooth_steps = smooth_steps;
322 ds->vis_glvis =
false;
325 else if (solver_type == 1)
328 const int newton_iter = 50;
331 else if (solver_type == 2)
335 else { MFEM_ABORT(
"Wrong solver option."); }
347 real_t filter_weight = dx;
349 if (solver_type == 2) { filter_weight *= 4.0; }
351 filter.
Filter(*ls_coeff, filt_gf);
368 "Input Level Set", 0, 0, size, size);
374 "Distance", size, 0, size, size,
381 "Directions", 2*size, 0, size, size,
382 "rRjmm********vveA");
395 const real_t s_norm = distance_s.ComputeL2Error(zero),
399 cout << fixed << setprecision(10) <<
"Norms: "
400 << s_norm <<
" " << v_norm << endl;
406 const real_t error_l1 = distance_s.ComputeL1Error(exact_dist_coeff),
407 error_li = distance_s.ComputeMaxError(exact_dist_coeff);
410 cout <<
"Global L1 error: " << error_l1 << endl
411 <<
"Global Linf error: " << error_li << endl;
414 ExactDistSphereLoc exact_dist_coeff_loc(distance_s);
415 const real_t error_l1_loc = distance_s.ComputeL1Error(exact_dist_coeff_loc),
416 error_li_loc = distance_s.ComputeMaxError(exact_dist_coeff_loc);
419 cout <<
"Local L1 error: " << error_l1_loc << endl
420 <<
"Local Linf error: " << error_li_loc << endl;
Base class Coefficients that optionally depend on space and time. These are used by the BilinearFormI...
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)
Delta function coefficient optionally multiplied by a weight coefficient and a scaled time dependent ...
The MFEM Device class abstracts hardware devices such as GPUs, as well as programming models such as ...
void Print(std::ostream &os=mfem::out)
Print the configuration of the MFEM virtual device object.
A general function coefficient.
Coefficient defined by a GridFunction. This coefficient is mesh dependent.
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.
void Clear()
Clear the contents of the Mesh.
int Dimension() const
Dimension of the reference space used within the elements.
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
static int WorldRank()
Return the MPI rank in MPI_COMM_WORLD.
static void Init(int &argc, char **&argv, int required=default_thread_required, int *provided=nullptr)
Singleton creation with Mpi::Init(argc, argv).
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.
Class for parallel grid function.
real_t ComputeL2Error(Coefficient *exsol[], const IntegrationRule *irs[]=NULL, const Array< int > *elems=NULL) const override
Returns ||u_ex - u_h||_L2 in parallel for H1 or L2 elements.
real_t GetValue(int i, const IntegrationPoint &ip, int vdim=1) const override
void ProjectCoefficient(Coefficient &coeff) override
Project coeff Coefficient to this GridFunction. The projection computation depends on the choice of t...
Class for parallel meshes.
void SetLevelsOfDetail(int levels_of_detail_)
Set the refinement level.
Writer for ParaView visualization (PVD and VTU format)
int Size() const
Returns the size of the vector.
void SetSize(int s)
Resize the vector to size s.
IterativeSolver::PrintLevel print_level
virtual void ComputeScalarDistance(Coefficient &zero_level_set, ParGridFunction &distance)=0
virtual void ComputeVectorDistance(Coefficient &zero_level_set, ParGridFunction &distance)
void Filter(ParGridFunction &func, ParGridFunction &ffield)
real_t sphere_ls(const Vector &x)
void DGyroid(const mfem::Vector &xx, mfem::Vector &vals)
real_t Sph(const mfem::Vector &xx)
real_t Gyroid(const Vector &xx)
real_t exact_dist_sphere(const Vector &x)
real_t sine_ls(const Vector &x)
real_t AvgElementSize(ParMesh &pmesh)
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)
MFEM_HOST_DEVICE dual< value_type, gradient_type > sqrt(dual< value_type, gradient_type > x)
implementation of square root for dual numbers
real_t p(const Vector &x, real_t t)
real_t doughnut_cheese(const Vector &coord)
PrintLevel & FirstAndLast()