12 #include "libmesh/petsc_vector.h" 13 #include "libmesh/petsc_solver_exception.h" 22 "The variable PETSc external solution will be synced to");
28 _sync_to_var_name(getParam<VariableName>(
"sync_variable")),
31 _ts(_external_petsc_app.getPetscTS()),
33 _petsc_sol(declareRestartableData<Vec>(
"petsc_sol")),
34 _petsc_sol_old(declareRestartableData<Vec>(
"petsc_sol_old")),
35 _petsc_udot(declareRestartableData<Vec>(
"petsc_udot"))
38 LibmeshPetscCall(TSGetDM(
_ts, &da));
40 LibmeshPetscCall(DMCreateGlobalVector(da, &
_petsc_sol));
43 LibmeshPetscCall(VecMPISetGhost(
_petsc_sol, 0,
nullptr));
64 CHKERRABORT(this->
comm().
get(), ierr);
70 _console <<
"PETSc External Solve!" << std::endl;
111 _console <<
"syncSolutions from external petsc App" << std::endl;
118 PetscInt i,
j, xs, ys, xm, ym, Mx;
119 PetscScalar ** _petsc_sol_array;
120 LibmeshPetscCall(TSGetDM(
_ts, &da));
121 LibmeshPetscCall(DMDAGetInfo(da,
135 LibmeshPetscCall(DMDAGetCorners(da, &xs, &ys, NULL, &xm, &ym, NULL));
136 LibmeshPetscCall(DMDAVecGetArray(da,
_petsc_sol, &_petsc_sol_array));
143 0,
_sync_to_var_name, Moose::VarKindType::VAR_ANY, Moose::VarFieldType::VAR_FIELD_STANDARD);
145 for (
j = ys;
j < ys + ym;
j++)
146 for (i = xs; i < xs + xm; i++)
148 Node * to_node = to_mesh.node_ptr(i +
j * Mx);
153 if (to_node->n_comp(sync_to_var.sys().number(), sync_to_var.number()) > 1)
154 mooseError(
"Does not support multiple components");
156 dof_id_type dof = to_node->dof_number(sync_to_var.sys().number(), sync_to_var.number(), 0);
158 sync_to_var.sys().solution().set(dof, _petsc_sol_array[
j][i]);
161 sync_to_var.sys().solution().close();
163 LibmeshPetscCall(DMDAVecRestoreArray(da,
_petsc_sol, &_petsc_sol_array));
166 sync_to_var.sys().update();
170 _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()
const Parallel::Communicator & comm() const
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()