libMesh
Classes | Functions
systems_test.C File Reference

Go to the source code of this file.

Classes

class  AugmentSparsityOnNodes
 
struct  TripleFunction
 
class  SystemsTest
 

Functions

void assemble_matrix_and_rhs (EquationSystems &es, const std::string &system_name)
 
void assembly_with_dg_fem_context (EquationSystems &es, const std::string &)
 
Number cubic_test (const Point &p, const Parameters &, const std::string &, const std::string &)
 
Number new_linear_test (const Point &p, const Parameters &, const std::string &, const std::string &)
 
Number disc_thirds_test (const Point &p, const Parameters &, const std::string &, const std::string &)
 
 CPPUNIT_TEST_SUITE_REGISTRATION (SystemsTest)
 

Function Documentation

◆ assemble_matrix_and_rhs()

void assemble_matrix_and_rhs ( EquationSystems es,
const std::string &  system_name 
)

Definition at line 109 of file systems_test.C.

111 {
112  const MeshBase& mesh = es.get_mesh();
114  const DofMap& dof_map = system.get_dof_map();
115 
118 
119  std::vector<dof_id_type> dof_indices;
120 
123 
124  for ( ; el != end_el; ++el)
125  {
126  const Elem* elem = *el;
127 
128  if(elem->type() == NODEELEM)
129  {
130  continue;
131  }
132 
133  dof_map.dof_indices (elem, dof_indices);
134  const unsigned int n_dofs = dof_indices.size();
135 
136  Ke.resize (n_dofs, n_dofs);
137  Fe.resize (n_dofs);
138 
139  for(unsigned int i=0; i<n_dofs; i++)
140  {
141  Ke(i,i) = 1.;
142  Fe(i) = 1.;
143  }
144 
145  system.matrix->add_matrix (Ke, dof_indices);
146  system.rhs->add_vector (Fe, dof_indices);
147  }
148 
149  // Add matrix for extra coupled dofs
150  {
151  const Node & node_1 = mesh.node_ref(1);
152  const Node & node_2 = mesh.node_ref(2);
153  dof_indices.resize(6);
154  dof_indices[0] =
155  node_1.dof_number(system.number(), system.variable_number("u"), 0);
156  dof_indices[1] =
157  node_1.dof_number(system.number(), system.variable_number("v"), 0);
158  dof_indices[2] =
159  node_1.dof_number(system.number(), system.variable_number("w"), 0);
160 
161  dof_indices[3] =
162  node_2.dof_number(system.number(), system.variable_number("u"), 0);
163  dof_indices[4] =
164  node_2.dof_number(system.number(), system.variable_number("v"), 0);
165  dof_indices[5] =
166  node_2.dof_number(system.number(), system.variable_number("w"), 0);
167 
168  const unsigned int n_dofs = dof_indices.size();
169  Ke.resize (n_dofs, n_dofs);
170  Fe.resize (n_dofs);
171 
172  for(unsigned int i=0; i<n_dofs; i++)
173  {
174  Ke(i,i) = 1.;
175  Fe(i) = 1.;
176  }
177 
178  system.matrix->add_matrix (Ke, dof_indices);
179  system.rhs->add_vector (Fe, dof_indices);
180  }
181 
182  system.rhs->close();
183  system.matrix->close();
184 }

References libMesh::MeshBase::active_local_elements_begin(), libMesh::MeshBase::active_local_elements_end(), libMesh::SparseMatrix< T >::add_matrix(), libMesh::NumericVector< T >::add_vector(), libMesh::SparseMatrix< T >::close(), libMesh::NumericVector< T >::close(), libMesh::DofObject::dof_number(), libMesh::System::get_dof_map(), libMesh::EquationSystems::get_mesh(), libMesh::EquationSystems::get_system(), libMesh::ImplicitSystem::matrix, mesh, libMesh::MeshBase::node_ref(), libMesh::NODEELEM, libMesh::System::number(), libMesh::DenseVector< T >::resize(), libMesh::DenseMatrix< T >::resize(), libMesh::ExplicitSystem::rhs, libMesh::Elem::type(), and libMesh::System::variable_number().

Referenced by SystemsTest::testDofCouplingWithVarGroups().

◆ assembly_with_dg_fem_context()

void assembly_with_dg_fem_context ( EquationSystems es,
const std::string &   
)

Definition at line 187 of file systems_test.C.

189 {
190  const MeshBase& mesh = es.get_mesh();
192 
195 
196  std::vector<dof_id_type> dof_indices;
197 
198  DGFEMContext context(system);
199  {
200  // For efficiency, we should prerequest all
201  // the data we will need to build the
202  // linear system before doing an element loop.
203  FEBase* elem_fe = NULL;
204  context.get_element_fe(0, elem_fe);
205  elem_fe->get_JxW();
206  elem_fe->get_phi();
207  elem_fe->get_dphi();
208 
209  FEBase* side_fe = NULL;
210  context.get_side_fe( 0, side_fe );
211  side_fe->get_JxW();
212  side_fe->get_phi();
213  }
214 
215  for (const auto & elem : mesh.active_local_element_ptr_range())
216  {
217  context.pre_fe_reinit(system, elem);
218  context.elem_fe_reinit();
219 
220  // Element interior assembly
221  {
222  FEBase* elem_fe = NULL;
223  context.get_element_fe(0, elem_fe);
224 
225  const std::vector<Real> &JxW = elem_fe->get_JxW();
226  const std::vector<std::vector<Real> >& phi = elem_fe->get_phi();
227  const std::vector<std::vector<RealGradient> >& dphi = elem_fe->get_dphi();
228 
229  unsigned int n_dofs = context.get_dof_indices(0).size();
230  unsigned int n_qpoints = context.get_element_qrule().n_points();
231 
232  for (unsigned int qp=0; qp != n_qpoints; qp++)
233  for (unsigned int i=0; i != n_dofs; i++)
234  for (unsigned int j=0; j != n_dofs; j++)
235  context.get_elem_jacobian()(i,j) += JxW[qp] * dphi[i][qp]*dphi[j][qp];
236 
237  for (unsigned int qp=0; qp != n_qpoints; qp++)
238  for (unsigned int i=0; i != n_dofs; i++)
239  context.get_elem_residual()(i) += JxW[qp] * phi[i][qp];
240  }
241 
242  system.matrix->add_matrix (context.get_elem_jacobian(), context.get_dof_indices());
243  system.rhs->add_vector (context.get_elem_residual(), context.get_dof_indices());
244 
245  // Element side assembly
246  for (context.side = 0; context.side != elem->n_sides(); ++context.side)
247  {
248  // If there is a neighbor, then we proceed with assembly
249  // that involves elem and neighbor
250  const Elem* neighbor = elem->neighbor_ptr(context.get_side());
251  if(neighbor)
252  {
253  context.side_fe_reinit();
254  context.set_neighbor(*neighbor);
255 
256  // This call initializes neighbor data, and also sets
257  // context.dg_terms_are_active() to true
258  context.neighbor_side_fe_reinit();
259 
260  FEBase* side_fe = NULL;
261  context.get_side_fe(0, side_fe);
262 
263  const std::vector<Real> &JxW_face = side_fe->get_JxW();
264  const std::vector<std::vector<Real> >& phi_face = side_fe->get_phi();
265 
266  FEBase* neighbor_side_fe = NULL;
267  context.get_neighbor_side_fe(0, neighbor_side_fe);
268 
269  // These shape functions have been evaluated on the quadrature points
270  // for elem->side on the neighbor element
271  const std::vector<std::vector<Real> >& phi_neighbor_face =
272  neighbor_side_fe->get_phi();
273 
274  const unsigned int n_dofs = context.get_dof_indices(0).size();
275  const unsigned int n_neighbor_dofs = context.get_neighbor_dof_indices(0).size();
276  unsigned int n_sidepoints = context.get_side_qrule().n_points();
277 
278  for (unsigned int qp=0; qp<n_sidepoints; qp++)
279  {
280  for (unsigned int i=0; i<n_dofs; i++)
281  for (unsigned int j=0; j<n_dofs; j++)
282  {
283  context.get_elem_elem_jacobian()(i,j) +=
284  JxW_face[qp] * phi_face[i][qp] * phi_face[j][qp];
285  }
286 
287  for (unsigned int i=0; i<n_dofs; i++)
288  for (unsigned int j=0; j<n_neighbor_dofs; j++)
289  {
290  context.get_elem_neighbor_jacobian()(i,j) +=
291  JxW_face[qp] * phi_face[i][qp] * phi_neighbor_face[j][qp];
292  }
293 
294  for (unsigned int i=0; i<n_neighbor_dofs; i++)
295  for (unsigned int j=0; j<n_neighbor_dofs; j++)
296  {
297  context.get_neighbor_neighbor_jacobian()(i,j) +=
298  JxW_face[qp] * phi_neighbor_face[i][qp] * phi_neighbor_face[j][qp];
299  }
300 
301  for (unsigned int i=0; i<n_neighbor_dofs; i++)
302  for (unsigned int j=0; j<n_dofs; j++)
303  {
304  context.get_neighbor_elem_jacobian()(i,j) +=
305  JxW_face[qp] * phi_neighbor_face[i][qp] * phi_face[j][qp];
306  }
307  }
308 
309  system.matrix->add_matrix (context.get_elem_elem_jacobian(),
310  context.get_dof_indices(),
311  context.get_dof_indices());
312 
313  system.matrix->add_matrix (context.get_elem_neighbor_jacobian(),
314  context.get_dof_indices(),
315  context.get_neighbor_dof_indices());
316 
317  system.matrix->add_matrix (context.get_neighbor_elem_jacobian(),
318  context.get_neighbor_dof_indices(),
319  context.get_dof_indices());
320 
321  system.matrix->add_matrix (context.get_neighbor_neighbor_jacobian(),
322  context.get_neighbor_dof_indices(),
323  context.get_neighbor_dof_indices());
324  }
325  }
326  }
327 }

References libMesh::MeshBase::active_local_element_ptr_range(), libMesh::SparseMatrix< T >::add_matrix(), libMesh::NumericVector< T >::add_vector(), libMesh::FEMContext::elem_fe_reinit(), libMesh::DiffContext::get_dof_indices(), libMesh::FEGenericBase< OutputType >::get_dphi(), libMesh::DGFEMContext::get_elem_elem_jacobian(), libMesh::DiffContext::get_elem_jacobian(), libMesh::DGFEMContext::get_elem_neighbor_jacobian(), libMesh::DiffContext::get_elem_residual(), libMesh::FEMContext::get_element_fe(), libMesh::FEMContext::get_element_qrule(), libMesh::FEAbstract::get_JxW(), libMesh::EquationSystems::get_mesh(), libMesh::DGFEMContext::get_neighbor_dof_indices(), libMesh::DGFEMContext::get_neighbor_elem_jacobian(), libMesh::DGFEMContext::get_neighbor_neighbor_jacobian(), libMesh::DGFEMContext::get_neighbor_side_fe(), libMesh::FEGenericBase< OutputType >::get_phi(), libMesh::FEMContext::get_side(), libMesh::FEMContext::get_side_fe(), libMesh::FEMContext::get_side_qrule(), libMesh::EquationSystems::get_system(), libMesh::ImplicitSystem::matrix, mesh, libMesh::QBase::n_points(), libMesh::Elem::neighbor_ptr(), libMesh::DGFEMContext::neighbor_side_fe_reinit(), libMesh::FEMContext::pre_fe_reinit(), libMesh::ExplicitSystem::rhs, libMesh::DGFEMContext::set_neighbor(), libMesh::FEMContext::side, and libMesh::DGFEMContext::side_fe_reinit().

Referenced by SystemsTest::testAssemblyWithDgFemContext().

◆ CPPUNIT_TEST_SUITE_REGISTRATION()

CPPUNIT_TEST_SUITE_REGISTRATION ( SystemsTest  )

◆ cubic_test()

Number cubic_test ( const Point p,
const Parameters ,
const std::string &  ,
const std::string &   
)

Definition at line 330 of file systems_test.C.

334 {
335  const Real & x = p(0);
336  const Real & y = LIBMESH_DIM > 1 ? p(1) : 0;
337  const Real & z = LIBMESH_DIM > 2 ? p(2) : 0;
338 
339  return x*(1-x)*(1-x) + x*x*(1-y) + x*(1-y)*(1-z) + y*(1-y)*z + z*(1-z)*(1-z);
340 }

References libMesh::Real.

Referenced by TripleFunction::component(), TripleFunction::operator()(), SystemsTest::testProjectCubeWithMeshFunction(), and SystemsTest::tripleValueTest().

◆ disc_thirds_test()

Number disc_thirds_test ( const Point p,
const Parameters ,
const std::string &  ,
const std::string &   
)

Definition at line 356 of file systems_test.C.

360 {
361  const Real & x = p(0);
362  const Real & y = LIBMESH_DIM > 1 ? p(1) : 0;
363  const Real & z = LIBMESH_DIM > 2 ? p(2) : 0;
364 
365  return (3*x < 1) + (3*y < 2) + (3*z > 2);
366 }

References libMesh::Real.

Referenced by TripleFunction::component(), TripleFunction::operator()(), and SystemsTest::tripleValueTest().

◆ new_linear_test()

Number new_linear_test ( const Point p,
const Parameters ,
const std::string &  ,
const std::string &   
)

Definition at line 343 of file systems_test.C.

347 {
348  const Real & x = p(0);
349  const Real & y = LIBMESH_DIM > 1 ? p(1) : 0;
350  const Real & z = LIBMESH_DIM > 2 ? p(2) : 0;
351 
352  return x + 2*y + 3*z - 1;
353 }

References libMesh::Real.

Referenced by TripleFunction::component(), TripleFunction::operator()(), and SystemsTest::tripleValueTest().

libMesh::SparseMatrix::close
virtual void close()=0
Calls the SparseMatrix's internal assembly routines, ensuring that the values are consistent across p...
libMesh::EquationSystems::get_mesh
const MeshBase & get_mesh() const
Definition: equation_systems.h:637
libMesh::ExplicitSystem::rhs
NumericVector< Number > * rhs
The system matrix.
Definition: explicit_system.h:114
libMesh::MeshBase::active_local_element_ptr_range
virtual SimpleRange< element_iterator > active_local_element_ptr_range()=0
libMesh::MeshBase::active_local_elements_begin
virtual element_iterator active_local_elements_begin()=0
libMesh::DGFEMContext
This class extends FEMContext in order to provide extra data required to perform local element residu...
Definition: dg_fem_context.h:39
libMesh::NumericVector::close
virtual void close()=0
Calls the NumericVector's internal assembly routines, ensuring that the values are consistent across ...
libMesh::FEGenericBase
This class forms the foundation from which generic finite elements may be derived.
Definition: exact_error_estimator.h:39
libMesh::EquationSystems::get_system
const T_sys & get_system(const std::string &name) const
Definition: equation_systems.h:757
libMesh::FEAbstract::get_JxW
const std::vector< Real > & get_JxW() const
Definition: fe_abstract.h:244
libMesh::Elem::set_neighbor
void set_neighbor(const unsigned int i, Elem *n)
Assigns n as the neighbor.
Definition: elem.h:2105
libMesh::DenseMatrix< Number >
libMesh::System::number
unsigned int number() const
Definition: system.h:2075
mesh
MeshBase & mesh
Definition: mesh_communication.C:1257
libMesh::FEGenericBase::get_dphi
const std::vector< std::vector< OutputGradient > > & get_dphi() const
Definition: fe_base.h:214
libMesh::DenseMatrix::resize
void resize(const unsigned int new_m, const unsigned int new_n)
Resize the matrix.
Definition: dense_matrix.h:822
libMesh::DofObject::dof_number
dof_id_type dof_number(const unsigned int s, const unsigned int var, const unsigned int comp) const
Definition: dof_object.h:956
libMesh::NumericVector::add_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].
Definition: numeric_vector.C:363
libMesh::MeshBase
This is the MeshBase class.
Definition: mesh_base.h:78
libMesh::MeshBase::active_local_elements_end
virtual element_iterator active_local_elements_end()=0
libMesh::ImplicitSystem::matrix
SparseMatrix< Number > * matrix
The system matrix.
Definition: implicit_system.h:393
libMesh::Node
A Node is like a Point, but with more information.
Definition: node.h:52
libMesh::MeshBase::const_element_iterator
The definition of the const_element_iterator struct.
Definition: mesh_base.h:1891
libMesh::MeshBase::node_ref
virtual const Node & node_ref(const dof_id_type i) const
Definition: mesh_base.h:451
libMesh::DenseVector::resize
void resize(const unsigned int n)
Resize the vector.
Definition: dense_vector.h:355
libMesh::SparseMatrix::add_matrix
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.
libMesh::DofMap
This class handles the numbering of degrees of freedom on a mesh.
Definition: dof_map.h:176
libMesh::Elem
This is the base class from which all geometric element types are derived.
Definition: elem.h:100
libMesh::System::variable_number
unsigned short int variable_number(const std::string &var) const
Definition: system.C:1232
libMesh::NODEELEM
Definition: enum_elem_type.h:66
libMesh::System::get_dof_map
const DofMap & get_dof_map() const
Definition: system.h:2099
libMesh::Elem::neighbor_ptr
const Elem * neighbor_ptr(unsigned int i) const
Definition: elem.h:2085
libMesh::FEGenericBase::get_phi
const std::vector< std::vector< OutputShape > > & get_phi() const
Definition: fe_base.h:206
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121
libMesh::LinearImplicitSystem
Manages consistently variables, degrees of freedom, coefficient vectors, matrices and linear solvers ...
Definition: linear_implicit_system.h:55
libMesh::Elem::type
virtual ElemType type() const =0
libMesh::DenseVector< Number >