113 using namespace mfem;
114 using namespace mfem::common;
115 using namespace mfem::electromagnetics;
119 static double mj_ = 0.0;
120 static double sj_ = 0.0;
121 static double wj_ = 0.0;
127 int main(
int argc,
char *argv[])
130 Mpi::Init(argc, argv);
131 int myid = Mpi::WorldRank();
138 const char *mesh_file =
"cylinder-hex.mesh";
139 int ser_ref_levels = 0;
140 int par_ref_levels = 0;
142 int ode_solver_type = 1;
143 double t_final = 100.0;
146 double sigma = 2.0*M_PI*10;
147 double Tcapacity = 1.0;
148 double Tconductivity = 0.01;
149 double freq = 1.0/60.0;
150 bool visualization =
true;
154 const char *basename =
"Joule";
160 args.
AddOption(&mesh_file,
"-m",
"--mesh",
161 "Mesh file to use.");
162 args.
AddOption(&ser_ref_levels,
"-rs",
"--refine-serial",
163 "Number of times to refine the mesh uniformly in serial.");
164 args.
AddOption(&par_ref_levels,
"-rp",
"--refine-parallel",
165 "Number of times to refine the mesh uniformly in parallel.");
167 "Order (degree) of the finite elements.");
168 args.
AddOption(&ode_solver_type,
"-s",
"--ode-solver",
169 "ODE solver: 1 - Backward Euler, 2 - SDIRK2, 3 - SDIRK3\n\t."
170 "\t 22 - Mid-Point, 23 - SDIRK23, 34 - SDIRK34.");
171 args.
AddOption(&t_final,
"-tf",
"--t-final",
172 "Final time; start time is 0.");
173 args.
AddOption(&dt,
"-dt",
"--time-step",
175 args.
AddOption(&mu,
"-mu",
"--permeability",
176 "Magnetic permeability coefficient.");
177 args.
AddOption(&sigma,
"-cnd",
"--sigma",
178 "Conductivity coefficient.");
179 args.
AddOption(&freq,
"-f",
"--frequency",
180 "Frequency of oscillation.");
181 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
182 "--no-visualization",
183 "Enable or disable GLVis visualization.");
184 args.
AddOption(&visit,
"-visit",
"--visit",
"-no-visit",
"--no-visit",
185 "Enable or disable VisIt visualization.");
186 args.
AddOption(&vis_steps,
"-vs",
"--visualization-steps",
187 "Visualize every n-th timestep.");
188 args.
AddOption(&basename,
"-k",
"--outputfilename",
189 "Name of the visit dump files");
190 args.
AddOption(&gfprint,
"-print",
"--print",
191 "Print results (grid functions) to disk.");
195 "Enable static condensation");
196 args.
AddOption(&debug,
"-debug",
"--debug",
197 "Print matrices and vectors to disk");
199 "Hypre print level");
200 args.
AddOption(&problem,
"-p",
"--problem",
201 "Name of problem to run");
222 cout <<
"\nSkin depth sqrt(2.0/(wj*mj*sj)) = " << sqrt(2.0/(wj_*mj_*sj_))
223 <<
"\nSkin depth sqrt(2.0*dt/(mj*sj)) = " << sqrt(2.0*dt/(mj_*sj_))
236 std::map<int, double> sigmaMap, InvTcondMap, TcapMap, InvTcapMap;
240 if (strcmp(problem,
"rod")==0 || strcmp(problem,
"coil")==0)
242 sigmaAir = 1.0e-6 *
sigma;
243 TcondAir = 1.0e6 * Tconductivity;
244 TcapAir = 1.0 * Tcapacity;
248 cerr <<
"Problem " << problem <<
" not recognized\n";
252 if (strcmp(problem,
"rod")==0 || strcmp(problem,
"coil")==0)
255 sigmaMap.insert(pair<int, double>(1, sigma));
256 sigmaMap.insert(pair<int, double>(2, sigmaAir));
257 sigmaMap.insert(pair<int, double>(3, sigmaAir));
259 InvTcondMap.insert(pair<int, double>(1, 1.0/Tconductivity));
260 InvTcondMap.insert(pair<int, double>(2, 1.0/TcondAir));
261 InvTcondMap.insert(pair<int, double>(3, 1.0/TcondAir));
263 TcapMap.insert(pair<int, double>(1, Tcapacity));
264 TcapMap.insert(pair<int, double>(2, TcapAir));
265 TcapMap.insert(pair<int, double>(3, TcapAir));
267 InvTcapMap.insert(pair<int, double>(1, 1.0/Tcapacity));
268 InvTcapMap.insert(pair<int, double>(2, 1.0/TcapAir));
269 InvTcapMap.insert(pair<int, double>(3, 1.0/TcapAir));
273 cerr <<
"Problem " << problem <<
" not recognized\n";
281 mesh =
new Mesh(mesh_file, 1, 1);
288 if (strcmp(problem,
"coil")==0)
304 thermal_ess_bdr[2] = 1;
310 poisson_ess_bdr[0] = 1;
311 poisson_ess_bdr[1] = 1;
314 else if (strcmp(problem,
"rod")==0)
329 thermal_ess_bdr[0] = 1;
330 thermal_ess_bdr[1] = 1;
336 poisson_ess_bdr[0] = 1;
337 poisson_ess_bdr[1] = 1;
342 cerr <<
"Problem " << problem <<
" not recognized\n";
353 switch (ode_solver_type)
366 cout <<
"Unknown ODE solver type: " << ode_solver_type <<
'\n';
375 for (
int lev = 0; lev < ser_ref_levels; lev++)
385 for (
int lev = 0; lev < par_ref_levels; lev++)
398 int numElems = pmesh->
GetNE();
399 for (
int ielem = 0; ielem < numElems; ielem++)
456 cout <<
"Number of Temperature Flux unknowns: " << glob_size_rt << endl;
457 cout <<
"Number of Temperature unknowns: " << glob_size_l2 << endl;
458 cout <<
"Number of Electric Field unknowns: " << glob_size_nd << endl;
459 cout <<
"Number of Magnetic Field unknowns: " << glob_size_rt << endl;
460 cout <<
"Number of Electrostatic unknowns: " << glob_size_h1 << endl;
463 int Vsize_l2 = L2FESpace.
GetVSize();
464 int Vsize_nd = HCurlFESpace.
GetVSize();
465 int Vsize_rt = HDivFESpace.
GetVSize();
466 int Vsize_h1 = HGradFESpace.
GetVSize();
479 true_offset[1] = true_offset[0] + Vsize_l2;
480 true_offset[2] = true_offset[1] + Vsize_rt;
481 true_offset[3] = true_offset[2] + Vsize_h1;
482 true_offset[4] = true_offset[3] + Vsize_nd;
483 true_offset[5] = true_offset[4] + Vsize_rt;
484 true_offset[6] = true_offset[5] + Vsize_l2;
493 T_gf.
MakeRef(&L2FESpace,F, true_offset[0]);
494 F_gf.
MakeRef(&HDivFESpace,F, true_offset[1]);
495 P_gf.
MakeRef(&HGradFESpace,F,true_offset[2]);
496 E_gf.
MakeRef(&HCurlFESpace,F,true_offset[3]);
497 B_gf.
MakeRef(&HDivFESpace,F, true_offset[4]);
498 w_gf.
MakeRef(&L2FESpace,F, true_offset[5]);
513 HDivFESpace, HGradFESpace,
514 ess_bdr, thermal_ess_bdr, poisson_ess_bdr,
515 mu, sigmaMap, TcapMap, InvTcapMap,
537 int Ww = 350,
Wh = 350;
541 P_gf,
"Electric Potential (Phi)", Wx,
Wy, Ww,
Wh);
545 E_gf,
"Electric Field (E)", Wx,
Wy, Ww,
Wh);
549 B_gf,
"Magnetic Field (B)", Wx,
Wy, Ww,
Wh);
554 w_gf,
"Joule Heating", Wx,
Wy, Ww,
Wh);
559 T_gf,
"Temperature", Wx,
Wy, Ww,
Wh);
584 ode_solver->
Init(oper);
587 bool last_step =
false;
588 for (
int ti = 1; !last_step; ti++)
590 if (t + dt >= t_final - dt/2)
597 ode_solver->
Step(F, t, dt);
601 oper.
Debug(basename,t);
606 ostringstream T_name, E_name, B_name, F_name, w_name, P_name, mesh_name;
607 T_name << basename <<
"_" << setfill(
'0') << setw(6) << t <<
"_"
608 <<
"T." << setfill(
'0') << setw(6) << myid;
609 E_name << basename <<
"_" << setfill(
'0') << setw(6) << t <<
"_"
610 <<
"E." << setfill(
'0') << setw(6) << myid;
611 B_name << basename <<
"_" << setfill(
'0') << setw(6) << t <<
"_"
612 <<
"B." << setfill(
'0') << setw(6) << myid;
613 F_name << basename <<
"_" << setfill(
'0') << setw(6) << t <<
"_"
614 <<
"F." << setfill(
'0') << setw(6) << myid;
615 w_name << basename <<
"_" << setfill(
'0') << setw(6) << t <<
"_"
616 <<
"w." << setfill(
'0') << setw(6) << myid;
617 P_name << basename <<
"_" << setfill(
'0') << setw(6) << t <<
"_"
618 <<
"P." << setfill(
'0') << setw(6) << myid;
619 mesh_name << basename <<
"_" << setfill(
'0') << setw(6) << t <<
"_"
620 <<
"mesh." << setfill(
'0') << setw(6) << myid;
622 ofstream mesh_ofs(mesh_name.str().c_str());
623 mesh_ofs.precision(8);
624 pmesh->
Print(mesh_ofs);
627 ofstream T_ofs(T_name.str().c_str());
632 ofstream E_ofs(E_name.str().c_str());
637 ofstream B_ofs(B_name.str().c_str());
642 ofstream F_ofs(F_name.str().c_str());
647 ofstream P_ofs(P_name.str().c_str());
652 ofstream w_ofs(w_name.str().c_str());
658 if (last_step || (ti % vis_steps) == 0)
665 cout <<
"step " << setw(6) << ti <<
",\tt = " << setw(6)
666 << setprecision(3) << t
667 <<
",\tdot(E, J) = " << setprecision(8) << el << endl;
677 int Ww = 350,
Wh = 350;
681 P_gf,
"Electric Potential (Phi)", Wx,
Wy, Ww,
Wh);
685 E_gf,
"Electric Field (E)", Wx,
Wy, Ww,
Wh);
689 B_gf,
"Magnetic Field (B)", Wx,
Wy, Ww,
Wh);
695 w_gf,
"Joule Heating", Wx,
Wy, Ww,
Wh);
700 T_gf,
"Temperature", Wx,
Wy, Ww,
Wh);
730 namespace electromagnetics
771 return T*cos(wj_ * t);
780 os <<
" ____. .__ " << endl
781 <<
" | | ____ __ __| | ____ " << endl
782 <<
" | |/ _ \\| | \\ | _/ __ \\ " << endl
783 <<
"/\\__| ( <_> ) | / |_\\ ___/ " << endl
784 <<
"\\________|\\____/|____/|____/\\___ >" << 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 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)
HYPRE_BigInt GlobalTrueVSize() const
Abstract class for solving systems of ODEs: dx/dt = f(x,t)
int GetNE() const
Returns number of elements.
virtual void Save(std::ostream &out) const
Abstract parallel finite element space.
Backward Euler ODE solver. L-stable.
void DeleteAll()
Delete the whole array.
void Debug(const char *basefilename, double time)
int close()
Close the socketstream.
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)
bool Nonconforming() const
void Finalize(bool refine=false, bool fix_orientation=false) override
Finalize the construction of a general Mesh.
void Parse()
Parse the command-line options. Note that this function expects all the options provided through the ...
int Append(const T &el)
Append element 'el' to array, resize if necessary.
void EnsureNCMesh(bool simplices_nonconforming=false)
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.
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)
void PrintUsage(std::ostream &out) const
Print the usage message.
void SetTime(double t)
Set physical time (for time-dependent simulations)
Arbitrary order H(div)-conforming Raviart-Thomas finite elements.
A general vector function coefficient.
double ElectricLosses(ParGridFunction &E_gf) const
Array< int > bdr_attributes
A list of all unique boundary attributes used by the Mesh.
virtual void Save() override
Save the collection and a VisIt root file.
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...
Implicit midpoint method. A-stable, not L-stable.
virtual void SetTime(double t)
Set the time for time dependent coefficients.
void PrintOptions(std::ostream &out) const
Print the options.
void E_exact(const Vector &, Vector &)
void edot_bc(const Vector &x, Vector &E)
A general function coefficient.
Arbitrary order H(curl)-conforming Nedelec finite elements.
double t_exact(const Vector &x)
Arbitrary order H1-conforming (continuous) finite elements.
void Print(std::ostream &out=mfem::out) const override
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.
virtual void Init(TimeDependentOperator &f_)
Associate a TimeDependentOperator with the ODE solver.
Arbitrary order "L2-conforming" discontinuous finite elements.
virtual void RegisterField(const std::string &field_name, GridFunction *gf) override
Add a grid function to the collection and update the root file.
double sigma(const Vector &x)
bool Good() const
Return true if the command line options were parsed successfully.