Skip to content

Commit 1280a9a

Browse files
Fix for linear and non-linear problems #31772
1 parent 0cdef74 commit 1280a9a

File tree

4 files changed

+35
-28
lines changed

4 files changed

+35
-28
lines changed

framework/src/mfem/equation_systems/EquationSystem.C

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ EquationSystem::FormLegacySystem(mfem::OperatorHandle & op,
272272
mfem::Vector aux_x, aux_rhs;
273273
mfem::HypreParMatrix * aux_a = new mfem::HypreParMatrix;
274274
blf->FormLinearSystem(
275-
_ess_tdof_lists.at(i), *(_var_ess_constraints.at(i)), *lf, *aux_a, aux_x, aux_rhs, true);
275+
_ess_tdof_lists.at(i), *(_var_ess_constraints.at(i)), *lf, *aux_a, aux_x, aux_rhs);
276276
_h_blocks(i, i) = aux_a;
277277
trueX.GetBlock(i) = aux_x;
278278
trueRHS.GetBlock(i) = aux_rhs;
@@ -339,44 +339,40 @@ EquationSystem::Mult(const mfem::Vector & sol, mfem::Vector & residual) const
339339

340340
_BlockResidual = 0.0;
341341

342-
for (unsigned int i = 0; i < _test_var_names.size(); i++)
343-
{
344-
auto & test_var_name = _test_var_names.at(i);
345-
346-
int offset = _BlockResidual.GetBlock(i).Size();
347-
mfem::Vector b(offset);
342+
if (_non_linear)
343+
{
344+
for (unsigned int i = 0; i < _test_var_names.size(); i++)
345+
{
346+
auto & test_var_name = _test_var_names.at(i);
348347

349-
auto lf = _lfs.GetShared(test_var_name);
350-
lf->Assemble();
351-
lf->ParallelAssemble(b);
348+
int offset = _BlockResidual.GetBlock(i).Size();
349+
mfem::Vector b(offset);
350+
351+
auto lf = _lfs.GetShared(test_var_name);
352+
lf->Assemble();
353+
lf->ParallelAssemble(b);
352354

353-
auto nlf = _nlfs.GetShared(test_var_name);
354-
nlf->Assemble();
355-
nlf->ParallelAssemble(_BlockResidual.GetBlock(i));
355+
auto nlf = _nlfs.GetShared(test_var_name);
356+
nlf->Assemble();
357+
nlf->ParallelAssemble(_BlockResidual.GetBlock(i));
356358

357-
_BlockResidual.GetBlock(i) -= b;
358-
_BlockResidual.GetBlock(i) *= -1;
359+
_BlockResidual.GetBlock(i) -= b;
360+
_BlockResidual.GetBlock(i) *= -1;
359361

360-
if (_non_linear)
361362
_BlockResidual.GetBlock(i).SetSubVector(_ess_tdof_lists.at(i), 0.0);
362-
}
363+
}
363364

364-
if (!_non_linear)
365-
{
366-
const_cast<EquationSystem *>(this)->FormLinearSystem(_jacobian, _trueBlockSol, _BlockResidual);
367-
const_cast<EquationSystem *>(this)->CopyVec(_BlockResidual, residual);
368-
}
369-
else
370-
{
371365
const_cast<EquationSystem *>(this)->CopyVec(_BlockResidual, residual);
372366
const_cast<EquationSystem *>(this)->FormLinearSystem(_jacobian, _trueBlockSol, _BlockResidual);
373-
}
367+
}
374368

375369
residual *= -1.0;
376370

377371
if (!_non_linear)
378372
{
379-
_jacobian->AddMult(sol, residual);
373+
//_jacobian->AddMult(sol, residual);
374+
residual = 0.0;
375+
_jacobian->Mult(sol, residual);
380376
}
381377

382378
sol.HostRead();

framework/src/mfem/problem_operators/EquationSystemProblemOperator.C

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ EquationSystemProblemOperator::Solve()
5454
zero_vec = 0.0;
5555
_problem_data.nonlinear_solver->SetSolver(_problem_data.jacobian_solver->getSolver());
5656
_problem_data.nonlinear_solver->SetOperator(*GetEquationSystem());
57-
_problem_data.nonlinear_solver->Mult(zero_vec, _true_x);
57+
58+
if(!(GetEquationSystem()->_non_linear))
59+
_problem_data.nonlinear_solver->Mult(_true_rhs, _true_x);
60+
else
61+
_problem_data.nonlinear_solver->Mult(zero_vec, _true_x);
5862

5963
GetEquationSystem()->RecoverFEMSolution(_true_x, _problem_data.gridfunctions);
6064
}

framework/src/mfem/problem_operators/TimeDomainEquationSystemProblemOperator.C

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,13 @@ TimeDomainEquationSystemProblemOperator::ImplicitSolve(const mfem::real_t dt,
7373

7474
_problem_data.nonlinear_solver->SetSolver(_problem_data.jacobian_solver->getSolver());
7575
_problem_data.nonlinear_solver->SetOperator(*GetEquationSystem());
76-
_problem_data.nonlinear_solver->Mult(zero_vec, dX_dt);
76+
77+
if(!(GetEquationSystem()->_non_linear))
78+
_problem_data.nonlinear_solver->Mult(_true_rhs, dX_dt);
79+
else
80+
_problem_data.nonlinear_solver->Mult(zero_vec, dX_dt);
81+
82+
//_problem_data.nonlinear_solver->Mult(zero_vec, dX_dt);
7783
SetTrialVariablesFromTrueVectors();
7884
}
7985

test/tests/mfem/kernels/tests

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
max_threads = 1
3535
platform = 'linux'
3636
abs_zero = 1e-6
37+
max_time = 1000
3738
[]
3839
[MFEMDiffusion]
3940
type = XMLDiff

0 commit comments

Comments
 (0)