source: src/Jobs/VMGJob.cpp@ 47cee7

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 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 47cee7 was ee9018, checked in by Frederik Heber <heber@…>, 12 years ago

InterfaceVMGJob now may also use open boundary (FAS instead of CS).

  • so far, according to Julian, only order 2 is implemented correctly.
  • we choose between open and periodic boundary conditions by a parameter in VMGJob.
  • VMGFragmentController uses the parameter when instantating VMGJobs.
  • Property mode set to 100644
File size: 7.9 KB
RevLine 
[d2a0f6d]1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2012 University of Bonn. All rights reserved.
[5aaa43]5 * Copyright (C) 2013 Frederik Heber. All rights reserved.
[d2a0f6d]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
[8a8c8c]37#ifdef HAVE_MPI
38#include "mpi.h"
39#endif
40
[d2a0f6d]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
[e9cfc4]46#include "mg.hpp"
47#include "base/object.hpp"
48#include "base/defs.hpp"
[8a8c8c]49
50#ifdef HAVE_MPI
51#include "comm/comm_mpi.hpp"
52#include "comm/domain_decomposition_mpi.hpp"
53#else
[e9cfc4]54#include "comm/comm_serial.hpp"
[8a8c8c]55#endif
[ee9018]56// periodic boundary conditions
[e9cfc4]57#include "cycles/cycle_cs_periodic.hpp"
[e8e472b]58#include "discretization/discretization_poisson_fd.hpp"
[ee9018]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"
[e9cfc4]65#include "grid/multigrid.hpp"
66//#include "grid/tempgrid.hpp"
[ee9018]67#include "level/level_operator_fas.hpp"
[e9cfc4]68#include "level/stencils.hpp"
[ee9018]69#include "smoother/gsrb_poisson_2.hpp"
[e9cfc4]70#include "solver/givens.hpp"
[ee9018]71#include "solver/solver_regular.hpp"
[a82602]72#include "units/particle/comm_mpi_particle.hpp"
[e9cfc4]73
[0990e1]74#include "CodePatterns/MemDebug.hpp"
75
76#include "Jobs/VMGJob.hpp"
77
[e9cfc4]78#include "LinearAlgebra/defs.hpp"
79#include "Jobs/InterfaceVMGJob.hpp"
80
[a82602]81#include "CodePatterns/Assert.hpp"
82
[e9cfc4]83using namespace VMG;
[d2a0f6d]84
[d12d621]85VMGJob::VMGJob(
86 const JobId_t _JobId,
[cd77fc]87 const SamplingGrid &_density_grid,
88 const std::vector< std::vector< double > > &_particle_positions,
[065574]89 const std::vector< double > &_particle_charges,
[cd2591]90 const size_t _near_field_cells,
[b6b21a]91 const size_t _interpolation_degree,
[e2925fd]92 const bool _DoImportParticles,
[ee9018]93 const bool _DoPrintDebug,
94 const bool _OpenBoundaryConditions) :
[d2a0f6d]95 FragmentJob(_JobId),
[442cee]96 density_grid(_density_grid),
[cd77fc]97 particle_positions(_particle_positions),
[2bc560]98 particle_charges(_particle_charges),
[065574]99 near_field_cells(_near_field_cells),
[cd2591]100 interpolation_degree(_interpolation_degree),
[e2925fd]101 DoImportParticles(_DoImportParticles),
102 DoPrintDebug(_DoPrintDebug),
[ee9018]103 OpenBoundaryConditions(_OpenBoundaryConditions),
[a82602]104 returndata(static_cast<const SamplingGridProperties &>(_density_grid)),
[e2925fd]105 particles()
[28c025]106{}
[d2a0f6d]107
108VMGJob::VMGJob() :
[065574]109 FragmentJob(JobId::IllegalJob),
[cd2591]110 near_field_cells(3),
111 interpolation_degree(3),
[e2925fd]112 DoImportParticles(true),
113 DoPrintDebug(false),
[ee9018]114 OpenBoundaryConditions(false),
[e2925fd]115 particles()
[e089fb]116{}
117
118VMGJob::~VMGJob()
119{
120}
121
122
123VMGJob::particle_arrays::particle_arrays() :
[a82602]124 num_particles(0),
125 f(NULL),
126 x(NULL),
127 p(NULL),
128 q(NULL)
[d2a0f6d]129{}
130
[e089fb]131VMGJob::particle_arrays::~particle_arrays()
[a82602]132{
133 delete[] f;
134 delete[] x;
135 delete[] p;
136 delete[] q;
137}
138
[e089fb]139void VMGJob::particle_arrays::init(const size_t _num_particles)
[a82602]140{
[e089fb]141 num_particles = _num_particles;
[a82602]142 f = new double[num_particles*3];
143 x = new double[num_particles*3];
144 p = new double[num_particles];
145 q = new double[num_particles];
[e089fb]146}
147
148void VMGJob::InitVMGArrays()
149{
150 particles.init(particle_charges.size());
[a82602]151
152 {
153 size_t index=0;
154 for (std::vector< std::vector< double > >::const_iterator iter = particle_positions.begin();
155 iter != particle_positions.end(); ++iter) {
156 for (std::vector< double >::const_iterator positer = (*iter).begin();
157 positer != (*iter).end(); ++positer) {
[e089fb]158 particles.f[index] = 0.;
159 particles.x[index++] = *positer;
[a82602]160 }
161 }
[e089fb]162 ASSERT( index == particles.num_particles*3,
[a82602]163 "VMGJob::VMGJob() - too many particles or components in particle_positions.");
164 }
165 {
166 size_t index = 0;
167 for (std::vector< double >::const_iterator iter = particle_charges.begin();
168 iter != particle_charges.end(); ++iter) {
[e089fb]169 particles.p[index] = 0.;
170 particles.q[index++] = *iter;
[a82602]171 }
[e089fb]172 ASSERT( index == particles.num_particles,
[a82602]173 "VMGJob::VMGJob() - too many charges in particle_charges.");
174 }
175}
176
[d2a0f6d]177
178FragmentResult::ptr VMGJob::Work()
179{
[e9cfc4]180 // initialize VMG library solver
181 InitVMG();
182
183 /*
184 * Start the multigrid solver
185 */
186 MG::Solve();
187
188 /// create and fill result object
[442cee]189 // place into returnstream
190 std::stringstream returnstream;
191 boost::archive::text_oarchive oa(returnstream);
[2bc560]192 oa << returndata;
[442cee]193
194 FragmentResult::ptr ptr( new FragmentResult(getId(), returnstream.str()) );
[e9cfc4]195
196 /*
197 * Delete all data.
198 */
199 MG::Destroy();
200
[d2a0f6d]201 return ptr;
202}
203
[e9cfc4]204/** Initialization of VMG library.
205 *
206 * The contents is heavily inspired from interface_fcs.cpp: VMG_fcs_init() of
207 * the ScaFaCoS project.
208 *
209 */
210void VMGJob::InitVMG()
211{
[ee9018]212 Boundary *boundary = NULL;
213 if (OpenBoundaryConditions)
214 boundary = new Boundary(Open, Open, Open);
215 else
216 boundary = new Boundary(Periodic, Periodic, Periodic);
[e9cfc4]217
218 /*
219 * Choose multigrid components (self-registering)
220 */
[ee9018]221
[8a8c8c]222#ifdef HAVE_MPI
[ee9018]223 new Particle::CommMPI(*boundary, new DomainDecompositionMPI());
[8a8c8c]224#else
[ee9018]225 new CommSerial(*boundary);
[8a8c8c]226#endif
[ee9018]227 if (OpenBoundaryConditions)
228 new DiscretizationPoissonFV(2);
229 else
230 new DiscretizationPoissonFD(4);
[e9cfc4]231 new VMGInterfaces::InterfaceVMGJob(
[8f3cdd]232 density_grid,
[2bc560]233 returndata,
[cd77fc]234 particle_positions,
235 particle_charges,
[ee9018]236 *boundary,
[e9cfc4]237 2,
[28c025]238 density_grid.level,
239 Vector(density_grid.begin),
[3d9a8d]240 density_grid.end[0]-density_grid.begin[0],
[b6b21a]241 near_field_cells,
[e2925fd]242 DoImportParticles ?
243 VMGInterfaces::InterfaceVMGJob::DoImportParticles
244 : VMGInterfaces::InterfaceVMGJob::DontImportParticles,
[b6b21a]245 DoPrintDebug);
[e9cfc4]246 const int cycle_type = 1; // V-type
[ee9018]247 if (OpenBoundaryConditions) {
248 new LevelOperatorFAS(Stencils::RestrictionFullWeight, Stencils::Injection, Stencils::InterpolationTrilinear);
249 new Givens<SolverRegular>();
250 new CycleFASDirichlet(cycle_type);
251 new GaussSeidelRBPoisson2();
252 } else {
253 new LevelOperatorCS(Stencils::RestrictionFullWeight, Stencils::InterpolationTrilinear);
254 new Givens<SolverSingular>();
255 new CycleCSPeriodic(cycle_type);
256 new GaussSeidelRBPoisson4();
257 }
258 delete boundary;
[e9cfc4]259
260 /*
261 * Register required parameters
262 */
263 new ObjectStorage<int>("PRESMOOTHSTEPS", 3);
264 new ObjectStorage<int>("POSTSMOOTHSTEPS", 3);
265 new ObjectStorage<vmg_float>("PRECISION", 1.0e-10);
266 new ObjectStorage<int>("MAX_ITERATION", 15);
[cd77fc]267 new ObjectStorage<int>("PARTICLE_NEAR_FIELD_CELLS", near_field_cells);
[cd2591]268 new ObjectStorage<int>("PARTICLE_INTERPOLATION_DEGREE", interpolation_degree);
[e9cfc4]269
[a82602]270 // first initialize f,x,p,q,... from STL vectors
271 InitVMGArrays();
272 // then initialize as objects with VMG's storage
[e089fb]273 new ObjectStorage<vmg_float*>("PARTICLE_POS_ARRAY", particles.x);
274 new ObjectStorage<vmg_float*>("PARTICLE_CHARGE_ARRAY", particles.q);
275 new ObjectStorage<vmg_float*>("PARTICLE_POTENTIAL_ARRAY", particles.p);
276 new ObjectStorage<vmg_float*>("PARTICLE_FIELD_ARRAY", particles.f);
277 new ObjectStorage<vmg_int>("PARTICLE_NUM_LOCAL", particles.num_particles);
[a82602]278
[e9cfc4]279 /*
280 * Post init
281 */
282 MG::PostInit();
283
284 /*
285 * Check whether the library is correctly initialized now.
286 */
287 MG::IsInitialized();
288}
289
[d2a0f6d]290// we need to explicitly instantiate the serialization functions as
291// its is only serialized through its base class FragmentJob
292BOOST_CLASS_EXPORT_IMPLEMENT(VMGJob)
Note: See TracBrowser for help on using the repository browser.