Skip to content

Commit 047adac

Browse files
committed
Implemented alignment to PIV field. It compiles but it needs to be tested.
1 parent 9b56026 commit 047adac

6 files changed

+209
-86
lines changed

CMakeBoostSetup.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ set(Boost_USE_MULTITHREAD "OFF")
4444
set(Boost_ADDITIONAL_VERSIONS "1.55.0" "1.55" "1.54" "1.54.0" "1.53" "1.53.0" "1.52" "1.52.0" "1.51" "1.51.0" "1.50" "1.50.0" "1.49" "1.49.0" "1.48" "1.48.0" "1.48.0.2" "1.47" "1.47.0" "1.46.1" "1.46" "1.46.0" "1.45" "1.45.0" "1.44" "1.44.0" "1.42" "1.42.0" "1.41.0" "1.41" "1.40.0" "1.40" "1.39.0" "1.39" "1.38.0")
4545

4646
# first, see if we can get any supported version of Boost
47-
find_package(Boost COMPONENTS regex iostreams REQUIRED)
47+
find_package(Boost COMPONENTS regex iostreams filesystem REQUIRED)
4848

4949

5050
# if we get boost 1.35 or greater, we need to get the system library too

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ include (CMakeCGALSetup.txt)
6363

6464
################################
6565
## Define common libraries used by every target in MEMBRANE
66-
set(BOOST_LIBS ${Boost_REGEX_LIBRARY} ${Boost_IOSTREAMS_LIBRARY} )
66+
set(BOOST_LIBS ${Boost_REGEX_LIBRARY} ${Boost_IOSTREAMS_LIBRARY} ${Boost_FILESYSTEM_LIBRARY} )
6767
set(GSL_LIBS ${GSL_LIBRARIES})
6868
set(MATH_LIB -lm)
6969
set(SAMoS_LIBS ${GSL_LIBS} ${MATH_LIB} ${BOOST_LIBS} ${VTK_LIBS})

src/aligner/external/external_piv_aligner.cpp

+66-21
Original file line numberDiff line numberDiff line change
@@ -33,39 +33,84 @@
3333
void ExternalPIVAlign::compute()
3434
{
3535
int N = m_system->size();
36-
double hx = m_hx, hy = m_hy, hz = m_hz;
37-
38-
for (int i = 0; i < N; i++)
36+
double gamma = m_gamma;
37+
double dx = (m_xhi - m_xlow)/(m_nx-1), dy = (m_yhi - m_ylow)/(m_ny - 1);
38+
39+
double t = static_cast<double>(m_step_counter) / static_cast<double>(m_n_piv_steps);
40+
for (int i = 0; i < N; i++)
3941
{
4042
Particle& pi = m_system->get_particle(i);
4143
if (m_has_params)
44+
gamma = m_type_params[pi.get_type()-1].gamma;
45+
if (pi.x > m_xhi || pi.x < m_xlow || pi.y > m_yhi || pi.y < m_ylow)
46+
throw runtime_error("One of the cells is outside the PIV mesh range. Please confien the system or make a larger PIV mesh");
47+
48+
int I = int((pi.x - m_xlow) / dx);
49+
int J = int((pi.y - m_ylow) / dy);
50+
51+
double u_c = m_u[m_piv_frame_counter].piv_data[I][J], u_n = m_u[m_piv_frame_counter + 1].piv_data[I][J];
52+
double v_c = m_v[m_piv_frame_counter].piv_data[I][J], v_n = m_v[m_piv_frame_counter + 1].piv_data[I][J];
53+
54+
double u = t * u_c + (1.0 - t) * u_n;
55+
double v = t * v_c + (1.0 - t) * v_n;
56+
57+
double vel = sqrt(u * u + v * v);
58+
if (vel > 0.0)
4259
{
43-
hx = m_type_params[pi.get_type()-1].hx;
44-
hy = m_type_params[pi.get_type()-1].hy;
45-
hz = m_type_params[pi.get_type()-1].hz;
60+
u *= gamma/vel;
61+
v *= gamma/vel;
4662
}
47-
pi.tau_x += hy*pi.nz - hz*pi.ny;
48-
pi.tau_y += hz*pi.nx - hx*pi.nz;
49-
pi.tau_z += hx*pi.ny - hy*pi.nx;
63+
pi.tau_z += u*pi.ny - v*pi.nx;
64+
5065
}
66+
m_step_counter++;
67+
if (m_step_counter % m_n_piv_steps == 0)
68+
{
69+
m_piv_frame_counter++;
70+
m_step_counter = 0;
71+
}
72+
if (m_piv_frame_counter >= m_u.size())
73+
throw runtime_error("Simulation time exceeded avaliable PIV snapshots.");
5174
}
5275

5376
// Private member function
54-
void ExternalPIVAlign::__read_csv(const string & fame, PIVData & data)
77+
void ExternalPIVAlign::__read_csv(const string & fname, PIVData & data)
5578
{
56-
ifstream f(fname.c_str());
57-
while (f.good())
79+
std::ifstream f(fname.c_str());
80+
if (f)
5881
{
59-
string line;
60-
getline(f, line);
61-
if (line.length() > 0)
82+
while (f.good())
6283
{
63-
istringstream buffer(line);
64-
string sval;
65-
vector<double> fline;
66-
while (getline(buffer, sval, ','))
67-
fline.push_back(stod(sval));
68-
data.piv_data.push_back(fline);
84+
string line;
85+
std::getline(f, line);
86+
if (line.length() > 0)
87+
{
88+
std::istringstream buffer(line);
89+
string sval;
90+
vector<double> fline;
91+
while (getline(buffer, sval, ','))
92+
fline.push_back(stod(sval));
93+
data.piv_data.push_back(fline);
94+
}
6995
}
7096
}
97+
else
98+
{
99+
throw runtime_error("Could not open file " + fname + ".");
100+
}
101+
}
102+
103+
// Get a list of all files matching base name
104+
void ExternalPIVAlign::__get_file_list(const string & base_name, vector<string> & all_matching_files)
105+
{
106+
const boost::regex filter(base_name + ".*\\."+m_ext);
107+
directory_iterator end_itr;
108+
for(directory_iterator i(m_path); i != end_itr; ++i)
109+
{
110+
if( !is_regular_file(i->status()) ) continue;
111+
boost::smatch what;
112+
if( !boost::regex_match(i->path().filename().string(), what, filter) ) continue;
113+
all_matching_files.push_back(m_path+i->path().filename().string());
114+
}
115+
sort(all_matching_files.begin(), all_matching_files.end());
71116
}

0 commit comments

Comments
 (0)