Skip to content

Commit 98bf0d6

Browse files
committed
HYD system:
- Bug fix FP angle -90 degree - added a dynamic stepsize for FP2FP coupling via Courant criteria - added hit-key figure, how often the limiter in FP2FP coupling is hit; also a percentage evaluation - added the error negative discharge boundaries, which can not be extracted out of the model to the hydrological bilan
1 parent 4e91362 commit 98bf0d6

21 files changed

+337
-73
lines changed

source_code/system_hydraulic/source_code/models/coupling/Hyd_Coupling_FP2FP.cpp

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ Hyd_Coupling_FP2FP::Hyd_Coupling_FP2FP(void){
88
this->defining_polysegment.set_line_type(_hyd_floodplain_polysegment_type::FP_BOUNDARYLINE);
99
this->area_limiter = 0.0;
1010
this->counter_limiter = 0;
11+
this->counter_tot_coupling_active=0;
12+
this->timestep_opt_hit_limit=0.0;
13+
this->timestep_opt_cor=0.0;
1114

1215
//count the memory
1316
Sys_Memory_Count::self()->add_mem(sizeof(Hyd_Coupling_FP2FP)-sizeof(Hyd_Coupling_Point_FP2FP_List), _sys_system_modules::HYD_SYS);
@@ -53,6 +56,9 @@ void Hyd_Coupling_FP2FP::init_coupling(void){
5356
this->area_limiter=*this->floodplain_model_1->Param_FP.get_ptr_width_x()* *this->floodplain_model_1->Param_FP.get_ptr_width_y();
5457
this->area_limiter = min(this->area_limiter, *this->floodplain_model_2->Param_FP.get_ptr_width_x() * *this->floodplain_model_2->Param_FP.get_ptr_width_y());
5558
this->counter_limiter = 0;
59+
this->counter_tot_coupling_active = 0;
60+
this->timestep_opt_hit_limit = 0.0;
61+
this->timestep_opt_cor = 0.0;
5662

5763
//sort it along the defining line
5864
this->list.sort_distance_along_polysegment();
@@ -96,8 +102,12 @@ void Hyd_Coupling_FP2FP::synchronise_models(const double timepoint, const double
96102

97103

98104
//}
105+
if (time_check == true) {
106+
this->timestep_opt_hit_limit = 0.0;
107+
this->timestep_opt_cor = 0.0;
108+
}
99109

100-
this->list.syncronisation_models_bylistpoints(timepoint, delta_t, time_check, internal_counter, this->area_limiter,&this->counter_limiter);
110+
this->list.syncronisation_models_bylistpoints(timepoint, delta_t, time_check, internal_counter, this->area_limiter,&this->counter_limiter, &this->counter_tot_coupling_active, &this->timestep_opt_hit_limit, &this->timestep_opt_cor);
101111

102112
}
103113
catch(Error msg){
@@ -145,6 +155,9 @@ void Hyd_Coupling_FP2FP::clone_couplings(Hyd_Coupling_FP2FP *coupling, Hyd_Hydra
145155
this->defining_polysegment.clone_polysegment(&coupling->defining_polysegment);
146156
this->area_limiter = coupling->area_limiter;
147157
this->counter_limiter = 0;
158+
this->counter_tot_coupling_active = 0;
159+
this->timestep_opt_hit_limit = 0.0;
160+
this->timestep_opt_cor = 0.0;
148161

149162
this->list.set_defining_polysegment(&this->defining_polysegment);
150163
this->list.clone_list(&coupling->list, this->floodplain_model_1, this->floodplain_model_2);
@@ -153,13 +166,25 @@ void Hyd_Coupling_FP2FP::clone_couplings(Hyd_Coupling_FP2FP *coupling, Hyd_Hydra
153166
//Reset counter limiter
154167
void Hyd_Coupling_FP2FP::reset_counter_limiter(void) {
155168
this->counter_limiter = 0;
169+
this->counter_tot_coupling_active = 0;
156170
}
157171
//Output number of limiter hits
158172
void Hyd_Coupling_FP2FP::output_number_limiter_hits(int* total, ostringstream* out) {
159-
*out << " Hits FP" <<this->floodplain_model_1->Param_FP.get_floodplain_number()<<" to FP"<< this->floodplain_model_2->Param_FP.get_floodplain_number()<<" :" << this->counter_limiter << endl;
173+
double perc = 0.0;
174+
if (this->counter_tot_coupling_active > 0) {
175+
perc = ((double)this->counter_limiter / (double)this->counter_tot_coupling_active) * 100.0;
176+
177+
}
178+
*out << " Hits FP" <<this->floodplain_model_1->Param_FP.get_floodplain_number()<<" to FP"<< this->floodplain_model_2->Param_FP.get_floodplain_number()<<" :" << this->counter_limiter <<" (active: "<< this->counter_tot_coupling_active<< P(1) << " "<< perc<<"%)"<< endl;
160179

161180
*total = *total + this->counter_limiter;
162181

182+
}
183+
//Get the minimal timestep for coupling
184+
double Hyd_Coupling_FP2FP::get_min_timestep(void) {
185+
186+
return this->list.get_min_timestep();
187+
163188
}
164189
//______________
165190
//private

source_code/system_hydraulic/source_code/models/coupling/Hyd_Coupling_FP2FP.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ class Hyd_Coupling_FP2FP
6161
///Output number of limiter hits
6262
void output_number_limiter_hits(int* total, ostringstream* out);
6363

64+
///Get the minimal timestep for coupling
65+
double get_min_timestep(void);
66+
6467

6568
private:
6669
//members
@@ -75,6 +78,13 @@ class Hyd_Coupling_FP2FP
7578
///Counter how often the limiter is reached
7679
int counter_limiter;
7780

81+
///Total counter how often a coupling is active
82+
int counter_tot_coupling_active;
83+
///Optimal timestep to avoid hitting limiter
84+
double timestep_opt_hit_limit;
85+
///Optimal timestep after Courant-criteria
86+
double timestep_opt_cor;
87+
7888
//methods
7989
///Set the defining polysegment with the boundary of the first floodplain model
8090
void set_defining_polysegment(void);

source_code/system_hydraulic/source_code/models/coupling/Hyd_Coupling_Management.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,6 +1411,24 @@ void Hyd_Coupling_Management::output_number_limiter_hits(void) {
14111411
}
14121412

14131413

1414+
}
1415+
///Get minimal timestep for FP2FP couplinbg
1416+
double Hyd_Coupling_Management::get_min_timestep_fp2fp(void) {
1417+
double min_t = 1000000000;
1418+
1419+
if (this->number_fp2fp > 0) {
1420+
1421+
1422+
1423+
for (int i = 0; i < this->number_fp2fp; i++) {
1424+
min_t = min(this->coupling_fp2fp[i].list.get_min_timestep(), min_t);
1425+
}
1426+
1427+
1428+
}
1429+
1430+
return min_t;
1431+
14141432
}
14151433
//__________________
14161434
//private

source_code/system_hydraulic/source_code/models/coupling/Hyd_Coupling_Management.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,9 @@ class Hyd_Coupling_Management : public _Sys_Common_System
246246
///Out number of limiter hits
247247
void output_number_limiter_hits(void);
248248

249+
///Get minimal timestep for FP2FP couplinbg
250+
double get_min_timestep_fp2fp(void);
251+
249252

250253
private:
251254

source_code/system_hydraulic/source_code/models/coupling/Hyd_Coupling_Point_FP2FP.cpp

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ void Hyd_Coupling_Point_FP2FP::reset_coupling_discharge(void){
194194
}
195195
}
196196
//Syncronisation of the coupled models with the couplingspoint
197-
void Hyd_Coupling_Point_FP2FP::syncronisation_coupled_models(const double timepoint, const double delta_t, const bool time_check, const int internal_counter, const double area_limiter, int *counter_limiter){
197+
void Hyd_Coupling_Point_FP2FP::syncronisation_coupled_models(const double timepoint, const double delta_t, const bool time_check, const int internal_counter, const double area_limiter, int *counter_limiter, int* counter_tot, double* opt_time_hit, double* opt_time_cor){
198198

199199
_Hyd_Coupling_Point::syncronisation_coupled_models();
200200
this->delta_t=delta_t;
@@ -326,24 +326,18 @@ void Hyd_Coupling_Point_FP2FP::syncronisation_coupled_models(const double timepo
326326
// this->q_list.smooth_discharge.append(this->current_q);
327327
//}
328328

329-
//calculate the flow-velocity
330-
if(flow_depth!=0.0){
331-
this->coupling_v=-1.0*this->current_q/(this->distance_down*flow_depth);
332-
}
333-
else{
334-
this->coupling_v=0.0;
335-
}
336329

337330

338331

339332

340-
//if (timepoint > 48600 && abs(this->current_q) > 0.0) {
333+
334+
//if (timepoint > 83000 && abs(this->current_q) > 0.0 && time_check==true) {
341335
// // // Daniel test alfnitz
342336
// ostringstream cout;
343337
// cout << "t " << timepoint << " fp_1_elem " << this->fp1_elem_index << " fp_2_elem " << this->fp2_elem_index ;
344338
// cout << " s_1 " << this->fp1_elem->get_z_value() + h_one_buff << " s_2 " << this->fp2_elem->get_z_value() + h_two_buff;
345339
// cout << " wd " << this->distance_down << " flow_h " << flow_depth;
346-
// cout << " cp_Q_buf " << q_buff << " cp_Q_s " << this->current_q<< " Q_max "<< max_Q;
340+
// cout << " cp_Q_buf " << q_buff << " cp_Q_s " << this->current_q;
347341
// if (abs(this->current_q) > 5) {
348342
// cout << "*";
349343
// }
@@ -362,20 +356,64 @@ void Hyd_Coupling_Point_FP2FP::syncronisation_coupled_models(const double timepo
362356

363357

364358
//Test a delimiter
359+
//Total overflow to total hits delimiter
360+
if (abs(this->current_q) > 0.0) {
361+
if (time_check == false) {
362+
(*counter_tot)++; //double* opt_time_cor
363+
}
364+
}
365+
365366
double max_Q = 0.0;
367+
//calculate the delimiter
366368
max_Q = (area_limiter* this->distance_down) / (4 * delta_t);
367369
if (max_Q < abs(this->current_q)) {
368370
if (time_check == false) {
369371
(*counter_limiter)++;
370372
}
371373
}
374+
//calculate optimal timestep for not hitting delimiter
375+
if (time_check == true) {
376+
if (max_Q < abs(this->current_q)) {
377+
378+
(*opt_time_hit) = (area_limiter * this->distance_down) / (4 * abs(this->current_q));
379+
}
380+
else {
381+
382+
(*opt_time_hit) = -1.0;
383+
}
384+
}
385+
//set the delimiter
372386
max_Q=min(abs(this->current_q), max_Q);
387+
373388
if (this->current_q < 0.0) {
374389
this->current_q = -1.0 * max_Q;
375390
}
376391
else {
377392
this->current_q = max_Q;
378393
}
394+
395+
396+
//calculate the flow-velocity
397+
if (flow_depth != 0.0) {
398+
this->coupling_v = -1.0 * this->current_q / (this->distance_down * flow_depth);
399+
}
400+
else {
401+
this->coupling_v = 0.0;
402+
}
403+
404+
//calculate optimal timestep with Courant-Criteria
405+
if (time_check == true) {
406+
double courant = 0.5;
407+
if (abs(this->coupling_v) > 0) {
408+
(*opt_time_cor) = (courant * this->flow_distance) / abs(this->coupling_v);
409+
410+
}
411+
else {
412+
(*opt_time_cor) = -1.0;
413+
414+
}
415+
416+
}
379417

380418

381419
this->calculate_maximum_values(timepoint, this->current_q, &this->max_coupling_v);

source_code/system_hydraulic/source_code/models/coupling/Hyd_Coupling_Point_FP2FP.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ friend class Hyd_Coupling_Point_FP2FP_List;
6060
///Reset the current coupling discharge of the points and the coupled element
6161
void reset_coupling_discharge(void);
6262
///Syncronisation of the coupled models with the couplingspoint
63-
void syncronisation_coupled_models(const double timepoint, const double delta_t, const bool time_check, const int internal_counter, const double area_limiter, int *counter_limiter);
63+
void syncronisation_coupled_models(const double timepoint, const double delta_t, const bool time_check, const int internal_counter, const double area_limiter, int *counter_limiter, int *counter_tot, double *opt_time_hit, double *opt_time_cor);
6464

6565
///Reset the smoothing calculation members
6666
void reset_smoothing(void);

source_code/system_hydraulic/source_code/models/coupling/Hyd_Coupling_Point_FP2FP_List.cpp

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
Hyd_Coupling_Point_FP2FP_List::Hyd_Coupling_Point_FP2FP_List(void){
66
this->number=0;
77
this->points=NULL;
8+
this->min_timestep = 0.0;
89

910
//count the memory
1011
Sys_Memory_Count::self()->add_mem(sizeof(Hyd_Coupling_Point_FP2FP_List), _sys_system_modules::HYD_SYS);
@@ -128,6 +129,7 @@ void Hyd_Coupling_Point_FP2FP_List::set_new_couplingpoint(Hyd_Coupling_Point_FP2
128129
void Hyd_Coupling_Point_FP2FP_List::delete_list(void){
129130
this->delete_couplingpoints();
130131
this->number=0;
132+
this->min_timestep = 0.0;
131133
}
132134
//Sort the points after the distance to the beginning of the defining polysegment
133135
void Hyd_Coupling_Point_FP2FP_List::sort_distance_along_polysegment(void){
@@ -260,12 +262,54 @@ void Hyd_Coupling_Point_FP2FP_List::reset_points(void){
260262
}
261263
}
262264
//Syncronisation of the coupled models with the stored couplingspoints in the list
263-
void Hyd_Coupling_Point_FP2FP_List::syncronisation_models_bylistpoints(const double timepoint, const double delta_t, const bool time_check, const int internal_counter, const double area_limiter, int *counter_limiter){
265+
void Hyd_Coupling_Point_FP2FP_List::syncronisation_models_bylistpoints(const double timepoint, const double delta_t, const bool time_check, const int internal_counter, const double area_limiter, int *counter_limiter, int* counter_tot, double* opt_time_hit, double* opt_time_cor){
266+
Sys_Median_Calculator by_hits;
267+
Sys_Median_Calculator by_cor;
268+
264269
for(int i=0; i<this->number;i++){
265270

266-
this->points[i].syncronisation_coupled_models(timepoint,delta_t, time_check, internal_counter, area_limiter, counter_limiter);
271+
this->points[i].syncronisation_coupled_models(timepoint,delta_t, time_check, internal_counter, area_limiter, counter_limiter, counter_tot,opt_time_hit, opt_time_cor);
272+
273+
//claculate the median of the timesteps
274+
if (time_check == true) {
275+
276+
if (*opt_time_hit > 0.0) {
277+
by_hits.add_value(*opt_time_hit);
278+
}
279+
280+
if (*opt_time_cor > 0.0) {
281+
by_cor.add_value(*opt_time_cor);
282+
//output
283+
/*ostringstream cout;
284+
cout << "t " << timepoint << " step " << delta_t << " opt_time " << (*opt_time_cor);
285+
cout << endl;
286+
Sys_Common_Output::output_hyd->output_txt(&cout, true);*/
287+
}
288+
289+
290+
291+
292+
293+
}
294+
267295

268296
}
297+
298+
if(time_check==true){
299+
//output
300+
//ostringstream cout;
301+
//cout << "t " << timepoint << " step " << delta_t<< " med_hit " << by_hits.get_median()<< " perc25_hit "<< by_hits.get_perc25();
302+
//cout << " med_cor " << by_cor.get_median() << " perc_25 " << by_cor.get_perc25() << " s";
303+
//cout << endl;
304+
//Sys_Common_Output::output_hyd->output_txt(&cout, true);
305+
306+
307+
//Make decision wich one courant crit or hit crit ...median, perc etc.
308+
this->min_timestep = by_cor.get_median();
309+
310+
}
311+
312+
269313
}
270314
//Clone the coupling point list
271315
void Hyd_Coupling_Point_FP2FP_List::clone_list(Hyd_Coupling_Point_FP2FP_List *list, Hyd_Model_Floodplain *fp1, Hyd_Model_Floodplain *fp2){
@@ -284,6 +328,10 @@ void Hyd_Coupling_Point_FP2FP_List::clone_list(Hyd_Coupling_Point_FP2FP_List *li
284328
this->points[i].set_second_fpelem_pointer(fp2->get_ptr_floodplain_elem(list->points[i].fp2_elem_index));
285329
}
286330
}
331+
//Get the minimal timestep
332+
double Hyd_Coupling_Point_FP2FP_List::get_min_timestep(void) {
333+
return this->min_timestep;
334+
}
287335
//Output the discharge list to file
288336
//void Hyd_Coupling_Point_FP2FP_List::output_discharge_lists(void){
289337
// for(int i=0; i< this->number; i++){

source_code/system_hydraulic/source_code/models/coupling/Hyd_Coupling_Point_FP2FP_List.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,25 @@ class Hyd_Coupling_Point_FP2FP_List : public _Hyd_Coupling_Point_List
7272
void reset_points(void);
7373

7474
///Syncronisation of the coupled models with the stored couplingspoints in the list
75-
void syncronisation_models_bylistpoints(const double timepoint, const double delta_t, const bool time_check, const int internal_counter, const double area_limiter, int *counter_limiter);
75+
void syncronisation_models_bylistpoints(const double timepoint, const double delta_t, const bool time_check, const int internal_counter, const double area_limiter, int *counter_limiter, int* counter_tot, double* opt_time_hit, double* opt_time_cor);
7676

7777
///Clone the coupling point list
7878
void clone_list(Hyd_Coupling_Point_FP2FP_List *list, Hyd_Model_Floodplain *fp1, Hyd_Model_Floodplain *fp2);
7979

8080
//Output the discharge list to file (just for testing)
8181
//void output_discharge_lists(void);
8282

83+
///Get the minimal timestep
84+
double get_min_timestep(void);
85+
8386

8487
private:
8588

8689
//members
8790
///Coupling points in list
8891
Hyd_Coupling_Point_FP2FP *points;
92+
///Minimal timestep
93+
double min_timestep;
8994

9095

9196
//methods

source_code/system_hydraulic/source_code/models/floodplain/Hyd_Model_Floodplain.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,6 +1186,16 @@ void Hyd_Model_Floodplain::make_hyd_balance_max(const double time_point){
11861186
for(int i=0; i< this->number_coup_cond; i++){
11871187
this->floodplain_elems[this->coup_cond_id[i]].element_type->calculate_hydrolocigal_balance_coupling(delta_t);
11881188
}
1189+
1190+
if (this->Param_FP.get_scheme_info().scheme_type != model::schemeTypes::kDiffusiveCPU) {
1191+
//check balanc deficit in gpu modells
1192+
1193+
1194+
this->error_zero_outflow_volume= this->pManager->getDomain()->getScheme()->get_bilan_deficit()*-1.0;
1195+
1196+
}
1197+
1198+
11891199
}
11901200
//Reset the solver of the model
11911201
void Hyd_Model_Floodplain::reset_solver(void){

source_code/system_hydraulic/source_code/models/floodplain/Hyd_Parse_FP.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,17 @@ void Hyd_Parse_FP::parse_general(_hyd_keyword_file Key, word Command){
176176
}
177177
else if (Key == eANGLE){
178178
buffer>>this->fp_params.angle;
179+
180+
if (this->fp_params.angle >= 90.0 - constant::angle_epsilon && this->fp_params.angle <= 90.0 + constant::angle_epsilon) {
181+
182+
this->fp_params.angle = this->fp_params.angle - constant::angle_epsilon*10;
183+
}
184+
if (this->fp_params.angle >= -90.0 - constant::angle_epsilon && this->fp_params.angle <= -90.0 + constant::angle_epsilon) {
185+
186+
this->fp_params.angle = this->fp_params.angle + constant::angle_epsilon*10;
187+
}
188+
189+
179190
this->found_angle=true;
180191
}
181192
else if (Key == eLOWLEFTX){

0 commit comments

Comments
 (0)