Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix bugs in simplifier and numerical solver; now simplified code runs…

… correctly through to specified end time.
  • Loading branch information...
commit c3d85c75fe9284cb1f36f4a478ba2561f5b4ce79 1 parent b15ec1c
@A1kmm authored
View
5 cellml12/Data/CellML12/ModelSolver.hs
@@ -954,7 +954,7 @@ tryFurtherSimplifications (assertions, _) = do
toMaybeSubst (Assertion
((WithMaybeSemantics _ (WithCommon _ (Apply eq [arg1, arg2]))),
AssertionContext m))
- | opIs "relation1" "eq" eq =
+ | opIs "relation1" "eq" eq =
case (extractCI (stripSemCom arg1), extractConstant (stripSemCom arg2),
extractCI (stripSemCom arg2), extractConstant (stripSemCom arg1)) of
(Just n, Just c, _, _) |
@@ -962,10 +962,12 @@ toMaybeSubst (Assertion
(_, _, Just n, Just c) |
Just (_, Just u, v) <- M.lookup n m -> Just (v, (c, u))
_ -> Nothing
+toMaybeSubst _ = Nothing
extractCI (ASTCi (Ci n)) = Just n
extractCI _ = Nothing
extractConstant (Cn cp) = Just (cpToDouble cp)
+extractConstant _ = Nothing
substituteInMaths m sm ex = transformBi (substituteVariable m sm) ex
substituteVariable m sm ex@(ASTCi (Ci n))
@@ -1022,7 +1024,6 @@ simplifyMathAST m (Apply op@(WithMaybeSemantics _ (WithCommon _ (Csymbol (Just c
let otherwise = listToMaybe . mapMaybe (extractPiecewiseOtherwise . stripSemCom) $ ops'
let pieces' = filter (\(_, x) -> not (isConstantBool (noSemCom x)) || toConstantBool (noSemCom x)) pieces
let defpieces = filter (isConstantBool . noSemCom . snd) pieces'
- Debug.Trace.trace "In piecewise simplifier" (return ())
return $ case (defpieces, pieces', otherwise) of
-- If there is a piece that is always true, use it.
((ex, _):_, _, _) -> ex
View
2  cellml12/Data/CellML12/ToSimplifiedModel.hs
@@ -50,7 +50,7 @@ buildAssertions m comps unitsTable typeTable varMap =
comp = withoutCommon . iComponent $ icomp
variableToContextPart (WithCommon _ v) =
(variableName v, (typeTable ! (cp, variableName v),
- M.lookup (cp, variableName v) unitsTable,
+ variableUnits v >>= \x -> M.lookup (cp, x) unitsTable,
varMap ! (cp, variableName v)))
assertVarMap = M.fromList $ map variableToContextPart (componentVariables comp)
in
View
10 cellml12/ccode/cellml12-solver-protocol.h
@@ -254,19 +254,23 @@ int main(int argc, char** argv)
IDAInit(idaProblem, compute_residuals, tStart, yvec, ypvec);
IDASStolerances(idaProblem, relTol, absTol);
IDASpgmr(idaProblem, 0);
-
+ IDASetStopTime(idaProblem, tEnd);
// TODO: IDARootInit for piecewise changes...
- while (IDASolve(idaProblem, tEnd, &tActual, yvec, ypvec, IDA_ONE_STEP) == IDA_SUCCESS)
+ while (1)
{
+ solret = IDASolve(idaProblem, tEnd, &tActual, yvec, ypvec, IDA_ONE_STEP);
+ if (solret != IDA_SUCCESS && solret != IDA_TSTOP_RETURN)
+ break;
+
/* Send NumericalData */
byte = 2;
write_fully(1, &byte);
work[0] = tActual;
write_fully(NWORK * sizeof(double), work);
- if (tEnd - tActual >= fabs(1E-6 * (tEnd - tStart)))
+ if (tEnd - tActual <= fabs(1E-6 * (tEnd - tStart)))
{
wasSuccess = 1;
break;
Please sign in to comment.
Something went wrong with that request. Please try again.