1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
|
#include <mystdlib.h>
#include "meshing.hpp"
namespace netgen
{
// A special function for Hermann Landes, Erlangen
void CutOffAndCombine (Mesh & mesh, const Mesh & othermesh)
{
int i, j;
int nse = othermesh.GetNSE();
int onp = othermesh.GetNP();
int ne = mesh.GetNE();
PrintMessage (1, "other mesh has ",
othermesh.GetNP(), " points, ",
othermesh.GetNSE(), " surface elements.");
NgArray<Box3d> otherbounds(nse);
Box3d otherbox;
double maxh = 0;
for (i = 1; i <= nse; i++)
{
const Element2d & sel = othermesh.SurfaceElement(i);
sel.GetBox(othermesh.Points(), otherbounds.Elem(i));
double loch = othermesh.GetH (othermesh.Point (sel.PNum(1)));
otherbounds.Elem(i).Increase(loch);
if (loch > maxh) maxh = loch;
}
otherbox.SetPoint (othermesh.Point(1));
for (i = 1; i <= othermesh.GetNP(); i++)
otherbox.AddPoint (othermesh.Point(i));
otherbox.Increase (maxh);
for (i = 1; i <= ne; i++)
{
Box3d box;
int remove = 0;
const Element & el = mesh.VolumeElement(i);
el.GetBox(mesh.Points(), box);
if (i % 10000 == 0)
cout << "+" << flush;
if (box.Intersect(otherbox))
{
for (j = 1; j <= nse && !remove; j++)
if (box.Intersect(otherbounds.Get(j)))
remove = 1;
}
if (remove)
mesh.VolumeElement(i).Delete();
}
cout << endl;
TBitArray<PointIndex> connected(mesh.GetNP());
connected.Clear();
for (i = 1; i <= mesh.GetNSE(); i++)
{
const Element2d & el = mesh.SurfaceElement(i);
for (j = 1; j <= 3; j++)
connected.SetBit(el.PNum(j));
}
bool changed;
do
{
changed = 0;
for (i = 1; i <= mesh.GetNE(); i++)
{
const Element & el = mesh.VolumeElement(i);
int has = 0, hasnot = 0;
if (el[0])
{
for (j = 0; j < 4; j++)
{
if (connected.Test(el[j]))
has = 1;
else
hasnot = 1;
}
if (has && hasnot)
{
changed = 1;
for (j = 0; j < 4; j++)
connected.SetBit (el[j]);
}
}
}
cout << "." << flush;
}
while (changed);
cout << endl;
for (i = 1; i <= mesh.GetNE(); i++)
{
const Element & el = mesh.VolumeElement(i);
int hasnot = 0;
if (el[0])
{
for (j = 0; j < 4; j++)
{
if (!connected.Test(el[j]))
hasnot = 1;
}
if (hasnot)
mesh.VolumeElement(i).Delete();
}
}
mesh.Compress();
mesh.FindOpenElements();
TBitArray<PointIndex> locked(mesh.GetNP());
locked.Set();
for (i = 1; i <= mesh.GetNOpenElements(); i++)
for (j = 1; j <= 3; j++)
locked.Clear (mesh.OpenElement(i).PNum(j));
// for (PointIndex i (1); i <= locked.Size(); i++)
for (PointIndex i : locked.Range())
if (locked.Test(i))
{
mesh.AddLockedPoint (i);
}
NgArray<PointIndex> pmat(onp);
for (i = 1; i <= onp; i++)
pmat.Elem(i) = mesh.AddPoint (othermesh.Point(i));
int fnum =
mesh.AddFaceDescriptor (FaceDescriptor(0,0,1,0));
for (i = 1; i <= othermesh.GetNSE(); i++)
{
Element2d tri = othermesh.SurfaceElement(i);
for (j = 1; j <= 3; j++)
tri.PNum(j) = pmat.Get(tri.PNum(j));
tri.SetIndex(fnum);
mesh.AddSurfaceElement (tri);
}
for (i = 1; i <= onp; i++)
mesh.AddLockedPoint (pmat.Elem(i));
mesh.CalcSurfacesOfNode();
mesh.CalcLocalH(0.3);
}
void HelmholtzMesh (Mesh & mesh)
{
int i;
double ri, ra, rinf;
cout << "ri = ";
cin >> ri;
cout << "ra = ";
cin >> ra;
cout << "rinf = ";
cin >> rinf;
double det = ri * ra * rinf - ri * ri * rinf;
double a = (ri - rinf) / det;
double b = (ri*ri - ra * rinf) / det;
for (i = 1; i <= mesh.GetNP(); i++)
{
Point<3> & p = mesh.Point(i);
double rold = sqrt (sqr(p(0)) + sqr(p(1)) + sqr(p(2)));
if (rold < ri) continue;
double rnew = 1 / (a * rold - b);
double fac = rnew / rold;
p(0) *= fac;
p(1) *= fac;
p(2) *= fac;
}
}
}
|