|
4 | 4 | #include "Functional.hh" |
5 | 5 | #include "algorithms/canonicalise.hh" |
6 | 6 | #include "modules/xperm_new.h" |
| 7 | +#include "properties/Trace.hh" |
7 | 8 | #include "properties/Traceless.hh" |
8 | 9 | #include "properties/Diagonal.hh" |
9 | 10 | #include "properties/Derivative.hh" |
@@ -50,18 +51,53 @@ bool canonicalise::remove_traceless_traces(iterator& it) |
50 | 51 | while(facit!=tr.end(it)) { |
51 | 52 | const Traceless *trl=kernel.properties.get_composite<Traceless>(facit); |
52 | 53 | if(trl) { |
| 54 | + unsigned int ihits=0; |
53 | 55 | tree_exact_less_mod_prel_obj comp(&kernel.properties); |
54 | 56 | std::set<Ex, tree_exact_less_mod_prel_obj> countmap(comp); |
55 | 57 | index_iterator indit=begin_index(facit); |
56 | 58 | while(indit!=end_index(facit)) { |
| 59 | + bool incremented_now=false; |
| 60 | + auto ind=kernel.properties.get<Indices>(indit, true); |
| 61 | + if(ind) { |
| 62 | + // The indexs need to be in the set for which the object is |
| 63 | + // traceless (if specified, otherwise accept all). |
| 64 | + if(ind->set_name==trl->index_set_name || trl->index_set_name=="") { |
| 65 | + incremented_now=true; |
| 66 | + ++ihits; |
| 67 | + } |
| 68 | + } |
| 69 | + else incremented_now=true; |
| 70 | + // Having no name is treated as having the right name |
57 | 71 | if(countmap.find(Ex(indit))==countmap.end()) { |
58 | 72 | countmap.insert(Ex(indit)); |
59 | | - ++indit; |
60 | 73 | } |
61 | | - else { |
| 74 | + else if(incremented_now) { |
62 | 75 | zero(it->multiplier); |
63 | 76 | return true; |
64 | 77 | } |
| 78 | + ++indit; |
| 79 | + } |
| 80 | + iterator parent=it; |
| 81 | + if (tr.number_of_children(it)==1 && !tr.is_head(it)) parent=tr.parent(it); |
| 82 | + const Trace *trace=kernel.properties.get<Trace>(parent); |
| 83 | + if(trace) { |
| 84 | + int tmp; |
| 85 | + auto impi=kernel.properties.get_with_pattern<ImplicitIndex>(facit, tmp); |
| 86 | + if(impi.first->explicit_form.size()>0) { |
| 87 | + // Does the explicit form have two more indices of the right type? |
| 88 | + Ex::iterator eform=impi.first->explicit_form.begin(); |
| 89 | + unsigned int ehits=0; |
| 90 | + indit=begin_index(eform); |
| 91 | + while(indit!=end_index(eform)) { |
| 92 | + auto ind=kernel.properties.get<Indices>(indit, true); |
| 93 | + if(ind->set_name==trl->index_set_name && ind->set_name==trace->index_set_name) ++ehits; |
| 94 | + if(ehits - ihits > 1) { |
| 95 | + zero(it->multiplier); |
| 96 | + return true; |
| 97 | + } |
| 98 | + ++indit; |
| 99 | + } |
| 100 | + } |
65 | 101 | } |
66 | 102 | } |
67 | 103 | ++facit; |
|
0 commit comments