Commit 3460c69a authored by Philippe Delandmeter's avatar Philippe Delandmeter
Browse files

flag to evaluate points at every time step or not

compute mass and evaluate points are computed together
parent c98a6fc6
Pipeline #1099 passed with stage
in 31 minutes and 37 seconds
......@@ -744,7 +744,7 @@ class ShallowWaterTracer2d:
class Loop:
"""Temporal solver"""
def __init__(self, maximum_time_step=3600, export_time=3600, path="./output"):
def __init__(self, maximum_time_step=3600, export_time=3600, path="./output", evaluateEveryTimeStep=False):
"""keyword arguments:
* maximum_time_step
......@@ -755,6 +755,8 @@ class Loop:
time step for results exportation [in seconds] (default: 3600 s)
* path
path to the output directory [string] (default: ./output)
* evaluateEveryTimeStep
flag to define if quantities (export_value_at_points and compute_mass) are evaluated every time step (True) or only at export time (False) (default: False)
"""
self._max_dt = float(maximum_time_step)
self._export_time = float(export_time)
......@@ -790,6 +792,7 @@ class Loop:
self._index_exporter_full = 1
self._n_iter = 1
self._index_export = 1
self._evaluateEveryTimeStep = evaluateEveryTimeStep
def add_equation(self, equation):
"""Add equation to the temporal solver
......@@ -1077,17 +1080,32 @@ class Loop:
for e in self._export_dofs :
if self._time > e[1]-self._eps and self._time < e[2]+self._eps:
e[0].exportIdx(self._index_export, self._time - e[1])
if self._index_sw2d_eq > -1 and self._equations[self._index_sw2d_eq]._wetting_drying is not None:
self._equations[self._index_sw2d_eq]._domain._groups.exportFunctionMsh(self._depth, self._output_directory + "/depth/depth-%06d" % self._index_export, self._time, self._index_export, "depth", self._equations[self._index_sw2d_eq]._solution)
self._equations[self._index_sw2d_eq]._domain._groups.exportFunctionMsh(self._bathy, self._output_directory + "/bathy/bathy-%06d" % self._index_export, self._time, self._index_export, "bathy", self._equations[self._index_sw2d_eq]._solution)
for eq in self._export_on_structured_grid:
if eq._name == "sw2d":
self._exporter_structured_grid.exportNetCDFVectorXY(eq._solution, self._structured_file_name + str(self._index_export) + '.nc', self._time, True, 0, 1, 2);
else:
self._exporter_structured_grid.exportNetCDFScalarXY(eq._solution, self._structured_file_name + str(self._index_export) + '.nc', self._time, True, 0, "[-]")
if (dgpy.Msg.GetCommRank() == 0):
time_struct = slim_private.time.gmtime(self._time)
time_print = str(time_struct[0])+'/'+str(time_struct[1]).zfill(2)+'/'+str(time_struct[2]).zfill(2)+' '+str(time_struct[3]).zfill(2)+':'+str(time_struct[4]).zfill(2)+':'+str(time_struct[5]).zfill(2)
slim_private._print("EXPORT "+str(self._index_export)+'/'+str(self._number_of_export)+", Time "+time_print+", CPU Time "+slim_private._cpu_time(slim_private.time.time() - self._tic))
self._index_export += 1
def evaluatePoints(self):
for eq in self._equations:
if eq._evaluator is not None:
res = dgpy.fullMatrixDouble(1,eq._equation.getNbFields())
str_sol = str(self._time)+","
str_sol = ('%+1.10e' % self._time)+","
x = eq._evaluator_points_x
y = eq._evaluator_points_y
z = eq._evaluator_points_z
for i in range(len(x)):
eq._evaluator.compute(x[i], y[i], z[i], res)
for j in range(eq._equation.getNbFields()):
str_sol += str(res.get(0,j))+","
str_sol += ('%+1.6e' % res.get(0,j))+", "
if (dgpy.Msg.GetCommRank() == 0):
f = open(eq._evaluator_output_name, 'a')
f.write(str_sol[:-1]+'\n')
......@@ -1098,19 +1116,6 @@ class Loop:
f = open(self._output_directory + '/' + eq._output_mass,"a")
f.write("mass %8.10f time %d\n" % (eq._mass(0,0),self._time-eq._initial_time))
f.close()
if self._index_sw2d_eq > -1 and self._equations[self._index_sw2d_eq]._wetting_drying is not None:
self._equations[self._index_sw2d_eq]._domain._groups.exportFunctionMsh(self._depth, self._output_directory + "/depth/depth-%06d" % self._index_export, self._time, self._index_export, "depth", self._equations[self._index_sw2d_eq]._solution)
self._equations[self._index_sw2d_eq]._domain._groups.exportFunctionMsh(self._bathy, self._output_directory + "/bathy/bathy-%06d" % self._index_export, self._time, self._index_export, "bathy", self._equations[self._index_sw2d_eq]._solution)
for eq in self._export_on_structured_grid:
if eq._name == "sw2d":
self._exporter_structured_grid.exportNetCDFVectorXY(eq._solution, self._structured_file_name + str(self._index_export) + '.nc', self._time, True, 0, 1, 2);
else:
self._exporter_structured_grid.exportNetCDFScalarXY(eq._solution, self._structured_file_name + str(self._index_export) + '.nc', self._time, True, 0, "[-]")
if (dgpy.Msg.GetCommRank() == 0):
time_struct = slim_private.time.gmtime(self._time)
time_print = str(time_struct[0])+'/'+str(time_struct[1]).zfill(2)+'/'+str(time_struct[2]).zfill(2)+' '+str(time_struct[3]).zfill(2)+':'+str(time_struct[4]).zfill(2)+':'+str(time_struct[5]).zfill(2)
slim_private._print("EXPORT "+str(self._index_export)+'/'+str(self._number_of_export)+", Time "+time_print+", CPU Time "+slim_private._cpu_time(slim_private.time.time() - self._tic))
self._index_export += 1
def run(self):
"""Time integration loop with exports
......@@ -1119,8 +1124,12 @@ class Loop:
while self._time < self._max_final_time+self._eps:
self.iterate(_temporal_scheme,self._offline)
self._time += self._dt
if self._evaluateEveryTimeStep:
self.evaluatePoints()
if (self._n_iter % self._n_iter_per_export)==0:
self.export_solutions(_temporal_scheme)
if not self._evaluateEveryTimeStep:
self.evaluatePoints()
self._n_iter += 1
if self._offline:
self._n_iter_offline += 1
......
Supports Markdown
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