Skip to content

Commit 4db2767

Browse files
Add elementid() function
1 parent 7aae0e4 commit 4db2767

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

src/geometry/functional.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3990,6 +3990,17 @@ objectintegralelementref *integral_getelementref(vm *v) {
39903990
return NULL;
39913991
}
39923992

3993+
/* ---------
3994+
* Elementid
3995+
* --------- */
3996+
3997+
static value integral_elementid(vm *v, int nargs, value *args) {
3998+
objectintegralelementref *elref = integral_getelementref(v);
3999+
if (!elref) { morpho_runtimeerror(v, INTEGRAL_SPCLFN, ELEMENTID_FUNCTION); return MORPHO_NIL; }
4000+
4001+
return MORPHO_INTEGER(elref->id);
4002+
}
4003+
39934004
/* --------
39944005
* Tangent
39954006
* -------- */
@@ -4036,6 +4047,7 @@ int normlhandle; // TL storage handle for normal vectors
40364047
/** Evaluates the normal vector */
40374048
void integral_evaluatenormal(vm *v, value *out) {
40384049
objectintegralelementref *elref = integral_getelementref(v);
4050+
40394051
if (!elref) { morpho_runtimeerror(v, INTEGRAL_SPCLFN, NORMAL_FUNCTION); return; }
40404052

40414053
int dim = elref->mesh->dim;
@@ -5040,6 +5052,7 @@ void functional_initialize(void) {
50405052
builtin_addclass(NEMATIC_CLASSNAME, MORPHO_GETCLASSDEFINITION(Nematic), objclass);
50415053
builtin_addclass(NEMATICELECTRIC_CLASSNAME, MORPHO_GETCLASSDEFINITION(NematicElectric), objclass);
50425054

5055+
builtin_addfunction(ELEMENTID_FUNCTION, integral_elementid, BUILTIN_FLAGSEMPTY);
50435056
builtin_addfunction(TANGENT_FUNCTION, integral_tangent, BUILTIN_FLAGSEMPTY);
50445057
builtin_addfunction(NORMAL_FUNCTION, integral_normal, BUILTIN_FLAGSEMPTY);
50455058
builtin_addfunction(GRAD_FUNCTION, integral_gradfn, BUILTIN_FLAGSEMPTY);

src/geometry/functional.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
#define FUNCTIONAL_INTEGRANDFORELEMENT_METHOD "integrandForElement"
5757

5858
/* Special functions that can be used in integrands */
59+
#define ELEMENTID_FUNCTION "elementid"
5960
#define TANGENT_FUNCTION "tangent"
6061
#define NORMAL_FUNCTION "normal"
6162
#define GRAD_FUNCTION "grad"

0 commit comments

Comments
 (0)