# Visualization of analytical solution

**URL:** https://community.geodynamics.org/t/visualization-of-analytical-solution/1080
**Category:** ASPECT
**Created:** [January 31, 2020, 3:27pm UTC](https://community.geodynamics.org/t/visualization-of-analytical-solution/1080 "2020-01-31T15:27:20Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![zhirui3](https://yyz2.discourse-cdn.com/flex036/user_avatar/community.geodynamics.org/zhirui3/32/447_2.png) [@zhirui3](https://community.geodynamics.org/u/zhirui3)
#### Post date: [January 31, 2020, 3:27pm UTC](https://community.geodynamics.org/t/visualization-of-analytical-solution/1080/1 "2020-01-31T15:27:20Z")

</div>

Hi all,

I am currently working on a benchmark problem and I am thinking that it would be nice to visualize both analytical and numerical solutions.

Here in order to visualize the analytical solution, I am thinking about implementing it into the MaterialModel::NamedAdditionalOuputs class, then generating the visualization in the PostProcess::VisualizationPostProcessors::NamedAdditionalOutputs. Yet I am wondering if there is any other simpler way to do that or if there is any example I can follow.

Thanks in advance,  
Regards,  
Ray

---

<div class="post-metadata">

### Author: ![tjhei](https://yyz2.discourse-cdn.com/flex036/user_avatar/community.geodynamics.org/tjhei/32/1163_2.png) [@tjhei](https://community.geodynamics.org/u/tjhei)
#### Post date: [January 31, 2020, 4:08pm UTC](https://community.geodynamics.org/t/visualization-of-analytical-solution/1080/2 "2020-01-31T16:08:51Z")

</div>

Yes, this sounds like a reasonable approach. We currently have no example that does this, but it would be very interesting to have! Let us know if you something we could try and include in one of the examples.  
You could also interpolate the analytical solution to a compositional field and output that, but you have to do a few tricks (you will need fields for each velocity component) and the FE degree is likely not correct (for example for the pressure, which should be 1 instead of 2). So, I think your plan sounds easier.

---

<div class="post-metadata">

### Author: ![bangerth](https://yyz2.discourse-cdn.com/flex036/user_avatar/community.geodynamics.org/bangerth/32/52_2.png) [@bangerth](https://community.geodynamics.org/u/bangerth)
#### Post date: [January 31, 2020, 10:23pm UTC](https://community.geodynamics.org/t/visualization-of-analytical-solution/1080/3 "2020-01-31T22:23:48Z")

</div>

Ray,

> I am currently working on a benchmark problem and I am thinking that it would  
> be nice to visualize both analytical and numerical solutions.
> 
> Here in order to visualize the analytical solution, I am thinking about  
> implementing it into the MaterialModel::NamedAdditionalOuputs class, then  
> generating the visualization in the  
> PostProcess::VisualizationPostProcessors::NamedAdditionalOutputs. Yet I am  
> wondering if there is any other simpler way to do that or if there is any  
> example I can follow.

Timo’s suggestions work, but I’d like to provide a slightly different  
perspective: You can’t see differences in figures that are below 10% of the  
function values. As a consequence, for most benchmarks, visualizing the exact  
solution will almost certainly look exactly like the numerical solution. When  
you see pictures in papers that show the “exact solution”, they almost always  
show the “numerical solution on a fine grid” instead.

In other words, it may not be worth your time to figure out a way to output  
the exact solution 🙂

Best  
W.

---

<div class="post-metadata">

### Author: ![zhirui3](https://yyz2.discourse-cdn.com/flex036/user_avatar/community.geodynamics.org/zhirui3/32/447_2.png) [@zhirui3](https://community.geodynamics.org/u/zhirui3)
#### Post date: [February 3, 2020, 1:21pm UTC](https://community.geodynamics.org/t/visualization-of-analytical-solution/1080/4 "2020-02-03T13:21:27Z")

</div>

Dear Timo and Wolfgang,

Thank you so much for your messages. The goal of visualizing the analytical solution is that I can then plot the relative error between analytical and numerical solutions throughout the entire domain. Thus I am thinking that I would be able to do it on Paraview if I can graphically output the analytical solution. Or maybe there are better approaches out there.

Thanks,  
Ray

---

<div class="post-metadata">

### Author: ![tjhei](https://yyz2.discourse-cdn.com/flex036/user_avatar/community.geodynamics.org/tjhei/32/1163_2.png) [@tjhei](https://community.geodynamics.org/u/tjhei)
#### Post date: [February 3, 2020, 2:38pm UTC](https://community.geodynamics.org/t/visualization-of-analytical-solution/1080/5 "2020-02-03T14:38:07Z")

</div>

This is not a good idea:

1. this will output a linear interpolation of the exact solution, so you are not comparing against the exact solution.
2. Operations in paraview are not exact but operate on (incorrectly) interpolated data.
3. I don’t trust paraview to be accurate even knowing these limitations.

Just compute the errors like we do in several of the benchmark/ examples (see burstedde for example).

---

<div class="post-metadata">

### Author: ![gassmoeller](https://yyz2.discourse-cdn.com/flex036/user_avatar/community.geodynamics.org/gassmoeller/32/11_2.png) [@gassmoeller](https://community.geodynamics.org/u/gassmoeller)
#### Post date: [February 3, 2020, 6:42pm UTC](https://community.geodynamics.org/t/visualization-of-analytical-solution/1080/6 "2020-02-03T18:42:02Z")

</div>

Just to extend a bit on this: Of course doing what you planned will give you an estimate for the differences between analytical and numerical solution, however as Timo pointed out it will be a pretty rough estimate, and you might as well use the Paraview “Calculator” filter to compute the analytical solution in Paraview, which might be simpler than implementing it in aspect. If you want to have more accurate estimates for the error (in particular if you want to quantify the error and not just get an impression for where the errors are) then you would need to calculate the error inside aspect, e.g. in as postprocessor (as in benchmarks/burstedde/burstedde.cc in the postprocessor class) which computes a combined norm of the error, or as a named additional named output in the material model, which would output the error at every point in the domain.

Best,  
Rene

---

<div class="post-metadata">

### Author: ![zhirui3](https://yyz2.discourse-cdn.com/flex036/user_avatar/community.geodynamics.org/zhirui3/32/447_2.png) [@zhirui3](https://community.geodynamics.org/u/zhirui3)
#### Post date: [February 4, 2020, 3:30pm UTC](https://community.geodynamics.org/t/visualization-of-analytical-solution/1080/7 "2020-02-04T15:30:19Z")

</div>

Thanks a lot! Calculating the errors inside the Aspect indeed sounds like a more accurate approach.

This may sound like a very silly question, but here in order to visualize the solution via the named additional output, I am wondering if I have to implement anything inside the Visualization::Postprocessor::NamedAdditionalOutuputs, or just fill the outputs in the material model is fine.

Best,  
Ray

---

<div class="post-metadata">

### Author: ![tjhei](https://yyz2.discourse-cdn.com/flex036/user_avatar/community.geodynamics.org/tjhei/32/1163_2.png) [@tjhei](https://community.geodynamics.org/u/tjhei)
#### Post date: [February 4, 2020, 3:46pm UTC](https://community.geodynamics.org/t/visualization-of-analytical-solution/1080/8 "2020-02-04T15:46:14Z")

</div>

> [@zhirui3](#):
>
> This may sound like a very silly question, but here in order to visualize the solution via the named additional output, I am wondering if I have to implement anything inside the Visualization::Postprocessor::NamedAdditionalOutuputs, or just fill the outputs in the material model is fine.

You would need to

1. Create a new class derived from NamedAdditionalMaterialOutputs (see SeismicAdditionalOutputs for example)
2. Your material model needs to implement create\_additional\_named\_outputs() (see CompositionReaction for an example).
3. You need to enable the “named additional outputs” visualization postprocessor.

That’s it.

---

<div class="post-metadata">

### Author: ![zhirui3](https://yyz2.discourse-cdn.com/flex036/user_avatar/community.geodynamics.org/zhirui3/32/447_2.png) [@zhirui3](https://community.geodynamics.org/u/zhirui3)
#### Post date: [February 5, 2020, 2:33pm UTC](https://community.geodynamics.org/t/visualization-of-analytical-solution/1080/9 "2020-02-05T14:33:50Z")

</div>

Thanks Timo! That makes much better sense now.

But when I am trying to enable the visualization postprocessor by entering my ‘named output’ (i.e. the error in this case) or ‘named additional outputs’ in the List of Output Variables of the parameter file. Aspect still gives me the invalid parameter file error. Thus I am wondering if I am still missing a step here.

Thanks a lot for the help

---

<div class="post-metadata">

### Author: ![tjhei](https://yyz2.discourse-cdn.com/flex036/user_avatar/community.geodynamics.org/tjhei/32/1163_2.png) [@tjhei](https://community.geodynamics.org/u/tjhei)
#### Post date: [February 5, 2020, 6:18pm UTC](https://community.geodynamics.org/t/visualization-of-analytical-solution/1080/10 "2020-02-05T18:18:45Z")

</div>

`set List of output variables = named additional outputs`  
should be working. If not, please post your .prm and the precise error message.

---

<div class="post-metadata">

### Author: ![zhirui3](https://yyz2.discourse-cdn.com/flex036/user_avatar/community.geodynamics.org/zhirui3/32/447_2.png) [@zhirui3](https://community.geodynamics.org/u/zhirui3)
#### Post date: [February 6, 2020, 4:05pm UTC](https://community.geodynamics.org/t/visualization-of-analytical-solution/1080/11 "2020-02-06T16:05:07Z")

</div>

Just figured it out today, thanks a lot!
