77static Vector ds_params_(0);
82static Vector cs_params_(0);
87static Vector pc_params_(0);
90static Vector vp_params_(0);
95static Vector e_uniform_(0);
101int main(
int argc,
char *argv[])
109 const char *mesh_file =
"../../data/ball-nurbs.mesh";
112 int serial_ref_levels = 0;
113 int parallel_ref_levels = 0;
115 bool visualization =
true;
127 args.
AddOption(&mesh_file,
"-m",
"--mesh",
128 "Mesh file to use.");
130 "Finite element order (polynomial degree).");
131 args.
AddOption(&serial_ref_levels,
"-rs",
"--serial-ref-levels",
132 "Number of serial refinement levels.");
133 args.
AddOption(¶llel_ref_levels,
"-rp",
"--parallel-ref-levels",
134 "Number of parallel refinement levels.");
135 args.
AddOption(&e_uniform_,
"-uebc",
"--uniform-e-bc",
136 "Specify if the three components of the constant "
138 args.
AddOption(&pw_eps_,
"-pwe",
"--piecewise-eps",
139 "Piecewise values of Permittivity");
140 args.
AddOption(&ds_params_,
"-ds",
"--dielectric-sphere-params",
141 "Center, Radius, and Permittivity of Dielectric Sphere");
142 args.
AddOption(&cs_params_,
"-cs",
"--charged-sphere-params",
143 "Center, Radius, and Total Charge of Charged Sphere");
144 args.
AddOption(&pc_params_,
"-pc",
"--point-charge-params",
145 "Charges and locations of Point Charges");
146 args.
AddOption(&vp_params_,
"-vp",
"--voltaic-pile-params",
147 "Axis End Points, Radius, and "
148 "Polarization of Cylindrical Voltaic Pile");
149 args.
AddOption(&dbcs,
"-dbcs",
"--dirichlet-bc-surf",
150 "Dirichlet Boundary Condition Surfaces");
151 args.
AddOption(&dbcv,
"-dbcv",
"--dirichlet-bc-vals",
152 "Dirichlet Boundary Condition Values");
153 args.
AddOption(&dbcg,
"-dbcg",
"--dirichlet-bc-gradient",
154 "-no-dbcg",
"--no-dirichlet-bc-gradient",
155 "Dirichlet Boundary Condition Gradient (phi = -z)");
156 args.
AddOption(&nbcs,
"-nbcs",
"--neumann-bc-surf",
157 "Neumann Boundary Condition Surfaces");
158 args.
AddOption(&nbcv,
"-nbcv",
"--neumann-bc-vals",
159 "Neumann Boundary Condition Values");
160 args.
AddOption(&maxit,
"-maxit",
"--max-amr-iterations",
161 "Max number of iterations in the main AMR loop.");
162 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
163 "--no-visualization",
164 "Enable or disable GLVis visualization.");
165 args.
AddOption(&visit,
"-visit",
"--visit",
"-no-visit",
"--no-visit",
166 "Enable or disable VisIt visualization.");
167 args.
AddOption(&visport,
"-p",
"--send-port",
"Socket for GLVis.");
185 Mesh *mesh =
new Mesh(mesh_file, 1, 1);
190 cout <<
"Starting initialization." << endl;
197 if (serial_ref_levels > 0) { serial_ref_levels--; }
208 for (
int l = 0; l < serial_ref_levels; l++)
216 ParMesh pmesh(MPI_COMM_WORLD, *mesh);
220 int par_ref_levels = parallel_ref_levels;
221 for (
int l = 0; l < par_ref_levels; l++)
230 if ( dbcg && e_uniform_.
Size() != sdim )
234 e_uniform_(sdim-1) = 1.0;
238 if ( dbcv.
Size() < dbcs.
Size() && !dbcg )
255 VoltaSolver Volta(pmesh, order, dbcs, dbcv, nbcs, nbcv, *epsCoef,
274 if (
Mpi::Root()) { cout <<
"Initialization done." << endl; }
281 const int max_dofs = 10000000;
282 for (
int it = 1; it <= maxit; it++)
286 cout <<
"\nAMR Iteration " << it << endl;
315 cout <<
"AMR iteration " << it <<
" complete." << endl;
319 if (prob_size > max_dofs)
323 cout <<
"Reached maximum number of dofs, exiting..." << endl;
336 cout <<
"press (q)uit or (c)ontinue --> " << flush;
339 MPI_Bcast(&c, 1, MPI_CHAR, 0, MPI_COMM_WORLD);
352 MPI_Allreduce(&local_max_err, &global_max_err, 1,
358 real_t threshold = frac * global_max_err;
359 if (
Mpi::Root()) { cout <<
"Refining ..." << endl; }
367 if (
Mpi::Root()) { cout <<
"Rebalancing ..." << endl; }
383 os <<
" ____ ____ __ __ " << endl
384 <<
" \\ \\ / /___ | |_/ |______ " << endl
385 <<
" \\ Y / _ \\| |\\ __\\__ \\ " << endl
386 <<
" \\ ( <_> ) |_| | / __ \\_ " << endl
387 <<
" \\___/ \\____/|____/__| (____ / " << endl
388 <<
" \\/ " << endl << flush;
398 if ( ds_params_.
Size() > 0 )
402 else if ( pw_eps_.
Size() > 0 )
421 for (
int i=0; i<x.
Size(); i++)
423 r2 += (x(i)-ds_params_(i))*(x(i)-ds_params_(i));
426 if ( sqrt(r2) <= ds_params_(x.
Size()) )
428 return ds_params_(x.
Size()+1) * epsilon0_;
441 if ( cs_params_(x.
Size()) > 0.0 )
446 rho = cs_params_(x.
Size()+1) /
447 (M_PI * pow(cs_params_(x.
Size()), 2));
450 rho = 0.75 * cs_params_(x.
Size()+1) /
451 (M_PI * pow(cs_params_(x.
Size()), 3));
458 for (
int i=0; i<x.
Size(); i++)
460 r2 += (x(i) - cs_params_(i)) * (x(i) - cs_params_(i));
463 if ( sqrt(r2) <= cs_params_(x.
Size()) )
483 for (
int i=0; i<x.
Size(); i++)
485 xu[i] -= vp_params_[i];
486 a[i] = vp_params_[x.
Size()+i] - vp_params_[i];
501 xu.
Add(-xa / (h * h),
a);
506 if ( xa >= 0.0 && xa <= h*h && xp <= r )
508 p.Add(vp_params_[2 * x.
Size() + 1] / h,
a);
518 for (
int i=0; i<x.
Size(); i++)
520 phi -= x(i) * e_uniform_(i);
int Size() const
Return the logical size of the array.
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.
A general function coefficient.
static void Init()
Initialize hypre by calling HYPRE_Init() and set default options. After calling Hypre::Init(),...
NURBSExtension * NURBSext
Optional NURBS mesh extension.
bool Nonconforming() const
Return a bool indicating whether this mesh is nonconforming.
int GetNE() const
Returns number of elements.
int SpaceDimension() const
Dimension of the physical space containing the mesh.
bool RefineByError(const Array< real_t > &elem_error, real_t threshold, int nonconforming=-1, int nc_limit=0)
void EnsureNCMesh(bool simplices_nonconforming=false)
virtual void SetCurvature(int order, bool discont=false, int space_dim=-1, int ordering=1)
Set the curvature of the mesh nodes using the given polynomial degree.
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
static bool Root()
Return true if the rank in MPI_COMM_WORLD is zero.
static int WorldSize()
Return the size of 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.
A piecewise constant coefficient with the constants keyed off the element attribute numbers.
Class for parallel meshes.
void Finalize(bool refine=false, bool fix_orientation=false) override
Finalize the construction of a general Mesh.
real_t Norml2() const
Returns the l2 norm of the vector.
real_t Max() const
Returns the maximal element of the vector.
int Size() const
Returns the size of the vector.
void SetSize(int s)
Resize the vector to size s.
Vector & Add(const real_t a, const Vector &Va)
(*this) += a * Va
Data collection with VisIt I/O routines.
void RegisterVisItFields(VisItDataCollection &visit_dc)
void DisplayToGLVis(int visport=19916)
void WriteVisItFields(int it=0)
void GetErrorEstimates(Vector &errors)
HYPRE_BigInt GetProblemSize()
real_t p(const Vector &x, real_t t)
Helper struct to convert a C++ type to an MPI type.
Coefficient * SetupPermittivityCoefficient()
real_t phi_bc_uniform(const Vector &)
real_t dielectric_sphere(const Vector &)
real_t charged_sphere(const Vector &)
void display_banner(ostream &os)
void voltaic_pile(const Vector &, Vector &)