FEM_2D
FEM_2D: A Rust Package for 2D Finite Element Method Computations with Extensive Support for hp-refinement - Published in JOSS (2023)
Science Score: 95.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
✓DOI references
Found 13 DOI reference(s) in README and JOSS metadata -
○Academic publication links
-
✓Committers with academic emails
2 of 3 committers (66.7%) from academic institutions -
○Institutional organization owner
-
✓JOSS paper metadata
Published in Journal of Open Source Software
Keywords from Contributors
Repository
A rust library for 2D Finite Element Method computations
Basic Info
- Host: GitHub
- Owner: jeremiah-corrado
- License: mit
- Language: Rust
- Default Branch: main
- Homepage: https://crates.io/crates/fem_2d
- Size: 119 MB
Statistics
- Stars: 13
- Watchers: 2
- Forks: 3
- Open Issues: 1
- Releases: 1
Metadata Files
README.md
fem_2d
A Rust library for 2D Finite Element Method computations, featuring:
- Highly flexible hp-Refinement
- Isotropic & Anisotropic h-refinements (with support for n-irregularity)
- Isotropic & Anisotropic p-refinements
- Generic shape function evaluation
- You can use one of the two built in sets of H(curl) conforming Shape Functions
- Or you can define your own by implementing the
ShapeFnTrait
- Two Eigensolvers
- Expressive Solution Evaluation
- Field solutions can easily be generated from an eigenvector
- Arbitrary functions of solutions can also be evaluated (ex: magnitude of a field)
- Solutions and expressions are easily printed to
.vtkfiles for plotting (using VISIT or similar tools)
Usage
Include this line in your Cargo.toml file under [dependencies]:
toml
fem_2d = "0.1.0"
Please include one or more of the following citations in any academic or commercial work based on this repository: * Corrado, Jeremiah; Harmon, Jake; Notaros, Branislav; Ilic, Milan M. (2022): FEM_2D: A Rust Package for 2D Finite Element Method Computations with Extensive Support for hp-refinement. TechRxiv. Preprint. https://doi.org/10.36227/techrxiv.19166339.v1 * Corrado, Jeremiah; Harmon, Jake; Notaros, Branislav (2021): A Refinement-by-Superposition Approach to Fully Anisotropic hp-Refinement for Improved Efficiency in CEM. TechRxiv. Preprint. https://doi.org/10.36227/techrxiv.16695163.v1 * Harmon, Jake; Corrado, Jeremiah; Notaros, Branislav (2021): A Refinement-by-Superposition hp-Method for H(curl)- and H(div)-Conforming Discretizations. TechRxiv. Preprint. https://doi.org/10.36227/techrxiv.14807895.v1
Documentation
The latest Documentation can be found here
Example
Solve the Maxwell Eigenvalue Problem on a standard Waveguide and print the Electric Fields to a VTK file.
This example encompasses most of the functionality of the library: ```rust use fem_2d::prelude::*;
fn solvebasicproblem() -> Result<(), Box
// Set the polynomial expansion order to 4 in both directions on all Elems
mesh.set_global_expansion_orders(Orders::new(4, 4));
// Isotropically refine all Elems
mesh.global_h_refinement(HRef::t());
// Then anisotropically refine the resultant Elems in the center of the mesh
let cenral_node_id = mesh.elems[0].nodes[3];
mesh.h_refine_with_filter(|elem| {
if elem.nodes.contains(&cenral_node_id) {
Some(HRef::u())
} else {
None
}
});
// Construct a Domain with H(curl) continuity conditions
let domain = Domain::from_mesh(mesh, ContinuityCondition::HCurl);
println!("Constructed Domain with {} DoFs", domain.dofs.len());
// Construct a generalized eigenvalue problem for the Electric Field
// (in parallel using the Rayon Global ThreadPool)
let gep = galerkin_sample_gep_hcurl::<
HierPoly,
CurlCurl,
L2Inner
>(&domain, Some([8, 8]))?;
// Solve the generalized eigenvalue problem using Nalgebra's Eigen-Decomposition
// look for an eigenvalue close to 10.0
let solution = nalgebra_solve_gep(gep, 10.0)?;
println!("Found Eigenvalue: {:.15}", solution.value);
// Construct a solution-field-space over the Domain with 64 samples on each "leaf" Elem
let mut field_space = UniformFieldSpace::new(&domain, [8, 8]);
// Compute the Electric Field in the X- and Y-directions (using the same ShapeFns as above)
let e_field_names = field_space.xy_fields::<HierPoly>
("E", solution.normalized_eigenvector())?;
// Compute the magnitude of the Electric Field
field_space.expression_2arg(e_field_names, "E_mag", |ex, ey| {
(ex.powi(2) + ey.powi(2)).sqrt()
})?;
// Print "E_x", "E_y" and "E_mag" to a VTK file
field_space.print_all_to_vtk("./test_output/electric_field_solution.vtk")?;
Ok(())
} ```
Mesh Refinement
A Mesh structure keeps track of the geometric layout of the finite elements (designated as Elems in the library), as well as the polynomial expansion orders on each element. These can be updated using h- and p-refinements respectively
h-Refinement:
h-Refinements* are implemented using the Refinement by Superposition (RBS) method
Technical details can be found in this paper: A Refinement-by-Superposition Approach to Fully Anisotropichp-Refinement for Improved Efficiency in CEM
Three types of h-refinement are supported: * T: Elements are superimposed with 4 equally sized child elements * U: Elements are superimposed with 2 child elements, such that the resolution is improved in the x-direction * V: Elements are superimposed with 2 child elements, such that the resolution is improved in the y-direction
These are designated as an Enum: HRef, located in the h_refinements module. They can be executed by constructing a refinement as follows:
Rust
let h_iso = HRef::T;
let h_aniso_u = HRef::U(None);
let h_aniso_v = HRef::V(None);
...and applying it to an element or group of elements using one of the many h-refinement methods on Mesh.
Multi-step anisotropic h-refinements can be executed by constructing the U or V variant with Some(0) or Some(1). This will cause the 0th or 1st resultant child element to be anisotropically refined in the opposite direction.
Mesh coarsening is not currently supported
p-Refinement:
p-Refinements allow elements to support a range of expansion orders in the X and Y directions. These can be modified separately for greater control over resource usage and solution accuracy.
As a Domain is constructed from a Mesh, Basis Functions are constructed based on the elements expansion orders.
Expansion orders can be increased or decreased by constructing a PRef, located in the p_refinements module:
Rust
let uv_plus_2 = PRef::from(2, 2);
let u_plus_1_v_minus_3 = PRef::from(1, -3);
...and applying it to an element or group of elements using one of the many p-refinement methods on Mesh.
JSON Mesh Files
fem_2d uses .json files to import and export Mesh layouts.
- The input format is simplified and describes the geometry of the problem only.
- The output format describes the Mesh in it's refined state which is usefull for debugging and observing the refinement state.
Input Mesh Files
A Mesh can be constructed from a JSON file with the following format:
JSON
{
"Elements": [
{
"materials": [eps_rel_re, eps_rel_im, mu_rel_re, mu_rel_im],
"node_ids": [node_0_id, node_1_id, node_2_id, node_3_id],
},
{
"materials": [1.0, 0.0, 1.0, 0.0],
"node_ids": [1, 2, 4, 5],
},
{
"materials": [1.2, 0.0, 0.9999, 0.0],
"node_ids": [2, 3, 5, 6],
}
],
"Nodes": [
[x_coordinate, y_coordinate],
[0.0, 0.0],
[1.0, 0.0],
[2.0, 0.0],
[0.0, 0.5],
[1.0, 0.5],
[2.0, 0.5],
]
}
(The first Element and Node are simply there to explain what variables mean. Those should not be included in an actual mesh file!)
The above file corresponds to this 2 Element mesh (with Node indices labeled): ```text 3 4 5 0.5 ------------------------------* | | | | air | teflon | | | | 0.0 ------------------------------* y 0 1 2 x 0.0 1.0 2.0
Both Elements start with a polynomial expansion order of 1 upon construction.
```
This library does not yet support curvilinear elements. When that feature is added, this file format will also be extended to describe higher-order geometry.
Output Mesh Files
A refined Mesh can also be exported and visualized using this tool:

