Poster of Linux kernelThe best gift for a Linux geek
petsc_diff_solver.C

petsc_diff_solver.C

Section: C Library Functions (3) Updated: Thu Apr 7 2011
Local index Up
 

NAME

petsc_diff_solver.C -  

SYNOPSIS


 

Typedefs


typedef int PetscErrorCode

typedef int PetscInt
 

Functions


PetscErrorCode __libmesh_petsc_diff_solver_monitor (SNES, PetscInt its, PetscReal fnorm, void *)

PetscErrorCode __libmesh_petsc_diff_solver_residual (SNES, Vec x, Vec r, void *ctx)

PetscErrorCode __libmesh_petsc_diff_solver_jacobian (SNES, Vec x, Mat *j, Mat *pc, MatStructure *msflag, void *ctx)
 

Typedef Documentation

 

typedef int PetscErrorCode

Definition at line 43 of file petsc_diff_solver.C.  

typedef int PetscInt

Definition at line 44 of file petsc_diff_solver.C.  

Function Documentation

 

PetscErrorCode __libmesh_petsc_diff_solver_jacobian (SNES, Vecx, Mat *j, Mat *pc, MatStructure *msflag, void *ctx)

Definition at line 105 of file petsc_diff_solver.C.

References DifferentiableSystem::assembly(), PetscMatrix< T >::close(), DofMap::enforce_constraints_exactly(), AutoPtr< Tp >::get(), System::get_dof_map(), ImplicitSystem::matrix, System::solution, PetscMatrix< T >::swap(), DiffSolver::system(), and System::update().

Referenced by PetscDiffSolver::solve().

{
  libmesh_assert (x   != NULL);
  libmesh_assert (j   != NULL);
//  libmesh_assert (pc  == j);  // We don't use separate preconditioners yet
  libmesh_assert (ctx != NULL);

  PetscDiffSolver& solver =
    *(static_cast<PetscDiffSolver*> (ctx));
  DifferentiableSystem &sys = solver.system();

  PetscVector<Number>& X_system =
    *libmesh_cast_ptr<PetscVector<Number>*>(sys.solution.get());
  PetscVector<Number> X_input(x);

  PetscMatrix<Number> J_input(*pc);
  PetscMatrix<Number>& J_system =
    *libmesh_cast_ptr<PetscMatrix<Number>*>(sys.matrix);

  // DiffSystem assembles from the solution and into the jacobian, so
  // swap those with our input vectors before assembling.  They'll
  // probably already be references to the same vectors, but PETSc
  // might do something tricky.
  X_input.swap(X_system);
  J_input.swap(J_system);

  // We may need to correct a non-conforming solution
  sys.get_dof_map().enforce_constraints_exactly(sys);

  // We may need to localize a parallel solution
  sys.update();

  // Do DiffSystem assembly
  sys.assembly(false, true);
  J_system.close();

  // Swap back
  X_input.swap(X_system);
  J_input.swap(J_system);

  *msflag = SAME_NONZERO_PATTERN;

  // No errors, we hope
  return 0;
}
 

PetscErrorCode __libmesh_petsc_diff_solver_monitor (SNES, PetscIntits, PetscRealfnorm, void *)

Definition at line 50 of file petsc_diff_solver.C.

Referenced by PetscDiffSolver::init().

{
  std::cout << '  PetscDiffSolver step ' << its
            << ', |residual|_2 = ' << fnorm << std::endl;

  return 0;
}
 

PetscErrorCode __libmesh_petsc_diff_solver_residual (SNES, Vecx, Vecr, void *ctx)

Definition at line 62 of file petsc_diff_solver.C.

References DifferentiableSystem::assembly(), DofMap::enforce_constraints_exactly(), AutoPtr< Tp >::get(), System::get_dof_map(), ExplicitSystem::rhs, System::solution, DiffSolver::system(), and System::update().

Referenced by PetscDiffSolver::solve().

{
  libmesh_assert (x   != NULL);
  libmesh_assert (r   != NULL);
  libmesh_assert (ctx != NULL);

  PetscDiffSolver& solver =
    *(static_cast<PetscDiffSolver*> (ctx));
  DifferentiableSystem &sys = solver.system();

  PetscVector<Number>& X_system =
    *libmesh_cast_ptr<PetscVector<Number>*>(sys.solution.get());
  PetscVector<Number>& R_system =
    *libmesh_cast_ptr<PetscVector<Number>*>(sys.rhs);
  PetscVector<Number> X_input(x), R_input(r);

  // DiffSystem assembles from the solution and into the rhs, so swap
  // those with our input vectors before assembling.  They'll probably
  // already be references to the same vectors, but PETSc might do
  // something tricky.
  X_input.swap(X_system);
  R_input.swap(R_system);

  // We may need to correct a non-conforming solution
  sys.get_dof_map().enforce_constraints_exactly(sys);

  // We may need to localize a parallel solution
  sys.update();

  // Do DiffSystem assembly
  sys.assembly(true, false);
  R_system.close();

  // Swap back
  X_input.swap(X_system);
  R_input.swap(R_system);

  // No errors, we hope
  return 0;
}
 

Author

Generated automatically by Doxygen for libMesh from the source code.


 

Index

NAME
SYNOPSIS
Typedefs
Functions
Typedef Documentation
typedef int PetscErrorCode
typedef int PetscInt
Function Documentation
PetscErrorCode __libmesh_petsc_diff_solver_jacobian (SNES, Vecx, Mat *j, Mat *pc, MatStructure *msflag, void *ctx)
PetscErrorCode __libmesh_petsc_diff_solver_monitor (SNES, PetscIntits, PetscRealfnorm, void *)
PetscErrorCode __libmesh_petsc_diff_solver_residual (SNES, Vecx, Vecr, void *ctx)
Author

This document was created by man2html, using the manual pages.
Time: 21:52:24 GMT, April 16, 2011