Re: [deal.II] Create a LinearOperator with a function instead of a matrix

2019-07-19 Thread Wolfgang Bangerth
> Would that work together with the GMG-preconditioner?

You mean you want to use the linear operator as a smoother for the GMG? Or 
where in the GMG do you want to use it?


> Will test it there as 
> soon as my problem in my second question could be solved.
> There I have the following code:
> |
> SolverControl       coarse_solver_control(1000,1e-10,false,false);
> SolverGMRES  coarse_solver(coarse_solver_control);
> PreconditionIdentityid;
> MGCoarseGridIterativeSolver SolverGMRES,
>              matrix_t,
> PreconditionIdentity>
>              coarse_grid_solver(coarse_solver,coarse_matrix,id);
> 
> usingSmoother=LA::MPI::PreconditionJacobi;
> MGSmootherPreconditionmg_smoother;
>      mg_smoother.initialize(mg_matrices,Smoother::AdditionalData(0.5));
>      mg_smoother.set_steps(2);
> 
>      mg::Matrixmg_matrix(mg_matrices);
>      mg::Matrixmg_interface_up(mg_interface_matrices);
>      mg::Matrixmg_interface_down(mg_interface_matrices);
> 
> Multigridmg(mg_matrix,coarse_grid_solver,mg_transfer,mg_smoother,mg_smoother);
>      mg.set_edge_matrices(mg_interface_down,mg_interface_up);
> 
> PreconditionMG>preconditioner(dof_handler,
>   
>  
>   mg,
>   
>  
>   mg_transfer);
> |
> 
> and here I intent to replace all occurences of matrix_t with my custom 
> LinearOperator (if that makes sense).

I don't know the multigrid well enough, but I would expect that it really only 
wants something that has a vmult.

My recommendation would be, if you don't know whether something would work, to 
just try it out.

Best
  W.

-- 

Wolfgang Bangerth  email: bange...@colostate.edu
www: http://www.math.colostate.edu/~bangerth/

-- 
The deal.II project is located at http://www.dealii.org/
For mailing list/forum options, see 
https://groups.google.com/d/forum/dealii?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"deal.II User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to dealii+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/dealii/6c2358d2-c9b6-1ca3-8212-8973a4aca5a4%40colostate.edu.


Re: [deal.II] Create a LinearOperator with a function instead of a matrix

2019-07-19 Thread 'Maxi Miller' via deal.II User Group
Would that work together with the GMG-preconditioner? Will test it there as 
soon as my problem in my second question could be solved.
There I have the following code:

SolverControlcoarse_solver_control(1000, 1e-10, false, false);
SolverGMRES   coarse_solver(coarse_solver_control);
PreconditionIdentity id;
MGCoarseGridIterativeSolver,
matrix_t,
PreconditionIdentity>
coarse_grid_solver(coarse_solver, coarse_matrix, id);

using Smoother = LA::MPI::PreconditionJacobi;
MGSmootherPrecondition mg_smoother;
mg_smoother.initialize(mg_matrices, Smoother::AdditionalData(0.5));
mg_smoother.set_steps(2);

mg::Matrix mg_matrix(mg_matrices);
mg::Matrix mg_interface_up(mg_interface_matrices);
mg::Matrix mg_interface_down(mg_interface_matrices);

Multigrid mg(mg_matrix, coarse_grid_solver, mg_transfer, 
mg_smoother, mg_smoother);
mg.set_edge_matrices(mg_interface_down, mg_interface_up);

PreconditionMG> 
preconditioner(dof_handler,

   mg,

   mg_transfer);

and here I intent to replace all occurences of matrix_t with my custom 
LinearOperator (if that makes sense).

Am Freitag, 19. Juli 2019 17:51:10 UTC+2 schrieb Wolfgang Bangerth:
>
> On 7/19/19 9:47 AM, 'Maxi Miller' via deal.II User Group wrote: 
> > What I did was the replacement of system_matrix with a function, 
> providing a 
> > vmult()-function. Now I would like to add a preconditioner based on that 
> > function to reduce the necessary GMRES-iterations. But until now most of 
> the 
> > preconditioners require a matrix for initialization. Thus I wanted to 
> replace 
> > that matrix with my LinearOperator, if that is possible? 
>
> Yes, as I already said, this is possible. Have you tried? 
>
> I think you should also be able to look at step-20 (and maybe 22) for 
> examples. 
>
> Best 
>   W. 
>
> -- 
>  
> Wolfgang Bangerth  email: bang...@colostate.edu 
>  
> www: http://www.math.colostate.edu/~bangerth/ 
>
>

-- 
The deal.II project is located at http://www.dealii.org/
For mailing list/forum options, see 
https://groups.google.com/d/forum/dealii?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"deal.II User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to dealii+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/dealii/0c8f71f7-8d29-4a4f-abb1-65afbcc72669%40googlegroups.com.


Re: [deal.II] Create a LinearOperator with a function instead of a matrix

