Skip to content

Commit 5d6cacf

Browse files
committed
Initial commit with no history
0 parents  commit 5d6cacf

File tree

16 files changed

+1337
-0
lines changed

16 files changed

+1337
-0
lines changed

CONTRIBUTING.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## Contributing to FEAScript
2+
3+
Thank you for your interest in contributing!</br>
4+
FEAScript is in early development with continuous addition of new features and improvements. To ensure a smooth and collaborative development process, please review and follow the guidelines.
5+
6+
## Contribution Guidelines
7+
8+
<!--1. Search the <a href="https://github.com/FEAScript/FEAScript/wiki/Roadmap" target="_blank">project roadmap</a> to see areas where help is needed.-->
9+
10+
1. Respect the existing FEAScript coding style. Observe the code near your intended change and attempt to preserve that style with your modifications.
11+
12+
2. We recommend using <a href="https://code.visualstudio.com/" target="_blank">Visual Studio Code</a> with the <a href="https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode" target="_blank">Prettier</a> plugin for automatic code formatting.
13+
14+
3. Ensure that you use <a href="https://en.wikipedia.org/wiki/Camel_case" target="_blank">camelCase</a> formatting for variable names throughout the code.
15+
16+
4. Before applying for a pull request, you can test your modifications by running the FEAScript library from a local server. For security reasons, it is recommended to use a <a href="https://docs.python.org/3/library/http.server.html" target="_blank">Python HTTP Server</a> by executing the following <a href="https://github.com/FEAScript/FEAScript-website/blob/main/corsHttpServer.py" target="_blank">script</a>. Start the Python server by running `python3 corsHttpServer.py` in your local repository folder. The server address will be http://127.0.0.1:8000/.
17+
18+
Alternatively, you can disable CORS in your browser for local testing. To disable CORS in Firefox:
19+
20+
1. Open Firefox and type `about:config` in the address bar, then press Enter.
21+
2. Accept the risk and continue to the advanced settings.
22+
3. In the search bar, type `security.fileuri.strict_origin_policy`.
23+
4. Double-click on the `security.fileuri.strict_origin_policy` preference to set it to `false`.

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 FEAScript
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<img src="https://feascript.github.io/FEAScript-website/images/FEAScriptLogo.png" width="80">
2+
3+
## FEAScript
4+
5+
<a href="https://feascript.com/" target="_blank">FEAScript</a> is an open-source JavaScript library for solving differential equations using the finite element method. It allows you to create and run browser-based simulations of physics and engineering problems.
6+
<br>
7+
</br>
8+
🚧 FEAScript is in early development, and new features and improvements are constantly being added 🚧
9+
10+
## How to Use
11+
12+
FEAScript is written in pure JavaScript, so it only requires an HTML page to run. The simulation inputs are passed as <a href="https://www.w3schools.com/js/js_json_intro.asp" target="_blank">JSON</a> files that can be stored locally or hosted online (e.g., using <a href="https://pages.github.com/" target="_blank">GitHub Pages</a> or other services dedicated to JSON file hosting like <a href="https://www.jsonkeeper.com/" target="_blank">JSON Keeper</a>). FEAScript runs locally on your browser - no cloud services are involved. There are several examples of using FEAScript to solve various problems <a href="https://github.com/FEAScript/FEAScript/tree/main/examples" target="_blank">here</a>.
13+
14+
## Contribute
15+
16+
We are actively looking for contributors to help evolve FEAScript. Please refer to <a href="./CONTRIBUTING.md" target="_blank">CONTRIBUTING.md</a> for instructions on how to contribute.
17+
18+
## License
19+
20+
FEAScript is distributed under the terms of the <a href="./LICENSE" target="_blank">MIT license</a>. &#169; 2024 FEAScript.
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>FEAScript: Heat Conduction in a Two-Dimensional Fin</title>
7+
8+
<!-- Math.js and Plotly.js libraries -->
9+
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjs/5.0.0/math.min.js"></script>
10+
<script src="https://cdnjs.cloudflare.com/ajax/libs/plotly.js/2.27.0/plotly.min.js"></script>
11+
12+
<!-- Style -->
13+
<style>
14+
html {
15+
max-width: 1500px;
16+
margin: auto;
17+
font-family: "Roboto", sans-serif;
18+
font-size: 90%;
19+
}
20+
21+
body {
22+
padding: 20px;
23+
line-height: 1.6;
24+
}
25+
26+
h1,
27+
h2,
28+
h3 {
29+
background: none;
30+
font-weight: normal;
31+
margin: 0;
32+
padding-top: 0.4em;
33+
padding-bottom: 0.2em;
34+
width: auto;
35+
margin-bottom: 0.5em;
36+
}
37+
38+
h1 {
39+
color: #555;
40+
font-size: 150%;
41+
margin-bottom: 0.4em;
42+
line-height: 1.2em;
43+
}
44+
45+
p {
46+
margin: 1em 0;
47+
max-width: 1000px;
48+
margin-bottom: 1em;
49+
}
50+
51+
a {
52+
text-decoration: none;
53+
}
54+
</style>
55+
</head>
56+
57+
<!-- Webpage text -->
58+
<body>
59+
<h1>Heat Conduction in a Two-Dimensional Fin</h1>
60+
<div id="solutionPlot"></div>
61+
62+
<p>
63+
The mesh configuration and boundary conditions can be adjusted by editing the respective JSON files
64+
(meshConfig.json and boundaryConditionsConfig.json). The solver configuration is set explicitly to
65+
solidHeatTransferScript in this example. Please refresh the page to update the results. Detailed
66+
instructions for this example can be found in the corresponding
67+
<a
68+
href="https://github.com/FEAScript/FEAScript-website/blob/main/tutorialSolidHeatTransfer01/tutorialSolidHeatTransfer01.html"
69+
target="_blank"
70+
>FEAScript tutorial</a
71+
>. If you need further assistance, you can visit the
72+
<a href="https://feascript.com/" target="_blank">FEAScript website</a>.
73+
</p>
74+
75+
<p>
76+
This example requires Cross-Origin Resource Sharing (CORS) to run if the JSON files are stored locally.
77+
To enable CORS on Firefox, you can follow these steps:
78+
</p>
79+
<ol>
80+
<li>Open Firefox and type <code>about:config</code> in the address bar, then press Enter.</li>
81+
<li>Accept the risk and continue to the advanced settings.</li>
82+
<li>
83+
In the search bar, type
84+
<code>security.fileuri.strict_origin_policy</code>.
85+
</li>
86+
<li>
87+
Double-click on the
88+
<code>security.fileuri.strict_origin_policy</code> preference to set it to <code>false</code>.
89+
</li>
90+
</ol>
91+
92+
<p>
93+
FEAScript is distributed under the terms of the
94+
<a href="https://opensource.org/license/mit" target="_blank">MIT license</a>. © 2024 FEAScript.
95+
</p>
96+
97+
<!-- JSON fetching -->
98+
<script>
99+
let meshConfig, boundaryConditionsConfig;
100+
const solverConfig = "solidHeatTransferScript"; // Set solverConfig explicitly
101+
102+
// Function to fetch and parse JSON files
103+
function fetchJSON(url) {
104+
return fetch(url).then((response) => response.json());
105+
}
106+
107+
// Fetch JSON files asynchronously from the provided URLs
108+
Promise.all([fetchJSON("meshConfig.json"), fetchJSON("boundaryConditionsConfig.json")]).then(
109+
([meshConfigData, boundaryConditionsConfigData]) => {
110+
meshConfig = meshConfigData;
111+
boundaryConditionsConfig = boundaryConditionsConfigData;
112+
}
113+
);
114+
</script>
115+
116+
<!-- FEAScript module and visualization -->
117+
<script type="module">
118+
import {
119+
FEAScript,
120+
plotSolution,
121+
printVersion,
122+
} from "https://feascript.github.io/FEAScript/src/index.js";
123+
124+
window.addEventListener("DOMContentLoaded", () => {
125+
// Print FEAScript version in the console
126+
printVersion();
127+
// Calculate solution and render plot once JSON data is loaded
128+
let { solutionVector, nodesCoordinates } = FEAScript(
129+
solverConfig,
130+
meshConfig,
131+
boundaryConditionsConfig
132+
);
133+
// Plot the solution as a 2D contour plot
134+
plotSolution(
135+
solutionVector,
136+
nodesCoordinates,
137+
solverConfig,
138+
meshConfig.meshDimension,
139+
"contour",
140+
"solutionPlot"
141+
);
142+
});
143+
</script>
144+
</body>
145+
</html>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<img src="https://feascript.github.io/FEAScript-website/images/FEAScriptLogo.png" width="80">
2+
3+
## Heat Conduction in a Two-Dimensional Fin
4+
5+
This example demonstrates how to solve a stationary heat transfer problem within a 2D rectangular domain using the FEAScript library. The problem is a typical cooling fin scenario.
6+
7+
### Files
8+
9+
- `meshConfig.json`: Defines the computational mesh parameters.
10+
- `boundaryConditionsConfig.json`: Specifies the boundary conditions for the problem.
11+
- `FEAScriptExampleSolidHeatTransfer01.html`: The main HTML file that sets up and runs the example.
12+
13+
### CORS Configuration
14+
15+
<p>
16+
This example requires Cross-Origin Resource Sharing (CORS) to run if the JSON files are stored locally. To
17+
enable CORS on Firefox, you can follow these steps:
18+
</p>
19+
<ol>
20+
<li>
21+
Open Firefox and type <code>about:config</code> in the address bar, then
22+
press Enter.
23+
</li>
24+
<li>Accept the risk and continue to the advanced settings.</li>
25+
<li>
26+
In the search bar, type
27+
<code>security.fileuri.strict_origin_policy</code>.
28+
</li>
29+
<li>
30+
Double-click on the
31+
<code>security.fileuri.strict_origin_policy</code> preference to set it
32+
to <code>false</code>.
33+
</li>
34+
</ol>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"0": ["constantTemp", 200],
3+
"1": ["symmetry"],
4+
"2": ["convection", 1, 20],
5+
"3": ["constantTemp", 200]
6+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"meshDimension": "2D",
3+
"elementOrder": "quadratic",
4+
"numElementsX": 8,
5+
"numElementsY": 4,
6+
"maxX": 4,
7+
"maxY": 2
8+
}

