Simpatico  v1.10
DeformCommand.cpp
1 /*
2 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
3 *
4 * Copyright 2010 - 2017, The Regents of the University of Minnesota
5 * Distributed under the terms of the GNU General Public License.
6 */
7 
8 #include "DeformCommand.h"
9 #include <mcMd/simulation/Simulation.h>
10 #include <mcMd/simulation/System.h>
11 //#include <util/format/Str.h>
12 //#include <util/misc/FileMaster.h>
13 
14 namespace McMd
15 {
16 
17  using namespace Util;
18 
19  /*
20  * Default constructor.
21  */
23  : Command("DEFORM_CELL"),
24  SystemInterface(system)
25  { setClassName("DeformCommand"); }
26 
27  /*
28  * Default destructor.
29  */
31  {}
32 
33  /*
34  * Execute command to deform unit cell.
35  */
36  void DeformCommand::execute(std::istream& in)
37  {
38 
39  // Transform atomic positions to generalized [0,1] coordinates
41  Molecule::AtomIterator atomIter;
42  Vector cartPosition, genPosition;
43  int nSpecies = simulation().nSpecies();
44  for (int iSpec=0; iSpec < nSpecies; ++iSpec) {
45  begin(iSpec, molIter);
46  for ( ; molIter.notEnd(); ++molIter) {
47  molIter->begin(atomIter);
48  for ( ; atomIter.notEnd(); ++atomIter) {
49  cartPosition = atomIter->position();
50  boundary().transformCartToGen(cartPosition, genPosition);
51  atomIter->position() = genPosition;
52  }
53  }
54  }
55 
56  // Read new system boundary
57  in >> boundary();
58  Log::file() << " " << system().boundary();
59  Log::file() << std::endl;
60 
61  // Transform positions back to Cartesian
62  for (int iSpec=0; iSpec < nSpecies; ++iSpec) {
63  begin(iSpec, molIter);
64  for ( ; molIter.notEnd(); ++molIter) {
65  molIter->begin(atomIter);
66  for ( ; atomIter.notEnd(); ++atomIter) {
67  genPosition = atomIter->position();
68  boundary().transformGenToCart(genPosition, cartPosition);
69  atomIter->position() = cartPosition;
70  }
71  }
72  }
73 
74  // Rebuild cell and/or pair list.
75  reneighbor();
76 
77  }
78 
79 }
A Vector is a Cartesian vector.
Definition: Vector.h:75
DeformCommand(System &system)
Constructor.
virtual ~DeformCommand()
Destructor.
An interface to a System.
bool notEnd() const
Is the current pointer not at the end of the array?
Definition: ArrayIterator.h:83
A set of interacting Molecules enclosed by a Boundary.
Definition: System.h:115
virtual void execute(std::istream &in)
Execute deformation command.
virtual void reneighbor()=0
Rebuild cell and/or pair list after deforming positions.
Simulation & simulation() const
Get the parent Simulation by reference.
bool notEnd() const
Is the current pointer not at the end of the PArray?
Utility classes for scientific computation.
Definition: accumulators.mod:1
Command is an object that can be invoked from the command script.
Definition: Command.h:40
Forward iterator for an Array or a C array.
Definition: ArrayIterator.h:39
Forward iterator for a PArray.
Definition: ArraySet.h:19
void transformGenToCart(const Vector &Rg, Vector &Rc) const
Transform Vector of generalized coordinates to Cartesian Vector.
static std::ostream & file()
Get log ostream by reference.
Definition: Log.cpp:57
void begin(int speciesId, System::MoleculeIterator &iterator)
Initialize an iterator for molecules of one species in this SystemInterface.
Boundary & boundary() const
Get the Boundary by reference.
Definition: System.h:1064
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
int nSpecies() const
Get the number of Species in this Simulation.
void setClassName(const char *className)
Set class name string.
Boundary & boundary() const
Get the Boundary by reference.
System & system() const
Get the parent System by reference.
void transformCartToGen(const Vector &Rc, Vector &Rg) const
Transform Cartesian Vector to scaled / generalized coordinates.