From f0543bb830576274b64734db11d186601a42cd81 Mon Sep 17 00:00:00 2001
From: David Seus <david.seus@ians.uni-stuttgart.de>
Date: Thu, 12 Sep 2019 14:56:26 +0200
Subject: [PATCH] fix not evaluating sources and bc terms at target timestep

---
 LDDsimulation/LDDsimulation.py | 33 ++++++++++++++++-----------------
 1 file changed, 16 insertions(+), 17 deletions(-)

diff --git a/LDDsimulation/LDDsimulation.py b/LDDsimulation/LDDsimulation.py
index e9d6057..a141313 100644
--- a/LDDsimulation/LDDsimulation.py
+++ b/LDDsimulation/LDDsimulation.py
@@ -67,8 +67,8 @@ class LDDsimulation(object):
         # df.parameters['std_out_all_processes'] = False
 
 
-        df.set_log_level(df.LogLevel.WARNING)
-        # df.set_log_level(df.LogLevel.INFO)
+        # df.set_log_level(df.LogLevel.WARNING)
+        df.set_log_level(df.LogLevel.INFO)
         # df.set_log_level(df.LogLevel.DEBUG)
 
         # CRITICAL  = 50, // errors that may lead to data corruption and suchlike
@@ -364,7 +364,11 @@ class LDDsimulation(object):
             print("LDD simulation use case: {}".format(self.use_case))
             print(f"entering timestep ",
                   "{}".format(self.timestep_num),
-                  "at time t = "+ "{number:.{digits}f}".format(number = self.t, digits = 4))
+                  "at time t = "+ "{number:.{digits}f}".format(number = self.t, digits = 6))
+            # self.t is now set to the new target time. self.t will be used
+            # to update the dirichlet and source terms so that we actually solve
+            # an iplicit euler.
+            self.t += self.timestep_size
 
             # check if the solver should be analised or not.
             if np.isin(self.timestep_num, analyse_solver_at_timesteps, assume_unique=True):
@@ -377,7 +381,6 @@ class LDDsimulation(object):
                                analyse_timestep=False,
                                analyse_condition=False)
 
-            self.t += self.timestep_size
             # calculate spacetime errornorms for self.output.
             space_errornorm = self._spacetime_errornorm_calc_step()
 
@@ -487,7 +490,7 @@ class LDDsimulation(object):
                     if self.write2file['subsequent_errors']:
                         subsequent_error_filename = self.output_dir\
                             +self.output_filename_parameter_part[sd_index]\
-                            +"subsequent_iteration_errors" +"_at_time"+\
+                            +"subsequent_iteration_errors" +"_at_timestep"+\
                             "{number}".format(number=self.timestep_num) +".csv"  #"{number:.{digits}f}".format(number=time, digits=4)
                         self.write_subsequent_errors_to_csv(
                             filename = subsequent_error_filename, #
@@ -515,7 +518,10 @@ class LDDsimulation(object):
                 if analyse_timestep and self.write2file['L_iterations_per_timestep']:
                     subdomain.write_solution_to_xdmf(#
                         file = solution_over_iteration_within_timestep[sd_index], #
-                        time = time,#
+                        # time has been set to the target timestep by the solver.
+                        # the timeste pat wich we are currently is one timestep_size
+                        # less than that.
+                        time = time-self.timestep_size,#
                         write_iter_for_fixed_time = True,
                         )
 
@@ -573,6 +579,8 @@ class LDDsimulation(object):
         """
         # in case no time is given, use the time of the class.
         if time is None:
+            # remember:  this has been set to the target timestep by the solver.
+            # the timestep we are calculating the solution for.
             time = self.t
 
         if analyse_timestep:
@@ -588,8 +596,8 @@ class LDDsimulation(object):
             # given.
             if analyse_timestep:
                 filename = self.output_dir+self.output_filename_parameter_part[ind]\
-                + "solution_iterations_at_t"\
-                + "{number:.{digits}f}".format(number=time, digits=2) +".xdmf"
+                + "solution_iterations_at_timestep"\
+                + "{number}".format(number=self.timestep_num) +".xdmf"
                 solution_over_iteration_within_timestep.update( #
                     {ind: SolutionFile(self._mpi_communicator, filename)}
                     )
@@ -677,21 +685,12 @@ class LDDsimulation(object):
                 for index, boundary in enumerate(subdomain.outer_boundary):
                     self.outerBC[subdomain_index][index][phase].apply(form_assembled, rhs_assembled)
 
-            if debug and subdomain.mesh.num_cells() < 36:
-                print("\nSystem after applying outer boundary conditions:")
-                # print(f"phase = {phase}: form_assembled:\n", form_assembled.array())
-                print(f"phase = {phase}: rhs_assembled:\n", rhs_assembled.get_local())
-                print("\npressure before solver:\n", subdomain.pressure[phase].vector().get_local())
-
             linear_solver = subdomain.linear_solver
             if linear_solver is None:
                 df.solve(form_assembled, subdomain.pressure[phase].vector(), rhs_assembled, self.solver, self.preconditioner)
             else:
                 linear_solver.solve(form_assembled, subdomain.pressure[phase].vector(), rhs_assembled)
 
-            if debug and subdomain.mesh.num_cells() < 36:
-                print("\npressure after solver:\n", subdomain.pressure[phase].vector().get_local())
-
         return condition_number
 
 
-- 
GitLab