mirror of
https://github.com/alvierahman90/fea.git
synced 2025-10-13 07:44:23 +00:00
Compare commits
4 Commits
2846d55194
...
main
Author | SHA1 | Date | |
---|---|---|---|
318f6d7d77
|
|||
131cc7ed84
|
|||
1d6713710f
|
|||
a1e2bb09cb
|
19
readme.md
19
readme.md
@@ -7,3 +7,22 @@ Currently the project can only be used to solve beam element problems where all
|
|||||||
by boundary conditions, but this will be improved in future.
|
by boundary conditions, but this will be improved in future.
|
||||||
The project also has no GUI for defining the problem at the moment, and must be written
|
The project also has no GUI for defining the problem at the moment, and must be written
|
||||||
in rust (see [`src/bin/two_d.rs`](./src/bin/two_d.rs) for an example of setting up a problem).
|
in rust (see [`src/bin/two_d.rs`](./src/bin/two_d.rs) for an example of setting up a problem).
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
- [OpenBLAS](https://github.com/OpenMathLib/OpenBLAS)
|
||||||
|
- A FORTRAN compiler, such as [GFortran](https://gcc.gnu.org/fortran/)
|
||||||
|
|
||||||
|
To install on an Arch based distro:
|
||||||
|
|
||||||
|
```
|
||||||
|
pacman -S blas-openblas gcc-fortran
|
||||||
|
```
|
||||||
|
|
||||||
|
# Format Specifications
|
||||||
|
|
||||||
|
The project will likely be composed of multiple independent programs as it is developed.
|
||||||
|
The formats specified in the [specs folder](./specs) will be used to to exchange information between
|
||||||
|
the programs.
|
||||||
|
|
||||||
|
- [PD2v1](./specs/pd2v1.md) (2D Problem Definition Version 1)
|
||||||
|
111
specs/pd2v1.md
Normal file
111
specs/pd2v1.md
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
# 2D Problem Definition Version 1 (PD2v1) Specification
|
||||||
|
|
||||||
|
A format for defining shapes that humans can write and machines can read.
|
||||||
|
|
||||||
|
I think it should have a better name.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
### Beam Elements (BE)
|
||||||
|
|
||||||
|
Beam element problem definitions use points to represent nodes and links to represent
|
||||||
|
beams.
|
||||||
|
|
||||||
|
A given point (node) can be connected to any number of links (beams).
|
||||||
|
|
||||||
|
### Finite Elements (FE)
|
||||||
|
|
||||||
|
Finite element problem definitions use points to represent nodes and links to represent
|
||||||
|
edges.
|
||||||
|
|
||||||
|
A given point (node) can only be connected to two links (edges).
|
||||||
|
|
||||||
|
### Mesh
|
||||||
|
|
||||||
|
The spec can also be used to export meshes by using fixed boundary conditions and definining a set
|
||||||
|
of `LINK_PROPS` that can be ignored (i.e. `LINK_PROPS ignore 0 0`).
|
||||||
|
|
||||||
|
## Types
|
||||||
|
|
||||||
|
### REAL
|
||||||
|
|
||||||
|
A real number
|
||||||
|
|
||||||
|
#### Examples
|
||||||
|
|
||||||
|
```
|
||||||
|
0
|
||||||
|
-1
|
||||||
|
1
|
||||||
|
-1.0
|
||||||
|
1.0
|
||||||
|
9999999.999999
|
||||||
|
```
|
||||||
|
|
||||||
|
### IDs (`ID`)
|
||||||
|
|
||||||
|
String that can include numbers, letters, underscores (`_`), and dashes (`-`).
|
||||||
|
|
||||||
|
### Boundary condition types (`BC_TYPE`)
|
||||||
|
|
||||||
|
- `NONE`
|
||||||
|
- `FIXED`
|
||||||
|
- `FORCE <VEC_ID>`
|
||||||
|
|
||||||
|
## Syntax
|
||||||
|
|
||||||
|
### Comments
|
||||||
|
|
||||||
|
```
|
||||||
|
// comments begin with // and end at the end of a line
|
||||||
|
```
|
||||||
|
|
||||||
|
### Definitions
|
||||||
|
|
||||||
|
Each definiton goes on its own line.
|
||||||
|
Definitons cannot refer to IDs of objects that are defined in latter lines.
|
||||||
|
|
||||||
|
Every ID given for every object must be unqiue amongst its object type but not between types (although it is fine if it is).
|
||||||
|
All definitions are immutable.
|
||||||
|
|
||||||
|
| Object Type | Syntax |
|
||||||
|
|--------------------|----------------------------------------------------------|
|
||||||
|
| Boundary Condition | `BOUNDARY_CONDITION <ID ID> <BC_TYPE BC_TYPE>` |
|
||||||
|
| Link | `LINK <ID ID> <ID LINK_PROPS> <ID NODE_ID> <ID NODE_ID>` |
|
||||||
|
| Link Properties | `LINK_PROPS <ID ID> <ID MATERIAL> <REAL AREA>` |
|
||||||
|
| Material | `MATERIAL <ID ID> <REAL YOUNGS_MODULUS>` |
|
||||||
|
| Point | `POINT <ID ID> <ID VEC_ID> <ID BOUNDARY_CONDITION>` |
|
||||||
|
| Vector | `VEC <ID ID> <REAL X> <REAL Y>` |
|
||||||
|
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
### Beam Element
|
||||||
|
|
||||||
|
```
|
||||||
|
// Define a fixed boundary conditon as it can be shared by all fixed points
|
||||||
|
BOUNDARY_CONDITION bc_fixed FIXED
|
||||||
|
MATERIAL aluminium 210000000000 250000000
|
||||||
|
LINK_PROPS beam_props aluminium 0.0019635
|
||||||
|
|
||||||
|
// Define the first node
|
||||||
|
VEC point1_pos 0 0
|
||||||
|
POINT point1 point1_pos bc_fixed
|
||||||
|
|
||||||
|
// Define node with force boundary condition
|
||||||
|
VEC point4_pos 1.7321 1
|
||||||
|
VEC bc4_mag 14142 14142
|
||||||
|
BOUNDARY_CONDITION bc4 FORCE bc4_mag
|
||||||
|
POINT point4 point4_pos bc4
|
||||||
|
|
||||||
|
// Define rest of the nodes
|
||||||
|
VEC point2_pos 0 1.1547
|
||||||
|
POINT point2 point2_pos bc_fixed
|
||||||
|
VEC point3_pos 0 4.4641
|
||||||
|
POINT point3 point3_pos bc_fixed
|
||||||
|
|
||||||
|
// And finally link the nodes together to create the beams
|
||||||
|
LINK link1 beam_props point1 point4
|
||||||
|
LINK link2 beam_props point2 point4
|
||||||
|
LINK link3 beam_props point3 point4
|
||||||
|
```
|
124
specs/pd2v1_drawer.html
Normal file
124
specs/pd2v1_drawer.html
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<head>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<link rel="stylesheet" type="text/css" href="https://styles.alv.cx/colors/gruvbox.css" />
|
||||||
|
<link rel="stylesheet" type="text/css" href="https://styles.alv.cx/base.css" />
|
||||||
|
<link rel="stylesheet" type="text/css" href="https://styles.alv.cx/modules/darkmode.css" />
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
margin: 0 auto 0 auto;
|
||||||
|
padding: 0;
|
||||||
|
height: 100vh;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
#canvas {
|
||||||
|
width: 100%;
|
||||||
|
height: 70%;
|
||||||
|
}
|
||||||
|
|
||||||
|
#options {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
#force_x, #force_y {
|
||||||
|
width: 6em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hidden {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<title>PD2v1 Drawer</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<canvas id="canvas"></canvas>
|
||||||
|
<div id="options">
|
||||||
|
<label for="bc_select">Boundary condition type: </label>
|
||||||
|
<select id="bc_select">
|
||||||
|
<option value="NONE">NONE</option>
|
||||||
|
<option value="FIXED">FIXED</option>
|
||||||
|
<option value="FORCE">FORCE</option>
|
||||||
|
</select>
|
||||||
|
<input type="number" id="force_x" name="force_x" placeholder="Force (X)" class="hidden">
|
||||||
|
<input type="number" id="force_y" name="force_y" placeholder="Force (Y)" class="hidden">
|
||||||
|
</div>
|
||||||
|
<script>
|
||||||
|
const MB_LEFT = "MB_LEFT";
|
||||||
|
const MB_RIGHT = "MB_RIGHT";
|
||||||
|
const MB_MIDDLE = "MB_MIDDLE";
|
||||||
|
|
||||||
|
const style = getComputedStyle(document.body);
|
||||||
|
const canvas = document.getElementById("canvas");
|
||||||
|
const ctx = canvas.getContext("2d");
|
||||||
|
const input_bc_select = document.getElementById("bc_select");
|
||||||
|
const input_force_x = document.getElementById("force_x");
|
||||||
|
const input_force_y = document.getElementById("force_y");
|
||||||
|
|
||||||
|
let points = [];
|
||||||
|
let links = [];
|
||||||
|
|
||||||
|
function handleCanvasClick(ev, mouse_button) {
|
||||||
|
ev.preventDefault();
|
||||||
|
|
||||||
|
const rect = canvas.getBoundingClientRect();
|
||||||
|
const x = (ev.clientX - rect.left)/rect.width;
|
||||||
|
const y = (ev.clientY - rect.top)/rect.height;
|
||||||
|
console.log(x, y, mouse_button);
|
||||||
|
|
||||||
|
if (mouse_button === MB_LEFT) {
|
||||||
|
addPoint(x, y, input_bc_select.value, input_force_x.value, input_force_y.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateBcInputs() {
|
||||||
|
if (input_bc_select.value === "FORCE") {
|
||||||
|
input_force_x.classList.remove("hidden");
|
||||||
|
input_force_y.classList.remove("hidden");
|
||||||
|
} else {
|
||||||
|
input_force_x.classList.add("hidden");
|
||||||
|
input_force_y.classList.add("hidden");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function addPoint(x, y, bc_type, bc_fx, bc_fy) {
|
||||||
|
points.push({
|
||||||
|
x: x,
|
||||||
|
y: y,
|
||||||
|
boundary_condition: {
|
||||||
|
type: bc_type,
|
||||||
|
force_x: bc_fx,
|
||||||
|
force_y: bc_fy
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
redraw();
|
||||||
|
}
|
||||||
|
|
||||||
|
function redraw() {
|
||||||
|
const canvas_styles = getComputedStyle(canvas);
|
||||||
|
canvas.height = canvas_styles.height.slice(0, -2);
|
||||||
|
canvas.width = canvas_styles.width.slice(0, -2);
|
||||||
|
const rect = canvas.getBoundingClientRect();
|
||||||
|
ctx.fillStyle = style.getPropertyValue("--fg");
|
||||||
|
ctx.fillRect(0, 0, rect.width, rect.height);
|
||||||
|
|
||||||
|
ctx.fillStyle = style.getPropertyValue("--red");
|
||||||
|
points.forEach(point => {
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.arc(point.x*rect.width, point.y*rect.height, rect.width/60, 0, 2*Math.PI);
|
||||||
|
ctx.fill();
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
canvas.addEventListener("click", ev => handleCanvasClick(ev, MB_LEFT));
|
||||||
|
canvas.addEventListener("contextmenu", ev => handleCanvasClick(ev, MB_RIGHT));
|
||||||
|
input_bc_select.addEventListener("change", updateBcInputs);
|
||||||
|
|
||||||
|
updateBcInputs();
|
||||||
|
redraw();
|
||||||
|
</script>
|
||||||
|
</body>
|
Reference in New Issue
Block a user