const Table<2,bool> &dof_mask,
internal::bool2type<true>) const;
+ /**
+ * This function returns a pointer to
+ * the respective ConstraintLine object
+ * if a dof is constrained, and a zero
+ * pointer otherwise.
+ */
+ std::vector<ConstraintLine>::const_iterator
+ find_constraint (const unsigned int line) const;
+
+ /**
+ * This function returns a pointer to
+ * the respective ConstraintLine object
+ * if a dof is constrained, and a zero
+ * pointer otherwise. This function is
+ * used if the constraint matrix has not
+ * been closed yet.
+ */
+ std::vector<ConstraintLine>::iterator
+ find_constraint (const unsigned int line);
+
#ifdef DEAL_II_USE_TRILINOS
//TODO: Make use of the following member thread safe
/**
Assert (line != column,
ExcMessage ("Can't constrain a degree of freedom to itself"));
- std::vector<ConstraintLine>::iterator line_ptr;
- const std::vector<ConstraintLine>::const_iterator start=lines.begin();
-
- // the usual case is that the line where
- // a value is entered is the one we
- // added last, so we search backward
- for (line_ptr=(lines.end()-1); line_ptr!=start; --line_ptr)
- if (line_ptr->line == line)
- break;
-
- // if the loop didn't break, then
- // line_ptr must be begin().
- // we have an error if that doesn't
- // point to 'line' then
- Assert (line_ptr->line==line, ExcLineInexistant(line));
- // second check: the respective
- // flag in the
- // constraint_line_exists field
- // must exist
- Assert (line < constraint_line_exists.size(), ExcInternalError());
- Assert (constraint_line_exists[line] == true, ExcInternalError());
-
+ std::vector<ConstraintLine>::iterator line_ptr = find_constraint(line);
// if in debug mode, check whether an
// entry for this column already
ConstraintMatrix::set_inhomogeneity (const unsigned int line,
const double value)
{
- std::vector<ConstraintLine>::iterator line_ptr;
- const std::vector<ConstraintLine>::const_iterator start=lines.begin();
-
- // the usual case is that the line where
- // the inhomogeneity is set to the one we
- // added last, so we search backward
- for (line_ptr=(lines.end()-1); line_ptr!=start; --line_ptr)
- if (line_ptr->line == line)
- break;
-
- // if the loop didn't break, then
- // line_ptr must be begin().
- // we have an error if that doesn't
- // point to 'line' then
- Assert (line_ptr->line==line, ExcLineInexistant(line));
- // second check: the respective
- // flag in the
- // constraint_line_exists field
- // must exist
- Assert (line < constraint_line_exists.size(), ExcInternalError());
- Assert (constraint_line_exists[line] == true, ExcInternalError());
-
- line_ptr->inhomogeneity = value;
+ find_constraint(line)->inhomogeneity = value;
}
bool
ConstraintMatrix::is_inhomogeneously_constrained (const unsigned int index) const
{
- if (is_constrained(index) == false)
- return false;
+ const std::vector<ConstraintLine>::const_iterator position
+ = find_constraint(index);
+ return position!=lines.end() ? position->inhomogeneity != 0 : false;
+}
+
+
+
+inline
+std::vector<ConstraintMatrix::ConstraintLine>::const_iterator
+ConstraintMatrix::find_constraint (const unsigned int line) const
+{
+ if (is_constrained(line) == false)
+ return lines.end();
+ Assert (sorted==true, ExcMatrixNotClosed());
ConstraintLine index_comparison;
- index_comparison.line = index;
+ index_comparison.line = line;
const std::vector<ConstraintLine>::const_iterator
position = std::lower_bound (lines.begin(),
lines.end(),
index_comparison);
Assert (position != lines.end(), ExcInternalError());
- return position->inhomogeneity != 0;
+
+ // check whether we've really found the
+ // right constraint.
+ Assert (position->line == line,
+ ExcInternalError());
+
+ return position;
+}
+
+
+
+inline
+std::vector<ConstraintMatrix::ConstraintLine>::iterator
+ConstraintMatrix::find_constraint (const unsigned int line)
+{
+ Assert (sorted==false, ExcMatrixIsClosed());
+ std::vector<ConstraintLine>::iterator line_ptr;
+ const std::vector<ConstraintLine>::const_iterator start=lines.begin();
+
+ // the usual case is that the line where
+ // a value is entered is the one we
+ // added last, so we search backward
+ for (line_ptr=(lines.end()-1); line_ptr!=start; --line_ptr)
+ if (line_ptr->line == line)
+ break;
+
+ // if the loop didn't break, then
+ // line_ptr must be begin().
+ // we have an error if that doesn't
+ // point to 'line' then
+ Assert (line_ptr->line==line, ExcLineInexistant(line));
+ // second check: the respective
+ // flag in the
+ // constraint_line_exists field
+ // must exist
+ Assert (line < constraint_line_exists.size(), ExcInternalError());
+ Assert (constraint_line_exists[line] == true, ExcInternalError());
+
+ return line_ptr;
}
DEAL_II_NAMESPACE_CLOSE
// vector that tells about whether a
// certain constraint exists. then, we
// simply copy over the data.
- if (is_constrained (local_dof_indices[i]) == false)
+ const std::vector<ConstraintLine>::const_iterator position =
+ find_constraint(local_dof_indices[i]);
+
+ if (position==lines.end())
{
global_vector(local_dof_indices[i]) += local_vector(i);
continue;
}
- // if the dof is constrained, we
- // have to find it in the list of
- // all constraints.
- ConstraintLine index_comparison;
- index_comparison.line = local_dof_indices[i];
-
- const std::vector<ConstraintLine>::const_iterator
- position = std::lower_bound (lines.begin(),
- lines.end(),
- index_comparison);
-
- // check whether we've really found the
- // right constraint.
- Assert (position->line == local_dof_indices[i],
- ExcInternalError());
-
if (use_matrix)
{
const double val = position->inhomogeneity;
if (val != 0)
for (unsigned int j=0; j<n_local_dofs; ++j)
- if (is_constrained (local_dof_indices[j]) == false)
- {
+ {
+ const std::vector<ConstraintLine>::const_iterator
+ position_j = find_constraint(local_dof_indices[j]);
+
+ if (position_j == lines.end())
global_vector(local_dof_indices[j]) -= val * local_matrix(j,i);
- }
- else
- {
- const double matrix_entry = local_matrix(j,i);
- if (matrix_entry == 0)
- continue;
-
- ConstraintLine index_comparison_j;
- index_comparison_j.line = local_dof_indices[j];
-
- const std::vector<ConstraintLine>::const_iterator
- position_j = std::lower_bound (lines.begin(),
- lines.end(),
- index_comparison_j);
- for (unsigned int q=0; q<position_j->entries.size(); ++q)
- {
- Assert (is_constrained(position_j->entries[q].first) == false,
- ExcMessage ("Tried to distribute to a fixed dof."));
- global_vector(position_j->entries[q].first)
- -= val * position_j->entries[q].second * matrix_entry;
- }
- }
+ else
+ {
+ const double matrix_entry = local_matrix(j,i);
+ if (matrix_entry == 0)
+ continue;
+
+ for (unsigned int q=0; q<position_j->entries.size(); ++q)
+ {
+ Assert (is_constrained(position_j->entries[q].first) == false,
+ ExcMessage ("Tried to distribute to a fixed dof."));
+ global_vector(position_j->entries[q].first)
+ -= val * position_j->entries[q].second * matrix_entry;
+ }
+ }
+ }
}
else
// in case the constraint is
// resolved in a second step.
for (unsigned int i = 0; i<n_local_dofs; ++i)
{
- if (constraint_line_exists.size() <= local_dof_indices[i] ||
- constraint_line_exists[local_dof_indices[i]] == false)
+ const std::vector<ConstraintLine>::const_iterator position =
+ find_constraint(local_dof_indices[i]);
+ if (position == lines.end())
{
my_indices[added_rows].global_row = local_dof_indices[i];
my_indices[added_rows].local_row = i;
continue;
}
- ConstraintLine index_comparison;
- index_comparison.line = local_dof_indices[i];
-
- const std::vector<ConstraintLine>::const_iterator
- position = std::lower_bound (lines.begin(),
- lines.end(),
- index_comparison);
- Assert (position->line == local_dof_indices[i],
- ExcInternalError());
-
constraint_lines.push_back (std::make_pair<unsigned int,
const ConstraintLine *>(i,&*position));
}
unsigned int added_rows = 0;
for (unsigned int i = 0; i<n_local_dofs; ++i)
{
- if (constraint_line_exists.size() <= local_dof_indices[i] ||
- constraint_line_exists[local_dof_indices[i]] == false)
+ const std::vector<ConstraintLine>::const_iterator position
+ = find_constraint (local_dof_indices[i]);
+ if (position == lines.end())
{
my_indices[added_rows].global_row = local_dof_indices[i];
my_indices[added_rows].local_row = i;
continue;
}
- ConstraintLine index_comparison;
- index_comparison.line = local_dof_indices[i];
-
- const std::vector<ConstraintLine>::const_iterator
- position = std::lower_bound (lines.begin(),
- lines.end(),
- index_comparison);
- Assert (position->line == local_dof_indices[i],
- ExcInternalError());
-
constraint_lines.push_back (std::make_pair<unsigned int,
const ConstraintLine *>(i,&*position));
}
std::vector<std::pair<unsigned int, const ConstraintLine *> > constraint_lines;
for (unsigned int i = 0; i<n_local_dofs; ++i)
{
- if (constraint_line_exists.size() <= local_dof_indices[i] ||
- constraint_line_exists[local_dof_indices[i]] == false)
+ const std::vector<ConstraintLine>::const_iterator position
+ = find_constraint(local_dof_indices[i]);
+ if (position == lines.end())
{
actual_dof_indices[added_rows] = local_dof_indices[i];
++added_rows;
continue;
}
- ConstraintLine index_comparison;
- index_comparison.line = local_dof_indices[i];
-
- const std::vector<ConstraintLine>::const_iterator
- position = std::lower_bound (lines.begin(),
- lines.end(),
- index_comparison);
- Assert (position->line == local_dof_indices[i],
- ExcInternalError());
-
constraint_lines.push_back (std::make_pair<unsigned int,
const ConstraintLine *>(i,&*position));
}
// resolved in a second step.
for (unsigned int i = 0; i<n_local_dofs; ++i)
{
- if (constraint_line_exists.size() <= local_dof_indices[i] ||
- constraint_line_exists[local_dof_indices[i]] == false)
+ const std::vector<ConstraintLine>::const_iterator position
+ = find_constraint(local_dof_indices[i]);
+ if (position == lines.end())
{
my_indices[added_rows].global_row = local_dof_indices[i];
my_indices[added_rows].local_row = i;
continue;
}
- ConstraintLine index_comparison;
- index_comparison.line = local_dof_indices[i];
-
- const std::vector<ConstraintLine>::const_iterator
- position = std::lower_bound (lines.begin(),
- lines.end(),
- index_comparison);
- Assert (position->line == local_dof_indices[i],
- ExcInternalError());
-
constraint_lines.push_back (std::make_pair<unsigned int,
const ConstraintLine *>(i,&*position));
}
std::vector<std::pair<unsigned int, const ConstraintLine *> > constraint_lines;
for (unsigned int i = 0; i<n_local_dofs; ++i)
{
- if (constraint_line_exists.size() <= local_dof_indices[i] ||
- constraint_line_exists[local_dof_indices[i]] == false)
+ const std::vector<ConstraintLine>::const_iterator position
+ = find_constraint(local_dof_indices[i]);
+ if (position == lines.end())
{
actual_dof_indices[added_rows] = local_dof_indices[i];
++added_rows;
continue;
}
- ConstraintLine index_comparison;
- index_comparison.line = local_dof_indices[i];
-
- const std::vector<ConstraintLine>::const_iterator
- position = std::lower_bound (lines.begin(),
- lines.end(),
- index_comparison);
- Assert (position->line == local_dof_indices[i],
- ExcInternalError());
-
constraint_lines.push_back (std::make_pair<unsigned int,
const ConstraintLine *>(i,&*position));
}