[cig-commits] r4128 - in mc/3D/CitcomS/trunk: CitcomS
CitcomS/Solver module
tan2 at geodynamics.org
tan2 at geodynamics.org
Mon Jul 31 17:23:12 PDT 2006
Author: tan2
Date: 2006-07-31 17:23:11 -0700 (Mon, 31 Jul 2006)
New Revision: 4128
Modified:
mc/3D/CitcomS/trunk/CitcomS/Controller.py
mc/3D/CitcomS/trunk/CitcomS/Solver/Solver.py
mc/3D/CitcomS/trunk/module/bindings.cc
mc/3D/CitcomS/trunk/module/misc.cc
mc/3D/CitcomS/trunk/module/misc.h
Log:
Completely fixed issue35 (inconsistent times) and related problems
* t, dt, step are modified only in the C code. Their python counterparts are read-only
* Changed the ancestor of the Controller from Pyre's SimulationController to Pyre's Component, as the SimulationController hinders the use of read-only properties
* Changed the ancestor of the Solver from Pyre's Solver to Pyre's Component, as Pyre's Solver hinders the use of read-only properties
Modified: mc/3D/CitcomS/trunk/CitcomS/Controller.py
===================================================================
--- mc/3D/CitcomS/trunk/CitcomS/Controller.py 2006-07-31 23:07:21 UTC (rev 4127)
+++ mc/3D/CitcomS/trunk/CitcomS/Controller.py 2006-08-01 00:23:11 UTC (rev 4128)
@@ -31,24 +31,27 @@
return Controller(name, facility)
-from pyre.simulations.SimulationController import SimulationController
+from pyre.components.Component import Component
import journal
-class Controller(SimulationController):
+class Controller(Component):
def __init__(self, name, facility):
- SimulationController.__init__(self, name, facility)
+ Component.__init__(self, name, facility)
- self.step = 0
- self.clock = 0.0
- self.dt = 0.0
self.done = False
self.solver = None
return
+ # Set these attributes as read-only properties, so that they are
+ # always in accordance with their counterparts in the C code
+ clock = property(lambda self: self.solver.t)
+ dt = property(lambda self: self.solver.dt)
+ step = property(lambda self: self.solver.step)
+
def initialize(self, app):
self.solver = app.solver
self.solver.initialize(app)
@@ -70,7 +73,6 @@
"""explicit time loop"""
if (self.step + 1) >= steps:
- self.step += 1
self.endSimulation()
return
@@ -79,20 +81,12 @@
# notify solvers we are starting a new timestep
self.startTimestep()
- # synchronize boundary information
- #self.applyBoundaryConditions()
-
# compute an acceptable timestep
- self.dt = self.stableTimestep()
+ dt = self.stableTimestep()
# advance
- self.advance(self.dt)
+ self.advance(dt)
- # update simulation clock and step number
- from CitcomSLib import return_times
- self.clock, self.dt = return_times(self.solver.all_variables)
- self.step += 1
-
# notify solver we finished a timestep
self.endTimestep(totalTime, steps)
@@ -111,7 +105,21 @@
return
+ def startTimestep(self):
+ self.solver.newStep()
+ return
+
+ def stableTimestep(self):
+ dt = self.solver.stableTimestep()
+ return dt
+
+
+ def advance(self, dt):
+ self.solver.advance(dt)
+ return
+
+
def endTimestep(self, totalTime, steps):
# are we done?
if steps and self.step >= steps:
@@ -120,21 +128,26 @@
self.done = True
# solver can terminate time marching by returning True
- self.done = self.solver.endTimestep(self.clock, self.step, self.done)
+ self.done = self.solver.endTimestep(self.done)
return
def endSimulation(self):
- self.solver.endSimulation(self.step)
+ self.solver.endSimulation()
return
def save(self):
- step = self.step
- self.solver.save(step, self.inventory.monitoringFrequency)
+ self.solver.save(self.inventory.monitoringFrequency)
return
+
+ class Inventory(Component.Inventory):
+
+ import pyre.inventory
+
+ monitoringFrequency = pyre.inventory.int("monitoringFrequency", default=100)
Modified: mc/3D/CitcomS/trunk/CitcomS/Solver/Solver.py
===================================================================
--- mc/3D/CitcomS/trunk/CitcomS/Solver/Solver.py 2006-07-31 23:07:21 UTC (rev 4127)
+++ mc/3D/CitcomS/trunk/CitcomS/Solver/Solver.py 2006-08-01 00:23:11 UTC (rev 4128)
@@ -26,16 +26,16 @@
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
-from CitcomSLib import CPU_time, output
-from pyre.simulations.Solver import Solver as BaseSolver
+from CitcomSLib import CPU_time, output, return_dt, return_t, return_step
+from pyre.components.Component import Component
import journal
-class Solver(BaseSolver):
+class Solver(Component):
def __init__(self, name, facility="solver"):
- BaseSolver.__init__(self, name, facility)
+ Component.__init__(self, name, facility)
self.all_variables = None
self.communicator = None
@@ -49,13 +49,32 @@
return
+ def _dt(self):
+ '''get the value of dt from the C code'''
+ return return_dt(self.all_variables)
+
+ def _t(self):
+ '''get the value of t from the C code'''
+ return return_t(self.all_variables)
+
+
+ def _step(self):
+ '''get the value of step from the C code'''
+ return return_step(self.all_variables)
+
+
+ # Set these attributes as read-only properties, so that they are
+ # always in accordance with their counterparts in the C code
+ t = property(_t)
+ dt = property(_dt)
+ step = property(_step)
+
+
def initialize(self, application):
from CitcomSLib import citcom_init, global_default_values, set_signal
- BaseSolver.initialize(self, application)
-
comm = application.solverCommunicator
all_variables = citcom_init(comm.handle())
self.communicator = comm
@@ -104,10 +123,7 @@
return
-
def launch(self, application):
- BaseSolver.launch(self, application)
-
mesher = self.inventory.mesher
mesher.setup()
@@ -170,8 +186,7 @@
- def newStep(self, t, step):
- BaseSolver.newStep(self, t, step)
+ def newStep(self):
if self.coupler:
self.coupler.newStep()
return
@@ -179,7 +194,6 @@
#def applyBoundaryConditions(self):
- #BaseSolver.applyBoundaryConditions(self)
#if self.coupler:
# self.coupler.applyBoundaryConditions()
#return
@@ -194,14 +208,11 @@
# negotiate with other solver(s)
dt = self.coupler.stableTimestep(dt)
- BaseSolver.stableTimestep(self, dt)
return dt
def advance(self, dt):
- BaseSolver.advance(self, dt)
-
self.solveTemperature(dt)
self.solveVelocities()
self.solveAdditional()
@@ -210,28 +221,25 @@
- def endTimestep(self, t, steps, done):
- BaseSolver.endTimestep(self, t)
-
+ def endTimestep(self, done):
self.inventory.visc.updateMaterial()
self.inventory.bc.updatePlateVelocity()
if self.coupler:
- done = self.coupler.endTimestep(steps, done)
+ done = self.coupler.endTimestep(self.step, done)
return done
- def endSimulation(self, step):
- BaseSolver.endSimulation(self, step, self.t)
-
+ def endSimulation(self):
+ step = self.step
total_cpu_time = CPU_time() - self.start_cpu_time
rank = self.communicator.rank
if not rank:
import sys
print >> sys.stderr, "Average cpu time taken for velocity step = %f" % (
- total_cpu_time / step )
+ total_cpu_time / (step+1) )
if self.coupler:
output(self.all_variables, step)
@@ -241,7 +249,9 @@
- def save(self, step, monitoringFrequency):
+ def save(self, monitoringFrequency):
+ step = self.step
+
# for non-coupled run, output spacing is 'monitoringFrequency'
if not (step % monitoringFrequency):
output(self.all_variables, step)
@@ -275,7 +285,7 @@
- class Inventory(BaseSolver.Inventory):
+ class Inventory(Component.Inventory):
import pyre.inventory
Modified: mc/3D/CitcomS/trunk/module/bindings.cc
===================================================================
--- mc/3D/CitcomS/trunk/module/bindings.cc 2006-07-31 23:07:21 UTC (rev 4127)
+++ mc/3D/CitcomS/trunk/module/bindings.cc 2006-08-01 00:23:11 UTC (rev 4128)
@@ -122,11 +122,21 @@
METH_VARARGS,
pyCitcom_Visc_update_material__doc__},
- {pyCitcom_return_times__name__,
- pyCitcom_return_times,
+ {pyCitcom_return_dt__name__,
+ pyCitcom_return_dt,
METH_VARARGS,
- pyCitcom_return_times__doc__},
+ pyCitcom_return_dt__doc__},
+ {pyCitcom_return_step__name__,
+ pyCitcom_return_step,
+ METH_VARARGS,
+ pyCitcom_return_step__doc__},
+
+ {pyCitcom_return_t__name__,
+ pyCitcom_return_t,
+ METH_VARARGS,
+ pyCitcom_return_t__doc__},
+
// from advdiffu.h
{pyCitcom_PG_timestep_init__name__,
Modified: mc/3D/CitcomS/trunk/module/misc.cc
===================================================================
--- mc/3D/CitcomS/trunk/module/misc.cc 2006-07-31 23:07:21 UTC (rev 4127)
+++ mc/3D/CitcomS/trunk/module/misc.cc 2006-08-01 00:23:11 UTC (rev 4128)
@@ -142,7 +142,7 @@
return PyErr_Format(pyCitcom_runtimeError,
"%s: 'mpi::Communicator *' argument is null",
pyCitcom_citcom_init__name__);
-
+
MPI_Comm world = comm->handle();
// Allocate global pointer E
@@ -308,22 +308,54 @@
}
-char pyCitcom_return_times__doc__[] = "";
-char pyCitcom_return_times__name__[] = "return_times";
+char pyCitcom_return_dt__doc__[] = "";
+char pyCitcom_return_dt__name__[] = "return_dt";
-PyObject * pyCitcom_return_times(PyObject *self, PyObject *args)
+PyObject * pyCitcom_return_dt(PyObject *self, PyObject *args)
{
PyObject *obj;
- if (!PyArg_ParseTuple(args, "O:return_times", &obj))
+ if (!PyArg_ParseTuple(args, "O:return_dt", &obj))
return NULL;
struct All_variables* E = static_cast<struct All_variables*>(PyCObject_AsVoidPtr(obj));
- return Py_BuildValue("ff", E->monitor.elapsed_time, E->advection.timestep);
+ return Py_BuildValue("f", E->advection.timestep);
}
+char pyCitcom_return_step__doc__[] = "";
+char pyCitcom_return_step__name__[] = "return_step";
+
+PyObject * pyCitcom_return_step(PyObject *self, PyObject *args)
+{
+ PyObject *obj;
+
+ if (!PyArg_ParseTuple(args, "O:return_step", &obj))
+ return NULL;
+
+ struct All_variables* E = static_cast<struct All_variables*>(PyCObject_AsVoidPtr(obj));
+
+ return Py_BuildValue("i", E->advection.timesteps);
+}
+
+
+char pyCitcom_return_t__doc__[] = "";
+char pyCitcom_return_t__name__[] = "return_t";
+
+PyObject * pyCitcom_return_t(PyObject *self, PyObject *args)
+{
+ PyObject *obj;
+
+ if (!PyArg_ParseTuple(args, "O:return_t", &obj))
+ return NULL;
+
+ struct All_variables* E = static_cast<struct All_variables*>(PyCObject_AsVoidPtr(obj));
+
+ return Py_BuildValue("f", E->monitor.elapsed_time);
+}
+
+
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
Modified: mc/3D/CitcomS/trunk/module/misc.h
===================================================================
--- mc/3D/CitcomS/trunk/module/misc.h 2006-07-31 23:07:21 UTC (rev 4127)
+++ mc/3D/CitcomS/trunk/module/misc.h 2006-08-01 00:23:11 UTC (rev 4128)
@@ -111,12 +111,24 @@
PyObject * pyCitcom_Visc_update_material(PyObject *, PyObject *);
-extern char pyCitcom_return_times__name__[];
-extern char pyCitcom_return_times__doc__[];
+extern char pyCitcom_return_dt__name__[];
+extern char pyCitcom_return_dt__doc__[];
extern "C"
-PyObject * pyCitcom_return_times(PyObject *, PyObject *);
+PyObject * pyCitcom_return_dt(PyObject *, PyObject *);
+extern char pyCitcom_return_step__name__[];
+extern char pyCitcom_return_step__doc__[];
+extern "C"
+PyObject * pyCitcom_return_step(PyObject *, PyObject *);
+
+
+extern char pyCitcom_return_t__name__[];
+extern char pyCitcom_return_t__doc__[];
+extern "C"
+PyObject * pyCitcom_return_t(PyObject *, PyObject *);
+
+
#endif
// version
More information about the cig-commits
mailing list