[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Getfem-commits] (no subject)
From: |
Yves Renard |
Subject: |
[Getfem-commits] (no subject) |
Date: |
Wed, 28 Feb 2018 14:37:01 -0500 (EST) |
branch: master
commit 0299ac1de147c68460206105c29dc0ef8c7fce5c
Author: Yves Renard <address@hidden>
Date: Wed Feb 28 20:36:44 2018 +0100
adding reg_pos_part a regularised positive part in the assembly language
---
doc/sphinx/source/userdoc/gasm_high.rst | 9 ++++++---
src/getfem_generic_assembly.cc | 17 ++++++++++++++++-
2 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/doc/sphinx/source/userdoc/gasm_high.rst
b/doc/sphinx/source/userdoc/gasm_high.rst
index b59d2ec..e688478 100644
--- a/doc/sphinx/source/userdoc/gasm_high.rst
+++ b/doc/sphinx/source/userdoc/gasm_high.rst
@@ -404,9 +404,12 @@ A certain number of predefined scalar functions can be
used. The exhaustive list
- ``erf(t)``, ``erfc(t)``
- ``sinc(t)`` (the cardinal sine function sin(t)/t)
- - ``Heaviside(t)`` (:math:`0 \mbox{ for } t < 0, 1 \mbox{ for } t \ge 0`),
- ``sign(t)``, ``abs(t)``, ``pos_part(t)`` (:math:`t*H(t)`),
- ``neg_part(t)`` (:math:`-t*H(-t)`), ``max(t, u)``, ``min(t, u)``
+ - ``Heaviside(t)`` (:math:`0 \mbox{ for } t < 0, 1 \mbox{ for } t \ge 0`)
+ - ``sign(t)``
+ - ``abs(t)``
+ - ``pos_part(t)`` (:math:`tH(t)`)
+ - ``reg_pos_part(t, eps)`` (:math:`(t-eps/2-t^2/(2eps))H(t-eps) +
t^2H(t)/(2eps)`)
+ - ``neg_part(t)`` (:math:`-tH(-t)`), ``max(t, u)``, ``min(t, u)``
A scalar function can be applied to a scalar expression, but also to a tensor
one. If is is applied to a tensor expression, is is applied componentwise and
the result is a tensor with the same dimensions. For functions having two
arguments (pow(t,u), min(t,u) ...) if two non-scalar arguments are passed, the
dimension have to be the same. For instance "max([1;2],[0;3])" will return
"[0;3]".
diff --git a/src/getfem_generic_assembly.cc b/src/getfem_generic_assembly.cc
index 081e3e4..17b7f69 100644
--- a/src/getfem_generic_assembly.cc
+++ b/src/getfem_generic_assembly.cc
@@ -2241,6 +2241,14 @@ namespace getfem {
static scalar_type ga_Heaviside(scalar_type t) { return (t >= 0.) ? 1.: 0.; }
static scalar_type ga_pos_part(scalar_type t) { return (t >= 0.) ? t : 0.; }
+ static scalar_type ga_reg_pos_part(scalar_type t, scalar_type eps)
+ { return (t >= eps) ? t-eps/2. : ((t <= 0) ? 0. : t*t/(2.*eps)); }
+ static scalar_type ga_der_reg_pos_part(scalar_type t, scalar_type eps)
+ { return (t >= eps) ? 1. : ((t <= 0) ? 0. : t/eps); }
+ static scalar_type ga_der2_reg_pos_part(scalar_type t, scalar_type eps)
+ { return (t >= eps) ? 0. : ((t <= 0) ? 0. : 1./eps); }
+
+
static scalar_type ga_half_sqr_pos_part(scalar_type t)
{ return (t >= 0.) ? 0.5*t*t : 0.; }
static scalar_type ga_neg_part(scalar_type t) { return (t >= 0.) ? 0. : -t; }
@@ -2548,6 +2556,7 @@ namespace getfem {
PREDEF_FUNCTIONS["sqr"] = ga_predef_function(ga_sqr, 2, "2*t");
PREDEF_FUNCTIONS["pow"] = ga_predef_function(pow, 1, "DER_PDFUNC1_POW",
"DER_PDFUNC2_POW");
+
PREDEF_FUNCTIONS["DER_PDFUNC_SQRT"] =
ga_predef_function(ga_der_sqrt, 2, "-0.25/(t*sqrt(t))");
PREDEF_FUNCTIONS["DER_PDFUNC1_POW"] =
@@ -2649,7 +2658,13 @@ namespace getfem {
= ga_predef_function(ga_neg_part, 1, "DER_PDFUNC_NEG_PART");
PREDEF_FUNCTIONS["half_sqr_neg_part"]
= ga_predef_function(ga_half_sqr_neg_part, 2, "-neg_part(t)");
-
+ PREDEF_FUNCTIONS["reg_pos_part"]
+ = ga_predef_function(ga_reg_pos_part, 1, "DER_REG_POS_PART", "");
+ PREDEF_FUNCTIONS["DER_REG_POS_PART"]
+ = ga_predef_function(ga_der_reg_pos_part, 1, "DER2_REG_POS_PART", "");
+ PREDEF_FUNCTIONS["DER_REG_POS_PART"]
+ = ga_predef_function(ga_der2_reg_pos_part);
+
PREDEF_FUNCTIONS["max"]
= ga_predef_function(ga_max, 1, "DER_PDFUNC1_MAX", "DER_PDFUNC2_MAX");
PREDEF_FUNCTIONS["min"]