93 #include "../common/mfem-common.hpp" 102 const double 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 double xc = x(0) - 0.5;
113 const double yc = (
dim > 1) ? x(1) - 0.5 : 0.0;
114 const double zc = (
dim > 2) ? x(2) - 0.5 : 0.0;
115 const double r = sqrt(xc*xc + yc*yc + zc*zc);
117 return (r >=
radius) ? -1.0 : 1.0;
123 const double xc = x(0) - 0.5;
124 const double yc = (
dim > 1) ? x(1) - 0.5 : 0.0;
125 const double zc = (
dim > 2) ? x(2) - 0.5 : 0.0;
126 const double r = sqrt(xc*xc + yc*yc + zc*zc);
139 : dist(d), dx(dist.ParFESpace()->GetParMesh()->GetElementSize(0)) { }
143 Vector pos(T.GetDimension());
144 T.Transform(ip, pos);
146 const double r = sqrt(pos * pos);
150 else {
return dist.
GetValue(T, ip); }
157 const double period = 2.0 * M_PI;
158 double x = xx[0]*period;
159 double y = xx[1]*period;
160 double 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]);
204 int main(
int argc,
char *argv[])
207 Mpi::Init(argc, argv);
208 int myid = Mpi::WorldRank();
212 const char *mesh_file =
"../../data/inline-quad.mesh";
217 double t_param = 1.0;
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 double 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 double s_norm = distance_s.ComputeL2Error(zero),
390 cout << fixed << setprecision(10) <<
"Norms: " 391 << s_norm <<
" " << v_norm << endl;
397 const double 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 double 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;
int main(int argc, char *argv[])
void SetCycle(int c)
Set time cycle (for time-dependent simulations)
A coefficient that is constant across space and time.
void PrintOptions(std::ostream &out) const
Print the options.
int Dimension() const
Dimension of the reference space used within the elements.
void SetSize(int s)
Resize the vector to size s.
Helper class for ParaView visualization data.
double exact_dist_sphere(const Vector &x)
void PrintUsage(std::ostream &out) const
Print the usage message.
void Filter(ParGridFunction &func, ParGridFunction &ffield)
int Size() const
Returns the size of the vector.
Coefficient defined by a GridFunction. This coefficient is mesh dependent.
Delta function coefficient optionally multiplied by a weight coefficient and a scaled time dependent ...
void Print(std::ostream &out=mfem::out)
Print the configuration of the MFEM virtual device object.
bool Good() const
Return true if the command line options were parsed successfully.
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 ComputeScalarDistance(Coefficient &zero_level_set, ParGridFunction &distance)=0
virtual void RegisterField(const std::string &field_name, GridFunction *gf)
Add a grid function to the collection.
void Parse()
Parse the command-line options. Note that this function expects all the options provided through the ...
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
double sine_ls(const Vector &x)
double Sph(const mfem::Vector &xx)
double sphere_ls(const Vector &x)
void VisualizeField(socketstream &sock, const char *vishost, int visport, ParGridFunction &gf, const char *title, int x=0, int y=0, int w=400, int h=400, bool vec=false)
PrintLevel & FirstAndLast()
void SetTime(double t)
Set physical time (for time-dependent simulations)
virtual double ComputeL2Error(Coefficient *exsol[], const IntegrationRule *irs[]=NULL, const Array< int > *elems=NULL) const
IterativeSolver::PrintLevel print_level
double p(const Vector &x, double t)
Base class Coefficients that optionally depend on space and time. These are used by the BilinearFormI...
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 DGyroid(const mfem::Vector &xx, mfem::Vector &vals)
virtual double GetValue(int i, const IntegrationPoint &ip, int vdim=1) const
Class for integration point with weight.
virtual void ComputeVectorDistance(Coefficient &zero_level_set, ParGridFunction &distance)
void SetLevelsOfDetail(int levels_of_detail_)
void Clear()
Clear the contents of the Mesh.
A general function coefficient.
double doughnut_cheese(const Vector &coord)
Arbitrary order H1-conforming (continuous) finite elements.
virtual void Save() override
Class for parallel grid function.
The MFEM Device class abstracts hardware devices such as GPUs, as well as programming models such as ...
double Gyroid(const Vector &xx)
Class for parallel meshes.
double AvgElementSize(ParMesh &pmesh)