2019-07-19 Thread Wolfgang Bangerth
On 7/19/19 9:47 AM, 'Maxi Miller' via deal.II User Group wrote:
> What I did was the replacement of system_matrix with a function, providing a 
> vmult()-function. Now I would like to add a preconditioner based on that 
> function to reduce the necessary GMRES-iterations. But until now most of the 
> preconditioners require a matrix for initialization. Thus I wanted to replace 
> that matrix with my LinearOperator, if that is possible?

Yes, as I already said, this is possible. Have you tried?

I think you should also be able to look at step-20 (and maybe 22) for examples.

Best
  W.

-- 

Wolfgang Bangerth  email: bange...@colostate.edu
www: http://www.math.colostate.edu/~bangerth/

-- 
The deal.II project is located at http://www.dealii.org/
For mailing list/forum options, see 
https://groups.google.com/d/forum/dealii?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"deal.II User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to dealii+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/dealii/9a9c4ce7-dbda-12e0-ceb6-325019686981%40colostate.edu.


Re: [deal.II] Create a LinearOperator with a function instead of a matrix

2019-07-19 Thread 'Maxi Miller' via deal.II User Group
What I did was the replacement of system_matrix with a function, providing 
a vmult()-function. Now I would like to add a preconditioner based on that 
function to reduce the necessary GMRES-iterations. But until now most of 
the preconditioners require a matrix for initialization. Thus I wanted to 
replace that matrix with my LinearOperator, if that is possible?

-- 
The deal.II project is located at http://www.dealii.org/
For mailing list/forum options, see 
https://groups.google.com/d/forum/dealii?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"deal.II User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to dealii+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/dealii/953da0b8-eb40-4ac1-8316-042c382f2978%40googlegroups.com.


Re: [deal.II] Create a LinearOperator with a function instead of a matrix

2019-07-19 Thread Wolfgang Bangerth
On 7/19/19 9:34 AM, 'Maxi Miller' via deal.II User Group wrote:
> I.e. (based on step-37) I can write something like
> |
> LinearOperator jacobian_operator;
> //vmult-operation is added later
> 
> using SystemMatrixType = jacobian_operator;
> SystemMatrixType system_matrix;
> |
> 
> and follow the example accordingly?

No. `jacobian_operator` here is the name of a local variable, but in a `using` 
statement, the right hand side needs to be a *type*.

What I'm saying is that you should be able to write something of the sort
   SolverCG<...>  solver_cg;
   solver_cg.solve (system_matrix, solution, rhs,
jacobian_operator);
where the last argument is any kind of type that provides a vmult something -- 
whether it's a matrix, a class with a vmult function, or a linear operator.

Best
  W.

-- 

Wolfgang Bangerth  email: bange...@colostate.edu
www: http://www.math.colostate.edu/~bangerth/

-- 
The deal.II project is located at http://www.dealii.org/
For mailing list/forum options, see 
https://groups.google.com/d/forum/dealii?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"deal.II User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to dealii+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/dealii/73877be0-e337-bf85-2792-ba31837a91b1%40colostate.edu.


Re: [deal.II] Create a LinearOperator with a function instead of a matrix

2019-07-19 Thread 'Maxi Miller' via deal.II User Group
I.e. (based on step-37) I can write something like
LinearOperator jacobian_operator;
//vmult-operation is added later

 using SystemMatrixType = jacobian_operator;
 SystemMatrixType system_matrix;

and follow the example accordingly?

Am Freitag, 19. Juli 2019 17:26:31 UTC+2 schrieb Wolfgang Bangerth:
>
> On 7/19/19 9:18 AM, 'Maxi Miller' via deal.II User Group wrote: 
> > Is it then possible to use this LinearOperator in a preconditioner? The 
> code 
> > works without one (i.e. PreconditionIdentity()), but the Iterations are 
> > increasing quite fast, thus negating all speedup gained from the 
> LinearOperator. 
> > I tried to find something in the examples, but only found data about 
> using 
> > matrices as input for preconditioners, not pure LinearOperators 
> containing 
> > only a vmult-function. 
>
> Yes, this is supposed to work! 
> Best 
>   W. 
>
> -- 
>  
> Wolfgang Bangerth  email: bang...@colostate.edu 
>  
> www: http://www.math.colostate.edu/~bangerth/ 
>
>

-- 
The deal.II project is located at http://www.dealii.org/
For mailing list/forum options, see 
https://groups.google.com/d/forum/dealii?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"deal.II User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to dealii+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/dealii/a77e57c0-c126-4b81-a41b-f95b45342897%40googlegroups.com.


Re: [deal.II] Create a LinearOperator with a function instead of a matrix

2019-07-19 Thread Wolfgang Bangerth
On 7/19/19 9:18 AM, 'Maxi Miller' via deal.II User Group wrote:
> Is it then possible to use this LinearOperator in a preconditioner? The code 
> works without one (i.e. PreconditionIdentity()), but the Iterations are 
> increasing quite fast, thus negating all speedup gained from the 
> LinearOperator.
> I tried to find something in the examples, but only found data about using 
> matrices as input for preconditioners, not pure LinearOperators containing 
> only a vmult-function.

Yes, this is supposed to work!
Best
  W.

-- 

