12 #include "libmesh/petsc_vector.h" 21 "The variable PETSc external solution will be synced to");
27 _sync_to_var_name(getParam<VariableName>(
"sync_variable")),
30 _ts(_external_petsc_app.getPetscTS()),
32 _petsc_sol(declareRestartableData<Vec>(
"petsc_sol")),
33 _petsc_sol_old(declareRestartableData<Vec>(
"petsc_sol_old")),
34 _petsc_udot(declareRestartableData<Vec>(
"petsc_udot"))
67 _console <<
"PETSc External Solve!" << std::endl;
106 _console <<
"syncSolutions from external petsc App" << std::endl;
113 PetscInt i,
j, xs, ys, xm, ym, Mx;
114 PetscScalar ** _petsc_sol_array;
130 DMDAGetCorners(da, &xs, &ys, NULL, &xm, &ym, NULL);
131 DMDAVecGetArray(da,
_petsc_sol, &_petsc_sol_array);
138 0,
_sync_to_var_name, Moose::VarKindType::VAR_ANY, Moose::VarFieldType::VAR_FIELD_STANDARD);
140 for (
j = ys;
j < ys + ym;
j++)
141 for (i = xs; i < xs + xm; i++)
143 Node * to_node = to_mesh.node_ptr(i +
j * Mx);
148 if (to_node->n_comp(sync_to_var.sys().number(), sync_to_var.number()) > 1)
149 mooseError(
"Does not support multiple components");
151 dof_id_type dof = to_node->dof_number(sync_to_var.sys().number(), sync_to_var.number(), 0);
153 sync_to_var.sys().solution().set(dof, _petsc_sol_array[
j][i]);
156 sync_to_var.sys().solution().close();
158 DMDAVecRestoreArray(da,
_petsc_sol, &_petsc_sol_array);
161 sync_to_var.sys().update();
165 _console <<
"syncSolutions to external petsc App " << std::endl;
virtual Real & time() const
This is an interface to call a pure PETSc solver.
Vec & _petsc_udot
Udot (u_n-u_{n-1})/dt.
static InputParameters validParams()
virtual void syncSolutions(Direction) override
Vec & _petsc_sol
PETSc solver solution.
This is a demo used to demonstrate how to couple an external app through the MOOSE wrapper APP...
virtual Real computeResidualL2Norm() override
virtual void externalSolve() override
PETSC_EXTERN PetscErrorCode externalPETScDiffusionFDMSolve(TS, Vec, Vec, PetscReal, PetscReal, PetscBool *)
virtual const MooseVariableFieldBase & getVariable(const THREAD_ID tid, const std::string &var_name, Moose::VarKindType expected_var_type=Moose::VarKindType::VAR_ANY, Moose::VarFieldType expected_var_field_type=Moose::VarFieldType::VAR_FIELD_ANY) const override
virtual void advanceState()
Vec _petsc_rhs
RHS vector.
Vec & _petsc_sol_old
Solution at the previous time step.
registerMooseObject("ExternalPetscSolverApp", ExternalPETScProblem)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual void advanceState() override
PetscBool _petsc_converged
If PETSc solver converged.
virtual MooseMesh & mesh() override
void mooseError(Args &&... args) const
static const std::complex< double > j(0, 1)
Complex number "j" (also known as "i")
const ConsoleStream _console
virtual Real & dt() const
PETSC_EXTERN PetscErrorCode FormInitialSolution(TS, Vec, void *)
const VariableName & _sync_to_var_name
The name of the variable to transfer to.
ExternalPETScProblem(const InputParameters ¶ms)
static InputParameters validParams()