Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to calculate solution at every cell center point? #12777

Closed
JiaShumei92 opened this issue Sep 27, 2021 · 5 comments
Closed

How to calculate solution at every cell center point? #12777

JiaShumei92 opened this issue Sep 27, 2021 · 5 comments

Comments

@JiaShumei92
Copy link

JiaShumei92 commented Sep 27, 2021

Dear every dealii user,
Wish you good day!
I am a beginner to dealii. The version that I am using is 9.3.0.
I have caught with a problem when I am solving my FEM problems. Could anyone please help me with it?
I am intended to get all active cells` center point values, so I followed the tutorials and use the following coding.

size_t cellCount = 0; //keep the cell`s count;
for (auto& cell : triangulation.active_cell_iterators())
{
//### get the cell`s center point solution:
double adata = dealii::VectorTools::point_value(dof_handler, solution, cell->center());

//### put the solution to a "VectorXd":
phantVValues(vindex) = adata;

//### next cell:
++cellCount;
}

The problem is that when my active cell`s amount is large, this coding is in vastly slow calculation speed. I find another dealii method to solve the problem,
which is as follows. However, it is also very 'expensive' for very large amount of cells.

//additional.
//### define a FEFieldFunction object 'solution_function',
dealii::Functions::FEFieldFunction<3, dealii::DoFHandler<3>, dealii::Vector<double>>
solution_function(dof_handler, solution);

size_t cellCount = 0; //keep the cell`s count;
for (const auto& cell : dof_handler.active_cell_iterators())
{
//### cell`s center axis:
dealii::Point<3> cCell = cell->center();

//### set this cell as active cell:
solution_function.set_active_cell(cell);

//### get the cell`s center point solution:
double adata = solution_function.value(cCell);

//### put the solution to a "VectorXd":
phantVValues(vindex) = adata;

//### next cell:
++cell_Count;
}

Are there any convenient and immediate methods in dealii version9.3.0 to get every cell center value?
I would be very appreciated if you can give me some suggestions.
Looking forward to your reply. Best wishes to you!

--

Yours,
sincerely.

@JiaShumei92 JiaShumei92 changed the title How to calculate solutions at every cell center point? How to calculate solution at every cell center point? Sep 27, 2021
@peterrum
Copy link
Member

Take a look at step-19 and how FEPointEvaluation is used:

FEPointEvaluation<1, dim> evaluator(mapping, fe, update_gradients);

You can simply fill particle_positions with your (0.5)^d.

Hope this helps! A general remark: normally we ask such type of questions on the google mailing list.

PM

@JiaShumei92
Copy link
Author

Take a look at step-19 and how FEPointEvaluation is used:

FEPointEvaluation<1, dim> evaluator(mapping, fe, update_gradients);

You can simply fill particle_positions with your (0.5)^d.

Hope this helps! A general remark: normally we ask such type of questions on the google mailing list.

PM

Thank you very much for your suggestion. I am learning step-19 now. I am sorry that I cannot open "https://groups.google.com/g/dealii" net address. So I put my question as an issue.

@drwells
Copy link
Member

drwells commented Sep 27, 2021

If you always need values at the cell center, another option is to use QMidpoint and FEValues::get_function_values().

@JiaShumei92
Copy link
Author

Take a look at step-19 and how FEPointEvaluation is used:

FEPointEvaluation<1, dim> evaluator(mapping, fe, update_gradients);

You can simply fill particle_positions with your (0.5)^d.

Hope this helps! A general remark: normally we ask such type of questions on the google mailing list.

PM

Thank you again! I have gotten my cell centers' solutions following @drwells suggestions and step-9 tutorial 'GradientEstimation' class.
The kernal lines are as follwing:

//
scratch_data.fe_midpoint_value.reinit(cell); //initialize FEValues object at an active cell;

scratch_data.fe_midpoint_value.get_function_values(scratch_data.solution, //my whole solutions at nodes;
scratch_data.cmVal); //vector cmVal(1), to get this cell center solution.

scratch_data.cell_midpoint_value(cell->active_cell_index()) = scratch_data.cmVal[0]; //push this cell center value to a full vector.
//

@JiaShumei92
Copy link
Author

If you always need values at the cell center, another option is to use QMidpoint and FEValues::get_function_values().

Thank you very much for your helpful suggestions! I have solved my problem successfully with QMidpoint and FEValues::get_function_values() methods. I put some of my kernal lines at the reply to @peterrum. (It is maybe useful to other users.)
Wish you good day!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants