Skip to content

Commit c954827

Browse files
committed
Merge branch 'cherry-pick-9811d0fc' into 'master'
replace Deriv by Diff See merge request jschoeberl/ngsolve!632
2 parents e2af34a + 13e3342 commit c954827

7 files changed

+119
-59
lines changed

comp/python_comp.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1718,7 +1718,8 @@ diffop : ngsolve.fem.DifferentialOperator
17181718
for (auto & ci : c1->icfs) faccf->icfs += make_shared<Integral>(fac*(*ci));
17191719
return faccf;
17201720
})
1721-
.def ("Derive", &SumOfIntegrals::Derive)
1721+
.def ("Diff", &SumOfIntegrals::Diff)
1722+
.def ("Derive", &SumOfIntegrals::Diff, "depricated: use 'Diff' instead")
17221723
.def ("Compile", &SumOfIntegrals::Compile, py::arg("realcompile")=false, py::arg("wait")=false)
17231724
;
17241725

fem/coefficient.cpp

Lines changed: 89 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,13 @@ namespace ngfem
107107
}
108108

109109
shared_ptr<CoefficientFunction> CoefficientFunction ::
110-
Derive (const CoefficientFunction * var, shared_ptr<CoefficientFunction> dir) const
110+
Diff (const CoefficientFunction * var, shared_ptr<CoefficientFunction> dir) const
111111
{
112112
throw Exception(string("Deriv not implemented for CF ")+typeid(*this).name());
113113
}
114114

115115
shared_ptr<CoefficientFunction> CoefficientFunctionNoDerivative ::
116-
Derive (const CoefficientFunction * var, shared_ptr<CoefficientFunction> dir) const
116+
Diff (const CoefficientFunction * var, shared_ptr<CoefficientFunction> dir) const
117117
{
118118
if (var == this)
119119
return dir;
@@ -1097,11 +1097,11 @@ class ScaleCoefficientFunction : public T_CoefficientFunction<ScaleCoefficientFu
10971097
values = input[0];
10981098
}
10991099

1100-
shared_ptr<CoefficientFunction> Derive (const CoefficientFunction * var,
1100+
shared_ptr<CoefficientFunction> Diff (const CoefficientFunction * var,
11011101
shared_ptr<CoefficientFunction> dir) const override
11021102
{
11031103
if (this == var) return dir;
1104-
return scal * c1->Derive(var, dir);
1104+
return scal * c1->Diff(var, dir);
11051105
}
11061106

11071107
};
@@ -1295,11 +1295,11 @@ class MultScalVecCoefficientFunction : public T_CoefficientFunction<MultScalVecC
12951295
values(j,i) = in0(0,i) * in1(j,i);
12961296
}
12971297

1298-
shared_ptr<CoefficientFunction> Derive (const CoefficientFunction * var,
1298+
shared_ptr<CoefficientFunction> Diff (const CoefficientFunction * var,
12991299
shared_ptr<CoefficientFunction> dir) const override
13001300
{
13011301
if (this == var) return dir;
1302-
return c1->Derive(var,dir)*c2 + c1 * c2->Derive(var,dir);
1302+
return c1->Diff(var,dir)*c2 + c1 * c2->Diff(var,dir);
13031303
}
13041304

13051305

@@ -1612,12 +1612,12 @@ class T_MultVecVecCoefficientFunction : public T_CoefficientFunction<T_MultVecVe
16121612
result(i,0) = InnerProduct(temp1.Row(i), temp2.Row(i));
16131613
}
16141614

1615-
shared_ptr<CoefficientFunction> Derive (const CoefficientFunction * var,
1615+
shared_ptr<CoefficientFunction> Diff (const CoefficientFunction * var,
16161616
shared_ptr<CoefficientFunction> dir) const override
16171617
{
16181618
if (this == var) return dir;
1619-
return InnerProduct(c1->Derive(var,dir),c2) + InnerProduct(c1,c2->Derive(var,dir));
1620-
// return c1->Derive(var,dir)*c2 + c1 * c2->Derive(var,dir);
1619+
return InnerProduct(c1->Diff(var,dir),c2) + InnerProduct(c1,c2->Diff(var,dir));
1620+
// return c1->Diff(var,dir)*c2 + c1 * c2->Diff(var,dir);
16211621
}
16221622

16231623

@@ -2153,11 +2153,11 @@ class MultMatMatCoefficientFunction : public T_CoefficientFunction<MultMatMatCoe
21532153
}
21542154
}
21552155