Solution Plotting
Solution figures like the ones below can be generated by exporting solutions as .vtk files and plotting using a compatible tool (such as Visit):

Community Guidelines / Code of Conduct
Contributions, questions, and bug-reports are welcome! Any pull requests, issues, etc. must adhere to Rust's Code of Conduct.
More details about how to contribute to this project can be found here.
Questions and bug-reports should be directed to the Issues tab.
Owner
- Login: jeremiah-corrado
- Kind: user
- Repositories: 4
- Profile: https://github.com/jeremiah-corrado
JOSS Publication
FEM_2D: A Rust Package for 2D Finite Element Method Computations with Extensive Support for hp-refinement
Authors
Department of Electrical and Computer Engineering, Colorado State University, USA
Department of Electrical and Computer Engineering, Colorado State University, USA, School of Electrical Engineering, University of Belgrade, Serbia
Department of Electrical and Computer Engineering, Colorado State University, USA
Tags
FEM CEM hp-refinement PDE SolversGitHub Events
Total
- Watch event: 5
Last Year
- Watch event: 5
Committers
Last synced: 7 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| jeremiah-corrado | j****o@r****u | 203 |
| Jed Brown | j****d@j****g | 1 |
| Daniel S. Katz | d****z@i****g | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 5
- Total pull requests: 7
- Average time to close issues: about 1 month
- Average time to close pull requests: 5 days
- Total issue authors: 2
- Total pull request authors: 3
- Average comments per issue: 2.0
- Average comments per pull request: 0.14
- Merged pull requests: 6
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- jeremylt (4)
- YohannDudouit (1)
Pull Request Authors
- jeremiah-corrado (5)
- jedbrown (1)
- danielskatz (1)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- cargo 5,432 total
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 4
- Total maintainers: 1
crates.io: fem_2d
2D Finite Element Method Toolkit
- Documentation: https://docs.rs/fem_2d/
- License: MIT
-
Latest release: 0.2.2
published almost 3 years ago
Rankings
Maintainers (1)
Dependencies
- approx 0.5.0
- autocfg 1.0.1
- bytemuck 1.7.3
- bytes 1.1.0
- cfg-if 1.0.0
- crossbeam-channel 0.5.2
- crossbeam-deque 0.8.1
- crossbeam-epoch 0.9.6
- crossbeam-utils 0.8.6
- either 1.6.1
- hermit-abi 0.1.19
- json 0.12.4
- lazy_static 1.4.0
- libc 0.2.112
- matrixmultiply 0.3.2
- memoffset 0.6.5
- nalgebra 0.30.1
- nalgebra-macros 0.1.0
- num-complex 0.4.0
- num-integer 0.1.44
- num-rational 0.4.0
- num-traits 0.2.14
- num_cpus 1.13.1
- paste 1.0.6
- proc-macro2 1.0.36
- quote 1.0.14
- rawpointer 0.2.1
- rayon 1.5.1
- rayon-core 1.9.1
- safe_arch 0.6.0
- scopeguard 1.1.0
- simba 0.7.0
- smallvec 1.8.0
- syn 1.0.85
- typenum 1.15.0
- unicode-xid 0.2.2
- wide 0.7.3
- actions/checkout v2 composite
- actions/upload-artifact v1 composite
- openjournals/openjournals-draft-action master composite
- actions/checkout v3 composite
