Commit 72281e73 by Francois Gygi

Added set_velocity command.

Updated help message of move command to include * arguments.


git-svn-id: http://qboxcode.org/svn/qb/trunk@1818 cba15fb0-1239-40c8-b417-11db7ca47a34
parent 20622faa
......@@ -15,7 +15,6 @@
// MoveCmd.h:
//
////////////////////////////////////////////////////////////////////////////////
// $Id: MoveCmd.h,v 1.5 2008-09-08 15:56:18 fgygi Exp $
#ifndef MOVECMD_H
#define MOVECMD_H
......@@ -44,7 +43,9 @@ class MoveCmd : public Cmd
" syntax: move atom_name {to|by} x y z \n\n"
" The move command displaces an atom to a new position.\n"
" The new position is defined by absolute coordinates (to) or\n"
" by a relative displacement (by).\n\n";
" by a relative displacement (by).\n"
" When using 'to', if one or more of the arguments is '*',\n"
" the corresponding component of the velocity is unchanged.\n\n";
}
int action(int argc, char **argv)
......
////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2008 The Regents of the University of California
//
// This file is part of Qbox
//
// Qbox is distributed under the terms of the GNU General Public License
// as published by the Free Software Foundation, either version 2 of
// the License, or (at your option) any later version.
// See the file COPYING in the root directory of this distribution
// or <http://www.gnu.org/licenses/>.
//
////////////////////////////////////////////////////////////////////////////////
//
// SetVelocityCmd.h:
//
////////////////////////////////////////////////////////////////////////////////
#ifndef SETVELOCITYCMD_H
#define SETVELOCITYCMD_H
#include <string>
#include <cstdlib>
#include <iostream>
using namespace std;
#include "UserInterface.h"
#include "Sample.h"
class SetVelocityCmd : public Cmd
{
public:
Sample *s;
SetVelocityCmd(Sample *sample) : s(sample) {};
const char *name(void) const { return "set_velocity"; }
const char *help_msg(void) const
{
return
"\n set_velocity\n\n"
" syntax: set_velocity atom_name {vx|*|-} {vy|*|-} {vz|*|-}\n\n"
" The set_velocity command sets the velocity of an atom to vx,vy,vz.\n"
" If an argument is '*', the corresponding component of\n"
" the velocity is unchanged.\n"
" If an argument is '-', the corresponding component of\n"
" the velocity changes sign.\n\n";
}
int action(int argc, char **argv)
{
// set_velocity must have 5 arguments including the command name
if ( argc != 5 )
{
if ( ui->onpe0() )
cout << " use: set_velocity atom_name vx vy vz " << endl;
return 1;
}
const string atom_name = argv[1];
const string vxs = argv[2];
const string vys = argv[3];
const string vzs = argv[4];
Atom* pa = s->atoms.findAtom(atom_name);
if ( !pa )
{
if ( ui->onpe0() )
cout << " SetVelocityCmd: could not find atom " << atom_name << endl;
return 1;
}
D3vector vel = pa->velocity();
double vx = vel.x;
double vy = vel.y;
double vz = vel.z;
// change component only if argument is not "*"
if ( vxs != "*" )
vx = atof(argv[2]);
if ( vys != "*" )
vy = atof(argv[3]);
if ( vzs != "*" )
vz = atof(argv[4]);
// change sign of component if argument is "-"
if ( vxs == "-" )
vx = -vel.x;
if ( vys == "-" )
vy = -vel.y;
if ( vzs == "-" )
vz = -vel.z;
vel = D3vector(vx,vy,vz);
pa->set_velocity(vel);
if ( ui->onpe0() )
cout << " SetVelocityCmd: atom " << atom_name << " set to "
<< vel << endl;
return 0;
}
};
#endif
......@@ -69,6 +69,7 @@ using namespace std;
#include "RunCmd.h"
#include "SaveCmd.h"
#include "SetCmd.h"
#include "SetVelocityCmd.h"
#include "SpeciesCmd.h"
#include "StatusCmd.h"
#include "StrainCmd.h"
......@@ -284,6 +285,7 @@ int main(int argc, char **argv, char **envp)
ui.addCmd(new RunCmd(s));
ui.addCmd(new SaveCmd(s));
ui.addCmd(new SetCmd(s));
ui.addCmd(new SetVelocityCmd(s));
ui.addCmd(new SpeciesCmd(s));
ui.addCmd(new StatusCmd(s));
ui.addCmd(new StrainCmd(s));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment