@@ -107,13 +107,13 @@ namespace ngfem
107
107
}
108
108
109
109
shared_ptr<CoefficientFunction> CoefficientFunction ::
110
- Derive (const CoefficientFunction * var, shared_ptr<CoefficientFunction> dir) const
110
+ Diff (const CoefficientFunction * var, shared_ptr<CoefficientFunction> dir) const
111
111
{
112
112
throw Exception (string (" Deriv not implemented for CF " )+typeid (*this ).name ());
113
113
}
114
114
115
115
shared_ptr<CoefficientFunction> CoefficientFunctionNoDerivative ::
116
- Derive (const CoefficientFunction * var, shared_ptr<CoefficientFunction> dir) const
116
+ Diff (const CoefficientFunction * var, shared_ptr<CoefficientFunction> dir) const
117
117
{
118
118
if (var == this )
119
119
return dir;
@@ -1097,11 +1097,11 @@ class ScaleCoefficientFunction : public T_CoefficientFunction<ScaleCoefficientFu
1097
1097
values = input[0 ];
1098
1098
}
1099
1099
1100
- shared_ptr<CoefficientFunction> Derive (const CoefficientFunction * var,
1100
+ shared_ptr<CoefficientFunction> Diff (const CoefficientFunction * var,
1101
1101
shared_ptr<CoefficientFunction> dir) const override
1102
1102
{
1103
1103
if (this == var) return dir;
1104
- return scal * c1->Derive (var, dir);
1104
+ return scal * c1->Diff (var, dir);
1105
1105
}
1106
1106
1107
1107
};
@@ -1295,11 +1295,11 @@ class MultScalVecCoefficientFunction : public T_CoefficientFunction<MultScalVecC
1295
1295
values (j,i) = in0 (0 ,i) * in1 (j,i);
1296
1296
}
1297
1297
1298
- shared_ptr<CoefficientFunction> Derive (const CoefficientFunction * var,
1298
+ shared_ptr<CoefficientFunction> Diff (const CoefficientFunction * var,
1299
1299
shared_ptr<CoefficientFunction> dir) const override
1300
1300
{
1301
1301
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);
1303
1303
}
1304
1304
1305
1305
@@ -1612,12 +1612,12 @@ class T_MultVecVecCoefficientFunction : public T_CoefficientFunction<T_MultVecVe
1612
1612
result (i,0 ) = InnerProduct (temp1.Row (i), temp2.Row (i));
1613
1613
}
1614
1614
1615
- shared_ptr<CoefficientFunction> Derive (const CoefficientFunction * var,
1615
+ shared_ptr<CoefficientFunction> Diff (const CoefficientFunction * var,
1616
1616
shared_ptr<CoefficientFunction> dir) const override
1617
1617
{
1618
1618
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);
1621
1621
}
1622
1622
1623
1623
@@ -2153,11 +2153,11 @@ class MultMatMatCoefficientFunction : public T_CoefficientFunction<MultMatMatCoe
2153
2153
}
2154
2154
}
2155
2155
2156
- shared_ptr<CoefficientFunction> Derive (const CoefficientFunction * var,
2156
+ shared_ptr<CoefficientFunction> Diff (const CoefficientFunction * var,
2157
2157
shared_ptr<CoefficientFunction> dir) const override
2158
2158
{
2159
2159
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);
2161
2161
}
2162
2162
2163
2163
};
@@ -2197,6 +2197,10 @@ class MultMatVecCoefficientFunction : public T_CoefficientFunction<MultMatVecCoe
2197
2197
BASE::DoArchive (ar);
2198
2198
ar.Shallow (c1).Shallow (c2) & inner_dim;
2199
2199
}
2200
+
2201
+ virtual string GetDescription () const override
2202
+ { return " Matrix-Vector multiply" ; }
2203
+
2200
2204
2201
2205
// virtual bool IsComplex() const { return c1->IsComplex() || c2->IsComplex(); }
2202
2206
// virtual int Dimension() const { return dims[0]; }
@@ -2333,11 +2337,11 @@ class MultMatVecCoefficientFunction : public T_CoefficientFunction<MultMatVecCoe
2333
2337
}
2334
2338
2335
2339
2336
- shared_ptr<CoefficientFunction> Derive (const CoefficientFunction * var,
2340
+ shared_ptr<CoefficientFunction> Diff (const CoefficientFunction * var,
2337
2341
shared_ptr<CoefficientFunction> dir) const override
2338
2342
{
2339
2343
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);
2341
2345
}
2342
2346
2343
2347
@@ -2367,6 +2371,9 @@ class TransposeCoefficientFunction : public T_CoefficientFunction<TransposeCoeff
2367
2371
BASE::DoArchive (ar);
2368
2372
ar.Shallow (c1);
2369
2373
}
2374
+
2375
+ virtual string GetDescription () const override
2376
+ { return " Matrix transpose" ; }
2370
2377
2371
2378
virtual void TraverseTree (const function<void (CoefficientFunction&)> & func) override
2372
2379
{
@@ -2492,11 +2499,11 @@ class TransposeCoefficientFunction : public T_CoefficientFunction<TransposeCoeff
2492
2499
values (j*hdims[1 ]+k, i) = in0 (k*hdims[0 ]+j, i);
2493
2500
}
2494
2501
2495
- shared_ptr<CoefficientFunction> Derive (const CoefficientFunction * var,
2502
+ shared_ptr<CoefficientFunction> Diff (const CoefficientFunction * var,
2496
2503
shared_ptr<CoefficientFunction> dir) const override
2497
2504
{
2498
2505
if (this == var) return dir;
2499
- return TransposeCF (c1->Derive (var, dir));
2506
+ return TransposeCF (c1->Diff (var, dir));
2500
2507
}
2501
2508
};
2502
2509
@@ -2655,11 +2662,11 @@ class InverseCoefficientFunction : public T_CoefficientFunction<InverseCoefficie
2655
2662
}
2656
2663
}
2657
2664
2658
- shared_ptr<CoefficientFunction> Derive (const CoefficientFunction * var,
2665
+ shared_ptr<CoefficientFunction> Diff (const CoefficientFunction * var,
2659
2666
shared_ptr<CoefficientFunction> dir) const override
2660
2667
{
2661
2668
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);
2663
2670
}
2664
2671
};
2665
2672
@@ -2808,11 +2815,11 @@ class DeterminantCoefficientFunction : public T_CoefficientFunction<DeterminantC
2808
2815
}
2809
2816
}
2810
2817
2811
- shared_ptr<CoefficientFunction> Derive (const CoefficientFunction * var,
2818
+ shared_ptr<CoefficientFunction> Diff (const CoefficientFunction * var,
2812
2819
shared_ptr<CoefficientFunction> dir) const override
2813
2820
{
2814
2821
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) );
2816
2823
}
2817
2824
};
2818
2825
@@ -2995,11 +3002,11 @@ class SymmetricCoefficientFunction : public T_CoefficientFunction<SymmetricCoeff
2995
3002
2996
3003
template <>
2997
3004
shared_ptr<CoefficientFunction>
2998
- cl_BinaryOpCF<GenericPlus>::Derive (const CoefficientFunction * var,
3005
+ cl_BinaryOpCF<GenericPlus>::Diff (const CoefficientFunction * var,
2999
3006
shared_ptr<CoefficientFunction> dir) const
3000
3007
{
3001
3008
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);
3003
3010
}
3004
3011
3005
3012
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
3010
3017
3011
3018
template <>
3012
3019
shared_ptr<CoefficientFunction>
3013
- cl_BinaryOpCF<GenericMinus>::Derive (const CoefficientFunction * var,
3020
+ cl_BinaryOpCF<GenericMinus>::Diff (const CoefficientFunction * var,
3014
3021
shared_ptr<CoefficientFunction> dir) const
3015
3022
{
3016
3023
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);
3018
3025
}
3019
3026
3020
3027
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
3024
3031
3025
3032
template <>
3026
3033
shared_ptr<CoefficientFunction>
3027
- cl_BinaryOpCF<GenericMult>::Derive (const CoefficientFunction * var,
3034
+ cl_BinaryOpCF<GenericMult>::Diff (const CoefficientFunction * var,
3028
3035
shared_ptr<CoefficientFunction> dir) const
3029
3036
{
3030
3037
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);
3032
3039
}
3033
3040
3034
3041
template <>
3035
3042
shared_ptr<CoefficientFunction>
3036
- cl_BinaryOpCF<GenericDiv>::Derive (const CoefficientFunction * var,
3043
+ cl_BinaryOpCF<GenericDiv>::Diff (const CoefficientFunction * var,
3037
3044
shared_ptr<CoefficientFunction> dir) const
3038
3045
{
3039
3046
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);
3041
3048
}
3042
3049
3043
3050
@@ -3264,11 +3271,11 @@ class ComponentCoefficientFunction : public T_CoefficientFunction<ComponentCoeff
3264
3271
values.Row (0 ).AddSize (ir.Size ()) = in0.Row (comp);
3265
3272
}
3266
3273
3267
- shared_ptr<CoefficientFunction> Derive (const CoefficientFunction * var,
3274
+ shared_ptr<CoefficientFunction> Diff (const CoefficientFunction * var,
3268
3275
shared_ptr<CoefficientFunction> dir) const override
3269
3276
{
3270
3277
if (this == var) return dir;
3271
- return MakeComponentCoefficientFunction (c1->Derive (var, dir), comp);
3278
+ return MakeComponentCoefficientFunction (c1->Diff (var, dir), comp);
3272
3279
}
3273
3280
3274
3281
virtual void NonZeroPattern (const class ProxyUserData & ud, FlatVector<bool > nonzero,
@@ -3390,14 +3397,14 @@ class DomainWiseCoefficientFunction : public T_CoefficientFunction<DomainWiseCoe
3390
3397
return Array<shared_ptr<CoefficientFunction>>(cfa);
3391
3398
}
3392
3399
3393
- shared_ptr<CoefficientFunction> Derive (const CoefficientFunction * var,
3400
+ shared_ptr<CoefficientFunction> Diff (const CoefficientFunction * var,
3394
3401
shared_ptr<CoefficientFunction> dir) const override
3395
3402
{
3396
3403
if (this == var) return dir;
3397
3404
Array<shared_ptr<CoefficientFunction>> ci_deriv;
3398
3405
for (auto & cf : ci)
3399
3406
if (cf)
3400
- ci_deriv.Append (cf->Derive (var, dir));
3407
+ ci_deriv.Append (cf->Diff (var, dir));
3401
3408
else
3402
3409
ci_deriv.Append (nullptr );
3403
3410
return make_shared<DomainWiseCoefficientFunction> (move (ci_deriv));
@@ -4091,7 +4098,7 @@ class VectorialCoefficientFunction : public T_CoefficientFunction<VectorialCoeff
4091
4098
elementwise_constant = false ;
4092
4099
// dims = Array<int> ( { dimension } );
4093
4100
}
4094
-
4101
+
4095
4102
void DoArchive (Archive& ar) override
4096
4103
{
4097
4104
BASE::DoArchive (ar);
@@ -4102,6 +4109,9 @@ class VectorialCoefficientFunction : public T_CoefficientFunction<VectorialCoeff
4102
4109
ar.Shallow (cf);
4103
4110
ar & dimi;
4104
4111
}
4112
+
4113
+ virtual string GetDescription () const override
4114
+ { return " VectorialCoefficientFunction" ; }
4105
4115
4106
4116
virtual void GenerateCode (Code &code, FlatArray<int > inputs, int index) const override ;
4107
4117
@@ -4232,14 +4242,14 @@ class VectorialCoefficientFunction : public T_CoefficientFunction<VectorialCoeff
4232
4242
}
4233
4243
}
4234
4244
4235
- shared_ptr<CoefficientFunction> Derive (const CoefficientFunction * var,
4245
+ shared_ptr<CoefficientFunction> Diff (const CoefficientFunction * var,
4236
4246
shared_ptr<CoefficientFunction> dir) const override
4237
4247
{
4238
4248
if (this == var) return dir;
4239
4249
Array<shared_ptr<CoefficientFunction>> diff_ci;
4240
4250
for (auto & cf : ci)
4241
4251
if (cf)
4242
- diff_ci.Append (cf->Derive (var, dir));
4252
+ diff_ci.Append (cf->Diff (var, dir));
4243
4253
else
4244
4254
diff_ci.Append (nullptr );
4245
4255
auto veccf = make_shared<VectorialCoefficientFunction> (move (diff_ci));
@@ -4459,6 +4469,51 @@ shared_ptr<CoefficientFunction> MakeCoordinateCoefficientFunction (int comp)
4459
4469
4460
4470
}
4461
4471
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
+
4462
4517
void DoArchive (Archive& ar) override
4463
4518
{
4464
4519
CoefficientFunction::DoArchive (ar);
0 commit comments