src/FEAScript.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// ______ ______ _____ _ _ //
2+
// | ____| ____| /\ / ____| (_) | | //
3+
// | |__ | |__ / \ | (___ ___ ____ _ ____ | |_ //
4+
// | __| | __| / /\ \ \___ \ / __| __| | _ \| __| //
5+
// | | | |____ / ____ \ ____) | (__| | | | |_) | | //
6+
// |_| |______/_/ \_\_____/ \___|_| |_| __/| | //
7+
// | | | | //
8+
// |_| | |_ //
9+
// Website: https://feascript.com/ \__| //
10+
11+
import { assembleSolidHeatTransferMat } from "./solvers/solidHeatTransferScript.js";
12+
13+
/**
14+
* FEAScript: An open-source JavaScript library to solve differential equations using the finite element method
15+
* @param {string} solverConfig - Parameter specifying the type of solver
16+
* @param {object} meshConfig - Object containing computational mesh details
17+
* @param {object} boundaryConditions - Object containing boundary conditions for the finite element analysis
18+
* @returns {object} An object containing the solution vector and additional mesh information
19+
*/
20+
export function FEAScript(solverConfig, meshConfig, boundaryConditions) {
21+
let jacobianMatrix = []; // Jacobian matrix
22+
let residualVector = []; // Galerkin residuals
23+
let solutionVector = []; // Solution vector
24+
let nodesCoordinates = {}; // Object to store x and y coordinates of nodes
25+
26+
// Assembly matrices
27+
console.time("assemblyMatrices");
28+
if (solverConfig === "solidHeatTransferScript") {
29+
console.log("FEAScript solver:", solverConfig);
30+
({ jacobianMatrix, residualVector, nodesCoordinates } = assembleSolidHeatTransferMat(
31+
meshConfig,
32+
boundaryConditions
33+
));
34+
}
35+
console.timeEnd("assemblyMatrices");
36+
37+
// System solving
38+
console.time("systemSolving");
39+
solutionVector = math.lusolve(jacobianMatrix, residualVector); // Solve the system of linear equations using LU decomposition
40+
console.timeEnd("systemSolving");
41+
42+
// Debugging statements
43+
//console.log(x);
44+
//console.log("nodesCoordinates:", nodesCoordinates);
45+
46+
// Return the solution matrix and nodes coordinates
47+
return {
48+
solutionVector,
49+
nodesCoordinates,
50+
};
51+
}

src/index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// ______ ______ _____ _ _ //
2+
// | ____| ____| /\ / ____| (_) | | //
3+
// | |__ | |__ / \ | (___ ___ ____ _ ____ | |_ //
4+
// | __| | __| / /\ \ \___ \ / __| __| | _ \| __| //
5+
// | | | |____ / ____ \ ____) | (__| | | | |_) | | //
6+
// |_| |______/_/ \_\_____/ \___|_| |_| __/| | //
7+
// | | | | //
8+
// |_| | |_ //
9+
// Website: https://feascript.com/ \__| //
10+
11+
export { FEAScript } from "./FEAScript.js";
12+
export { plotSolution } from "./visualization/plotSolutionScript.js";
13+
export { printVersion } from "./utilities/helperFunctionsScript.js";

0 commit comments

Comments
 (0)