33 #include "libmesh/getpot.h" 34 #include "libmesh/mesh.h" 35 #include "libmesh/mesh_generation.h" 36 #include "libmesh/linear_implicit_system.h" 37 #include "libmesh/equation_systems.h" 38 #include "libmesh/fe.h" 39 #include "libmesh/elem.h" 40 #include "libmesh/quadrature_gauss.h" 41 #include "libmesh/dense_matrix.h" 42 #include "libmesh/sparse_matrix.h" 43 #include "libmesh/numeric_vector.h" 44 #include "libmesh/dof_map.h" 45 #include "libmesh/point_locator_tree.h" 47 #include "libmesh/inf_fe.h" 48 #include "libmesh/inf_elem_builder.h" 50 #include "libmesh/error_vector.h" 51 #include "libmesh/mesh_refinement.h" 52 #include "libmesh/kelly_error_estimator.h" 54 #include "libmesh/parallel_ghost_sync.h" 61 #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS 66 const FEType fe_type = dof_map.variable_type(0);
70 const std::set<dof_id_type > charged_objects = es.
parameters.
get<std::set<dof_id_type> >(
"charged_elem_id");
73 fe->attach_quadrature_rule (&*qrule);
74 inf_fe->attach_quadrature_rule (&*qrule);
82 std::vector<dof_id_type> dof_indices;
86 for (
const auto & elem :
mesh.active_local_element_ptr_range())
92 dof_map.dof_indices (elem, dof_indices);
95 FEBase * cfe = libmesh_nullptr;
115 M.
resize (dof_indices.size(), dof_indices.size());
116 f.
resize (dof_indices.size());
120 if (charged_objects.count(elem->id()))
121 rho=1./elem->volume();
126 for (
unsigned int qp=0; qp<max_qp; ++qp)
128 const unsigned int n_sf =
130 for (
unsigned int i=0; i<n_sf; ++i)
133 f(i) -=4*
pi*JxW[qp]*rho*phi[i][qp];
137 const RealGradient dphi_i=dphi[i][qp]*sob_w[qp]+phi[i][qp]*dsob_w[qp];
138 for (
unsigned int j=0; j<n_sf; ++j)
140 M(i,j) += JxW[qp]*dphi_i*dphi[j][qp];
144 dof_map.constrain_element_matrix_and_vector(M, f, dof_indices);
153 #else //ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS 160 int main (
int argc,
char** argv)
166 std::cout <<
"Running " << argv[0];
167 for (
int i=1; i<argc; i++)
168 std::cout <<
" " << argv[i];
169 std::cout << std::endl << std::endl;
171 #ifndef LIBMESH_ENABLE_INFINITE_ELEMENTS 172 libmesh_example_requires(
false,
"--enable-ifem");
177 libmesh_example_requires(3 <= LIBMESH_DIM,
"3D support");
206 for (
auto & elem :
mesh.element_ptr_range())
207 if (elem->infinite())
209 elem->subdomain_id() = 1;
211 elem->neighbor_ptr(0)->subdomain_id()=2;
227 auto & pt_lctr = *p_pt_lctr;
228 pt_lctr.enable_out_of_mesh_mode();
230 std::set<dof_id_type> charged_elem_ids;
232 Point pt_0(-3.,-3.0,-1.5);
233 Point pt_1(2.,-2.6,-1.5);
234 Point pt_2(2., 3.1, 1.7);
235 const Elem * elem_0=pt_lctr(pt_0);
237 charged_elem_ids.insert(elem_0->
id());
238 const Elem * elem_1=pt_lctr(pt_1);
240 charged_elem_ids.insert(elem_1->
id());
241 const Elem * elem_2=pt_lctr(pt_2);
243 charged_elem_ids.insert(elem_2->
id());
251 libmesh_assert_equal_to(charged_elem_ids.size(), 3);
260 eq_sys.
parameters.
set<std::set<dof_id_type> >(
"charged_elem_id")=charged_elem_ids;
277 #ifdef LIBMESH_ENABLE_AMR 278 for (
unsigned int i=0; i< 2; ++i)
294 std::set<dof_id_type> charged_elem_children;
295 for(
auto id : charged_elem_ids)
307 if (!child.is_remote())
308 charged_elem_children.insert(child.id());
311 charged_elem_children.insert(charged_elem->
id());
314 charged_elem_ids=charged_elem_children;
318 eq_sys.
parameters.
set<std::set<dof_id_type> >(
"charged_elem_id")=charged_elem_ids;
323 #endif // LIBMESH_ENABLE_AMR 326 #endif // LIBMESH_ENABLE_INFINITE_ELEMENTS class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
This is the EquationSystems class.
static unsigned int n_dofs(const unsigned int dim, const FEType &fe_t, const ElemType t)
virtual const std::vector< Real > & get_Sobolev_weightxR_sq() const
std::unique_ptr< PointLocatorBase > sub_point_locator() const
void allow_renumbering(bool allow)
If false is passed in then this mesh will no longer be renumbered when being prepared for use...
The ErrorVector is a specialization of the StatisticsVector for error data computed on a finite eleme...
Manages consistently variables, degrees of freedom, coefficient vectors, matrices and linear solvers ...
void resize(const unsigned int n)
Resize the vector.
virtual void add_vector(const T *v, const std::vector< numeric_index_type > &dof_indices)
Computes , where v is a pointer and each dof_indices[i] specifies where to add value v[i]...
virtual void find_neighbors(const bool reset_remote_elements=false, const bool reset_current_list=true, const bool assert_valid=true)=0
Locate element face (edge in 2D) neighbors.
This is the base class from which all geometric element types are derived.
NumericVector< Number > * rhs
The system matrix.
const Parallel::Communicator & comm() const
Real & refine_fraction()
The refine_fraction sets either a desired target or a desired maximum number of elements to flag for ...
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
The libMesh namespace provides an interface to certain functionality in the library.
virtual void solve() override
Assembles & solves the linear system A*x=b.
const T_sys & get_system(std::string_view name) const
This is the MeshBase class.
SimpleRange< ChildRefIter > child_ref_range()
Returns a range with all children of a parent element, usable in range-based for loops.
FEType get_fe_type() const
This class handles the numbering of degrees of freedom on a mesh.
std::unique_ptr< QBase > default_quadrature_rule(const unsigned int dim, const int extraorder=0) const
virtual bool is_serial() const
void libmesh_ignore(const Args &...)
virtual void add_matrix(const DenseMatrix< T > &dm, const std::vector< numeric_index_type > &rows, const std::vector< numeric_index_type > &cols)=0
Add the full matrix dm to the SparseMatrix.
const T & get(std::string_view) const
Implements (adaptive) mesh refinement algorithms for a MeshBase.
virtual const std::vector< Real > & get_JxWxdecay_sq() const
This function is the variant of get_JxW() for InfFE.
virtual unsigned int n_quadrature_points() const
void print_info(std::ostream &os=libMesh::out, const unsigned int verbosity=0, const bool global=true) const
Prints relevant information about the mesh.
virtual void reinit()
Handle any mesh changes and reinitialize all the systems on the updated mesh.
virtual const std::vector< std::vector< OutputShape > > & get_phi_over_decayxR() const
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
static std::unique_ptr< FEGenericBase > build(const unsigned int dim, const FEType &type)
Builds a specific finite element type.
virtual void reinit(const Elem *elem, const std::vector< Point > *const pts=nullptr, const std::vector< Real > *const weights=nullptr)=0
This is at the core of this class.
unsigned int add_variable(std::string_view var, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=nullptr)
Adds the variable var to the list of variables for this system.
void attach_assemble_function(void fptr(EquationSystems &es, const std::string &name))
Register a user function to use in assembling the system matrix and RHS.
void sync_dofobject_data_by_id(const Communicator &comm, const Iterator &range_begin, const Iterator &range_end, SyncFunctor &sync)
Request data about a range of ghost dofobjects uniquely identified by their id.
virtual void close()=0
Calls the NumericVector's internal assembly routines, ensuring that the values are consistent across ...
This class is used to build infinite elements on top of an existing mesh.
void assemble_func(EquationSystems &es, const std::string &system_name)
This class implements the Kelly error indicator which is based on the flux jumps between elements...
virtual void close()=0
Calls the SparseMatrix's internal assembly routines, ensuring that the values are consistent across p...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual const Elem * query_elem_ptr(const dof_id_type i) const =0
const Point build_inf_elem(const bool be_verbose=false)
Build infinite elements atop a volume-based mesh, determine origin automatically. ...
int main(int argc, char **argv)
T & set(const std::string &)
SparseMatrix< Number > * matrix
The system matrix.
bool refine_and_coarsen_elements()
Refines and coarsens user-requested elements.
const MeshBase & get_mesh() const
void resize(const unsigned int new_m, const unsigned int new_n)
Resizes the matrix to the specified size and calls zero().
unsigned int mesh_dimension() const
Parameters parameters
Data structure holding arbitrary parameters.
void flag_elements_by_error_fraction(const ErrorVector &error_per_cell, const Real refine_fraction=0.3, const Real coarsen_fraction=0.0, const unsigned int max_level=libMesh::invalid_uint)
Flags elements for coarsening and refinement based on the computed error passed in error_per_cell...
static std::unique_ptr< FEGenericBase > build_InfFE(const unsigned int dim, const FEType &type)
Builds a specific infinite element type.
virtual const std::vector< RealGradient > & get_Sobolev_dweightxR_sq() const
virtual void estimate_error(const System &system, ErrorVector &error_per_cell, const NumericVector< Number > *solution_vector=nullptr, bool estimate_parent_error=false) override
This function uses the derived class's jump error estimate formula to estimate the error on each cell...
virtual void init()
Initialize all the systems.
virtual System & add_system(std::string_view system_type, std::string_view name)
Add the system of type system_type named name to the systems array.
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
const DofMap & get_dof_map() const
A Point defines a location in LIBMESH_DIM dimensional Real space.
bool has_children() const
This class forms the foundation from which generic finite elements may be derived.
virtual const std::vector< std::vector< OutputGradient > > & get_dphi_over_decayxR() const
void set_union(T &data, const unsigned int root_id) const