[Trilinos-Users] AztecOO: result is zero?
Sensei
senseiwa at gmail.com
Mon Apr 4 11:49:15 MDT 2011
On Apr 4, 2011, at 1:45pm, dorian.krause at usi.ch wrote:
>
> On Apr 4, 2011, at 1:06 PM, Sensei wrote:
>
>> I don't understand... Solving a linear problem with a 2D laplacian matrix should be a piece of cake: shouldn't it converge to the correct result, and not zero?
>>
> If the right hand side is zero, the exact solution is zero. In the code,
> you can find theses lines:
>
>
> Epetra_Vector<http://trilinos.sandia.gov/packages/docs/r6.0/packages/epetra/doc/html/classEpetra__Vector.html> x(Map);
> Epetra_Vector<http://trilinos.sandia.gov/packages/docs/r6.0/packages/epetra/doc/html/classEpetra__Vector.html> b(Map);
>
> x.Random();
>
>
> This initializes x with random values and b with zeros (since the zeroOut value is true by default).
Then I am probably doing something terribly wrong. I think I am missing something in my code, or worse, I forgot how solvers work!
First, I am initializing the known term v, with values 10 * (index + 1), and it prints ok, so the following code works.
Epetra_Vector v(Map);
// set every element in the vector
for (i = 0; i < Map.NumMyElements(); i++)
{
v[i] = 10 * (i + 1 + Map.MinMyGID());
}
Next, I set the matrix to a (standard metrics) laplacian matrix (with elements being +1 -2 +1). The matrix prints fine after GlobalAssemble().
Finally, I set up the linear problem and the solver:
// results vector
Epetra_Vector res(Map);
// construct the linear problem
Epetra_LinearProblem lp(&m, &res, &v);
// solver
AztecOO solver(lp);
// get defaults and set them
int opt[AZ_OPTIONS_SIZE];
double par[AZ_PARAMS_SIZE];
AZ_defaults(opt, par);
solver.SetAllAztecOptions(opt);
solver.SetAllAztecParams(par);
// set specific parameters
solver.SetAztecOption(AZ_solver, AZ_cg);
solver.Iterate(1000, 10e-9);
From the documentation I see that Epetra_LinearProblem needs, in order, the matrix, the resulting vector, and the known term. In my code, I am passing them in order, I think!
However, res contains only zero values. In contrast, if I initialize res with v (copy constructor), res will end up containing all the original values of v.
So, is my code completely a havoc? What am I missing and doing wrong?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://software.sandia.gov/pipermail/trilinos-users/attachments/20110404/8f8c72ac/attachment-0001.html
More information about the Trilinos-Users
mailing list