@@ -87,21 +87,6 @@ void add(DataMap & u, const Number k, const DataMap & v)
8787 }
8888}
8989
90- // Implement u <- k*u
91- template < typename DataMap >
92- void scale (DataMap & u , const Number k )
93- {
94- for (auto & it : u )
95- {
96- std ::vector < std ::vector < Number >> & outer_vec = it .second ;
97- for (auto & inner_vec : outer_vec )
98- for (auto & value : inner_vec )
99- {
100- value *= k ;
101- }
102- }
103- }
104-
10590void add_node_data_map (RBEIMConstruction ::NodeDataMap & u , const Number k , const RBEIMConstruction ::NodeDataMap & v )
10691{
10792 for (auto & [key , vec_u ] : u )
@@ -117,18 +102,6 @@ void add_node_data_map(RBEIMConstruction::NodeDataMap & u, const Number k, const
117102 }
118103}
119104
120- void scale_node_data_map (RBEIMConstruction ::NodeDataMap & u , const Number k )
121- {
122- for (auto & it : u )
123- {
124- std ::vector < Number > & vec = it .second ;
125- for (auto & value : vec )
126- {
127- value *= k ;
128- }
129- }
130- }
131-
132105}
133106
134107RBEIMConstruction ::RBEIMConstruction (EquationSystems & es ,
@@ -434,6 +407,9 @@ void RBEIMConstruction::set_rb_construction_parameters(unsigned int n_training_s
434407
435408Real RBEIMConstruction ::train_eim_approximation ()
436409{
410+ if (_normalize_solution_snapshots )
411+ apply_normalization_to_solution_snapshots ();
412+
437413 if (best_fit_type_flag == POD_BEST_FIT )
438414 {
439415 train_eim_approximation_with_POD ();
@@ -644,6 +620,51 @@ Real RBEIMConstruction::train_eim_approximation_with_greedy()
644620 return greedy_error ;
645621}
646622
623+ void RBEIMConstruction ::apply_normalization_to_solution_snapshots ()
624+ {
625+ LOG_SCOPE ("apply_normalization_to_solution_snapshots()" , "RBEIMConstruction" );
626+
627+ libMesh ::out << "Normalizing solution snapshots" << std ::endl ;
628+
629+ bool apply_comp_scaling = !get_rb_eim_evaluation ().scale_components_in_enrichment ().empty ();
630+ unsigned int n_snapshots = get_n_training_samples ();
631+ RBEIMEvaluation & rbe = get_rb_eim_evaluation ();
632+
633+ for (unsigned int i = 0 ; i < n_snapshots ; i ++ )
634+ {
635+ if (rbe .get_parametrized_function ().on_mesh_sides ())
636+ {
637+ Real norm_val = std ::sqrt (std ::real (side_inner_product (
638+ _local_side_parametrized_functions_for_training [i ],
639+ _local_side_parametrized_functions_for_training [i ],
640+ apply_comp_scaling )));
641+
642+ if (norm_val > 0. )
643+ scale_parametrized_function (_local_side_parametrized_functions_for_training [i ], 1. /norm_val );
644+ }
645+ else if (rbe .get_parametrized_function ().on_mesh_nodes ())
646+ {
647+ Real norm_val = std ::sqrt (std ::real (node_inner_product (
648+ _local_node_parametrized_functions_for_training [i ],
649+ _local_node_parametrized_functions_for_training [i ],
650+ apply_comp_scaling )));
651+
652+ if (norm_val > 0. )
653+ scale_node_parametrized_function (_local_node_parametrized_functions_for_training [i ], 1. /norm_val );
654+ }
655+ else
656+ {
657+ Real norm_val = std ::sqrt (std ::real (inner_product (
658+ _local_parametrized_functions_for_training [i ],
659+ _local_parametrized_functions_for_training [i ],
660+ apply_comp_scaling )));
661+
662+ if (norm_val > 0. )
663+ scale_parametrized_function (_local_parametrized_functions_for_training [i ], 1. /norm_val );
664+ }
665+ }
666+ }
667+
647668Real RBEIMConstruction ::train_eim_approximation_with_POD ()
648669{
649670 LOG_SCOPE ("train_eim_approximation_with_POD()" , "RBEIMConstruction" );
@@ -823,13 +844,13 @@ Real RBEIMConstruction::train_eim_approximation_with_POD()
823844
824845 if (!is_zero_bf )
825846 {
826- scale (v , 0. );
847+ scale_parametrized_function (v , 0. );
827848
828849 for ( unsigned int i = 0 ; i < n_snapshots ; ++ i )
829850 add (v , U .el (i , j ), _local_side_parametrized_functions_for_training [i ] );
830851
831852 Real norm_v = std ::sqrt (sigma (j ));
832- scale (v , 1. /norm_v );
853+ scale_parametrized_function (v , 1. /norm_v );
833854 }
834855
835856 libmesh_try
@@ -889,13 +910,13 @@ Real RBEIMConstruction::train_eim_approximation_with_POD()
889910
890911 if (!is_zero_bf )
891912 {
892- scale_node_data_map (v , 0. );
913+ scale_node_parametrized_function (v , 0. );
893914
894915 for ( unsigned int i = 0 ; i < n_snapshots ; ++ i )
895916 add_node_data_map (v , U .el (i , j ), _local_node_parametrized_functions_for_training [i ] );
896917
897918 Real norm_v = std ::sqrt (sigma (j ));
898- scale_node_data_map (v , 1. /norm_v );
919+ scale_node_parametrized_function (v , 1. /norm_v );
899920 }
900921
901922 libmesh_try
@@ -955,13 +976,13 @@ Real RBEIMConstruction::train_eim_approximation_with_POD()
955976
956977 if (!is_zero_bf )
957978 {
958- scale (v , 0. );
979+ scale_parametrized_function (v , 0. );
959980
960981 for ( unsigned int i = 0 ; i < n_snapshots ; ++ i )
961982 add (v , U .el (i , j ), _local_parametrized_functions_for_training [i ] );
962983
963984 Real norm_v = std ::sqrt (sigma (j ));
964- scale (v , 1. /norm_v );
985+ scale_parametrized_function (v , 1. /norm_v );
965986 }
966987
967988 libmesh_try
0 commit comments