30 #include "libmesh/dof_map.h" 57 const libMesh::DofMap &dof_map = system.get_dof_map();
58 const libMesh::MeshBase &mesh = system.get_mesh();
60 std::set<const libMesh::Node*> negative_phi_nodes;
61 std::vector<const libMesh::Elem*>
64 elems_to_factor.reserve(mesh.n_local_elem()),
65 negative_phi_elems.reserve(mesh.n_local_elem());
69 libMesh::MeshBase::const_element_iterator
70 el = mesh.active_local_elements_begin(),
71 end_el = mesh.active_local_elements_end();
74 for ( ; el != end_el; ++el) {
76 const libMesh::Elem* elem = *el;
77 intersection.
init(phi, *elem, system.time,
78 system.get_mesh().max_elem_id(),
79 system.get_mesh().max_node_id());
84 std::set<const libMesh::Node*>::const_iterator
85 nd_it = negative_phi_nodes.begin(),
86 nd_end = negative_phi_nodes.end();
88 for ( ; nd_it != nd_end; nd_it++) {
91 patch.
init(*elem, **nd_it, phi, system.time);
92 std::set<const libMesh::Elem*>
94 std::set<const libMesh::Elem*>::const_iterator
95 el_it = patch_elems_to_factor.begin(),
96 el_end = patch_elems_to_factor.end();
98 for ( ; el_it != el_end; el_it++)
99 elems_to_factor.push_back(*el_it);
103 negative_phi_nodes.clear();
104 intersection.
clear();
108 std::set<const libMesh::Elem*> elems_to_factor_set(elems_to_factor.begin(),
109 elems_to_factor.end());
111 elems_to_factor.clear();
114 std::set<const libMesh::Elem*>::const_iterator
115 el_it = elems_to_factor_set.begin(),
116 el_end = elems_to_factor_set.end();
118 std::vector<libMesh::dof_id_type> dof_ids;
119 std::pair<const libMesh::Elem*, RealVectorX> elem_sol_pair;
121 for ( ; el_it != el_end; el_it++) {
123 dof_map.dof_indices(*el_it, dof_ids);
124 elem_sol_pair.first = *el_it;
125 elem_sol_pair.second = RealVectorX::Zero(dof_ids.size());
143 std::vector<libMesh::dof_id_type>& material_dofs,
144 std::vector<libMesh::dof_id_type>& void_dofs) {
151 n_nodes = elem.n_nodes();
154 libmesh_assert_equal_to(elem.type(), libMesh::QUAD4);
158 libmesh_assert_equal_to(system.variable_type(0).family, libMesh::LAGRANGE);
163 material_dofs.reserve(nvars*elem.n_nodes());
164 void_dofs.reserve(nvars*elem.n_nodes());
166 for (
unsigned int i=0; i<elem.n_nodes(); i++) {
168 (*_phi)(*elem.node_ptr(i), system.time, val);
172 for (
unsigned int j=0; j<nvars; j++)
173 void_dofs.push_back(j*n_nodes+i);
178 for (
unsigned int j=0; j<nvars; j++)
179 material_dofs.push_back(j*n_nodes+i);
184 std::sort(void_dofs.begin(), void_dofs.end());
185 std::sort(material_dofs.begin(), material_dofs.end());
192 std::vector<libMesh::dof_id_type>& material_dofs,
193 std::vector<libMesh::dof_id_type>& void_dofs) {
202 const libMesh::DofMap &dof_map = system.get_dof_map();
203 std::vector<libMesh::dof_id_type>
206 dof_map.dof_indices(&elem, dof_ids);
208 for (
unsigned int i=0; i<material_dofs.size(); i++)
209 material_dofs[i] = dof_ids[material_dofs[i]];
211 for (
unsigned int i=0; i<void_dofs.size(); i++)
212 void_dofs[i] = dof_ids[void_dofs[i]];
221 std::map<const libMesh::Elem*, RealVectorX>::const_iterator
225 libmesh_assert(it != end);
227 std::vector<libMesh::dof_id_type>
232 &free_sol = it->second;
237 for (
unsigned int i=0; i<void_dofs.size(); i++)
238 elem_sol(void_dofs[i]) = free_sol(void_dofs[i]);
247 std::vector<libMesh::dof_id_type>& material_dof_ids,
250 std::vector<libMesh::dof_id_type>
278 std::vector<libMesh::dof_id_type>& material_dof_ids,
282 std::vector<libMesh::dof_id_type>
303 nu = material_dof_ids.size(),
304 nf = void_dof_ids.size();
307 res_f = RealVectorX::Zero(nf);
309 res_factored_u = RealVectorX::Zero(nu);
311 for (
unsigned int i=0; i<material_dof_ids.size(); i++)
312 res_factored_u(i) = res(material_dof_ids[i]);
314 for (
unsigned int i=0; i<void_dof_ids.size(); i++)
315 res_f(i) = res(void_dof_ids[i]);
319 res_factored_u -= jac_uf * jac_ff_inv * res_f;
328 std::vector<libMesh::dof_id_type>& material_dof_ids,
329 std::vector<libMesh::dof_id_type>& void_dof_ids,
337 material_dof_ids.clear();
338 void_dof_ids.clear();
343 nu = material_dof_ids.size(),
344 nf = void_dof_ids.size();
346 jac_uu = RealMatrixX::Zero(nu, nu);
347 jac_uf = RealMatrixX::Zero(nu, nf);
348 jac_fu = RealMatrixX::Zero(nf, nu);
349 jac_ff = RealMatrixX::Zero(nf, nf);
357 for (
unsigned int i=0; i<nu; i++) {
358 for (
unsigned int j=0; j<nu; j++)
359 jac_uu(i,j) = jac(material_dof_ids[i], material_dof_ids[j]);
361 for (
unsigned int j=0; j<nf; j++)
362 jac_uf(i,j) = jac(material_dof_ids[i], void_dof_ids[j]);
365 for (
unsigned int i=0; i<nf; i++) {
366 for (
unsigned int j=0; j<nu; j++)
367 jac_fu(i,j) = jac(void_dof_ids[i], material_dof_ids[j]);
369 for (
unsigned int j=0; j<nf; j++)
370 jac_ff(i,j) = jac(void_dof_ids[i], void_dof_ids[j]);
375 jac_factored_uu = jac_uu - jac_uf * jac_ff_inv * jac_fu;
388 std::map<const libMesh::Elem*, RealVectorX>::iterator
392 libmesh_assert(it != end);
401 std::vector<libMesh::dof_id_type>
408 libmesh_assert_greater(material_dof_ids.size(), 0);
409 libmesh_assert_greater( void_dof_ids.size(), 0);
412 nu = material_dof_ids.size(),
413 nf = void_dof_ids.size();
416 jac_fu = RealMatrixX::Zero(nf, nu),
417 jac_ff = RealMatrixX::Zero(nf, nf),
421 f_u = RealVectorX::Zero(nu),
422 f_f = RealVectorX::Zero(nf),
423 dx_u = RealVectorX::Zero(nu),
424 dx_f = RealVectorX::Zero(nf);
430 for (
unsigned int i=0; i<nf; i++) {
432 for (
unsigned int j=0; j<nu; j++)
433 jac_fu(i,j) = jac(void_dof_ids[i], material_dof_ids[j]);
435 for (
unsigned int j=0; j<nf; j++)
436 jac_ff(i,j) = jac(void_dof_ids[i], void_dof_ids[j]);
438 f_f(i) = res(void_dof_ids[i]);
441 for (
unsigned int i=0; i<nu; i++)
442 dx_u(i)= dsol(material_dof_ids[i]);
446 dx_f = jac_ff_inv * (-f_f - jac_fu * dx_u);
449 for (
unsigned int i=0; i<nf; i++)
450 updated_sol(void_dof_ids[i]) += dx_f(i);
456 it->second = updated_sol;
468 libmesh_assert_equal_to(m, n);
470 Eigen::FullPivLU<RealMatrixX> solver(mat);
472 rhs = RealVectorX::Zero(m);
474 mat_inv = RealMatrixX::Zero(m, m);
476 for (
unsigned int i=0; i<m; i++) {
478 rhs = RealVectorX::Zero(m);
481 mat_inv.col(i) = solver.solve(rhs);
void element_factored_jacobian(const libMesh::Elem &elem, const RealMatrixX &jac, std::vector< libMesh::dof_id_type > &material_dof_ids, RealMatrixX &jac_factored_uu)
a wrapper around the second element_factored_jacobian.
void update_factored_element_solution(const libMesh::Elem &elem, const RealMatrixX &res, const RealMatrixX &jac, const RealMatrixX &sol, const RealMatrixX &dsol, RealVectorX &updated_sol)
MAST::NonlinearSystem & system()
std::map< const libMesh::Elem *, RealVectorX > _elem_sol
This class implements a system for solution of nonlinear systems.
void solution_of_factored_element(const libMesh::Elem &elem, RealVectorX &elem_sol)
updates the components of the solution vector in elem_sol for the void domain using the stored soluti...
void init(const libMesh::Elem &elem, const libMesh::Node &node, const MAST::FieldFunction< Real > &phi, const Real t)
initialize the patch around node of elem.
LevelSetInterfaceDofHandler()
unsigned int n_vars() const
const std::set< const libMesh::Elem * > & get_elems_to_factor() const
void init(const MAST::FieldFunction< Real > &phi, const libMesh::Elem &e, const Real t, unsigned int max_elem_id, unsigned int max_node_id)
void _compute_matrix_inverse(const RealMatrixX &mat, RealMatrixX &mat_inv)
MAST::FieldFunction< Real > * _phi
Matrix< Real, Dynamic, Dynamic > RealMatrixX
A patch is defines as the set of elements sharing a node.
void element_factored_residual_and_jacobian(const libMesh::Elem &elem, const RealMatrixX &jac, const RealVectorX &res, std::vector< libMesh::dof_id_type > &material_dof_ids, RealMatrixX &jac_factored_uu, RealVectorX &res_factored_u)
factorizes the residual and jacobian into the components for the dofs on material nodes...
Matrix< Real, Dynamic, 1 > RealVectorX
void get_corner_nodes_on_negative_phi(std::set< const libMesh::Node * > &nodes) const
bool if_elem_has_boundary() const
void partition_global_elem_rows(const libMesh::Elem &elem, std::vector< libMesh::dof_id_type > &material_dofs, std::vector< libMesh::dof_id_type > &void_dofs)
fills the material_dofs and void_dofs with the dofs_ids in the global system corresponding to these d...
void init(const MAST::SystemInitialization &sys_init, MAST::LevelSetIntersection &intersection, MAST::FieldFunction< Real > &phi)
const MAST::SystemInitialization * _sys_init
bool if_factor_element(const libMesh::Elem &elem) const
void partition_local_elem_rows(const libMesh::Elem &elem, std::vector< libMesh::dof_id_type > &material_dofs, std::vector< libMesh::dof_id_type > &void_dofs)
identifies which rows in the element residual vector and rows/columns in the jacobian matrix correspo...
virtual ~LevelSetInterfaceDofHandler()
void clear()
clears the data structures