Skip to content

Commit f11cc48

Browse files
Merge pull request #295 from Morpho-lang/dev
Morpho v0.6.2 release
2 parents af6505e + 56accee commit f11cc48

File tree

3 files changed

+49
-13
lines changed

3 files changed

+49
-13
lines changed

src/geometry/functional.c

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2119,6 +2119,7 @@ MORPHO_ENDCLASS
21192119
* ---------------------------------------------- */
21202120

21212121
static value linearelasticity_referenceproperty;
2122+
static value linearelasticity_weightbyreferenceproperty;
21222123
static value linearelasticity_poissonproperty;
21232124

21242125
typedef struct {
@@ -3890,6 +3891,7 @@ typedef struct {
38903891
value method; // Method dictionary
38913892
objectmesh *mref; // Reference mesh
38923893
vm *v;
3894+
bool weightbyref; // Use reference mesh for the element
38933895
} integralref;
38943896

38953897
/* ----------------------------------------------
@@ -4206,12 +4208,14 @@ bool integral_prepareref(objectinstance *self, objectmesh *mesh, grade g, object
42064208
bool success=false;
42074209
value func=MORPHO_NIL;
42084210
value mref=MORPHO_NIL;
4211+
value wtbyref=MORPHO_NIL;
42094212
value field=MORPHO_NIL;
42104213
value method=MORPHO_NIL;
42114214
ref->v=NULL;
42124215
ref->nfields=0;
42134216
ref->method=MORPHO_NIL;
42144217
ref->mref=NULL;
4218+
ref->weightbyref=false;
42154219

42164220
if (objectinstance_getpropertyinterned(self, scalarpotential_functionproperty, &func) &&
42174221
MORPHO_ISCALLABLE(func)) {
@@ -4222,6 +4226,9 @@ bool integral_prepareref(objectinstance *self, objectmesh *mesh, grade g, object
42224226
MORPHO_ISMESH(mref)) {
42234227
ref->mref=MORPHO_GETMESH(mref);
42244228
}
4229+
if (objectinstance_getpropertyinterned(self, linearelasticity_weightbyreferenceproperty, &wtbyref)) {
4230+
ref->weightbyref=!morpho_isfalse(wtbyref);
4231+
}
42254232
if (objectinstance_getpropertyinterned(self, functional_methodproperty, &method)) {
42264233
ref->method=method;
42274234
}
@@ -4352,12 +4359,15 @@ value LineIntegral_init(vm *v, int nargs, value *args) {
43524359
int nfixed;
43534360
value method=MORPHO_NIL;
43544361
value mref=MORPHO_NIL;
4362+
value wtbyref=MORPHO_NIL;
43554363

4356-
if (builtin_options(v, nargs, args, &nfixed, 2,
4364+
if (builtin_options(v, nargs, args, &nfixed, 3,
43574365
functional_methodproperty, &method,
4358-
linearelasticity_referenceproperty, &mref)) {
4366+
linearelasticity_referenceproperty, &mref,
4367+
linearelasticity_weightbyreferenceproperty, &wtbyref)) {
43594368
if (MORPHO_ISDICTIONARY(method)) objectinstance_setproperty(self, functional_methodproperty, method);
43604369
if (MORPHO_ISMESH(mref)) objectinstance_setproperty(self, linearelasticity_referenceproperty, mref);
4370+
if (MORPHO_ISBOOL(wtbyref)) objectinstance_setproperty(self, linearelasticity_weightbyreferenceproperty, wtbyref);
43614371
} else {
43624372
morpho_runtimeerror(v, LINEINTEGRAL_ARGS);
43634373
return MORPHO_NIL;
@@ -4447,8 +4457,12 @@ bool areaintegral_integrand(vm *v, objectmesh *mesh, elementid id, int nv, int *
44474457
elref.iref = &iref;
44484458
elref.vertexposn = x;
44494459
elref.qgrad=qgrad;
4450-
4451-
if (!functional_elementsize(v, mesh, MESH_GRADE_AREA, id, nv, vid, &elref.elementsize)) return false;
4460+
4461+
if (iref.weightbyref) {
4462+
if (!functional_elementsize(v, iref.mref, MESH_GRADE_AREA, id, nv, vid, &elref.elementsize)) return false;
4463+
} else {
4464+
if (!functional_elementsize(v, mesh, MESH_GRADE_AREA, id, nv, vid, &elref.elementsize)) return false;
4465+
}
44524466

44534467
iref.v=v;
44544468
for (unsigned int i=0; i<nv; i++) {
@@ -4621,7 +4635,7 @@ MORPHO_ENDCLASS
46214635
* Initialization
46224636
* ********************************************************************** */
46234637

4624-
double ff(double x) {
4638+
/*double ff(double x) {
46254639
return exp(x);
46264640
}
46274641
@@ -4632,7 +4646,7 @@ double dff(double x) {
46324646
void functional_fdtest(void) {
46334647
double h1 = 1e-8;
46344648
4635-
//double xi[] = { -100, -10, -1.0, 0.0, 1e-7, 1e-5, 1e-2, 0.1, 1, 10, 100, 1e100 /* Terminator */};
4649+
//double xi[] = { -100, -10, -1.0, 0.0, 1e-7, 1e-5, 1e-2, 0.1, 1, 10, 100, 1e100 };
46364650
46374651
for (int i=-6; i<3; i++) {
46384652
double x = pow(10.0, (double) i);
@@ -4646,7 +4660,7 @@ void functional_fdtest(void) {
46464660
printf("%g: %g %g %g\n", x, fex, fabs((f1-fex)/fex), fabs((f2-fex)/fex));
46474661
}
46484662
4649-
}
4663+
}*/
46504664

