← Back to team overview

dolfin team mailing list archive

[noreply@xxxxxxxxxxxxx: [Branch ~ffc-core/ffc/error-control] Rev 1534: Generate code for GoalFunctional. We can now automatically estimate]

 

Marie is making good progress on porting the automated adaptivity to
C++!

The experimental branch of FFC is now generating auxiliary code for
error estimation and adaptivity.

--
Anders
--- Begin Message ---
------------------------------------------------------------
revno: 1534
committer: Marie E. Rognes <meg@xxxxxxxxx>
branch nick: ffc-error-control
timestamp: Thu 2010-09-16 23:22:22 +0200
message:
  Generate code for GoalFunctional. We can now automatically estimate
  the error and compute error indicators for linear variational problems
  without boundary conditions!
  
  Notes:
  
  (1) The ffc code generation is very, very ugly.
  (2) We are not yet computing facet residuals (Marie will fix, should be easy)
  (3) We are not  handling boundary conditions (Marie will fix, should be easy)
  (4) We should start discussing TrialFunctions.
  (5) Anders should start thinking about how to update to new meshes, so
  that actual adaptivity can happen.
modified:
  ffc/errorcontrol.py
  ffc/errorcontrolwrappers.py


--
lp:~ffc-core/ffc/error-control
https://code.launchpad.net/~ffc-core/ffc/error-control

Your team FFC Core Team is subscribed to branch lp:~ffc-core/ffc/error-control.
To unsubscribe from this branch go to https://code.launchpad.net/~ffc-core/ffc/error-control/+edit-subscription
=== modified file 'ffc/errorcontrol.py'
--- ffc/errorcontrol.py	2010-09-16 13:17:28 +0000
+++ ffc/errorcontrol.py	2010-09-16 21:22:22 +0000
@@ -209,7 +209,32 @@
 
     return (forms, names)
 
-def write_code(prefix, code):
+def hack(lines, prefix):
+
+    code = "".join(lines)
+
+    (before, after) = code.split("class Form_8:")
+
+    print "after = ", after
+
+    after = after.replace(" public dolfin::Form",
+                          "class Form_8: public dolfin::GoalFunctional")
+    after = after.replace("dolfin::Form", "dolfin::GoalFunctional")
+
+    updating = """
+    virtual void update_ec(const dolfin::Form& a, const dolfin::Form& L)
+    {
+      // Update self
+      ec.reset(new %s::ErrorControl(a, L, *this));
+    }
+    };
+    """ % prefix
+
+    after = after.replace("};", updating)
+
+    return (before, after)
+
+def write_code(prefix, ec_code, typedefs):
 
     # Append code to above file (must fix #endif)
     file = open(prefix + ".h", "r")
@@ -218,10 +243,13 @@
     file.close()
 
     file = open(prefix + ".h", "w")
-    file.write("".join(lines))
-    file.write(code)
+    # meg: Not proud moment. No need for yelling.
+    (before, after) = hack(lines, prefix)
+    file.write(before)
+    file.write(ec_code)
+    file.write(after)
+    file.write(typedefs)
     file.write("}\n#endif\n");
-
     file.close()
 
 
@@ -246,15 +274,15 @@
     compile_form(all_forms, all_names, prefix, parameters)
 
     # Generate error_control DOLFIN wrapper
-    code = generate_error_control_wrapper(prefix)
+    (ec_code, typedefs) = generate_error_control_wrapper(prefix)
 
     print "-"*80
     print "- Wrapper code - "
     print "-"*80
-    print code
+    print ec_code
     print "-"*80
 
-    write_code(prefix, code)
+    write_code(prefix, ec_code, typedefs)
 
     return 0
 

=== modified file 'ffc/errorcontrolwrappers.py'
--- ffc/errorcontrolwrappers.py	2010-09-16 15:52:24 +0000
+++ ffc/errorcontrolwrappers.py	2010-09-16 21:22:22 +0000
@@ -2,13 +2,15 @@
 __copyright__ = "Copyright (C) 2010 " + __author__
 __license__  = "GNU LGPL version 3 or any later version"
 
-base = """
+
+error_control_base = """
   class %(class_name)s: public dolfin::ErrorControl
   {
 
    public:
 
-   %(class_name)s(const dolfin::Form& a, const dolfin::Form& L, dolfin::Form& M)
+   %(class_name)s(const dolfin::Form& a, const dolfin::Form& L,
+                  dolfin::GoalFunctional& M)
       : dolfin::%(class_name)s(a, L, M)
 
    {
@@ -62,12 +64,14 @@
 
   };
 
+"""
+
+typedefs = """
   typedef %(a)s BilinearForm;
   typedef %(L)s LinearForm;
   typedef %(M)s GoalFunctional;
   typedef %(a)s::TestSpace TestSpace;
   typedef %(a)s::TrialSpace TrialSpace;
-
 """
 
 def generate_attach_snippet(to, from_form):
@@ -95,24 +99,27 @@
     L_R_T_snippet = generate_attach_snippet("_L_R_T", "a") + "\n\t" + \
                     generate_attach_snippet("_L_R_T", "L")
 
-    code = base % {"class_name": "ErrorControl",
-                   "a_star": "Form_%d" % (N),
-                   "L_star": "Form_%d" % (N+1),
-                   "E_space": "CoefficientSpace_%s" % "Ez_h",
-                   "residual": "Form_%d" % (N+2),
-                   "DGk_space": "Form_%d::TestSpace" % (N+3),
-                   "a_R_T": "Form_%d" % (N+3),
-                   "L_R_T": "Form_%d" % (N+4),
-                   "DG0_space": "Form_%d::TestSpace" % (N+5),
-                   "Bubble_space": "Form_%d::CoefficientSpace_%s" % (N+3, "b_T"),
-                   "eta_T": "Form_%d" % (N+5),
-                   "a": "Form_%d" %(N + d),
-                   "L": "Form_%d" %(N + d+1),
-                   "M": "Form_%d" %(N + d+2),
-                   "attach_a_star": generate_attach_snippet("_a_star", "a"),
-                   "attach_L_star": generate_attach_snippet("_L_star", "M"),
-                   "attach_residual": residual_snippet,
-                   "attach_L_R_T": L_R_T_snippet,
-                   }
-
-    return code
+    maps = {"class_name": "ErrorControl",
+              "a_star": "Form_%d" % (N),
+              "L_star": "Form_%d" % (N+1),
+              "E_space": "CoefficientSpace_%s" % "Ez_h",
+              "residual": "Form_%d" % (N+2),
+              "DGk_space": "Form_%d::TestSpace" % (N+3),
+              "a_R_T": "Form_%d" % (N+3),
+              "L_R_T": "Form_%d" % (N+4),
+              "DG0_space": "Form_%d::TestSpace" % (N+5),
+              "Bubble_space": "Form_%d::CoefficientSpace_%s" % (N+3, "b_T"),
+              "eta_T": "Form_%d" % (N+5),
+              "a": "Form_%d" %(N + d),
+              "L": "Form_%d" %(N + d+1),
+              "M": "Form_%d" %(N + d+2),
+              "attach_a_star": generate_attach_snippet("_a_star", "a"),
+              "attach_L_star": generate_attach_snippet("_L_star", "M"),
+              "attach_residual": residual_snippet,
+              "attach_L_R_T": L_R_T_snippet
+              }
+
+    code = error_control_base % maps
+    defs = typedefs % maps
+
+    return (code, defs)


--- End Message ---

Follow ups