Skip to content
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

TCAD adaptive remeshing #1074

Merged
merged 5 commits into from Jan 4, 2023
Merged

TCAD adaptive remeshing #1074

merged 5 commits into from Jan 4, 2023

Conversation

simbilod
Copy link
Collaborator

@simbilod simbilod commented Jan 3, 2023

Bisect the mesh according to simulation results, making the simulator usable. For instance:

Initial simulation:

    c = DDComponent(
        component=waveguide,
        xsection_bounds=[(4, -4), (4, 4)],
        full_layerstack=get_layer_stack_generic(),
        physical_layerstack=physical_layerstack,
        doping_info=get_doping_info_generic(),
        contact_info=contact_info,
        resolutions=resolutions,
        mesh_scaling_factor=1e-4,
        background_tag=None,
    )

    c.ddsolver()
    c.save_device("test1.dat")

image

Now use the simulation results to compute a new mesh size, and generate a new simulation with it:

    meshing_field = c.get_refined_mesh(
        factor=2.0,
        refine_dict={
            "Potential": {
                "func": lambda x0, x1: abs(x0 - x1),
                "threshold": 0.05,
            },
            "Electrons": {
                "func": lambda x0, x1: np.abs(np.log10(x0) - np.log10(x1)),
                "threshold": 1,
            },
        },
        refine_regions=["si"],
    )

   c.delete_device()
    c = DDComponent(
        component=waveguide,
        xsection_bounds=[(4, -4), (4, 4)],
        full_layerstack=get_layer_stack_generic(),
        physical_layerstack=physical_layerstack,
        doping_info=get_doping_info_generic(),
        contact_info=contact_info,
        resolutions=resolutions,
        mesh_scaling_factor=1e-4,
        background_tag=None,
    )

    c.ddsolver(global_meshsize_array=meshing_field)
    c.save_device("test2.dat")

image

The new mesh is only finer where it needs to be.

TODO:

  • Initialize the new simulation with the last results instead of complete reinitialization
  • Repeat the remeshing until some criteria (number of bisections, or some tolerance on result)

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jan 3, 2023

Sourcery Code Quality Report

❌  Merging this PR will decrease code quality in the affected files by 13.43%.

Quality metrics Before After Change
Complexity 2.79 ⭐ 4.46 ⭐ 1.67 👎
Method Length 62.38 🙂 88.23 🙂 25.85 👎
Working memory 7.65 🙂 11.24 😞 3.59 👎
Quality 75.09% 61.66% 🙂 -13.43% 👎
Other metrics Before After Change
Lines 354 700 346
Changed files Quality Before Quality After Quality Change
gdsfactory/simulation/devsim/get_solver.py 78.57% ⭐ 58.38% 🙂 -20.19% 👎
gdsfactory/simulation/gmsh/mesh.py 71.21% 🙂 70.50% 🙂 -0.71% 👎

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
gdsfactory/simulation/devsim/get_solver.py DDComponent.get_refined_mesh 14 🙂 339 ⛔ 15 😞 31.02% 😞 Try splitting into smaller methods. Extract out complex expressions
gdsfactory/simulation/devsim/get_solver.py DDComponent.__init__ 4 ⭐ 150 😞 28 ⛔ 43.74% 😞 Try splitting into smaller methods. Extract out complex expressions
gdsfactory/simulation/gmsh/mesh.py mesh_from_polygons 4 ⭐ 140 😞 16 ⛔ 51.03% 🙂 Try splitting into smaller methods. Extract out complex expressions
gdsfactory/simulation/gmsh/mesh.py tag_interfaces 6 ⭐ 84 🙂 10 😞 65.33% 🙂 Extract out complex expressions
gdsfactory/simulation/devsim/get_solver.py DDComponent.ddsolver 4 ⭐ 176 😞 6 ⭐ 65.49% 🙂 Try splitting into smaller methods

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

@codecov
Copy link

codecov bot commented Jan 3, 2023

Codecov Report

Merging #1074 (05417a0) into main (6bae6aa) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main    #1074   +/-   ##
=======================================
  Coverage   72.32%   72.32%           
=======================================
  Files         436      436           
  Lines       22569    22569           
  Branches     2993     2993           
=======================================
  Hits        16323    16323           
  Misses       5365     5365           
  Partials      881      881           

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@simbilod simbilod mentioned this pull request Jan 4, 2023
10 tasks
@joamatab joamatab merged commit 93346ba into gdsfactory:main Jan 4, 2023
simbilod pushed a commit to simbilod/gdsfactory that referenced this pull request Mar 2, 2023
TCAD adaptive remeshing

Former-commit-id: f4f9187 [formerly 93346ba]
Former-commit-id: a7d0a612b74f5535cf99db234c4f2c2bb34186f0
@simbilod simbilod deleted the devsim_adaptive branch April 5, 2023 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants