* Implementation of GiNaC's special tensors. */
/*
- * GiNaC Copyright (C) 1999-2008 Johannes Gutenberg University Mainz, Germany
+ * GiNaC Copyright (C) 1999-2024 Johannes Gutenberg University Mainz, Germany
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include <iostream>
-#include <stdexcept>
-#include <vector>
-
#include "tensor.h"
#include "idx.h"
#include "indexed.h"
#include "archive.h"
#include "utils.h"
+#include <iostream>
+#include <stdexcept>
+#include <vector>
+
namespace GiNaC {
GINAC_IMPLEMENT_REGISTERED_CLASS(tensor, basic)
if (minkowski) {
for (size_t j=1; j<i.nops(); j++) {
const ex & x = i.op(j);
- if (!is_a<varidx>(x))
+ if (!is_a<varidx>(x)) {
throw(std::runtime_error("indices of epsilon tensor in Minkowski space must be of type varidx"));
- if (ex_to<varidx>(x).is_covariant())
- if (ex_to<idx>(x).get_value().is_zero())
+ }
+ if (ex_to<varidx>(x).is_covariant()) {
+ if (ex_to<idx>(x).get_value().is_zero()) {
sign = (pos_sig ? -sign : sign);
- else
+ }
+ else {
sign = (pos_sig ? sign : -sign);
+ }
+ }
}
}
ex delta_tensor(const ex & i1, const ex & i2)
{
- static ex delta = (new tensdelta)->setflag(status_flags::dynallocated);
+ static ex delta = dynallocate<tensdelta>();
if (!is_a<idx>(i1) || !is_a<idx>(i2))
throw(std::invalid_argument("indices of delta tensor must be of type idx"));
ex metric_tensor(const ex & i1, const ex & i2)
{
- static ex metric = (new tensmetric)->setflag(status_flags::dynallocated);
+ static ex metric = dynallocate<tensmetric>();
if (!is_a<varidx>(i1) || !is_a<varidx>(i2))
throw(std::invalid_argument("indices of metric tensor must be of type varidx"));
ex lorentz_g(const ex & i1, const ex & i2, bool pos_sig)
{
- static ex metric_neg = (new minkmetric(false))->setflag(status_flags::dynallocated);
- static ex metric_pos = (new minkmetric(true))->setflag(status_flags::dynallocated);
+ static ex metric_neg = dynallocate<minkmetric>(false);
+ static ex metric_pos = dynallocate<minkmetric>(true);
if (!is_a<varidx>(i1) || !is_a<varidx>(i2))
throw(std::invalid_argument("indices of metric tensor must be of type varidx"));
ex spinor_metric(const ex & i1, const ex & i2)
{
- static ex metric = (new spinmetric)->setflag(status_flags::dynallocated);
+ static ex metric = dynallocate<spinmetric>();
if (!is_a<spinidx>(i1) || !is_a<spinidx>(i2))
throw(std::invalid_argument("indices of spinor metric must be of type spinidx"));
ex epsilon_tensor(const ex & i1, const ex & i2)
{
- static ex epsilon = (new tensepsilon)->setflag(status_flags::dynallocated);
+ static ex epsilon = dynallocate<tensepsilon>();
if (!is_a<idx>(i1) || !is_a<idx>(i2))
throw(std::invalid_argument("indices of epsilon tensor must be of type idx"));
ex epsilon_tensor(const ex & i1, const ex & i2, const ex & i3)
{
- static ex epsilon = (new tensepsilon)->setflag(status_flags::dynallocated);
+ static ex epsilon = dynallocate<tensepsilon>();
if (!is_a<idx>(i1) || !is_a<idx>(i2) || !is_a<idx>(i3))
throw(std::invalid_argument("indices of epsilon tensor must be of type idx"));
ex lorentz_eps(const ex & i1, const ex & i2, const ex & i3, const ex & i4, bool pos_sig)
{
- static ex epsilon_neg = (new tensepsilon(true, false))->setflag(status_flags::dynallocated);
- static ex epsilon_pos = (new tensepsilon(true, true))->setflag(status_flags::dynallocated);
+ static ex epsilon_neg = dynallocate<tensepsilon>(true, false);
+ static ex epsilon_pos = dynallocate<tensepsilon>(true, true);
if (!is_a<varidx>(i1) || !is_a<varidx>(i2) || !is_a<varidx>(i3) || !is_a<varidx>(i4))
throw(std::invalid_argument("indices of Lorentz epsilon tensor must be of type varidx"));