Wolfgang Bangerth  email: bange...@colostate.edu
www: http://www.math.colostate.edu/~bangerth/

-- 
The deal.II project is located at http://www.dealii.org/
For mailing list/forum options, see 
https://groups.google.com/d/forum/dealii?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"deal.II User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to dealii+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/dealii/8ff18c35-5f31-c35f-b79e-1eb3d3fde1a6%40colostate.edu.


Re: [deal.II] Create a LinearOperator with a function instead of a matrix

2019-07-19 Thread 'Maxi Miller' via deal.II User Group
Is it then possible to use this LinearOperator in a preconditioner? The 
code works without one (i.e. PreconditionIdentity()), but the Iterations 
are increasing quite fast, thus negating all speedup gained from the 
LinearOperator.
I tried to find something in the examples, but only found data about using 
matrices as input for preconditioners, not pure LinearOperators containing 
only a vmult-function.

Am Dienstag, 16. Juli 2019 18:21:28 UTC+2 schrieb Matthias Maier:
>
> A short comment: 
>
> On Tue, Jul 16, 2019, at 11:18 CDT, Matthias Maier  > wrote: 
>
> > struct LeftVector { 
> > }; 
>
> > struct RightVector { 
> > }; 
>
> These two classes are of course just decoration (showing the minimal 
> interface a vector has to possess). There is usually no need to define 
> custom Vector clases. 
>

-- 
The deal.II project is located at http://www.dealii.org/
For mailing list/forum options, see 
https://groups.google.com/d/forum/dealii?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"deal.II User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to dealii+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/dealii/c7bc4fb5-1cf7-46ce-af94-2bd5a796715d%40googlegroups.com.


Re: [deal.II] Create a LinearOperator with a function instead of a matrix

2019-07-16 Thread Matthias Maier
A short comment:

On Tue, Jul 16, 2019, at 11:18 CDT, Matthias Maier  wrote:

> struct LeftVector {
> };

> struct RightVector {
> };

These two classes are of course just decoration (showing the minimal
interface a vector has to possess). There is usually no need to define
custom Vector clases.

-- 
The deal.II project is located at http://www.dealii.org/
For mailing list/forum options, see 
https://groups.google.com/d/forum/dealii?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"deal.II User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to dealii+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/dealii/87d0iaar22.fsf%4043-1.org.
For more options, visit https://groups.google.com/d/optout.


Re: [deal.II] Create a LinearOperator with a function instead of a matrix

2019-07-16 Thread Matthias Maier
Hi,

the following example (which is a simplified version of test
lac/linear_operator_01) should get you started. In short: Simply create
an empty LinearOperator object (with the appropriate template
parameters) and populate the corresponding std::function objects.

Best,
Matthias



#include 
#include 

using namespace dealii;

struct LeftVector {
  typedef double value_type;
  value_type value;

  LeftVector =(value_type new_value)
  {
value = new_value;
return *this;
  }
  LeftVector *=(value_type scale)
  {
value *= scale;
return *this;
  }
  LeftVector /=(value_type scale)
  {
value /= scale;
return *this;
  }
  LeftVector +=(const LeftVector )
  {
value += u.value;
return *this;
  }
  int size() const
  {
return 1;
  }
  std::size_t memory_consumption() const
  {
return 1;
  }
};

struct RightVector {
  typedef double value_type;
  value_type value;

  RightVector =(value_type new_value)
  {
value = new_value;
return *this;
  }
  RightVector *=(value_type scale)
  {
value *= scale;
return *this;
  }
  RightVector /=(value_type scale)
  {
value /= scale;
return *this;
  }
  RightVector +=(const RightVector )
  {
value += u.value;
return *this;
  }
  int size() const
  {
return 1;
  }
  std::size_t memory_consumption() const
  {
return 1;
  }
};

int main()
{
  LinearOperator multiply2;

  multiply2.vmult = [](LeftVector , const RightVector ) {
v.value = 2 * u.value;
  };
  multiply2.vmult_add = [](LeftVector , const RightVector ) {
v.value += 2 * u.value;
  };
  multiply2.Tvmult = [](RightVector , const LeftVector ) {
v.value = 2 * u.value;
  };
  multiply2.Tvmult_add = [](RightVector , const LeftVector ) {
v.value += 2 * u.value;
  };
  multiply2.reinit_range_vector = [](LeftVector &, bool omit_zeroing_values) {
// do nothing
  };
  multiply2.reinit_domain_vector = [](RightVector &, bool omit_zeroing_values) {
// do nothing
  };

  // Small test:

  RightVector u = {4.};
  LeftVector v = {0.};

  multiply2.vmult(v, u);
  std::cout << "2 * " << u.value << " = " << v.value << std::endl;

  multiply2.vmult_add(v, u);
  std::cout << "... + 2 * " << u.value << " = " << v.value << std::endl;

  return 0;
}

-- 
The deal.II project is located at http://www.dealii.org/
For mailing list/forum options, see 
https://groups.google.com/d/forum/dealii?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"deal.II User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to dealii+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/dealii/87h87mar6y.fsf%4043-1.org.
For more options, visit https://groups.google.com/d/optout.