CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

Is there a trigger that tells me whether the matrix has changed

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 10, 2025, 20:13
Default Is there a trigger that tells me whether the matrix has changed
  #1
Senior Member
 
Klaus
Join Date: Mar 2009
Posts: 293
Rep Power: 23
klausb will become famous soon enough
I am looking for a (boolean) trigger that tells me whether the matrix has changed since the last check to be able to cache and re-use data.


The idea is to toggle between true and false and re-use data as often as possible to avoid expensive re-calculations.

Is there something like that?
klausb is offline   Reply With Quote

Old   April 23, 2025, 09:47
Default
  #2
Member
 
Amirhossein Taran
Join Date: Sep 2016
Location: Dublin, Ireland
Posts: 65
Rep Power: 10
amirhosseintaran is on a distinguished road
Quote:
Originally Posted by klausb View Post
I am looking for a (boolean) trigger that tells me whether the matrix has changed since the last check to be able to cache and re-use data.


The idea is to toggle between true and false and re-use data as often as possible to avoid expensive re-calculations.

Is there something like that?

Hi Klaus,

I don't understand why you can't define this boolean yourself.

e.g. comparing the matrix with itself shows whether it has changed or not!


Regards,
Amir.
amirhosseintaran is offline   Reply With Quote

Old   April 25, 2025, 14:00
Default
  #3
New Member
 
Junchao Zhang
Join Date: Jan 2025
Location: U.S.
Posts: 15
Rep Power: 2
jczhang is on a distinguished road
Quote:
Originally Posted by amirhosseintaran View Post
Hi Klaus,

I don't understand why you can't define this boolean yourself.

e.g. comparing the matrix with itself shows whether it has changed or not!


Regards,
Amir.
Wow, I also had the same question. To compare, you need to save the old matrix. There is a cost in saving the matrix and then comparing. We want to avoid the cost.
jczhang is offline   Reply With Quote

Old   April 27, 2025, 05:13
Default
  #4
Senior Member
 
Klaus
Join Date: Mar 2009
Posts: 293
Rep Power: 23
klausb will become famous soon enough
The point is indeed, that comparing entire matrices has a significant impact on data storage requirements and overall performance even when using hash algorithms and I am looking for ways to speed simulations up.
klausb is offline   Reply With Quote

Old   April 28, 2025, 00:00
Default
  #5
Senior Member
 
Arjun
Join Date: Mar 2009
Location: Nurenberg, Germany
Posts: 1,310
Rep Power: 36
arjun will become famous soon enougharjun will become famous soon enough
Quote:
Originally Posted by klausb View Post
The point is indeed, that comparing entire matrices has a significant impact on data storage requirements and overall performance even when using hash algorithms and I am looking for ways to speed simulations up.


Just save the sum of diagonals and sum of off diagonals in two variables. Just compare these two values and see if they changed above a thresold.

You can also add, min, max of dia and min max of off diagonals. This was you do not need to store last matrix.
arjun is offline   Reply With Quote

Old   April 28, 2025, 09:57
Default
  #6
New Member
 
Junchao Zhang
Join Date: Jan 2025
Location: U.S.
Posts: 15
Rep Power: 2
jczhang is on a distinguished road
I feel all these approach are unsafe with respect to false positive, i.e., the sums of entries of two matrices are equal but the two matrices are not equal.
jczhang is offline   Reply With Quote

Old   April 29, 2025, 07:45
Default
  #7
Senior Member
 
Arjun
Join Date: Mar 2009
Location: Nurenberg, Germany
Posts: 1,310
Rep Power: 36
arjun will become famous soon enougharjun will become famous soon enough
Quote:
Originally Posted by jczhang View Post
I feel all these approach are unsafe with respect to false positive, i.e., the sums of entries of two matrices are equal but the two matrices are not equal.



Only way to be hundred percent sure is to cache the matrix. Any other method will always have some doubts.
arjun is offline   Reply With Quote

Old   April 29, 2025, 23:47
Default
  #8
New Member
 
Junchao Zhang
Join Date: Jan 2025
Location: U.S.
Posts: 15
Rep Power: 2
jczhang is on a distinguished road
Quote:
Originally Posted by arjun View Post
Only way to be hundred percent sure is to cache the matrix. Any other method will always have some doubts.
It depends on the design. For example, in petsc a matrix has a two integer attributes: state and nonzerostate. Whenever the sparsity pattern changed, the nonzerostate is increased; and whenever an operation modifying matrix values is called, the state is increased. With that, one can easily and safely detect matrix changes.
jczhang is offline   Reply With Quote

Old   May 1, 2025, 04:05
Default
  #9
Senior Member
 
Domenico Lahaye
Join Date: Dec 2013
Posts: 844
Blog Entries: 1
Rep Power: 19
dlahaye is on a distinguished road
Quote:
Originally Posted by klausb View Post
I am looking for a (boolean) trigger that tells me whether the matrix has changed since the last check to be able to cache and re-use data.


The idea is to toggle between true and false and re-use data as often as possible to avoid expensive re-calculations.

Is there something like that?
1/ I think it is save to assume that the matrix changes at every inner iteration of e.g. a SIMPLE iteration. You might this be looking for deviations from this rule;

2/ When is matrix assembly a computational bottleneck?
dlahaye is offline   Reply With Quote

Old   May 2, 2025, 07:08
Default
  #10
Senior Member
 
Klaus
Join Date: Mar 2009
Posts: 293
Rep Power: 23
klausb will become famous soon enough
@dlahaye


1/ I think it is save to assume that the matrix changes at every inner iteration of e.g. a SIMPLE iteration. You might this be looking for deviations from this rule;

>> Not really, it depends on the simulation type, e.g. moving mesh...


2/ When is matrix assembly a computational bottleneck?

>> It's not. A matrix change, changes the eigenvalues, which triggers computationally expensive re-calculations which I want to keep to a minimum
klausb is offline   Reply With Quote

Old   May 2, 2025, 08:39
Default
  #11
Senior Member
 
Arjun
Join Date: Mar 2009
Location: Nurenberg, Germany
Posts: 1,310
Rep Power: 36
arjun will become famous soon enougharjun will become famous soon enough
Quote:
Originally Posted by jczhang View Post
It depends on the design. For example, in petsc a matrix has a two integer attributes: state and nonzerostate. Whenever the sparsity pattern changed, the nonzerostate is increased; and whenever an operation modifying matrix values is called, the state is increased. With that, one can easily and safely detect matrix changes.



Then i think you do not understand the problem that has been discussed.

Every iteration an operation modiying the matrix IS performed thanks to descretization.

What we are talking about is matrix being same as last iteration that one obtained after descretization. This matrix will stop to be different once the convergence is achieved.
arjun is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Access and modify zero matrix coefficient thang_cegroup OpenFOAM Programming & Development 0 April 16, 2019 23:01
Problem simulating the temperature rise in a composite material (chtMultiRegionFoam) Adam_K OpenFOAM Running, Solving & CFD 2 March 27, 2019 06:51
How can I get the number of elements per row form the matrix? klausb OpenFOAM Programming & Development 2 December 30, 2018 15:27
Changing viewfactor Model and use the changed my model by calling "mySolver" FabianF OpenFOAM Programming & Development 2 January 14, 2014 11:25
How to find the product of A+ matrix and A- matrix arjun shanker Main CFD Forum 0 November 12, 2010 22:12


All times are GMT -4. The time now is 02:36.