From 227175fda59246739ecca92e8a472172d63964b7 Mon Sep 17 00:00:00 2001
From: Martin Genet <martin.genet@polytechnique.edu>
Date: Fri, 11 Jan 2019 12:30:12 +0100
Subject: [PATCH] first attempt at loading initial displacement

---
 ImageIterator.py | 8 +++++++-
 fedic2.py        | 6 +++++-
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/ImageIterator.py b/ImageIterator.py
index 08dd004..749e726 100644
--- a/ImageIterator.py
+++ b/ImageIterator.py
@@ -34,6 +34,7 @@ class ImageIterator():
 
         self.working_folder           = parameters["working_folder"]           if ("working_folder"           in parameters) else "."
         self.working_basename         = parameters["working_basename"]         if ("working_basename"         in parameters) else "sol"
+        self.initialize_U_from_file   = parameters["initialize_U_from_file"]   if ("initialize_U_from_file"   in parameters) else False
         self.initialize_DU_with_DUold = parameters["initialize_DU_with_DUold"] if ("initialize_DU_with_DUold" in parameters) else False
 
 
@@ -94,7 +95,12 @@ class ImageIterator():
                     k_frame_old = k_frame+1
                 #self.printer.print_var("k_frame_old",k_frame_old,-1)
 
-                if (self.initialize_DU_with_DUold):
+                if (self.initialize_U_from_file):
+                    xdmf_filename = self.initialize_U_from_file+"_"+str(k_frame).zfill(2)+".xdmf"
+                    xdmf_file = dolfin.XDMFFile(xdmf_filename)
+                    xdmf_file.read(self.problem.U, "U")
+                    xdmf_file.close()
+                elif (self.initialize_DU_with_DUold):
                     self.problem.U.vector().axpy(1., self.problem.DUold.vector())
 
                 self.problem.call_before_solve(
diff --git a/fedic2.py b/fedic2.py
index ac4143c..cc79220 100644
--- a/fedic2.py
+++ b/fedic2.py
@@ -41,6 +41,7 @@ def fedic2(
         residual_type="Iref", # Iref, Iold, Iref-then-Iold
         relax_type="gss", # constant, aitken, gss
         relax_init=1.0,
+        initialize_U_from_file=0,
         initialize_DU_with_DUold=0,
         tol_res=None,
         tol_res_rel=None,
@@ -59,6 +60,8 @@ def fedic2(
         "residual_type must be \"Iref\". Aborting."
     assert (relax_init == 1.),\
         "relax_init must be 1. Aborting."
+    assert (not ((initialize_U_from_file) and (initialize_DU_with_DUold))),\
+        "Cannot initialize U from file and DU with DUold together. Aborting."
     assert (tol_res is None),\
         "tol_res is deprecated. Aborting."
     assert (tol_im is None),\
@@ -135,6 +138,7 @@ def fedic2(
         parameters={
             "working_folder":working_folder,
             "working_basename":working_basename,
-            "initialize_DU_with_DUold":initialize_DU_with_DUold})
+            "initialize_DU_with_DUold":initialize_DU_with_DUold,
+            "initialize_U_from_file":initialize_U_from_file})
 
     image_iterator.iterate()
-- 
GitLab