## Re: [Libmesh-users] Reusing the same stiffness matrix with different force vectors?

 Re: [Libmesh-users] Reusing the same stiffness matrix with different force vectors? From: David Knezevic - 2012-07-05 18:35:50 ```On 07/05/2012 02:34 PM, James J Ramsey wrote: > On Thu, Jul 5, 2012 at 1:34 PM, David Knezevic > wrote: >> The init() should be before the loop, it doesn't need to be called >> before each solve. > I wondered about that. When does init() need to be called, though? The > examples tend to put it almost right before the solve(), and it's not > clear what exactly it's initializing. It initializes the system, i.e. it sets up the degree-of-freedom numbering, the matrix sparsity pattern etc etc. These things don't change from one solve to the next. ```

 [Libmesh-users] Reusing the same stiffness matrix with different force vectors? From: James J Ramsey - 2012-07-03 12:55:50 ```I noticed that the examples generally have the stiffness matrix and force vector assembled in some function that becomes an argument to the "attach_assemble_function" method. I have a possible application in mind that involves using the same stiffness matrix with different force vectors. Is there a way that I can do this without recalculating the stiffness matrix each time? ```
 Re: [Libmesh-users] Reusing the same stiffness matrix with different force vectors? From: David Knezevic - 2012-07-03 14:16:23 ```System has a public boolean called "assemble_before_solve", which is true by default. Set that to false and then solve() won't call assemble, e.g. see LinearImplicitSystem::solve(). You'll have to make sure to call your assembly function yourself when appropriate though. David On 07/03/2012 08:55 AM, James J Ramsey wrote: > I noticed that the examples generally have the stiffness matrix and > force vector assembled in some function that becomes an argument to > the "attach_assemble_function" method. I have a possible application > in mind that involves using the same stiffness matrix with different > force vectors. Is there a way that I can do this without recalculating > the stiffness matrix each time? > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > Libmesh-users mailing list > Libmesh-users@... > https://lists.sourceforge.net/lists/listinfo/libmesh-users ```
 Re: [Libmesh-users] Reusing the same stiffness matrix with different force vectors? From: David Knezevic - 2012-07-03 14:25:15 ```On 07/03/2012 10:16 AM, David Knezevic wrote: > System has a public boolean called "assemble_before_solve", which is > true by default. Set that to false and then solve() won't call assemble, > e.g. see LinearImplicitSystem::solve(). You'll have to make sure to call > your assembly function yourself when appropriate though. Or even easier is to put the stiffness matrix part of your assembly inside an "if" statement and use equation_systems.parameters to determine whether or not to do the matrix assembly. Also, if you're not changing the matrix, it's good to set "reuse_preconditioner(true)" in the System's linear_solver after the first solve. > > On 07/03/2012 08:55 AM, James J Ramsey wrote: >> I noticed that the examples generally have the stiffness matrix and >> force vector assembled in some function that becomes an argument to >> the "attach_assemble_function" method. I have a possible application >> in mind that involves using the same stiffness matrix with different >> force vectors. Is there a way that I can do this without recalculating >> the stiffness matrix each time? >> >> ------------------------------------------------------------------------------ >> Live Security Virtual Conference >> Exclusive live event will cover all the ways today's security and >> threat landscape has changed and how IT managers can respond. Discussions >> will include endpoint security, mobile security and the latest in malware >> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ >> _______________________________________________ >> Libmesh-users mailing list >> Libmesh-users@... >> https://lists.sourceforge.net/lists/listinfo/libmesh-users > > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > Libmesh-users mailing list > Libmesh-users@... > https://lists.sourceforge.net/lists/listinfo/libmesh-users ```
 Re: [Libmesh-users] Reusing the same stiffness matrix with different force vectors? From: James J Ramsey - 2012-07-05 16:18:27 ```On Tue, Jul 3, 2012 at 10:25 AM, David Knezevic wrote: > > On 07/03/2012 10:16 AM, David Knezevic wrote: > > Or even easier is to put the stiffness matrix part of your assembly > inside an "if" statement and use equation_systems.parameters to > determine whether or not to do the matrix assembly. So I gather I'd do something like this: // Misc. setup ... equation_systems.get_system("My system").attach_assemble_function(my_assemble_function); for (int vecNum = 0; vecNum < numVecs; vecNum++) { equation_systems.set("vecNum") = vecNum; equation_systems.init(); // Does this need to be inside the loop, right before the solve? equation_systems.get_system("My system").solve(); } ... void my_assemble_function(EquationSystems& es, const std::string& system_name) { // Misc. setup ... if es.parameters.get("vecNum") == 0 { // Code for assembling stiffness matrix } // Code for assembling force vector } For this to work, whatever stiffness matrix was created during the first call to my_assemble_function would have to persist until subsequent calls. Are you sure the stiffness matrix isn't destroyed by calls to init() or whatever other bookkeeping precedes the call to the assembly function? ```
 Re: [Libmesh-users] Reusing the same stiffness matrix with different force vectors? From: David Knezevic - 2012-07-05 17:34:21 ```On 07/05/2012 11:51 AM, James J Ramsey wrote: > On Tue, Jul 3, 2012 at 10:25 AM, David Knezevic > wrote: >> On 07/03/2012 10:16 AM, David Knezevic wrote: >> >> Or even easier is to put the stiffness matrix part of your assembly >> inside an "if" statement and use equation_systems.parameters to >> determine whether or not to do the matrix assembly. > So I gather I'd do something like this: > > // Misc. setup ... > > equation_systems.get_system("My > system").attach_assemble_function(my_assemble_function); > > for (int vecNum = 0; vecNum < numVecs; vecNum++) { > equation_systems.set("vecNum") = vecNum; > equation_systems.init(); // Does this need to be inside the loop, > right before the solve? > equation_systems.get_system("My system").solve(); > } > The init() should be before the loop, it doesn't need to be called before each solve. > void my_assemble_function(EquationSystems& es, const std::string& system_name) { > // Misc. setup ... > > if es.parameters.get("vecNum") == 0 { > // Code for assembling stiffness matrix > } > > // Code for assembling force vector > } > > For this to work, whatever stiffness matrix was created during the > first call to my_assemble_function would have to persist until > subsequent calls. Are you sure the stiffness matrix isn't destroyed by > calls to init() or whatever other bookkeeping precedes the call to the > assembly function? If you move the init() before the loop it should work fine... David ```
 Re: [Libmesh-users] Reusing the same stiffness matrix with different force vectors? From: James J Ramsey - 2012-07-05 18:34:26 ```On Thu, Jul 5, 2012 at 1:34 PM, David Knezevic wrote: > > The init() should be before the loop, it doesn't need to be called > before each solve. I wondered about that. When does init() need to be called, though? The examples tend to put it almost right before the solve(), and it's not clear what exactly it's initializing. ```
 Re: [Libmesh-users] Reusing the same stiffness matrix with different force vectors? From: David Knezevic - 2012-07-05 18:35:50 ```On 07/05/2012 02:34 PM, James J Ramsey wrote: > On Thu, Jul 5, 2012 at 1:34 PM, David Knezevic > wrote: >> The init() should be before the loop, it doesn't need to be called >> before each solve. > I wondered about that. When does init() need to be called, though? The > examples tend to put it almost right before the solve(), and it's not > clear what exactly it's initializing. It initializes the system, i.e. it sets up the degree-of-freedom numbering, the matrix sparsity pattern etc etc. These things don't change from one solve to the next. ```