[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 |
|
---|
[88c2c1] | 39 | #include "CodePatterns/Log.hpp"
|
---|
| 40 |
|
---|
[e9cfc4] | 41 | #include "base/vector.hpp"
|
---|
| 42 | #include "grid/grid.hpp"
|
---|
| 43 | #include "grid/multigrid.hpp"
|
---|
| 44 |
|
---|
| 45 | #include "InterfaceVMGJob.hpp"
|
---|
| 46 |
|
---|
| 47 | using namespace VMG;
|
---|
| 48 | using VMGInterfaces::InterfaceVMGJob;
|
---|
| 49 |
|
---|
| 50 | void InterfaceVMGJob::ImportRightHandSide(Multigrid& multigrid)
|
---|
| 51 | {
|
---|
| 52 | Index i;
|
---|
| 53 | Vector pos;
|
---|
| 54 |
|
---|
| 55 | // VMG::TempGrid *temp_grid = new VMG::TempGrid(129, 0, 0., 1.);
|
---|
| 56 |
|
---|
| 57 | Grid& grid = multigrid(multigrid.MaxLevel());
|
---|
| 58 | grid.ClearBoundary();
|
---|
| 59 |
|
---|
| 60 | const Index begin_local = grid.Global().LocalBegin() - grid.Local().HaloSize1();
|
---|
| 61 |
|
---|
[88c2c1] | 62 | LOG(1, "INFO: Mesh has extent " << grid.Extent().MeshWidth() << ".");
|
---|
[d12d621] | 63 | const int gridpoints = pow(2, level);
|
---|
| 64 | LOG(1, "INFO: gridpoints on finest level are " << gridpoints << ".");
|
---|
| 65 | assert( (grid.Extent().MeshWidth().X() * gridpoints) == 1 );
|
---|
| 66 | assert( (grid.Extent().MeshWidth().Y() * gridpoints) == 1 );
|
---|
| 67 | assert( (grid.Extent().MeshWidth().Z() * gridpoints) == 1 );
|
---|
[88c2c1] | 68 | LOG(1, "INFO: "
|
---|
| 69 | << "X in [" << grid.Local().Begin().X() << "," << grid.Local().End().X() << "],"
|
---|
| 70 | << "Y in [" << grid.Local().Begin().Y() << "," << grid.Local().End().Y() << "],"
|
---|
| 71 | << "Z in [" << grid.Local().Begin().Z() << "," << grid.Local().End().Z() << "].");
|
---|
[d12d621] | 72 |
|
---|
| 73 | std::vector<double>::const_iterator sample_iter = sampled_input.begin();
|
---|
[e9cfc4] | 74 | for (i.X()=grid.Local().Begin().X(); i.X()<grid.Local().End().X(); ++i.X())
|
---|
| 75 | for (i.Y()=grid.Local().Begin().Y(); i.Y()<grid.Local().End().Y(); ++i.Y())
|
---|
| 76 | for (i.Z()=grid.Local().Begin().Z(); i.Z()<grid.Local().End().Z(); ++i.Z()) {
|
---|
| 77 | pos = grid.Extent().MeshWidth() * static_cast<Vector>(begin_local + i);
|
---|
| 78 | // R.x() = pos.X();
|
---|
| 79 | // R.y() = pos.Y();
|
---|
| 80 | // R.z() = pos.Z();
|
---|
[d12d621] | 81 | grid(i) = *sample_iter; //temp_grid(i);
|
---|
| 82 | ++sample_iter;
|
---|
[e9cfc4] | 83 | }
|
---|
[d12d621] | 84 | assert( sample_iter == sampled_input.end() );
|
---|
[e9cfc4] | 85 |
|
---|
| 86 | Grid::iterator grid_iter;
|
---|
| 87 | double charge_sum = 0.0;
|
---|
| 88 | for (grid_iter=grid.Iterators().Local().Begin(); grid_iter!=grid.Iterators().Local().End(); ++grid_iter)
|
---|
| 89 | charge_sum += grid.GetVal(*grid_iter);
|
---|
| 90 | // charge_sum = MG::GetComm()->GlobalSum(charge_sum);
|
---|
| 91 | // comm.PrintStringOnce("Grid charge sum: %e", charge_sum);
|
---|
| 92 | std::cout << "Grid charge sum: " << charge_sum << std::endl;
|
---|
| 93 |
|
---|
| 94 | // delete temp_grid;
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | void InterfaceVMGJob::ExportSolution(Grid& grid)
|
---|
| 98 | {
|
---|
| 99 | // grid now contains the sough-for potential
|
---|
| 100 |
|
---|
| 101 | const Index begin_local = grid.Global().LocalBegin() - grid.Local().HaloSize1();
|
---|
| 102 | Index i;
|
---|
| 103 |
|
---|
[442cee] | 104 | sampled_output.clear();
|
---|
[e9cfc4] | 105 | for (i.X()=grid.Local().Begin().X(); i.X()<grid.Local().End().X(); ++i.X())
|
---|
| 106 | for (i.Y()=grid.Local().Begin().Y(); i.Y()<grid.Local().End().Y(); ++i.Y())
|
---|
| 107 | for (i.Z()=grid.Local().Begin().Z(); i.Z()<grid.Local().End().Z(); ++i.Z()) {
|
---|
[442cee] | 108 | sampled_output.push_back(grid(i));
|
---|
[e9cfc4] | 109 | }
|
---|
| 110 |
|
---|
| 111 | Grid::iterator grid_iter;
|
---|
| 112 | double potential_sum = 0.0;
|
---|
| 113 | for (grid_iter=grid.Iterators().Local().Begin(); grid_iter!=grid.Iterators().Local().End(); ++grid_iter)
|
---|
| 114 | potential_sum += grid.GetVal(*grid_iter);
|
---|
| 115 | // charge_sum = MG::GetComm()->GlobalSum(potential_sum);
|
---|
| 116 | // comm.PrintStringOnce("Grid potential sum: %e", potential_sum);
|
---|
| 117 | std::cout << "Grid potential sum: " << potential_sum << std::endl;
|
---|
| 118 |
|
---|
| 119 | //Particle::CommMPI& comm = *dynamic_cast<Particle::CommMPI*>(MG::GetComm());
|
---|
| 120 | //e_long = comm.GlobalSumRoot(e_long);
|
---|
| 121 |
|
---|
| 122 | }
|
---|