Skip to content

Commit 644101b

Browse files
committed
(a) specifying element range in project_solution as well (b) add a test to project solution onto specific elements
1 parent d01b3ce commit 644101b

File tree

5 files changed

+290
-21
lines changed

5 files changed

+290
-21
lines changed

include/systems/system.h

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -515,19 +515,25 @@ class System : public ReferenceCountedObject<System>,
515515
* user-provided cloneable functors.
516516
* A gradient \p g is only required/used for projecting onto finite
517517
* element spaces with continuous derivatives.
518+
* elem_range \p active_local_range, if provided, indicates the range of elements
519+
* over which to perform the projection.
518520
*/
519521
void project_solution (FunctionBase<Number> * f,
520-
FunctionBase<Gradient> * g = nullptr) const;
522+
FunctionBase<Gradient> * g = nullptr,
523+
std::optional<ConstElemRange> active_local_range = std::nullopt) const;
521524

522525
/**
523526
* Projects arbitrary functions onto the current solution.
524527
* The function value \p f and its gradient \p g are
525528
* user-provided cloneable functors.
526529
* A gradient \p g is only required/used for projecting onto finite
527530
* element spaces with continuous derivatives.
531+
* elem_range \p active_local_range, if provided, indicates the range of elements
532+
* over which to perform the projection.
528533
*/
529534
void project_solution (FEMFunctionBase<Number> * f,
530-
FEMFunctionBase<Gradient> * g = nullptr) const;
535+
FEMFunctionBase<Gradient> * g = nullptr,
536+
std::optional<ConstElemRange> active_local_range = std::nullopt) const;
531537

532538
/**
533539
* Projects arbitrary functions onto the current solution.
@@ -546,7 +552,8 @@ class System : public ReferenceCountedObject<System>,
546552
const std::string & unknown_name);
547553
void project_solution (ValueFunctionPointer fptr,
548554
GradientFunctionPointer gptr,
549-
const Parameters & parameters) const;
555+
const Parameters & parameters,
556+
std::optional<ConstElemRange> active_local_range = std::nullopt) const;
550557

551558
/**
552559
* Projects arbitrary functions onto a vector of degree of freedom
@@ -555,6 +562,8 @@ class System : public ReferenceCountedObject<System>,
555562
* user-provided cloneable functors.
556563
* A gradient \p g is only required/used for projecting onto finite
557564
* element spaces with continuous derivatives.
565+
* elem_range \p active_local_range, if provided, indicates the range of elements
566+
* over which to perform the projection.
558567
*
559568
* Constrain the new vector using the requested adjoint rather than
560569
* primal constraints if is_adjoint is non-negative.
@@ -572,6 +581,8 @@ class System : public ReferenceCountedObject<System>,
572581
* user-provided cloneable functors.
573582
* A gradient \p g is only required/used for projecting onto finite
574583
* element spaces with continuous derivatives.
584+
* elem_range \p active_local_range, if provided, indicates the range of elements
585+
* over which to perform the projection.
575586
*
576587
* Constrain the new vector using the requested adjoint rather than
577588
* primal constraints if is_adjoint is non-negative.
@@ -589,6 +600,8 @@ class System : public ReferenceCountedObject<System>,
589600
* represented by function pointers.
590601
* A gradient \p gptr is only required/used for projecting onto
591602
* finite element spaces with continuous derivatives.
603+
* elem_range \p active_local_range, if provided, indicates the range of elements
604+
* over which to perform the projection.
592605
*
593606
* Constrain the new vector using the requested adjoint rather than
594607
* primal constraints if is_adjoint is non-negative.
@@ -611,11 +624,14 @@ class System : public ReferenceCountedObject<System>,
611624
* user-provided cloneable functors.
612625
* A gradient \p g is only required/used for projecting onto finite
613626
* element spaces with continuous derivatives.
627+
* elem_range \p active_local_range, if provided, indicates the range of elements
628+
* over which to perform the projection.
614629
*/
615630
void boundary_project_solution (const std::set<boundary_id_type> & b,
616631
const std::vector<unsigned int> & variables,
617632
FunctionBase<Number> * f,
618-
FunctionBase<Gradient> * g = nullptr);
633+
FunctionBase<Gradient> * g = nullptr,
634+
std::optional<ConstElemRange> active_local_range = std::nullopt);
619635

620636
/**
621637
* Projects arbitrary boundary functions onto a vector of degree of
@@ -628,12 +644,15 @@ class System : public ReferenceCountedObject<System>,
628644
* represented by function pointers.
629645
* A gradient \p gptr is only required/used for projecting onto
630646
* finite element spaces with continuous derivatives.
647+
* elem_range \p active_local_range, if provided, indicates the range of elements
648+
* over which to perform the projection.
631649
*/
632650
void boundary_project_solution (const std::set<boundary_id_type> & b,
633651
const std::vector<unsigned int> & variables,
634652
ValueFunctionPointer fptr,
635653
GradientFunctionPointer gptr,
636-
const Parameters & parameters);
654+
const Parameters & parameters,
655+
std::optional<ConstElemRange> active_local_range = std::nullopt);
637656

