Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 539a096

Browse files
committedFeb 25, 2025·
output
1 parent 70ba141 commit 539a096

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
 

‎opm/simulators/wells/WellState.cpp

+60
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,7 @@ void WellState<Scalar>::initWellStateMSWell(const std::vector<Well>& wells_ecl,
684684
// we need to know for each segment, how many perforation it has and how many segments using it as outlet_segment
685685
// that is why I think we should use a well model to initialize the WellState here
686686
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;
687688
std::unordered_map<int,int> active_perf_index_local_to_global = {};
688689
for (std::size_t perf = 0; perf < completion_set.size(); ++perf) {
689690
if (ws.parallel_info.get().globalToLocal(perf) == 0) {
@@ -692,6 +693,7 @@ void WellState<Scalar>::initWellStateMSWell(const std::vector<Well>& wells_ecl,
692693
}
693694
const Connection& connection = completion_set.get(perf);
694695
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;
695697
const int segment_index = segment_set.segmentNumberToIndex(connection.segment());
696698
if (segment_index == -1) {
697699
OPM_THROW(std::logic_error,
@@ -707,12 +709,15 @@ void WellState<Scalar>::initWellStateMSWell(const std::vector<Well>& wells_ecl,
707709
}
708710
n_activeperf++;
709711
n_activeperf_local++;
712+
} else {
713+
std::cout << "no activeperf, perf = " << perf << ", local = " << ws.parallel_info.get().globalToLocal(perf) << std::endl;
710714
}
711715
}
712716

713717
if (!this->enableDistributedWells_ && static_cast<int>(ws.perf_data.size()) != n_activeperf)
714718
throw std::logic_error("Distributed multi-segment wells cannot be initialized properly yet.");
715719

720+
std::cout << "(should be the same?) n_activeperf: " << n_activeperf << std::endl;
716721

717722
std::vector<std::vector<int>> segment_inlets(well_nseg);
718723
for (int seg = 0; seg < well_nseg; ++seg) {
@@ -725,10 +730,20 @@ void WellState<Scalar>::initWellStateMSWell(const std::vector<Well>& wells_ecl,
725730
segment_inlets[outlet_segment_index].push_back(segment_index);
726731
}
727732
}
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+
}
728741

729742
auto& perf_data = ws.perf_data;
743+
std::cout << "in the loop for gas" << std::endl;
730744
// for the seg_rates_, now it becomes a recursive solution procedure.
731745
if (pu.phase_used[Gas]) {
746+
std::cout << "in the loop for gas" << std::endl;
732747
auto& perf_rates = perf_data.phase_rates;
733748
const int gaspos = pu.phase_pos[Gas];
734749
// 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,
740755
perf_rates[perf*np + gaspos] *= 100;
741756
}
742757

758+
std::cout << "perf_data.size() = " << perf_data.size() << std::endl;
759+
std::cout << "np = " << np << std::endl;
743760
const auto& perf_rates = perf_data.phase_rates;
744761
const auto& perf_press = perf_data.pressure;
745762
// The function calculateSegmentRates as well as the loop filling the segment_pressure work
746763
// with *global* containers. Now we create global vectors containing the phase_rates and
747764
// 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;
748767
size_t number_of_global_perfs = 0;
749768

750769
if (ws.parallel_info.get().communication().size() > 1) {
@@ -755,24 +774,44 @@ void WellState<Scalar>::initWellStateMSWell(const std::vector<Well>& wells_ecl,
755774

756775
std::vector<Scalar> perforation_rates(number_of_global_perfs * np, 0.0);
757776
std::vector<Scalar> perforation_pressures(number_of_global_perfs, 0.0);
777+
std::cout << "After communication: perforation_rates.size() = " << perforation_rates.size() << std::endl;
758778

759779
assert(perf_data.size() == perf_press.size());
760780
assert(perf_data.size() * np == perf_rates.size());
761781
for (size_t perf = 0; perf < perf_data.size(); ++perf) {
782+
std::cout << "looping over perf_data.size(), perf = " << perf;
762783
if (active_perf_index_local_to_global.count(perf) > 0) {
763784
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];
764787
for (int i = 0; i < np; i++) {
765788
perforation_rates[global_active_perf_index * np + i] = perf_rates[perf * np + i];
766789
}
767790
} else {
791+
std::cout << std::endl;
768792
OPM_THROW(std::logic_error,fmt::format("Error when initializing MS Well state, there is no active perforation index for the local index {}", perf));
769793
}
770794
}
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+
771803
if (ws.parallel_info.get().communication().size() > 1) {
772804
ws.parallel_info.get().communication().sum(perforation_rates.data(), perforation_rates.size());
773805
ws.parallel_info.get().communication().sum(perforation_pressures.data(), perforation_pressures.size());
774806
}
775807

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+
776815
calculateSegmentRates(ws.parallel_info, segment_inlets, segment_perforations, perforation_rates, np, 0 /* top segment */, ws.segments.rates);
777816

778817
// 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,
784823
// top segment is always the first one, and its pressure is the well bhp
785824
auto& segment_pressure = ws.segments.pressure;
786825
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+
787831
// The segment_indices contain the indices of the segments, that are only available on one process.
788832
std::vector<int> segment_indices;
789833
for (int seg = 1; seg < well_nseg; ++seg) {
790834
if (!segment_perforations[seg].empty()) {
791835
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;
792837
segment_pressure[seg] = perforation_pressures[first_perf_global_index];
793838
segment_indices.push_back(seg);
794839
} else {
@@ -839,6 +884,7 @@ calculateSegmentRatesBeforeSum(const ParallelWellInfo<Scalar>& pw_info,
839884
const int np, const int segment,
840885
std::vector<Scalar>& segment_rates)
841886
{
887+
std::cout << "calculateSegmentRatesBeforeSum for the segment " << segment << std::endl;
842888
// the rate of the segment equals to the sum of the contribution from the perforations and inlet segment rates.
843889
// the first segment is always the top segment, its rates should be equal to the well rates.
844890
assert(segment_inlets.size() == segment_perforations.size());
@@ -847,19 +893,30 @@ calculateSegmentRatesBeforeSum(const ParallelWellInfo<Scalar>& pw_info,
847893
segment_rates.resize(np * well_nseg, 0.0);
848894
}
849895
// contributions from the perforations belong to this segment
896+
std::cout << "Will now look at the perforations of segment " << segment << std::endl;
850897
for (const int& perf : segment_perforations[segment]) {
851898
auto local_perf = pw_info.globalToLocal(perf);
899+
std::cout << "perf = " << perf << ", local_perf = " << local_perf << std::endl;
852900
// If local_perf == -1, then the perforation is not on this process.
853901
// The perforation of the other processes are added in calculateSegmentRates.
854902
if (local_perf > -1) {
903+
std::cout << "segment_rates.size() = " << segment_rates.size() << ", perforation_rates.size() = " << perforation_rates.size() << std::endl;
855904
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;
856906
segment_rates[np * segment + p] += perforation_rates[np * local_perf + p];
857907
}
858908
}
859909
}
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;
860914
for (const int& inlet_seg : segment_inlets[segment]) {
915+
std::cout << "Now call calculateSegmentRatesBeforeSum for the inlet_seg " << inlet_seg << std::endl;
861916
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;
862918
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;
863920
segment_rates[np * segment + p] += segment_rates[np * inlet_seg + p];
864921
}
865922
}
@@ -873,6 +930,9 @@ calculateSegmentRates(const ParallelWellInfo<Scalar>& pw_info,
873930
const int np, const int segment,
874931
std::vector<Scalar>& segment_rates)
875932
{
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;
876936
calculateSegmentRatesBeforeSum(pw_info, segment_inlets, segment_perforations, perforation_rates, np, segment, segment_rates);
877937
pw_info.communication().sum(segment_rates.data(), segment_rates.size());
878938
}

0 commit comments

Comments
 (0)
Please sign in to comment.