//
// This file is part of the book "Language C++ et calcul scientifique"
//
// Copyright (C) 2005-2012 Pierre Saramito <Pierre.Saramito@imag.fr>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
//
#include "unique_insert.h"
template <typename T, size_t D>
void pass1 (const mesh<T,D>& Th,
  const std::valarray<size_t>& num, matrix<T>& a)
{
  size_t n = Th.n_internal_vertex();
  std::vector<std::list<size_t> > s(n);
  for (size_t e = 0; e < Th.size(); e++)
    for (size_t ie = 0; ie < D+1; ie++) {
      size_t i = Th[e][ie];
      if (Th.is_boundary(i)) continue;
      unique_insert (s[num[i]], num[i]);
      for (size_t je = 0; je < D+1; je++) {
        size_t j = Th[e][je];
        if (je == ie || Th.is_boundary(j)) continue;
        unique_insert (s[num[i]], num[j]);
      }
    }
  a.resize (s, n);
}
