Skip to content

Commit 8dc400d

Browse files
committed
add delta wing test driver
1 parent 0191626 commit 8dc400d

File tree

2 files changed

+190
-0
lines changed

2 files changed

+190
-0
lines changed

test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ test_exe_func(xgc_split xgc_split.cc)
168168
test_exe_func(ma_insphere ma_insphere.cc)
169169
test_exe_func(ma_test ma_test.cc)
170170
test_exe_func(aniso_ma_test aniso_ma_test.cc)
171+
test_exe_func(anisoDelta_ma_test anisoDelta_ma_test.cc)
171172
test_exe_func(torus_ma_test torus_ma_test.cc)
172173
test_exe_func(dg_ma_test dg_ma_test.cc)
173174
test_exe_func(prismCodeMatch ../ma/prismCodeMatch.cc)

test/anisoDelta_ma_test.cc

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
#include "ma.h"
2+
#include <apf.h>
3+
#include <gmi_mesh.h>
4+
#include <gmi_null.h>
5+
#include <apfMDS.h>
6+
#include <apfShape.h>
7+
#include <apfField.h>
8+
#include <PCU.h>
9+
#include <lionPrint.h>
10+
#include <pcu_util.h>
11+
#include "pumi.h"
12+
#include <apfMatrix.h>
13+
14+
#include <stdlib.h>
15+
#include "maStats.h"
16+
#include <iostream>
17+
#include <fstream>
18+
#include <sstream>
19+
20+
//TODO commented blocks are for setting the input size and frames
21+
/*
22+
void getValue(ma::Mesh *m, ma::Entity* v, ma::Matrix& R, ma::Vector& H) {
23+
auto targetMetric = m->findField("target_metric");
24+
PCU_ALWAYS_ASSERT(targetMetric);
25+
int nComps = targetMetric->countComponents();
26+
auto vals = new double[nComps];
27+
apf::getComponents(targetMetric, v, 0, vals);
28+
auto scale = 1e4;
29+
vals[0] = vals[0]/scale;
30+
vals[1] = vals[1]/scale;
31+
vals[2] = vals[2]/scale;
32+
vals[3] = vals[3]/scale;
33+
vals[4] = vals[4]/scale;
34+
vals[5] = vals[5]/scale;
35+
ma::Matrix M(vals[0], vals[3], vals[5],
36+
vals[3], vals[1], vals[4],
37+
vals[5], vals[4], vals[2]);
38+
39+
double eigenValues[3];
40+
ma::Vector eigenVectors[3];
41+
apf::eigen(M, eigenVectors, eigenValues);
42+
ma::Matrix RT(eigenVectors); // eigen vectors are stored in the rows of RT
43+
RT[0] = RT[0].normalize();
44+
RT[1] = RT[1] - RT[0]*(RT[0]*RT[1]);
45+
RT[1] = RT[1].normalize();
46+
RT[2] = apf::cross(RT[0],RT[1]);
47+
R = apf::transpose(RT);
48+
49+
double h[3];
50+
for (int i = 0; i < 3; ++i)
51+
h[i] = std::sqrt(1.0/(eigenValues[i]*scale));
52+
H = ma::Vector(h);
53+
delete [] vals;
54+
}
55+
*/
56+
57+
class AnIso : public ma::AnisotropicFunction {
58+
public:
59+
AnIso(ma::Mesh* m) {
60+
mesh = m;
61+
ma::getBoundingBox(m,lower,upper);
62+
targetMetric = m->findField("target_metric");
63+
PCU_ALWAYS_ASSERT(targetMetric);
64+
int nComps = targetMetric->countComponents();
65+
vals = new double[nComps];
66+
}
67+
~AnIso() {
68+
delete [] vals;
69+
}
70+
virtual void getValue(ma::Entity* v, ma::Matrix& R, ma::Vector& H) {
71+
apf::getComponents(targetMetric, v, 0, vals);
72+
auto scale = 1e4;
73+
vals[0] = vals[0]/scale;
74+
vals[1] = vals[1]/scale;
75+
vals[2] = vals[2]/scale;
76+
vals[3] = vals[3]/scale;
77+
vals[4] = vals[4]/scale;
78+
vals[5] = vals[5]/scale;
79+
ma::Matrix M(vals[0], vals[3], vals[5],
80+
vals[3], vals[1], vals[4],
81+
vals[5], vals[4], vals[2]);
82+
83+
double eigenValues[3];
84+
ma::Vector eigenVectors[3];
85+
apf::eigen(M, eigenVectors, eigenValues);
86+
ma::Matrix RT(eigenVectors); // eigen vectors are stored in the rows of RT
87+
RT[0] = RT[0].normalize();
88+
RT[1] = RT[1] - RT[0]*(RT[0]*RT[1]);
89+
RT[1] = RT[1].normalize();
90+
RT[2] = apf::cross(RT[0],RT[1]);
91+
R = apf::transpose(RT);
92+
93+
double h[3];
94+
for (int i = 0; i < 3; ++i)
95+
h[i] = std::sqrt(1.0/(eigenValues[i]*scale));
96+
H = ma::Vector(h);
97+
}
98+
private:
99+
ma::Mesh* mesh;
100+
ma::Vector lower;
101+
ma::Vector upper;
102+
apf::Field* targetMetric;
103+
double* vals;
104+
};
105+
106+
int main(int argc, char** argv) {
107+
PCU_ALWAYS_ASSERT(argc == 3);
108+
const char *modelFile = argv[1];
109+
const char *meshFile = argv[2];
110+
bool logInterpolation = true;
111+
MPI_Init(&argc, &argv);
112+
PCU_Comm_Init ();
113+
lion_set_verbosity (1);
114+
gmi_register_mesh ();
115+
gmi_register_null ();
116+
ma::Mesh* m = apf::loadMdsMesh (modelFile, meshFile);
117+
auto targetMetric = m->findField ("target_metric");
118+
PCU_ALWAYS_ASSERT (targetMetric);
119+
m->verify();
120+
apf::writeVtkFiles ("anisoDelta_before",m);
121+
122+
/*
123+
apf::MeshEntity* ent;
124+
apf::MeshIterator* it;
125+
126+
apf::Field* sizes = apf::createField(m, "sizes", apf::VECTOR, apf::getLagrange(1));
127+
apf::Field* frames = apf::createField(m, "frames", apf::MATRIX, apf::getLagrange(1));
128+
it = m->begin(0);
129+
while( (ent = m->iterate(it)) ) {
130+
apf::Vector3 sz; // use what your have to get this H
131+
apf::Matrix3x3 frm; // use what you have to get this R
132+
getValue(ent, frm, sz);
133+
apf::setVector(sizes, ent, 0, sz);
134+
apf::setMatrix(frames, ent, 0, frm);
135+
}
136+
m->end(it);
137+
138+
ma::Input *in = ma::configure(m, sizes, frames, 0, true);
139+
*/
140+
141+
AnIso sf (m);
142+
// the metrics should be given as input using sizes and frames same as
143+
// test/highOrderSizeFields.cc
144+
ma::Input* in = ma::makeAdvanced(ma::configure (m, &sf, 0, logInterpolation));
145+
in-> shouldRunPreZoltan = true;
146+
in-> shouldRunPostZoltan = true;
147+
in-> shouldRunMidParma = false;
148+
in-> shouldRunPostParma = false;
149+
in-> shouldRefineLayer = false;
150+
in-> goodQuality = 0.027;
151+
152+
in->maximumIterations = 10;
153+
154+
ma::adaptVerbose (in);
155+
m-> verify ();
156+
157+
std::vector<double> lengths;
158+
std::vector<double> qualities;
159+
in = ma::makeAdvanced(ma::configure (m, &sf, 0, logInterpolation));
160+
ma::stats(m, in->sizeField, lengths, qualities, true);// we need to define
161+
// the size fields in order to get the lengths and qualities
162+
163+
std::ostringstream len_fileNameStream;
164+
len_fileNameStream << "lengths_" << PCU_Comm_Self() << ".txt";
165+
std::string len_fileName = len_fileNameStream.str();
166+
std::ofstream len_file;
167+
len_file.open (len_fileName.c_str());
168+
for(std::size_t i = 0; i < lengths.size(); ++i) {
169+
len_file << lengths[i] << "\n";
170+
}
171+
len_file.close();
172+
173+
std::ostringstream qua_fileNameStream;
174+
qua_fileNameStream << "qualities_" << PCU_Comm_Self() << ".txt";
175+
std::string qua_fileName = qua_fileNameStream.str();
176+
std::ofstream qua_file;
177+
qua_file.open (qua_fileName.c_str());
178+
for(std::size_t i = 0; i < qualities.size(); ++i) {
179+
qua_file << qualities[i] << "\n";
180+
}
181+
qua_file.close();
182+
183+
apf::writeVtkFiles ("anisoDelta_after",m);
184+
185+
m->destroyNative ();
186+
apf::destroyMesh (m);
187+
PCU_Comm_Free ();
188+
MPI_Finalize ();
189+
}

0 commit comments

Comments
 (0)