npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@simzero/rom

v1.1.0

Published

A JS module for the online stage of ROM

Downloads

14

Readme

rom.js

npm version Docker stability-beta Join Slack License: LGPL v3

rom.js is a JavaScript port for solving the online stage of reduced-order model (ROM) and visualizing the outputs on the web. The current version uses OpenFOAM and ITHACA-FV for generating the CFD snapshots and the ROM.

rom.js is used in http://cfd.xyz, check the website and the code at cfd.xyz GitHub.

This is a beta version, please handle it with care. Further features, optimizations and fixes are expected.

Usage

This module can be directly installed with:

npm install --save @simzero/rom

The standalone-templates directory contains instructions and examples for using the module and generating CFD results with the available ROMs. Alternatively, the module and ROMs can be built and tested following the instructions described in Option 1 and Option 2.

A minimal example for steady-state cases can be found in standalone-templates/steady.mjs. The main parts of this code are shown below:

import rom from '@simzero/rom'
import Papa from 'papaparse'
import fs from 'fs'
import yargs from 'yargs'

// - Defining functions and configuration
...

(async () => {

  await rom.ready

  // - Loading ROM data (e.g. generated with the steady app)
  ...
  
  // - Defining reducedSteady
  const reduced = new rom.reducedSteady(nPhiU + nPhiP, nPhiU + nPhiP);

  // - Setting up grid and ROM data
  reduced.stabilization(argv.stabilization);
  reduced.nPhiU(nPhiU);
  reduced.nPhiP(nPhiP);
  reduced.nPhiNut(nPhiNut);
  reduced.nRuns(nRuns);
  reduced.nBC(nBC);

  reduced.readUnstructuredGrid(gridData);
  reduced.initialize();

  reduced.K().set(KData[0]);
  reduced.B().set(BData[0]);
  reduced.P().set(PData[0]);
  reduced.modes().set(modesData[0]);
  reduced.coeffL2().set(coeffL2Data[0]);
  reduced.mu().set(muData[0]);

  // - Loading turbulent related matrices and weights
  for (var i = 0; i < nPhiU; i ++ ){
    // - Loading data
    ...

    reduced.C().set(CData[0]);
    reduced.addCMatrix();
    reduced.Ct1().set(Ct1Data[0]);
    reduced.addCt1Matrix();
    reduced.Ct2().set(Ct2Data[0]);
    reduced.addCt2Matrix();
  }

  for (var i = 0; i < nPhiNut; i ++ ){
    // - Loading data
    ...

    reduced.weights().set(weightsData[0]);
    reduced.addWeights();
  }

  reduced.setRBF();

  // - Defining viscosity and solving for the given velocity
  reduced.nu(argv.nu);
  reduced.solveOnline(argv.Ux, argv.Uy);

  // - Reconstructing data from Eigen to VTK and exporting the grid
  reduced.reconstruct();
  const dataString = reduced.exportUnstructuredGrid();

  // - Saving the VTK file
  const outputFile = 'U_' + U + '_nu_' + nu + '.vtu';
  fs.writeFileSync(outputFile, dataString);

  reduced.delete();

})();

Performance

The module has been tested in the following devices:

| Label | OS | CPU | RAM | | ------------------ | -------------------- | ----------------------------------------- | ------------------------ | | Raspberry Pi 3 | Raspberry Pi OS 10.0 | ARM Cortex-A53 @ 1.2 GHz (armv7l) | 1 GB LPDDR2 SRDRAM | | Low-end smartphone | Android 11 | ARM Cortex-A73 @ 1.8 GHz (armv8) | 2x2 GB LPDDR4 @ 1.86 GHZ | | Windows laptop | MS Windows 11 Home | Intel® Core™ i7-11370H @ 3.3 GHz (x86_64) | 2x8 GB DDR4 @ 3200 MHz | | Linux laptop | Ubuntu 22.04 | Intel® Core™ i7-1165G7 @ 2.8 GHz (x86_64) | 2x8 GB DDR4 @ 3200 MHz | | Workstation | Ubuntu 22.04 | AMD Ryzen 9 5950X @ 3.4 GHz (x86_64) | 2x32 GB DDR4 @ 3200 MHz |

The calculation for one set of parameters for the different models was tested on these devices obtaining the following results:

performance

Accuracy

TODO: We will soon display accuracy of the surrogate models for the considered parametric space. In the meanwhile please check the results on the OFJ techcnical note forpitzDaily.

