1 | /*!\file BamgMesh.cpp
|
---|
2 | */
|
---|
3 |
|
---|
4 | #include <stdio.h>
|
---|
5 | #include "../../../objects/objects.h"
|
---|
6 | #include "../../../io/io.h"
|
---|
7 | #include "../../../shared/shared.h"
|
---|
8 | #include "../../io/matlabio.h"
|
---|
9 |
|
---|
10 | /*Constructors/Destructors*/
|
---|
11 | /*FUNCTION BamgMesh::BamgMesh(void* module_struct){{{1*/
|
---|
12 | BamgMesh::BamgMesh(void* module_struct){
|
---|
13 |
|
---|
14 | mxArray* matlab_struct=NULL;
|
---|
15 | int lines,cols;
|
---|
16 |
|
---|
17 | /*recover our pointer: */
|
---|
18 | matlab_struct=(mxArray*)module_struct;
|
---|
19 |
|
---|
20 |
|
---|
21 | FetchData(&this->Vertices, &this->VerticesSize[0], &this->VerticesSize[1], mxGetAssignedField(matlab_struct,0,"Vertices"));
|
---|
22 | FetchData(&this->Edges, &this->EdgesSize[0], &this->EdgesSize[1], mxGetAssignedField(matlab_struct,0,"Edges"));
|
---|
23 | FetchData(&this->Triangles, &this->TrianglesSize[0], &this->TrianglesSize[1], mxGetAssignedField(matlab_struct,0,"Triangles"));
|
---|
24 | this->QuadrilateralsSize[0]=0, this->QuadrilateralsSize[1]=0; this->Quadrilaterals=NULL;
|
---|
25 |
|
---|
26 | this->SubDomainsSize[0]=0, this->SubDomainsSize[1]=0; this->SubDomains=NULL;
|
---|
27 | this->SubDomainsFromGeomSize[0]=0, this->SubDomainsFromGeomSize[1]=0; this->SubDomainsFromGeom=NULL;
|
---|
28 | this->CrackedVerticesSize[0]=0, this->CrackedVerticesSize[1]=0; this->CrackedVertices=NULL;
|
---|
29 | FetchData(&this->CrackedEdges, &this->CrackedEdgesSize[0], &this->CrackedEdgesSize[1], mxGetAssignedField(matlab_struct,0,"CrackedEdges"));
|
---|
30 |
|
---|
31 | FetchData(&this->VerticesOnGeomEdge, &this->VerticesOnGeomEdgeSize[0], &this->VerticesOnGeomEdgeSize[1], mxGetAssignedField(matlab_struct,0,"VerticesOnGeomEdge"));
|
---|
32 | FetchData(&this->VerticesOnGeomVertex,&this->VerticesOnGeomVertexSize[0],&this->VerticesOnGeomVertexSize[1],mxGetAssignedField(matlab_struct,0,"VerticesOnGeomVertex"));
|
---|
33 | FetchData(&this->EdgesOnGeomEdge, &this->EdgesOnGeomEdgeSize[0], &this->EdgesOnGeomEdgeSize[1], mxGetAssignedField(matlab_struct,0,"EdgesOnGeomEdge"));
|
---|
34 |
|
---|
35 | this->IssmEdgesSize[0]=0, this->IssmEdgesSize[1]=0; this->IssmEdges=NULL;
|
---|
36 | FetchData(&this->IssmSegments, &this->IssmSegmentsSize[0], &this->IssmSegmentsSize[1], mxGetAssignedField(matlab_struct,0,"IssmSegments"));
|
---|
37 |
|
---|
38 | this->ElementConnectivitySize[0]=0, this->ElementConnectivitySize[1]=0; this->ElementConnectivity=NULL;
|
---|
39 | this->NodalConnectivitySize[0]=0, this->NodalConnectivitySize[1]=0; this->NodalConnectivity=NULL;
|
---|
40 | this->NodalElementConnectivitySize[0]=0, this->NodalElementConnectivitySize[1]=0; this->NodalElementConnectivity=NULL;
|
---|
41 |
|
---|
42 | }
|
---|
43 | /*}}}*/
|
---|
44 |
|
---|
45 | /*Methods*/
|
---|
46 | /*FUNCTION BamgMesh::SetStructureFields{{{1*/
|
---|
47 | void BamgMesh::SetStructureFields(void* module_struct){
|
---|
48 |
|
---|
49 | mxArray** matlab_struct=NULL;
|
---|
50 |
|
---|
51 | /*Intermediary*/
|
---|
52 | int i;
|
---|
53 | mxArray* output=NULL;
|
---|
54 | const int numfields=16;
|
---|
55 | const char* fnames[numfields];
|
---|
56 | mwSize ndim=2;
|
---|
57 | mwSize dimensions[2]={1,1};
|
---|
58 |
|
---|
59 | /*recover pointer: */
|
---|
60 | matlab_struct=(mxArray**)module_struct;
|
---|
61 |
|
---|
62 | /*Initialize field names*/
|
---|
63 | i=0;
|
---|
64 | fnames[i++] = "Triangles";
|
---|
65 | fnames[i++] = "Vertices";
|
---|
66 | fnames[i++] = "Edges";
|
---|
67 | fnames[i++] = "IssmSegments";
|
---|
68 | fnames[i++] = "IssmEdges";
|
---|
69 | fnames[i++] = "Quadrilaterals";
|
---|
70 | fnames[i++] = "VerticesOnGeomVertex";
|
---|
71 | fnames[i++] = "VerticesOnGeomEdge";
|
---|
72 | fnames[i++] = "EdgesOnGeomEdge";
|
---|
73 | fnames[i++] = "SubDomains";
|
---|
74 | fnames[i++] = "SubDomainsFromGeom";
|
---|
75 | fnames[i++] = "ElementConnectivity";
|
---|
76 | fnames[i++] = "NodalConnectivity";
|
---|
77 | fnames[i++] = "NodalElementConnectivity";
|
---|
78 | fnames[i++] = "CrackedVertices";
|
---|
79 | fnames[i++] = "CrackedEdges";
|
---|
80 | _assert_(i==numfields);
|
---|
81 |
|
---|
82 | /*Initialize Matlab structure*/
|
---|
83 | output=mxCreateStructArray(ndim,dimensions,numfields,fnames);
|
---|
84 |
|
---|
85 | /*set each matlab each field*/
|
---|
86 | i=0;
|
---|
87 | i++; SetStructureField(output,"Triangles", this->TrianglesSize[0], this->TrianglesSize[1], this->Triangles);
|
---|
88 | i++; SetStructureField(output,"Vertices", this->VerticesSize[0], this->VerticesSize[1], this->Vertices);
|
---|
89 | i++; SetStructureField(output,"Edges", this->EdgesSize[0], this->EdgesSize[1], this->Edges);
|
---|
90 | i++; SetStructureField(output,"IssmSegments", this->IssmSegmentsSize[0], this->IssmSegmentsSize[1], this->IssmSegments);
|
---|
91 | i++; SetStructureField(output,"IssmEdges", this->IssmEdgesSize[0], this->IssmEdgesSize[1], this->IssmEdges);
|
---|
92 | i++; SetStructureField(output,"Quadrilaterals", this->QuadrilateralsSize[0], this->QuadrilateralsSize[1], this->Quadrilaterals);
|
---|
93 | i++; SetStructureField(output,"VerticesOnGeomVertex",this->VerticesOnGeomVertexSize[0],this->VerticesOnGeomVertexSize[1], this->VerticesOnGeomVertex);
|
---|
94 | i++; SetStructureField(output,"VerticesOnGeomEdge", this->VerticesOnGeomEdgeSize[0], this->VerticesOnGeomEdgeSize[1], this->VerticesOnGeomEdge);
|
---|
95 | i++; SetStructureField(output,"EdgesOnGeomEdge", this->EdgesOnGeomEdgeSize[0], this->EdgesOnGeomEdgeSize[1], this->EdgesOnGeomEdge);
|
---|
96 | i++; SetStructureField(output,"SubDomains", this->SubDomainsSize[0], this->SubDomainsSize[1], this->SubDomains);
|
---|
97 | i++; SetStructureField(output,"SubDomainsFromGeom", this->SubDomainsFromGeomSize[0], this->SubDomainsFromGeomSize[1], this->SubDomainsFromGeom);
|
---|
98 | i++; SetStructureField(output,"ElementConnectivity", this->ElementConnectivitySize[0], this->ElementConnectivitySize[1], this->ElementConnectivity);
|
---|
99 | i++; SetStructureField(output,"NodalConnectivity", this->NodalConnectivitySize[0], this->NodalConnectivitySize[1], this->NodalConnectivity);
|
---|
100 | i++; SetStructureField(output,"NodalElementConnectivity", this->NodalElementConnectivitySize[0], this->NodalElementConnectivitySize[1], this->NodalElementConnectivity);
|
---|
101 | i++; SetStructureField(output,"CrackedVertices", this->CrackedVerticesSize[0], this->CrackedVerticesSize[1], this->CrackedVertices);
|
---|
102 | i++; SetStructureField(output,"CrackedEdges", this->CrackedEdgesSize[0], this->CrackedEdgesSize[1], this->CrackedEdges);
|
---|
103 | _assert_(i==numfields);
|
---|
104 |
|
---|
105 | /*Assign output*/
|
---|
106 | *matlab_struct=output;
|
---|
107 |
|
---|
108 | }
|
---|
109 | /*}}}*/
|
---|
110 | /*FUNCTION BamgMesh::SetStructureField{{{1*/
|
---|
111 | void BamgMesh::SetStructureField(void* module_struct,const char* fieldname,int fieldrows,int fieldcols,double* fieldpointer){
|
---|
112 |
|
---|
113 | /*Intermediary*/
|
---|
114 | mxArray* matlab_struct=NULL;
|
---|
115 | int i1,i2;
|
---|
116 | mxArray* pfield=NULL;
|
---|
117 | mxArray* pfield2=NULL;
|
---|
118 |
|
---|
119 | /*recover pointer: */
|
---|
120 | matlab_struct=(mxArray*)module_struct;
|
---|
121 |
|
---|
122 | /*Copy field*/
|
---|
123 | double* fieldcopy=NULL;
|
---|
124 | if (fieldrows*fieldcols){
|
---|
125 | fieldcopy=(double*)xmalloc(fieldrows*fieldcols*sizeof(double));
|
---|
126 | for(i1=0;i1<fieldrows;i1++){
|
---|
127 | for(i2=0;i2<fieldcols;i2++){
|
---|
128 | fieldcopy[fieldcols*i1+i2]=fieldpointer[fieldcols*i1+i2];
|
---|
129 | }
|
---|
130 | }
|
---|
131 | }
|
---|
132 |
|
---|
133 | /*Set matlab field*/
|
---|
134 | pfield=mxCreateDoubleMatrix(0,0,mxREAL);
|
---|
135 | mxSetM(pfield,fieldcols);
|
---|
136 | mxSetN(pfield,fieldrows);
|
---|
137 | mxSetPr(pfield,fieldcopy);
|
---|
138 | mexCallMATLAB(1,&pfield2,1,&pfield,"transpose");//transpose
|
---|
139 | mxSetField(matlab_struct,0,fieldname,pfield2);
|
---|
140 | }
|
---|
141 | /*}}}*/
|
---|