On 25 Apr 2014, at 21:34, Nigel Nunn <[email protected]> wrote:
> On 09 Jul 2013, at 10:34, Christophe Geuzaine <cgeuzaine at ulg.ac.be> wrote:
>
> > Hi Nigel - Have a look at utils/solvers/c++ and utils/solvers/python in SVN.
>
> Dear Christophe,
>
> Thanks for the hint! I used /utils/solvers/c++/pend.cpp as an example for
> interacting with ONELAB, added some code to handle MPI launch commands, and
> everything is working even better than before :-)
>
> For our MPI+GPU solvers, it's important to be able to [Pause] and inspect a
> simulation, so I added a [Pause] button. This uses the process id returned
> from MPI proc[0] (during /Action = "initialize") to pause that particular
> process, which just happens to pause all the MPI procs at the next MPI
> barrier.
>
> Since my code to make this work (on Win x64) is a bit of a hack, I wonder if
> any of your getDP or ONELAB collaborators have set up a more ONELAB-standard
> [Pause] mechanism?
Why not just creating a onelab variable for pausing? Attached is my first try
in python:
#!/usr/bin/env python
#coding=utf-8
# 1) launch "gmsh pend.py"
# 2) there is no 2... :-)
import onelab
import math, os
def exportMsh(le1,le2):
mshFile = open(onelab.path(__file__, "pend.msh"),'w')
mshFile.write('$MeshFormat\n2.2 0 8\n$EndMeshFormat\n')
mshFile.write('$Nodes\n3\n1 0 0 0\n2 0 %s 0\n3 0 %s 0\n$EndNodes\n' %(-le1, -le1-le2))
mshFile.write('$Elements\n3\n1 1 2 0 1 1 2\n2 1 2 0 1 2 3\n3 15 2 0 2 3\n$EndElements\n')
mshFile.close()
def exportMshOpt():
optFile = open(onelab.path(__file__, "pend.msh.opt"),'w')
optFile.write('n = PostProcessing.NbViews - 1;\n')
optFile.write('If(n >= 0)\nView[n].ShowScale = 0;\nView[n].VectorType = 5;\n')
optFile.write('View[n].ExternalView = 0;\nView[n].DisplacementFactor = 1 ;\n')
optFile.write('View[n].PointType = 1;\nView[n].PointSize = 5;\n')
optFile.write('View[n].LineWidth = 2;\nEndIf\n')
optFile.close()
def exportIter(iter,t,x1,y1,x2,y2):
mshFile = open(onelab.path(__file__, "pend.msh"),'a')
mshFile.write('$NodeData\n1\n"motion"\n1\n\t%f\n3\n\t%d\n3\n' % (t, iter))
mshFile.write('\t3\n\t1 0 0 0\n\t2 %f %f 0\n\t3 %f %f 0\n$EndNodeData\n' %(x1,y1,x2,y2))
mshFile.close()
c = onelab.client()
g = 9.8 # acceleration of gravity
m = 0.3 # mass of pendulum balls
l = c.defineNumber('Geom/arm length [m]', value=1.0)
time = c.defineNumber('Dyna/time [s]', value=0.0)
dt = c.defineNumber('Dyna/time step [s]', value=0.001)
tmax = c.defineNumber('Dyna/max time [s]', value=20)
refresh = c.defineNumber('Dyna/refresh interval [s]', value=0.05)
theta0 = c.defineNumber('Init/initial theta angle [deg]', value=10,
attributes={'Highlight':'Pink'})
phi0 = c.defineNumber('Init/initial phi angle [deg]', value=180,
attributes={'Highlight':'Pink'})
pause = c.defineNumber('Pause', value=0, choices=[0,1])
# we're done if we are in the "check" phase
if c.action == 'check' :
exit(0)
l1 = l;
l2 = l;
m1 = m;
m2 = m;
theta = theta0 / 180.*math.pi;
phi = phi0 / 180.*math.pi;
theta_dot = 0.0
phi_dot = 0.0
refr = 0.0
iter = 0
time = 0.0
while (time < tmax):
if(c.getNumber('Pause')):
continue;
delta = phi - theta
sdelta = math.sin(delta)
cdelta = math.cos(delta)
theta_dot_dot = ( m2*l1*(theta_dot**2.0)*sdelta*cdelta
+ m2*g*math.sin(phi)*cdelta
+ m2*l2*(phi_dot**2.0)*sdelta
- (m1+m2)*g*math.sin(theta) )
theta_dot_dot /= ( (m1+m2)*l1 - m2*l1*(cdelta)**2.0 )
phi_dot_dot = ( -m2*l2*(phi_dot**2.0)*sdelta*cdelta
+ (m1+m2)*(g*math.sin(theta)*cdelta
- l1*(theta_dot**2.0)*sdelta
- g*math.sin(phi)) )
phi_dot_dot /= ( (m1+m2)*l2 - m2*l2*(cdelta)**2.0 )
theta_dot = theta_dot + theta_dot_dot*dt
phi_dot = phi_dot + phi_dot_dot*dt
theta = theta + theta_dot*dt
phi = phi + phi_dot*dt
x1 = l1*math.sin(theta)
y1 = -l1*math.cos(theta)
x2 = l1*math.sin(theta) + l2*math.sin(phi)
y2 = -l1*math.cos(theta) - l2*math.cos(phi)
time += dt
refr += dt
exportMshOpt()
if refr >= refresh:
refr = 0
c.setNumber(c.name + '/Progress', value=time, min=0, max=tmax, visible=0)
c.setNumber('Dyna/time [s]', value=time)
c.setNumber('Solu/phi', value=phi)
c.addNumberChoice('Solu/phi', phi)
c.setNumber('Solu/theta', value=theta)
c.addNumberChoice('Solu/theta', theta)
c.setNumber('Solu/phi dot', value=phi_dot)
c.addNumberChoice('Solu/phi dot', phi_dot)
c.setNumber('Solu/theta dot', value=theta_dot)
c.addNumberChoice('Solu/theta dot', theta_dot)
# ask Gmsh to refresh
c.setString('Gmsh/Action', value='refresh')
# stop if we are asked to (by Gmsh)
if(c.getString(c.name + '/Action') == 'stop'):
break;
exportMsh(l1, l2)
exportIter(iter, time, x1, y1+l1, x2, y2+l1+l2)
c.mergeFile(onelab.path(__file__, 'pend.msh'))
iter += 1
c.setNumber(c.name + '/Progress', value=0)
> thanks for all the splendid work!
>
> Nigel
>
>
>
> On 07 May 2013, at 00:55, Nigel Nunn <nnnunnn at gmail.com> wrote:
>
> > Hi Gmsh,
> >
> > Sometime before the onelab update, I used GmshClient (from old
> > GmshSocket.h) to drive our family of mpi gpu accelerated solvers
> > (discontinuous Galerkin). I hooked up a pause button to manage the
> > mpi fleet, and a few parameters for adjusting runtime results passed
> > back to Gmsh.
> >
> > After looking at the classes in [gmsh/contrib/onelab] and
> > [gmsh/projects/onelab, and the way getdp uses onelab, I am not sure
> > how to begin upgrading from GmshSocket to onelab. Can someone please
> > suggest which of the classes derived from onelab client would do?
> > First stage is to reproduce what we had with GmshClient : get Gmsh to
> > query our solver (mpi proc [0]) for parameters, then launch, pause and
> > stop a simulation using 4 gpus on a single node (dual Xeon).
> >
> > runGmshClient() from [gmsh/Common/onelabUtils.cpp] sounds promising,
> > but which client?
> >
>
> Hi Nigel - Have a look at utils/solvers/c++ and utils/solvers/python in SVN.
>
>
> > thanks for any help!
> > Nigel
> >
> > _______________________________________________
> > gmsh mailing list
> > gmsh at geuz.org
> > http://www.geuz.org/mailman/listinfo/gmsh
>
> --
> Prof. Christophe Geuzaine
> University of Liege, Electrical Engineering and Computer Science
>
> http://www.montefiore.ulg.ac.be/~geuzaine
>
--
Prof. Christophe Geuzaine
University of Liege, Electrical Engineering and Computer Science
http://www.montefiore.ulg.ac.be/~geuzaine
_______________________________________________
gmsh mailing list
[email protected]
http://www.geuz.org/mailman/listinfo/gmsh