2156-
shared_ptr<CoefficientFunction> Derive (const CoefficientFunction * var,
2156+
shared_ptr<CoefficientFunction> Diff (const CoefficientFunction * var,
21572157
shared_ptr<CoefficientFunction> dir) const override
21582158
{
21592159
if (var == this) return dir;
2160-
return c1->Derive(var,dir)*c2 + c1 * c2->Derive(var,dir);
2160+
return c1->Diff(var,dir)*c2 + c1 * c2->Diff(var,dir);
21612161
}
21622162

21632163
};
@@ -2197,6 +2197,10 @@ class MultMatVecCoefficientFunction : public T_CoefficientFunction<MultMatVecCoe
21972197
BASE::DoArchive(ar);
21982198
ar.Shallow(c1).Shallow(c2) & inner_dim;
21992199
}
2200+
2201+
virtual string GetDescription () const override
2202+
{ return "Matrix-Vector multiply"; }
2203+
22002204

22012205
// virtual bool IsComplex() const { return c1->IsComplex() || c2->IsComplex(); }
22022206
// virtual int Dimension() const { return dims[0]; }
@@ -2333,11 +2337,11 @@ class MultMatVecCoefficientFunction : public T_CoefficientFunction<MultMatVecCoe
23332337
}
23342338

23352339

2336-
shared_ptr<CoefficientFunction> Derive (const CoefficientFunction * var,
2340+
shared_ptr<CoefficientFunction> Diff (const CoefficientFunction * var,
23372341
shared_ptr<CoefficientFunction> dir) const override
23382342
{
23392343
if (this == var) return dir;
2340-
return c1->Derive(var,dir)*c2 + c1 * c2->Derive(var,dir);
2344+
return c1->Diff(var,dir)*c2 + c1 * c2->Diff(var,dir);
23412345
}
23422346

23432347

@@ -2367,6 +2371,9 @@ class TransposeCoefficientFunction : public T_CoefficientFunction<TransposeCoeff
23672371
BASE::DoArchive(ar);
23682372
ar.Shallow(c1);
23692373
}
2374+
2375+
virtual string GetDescription () const override
2376+
{ return "Matrix transpose"; }
23702377

23712378
virtual void TraverseTree (const function<void(CoefficientFunction&)> & func) override
23722379
{
@@ -2492,11 +2499,11 @@ class TransposeCoefficientFunction : public T_CoefficientFunction<TransposeCoeff
24922499
values(j*hdims[1]+k, i) = in0(k*hdims[0]+j, i);
24932500
}
24942501

2495-
shared_ptr<CoefficientFunction> Derive (const CoefficientFunction * var,
2502+
shared_ptr<CoefficientFunction> Diff (const CoefficientFunction * var,
24962503
shared_ptr<CoefficientFunction> dir) const override
24972504
{
24982505
if (this == var) return dir;
2499-
return TransposeCF (c1->Derive(var, dir));
2506+
return TransposeCF (c1->Diff(var, dir));
25002507
}
25012508
};
25022509

@@ -2655,11 +2662,11 @@ class InverseCoefficientFunction : public T_CoefficientFunction<InverseCoefficie
26552662
}
26562663
}
26572664

2658-
shared_ptr<CoefficientFunction> Derive (const CoefficientFunction * var,
2665+
shared_ptr<CoefficientFunction> Diff (const CoefficientFunction * var,
26592666
shared_ptr<CoefficientFunction> dir) const override
26602667
{
26612668
if (this == var) return dir;
2662-
return (-1)*InverseCF(c1) * c1->Derive(var,dir) * InverseCF(c1);
2669+
return (-1)*InverseCF(c1) * c1->Diff(var,dir) * InverseCF(c1);
26632670
}
26642671
};
26652672

@@ -2808,11 +2815,11 @@ class DeterminantCoefficientFunction : public T_CoefficientFunction<DeterminantC
28082815
}
28092816
}
28102817

