#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <float.h>
Go to the source code of this file.
|
#define | PI 3.14159265358979323846 |
|
#define PI 3.14159265358979323846 |
Mesh CreateBasicCubicMesh |
( |
| ) |
|
Definition at line 63 of file MeshSphericalshell.c.
References Element::E1, Element::E2, Element::E3, Mesh::Edges, Mesh::Elements, Mesh::NbEdges, Mesh::NbElements, Edge::NbSubdiv, Mesh::NbVertexes, Edge::V1, Edge::V2, Mesh::Vertexes, Vertex::X, Vertex::Y, and Vertex::Z.
Referenced by main().
Represents a vertex in the mesh.
void CutEdge |
( |
Mesh * |
LocMesh, |
|
|
int |
IdEdge |
|
) |
| |
Definition at line 129 of file MeshSphericalshell.c.
References Element::E1, Element::E2, Element::E3, Mesh::Edges, Mesh::Elements, Mesh::NbEdges, Mesh::NbElements, Edge::NbSubdiv, Mesh::NbVertexes, Edge::V1, Edge::V2, Mesh::Vertexes, Vertex::X, Vertex::Y, and Vertex::Z.
Referenced by ProjectMeshSphereAndRefine(), and RefineMesh().
144 int IdSubdiviedElement1;
145 int IdSubdiviedElement2;
159 IdNgbhVortex1=LocMesh->
Edges[IdEdge].
V1;
160 IdNgbhVortex2=LocMesh->
Edges[IdEdge].
V2;
163 IdSubdiviedEdge=IdEdge;
168 IdSubdiviedElement1=-1;
169 IdSubdiviedElement2=-1;
171 if (IdSubdiviedElement1==-1){
172 IdSubdiviedElement1=i;
200 IdSubdiviedElement2=i;
237 LocMesh->
Edges[IdSubdiviedEdge].
V1=IdNgbhVortex1;
238 LocMesh->
Edges[IdSubdiviedEdge].
V2=IdNewVortex;
240 LocMesh->
Edges[IdNewEdge1].
V1=IdNewVortex;
241 LocMesh->
Edges[IdNewEdge1].
V2=IdNgbhVortex2;
244 LocMesh->
Edges[IdNewEdge2].
V1=IdNewVortex;
245 LocMesh->
Edges[IdNewEdge2].
V2=IdNgbhVortex4;
248 LocMesh->
Edges[IdNewEdge3].
V1=IdNewVortex;
249 LocMesh->
Edges[IdNewEdge3].
V2=IdNgbhVortex3;
254 LocMesh->
Elements[IdSubdiviedElement1].
E1=IdSubdiviedEdge;
255 LocMesh->
Elements[IdSubdiviedElement1].
E2=IdNewEdge3;
256 LocMesh->
Elements[IdSubdiviedElement1].
E3=IdNgbhEdge1;
258 LocMesh->
Elements[IdSubdiviedElement2].
E1=IdNgbhEdge2;
259 LocMesh->
Elements[IdSubdiviedElement2].
E2=IdNewEdge2;
260 LocMesh->
Elements[IdSubdiviedElement2].
E3=IdSubdiviedEdge;
262 LocMesh->
Elements[IdNewElement1].
E1=IdNewEdge1;
263 LocMesh->
Elements[IdNewElement1].
E2=IdNgbhEdge3;
264 LocMesh->
Elements[IdNewElement1].
E3=IdNewEdge3;
266 LocMesh->
Elements[IdNewElement2].
E1=IdNgbhEdge4;
267 LocMesh->
Elements[IdNewElement2].
E2=IdNewEdge1;
268 LocMesh->
Elements[IdNewElement2].
E3=IdNewEdge2;
Represents a vertex in the mesh.
int main |
( |
int |
argc, |
|
|
char ** |
argv |
|
) |
| |
Definition at line 622 of file MeshSphericalshell.c.
References CreateBasicCubicMesh(), ProjectMeshSphereAndRefine(), usage(), and WriteMesh().
625 char *output_name =
"toto.xml";
635 if ((ok == 0) && (strcmp(argv[1],
"help") == 0)) {
638 if ((ok == 0) && (strcmp(argv[1],
"-NameFile") == 0)) {
641 output_name = argv[1];
646 if ((ok == 0) && (strcmp(argv[1],
"-Radius") == 0)) {
649 Radius = atof(argv[1]);
650 if (Radius<0) Radius=1.;
655 if ((ok == 0) && (strcmp(argv[1],
"-MaxLength") == 0)) {
658 Prec = atof(argv[1]);
659 if ((Prec<Radius*0.001)) Prec=Radius*0.001;
664 if ((ok == 0) && (strcmp(argv[1],
"-NbSubdiv") == 0)) {
667 NbSubdiv = atoi(argv[1]);
668 if ((NbSubdiv<1)) NbSubdiv=1;
674 printf(
"Unknown option: \n");
679 printf(
"Output file: %s / Radius: %lf / Precision: %lf / Subdivisions: %d\n",output_name,Radius,Prec,NbSubdiv);
Mesh CreateBasicCubicMesh()
void ProjectMeshSphereAndRefine(Mesh *LocMesh, double R, double MaxEdgeLength, int NbSubdiv)
void WriteMesh(Mesh *LocMesh, char FileName[256])
void MakeClockwiseOrder |
( |
Mesh * |
LocMesh | ) |
|
Definition at line 311 of file MeshSphericalshell.c.
References Element::E1, Element::E2, Element::E3, Mesh::Edges, Mesh::Elements, Mesh::NbElements, Edge::NbSubdiv, Edge::SubiVertex, Edge::V1, Edge::V2, Mesh::Vertexes, Vertex::X, Vertex::Y, and Vertex::Z.
Referenced by WriteMesh().
313 int Ve1,Ed1,Ve2,Ed2,Ve3,Ed3;
315 double x1,x2,x3,y1,y2,y3,z1,z2,z3;
316 double u1,u2,u3,v1,v2,v3;
328 temp=Ed2; Ed2=Ed3; Ed3=temp;
354 printf(
"This is not good!!!\n");
362 u1=x2-x1; u2=y2-y1; u3=z2-z1;
363 v1=x3-x1; v2=y3-y1; v3=z3-z1;
372 if (x1*vp1+y1*vp2+z1*vp3<0){
374 temp=Ed3; Ed3=Ed2; Ed2=temp;
void ProjectMeshSphere |
( |
Mesh * |
LocMesh, |
|
|
double |
R |
|
) |
| |
Definition at line 272 of file MeshSphericalshell.c.
References Mesh::NbVertexes, Mesh::Vertexes, Vertex::X, Vertex::Y, and Vertex::Z.
Referenced by ProjectMeshSphereAndRefine().
274 double Xmax,Xmin,Ymax,Ymin,Zmax,Zmin,Xmean,Ymean,Zmean;
void ProjectMeshSphereAndRefine |
( |
Mesh * |
LocMesh, |
|
|
double |
R, |
|
|
double |
MaxEdgeLength, |
|
|
int |
NbSubdiv |
|
) |
| |
Definition at line 428 of file MeshSphericalshell.c.
References CutEdge(), Mesh::Edges, Nektar::for(), Mesh::NbEdges, Edge::NbSubdiv, ProjectMeshSphere(), Edge::SubiVertex, Edge::V1, Edge::V2, Mesh::Vertexes, Vertex::X, Vertex::Y, and Vertex::Z.
Referenced by main().
431 double SqLengthI,SqLengthJ;
437 double EdgeV1_X,EdgeV1_Y,EdgeV1_Z,EdgeV2_X,EdgeV2_Y,EdgeV2_Z;
440 order=(
int*)malloc(LocMesh->
NbEdges*
sizeof(
int));
441 for (i=0;i<LocMesh->
NbEdges;i++) order[i]=i;
451 order=(
int*)realloc(order,LocMesh->
NbEdges*
sizeof(
int));
452 for (i=0;i<LocMesh->
NbEdges;i++) order[i]=i;
455 for (i=0;i<LocMesh->
NbEdges-1;i++)
for (j=i+1;j<LocMesh->
NbEdges;j++){
463 if (SqLengthI<SqLengthJ){ k=order[i]; order[i]=order[j]; order[j]=k;}
468 for (i=0;i<OrigNbEdges;i++){
473 if (sqrt(SqLengthI)>MaxEdgeLength){
488 for (i=0;i<LocMesh->
NbEdges;i++){
506 LocMesh->
Edges[i].
SubiVertex[j].
X=EdgeV1_X*(dNbSubdiv-dj)/dNbSubdiv+EdgeV2_X*dj/dNbSubdiv;
507 LocMesh->
Edges[i].
SubiVertex[j].
Y=EdgeV1_Y*(dNbSubdiv-dj)/dNbSubdiv+EdgeV2_Y*dj/dNbSubdiv;
508 LocMesh->
Edges[i].
SubiVertex[j].
Z=EdgeV1_Z*(dNbSubdiv-dj)/dNbSubdiv+EdgeV2_Z*dj/dNbSubdiv;
for(iterator iter=lhs.begin();iter!=lhs.end();++iter)
void ProjectMeshSphere(Mesh *LocMesh, double R)
Represents a vertex in the mesh.
void CutEdge(Mesh *LocMesh, int IdEdge)
void RefineMesh |
( |
Mesh * |
LocMesh | ) |
|
Definition at line 394 of file MeshSphericalshell.c.
References CutEdge(), Mesh::Edges, Mesh::NbEdges, Edge::V1, Edge::V2, Mesh::Vertexes, Vertex::X, Vertex::Y, and Vertex::Z.
397 double SqLengthI,SqLengthJ;
400 order=(
int*)malloc(LocMesh->
NbEdges*
sizeof(
int));
402 for (i=0;i<LocMesh->
NbEdges;i++) order[i]=i;
404 for (i=0;i<LocMesh->
NbEdges-1;i++)
405 for (j=i+1;j<LocMesh->
NbEdges;j++){
413 if (SqLengthI<SqLengthJ){
421 for (i=0;i<OrigNbEdges;i++)
CutEdge(LocMesh,order[i]);
void CutEdge(Mesh *LocMesh, int IdEdge)
Definition at line 611 of file MeshSphericalshell.c.
Referenced by main().
613 printf(
"Usage: makeSphereNektar <options>\n");
614 printf(
"Where <options> are one or more of the following:\n");
615 printf(
"\t<-NameFile n> Name of the output file containg the sphere (default=\"toto.xml\")\n");
616 printf(
"\t<-Radius n> Radius of the sphere (default=1.)\n");
617 printf(
"\t<-MaxLength n> Maximum length allowed for an edge (default=0.5)\n");
618 printf(
"\t<-NbSubdiv n> Number of subdivisions of each edge to make it curved (default=1)\n");
void WriteMesh |
( |
Mesh * |
LocMesh, |
|
|
char |
FileName[256] |
|
) |
| |
Definition at line 524 of file MeshSphericalshell.c.
References Element::E1, Element::E2, Element::E3, Mesh::Edges, Mesh::Elements, MakeClockwiseOrder(), Mesh::NbEdges, Mesh::NbElements, Edge::NbSubdiv, Mesh::NbVertexes, Edge::SubiVertex, Edge::V1, Edge::V2, Mesh::Vertexes, Vertex::X, Vertex::Y, and Vertex::Z.
Referenced by main().
525 FILE * XmlMeshGeomFile;
526 int i,j,NbCurvedEdge;
532 XmlMeshGeomFile = fopen(FileName,
"w");
535 fprintf(XmlMeshGeomFile,
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
536 fprintf(XmlMeshGeomFile,
"\n");
537 fprintf(XmlMeshGeomFile,
"<NEKTAR>\n");
538 fprintf(XmlMeshGeomFile,
"<!-- Embed a 2-dimensional object in a 2-dimensional space -->\n");
539 fprintf(XmlMeshGeomFile,
"<!-- DIM <= SPACE -->\n");
540 fprintf(XmlMeshGeomFile,
"<!-- This provides a method of optimizing code for a 1-D curve embedded in 3-space. -->\n");
541 fprintf(XmlMeshGeomFile,
"<GEOMETRY DIM=\"2\" SPACE=\"3\">\n");
542 fprintf(XmlMeshGeomFile,
"\n");
545 fprintf(XmlMeshGeomFile,
" <VERTEX>\n");
546 fprintf(XmlMeshGeomFile,
" <!-- Always must have four values per entry. -->\n");
549 fprintf(XmlMeshGeomFile,
" </VERTEX>\n");
550 fprintf(XmlMeshGeomFile,
" \n");
553 fprintf(XmlMeshGeomFile,
" <EDGE>\n");
554 fprintf(XmlMeshGeomFile,
" <!--Edges are vertex pairs -->\n");
555 for (i=0;i<LocMesh->
NbEdges;i++)
556 fprintf(XmlMeshGeomFile,
" <E ID=\"%d\"> %d %d </E>\n",i,LocMesh->
Edges[i].
V1,LocMesh->
Edges[i].
V2);
557 fprintf(XmlMeshGeomFile,
" </EDGE>\n");
558 fprintf(XmlMeshGeomFile,
" \n");
561 fprintf(XmlMeshGeomFile,
" <ELEMENT>\n");
564 fprintf(XmlMeshGeomFile,
" </ELEMENT>\n");
565 fprintf(XmlMeshGeomFile,
" \n");
570 fprintf(XmlMeshGeomFile,
" <CURVED>\n");
573 fprintf(XmlMeshGeomFile,
" <E ID=\"%d\" EDGEID=\"%d\" TYPE=\"PolyEvenlySpaced\" NUMPOINTS=\"%d\">\n",NbCurvedEdge,i,LocMesh->
Edges[i].
NbSubdiv+1);
577 fprintf(XmlMeshGeomFile,
" </E>\n\n");
580 fprintf(XmlMeshGeomFile,
" </CURVED>\n");
584 fprintf(XmlMeshGeomFile,
"<!-- V - vertex, E - edge, F - face, L - element -->\n");
585 fprintf(XmlMeshGeomFile,
" <COMPOSITE>\n");
586 fprintf(XmlMeshGeomFile,
" <C ID=\"0\"> T[0-%d]\n",LocMesh->
NbElements-1);
587 fprintf(XmlMeshGeomFile,
" </C>\n");
588 fprintf(XmlMeshGeomFile,
" <C ID=\"1\"> E[2,3,4,5,7,8]\n");
589 fprintf(XmlMeshGeomFile,
" </C>\n");
590 fprintf(XmlMeshGeomFile,
" </COMPOSITE>\n");
591 fprintf(XmlMeshGeomFile,
" \n");
592 fprintf(XmlMeshGeomFile,
" <DOMAIN> C[0] </DOMAIN>\n");
593 fprintf(XmlMeshGeomFile,
" \n");
596 fprintf(XmlMeshGeomFile,
"</GEOMETRY>\n");
599 fclose(XmlMeshGeomFile);
void MakeClockwiseOrder(Mesh *LocMesh)