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" 59 #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS 64 const FEType fe_type = dof_map.variable_type(0);
68 const std::vector<dof_id_type > charged_objects = es.
parameters.
get<std::vector<dof_id_type> >(
"charged_elem_id");
71 fe->attach_quadrature_rule (&*qrule);
72 inf_fe->attach_quadrature_rule (&*qrule);
80 std::vector<dof_id_type> dof_indices;
84 for (
const auto & elem :
mesh.active_local_element_ptr_range())
90 dof_map.dof_indices (elem, dof_indices);
93 FEBase * cfe = libmesh_nullptr;
113 M.
resize (dof_indices.size(), dof_indices.size());
114 f.
resize (dof_indices.size());
118 if (std::find(charged_objects.begin(), charged_objects.end(), elem->id()) != charged_objects.end())
119 rho=1./elem->volume();
124 for (
unsigned int qp=0; qp<max_qp; ++qp)
126 const unsigned int n_sf =
128 for (
unsigned int i=0; i<n_sf; ++i)
131 f(i) -=4*
pi*JxW[qp]*rho*phi[i][qp];
135 const RealGradient dphi_i=dphi[i][qp]*sob_w[qp]+phi[i][qp]*dsob_w[qp];
136 for (
unsigned int j=0; j<n_sf; ++j)
138 M(i,j) += JxW[qp]*dphi_i*dphi[j][qp];
142 dof_map.constrain_element_matrix_and_vector(M, f, dof_indices);
151 #else //ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS 158 int main (
int argc,
char** argv)
164 std::cout <<
"Running " << argv[0];
165 for (
int i=1; i<argc; i++)
166 std::cout <<
" " << argv[i];
167 std::cout << std::endl << std::endl;
169 #ifndef LIBMESH_ENABLE_INFINITE_ELEMENTS 170 libmesh_example_requires(
false,
"--enable-ifem");
175 libmesh_example_requires(3 <= LIBMESH_DIM,
"3D support");
200 for (
auto & elem :
mesh.element_ptr_range())
201 if (elem->infinite())
203 elem->subdomain_id() = 1;
205 elem->neighbor_ptr(0)->subdomain_id()=2;
212 std::vector<dof_id_type> charged_elem_ids(3);
214 Point pt_0(-3.,-3.0,-1.5);
215 Point pt_1(2.,-2.6,-1.5);
216 Point pt_2(2., 3.1, 1.7);
217 const Elem * elem_0=pt_lctr(pt_0);
219 charged_elem_ids[0]=elem_0->
id();
222 libmesh_not_implemented();
223 const Elem * elem_1=pt_lctr(pt_1);
225 charged_elem_ids[1]=elem_1->
id();
227 libmesh_not_implemented();
228 const Elem * elem_2=pt_lctr(pt_2);
230 charged_elem_ids[2]=elem_2->
id();
232 libmesh_not_implemented();
241 eq_sys.
parameters.
set<std::vector<dof_id_type> >(
"charged_elem_id")=charged_elem_ids;
258 #ifdef LIBMESH_ENABLE_AMR 259 for (
unsigned int i=0; i< 2; ++i)
275 std::vector<dof_id_type> charged_elem_child(0);
276 for(
unsigned int j=0; j< charged_elem_ids.size(); ++j)
282 charged_elem_child.push_back(child.id());
285 charged_elem_child.push_back(charged_elem->
id());
288 charged_elem_ids=charged_elem_child;
289 eq_sys.
parameters.
set<std::vector<dof_id_type> >(
"charged_elem_id")=charged_elem_ids;
294 #endif // LIBMESH_ENABLE_AMR 297 #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
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]...
This is the base class from which all geometric element types are derived.
NumericVector< Number > * rhs
The system matrix.
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
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.
virtual void find_neighbors(const bool reset_remote_elements=false, const bool reset_current_list=true)=0
Locate element face (edge in 2D) neighbors.
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.
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.
virtual const Elem * elem_ptr(const dof_id_type i) const =0
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
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