//
// 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 "coeff.h"
template <typename T, size_t D>
void pass2 (const mesh<T,D>& Th, const std::valarray<size_t>& num,
    matrix<T>& a) {
  for (size_t e = 0; e < Th.size(); e++) {
    T c = 1/meas(Th,e);
    for (size_t ie = 0; ie < D+1; ie++) {
      size_t i = Th[e][ie];
      if (Th.is_boundary(i)) continue;
      a.entry (num[i],num[i])   += c*coeff (Th, e, ie, ie);
      for (size_t je = 0; je < D+1; je++) {
        size_t j = Th[e][je];
        if (je == ie || Th.is_boundary(j)) continue;
        a.entry (num[i],num[j]) += c*coeff (Th, e, ie, je);
      }
    }
  }
}
