mfem: Question about anisotropic materials for Darcy-type problem

Hi all, we’ve been doing pretty great progress on an electromagnetic solver for modeling electrostatic problems with anisotropic materials (related to https://github.com/mfem/mfem/issues/4475 and also https://github.com/mfem/mfem/issues/2008).

I am using a Darcy-type solver (similar to ex5) which is starting to work pretty well (we’re using fairly complex mixed meshes but I am going to show results for coil.gen). Essentially I want to set anisotropic electric conductivity for some attributes (representing on of the conductive media) while the rest has isotropic conductivity. My approach of getting the parallel direction for the different mesh elements is to solve a simple isotropic diffusion problem and take the gradient of the scalar potential as a surrogate for the direction, which is working pretty well (also looked at other approaches, incl. semi-analytic approaches):

cfea_anisotropy_DEBUG_1

The label rho_ij refer to the resistivity tensor elements (2-rank). In the example above I used a parallel conductivity equivalent to copper and a perpendicular conductivity to 1/1000th of the parallel one. If I solve these two cases, I get the following current density.

cfea_anisotropy_DEBUG_2

The voltage and port current values are as follows:

Isotropic:

  -- Port currents: [    -493.8926 kA,     493.8970 kA ]
  -- Port voltages: [      -0.5000 mV,      +0.5000 mV ]

Anisotropic:

  -- Port currents: [    -414.4124 kA,     414.4124 kA ]
  -- Port voltages: [      -0.5000 mV,      +0.5000 mV ]

I don’t fully trust these results. I don’t think I would expect such a dramatic drop in current density (or in other words, such a big increase in “measured” resistance). The overall noisy solution for the anisotropic case plus the poor convergence (47 vs. 882 iterations) suggest that something is going wrong here. Ultimately, we also want to run this with a much greater parallel vs. perpendicular contrast (about 10 orders of magnitude). Am I missing something obvious here? Maybe I am too liberal in the way that the anisotropic conductivity is defined (steep transition from anisotropic to isotropic)? Or could this be address with a different solver and/or preconditioner (current using HypreDiagScale and HypreBoomerAMG for the Darcy block system).

Big thanks in advance for any helpful comments!! Mathias

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 1
  • Comments: 85 (43 by maintainers)

Most upvoted comments

I am happy to announce linear hybridization is out! 🎉 Nonlinear extension should follow soon 🚀 .

To give you an idea, I may show you the results from ex5-aniso.cpp, in particular the problem of “diffusion ring”, where the conduction along the circle is 1e8 stronger than perpendicular to it. The initial arc segment is then diffused on square-disc.mesh from MFEM, yielding the following results: image

Hi @najlkin , sorry not responding for a while: we had to (temporarily) shift our focus to some other work, and this somehow disappeared from my radar. I will try to give this a test run this week or next week; I am curious to see how the solution-based iterator performs. We’ll definitely revisit this problem with some time commitment hopefully soon (it’s not become less important, quite the opposite actually).

Thanks for continuing to work on this! 🚀 Mathias

Hi @najlkin , I got a chance to run some tests with the new version yesterday. Below are some results; looks like it’s going in a good direction, but still some effects I don’t quite understand. Also: as mentioned before I am more than happy to share the two test meshes used below and integrate those in the most recent version, if you would like to run some tests on your end.

Test cases:

  • The model consists of copper (sigma = 5.8e+07) and a high conductivity beam in the central plate (sigma_par = 5e+15, sigma_perp = 1e+06
  • For the anisotropic cases, the high conductivity sigma_par is used for “along the beam” and for the “through the screen” directions
  • All plots are showing the flux/current plots (not showing the voltage plots but can add those if it’s helpful)

RT cases

  • Top row is the mixed mesh, bottom is tet only
  • Left of the red line is fully isotropic, right of the red line with anisotropy in the central beam Image

Few things I noticed:

  • hybridization in the anisotropic cases looks great for the tet-only mesh (bottom) but seems to fail for the mixed mesh
  • reduction seems quite noisy, and does not seem compatible with the mixed mesh (got an error about incompatible finite elements)

DG isotropic cases

  • Top row is order=1, bottom row is order=2
  • All cases shown are for the tet-only meshes, but I assume with the upcoming MFEM 4.8 (with support for pyramids) I might be able to run mixed meshes, too Image

Few things I noticed:

  • hybridization generally looking good, reduction also good but noisy
  • A lot of cases seem to have an artifact at the port regions (I am using voltage constraints at the port boundaries, and a J=0 constraint at the non-port boundaries

DG anisotropic cases

Image

Few things I noticed:

  • hybridization generally looking good, reduction is noisy
  • Similar artifacts at the port regions

So it seems that hybridized RT is the current front runner! I think it’s moving in a great direction, thank again for making these very cool additions.

BTW: I also looked into the ex5-nguyen examples, but these are quite difficult to follow due to the sparsity of comments. Any chance you would be okay with adding some comments (especially regarding the functions cFun, tFun, fFun, …). I think that would be super helpful (probably for others, too).

Thanks again for the extensive help with this so far, Jan! Mathias

Potential reduction (RTDG) is out too! 🚀 There is just no example code for it now 😅 .

Ok, I just added parallelized flux reduction (LDG), give it a try😉

Hi @najlkin , I ran a quick first test yesterday on one of the test models I used before, without employing any anisotropic materials and solved using GMRES. The base RT case (left) is running fine (as expected); for the DG case (right) I assume there is something missing in how I am setting up the problem:

Image

I made the following changes to your code:

  • Read isotropic and anisotropic coefficients from external file (this is identical to the script I had shared earlier in our discussion)
  • Disable mesh refinement
  • Plus the more complex changes below

Define voltage ports

Image

Zero flux BC on non-port boundaries

Image

Set flux TDOFs

Image

Anything I am missing here when setting up the DG case? Also want to reiterate: this is great stuff!! Excited to dive into some test cases! 😃 Have a great weekend! Mathias

Hi, the parallelization is underway 🚀 . There is ParDarcyForm, which is limited currently only to RTDG or LDG, but you may try it already 😉 . See the new ex5p-hdg.cpp for an example. The next should be reduction and then hybridization.

Perfect timing, @najlkin ! Was just looking into UMFPackSolver and actually had some trouble with hybridization (which I assume your modifications might address). I also ran some tests with DG and that started to work better (especially given your suggestion). I was working on a simpler test mesh today (for which I can generate the ideal anisotropy) and will rerun those tests shortly and post some updates. In any case, big thanks for the continuous help on this!! It’s greatly appreciated! 😃 Mathias

Hi @najlkin , thanks for checking in! I had to put this aside for a few days, but just resumed working on this. I am currently trying a few of the experimental features and various dev branches directly in MFEM (rather than in PyMFEM) and directly on our more complex meshes (rather than the more simple meshes). For one, my runs were previously restricted to lower order basis functions since our meshes use Pyramid basis functions (currently looking into pyramid-dev to address this), which might play a role. I will also run some more complex test cases using your DarcyOperator classes in darcy-hdg-dev. I will try to post a more detailed update in a couple of days here Mathias

Hi, @mdavids-cfs, Just a quick question (I hope). Am I correct in thinking that you’re solving a simple Laplacian problem $\nabla\cdot\sigma\nabla\phi=0$ with voltage boundary conditions and your spatially varying anisotropic $\sigma$? If so, my main question is how do you recover the current density that you’re displaying? Best wishes, Mark

The bot wants to close this issue again 🤖 . I understand if you do not have much time to work on this project, but your input is valuable for us and helps us among other things to decide what should go into master 😉 . It is true that getting the whole thing there will take time, but there will be multiple phases and with completed parallelization and reconstruction of total fluxes it is closer than ever 🚀 .

Great results! 👍 The winning stage is split for me 🥇 , HRT and HDG results are very close. The port errors of HDG look ugly, but it is a known problem of DG, where we do not have an essential boundary condition and they are not harmful overall. HRT shows some extra artifacts, which is rather worrying to me. I have not tried mixed meshes, I need to have a look later at that reduction what happens there. However, reduction does not have a priority, as it performs worse in all aspects than hybridization basically, so no guarantees this case will be supported. LDG is there mainly for reference. In any case, what is striking here is the very low number of iterations for such difficult cases, where convergence is indicated, but you can see visually there are big errors (especially that mixed anisotropic case is funny 😄 ). I think you should really try to redefine the solver norm. We have run into that before, but it is even more important here when most of the domain is covered by background and the object of interest is immersed in it. Good news are that #4483 has got merged 🎉 , so you may easily define the norm through IterativeSolverController. The question is what norm to use and how to construct it. For HRT/DG, we would need a flux norm derived from the trace values, so something like $|\kappa [\hat{t}]|$. Unfortunately, I had to switch from RT_Trace elements to DG_Interface elements in hybridization because of the parallelization, which means there is no easy way how to get (generalized) gradient of the traces🤔 . However, we do not need the orientation of the gradient for the norm, so it is still doable with a bit of some extra work. Anyway, I would propose to start with LDG (=reduction), where the primary quantity is the potential, so you may easily take $||\kappa [t]|| + ||\kappa \nabla t||$ 😉 . Check GridFunction::ComputeDGFaceJumpError() and GridFunction::ComputeGradError(). With ex5-nguyen.cpp, it really follows the notation in the header. tcoef is the analytic temperature, ccoef the velocity, fcoef the temperature rhs. Do not read much in their definitions, they are complex, but it just follows the paper, so check there what the problems are about 😉 .

That’s very exciting, @najlkin ! I am currently traveling, but will give this a test run once I am back! Thanks again for putting this together! It’s a great addition (to a great library)! Mathias

These are great results and also progress with LDG 👍 There are two things we need to distinguish:

  • effect of the stabilization (only LDG) - This causes formation of a transition layer inside the domain where the different materials meet, similar to the boundary layer we could see before, and the artifacts in the beam are maybe just “ringing” spreading from this layer. You may try to play with the definition of the stabilization term, which takes arithmetic average of (normal) conductivities: https://github.com/mfem/mfem/blob/85fe37c27d4bcf9ee807c7487e2934de9d5e8d31/fem/bilininteg.cpp#L4682 You may try to change it to wq = max(wq, ni * nor) or wq = min(wq, ni * nor) if it will have some effect.
  • effect of the norm definition (RT/LDG) - This is similar for both methods and we have discussed it before, but we are maybe jumping to conclusions here too early. It might be the previous effect for LDG which dominates. We will get more clarity to it soon with parallelized reduction 😉

Ok, it seems like stabilization only on the interior but not on the boundary produces some decent results, however, still with somewhat poor convergence.

  • Top row is RT, bottom is DG
  • Left column is isotropic materials everywhere, right column is anisotropy within the central beam

Image

There still seem to be artifacts though, especially in the transition zone between port and beam, where the current amplitude seems way too high.

Looks amazing! Try to play with that stabilization parameter td as I mentioned earlier and add it to the boundary term or try to remove the stabilization term for the boundary altogether. Nice weekend 👋 .

Hi @najlkin ! That’s fantastic!! 🚀 I will start running some tests and will post these soon!

That makes a lot of sense, thanks @najlkin for clarifying! I guess I wasn’t ready to fully give up on the non-“HDG-hybridization-reduction” approach 🙈 (which was only meant as a temporary solution, while the Darcy-dev is work in progress), but I think you’re right. I will just wait for the parallelized version of the darcy-hdg-dev branch. Very exciting to hear that you’re working on the parallelization though! Please let me know if/when I can help with running any test-cases or provide test meshes, etc. Thanks again! Mathias

Maybe the fundamental problem here is that you have a system of two equations, which you put into a block and solve them like one, i.e., the solver uses a single norm, which is like ||j|| + ||phi||, which does not make much sense as you are mixing apples with oranges here 🍏 🟠 . It should be more like ||j|| + ||kappa grad phi||, which it actually almost is, because the residuum is measured, so it is more complicated than this, but to give you an idea. It can happen it is insensitive to one of the equations, so you get maybe perfect solution in phi, but poor in j. You are not the only one facing this and there is pull request #4483 for generalization of the norm used by solvers. With that you could decide that the solution is converged only when both quantities are converged.

In any case, I would not spend too much time on this at your place, as you do not need to care about it with hybridization/reduction and their parallelization is underway 🚀 .

Hi, all the best to the new year! 🎉 The idea of virtual time stepping is simple - start with higher values of mass/stabilization and iteratively decrease it to small values, where every iteration serves as the initial condition (in the case of mass) / guess (in the case of stabilization) for the next one 👍 . This is getting complicated in such settings and that is why the main focus should be on HDG here. I would like to parallelize it with MPI soon. In the meantime you may try to solve (curl B, curl Xi) = <phi, n . curl Xi>_phi for B, Xi in Hcurl. For the BC term you will need to write your own integrator probably. The current you will get then as j = curl B through CurlInterpolator 😉 .

Hi @najlkin , awesome, thanks so much for looking into this. About the virtual time stepping: how can this be implemented? I.e., how can I decrease/increase the stabilization/mass portion of the problem? Happy to give it a try.

Also, regarding DivergenceCleaning and stationary magnetic diffusion approaches: is there a starting point somewhere one github (or maybe someone has a few more thoughts on how to tackle this?). Not sure how the filter could be implemented (not sure how the CurlCurlIntegrator would fit into a problem where J is in HDiv). Also, for solving the magnetic diffusion problem directly, I am not sure how I could impose the appropriate BCs (i.e., either voltage or current BCs). But would love to give it a try, if someone has some helpful thoughts on how get started with this 😃

Thanks a lot and happy new year! Mathias

Nice holiday time ☃️, I found some time to look at the code and ran the cases 1 and 2 (3 is too big for my laptop 😊 ). And identified a few things with L/HDG:

  • LDG - electric current drop towards the center - It is caused by the diffusion stabilization term, which effectively adds “inertia” to the potential. When you use coefficient like 1e-6 in HDGDiffusionIntegrator, the drop is gone, but you may have hard time to get it converged. This returns us to the idea of virtual time stepping proposed above, where you could solve this predominantly boundary problem iteratively and gradually decrease the stabilization/mass.
  • LDG - potential drop to the sides - It is partially the previous issue, but not even the boundary conditions for the current are satisfied, i.e., current is not tangential to the boundaries. It is also probably a problem with the extreme non-homogeneity, i.e., ratio between the conductivities, which leads to insensitivity of the iterative solver.
  • L/HDG - boundary errors on tet mesh - I thought it is maybe DofTransformation, but it is NULL when returned by GetElementVDofs. Zero order looks relatively fine, but first and higher have concentrated random currents at the boundaries (like the right column of your results) I do not know, do you think it could be some bug of L2 elements on tets, @mlstowell ?

Hi, that is the thing, it is a different equation for different quantities, i.e., electric current and magnetic field (or something acting like that). So compatibility is an issue, but you may use it at least for that Helmholtz decomposition, because there must exist a vector field which produces purely solenoidal, divergence-free electric current field. However, I am confused now, I thought you have J in Hdiv. If it is in Hcurl, which makes more sense as you may get it through GradientInterpolator from phi in H1, then it is purely gradient, not solenoidal.

Hi, sorry, I had no time for that, I was working on projects for running collaborations. Maybe I will get to it later during vacation.

Yes, I think it might be a good approach for now before we do parallelization of HDG/HRT to solve a single equation instead. If you want a divergence-free solution the equation should rather be curl sigma^-1 curl B = 0 in Hcurl and then you may get J = curl B with the discrete CurlInterpolator. That is an equation for stationary magnetic diffusion instead of the electrostatic problem. This is conceptually similar to the Helmholtz decomposition in DivergenceFreeProjector, but there it is between H1 and Hcurl through Laplace similar to yours. So if you cannot solve the problem with B directly, you may solve with phi instead and then use the mentioned equation as a filter, trying to find a B that would correspond to the solution, eliminating the divergence part.

@mdavids-cfs , this is exactly why we are working on HDG and why it is important for tokamaks 🙂 . This anisotropy is causing failure of classical methods, while they might be perfectly fine for isotropic diffusion. This is what we discussed before. HDG outperforms other methods, as far as I can say and also your results suggest that, but it is not parallelized, so you cannot use multi-grid preconditioners/solvers, so convergence might be slower sometimes for that reason.

Hi, @mdavids-cfs, This may not be relevant but some time ago I was looking at highly anisotropic scalar diffusion. I found that refining the mesh helped but increasing the basis function order helped much more. If I remember correctly, I found that for a given number of degrees of freedom it was best to use 3rd or 4th order basis functions on a relatively coarse mesh rather than 1st or 2nd order on a finer mesh. I think 1e9 was the highest contrast I looked at so your case will be even more challenging. Best wishes, Mark

Hi @najlkin and others, I just uploaded the modified version of ex5-hdg that I’ve been using along with the meshes and resistivity values (stored in text files with the ending .mat, not to be confused with Matlab data files) here.

You can use the flag -m to switch between the different meshes (1 = hex beam, 2 = tet beam, 3 = tet solenoid based on coil.gen) and -iso or -aniso to switch between isotropic and anisotropic materials. Note that for anisotropic materials, I am using per-element attributes to define per-element tensors (this was due to a limitation of PyMFEM which I believe is now resolved), but it should all be handled automatically in the modified version of ex5-hdg. Thanks again for offering to have a look, and let me know if any more test cases or meshes etc. would be helpful. Of course, I am also doing more testing on my end, and will keep you posted about these, too. Thanks and warm regards, Mathias

Hi all, I ran another set of simulations today, especially comparing HEX and TET meshes of the same geometry. MFEM_debug_meshes

Here are results for the TET mesh case.

(similar to yesterday’s results on the HEX mesh)

I looked at fully isotropic case (top) as well anisotropic cases using “analytic (uniform) tensors” and tensors obtained by solving a simple isotropic diffusion on the sub-mesh representing the central beam. I actually ended up fine-tuning this, because my initial approach had some noise in the resulting vector field which is now mostly resolved. Also I left out -dg and -dg -rd cases, since they didn’t work very well (similarly to what I’ve shown yesterday).

MFEM_debug_D

A few things I noticed:

  • The solve is very sensitive to noise in the tensor field (not very surprising but was good to see this on a specific example)
  • In the most simple case (isotropic ex5-hdg, i.e., no hybridization or DG) the solve did not converge within 1000 iterations and had an artifact in the potential. EDIT: It converged after 1700 iterations and the artifact was gone, so again just slow convergence
  • Even with the ideal (analytic) anisotropic tensor field (second row) convergence was very slow. I guess the TET mesh is just much more challenging that the HEX mesh
  • At least in this particular case DG did not work well even with hybridization for both isotropic and anisotropic cases

I will make sure to also try the things you suggested above, @najlkin . Just got a bit into the TET mesh rabbit hole today, but glad I found the issue with how I am generating the tensor field.

Mathias

EDIT: Regarding this suggestion:

  • RTDG (ex5-hdg) and HRT (-hb) are equivalent schemes (not so LDG and HDG), so it keeps me wondering why they show different results even when reportedly are both converged 🤔 We do not have an analytic solution, but HRT result looks better to me. Maybe MINRES does some gimmicks, is there any difference when you run RTDG with GMRES?

What pre-conditioner would you use in this case with GMRES? If try to use the solver code block following this line: https://github.com/mfem/mfem/blob/e92c3f4a5b4f582c2af9bec41b59a4a8bccf862c/examples/ex5-hdg.cpp#L282

I get the following error:

Verification failed: (it != maps->memories.end()) is false:
 --> host pointer is not registered: h_ptr = 0x3
 ... in function: static void mfem::MemoryManager::CheckHostMemoryType_(MemoryType, void *, bool)
 ... in file: general/mem_manager.cpp:1711

There is a LOT more in the 519 commits 😄 . I would like to get to parallelization soon, but there are still other things to do. However, it is only a preconditioner for the Schur complement or eventually the hybridized matrix, so it does not change the properties of the scheme, just accelerates the convergence. If it shows convergence with Gauss-Seidel or UMFPack, that should be it, nothing to improve except the speed (unless there is some ambiguity in the solution 😯 ).

Hi @najlkin , thanks for the comments; I will run some more tests as you suggested. Also more than happy to share the code and the test mesh I was using. Another quick question: is it possible to test ex5p in master with hybridization and run with HyperAMG? I.e., does it work to EnableHybridization for the different blocks in BlockOperator, or is there more going on behind the scenes (I guess there must be, since you ended up writing a specific class for this). Thanks again! Mathias

Wow, these are very interesting results indeed! 🤩 There a few points from my side:

  • RTDG (ex5-hdg) and HRT (-hb) are equivalent schemes (not so LDG and HDG), so it keeps me wondering why they show different results even when reportedly are both converged 🤔 We do not have an analytic solution, but HRT result looks better to me. Maybe MINRES does some gimmicks, is there any difference when you run RTDG with GMRES?
  • HDG (-dg -hb) looks great 👍 . The results are nicely smooth like for HRT, while the iteration count (and computation time, I guess) starts to be lower with higher anisotropy. Btw, you do not need to use -rd in combination with -hb, it is one or the other, so it is ignored in this case.
  • LDG (-dg (-rd)) looks really bad 🫠 . I wonder if there is not a bug as I would expect it to converge at least in the isotropic case 🤔 . Could you share the code somehow? Maybe in a public fork?

Hi all, here is some more test results: First, I took a step back and generated the simplest model possible: a straight high-conductivity (anisotropic) slab embedded in a low conductivity (isotropic) region. The anisotropic direction is left-right, and the direction along the slab and top-down is the high-conductivity direction. I solved this for both isotropic and anisotropic conductivity cases using my default workflow (in PyMFEM based on ex5p in master with added BC on the flux on the non-port regions) and saw (almost) no difference, which makes sense since given the port configuration, the current is only flowing along the high conductivity direction, so all good here. MFEM_debug_A

I then ran the same model using ex5-hdg in darcy-hdg-dev with a few different configurations (hybridization, DG, etc.)

Only isotropic materials

MFEM_debug_B

With anisotropic high-conductivity material

MFEM_debug_C

So at least for this simple example, DG seems to work quite well with hybridization. I will rerun the more complex example of the full solenoid tomorrow. DG without hybridization did not work for both the isotropic and anisotropic cases; would this point a problem, or is this expected?

Cheers! Mathias

Ok, I investigated that MINRES and the problem is in how it calculates “norms”, where it takes r * P(r), while GMRES uses P(r) * P(r) (r -residuum, P - preconditioner). The former is negative sometimes, so the square root of it yields that NaN. You may just comment out the preconditioner and MINRES runs fine 😉 I also added completion of the diagonal of the hybridized matrix with ones, so you may use more solvers, including direct solvers like UMFPackSolver 😉 . In any case, try those DGs, I am curious how that will work…

Cool, that is an impressive comparison 👍 . I think hybridization runs quite well, considering it uses just a poor Gauss-Seidel for preconditioning. Sure, maybe you get better results with the mixed form and AMG for Schur now, but the thing is hybridization is robust when it comes to anisotropy, so it is a better choice for the future 😉 . Hopefully, I will get to parallelization soon. Anyway, maybe try using MINRES instead of GMRES like you do without hybridization. Regarding DGs, the problem is that there are no essential BCs as there are no boundary DOFs 😄 I did not demonstrate that in this example, because the original problem had no BC for flux. You may find it in more advanced examples, but it is too complicated there maybe. With zero BC, all you need to do should be:

bVarf->AddBdrFaceIntegrator(new TransposeIntegrator(
                                          new DGNormalTraceIntegrator(-1.)), ess_bdr_J);
mtVarf->AddBdrFaceIntegrator(new HDGDiffusionIntegrator(ikcoeff), ess_bdr_J);

That is extension of the weak gradient to the boundary, i.e., natural BC. PS: You may use hybridization with DGs too 😉

Hi @najlkin , just ran a few tests using ex5-hdg. As before, the hybridization approach worked slightly better but still not as good as the ex5p example in master with HypreAMG. The DG options didn’t really work, although I am wondering if enforcing the BC on the potential/pressure works in a similar fashion, or if other steps would be needed here:

if (dg)
 {
    fform->AddDomainIntegrator(new VectorDomainLFIntegrator(fcoeff));
    fform->AddBdrFaceIntegrator(new VectorBoundaryFluxLFIntegrator(fnatcoeff), ess_bdr_phi);
 }
 else
 {
    fform->AddDomainIntegrator(new VectorFEDomainLFIntegrator(fcoeff));
    fform->AddBoundaryIntegrator(new VectorFEBoundaryFluxLFIntegrator(fnatcoeff), ess_bdr_phi);
 }

Here is an overview of the results with the four approaches (regular, hybridization, DG, DG + reduction)

MFEM_debug_2b

The conductivity of the wire is ~10 orders of magnitude higher than the surrounding materials, so the current should be mostly confined to the wire, which I do indeed see in ex5p in master.

Also, @mlstowell : I forgot to add the question following the quote in my previous post: you made a comment about how I am calculating the current density. In fact, I was wondering if a step might be missing in how I am calculating the current density? Using something similar to this in my implementation based on ex5p in master (didn’t make changes to ex5-hdg):

# Electric scalar potential
gridfunctions['phi'] = mfem.ParGridFunction()
gridfunctions['phi'].MakeRef(L2FESpace, x.GetBlock(1), 0)
gridfunctions['phi'].Distribute(trueX.GetBlock(1))

# Electric current density
gridfunctions['J'] = mfem.ParGridFunction()
gridfunctions['J'].MakeRef(HDivFESpace, x.GetBlock(0), 0)
gridfunctions['J'].Distribute(trueX.GetBlock(0))

Thanks again for the help with this! Mathias

Cool, @mdavids-cfs , there is a big difference between the poor Gauss-Seidel and a multi-grid (BoomerAMG), as the residuum shows, but both did not converge. It is good for regression using plain DarcyForm, so we know it works the same way as master. However, the main benefit is that you may turn on hybridization (-hb, works for RTs and DGs) or reduction of the DG flux (-rd) 😮 (I just added that reduction to ex5-hdg.cpp). Does that work?

Hi @najlkin , I’ve done a few more tests, especially comparing my current approach based on ex5 and ex5p in the main branch with ex5 in darcy-hdg-dev that uses the DarcyOperator class. For now, I am solving with only isotropic materials using coil.gen. Few comments on the overall setup:

  • Voltage constraints (+1V and -1V on the coil ports)
  • Enforcing div J = 0 on the walls (except for the ports)
  • Serial versions are solved using MINRES with DSmoother and GSSmoother for the two blocks (also tried GMRES, which didn’t really have an impact)
  • Parallel version is solver using MINRES with HypreDiagScale and HypreBoomerAMG
  • All materials are conductive (rho between 6.6e-17 and 5.14e-07):

These are the results for order = 0 for the three cases:

(three rows are potential, current (linear scale) and current (log scale)) MFEM_debug_B

Switching to order = 1 seemed to make things worse for the serial methods in darcy-hdg-dev and main (three rows are potential, current (log scale) and current (linear scale))

Here is the code changes I made to implement the model described above:

Boundary constraints for phi and J

// Assign high conductivity (low resistivity) to the wire (attr = 1) and central rod (attr = 3) and low conductivity 
// (high resistivity) to air (attr = 2)
Vector k_values(3);
k_values[0] = 6.6e-17;
k_values[1] = 5.14e-07;
k_values[2] = 6.28277e-10;

PWConstCoefficient kcoeff(k_values);
RatioCoefficient ikcoeff(1., kcoeff);

// Marker for coil port boundaries 
Array<int> ess_bdr_phi(mesh->bdr_attributes.Max());
ess_bdr_phi = 0;
ess_bdr_phi[0] = 1;
ess_bdr_phi[1] = 1;

// Mark the two walls (bdr_attr 3 and 4, ie., non-port boundaries) as essential, 
// i.e., enforce zero flux through them
Array<int> ess_flux_tdofs_list;
Array<int> ess_bdr_J(mesh->bdr_attributes.Max());
ess_bdr_J = 0;
ess_bdr_J[2] = 1;
ess_bdr_J[3] = 1;
R_space->GetEssentialTrueDofs(ess_bdr_J, ess_flux_tdofs_list);

// Voltage boundary values
Vector ess_bdr_phi_vals(mesh->bdr_attributes.Max());
ess_bdr_phi_vals = 0.0;

// Ports on attribute 0 and 1 --> +/- 1V
ess_bdr_phi_vals[0] = +1.0;
ess_bdr_phi_vals[1] = -1.0;
PWConstCoefficient fnatcoeff(ess_bdr_phi_vals);

Vector zero_vec(dim);
zero_vec = 0.0;
VectorConstantCoefficient fcoeff(zero_vec);
ConstantCoefficient gcoeff(0.0);

Enforce voltage boundary values only on ports

fform->AddBoundaryIntegrator(new VectorFEBoundaryFluxLFIntegrator(fnatcoeff), ess_bdr_phi);   

Only for ex5 and ex5p in main

mVarf->AddDomainIntegrator(new VectorFEMassIntegrator(kcoeff));
mVarf->Assemble();
mVarf->EliminateEssentialBC(ess_bdr_J, x.GetBlock(0), rhs.GetBlock(0));
mVarf->Finalize();

bVarf->AddDomainIntegrator(new VectorFEDivergenceIntegrator);
bVarf->Assemble();
bVarf->EliminateTrialDofs  (ess_bdr_J, x.GetBlock(0), rhs.GetBlock(1));  
bVarf->Finalize();

It seems that I am missing something in setting up the serial cases, or is it only the Hypre preconditioners that causes the big difference between the serial and parallel runs? Also @najlkin if you have some guidance on how to set up this problem using the DarcyOperator class (or would even be interested in doing a run on your end) that would be incredibly helpful. I would guess that this problem should be a pretty easy solve for your dedicated operator (especially since there’s no anisotropy). Also happy to share the full code I used in each case, if that’s helpful.

Also @mlstowell regarding your previous comment above:

Hi, @mdavids-cfs, Just a quick question (I hope). Am I correct in thinking that you’re solving a simple Laplacian problem ∇ ⋅ σ ∇ ϕ = 0 with voltage boundary conditions and your spatially varying anisotropic σ ? If so, my main question is how do you recover the current density that you’re displaying? Best wishes, Mark

Thanks again everyone for the help so far! Mathias

Hi @mdavids-cfs , thanks for your interest! 😉 The code looks alright at first glance 👍 . Maybe try solving it without hybridization first, to verify the setup is correct. However, is your mesh conforming? Because that is also one of the current limitations of the implementation. I believe I will get to it soon together with that parallelization (as both things are conceptually close in MFEM), but it is as it is for now. Sure, a beer sounds good 🍻 , but let us wait with that until something works 😅 . PS: Yes, I think you need to be member of some of those teams to be able to make branches and contribute directly. However, it is not critical now, I think…

Hi @najlkin , thanks a lot for looking into this!

The conductivity tensors are all symmetric. They are all 2-rank tensors given by a directional vector v_par and two conductivities sigma_par and sigma_perp using

sigma = sigma_par * v_par^T  v_par + sigma_perp * (I - v_par^T v_par)

I will generate some more plots tomorrow (would something similar to my earlier post be helpful?).

Also, here is a bit of a clean-up version of the relevant code pieces I am currently using:

Boundary markers and values

ess_bdr_phi = Marker for coil ports (1 = port)
ess_bdr_j = Marker for div J = 0 (1 = non-port boundary)
bdr_attr_values = Length of bdr attributes, contains voltage values

Linear forms

# Flux linear form
#-----------------
fform = mfem.ParLinearForm()
fform.Update(HDivFESpace, rhs.GetBlock(0), 0)

# Domain integrator
fcoeff = mfem.VectorConstantCoefficient(0.0)
fform.AddDomainIntegrator(mfem.VectorFEDomainLFIntegrator(fcoeff))

# Boundary integrator (voltage values on ports)
fnat_vec = mfem.Vector(bdr_attr_values)
fnatcoeff = mfem.PWConstCoefficient(fnat_vec)
fform.AddBoundaryIntegrator(mfem.VectorFEBoundaryFluxLFIntegrator(fnatcoeff), ess_bdr_phi)

fform.Assemble()
fform.ParallelAssemble(trueRhs.GetBlock(0))

# Flux div linear form  
#---------------------   
gform = mfem.ParLinearForm()
gform.Update(L2FESpace, rhs.GetBlock(1), 0)

# Domain integrator
gcoeff = mfem.ConstantCoefficient(0.0)
gform.AddDomainIntegrator(mfem.DomainLFIntegrator(gcoeff))
gform.Assemble()
gform.ParallelAssemble(trueRhs.GetBlock(1))

Bilinear forms

# Flux mass
mVarf = mfem.ParBilinearForm(HDivFESpace)
mVarf.AddDomainIntegrator(mfem.VectorFEMassIntegrator(rhoCoef)) # this had k before
mVarf.Assemble()

bVarf = mfem.ParMixedBilinearForm(HDivFESpace, L2FESpace)
bVarf.AddDomainIntegrator(mfem.VectorFEDivergenceIntegrator())
bVarf.Assemble()

Boundary DoFs

# Flux mass form
mVarf.EliminateEssentialBC(ess_bdr_j, x.GetBlock(0), rhs.GetBlock(0))
mVarf.Finalize()

# Flux div form
bVarf.EliminateTrialDofs(ess_bdr_j, x.GetBlock(0), rhs.GetBlock(1))
bVarf.Finalize()

Darcy operator

darcyOp = mfem.BlockOperator(block_trueOffsets)
M = mVarf.ParallelAssemble()
B = bVarf.ParallelAssemble()
B *= -1
Bt = mfem.TransposeOperator(B)

darcyOp.SetBlock(0, 0, M)
darcyOp.SetBlock(0, 1, Bt)
darcyOp.SetBlock(1, 0, B)

Darcy preconditioner

darcyPr = mfem.BlockDiagonalPreconditioner(block_trueOffsets)

Md = mfem.HypreParVector(MPI.COMM_WORLD, M.GetGlobalNumRows(), M.GetRowStarts())
M.GetDiag(Md)

MinvBt = B.Transpose()
MinvBt.InvScaleRows(Md)
S = mfem.hypre.ParMult(B, MinvBt)
        
invM = mfem.HypreSmoother(M)        
invS = mfem.HypreBoomerAMG(S)

invM.iterative_mode = False
invS.iterative_mode = False

darcyPr.SetDiagonalBlock(0, invM)
darcyPr.SetDiagonalBlock(1, invS)

Solver

solver_name = "GMRES"
solver = mfem.GMRESSolver(MPI.COMM_WORLD)
solver.SetAbsTol(atol)
solver.SetRelTol(rtol)
solver.SetMaxIter(maxIter)
solver.SetOperator(darcyOp)
solver.SetPreconditioner(darcyPr)
solver.SetPrintLevel(1)
trueX.Assign(0.0)

# Solve
solver.Mult(trueRhs, trueX)

Get final solutions

# Electric scalar potential
gridfunctions['phi'] = mfem.ParGridFunction()
gridfunctions['phi'].MakeRef(L2FESpace, x.GetBlock(1), 0)
gridfunctions['phi'].Distribute(trueX.GetBlock(1))

# Electric current density
gridfunctions['J'] = mfem.ParGridFunction()
gridfunctions['J'].MakeRef(HDivFESpace, x.GetBlock(0), 0)
gridfunctions['J'].Distribute(trueX.GetBlock(0))

Thanks again for offering to help with this! It’s greatly appreciated!! (also applies to @mlstowell and anyone on the MFEM team)! Mathias

PS: I started to look into your Darcy forms and operators in darcy-hdg-dev, looks super interesting and very relevant indeed. Since we’re currently using PyMFEM (which is part of a bigger library we’re working on), I’d love to stay within PyMFEM, but if nothing else helps, I could also try to expand PyMFEM’s swig interface to include your classes.

@mdavids-cfs , we discussed the problem today and a few things came up:

  • Is the conductivity a symmetric tensor? It is important for choice of the solver and preconditioning…
  • Could you visualize the conductivity? It would be useful to check if the effects are not coming from it. You may visualize the norm or trace, or if it is symmetric, you may plot the “conductivity vector”, i.e., the diagonal of the matrix.

It seems that GMRES does not converge, which indicates it is a pretty hard problem indeed and the simple approach of example 5 is not ideal. Two things to it:

  • There is a miniapp for block-solvers, which goes further and shows usage of more advanced solvers.
  • This problem can be easily handled by HRT method in darcy-hdg-dev with minimal effort. It is just not parallelized atm.

Hi @mlstowell , I am solving a Darcy type problem (following ex5p) with voltage boundary condition on two ports, and then of course divergence-free J is enforced everywhere except on the two ports. I am extracting J via

# Electric current density
J_gf = mfem.ParGridFunction()
J_gf.MakeRef(self.HDivFESpace, self.x.GetBlock(0), 0)
J_gf.Distribute(self.trueX.GetBlock(0))

i.e., again following ex5p. The implementation is very close to this post I made a while back.

Thanks @najlkin for the recommendations! Just ran a quick test:

cfea_anisotropy_V4_solvers

The results across the different solvers and pre-conditioners were almost identical, although the MINRES and HypreSmoother combination really improved the convergence so that’s good. It makes me wonder though if this is less of a convergence/solver issue, but rather a model setup/tensor issue… I will try to remesh this model and run it with refinement to see if makes a difference. But if anything else comes to mind let me know! Thanks a lot and have a great weekend everyone \o/ Mathias

@mdavids-cfs , try GMRES, which is more resilient for asymmetric cases and also you may try HypreSmoother instead of HypreDiagScale, which has more options to play with. What exactly parameters to set for HypreBoomerAMG, I do not remember from top of my head and it might be problem-dependent. However, this should not affect the converged solution, just the convergence rate. That GMRES is more important for that and also maybe set lower absolute tolerance 🤔

Hi @mlstowell , I guess the wording was bit misleading: with the most recent runs, the solver always converged, although of course much slower for the anisotropic case:

  • isotropic case typically converges within 150 to 250 iterations,
  • anisotropic case typically takes ~1500 to 1700 iterations

Here are some details on the solver:

  • MINRES with HypreDiagScale + HypreBoomerAMG for the two blocks
  • rtol = 1e-6
  • atol = 1e-10

Hi, @mdavids-cfs, You said “if the solver just goes astray”. Did the solver converge when the above artifacts were seen? If it did not converge these artifacts may not mean much. Best wishes, Mark

Hi, @mdavids-cfs, This looks very good to me. One possible improvement to the resistivity tensor would be to compute it at each quadrature point. The basic idea is to create a custom MatrixCoefficient which evaluates the gradient field and computes the tensor on the fly. This might take better advantage of the continuous nature of the gradient field. I would be curious to see how much difference this might produce (perhaps not that much). Best wishes, Mark

Yes, you may use a direct solver like UMFPackSolver which is also used in example 5. Unfortunately, these solvers do not scale well to computing clusters and have significant memory usage, so we try to depart from those and use iterative solvers for HDG instead 😉 .

Hi, @mdavids-cfs,

I don’t have a code snippet handy but the basic pieces you need are a pair of bilinear forms; one using GradientIntegrator and the other using VectorMassIntegrator. Multiply the GradientIntegrator bilinear form by your H1 field to produce a right hand side vector. Then solve the VectorMassIntegrator bilinear form using that right hand side. The resulting solution vector should be a vector-H1 field (using a finite element space created with an extra “dim” argument e.g. FiniteElementSpace fespace_h1v(&mesh, &fec_h1, dim);).

Best wishes, Mark

Hi @mdavids-cfs , I agree with @mlstowell that H1 is probably a better option. But I would like to comment on the performance and discretization in general, as I am working on anisotropic diffusion. The thing is that the good performance of the classical mixed scheme does not translate well to anisotropic media and you may observe (even in much simpler scenarios) decay of the precision of the solution and convergence rate. The classical mixed discretization follows de Rham complex, but this starts to be inefficient when the anisotropic coefficient couples together the continuous and discontinuous components of Raviart-Thomas or Nedelec. Not only you are losing the polynomial order, but also conditioning of such system is in question. The second thing is preconditioning, where the classical multigrids also lose performance as they do dimensional split, which does not work much anymore if the conductivity changes rapidly. You may play with the options of AMG, there are plenty and some may improve the performance. Finally, the global solver has a hard time to solve an asymmetric saddle-point problem. All these points led us to development of the L/HDG framework for mixed systems, which you may find in #4350 . I am going to present the recent progress there in my talk at the MFEM workshop. If you are around, we may talk about it 😉 . The main focus is on heat diffusion though, so support for Maxwell’s equations is limited right now, but I would like to add that feature set for Nedelecs and curl of DGs soon 🚀 .

Hi, @mdavids-cfs,

As always you produce such interesting simulations.

My first impression is that higher order basis functions would probably produce significantly smoother results. This is often the case with tetrahedral elements in particular. However, that is probably too simplistic. To go further we would need to know more about your discretization.

I assume your electrostatic solution to obtain the parallel direction uses H1 elements. The natural choice for the gradient would then be Nedelec elements. Normally I’m a big fan of Nedelec elements but they might be a poor choice in this context. My guess is that a low order Nedelec gradient on a tetrahedral mesh would produce a direction field which zig zags through the coil aligning with the local edges which are most closely aligned with the direction along the coil. This is likely to produce a discontinuous conductivity and a longer effective path through the coil (just a guess). Raviart-Thomas might do a little better at producing a conductivity which is continuous across element interfaces but I would recommend going with a fully continuous gradient i.e. vector H1. Of course this would require that you preform a global solve to compute the direction field but I suspect the results would be worth the added computational cost. This would be particularly true if the direction field remains unchanged so the added expense would be a one time cost.

Best wishes, Mark