[petsc-users] How can I do matrix addition with different nonzeros patterns correctly?

Matthew Knepley knepley at gmail.com
Sat Mar 4 09:49:20 CST 2017


On Fri, Mar 3, 2017 at 5:12 PM, Fangbo Wang <fangbowa at buffalo.edu> wrote:

> I am doing analysis on wave propagation through a linear solid media using
> finite element method. The PDE from the system can be discretized to a
> system of linear equations.
> Newmark method is used to solve this problem with changing waves along
> time.
>
> Here, the A, B, C, D mean stiffness matrix, mass matrix, damping matrix,
> effective stiffness matrix of the system, respectively.  The scalars are
> just some random numbers I put.
>

Since this is explicit, you should just be assembling the entire system
directly in to one matrix, rather than making several matrices and doing
algebra.

   Matt


> On Fri, Mar 3, 2017 at 4:55 PM, Barry Smith <bsmith at mcs.anl.gov> wrote:
>
>>
>> > On Mar 3, 2017, at 3:31 PM, Fangbo Wang <fangbowa at buffalo.edu> wrote:
>> >
>> > Hi,
>> >
>> > I am a little bit confused on how to appropriately do matrix addition
>> with different nonzeros patterns.
>> >
>> > Suppose I want to do D=2*A+3*B+4*C, A, B and C all have different
>> nonzero patterns.
>> > I know I can use MatDuplicate, MatCopy, MatConvert to create a matrix
>> D, which way is the right way?
>>
>>    There is no particular "right way". You could use a MatDuplicate()
>> then a MatScale and then two MatAXPY()
>>
>>    D=2*A+3*B+4*C looks like a MATLAB thing, not something you would need
>> to do when solving PDEs, where do you get this need? Perhaps there is an
>> alternative way to get what you want.
>>
>> >
>> > What's the difference between MatDuplicate and MatCopy?
>>
>>    MatDuplicate() CREATES a new matrix while MatCopy() copies values from
>> an already existing matrix to another already existing matrix.
>>
>>
>> >
>> > Thank you very much!
>> >
>> > Best regards,
>> >
>> > Fangbo
>> >
>> >
>> > --
>> > Fangbo Wang, PhD student
>> > Stochastic Geomechanics Research Group
>> > Department of Civil, Structural and Environmental Engineering
>> > University at Buffalo
>> > Email: fangbowa at buffalo.edu
>>
>>
>
>
> --
> Fangbo Wang, PhD student
> Stochastic Geomechanics Research Group
> Department of Civil, Structural and Environmental Engineering
> University at Buffalo
> Email: *fangbowa at buffalo.edu <fangbowa at buffalo.edu>*
>



-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20170304/06c481d6/attachment.html>


More information about the petsc-users mailing list