98using namespace common;
102 const real_t sine = 0.25 * std::sin(4 * M_PI * x(0)) +
103 0.05 * std::sin(16 * M_PI * x(0));
104 return (x(1) >= sine + 0.5) ? -1.0 : 1.0;
112 const real_t xc = x(0) - 0.5;
113 const real_t yc = (
dim > 1) ? x(1) - 0.5 : 0.0;
114 const real_t zc = (
dim > 2) ? x(2) - 0.5 : 0.0;
115 const real_t r = sqrt(xc*xc + yc*yc + zc*zc);
117 return (r >=
radius) ? -1.0 : 1.0;
123 const real_t xc = x(0) - 0.5;
124 const real_t yc = (
dim > 1) ? x(1) - 0.5 : 0.0;
125 const real_t zc = (
dim > 2) ? x(2) - 0.5 : 0.0;
126 const real_t r = sqrt(xc*xc + yc*yc + zc*zc);
139 : dist(d), dx(dist.ParFESpace()->GetParMesh()->GetElementSize(0)) { }
146 const real_t r = sqrt(pos * pos);
150 else {
return dist.
GetValue(T, ip); }
157 const real_t period = 2.0 * M_PI;
160 real_t z = (xx.
Size()==3) ? xx[2]*period : 0.0;
162 return std::sin(x)*std::cos(y) +
163 std::sin(y)*std::cos(z) +
164 std::sin(z)*std::cos(x);
172 for (
int i=0; i<xx.
Size(); i++)
177 return lvec[0]*lvec[0]+lvec[1]*lvec[1]+lvec[2]*lvec[2]-R*R;
189 for (
int i=0; i<xx.
Size(); i++)
194 vals[0]=cos(lvec[0])*cos(lvec[1])-sin(lvec[2])*sin(lvec[0]);
195 vals[1]=-sin(lvec[0])*sin(lvec[1])+cos(lvec[1])*cos(lvec[2]);
198 vals[2]=-sin(lvec[1])*sin(lvec[2])+cos(lvec[2])*cos(lvec[0]);
204int main(
int argc,
char *argv[])
212 const char *mesh_file =
"../../data/inline-quad.mesh";
218 const char *device_config =
"cpu";
219 bool visualization =
true;
222 args.
AddOption(&mesh_file,
"-m",
"--mesh",
223 "Mesh file to use.");
224 args.
AddOption(&solver_type,
"-s",
"--solver",
228 "2: Rvachev scaling");
231 "0: Point source\n\t"
232 "1: Circle / sphere level set in 2D / 3D\n\t"
233 "2: 2D sine-looking level set\n\t"
234 "3: Gyroid level set in 2D or 3D\n\t"
235 "4: Combo of a doughnut and swiss cheese shapes in 3D.");
236 args.
AddOption(&rs_levels,
"-rs",
"--refine-serial",
237 "Number of times to refine the mesh uniformly in serial.");
239 "Finite element order (polynomial degree) or -1 for"
240 " isoparametric space.");
241 args.
AddOption(&t_param,
"-t",
"--t-param",
242 "Diffusion time step (scaled internally scaled by dx*dx).");
243 args.
AddOption(&device_config,
"-d",
"--device",
244 "Device configuration string, see Device::Configure().");
245 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
246 "--no-visualization",
247 "Enable or disable GLVis visualization.");
261 Device device(device_config);
262 if (myid == 0) { device.
Print(); }
265 Mesh mesh(mesh_file, 1, 1);
270 ParMesh pmesh(MPI_COMM_WORLD, mesh);
300 else { MFEM_ABORT(
"Unrecognized -problem option."); }
304 if (solver_type == 0)
309 ds->transform =
false;
311 ds->smooth_steps = smooth_steps;
312 ds->vis_glvis =
false;
315 else if (solver_type == 1)
318 const int newton_iter = 50;
321 else if (solver_type == 2)
325 else { MFEM_ABORT(
"Wrong solver option."); }
337 real_t filter_weight = dx;
339 if (solver_type == 2) { filter_weight *= 4.0; }
341 filter.
Filter(*ls_coeff, filt_gf);
359 "Input Level Set", 0, 0, size, size);
365 "Distance", size, 0, size, size,
372 "Directions", 2*size, 0, size, size,
373 "rRjmm********vveA");
386 const real_t s_norm = distance_s.ComputeL2Error(zero),
390 cout << fixed << setprecision(10) <<
"Norms: "
391 << s_norm <<
" " << v_norm << endl;
397 const real_t error_l1 = distance_s.ComputeL1Error(exact_dist_coeff),
398 error_li = distance_s.ComputeMaxError(exact_dist_coeff);
401 cout <<
"Global L1 error: " << error_l1 << endl
402 <<
"Global Linf error: " << error_li << endl;
405 ExactDistSphereLoc exact_dist_coeff_loc(distance_s);
406 const real_t error_l1_loc = distance_s.ComputeL1Error(exact_dist_coeff_loc),
407 error_li_loc = distance_s.ComputeMaxError(exact_dist_coeff_loc);
410 cout <<
"Local L1 error: " << error_l1_loc << endl
411 <<
"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 &out=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
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.
Helper class for ParaView visualization data.
void SetLevelsOfDetail(int levels_of_detail_)
virtual void Save() override
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)
real_t p(const Vector &x, real_t t)
real_t doughnut_cheese(const Vector &coord)
PrintLevel & FirstAndLast()