ComputeMField.C:28:3: error: expected ‘)’ before ‘!’ token

Hello all
i am a beginner in C++ and i have got an error when I am running my code on Ubuntu.
I want to have the velocity in half step time for every atom, so I have defined the halfstep in atom structure;
*************************************
1
2
3
4
5
struct FullAtom : CompAtom, CompAtomExt{
  Velocity velocity;
  Velocity velocityHalfStep;
  Position fixedPosition;
  Mass mass;

******************************************sequencer.h
void UpdateHalfStepVelocities();
**************************************sequencer.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
for ( ++step; step <= numberOfSteps; ++step )
    {

      rescaleVelocities(step);
      tcoupleVelocities(timestep,step);
      berendsenPressure(step);

      if ( ! commOnly ) {
        newtonianVelocities(0.5,timestep,nbondstep,slowstep,staleForces,doNonbonded,doFullElectrostatics); 
        UpdateHalfStepVelocities();
      }
     
      

      // We do RATTLE here if multigrator thermostat was applied in the previous step
      if (doMultigratorRattle) rattle1(timestep, 1);



*****************************************************ComputeMField
( ! commOnly ) {
newtonianVelocities(0.5,timestep,nbondstep,slowstep,staleForces,doNonbonded,doFullElectrostatics);
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//  Loop through and check each atom
  for (int i=0; i<numAtoms; i++) {
    Force force = p[i].charge * cross(p[i].velocityHalfStep, mField1);
    forces[i] += force;
    Position vpos = homePatch->lattice.reverse_transform(
		p[i].position, p[i].transform );
    energy -= force * (vpos - homePatch->lattice.origin()); //TODO: Kosar, energy preservation should hold
    printf("charge: %f", p[i].charge);
    printf(", force: [%f, %f, %f]", force.x, force.y, force.z);
    printf(", velocity: [%f, %f, %f]\n\n", p[i].velocity.x, p[i].velocity.y, p[i].velocity.z);
    if ( ! normalized ) {
      extForce += force;
      extVirial += outer(force,vpos);
      }
}      
[/code]
***************************
finally after running this subroutines, I have got this error;
ComputeMField.C:28:3: error: expected unqualified-id before ‘!’ token
 ( ! commOnly ) {
   ^

ComputeMField.C:28:3: error: expected ‘)’ before ‘!’ token
make: *** [obj/ComputeMField.o] Error 1

**********************************************
I can not understand fully the error and I do not know how I can resolve it.
Any suggestion will be helpful...
thank you for your consideration
Best
Kosar

Last edited on
First, please use code tags when you post code. See http://www.cplusplus.com/articles/jEywvCM9/

Formatting of text can substantially help seeing odd bits.

1
2
3
4
if ( ! commOnly ) {
  newtonianVelocities(/*args*/);
  UpdateHalfStepVelocities();
}


What is the scope, where this if-statement is in?
Such statements must be inside a body of a function.
dear keskiverto
Thanks for quick reply. I am sorry. I tried to edit the question and code's parts.
however, there is a limitation to include all the "sequencer.c" in this massage.
Yes, my problem is that "newtonianVelocities" has been called inside a "for" loop and I am going to save its data and call it in "ComputeMField".
I do not know what is the meaning of "scope" in your question.
these files are part of source code which i am trying to extend it. I need velocity in half step (i mean "newtonianvelocities(0.5,...)). maybe this helps to clarify my question.
thanks in advance
Kosar
Last edited on
What is on line 28 of file ComputeMField.C, and before that line?
1
2
3
( ! commOnly ) {
        newtonianVelocities(0.5,timestep,nbondstep,slowstep,staleForces,doNonbonded,doFullElectrostatics); 
      }





I though that I should write it in "computeMfield.c"...
After deleting that comment in "computeMField.c", i have got below error;
struct FullAtom
class FullAtom
} FullAtom;
typdef Atom FullAtom;
src/ScriptTcl.C: In static member function ‘static int ScriptTcl::Tcl_reinitatoms(ClientData, Tcl_Interp*, int, char**)’:
src/ScriptTcl.C:1554:53: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
     Tcl_SetResult(interp,"wrong # args",TCL_VOLATILE);
                                                     ^
src/ScriptTcl.C: In static member function ‘static int ScriptTcl::Tcl_reloadStructure(ClientData, Tcl_Interp*, int, char**)’:
src/ScriptTcl.C:1907:60: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
       Tcl_SetResult(interp,"unknown structure",TCL_VOLATILE);
                                                            ^
g++ -m64 -std=c++0x -O3 -I.rootdir/charm-6.7.1/multicore-linux64/include -DCMK_OPTIMIZE=1 -Isrc -Iinc    -Iplugins/include -DSTATIC_PLUGIN -I.rootdir/tcl-threaded/include -DNAMD_TCL  -I.rootdir/fftw/include -DNAMD_FFTW     -DNAMD_VERSION=\"2.12\" -DNAMD_PLATFORM=\"Linux-x86_64-multicore\"  -DREMOVE_PROXYRESULTMSG_EXTRACOPY -DNODEAWARE_PROXY_SPANNINGTREE -DUSE_NODEPATCHMGR    -DUSE_CKLOOP=1 -fexpensive-optimizations -ffast-math   -o obj/Sequencer.o -c src/Sequencer.C
src/Sequencer.C: In member function ‘void Sequencer::integrate(int)’:
src/Sequencer.C:340:7: error: expected primary-expression before ‘/’ token
       /reassignment based on half-step velocities
       ^
src/Sequencer.C:340:8: error: ‘reassignment’ was not declared in this scope
       /reassignment based on half-step velocities
        ^
src/Sequencer.C:340:21: error: expected ‘;’ before ‘based’
       /reassignment based on half-step velocities
                     ^
src/Sequencer.C:349:12: error: expected primary-expression before ‘/’ token
          } /
            ^
make: *** [obj/Sequencer.o] Error 1
Deleting a comment cannot change anything (except line numbering).


You say that line 28 of ComputeMField.C is exactly:
( ! commOnly ) {

What is before that line?


You have not shown relevant code yet.
Hello again...I have a simple question!
I am working with the source code of molecular dynamics simulation package.
The "cross product" has been defined in one of its file as below;
1
2
3
4
5
6
7
8
9
10
11
12
AVector AVector::cross(const AVector& Vector) {
//-------------------------------------------------------------------
// calculate this vector crossed with Vector (this x Vector).
// see Mathematical Handbook, p.118.
//-------------------------------------------------------------------
  AVector CrossProduct;

  CrossProduct.m_x = (m_y * Vector.m_z) - (m_z * Vector.m_y);
  CrossProduct.m_y = (m_z * Vector.m_x) - (m_x * Vector.m_z);
  CrossProduct.m_z = (m_x * Vector.m_y) - (m_y * Vector.m_x);
  return(CrossProduct);
}

And I have made some modification in the source code, same below to update the
force
;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/**
***  Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000 by
***  The Board of Trustees of the University of Illinois.
***  All rights reserved.
**/

#include "InfoStream.h"
#include "ComputeMField.h"
#include "Node.h"
#include "SimParameters.h"
#include "HomePatch.h"
#include "Sequencer.h"
#include "HomePatch.h"
#include "ReductionMgr.h"
#include "CollectionMgr.h"
#include "BroadcastObject.h"
#include "Output.h"
#include "Controller.h"
#include "Broadcasts.h"
#include "Molecule.h"
#include "NamdOneTools.h"
#include "LdbCoordinator.h"
#include "Thread.h"
#include "Random.h"
#include "PatchMap.inl"
#include "ComputeMgr.h"
#include "ComputeGlobal.h"

ComputeMField::ComputeMField(ComputeID c, PatchID pid)
  : ComputeHomePatch(c,pid)
{

	reduction = ReductionMgr::Object()->willSubmit(REDUCTIONS_BASIC);

}
/*			END OF FUNCTION ComputeMField		*/


ComputeMField::~ComputeMField()

{
	delete reduction;
}
/*			END OF FUNCTION ~ComputeMField		*/


void ComputeMField::doForce(FullAtom* p, Results* r) {

  SimParameters *simParams = Node::Object()->simParameters;
  Vector mField = simParams->mField;
  // Calculate the angular frequency in 1/fs.
  //TODO: Kosar, does frequency and phase  make sense in magnetic field? If not, change where approperate
  BigReal omega = TWOPI * simParams->mFieldFreq / 1000.;
  BigReal phi = PI/180.* simParams->mFieldPhase;
  BigReal t = patch->flags.step * simParams->dt;
  Vector mField1 = cos(omega * t - phi) * mField;

  const int normalized = simParams->mFieldNormalized;
  if ( normalized ) {
    Lattice &l = homePatch->lattice;
    mField1 = Vector(l.a_r()*mField1, l.b_r()*mField1, l.c_r()*mField1);
  }

  Force *forces = r->f[Results::normal];
  BigReal energy = 0;
  Force extForce = 0.;
  Tensor extVirial;

  //  Loop through and check each atom
  for (int i=0; i<numAtoms; i++) {
    Force force = (-p[i].charge) * cross(mField1, p[i].velocity);
    forces[i] += force;
    Position vpos = homePatch->lattice.reverse_transform(
		p[i].position, p[i].transform );
    energy -= force * (vpos - homePatch->lattice.origin()); //TODO: Kosar, energy preservation should hold
    printf("charge: %f", p[i].charge);
    printf(", force: [%f, %f, %f]", force.x, force.y, force.z);
    printf(", velocity: [%f, %f, %f]\n\n", p[i].velocityHalfStep.x, p[i].velocityHalfStep.y, p[i].velocityHalfStep.z);
    if ( ! normalized ) {
      extForce += force;
      extVirial += outer(force,vpos);
      }
}                                                                                                                                                            

  reduction->item(REDUCTION_MISC_ENERGY) += energy;
  if ( ! normalized ) {
    ADD_VECTOR_OBJECT(reduction,REDUCTION_EXT_FORCE_NORMAL,extForce);
    ADD_TENSOR_OBJECT(reduction,REDUCTION_VIRIAL_NORMAL,extVirial);
  }
  reduction->submit();

}
/*			END OF FUNCTION force				*/

Now my question is that;
when I set the
Force force = (-p[i].charge) * cross(mField1, p[i].velocity);
the results are completely correct.
when I set the
Force force = (p[i].charge) * cross( p[i].velocity, mField1);
the result are not meaningful!!!
what is different between these two? We know that
A*B=-B*A

Also I should mention that in the manual of the package, the cross has been explained same as below;
friend Vector cross(const Vector &v1, const Vector &v2)
returns the Vector cross product, which is v1*v2

And the velocity vector and mField1 vector, both have been defined at the beginning of the code...
Thanks in advance for your comments...

Last edited on
Topic archived. No new replies allowed.