source: src/Jobs/WindowGrid_converter.cpp@ 27ef5c

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 Candidate_v1.7.0 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 27ef5c was 27ef5c, checked in by Frederik Heber <heber@…>, 12 years ago

Density is now correctly written onto grid with both periodic and open boundary condittions.

  • Property mode set to 100644
File size: 11.3 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2012 University of Bonn. All rights reserved.
5 * Copyright (C) 2013 Frederik Heber. All rights reserved.
6 * Please see the COPYING file or "Copyright notice" in builder.cpp for details.
7 *
8 *
9 * This file is part of MoleCuilder.
10 *
11 * MoleCuilder is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * MoleCuilder is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
23 */
24
25/*
26 * WindowGrid_converter.cpp
27 *
28 * Created on: Dec 20, 2012
29 * Author: heber
30 */
31
32
33// include config.h
34#ifdef HAVE_CONFIG_H
35#include <config.h>
36#endif
37
38#include "grid/grid.hpp"
39
40#include "WindowGrid_converter.hpp"
41
42#include "CodePatterns/MemDebug.hpp"
43
44#include <iostream>
45#include <iterator>
46#include <limits>
47
48#include "CodePatterns/Assert.hpp"
49#include "CodePatterns/Log.hpp"
50
51#include "Fragmentation/Summation/SetValues/SamplingGrid.hpp"
52
53void WindowGrid_converter::addGridOntoWindow(
54 VMG::Grid &grid,
55 SamplingGrid &window,
56 const double prefactor)
57{
58#ifndef NDEBUG
59 for(size_t index=0;index<3;++index) {
60 ASSERT( window.begin[index] >= window.begin_window[index],
61 "InterfaceVMGJob::addGridOntoWindow() - given grid starts earlier than window in component "
62 +toString(index)+".");
63 ASSERT( window.end[index] <= window.end_window[index],
64 "InterfaceVMGJob::addGridOntoWindow() - given grid ends later than window in component "
65 +toString(index)+".");
66 }
67#endif
68 // the only issue are indices
69 const size_t gridpoints_axis = window.getGridPointsPerAxis();
70 size_t pre_offset[3];
71 size_t post_offset[3];
72 size_t length[3];
73 size_t total[3];
74 const double round_offset =
75 (std::numeric_limits<size_t>::round_style == std::round_toward_zero) ?
76 0.5 : 0.; // need offset to get to round_toward_nearest behavior
77 for(size_t index=0;index<3;++index) {
78 const double delta = (double)gridpoints_axis/(window.end[index] - window.begin[index]);
79 // delta is conversion factor from box length to discrete length, i.e. number of points
80 pre_offset[index] = delta*(window.begin[index] - window.begin_window[index])+round_offset;
81 length[index] = delta*(window.end[index] - window.begin[index])+round_offset;
82 post_offset[index] = delta*(window.end_window[index] - window.end[index])+round_offset;
83 total[index] = delta*(window.end_window[index] - window.begin_window[index])+round_offset;
84 // total is used as safe-guard against loss due to discrete conversion
85 ASSERT( pre_offset[index]+post_offset[index]+length[index] == total[index],
86 "InterfaceVMGJob::addGridOntoWindow() - pre, post, and length don't sum up to total for "
87 +toString(index)+"th component.");
88 }
89#ifndef NDEBUG
90 const size_t calculated_size = length[0]*length[1]*length[2];
91// const size_t given_size = std::distance(grid_begin, grid_end);
92// ASSERT( calculated_size == given_size,
93// "InterfaceVMGJob::addGridOntoWindow() - not enough sampled values given: "
94// +toString(calculated_size)+" != "+toString(given_size)+".");
95 ASSERT( calculated_size <= window.sampled_grid.size(),
96 "InterfaceVMGJob::addGridOntoWindow() - not enough sampled values available: "
97 +toString(calculated_size)+" <= "+toString(window.sampled_grid.size())+".");
98 const size_t total_size = total[0]*total[1]*total[2];
99 ASSERT( total_size == window.sampled_grid.size(),
100 "InterfaceVMGJob::addGridOntoWindow() - total size is not equal to number of present points: "
101 +toString(total_size)+" != "+toString(window.sampled_grid.size())+".");
102#endif
103 size_t N[3];
104 SamplingGrid::sampledvalues_t::iterator griditer = window.sampled_grid.begin();
105 std::advance(griditer, pre_offset[0]*total[1]*total[2]);
106 VMG::Grid::iterator copyiter = grid.Iterators().Local().Begin();
107 for(N[0]=0; N[0] < length[0]; ++N[0]) {
108 std::advance(griditer, pre_offset[1]*total[2]);
109 for(N[1]=0; N[1] < length[1]; ++N[1]) {
110 std::advance(griditer, pre_offset[2]);
111 for(N[2]=0; N[2] < length[2]; ++N[2]) {
112 ASSERT( griditer != window.sampled_grid.end(),
113 "InterfaceVMGJob::addGridOntoWindow() - griditer is already at end of window.");
114 ASSERT( copyiter != grid.Iterators().Local().End(),
115 "InterfaceVMGJob::addGridOntoWindow() - griditer is already at end of window.");
116 *griditer++ += prefactor*grid(*copyiter++);
117 }
118 std::advance(griditer, post_offset[2]);
119 }
120 std::advance(griditer, post_offset[1]*total[2]);
121 }
122#ifndef NDEBUG
123 std::advance(griditer, post_offset[0]*total[1]*total[2]);
124 ASSERT( griditer == window.sampled_grid.end(),
125 "InterfaceVMGJob::addGridOntoWindow() - griditer is not at end of window.");
126 ASSERT( copyiter == grid.Iterators().Local().End(),
127 "InterfaceVMGJob::addGridOntoWindow() - copyiter is not at end of window.");
128#endif
129}
130
131void WindowGrid_converter::addWindowOntoGrid(
132 VMG::Grid& window,
133 const SamplingGrid &grid,
134 const double prefactor,
135 const bool OpenBoundaryConditions)
136{
137#ifndef NDEBUG
138 for(size_t index=0;index<3;++index) {
139 ASSERT( grid.begin_window[index] >= grid.begin[index],
140 "InterfaceVMGJob::addWindowOntoGrid() - given window starts earlier than grid in component "
141 +toString(index)+".");
142 ASSERT( grid.end_window[index] <= grid.end[index],
143 "InterfaceVMGJob::addWindowOntoGrid() - given window ends later than grid in component "
144 +toString(index)+".");
145 }
146#endif
147 // the only issue are indices
148 const size_t gridpoints_axis = grid.getGridPointsPerAxis();
149 size_t pre_offset[3];
150 size_t post_offset[3];
151 size_t length[3];
152 size_t total[3];
153 const double round_offset =
154 (std::numeric_limits<size_t>::round_style == std::round_toward_zero) ?
155 0.5 : 0.; // need offset to get to round_toward_nearest behavior
156 for(size_t index=0;index<3;++index) {
157 const double delta = (double)gridpoints_axis/(grid.end[index] - grid.begin[index]);
158 // delta is conversion factor from box length to discrete length, i.e. number of points
159 pre_offset[index] = delta*(grid.begin_window[index] - grid.begin[index])+round_offset;
160 length[index] = delta*(grid.end_window[index] - grid.begin_window[index])+round_offset;
161 post_offset[index] = delta*(grid.end[index] - grid.end_window[index])+round_offset;
162 total[index] = delta*(grid.end[index] - grid.begin[index])+round_offset;
163 // total is used as safe-guard against loss due to discrete conversion
164 ASSERT( pre_offset[index]+post_offset[index]+length[index] == total[index],
165 "InterfaceVMGJob::addWindowOntoGrid() - pre, post, and length don't sum up to total for "
166 +toString(index)+"th component.");
167 }
168#ifndef NDEBUG
169 const size_t calculated_size = length[0]*length[1]*length[2];
170 ASSERT( calculated_size == grid.sampled_grid.size(),
171 "InterfaceVMGJob::addWindowOntoGrid() - not enough sampled values given: "
172 +toString(calculated_size)+" != "+toString(grid.sampled_grid.size())+".");
173// ASSERT( calculated_size <= given_size,
174// "InterfaceVMGJob::addWindowOntoGrid() - not enough sampled values available: "
175// +toString(calculated_size)+" <= "+toString(given_size)+".");
176// const size_t total_size = total[0]*total[1]*total[2];
177// ASSERT( total_size == given_size,
178// "InterfaceVMGJob::addWindowOntoGrid() - total size is not equal to number of present points: "
179// +toString(total_size)+" != "+toString(given_size)+".");
180#endif
181 size_t N[3];
182 // in open boundary case grid.Local() contains more than just the inner area. The grid
183 // is actually twice as large to allow for the FV discretization to work. Hence, we first
184 // have to seek our starting point ... see VMG::Grid::GetSpatialPos()
185 if (OpenBoundaryConditions) {
186 const VMG::Index size = window.Local().Size();
187 const VMG::Index halosize = window.Local().HaloSize1();
188 for (size_t i=0;i<3;++i)
189 pre_offset[i] += size[i] / 4;
190 for (size_t i=0;i<3;++i)
191 total[i] = size[i];
192 for (size_t i=0;i<3;++i)
193 post_offset[i] = size[i] - pre_offset[i] - length[i];
194 }
195
196 VMG::Grid::iterator griditer = window.Iterators().Local().Begin();
197// griditer.advance(pre_offset[0]*total[1]*total[2]);
198 for(N[0]=0; N[0] < pre_offset[0]; ++N[0])
199 for(N[1]=0; N[1] < total[1]; ++N[1])
200 for(N[2]=0; N[2] < total[2]; ++N[2]) {
201 ASSERT( griditer != window.Iterators().Local().End(),
202 "InterfaceVMGJob::addWindowOntoGrid() - griditer is already at end of window.");
203 window(*griditer++) = 0.;
204 }
205 SamplingGrid::sampledvalues_t::const_iterator copyiter = grid.sampled_grid.begin();
206 for(N[0]=0; N[0] < length[0]; ++N[0]) {
207// griditer.advance(pre_offset[1]*total[2]);
208 for(N[1]=0; N[1] < pre_offset[1]; ++N[1])
209 for(N[2]=0; N[2] < total[2]; ++N[2]) {
210 ASSERT( griditer != window.Iterators().Local().End(),
211 "InterfaceVMGJob::addWindowOntoGrid() - griditer is already at end of window.");
212 window(*griditer++) = 0.;
213 }
214 for(N[1]=0; N[1] < length[1]; ++N[1]) {
215// griditer.advance(pre_offset[2]);
216 for(N[2]=0; N[2] < pre_offset[2]; ++N[2])
217 window(*griditer++) = 0.;
218 for(N[2]=0; N[2] < length[2]; ++N[2]) {
219 ASSERT( griditer != window.Iterators().Local().End(),
220 "InterfaceVMGJob::addWindowOntoGrid() - griditer is already at end of window.");
221 ASSERT( copyiter != grid.sampled_grid.end(),
222 "InterfaceVMGJob::addWindowOntoGrid() - griditer is already at end of window.");
223 window(*griditer++) += prefactor*(*copyiter++);
224 }
225// griditer.advance(post_offset[2]);
226 for(N[2]=0; N[2] < post_offset[2]; ++N[2]) {
227 ASSERT( griditer != window.Iterators().Local().End(),
228 "InterfaceVMGJob::addWindowOntoGrid() - griditer is already at end of window.");
229 window(*griditer++) = 0.;
230 }
231 }
232// griditer.advance(post_offset[1]*total[2]);
233 for(N[1]=0; N[1] < post_offset[1]; ++N[1])
234 for(N[2]=0; N[2] < total[2]; ++N[2]) {
235 ASSERT( griditer != window.Iterators().Local().End(),
236 "InterfaceVMGJob::addWindowOntoGrid() - griditer is already at end of window.");
237 window(*griditer++) = 0.;
238 }
239 }
240 // griditer.advance(post_offset[0]*total[1]*total[2]);
241 for(N[0]=0; N[0] < post_offset[0]; ++N[0])
242 for(N[1]=0; N[1] < total[1]; ++N[1])
243 for(N[2]=0; N[2] < total[2]; ++N[2]) {
244 ASSERT( griditer != window.Iterators().Local().End(),
245 "InterfaceVMGJob::addWindowOntoGrid() - griditer is already at end of window.");
246 window(*griditer++) = 0.;
247 }
248#ifndef NDEBUG
249 ASSERT( griditer == window.Iterators().Local().End(),
250 "InterfaceVMGJob::addWindowOntoGrid() - griditer is not at end of window.");
251 ASSERT( copyiter == grid.sampled_grid.end(),
252 "InterfaceVMGJob::addWindowOntoGrid() - copyiter is not at end of window.");
253#endif
254// LOG(2, "DEBUG: Grid after adding other is " << grid << ".");
255}
Note: See TracBrowser for help on using the repository browser.