Option 1 Building and testing with Docker as the only requirement

This is the preferred and easiest method for working with this repository.

The rom-js Docker image contains all the configuration and required third-party libraries for: 1) building the JavaScript module, 2) running OpenFOAM and 3) generating the ROM data using ITHACA-FV. The following versions are included in the image:

Requirements

Building

The node version of the module can be executed outside a web browser with a back-end JavaScript runtime environment (Node.js). The following command builds both the node and browser version of the module:

make all

Generating the ROM data

The CFD snapshots are generated directly with OpenFOAM and later used in ITHACA-FV for generating the ROM. This results in hundreds of simulation executions and multiple GB of data. You can skip running this step by directly downloading the ROM data into the surrogates folder with:

make data

Alternatively, You can also create the ROM data by yourself. Single core simulations are run in parallel in batches with the number of cores set by the CORES variable:

CORES=8 make rom

The snasphots will be generated at ITHACAoutput/Offline with ITHACAoutput/Parameters showing the coressponding parameters for every folder in ITHACAoutput/Offline. The ITHACAoutput/Reconstruction contains folders for the online stage for the selected parameters. All the ROM data wil be collected in the surrogates folder.

Using the ROM

Once that you have the surrogates you can cd into an example and test the rom.js module. For example:

cd examples/OpenFOAM/incompressible/simpleFoam/pitzDaily
./run-online.sh

Option 2 Building and testing by natively building the third-party libraries

This option compiles Emscripten versions of Splinter, Eigen and VTK. OpenFOAM and ITHACA-FV are also compiled.

Requirements

  • Docker 20.10.12
  • npm 6.14.11
  • node v14.15.5

Note: Docker is only used for compiling with Emscripten.

Building

Initialize the third-party submodules with:

git submodule update --init --recursive

A local installation of ITHACA-FV (@carpemonf fork) and OpenFOAM (v2106) is needed. You can use your local versions and skip this step and jump to Generating the ROM data.

Check system requirements for OpenFOAM and ITHACA-FV and run:

make native-thirdparty

Ported code need to be also compiled before building the final rom.js module with:

make native-thirdparty-emcc

Install the package dependencies:

make native-install

For building the rom.js module run:

make native-build

Generating the ROM data with native OpenFOAM and ITHACA-FV

The CFD snapshots are generated directly with OpenFOAM and later used in ITHACA-FV for generating the ROM. This results in hundreds of simulation executions and multiple GB of data. You can skip running this step by directly downloading the ROM data into the surrogates folder with:

make native-data

Alternatively, You can also create the ROM data by yourself. Single core simulations are run in parallel in batches with the number of cores set by the CORES variable:

CORES=8 make native-rom

If you have your own installation of ITHACA-FV (@carpemonf fork) and OpenFOAM (v2106), just set up the environment and run:

cd examples && ./Allrun 8

The snasphots will be generated at ITHACAoutput/Offline with ITHACAoutput/Parameters showing the coressponding parameters for every folder in ITHACAoutput/Offline. The ITHACAoutput/Reconstruction contains folders for the online stage for the selected parameters. All the ROM data wil be collected in the surrogates folder.

Using the ROM

Once that you have the surrogates you can cd into an example and test the rom.js module. For example:

cd examples/OpenFOAM/incompressible/simpleFoam/pitzDaily
./run-online.sh

Contributing

Everyone is welcome to contribute to this project. See CONTRIBUTING.md for further details.

Your donations encourage future developments and help with server costs for providing a better service. If you like the tool you can :heart: donate.

Citation

  • Article published in the OpenFOAM® Journal:
@article{Pena-Monferrer_Diaz-Marin_2022,
  author={Peña-Monferrer, Carlos and Diaz-Marin, Carmen},
  title={rom.js/cfd.xyz: An open-source framework for generating and visualizing parametric {CFD} results},
  journal={OpenFOAM® Journal},
  volume={2},
  month={Oct.},
  pages={143–148}
  DOI={10.51560/ofj.v2.83},
  url={https://journal.openfoam.com/index.php/ofj/article/view/83},
  year={2022},
}
  • Repository:
@online{rom_js_repo_2022,
  author={{SIMZERO}},
  title={{rom.js}},
  howpublished={\url{https://github.com/simzero-oss/rom-js}},
  addendum="(accessed: 28.04.2022)",
}

License

GNU Lesser General Public License v3.0