22 if (!
impl.hasTimeWindowSize() || !expl.hasTimeWindowSize()) {
25 double idt =
impl.getTimeWindowSize();
26 double edt = expl.getTimeWindowSize();
34 if (compatibleTimeWindowSizes(
impl, expl)) {
39 auto implPartners =
impl.getCouplingPartners();
41 double idt =
impl.getTimeWindowSize();
44 "The participant {} is implicitly coupled to {} with time-window-size {} and explicitly coupled to {} with time-window-size {}, which isn't well-defined. "
45 "Explicit time windows should be aligned with implicit time windows. "
46 "Choose time window sizes so that the explicit (currently {}) is an integer multiple of the implicit (currently {}).",
47 local, implPartners.front(), idt, explPartners.front(), edt,
55 if (!couplingScheme->isImplicitCouplingScheme()) {
109 auto explicitAtWindowEnd =
false;
111 explicitAtWindowEnd |= scheme->addComputedTime(timeToAdd);
113 return explicitAtWindowEnd;
117 auto implicitAtWindowEnd =
_implicitScheme->addComputedTime(timeToAdd);
123 return implicitAtWindowEnd;
127 auto explicitAtWindowEnd =
false;
129 explicitAtWindowEnd |= scheme->addComputedTime(timeToAdd);
132 if (implicitAtWindowEnd) {
133 PRECICE_DEBUG(
"Implicit scheme reached the end of the first iteration at t={}. "
134 "Explicit schemes are on hold until convergence achieved.",
141 return implicitAtWindowEnd || explicitAtWindowEnd;
151 auto remoteChanges = scheme->firstSynchronization(changes);
152 totalChanges.
insert(totalChanges.
end(), remoteChanges.begin(), remoteChanges.end());
163 scheme->firstExchange();
176 scheme->firstExchange();
186 auto remoteChanges = scheme->secondSynchronization();
187 totalChanges.
insert(totalChanges.
end(), remoteChanges.begin(), remoteChanges.end());
198 scheme->secondExchange();
208 bool iterating = implicitTime < explicitTime;
211 PRECICE_DEBUG(
"Implicit scheme hasn't converged. Explicit schemes remain on hold.");
215 PRECICE_DEBUG(
"Implicit scheme converged. Running explicit schemes.");
218 scheme->firstExchange();
221 scheme->secondSynchronization();
224 scheme->secondExchange();
226 PRECICE_DEBUG(
"Explicit schemes caught up. All schemes are in sync.");
245 auto subpartners = scheme->getCouplingPartners();
246 partners.
insert(partners.
end(), subpartners.begin(), subpartners.end());
263 bool willBeExchanged =
std::any_of(schemes.begin(), schemes.end(),
264 [lastSolverTimeStepSize](
const auto &cpl) { return cpl->willDataBeExchanged(lastSolverTimeStepSize); });
266 return willBeExchanged;
276 return hasBeenReceived;
297 schemes.begin(), schemes.end(),
299 [](
double a,
double b) { return std::min(a, b); },
309 schemes.begin(), schemes.end(),
311 [](
int a,
int b) { return std::min(a, b); },
353 [](
double a,
double b) { return std::min(a, b); },
377 return isOneCompleted;
384 bool isRequired =
false;
387 if (scheme->isActionRequired(
action)) {
400 bool isFulfilled =
false;
402 if (scheme->isActionFulfilled(
action)) {
416 if (scheme->isActionRequired(
action)) {
417 scheme->markActionFulfilled(
action);
435 if (not state.
empty()) {
438 partners = scheme->getCouplingPartners();
439 state += partners[0];
441 state += scheme->printCouplingState();
504 if (scheme->requiresSubsteps()) {
#define PRECICE_WARN(...)
#define PRECICE_DEBUG(...)
#define PRECICE_TRACE(...)
#define PRECICE_ASSERT(...)
#define PRECICE_UNREACHABLE(...)
PtrCouplingScheme _implicitScheme
The optional implicit scheme to be handled last.
ChangedMeshes secondSynchronization() override
bool sendsInitializedData() const final override
Returns true, if any of the composed coupling schemes sendsInitializedData for this participant.
std::vector< CouplingScheme * > activeOrAllSchemes() const
Actions also work before initialize is called.
bool isTimeWindowComplete() const final override
Returns true, when the accessor can advance to the next time window.
std::vector< CouplingScheme * > allSchemes() const
Returns all schemes in execution order, explicit as well as implicit.
void updateActiveSchemes()
std::string localParticipant() const final override
Returns the name of the local participant.
void finalize() final override
Finalizes the coupling and disconnects communication.
ImplicitData implicitDataToReceive() const final override
Returns a vector of implicit data to receive in the next advance.
std::vector< CouplingScheme * > _activeSchemes
bool isCouplingOngoing() const final override
Returns true, when the coupled simulation is still ongoing.
double getTime() const final override
Returns the currently computed time of the coupling scheme.
std::vector< std::string > getCouplingPartners() const final override
Returns list of all coupling partners.
void initialize() final override
Initializes the coupling scheme and establishes a communication connection to the coupling partner.
Schemes _explicitSchemes
Explicit coupling schemes to be executed.
bool isImplicitCouplingScheme() const final override
True if one cplscheme is an implicit scheme.
double getTimeWindowSize() const final override
Returns the time window size, if one is given by the coupling scheme.
void secondExchange() override
bool requiresSubsteps() const final override
Returns true if any send data of the scheme requires substeps.
bool isActionRequired(Action action) const final override
Returns true, if the given action has to be performed by the accessor.
void markActionFulfilled(Action action) final override
Tells the coupling scheme that the accessor has performed the given action.
bool addComputedTime(double timeToAdd) final override
Adds newly computed time. Has to be called before every advance.
bool hasDataBeenReceived() const final override
checks all coupling schemes this coupling scheme is composed of.
bool hasConverged() const final override
True if the implicit scheme has converged or no implicit scheme is defined.
int getTimeWindows() const final override
Returns the currently computed time windows of the coupling scheme.
void requireAction(Action action) final override
Sets an action required to be performed by the accessor.
bool isInitialized() const final override
Returns true, if initialize has been called.
bool _explicitOnHold
Are explicit schemes on hold?
double getNextTimeStepMaxSize() const final override
Returns the maximal size of the next time step to be computed.
bool hasTimeWindowSize() const final override
Returns true, if time window size is given by any of the coupling schemes in this compositional coupl...
void addCouplingScheme(const PtrCouplingScheme &scheme)
Adds another coupling scheme in parallel to this scheme.
void firstExchange() override
ChangedMeshes firstSynchronization(const ChangedMeshes &changes) override
Exchanges data and updates the state of the coupling scheme.
bool willDataBeExchanged(double lastSolverTimeStepSize) const final override
Returns true, if data will be exchanged when calling advance().
void checkCompatibleTimeWindowSizes(const CouplingScheme &impl, const CouplingScheme &expl) const
check if time windows are compatible
void reinitialize() final override
Reinitializes the coupling scheme, coupling data, and acceleration schemes.
std::string printCouplingState() const final override
Returns a string representation of the current coupling state.
double getTimeWindowStart() const final override
bool isActionFulfilled(Action action) const final override
Returns true, if the given action has been performed by the accessor.
Interface for all coupling schemes.
std::vector< MeshID > ChangedMeshes
Action
Actions that are required by CouplingSchemes.
virtual std::vector< std::string > getCouplingPartners() const =0
Returns list of all coupling partners.
virtual double getTimeWindowStart() const =0
virtual bool isInitialized() const =0
Returns true, if initialize has been called.
virtual double getNextTimeStepMaxSize() const =0
Returns the maximal size of the next time step to be computed.
virtual bool isTimeWindowComplete() const =0
Returns true, when the accessor can advance to the next time window.
virtual double getTimeWindowSize() const =0
Returns the time window size, if one is given by the coupling scheme.
virtual bool sendsInitializedData() const =0
Returns whether this participant of the coupling scheme sends initialized data.
virtual int getTimeWindows() const =0
Returns the currently computed time windows of the coupling scheme.
virtual bool hasDataBeenReceived() const =0
Returns true, if data has been exchanged in last call of advance().
virtual std::string localParticipant() const =0
Returns the name of the local participant.
CouplingScheme get(CouplingScheme... args)
contains actions to modify exchanged data.
contains implementations of coupling schemes for coupled simulations.
std::shared_ptr< CouplingScheme > PtrCouplingScheme
constexpr bool equals(const Eigen::MatrixBase< DerivedA > &A, const Eigen::MatrixBase< DerivedB > &B, double tolerance=NUMERICAL_ZERO_DIFFERENCE)
Compares two Eigen::MatrixBase for equality up to tolerance.