# Fenicsx takes up too much disk space, generates a lot of cache files, clear cache

**URL:** <https://fenicsproject.discourse.group/t/fenicsx-takes-up-too-much-disk-space-generates-a-lot-of-cache-files-clear-cache/13812>\
**Category:** General\
**Created:** [March 4, 2024, 5:16pm UTC](https://fenicsproject.discourse.group/t/fenicsx-takes-up-too-much-disk-space-generates-a-lot-of-cache-files-clear-cache/13812 "2024-03-04T17:16:05Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yankang\_Liu](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/yankang_liu/32/5392_2.png) [@Yankang\_Liu](https://fenicsproject.discourse.group/u/Yankang_Liu)\
**Post date:** [March 4, 2024, 5:16pm UTC](https://fenicsproject.discourse.group/t/fenicsx-takes-up-too-much-disk-space-generates-a-lot-of-cache-files-clear-cache/13812/1 "2024-03-04T17:16:05Z")

</div>

This post address the issue that after running fenicsx for several times, the cache file takes too much disk storage. Sometimes the program interrupted with error prompting clear cache. Below is my solution in the user end.

---

<div class="post-metadata">

**Author:** ![Yankang\_Liu](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/yankang_liu/32/5392_2.png) [@Yankang\_Liu](https://fenicsproject.discourse.group/u/Yankang_Liu)\
**Post date:** [March 4, 2024, 5:20pm UTC](https://fenicsproject.discourse.group/t/fenicsx-takes-up-too-much-disk-space-generates-a-lot-of-cache-files-clear-cache/13812/2 "2024-03-04T17:20:29Z")

</div>

You can find and clear the hidden file .cache. You can confirm if this files takes huge space before deleting.

For Mac user, go to the disk you install fenicsx, go to Users/your\_user\_name/, and press cmd+shift+. to show hidden files, delete .cache.

For Ubuntu, go to Home, press Ctrl+H to show hidden files, delete .cache.

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [March 4, 2024, 5:28pm UTC](https://fenicsproject.discourse.group/t/fenicsx-takes-up-too-much-disk-space-generates-a-lot-of-cache-files-clear-cache/13812/3 "2024-03-04T17:28:27Z")

</div>

Note that FEniCSx should not generate a lot of files in cache.

This might point to a systematic issue in your code where your form should be independent of some parameters, but you are compiling a file for each option (say a constant value that is changing, but not wrapped as `dolfinx.fem.Constant`. See for instance: [Form compilation — FEniCS Tutorial @ Sorbonne](https://jsdokken.com/FEniCS23-tutorial/src/form_compilation.html) which contains various ways of minimizing the amount of generated code.

---

<div class="post-metadata">

**Author:** ![Yankang\_Liu](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/yankang_liu/32/5392_2.png) [@Yankang\_Liu](https://fenicsproject.discourse.group/u/Yankang_Liu)\
**Post date:** [March 4, 2024, 6:10pm UTC](https://fenicsproject.discourse.group/t/fenicsx-takes-up-too-much-disk-space-generates-a-lot-of-cache-files-clear-cache/13812/4 "2024-03-04T18:10:46Z")

</div>

Should I define all numbers in my code using `dolfinx.fem.Constant` or just for the changed ones or doesn’t matter?

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [March 4, 2024, 6:18pm UTC](https://fenicsproject.discourse.group/t/fenicsx-takes-up-too-much-disk-space-generates-a-lot-of-cache-files-clear-cache/13812/5 "2024-03-04T18:18:23Z")

</div>

For any number that might change within a loop, causing you to have to re-call `dolfinx.fem.form` you should define them as constants outside the loop. If you have parameters that will never change, say like a 0.5 or so, you don’t need to wrap it (but it doesn’t hurt to wrap it)

---

<div class="post-metadata">

**Author:** ![Yankang\_Liu](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/yankang_liu/32/5392_2.png) [@Yankang\_Liu](https://fenicsproject.discourse.group/u/Yankang_Liu)\
**Post date:** [March 4, 2024, 6:22pm UTC](https://fenicsproject.discourse.group/t/fenicsx-takes-up-too-much-disk-space-generates-a-lot-of-cache-files-clear-cache/13812/6 "2024-03-04T18:22:09Z")

</div>

I see thank you very much!

---

<div class="post-metadata">

**Author:** ![Yankang\_Liu](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/yankang_liu/32/5392_2.png) [@Yankang\_Liu](https://fenicsproject.discourse.group/u/Yankang_Liu)\
**Post date:** [March 4, 2024, 7:19pm UTC](https://fenicsproject.discourse.group/t/fenicsx-takes-up-too-much-disk-space-generates-a-lot-of-cache-files-clear-cache/13812/7 "2024-03-04T19:19:56Z")

</div>

By the way do I need to clear cache some time even I define constant variable as you indicated if I have to solve the nonlinear systems tens of thousands of times or even more?

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [March 4, 2024, 7:46pm UTC](https://fenicsproject.discourse.group/t/fenicsx-takes-up-too-much-disk-space-generates-a-lot-of-cache-files-clear-cache/13812/8 "2024-03-04T19:46:58Z")

</div>

No, if you define your form outside the loops, and ensure that it is generalized for the various runs and iterations, there will only be code generation once.

---

<div class="post-metadata">

**Author:** ![Yankang\_Liu](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/yankang_liu/32/5392_2.png) [@Yankang\_Liu](https://fenicsproject.discourse.group/u/Yankang_Liu)\
**Post date:** [March 4, 2024, 8:27pm UTC](https://fenicsproject.discourse.group/t/fenicsx-takes-up-too-much-disk-space-generates-a-lot-of-cache-files-clear-cache/13812/9 "2024-03-04T20:27:32Z")

</div>

I see thank you very much!
