/*
 *    vmg - a versatile multigrid solver
 *    Copyright (C) 2012 Institute for Numerical Simulation, University of Bonn
 *
 *  vmg 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.
 *
 *  vmg 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 .
 */
/*
 * interface_sinus.cpp
 *
 *  Created on: 31.03.2011
 *      Author: Julian Iseringhausen
 */
#ifdef HAVE_CONFIG_H
#include 
#endif
#include 
#include 
#include "grid/grid.hpp"
#include "grid/multigrid.hpp"
#include "interface_sinus.hpp"
using namespace VMG;
using VMGInterfaces::InterfaceSinus;
void InterfaceSinus::ImportRightHandSide(Multigrid& multigrid)
{
  Index i;
  Vector pos;
  Grid& grid = multigrid(multigrid.MaxLevel());
  grid.Clear();
  const Index begin_local = grid.Global().LocalBegin() - grid.Local().HaloSize1();
  for (i.X()=grid.Local().Begin().X(); i.X()(begin_local + i);
	grid(i) = 3.0 * sine_factor * sine_factor * std::sin(sine_factor * pos.X()) * std::sin(sine_factor * pos.Y()) * std::sin(sine_factor * pos.Z());
      }
}
void InterfaceSinus::ExportSolution(Grid& grid)
{
  Index i;
  vmg_float err_1 = 0.0;
  vmg_float err_2 = 0.0;
  vmg_float err_inf = 0.0;
  const Index begin_local = grid.Global().LocalBegin() - grid.Local().HaloSize1();
  for (i.X()=grid.Local().Begin().X(); i.X()(begin_local + i);
	const vmg_float err = std::abs(grid.GetVal(i) - std::sin(sine_factor * pos.X()) * std::sin(sine_factor * pos.Y()) * std::sin(sine_factor * pos.Z()));
	err_1 += err;
	err_2 += err * err;
	err_inf = std::max(err_inf, err);
      }
  err_1 = grid.Extent().MeshWidth().Product() * err_1;
  err_2 = std::sqrt(grid.Extent().MeshWidth().Product() * err_2);
  err_inf = grid.Extent().MeshWidth().Product() * err_inf;
  std::cout << std::scientific << "Error L1-Norm:   " << err_1 << std::endl
	    << "Error L2-Norm:   " << err_2 << std::endl
	    << "Error Inf-Norm: " << err_inf << std::endl;
}