2811-
shared_ptr<CoefficientFunction> Derive (const CoefficientFunction * var,
2818+
shared_ptr<CoefficientFunction> Diff (const CoefficientFunction * var,
28122819
shared_ptr<CoefficientFunction> dir) const override
28132820
{
28142821
if (this == var) return dir;
2815-
return DeterminantCF(c1) * InnerProduct( TransposeCF(InverseCF(c1)), c1->Derive(var,dir) );
2822+
return DeterminantCF(c1) * InnerProduct( TransposeCF(InverseCF(c1)), c1->Diff(var,dir) );
28162823
}
28172824
};
28182825

@@ -2995,11 +3002,11 @@ class SymmetricCoefficientFunction : public T_CoefficientFunction<SymmetricCoeff
29953002

29963003
template <>
29973004
shared_ptr<CoefficientFunction>
2998-
cl_BinaryOpCF<GenericPlus>::Derive(const CoefficientFunction * var,
3005+
cl_BinaryOpCF<GenericPlus>::Diff(const CoefficientFunction * var,
29993006
shared_ptr<CoefficientFunction> dir) const
30003007
{
30013008
if (var == this) return dir;
3002-
return c1->Derive(var,dir) + c2->Derive(var,dir);
3009+
return c1->Diff(var,dir) + c2->Diff(var,dir);
30033010
}
30043011

30053012
shared_ptr<CoefficientFunction> operator+ (shared_ptr<CoefficientFunction> c1, shared_ptr<CoefficientFunction> c2)
@@ -3010,11 +3017,11 @@ shared_ptr<CoefficientFunction> operator+ (shared_ptr<CoefficientFunction> c1, s
30103017

30113018
template <>
30123019
shared_ptr<CoefficientFunction>
3013-
cl_BinaryOpCF<GenericMinus>::Derive(const CoefficientFunction * var,
3020+
cl_BinaryOpCF<GenericMinus>::Diff(const CoefficientFunction * var,
30143021
shared_ptr<CoefficientFunction> dir) const
30153022
{
30163023
if (var == this) return dir;
3017-
return c1->Derive(var,dir) - c2->Derive(var,dir);
3024+
return c1->Diff(var,dir) - c2->Diff(var,dir);
30183025
}
30193026

30203027
shared_ptr<CoefficientFunction> operator- (shared_ptr<CoefficientFunction> c1, shared_ptr<CoefficientFunction> c2)
@@ -3024,20 +3031,20 @@ shared_ptr<CoefficientFunction> operator- (shared_ptr<CoefficientFunction> c1, s
30243031

30253032
template <>
30263033
shared_ptr<CoefficientFunction>
3027-
cl_BinaryOpCF<GenericMult>::Derive(const CoefficientFunction * var,
3034+
cl_BinaryOpCF<GenericMult>::Diff(const CoefficientFunction * var,
30283035
shared_ptr<CoefficientFunction> dir) const
30293036
{
30303037
if (var == this) return dir;
3031-
return c1->Derive(var,dir)*c2 + c1*c2->Derive(var,dir);
3038+
return c1->Diff(var,dir)*c2 + c1*c2->Diff(var,dir);
30323039
}
30333040

30343041
template <>
30353042
shared_ptr<CoefficientFunction>
3036-
cl_BinaryOpCF<GenericDiv>::Derive(const CoefficientFunction * var,
3043+
cl_BinaryOpCF<GenericDiv>::Diff(const CoefficientFunction * var,
30373044
shared_ptr<CoefficientFunction> dir) const
30383045
{
30393046
if (var == this) return dir;
3040-
return (c1->Derive(var,dir)*c2 - c1*c2->Derive(var,dir)) / (c2*c2);
3047+
return (c1->Diff(var,dir)*c2 - c1*c2->Diff(var,dir)) / (c2*c2);
30413048
}
30423049

30433050

@@ -3264,11 +3271,11 @@ class ComponentCoefficientFunction : public T_CoefficientFunction<ComponentCoeff
32643271
values.Row(0).AddSize(ir.Size()) = in0.Row(comp);
32653272
}
32663273

3267-
shared_ptr<CoefficientFunction> Derive (const CoefficientFunction * var,
3274+
shared_ptr<CoefficientFunction> Diff (const CoefficientFunction * var,
32683275
shared_ptr<CoefficientFunction> dir) const override
32693276
{
32703277
if (this == var) return dir;
3271-
return MakeComponentCoefficientFunction (c1->Derive(var, dir), comp);
3278+
return MakeComponentCoefficientFunction (c1->Diff(var, dir), comp);
32723279
}
32733280

32743281
virtual void NonZeroPattern (const class ProxyUserData & ud, FlatVector<bool> nonzero,
@@ -3390,14 +3397,14 @@ class DomainWiseCoefficientFunction : public T_CoefficientFunction<DomainWiseCoe
33903397
return Array<shared_ptr<CoefficientFunction>>(cfa);
33913398
}
33923399

3393-
shared_ptr<CoefficientFunction> Derive (const CoefficientFunction * var,
3400+
shared_ptr<CoefficientFunction> Diff (const CoefficientFunction * var,
33943401
shared_ptr<CoefficientFunction> dir) const override
33953402
{
33963403
if (this == var) return dir;
33973404
Array<shared_ptr<CoefficientFunction>> ci_deriv;
33983405
for (auto & cf : ci)
33993406
if (cf)
3400-
ci_deriv.Append (cf->Derive(var, dir));
3407+
ci_deriv.Append (cf->Diff(var, dir));
34013408
else
34023409
ci_deriv.Append (nullptr);
34033410
return make_shared<DomainWiseCoefficientFunction> (move (ci_deriv));
@@ -4091,7 +4098,7 @@ class VectorialCoefficientFunction : public T_CoefficientFunction<VectorialCoeff
40914098
elementwise_constant = false;
40924099
// dims = Array<int> ( { dimension } );
40934100
}
4094-
4101+
40954102
void DoArchive(Archive& ar) override
40964103
{
40974104
BASE::DoArchive(ar);
@@ -4102,6 +4109,9 @@ class VectorialCoefficientFunction : public T_CoefficientFunction<VectorialCoeff
41024109
ar.Shallow(cf);
41034110
ar & dimi;
41044111
}
4112+
4113+
virtual string GetDescription () const override
4114+
{ return "VectorialCoefficientFunction"; }
41054115

41064116
virtual void GenerateCode(Code &code, FlatArray<int> inputs, int index) const override;
41074117

@@ -4232,14 +4242,14 @@ class VectorialCoefficientFunction : public T_CoefficientFunction<VectorialCoeff
42324242
}
42334243
}
42344244

4235-
shared_ptr<CoefficientFunction> Derive (const CoefficientFunction * var,
4245+
shared_ptr<CoefficientFunction> Diff (const CoefficientFunction * var,
42364246
shared_ptr<CoefficientFunction> dir) const override
42374247
{
42384248
if (this == var) return dir;
42394249
Array<shared_ptr<CoefficientFunction>> diff_ci;
42404250
for (auto & cf : ci)
42414251
if (cf)
4242-
diff_ci.Append (cf->Derive(var, dir));
4252+
diff_ci.Append (cf->Diff(var, dir));
42434253
else
42444254
diff_ci.Append (nullptr);
42454255
auto veccf = make_shared<VectorialCoefficientFunction> (move(diff_ci));
@@ -4459,6 +4469,51 @@ shared_ptr<CoefficientFunction> MakeCoordinateCoefficientFunction (int comp)
44594469

44604470
}
44614471

4472+
4473+
void PrintReport (ostream & ost) const override
4474+
{
4475+
ost << "Compiled CF:" << endl;
4476+
for (int i : Range(steps))
4477+
{
4478+
auto & cf = steps[i];
4479+
ost << "Step " << i << ": " << cf->GetDescription();
4480+
if (cf->Dimensions().Size() == 1)
4481+
ost << ", dim=" << cf->Dimension();
4482+
else if (cf->Dimensions().Size() == 2)
4483+
ost << ", dims = " << cf->Dimensions()[0] << " x " << cf->Dimensions()[1];
4484+
ost << endl;
4485+
if (inputs[i].Size() > 0)
4486+
{
4487+
ost << " input: ";
4488+
for (auto innr : inputs[i])
4489+
ost << innr << " ";
4490+
ost << endl;
4491+
}
4492+
}
4493+
/*
4494+
for (auto cf : steps)
4495+
ost << cf -> GetDescription() << endl;
4496+
ost << "inputs = " << endl << inputs << endl;
4497+
*/
4498+
4499+
/*
4500+
for (int i = 0; i < 2*level; i++)
4501+
ost << ' ';
4502+
ost << "coef " << GetDescription() << ","
4503+
<< (IsComplex() ? " complex" : " real");
4504+
if (Dimensions().Size() == 1)
4505+
ost << ", dim=" << Dimension();
4506+
else if (Dimensions().Size() == 2)
4507+
ost << ", dims = " << Dimensions()[0] << " x " << Dimensions()[1];
4508+
ost << endl;
4509+
4510+
Array<shared_ptr<CoefficientFunction>> input = InputCoefficientFunctions();
4511+
for (int i = 0; i < input.Size(); i++)
4512+
input[i] -> PrintReportRec (ost, level+1);
4513+
*/
4514+
}
4515+
4516+
44624517
void DoArchive(Archive& ar) override
44634518
{
44644519
CoefficientFunction::DoArchive(ar);

fem/coefficient.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ namespace ngfem
332332
virtual string GetDescription () const;
333333

334334
virtual shared_ptr<CoefficientFunction>
335-
Derive (const CoefficientFunction * var, shared_ptr<CoefficientFunction> dir) const;
335+
Diff (const CoefficientFunction * var, shared_ptr<CoefficientFunction> dir) const;
336336
virtual void TraverseTree (const function<void(CoefficientFunction&)> & func);
337337
virtual Array<shared_ptr<CoefficientFunction>> InputCoefficientFunctions() const
338338
{ return Array<shared_ptr<CoefficientFunction>>(); }
@@ -503,7 +503,7 @@ namespace ngfem
503503
}
504504

505505
virtual shared_ptr<CoefficientFunction>
506-
Derive (const CoefficientFunction * var, shared_ptr<CoefficientFunction> dir) const override;
506+
Diff (const CoefficientFunction * var, shared_ptr<CoefficientFunction> dir) const override;
507507
};
508508

509509

@@ -1268,7 +1268,7 @@ namespace ngfem
12681268
}
12691269

12701270
virtual shared_ptr<CoefficientFunction>
1271-
Derive (const CoefficientFunction * var, shared_ptr<CoefficientFunction> dir) const override
1271+
Diff (const CoefficientFunction * var, shared_ptr<CoefficientFunction> dir) const override
12721272
{ throw Exception ("unarycf "+name+" does not provide a derivative"); }
12731273

12741274
virtual void NonZeroPattern (const class ProxyUserData & ud,
@@ -1527,7 +1527,7 @@ shared_ptr<CoefficientFunction> UnaryOpCF(shared_ptr<CoefficientFunction> c1,
15271527
}
15281528

15291529
virtual shared_ptr<CoefficientFunction>
1530-
Derive (const CoefficientFunction * var, shared_ptr<CoefficientFunction> dir) const override
1530+
Diff (const CoefficientFunction * var, shared_ptr<CoefficientFunction> dir) const override
15311531
{ throw Exception ("binarycf "+opname+" does not provide a derivative"); }
15321532

15331533
virtual void NonZeroPattern (const class ProxyUserData & ud,

fem/integratorcf.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ namespace ngfem
4747
{ icfs += icf; }
4848

4949
shared_ptr<SumOfIntegrals>
50-
Derive (shared_ptr<CoefficientFunction> var,
51-
shared_ptr<CoefficientFunction> dir) const
50+
Diff (shared_ptr<CoefficientFunction> var,
51+
shared_ptr<CoefficientFunction> dir) const
5252
{
5353
auto deriv = make_shared<SumOfIntegrals>();
5454
for (auto & icf : icfs)
55-
deriv->icfs += make_shared<Integral> (icf->cf->Derive(var.get(), dir), icf->dx);
55+
deriv->icfs += make_shared<Integral> (icf->cf->Diff(var.get(), dir), icf->dx);
5656
return deriv;
5757
}
5858

0 commit comments

Comments
 (0)