Commit ce5eae47 by Francois Gygi

Added iter_cmd and iter_cmd_period variables


git-svn-id: http://qboxcode.org/svn/qb/trunk@1765 cba15fb0-1239-40c8-b417-11db7ca47a34
parent c91a9f9b
......@@ -25,6 +25,7 @@
#include "PSDWavefunctionStepper.h"
#include "PSDAWavefunctionStepper.h"
#include "JDWavefunctionStepper.h"
#include "UserInterface.h"
#include "Preconditioner.h"
#include "SDIonicStepper.h"
#include "SDAIonicStepper.h"
......@@ -37,10 +38,6 @@
#include "MLWFTransform.h"
#include "D3tensor.h"
#ifdef USE_APC
#include "apc.h"
#endif
#include <iostream>
#include <iomanip>
using namespace std;
......@@ -355,9 +352,6 @@ void BOSampleStepper::step(int niter)
// ionic iteration
tm_iter.start();
#ifdef USE_APC
ApcStart(1);
#endif
if ( onpe0 )
cout << "<iteration count=\"" << iter+1 << "\">\n";
......@@ -1131,9 +1125,20 @@ void BOSampleStepper::step(int niter)
}
}
#ifdef USE_APC
ApcStop(1);
#endif
if ( atoms_move )
s_.constraints.update_constraints(dt);
// execute commands in iter_cmd if defined
if ( !s_.ctrl.iter_cmd.empty() )
{
if ( iter % s_.ctrl.iter_cmd_period == 0 )
{
// command must be terminated with \n
istringstream cmdstream(s_.ctrl.iter_cmd + "\n");
s_.ui->processCmds(cmdstream,"[iter_cmd]",true);
}
}
// print iteration time
double time = tm_iter.real();
double tmin = time;
......@@ -1148,8 +1153,6 @@ void BOSampleStepper::step(int niter)
<< endl;
cout << "</iteration>" << endl;
}
if ( atoms_move )
s_.constraints.update_constraints(dt);
} // for iter
if ( atoms_move )
......
......@@ -72,5 +72,8 @@ struct Control
D3vector e_field;
std::string polarization;
std::string iter_cmd;
int iter_cmd_period;
};
#endif
////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2015 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/>.
//
////////////////////////////////////////////////////////////////////////////////
//
// IterCmd.h
//
////////////////////////////////////////////////////////////////////////////////
#ifndef ITERCMD_H
#define ITERCMD_H
#include<iostream>
#include<iomanip>
#include<sstream>
#include<stdlib.h>
#include "Sample.h"
class IterCmd : public Var
{
Sample *s;
public:
const char *name ( void ) const { return "iter_cmd"; };
int set ( int argc, char **argv )
{
// include all arguments until \n
string v;
for ( int i = 1; i < argc; i++ )
v += argv[i];
s->ctrl.iter_cmd = v;
return 0;
}
string print (void) const
{
ostringstream st;
st.setf(ios::left,ios::adjustfield);
st << setw(10) << name() << " = ";
st.setf(ios::right,ios::adjustfield);
st << s->ctrl.iter_cmd;
return st.str();
}
IterCmd(Sample *sample) : s(sample) { s->ctrl.iter_cmd = ""; };
};
#endif
////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2015 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/>.
//
////////////////////////////////////////////////////////////////////////////////
//
// IterCmdPeriod.h
//
////////////////////////////////////////////////////////////////////////////////
#ifndef ITERCMDPERIOD_H
#define ITERCMDPERIOD_H
#include<iostream>
#include<iomanip>
#include<sstream>
#include<stdlib.h>
#include "Sample.h"
class IterCmdPeriod : public Var
{
Sample *s;
public:
const char *name ( void ) const { return "iter_cmd_period"; };
int set ( int argc, char **argv )
{
if ( argc != 2 )
{
if ( ui->onpe0() )
cout << " iter_cmd_period must be a positive integer" << endl;
return 1;
}
int v = atoi(argv[1]);
if ( v <= 0 )
{
if ( ui->onpe0() )
cout << " iter_cmd_period must be a positive integer" << endl;
return 1;
}
s->ctrl.iter_cmd_period = v;
return 0;
}
string print (void) const
{
ostringstream st;
st.setf(ios::left,ios::adjustfield);
st << setw(10) << name() << " = ";
st.setf(ios::right,ios::adjustfield);
st << setw(10) << s->ctrl.iter_cmd_period;
return st.str();
}
IterCmdPeriod(Sample *sample) : s(sample) { s->ctrl.iter_cmd_period = 1; };
};
#endif
......@@ -15,7 +15,6 @@
// Sample.h
//
////////////////////////////////////////////////////////////////////////////////
// $Id: Sample.h,v 1.13 2010-02-20 23:13:02 fgygi Exp $
#ifndef SAMPLE_H
#define SAMPLE_H
......@@ -27,6 +26,7 @@
#include "Control.h"
class Context;
class UserInterface;
class Sample
{
......@@ -42,8 +42,10 @@ class Sample
Wavefunction wf;
Wavefunction* wfv; // wavefunction velocity
Control ctrl;
UserInterface *ui;
Sample(const Context& ctxt) : ctxt_(ctxt), atoms(ctxt), constraints(ctxt),
Sample(const Context& ctxt, UserInterface *ui_) : ctxt_(ctxt), ui(ui_),
atoms(ctxt), constraints(ctxt),
extforces(ctxt), wf(ctxt), wfv(0) {}
~Sample(void) { delete wfv; }
void reset(void)
......
......@@ -15,7 +15,6 @@
// UserInterface.C: definition of readCmd and processCmds
//
////////////////////////////////////////////////////////////////////////////////
// $Id: UserInterface.C,v 1.14 2009-11-30 02:28:54 fgygi Exp $
#include "UserInterface.h"
#include "qbox_xmlns.h"
......@@ -73,8 +72,17 @@ UserInterface::~UserInterface(void)
int UserInterface::readCmd(char *s, int max, istream &fp, bool echo)
{
int ch, i = 0;
while ( (ch = fp.get()) != EOF && !( ch == '\n' || ch ==';' || ch == '#') )
if ( fp.eof() )
{
//!!
cout << "early return" << endl;
return 0;
}
while ( !fp.eof() && !( ch == '\n' || ch ==';' || ch == '#') )
{
ch = fp.get();
//!!
//!!cout << (char)ch;
if ( ch == '\\' ) // line continuation character
{
// check if backslash is followed by a newline
......@@ -92,15 +100,16 @@ int UserInterface::readCmd(char *s, int max, istream &fp, bool echo)
s[i++] = ch;
}
}
else
else if ( !fp.eof() && !( ch == '\n' || ch == ';' || ch == '#' ) )
{
if (i < max - 1)
s[i++] = ch;
}
}
if (max > 0) s[i] = '\0'; /* add terminating NULL */
if ( !(ch == '\n' || ch == ';' || ch == '#') )
if ( fp.eof() )
return 0; /* return 0 for end of file */
// output command line if reading from a script
......@@ -126,6 +135,10 @@ int UserInterface::readCmd(char *s, int max, istream &fp, bool echo)
void UserInterface::processCmds ( istream &cmdstream, const char *prompt,
bool echo)
{
#if DEBUG
cout << "UserInterface::processCmds: prompt="
<< prompt << " echo=" << echo << endl;
#endif
// read and process commands from cmdstream until done
char cmdline[256];
for ( int i = 0; i < 256; i++ )
......@@ -150,6 +163,9 @@ void UserInterface::processCmds ( istream &cmdstream, const char *prompt,
MPI_Bcast(&cmd_read,1,MPI_INT,0,MPI_COMM_WORLD);
#endif
//!!
//!!cout << "cmd_read=" << cmd_read << endl;
if ( cmd_read )
{
// cmdline contains a string of tokens terminated by '\0'
......@@ -228,7 +244,7 @@ void UserInterface::processCmds ( istream &cmdstream, const char *prompt,
MPI_Barrier(MPI_COMM_WORLD);
#endif
#if DEBUG
cout << " command completed" << cmdptr->name() << endl;
cout << " command completed " << cmdptr->name() << endl;
#endif
}
else
......
////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2008-2012 The Regents of the University of California
// Copyright (c) 2008-2015 The Regents of the University of California
//
// This file is part of Qbox
//
......@@ -27,9 +27,6 @@ using namespace std;
#if AIX
#include<filehdr.h>
#endif
#ifdef USE_APC
#include "apc.h"
#endif
#include "isodate.h"
#include "release.h"
......@@ -99,6 +96,8 @@ using namespace std;
#include "Emass.h"
#include "ExtStress.h"
#include "FermiTemp.h"
#include "IterCmd.h"
#include "IterCmdPeriod.h"
#include "Dt.h"
#include "Nempty.h"
#include "NetCharge.h"
......@@ -127,9 +126,6 @@ int main(int argc, char **argv, char **envp)
#if USE_MPI
MPI_Init(&argc,&argv);
#endif
#if USE_APC
ApcInit();
#endif
#if BGLDEBUG
{
......@@ -258,9 +254,8 @@ int main(int argc, char **argv, char **envp)
<< " </omp_max_threads>" << endl;
#endif
Sample* s = new Sample(ctxt);
UserInterface ui;
Sample* s = new Sample(ctxt, &ui);
ui.addCmd(new AngleCmd(s));
ui.addCmd(new AtomCmd(s));
......@@ -315,6 +310,8 @@ int main(int argc, char **argv, char **envp)
ui.addVar(new Emass(s));
ui.addVar(new ExtStress(s));
ui.addVar(new FermiTemp(s));
ui.addVar(new IterCmd(s));
ui.addVar(new IterCmdPeriod(s));
ui.addVar(new Nempty(s));
ui.addVar(new NetCharge(s));
ui.addVar(new Nrowmax(s));
......@@ -391,9 +388,6 @@ int main(int argc, char **argv, char **envp)
delete s;
} // end of Context scope
#if USE_APC
ApcFinalize();
#endif
#if USE_MPI
MPI_Finalize();
#endif
......
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