20 using namespace common;
22 namespace electromagnetics
25 VoltaSolver::VoltaSolver(
ParMesh & pmesh,
int order,
29 double (*phi_bc )(
const Vector&),
30 double (*rho_src)(
const Vector&),
70 rho_src_func_(rho_src),
72 point_charge_params_(point_charges),
76 MPI_Comm_size(pmesh_->
GetComm(), &num_procs_);
77 MPI_Comm_rank(pmesh_->
GetComm(), &myid_);
90 for (
int i=0; i<dbcs_->
Size(); i++)
92 ess_bdr_[(*dbcs_)[i]-1] = 1;
98 if ( phi_bc_func_ != NULL )
104 if ( rho_src_func_ != NULL )
110 if ( p_src_func_ != NULL )
144 if ( point_charge_params_.
Size() > 0 )
147 int npts = point_charge_params_.
Size() / (dim + 1);
148 point_charges_.resize(npts);
151 for (
int i=0; i<npts; i++)
153 for (
int d=0; d<
dim; d++)
155 cent[d] = point_charge_params_[(dim + 1) * i + d];
157 double s = point_charge_params_[(dim + 1) * i + dim];
160 point_charges_[i]->SetScale(s);
161 point_charges_[i]->SetDeltaCenter(cent);
186 if ( nbcs_->
Size() > 0 )
219 delete hCurlHDivEps_;
224 delete HCurlFESpace_;
228 for (
unsigned int i=0; i<point_charges_.size(); i++)
230 delete point_charges_[i];
233 map<string,socketstream*>::iterator mit;
234 for (mit=socks_.begin(); mit!=socks_.end(); mit++)
255 cout <<
"Number of H1 unknowns: " << size_h1 << endl;
256 cout <<
"Number of H(Curl) unknowns: " << size_nd << endl;
257 cout <<
"Number of H(Div) unknowns: " << size_rt << endl;
258 cout <<
"Number of L2 unknowns: " << size_l2 << endl;
264 if (myid_ == 0) { cout <<
"Assembling ... " << flush; }
308 if (myid_ == 0) { cout <<
"done." << endl << flush; }
314 if (myid_ == 0) { cout <<
"Updating ..." << endl; }
319 H1FESpace_->
Update(
false);
320 HCurlFESpace_->
Update(
false);
321 HDivFESpace_->
Update(
false);
322 L2FESpace_->
Update(
false);
332 if ( rho_src_ ) { rho_src_->
Update(); }
333 if ( sigma_src_ ) { sigma_src_->
Update(); }
334 if ( p_src_ ) { p_src_->
Update(); }
341 if ( h1Mass_ ) { h1Mass_->
Update(); }
342 if ( h1SurfMass_ ) { h1SurfMass_->
Update(); }
343 if ( hCurlHDiv_ ) { hCurlHDiv_->
Update(); }
344 if ( weakDiv_ ) { weakDiv_->
Update(); }
354 if (myid_ == 0) { cout <<
"Running solver ... " << endl; }
359 if ( dbcs_->
Size() > 0 )
370 for (
int i=0; i<dbcs_->
Size(); i++)
374 if ((*dbcs_)[i] <= dbc_bdr_attr.Size())
376 dbc_bdr_attr[(*dbcs_)[i]-1] = 1;
387 h1Mass_->
AddMult(*rho_src_, *rhod_);
394 weakDiv_->
AddMult(*p_src_, *rhod_);
403 for (
int i=0; i<nbcs_->
Size(); i++)
407 if ((*nbcs_)[i] <= nbc_bdr_attr.Size())
409 nbc_bdr_attr[(*nbcs_)[i]-1] = 1;
413 h1SurfMass_->
AddMult(*sigma_src_, *rhod_);
417 if ( dbcs_->
Size() > 0 )
428 ess_bdr_tdofs_[0] = 0;
458 grad_->
Mult(*phi_, *e_); *e_ *= -1.0;
461 if (myid_ == 0) { cout <<
"Computing D ..." << flush; }
464 hCurlHDivEps_->
Mult(*e_, ed);
467 hCurlHDiv_->
AddMult(*p_src_, ed, -1.0);
487 div_->
Mult(*d_, *rho_);
489 if (myid_ == 0) { cout <<
"done." << flush; }
493 double charge_rho = (*l2_vol_int_)(*rho_);
496 double charge_D = (*rt_surf_int_)(*d_);
500 cout << endl <<
"Total charge: \n"
501 <<
" Volume integral of charge density: " << charge_rho
502 <<
"\n Surface integral of dielectric flux: " << charge_D
507 if (myid_ == 0) { cout <<
"Solver done. " << endl; }
513 if (myid_ == 0) { cout <<
"Estimating Error ... " << flush; }
527 smooth_flux_fes, flux_fes, errors, norm_p);
529 if (myid_ == 0) { cout <<
"done." << endl; }
535 visit_dc_ = &visit_dc;
541 if ( rho_src_ ) { visit_dc.
RegisterField(
"Rho Source", rho_src_); }
542 if ( p_src_ ) { visit_dc.
RegisterField(
"P Source", p_src_); }
543 if ( sigma_src_ ) { visit_dc.
RegisterField(
"Sigma Source", sigma_src_); }
551 if (myid_ == 0) { cout <<
"Writing VisIt files ..." << flush; }
558 if (myid_ == 0) { cout <<
" done." << endl; }
565 if ( myid_ == 0 ) { cout <<
"Opening GLVis sockets." << endl; }
568 socks_[
"Phi"]->precision(8);
571 socks_[
"D"]->precision(8);
574 socks_[
"E"]->precision(8);
577 socks_[
"Rho"]->precision(8);
582 socks_[
"RhoSrc"]->precision(8);
587 socks_[
"PSrc"]->precision(8);
592 socks_[
"SigmaSrc"]->precision(8);
599 if (myid_ == 0) { cout <<
"Sending data to GLVis ..." << flush; }
601 char vishost[] =
"localhost";
605 int Ww = 350,
Wh = 350;
609 *phi_,
"Electric Potential (Phi)", Wx,
Wy, Ww,
Wh);
613 *e_,
"Electric Field (E)", Wx,
Wy, Ww,
Wh);
617 *d_,
"Electric Displacement (D)", Wx,
Wy, Ww,
Wh);
621 *rho_,
"Charge Density", Wx,
Wy, Ww,
Wh);
627 *rho_src_,
"Charge Density Source (Rho)", Wx,
Wy, Ww,
Wh);
633 *p_src_,
"Electric Polarization Source (P)",
640 *sigma_src_,
"Surface Charge Density Source (Sigma)",
644 if (myid_ == 0) { cout <<
" done." << endl; }
651 #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
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)
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.
Arbitrary order "L2-conforming" discontinuous finite elements.