19 using namespace miniapps;
21 namespace electromagnetics
24 VoltaSolver::VoltaSolver(
ParMesh & pmesh,
int order,
28 double (*phi_bc )(
const Vector&),
29 double (*rho_src)(
const Vector&),
66 point_charge_params_(point_charges),
70 MPI_Comm_size(pmesh_->
GetComm(), &num_procs_);
71 MPI_Comm_rank(pmesh_->
GetComm(), &myid_);
83 for (
int i=0; i<dbcs_->
Size(); i++)
85 ess_bdr_[(*dbcs_)[i]-1] = 1;
91 if ( phi_bc_ != NULL )
97 if ( rho_src_ != NULL )
103 if ( p_src_ != NULL )
129 if ( point_charge_params_.
Size() > 0 )
132 int npts = point_charge_params_.
Size() / (dim + 1);
133 point_charges_.resize(npts);
136 for (
int i=0; i<npts; i++)
138 for (
int d=0; d<
dim; d++)
140 cent[d] = point_charge_params_[(dim + 1) * i + d];
142 double s = point_charge_params_[(dim + 1) * i + dim];
145 point_charges_[i]->SetScale(s);
146 point_charges_[i]->SetDeltaCenter(cent);
172 if ( nbcs_->
Size() > 0 )
201 delete hCurlHDivEps_;
206 delete HCurlFESpace_;
209 for (
unsigned int i=0; i<point_charges_.size(); i++)
211 delete point_charges_[i];
214 map<string,socketstream*>::iterator mit;
215 for (mit=socks_.begin(); mit!=socks_.end(); mit++)
235 cout <<
"Number of H1 unknowns: " << size_h1 << endl;
236 cout <<
"Number of H(Curl) unknowns: " << size_nd << endl;
237 cout <<
"Number of H(Div) unknowns: " << size_rt << endl;
243 if (myid_ == 0) { cout <<
"Assembling ... " << flush; }
281 if (myid_ == 0) { cout <<
"done." << endl << flush; }
287 if (myid_ == 0) { cout <<
"Updating ..." << endl; }
292 H1FESpace_->
Update(
false);
293 HCurlFESpace_->
Update(
false);
294 HDivFESpace_->
Update(
false);
301 if ( rho_ ) { rho_->
Update(); }
302 if ( sigma_ ) { sigma_->
Update(); }
303 if ( p_ ) { p_->
Update(); }
310 if ( h1Mass_ ) { h1Mass_->
Update(); }
311 if ( h1SurfMass_ ) { h1SurfMass_->
Update(); }
312 if ( hCurlHDiv_ ) { hCurlHDiv_->
Update(); }
313 if ( weakDiv_ ) { weakDiv_->
Update(); }
322 if (myid_ == 0) { cout <<
"Running solver ... " << endl; }
327 if ( dbcs_->
Size() > 0 )
338 for (
int i=0; i<dbcs_->
Size(); i++)
342 dbc_bdr_attr[(*dbcs_)[i]-1] = 1;
352 h1Mass_->
AddMult(*rho_, *rhod_);
359 weakDiv_->
AddMult(*p_, *rhod_);
368 for (
int i=0; i<nbcs_->
Size(); i++)
372 nbc_bdr_attr[(*nbcs_)[i]-1] = 1;
375 h1SurfMass_->
AddMult(*sigma_, *rhod_);
379 if ( dbcs_->
Size() > 0 )
390 ess_bdr_tdofs_[0] = 0;
420 grad_->
Mult(*phi_, *e_); *e_ *= -1.0;
423 if (myid_ == 0) { cout <<
"Computing D ..." << flush; }
426 hCurlHDivEps_->
Mult(*e_, ed);
429 hCurlHDiv_->
AddMult(*p_, ed, -1.0);
448 if (myid_ == 0) { cout <<
"done." << flush; }
450 if (myid_ == 0) { cout <<
"Solver done. " << endl; }
456 if (myid_ == 0) { cout <<
"Estimating Error ... " << flush; }
470 smooth_flux_fes, flux_fes, errors, norm_p);
472 if (myid_ == 0) { cout <<
"done." << endl; }
478 visit_dc_ = &visit_dc;
493 if (myid_ == 0) { cout <<
"Writing VisIt files ..." << flush; }
500 if (myid_ == 0) { cout <<
" done." << endl; }
507 if ( myid_ == 0 ) { cout <<
"Opening GLVis sockets." << endl; }
510 socks_[
"Phi"]->precision(8);
513 socks_[
"D"]->precision(8);
516 socks_[
"E"]->precision(8);
521 socks_[
"Rho"]->precision(8);
526 socks_[
"P"]->precision(8);
531 socks_[
"Sigma"]->precision(8);
538 if (myid_ == 0) { cout <<
"Sending data to GLVis ..." << flush; }
540 char vishost[] =
"localhost";
544 int Ww = 350,
Wh = 350;
548 *phi_,
"Electric Potential (Phi)", Wx,
Wy, Ww,
Wh);
552 *d_,
"Electric Displacement (D)", Wx,
Wy, Ww,
Wh);
556 *e_,
"Electric Field (E)", Wx,
Wy, Ww,
Wh);
563 *rho_,
"Charge Density (Rho)", Wx,
Wy, Ww,
Wh);
569 *p_,
"Electric Polarization (P)", Wx,
Wy, Ww,
Wh);
575 *sigma_,
"Surface Charge Density (Sigma)", Wx,
Wy, Ww,
Wh);
578 if (myid_ == 0) { cout <<
" done." << endl; }
585 #endif // MFEM_USE_MPI
void WriteVisItFields(int it=0)
int Size() const
Logical size of the array.
Class for domain integration L(v) := (f, v)
virtual void GetEssentialTrueDofs(const Array< int > &bdr_attr_is_ess, Array< int > &ess_tdof_list, int component=-1)
void SetCycle(int c)
Set time cycle (for time-dependent simulations)
Subclass constant coefficient.
HYPRE_Int GetProblemSize()
virtual void Update(bool want_transform=true)
Delta function coefficient.
int Size() const
Returns the size of the vector.
virtual void Save()
Save the collection and a VisIt root file.
Abstract parallel finite element space.
void RegisterVisItFields(VisItDataCollection &visit_dc)
virtual void ProjectCoefficient(Coefficient &coeff)
void SetPrintLevel(int print_lvl)
void GetErrorEstimates(Vector &errors)
The BoomerAMG solver in hypre.
virtual void Update()
Transform by the Space UpdateMatrix (e.g., on Mesh change).
Jacobi preconditioner in hypre.
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
void SetTime(double t)
Set physical time (for time-dependent simulations)
void SetMaxIter(int max_iter)
Arbitrary order H(div)-conforming Raviart-Thomas finite elements.
int SpaceDimension() const
Wrapper for hypre's parallel vector class.
Array< int > bdr_attributes
A list of all unique boundary attributes used by the Mesh.
void ProjectBdrCoefficient(Coefficient *coeff[], VectorCoefficient *vcoeff, Array< int > &attr)
Base class Coefficient that may optionally depend on time.
void SetSize(int nsize)
Change logical size of the array, keep existing entries.
double L2ZZErrorEstimator(BilinearFormIntegrator &flux_integrator, const ParGridFunction &x, ParFiniteElementSpace &smooth_flux_fes, ParFiniteElementSpace &flux_fes, Vector &errors, int norm_p, double solver_tol, int solver_max_it)
virtual void RegisterField(const std::string &field_name, GridFunction *gf)
Add a grid function to the collection and update the root file.
void SetPreconditioner(HypreSolver &precond)
Set the hypre solver to be used as a preconditioner.
class for C-function coefficient
Class for parallel grid function.
Wrapper for hypre's ParCSR matrix class.
virtual void Assemble(int skip_zeros=1)
Construct the internal matrix representation of the discrete linear operator.
virtual void Mult(const HypreParVector &b, HypreParVector &x) const
Solve Ax=b with hypre's PCG.
Class for parallel meshes.
Integrator for (Q u, v) for VectorFiniteElements.
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.