Skip to content

Commit 7eb2983

Browse files
committed
Implement the debugging versions of all the overloads of the integrate function
1 parent affa5ee commit 7eb2983

2 files changed

Lines changed: 259 additions & 2 deletions

File tree

include/MGIS/Behaviour/Integrate.hxx

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,19 @@ namespace mgis::behaviour {
285285
* must be computed.
286286
*/
287287
int integrate(BehaviourDataView&, const Behaviour&);
288+
/*!
289+
* \brief integrate the behaviour. In case of non convergence, an
290+
* mtest file is generated.
291+
*
292+
* The returned value has the following meaning:
293+
* - -1: integration failed
294+
* - 0: integration succeeded but results are unreliable
295+
* - 1: integration succeeded and results are reliable
296+
*
297+
* \param[in,out] d: behaviour data
298+
* \param[in,out] b: behaviour
299+
*/
300+
MGIS_EXPORT int integrate_debug(BehaviourDataView&, const Behaviour&);
288301
/*!
289302
* \brief integrate the behaviour. In case of non convergence, an
290303
* mtest file is generated.
@@ -300,8 +313,7 @@ namespace mgis::behaviour {
300313
MGIS_EXPORT int integrate_debug(
301314
BehaviourDataView&,
302315
const Behaviour&,
303-
const debug::BehaviourIntegrationFailureAnalyser& =
304-
debug::getDefaultBehaviourIntegrationFailureAnalyser());
316+
const debug::BehaviourIntegrationFailureAnalyser&);
305317
/*!
306318
* \brief integrate the behaviour for a range of integration points.
307319
* \return the result of the behaviour integration.
@@ -314,6 +326,15 @@ namespace mgis::behaviour {
314326
*/
315327
MGIS_EXPORT BehaviourIntegrationResult integrate(
316328
MaterialDataManager&, const BehaviourIntegrationOptions&, const real);
329+
//! \brief debugging version
330+
MGIS_EXPORT BehaviourIntegrationResult integrate_debug(
331+
MaterialDataManager&, const BehaviourIntegrationOptions&, const real);
332+
//! \brief debugging version
333+
MGIS_EXPORT BehaviourIntegrationResult
334+
integrate_debug(MaterialDataManager&,
335+
const BehaviourIntegrationOptions&,
336+
const real,
337+
const debug::BehaviourIntegrationFailureAnalyser&);
317338
/*!
318339
* \brief integrate the behaviour for a range of integration points.
319340
* \return the result of the behaviour integration.
@@ -332,6 +353,21 @@ namespace mgis::behaviour {
332353
const real,
333354
const size_type,
334355
const size_type);
356+
//! \brief debugging version
357+
MGIS_EXPORT BehaviourIntegrationResult
358+
integrate_debug(MaterialDataManager&,
359+
const BehaviourIntegrationOptions&,
360+
const real,
361+
const size_type,
362+
const size_type);
363+
//! \brief debugging version
364+
MGIS_EXPORT BehaviourIntegrationResult
365+
integrate_debug(MaterialDataManager&,
366+
const BehaviourIntegrationOptions&,
367+
const real,
368+
const size_type,
369+
const size_type,
370+
const debug::BehaviourIntegrationFailureAnalyser&);
335371
/*!
336372
* \brief integrate the behaviour over all integration points using a thread
337373
* pool to parallelize the integration.
@@ -349,6 +385,19 @@ namespace mgis::behaviour {
349385
MaterialDataManager&,
350386
const BehaviourIntegrationOptions&,
351387
const real);
388+
//! \brief debugging version
389+
MGIS_EXPORT MultiThreadedBehaviourIntegrationResult
390+
integrate_debug(mgis::ThreadPool&,
391+
MaterialDataManager&,
392+
const BehaviourIntegrationOptions&,
393+
const real);
394+
//! \brief debugging version
395+
MGIS_EXPORT MultiThreadedBehaviourIntegrationResult
396+
integrate_debug(mgis::ThreadPool&,
397+
MaterialDataManager&,
398+
const BehaviourIntegrationOptions&,
399+
const real,
400+
const debug::BehaviourIntegrationFailureAnalyser&);
352401
/*!
353402
* \brief integrate the behaviour for a range of integration points.
354403
* \return an exit status. The returned value has the following meaning:
@@ -368,6 +417,18 @@ namespace mgis::behaviour {
368417
MaterialDataManager&,
369418
const IntegrationType it,
370419
const real);
420+
//! \brief debugging version
421+
MGIS_EXPORT int integrate_debug(mgis::ThreadPool&,
422+
MaterialDataManager&,
423+
const IntegrationType it,
424+
const real);
425+
//! \brief debugging version
426+
MGIS_EXPORT int integrate_debug(
427+
mgis::ThreadPool&,
428+
MaterialDataManager&,
429+
const IntegrationType it,
430+
const real,
431+
const debug::BehaviourIntegrationFailureAnalyser&);
371432
/*!
372433
* \brief integrate the behaviour for a range of integration points.
373434
* \return an exit status. The returned value has the following meaning:
@@ -389,6 +450,20 @@ namespace mgis::behaviour {
389450
const real,
390451
const size_type,
391452
const size_type);
453+
//! \brief debugging version
454+
MGIS_EXPORT int integrate_debug(MaterialDataManager&,
455+
const IntegrationType,
456+
const real,
457+
const size_type,
458+
const size_type);
459+
//! \brief debugging version
460+
MGIS_EXPORT int integrate_debug(
461+
MaterialDataManager&,
462+
const IntegrationType,
463+
const real,
464+
const size_type,
465+
const size_type,
466+
const debug::BehaviourIntegrationFailureAnalyser&);
392467
/*!
393468
* \brief execute the given post-processing
394469
* \param[out] outputs: post-processing results

src/Integrate.cxx

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,56 @@ namespace mgis::behaviour::internals {
400400
return r;
401401
} // end of integrate
402402

403+
/*!
404+
* \brief perform the integration of the behaviour over a range of integration
405+
* points.
406+
*/
407+
static BehaviourIntegrationResult integrate_debug(
408+
MaterialDataManager& m,
409+
const BehaviourIntegrationOptions& opts,
410+
const real dt,
411+
const size_type b,
412+
const size_type e,
413+
const debug::BehaviourIntegrationFailureAnalyser& analyser) {
414+
// workspace
415+
auto& ws = m.getBehaviourIntegrationWorkSpace();
416+
auto v = internals::initializeBehaviourDataView(ws);
417+
auto behaviour_evaluators = internals::buildBehaviourEvaluators(ws, m);
418+
// loop over integration points
419+
auto r = BehaviourIntegrationResult{};
420+
auto rdt0 = r.time_step_increase_factor;
421+
const real Ke = encodeBehaviourIntegrationOptions(opts);
422+
real bopts[Behaviour::nopts + 1]; // option passed to the behaviour
423+
for (auto i = b; i != e; ++i) {
424+
internals::evaluate(ws, behaviour_evaluators, i);
425+
internals::updateView(v, m, i);
426+
auto rdt = rdt0;
427+
v.error_message[0] = '\0';
428+
v.rdt = &rdt;
429+
v.dt = dt;
430+
if ((opts.integration_type !=
431+
IntegrationType::INTEGRATION_NO_TANGENT_OPERATOR) &&
432+
(m.K_stride != 0)) {
433+
v.K = m.K.data() + m.K_stride * i;
434+
} else {
435+
v.K = &bopts[0];
436+
}
437+
v.K[0] = Ke;
438+
const auto ri = integrate_debug(v, m.b, analyser);
439+
r.exit_status = std::min(ri, r.exit_status);
440+
r.time_step_increase_factor = std::min(rdt, r.time_step_increase_factor);
441+
if (ri == 0) {
442+
r.n = i;
443+
} else if (ri == -1) {
444+
r.n = i;
445+
v.error_message[511] = '\0';
446+
r.error_message = std::string(v.error_message);
447+
return r;
448+
}
449+
}
450+
return r;
451+
} // end of integrate_debug
452+
403453
/*!
404454
* \brief execute the given post-processing over a range of integration
405455
* points.
@@ -658,6 +708,23 @@ namespace mgis::behaviour {
658708
return internals::integrate(m, opts, dt, 0, m.n);
659709
} // end of integrate
660710

711+
BehaviourIntegrationResult integrate_debug(
712+
MaterialDataManager& m,
713+
const BehaviourIntegrationOptions& opts,
714+
const real dt) {
715+
const auto& a = debug::getDefaultBehaviourIntegrationFailureAnalyser();
716+
return integrate_debug(m, opts, dt, a);
717+
} // end of integrate_debug
718+
719+
BehaviourIntegrationResult integrate_debug(
720+
MaterialDataManager& m,
721+
const BehaviourIntegrationOptions& opts,
722+
const real dt,
723+
const debug::BehaviourIntegrationFailureAnalyser& analyser) {
724+
internals::allocate(m, opts);
725+
return internals::integrate_debug(m, opts, dt, 0, m.n, analyser);
726+
} // end of integrate
727+
661728
BehaviourIntegrationResult integrate(MaterialDataManager& m,
662729
const BehaviourIntegrationOptions& opts,
663730
const real dt,
@@ -668,6 +735,28 @@ namespace mgis::behaviour {
668735
return internals::integrate(m, opts, dt, b, e);
669736
} // end of integrate
670737

738+
BehaviourIntegrationResult integrate_debug(
739+
MaterialDataManager& m,
740+
const BehaviourIntegrationOptions& opts,
741+
const real dt,
742+
const size_type b,
743+
const size_type e) {
744+
const auto& a = debug::getDefaultBehaviourIntegrationFailureAnalyser();
745+
return integrate_debug(m, opts, dt, b, e, a);
746+
} // end of integrate_debug
747+
748+
BehaviourIntegrationResult integrate_debug(
749+
MaterialDataManager& m,
750+
const BehaviourIntegrationOptions& opts,
751+
const real dt,
752+
const size_type b,
753+
const size_type e,
754+
const debug::BehaviourIntegrationFailureAnalyser& analyser) {
755+
internals::allocate(m, opts);
756+
internals::checkIntegrationPointsRange(m, b, e);
757+
return internals::integrate_debug(m, opts, dt, b, e, analyser);
758+
} // end of integrate
759+
671760
MultiThreadedBehaviourIntegrationResult integrate(
672761
mgis::ThreadPool& p,
673762
MaterialDataManager& m,
@@ -704,6 +793,52 @@ namespace mgis::behaviour {
704793
return res;
705794
} // end of integrate
706795

796+
MultiThreadedBehaviourIntegrationResult integrate_debug(
797+
mgis::ThreadPool& p,
798+
MaterialDataManager& m,
799+
const BehaviourIntegrationOptions& opts,
800+
const real dt) {
801+
const auto& a = debug::getDefaultBehaviourIntegrationFailureAnalyser();
802+
return integrate_debug(p, m, opts, dt, a);
803+
} // end if integrate_debug
804+
805+
MultiThreadedBehaviourIntegrationResult integrate_debug(
806+
mgis::ThreadPool& p,
807+
MaterialDataManager& m,
808+
const BehaviourIntegrationOptions& opts,
809+
const real dt,
810+
const debug::BehaviourIntegrationFailureAnalyser& analyser) {
811+
m.setThreadSafe(true);
812+
internals::allocate(m, opts);
813+
// get number of threads
814+
const auto nth = p.getNumberOfThreads();
815+
const auto d = m.n / nth;
816+
const auto r = m.n % nth;
817+
size_type b = 0;
818+
std::vector<std::future<ThreadedTaskResult<BehaviourIntegrationResult>>>
819+
tasks;
820+
tasks.reserve(nth);
821+
for (size_type i = 0; i != r; ++i) {
822+
tasks.push_back(p.addTask([&m, &opts, dt, b, d, &analyser] {
823+
return internals::integrate_debug(m, opts, dt, b, b + d + 1, analyser);
824+
}));
825+
b += d + 1;
826+
}
827+
for (size_type i = r; i != nth; ++i) {
828+
tasks.push_back(p.addTask([&m, &opts, dt, b, d, &analyser] {
829+
return internals::integrate_debug(m, opts, dt, b, b + d, analyser);
830+
}));
831+
b += d;
832+
}
833+
auto res = MultiThreadedBehaviourIntegrationResult{};
834+
for (auto& t : tasks) {
835+
const auto& ri = *(t.get());
836+
res.exit_status = std::min(res.exit_status, ri.exit_status);
837+
res.results.push_back(ri);
838+
}
839+
return res;
840+
} // end of integrate_debug
841+
707842
int integrate(mgis::ThreadPool& p,
708843
MaterialDataManager& m,
709844
const IntegrationType it,
@@ -714,6 +849,26 @@ namespace mgis::behaviour {
714849
return r.exit_status;
715850
} // end of integrate
716851

852+
int integrate_debug(mgis::ThreadPool& p,
853+
MaterialDataManager& m,
854+
const IntegrationType it,
855+
const real dt) {
856+
const auto& a = debug::getDefaultBehaviourIntegrationFailureAnalyser();
857+
return integrate_debug(p, m, it, dt, a);
858+
}
859+
860+
int integrate_debug(
861+
mgis::ThreadPool& p,
862+
MaterialDataManager& m,
863+
const IntegrationType it,
864+
const real dt,
865+
const debug::BehaviourIntegrationFailureAnalyser& analyser) {
866+
BehaviourIntegrationOptions opts;
867+
opts.integration_type = it;
868+
const auto r = integrate_debug(p, m, opts, dt, analyser);
869+
return r.exit_status;
870+
} // end of integrate_debug
871+
717872
int integrate(MaterialDataManager& m,
718873
const IntegrationType it,
719874
const real dt,
@@ -725,6 +880,28 @@ namespace mgis::behaviour {
725880
return r.exit_status;
726881
} // end of integrate
727882

883+
int integrate_debug(MaterialDataManager& m,
884+
const IntegrationType it,
885+
const real dt,
886+
const size_type b,
887+
const size_type e) {
888+
const auto& a = debug::getDefaultBehaviourIntegrationFailureAnalyser();
889+
return integrate_debug(m, it, dt, b, e, a);
890+
} // end of integrate
891+
892+
int integrate_debug(
893+
MaterialDataManager& m,
894+
const IntegrationType it,
895+
const real dt,
896+
const size_type b,
897+
const size_type e,
898+
const debug::BehaviourIntegrationFailureAnalyser& analyser) {
899+
BehaviourIntegrationOptions opts;
900+
opts.integration_type = it;
901+
const auto r = integrate_debug(m, opts, dt, b, e, analyser);
902+
return r.exit_status;
903+
} // end of integrate
904+
728905
static void copy(State& s, const auto& src) {
729906
if (src.stored_energy != nullptr) {
730907
s.stored_energy = *(src.stored_energy);
@@ -757,6 +934,11 @@ namespace mgis::behaviour {
757934
s.external_state_variables.begin());
758935
} // end of copy
759936

937+
int integrate_debug(BehaviourDataView& d, const Behaviour& b) {
938+
const auto& a = debug::getDefaultBehaviourIntegrationFailureAnalyser();
939+
return integrate_debug(d, b, a);
940+
} // end of integrate_debug
941+
760942
int integrate_debug(
761943
BehaviourDataView& d,
762944
const Behaviour& b,

0 commit comments

Comments
 (0)