FreeFem++ is a partial differential equation solver. Its primary users are mathematicians. As for many other software, some computing knowledge is required to install it on the many different computer systems that mathematicians use. But mathematical researchers, teachers or students should not be required to have this level of computing knowledge. The Javascript version of FreeFem++ works straight out of an HTML page, on any recent internet browser, both online or offline, on any operating system where such a browser is available. Creating a FreeFem++ program means editing a standard HTML page, which can become a complete literate program with math equations, editable portions and graphics. FreeFem++-js users can exchange their programs as HTML files with modifiable and fixed parts. This document itself is a FreeFem++ script. The current version of FreeFem++-js is 17.1.
Examples
- FreeFem++-js
- Run FreeFem++ scripts online.
- A Mathematical Model for Electrostatics as a Literate FreeFem++ Program
- From chapter 9.1.2 of the FreeFem++ documentation.
- Working Template
- Contains everything necessary to create a new FreeFem++-js document.
HowTo
Here is how to include a runnable FreeFem++ script into any HTML page. A working template is also available.
-
The <head> section of the HTML document should contain
<script src="//www.ljll.math.upmc.fr/lehyaric/ffjs/jquery-1.11.2.min.js"></script> <script src="pub/FileSaver.js/FileSaver.min.js"></script> <script src="//www.ljll.math.upmc.fr/lehyaric/ffjs/17.1/freefem.min.js" type="text/javascript"></script> <script src="//www.ljll.math.upmc.fr/lehyaric/ffjs/17.1/ffapi.js" type="text/javascript"></script>
-
All script parts should be contained in HTML elements of class="ffjs", but they don't need to be contiguous. The program
listing can be interrupted anywhere to add more explanations as HTML, Latex (i.e. MathJax), pictures, etc. Some overly complex
script details can be hidden from view in a hidden HTML element (if they keep the ffjs class). Some lines of the
FreeFem++ may be modifiable (eg the following program text area can be widened to enter any FreeFem++ script).
<textarea class="ffjs"> mesh Th=square(10,10); plot(Th); </textarea>
-
The rest of the script can be displayed as fixed text fields with class="ffjs". All the script text is evaluated by
FreeFem++ when clicking on the evaluate button. The filename.edp parameter can be changed at any time.
<button type="button" onclick="ffjs_export('filename.edp')">Save</button> <button type="button" onclick="ffjs_evaluate()">Run</button> <button type="button" onclick="ffjs_reset()">Reset</button>
-
stdout and stderr are inserted into the same page.
<div id="ffjs_stdout" style="font-family:monospace;"></div> <div id="ffjs_stderr" style="font-family:monospace;"></div>
FreeFem++ textual output will appear here -
2D graphical results, with data-ffjs="default" to draw all plots in the same element, or data-ffjs="figure.eps"
to draw a plot with parameter ps="figure.eps" separately.
<canvas class="ffjs_graph" data-ffjs="default" style="width:100%;"> (message for older browsers where canvas is not implemented) </canvas>
FreeFem++ graphics will appear here
FAQ
- What is the required computer configuration?
- FreeFem++-js works on any computer or smartphone. It runs in the internet browser. No download or install is required.
- Where are the numerical computations done?
- There is no computational server. FreeFem++-js runs on the machine where a browser is opened. Scripts saved locally as HTML pages with their Javascript dependencies will still work as they do not depend on any online facility.
- Is there a risk of virus infection?
- FreeFem++-js runs inside the Javascript virtual machine, which is built to stop viruses.
- How to run FreeFem++-js scripts when disconnected from the internet?
- Saving an HTML page containing FreeFem++-js to a local disk is enough to make it available offline. Saving a page can be also useful to keep a record of a modified script or to save on slow or data-capped internet connections.
- Will any FreeFem++ script run?
- At the moment, scripts will work if they do not contain the following features (not compiled into Javascript yet) : 3d graphs, include files, external tools (UMPPACK, ARPACK, etc), dynamic libraries.
- With many thanks to the projects which where used in the making of FreeFem++-js
- Debian Linux, Emscripten, JQuery, Bootstrap, MathJax