Index: src/Jobs/InterfaceVMGDebugGridJob.cpp
===================================================================
--- src/Jobs/InterfaceVMGDebugGridJob.cpp	(revision 2388688c3e24cb54fc978d6c8efd1ddead979d8a)
+++ src/Jobs/InterfaceVMGDebugGridJob.cpp	(revision 2388688c3e24cb54fc978d6c8efd1ddead979d8a)
@@ -0,0 +1,112 @@
+/*
+ * Project: MoleCuilder
+ * Description: creates and alters molecular systems
+ * Copyright (C)  2012 University of Bonn. All rights reserved.
+ * 
+ *
+ *   This file is part of MoleCuilder.
+ *
+ *    MoleCuilder 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 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    MoleCuilder 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 MoleCuilder.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * InterfaceVMGDebugGridJob.cpp
+ *
+ *  Created on: 10.06.2012
+ *      Author: Frederik Heber
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef HAVE_MPI
+#include "mpi.h"
+#endif
+
+#include "base/vector.hpp"
+#include "base/math.hpp"
+#include "comm/comm.hpp"
+#include "grid/grid.hpp"
+#include "grid/multigrid.hpp"
+#include "mg.hpp"
+
+#include "InterfaceVMGDebugGridJob.hpp"
+
+#include "CodePatterns/MemDebug.hpp"
+
+#include <cmath>
+#include <iostream>
+
+#include "CodePatterns/Log.hpp"
+
+
+using namespace VMG;
+using VMGInterfaces::InterfaceVMGDebugGridJob;
+
+InterfaceVMGDebugGridJob::InterfaceVMGDebugGridJob(
+    const std::vector< double > &_sampled_input,
+    VMG::Boundary boundary,
+    int levelMin,
+    int levelMax,
+    const VMG::Vector &box_begin,
+    vmg_float box_end,
+    const int& near_field_cells,
+    int coarseningSteps,
+    double alpha) :
+  VMG::Interface(boundary, levelMin, levelMax,
+      box_begin, box_end, coarseningSteps, alpha),
+  sampled_input(_sampled_input),
+  level(levelMax)
+{
+}
+
+InterfaceVMGDebugGridJob::~InterfaceVMGDebugGridJob()
+{}
+
+void InterfaceVMGDebugGridJob::ImportRightHandSide(Multigrid& multigrid)
+{
+  Index i;
+  Vector pos;
+  //  VMG::TempGrid *temp_grid = new VMG::TempGrid(129, 0, 0., 1.);
+
+  Grid& grid = multigrid(multigrid.MaxLevel());
+  //grid.ClearBoundary(); // we don't have a boundary under periodic boundary conditions
+
+  // print debugging info on grid size
+  LOG(1, "INFO: Mesh has extent " << grid.Extent().MeshWidth() << ".");
+  const int gridpoints = pow(2, level);
+  LOG(1, "INFO: gridpoints on finest level are " << gridpoints << ".");
+  LOG(1, "INFO: "
+      << "X in [" << grid.Local().Begin().X() << "," << grid.Local().End().X() << "],"
+      << "Y in [" << grid.Local().Begin().Y() << "," << grid.Local().End().Y() << "],"
+      << "Z in [" << grid.Local().Begin().Z() << "," << grid.Local().End().Z() << "].");
+
+  // add sampled grid points to grid
+  std::vector<double>::const_iterator sample_iter = sampled_input.begin();
+  for (Grid::iterator iter = grid.Iterators().Local().Begin();
+      iter != grid.Iterators().Local().End();
+      ++iter)
+    grid(*iter) = -1. * (*sample_iter++);
+  assert( sample_iter == sampled_input.end() );
+
+  // print electron grid to vtk
+  Comm& comm = *MG::GetComm();
+  comm.PrintGrid(grid, "Sampled Grid");
+}
+
+void InterfaceVMGDebugGridJob::ExportSolution(Grid& grid)
+{
+  // we don't solve anything, hence nothing to do here
+}
Index: src/Jobs/InterfaceVMGDebugGridJob.hpp
===================================================================
--- src/Jobs/InterfaceVMGDebugGridJob.hpp	(revision 2388688c3e24cb54fc978d6c8efd1ddead979d8a)
+++ src/Jobs/InterfaceVMGDebugGridJob.hpp	(revision 2388688c3e24cb54fc978d6c8efd1ddead979d8a)
@@ -0,0 +1,60 @@
+/*
+ * InterfaceVMGDebugGridJob.hpp
+ *
+ *  Created on: 31.08.2012
+ *      Author: Frederik Heber
+ */
+
+#ifndef INTERFACEVMGDEBUGGRIDJOB_HPP_
+#define INTERFACEVMGDEBUGGRIDJOB_HPP_
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "base/interface.hpp"
+#include "base/vector.hpp"
+
+namespace VMG
+{
+class Grid;
+class Multigrid;
+}
+
+namespace VMGInterfaces
+{
+
+/** This interface is only used to get the \a sampled_input into the VMG
+ *  grid to make use of its vtk displayer for debugging purposes.
+ *
+ *  See VMGDebugGridJob.
+ */
+class InterfaceVMGDebugGridJob : public VMG::Interface
+{
+public:
+  InterfaceVMGDebugGridJob(
+      const std::vector< double > &_sampled_input,
+      VMG::Boundary boundary,
+      int levelMin,
+      int levelMax,
+      const VMG::Vector &box_begin,
+      vmg_float box_end,
+      const int& near_field_cells,
+      int coarseningSteps=0,
+      double alpha=1.6);
+
+  virtual ~InterfaceVMGDebugGridJob();
+
+  void ImportRightHandSide(VMG::Multigrid& multigrid);
+  void ExportSolution(VMG::Grid& grid);
+
+private:
+  //!> sampled density on the grid as input
+  const std::vector< double > sampled_input;
+  //!> number of grid points per axis as \f$2^{\text{level}}\f$
+  const int level;
+};
+
+}
+
+#endif /* INTERFACEVMGDEBUGGRIDJOB_HPP_ */
Index: src/Jobs/Makefile.am
===================================================================
--- src/Jobs/Makefile.am	(revision 4aee30a5e04ca02651e262da12049cf46466d8d3)
+++ src/Jobs/Makefile.am	(revision 2388688c3e24cb54fc978d6c8efd1ddead979d8a)
@@ -8,6 +8,8 @@
 if CONDVMG
 JOBSSOURCE += \