46514665
void functional_initialize(void) {
46524666
fddelta1 = pow(MORPHO_EPS, 1.0/3.0);
@@ -4657,6 +4671,7 @@ void functional_initialize(void) {
46574671
scalarpotential_functionproperty=builtin_internsymbolascstring(SCALARPOTENTIAL_FUNCTION_PROPERTY);
46584672
scalarpotential_gradfunctionproperty=builtin_internsymbolascstring(SCALARPOTENTIAL_GRADFUNCTION_PROPERTY);
46594673
linearelasticity_referenceproperty=builtin_internsymbolascstring(LINEARELASTICITY_REFERENCE_PROPERTY);
4674+
linearelasticity_weightbyreferenceproperty=builtin_internsymbolascstring(LINEARELASTICITY_WTBYREF_PROPERTY);
46604675
linearelasticity_poissonproperty=builtin_internsymbolascstring(LINEARELASTICITY_POISSON_PROPERTY);
46614676
hydrogel_aproperty=builtin_internsymbolascstring(HYDROGEL_A_PROPERTY);
46624677
hydrogel_bproperty=builtin_internsymbolascstring(HYDROGEL_B_PROPERTY);

src/geometry/functional.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919

2020
/* Functional properties */
2121
#define FUNCTIONAL_GRADE_PROPERTY "grade"
22-
#define FUNCTIONAL_ONESIDED_PROPERTY "onesided"
2322
#define FUNCTIONAL_FIELD_PROPERTY "field"
2423
#define SCALARPOTENTIAL_FUNCTION_PROPERTY "function"
2524
#define SCALARPOTENTIAL_GRADFUNCTION_PROPERTY "gradfunction"
2625
#define LINEARELASTICITY_REFERENCE_PROPERTY "reference"
26+
#define LINEARELASTICITY_WTBYREF_PROPERTY "weightByReference"
2727
#define LINEARELASTICITY_POISSON_PROPERTY "poissonratio"
2828
#define HYDROGEL_A_PROPERTY "a"
2929
#define HYDROGEL_B_PROPERTY "b"

test/functionals/areaintegral/cgtensor.morpho

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Cauchy-Green tensor in integrals
2+
13
import constants
24
import meshtools
35

@@ -13,12 +15,31 @@ var mref = m.clone()
1315

1416
m.setvertexmatrix(2*m.vertexmatrix())
1517

16-
var phi = Field(m, fn (x,y) 1+x)
17-
18-
fn integrand(x, f) {
18+
fn integrand(x) {
1919
var cg = cgtensor()
2020
return cg.trace()
2121
}
2222

23-
var a = AreaIntegral(integrand, phi, reference=mref)
24-
print a.total(m) // expect: 6
23+
var a = AreaIntegral(integrand, reference=mref)
24+
print a.total(m) // expect: 6
25+
26+
var b = AreaIntegral(integrand, reference=mref, weightByReference=true)
27+
print b.total(m) // expect: 1.5
28+
29+
// Ensure equivalence of LinearElasticity and AreaIntegral formulations
30+
var nu = 0.3
31+
var mu = 1/2/(1+nu)
32+
var lambda = nu/(1+nu)/(1-2*nu)
33+
34+
fn elasticity(x) {
35+
var cg = cgtensor()
36+
37+
var trCG=cg.trace()
38+
var trCGCG = (cg * cg).trace()
39+
40+
return mu*trCGCG + lambda*trCG^2/2
41+
}
42+
43+
print (LinearElasticity(mref).total(m) -
44+
AreaIntegral(elasticity, reference=mref, weightByReference=true).total(m)) < 1e-8
45+
// expect: true

0 commit comments

Comments
 (0)