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

fix_IndexSwarmVariable #267

Merged
merged 2 commits into from
Jan 16, 2025
Merged

Conversation

NengLu
Copy link
Contributor

@NengLu NengLu commented Nov 13, 2024

update two files

  • test_1130_IndexSwarmVariable.py
    Test IndexSwarmVariable in getting the right value on the Symmetrical Points.
  • Ex_IndexSwarmVariable.ipynb
    Vis the errors in the original code uw.swarm.IndexSwarmVariable._update(), and provide two methods to fix that.
    • MaterialA: the original code
    • MaterialB: assign the particles to the nearest mesh_levelset nodes, and calculate the material property value on mesh_levelset nodes from them.
    • MaterialC: calculate the material property value on mesh_levelset nodes from the nearest N particles directly.

The values on mesh_levelset nodes (for M_0 indicated by red, P=10.0, for M_1 indicated by blue, P=1.0)
image
The particles used to calculate the value on nodes 6 (blue) and 7 (red) (nodes 6 & 7 are the points in the middle of the left and right wall)
image

Need a further review of these two methods. They work fine for the structured box, but not well in the unstructured_irregular box.

@bknight1
Copy link
Member

bknight1 commented Nov 13, 2024

Nice work Neng!

Just a suggestion, would it be worth implementing something similar to the marker chain method? I.e. the material properties are taken at/close to the centre of the element (when degree = 0)? This would give us results to directly compare against and we know it works well in both mesh types

@NengLu
Copy link
Contributor Author

NengLu commented Nov 13, 2024

Nice work Neng!

Just a suggestion, would it be worth implementing something similar to the marker chain method? I.e. the material properties are taken at/close to the centre of the element (when degree = 0)? This would give us results to directly compare against and we know it works well in both mesh types

Thanks, Ben. Yes, and it can be done by setting the proxy_continuous as False.
IndexSwarmVariable("M", swarm, indices=2, proxy_degree=0, proxy_continuous=False), which calculates the material property value at the centre points in cells.

Sth related to the marker chain method or level set method, I am thinking about: can we use some strategies like adaptive particle refinement in SPH (smoothed particle hydrodynamics) method to improve the performance in the particle-in-cell method, as mesh elements inside the materials and far away from the interface between different materials do not need so many particles in them, and near the interface we need more particles to better "describe" the interface.

@bknight1
Copy link
Member

Nice work Neng!
Just a suggestion, would it be worth implementing something similar to the marker chain method? I.e. the material properties are taken at/close to the centre of the element (when degree = 0)? This would give us results to directly compare against and we know it works well in both mesh types

Thanks, Ben. Yes, and it can be done by setting the proxy_continuous as False. IndexSwarmVariable("M", swarm, indices=2, proxy_degree=0, proxy_continuous=False), which calculates the material property value at the centre points in cells.

Sth related to the marker chain method or level set method, I am thinking about: can we use some strategies like adaptive particle refinement in SPH (smoothed particle hydrodynamics see) method to improve the performance in the particle-in-cell method, as mesh elements inside the materials and far away from the interface between different materials do not need so many particles in them, and near the interface we need more particles to better "describe" the interface.

Nice one mate, good to know we can reproduce the MC method with the index swarm!

SPH looks interesting, will be keen to see what you come up with

@lmoresi
Copy link
Member

lmoresi commented Nov 13, 2024

I think the n-particles to nodes is consistent with what we do for our other mappings (eg. the evalf function). It might well be worth investigating other methods for mapping the properties but it would also make sense to use the existing PETSc functionality for this instead.

Not sure I understand your comments about Marker Chain, Ben. Would we be able to use the same strategy for a swarm that is restricted to the interface ?

@NengLu
Copy link
Contributor Author

NengLu commented Jan 16, 2025

2ff32fd has introduced a fix in swarm.py that allows for two methods of assigning material properties.

To call:
Method B (Debug version of the original code):
material = uw.swarm.IndexSwarmVariable("M", swarm,update_type=0)
Method C:
material = uw.swarm.IndexSwarmVariable("M", swarm,update_type=1)

Update Type Descriptions:

  • Update Type 0: Assigns particles to the nearest mesh_levelset nodes and calculates the material property values at these nodes based on the assigned particles.

  • Update Type 1: Calculates the material property values directly at mesh_levelset nodes using the nearest N particles.

Copy link
Member

@lmoresi lmoresi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is sensible to provide the additional options, as long as they default to the previous behaviour. I'll flag two things:

  • The docstrings should go through a copy-editing step to make sure a typical user can understand what is intended (this is the dev branch so another issue can be raised after the merge)
  • There is code repetition in the branching between different options. This is probably sensible in the dev phase (perhaps we will remove all the different options when we have done more testing) but, again, should not be merged to the release branches in this state.

@lmoresi lmoresi merged commit e365dae into underworldcode:development Jan 16, 2025
1 check passed
@NengLu
Copy link
Contributor Author

NengLu commented Jan 16, 2025

Agree, and now the code includes several options available to users, such as the following:
materialB = uw.swarm.IndexSwarmVariable("M", swarm, indices=2, proxy_degree=ppdegree,proxy_continuous=ppcont,update_type=0,radius=0.6*dy,npoints=npointsB)

materialC = uw.swarm.IndexSwarmVariable("M", swarm, indices=2, proxy_degree=ppdegree,proxy_continuous=ppcont,update_type=1,radius=0.6*dy,npoints=npointsC,npoints_bc=npointsC_bc,ind_bc=ind_bc)

  • radius: Represents the distance threshold. The calculation uses the particles meet condition ($\text{dis} < \text{radius}$) (where 'dis' is the distance between particles and nodes).
  • npoints: The number of nearest points to consider.
  • npoints_bc: Used in update_type=1, the number of nearest points to consider on the boundaries. This parameter is not needed when using the dQ dP type material level_set variable.
  • ind_bc: Used in update_type=1, the index of the boundaries.

I need to conduct more tests to determine the optimal suggestion settings for users.

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.

3 participants