+	Jobs/InterfaceVMGDebugGridJob.cpp \
 	Jobs/InterfaceVMGJob.cpp \
 	Jobs/VMGData.cpp \
+	Jobs/VMGDebugGridJob.cpp \
 	Jobs/VMGJob.cpp
 endif
@@ -22,4 +24,5 @@
 if CONDVMG
 JOBSHEADER += \
+	Jobs/InterfaceVMGDebugGridJob.hpp \
 	Jobs/InterfaceVMGJob.hpp \
 	Jobs/VMGData.hpp \
@@ -27,4 +30,5 @@
   Jobs/VMGDataMap.hpp \
   Jobs/VMGData_printKeyNames.hpp \
+	Jobs/VMGDebugGridJob.hpp \
 	Jobs/VMGJob.hpp
 endif
Index: src/Jobs/VMGDebugGridJob.cpp
===================================================================
--- src/Jobs/VMGDebugGridJob.cpp	(revision 2388688c3e24cb54fc978d6c8efd1ddead979d8a)
+++ src/Jobs/VMGDebugGridJob.cpp	(revision 2388688c3e24cb54fc978d6c8efd1ddead979d8a)
@@ -0,0 +1,172 @@
+/*
+ * Project: MoleCuilder
+ * Description: creates and alters molecular systems
+ * Copyright (C)  2012 University of Bonn. All rights reserved.
+ * 
+ *
+ *   This file is part of MoleCuilder.
+ *
+ *    MoleCuilder 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 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    MoleCuilder 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 MoleCuilder.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * VMGDebugGridJob.cpp
+ *
+ *  Created on: Jul 13, 2012
+ *      Author: heber
+ */
+
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef HAVE_MPI
+#include "mpi.h"
+#endif
+
+// include headers that implement a archive in simple text format
+// otherwise BOOST_CLASS_EXPORT_IMPLEMENT has no effect
+#include <boost/archive/text_oarchive.hpp>
+#include <boost/archive/text_iarchive.hpp>
+
+#include "mg.hpp"
+#include "base/object.hpp"
+#include "base/defs.hpp"
+
+#ifdef HAVE_MPI
+#include "comm/comm_mpi.hpp"
+#include "comm/domain_decomposition_mpi.hpp"
+#else
+#include "comm/comm_serial.hpp"
+#endif
+#include "cycles/cycle_cs_periodic.hpp"
+#include "grid/multigrid.hpp"
+//#include "grid/tempgrid.hpp"
+#include "level/level_operator_cs.hpp"
+#include "level/stencils.hpp"
+#include "samples/discretization_poisson_fd.hpp"
+#include "smoother/gsrb_poisson_4.hpp"
+#include "solver/givens.hpp"
+//#include "solver/solver_regular.hpp"
+#include "solver/solver_singular.hpp"
+//#include "units/particle/comm_mpi_particle.hpp"
+
+#include "CodePatterns/MemDebug.hpp"
+
+#include "Jobs/VMGDebugGridJob.hpp"
+
+#include "LinearAlgebra/defs.hpp"
+#include "Jobs/InterfaceVMGDebugGridJob.hpp"
+
+using namespace VMG;
+
+VMGDebugGridJob::VMGDebugGridJob(
+    const JobId_t _JobId,
+    const SamplingGrid &_density_grid) :
+  FragmentJob(_JobId),
+  density_grid(_density_grid)
+{}
+
+VMGDebugGridJob::VMGDebugGridJob() :
+  FragmentJob(JobId::IllegalJob)
+{}
+
+VMGDebugGridJob::~VMGDebugGridJob()
+{}
+
+FragmentResult::ptr VMGDebugGridJob::Work()
+{
+  // initialize VMG library solver
+  InitVMG();
+
+  /*
+   * Start the multigrid solver,
+   * hence calling InterfaceVMGDebugGridJob::ImportRightHandSide()
+   */
+  MG::Solve();
+
+  /*
+   * Delete all data.
+   */
+  MG::Destroy();
+
+  std::stringstream returnstream;
+  boost::archive::text_oarchive oa(returnstream);
+  std::string message("Sampled Grid");
+  oa << message;
+  FragmentResult::ptr ptr( new FragmentResult(getId(), returnstream.str()) );
+  return ptr;
+}
+
+/** Initialization of VMG library.
+ *
+ * The contents is heavily inspired from interface_fcs.cpp: VMG_fcs_init() of
+ * the ScaFaCoS project.
+ *
+ */
+void VMGDebugGridJob::InitVMG()
+{
+  // TODO: As a matter of fact should use open boundary conditions
+  const Boundary boundary(Periodic, Periodic, Periodic);
+
+  /*
+   * Choose multigrid components
+   */
+#ifdef HAVE_MPI
+  new CommMPI(boundary, new DomainDecompositionMPI());
+#else
+  new CommSerial(boundary);
+#endif
+  new DiscretizationPoissonFD(4);
+  new VMGInterfaces::InterfaceVMGDebugGridJob(
+      density_grid.sampled_grid,
+      boundary,
+      2,
+      density_grid.level,
+      Vector(density_grid.begin),
+      density_grid.size,
+      5);
+  new LevelOperatorCS(Stencils::RestrictionFullWeight, Stencils::InterpolationTrilinear);
+  new Givens<SolverSingular>();
+  const int cycle_type = 1; // V-type
+  new CycleCSPeriodic(cycle_type);
+  new GaussSeidelRBPoisson4();
+
+  /*
+   * Register required parameters.
+   * We don't actually want solve anything here
+   */
+  new ObjectStorage<int>("PRESMOOTHSTEPS", 1);
+  new ObjectStorage<int>("POSTSMOOTHSTEPS", 1);
+  new ObjectStorage<vmg_float>("PRECISION", 1.0e-0);
+  new ObjectStorage<int>("MAX_ITERATION", 1);
+  new ObjectStorage<int>("PARTICLE_NEAR_FIELD_CELLS", 3);
+  new ObjectStorage<int>("PARTICLE_INTERPOLATION_DEGREE", 3);
+
+  /*
+   * Post init
+   */
+  MG::PostInit();
+
+  /*
+   * Check whether the library is correctly initialized now.
+   */
+  MG::IsInitialized();
+}
+
+// we need to explicitly instantiate the serialization functions as
+// its is only serialized through its base class FragmentJob
+BOOST_CLASS_EXPORT_IMPLEMENT(VMGDebugGridJob)
Index: src/Jobs/VMGDebugGridJob.hpp
===================================================================
--- src/Jobs/VMGDebugGridJob.hpp	(revision 2388688c3e24cb54fc978d6c8efd1ddead979d8a)
+++ src/Jobs/VMGDebugGridJob.hpp	(revision 2388688c3e24cb54fc978d6c8efd1ddead979d8a)
@@ -0,0 +1,72 @@
+/*
+ * VMGDebugGridJob.hpp
+ *
+ *  Created on: Aug 31, 2012
+ *      Author: heber
+ */
+
+#ifndef VMGDEBUGGRIDJOB_HPP_
+#define VMGDEBUGGRIDJOB_HPP_
+
+
+// include config.h
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "boost/serialization/export.hpp"
+#include "boost/serialization/vector.hpp"
+
+#include "JobMarket/Jobs/FragmentJob.hpp"
+#include "Jobs/Grid/SamplingGrid.hpp"
+
+#include <vector>
+
+/** This class encapsulates a Debug Grid Job.
+ *
+ *  VMGDebugGridJob just stores the sampled grid into a VMG job and lets VMG
+ *  print the grid in a VTK compatible format to make use of its grid_viewer
+ *  for debugging purposes.
+ *
+ */
+class VMGDebugGridJob : public FragmentJob
+{
+public:
+  /** Constructor for class VMGDebugGridJob.
+   *
+   * @param _JobId id of the job
+   * @param _density_grid sampled electron charge density from short-range solutions
+   */
+  VMGDebugGridJob(const JobId_t _JobId,
+      const SamplingGrid &density_grid);
+  virtual ~VMGDebugGridJob();
+
+  FragmentResult::ptr Work();
+
+private:
+  void InitVMG();
+
+private:
+  //!> sampled density required as input
+  const SamplingGrid density_grid;
+
+private:
+  /** private default cstor for serialization only
+   */
+  VMGDebugGridJob();
+
+  friend class boost::serialization::access;
+  // serialization
+  template <typename Archive>
+  void serialize(Archive& ar, const unsigned int version)
+  {
+    ar & boost::serialization::base_object<FragmentJob>(*this);
+    ar & const_cast< SamplingGrid &>(density_grid);
+  }
+};
+
+// we need to give this class a unique key for serialization
+// its is only serialized through its base class FragmentJob
+BOOST_CLASS_EXPORT_KEY(VMGDebugGridJob)
+
+#endif /* VMGDEBUGGRIDJOB_HPP_ */
