www.mooseframework.org
SparsityBasedContactConstraint.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
11 
12 // MOOSE includes
13 #include "MooseVariable.h"
14 
15 #include "libmesh/petsc_macro.h"
16 #include "libmesh/petsc_matrix.h"
17 
19 
20 template <>
21 InputParameters
23 {
24  InputParameters params = validParams<NodeFaceConstraint>();
25  return params;
26 }
27 
28 void
30 {
31 #if defined(LIBMESH_HAVE_PETSC) && !PETSC_VERSION_LESS_THAN(3, 3, 0)
32  _connected_dof_indices.clear();
33 
34  // An ugly hack: have to extract the row and look at it's sparsity structure, since otherwise I
35  // won't get the dofs connected to this row by virtue of intervariable coupling
36  // This is easier than sifting through all coupled variables, selecting those active on the
37  // current subdomain, dealing with the scalar variables, etc.
38  // Also, importantly, this will miss coupling to variables that might have introduced by prior
39  // constraints similar to this one!
40  PetscMatrix<Number> * petsc_jacobian = dynamic_cast<PetscMatrix<Number> *>(_jacobian);
41  mooseAssert(petsc_jacobian, "Expected a PETSc matrix");
42  Mat jac = petsc_jacobian->mat();
43  PetscErrorCode ierr;
44  PetscInt ncols;
45  const PetscInt * cols;
46  ierr = MatGetRow(jac, static_cast<PetscInt>(_var.nodalDofIndex()), &ncols, &cols, PETSC_NULL);
47  CHKERRABORT(_communicator.get(), ierr);
48  bool debug = false;
49  if (debug)
50  {
51  libMesh::out << "_connected_dof_indices: adding " << ncols << " dofs from Jacobian row["
52  << _var.nodalDofIndex() << "] = [";
53  }
54  for (PetscInt i = 0; i < ncols; ++i)
55  {
56  if (debug)
57  {
58  libMesh::out << cols[i] << " ";
59  }
60  _connected_dof_indices.push_back(cols[i]);
61  }
62  if (debug)
63  {
64  libMesh::out << "]\n";
65  }
66  ierr = MatRestoreRow(jac, static_cast<PetscInt>(_var.nodalDofIndex()), &ncols, &cols, PETSC_NULL);
67  CHKERRABORT(_communicator.get(), ierr);
68 #else
69  NodeFaceConstraint::getConnectedDofIndices();
70 #endif
71 }
validParams< SparsityBasedContactConstraint >
InputParameters validParams< SparsityBasedContactConstraint >()
Definition: SparsityBasedContactConstraint.C:22
SparsityBasedContactConstraint.h
registerMooseObject
registerMooseObject("ContactApp", SparsityBasedContactConstraint)
SparsityBasedContactConstraint::getConnectedDofIndices
virtual void getConnectedDofIndices()
Gets the indices for all dofs conected to the constraint Get indices for all the slave Jacobian colum...
Definition: SparsityBasedContactConstraint.C:29
SparsityBasedContactConstraint
Definition: SparsityBasedContactConstraint.h:21