-
Notifications
You must be signed in to change notification settings - Fork 8
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
base: main
Are you sure you want to change the base?
Conversation
Conflicts: .github/docker/Dockerfile .github/workflows/test_demos.yml .github/workflows/tests_macos.yml .github/workflows/tests_parallel.yml .github/workflows/tests_serial.yml cashocs/_optimization/topology_optimization/topology_optimization_algorithm.py cashocs/_optimization/topology_optimization/topology_optimization_problem.py pyproject.toml
for more information, see https://pre-commit.ci
cashocs/_optimization/topology_optimization/topology_optimization_problem.py
Fixed
Show fixed
Hide fixed
cashocs/_optimization/topology_optimization/topology_optimization_problem.py
Fixed
Show fixed
Hide fixed
There was a problem hiding this 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.
There was a problem hiding this comment.
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)
tests/test_projection_cantilever.py
Outdated
There was a problem hiding this comment.
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``). |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
tests/test_projection_cantilever.py
Outdated
cantilever_problem.projection = bisection.projection_levelset( | ||
cantilever_problem.levelset_function, volume_restriction=vol | ||
) | ||
cantilever_problem.solve(algorithm=algorithm, max_iter=2) |
There was a problem hiding this comment.
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.
tests/test_projection_cantilever.py
Outdated
("convex_combination", [2 * rng.rand()]), | ||
("gradient_descent", [2 * rng.rand()]), | ||
("bfgs", [2 * rng.rand()]), | ||
], |
There was a problem hiding this comment.
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) ?
tests/test_projection_general.py
Outdated
There was a problem hiding this comment.
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.
tests/test_projection_general.py
Outdated
levelset_function, volume_restriction=volume | ||
) | ||
projection.project() | ||
projection_volume = projection.evaluate(0.0, 0.0) |
There was a problem hiding this comment.
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)
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
Addition of a class for the topology optimization to handle volume constraints by a projection of the level-set function.
Closes #220