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[])
137 const char *mesh_file =
"cylinder-hex.mesh";
138 int ser_ref_levels = 0;
139 int par_ref_levels = 0;
141 int ode_solver_type = 1;
142 double t_final = 100.0;
145 double sigma = 2.0*M_PI*10;
146 double Tcapacity = 1.0;
147 double Tconductivity = 0.01;
148 double freq = 1.0/60.0;
149 bool visualization =
true;
153 const char *basename =
"Joule";
159 args.
AddOption(&mesh_file,
"-m",
"--mesh",
160 "Mesh file to use.");
161 args.
AddOption(&ser_ref_levels,
"-rs",
"--refine-serial",
162 "Number of times to refine the mesh uniformly in serial.");
163 args.
AddOption(&par_ref_levels,
"-rp",
"--refine-parallel",
164 "Number of times to refine the mesh uniformly in parallel.");
166 "Order (degree) of the finite elements.");
167 args.
AddOption(&ode_solver_type,
"-s",
"--ode-solver",
168 "ODE solver: 1 - Backward Euler, 2 - SDIRK2, 3 - SDIRK3\n\t."
169 "\t 22 - Mid-Point, 23 - SDIRK23, 34 - SDIRK34.");
170 args.
AddOption(&t_final,
"-tf",
"--t-final",
171 "Final time; start time is 0.");
172 args.
AddOption(&dt,
"-dt",
"--time-step",
174 args.
AddOption(&mu,
"-mu",
"--permeability",
175 "Magnetic permeability coefficient.");
176 args.
AddOption(&sigma,
"-cnd",
"--sigma",
177 "Conductivity coefficient.");
178 args.
AddOption(&freq,
"-f",
"--frequency",
179 "Frequency of oscillation.");
180 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
181 "--no-visualization",
182 "Enable or disable GLVis visualization.");
183 args.
AddOption(&visit,
"-visit",
"--visit",
"-no-visit",
"--no-visit",
184 "Enable or disable VisIt visualization.");
185 args.
AddOption(&vis_steps,
"-vs",
"--visualization-steps",
186 "Visualize every n-th timestep.");
187 args.
AddOption(&basename,
"-k",
"--outputfilename",
188 "Name of the visit dump files");
189 args.
AddOption(&gfprint,
"-print",
"--print",
190 "Print results (grid functions) to disk.");
194 "Enable static condensation");
195 args.
AddOption(&debug,
"-debug",
"--debug",
196 "Print matrices and vectors to disk");
198 "Hypre print level");
199 args.
AddOption(&problem,
"-p",
"--problem",
200 "Name of problem to run");
221 cout <<
"\nSkin depth sqrt(2.0/(wj*mj*sj)) = " << sqrt(2.0/(wj_*mj_*sj_))
222 <<
"\nSkin depth sqrt(2.0*dt/(mj*sj)) = " << sqrt(2.0*dt/(mj_*sj_))
235 std::map<int, double> sigmaMap, InvTcondMap, TcapMap, InvTcapMap;
239 if (strcmp(problem,
"rod")==0 || strcmp(problem,
"coil")==0)
241 sigmaAir = 1.0e-6 *
sigma;
242 TcondAir = 1.0e6 * Tconductivity;
243 TcapAir = 1.0 * Tcapacity;
247 cerr <<
"Problem " << problem <<
" not recognized\n";
251 if (strcmp(problem,
"rod")==0 || strcmp(problem,
"coil")==0)
254 sigmaMap.insert(pair<int, double>(1, sigma));
255 sigmaMap.insert(pair<int, double>(2, sigmaAir));
256 sigmaMap.insert(pair<int, double>(3, sigmaAir));
258 InvTcondMap.insert(pair<int, double>(1, 1.0/Tconductivity));
259 InvTcondMap.insert(pair<int, double>(2, 1.0/TcondAir));
260 InvTcondMap.insert(pair<int, double>(3, 1.0/TcondAir));
262 TcapMap.insert(pair<int, double>(1, Tcapacity));
263 TcapMap.insert(pair<int, double>(2, TcapAir));
264 TcapMap.insert(pair<int, double>(3, TcapAir));
266 InvTcapMap.insert(pair<int, double>(1, 1.0/Tcapacity));
267 InvTcapMap.insert(pair<int, double>(2, 1.0/TcapAir));
268 InvTcapMap.insert(pair<int, double>(3, 1.0/TcapAir));
272 cerr <<
"Problem " << problem <<
" not recognized\n";
280 mesh =
new Mesh(mesh_file, 1, 1);
287 if (strcmp(problem,
"coil")==0)
303 thermal_ess_bdr[2] = 1;
309 poisson_ess_bdr[0] = 1;
310 poisson_ess_bdr[1] = 1;
313 else if (strcmp(problem,
"rod")==0)
328 thermal_ess_bdr[0] = 1;
329 thermal_ess_bdr[1] = 1;
335 poisson_ess_bdr[0] = 1;
336 poisson_ess_bdr[1] = 1;
341 cerr <<
"Problem " << problem <<
" not recognized\n";
352 switch (ode_solver_type)
365 cout <<
"Unknown ODE solver type: " << ode_solver_type <<
'\n';
374 for (
int lev = 0; lev < ser_ref_levels; lev++)
384 for (
int lev = 0; lev < par_ref_levels; lev++)
397 int numElems = pmesh->
GetNE();
398 for (
int ielem = 0; ielem < numElems; ielem++)
459 cout <<
"Number of Temperature Flux unknowns: " << glob_size_rt << endl;
460 cout <<
"Number of Temperature unknowns: " << glob_size_l2 << endl;
461 cout <<
"Number of Electric Field unknowns: " << glob_size_nd << endl;
462 cout <<
"Number of Magnetic Field unknowns: " << glob_size_rt << endl;
463 cout <<
"Number of Electrostatic unknowns: " << glob_size_h1 << endl;
466 int Vsize_l2 = L2FESpace.
GetVSize();
467 int Vsize_nd = HCurlFESpace.
GetVSize();
468 int Vsize_rt = HDivFESpace.
GetVSize();
469 int Vsize_h1 = HGradFESpace.
GetVSize();
481 true_offset[1] = true_offset[0] + Vsize_l2;
482 true_offset[2] = true_offset[1] + Vsize_rt;
483 true_offset[3] = true_offset[2] + Vsize_h1;
484 true_offset[4] = true_offset[3] + Vsize_nd;
485 true_offset[5] = true_offset[4] + Vsize_rt;
486 true_offset[6] = true_offset[5] + Vsize_l2;
495 T_gf.
MakeRef(&L2FESpace,F, true_offset[0]);
496 F_gf.
MakeRef(&HDivFESpace,F, true_offset[1]);
497 P_gf.
MakeRef(&HGradFESpace,F,true_offset[2]);
498 E_gf.
MakeRef(&HCurlFESpace,F,true_offset[3]);
499 B_gf.
MakeRef(&HDivFESpace,F, true_offset[4]);
500 w_gf.
MakeRef(&L2FESpace,F, true_offset[5]);
515 HDivFESpace, HGradFESpace,
516 ess_bdr, thermal_ess_bdr, poisson_ess_bdr,
517 mu, sigmaMap, TcapMap, InvTcapMap,
524 char vishost[] =
"localhost";
539 int Ww = 350,
Wh = 350;
543 P_gf,
"Electric Potential (Phi)", Wx,
Wy, Ww,
Wh);
547 E_gf,
"Electric Field (E)", Wx,
Wy, Ww,
Wh);
551 B_gf,
"Magnetic Field (B)", Wx,
Wy, Ww,
Wh);
556 w_gf,
"Joule Heating", Wx,
Wy, Ww,
Wh);
561 T_gf,
"Temperature", Wx,
Wy, Ww,
Wh);
586 ode_solver->
Init(oper);
589 bool last_step =
false;
590 for (
int ti = 1; !last_step; ti++)
592 if (t + dt >= t_final - dt/2)
599 ode_solver->
Step(F, t, dt);
603 oper.
Debug(basename,t);
608 ostringstream T_name, E_name, B_name, F_name, w_name, P_name, mesh_name;
609 T_name << basename <<
"_" << setfill(
'0') << setw(6) << t <<
"_"
610 <<
"T." << setfill(
'0') << setw(6) << myid;
611 E_name << basename <<
"_" << setfill(
'0') << setw(6) << t <<
"_"
612 <<
"E." << setfill(
'0') << setw(6) << myid;
613 B_name << basename <<
"_" << setfill(
'0') << setw(6) << t <<
"_"
614 <<
"B." << setfill(
'0') << setw(6) << myid;
615 F_name << basename <<
"_" << setfill(
'0') << setw(6) << t <<
"_"
616 <<
"F." << setfill(
'0') << setw(6) << myid;
617 w_name << basename <<
"_" << setfill(
'0') << setw(6) << t <<
"_"
618 <<
"w." << setfill(
'0') << setw(6) << myid;
619 P_name << basename <<
"_" << setfill(
'0') << setw(6) << t <<
"_"
620 <<
"P." << setfill(
'0') << setw(6) << myid;
621 mesh_name << basename <<
"_" << setfill(
'0') << setw(6) << t <<
"_"
622 <<
"mesh." << setfill(
'0') << setw(6) << myid;
624 ofstream mesh_ofs(mesh_name.str().c_str());
625 mesh_ofs.precision(8);
626 pmesh->
Print(mesh_ofs);
629 ofstream T_ofs(T_name.str().c_str());
634 ofstream E_ofs(E_name.str().c_str());
639 ofstream B_ofs(B_name.str().c_str());
644 ofstream F_ofs(F_name.str().c_str());
649 ofstream P_ofs(P_name.str().c_str());
654 ofstream w_ofs(w_name.str().c_str());
660 if (last_step || (ti % vis_steps) == 0)
667 cout <<
"step " << setw(6) << ti <<
",\tt = " << setw(6)
668 << setprecision(3) << t
669 <<
",\tdot(E, J) = " << setprecision(8) << el << endl;
679 int Ww = 350,
Wh = 350;
683 P_gf,
"Electric Potential (Phi)", Wx,
Wy, Ww,
Wh);
687 E_gf,
"Electric Field (E)", Wx,
Wy, Ww,
Wh);
691 B_gf,
"Magnetic Field (B)", Wx,
Wy, Ww,
Wh);
697 w_gf,
"Joule Heating", Wx,
Wy, Ww,
Wh);
702 T_gf,
"Temperature", Wx,
Wy, Ww,
Wh);
732 namespace electromagnetics
773 return T*cos(wj_ * t);
782 os <<
" ____. .__ " << endl
783 <<
" | | ____ __ __| | ____ " << endl
784 <<
" | |/ _ \\| | \\ | _/ __ \\ " << endl
785 <<
"/\\__| ( <_> ) | / |_\\ ___/ " << endl
786 <<
"\\________|\\____/|____/|____/\\___ >" << 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)
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 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.
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 edot_bc(const Vector &x, Vector &E)
class for C-function coefficient
Arbitrary order H(curl)-conforming Nedelec finite elements.
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 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.
Arbitrary order "L2-conforming" discontinuous finite elements.
double sigma(const Vector &x)