Documentation of MARTY
A Modern ARtificial Theoretical phYsicist
modelBuilder.h
Go to the documentation of this file.
1 // This file is part of MARTY.
2 //
3 // MARTY is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // MARTY is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with MARTY. If not, see <https://www.gnu.org/licenses/>.
15 
24 #ifndef MODEL_BUILDER_H_INCLUDED
25 #define MODEL_BUILDER_H_INCLUDED
26 
27 #include "modelData.h"
28 #include "spectrum.h"
29 
30 namespace mty {
31 
32 class Amplitude;
33 
37 struct MassBlock {
38  std::vector<size_t> positions;
39  std::vector<Particle> particles;
40  std::vector<Lagrangian::TermType> terms;
41 };
42 
54 class ModelBuilder: public ModelData {
55 
56 public:
57 
59  // Constructors
61 
62 public:
63 
76  template<class ...Args>
77  explicit ModelBuilder(Args &&...args)
78  :ModelData(std::forward<Args>(args)...) {}
79 
83  ~ModelBuilder() override {};
84 
90  ModelBuilder(ModelBuilder &&other) = default;
91 
99  ModelBuilder &operator=(ModelBuilder &&other) = default;
100 
106  ModelBuilder(ModelBuilder const &other) = delete;
107 
115  ModelBuilder &operator=(ModelBuilder const &other) = delete;
116 
120  std::vector<csl::Expr> const &getAbbreviatedMassExpressions() const {
121  return abbreviatedMassExpressions;
122  }
123 
125  // Replacements
127 
128 public:
129 
130  void replace(
131  csl::Expr const &oldExpression,
132  csl::Expr const &newExpression
133  );
134 
135  void replace(
136  csl::Tensor &oldExpression,
137  csl::Expr const &newExpression
138  );
139 
140  void replace(
141  csl::Tensor &oldExpression,
142  csl::Tensor &newExpression,
143  std::function<bool(csl::Expr const&)> condition
144  = [](csl::Expr const&) { return true; }
145  );
146 
147  void replace(
148  mty::Particle const& particle,
149  csl::Expr newExpression,
150  std::function<bool(csl::Expr const&)> condition
151  = [](csl::Expr const&) { return true; }
152  );
153 
154  void rotateFields(
155  mty::Particle &fields,
156  csl::Tensor &unitaryMatrix,
157  std::function<bool(csl::Expr const&)> condition
158  = [](csl::Expr const&) { return true; }
159  );
160 
161  void rotateFields(
162  std::string const &fields,
163  csl::Tensor &unitaryMatrix,
164  std::function<bool(csl::Expr const&)> condition
165  = [](csl::Expr const&) { return true; }
166  )
167  {
168  auto part = getParticle(fields);
169  rotateFields(part, unitaryMatrix, condition);
170  }
171 
172  void rotateFields(
173  std::vector<mty::Particle> const &fields,
174  std::vector<mty::Particle> const &newFields,
175  std::vector<std::vector<csl::Expr>> const &rotation,
176  bool diagonalizeMasses = false,
177  int nMassLessFields = 0
178  );
179 
180  void rotateFields(
181  std::vector<mty::Particle> const &fields1,
182  std::vector<mty::Particle> const &newFields1,
183  std::vector<std::vector<csl::Expr>> const &rotation1,
184  std::vector<mty::Particle> const &fields2,
185  std::vector<mty::Particle> const &newFields2,
186  std::vector<std::vector<csl::Expr>> const &rotation2,
187  int nMassLessFields = 0
188  );
189 
190  void rotateFields(
191  std::vector<mty::Particle> const &fields,
192  bool diagonalizeMasses = false,
193  int nMassLessFields = 0
194  );
195 
196  void birotateFields(
197  std::vector<mty::Particle> const &fields1,
198  std::vector<mty::Particle> const &fields2,
199  int nMassLessFields = 0
200  );
201 
202  void rotateFields(
203  std::vector<std::string> const &fields,
204  std::vector<std::string> const &newFields,
205  std::vector<std::vector<csl::Expr>> const &rotation,
206  bool diagonalizeMasses = false,
207  int nMassLessFields = 0
208  );
209 
210  void rotateFields(
211  std::vector<std::string> const &fields1,
212  std::vector<std::string> const &newFields1,
213  std::vector<std::vector<csl::Expr>> const &rotation1,
214  std::vector<std::string> const &fields2,
215  std::vector<std::string> const &newFields2,
216  std::vector<std::vector<csl::Expr>> const &rotation2,
217  int nMassLessFields = 0
218  );
219 
220  void rotateFields(
221  std::initializer_list<std::string> const &fields,
222  std::initializer_list<std::string> const &newFields,
223  std::vector<std::vector<csl::Expr>> const &rotation,
224  bool diagonalizeMasses = false,
225  int nMassLessFields = 0
226  )
227  {
228  return rotateFields(
229  std::vector<std::string>(fields),
230  std::vector<std::string>(newFields),
231  rotation,
232  diagonalizeMasses,
233  nMassLessFields
234  );
235  }
236 
237  void rotateFields(
238  std::initializer_list<std::string> const &fields1,
239  std::initializer_list<std::string> const &newFields1,
240  std::vector<std::vector<csl::Expr>> const &rotation1,
241  std::initializer_list<std::string> const &fields2,
242  std::initializer_list<std::string> const &newFields2,
243  std::vector<std::vector<csl::Expr>> const &rotation2,
244  int nMassLessFields = 0
245  )
246  {
247  return rotateFields(
248  std::vector<std::string>(fields1),
249  std::vector<std::string>(newFields1),
250  rotation1,
251  std::vector<std::string>(fields2),
252  std::vector<std::string>(newFields2),
253  rotation2,
254  nMassLessFields
255  );
256  }
257 
258  void rotateFields(
259  std::vector<std::string> const &fields,
260  bool diagonalizeMasses = false,
261  int nMassLessFields = 0
262  );
263 
264  void birotateFields(
265  std::vector<std::string> const &fields1,
266  std::vector<std::string> const &fields2,
267  int nMassLessFields = 0
268  );
269 
270  void rotateFields(
271  std::initializer_list<std::string> const &fields,
272  bool diagonalizeMasses = false,
273  int nMassLessFields = 0
274  )
275  {
276  return rotateFields(
277  std::vector<std::string>(fields),
278  diagonalizeMasses,
279  nMassLessFields
280  );
281  }
282 
283  void birotateFields(
284  std::initializer_list<std::string> const &fields1,
285  std::initializer_list<std::string> const &fields2,
286  int nMassLessFields = 0
287  )
288  {
289  return birotateFields(
290  std::vector<std::string>(fields1),
291  std::vector<std::string>(fields2),
292  nMassLessFields
293  );
294  }
295 
296  void applyUnitaryCondition(
297  std::vector<std::vector<csl::Expr>> const& unitary
298  );
299 
300  void saveModel(
301  std::ostream &out,
302  int indent = 4
303  ) override;
304 
306  // Pure model building utilities
308 
309 public:
310 
311  template<class GroupType>
312  void setGaugeChoice(
313  GroupType &&group,
314  gauge::Type choice
315  );
316 
317  template<class FieldType1, class FieldType2>
318  void promoteToGoldstone(
319  FieldType1 &&goldstone,
320  FieldType2 &&gaugeBoson
321  );
322 
323  template<class FieldType1, class FieldType2>
324  void promoteToGhost(
325  FieldType1 &&ghost,
326  FieldType2 &&gaugeBoson
327  );
328 
329  template<class FieldType, class ...Args>
330  void promoteToMajorana(
331  FieldType &&weylFermion,
332  Args &&...args
333  );
334 
335  static void findAbreviation(csl::Expr &expr);
336  void integrateOutParticle(
337  mty::Particle const &particle,
338  std::vector<csl::Expr> newInteractions
339  );
340 
341  void diracFermionEmbedding(
342  std::string const &leftName,
343  std::string const &rightName
344  );
345 
346  void diracFermionEmbedding(
349  );
350  void applyDiracFermionEmbedding(
351  std::shared_ptr<mty::DiracFermion> const &diracFermion,
354  std::vector<mty::Lagrangian::TermType> &interaction
355  );
356 
357  void gatherMass(mty::Particle const &part);
358  void gatherMass(std::string const &name);
359 
360  void gatherMasses();
361 
362  void refresh();
363 
364  void breakU1GaugeSymmetry(
365  std::string const &groupName
366  );
367 
368  void breakGaugeSymmetry(std::string const &brokenGroup);
369 
370  void breakGaugeSymmetry(
371  std::string const &brokenGroup,
372  std::vector<mty::Particle> const &brokenFields,
373  std::vector<std::vector<std::string>> const &newNames
374  );
375 
376  void breakGaugeSymmetry(
377  std::string const &brokenGroup,
378  std::vector<std::string> const &brokenFields,
379  std::vector<std::vector<std::string>> const &newNames
380  );
381 
382  void breakGaugeSymmetry(
383  std::string const &brokenGroup,
384  std::vector<std::string> const &brokenFields
385  );
386 
387  void breakGaugeSymmetry(
388  std::string const &brokenGroup,
389  std::vector<mty::Particle> const &brokenFields
390  );
391 
392  void breakGaugeSymmetry(
393  Group *brokenGroup,
394  std::vector<mty::Particle> const &brokenFields,
395  std::vector<std::vector<std::string>> const &newNames
396  );
397 
398  void breakFlavorSymmetry(std::string const &nameGroup);
399 
400  void breakFlavorSymmetry(
401  std::string const &flavorName,
402  std::vector<size_t> const &subGroups,
403  std::vector<std::string> newFlavorNames
404  = std::vector<std::string>()
405  );
406 
407  void breakFlavorSymmetry(
408  std::string const &flavorName,
409  std::vector<mty::Particle> const &brokenFields,
410  std::vector<std::vector<std::string>> const &newNames
411  );
412 
413  void breakFlavorSymmetry(
414  std::string const &flavorName,
415  std::vector<size_t> const &subGroups,
416  std::vector<mty::Particle> const &brokenFields,
417  std::vector<std::vector<std::string>> const &newNames,
418  std::vector<std::string> const &newFlavorNames
419  );
420 
421  void diagonalizeMassMatrices();
422 
423  template<class FieldType>
424  bool diagonalizeSymbolically(
425  FieldType &&field,
426  bool forceDetZero = false);
427 
428  void diagonalizeYukawa(
429  std::string const &nameYukawa,
430  std::vector<std::string> const &nameMass,
431  csl::Expr const &globalFactor = CSL_1
432  );
433  void diagonalizeYukawa(
434  std::string const &nameYukawa,
435  std::vector<std::string> const &nameMass,
436  csl::Expr const &globalFactor,
437  csl::Tensor &mixing,
438  std::vector<mty::Particle> mixed
439  );
440  void diagonalizeYukawa(
441  std::string const &nameYukawa,
442  std::vector<csl::Expr> const &diagonal,
443  csl::Tensor mixing,
444  std::vector<mty::Particle> mixed
445  );
446 
447  void addSpectrum(
448  std::vector<mty::Particle> const &particles,
449  std::vector<std::vector<csl::Expr>> const &mass,
450  std::vector<std::vector<csl::Expr>> const &mix,
451  std::vector<std::vector<csl::Expr>> const &mix2
452  = std::vector<std::vector<csl::Expr>>()
453  );
454 
455  void updateDiagonalizationData();
456 
457  void applyDiagonalizationData(csl::Expr &expr) const;
458  void applyDiagonalizationData(std::vector<csl::Expr> &expr) const;
459  void applyDiagonalizationData(csl::LibraryGenerator &lib) const;
460  void applyDiagonalizationData(
462  mty::Amplitude const &amplitudes
463  ) const;
464  void applyDiagonalizationData(
466  std::function<bool(mty::Spectrum const &)> const &condition
467  ) const;
468  void addMassAbbreviations(
470  );
471 
472  void abbreviateBigTerms(size_t maxLeafs = 30);
473 
474  void checksRotation(
475  std::vector<mty::Particle> const &fields,
476  std::vector<mty::Particle> const &newFields,
477  std::vector<std::vector<csl::Expr>> const &rotation
478  );
479 
480  std::vector<csl::Expr> getRotationTerms(
481  std::vector<mty::Particle> const &newFields,
482  std::vector<std::vector<csl::Expr>> const &rotation
483  ) const;
484 
485  std::vector<csl::Expr> getFullMassMatrix(
486  std::vector<mty::Particle> const &fields
487  ) const;
488 
489  void fillDependenciesForRotation(
490  std::vector<csl::Expr> &kinetic,
491  std::vector<csl::Expr> &interaction,
492  mty::Particle const &field
493  );
494 
495  void fillDependenciesForRotation(
496  std::vector<csl::Expr> &kinetic,
497  std::vector<csl::Expr> &interaction,
498  std::vector<mty::Particle> const &fields
499  );
500 
501  void applyRotation(
502  mty::Particle const &field,
503  mty::Particle const &newField,
504  csl::Expr const &rotation
505  );
506 
507  void applyRotation(
508  std::vector<mty::Particle> const &fields,
509  std::vector<mty::Particle> const &newFields,
510  std::vector<csl::Expr> const &rotations
511  );
512 
513  void diagonalizeWithSpectrum(
514  std::vector<mty::Particle> const &fields,
515  std::vector<mty::Particle> const &newFields,
516  std::vector<std::vector<csl::Expr>> const &mixing,
517  std::vector<csl::Expr> const &massMatrix
518  );
519 
520  void bidiagonalizeWithSpectrum(
521  std::vector<mty::Particle> const &fields1,
522  std::vector<mty::Particle> const &newFields1,
523  std::vector<std::vector<csl::Expr>> const &mixing1,
524  std::vector<mty::Particle> const &fields2,
525  std::vector<mty::Particle> const &newFields2,
526  std::vector<std::vector<csl::Expr>> const &mixing2,
527  std::vector<csl::Expr> const &massMatrix
528  );
529 
530  std::vector<std::vector<mty::Particle>> const &getParticleFamilies() const {
531  return particleFamilies;
532  }
533 
534  void addParticleFamily(std::vector<mty::Particle> const &families);
535  void removeParticleFamily(mty::Particle const &particle);
536 
537  void addParticleFamily(std::vector<std::string> const &familyNames);
538  void removeParticleFamily(std::string const &particleName);
539 
540 protected:
541 
542  void replaceTermInLagrangian(
543  std::vector<Lagrangian::TermType> &lagrangian,
544  size_t &i,
545  csl::vector_expr &newTerms);
546 
547  void fillDependencies(
548  std::vector<csl::Expr> &kinetic,
549  std::vector<csl::Expr> &mass,
550  std::vector<csl::Expr> &interaction,
551  std::function<bool(Lagrangian::TermType const&)> dependencyFunc
552  );
553 
554  std::vector<csl::Expr> clearDependencies(
555  std::function<bool(Lagrangian::TermType const&)> dependencyFunc
556  );
557 
558  std::vector<csl::Expr> clearDependencies(
559  std::vector<Lagrangian::TermType> &terms,
560  std::function<bool(Lagrangian::TermType const&)> dependencyFunc
561  );
562 
563  void doSetGaugeChoice(
564  mty::Particle vectorBoson,
565  gauge::Type choice
566  );
567 
568  void doPromoteToGoldstone(
569  mty::Particle& goldstone,
570  mty::Particle& gaugeBoson
571  );
572 
573  void doPromoteToGhost(
574  mty::Particle& ghost,
575  mty::Particle& gaugeBoson
576  );
577 
578  void clearProjectorsInMass();
579 
580  void doPromoteToMajorana(
581  mty::Particle &weylFermion,
582  std::string const &newParticleName = ""
583  );
584 
585  bool doDiagonalizeSymbolically(
586  mty::Particle const &field,
587  bool forceDetZero = false
588  );
589 
590  void breakLagrangian(
591  mty::Particle const &init,
592  csl::Space const *brokenSpace
593  );
594  void breakLagrangian(
595  mty::Particle const &init,
596  csl::Space const *brokenSpace,
597  std::vector<csl::Space const*> const &newSpace
598  );
599 
600  static bool isValidMassTerm(mty::InteractionTerm const &term);
601 
602  static std::vector<mty::Particle> uniqueContent(
603  mty::InteractionTerm const &term
604  );
605 
606  static std::vector<mty::Particle>::const_iterator findInContent(
607  std::vector<mty::Particle> const &content,
608  mty::Particle const &field
609  );
610  static bool fieldInContent(
611  std::vector<mty::Particle> const &content,
612  mty::Particle const &field
613  );
614 
615  std::vector<MassBlock> getMassBlocks() const;
616 
617  static csl::Expr getMassMatrixOf(MassBlock const &block);
618 
619  bool diagonalizeExplicitely(
620  MassBlock const &block,
621  std::vector<mty::Particle> &newFields,
622  bool forceDetZero = false
623  );
624 
625  void writeMatrix(
627  std::ostream &out,
628  std::string const &indent
629  ) const;
630 
631  void writeSpectrum(
632  std::ostream &out,
633  int indentSize
634  ) const;
635 
636 protected:
637 
643  std::vector<Spectrum> spectra;
644 
650  std::vector<csl::Expr> abbreviatedMassExpressions;
651 
652  std::vector<std::vector<mty::Particle>> particleFamilies;
653 };
654 
656 // Template specializations
658 
659 template<class FieldType>
660  void ModelBuilder::setGaugeChoice(
661  FieldType &&field,
662  gauge::Type choice
663  )
664  {
665  constexpr bool group_valid =
666  std::is_convertible<
667  FieldType,
668  mty::Particle>::value;
669 
670  if constexpr (group_valid)
671  doSetGaugeChoice(field, choice);
672  else
673  setGaugeChoice(
674  getParticle(std::forward<FieldType>(field)),
675  choice
676  );
677  }
678 
679 template<class FieldType1, class FieldType2>
680  void ModelBuilder::promoteToGoldstone(
681  FieldType1 &&goldstone,
682  FieldType2 &&gaugeBoson
683  )
684  {
685  constexpr bool field1_valid =
686  std::is_convertible<
687  FieldType1,
688  mty::Particle const&>::value;
689  constexpr bool field2_valid =
690  std::is_convertible<
691  FieldType2,
692  mty::Particle const&>::value;
693 
694  if constexpr(field1_valid) {
695  if constexpr(field2_valid)
696  return doPromoteToGoldstone(goldstone, gaugeBoson);
697  else
698  return promoteToGoldstone(
699  goldstone,
700  getParticle(std::forward<FieldType2>(gaugeBoson))
701  );
702  }
703  else if constexpr (field2_valid)
704  return promoteToGoldstone(
705  getParticle(std::forward<FieldType1>(goldstone)),
706  gaugeBoson
707  );
708  else
709  return promoteToGoldstone(
710  getParticle(std::forward<FieldType1>(goldstone)),
711  getParticle(std::forward<FieldType2>(gaugeBoson))
712  );
713  }
714 
715 template<class FieldType1, class FieldType2>
716  void ModelBuilder::promoteToGhost(
717  FieldType1 &&ghost,
718  FieldType2 &&gaugeBoson
719  )
720  {
721  constexpr bool field1_valid =
722  std::is_convertible<
723  FieldType1,
724  mty::Particle const&>::value;
725  constexpr bool field2_valid =
726  std::is_convertible<
727  FieldType2,
728  mty::Particle const&>::value;
729 
730  if constexpr(field1_valid) {
731  if constexpr(field2_valid)
732  return doPromoteToGhost(ghost, gaugeBoson);
733  else
734  return promoteToGhost(
735  ghost,
736  getParticle(std::forward<FieldType2>(gaugeBoson))
737  );
738  }
739  else if constexpr (field2_valid)
740  return promoteToGhost(
741  getParticle(std::forward<FieldType1>(ghost)),
742  gaugeBoson
743  );
744  else
745  return promoteToGhost(
746  getParticle(std::forward<FieldType1>(ghost)),
747  getParticle(std::forward<FieldType2>(gaugeBoson))
748  );
749  }
750 
751 template<class FieldType, class ...Args>
752  void ModelBuilder::promoteToMajorana(
753  FieldType &&weylFermion,
754  Args &&...args
755  )
756  {
757  constexpr bool field_valid =
758  std::is_convertible<
759  FieldType,
760  mty::Particle const&>::value;
761 
762  if constexpr(field_valid) {
763  return doPromoteToMajorana(weylFermion, std::forward<Args>(args)...);
764  }
765  else
766  return promoteToMajorana(
767  getParticle(std::forward<FieldType>(weylFermion)),
768  std::forward<Args>(args)...
769  );
770  }
771 
772  template<class FieldType>
773  bool ModelBuilder::diagonalizeSymbolically(
774  FieldType &&field,
775  bool forceDetZero
776  )
777  {
778  constexpr bool field_valid =
779  std::is_convertible<
780  FieldType,
781  mty::Particle const&>::value;
782 
783  if constexpr(field_valid)
784  return doDiagonalizeSymbolically(
785  field,
786  forceDetZero
787  );
788  else
789  return doDiagonalizeSymbolically(
790  getParticle(std::forward<FieldType>(field)),
791  forceDetZero
792  );
793  }
794 
795 } // End of namespace mty
796 
797 #endif
Helper struct to store mass block data when diagonalizing.
Definition: modelBuilder.h:37
Class handling numerical diagonalization for HEP models.
Definition: spectrum.h:82
This class inherits from std::shared_ptr<QuantumFieldParent> and should be used instead of direct Qua...
Definition: quantumField.h:1409
Namespace of MARTY.
Definition: 2HDM.h:31
std::vector< csl::Expr > abbreviatedMassExpressions
Vector of abbreviated masses in the model, determined by the ModelBuilder::gatherMasses() function an...
Definition: modelBuilder.h:650
class mty::AbstractGroup Group
Abstract base class for groups.
Definition: matrix.h:36
Interface class containing the result of an amplitude calculation.
Definition: amplitude.h:41
File containing the Spectrum class, handling numerical diagonalization for High-Energy physics models...
First abstraction layer for a High-Energy Physics model.
ModelBuilder(Args &&...args)
Constructor.
Definition: modelBuilder.h:77
std::vector< csl::Expr > const & getAbbreviatedMassExpressions() const
Definition: modelBuilder.h:120
Type
Different types of gauge ficing parameter for gauge boson propagators.
Definition: gaugedGroup.h:92
The class ModelData contains all the necessary features to store and manipulate the content of a mode...
Definition: modelData.h:56
Interaction term (in the Lagrangian) in MARTY.
Definition: interactionTerm.h:50
~ModelBuilder() override
Default destructor.
Definition: modelBuilder.h:83
std::vector< Spectrum > spectra
Vector of Spectrum objects, remembering symbolic diagonalizations to, later on, diagonalize numerical...
Definition: modelBuilder.h:643
Class containing all model building features of MARTY.
Definition: modelBuilder.h:54