[e9cfc4] | 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 | * InterfaceVMGJob.cpp
|
---|
| 25 | *
|
---|
| 26 | * Created on: 10.06.2012
|
---|
| 27 | * Author: Frederik Heber
|
---|
| 28 | */
|
---|
| 29 |
|
---|
| 30 | #ifdef HAVE_CONFIG_H
|
---|
| 31 | #include <config.h>
|
---|
| 32 | #endif
|
---|
| 33 |
|
---|
| 34 | #include "CodePatterns/MemDebug.hpp"
|
---|
| 35 |
|
---|
| 36 | #include <cmath>
|
---|
| 37 | #include <iostream>
|
---|
| 38 |
|
---|
| 39 | #include "base/vector.hpp"
|
---|
| 40 | #include "grid/grid.hpp"
|
---|
| 41 | #include "grid/multigrid.hpp"
|
---|
| 42 |
|
---|
| 43 | #include "InterfaceVMGJob.hpp"
|
---|
| 44 |
|
---|
| 45 | using namespace VMG;
|
---|
| 46 | using VMGInterfaces::InterfaceVMGJob;
|
---|
| 47 |
|
---|
| 48 | void InterfaceVMGJob::ImportRightHandSide(Multigrid& multigrid)
|
---|
| 49 | {
|
---|
| 50 | Index i;
|
---|
| 51 | Vector pos;
|
---|
| 52 |
|
---|
| 53 | // VMG::TempGrid *temp_grid = new VMG::TempGrid(129, 0, 0., 1.);
|
---|
| 54 |
|
---|
| 55 | Grid& grid = multigrid(multigrid.MaxLevel());
|
---|
| 56 | grid.ClearBoundary();
|
---|
| 57 |
|
---|
| 58 | const Index begin_local = grid.Global().LocalBegin() - grid.Local().HaloSize1();
|
---|
| 59 |
|
---|
| 60 | for (i.X()=grid.Local().Begin().X(); i.X()<grid.Local().End().X(); ++i.X())
|
---|
| 61 | for (i.Y()=grid.Local().Begin().Y(); i.Y()<grid.Local().End().Y(); ++i.Y())
|
---|
| 62 | for (i.Z()=grid.Local().Begin().Z(); i.Z()<grid.Local().End().Z(); ++i.Z()) {
|
---|
| 63 | pos = grid.Extent().MeshWidth() * static_cast<Vector>(begin_local + i);
|
---|
| 64 | // R.x() = pos.X();
|
---|
| 65 | // R.y() = pos.Y();
|
---|
| 66 | // R.z() = pos.Z();
|
---|
| 67 | grid(i) = 0.; //temp_grid(i);
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | Grid::iterator grid_iter;
|
---|
| 71 | double charge_sum = 0.0;
|
---|
| 72 | for (grid_iter=grid.Iterators().Local().Begin(); grid_iter!=grid.Iterators().Local().End(); ++grid_iter)
|
---|
| 73 | charge_sum += grid.GetVal(*grid_iter);
|
---|
| 74 | // charge_sum = MG::GetComm()->GlobalSum(charge_sum);
|
---|
| 75 | // comm.PrintStringOnce("Grid charge sum: %e", charge_sum);
|
---|
| 76 | std::cout << "Grid charge sum: " << charge_sum << std::endl;
|
---|
| 77 |
|
---|
| 78 | // delete temp_grid;
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | void InterfaceVMGJob::ExportSolution(Grid& grid)
|
---|
| 82 | {
|
---|
| 83 | // grid now contains the sough-for potential
|
---|
| 84 |
|
---|
| 85 | const Index begin_local = grid.Global().LocalBegin() - grid.Local().HaloSize1();
|
---|
| 86 | Index i;
|
---|
| 87 |
|
---|
| 88 | for (i.X()=grid.Local().Begin().X(); i.X()<grid.Local().End().X(); ++i.X())
|
---|
| 89 | for (i.Y()=grid.Local().Begin().Y(); i.Y()<grid.Local().End().Y(); ++i.Y())
|
---|
| 90 | for (i.Z()=grid.Local().Begin().Z(); i.Z()<grid.Local().End().Z(); ++i.Z()) {
|
---|
| 91 | grid(i);
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | Grid::iterator grid_iter;
|
---|
| 95 | double potential_sum = 0.0;
|
---|
| 96 | for (grid_iter=grid.Iterators().Local().Begin(); grid_iter!=grid.Iterators().Local().End(); ++grid_iter)
|
---|
| 97 | potential_sum += grid.GetVal(*grid_iter);
|
---|
| 98 | // charge_sum = MG::GetComm()->GlobalSum(potential_sum);
|
---|
| 99 | // comm.PrintStringOnce("Grid potential sum: %e", potential_sum);
|
---|
| 100 | std::cout << "Grid potential sum: " << potential_sum << std::endl;
|
---|
| 101 |
|
---|
| 102 | //Particle::CommMPI& comm = *dynamic_cast<Particle::CommMPI*>(MG::GetComm());
|
---|
| 103 | //e_long = comm.GlobalSumRoot(e_long);
|
---|
| 104 |
|
---|
| 105 | }
|
---|