source: src/Jobs/VMGJob.cpp@ 9ff818

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults 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 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_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 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 9ff818 was 9ff818, checked in by Frederik Heber <heber@…>, 9 years ago

MPQCJob and VMGJob contain reached and desired accuracy.

  • both set exitflag to 1 if desired accuracy has not been reached.
  • Property mode set to 100644
File size: 8.4 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 *
7 *
8 * This file is part of MoleCuilder.
9 *
10 * MoleCuilder is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * MoleCuilder is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24/*
25 * VMGJob.cpp
26 *
27 * Created on: Jul 13, 2012
28 * Author: heber
29 */
30
31
32// include config.h
33#ifdef HAVE_CONFIG_H
34#include <config.h>
35#endif
36
37#ifdef HAVE_MPI
38#include "mpi.h"
39#endif
40
41// include headers that implement a archive in simple text format
42// otherwise BOOST_CLASS_EXPORT_IMPLEMENT has no effect
43#include <boost/archive/text_oarchive.hpp>
44#include <boost/archive/text_iarchive.hpp>
45
46#include "mg.hpp"
47#include "base/object.hpp"
48#include "base/defs.hpp"
49
50#ifdef HAVE_MPI
51#include "comm/comm_mpi.hpp"
52#include "comm/domain_decomposition_mpi.hpp"
53#else
54#include "comm/comm_serial.hpp"
55#endif
56// periodic boundary conditions
57#include "cycles/cycle_cs_periodic.hpp"
58#include "discretization/discretization_poisson_fd.hpp"
59#include "level/level_operator_cs.hpp"
60#include "smoother/gsrb_poisson_4.hpp"
61#include "solver/solver_singular.hpp"
62// open boundary conditions
63#include "cycles/cycle_fas_dirichlet.hpp"
64#include "discretization/discretization_poisson_fv.hpp"
65#include "grid/multigrid.hpp"
66//#include "grid/tempgrid.hpp"
67#include "level/level_operator_fas.hpp"
68#include "level/stencils.hpp"
69#include "smoother/gsrb_poisson_2.hpp"
70#include "solver/givens.hpp"
71#include "solver/solver_regular.hpp"
72#include "units/particle/comm_mpi_particle.hpp"
73
74#include "CodePatterns/MemDebug.hpp"
75
76#include "Jobs/VMGJob.hpp"
77
78#include "LinearAlgebra/defs.hpp"
79#include "Jobs/InterfaceVMGJob.hpp"
80
81#include "CodePatterns/Assert.hpp"
82#include "CodePatterns/Log.hpp"
83
84using namespace VMG;
85
86VMGJob::VMGJob(
87 const JobId_t _JobId,
88 const SamplingGrid &_density_grid,
89 const std::vector< std::vector< double > > &_particle_positions,
90 const std::vector< double > &_particle_charges,
91 const size_t _near_field_cells,
92 const size_t _interpolation_degree,
93 const bool _DoImportParticles,
94 const bool _DoPrintDebug,
95 const bool _OpenBoundaryConditions,
96 const bool _DoSmearCharges) :
97 FragmentJob(_JobId),
98 density_grid(_density_grid),
99 particle_positions(_particle_positions),
100 particle_charges(_particle_charges),
101 near_field_cells(_near_field_cells),
102 interpolation_degree(_interpolation_degree),
103 DoImportParticles(_DoImportParticles),
104 DoPrintDebug(_DoPrintDebug),
105 OpenBoundaryConditions(_OpenBoundaryConditions),
106 DoSmearCharges(_DoSmearCharges),
107 returndata(static_cast<const SamplingGridProperties &>(_density_grid)),
108 particles()
109{}
110
111VMGJob::VMGJob() :
112 FragmentJob(JobId::IllegalJob),
113 near_field_cells(3),
114 interpolation_degree(3),
115 DoImportParticles(true),
116 DoPrintDebug(false),
117 OpenBoundaryConditions(false),
118 DoSmearCharges(false),
119 particles()
120{}
121
122VMGJob::~VMGJob()
123{
124}
125
126
127VMGJob::particle_arrays::particle_arrays() :
128 num_particles(0),
129 f(NULL),
130 x(NULL),
131 p(NULL),
132 q(NULL)
133{}
134
135VMGJob::particle_arrays::~particle_arrays()
136{
137 delete[] f;
138 delete[] x;
139 delete[] p;
140 delete[] q;
141}
142
143void VMGJob::particle_arrays::init(const size_t _num_particles)
144{
145 num_particles = _num_particles;
146 f = new double[num_particles*3];
147 x = new double[num_particles*3];
148 p = new double[num_particles];
149 q = new double[num_particles];
150}
151
152void VMGJob::InitVMGArrays()
153{
154 particles.init(particle_charges.size());
155
156 {
157 size_t index=0;
158 for (std::vector< std::vector< double > >::const_iterator iter = particle_positions.begin();
159 iter != particle_positions.end(); ++iter) {
160 for (std::vector< double >::const_iterator positer = (*iter).begin();
161 positer != (*iter).end(); ++positer) {
162 particles.f[index] = 0.;
163 particles.x[index++] = *positer;
164 }
165 }
166 ASSERT( index == particles.num_particles*3,
167 "VMGJob::VMGJob() - too many particles or components in particle_positions.");
168 }
169 {
170 size_t index = 0;
171 for (std::vector< double >::const_iterator iter = particle_charges.begin();
172 iter != particle_charges.end(); ++iter) {
173 particles.p[index] = 0.;
174 particles.q[index++] = *iter;
175 }
176 ASSERT( index == particles.num_particles,
177 "VMGJob::VMGJob() - too many charges in particle_charges.");
178 }
179}
180
181
182FragmentResult::ptr VMGJob::Work()
183{
184 // initialize VMG library solver
185 InitVMG();
186
187 /*
188 * Start the multigrid solver
189 */
190 MG::Solve();
191
192 /// create and fill result object
193 // place into returnstream
194 std::stringstream returnstream;
195 {
196 const VMGData archivedata(returndata);
197 boost::archive::text_oarchive oa(returnstream);
198 oa << archivedata;
199 }
200
201 FragmentResult::ptr ptr( new FragmentResult(getId(), returnstream.str()) );
202 if (returndata.precision != 0.) {
203 ptr->exitflag = returndata.relative_residual < returndata.precision ? 0 : 1;
204 if (ptr->exitflag != 0)
205 ELOG(1, "Job #" << ptr->getId() << " failed to reach desired accuracy.");
206 } else {
207 LOG(3, "INFO: No precision returned from VMG job, not checking.");
208 }
209
210 /*
211 * Delete all data.
212 */
213 MG::Destroy();
214
215 return ptr;
216}
217
218/** Initialization of VMG library.
219 *
220 * The contents is heavily inspired from interface_fcs.cpp: VMG_fcs_init() of
221 * the ScaFaCoS project.
222 *
223 */
224void VMGJob::InitVMG()
225{
226 Boundary *boundary = NULL;
227 if (OpenBoundaryConditions)
228 boundary = new Boundary(Open, Open, Open);
229 else
230 boundary = new Boundary(Periodic, Periodic, Periodic);
231
232 /*
233 * Choose multigrid components (self-registering)
234 */
235
236#ifdef HAVE_MPI
237 new Particle::CommMPI(*boundary, new DomainDecompositionMPI());
238#else
239 new CommSerial(*boundary);
240#endif
241 if (OpenBoundaryConditions)
242 new DiscretizationPoissonFV(2);
243 else
244 new DiscretizationPoissonFD(4);
245 new VMGInterfaces::InterfaceVMGJob(
246 density_grid,
247 returndata,
248 particle_positions,
249 particle_charges,
250 *boundary,
251 2,
252 density_grid.level,
253 Vector(density_grid.begin),
254 density_grid.end[0]-density_grid.begin[0],
255 near_field_cells,
256 DoImportParticles ?
257 VMGInterfaces::InterfaceVMGJob::DoImportParticles
258 : VMGInterfaces::InterfaceVMGJob::DontImportParticles,
259 DoPrintDebug,
260 DoSmearCharges);
261 const int cycle_type = 1; // V-type
262 if (OpenBoundaryConditions) {
263 new LevelOperatorFAS(Stencils::RestrictionFullWeight, Stencils::Injection, Stencils::InterpolationTrilinear);
264 new Givens<SolverRegular>();
265 new CycleFASDirichlet(cycle_type);
266 new GaussSeidelRBPoisson2();
267 } else {
268 new LevelOperatorCS(Stencils::RestrictionFullWeight, Stencils::InterpolationTrilinear);
269 new Givens<SolverSingular>();
270 new CycleCSPeriodic(cycle_type);
271 new GaussSeidelRBPoisson4();
272 }
273 delete boundary;
274
275 /*
276 * Register required parameters
277 */
278 new ObjectStorage<int>("PRESMOOTHSTEPS", 3);
279 new ObjectStorage<int>("POSTSMOOTHSTEPS", 3);
280 new ObjectStorage<vmg_float>("PRECISION", 1.0e-10);
281 new ObjectStorage<int>("MAX_ITERATION", 15);
282 new ObjectStorage<int>("PARTICLE_NEAR_FIELD_CELLS", near_field_cells);
283 new ObjectStorage<int>("PARTICLE_INTERPOLATION_DEGREE", interpolation_degree);
284
285 // first initialize f,x,p,q,... from STL vectors
286 InitVMGArrays();
287 // then initialize as objects with VMG's storage
288 new ObjectStorage<vmg_float*>("PARTICLE_POS_ARRAY", particles.x);
289 new ObjectStorage<vmg_float*>("PARTICLE_CHARGE_ARRAY", particles.q);
290 new ObjectStorage<vmg_float*>("PARTICLE_POTENTIAL_ARRAY", particles.p);
291 new ObjectStorage<vmg_float*>("PARTICLE_FIELD_ARRAY", particles.f);
292 new ObjectStorage<vmg_int>("PARTICLE_NUM_LOCAL", particles.num_particles);
293
294 /*
295 * Post init
296 */
297 MG::PostInit();
298
299 /*
300 * Check whether the library is correctly initialized now.
301 */
302 MG::IsInitialized();
303}
304
305// we need to explicitly instantiate the serialization functions as
306// its is only serialized through its base class FragmentJob
307BOOST_CLASS_EXPORT_IMPLEMENT(VMGJob)
Note: See TracBrowser for help on using the repository browser.