| 1 | /*
|
|---|
| 2 | * Project: MoleCuilder
|
|---|
| 3 | * Description: creates and alters molecular systems
|
|---|
| 4 | * Copyright (C) 2012 University of Bonn. All rights reserved.
|
|---|
| 5 | *
|
|---|
| 6 | *
|
|---|
| 7 | * This file is part of MoleCuilder.
|
|---|
| 8 | *
|
|---|
| 9 | * MoleCuilder is free software: you can redistribute it and/or modify
|
|---|
| 10 | * it under the terms of the GNU General Public License as published by
|
|---|
| 11 | * the Free Software Foundation, either version 2 of the License, or
|
|---|
| 12 | * (at your option) any later version.
|
|---|
| 13 | *
|
|---|
| 14 | * MoleCuilder is distributed in the hope that it will be useful,
|
|---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 17 | * GNU General Public License for more details.
|
|---|
| 18 | *
|
|---|
| 19 | * You should have received a copy of the GNU General Public License
|
|---|
| 20 | * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
|
|---|
| 21 | */
|
|---|
| 22 |
|
|---|
| 23 | /*
|
|---|
| 24 | * VMGDebugGridJob.cpp
|
|---|
| 25 | *
|
|---|
| 26 | * Created on: Jul 13, 2012
|
|---|
| 27 | * Author: heber
|
|---|
| 28 | */
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 | // include config.h
|
|---|
| 32 | #ifdef HAVE_CONFIG_H
|
|---|
| 33 | #include <config.h>
|
|---|
| 34 | #endif
|
|---|
| 35 |
|
|---|
| 36 | #ifdef HAVE_MPI
|
|---|
| 37 | #include "mpi.h"
|
|---|
| 38 | #endif
|
|---|
| 39 |
|
|---|
| 40 | // include headers that implement a archive in simple text format
|
|---|
| 41 | // otherwise BOOST_CLASS_EXPORT_IMPLEMENT has no effect
|
|---|
| 42 | #include <boost/archive/text_oarchive.hpp>
|
|---|
| 43 | #include <boost/archive/text_iarchive.hpp>
|
|---|
| 44 |
|
|---|
| 45 | #include "mg.hpp"
|
|---|
| 46 | #include "base/object.hpp"
|
|---|
| 47 | #include "base/defs.hpp"
|
|---|
| 48 |
|
|---|
| 49 | #ifdef HAVE_MPI
|
|---|
| 50 | #include "comm/comm_mpi.hpp"
|
|---|
| 51 | #include "comm/domain_decomposition_mpi.hpp"
|
|---|
| 52 | #include "units/particle/comm_mpi_particle.hpp"
|
|---|
| 53 | #else
|
|---|
| 54 | #include "comm/comm_serial.hpp"
|
|---|
| 55 | #endif
|
|---|
| 56 | #include "grid/multigrid.hpp"
|
|---|
| 57 | //#include "grid/tempgrid.hpp"
|
|---|
| 58 | #include "level/stencils.hpp"
|
|---|
| 59 | #include "solver/givens.hpp"
|
|---|
| 60 |
|
|---|
| 61 | // periodic boundary conditions
|
|---|
| 62 | #include "cycles/cycle_cs_periodic.hpp"
|
|---|
| 63 | #include "discretization/discretization_poisson_fd.hpp"
|
|---|
| 64 | #include "level/level_operator_cs.hpp"
|
|---|
| 65 | #include "smoother/gsrb_poisson_4.hpp"
|
|---|
| 66 | #include "solver/solver_singular.hpp"
|
|---|
| 67 | // open boundary conditions
|
|---|
| 68 | #ifndef NDEBUG
|
|---|
| 69 | #include "cycles/cycle_fas_dirichlet_debug.hpp"
|
|---|
| 70 | #else
|
|---|
| 71 | #include "cycles/cycle_fas_dirichlet.hpp"
|
|---|
| 72 | #endif
|
|---|
| 73 | #include "discretization/discretization_poisson_fv.hpp"
|
|---|
| 74 | #include "level/level_operator_fas.hpp"
|
|---|
| 75 | #include "smoother/gsrb_poisson_2.hpp"
|
|---|
| 76 | #include "solver/solver_regular.hpp"
|
|---|
| 77 |
|
|---|
| 78 | //#include "CodePatterns/MemDebug.hpp"
|
|---|
| 79 |
|
|---|
| 80 | #include "Jobs/VMGDebugGridJob.hpp"
|
|---|
| 81 |
|
|---|
| 82 | #include "LinearAlgebra/defs.hpp"
|
|---|
| 83 | #include "Jobs/InterfaceVMGDebugGridJob.hpp"
|
|---|
| 84 |
|
|---|
| 85 | using namespace VMG;
|
|---|
| 86 |
|
|---|
| 87 | VMGDebugGridJob::VMGDebugGridJob(
|
|---|
| 88 | const JobId_t _JobId,
|
|---|
| 89 | const SamplingGrid &_density_grid,
|
|---|
| 90 | const bool _OpenBoundaryConditions) :
|
|---|
| 91 | FragmentJob(_JobId),
|
|---|
| 92 | density_grid(_density_grid),
|
|---|
| 93 | OpenBoundaryConditions(_OpenBoundaryConditions)
|
|---|
| 94 | {}
|
|---|
| 95 |
|
|---|
| 96 | VMGDebugGridJob::VMGDebugGridJob() :
|
|---|
| 97 | FragmentJob(JobId::IllegalJob),
|
|---|
| 98 | OpenBoundaryConditions(false)
|
|---|
| 99 | {}
|
|---|
| 100 |
|
|---|
| 101 | VMGDebugGridJob::~VMGDebugGridJob()
|
|---|
| 102 | {}
|
|---|
| 103 |
|
|---|
| 104 | FragmentResult::ptr VMGDebugGridJob::Work()
|
|---|
| 105 | {
|
|---|
| 106 | // initialize VMG library solver
|
|---|
| 107 | InitVMG();
|
|---|
| 108 |
|
|---|
| 109 | /*
|
|---|
| 110 | * Start the multigrid solver,
|
|---|
| 111 | * hence calling InterfaceVMGDebugGridJob::ImportRightHandSide()
|
|---|
| 112 | */
|
|---|
| 113 | MG::Solve();
|
|---|
| 114 |
|
|---|
| 115 | /*
|
|---|
| 116 | * Delete all data.
|
|---|
| 117 | */
|
|---|
| 118 | MG::Destroy();
|
|---|
| 119 |
|
|---|
| 120 | std::stringstream returnstream;
|
|---|
| 121 | boost::archive::text_oarchive oa(returnstream);
|
|---|
| 122 | std::string message("Sampled Grid");
|
|---|
| 123 | oa << message;
|
|---|
| 124 | FragmentResult::ptr ptr( new FragmentResult(getId(), returnstream.str()) );
|
|---|
| 125 | return ptr;
|
|---|
| 126 | }
|
|---|
| 127 |
|
|---|
| 128 | /** Initialization of VMG library.
|
|---|
| 129 | *
|
|---|
| 130 | * The contents is heavily inspired from interface_fcs.cpp: VMG_fcs_init() of
|
|---|
| 131 | * the ScaFaCoS project.
|
|---|
| 132 | *
|
|---|
| 133 | */
|
|---|
| 134 | void VMGDebugGridJob::InitVMG()
|
|---|
| 135 | {
|
|---|
| 136 | Boundary *boundary= NULL;
|
|---|
| 137 | if (OpenBoundaryConditions)
|
|---|
| 138 | boundary = new Boundary(Open, Open, Open);
|
|---|
| 139 | else
|
|---|
| 140 | boundary = new Boundary(Periodic, Periodic, Periodic);
|
|---|
| 141 |
|
|---|
| 142 | #ifdef HAVE_MPI
|
|---|
| 143 | new Particle::CommMPI(*boundary, new DomainDecompositionMPI());
|
|---|
| 144 | #else
|
|---|
| 145 | new CommSerial(*boundary);
|
|---|
| 146 | #endif
|
|---|
| 147 | if (OpenBoundaryConditions)
|
|---|
| 148 | new DiscretizationPoissonFV(2);
|
|---|
| 149 | else
|
|---|
| 150 | new DiscretizationPoissonFD(4);
|
|---|
| 151 | new VMGInterfaces::InterfaceVMGDebugGridJob(
|
|---|
| 152 | density_grid,
|
|---|
| 153 | *boundary,
|
|---|
| 154 | 2,
|
|---|
| 155 | density_grid.level,
|
|---|
| 156 | Vector(density_grid.begin),
|
|---|
| 157 | density_grid.end[0]-density_grid.begin[0],
|
|---|
| 158 | 5);
|
|---|
| 159 | const int cycle_type = 1; // V-type
|
|---|
| 160 | if (OpenBoundaryConditions) {
|
|---|
| 161 | new LevelOperatorFAS(Stencils::RestrictionFullWeight, Stencils::Injection, Stencils::InterpolationTrilinear);
|
|---|
| 162 | new Givens<SolverRegular>();
|
|---|
| 163 | #ifndef NDEBUG
|
|---|
| 164 | new CycleFASDirichletDebug(cycle_type);
|
|---|
| 165 | #else
|
|---|
| 166 | new CycleFASDirichlet(cycle_type);
|
|---|
| 167 | #endif
|
|---|
| 168 | new GaussSeidelRBPoisson2();
|
|---|
| 169 | } else {
|
|---|
| 170 | new LevelOperatorCS(Stencils::RestrictionFullWeight, Stencils::InterpolationTrilinear);
|
|---|
| 171 | new Givens<SolverSingular>();
|
|---|
| 172 | new CycleCSPeriodic(cycle_type);
|
|---|
| 173 | new GaussSeidelRBPoisson4();
|
|---|
| 174 | }
|
|---|
| 175 | delete boundary;
|
|---|
| 176 |
|
|---|
| 177 | /*
|
|---|
| 178 | * Register required parameters
|
|---|
| 179 | */
|
|---|
| 180 | new ObjectStorage<int>("PRESMOOTHSTEPS", 3);
|
|---|
| 181 | new ObjectStorage<int>("POSTSMOOTHSTEPS", 3);
|
|---|
| 182 | new ObjectStorage<vmg_float>("PRECISION", 1.0e-10);
|
|---|
| 183 | new ObjectStorage<int>("MAX_ITERATION", 15);
|
|---|
| 184 | new ObjectStorage<int>("PARTICLE_NEAR_FIELD_CELLS", 5);
|
|---|
| 185 | new ObjectStorage<int>("PARTICLE_INTERPOLATION_DEGREE", 3);
|
|---|
| 186 |
|
|---|
| 187 | /*
|
|---|
| 188 | * Post init
|
|---|
| 189 | */
|
|---|
| 190 | MG::PostInit();
|
|---|
| 191 |
|
|---|
| 192 | /*
|
|---|
| 193 | * Check whether the library is correctly initialized now.
|
|---|
| 194 | */
|
|---|
| 195 | MG::IsInitialized();
|
|---|
| 196 | }
|
|---|
| 197 |
|
|---|
| 198 | // we need to explicitly instantiate the serialization functions as
|
|---|
| 199 | // its is only serialized through its base class FragmentJob
|
|---|
| 200 | BOOST_CLASS_EXPORT_IMPLEMENT(VMGDebugGridJob)
|
|---|