Skip to content
Closed
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
d084423
Generalize ODE param list using symbolic dim
Jul 1, 2025
db3c270
000
Jul 1, 2025
986746d
000
Jul 2, 2025
4d90fe1
Standardize Clifford algebra support in Space type
Jul 3, 2025
decb5ca
Jasons comment fix
Jul 3, 2025
4644ec0
Fixed the other helpers
Jul 3, 2025
5269cd1
000
Jul 3, 2025
11eaa2b
000
Jul 3, 2025
edb9605
000
Jul 3, 2025
8f86213
000
Jul 3, 2025
2a3c2d3
Added more comments to Space.hs file
Jul 4, 2025
702f9ac
000
Jul 4, 2025
b839e9c
@JacquesCarette
Jul 4, 2025
723ef84
000
Jul 4, 2025
9abf5d3
Comments for new logic
Jul 4, 2025
3025eb5
Changed the vectNDS to ClifS
Jul 4, 2025
b584df6
000
Jul 7, 2025
dad1ff9
000
Jul 7, 2025
df26aab
fixed some clifs related stuff
Jul 7, 2025
58a8950
vector-based dblpend ODE
Jul 10, 2025
c3de4b7
Merge branch 'main' into CSchankGA
sarrasoussia Jul 10, 2025
d7b6f28
resovled some warnings
Jul 10, 2025
bbd95c6
build errors fix
Jul 10, 2025
0521708
000
Jul 10, 2025
c09e081
build errors kinda fixed
Jul 10, 2025
5ae98e2
000
Jul 15, 2025
c0f02aa
000
Jul 16, 2025
b9438d1
000
Jul 16, 2025
88ab96f
fixed derivation file to replace old tensions to mvforces
Jul 17, 2025
aa69081
fixed gamephysics datadef
Jul 17, 2025
973b0af
fixed build errors for dblpend and gamephysics
Jul 17, 2025
74c695a
The guide files and examples will be added later
Jul 17, 2025
cb7f09e
Fixed the Expression file to use Clifford operations
Jul 21, 2025
2cf75ea
Fixed mixed multivector and scalar operations
Jul 21, 2025
f6a9fd8
Fixed the HLint warnings about using record patterns for the ClifS
Jul 21, 2025
4b9f763
Fixed redundant bracket issues
Jul 21, 2025
c27c968
Fixed HLint errors
Jul 21, 2025
03d8348
GA implementation in the DblPend example
Jul 22, 2025
d3d043d
Proper clif implementation in Expressions
Jul 22, 2025
84ad7e3
Moved explanation to a seperate file
Jul 22, 2025
717a4c3
Dblpend expressions fixes
Jul 22, 2025
fc9f53e
Merge branch 'main' into CSchankGA
sarrasoussia Jul 24, 2025
ef71df2
000
Aug 18, 2025
296a1a7
explicit import fix
Aug 18, 2025
d005734
dblpend ODE fix
Aug 18, 2025
7932d10
cleaned code and created helper fct in physics.hs
Aug 18, 2025
750d737
Add enhanced dblpend example with Clifford algebra and abbreviation s…
Aug 19, 2025
73730eb
Fix VDim type issues across examples with realVect helper function
Aug 19, 2025
7a989c2
merge conflict fix
Aug 20, 2025
f574712
000
Aug 20, 2025
a892c0a
dblpend SRS modifs
Aug 20, 2025
3b79be8
Fix Clifford algebra integration issues
Aug 20, 2025
e45bf5b
Merge branch 'main' into CSchankGA
sarrasoussia Aug 20, 2025
f58a8e7
Fix hlint warnings
Aug 20, 2025
ca4f6a4
stable
Aug 21, 2025
1de11bd
hlint fix
Aug 21, 2025
6496563
build error fix
Aug 21, 2025
6716a06
error fix
Aug 21, 2025
0f5793c
error fix and file cleaning
Aug 21, 2025
2f2d762
code fixes
Aug 21, 2025
e52d4c9
fix
Aug 21, 2025
9bfa485
trigger CI rebuild with all fixes applied
Aug 21, 2025
d8b270d
drasil printers built success
Aug 22, 2025
25c2072
Fix HLint: use record patterns
Aug 22, 2025
7efc3dd
Fix HTML printer pattern match
Aug 22, 2025
e9d0354
Fix JSON printer patterns
Aug 22, 2025
dfcd714
Fix unused imports and name shadowing in ODELibraries.hs
Aug 22, 2025
15a1ff6
Fix unused imports and local bindings in dblpend ODEs and DataDefs
Aug 22, 2025
9f73b0f
Fix unused imports in example Unitals files
Aug 22, 2025
1d27129
Fix unused imports in dblpend Derivations.hs
Aug 22, 2025
56ba678
Fix unused imports in dblpend Body.hs
Aug 22, 2025
cf04af3
resolved unused imports
Aug 24, 2025
82a0599
dblpend concepts file modif
Aug 24, 2025
23823bc
improt fix
Aug 27, 2025
976a9d3
fixed CI error
Aug 27, 2025
5fc5882
restored Characteristics of Intended Reader section from dblpend SRS
Aug 28, 2025
f85552a
stable
Aug 28, 2025
080c7da
merge main
Sep 9, 2025
38750d8
merge fix
Sep 9, 2025
495520b
Fix dblpend GA UID clash; expose GA IdeaDicts for sglpend
Sep 11, 2025
aea893e
fixed velocities and accelerations formulas
Sep 13, 2025
a65ada1
refix equations of acceleration
Sep 13, 2025
615a1fa
force datadef table fix
Sep 14, 2025
b291a7d
cleaned useless methods in expressions
Sep 14, 2025
e53b68b
stable
Sep 14, 2025
023272f
removed extra lines
Sep 14, 2025
b24dd3d
final equations expression fix
Sep 14, 2025
9a7aa46
hlint fix
Sep 14, 2025
5b728ca
stable
Sep 14, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ module Data.Drasil.ExternalLibraries.ODELibraries (
odeintPckg, odeintSymbols
) where

import Language.Drasil (HasSymbol(symbol), HasUID(uid), MayHaveUnit(getUnit),
QuantityDict, HasSpace(typ), Space (Actor, Natural, Real, Void, Boolean, String, Array, Vect), implVar,
implVarUID, implVarUID', qw, compoundPhrase, nounPhrase, nounPhraseSP, label,
sub, Idea(getA), NamedIdea(term), Stage(..), (+++))
import Language.Drasil hiding (dim)
import Language.Drasil.Space (ClifKind(..), Dimension(..))
import Language.Drasil.Display (Symbol(Label, Concat))

import Language.Drasil.Code (Lang(..), ExternalLibrary, Step, Argument,
Expand All @@ -39,8 +37,8 @@ import Language.Drasil.Code (Lang(..), ExternalLibrary, Step, Argument,
mkODELibNoPath, pubStateVar, privStateVar,
NamedArgument, narg)

import Drasil.Code.CodeExpr
import Drasil.Code.CodeExpr.Development
import Drasil.Code.CodeExpr hiding (dim)
import qualified Drasil.Code.CodeExpr.Development as CE

import Control.Lens ((^.), _1, _2, over)

Expand Down Expand Up @@ -431,6 +429,11 @@ computeDerivatives = quantfunc $ implVar "computeDerivatives_apache" (nounPhrase
odeintPckg :: ODELibPckg
odeintPckg = mkODELib "odeint" "v2" odeint odeintCall "." [Cpp]

-- | Symbolic dimension used for vector-valued ODE variables.
-- Allows examples to specialize this to "2", "3", etc., while keeping library code generic.
dim :: String
dim = "n"

odeint :: ExternalLibrary
odeint = externalLib [
choiceSteps [
Expand All @@ -444,15 +447,20 @@ odeint = externalLib [
customObjArg [] "Class representing an ODE system" ode odeCtor
(customClass [constructorInfo odeCtor [] [],
methodInfoNoReturn odeOp "function representation of ODE system"
[unnamedParam (Vect Real), unnamedParam (Vect Real), lockedParam t]
-- | ODE parameters: generalized for vectors of symbolic dimension 'dim'.
-- TODO: Once ClifS is integrated, revisit this to allow symbolic multivectors as parameter types.
-- Likely replacement: ClifS dim Real instead of ClifS (VDim dim) Multivector Real.
[unnamedParam (ClifS (VDim dim) Multivector Real), unnamedParam (ClifS (VDim dim) Multivector Real), lockedParam t]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be Vector rather than Multivector

[assignArrayIndex]]),
-- [unnamedParam (ClifS (VDim dim) Multivector Real), unnamedParam (ClifS (VDim dim) Multivector Real), lockedParam t]
-- [assignArrayIndex]]),
-- Need to declare variable holding initial value because odeint will update this variable at each step
preDefinedArg odeintCurrVals,
inlineArg Real, inlineArg Real, inlineArg Real,
customObjArg []
"Class for populating a list during an ODE solution process"
pop popCtor (customClass [
constructorInfo popCtor [unnamedParam (Vect Real)] [],
constructorInfo popCtor [unnamedParam (ClifS (VDim dim) Multivector Real)] [],
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also Vector?

methodInfoNoReturn popOp
"appends solution point for current ODE solution step"
[lockedParam y, lockedParam t] [appendCurrSol (sy y)]])]]
Expand Down Expand Up @@ -497,7 +505,7 @@ odeintCurrVals, rk, stepper, pop :: CodeVarChunk
odeintCurrVals = quantvar $ implVar "currVals_odeint" (nounPhrase
"vector holding ODE solution values for the current step"
"vectors holding ODE solution values for the current step")
(Vect Real) (label "currVals")
(ClifS (VDim dim) Multivector Real) (label "currVals")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also Vector ?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I won't continue pointing those out, they should all be reviewed)

rk = quantvar $ implVar "rk_odeint" (nounPhrase
"stepper for solving ODE system using Runge-Kutta-Dopri5 method"
"steppers for solving ODE system using Runge-Kutta-Dopri5 method")
Expand Down Expand Up @@ -556,7 +564,7 @@ t = quantvar $ implVar "t_ode" (nounPhrase
y = quantvar $ implVar "y_ode" (nounPhrase
"current dependent variable value in ODE solution"
"current dependent variable value in ODE solution")
(Vect Real) (label "y")
(ClifS (VDim dim) Multivector Real) (label "y")

-- | ODE object constructor.
odeCtor :: CodeFuncChunk
Expand Down Expand Up @@ -586,35 +594,36 @@ diffCodeChunk c = quantvar $ implVarUID' (c +++ "d" )
modifiedODESyst :: String -> ODEInfo -> [CodeExpr]
modifiedODESyst sufx info = map replaceDepVar (odeSyst info)
where
replaceDepVar cc@(C c) | c == depVar info ^. uid = C $ depVar info +++ ("_" ++ sufx)
replaceDepVar cc@(CE.C c) | c == depVar info ^. uid = CE.C $ depVar info +++ ("_" ++ sufx)
| otherwise = cc
replaceDepVar (AssocA a es) = AssocA a (map replaceDepVar es)
replaceDepVar (AssocB b es) = AssocB b (map replaceDepVar es)
replaceDepVar (FCall u es nes) = FCall u (map replaceDepVar es)
replaceDepVar (CE.AssocA a es) = CE.AssocA a (map replaceDepVar es)
replaceDepVar (CE.AssocB b es) = CE.AssocB b (map replaceDepVar es)
replaceDepVar (CE.FCall u es nes) = CE.FCall u (map replaceDepVar es)
(map (over _2 replaceDepVar) nes)
replaceDepVar (New u es nes) = New u (map replaceDepVar es)
replaceDepVar (CE.New u es nes) = CE.New u (map replaceDepVar es)
(map (over _2 replaceDepVar) nes)
replaceDepVar (Message au mu es nes) = Message au mu (map replaceDepVar es)
replaceDepVar (CE.Message au mu es nes) = CE.Message au mu (map replaceDepVar es)
(map (over _2 replaceDepVar) nes)
replaceDepVar (Case c cs) = Case c (map (over _1 replaceDepVar) cs)
replaceDepVar (Matrix es) = Matrix $ map (map replaceDepVar) es
replaceDepVar (UnaryOp u e) = UnaryOp u $ replaceDepVar e
replaceDepVar (UnaryOpB u e) = UnaryOpB u $ replaceDepVar e
replaceDepVar (UnaryOpVV u e) = UnaryOpVV u $ replaceDepVar e
replaceDepVar (UnaryOpVN u e) = UnaryOpVN u $ replaceDepVar e
replaceDepVar (ArithBinaryOp b e1 e2) = ArithBinaryOp b
replaceDepVar (CE.Case c cs) = CE.Case c (map (over _1 replaceDepVar) cs)
replaceDepVar (CE.Matrix es) = CE.Matrix $ map (map replaceDepVar) es
replaceDepVar (CE.UnaryOp u e) = CE.UnaryOp u $ replaceDepVar e
replaceDepVar (CE.UnaryOpB u e) = CE.UnaryOpB u $ replaceDepVar e
-- TODO: When ClifS or multivectors are introduced, add support for UnaryOpCC and UnaryOpCN here.
replaceDepVar (CE.UnaryOpCC u e) = CE.UnaryOpCC u $ replaceDepVar e
replaceDepVar (CE.UnaryOpCN u e) = CE.UnaryOpCN u $ replaceDepVar e
replaceDepVar (CE.ArithBinaryOp b e1 e2) = CE.ArithBinaryOp b
(replaceDepVar e1) (replaceDepVar e2)
replaceDepVar (BoolBinaryOp b e1 e2) = BoolBinaryOp b
replaceDepVar (CE.BoolBinaryOp b e1 e2) = CE.BoolBinaryOp b
(replaceDepVar e1) (replaceDepVar e2)
replaceDepVar (EqBinaryOp b e1 e2) = EqBinaryOp b
replaceDepVar (CE.EqBinaryOp b e1 e2) = CE.EqBinaryOp b
(replaceDepVar e1) (replaceDepVar e2)
replaceDepVar (LABinaryOp b e1 e2) = LABinaryOp b
replaceDepVar (CE.LABinaryOp b e1 e2) = CE.LABinaryOp b
(replaceDepVar e1) (replaceDepVar e2)
replaceDepVar (OrdBinaryOp b e1 e2) = OrdBinaryOp b
replaceDepVar (CE.OrdBinaryOp b e1 e2) = CE.OrdBinaryOp b
(replaceDepVar e1) (replaceDepVar e2)
replaceDepVar (VVNBinaryOp b e1 e2) = VVNBinaryOp b
replaceDepVar (CE.CCNBinaryOp b e1 e2) = CE.CCNBinaryOp b
(replaceDepVar e1) (replaceDepVar e2)
replaceDepVar (VVVBinaryOp b e1 e2) = VVVBinaryOp b
replaceDepVar (CE.CCCBinaryOp b e1 e2) = CE.CCCBinaryOp b
(replaceDepVar e1) (replaceDepVar e2)
replaceDepVar (Operator ao dd e) = Operator ao dd $ replaceDepVar e
replaceDepVar (CE.Operator ao dd e) = CE.Operator ao dd $ replaceDepVar e
replaceDepVar e = e
4 changes: 2 additions & 2 deletions code/drasil-code/lib/Language/Drasil/Chunk/Parameter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ instance Eq ParameterChunk where c1 == c2 = (c1 ^. uid) == (c2 ^. uid)
-- | Finds the units of the 'CodeChunk' used to make the 'ParameterChunk'.
instance MayHaveUnit ParameterChunk where getUnit = getUnit . view pcc

-- | Automatically chooses 'PassBy' based on 'Space' ('Vect'ors and 'Actor's passed by reference).
-- | Automatically chooses 'PassBy' based on 'Space' ('Clif's and 'Actor's passed by reference).
pcAuto :: (CodeIdea c) => c -> ParameterChunk
pcAuto c = PC cdch (choosePB $ cdch ^. typ)
where cdch = codeChunk c
choosePB (Vect _) = Ref
choosePB (ClifS {}) = Ref
choosePB (Actor _) = Ref
choosePB _ = Val

Expand Down
17 changes: 12 additions & 5 deletions code/drasil-code/lib/Language/Drasil/Code/Code.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ module Language.Drasil.Code.Code (
spaceToCodeType
) where

import qualified Language.Drasil as S (Space(..))

import qualified Language.Drasil.Space as S (Space(..), ClifKind(..))
import Drasil.GOOL (CodeType(..))

import Text.PrettyPrint.HughesPJ (Doc)
Expand All @@ -15,6 +14,9 @@ import Data.List.NonEmpty (toList)
newtype Code = Code { unCode :: [(FilePath, Doc)]}

-- | Default mapping between 'Space' and 'CodeType'.
-- TODO: For now, ClifS is rendered like Vect (i.e., as a list).
-- This does not support full GA structure (e.g., blades, bivectors, matrices).
-- Matrix <-> ClifS representation is unclear and deferred.
spaceToCodeType :: S.Space -> [CodeType]
spaceToCodeType S.Integer = [Integer]
spaceToCodeType S.Natural = [Integer]
Expand All @@ -23,12 +25,17 @@ spaceToCodeType S.Rational = [Double, Float]
spaceToCodeType S.Boolean = [Boolean]
spaceToCodeType S.Char = [Char]
spaceToCodeType S.String = [String]
spaceToCodeType (S.Vect s) = map List (spaceToCodeType s)
spaceToCodeType (S.ClifS _ kind s) = case kind of
S.Scalar -> spaceToCodeType s
S.Vector -> map List (spaceToCodeType s)
S.Bivector -> map List (spaceToCodeType s)
S.Multivector -> map (List . List) (spaceToCodeType s)
spaceToCodeType (S.Matrix _ _ s) = map (List . List) (spaceToCodeType s)
spaceToCodeType (S.Set s) = map List (spaceToCodeType s)
spaceToCodeType (S.Array s) = map Array (spaceToCodeType s)
spaceToCodeType (S.Actor s) = [Object s]
spaceToCodeType S.Void = [Void]
spaceToCodeType (S.Function i t) = [Func is ts | is <- ins, ts <- trgs]
where trgs = spaceToCodeType t
ins = map spaceToCodeType (toList i)
where trgs = spaceToCodeType t
ins = map spaceToCodeType (toList i)

Loading