Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
702851c
Scripts: clean up more stuff.
agarny Jul 23, 2025
b79d899
Compiler: added JavaScript support.
agarny Jul 16, 2025
bb070ac
libCellML: use commit 04d8d15.
agarny Jul 17, 2025
7c59aa8
Compiler: only generate optimised code.
agarny Jul 17, 2025
cf6ff72
Removed some solver-specific methods from src/misc/utils.[cpp|h].
agarny Jul 22, 2025
9ad87af
Utils: use std::cout rather than printf().
agarny Jul 22, 2025
df02eeb
Utils: moved our printIssues() method to the general utils.
agarny Jul 22, 2025
9a1e936
C++: use `std::make_unique<clang:XXX>` rather than `new clang:XXX`.
agarny Jul 23, 2025
e9c35ab
Compiler: some minor cleaning up.
agarny Jul 23, 2025
40518c6
C++: replaced std::endl with "\n".
agarny Jul 22, 2025
a770e49
Some minor cleaning up.
agarny Jul 17, 2025
a601488
JavaScript: formatting.
agarny Jul 17, 2025
65da03a
Don't allow models to be interpreted anymore.
agarny Jul 17, 2025
e9c61a7
CellML file runtime: some minor cleaning up.
agarny Jul 24, 2025
80a5e7d
Compiler: compile some C code to WASM.
agarny Jul 21, 2025
2eef020
Emscripten: disable assertions.
agarny Jul 24, 2025
d015b2e
JavaScript playground: revisited the way we handle issues.
agarny Jul 25, 2025
1189fc6
JavaScript: updated our simulation-related tests.
agarny Jul 25, 2025
1347e04
Compiler: reuse the first part of our compilation code.
agarny Jul 27, 2025
fc68e6b
Tests: some minor cleaning up.
agarny Jul 28, 2025
bb5738d
Simplified (and improved) the implementation of our nlaSolve() method.
agarny Jul 28, 2025
3d6863a
JavaScript: added support for NLA/DAE models.
agarny Jul 31, 2025
bca8529
Improved our nlaSolverAddress() method.
agarny Jul 31, 2025
a429234
Utils: some minor cleaning up.
agarny Jul 31, 2025
f7e3ab1
Make code analysis happy.
agarny Jul 31, 2025
bb579f5
Make code coverage happy.
agarny Jul 31, 2025
bc4b19e
JavaScript: don't need to export `stringToUTF8` and `lengthBytesUTF8`…
agarny Jul 31, 2025
c11a4f5
Documentation: some minor cleaning up.
agarny Jul 31, 2025
291ec7b
Some minor cleaning up.
agarny Jul 31, 2025
59683ff
JavaScript: added the use of precision to our float point tests.
agarny Aug 1, 2025
236f6ce
Tests: improved the way we expect values in C++ and Python.
agarny Aug 1, 2025
3bc3984
Added a test for our extra mathematical operators and constants.
agarny Aug 1, 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
6 changes: 3 additions & 3 deletions cmake/base64encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ int main(int pArgC, char *pArgV[])
// Convert the given file to a base64-encoded string.

if (pArgC != 2) {
std::cerr << "Usage: " << pArgV[0] << " <file>" << std::endl;
std::cerr << "Usage: " << pArgV[0] << " <file>\n";

return 1;
}
Expand All @@ -37,7 +37,7 @@ int main(int pArgC, char *pArgV[])
file.read(buffer, fileSize);

if (!file) {
std::cerr << "Error: the file could not be read." << std::endl;
std::cerr << "Error: the file could not be read.\n";

return 1;
}
Expand All @@ -48,7 +48,7 @@ int main(int pArgC, char *pArgV[])

modp_b64_encode(base64, buffer, fileSize);

std::cout << base64 << std::endl;
std::cout << base64 << "\n";

