Actual source code: cartesian.c
1: #include "private/meshimpl.h"
2: #include <CartesianSieve.hh>
6: /*@C
7: MeshCartesianGetMesh - Gets the internal mesh object
9: Not collective
11: Input Parameter:
12: . mesh - the mesh object
14: Output Parameter:
15: . m - the internal mesh object
16:
17: Level: advanced
19: .seealso MeshCreate(), MeshCartesianSetMesh()
21: @*/
22: PetscErrorCode MeshCartesianGetMesh(Mesh mesh, ALE::Obj<ALE::CartesianMesh>& m)
23: {
26: m = *((ALE::Obj<ALE::CartesianMesh> *) mesh->data);
27: return(0);
28: }
32: /*@C
33: MeshCartesianSetMesh - Sets the internal mesh object
35: Not collective
37: Input Parameters:
38: + mesh - the mesh object
39: - m - the internal mesh object
40:
41: Level: advanced
43: .seealso MeshCreate(), MeshCartesianGetMesh()
45: @*/
46: PetscErrorCode MeshCartesianSetMesh(Mesh mesh, const ALE::Obj<ALE::CartesianMesh>& m)
47: {
50: *((ALE::Obj<ALE::CartesianMesh> *) mesh->data) = m;
51: return(0);
52: }
56: PetscErrorCode MeshDestroy_Cartesian(Mesh mesh)
57: {
61: if (mesh->data) {
62: *((ALE::Obj<ALE::CartesianMesh> *) mesh->data) = PETSC_NULL;
63: PetscFree(mesh->data);
64: mesh->data = PETSC_NULL;
65: }
66: return(0);
67: }
71: PetscErrorCode MeshView_Cartesian_Ascii(const ALE::Obj<ALE::CartesianMesh>& mesh, PetscViewer viewer)
72: {
73: PetscViewerFormat format;
74: PetscErrorCode ierr;
77: PetscViewerGetFormat(viewer, &format);
78: if (format == PETSC_VIEWER_ASCII_VTK) {
79: #if 0
80: VTKViewer::writeHeader(viewer);
81: VTKViewer::writeVertices(mesh, viewer);
82: VTKViewer::writeElements(mesh, viewer);
83: #endif
84: } else {
85: int dim = mesh->getDimension();
87: PetscViewerASCIIPrintf(viewer, "Mesh in %d dimensions:\n", dim);
88: // FIX: Need to globalize
89: PetscViewerASCIIPrintf(viewer, " %d vertices\n", mesh->getSieve()->getNumVertices());
90: PetscViewerASCIIPrintf(viewer, " %d cells\n", mesh->getSieve()->getNumCells());
91: }
92: PetscViewerFlush(viewer);
93: return(0);
94: }
96: PetscErrorCode MeshView_Cartesian(Mesh mesh, PetscViewer viewer)
97: {
98: PetscTruth iascii, isbinary, isdraw;
102: PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_ASCII, &iascii);
103: PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_BINARY, &isbinary);
104: PetscTypeCompare((PetscObject) viewer, PETSC_VIEWER_DRAW, &isdraw);
106: if (iascii){
107: MeshView_Cartesian_Ascii(*((ALE::Obj<ALE::CartesianMesh> *) mesh->data), viewer);
108: } else if (isbinary) {
109: SETERRQ(PETSC_ERR_SUP, "Binary viewer not implemented for Cartesian Mesh");
110: } else if (isdraw){
111: SETERRQ(PETSC_ERR_SUP, "Draw viewer not implemented for Cartesian Mesh");
112: } else {
113: SETERRQ1(PETSC_ERR_SUP,"Viewer type %s not supported by this mesh object", ((PetscObject)viewer)->type_name);
114: }
115: return(0);
116: }
120: PetscErrorCode MeshGetInterpolation_Cartesian(Mesh fineMesh, Mesh coarseMesh, Mat *interpolation, Vec *scaling)
121: {
122: ALE::Obj<ALE::CartesianMesh> coarse;
123: ALE::Obj<ALE::CartesianMesh> fine;
124: Mat P;
125: PetscErrorCode ierr;
128: MeshCartesianGetMesh(fineMesh, fine);
129: MeshCartesianGetMesh(coarseMesh, coarse);
130: #if 0
131: const ALE::Obj<ALE::Mesh::real_section_type>& coarseCoordinates = coarse->getRealSection("coordinates");
132: const ALE::Obj<ALE::Mesh::real_section_type>& fineCoordinates = fine->getRealSection("coordinates");
133: const ALE::Obj<ALE::Mesh::label_sequence>& vertices = fine->depthStratum(0);
134: const ALE::Obj<ALE::Mesh::real_section_type>& sCoarse = coarse->getRealSection("default");
135: const ALE::Obj<ALE::Mesh::real_section_type>& sFine = fine->getRealSection("default");
136: const ALE::Obj<ALE::Mesh::order_type>& coarseOrder = coarse->getFactory()->getGlobalOrder(coarse, "default", sCoarse);
137: const ALE::Obj<ALE::Mesh::order_type>& fineOrder = fine->getFactory()->getGlobalOrder(fine, "default", sFine);
138: const int dim = coarse->getDimension();
139: double *v0, *J, *invJ, detJ, *refCoords, *values;
140: #endif
142: MatCreate(fine->comm(), &P);
143: #if 0
144: MatSetSizes(P, sFine->size(), sCoarse->size(), PETSC_DETERMINE, PETSC_DETERMINE);
145: MatSetFromOptions(P);
146: PetscMalloc5(dim,double,&v0,dim*dim,double,&J,dim*dim,double,&invJ,dim,double,&refCoords,dim+1,double,&values);
147: for(ALE::Mesh::label_sequence::iterator v_iter = vertices->begin(); v_iter != vertices->end(); ++v_iter) {
148: const ALE::Mesh::real_section_type::value_type *coords = fineCoordinates->restrictPoint(*v_iter);
149: const ALE::Mesh::point_type coarseCell = coarse->locatePoint(coords);
151: coarse->computeElementGeometry(coarseCoordinates, coarseCell, v0, J, invJ, detJ);
152: for(int d = 0; d < dim; ++d) {
153: refCoords[d] = 0.0;
154: for(int e = 0; e < dim; ++e) {
155: refCoords[d] += invJ[d*dim+e]*(coords[e] - v0[e]);
156: }
157: refCoords[d] -= 1.0;
158: }
159: values[0] = 1.0/3.0 - (refCoords[0] + refCoords[1])/3.0;
160: values[1] = 0.5*(refCoords[0] + 1.0);
161: values[2] = 0.5*(refCoords[1] + 1.0);
162: updateOperatorGeneral(P, fine, sFine, fineOrder, *v_iter, sCoarse, coarseOrder, coarseCell, values, INSERT_VALUES);
163: }
164: PetscFree5(v0,J,invJ,refCoords,values);
165: #endif
166: MatAssemblyBegin(P, MAT_FINAL_ASSEMBLY);
167: MatAssemblyEnd(P, MAT_FINAL_ASSEMBLY);
168: *interpolation = P;
169: return(0);
170: }
174: PetscErrorCode MeshRefine_Cartesian(Mesh mesh, MPI_Comm comm, Mesh *refinedMesh)
175: {
176: ALE::Obj<ALE::CartesianMesh> oldMesh;
177: PetscErrorCode ierr;
180: MeshCartesianGetMesh(mesh, oldMesh);
181: MeshCreate(comm, refinedMesh);
182: #if 0
183: ALE::Obj<ALE::Mesh> newMesh = ALE::Generator::refineMesh(oldMesh, refinementLimit, false);
184: MeshCartesianSetMesh(*refinedMesh, newMesh);
185: const ALE::Obj<ALE::CartesianMesh::real_section_type>& s = newMesh->getRealSection("default");
187: newMesh->setDiscretization(oldMesh->getDiscretization());
188: newMesh->setBoundaryCondition(oldMesh->getBoundaryCondition());
189: newMesh->setupField(s);
190: #else
191: SETERRQ(PETSC_ERR_SUP, "Not yet implemented");
192: #endif
193: return(0);
194: }
198: PetscErrorCode MeshCoarsen_Cartesian(Mesh mesh, MPI_Comm comm, Mesh *coarseMesh)
199: {
200: ALE::Obj<ALE::CartesianMesh> oldMesh;
201: PetscErrorCode ierr;
204: MeshCartesianGetMesh(mesh, oldMesh);
205: MeshCreate(comm, coarseMesh);
206: #if 0
207: ALE::Obj<ALE::Mesh> newMesh = ALE::Generator::refineMesh(oldMesh, refinementLimit, false);
208: MeshCartesianSetMesh(*coarseMesh, newMesh);
209: const ALE::Obj<ALE::CartesianMesh::real_section_type>& s = newMesh->getRealSection("default");
211: newMesh->setDiscretization(oldMesh->getDiscretization());
212: newMesh->setBoundaryCondition(oldMesh->getBoundaryCondition());
213: newMesh->setupField(s);
214: #else
215: SETERRQ(PETSC_ERR_SUP, "Not yet implemented");
216: #endif
217: return(0);
218: }
222: PetscErrorCode MeshGetSectionReal_Cartesian(Mesh mesh, const char name[], SectionReal *section)
223: {
224: ALE::Obj<ALE::CartesianMesh> m;
225: PetscErrorCode ierr;
228: MeshCartesianGetMesh(mesh, m);
229: SectionRealCreate(m->comm(), section);
230: PetscObjectSetName((PetscObject) *section, name);
231: #if 0
232: SectionRealSetSection(*section, m->getRealSection(std::string(name)));
233: SectionRealSetBundle(*section, m);
234: #endif
235: return(0);
236: }
241: PetscErrorCode MeshCreate_Cartesian(Mesh mesh)
242: {
243: ALE::Obj<ALE::CartesianMesh> *cm;
249: PetscMalloc(sizeof(ALE::Obj<ALE::CartesianMesh>), &cm);
250: PetscLogObjectMemory(mesh, sizeof(ALE::Obj<ALE::CartesianMesh>));
251: mesh->ops->view = MeshView_Cartesian;
252: mesh->ops->destroy = MeshDestroy_Cartesian;
253: mesh->ops->createglobalvector = MeshCreateGlobalVector;
254: mesh->ops->getcoloring = PETSC_NULL;
255: mesh->ops->getmatrix = MeshGetMatrix;
256: mesh->ops->getinterpolation = MeshGetInterpolation_Cartesian;
257: mesh->ops->getinjection = PETSC_NULL;
258: mesh->ops->refine = MeshRefine_Cartesian;
259: mesh->ops->coarsen = MeshCoarsen_Cartesian;
260: mesh->ops->refinehierarchy = PETSC_NULL;
261: mesh->ops->coarsenhierarchy = PETSC_NULL;
263: mesh->m = PETSC_NULL;
264: mesh->globalScatter = PETSC_NULL;
265: mesh->lf = PETSC_NULL;
266: mesh->lj = PETSC_NULL;
267: mesh->mcompat = PETSC_NULL;
268: mesh->data = cm;
269: return(0);
270: }