Commit 2a1f8865 authored by Grégoire Uhlrich's avatar Grégoire Uhlrich
Browse files

MARTY-1.3.1 : mostly MSM corrections and bug fixes + Majorana promotion from...

MARTY-1.3.1 : mostly MSM corrections and bug fixes + Majorana promotion from Weyl Fermion (coming with fix oof Conjugation matrix)
parent 2f1c58d6
......@@ -7,8 +7,8 @@ VERSION = 1.0
STATICLIBRARY = libcsl.a
DYNAMICLIBRARY = libcsl.so
CXXDEBUG = $(CXX) -g # -D DEBUG
CFLAGS = -Wall -Wextra -Wpedantic -Wfatal-errors -std=c++17 -O3 -fPIC
CXXDEBUG = $(CXX) -g
CFLAGS = -Wall -Wextra -Wpedantic -std=c++17 -O3 -fPIC
SRCDIR = src
HEADDIR = include
......
......@@ -229,57 +229,84 @@ class Abbreviation: public BaseParent {
evaluation = not evaluation;
};
/**
* @brief Returns the encapsulated expression, applying to it the correct
* index structure.
*
* @param self Abbreviated expression.
*
* @return The encapsulated expression with the correct index structure.
*
* @details This function uses getEncapsulated() and applies the current
* index structure, from the abbreviation object **self**, to it. The result
* is then the mathematically equivalent encapsulated expression. Therefore
* this function performs calculations (contrary to getEncapsulated()) but
* yields an expression that can replace the initial abbreviation object in
* expressions ensuring that the result is still mathematically valid.
*/
csl::Expr getExactEncapsulated(Expr_info self) const override
{
Expr res = DeepCopy(getEncapsulated());
if (self->isComplexConjugate())
res = csl::GetComplexConjugate(res);
csl::IndexStructure structure = self->getIndexStructure();
CSL_ASSERT_SPEC(structure.size() == initialStructure.size(),
CSLError::RuntimeError,
"Wrong indicial structure " + toString(structure)
+ " to apply for " + toString(initialStructure)
+ " initially.");
// csl::IndexStructure intermediate(structure);
// for (auto &index : intermediate)
// index = index.rename();
std::map<csl::Index, csl::Index> mapping;
csl::ForEachLeaf(res, [&](Expr &sub)
{
if (!IsIndicialTensor(sub))
return;
IndexStructure &index = sub->getIndexStructureView();
for (auto &i : index) {
auto pos = std::find(
initialStructure.begin(),
initialStructure.end(),
i);
if (pos == initialStructure.end()) {
auto pos2 = mapping.find(i);
const bool sign = i.getSign();
if (pos2 == mapping.end()) {
mapping[i] = i.rename();
mapping[i].setSign(false);
i = mapping[i];
if (sign)
i = +i;
}
else {
i = mapping[i];
if (sign)
i = +i;
}
}
}
});
Replace(res, initialStructure, structure);
return res;
}
std::optional<Expr> evaluate(
Expr_info self,
csl::eval::mode user_mode = csl::eval::base) const override {
if (evaluation or csl::eval::isContained(user_mode, csl::eval::abbreviation)) {
Expr res = DeepCopy(encapsulated);
if (self->isComplexConjugate())
res = csl::GetComplexConjugate(res);
csl::IndexStructure structure = self->getIndexStructure();
CSL_ASSERT_SPEC(structure.size() == initialStructure.size(),
CSLError::RuntimeError,
"Wrong indicial structure " + toString(structure)
+ " to apply for " + toString(initialStructure)
+ " initially.");
// csl::IndexStructure intermediate(structure);
// for (auto &index : intermediate)
// index = index.rename();
std::map<csl::Index, csl::Index> mapping;
csl::ForEachLeaf(res, [&](Expr &sub)
{
if (!IsIndicialTensor(sub))
return;
IndexStructure &index = sub->getIndexStructureView();
for (auto &i : index) {
auto pos = std::find(
initialStructure.begin(),
initialStructure.end(),
i);
if (pos == initialStructure.end()) {
auto pos2 = mapping.find(i);
const bool sign = i.getSign();
if (pos2 == mapping.end()) {
mapping[i] = i.rename();
mapping[i].setSign(false);
i = mapping[i];
if (sign)
i = +i;
}
else {
i = mapping[i];
if (sign)
i = +i;
}
}
}
});
Replace(res, initialStructure, structure);
if (evaluation or csl::eval::isContained(user_mode, csl::eval::abbreviation)){
auto res = getExactEncapsulated(self);
return Evaluated(res, user_mode);
}
return std::nullopt;
}
/**
* @return The initial encapsulated expression.
*
* @details To have the exact index correspondence with the actual
* abbreviation see getExactEncapsulated().
*/
Expr const &getEncapsulated() const override {
return encapsulated;
}
......
......@@ -148,19 +148,24 @@ public:
static LibEvalSession parseExpression(
Expr &expr,
bool display = false,
bool findIntermediates = true
);
void parse(
Expr &expr,
bool display = false,
bool findIntermediates,
std::map<csl::AbstractParent const*, csl::Expr> &parsedAbbrevs
);
void parse(
Expr &expr,
bool findIntermediates = true
);
void parseProduct(
Expr &iprod,
bool findIntermediates = true
bool findIntermediates,
std::map<csl::AbstractParent const*, csl::Expr> &parsedAbbrevs
);
void gatherUnEvalAndTensors(Expr const &result);
......@@ -190,11 +195,6 @@ protected:
std::vector<int> &nOccurences
);
void transform(
Expr &expr,
bool findIntermediates = true
);
static Expr expandIProd(Expr const &iprod);
void addUnEval(Expr const& expr) const;
void addTensor(csl::Tensor const& parent) const;
......
......@@ -67,9 +67,9 @@ namespace csl {
return functions;
}
LibFunction &addFunction(LibFunction const &func)
LibFunction &addFunction(LibFunction &&func)
{
functions.push_back(func);
functions.emplace_back(std::move(func));
return functions.back();
}
......
......@@ -202,6 +202,9 @@ class AbstractParent: public std::enable_shared_from_this<AbstractParent>{
virtual
Expr const &getEncapsulated() const;
virtual
Expr getExactEncapsulated(Expr_info self) const;
virtual
void setEncapsulated(Expr const &);
......
......@@ -54,7 +54,7 @@ void CallErrorImpl(CSLError error,
{
std::cerr << error << " in " << func << " (" << file << " l. " << line
<< ").\n";
std::raise(SIGTERM);
throw error;
}
void CallErrorImpl(CSLError error,
......@@ -65,5 +65,5 @@ void CallErrorImpl(CSLError error,
{
std::cerr << error << " in " << func << " (" << file << " l. " << line
<< "): " << message << '\n';
std::raise(SIGTERM);
throw error;
}
......@@ -786,12 +786,11 @@ void LibEvalSession::simplifySums()
LibEvalSession LibEvalSession::parseExpression(
Expr &expr,
bool display,
bool findIntermediates
)
{
LibEvalSession session;
session.parse(expr, display, findIntermediates);
session.parse(expr, findIntermediates);
return session;
}
......@@ -808,49 +807,6 @@ csl::IndexStructure LibEvalSession::getFreeStructure(
return csl::Abbrev::getFreeStructure(t_init);
}
void LibEvalSession::transform(
Expr &expr,
bool findIntermediates)
{
// static size_t n = 0;
// lib_log << "Transforming (" << n << ")\n" << expr << std::endl;
//LibraryExpander::apply(expr);
csl::ForEachNodeReversed(expr, [&](Expr& el)
{
if (el->getType() == csl::Type::Prod
and el->isIndexed()) {
parseProduct(el, findIntermediates);
}
if (csl::Abbrev::getFreeStructure(el).size() == 0) {
if (el->size() == 0
and csl::Abbrev::isAnAbbreviation(el)) {
auto parent = el->getParent_info();
if (abbreviations.find(parent) != abbreviations.end()) {
if (el->isComplexConjugate())
el = GetComplexConjugate(abbreviations[parent]);
else
el = abbreviations[parent];
return;
}
Expr encaps = DeepCopy(parent->getEncapsulated());
parse(encaps, false, findIntermediates);
if (el->isComplexConjugate())
el = GetComplexConjugate(addEval(encaps));
else
el = addEval(encaps);
abbreviations[parent] = encaps;
return;
}
if (!findIntermediates or el->size() == 0)
return;
el = addEval(el);
return;
}
});
csl::DeepRefresh(expr);
// lib_log << "RES transform (" << n++ << ") = " << expr << std::endl;
}
size_t getNLeafs(csl::Expr const &expr)
{
size_t n = 0;
......@@ -860,18 +816,17 @@ size_t getNLeafs(csl::Expr const &expr)
void LibEvalSession::parse(
Expr &expr,
bool display,
bool findIntermediates
bool findIntermediates,
std::map<csl::AbstractParent const*, csl::Expr> &parsedAbbrevs
)
{
csl::ScopedProperty prop(&csl::option::canonicalSumNumericalFactor, false);
csl::Evaluate(expr, csl::eval::numerical | csl::eval::literal);
std::map<AbstractParent const*, csl::Expr> parsedAbbrevs;
csl::ForEachNodeReversed(expr, [&](Expr& el)
{
if (el->getType() == csl::Type::Prod
and el->isIndexed()) {
parseProduct(el, findIntermediates);
parseProduct(el, findIntermediates, parsedAbbrevs);
}
});
csl::DeepRefresh(expr);
......@@ -892,7 +847,7 @@ void LibEvalSession::parse(
}
else {
csl::Expr encaps = parent->getEncapsulated();
parse(encaps);
parse(encaps, findIntermediates, parsedAbbrevs);
encaps = addEval(encaps);
parsedAbbrevs[parent] = encaps;
if (el->isComplexConjugate())
......@@ -909,31 +864,15 @@ void LibEvalSession::parse(
}
});
csl::Evaluate(expr, csl::eval::indicial);
return;
// static size_t n = 0;
// lib_log << "Parsing (" << n << ")\n" << expr << std::endl;
// std::vector<Expr> params;
// csl::VisitEachLeaf(expr, [&](Expr const &sub) {
// if (csl::IsLiteral(sub) and not csl::Abbrev::find_opt(sub->getName())) {
// auto pos = std::find(params.begin(), params.end(), sub);
// if (pos == params.end())
// params.push_back(sub);
// }
// });
// std::cout << "HERE " << expr << std::endl;
// csl::DeepCollect(expr, params);
csl::Evaluate(expr, csl::eval::numerical | csl::eval::literal);
if (expr->size() > 0) {
csl::ProgressBar bar(expr->size());
size_t index = 0;
for (size_t i = 0; i != expr->size(); ++i) {
if (display)
bar.progress(index++);
transform((*expr)[i], findIntermediates);
}
}
transform(expr, findIntermediates);
// lib_log << "RES parse (" << n++ << ") = " << expr << std::endl;
}
void LibEvalSession::parse(
Expr &expr,
bool findIntermediates
)
{
std::map<csl::AbstractParent const*, csl::Expr> parsedAbbrevs;
parse(expr, findIntermediates, parsedAbbrevs);
}
Expr LibEvalSession::expandIProd(Expr const &iprod)
......@@ -1007,7 +946,8 @@ Expr LibEvalSession::expandIProd(Expr const &iprod)
void LibEvalSession::parseProduct(
Expr &iprod,
bool findIntermediates
bool findIntermediates,
std::map<csl::AbstractParent const*, csl::Expr> &parsedAbbrevs
)
{
CSL_ASSERT_SPEC(iprod->getType() == csl::Type::Prod
......@@ -1085,7 +1025,7 @@ void LibEvalSession::parseProduct(
if (findIntermediates and expanded == prod)
args[pos] = addEval(prod);
else if (expanded != prod){
parse(expanded, false, findIntermediates);
parse(expanded, findIntermediates, parsedAbbrevs);
args[pos] = expanded;
}
else
......
......@@ -238,7 +238,7 @@ namespace csl {
csl::eval::literal
| csl::eval::numerical);
auto f = LibFunction{nameFunction, expr, group};
return group->addFunction(f);
return group->addFunction(std::move(f));
}
void LibraryGenerator::addDiagonalization(
......
......@@ -1392,8 +1392,11 @@ void Prod::print(
out<<"*";
}
if (denominatorIndices.size() > 0) {
if (numeratorIndices.size() == 0)
if (numeratorIndices.size() == 0
|| (numeratorIndices.size() == 1
&& argument[numeratorIndices[0]] == CSL_M_1)) {
out << "1";
}
out<<"/";
if (denominatorIndices.size() == 1)
argument[denominatorIndices[0]]->getArgument(0)->print(3, out, lib);
......
......@@ -204,6 +204,14 @@ Expr const &AbstractParent::getEncapsulated() const
return CSL_UNDEF;
}
Expr AbstractParent::getExactEncapsulated(Expr_info) const
{
std::cout << getName() << ": type " << getType() << std::endl;
callError(cslError::AbstractFuncCalled,
"AbstractParent::getExactEncapsulated() const");
return CSL_UNDEF;
}
void AbstractParent::setEncapsulated(Expr const &)
{
callError(cslError::AbstractFuncCalled,
......
......@@ -299,7 +299,7 @@ namespace csl {
if (parent && parent->isAnAbbreviation()) {
if (hasWeakDependency(sub, predicate)) {
std::string const &name = parent->getBaseName();
csl::Expr encaps = csl::DeepCopy(parent->getEncapsulated());
csl::Expr encaps = parent->getExactEncapsulated(sub.get());
applyThroughAbbreviations(encaps, rule);
sub = csl::Abbrev::makeAbbreviation(name, encaps);
return true;
......
......@@ -9,8 +9,8 @@ DYNAMICLIBRARY = libmarty.so
LTVERSION = 2.15
CXXDEBUG = $(CXX) -g # -D DEBUG
CXXFLAGS = $(MARTY_CXX_FLAGS) -Wall -Wextra -Wpedantic -std=c++17 -O3 -fPIC -Wfatal-errors -DDEBUGLOG
CXXDEBUG = $(CXX) -g
CXXFLAGS = $(MARTY_CXX_FLAGS) -Wall -Wextra -Wpedantic -std=c++17 -O3 -fPIC
SRCDIR = src
HEADDIR = include
......@@ -34,11 +34,11 @@ GSLLIB = lib/libgsl.a
GSLCBLASLIB = lib/libgslcblas.a
MAKE = /usr/bin/make
MODELDIR = models/include
SGLDIR = sgl/include
MODELINCDIR = models/include
SGLINCDIR = sgl/include
INCPATH = -I.. -I./$(HEADDIR) -I$(MODELDIR) -I../csl/$(HEADDIR)\
-I../jsonparser/$(HEADDIR) -I../grafed/$(HEADDIR) -I$(SGLDIR)\
INCPATH = -I.. -I./$(HEADDIR) -I$(MODELINCDIR) -I../csl/$(HEADDIR)\
-I../jsonparser/$(HEADDIR) -I../grafed/$(HEADDIR) -I$(SGLINCDIR)\
-I../dependencies/LoopTools-2.15/include
LIBPATH = -L../dependencies/LoopTools-2.15/build
INCLIBPATH = $(INCPATH) $(LIBPATH)
......@@ -83,13 +83,11 @@ all: models sgl lib release debug
marty: lib
models:
cd models; $(MAKE) all
sgl:
cd sgl; $(MAKE) all
models: $(modelOBJ) $(modelOBJDEBUG)
sgl: $(sglOBJ) $(sglOBJDEBUG)
lib: $(OBJ) $(OBJDEBUG) $(LIBDIR)/$(STATICLIBRARY) $(LIBDIR)/$(DYNAMICLIBRARY)\
$(modelOBJ) $(modelOBJDEBUG) $(sglOBJDEBUG)
lib: $(OBJ) $(OBJDEBUG) sgl models \
$(LIBDIR)/$(STATICLIBRARY) $(LIBDIR)/$(DYNAMICLIBRARY)
install:
mkdir -p $(INSTALLDIR)/include/marty
echo "#include \"marty/marty.h\"" >> $(INSTALLDIR)/include/marty.h
......@@ -108,6 +106,14 @@ debug: $(BINDEBUG)
.PRECIOUS: models/obj/%.o
.PRECIOUS: models/obj/%_debug.o
# Création des différents *.o à partir des *.cpp
sgl/$(OBJDIR)/%.o: sgl/$(SRCDIR)/%.cpp
$(CXX) $(CXXFLAGS) -o $@ -c $< $(INCPATH)
# Création des différents *.o à partir des *.cpp
models/$(OBJDIR)/%.o: models/$(SRCDIR)/%.cpp
$(CXX) $(CXXFLAGS) -o $@ -c $< $(INCPATH)
# Création des différents *.o à partir des *.cpp
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
$(CXX) $(CXXFLAGS) -o $@ -c $< $(INCPATH)
......@@ -120,6 +126,14 @@ $(PROGOBJDIR)/%.o: $(PROGDIR)/%.cpp
$(CXX) $(CXXFLAGS) -o $(BINDIR)/$@ $^ $(LIBPATH) $(LIBS)
# Création des différents *.o à partir des *.cpp
sgl/$(OBJDIR)/%_debug.o: sgl/$(SRCDIR)/%.cpp
$(CXXDEBUG) $(CXXFLAGS) -o $@ -c $< $(INCPATH)
# Création des différents *.o à partir des *.cpp
models/$(OBJDIR)/_debug%.o: models/$(SRCDIR)/%.cpp
$(CXXDEBUG) $(CXXFLAGS) -o $@ -c $< $(INCPATH)
# Version avec deboggage
$(OBJDIR)/%_debug.o: $(SRCDIR)/%.cpp
$(CXXDEBUG) $(CXXFLAGS) -o $@ -c $< $(INCPATH)
......@@ -132,16 +146,16 @@ $(PROGOBJDIR)/%_debug.o: $(PROGDIR)/%.cpp
$(CXXDEBUG) $(CXXFLAGS) -o $(BINDIR)/$@ $^ $(LIBPATH) $(LIBS)
# Library compilations
$(LIBDIR)/$(STATICLIBRARY): $(OBJ)
$(LIBDIR)/$(STATICLIBRARY): $(OBJ) $(sglOBJ) $(modelOBJ)
ar rcs $@ $(OBJ) $(cslOBJ) $(jsonOBJ) $(drawerOBJ) $(modelOBJ) $(sglOBJ)
$(LIBDIR)/$(DYNAMICLIBRARY): $(OBJ)
$(LIBDIR)/$(DYNAMICLIBRARY): $(OBJ) $(sglOBJ) $(modelOBJ)
$(CXX) $(CXXFLAGS) -shared -o $@ $(OBJ) $(cslOBJ) $(jsonOBJ) $(drawerOBJ)\
$(modelOBJ) $(sglOBJ) $(LIBPATH) $(LIBS)
clean:
cd models/&& $(MAKE) clean;
cd sgl/&& $(MAKE) clean;
-rm -f sgl/$(OBJDIR)/*.o;
-rm -f models/$(OBJDIR)/*.o;
-rm -f $(OBJDIR)/*.o;
-rm -f $(PROGOBJDIR)/*.o;
-rm -f lib/*.a lib/*.so
......
......@@ -4,8 +4,8 @@ DYNAMICLIBRARY = libmarty.so
LTVERSION = 2.15
CXXDEBUG = $(CXX) -g # -D DEBUG
CXXFLAGS = $(MARTY_CXX_FLAGS) -Wall -Wextra -Wpedantic -std=c++17 -O3 -fPIC -Wfatal-errors
CXXDEBUG = $(CXX) -g
CXXFLAGS = $(MARTY_CXX_FLAGS) -Wall -Wextra -Wpedantic -std=c++17 -O3 -fPIC
SRCDIR = src
HEADDIR = include
......@@ -29,11 +29,11 @@ GSLLIB = lib/libgsl.a
GSLCBLASLIB = lib/libgslcblas.a
MAKE = /usr/bin/make
MODELDIR = models/include
SGLDIR = sgl/include
MODELINCDIR = models/include
SGLINCDIR = sgl/include
INCPATH = -I.. -I./$(HEADDIR) -I$(MODELDIR) -I../csl/$(HEADDIR)\
-I../jsonparser/$(HEADDIR) -I../grafed/$(HEADDIR) -I$(SGLDIR)\
INCPATH = -I.. -I./$(HEADDIR) -I$(MODELINCDIR) -I../csl/$(HEADDIR)\
-I../jsonparser/$(HEADDIR) -I../grafed/$(HEADDIR) -I$(SGLINCDIR)\
-I../dependencies/LoopTools-2.15/include
LIBPATH = -L../dependencies/LoopTools-2.15/build
INCLIBPATH = $(INCPATH) $(LIBPATH)
......@@ -78,13 +78,11 @@ all: models sgl lib release debug
marty: lib
models:
cd models; $(MAKE) all
sgl:
cd sgl; $(MAKE) all
models: $(modelOBJ) $(modelOBJDEBUG)
sgl: $(sglOBJ) $(sglOBJDEBUG)
lib: $(OBJ) $(OBJDEBUG) $(LIBDIR)/$(STATICLIBRARY) $(LIBDIR)/$(DYNAMICLIBRARY)\
$(modelOBJ) $(modelOBJDEBUG) $(sglOBJDEBUG)
lib: $(OBJ) $(OBJDEBUG) sgl models \
$(LIBDIR)/$(STATICLIBRARY) $(LIBDIR)/$(DYNAMICLIBRARY)
install:
mkdir -p $(INSTALLDIR)/include/marty
echo "#include \"marty/marty.h\"" >> $(INSTALLDIR)/include/marty.h
......@@ -103,6 +101,14 @@ debug: $(BINDEBUG)
.PRECIOUS: models/obj/%.o
.PRECIOUS: models/obj/%_debug.o
# Création des différents *.o à partir des *.cpp
sgl/$(OBJDIR)/%.o: sgl/$(SRCDIR)/%.cpp
$(CXX) $(CXXFLAGS) -o $@ -c $< $(INCPATH)
# Création des différents *.o à partir des *.cpp
models/$(OBJDIR)/%.o: models/$(SRCDIR)/%.cpp
$(CXX) $(CXXFLAGS) -o $@ -c $< $(INCPATH)
# Création des différents *.o à partir des *.cpp
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
$(CXX) $(CXXFLAGS) -o $@ -c $< $(INCPATH)
......@@ -115,6 +121,14 @@ $(PROGOBJDIR)/%.o: $(PROGDIR)/%.cpp
$(CXX) $(CXXFLAGS) -o $(BINDIR)/$@ $^ $(LIBPATH) $(LIBS)
# Création des différents *.o à partir des *.cpp
sgl/$(OBJDIR)/%_debug.o: sgl/$(SRCDIR)/%.cpp
$(CXXDEBUG) $(CXXFLAGS) -o $@ -c $< $(INCPATH)
# Création des différents *.o à partir des *.cpp
models/$(OBJDIR)/_debug%.o: models/$(SRCDIR)/%.cpp
$(CXXDEBUG) $(CXXFLAGS) -o $@ -c $< $(INCPATH)
# Version avec deboggage
$(OBJDIR)/%_debug.o: $(SRCDIR)/%.cpp
$(CXXDEBUG) $(CXXFLAGS) -o $@ -c $< $(INCPATH)
......@@ -127,16 +141,16 @@ $(PROGOBJDIR)/%_debug.o: $(PROGDIR)/%.cpp
$(CXXDEBUG) $(CXXFLAGS) -o $(BINDIR)/$@ $^ $(LIBPATH) $(LIBS)
# Library compilations
$(LIBDIR)/$(STATICLIBRARY): $(OBJ)
$(LIBDIR)/$(STATICLIBRARY): $(OBJ) $(sglOBJ) $(modelOBJ)
ar rcs $@ $(OBJ) $(cslOBJ) $(jsonOBJ) $(drawerOBJ) $(modelOBJ) $(sglOBJ)
$(LIBDIR)/$(DYNAMICLIBRARY): $(OBJ)
$(LIBDIR)/$(DYNAMICLIBRARY): $(OBJ) $(sglOBJ) $(modelOBJ)
$(CXX) $(CXXFLAGS) -shared -o $@ $(OBJ) $(cslOBJ) $(jsonOBJ) $(drawerOBJ)\
$(modelOBJ) $(sglOBJ) $(LIBPATH) $(LIBS)
clean:
cd models/&& $(MAKE) clean;
cd sgl/&& $(MAKE) clean;
-rm -f sgl/$(OBJDIR)/*.o;
-rm -f models/$(OBJDIR)/*.o;
-rm -f $(OBJDIR)/*.o;
-rm -f $(PROGOBJDIR)/*.o;
-rm -f lib/*.a lib/*.so
......