Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Precomputed velocities #202 #208

Merged
merged 12 commits into from
Apr 2, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 71 additions & 70 deletions Code/Source/svFSI/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,95 +85,96 @@

}

/// @brief Iterate the simulation in time.
///
/// Reproduces the outer and inner loops in Fortan MAIN.f.
//


/// @brief Iterate the precomputed state-variables in time using linear interpolation to the current time step size
///
//
void iterate_precomputed_time(Simulation* simulation) {
using namespace consts;
using namespace consts;

auto& com_mod = simulation->com_mod;
auto& cm_mod = simulation->cm_mod;
auto& cm = com_mod.cm;
auto& cep_mod = simulation->get_cep_mod();
auto& com_mod = simulation->com_mod;
auto& cm_mod = simulation->cm_mod;
auto& cm = com_mod.cm;
auto& cep_mod = simulation->get_cep_mod();

int nTS = com_mod.nTS;
int stopTS = nTS;
int tDof = com_mod.tDof;
int tnNo = com_mod.tnNo;
int nFacesLS = com_mod.nFacesLS;
int nsd = com_mod.nsd;
int nTS = com_mod.nTS;
int stopTS = nTS;
int tDof = com_mod.tDof;
int tnNo = com_mod.tnNo;
int nFacesLS = com_mod.nFacesLS;
int nsd = com_mod.nsd;

auto& Ad = com_mod.Ad; // Time derivative of displacement
auto& Rd = com_mod.Rd; // Residual of the displacement equation
auto& Kd = com_mod.Kd; // LHS matrix for displacement equation
auto& Ad = com_mod.Ad; // Time derivative of displacement
auto& Rd = com_mod.Rd; // Residual of the displacement equation
auto& Kd = com_mod.Kd; // LHS matrix for displacement equation

auto& Ao = com_mod.Ao; // Old time derivative of variables (acceleration)
auto& Yo = com_mod.Yo; // Old variables (velocity)
auto& Do = com_mod.Do; // Old integrated variables (dissplacement)
auto& Ao = com_mod.Ao; // Old time derivative of variables (acceleration)
auto& Yo = com_mod.Yo; // Old variables (velocity)
auto& Do = com_mod.Do; // Old integrated variables (dissplacement)

auto& An = com_mod.An; // New time derivative of variables
auto& Yn = com_mod.Yn; // New variables (velocity)
auto& Dn = com_mod.Dn; // New integrated variables
auto& An = com_mod.An; // New time derivative of variables
auto& Yn = com_mod.Yn; // New variables (velocity)
auto& Dn = com_mod.Dn; // New integrated variables

int& cTS = com_mod.cTS;
int& nITs = com_mod.nITs;
double& dt = com_mod.dt;
int& cTS = com_mod.cTS;
int& nITs = com_mod.nITs;
double& dt = com_mod.dt;

if (com_mod.usePrecomp) {
if (com_mod.usePrecomp) {
#ifdef debug_iterate_solution
dmsg << "Use precomputed values ..." << std::endl;
#endif
// This loop is used to interpolate between known time values of the precomputed
// state-variable solution
for (int l = 0; l < com_mod.nMsh; l++) {
auto lM = com_mod.msh[l];
if (lM.Ys.nslices() > 1) {
// If there is only one temporal slice, then the solution is assumed constant
// in time and no interpolation is performed
// If there are multiple temporal slices, then the solution is linearly interpolated
// between the known time values and the current time.
double precompDt = com_mod.precompDt;
double preTT = precompDt * (lM.Ys.nslices() - 1);
double cT = cTS * dt;
double rT = std::fmod(cT, preTT);
int n1, n2;
double alpha;
if (precompDt == dt) {
alpha = 0.0;
if (cTS < lM.Ys.nslices()) {
n1 = cTS - 1;
} else {
n1 = cTS % lM.Ys.nslices() - 1;
}
} else {
n1 = static_cast<int>(rT / precompDt) - 1;
alpha = std::fmod(rT, precompDt);
}
n2 = n1 + 1;
for (int i = 0; i < tnNo; i++) {
for (int j = 0; j < nsd; j++) {
if (alpha == 0.0) {
Yn(j, i) = lM.Ys(j, i, n2);
} else {
Yn(j, i) = (1.0 - alpha) * lM.Ys(j, i, n1) + alpha * lM.Ys(j, i, n2);
}
}
}
// This loop is used to interpolate between known time values of the precomputed
// state-variable solution
for (int l = 0; l < com_mod.nMsh; l++) {
auto lM = com_mod.msh[l];
if (lM.Ys.nslices() > 1) {
zasexton marked this conversation as resolved.
Show resolved Hide resolved
// If there is only one temporal slice, then the solution is assumed constant
// in time and no interpolation is performed
// If there are multiple temporal slices, then the solution is linearly interpolated
// between the known time values and the current time.
double precompDt = com_mod.precompDt;
double preTT = precompDt * (lM.Ys.nslices() - 1);
double cT = cTS * dt;
double rT = std::fmod(cT, preTT);
int n1, n2;
double alpha;
if (precompDt == dt) {
alpha = 0.0;
if (cTS < lM.Ys.nslices()) {
n1 = cTS - 1;
} else {
n1 = cTS % lM.Ys.nslices() - 1;

Check warning on line 147 in Code/Source/svFSI/main.cpp

View check run for this annotation

Codecov / codecov/patch

Code/Source/svFSI/main.cpp#L147

Added line #L147 was not covered by tests
}
} else {
n1 = static_cast<int>(rT / precompDt) - 1;
alpha = std::fmod(rT, precompDt);

Check warning on line 151 in Code/Source/svFSI/main.cpp

View check run for this annotation

Codecov / codecov/patch

Code/Source/svFSI/main.cpp#L150-L151

Added lines #L150 - L151 were not covered by tests
}
n2 = n1 + 1;
for (int i = 0; i < tnNo; i++) {
for (int j = 0; j < nsd; j++) {
if (alpha == 0.0) {
Yn(j, i) = lM.Ys(j, i, n2);
} else {
for (int i = 0; i < tnNo; i++) {
for (int j = 0; j < nsd; j++) {
Yn(j, i) = lM.Ys(j, i, 0);
}
}
Yn(j, i) = (1.0 - alpha) * lM.Ys(j, i, n1) + alpha * lM.Ys(j, i, n2);

Check warning on line 159 in Code/Source/svFSI/main.cpp

View check run for this annotation

Codecov / codecov/patch

Code/Source/svFSI/main.cpp#L159

Added line #L159 was not covered by tests
}
}
}
} else {
for (int i = 0; i < tnNo; i++) {
for (int j = 0; j < nsd; j++) {
Yn(j, i) = lM.Ys(j, i, 0);

Check warning on line 166 in Code/Source/svFSI/main.cpp

View check run for this annotation

Codecov / codecov/patch

Code/Source/svFSI/main.cpp#L164-L166

Added lines #L164 - L166 were not covered by tests
}
}
}
}
}
}

/// @brief Iterate the simulation in time.
///
/// Reproduces the outer and inner loops in Fortan MAIN.f.
//
void iterate_solution(Simulation* simulation)
{
using namespace consts;
Expand Down
Loading