Actual source code: tscreate.c
1: #ifdef PETSC_RCS_HEADER
2: static char vcid[] = "$Id: tscreate.c,v 1.7 2000/01/10 03:54:25 knepley Exp $";
3: #endif
5: #include src/ts/tsimpl.h
7: #undef __FUNCT__
9: static int TSPublish_Petsc(PetscObject obj)
10: {
11: #if defined(PETSC_HAVE_AMS)
12: TS v = (TS) obj;
13: int ierr;
14: #endif
18: #if defined(PETSC_HAVE_AMS)
19: /* if it is already published then return */
20: if (v->amem >=0) return(0);
22: PetscObjectPublishBaseBegin(obj);
23: AMS_Memory_add_field((AMS_Memory)v->amem,"Step",&v->steps,1,AMS_INT,AMS_READ,
24: AMS_COMMON,AMS_REDUCT_UNDEF);
25: AMS_Memory_add_field((AMS_Memory)v->amem,"Time",&v->ptime,1,AMS_DOUBLE,AMS_READ,
26: AMS_COMMON,AMS_REDUCT_UNDEF);
27: AMS_Memory_add_field((AMS_Memory)v->amem,"CurrentTimeStep",&v->time_step,1,
28: AMS_DOUBLE,AMS_READ,AMS_COMMON,AMS_REDUCT_UNDEF);
29: PetscObjectPublishBaseEnd(obj);
30: #endif
31: return(0);
32: }
34: #undef __FUNCT__
36: /*@C
37: TSCreate - This function creates an empty timestepper. The problem type can then be set with TSSetProblemType() and the
38: type of solver can then be set with TSSetType().
40: Collective on MPI_Comm
42: Input Parameter:
43: . comm - The communicator
45: Output Parameter:
46: . ts - The TS
48: Level: beginner
50: .keywords: TS, create
51: .seealso: TSSetType(), TSSetUp(), TSDestroy(), MeshCreate(), TSSetProblemType()
52: @*/
53: int TSCreate(MPI_Comm comm, TS *ts) {
54: TS t;
59: *ts = PETSC_NULL;
60: #ifndef PETSC_USE_DYNAMIC_LIBRARIES
61: TSInitializePackage(PETSC_NULL);
62: #endif
64: PetscHeaderCreate(t, _p_TS, struct _TSOps, TS_COOKIE, -1, "TS", comm, TSDestroy, TSView);
65: PetscLogObjectCreate(t);
66: PetscLogObjectMemory(t, sizeof(struct _p_TS));
67: PetscMemzero(t->ops, sizeof(struct _TSOps));
68: t->bops->publish = TSPublish_Petsc;
69: t->type_name = PETSC_NULL;
70: t->serialize_name = PETSC_NULL;
72: t->ops->applymatrixbc = TSDefaultSystemMatrixBC;
73: t->ops->applyrhsbc = TSDefaultRhsBC;
74: t->ops->applysolbc = TSDefaultSolutionBC;
75: t->ops->prestep = TSDefaultPreStep;
76: t->ops->update = TSDefaultUpdate;
77: t->ops->poststep = TSDefaultPostStep;
79: /* General TS description */
80: t->problem_type = TS_LINEAR;
81: t->vec_sol = PETSC_NULL;
82: t->vec_sol_always = PETSC_NULL;
83: t->numbermonitors = 0;
84: t->isGTS = PETSC_FALSE;
85: t->isExplicit = PETSC_NULL;
86: t->Iindex = PETSC_NULL;
87: t->sles = PETSC_NULL;
88: t->A = PETSC_NULL;
89: t->B = PETSC_NULL;
90: t->snes = PETSC_NULL;
91: t->funP = PETSC_NULL;
92: t->jacP = PETSC_NULL;
93: t->setupcalled = 0;
94: t->data = PETSC_NULL;
95: t->user = PETSC_NULL;
96: t->max_steps = 5000;
97: t->max_time = 5.0;
98: t->time_step = .1;
99: t->time_step_old = t->time_step;
100: t->initial_time_step = t->time_step;
101: t->steps = 0;
102: t->ptime = 0.0;
103: t->linear_its = 0;
104: t->nonlinear_its = 0;
105: t->work = PETSC_NULL;
106: t->nwork = 0;
108: *ts = t;
109: return(0);
110: }
112: #undef __FUNCT__
114: /*@
115: TSSerialize - This function stores or recreates a timestepper using a viewer for a binary file.
117: Collective on MPI_Comm
119: Input Parameters:
120: + comm - The communicator for the ts object
121: . viewer - The viewer context
122: - store - This flag is PETSC_TRUE is data is being written, otherwise it will be read
124: Output Parameter:
125: . ts - The ts
127: Level: beginner
129: .keywords: TS, serialize
130: .seealso: PartitionSerialize(), TSSerialize()
131: @*/
132: int TSSerialize(MPI_Comm comm, TS *ts, PetscViewer viewer, PetscTruth store)
133: {
134: int (*serialize)(MPI_Comm, TS *, PetscViewer, PetscTruth);
135: int fd, len;
136: char *name;
137: PetscTruth match;
138: int ierr;
144: PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_BINARY, &match);
145: if (match == PETSC_FALSE) SETERRQ(PETSC_ERR_ARG_WRONG, "Must be binary viewer");
146: PetscViewerBinaryGetDescriptor(viewer, &fd);
148: if (!TSSerializeRegisterAllCalled) {
149: TSSerializeRegisterAll(PETSC_NULL);
150: }
151: if (!TSSerializeList) SETERRQ(PETSC_ERR_ARG_CORRUPT, "Could not find table of methods");
153: if (store) {
155: PetscStrlen((*ts)->class_name, &len);
156: PetscBinaryWrite(fd, &len, 1, PETSC_INT, 0);
157: PetscBinaryWrite(fd, (*ts)->class_name, len, PETSC_CHAR, 0);
158: PetscStrlen((*ts)->serialize_name, &len);
159: PetscBinaryWrite(fd, &len, 1, PETSC_INT, 0);
160: PetscBinaryWrite(fd, (*ts)->serialize_name, len, PETSC_CHAR, 0);
161: PetscFListFind(comm, TSSerializeList, (*ts)->serialize_name, (void (**)(void)) &serialize);
162: if (!serialize) SETERRQ(PETSC_ERR_ARG_WRONG, "Type cannot be serialized");
163: (*serialize)(comm, ts, viewer, store);
164: } else {
165: PetscBinaryRead(fd, &len, 1, PETSC_INT);
166: PetscMalloc((len+1) * sizeof(char), &name);
167: name[len] = 0;
168: PetscBinaryRead(fd, name, len, PETSC_CHAR);
169: PetscStrcmp(name, "TS", &match);
170: PetscFree(name);
171: if (match == PETSC_FALSE) SETERRQ(PETSC_ERR_ARG_WRONG, "Non-ts object");
172: /* Dispatch to the correct routine */
173: PetscBinaryRead(fd, &len, 1, PETSC_INT);
174: PetscMalloc((len+1) * sizeof(char), &name);
175: name[len] = 0;
176: PetscBinaryRead(fd, name, len, PETSC_CHAR);
177: PetscFListFind(comm, TSSerializeList, name, (void (**)(void)) &serialize);
178: if (!serialize) SETERRQ(PETSC_ERR_ARG_WRONG, "Type cannot be serialized");
179: (*serialize)(comm, ts, viewer, store);
180: PetscStrfree((*ts)->serialize_name);
181: (*ts)->serialize_name = name;
182: }
184: return(0);
185: }