23 #ifndef SPACE_H_INCLUDED 24 #define SPACE_H_INCLUDED 33 template<
typename T,
typename G>
34 typename std::vector<std::pair<T,G>>::iterator findFirstInPair(
35 std::vector<std::pair<T,G>>& v,
const T& element)
37 typename std::vector<std::pair<T,G>>::iterator
39 while (iter != v.end() and (*iter).first != element)
45 template<
typename T,
typename G>
46 typename std::vector<std::pair<T,G>>::iterator findSecondInPair(
47 std::vector<std::pair<T,G>>& v,
const G& element)
49 typename std::vector<std::pair<T,G>>::iterator
51 while (iter != v.end() and (*iter).second != element)
68 mutable bool keepCycles =
false;
70 static bool applyMetric;
94 std::map<char, std::string> nameIndices;
97 std::map<std::string, char> specIndices;
100 std::vector<std::pair<std::string, Index::ID_type>> availableIndices;
103 std::vector<std::pair<std::string, unsigned short>> availableVectors;
106 std::vector<std::string>::const_iterator defaultName;
108 std::vector<std::string> defaultIndexNames;
152 Space(
const std::string& t_name,
154 std::vector<std::string>
const& indexNames
155 = {
"i",
"j",
"k",
"l"});
171 Space(
const std::string& t_name,
173 const std::string& name_metric,
174 const Expr& t_metric,
175 std::vector<std::string>
const& indexNames
176 = {
"i",
"j",
"k",
"l"});
190 void printDefinition(
199 virtual std::string
getName()
const;
201 inline std::string getNextIndexName()
const;
203 inline std::string getIndexName(
char spec)
const;
205 inline std::string_view getIndexNameView(
char spec)
const;
207 inline char getSpecFromIndexName(std::string
const& t_name)
const;
212 inline int getDim()
const;
221 bool hasSpecialTraceProperty(
const csl::vector_expr& tensors)
const;
223 csl::vector_expr getSignature()
const;
227 Tensor getInverseMetric()
const;
231 Tensor getEpsilon()
const;
233 Expr applyMetricOnTensor(
Expr const& tensor,
235 bool covariant)
const;
257 inline std::vector<Index> generateIndices(
size_t N)
const;
258 inline std::vector<Index> generateIndices(
260 const std::string& name
263 inline Index generateSimilar(
const Index& model)
const;
265 inline void resetIndexNumber()
const;
267 inline void refreshIndexName(
Index& index)
const;
280 std::string generateVectorName(
const std::string& t_name)
const;
282 void addIndexNames(
const std::string& name)
const;
284 void addVectorNames(
const std::string& name)
const;
286 void addIndexNames(
const std::vector<std::string>& names)
const;
288 void addVectorNames(
const std::vector<std::string>& names)
const;
291 Expr calculateTrace(csl::vector_expr tensors)
const;
297 inline Index::ID_type getID(std::string_view name)
const;
299 std::string getProperVectorName(
const std::string& initialName)
const;
302 std::string Space::getIndexName(
char spec)
const 304 return nameIndices[spec];
307 std::string_view Space::getIndexNameView(
char spec)
const 309 return nameIndices[spec];
312 char Space::getSpecFromIndexName(std::string
const& t_name)
const 314 if (specIndices.find(t_name) == specIndices.end()) {
315 constexpr
char maxChar = std::numeric_limits<char>::max();
318 if (nameIndices.find(c) == nameIndices.end()) {
319 nameIndices[c] = t_name;
320 specIndices[t_name] = c;
328 return specIndices[t_name];
341 void Space::resetIndexNumber()
const 343 availableIndices.clear();
344 defaultName = defaultIndexNames.begin();
347 void Space::refreshIndexName(
Index& index)
const 349 index.setID(getID(index.getName()));
352 Index::ID_type Space::getID(std::string_view t_name)
const 354 for (
size_t i = 0; i != availableIndices.size(); ++i)
355 if (availableIndices[i].first == t_name) {
356 return ++availableIndices[i].second;
358 availableIndices.push_back(make_pair(std::string(t_name), 0));
362 Index Space::generateSimilar(
const Index& model)
const {
363 Index newIndex = model;
364 refreshIndexName(newIndex);
369 return Index(t_name,
this,getID(t_name));
372 std::string Space::getNextIndexName()
const 374 auto iter = defaultName;
376 if (defaultName == defaultIndexNames.end())
377 defaultName = defaultIndexNames.begin();
385 std::vector<Index> Space::generateIndices(
size_t N)
const 387 std::vector<Index> indices(N);
388 for (
size_t i = 0; i != N; ++i)
394 std::vector<Index> Space::generateIndices(
396 const std::string& name
399 std::vector<Index> indices(N);
400 for (
size_t i = 0; i != N; ++i)
406 inline Expr DMinko = csl::constant_s(
"D", csl::int_s(4));
408 inline const Space& buildMinkowski()
414 matrix_s({{CSL_1,CSL_0,CSL_0,CSL_0},
415 {CSL_0,CSL_M_1,CSL_0,CSL_0},
416 {CSL_0,CSL_0,CSL_M_1,CSL_0},
417 {CSL_0,CSL_0,CSL_0,CSL_M_1}}),
418 {
"\\mu",
"\\nu",
"\\rho",
"\\sigma",
"\\lambda",
"\\tau"});
427 void fillEpsilonTensor(
Expr& tensor,
Namespace for csl library.
Definition: abreviation.h:34
int dim
Dimension of the space.
Definition: space.h:82
Index object that is used for indicial objects.
Definition: index.h:75
Space(const std::string &t_name, int t_dim, std::vector< std::string > const &indexNames={"i", "j", "k", "l"})
Initializes the name and the dimension of the space, no metric so only the kronecker delta is relevan...
Definition: space.cpp:27
Tensor delta
Kronecker delta, public attribute for readability in usage. Element i,j of the tensor is then accessi...
Definition: space.h:121
virtual std::string getName() const
Definition: space.cpp:162
const Space Euclid_R4("R4", 4)
Space .
int getDim() const
Definition: space.h:331
bool getSignedIndex() const
Definition: space.h:336
bool signedIndex
Property of indices: if true, it means that the metric is non trivial (given by the user at initializ...
Definition: space.h:89
Vector space that has a name, a dimension, a delta tensor and possibly a non-trivial metric...
Definition: space.h:64
Objects handling vectors, matrices and higher-dimensional tensors.
Expr generateVector(const std::string &t_name) const
Generates and returns a Vector in the right Space (itself) of name name, filled with Variable objects...
Definition: space.cpp:237
const Space Euclid_R2("R2", 2)
Space .
Index generateIndex() const
Generates and returns an index in the right Space (itself) of name defined by the program...
Definition: space.h:381
Tensor metric
Public attribute for readability in usage. Element i,j of the tensor is then accessible by space...
Definition: space.h:135
std::string name
Name of the vector space.
Definition: space.h:77
Objects handling indexed expressions in order to perform indicial tensor calculations.
virtual ~Space()
Destructor.
Definition: space.cpp:80
const Space Euclid_R3("R3", 3)
Space .
const Space & Minkowski
Space with a metric g = diag(-1,1,1,1).
Definition: space.h:448
Definition: indicial.h:675
Expression type/.
Definition: abstract.h:1573