template <int dim>
void MaxwellProblem<dim>::compute_Curl_field()
{
QGauss<dim> quadrature_formula(quad_order);
const unsigned int n_q_points = quadrature_formula.size();
FEValues<dim> fe_values(fe, quadrature_formula,
update_values | update_gradients | update_quadrature_points
| update_JxW_values);
const unsigned int dofs_per_cell = fe.dofs_per_cell;
std::vector<types::global_dof_index> local_dof_indices(dofs_per_cell);
// storage for computed H field solution:
Tensor<1, dim> curlsol(n_q_points);
typename DoFHandler<dim>::active_cell_iterator cell =
dof_handler.begin_active(), endc = dof_handler.end();
for (; cell != endc; ++cell)
{
fe_values.reinit(cell);
// Determine the global indices of the cell Dof:
cell->get_dof_indices(local_dof_indices);
if (cell == dof_handler.begin_active())
std::cout << "local_dofs_size: " << local_dof_indices.size() << std::endl;
// Calculate the values of curl of the fe solution:
// Loop over quad points to calculate solution:
for (unsigned int q_point = 0; q_point < n_q_points; ++q_point)
{
curlsol[q_point] = 0.0;
// Loop over DoFs to calculate curl of solution @ quad point
for (unsigned int i = 0; i < dofs_per_cell; ++i)
{
// Construct local curl value @ quad point integrating
curlsol += solution(local_dof_indices[i])
* fe_values[A_re].curl(i, q_point)
* fe_values.JxW(q_point);
}
}
// Store the curl of the solution in H_solution
for (unsigned int i = 0; i < n_q_points; ++i)
H_solution(local_dof_indices[i]) = curlsol[i];
// \-> This would seems to be included in the loop over the quadrature
// points, but then how would it be added into the global H_solution
// vector of curl's.
}
}
template <int dim>
void MaxwellProblem<dim>::output_results() const
{
deallog << "Generating output... ";
DataOut<dim> data_out;
data_out.attach_dof_handler(dof_handler);
std::ostringstream filename;
filename << "solution-MagnetostaticProblem" << ".vtu";
std::ofstream output(filename.str().c_str());
std::vector<std::string> solution_names;
solution_names.push_back("A_x");
solution_names.push_back("A_y");
solution_names.push_back("A_z");
std::vector<std::string> curl_solution_names;
curl_solution_names.push_back("H_x");
curl_solution_names.push_back("H_y");
curl_solution_names.push_back("H_z");
data_out.add_data_vector(H_solution, curl_solution_names);
data_out.build_patches();
data_out.write_vtu(output);
}
// Loop over quad points to calculate solution:for (unsigned int q_point=0; q_point<n_q_points; ++q_point){
// Loop over DoFs to calculate curl of solution @ quad point
curlsol_re=0.0; for (unsigned int i=0; i<dofs_per_cell; ++i) { // Calculate contribute @ this quad point for this local DoF: curlsol_re += solution(local_dof_indices[i])*fe_values[A_re].curl(i,q_point); } // Store local curl solution for this quad point: local_curl(q_point) = curlsol_re;}
H_solution(local_dof_indices[i]) = curlsol[i];
computed_quantities[q](0) = (duh[q][2][1]-duh[q][1][2]);
computed_quantities[q](1) = (duh[q][0][2]-duh[q][2][0]);computed_quantities[q](2) = (duh[q][1][0]-duh[q][0][1]);
// storage for computed H field solution:
Tensor<1, dim> curlsol(n_q_points);
Tensor<1, dim> curlsol;
temp_curlsol += solution(local_dof_indices[i]) * fe_values[A_re].curl(i, q_point) * fe_values.JxW(q_point);
1. In the inner loop I am doing as you suggest but I am also adding the "fe_values.JxW(q_point)" as this is needed to compute the curl in the real cell from the referece cell values given by the "fe_values[A_re].curl(i, q_point)" function as follows:
temp_curlsol += solution(local_dof_indices[i]) * fe_values[A_re].curl(i, q_point) * fe_values.JxW(q_point);
2. This approach would also help me, but I am not sure how to go about it. How can I extract these differentials (fe_values.shape_grad_component (...)?)
per quadrature point and then compute the curl as in the code snippet you suggest?
Also, I would like to evaluate the curl in the center of the element (cell->center), so I would want to evaluate the curl from the shaper functions at this point, is there support in deal.ii for this?
Thanks!
Best
Alexander