-
Notifications
You must be signed in to change notification settings - Fork 16
stochastic galerkin projection routines #300
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
base: develop
Are you sure you want to change the base?
Changes from all commits
4bf033a
d2eb0af
8f5148a
9094916
a95460b
e0b9fcd
26f1a4f
12c50c7
21fdaba
ab31a90
54213bb
ecd8234
56c0160
e489bea
17644e3
d542524
aea8cb6
15897c1
5643ec2
6356c81
bb20610
6d6e7e1
65a09c9
4f664bc
af6e728
a6207e7
d51b3cd
73d2143
4e626c9
5dca135
e0915d1
0310306
4556bdc
24eccd5
083144c
30785f1
82f2fa8
7a9785d
5a3d44a
80f8aba
e0c310d
86285ff
a92a3d1
228d58a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ | |
|
|
||
| namespace pcms | ||
| { | ||
| PetscErrorCode calculateLoadVector(Omega_h::Mesh& target_mesh, | ||
| PetscErrorCode calculateLoadVectorMI(Omega_h::Mesh& target_mesh, | ||
| Omega_h::Mesh& source_mesh, | ||
| const IntersectionResults& intersection, | ||
| const Omega_h::Reals& source_values, | ||
|
|
@@ -21,7 +21,52 @@ PetscErrorCode calculateLoadVector(Omega_h::Mesh& target_mesh, | |
|
|
||
| // Fill COO values | ||
| auto elmLoadVector = | ||
| buildLoadVector(target_mesh, source_mesh, intersection, source_values); | ||
| buildLoadVectorMI(target_mesh, source_mesh, intersection, source_values); | ||
|
|
||
| auto hostElmLoadVector = Kokkos::create_mirror_view(elmLoadVector); | ||
| Kokkos::deep_copy(hostElmLoadVector, elmLoadVector); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a |
||
| PetscCheck(static_cast<PetscInt>(hostElmLoadVector.extent(0)) == nnz, | ||
| PETSC_COMM_SELF, PETSC_ERR_ARG_SIZ, | ||
| "Element load vector size (%d) does not match COO nnz (%d)", | ||
| static_cast<PetscInt>(hostElmLoadVector.extent(0)), nnz); | ||
|
|
||
| for (PetscInt e = 0; e < nnz; ++e) { | ||
| coo_vals[e] = hostElmLoadVector(e); | ||
| } | ||
|
|
||
| // create vector with preallocated COO structure | ||
| Vec vec; | ||
| PetscCall(createSeqVec(PETSC_COMM_WORLD, target_mesh.nverts(), &vec)); | ||
| PetscCall(VecSetPreallocationCOO(vec, nnz, coo_i)); | ||
| PetscCall(VecSetValuesCOO(vec, coo_vals, ADD_VALUES)); | ||
| PetscCall(PetscFree(coo_i)); | ||
| PetscCall(PetscFree(coo_vals)); | ||
|
|
||
| if (target_mesh.nelems() < 10) { | ||
| PetscCall(VecView(vec, PETSC_VIEWER_STDOUT_WORLD)); | ||
| } | ||
|
|
||
| *loadVec_out = vec; | ||
| PetscFunctionReturn(PETSC_SUCCESS); | ||
| } | ||
|
|
||
| PetscErrorCode calculateLoadVectorMC( | ||
| Omega_h::Mesh& target_mesh, const Omega_h::Reals& field_values_at_points, | ||
| const int npoints_each_tri, SamplingMethod method, Vec* loadVec_out, | ||
| const std::string sobol_filename) | ||
| { | ||
|
|
||
| PetscFunctionBeginUser; | ||
| PetscInt nnz = 0; | ||
| PetscInt* coo_i = nullptr; | ||
| PetscCall(build_linear_triangle_coo_rows(target_mesh, &coo_i, &nnz)); | ||
| PetscScalar* coo_vals = nullptr; | ||
| PetscCall(PetscMalloc1(nnz, &coo_vals)); | ||
|
|
||
| // Fill COO values | ||
| auto elmLoadVector = | ||
| buildLoadVectorMC(target_mesh, field_values_at_points, npoints_each_tri, | ||
| method, sobol_filename); | ||
|
|
||
| auto hostElmLoadVector = Kokkos::create_mirror_view(elmLoadVector); | ||
| Kokkos::deep_copy(hostElmLoadVector, elmLoadVector); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -86,10 +86,9 @@ static Omega_h::Reals vecToOmegaHReals(Vec vec) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return Omega_h::Reals(values_host); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Omega_h::Reals solveGalerkinProjection(Omega_h::Mesh& target_mesh, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Omega_h::Mesh& source_mesh, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const IntersectionResults& intersection, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const Omega_h::Reals& source_values) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Omega_h::Reals solveGalerkinProjectionMI( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Omega_h::Mesh& target_mesh, Omega_h::Mesh& source_mesh, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const IntersectionResults& intersection, const Omega_h::Reals& source_values) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ((PetscInt)source_values.size() != | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| source_mesh.coords().size() / source_mesh.dim()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -105,8 +104,8 @@ Omega_h::Reals solveGalerkinProjection(Omega_h::Mesh& target_mesh, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CHKERRABORT(PETSC_COMM_WORLD, ierr); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Vec vec; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ierr = calculateLoadVector(target_mesh, source_mesh, intersection, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| source_values, &vec); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ierr = calculateLoadVectorMI(target_mesh, source_mesh, intersection, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| source_values, &vec); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CHKERRABORT(PETSC_COMM_WORLD, ierr); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Vec x = solveLinearSystem(mass, vec); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -123,15 +122,46 @@ Omega_h::Reals solveGalerkinProjection(Omega_h::Mesh& target_mesh, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return solution_vector; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Omega_h::Reals rhsVectorMI(Omega_h::Mesh& target_mesh, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Omega_h::Mesh& source_mesh, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const IntersectionResults& intersection, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const Omega_h::Reals& source_values) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Omega_h::Reals solveGalerkinProjectionMC( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Omega_h::Mesh& target_mesh, const Omega_h::Reals& field_values_at_points, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const int npoints_each_tri, SamplingMethod method, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const std::string sobol_filename) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Mat mass; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| PetscErrorCode ierr = calculateMassMatrix(target_mesh, &mass); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CHKERRABORT(PETSC_COMM_WORLD, ierr); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Vec vec; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ierr = calculateLoadVectorMC(target_mesh, field_values_at_points, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| npoints_each_tri, method, &vec, sobol_filename); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CHKERRABORT(PETSC_COMM_WORLD, ierr); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+126
to
+139
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Vec x = solveLinearSystem(mass, vec); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| auto solution_vector = vecToOmegaHReals(x); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ierr = VecDestroy(&x); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CHKERRABORT(PETSC_COMM_WORLD, ierr); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ierr = MatDestroy(&mass); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CHKERRABORT(PETSC_COMM_WORLD, ierr); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ierr = VecDestroy(&vec); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CHKERRABORT(PETSC_COMM_WORLD, ierr); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return solution_vector; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Omega_h::Reals computeRhsVectorMI(Omega_h::Mesh& target_mesh, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Omega_h::Mesh& source_mesh, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const IntersectionResults& intersection, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const Omega_h::Reals& source_values) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Vec vec; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| PetscErrorCode ierr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ierr = calculateLoadVector(target_mesh, source_mesh, intersection, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| source_values, &vec); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ierr = calculateLoadVectorMI(target_mesh, source_mesh, intersection, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| source_values, &vec); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CHKERRABORT(PETSC_COMM_WORLD, ierr); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| auto rhsvector = vecToOmegaHReals(vec); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -141,4 +171,26 @@ Omega_h::Reals rhsVectorMI(Omega_h::Mesh& target_mesh, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return rhsvector; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Omega_h::Reals computeRhsVectorMC(Omega_h::Mesh& target_mesh, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const Omega_h::Reals& field_values_at_points, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const int npoints_each_tri, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| SamplingMethod method, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const std::string& sobol_filename) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Vec vec; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| PetscErrorCode ierr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ierr = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| calculateLoadVectorMC(target_mesh, field_values_at_points, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| npoints_each_tri, method, &vec, sobol_filename); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CHKERRABORT(PETSC_COMM_WORLD, ierr); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| auto rhsvector = vecToOmegaHReals(vec); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ierr = VecDestroy(&vec); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CHKERRABORT(PETSC_COMM_WORLD, ierr); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return rhsvector; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+181
to
+195
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Vec vec; | |
| PetscErrorCode ierr; | |
| ierr = | |
| calculateLoadVectorMC(target_mesh, field_values_at_points, | |
| npoints_each_tri, method, &vec, sobol_filename); | |
| CHKERRABORT(PETSC_COMM_WORLD, ierr); | |
| auto rhsvector = vecToOmegaHReals(vec); | |
| ierr = VecDestroy(&vec); | |
| CHKERRABORT(PETSC_COMM_WORLD, ierr); | |
| return rhsvector; | |
| } | |
| Vec vec; | |
| PetscErrorCode ierr; | |
| ierr = | |
| calculateLoadVectorMC(target_mesh, field_values_at_points, | |
| npoints_each_tri, method, &vec, sobol_filename); | |
| CHKERRABORT(PETSC_COMM_WORLD, ierr); | |
| auto rhsvector = vecToOmegaHReals(vec); | |
| ierr = VecDestroy(&vec); | |
| CHKERRABORT(PETSC_COMM_WORLD, ierr); | |
| return rhsvector; | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I haven't missed anything, the
calculateLoadVectorMIandcalculateLoadVectorMCshare roughly 90% of their code, there may be room to refactor and eliminate the duplication.