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

Add volume constraints for topology optimization #377

Open
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

leonbaeck
Copy link

@leonbaeck leonbaeck commented Jan 9, 2024

Addition of a class for the topology optimization to handle volume constraints by a projection of the level-set function.

Closes #220

@sblauth sblauth self-requested a review January 9, 2024 10:26
Copy link
Owner

@sblauth sblauth left a comment

Choose a reason for hiding this comment

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

All in all, the code looks pretty good already.
However, the major point that should be fixed is the initialization of the topology optimization problem with volume constraints - this should be done directly with the init method.

Copy link
Owner

Choose a reason for hiding this comment

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

There are some issues here, which can be seen from the CodeQL and codacy annotations here.
Also, the pre-commit run failed (most of these issues are also already adressed there)

Copy link
Owner

Choose a reason for hiding this comment

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

The tests in test_projection_cantilever and test_projection_general should be merged, and both of them should be added to the test_topology_optimization

levelset function.
volume_restriction: A float or a list of floats that describes the
volume restriction that the levelset function should fulfill.
If this is ``None`` no projection is performed (default is ``None``).
Copy link
Owner

Choose a reason for hiding this comment

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

This should be documented more detailedly: What happens when a single a float is passed, and what happens when two are passed?
Also, I would advise for using a tuple[float, float] instead of list[float] as datatype for the case of box constraints (as tuples are immutable)


self.dx = fenics.Measure("dx", self.levelset_function.function_space().mesh())

self.dg0_space = fenics.FunctionSpace(
Copy link
Owner

Choose a reason for hiding this comment

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

Isn't there already some DG0 space defined for topology optimization which we could use instead of defining a new one?

"bound.",
)

self.max_iter_bisect = 100
Copy link
Owner

Choose a reason for hiding this comment

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

The attributes max_iter_bisect and tolerance_bisect should probably be specified via a config file? And the parameters used here could be the defaults?

Copy link
Owner

Choose a reason for hiding this comment

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

Quick question: Is this identical to the demo_cantilever?

cantilever_problem.projection = bisection.projection_levelset(
cantilever_problem.levelset_function, volume_restriction=vol
)
cantilever_problem.solve(algorithm=algorithm, max_iter=2)
Copy link
Owner

Choose a reason for hiding this comment

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

Again, I think the style here is not good - the volume constraint should be passed in the constructor.

("convex_combination", [2 * rng.rand()]),
("gradient_descent", [2 * rng.rand()]),
("bfgs", [2 * rng.rand()]),
],
Copy link
Owner

Choose a reason for hiding this comment

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

Does this work properly? Is the range of rng.rand in (0,1) ?

Copy link
Owner

Choose a reason for hiding this comment

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

All the (new) files should have the copyright / license header which the other .py files already have.

levelset_function, volume_restriction=volume
)
projection.project()
projection_volume = projection.evaluate(0.0, 0.0)
Copy link
Owner

Choose a reason for hiding this comment

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

Here, I would say it is more sensible to assemble the volume of the levelset function directly - you haven't really checked that projection.evaluate(0,0) actually does return the volume (but this could be another test)

@sblauth sblauth changed the title Bisection Add volume constrBisectionaints for topology optimization Jan 10, 2024
@sblauth sblauth changed the title Add volume constrBisectionaints for topology optimization Add volume constraints for topology optimization Jan 10, 2024
@sblauth sblauth added enhancement New feature or request development Development-related matters labels Jan 10, 2024
Copy link

codecov bot commented Feb 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (07d1c80) 92.15% compared to head (f9369af) 92.33%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #377      +/-   ##
==========================================
+ Coverage   92.15%   92.33%   +0.18%     
==========================================
  Files          84       85       +1     
  Lines        6730     6796      +66     
==========================================
+ Hits         6202     6275      +73     
+ Misses        528      521       -7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
development Development-related matters enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Development] Add the possibility to project the level-set to obtain a desired volume
2 participants