Lines Matching refs:tsh
13 PetscErrorCode TSHistoryGetNumSteps(TSHistory tsh, PetscInt *n) in TSHistoryGetNumSteps() argument
17 PetscCall(PetscIntCast(tsh->n, n)); in TSHistoryGetNumSteps()
21 PetscErrorCode TSHistoryUpdate(TSHistory tsh, PetscInt id, PetscReal time) in TSHistoryUpdate() argument
24 if (tsh->n == tsh->c) { /* reallocation */ in TSHistoryUpdate()
25 tsh->c += tsh->s; in TSHistoryUpdate()
26 PetscCall(PetscRealloc(tsh->c * sizeof(*tsh->hist), &tsh->hist)); in TSHistoryUpdate()
27 PetscCall(PetscRealloc(tsh->c * sizeof(*tsh->hist_id), &tsh->hist_id)); in TSHistoryUpdate()
29 …tsh->sorted = (PetscBool)(tsh->sorted && (tsh->n ? (PetscBool)(time >= tsh->hist[tsh->n - 1]) : PE… in TSHistoryUpdate()
31 if (tsh->n) { /* id should be unique */ in TSHistoryUpdate()
34 PetscCall(PetscMalloc1(tsh->n, &ids)); in TSHistoryUpdate()
35 PetscCall(PetscArraycpy(ids, tsh->hist_id, tsh->n)); in TSHistoryUpdate()
36 PetscCall(PetscSortInt(tsh->n, ids)); in TSHistoryUpdate()
37 PetscCall(PetscFindInt(id, tsh->n, ids, &loc)); in TSHistoryUpdate()
42 tsh->hist[tsh->n] = time; in TSHistoryUpdate()
43 tsh->hist_id[tsh->n] = id; in TSHistoryUpdate()
44 tsh->n += 1; in TSHistoryUpdate()
48 PetscErrorCode TSHistoryGetTime(TSHistory tsh, PetscBool backward, PetscInt step, PetscReal *t) in TSHistoryGetTime() argument
53 if (!tsh->sorted) { in TSHistoryGetTime()
54 PetscCall(PetscSortRealWithArrayInt(tsh->n, tsh->hist, tsh->hist_id)); in TSHistoryGetTime()
55 tsh->sorted = PETSC_TRUE; in TSHistoryGetTime()
57 …tep < tsh->n, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Given time step %" PetscInt_FMT " does not match a… in TSHistoryGetTime()
58 if (!backward) *t = tsh->hist[step]; in TSHistoryGetTime()
59 else *t = tsh->hist[tsh->n - step - 1]; in TSHistoryGetTime()
63 PetscErrorCode TSHistoryGetTimeStep(TSHistory tsh, PetscBool backward, PetscInt step, PetscReal *dt) in TSHistoryGetTimeStep() argument
68 if (!tsh->sorted) { in TSHistoryGetTimeStep()
69 PetscCall(PetscSortRealWithArrayInt(tsh->n, tsh->hist, tsh->hist_id)); in TSHistoryGetTimeStep()
70 tsh->sorted = PETSC_TRUE; in TSHistoryGetTimeStep()
72 …ep <= tsh->n, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Given time step %" PetscInt_FMT " does not match a… in TSHistoryGetTimeStep()
73 …if (!backward) *dt = tsh->hist[PetscMin(step + 1, tsh->n - 1)] - tsh->hist[PetscMin(step, tsh->n -… in TSHistoryGetTimeStep()
74 else *dt = tsh->hist[PetscMax(tsh->n - step - 1, 0)] - tsh->hist[PetscMax(tsh->n - step - 2, 0)]; in TSHistoryGetTimeStep()
78 PetscErrorCode TSHistoryGetLocFromTime(TSHistory tsh, PetscReal time, PetscInt *loc) in TSHistoryGetLocFromTime() argument
82 if (!tsh->sorted) { in TSHistoryGetLocFromTime()
83 PetscCall(PetscSortRealWithArrayInt(tsh->n, tsh->hist, tsh->hist_id)); in TSHistoryGetLocFromTime()
84 tsh->sorted = PETSC_TRUE; in TSHistoryGetLocFromTime()
86 PetscCall(PetscFindReal(time, tsh->n, tsh->hist, PETSC_SMALL, loc)); in TSHistoryGetLocFromTime()
90 PetscErrorCode TSHistorySetHistory(TSHistory tsh, PetscInt n, PetscReal hist[], PetscInt hist_id[],… in TSHistorySetHistory() argument
93 PetscValidLogicalCollectiveIntComm(tsh->comm, n, 2); in TSHistorySetHistory()
94 …PetscCheck(n >= 0, tsh->comm, PETSC_ERR_ARG_OUTOFRANGE, "Cannot request a negative size for histor… in TSHistorySetHistory()
96 PetscCall(PetscFree(tsh->hist)); in TSHistorySetHistory()
97 PetscCall(PetscFree(tsh->hist_id)); in TSHistorySetHistory()
98 tsh->n = (size_t)n; in TSHistorySetHistory()
99 tsh->c = (size_t)n; in TSHistorySetHistory()
100 PetscCall(PetscMalloc1(tsh->n, &tsh->hist)); in TSHistorySetHistory()
101 PetscCall(PetscMalloc1(tsh->n, &tsh->hist_id)); in TSHistorySetHistory()
103 tsh->hist[i] = hist[i]; in TSHistorySetHistory()
104 tsh->hist_id[i] = hist_id ? hist_id[i] : i; in TSHistorySetHistory()
106 if (!sorted) PetscCall(PetscSortRealWithArrayInt(tsh->n, tsh->hist, tsh->hist_id)); in TSHistorySetHistory()
107 tsh->sorted = PETSC_TRUE; in TSHistorySetHistory()
111 PetscErrorCode TSHistoryGetHistory(TSHistory tsh, PetscInt *n, const PetscReal *hist[], const Petsc… in TSHistoryGetHistory() argument
114 if (n) PetscCall(PetscIntCast(tsh->n, n)); in TSHistoryGetHistory()
115 if (hist) *hist = tsh->hist; in TSHistoryGetHistory()
116 if (hist_id) *hist_id = tsh->hist_id; in TSHistoryGetHistory()
117 if (sorted) *sorted = tsh->sorted; in TSHistoryGetHistory()
121 PetscErrorCode TSHistoryDestroy(TSHistory *tsh) in TSHistoryDestroy() argument
124 if (!*tsh) PetscFunctionReturn(PETSC_SUCCESS); in TSHistoryDestroy()
125 PetscCall(PetscFree((*tsh)->hist)); in TSHistoryDestroy()
126 PetscCall(PetscFree((*tsh)->hist_id)); in TSHistoryDestroy()
127 PetscCall(PetscCommDestroy(&(*tsh)->comm)); in TSHistoryDestroy()
128 PetscCall(PetscFree(*tsh)); in TSHistoryDestroy()
129 *tsh = NULL; in TSHistoryDestroy()
135 TSHistory tsh; in TSHistoryCreate() local
139 PetscCall(PetscNew(&tsh)); in TSHistoryCreate()
140 PetscCall(PetscCommDuplicate(comm, &tsh->comm, NULL)); in TSHistoryCreate()
142 tsh->c = 1024; /* capacity */ in TSHistoryCreate()
143 tsh->s = 1024; /* reallocation size */ in TSHistoryCreate()
144 tsh->sorted = PETSC_TRUE; in TSHistoryCreate()
146 PetscCall(PetscMalloc1(tsh->c, &tsh->hist)); in TSHistoryCreate()
147 PetscCall(PetscMalloc1(tsh->c, &tsh->hist_id)); in TSHistoryCreate()
148 *hst = tsh; in TSHistoryCreate()