-
Notifications
You must be signed in to change notification settings - Fork 13
Feature/solver inspect geometry #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 11 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
fb4fac6
fix: bug related to an empty path, was preventing cadquery STL export
elenafuengar 6ec07df
style: apply RUFFs suggestions + add logo with private function
elenafuengar 2a32aec
refact: include stl_colors in prepare stl dicts, now it will always cβ¦
elenafuengar a68990a
style: modify materials and colors dictionaries
elenafuengar 5629281
feature: allow logger to be saved from any class, by passing the mateβ¦
elenafuengar 6b5e9d0
feature: add method `inspect()` to interactively show all the solids β¦
elenafuengar 2b5c191
fix: apply codeQL findings + fix test failing
elenafuengar f0f9b02
feature: add progress bar to STL importing when grid is large >5M cells
elenafuengar 5b19781
fix: solve some visualization errors + homogenize parameters `offscreβ¦
elenafuengar 3f9a1b9
feature: add `solver.inspect()` to notebook 002
elenafuengar 6e53f24
test: reorganize test, now all 3D interactive plotting routines are iβ¦
elenafuengar e713135
test: solve deprecation warnings and off_screen/on_screen test passinβ¦
elenafuengar 5de157c
style: change default stainless steel material to `silver`
elenafuengar f75be71
tests: use vtk-osmesa to run the 3D plotting offscreen
elenafuengar 40aba8d
tests: update interactive plots, now not skipped thanks to vtk-osmesaβ¦
elenafuengar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,165 @@ | ||
| import os | ||
| import sys | ||
| import numpy as np | ||
| import pyvista as pv | ||
| import matplotlib.pyplot as plt | ||
github-code-quality[bot] marked this conversation as resolved.
Fixed
Show fixed
Hide fixed
|
||
|
|
||
| sys.path.append('../wakis') | ||
|
|
||
| from tqdm import tqdm | ||
| from scipy.constants import c | ||
|
|
||
| from wakis import SolverFIT3D | ||
| from wakis import GridFIT3D | ||
| from wakis.sources import Beam | ||
|
|
||
| import pytest | ||
|
|
||
| # Turn true when running local | ||
| flag_plot_3D = False | ||
| flag_offscreen = False | ||
|
|
||
| @pytest.mark.slow | ||
| class Test3Dplotting: | ||
|
|
||
| img_folder = 'tests/008_img/' | ||
|
|
||
| def test_simulation(self): | ||
|
|
||
| # ---------- Domain setup --------- | ||
|
|
||
| # Geometry & Materials | ||
| solid_1 = 'tests/stl/007_vacuum_cavity.stl' | ||
| solid_2 = 'tests/stl/007_lossymetal_shell.stl' | ||
|
|
||
| stl_solids = {'cavity': solid_1, | ||
| 'shell': solid_2 | ||
| } | ||
|
|
||
| stl_materials = {'cavity': 'vacuum', | ||
| 'shell': [30, 1.0, 30] #[eps_r, mu_r, sigma[S/m]] | ||
| } | ||
|
|
||
| stl_colors = {'cavity': 'vacuum', | ||
| 'shell': [1, 1, 1]} | ||
|
|
||
| # Extract domain bounds from geometry | ||
| solids = pv.read(solid_1) + pv.read(solid_2) | ||
| xmin, xmax, ymin, ymax, ZMIN, ZMAX = solids.bounds | ||
|
|
||
| # Number of mesh cells | ||
| Nx = 60 | ||
| Ny = 60 | ||
| NZ = 140 | ||
|
|
||
| grid = GridFIT3D(xmin, xmax, ymin, ymax, ZMIN, ZMAX, | ||
| Nx, Ny, NZ, | ||
| use_mpi=False, # Enables MPI subdivision of the domain | ||
| stl_solids=stl_solids, | ||
| stl_materials=stl_materials, | ||
| stl_colors=stl_colors, | ||
| stl_scale=1.0, | ||
| stl_rotate=[0,0,0], | ||
| stl_translate=[0,0,0], | ||
| verbose=1) | ||
|
|
||
| # ------------ Beam source & Wake ---------------- | ||
| # Beam parameters | ||
| sigmaz = 10e-2 #[m] -> 2 GHz | ||
| q = 1e-9 #[C] | ||
| beta = 1.0 # beam beta | ||
| xs = 0. # x source position [m] | ||
| ys = 0. # y source position [m] | ||
| ti = 3*sigmaz/c # injection time [s] | ||
|
|
||
| beam = Beam(q=q, sigmaz=sigmaz, beta=beta, | ||
| xsource=xs, ysource=ys, ti=ti) | ||
|
|
||
| # ----------- Solver & Simulation ---------- | ||
| # boundary conditions | ||
| bc_low=['pec', 'pec', 'pec'] | ||
| bc_high=['pec', 'pec', 'pec'] | ||
|
|
||
| # Solver setup | ||
| global solver | ||
| solver = SolverFIT3D(grid, | ||
| bc_low=bc_low, | ||
| bc_high=bc_high, | ||
| use_stl=True, | ||
| use_mpi=False, # Activate MPI | ||
| bg='pec' # Background material | ||
| ) | ||
|
|
||
| # -------------- Output folder --------------------- | ||
| if not os.path.exists(self.img_folder): | ||
| os.mkdir(self.img_folder) | ||
|
|
||
| # -------------- Custom time loop ----------------- | ||
| Nt = 3000 | ||
| for n in tqdm(range(Nt)): | ||
| beam.update(solver, n*solver.dt) | ||
| solver.one_step() | ||
|
|
||
| @pytest.mark.skipif(not flag_plot_3D, reason="Requires interactive plotting") | ||
| def test_grid_inspect(self): | ||
| # Plot grid and imported solids | ||
| global solver | ||
| solver.grid.inspect(add_stl=['cavity', 'shell'], | ||
| stl_opacity=0.1, off_screen=flag_offscreen, | ||
| anti_aliasing='ssaa') | ||
|
|
||
| @pytest.mark.skipif(not flag_plot_3D, reason="Requires interactive plotting") | ||
| def test_grid_plot_solids(self): | ||
| # Plot only imported solids | ||
| global solver | ||
| solver.grid.plot_solids(bounding_box=True, | ||
| show_grid=True, | ||
| opacity=1, | ||
| specular=0.5, | ||
| smooth_shading=False, | ||
| off_screen=flag_offscreen,) | ||
|
|
||
| @pytest.mark.skipif(not flag_plot_3D, reason="Requires interactive plotting") | ||
| def test_grid_stl_mask(self): | ||
| # Plot STL solid masks in the grid | ||
| global solver | ||
| solver.grid.plot_stl_mask(stl_solid='cavity', | ||
| cmap='viridis', | ||
| add_stl='all', | ||
| stl_opacity=0.5, | ||
| smooth_shading=False, | ||
| anti_aliasing='ssaa', | ||
| ymax=0.0, | ||
| off_screen=flag_offscreen,) | ||
|
|
||
| @pytest.mark.skipif(not flag_plot_3D, reason="Requires interactive plotting") | ||
| def test_solver_inspect(self): | ||
| # Plot imported solids and beam source and integraiton path | ||
| global solver | ||
| pl = solver.inspect(window_size=(1200,800), off_screen=flag_offscreen, | ||
| specular=0.,opacity=1, inactive_opacity=0.1, | ||
| add_silhouette=True,) | ||
| if flag_offscreen: | ||
| pl.export_html(self.img_folder+'solver_inspect.html') | ||
| pl.screenshot(self.img_folder+'solver_inspect.png') | ||
|
|
||
| @pytest.mark.skipif(not flag_plot_3D, reason="Requires interactive plotting") | ||
| def test_plot3D(self): | ||
| # Plot Abs Electric field on domain | ||
| global solver | ||
| solver.plot3D('E', component='Abs', | ||
| cmap='rainbow', clim=[0, 500], | ||
| add_stl=['cavity', 'shell'], stl_opacity=0.1, | ||
| clip_interactive=True, clip_normal='-y', | ||
| off_screen=flag_offscreen) | ||
|
|
||
| @pytest.mark.skipif(not flag_plot_3D, reason="Requires interactive plotting") | ||
| def test_plot3DonSTL(self): | ||
| # Plot Abs Electric field on STL solid `cavity` | ||
| global solver | ||
| solver.plot3DonSTL('E', component='Abs', | ||
| cmap='rainbow', clim=[0, 500], | ||
| stl_with_field='cavity', field_opacity=1.0, | ||
| stl_transparent='shell', stl_opacity=0.1, stl_colors='white', | ||
| clip_plane=True, clip_normal='-y', clip_origin=[0,0,0], | ||
| off_screen=flag_offscreen, zoom=1.2, title=self.img_folder+'Ez3d') | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.