@@ -56,6 +56,13 @@ QDataStream &operator<<(QDataStream &ds, const LambdaSchedule &schedule)
56
56
return ds;
57
57
}
58
58
59
+ Symbol LambdaSchedule::lambda_symbol (" λ" );
60
+ Symbol LambdaSchedule::initial_symbol (" initial" );
61
+ Symbol LambdaSchedule::final_symbol (" final" );
62
+
63
+ Expression LambdaSchedule::default_morph_equation = (1.0 - LambdaSchedule::lam()) * LambdaSchedule::initial () +
64
+ LambdaSchedule::lam() * LambdaSchedule::final ();
65
+
59
66
QDataStream &operator >>(QDataStream &ds, LambdaSchedule &schedule)
60
67
{
61
68
VersionID v = readHeader (ds, r_schedule);
@@ -68,6 +75,21 @@ QDataStream &operator>>(QDataStream &ds, LambdaSchedule &schedule)
68
75
schedule.lever_names >> schedule.stage_names >>
69
76
schedule.default_equations >> schedule.stage_equations >>
70
77
static_cast <Property &>(schedule);
78
+
79
+ for (auto &expression : schedule.default_equations )
80
+ {
81
+ if (expression == LambdaSchedule::default_morph_equation)
82
+ expression = LambdaSchedule::default_morph_equation;
83
+ }
84
+
85
+ for (auto &stage_equations : schedule.stage_equations )
86
+ {
87
+ for (auto &expression : stage_equations)
88
+ {
89
+ if (expression == LambdaSchedule::default_morph_equation)
90
+ expression = LambdaSchedule::default_morph_equation;
91
+ }
92
+ }
71
93
}
72
94
else
73
95
throw version_error (v, " 1" , r_schedule, CODELOC);
@@ -203,10 +225,6 @@ LambdaSchedule LambdaSchedule::charge_scaled_morph(double scale)
203
225
return l;
204
226
}
205
227
206
- Symbol LambdaSchedule::lambda_symbol (" λ" );
207
- Symbol LambdaSchedule::initial_symbol (" initial" );
208
- Symbol LambdaSchedule::final_symbol (" final" );
209
-
210
228
/* * Return the symbol used to represent the :lambda: coordinate.
211
229
* This symbol is used to represent the per-stage :lambda:
212
230
* variable that goes from 0.0-1.0 within that stage.
@@ -438,8 +456,7 @@ void LambdaSchedule::clear()
438
456
*/
439
457
void LambdaSchedule::addMorphStage (const QString &name)
440
458
{
441
- this ->addStage (name, (this ->lam () * this ->final ()) +
442
- ((1 - this ->lam ()) * this ->initial ()));
459
+ this ->addStage (name, default_morph_equation);
443
460
}
444
461
445
462
/* * Append a morph stage onto this schedule. The morph stage is a
@@ -501,9 +518,14 @@ void LambdaSchedule::addChargeScaleStages(double scale)
501
518
void LambdaSchedule::prependStage (const QString &name,
502
519
const SireCAS::Expression &equation)
503
520
{
521
+ auto e = equation;
522
+
523
+ if (e == default_morph_equation)
524
+ e = default_morph_equation;
525
+
504
526
if (this ->nStages () == 0 )
505
527
{
506
- this ->appendStage (name, equation );
528
+ this ->appendStage (name, e );
507
529
return ;
508
530
}
509
531
@@ -514,7 +536,7 @@ void LambdaSchedule::prependStage(const QString &name,
514
536
CODELOC);
515
537
516
538
this ->stage_names .prepend (name);
517
- this ->default_equations .prepend (equation );
539
+ this ->default_equations .prepend (e );
518
540
this ->stage_equations .prepend (QHash<QString, Expression>());
519
541
}
520
542
@@ -532,8 +554,13 @@ void LambdaSchedule::appendStage(const QString &name,
532
554
.arg (name),
533
555
CODELOC);
534
556
557
+ auto e = equation;
558
+
559
+ if (e == default_morph_equation)
560
+ e = default_morph_equation;
561
+
535
562
this ->stage_names .append (name);
536
- this ->default_equations .append (equation );
563
+ this ->default_equations .append (e );
537
564
this ->stage_equations .append (QHash<QString, Expression>());
538
565
}
539
566
@@ -546,14 +573,19 @@ void LambdaSchedule::insertStage(int i,
546
573
const QString &name,
547
574
const SireCAS::Expression &equation)
548
575
{
576
+ auto e = equation;
577
+
578
+ if (e == default_morph_equation)
579
+ e = default_morph_equation;
580
+
549
581
if (i == 0 )
550
582
{
551
- this ->prependStage (name, equation );
583
+ this ->prependStage (name, e );
552
584
return ;
553
585
}
554
586
else if (i >= this ->nStages ())
555
587
{
556
- this ->appendStage (name, equation );
588
+ this ->appendStage (name, e );
557
589
return ;
558
590
}
559
591
@@ -564,7 +596,7 @@ void LambdaSchedule::insertStage(int i,
564
596
CODELOC);
565
597
566
598
this ->stage_names .insert (i, name);
567
- this ->default_equations .insert (i, equation );
599
+ this ->default_equations .insert (i, e );
568
600
this ->stage_equations .insert (i, QHash<QString, Expression>());
569
601
}
570
602
@@ -605,7 +637,12 @@ int LambdaSchedule::find_stage(const QString &stage) const
605
637
void LambdaSchedule::setDefaultEquation (const QString &stage,
606
638
const Expression &equation)
607
639
{
608
- this ->default_equations [this ->find_stage (stage)] = equation;
640
+ auto e = equation;
641
+
642
+ if (e == default_morph_equation)
643
+ e = default_morph_equation;
644
+
645
+ this ->default_equations [this ->find_stage (stage)] = e;
609
646
}
610
647
611
648
/* * Set the custom equation used to control the specified
@@ -617,12 +654,17 @@ void LambdaSchedule::setEquation(const QString &stage,
617
654
const QString &lever,
618
655
const Expression &equation)
619
656
{
657
+ auto e = equation;
658
+
659
+ if (e == default_morph_equation)
660
+ e = default_morph_equation;
661
+
620
662
auto &lever_expressions = this ->stage_equations [this ->find_stage (stage)];
621
663
622
664
if (not this ->lever_names .contains (lever))
623
665
this ->addLever (lever);
624
666
625
- lever_expressions[lever] = equation ;
667
+ lever_expressions[lever] = e ;
626
668
}
627
669
628
670
/* * Remove the custom equation for the specified `lever` at the
@@ -875,21 +917,31 @@ QVector<double> LambdaSchedule::morph(const QString &lever_name,
875
917
const auto equation = this ->stage_equations [stage].value (
876
918
lever_name, this ->default_equations [stage]);
877
919
878
- Values input_values = this ->constant_values ;
879
- input_values.set (this ->lam (), std::get<1 >(resolved));
880
-
881
920
QVector<double > morphed (nparams);
882
-
883
921
auto morphed_data = morphed.data ();
884
922
const auto initial_data = initial.constData ();
885
923
const auto final_data = final .constData ();
886
924
887
- for ( int i = 0 ; i < nparams; ++i )
925
+ if (equation == default_morph_equation )
888
926
{
889
- input_values.set (this ->initial (), initial_data[i]);
890
- input_values.set (this ->final (), final_data[i]);
927
+ for (int i = 0 ; i < nparams; ++i)
928
+ {
929
+ morphed_data[i] = (1.0 - lambda_value) * initial_data[i] +
930
+ lambda_value * final_data[i];
931
+ }
932
+ }
933
+ else
934
+ {
935
+ Values input_values = this ->constant_values ;
936
+ input_values.set (this ->lam (), std::get<1 >(resolved));
937
+
938
+ for (int i = 0 ; i < nparams; ++i)
939
+ {
940
+ input_values.set (this ->initial (), initial_data[i]);
941
+ input_values.set (this ->final (), final_data[i]);
891
942
892
- morphed_data[i] = equation (input_values);
943
+ morphed_data[i] = equation (input_values);
944
+ }
893
945
}
894
946
895
947
return morphed;
0 commit comments