638657
/**
639658
* Projects arbitrary boundary functions onto a vector of degree of
@@ -646,6 +665,8 @@ class System : public ReferenceCountedObject<System>,
646665
* user-provided cloneable functors.
647666
* A gradient \p g is only required/used for projecting onto finite
648667
* element spaces with continuous derivatives.
668+
* elem_range \p active_local_range, if provided, indicates the range of elements
669+
* over which to perform the projection.
649670
*
650671
* Constrain the new vector using the requested adjoint rather than
651672
* primal constraints if is_adjoint is non-negative.
@@ -669,6 +690,8 @@ class System : public ReferenceCountedObject<System>,
669690
* represented by function pointers.
670691
* A gradient \p gptr is only required/used for projecting onto
671692
* finite element spaces with continuous derivatives.
693+
* elem_range \p active_local_range, if provided, indicates the range of elements
694+
* over which to perform the projection.
672695
*
673696
* Constrain the new vector using the requested adjoint rather than
674697
* primal constraints if is_adjoint is non-negative.

src/systems/system_projection.C

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,11 +1031,12 @@ void System::projection_matrix (SparseMatrix<Number> & proj_mat) const
10311031
*/
10321032
void System::project_solution (ValueFunctionPointer fptr,
10331033
GradientFunctionPointer gptr,
1034-
const Parameters & function_parameters) const
1034+
const Parameters & function_parameters,
1035+
std::optional<ConstElemRange> active_local_range) const
10351036
{
10361037
WrappedFunction<Number> f(*this, fptr, &function_parameters);
10371038
WrappedFunction<Gradient> g(*this, gptr, &function_parameters);
1038-
this->project_solution(&f, &g);
1039+
this->project_solution(&f, &g, active_local_range);
10391040
}
10401041

10411042

@@ -1044,9 +1045,10 @@ void System::project_solution (ValueFunctionPointer fptr,
10441045
* projections and nodal interpolations on each element.
10451046
*/
10461047
void System::project_solution (FunctionBase<Number> * f,
1047-
FunctionBase<Gradient> * g) const
1048+
FunctionBase<Gradient> * g,
1049+
std::optional<ConstElemRange> active_local_range) const
10481050
{
1049-
this->project_vector(*solution, f, g);
1051+
this->project_vector(*solution, f, g, /*is_adjoint=*/-1, active_local_range);
10501052

10511053
solution->localize(*current_local_solution, _dof_map->get_send_list());
10521054
}
@@ -1057,9 +1059,10 @@ void System::project_solution (FunctionBase<Number> * f,
10571059
* projections and nodal interpolations on each element.
10581060
*/
10591061
void System::project_solution (FEMFunctionBase<Number> * f,
1060-
FEMFunctionBase<Gradient> * g) const
1062+
FEMFunctionBase<Gradient> * g,
1063+
std::optional<ConstElemRange> active_local_range) const
10611064
{
1062-
this->project_vector(*solution, f, g);
1065+
this->project_vector(*solution, f, g, /*is_adjoint=*/-1, active_local_range);
10631066

10641067
solution->localize(*current_local_solution, _dof_map->get_send_list());
10651068
}
@@ -1248,11 +1251,13 @@ void System::boundary_project_solution (const std::set<boundary_id_type> & b,
12481251
const std::vector<unsigned int> & variables,
12491252
ValueFunctionPointer fptr,
12501253
GradientFunctionPointer gptr,
1251-
const Parameters & function_parameters)
1254+
const Parameters & function_parameters,
1255+
std::optional<ConstElemRange> active_local_range)
1256+
12521257
{
12531258
WrappedFunction<Number> f(*this, fptr, &function_parameters);
12541259
WrappedFunction<Gradient> g(*this, gptr, &function_parameters);
1255-
this->boundary_project_solution(b, variables, &f, &g);
1260+
this->boundary_project_solution(b, variables, &f, &g, active_local_range);
12561261
}
12571262

12581263

@@ -1264,9 +1269,10 @@ void System::boundary_project_solution (const std::set<boundary_id_type> & b,
12641269
void System::boundary_project_solution (const std::set<boundary_id_type> & b,
12651270
const std::vector<unsigned int> & variables,
12661271
FunctionBase<Number> * f,
1267-
FunctionBase<Gradient> * g)
1272+
FunctionBase<Gradient> * g,
1273+
std::optional<ConstElemRange> active_local_range)
12681274
{
1269-
this->boundary_project_vector(b, variables, *solution, f, g);
1275+
this->boundary_project_vector(b, variables, *solution, f, g, -1 /*is_adjoint*/, active_local_range);
12701276

12711277
solution->localize(*current_local_solution);
12721278
}

tests/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ unit_tests_sources = \
9494
mesh/write_nodeset_data.C \
9595
mesh/write_edgeset_data.C \
9696
mesh/write_vec_and_scalar.C \
97+
mesh/project_solution_test.C \
9798
numerics/composite_function_test.C \
9899
numerics/coupling_matrix_test.C \
99100
numerics/distributed_vector_test.C \

0 commit comments

Comments
 (0)