delete[] base64;
delete[] buffer;
Expand Down
4 changes: 2 additions & 2 deletions cmake/packages.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@ function(retrieve_package PACKAGE_NAME PACKAGE_VERSION PACKAGE_REPOSITORY RELEAS
set(PACKAGE_URL "https://github.com/opencor/${PACKAGE_REPOSITORY}/releases/download/${RELEASE_TAG}/${PACKAGE_FILE}")

if("${PACKAGE_NAME}" STREQUAL "libCellML")
#---GRY--- THIS IS TEMPORARY UNTIL libCellML HAS AN OFFICIAL RELEASE WITH THE INTERPRETER.
#---GRY--- USE THIS VERSION OF libCellML WHICH CORRESPONDS TO PR #1256 UNTIL IT GETS MERGED IN.

set(PACKAGE_URL "https://github.com/agarny/${PACKAGE_REPOSITORY}/releases/download/707e211/${PACKAGE_FILE}")
set(PACKAGE_URL "https://github.com/agarny/${PACKAGE_REPOSITORY}/releases/download/04d8d15/${PACKAGE_FILE}")
endif()

set(ATTEMPT 1)
Expand Down
7 changes: 2 additions & 5 deletions scripts/genericclean
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ fi

appDir=$(cd $(dirname $0); pwd)/..

for i in _skbuild build src/bindings/python/libopencor.egg-info tests/install/build; do
rm -fr $appDir/$i
done

find $appDir -name .DS_Store -exec rm -f {} \;
find $appDir -type f -name .DS_Store -exec rm -f {} \; 2> /dev/null
find $appDir -type d \( -name .pytest_cache -o -name __pycache__ -o -name _skbuild -o -name build \) -exec rm -fr {} \; 2> /dev/null

if [ "$1" = "all" ]; then
rm -fr $appDir/prebuilt/* > /dev/null 2>&1
Expand Down
4 changes: 3 additions & 1 deletion scripts/genericclean.bat
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ IF "%1" == "all" (
SET AppDir=%~dp0..\
SET OrigDir=!CD!

FOR /D %%I IN (_skbuild build src\bindings\python\libopencor.egg-info tests\install\build) DO IF EXIST !AppDir!%%I RMDIR /S /Q !AppDir!%%I
FOR /R "%AppDir%" %%d IN (.pytest_cache __pycache__ _skbuild build) DO (
IF EXIST "%%d" RMDIR /S /Q "%%d"
)

IF "%1" == "all" (
IF EXIST !AppDir!prebuilt (
Expand Down
18 changes: 9 additions & 9 deletions src/3rdparty/libCellML/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,49 +34,49 @@ if(LIBOPENCOR_PREBUILT_LIBCELLML OR ONLY_BUILD_JAVASCRIPT_THIRD_PARTY_LIBRARIES)
if(EMSCRIPTEN)
retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION}
${PACKAGE_REPOSITORY} ${RELEASE_TAG}
e6e9bfdc883280289aa6131598b617b54672ae72)
13a93a71d210b4ec3af336180f5d386b1e6d44c9)
else()
if(WIN32)
if(RELEASE_MODE)
if(INTEL_MODE)
retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION}
${PACKAGE_REPOSITORY} ${RELEASE_TAG}
c688813b383c5759cb4982c1d6737f0fa0d68462)
25c2e2dd016a47e9fff6a81b610de7be6cdb6bbc)
else()
retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION}
${PACKAGE_REPOSITORY} ${RELEASE_TAG}
a1cab436551c576ab8d1bd16b6156e246134b733)
bb4b2e898776d03abd0644e2662d97034725f8d7)
endif()
else()
if(INTEL_MODE)
retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION}
${PACKAGE_REPOSITORY} ${RELEASE_TAG}
9623a3a236f4eadd9a9e7614b66fad916f07ea1d)
526cfc4d623af35081c37e865f37b856cd39fe0a)
else()
retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION}
${PACKAGE_REPOSITORY} ${RELEASE_TAG}
d486630d09a245f8b35670304f259019afb70fc9)
770ac1735960bf4d01564fee6a09ff33a62486ab)
endif()
endif()
elseif(APPLE)
if(INTEL_MODE)
retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION}
${PACKAGE_REPOSITORY} ${RELEASE_TAG}
62768aa55bea80757378c706cb190043173991fb)
836e28f4bce436fbee88f109a4f050b9e4dd68f6)
else()
retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION}
${PACKAGE_REPOSITORY} ${RELEASE_TAG}
c80100db4e298acc5a1e2ea06c71c7b2766e49d4)
555c258f6541ca7c51c54445a02386c5a619d754)
endif()
else()
if(INTEL_MODE)
retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION}
${PACKAGE_REPOSITORY} ${RELEASE_TAG}
1ce868ce9918deb8972f869f63817cbfbf6a411e)
0842347a0a7abf4c6350aa44a6142ad5ba22a397)
else()
retrieve_package(${PACKAGE_NAME} ${PACKAGE_VERSION}
${PACKAGE_REPOSITORY} ${RELEASE_TAG}
deb06fa9adcae7a786f8150e3fa77aafa175e297)
235fb4aa20bc3dde6ad28483775f2e41e9a093ef)
endif()
endif()
endif()
Expand Down
25 changes: 8 additions & 17 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ set(API_MODULE_FILE ${GIT_API_MODULE_FILE})

set(INTERNAL_SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/file/filemanager.cpp
${CMAKE_CURRENT_SOURCE_DIR}/misc/compiler.cpp
${CMAKE_CURRENT_SOURCE_DIR}/misc/utils.cpp
${CMAKE_CURRENT_SOURCE_DIR}/solver/solver.cpp
${CMAKE_CURRENT_SOURCE_DIR}/solver/solvercvode.cpp
Expand All @@ -148,12 +149,6 @@ set(INTERNAL_SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/support/sedml/sedmlfile.cpp
)

if(NOT EMSCRIPTEN)
list(APPEND INTERNAL_SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/misc/compiler.cpp
)
endif()

set(GIT_API_SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/file/file.cpp
${CMAKE_CURRENT_SOURCE_DIR}/file/filemanager.cpp
Expand Down Expand Up @@ -214,6 +209,8 @@ set(SOURCE_FILES
)

set(INTERNAL_HEADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/misc/compiler_p.h
${CMAKE_CURRENT_SOURCE_DIR}/misc/compiler.h
${CMAKE_CURRENT_SOURCE_DIR}/misc/utils.h
${CMAKE_CURRENT_SOURCE_DIR}/solver/solver_p.h
${CMAKE_CURRENT_SOURCE_DIR}/solver/solvercvode_p.h
Expand All @@ -236,13 +233,6 @@ set(INTERNAL_HEADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/unittestingexport.h
)

if(NOT EMSCRIPTEN)
list(APPEND INTERNAL_HEADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/misc/compiler_p.h
${CMAKE_CURRENT_SOURCE_DIR}/misc/compiler.h
)
endif()

set(GIT_HEADER_FILES
${INTERNAL_HEADER_FILES}
${THIRD_PARTY_HEADER_FILES}
Expand Down Expand Up @@ -281,9 +271,10 @@ if(EMSCRIPTEN)

# Set the flags for our generated .js file.
# Note #1: we use -O3 to get the best performance, -sALLOW_MEMORY_GROWTH to allow the memory to grow dynamically,
# -sEXPORT_ES6=1 to export ES6 classes, -sEXPORTED_FUNCTIONS to export the functions we need,
# -sINLINING_LIMIT to increase the inlining limit, -sSINGLE_FILE=1 to generate a single file, -sSTACK_SIZE
# to increase the stack size, and --bind to generate the necessary bindings.
# -sASSERTIONS=0 to disable assertions (which are not needed in production), -sEXPORT_ES6=1 to export ES6
# classes, -sEXPORTED_FUNCTIONS to export the functions we need, -sINLINING_LIMIT to increase the inlining
# limit, -sSINGLE_FILE=1 to generate a single file, -sSTACK_SIZE to increase the stack size, and --bind to
# generate the necessary bindings.
# Note #2: by default, Emscripten uses 64KB of stack, but this is not enough for "complex" models such as the Zhang
# et al. model (see https://github.com/agarny/COR/blob/master/Models/zhang_SAN_model_2000_all.cellml). For
# that model, we need about 108KB of stack. However, Emscripten originally used to use 5MB of stack (see
Expand All @@ -301,7 +292,7 @@ if(EMSCRIPTEN)

set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES
COMPILE_FLAGS "-O3"
LINK_FLAGS "-O3 -sALLOW_MEMORY_GROWTH -sEXPORT_ES6=1 -sEXPORTED_FUNCTIONS=[_malloc,_free] -sEXPORTED_RUNTIME_METHODS=HEAPU8 -sINLINING_LIMIT -sSINGLE_FILE=1 -sSTACK_SIZE=4MB --bind")
LINK_FLAGS "-O3 -sALLOW_MEMORY_GROWTH -sASSERTIONS=0 -sEXPORT_ES6=1 -sEXPORTED_FUNCTIONS=[_malloc,_free] -sEXPORTED_RUNTIME_METHODS=HEAPU8 -sINLINING_LIMIT -sSINGLE_FILE=1 -sSTACK_SIZE=4MB --bind")

# Create a .tgz file for our generated .js file that can be used to distribute our JavaScript bindings.

Expand Down
7 changes: 0 additions & 7 deletions src/api/libopencor/seddocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,17 +320,10 @@ class LIBOPENCOR_EXPORT SedDocument: public Logger
*
* Create an instance of this simulation experiment description.
*
* @param pCompiled Whether the instance of this simulation experiment description is to be compiled (as opposed to
* being interpreted).
*
* @return A smart pointer to a @ref SedInstance object.
*/

#ifdef __EMSCRIPTEN__
SedInstancePtr instantiate();
#else
SedInstancePtr instantiate(bool pCompiled = true);
#endif

private:
class Impl; /**< Forward declaration of the implementation class, @private. */
Expand Down
2 changes: 1 addition & 1 deletion src/api/libopencor/sedinstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class LIBOPENCOR_EXPORT SedInstance: public Logger
private:
class Impl; /**< Forward declaration of the implementation class, @private. */

explicit SedInstance(const SedDocumentPtr &pDocument, bool pCompiled); /**< Constructor @private. */
explicit SedInstance(const SedDocumentPtr &pDocument); /**< Constructor @private. */

Impl *pimpl(); /**< Private implementation pointer, @private. */
const Impl *pimpl() const; /**< Constant private implementation pointer, @private. */
Expand Down
2 changes: 1 addition & 1 deletion src/api/libopencor/sedinstancetask.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ class LIBOPENCOR_EXPORT SedInstanceTask: public Logger
private:
class Impl; /**< Forward declaration of the implementation class, @private. */

explicit SedInstanceTask(const SedAbstractTaskPtr &pTask, bool pCompiled); /**< Constructor @private. */
explicit SedInstanceTask(const SedAbstractTaskPtr &pTask); /**< Constructor @private. */

Impl *pimpl(); /**< Private implementation pointer, @private. */
const Impl *pimpl() const; /**< Constant private implementation pointer, @private. */
Expand Down
12 changes: 8 additions & 4 deletions src/api/libopencor/solvernla.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class LIBOPENCOR_EXPORT SolverNla: public Solver
friend class SedSimulation;

public:
using ComputeSystem = void (*)(double *pU, double *pF, void *pUserData); /**< Signature of the method that computes the system of NLA equations. */
using ComputeObjectiveFunction = void (*)(double *pU, double *pF, void *pUserData); /**< Signature of the method that computes the objective function of the NLA system. */

/**
* Constructors, destructor, and assignment operators.
Expand All @@ -54,15 +54,19 @@ class LIBOPENCOR_EXPORT SolverNla: public Solver
*
* Solve the NLA system.
*
* @param pComputeSystem The method that computes the system of NLA equations.
* @param pComputeObjectiveFunction The method that computes the objective function of the NLA system.
* @param pU The initial guess for the solution of the NLA system.
* @param pN The number of variables in the NLA system.
* @param pUserData Some user data that may be passed to @p pComputeSystem.
* @param pUserData User data, if any, that are passed to @p pComputeObjectiveFunction.
*
* @return @c true if the NLA system could be solved, @c false otherwise.
*/

bool solve(ComputeSystem pComputeSystem, double *pU, size_t pN, void *pUserData);
#ifdef __EMSCRIPTEN__
bool solve(size_t pComputeObjectiveFunctionIndex, double *pU, size_t pN, void *pUserData);
#else
bool solve(ComputeObjectiveFunction pComputeObjectiveFunction, double *pU, size_t pN, void *pUserData);
#endif

protected:
class Impl; /**< Forward declaration of the implementation class, @private. */
Expand Down
7 changes: 7 additions & 0 deletions src/bindings/javascript/solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

#include "solvernla_p.h"

#include <libopencor>

void solverApi()
Expand Down Expand Up @@ -47,6 +49,11 @@ void solverApi()

// SolverNla API.

emscripten::function("nlaSolve", emscripten::optional_override([](uintptr_t pNlaSolverAddress, size_t pObjectiveFunctionIndex, uintptr_t pU, size_t pN, uintptr_t pData) {
libOpenCOR::nlaSolve(pNlaSolverAddress, pObjectiveFunctionIndex,
reinterpret_cast<double *>(pU), pN, reinterpret_cast<void *>(pData));
}));

emscripten::class_<libOpenCOR::SolverNla, emscripten::base<libOpenCOR::Solver>>("SolverNla")
.smart_ptr<libOpenCOR::SolverNlaPtr>("SolverNla");

Expand Down
2 changes: 1 addition & 1 deletion src/bindings/python/sed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void sedApi(nb::module_ &m)
.def("add_task", &libOpenCOR::SedDocument::addTask, "Add a task.", nb::arg("task").none())
.def("remove_task", &libOpenCOR::SedDocument::removeTask, "Remove a task.", nb::arg("task").none())
.def("remove_all_tasks", &libOpenCOR::SedDocument::removeAllTasks, "Remove all tasks.")
.def("instantiate", &libOpenCOR::SedDocument::instantiate, "Instantiate this SedDocument object.", nb::arg("compiled") = true);
.def("instantiate", &libOpenCOR::SedDocument::instantiate, "Instantiate this SedDocument object.");

// SedInstance API.

Expand Down
Loading
Loading