@@ -684,6 +684,7 @@ void WellState<Scalar>::initWellStateMSWell(const std::vector<Well>& wells_ecl,
684
684
// we need to know for each segment, how many perforation it has and how many segments using it as outlet_segment
685
685
// that is why I think we should use a well model to initialize the WellState here
686
686
std::vector<std::vector<int >> segment_perforations (well_nseg);
687
+ std::cout << " Will now loop over perforations, from 0 to " << completion_set.size () << std::endl;
687
688
std::unordered_map<int ,int > active_perf_index_local_to_global = {};
688
689
for (std::size_t perf = 0 ; perf < completion_set.size (); ++perf) {
689
690
if (ws.parallel_info .get ().globalToLocal (perf) == 0 ) {
@@ -692,6 +693,7 @@ void WellState<Scalar>::initWellStateMSWell(const std::vector<Well>& wells_ecl,
692
693
}
693
694
const Connection& connection = completion_set.get (perf);
694
695
if (connection.state () == Connection::State::OPEN) {
696
+ std::cout << " activeperf_global = " << n_activeperf << " , activeperf_local = " << n_activeperf_local << " , perf_global = " << perf << " , perf_local = " << ws.parallel_info .get ().globalToLocal (perf) << std::endl;
695
697
const int segment_index = segment_set.segmentNumberToIndex (connection.segment ());
696
698
if (segment_index == -1 ) {
697
699
OPM_THROW (std::logic_error,
@@ -707,12 +709,15 @@ void WellState<Scalar>::initWellStateMSWell(const std::vector<Well>& wells_ecl,
707
709
}
708
710
n_activeperf++;
709
711
n_activeperf_local++;
712
+ } else {
713
+ std::cout << " no activeperf, perf = " << perf << " , local = " << ws.parallel_info .get ().globalToLocal (perf) << std::endl;
710
714
}
711
715
}
712
716
713
717
if (!this ->enableDistributedWells_ && static_cast <int >(ws.perf_data .size ()) != n_activeperf)
714
718
throw std::logic_error (" Distributed multi-segment wells cannot be initialized properly yet." );
715
719
720
+ std::cout << " (should be the same?) n_activeperf: " << n_activeperf << std::endl;
716
721
717
722
std::vector<std::vector<int >> segment_inlets (well_nseg);
718
723
for (int seg = 0 ; seg < well_nseg; ++seg) {
@@ -725,10 +730,20 @@ void WellState<Scalar>::initWellStateMSWell(const std::vector<Well>& wells_ecl,
725
730
segment_inlets[outlet_segment_index].push_back (segment_index);
726
731
}
727
732
}
733
+ std::cout << " Now: segment_inlets (of size " << well_nseg << " ): " << std::endl;
734
+ for (size_t i = 0 ; i < segment_inlets.size (); ++i) {
735
+ std::cout << " segment_inlets[" << i << " ]: " ;
736
+ for (int inlet : segment_inlets[i]) {
737
+ std::cout << inlet << " , " ;
738
+ }
739
+ std::cout << std::endl;
740
+ }
728
741
729
742
auto & perf_data = ws.perf_data ;
743
+ std::cout << " in the loop for gas" << std::endl;
730
744
// for the seg_rates_, now it becomes a recursive solution procedure.
731
745
if (pu.phase_used [Gas]) {
746
+ std::cout << " in the loop for gas" << std::endl;
732
747
auto & perf_rates = perf_data.phase_rates ;
733
748
const int gaspos = pu.phase_pos [Gas];
734
749
// scale the phase rates for Gas to avoid too bad initial guess for gas fraction
@@ -740,11 +755,15 @@ void WellState<Scalar>::initWellStateMSWell(const std::vector<Well>& wells_ecl,
740
755
perf_rates[perf*np + gaspos] *= 100 ;
741
756
}
742
757
758
+ std::cout << " perf_data.size() = " << perf_data.size () << std::endl;
759
+ std::cout << " np = " << np << std::endl;
743
760
const auto & perf_rates = perf_data.phase_rates ;
744
761
const auto & perf_press = perf_data.pressure ;
745
762
// The function calculateSegmentRates as well as the loop filling the segment_pressure work
746
763
// with *global* containers. Now we create global vectors containing the phase_rates and
747
764
// pressures of all processes.
765
+ std::cout << " perf_rates.size() = " << perf_rates.size () << std::endl;
766
+ std::cout << " perf_press.size() = " << perf_press.size () << std::endl;
748
767
size_t number_of_global_perfs = 0 ;
749
768
750
769
if (ws.parallel_info .get ().communication ().size () > 1 ) {
@@ -755,24 +774,44 @@ void WellState<Scalar>::initWellStateMSWell(const std::vector<Well>& wells_ecl,
755
774
756
775
std::vector<Scalar> perforation_rates (number_of_global_perfs * np, 0.0 );
757
776
std::vector<Scalar> perforation_pressures (number_of_global_perfs, 0.0 );
777
+ std::cout << " After communication: perforation_rates.size() = " << perforation_rates.size () << std::endl;
758
778
759
779
assert (perf_data.size () == perf_press.size ());
760
780
assert (perf_data.size () * np == perf_rates.size ());
761
781
for (size_t perf = 0 ; perf < perf_data.size (); ++perf) {
782
+ std::cout << " looping over perf_data.size(), perf = " << perf;
762
783
if (active_perf_index_local_to_global.count (perf) > 0 ) {
763
784
const int global_active_perf_index = active_perf_index_local_to_global.at (perf);
785
+ std::cout << " , global_active_perf_index = " << global_active_perf_index << std::endl;
786
+ perforation_pressures[global_active_perf_index] = perf_press[perf];
764
787
for (int i = 0 ; i < np; i++) {
765
788
perforation_rates[global_active_perf_index * np + i] = perf_rates[perf * np + i];
766
789
}
767
790
} else {
791
+ std::cout << std::endl;
768
792
OPM_THROW (std::logic_error,fmt::format (" Error when initializing MS Well state, there is no active perforation index for the local index {}" , perf));
769
793
}
770
794
}
795
+
796
+ std::cout << " Before communication: calculateSegmentRates: perforation_rates.size() " << perforation_rates.size () << " , and the content:" << std::endl;
797
+ std::for_each (perforation_rates.begin (), perforation_rates.end (), [](const auto & entry) {std::cout << entry << " , " ;});
798
+ std::cout << std::endl;
799
+ std::cout << " Before communication: calculateSegmentRates: perforation_pressures.size() " << perforation_pressures.size () << " , and the content:" << std::endl;
800
+ std::for_each (perforation_pressures.begin (), perforation_pressures.end (), [](const auto & entry) {std::cout << entry << " , " ;});
801
+ std::cout << std::endl;
802
+
771
803
if (ws.parallel_info .get ().communication ().size () > 1 ) {
772
804
ws.parallel_info .get ().communication ().sum (perforation_rates.data (), perforation_rates.size ());
773
805
ws.parallel_info .get ().communication ().sum (perforation_pressures.data (), perforation_pressures.size ());
774
806
}
775
807
808
+ std::cout << " After communication: calculateSegmentRates: perforation_rates.size() " << perforation_rates.size () << " , and the content:" << std::endl;
809
+ std::for_each (perforation_rates.begin (), perforation_rates.end (), [](const auto & entry) {std::cout << entry << " , " ;});
810
+ std::cout << std::endl;
811
+ std::cout << " After communication: calculateSegmentRates: perforation_pressures.size() " << perforation_pressures.size () << " , and the content:" << std::endl;
812
+ std::for_each (perforation_pressures.begin (), perforation_pressures.end (), [](const auto & entry) {std::cout << entry << " , " ;});
813
+ std::cout << std::endl;
814
+
776
815
calculateSegmentRates (ws.parallel_info , segment_inlets, segment_perforations, perforation_rates, np, 0 /* top segment */ , ws.segments .rates );
777
816
778
817
// for the segment pressure, the segment pressure is the same with the first perforation belongs to the segment
@@ -784,11 +823,17 @@ void WellState<Scalar>::initWellStateMSWell(const std::vector<Well>& wells_ecl,
784
823
// top segment is always the first one, and its pressure is the well bhp
785
824
auto & segment_pressure = ws.segments .pressure ;
786
825
segment_pressure[0 ] = ws.bhp ;
826
+ std::cout << " segment_pressure.size() " << segment_pressure.size () << std::endl;
827
+ std::cout << " perf_press.size() " << perforation_pressures.size () << " , perforation_pressures:" << std::endl;
828
+ std::for_each (perforation_pressures.begin (), perforation_pressures.end (), [](const auto & entry) {std::cout << entry << " , " ;});
829
+ std::cout << std::endl;
830
+
787
831
// The segment_indices contain the indices of the segments, that are only available on one process.
788
832
std::vector<int > segment_indices;
789
833
for (int seg = 1 ; seg < well_nseg; ++seg) {
790
834
if (!segment_perforations[seg].empty ()) {
791
835
const int first_perf_global_index = segment_perforations[seg][0 ];
836
+ std::cout << " first perf of segment " << seg << " seg: " << first_perf_global_index << std::endl;
792
837
segment_pressure[seg] = perforation_pressures[first_perf_global_index];
793
838
segment_indices.push_back (seg);
794
839
} else {
@@ -839,6 +884,7 @@ calculateSegmentRatesBeforeSum(const ParallelWellInfo<Scalar>& pw_info,
839
884
const int np, const int segment,
840
885
std::vector<Scalar>& segment_rates)
841
886
{
887
+ std::cout << " calculateSegmentRatesBeforeSum for the segment " << segment << std::endl;
842
888
// the rate of the segment equals to the sum of the contribution from the perforations and inlet segment rates.
843
889
// the first segment is always the top segment, its rates should be equal to the well rates.
844
890
assert (segment_inlets.size () == segment_perforations.size ());
@@ -847,19 +893,30 @@ calculateSegmentRatesBeforeSum(const ParallelWellInfo<Scalar>& pw_info,
847
893
segment_rates.resize (np * well_nseg, 0.0 );
848
894
}
849
895
// contributions from the perforations belong to this segment
896
+ std::cout << " Will now look at the perforations of segment " << segment << std::endl;
850
897
for (const int & perf : segment_perforations[segment]) {
851
898
auto local_perf = pw_info.globalToLocal (perf);
899
+ std::cout << " perf = " << perf << " , local_perf = " << local_perf << std::endl;
852
900
// If local_perf == -1, then the perforation is not on this process.
853
901
// The perforation of the other processes are added in calculateSegmentRates.
854
902
if (local_perf > -1 ) {
903
+ std::cout << " segment_rates.size() = " << segment_rates.size () << " , perforation_rates.size() = " << perforation_rates.size () << std::endl;
855
904
for (int p = 0 ; p < np; ++p) {
905
+ std::cout << " will access segment_rates[" << np * segment + p << " ] and perforation_rates[" << np * local_perf + p << " ]" << std::endl;
856
906
segment_rates[np * segment + p] += perforation_rates[np * local_perf + p];
857
907
}
858
908
}
859
909
}
910
+ std::cout << " Will now loop over the inlet_segs of segment " << segment << std::endl;
911
+ std::cout << " The inlet segs are: " ;
912
+ std::for_each (segment_inlets[segment].begin (), segment_inlets[segment].end (), [](const auto & entry) {std::cout << entry << " , " ;});
913
+ std::cout << std::endl;
860
914
for (const int & inlet_seg : segment_inlets[segment]) {
915
+ std::cout << " Now call calculateSegmentRatesBeforeSum for the inlet_seg " << inlet_seg << std::endl;
861
916
calculateSegmentRatesBeforeSum (pw_info, segment_inlets, segment_perforations, perforation_rates, np, inlet_seg, segment_rates);
917
+ std::cout << " segment_rates.size() = " << segment_rates.size () << std::endl;
862
918
for (int p = 0 ; p < np; ++p) {
919
+ std::cout << " will access segment_rates[" << np * segment + p << " ] and segment_rates[" << np * inlet_seg + p << " ]" << std::endl;
863
920
segment_rates[np * segment + p] += segment_rates[np * inlet_seg + p];
864
921
}
865
922
}
@@ -873,6 +930,9 @@ calculateSegmentRates(const ParallelWellInfo<Scalar>& pw_info,
873
930
const int np, const int segment,
874
931
std::vector<Scalar>& segment_rates)
875
932
{
933
+ std::cout << " calculateSegmentRates called, segment = " << segment << std::endl;
934
+ std::cout << " segment_perforations.size() = " << segment_perforations.size () << std::endl;
935
+ std::cout << " (should be the same across all proceses:) segment_rates.size() = " << segment_rates.size () << std::endl;
876
936
calculateSegmentRatesBeforeSum (pw_info, segment_inlets, segment_perforations, perforation_rates, np, segment, segment_rates);
877
937
pw_info.communication ().sum (segment_rates.data (), segment_rates.size ());
878
938
}
0 commit comments