Essential BC for mixed problem #3431
-
Dear community, How do I implement essential (e.g. homogeneous Dirichlet) boundary conditions for a mixed finite element (involving multiple gridfunctions and FE-spaces) problem that involves a block matrix consisting of several submatrices? Ideally, I would like to have a command, that sets the degrees of freedom of one FE-space (or rather gridfunction) on the boundary to a certain value, independent of how the resulting matrix will get added to the large system matrix. I checked the example selection, the website and the documentation, but this was not very fruitful. Thank you in advance |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Hi @markusrenoldner, You can call You can run the example with (Note you can also do the elimination in the 2x2 system "by hand", e.g. by using diff --git a/examples/ex5.cpp b/examples/ex5.cpp
index a59dde087..955ca5562 100644
--- a/examples/ex5.cpp
+++ b/examples/ex5.cpp
@@ -128,6 +128,12 @@ int main(int argc, char *argv[])
std::cout << "dim(R+W) = " << block_offsets.Last() << "\n";
std::cout << "***********************************************************\n";
+ Array<int> natural_bdr({1, 1, 0, 0});
+ Array<int> ess_bdr({0, 0, 1, 1});
+
+ Array<int> ess_dofs;
+ R_space->GetEssentialTrueDofs(ess_bdr, ess_dofs);
+
// 7. Define the coefficients, analytical solution, and rhs of the PDE.
ConstantCoefficient k(1.0);
@@ -149,7 +155,8 @@ int main(int argc, char *argv[])
LinearForm *fform(new LinearForm);
fform->Update(R_space, rhs.GetBlock(0), 0);
fform->AddDomainIntegrator(new VectorFEDomainLFIntegrator(fcoeff));
- fform->AddBoundaryIntegrator(new VectorFEBoundaryFluxLFIntegrator(fnatcoeff));
+ fform->AddBoundaryIntegrator(new VectorFEBoundaryFluxLFIntegrator(fnatcoeff),
+ natural_bdr);
fform->Assemble();
fform->SyncAliasMemory(rhs);
@@ -267,6 +274,12 @@ int main(int argc, char *argv[])
darcyPrec.SetDiagonalBlock(0, invM);
darcyPrec.SetDiagonalBlock(1, invS);
+ Operator *darcyOpConstrained;
+ Vector X, B;
+ x = 0.0;
+
+ darcyOp.FormLinearSystem(ess_dofs, x, rhs, darcyOpConstrained, X, B);
+
// 11. Solve the linear system with MINRES.
// Check the norm of the unpreconditioned residual.
int maxIter(1000);
@@ -279,14 +292,16 @@ int main(int argc, char *argv[])
solver.SetAbsTol(atol);
solver.SetRelTol(rtol);
solver.SetMaxIter(maxIter);
- solver.SetOperator(darcyOp);
+ solver.SetOperator(*darcyOpConstrained);
solver.SetPreconditioner(darcyPrec);
solver.SetPrintLevel(1);
- x = 0.0;
- solver.Mult(rhs, x);
+ X = 0.0;
+ solver.Mult(B, X);
if (device.IsEnabled()) { x.HostRead(); }
chrono.Stop();
+ x.Vector::operator=(X);
+
if (solver.GetConverged())
{
std::cout << "MINRES converged in " << solver.GetNumIterations() |
Beta Was this translation helpful? Give feedback.
-
Dear Will, My problem is to find u which is computed iteratively (k denote the time steps). I am adapting a working code for the Hence, trying to mimic your 2nd suggestion ("you can also do the elimination in the 2x2 system by hand [...]") - i did the following:
this should set the boundary values to zero:
submatrix assembly:
(and similar for
Right hand side assembly:
and then i call MINRES
To summarize: I am using the Generally speaking, does this procedure suffice? Does MFEM process everything correctly, or do I also need to eliminate DOFs in the |
Beta Was this translation helpful? Give feedback.
Hi @markusrenoldner,
You can call
Operator::FormLinearSystem
on theBlockOperator
, where the list of essential DOFs indexes into the monolithic block vector. For example, this modification of example 5 solves the Darcy system on a unit square mesh with essential boundary conditions on part of the boundary, and natural boundary conditions on the remainder.You can run the example with
./ex5 -m ../data/inline-quad.mesh
.(Note you can also do the elimination in the 2x2 system "by hand", e.g. by using
FormLinearSystem
,FormSystemMatrix
, andFormRectangularSystemMatrix
on the relevant blocks that need to have DOFs eliminated. You will need to ensure that you modify the RHS appropriately).diff…