113 using namespace mfem;
114 using namespace mfem::electromagnetics;
118 static double mj_ = 0.0;
119 static double sj_ = 0.0;
120 static double wj_ = 0.0;
122 int main(
int argc,
char *argv[])
132 const char *mesh_file =
"cylinder-hex.mesh";
133 int ser_ref_levels = 0;
134 int par_ref_levels = 0;
136 int ode_solver_type = 1;
137 double t_final = 100.0;
140 double sigma = 2.0*M_PI*10;
141 double Tcapacity = 1.0;
142 double Tconductivity = 0.01;
143 double freq = 1.0/60.0;
144 bool visualization =
true;
148 const char *basename =
"Joule";
154 args.
AddOption(&mesh_file,
"-m",
"--mesh",
155 "Mesh file to use.");
156 args.
AddOption(&ser_ref_levels,
"-rs",
"--refine-serial",
157 "Number of times to refine the mesh uniformly in serial.");
158 args.
AddOption(&par_ref_levels,
"-rp",
"--refine-parallel",
159 "Number of times to refine the mesh uniformly in parallel.");
161 "Order (degree) of the finite elements.");
162 args.
AddOption(&ode_solver_type,
"-s",
"--ode-solver",
163 "ODE solver: 1 - Backward Euler, 2 - SDIRK2, 3 - SDIRK3\n\t."
164 "\t 22 - Mid-Point, 23 - SDIRK23, 34 - SDIRK34.");
165 args.
AddOption(&t_final,
"-tf",
"--t-final",
166 "Final time; start time is 0.");
167 args.
AddOption(&dt,
"-dt",
"--time-step",
169 args.
AddOption(&mu,
"-mu",
"--permeability",
170 "Magnetic permeability coefficient.");
171 args.
AddOption(&sigma,
"-cnd",
"--sigma",
172 "Conductivity coefficient.");
173 args.
AddOption(&freq,
"-f",
"--frequency",
174 "Frequency of oscillation.");
175 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
176 "--no-visualization",
177 "Enable or disable GLVis visualization.");
178 args.
AddOption(&visit,
"-visit",
"--visit",
"-no-visit",
"--no-visit",
179 "Enable or disable VisIt visualization.");
180 args.
AddOption(&vis_steps,
"-vs",
"--visualization-steps",
181 "Visualize every n-th timestep.");
182 args.
AddOption(&basename,
"-k",
"--outputfilename",
183 "Name of the visit dump files");
184 args.
AddOption(&gfprint,
"-print",
"--print",
185 "Print results (grid functions) to disk.");
188 args.
AddOption(&STATIC_COND,
"-sc",
"--static-condensation",
189 "Enable static condensation");
190 args.
AddOption(&debug,
"-debug",
"--debug",
191 "Print matrices and vectors to disk");
192 args.
AddOption(&SOLVER_PRINT_LEVEL,
"-hl",
"--hypre-print-level",
193 "Hypre print level");
194 args.
AddOption(&problem,
"-p",
"--problem",
195 "Name of problem to run");
216 cout <<
"\nSkin depth sqrt(2.0/(wj*mj*sj)) = " << sqrt(2.0/(wj_*mj_*sj_))
217 <<
"\nSkin depth sqrt(2.0*dt/(mj*sj)) = " << sqrt(2.0*dt/(mj_*sj_))
230 std::map<int, double> sigmaMap, InvTcondMap, TcapMap, InvTcapMap;
234 if (strcmp(problem,
"rod")==0 || strcmp(problem,
"coil")==0)
236 sigmaAir = 1.0e-6 *
sigma;
237 TcondAir = 1.0e6 * Tconductivity;
238 TcapAir = 1.0 * Tcapacity;
242 cerr <<
"Problem " << problem <<
" not recognized\n";
246 if (strcmp(problem,
"rod")==0 || strcmp(problem,
"coil")==0)
249 sigmaMap.insert(pair<int, double>(1, sigma));
250 sigmaMap.insert(pair<int, double>(2, sigmaAir));
251 sigmaMap.insert(pair<int, double>(3, sigmaAir));
253 InvTcondMap.insert(pair<int, double>(1, 1.0/Tconductivity));
254 InvTcondMap.insert(pair<int, double>(2, 1.0/TcondAir));
255 InvTcondMap.insert(pair<int, double>(3, 1.0/TcondAir));
257 TcapMap.insert(pair<int, double>(1, Tcapacity));
258 TcapMap.insert(pair<int, double>(2, TcapAir));
259 TcapMap.insert(pair<int, double>(3, TcapAir));
261 InvTcapMap.insert(pair<int, double>(1, 1.0/Tcapacity));
262 InvTcapMap.insert(pair<int, double>(2, 1.0/TcapAir));
263 InvTcapMap.insert(pair<int, double>(3, 1.0/TcapAir));
267 cerr <<
"Problem " << problem <<
" not recognized\n";
275 mesh =
new Mesh(mesh_file, 1, 1);
282 if (strcmp(problem,
"coil")==0)
298 thermal_ess_bdr[2] = 1;
304 poisson_ess_bdr[0] = 1;
305 poisson_ess_bdr[1] = 1;
308 else if (strcmp(problem,
"rod")==0)
323 thermal_ess_bdr[0] = 1;
324 thermal_ess_bdr[1] = 1;
330 poisson_ess_bdr[0] = 1;
331 poisson_ess_bdr[1] = 1;
336 cerr <<
"Problem " << problem <<
" not recognized\n";
347 switch (ode_solver_type)
360 cout <<
"Unknown ODE solver type: " << ode_solver_type <<
'\n';
369 for (
int lev = 0; lev < ser_ref_levels; lev++)
379 for (
int lev = 0; lev < par_ref_levels; lev++)
392 int numElems = pmesh->
GetNE();
393 for (
int ielem = 0; ielem < numElems; ielem++)
454 cout <<
"Number of Temperature Flux unknowns: " << glob_size_rt << endl;
455 cout <<
"Number of Temperature unknowns: " << glob_size_l2 << endl;
456 cout <<
"Number of Electric Field unknowns: " << glob_size_nd << endl;
457 cout <<
"Number of Magnetic Field unknowns: " << glob_size_rt << endl;
458 cout <<
"Number of Electrostatic unknowns: " << glob_size_h1 << endl;
461 int Vsize_l2 = L2FESpace.
GetVSize();
462 int Vsize_nd = HCurlFESpace.
GetVSize();
463 int Vsize_rt = HDivFESpace.
GetVSize();
464 int Vsize_h1 = HGradFESpace.
GetVSize();
476 true_offset[1] = true_offset[0] + Vsize_l2;
477 true_offset[2] = true_offset[1] + Vsize_rt;
478 true_offset[3] = true_offset[2] + Vsize_h1;
479 true_offset[4] = true_offset[3] + Vsize_nd;
480 true_offset[5] = true_offset[4] + Vsize_rt;
481 true_offset[6] = true_offset[5] + Vsize_l2;
490 T_gf.
MakeRef(&L2FESpace,F, true_offset[0]);
491 F_gf.
MakeRef(&HDivFESpace,F, true_offset[1]);
492 P_gf.
MakeRef(&HGradFESpace,F,true_offset[2]);
493 E_gf.
MakeRef(&HCurlFESpace,F,true_offset[3]);
494 B_gf.
MakeRef(&HDivFESpace,F, true_offset[4]);
495 w_gf.
MakeRef(&L2FESpace,F, true_offset[5]);
510 HDivFESpace, HGradFESpace,
511 ess_bdr, thermal_ess_bdr, poisson_ess_bdr,
512 mu, sigmaMap, TcapMap, InvTcapMap,
519 char vishost[] =
"localhost";
534 int Ww = 350,
Wh = 350;
538 P_gf,
"Electric Potential (Phi)", Wx,
Wy, Ww,
Wh);
542 E_gf,
"Electric Field (E)", Wx,
Wy, Ww,
Wh);
546 B_gf,
"Magnetic Field (B)", Wx,
Wy, Ww,
Wh);
551 w_gf,
"Joule Heating", Wx,
Wy, Ww,
Wh);
556 T_gf,
"Temperature", Wx,
Wy, Ww,
Wh);
581 ode_solver->
Init(oper);
584 bool last_step =
false;
585 for (
int ti = 1; !last_step; ti++)
587 if (t + dt >= t_final - dt/2)
594 ode_solver->
Step(F, t, dt);
598 oper.
Debug(basename,t);
603 ostringstream T_name, E_name, B_name, F_name, w_name, P_name, mesh_name;
604 T_name << basename <<
"_" << setfill(
'0') << setw(6) << t <<
"_"
605 <<
"T." << setfill(
'0') << setw(6) << myid;
606 E_name << basename <<
"_" << setfill(
'0') << setw(6) << t <<
"_"
607 <<
"E." << setfill(
'0') << setw(6) << myid;
608 B_name << basename <<
"_" << setfill(
'0') << setw(6) << t <<
"_"
609 <<
"B." << setfill(
'0') << setw(6) << myid;
610 F_name << basename <<
"_" << setfill(
'0') << setw(6) << t <<
"_"
611 <<
"F." << setfill(
'0') << setw(6) << myid;
612 w_name << basename <<
"_" << setfill(
'0') << setw(6) << t <<
"_"
613 <<
"w." << setfill(
'0') << setw(6) << myid;
614 P_name << basename <<
"_" << setfill(
'0') << setw(6) << t <<
"_"
615 <<
"P." << setfill(
'0') << setw(6) << myid;
616 mesh_name << basename <<
"_" << setfill(
'0') << setw(6) << t <<
"_"
617 <<
"mesh." << setfill(
'0') << setw(6) << myid;
619 ofstream mesh_ofs(mesh_name.str().c_str());
620 mesh_ofs.precision(8);
621 pmesh->
Print(mesh_ofs);
624 ofstream T_ofs(T_name.str().c_str());
629 ofstream E_ofs(E_name.str().c_str());
634 ofstream B_ofs(B_name.str().c_str());
639 ofstream F_ofs(F_name.str().c_str());
644 ofstream P_ofs(P_name.str().c_str());
649 ofstream w_ofs(w_name.str().c_str());
655 if (last_step || (ti % vis_steps) == 0)
662 cout <<
"step " << setw(6) << ti <<
",\tt = " << setw(6)
663 << setprecision(3) << t
664 <<
",\tdot(E, J) = " << setprecision(8) << el << endl;
674 int Ww = 350,
Wh = 350;
678 P_gf,
"Electric Potential (Phi)", Wx,
Wy, Ww,
Wh);
682 E_gf,
"Electric Field (E)", Wx,
Wy, Ww,
Wh);
686 B_gf,
"Magnetic Field (B)", Wx,
Wy, Ww,
Wh);
692 w_gf,
"Joule Heating", Wx,
Wy, Ww,
Wh);
697 T_gf,
"Temperature", Wx,
Wy, Ww,
Wh);
727 namespace electromagnetics
768 return T*cos(wj_ * t);
777 os <<
" ____. .__ " << endl
778 <<
" | | ____ __ __| | ____ " << endl
779 <<
" | |/ _ \\| | \\ | _/ __ \\ " << endl
780 <<
"/\\__| ( <_> ) | / |_\\ ___/ " << endl
781 <<
"\\________|\\____/|____/|____/\\___ >" << endl
int GetVSize() const
Return the number of vector dofs, i.e. GetNDofs() x GetVDim().
void SetCycle(int c)
Set time cycle (for time-dependent simulations)
A class to handle Vectors in a block fashion.
virtual void ReorientTetMesh()
See the remarks for the serial version in mesh.hpp.
virtual void Step(Vector &x, double &t, double &dt)=0
Perform a time step from time t [in] to time t [out] based on the requested step size dt [in]...
void e_exact(const Vector &x, double t, Vector &E)
double t_exact(Vector &x)
virtual void Init(TimeDependentOperator &f)
Associate a TimeDependentOperator with the ODE solver.
Abstract class for solving systems of ODEs: dx/dt = f(x,t)
int GetNE() const
Returns number of elements.
virtual void Save()
Save the collection and a VisIt root file.
virtual void Save(std::ostream &out) const
Abstract parallel finite element space.
int main(int argc, char *argv[])
Backward Euler ODE solver. L-stable.
void DeleteAll()
Delete whole array.
void Debug(const char *basefilename, double time)
virtual void MakeRef(FiniteElementSpace *f, double *v)
Make the ParGridFunction reference external data on a new FiniteElementSpace.
double p_bc(const Vector &x, double t)
void Rebalance()
Load balance the mesh. NC meshes only.
bool Nonconforming() const
A simple convenience class that calls MPI_Init() at construction and MPI_Finalize() at destruction...
int Append(const T &el)
Append element to array, resize if necessary.
void mfem_error(const char *msg)
Function called when an error is encountered. Used by the macros MFEM_ABORT, MFEM_ASSERT, MFEM_VERIFY.
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
Data collection with VisIt I/O routines.
T Max() const
Find the maximal element in the array, using the comparison operator < for class T.
HYPRE_Int GlobalTrueVSize() const
bool Root() const
Return true if WorldRank() == 0.
virtual void Print(std::ostream &out=mfem::out) const
void PrintUsage(std::ostream &out) const
void SetTime(double t)
Set physical time (for time-dependent simulations)
Arbitrary order H(div)-conforming Raviart-Thomas finite elements.
double ElectricLosses(ParGridFunction &E_gf) const
Array< int > bdr_attributes
A list of all unique boundary attributes used by the Mesh.
int WorldRank() const
Return MPI_COMM_WORLD's rank.
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)
virtual void RegisterField(const std::string &field_name, GridFunction *gf)
Add a grid function to the collection and update the root file.
Implicit midpoint method. A-stable, not L-stable.
void PrintOptions(std::ostream &out) const
void E_exact(const Vector &, Vector &)
virtual void Finalize(bool refine=false, bool fix_orientation=false)
Finalize the construction of a general Mesh.
void EnsureNCMesh(bool triangles_nonconforming=false)
void edot_bc(const Vector &x, Vector &E)
class for C-function coefficient
Arbitrary order H(curl)-conforming Nedelec finite elements.
Arbitrary order H1-conforming (continuous) finite elements.
void b_exact(const Vector &x, double t, Vector &B)
Class for parallel grid function.
void display_banner(ostream &os)
void GeneralRefinement(const Array< Refinement > &refinements, int nonconforming=-1, int nc_limit=0)
Class for parallel meshes.
int GetAttribute(int i) const
Return the attribute of element i.
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)
Arbitrary order "L2-conforming" discontinuous finite elements.
double sigma(const Vector &x)