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.

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.

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

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.

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.

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.

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.