74static Vector pw_mu_inv_(0);
75static Vector ms_params_(0);
81static Vector cr_params_(0);
87static Vector bm_params_(0);
91static Vector ha_params_(0);
98static Vector b_uniform_(0);
107int main(
int argc,
char *argv[])
115 const char *mesh_file =
"../../data/ball-nurbs.mesh";
118 int serial_ref_levels = 0;
119 int parallel_ref_levels = 0;
120 bool visualization =
true;
129 args.
AddOption(&mesh_file,
"-m",
"--mesh",
130 "Mesh file to use.");
132 "Finite element order (polynomial degree).");
133 args.
AddOption(&serial_ref_levels,
"-rs",
"--serial-ref-levels",
134 "Number of serial refinement levels.");
135 args.
AddOption(¶llel_ref_levels,
"-rp",
"--parallel-ref-levels",
136 "Number of parallel refinement levels.");
137 args.
AddOption(&b_uniform_,
"-ubbc",
"--uniform-b-bc",
138 "Specify if the three components of the constant magnetic flux density");
139 args.
AddOption(&pw_mu_,
"-pwm",
"--piecewise-mu",
140 "Piecewise values of Permeability");
141 args.
AddOption(&ms_params_,
"-ms",
"--magnetic-shell-params",
142 "Center, Inner Radius, Outer Radius, and Permeability of Magnetic Shell");
143 args.
AddOption(&cr_params_,
"-cr",
"--current-ring-params",
144 "Axis End Points, Inner Radius, Outer Radius and Total Current of Annulus");
145 args.
AddOption(&bm_params_,
"-bm",
"--bar-magnet-params",
146 "Axis End Points, Radius, and Magnetic Field of Cylindrical Magnet");
147 args.
AddOption(&ha_params_,
"-ha",
"--halbach-array-params",
148 "Bounding Box Corners and Number of Segments");
149 args.
AddOption(&kbcs,
"-kbcs",
"--surface-current-bc",
150 "Surfaces for the Surface Current (K) Boundary Condition");
151 args.
AddOption(&vbcs,
"-vbcs",
"--voltage-bc-surf",
152 "Voltage Boundary Condition Surfaces (to drive K)");
153 args.
AddOption(&vbcv,
"-vbcv",
"--voltage-bc-vals",
154 "Voltage Boundary Condition Values (to drive K)");
155 args.
AddOption(&maxit,
"-maxit",
"--max-amr-iterations",
156 "Max number of iterations in the main AMR loop.");
157 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
158 "--no-visualization",
159 "Enable or disable GLVis visualization.");
160 args.
AddOption(&visit,
"-visit",
"--visit",
"-no-visit",
"--no-visit",
161 "Enable or disable VisIt visualization.");
179 Mesh *mesh =
new Mesh(mesh_file, 1, 1);
183 cout <<
"Starting initialization." << endl;
190 if (serial_ref_levels > 0) { serial_ref_levels--; }
200 for (
int l = 0; l < serial_ref_levels; l++)
208 ParMesh pmesh(MPI_COMM_WORLD, *mesh);
212 int par_ref_levels = parallel_ref_levels;
213 for (
int l = 0; l < par_ref_levels; l++)
221 if ( ( vbcs.
Size() > 0 && kbcs.
Size() == 0 ) ||
222 ( kbcs.
Size() > 0 && vbcs.
Size() == 0 ) ||
227 cout <<
"The surface current (K) boundary condition requires "
228 <<
"surface current boundary condition surfaces (with -kbcs), "
229 <<
"voltage boundary condition surface (with -vbcs), "
230 <<
"and voltage boundary condition values (with -vbcv)."
240 TeslaSolver Tesla(pmesh, order, kbcs, vbcs, vbcv, *muInvCoef,
259 if (
Mpi::Root()) { cout <<
"Initialization done." << endl; }
266 const int max_dofs = 10000000;
267 for (
int it = 1; it <= maxit; it++)
271 cout <<
"\nAMR Iteration " << it << endl;
300 cout <<
"AMR iteration " << it <<
" complete." << endl;
304 if (prob_size > max_dofs)
308 cout <<
"Reached maximum number of dofs, exiting..." << endl;
321 cout <<
"press (q)uit or (c)ontinue --> " << flush;
324 MPI_Bcast(&c, 1, MPI_CHAR, 0, MPI_COMM_WORLD);
337 MPI_Allreduce(&local_max_err, &global_max_err, 1,
343 real_t threshold = frac * global_max_err;
344 if (
Mpi::Root()) { cout <<
"Refining ..." << endl; }
352 if (
Mpi::Root()) { cout <<
"Rebalancing ..." << endl; }
368 os <<
" ___________ __ " << endl
369 <<
" \\__ ___/___ _____| | _____ " << endl
370 <<
" | |_/ __ \\ / ___/ | \\__ \\ " << endl
371 <<
" | |\\ ___/ \\___ \\| |__/ __ \\_ " << endl
372 <<
" |____| \\___ >____ >____(____ / " << endl
373 <<
" \\/ \\/ \\/ " << endl << flush;
383 if ( ms_params_.
Size() > 0 )
387 else if ( pw_mu_.
Size() > 0 )
390 for (
int i = 0; i < pw_mu_.
Size(); i++)
392 MFEM_ASSERT( pw_mu_[i] > 0.0,
"permeability values must be positive" );
393 pw_mu_inv_[i] = 1.0/pw_mu_[i];
412 for (
int i = 0; i < x.
Size(); i++)
414 r2 += (x(i) - ms_params_(i))*(x(i) - ms_params_(i));
417 if ( sqrt(r2) >= ms_params_(x.
Size()) &&
418 sqrt(r2) <= ms_params_(x.
Size()+1) )
420 return mu0_*ms_params_(x.
Size()+2);
429 MFEM_ASSERT(x.
Size() == 3,
"current_ring source requires 3D space.");
440 for (
int i=0; i<x.
Size(); i++)
442 xu[i] -= cr_params_[i];
443 a[i] = cr_params_[x.
Size()+i] - cr_params_[i];
470 if ( xa >= 0.0 && xa <= h*h && xp >= ra && xp <= rb )
472 ju(0) =
a(1) * xu(2) -
a(2) * xu(1);
473 ju(1) =
a(2) * xu(0) -
a(0) * xu(2);
474 ju(2) =
a(0) * xu(1) -
a(1) * xu(0);
477 j.
Add(cr_params_[2*x.
Size()+2]/(h*(rb-ra)),ju);
494 for (
int i=0; i<x.
Size(); i++)
496 xu[i] -= bm_params_[i];
497 a[i] = bm_params_[x.
Size()+i] - bm_params_[i];
517 if ( xa >= 0.0 && xa <= h*h && xp <= r )
519 m.
Add(bm_params_[2*x.
Size()+1]/h,
a);
532 if ( x[0] < ha_params_[0] || x[0] > ha_params_[3] ||
533 x[1] < ha_params_[1] || x[1] > ha_params_[4] ||
534 x[2] < ha_params_[2] || x[2] > ha_params_[5] )
539 int ai = (int)ha_params_[6];
540 int ri = (int)ha_params_[7];
541 int n = (int)ha_params_[8];
543 int i =
static_cast<int>(n * (x[ai] - ha_params_[ai]) /
544 (ha_params_[ai+3] - ha_params_[ai]));
546 m[(ri + 1 + (i % 2)) % 3] =
static_cast<int>(pow(-1.0,i/2));
554 a(0) = b_uniform_(1) * x(2);
555 a(1) = b_uniform_(2) * x(0);
556 a(2) = b_uniform_(0) * x(1);
563 return -x(x.
Size()-1);
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
int GetNE() const
Returns number of elements.
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 GetErrorEstimates(Vector &errors)
HYPRE_BigInt GetProblemSize()
void WriteVisItFields(int it=0)
void RegisterVisItFields(VisItDataCollection &visit_dc)
Helper struct to convert a C++ type to an MPI type.
real_t magnetic_shell(const Vector &)
real_t magnetic_shell_inv(const Vector &x)
void bar_magnet(const Vector &, Vector &)
void display_banner(ostream &os)
Coefficient * SetupInvPermeabilityCoefficient()
void a_bc_uniform(const Vector &, Vector &)
void halbach_array(const Vector &, Vector &)
real_t phi_m_bc_uniform(const Vector &x)
void current_ring(const Vector &, Vector &)