Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions src/Basic.wl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ GetProject::usage = "GetProject[] returns the project name used in code generati

SetProject::usage = "SetProject[name] sets the project name used in code generation.";

GetDefaultManifold::usage = "GetDefaultManifold[] returns the first defined manifold. Returns $Failed if no manifolds have been defined.";

GetDefaultChart::usage = "GetDefaultChart[] returns the default coordinate chart of the first defined manifold.";

GetDim::usage = "GetDim[] returns the dimension of the first defined manifold.";
Expand Down Expand Up @@ -205,11 +207,39 @@ SetProject[name_] :=

Protect[SetProject];

GetDefaultManifold[] :=
Module[{},
If[Length[$Manifolds] === 0,
Message[GetDefaultManifold::NoManifolds];
Return[$Failed]
,
Return[$Manifolds[[1]]]
]
];

GetDefaultManifold::NoManifolds = "No manifolds have been defined. Use DefManifold to define a manifold.";

Protect[GetDefaultManifold];

GetDefaultChart[] :=
Return[ChartsOfManifold[$Manifolds[[1]]][[1]]];
Module[{manifold = GetDefaultManifold[]},
If[manifold === $Failed,
Return[$Failed],
Return[ChartsOfManifold[manifold][[1]]]
]
];

Protect[GetDefaultChart];

GetDim[] :=
Return[DimOfManifold[$Manifolds[[1]]]];
Module[{manifold = GetDefaultManifold[]},
If[manifold === $Failed,
Return[$Failed],
Return[DimOfManifold[manifold]]
]
];

Protect[GetDim];

IsDefined[term_] :=
Module[{head = Head[term]},
Expand Down
2 changes: 1 addition & 1 deletion src/Varlist.wl
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ ParseVarlist::ESymmetryType = "Symmetry type of the `1`-th var, `2`, in varlist
Protect[ParseVarlist];

DefineTensor[varname_, symmetry_, printname_] :=
Module[{manifold = $Manifolds[[1]]},
Module[{manifold = GetDefaultManifold[]},
If[symmetry =!= Null && StringLength[printname] > 0,
DefTensor[varname, manifold, symmetry, PrintAs -> printname]
,
Expand Down
66 changes: 66 additions & 0 deletions test/unit/BasicTests.wl
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,44 @@ AppendTo[$AllTests,
]
];

(* ========================================= *)
(* Test: GetDefaultManifold *)
(* ========================================= *)

AppendTo[$AllTests,
VerificationTest[
(* GetDefaultManifold should return a symbol when manifolds exist *)
Module[{result = GetDefaultManifold[]},
Head[result] === Symbol && MemberQ[$Manifolds, result]
],
True,
TestID -> "GetDefaultManifold-ReturnsFirstManifold"
]
];

AppendTo[$AllTests,
VerificationTest[
(* GetDefaultManifold should return the first manifold in $Manifolds *)
GetDefaultManifold[] === $Manifolds[[1]],
True,
TestID -> "GetDefaultManifold-ReturnsFirstInList"
]
];

AppendTo[$AllTests,
VerificationTest[
(* GetDefaultManifold should return $Failed when no manifolds exist *)
Module[{savedManifolds = $Manifolds, result},
Block[{$Manifolds = {}},
result = Quiet[GetDefaultManifold[]];
result === $Failed
]
],
True,
TestID -> "GetDefaultManifold-EmptyManifolds-ReturnsFailed"
]
];

(* ========================================= *)
(* Test: GetDefaultChart *)
(* ========================================= *)
Expand All @@ -188,6 +226,20 @@ AppendTo[$AllTests,
]
];

AppendTo[$AllTests,
VerificationTest[
(* GetDefaultChart should return $Failed when no manifolds exist *)
Module[{savedManifolds = $Manifolds, result},
Block[{$Manifolds = {}},
result = Quiet[GetDefaultChart[]];
result === $Failed
]
],
True,
TestID -> "GetDefaultChart-EmptyManifolds-ReturnsFailed"
]
];

(* ========================================= *)
(* Test: GetDim *)
(* ========================================= *)
Expand All @@ -203,6 +255,20 @@ AppendTo[$AllTests,
]
];

AppendTo[$AllTests,
VerificationTest[
(* GetDim should return $Failed when no manifolds exist *)
Module[{savedManifolds = $Manifolds, result},
Block[{$Manifolds = {}},
result = Quiet[GetDim[]];
result === $Failed
]
],
True,
TestID -> "GetDim-EmptyManifolds-ReturnsFailed"
]
];

(* Reset to clean state - all modified variables *)
SetPVerbose[False];
SetPrintDate[False];
Expand Down