From c5efb595f1b44f4759f847ef0d1a13355b35b0a8 Mon Sep 17 00:00:00 2001 From: Shiyi Chen Date: Mon, 13 Oct 2025 01:57:45 +0000 Subject: [PATCH 01/33] Add CMake build artifacts and vim swap files to .gitignore - Add CMake-generated files (CMakeCache.txt, CMakeFiles/, Makefile, etc.) - Add build directories (*-build/, *-prefix/) - Add compiled outputs (Code/bin/, Code/lib/) - Add generated headers - Add vim swap files (*.swp, *.swo, *~) Related to #442 --- .gitignore | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/.gitignore b/.gitignore index 6c19192e5..2eb401315 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,27 @@ build +# CMake build artifacts +CMakeCache.txt +CMakeFiles/ +Makefile +cmake_install.cmake +*-build/ +*-prefix/ + +# Compiled binaries and libraries +Code/bin/ +Code/lib/ + +# Generated headers +Code/Source/Include/simvascular_options.h +Code/Source/Include/simvascular_version.h +Code/ThirdParty/*/simvascular_*.h + +# Vim swap files +*.swp +*.swo +*~ + # System files osx **/.DS_Store From b324b1f77a13113d34596dd5c760f768ccff17ff Mon Sep 17 00:00:00 2001 From: Shiyi Chen Date: Mon, 13 Oct 2025 02:06:40 +0000 Subject: [PATCH 02/33] Add Integrator class to encapsulate Newton iteration logic - Create integrator.h and integrator.cpp with Integrator class - Encapsulates solution variables (Ag, Yg, Dg) - Handles Newton iteration loop - Manages linear system assembly and solve - Applies boundary conditions - Update CMakeLists.txt to include new source files This is the first step toward implementing partitioned FSI as described in #442 --- Code/Source/solver/CMakeLists.txt | 1 + Code/Source/solver/integrator.cpp | 361 ++++++++++++++++++++++++++++++ Code/Source/solver/integrator.h | 122 ++++++++++ 3 files changed, 484 insertions(+) create mode 100644 Code/Source/solver/integrator.cpp create mode 100644 Code/Source/solver/integrator.h diff --git a/Code/Source/solver/CMakeLists.txt b/Code/Source/solver/CMakeLists.txt index 85da4dd30..85ce9b322 100644 --- a/Code/Source/solver/CMakeLists.txt +++ b/Code/Source/solver/CMakeLists.txt @@ -181,6 +181,7 @@ set(CSRCS heatf.h heatf.cpp heats.h heats.cpp initialize.h initialize.cpp + integrator.h integrator.cpp l_elas.h l_elas.cpp lhsa.h lhsa.cpp ls.h ls.cpp diff --git a/Code/Source/solver/integrator.cpp b/Code/Source/solver/integrator.cpp new file mode 100644 index 000000000..f5afd854c --- /dev/null +++ b/Code/Source/solver/integrator.cpp @@ -0,0 +1,361 @@ +/* Copyright (c) Stanford University, The Regents of the University of California, and others. + * + * All Rights Reserved. + * + * See Copyright-SimVascular.txt for additional details. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject + * to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "integrator.h" +#include "all_fun.h" +#include "bf.h" +#include "contact.h" +#include "eq_assem.h" +#include "fs.h" +#include "ls.h" +#include "output.h" +#include "pic.h" +#include "ris.h" +#include "set_bc.h" +#include "ustruct.h" + +#include +#include +#include + +using namespace consts; + +//------------------------ +// Integrator Constructor +//------------------------ +Integrator::Integrator(Simulation* simulation) + : simulation_(simulation), inner_count_(0) +{ + initialize_arrays(); +} + +//------------------------ +// Integrator Destructor +//------------------------ +Integrator::~Integrator() { + // Arrays will be automatically cleaned up +} + +//------------------------ +// initialize_arrays +//------------------------ +void Integrator::initialize_arrays() { + auto& com_mod = simulation_->com_mod; + int tDof = com_mod.tDof; + int tnNo = com_mod.tnNo; + int nFacesLS = com_mod.nFacesLS; + + Ag_.resize(tDof, tnNo); + Yg_.resize(tDof, tnNo); + Dg_.resize(tDof, tnNo); + res_.resize(nFacesLS); + incL_.resize(nFacesLS); +} + +//------------------------ +// step +//------------------------ +/// @brief Execute one Newton iteration loop for the current time step +bool Integrator::step() { + using namespace consts; + + auto& com_mod = simulation_->com_mod; + auto& cm_mod = simulation_->cm_mod; + auto& cep_mod = simulation_->get_cep_mod(); + + auto& An = com_mod.An; + auto& Yn = com_mod.Yn; + auto& Dn = com_mod.Dn; + + int& cTS = com_mod.cTS; + int& cEq = com_mod.cEq; + + #define n_debug_integrator_step + #ifdef debug_integrator_step + DebugMsg dmsg(__func__, com_mod.cm.idcm()); + dmsg.banner(); + #endif + + // Inner loop for Newton iteration + inner_count_ = 1; + int reply; + int iEqOld; + + // Looping over Newton iterations + while (true) { + #ifdef debug_integrator_step + dmsg << "---------- Inner Loop " + std::to_string(inner_count_) << " -----------" << std::endl; + dmsg << "cEq: " << cEq; + dmsg << "com_mod.eq[cEq].sym: " << com_mod.eq[cEq].sym; + #endif + + auto istr = "_" + std::to_string(cTS) + "_" + std::to_string(inner_count_); + iEqOld = cEq; + auto& eq = com_mod.eq[cEq]; + + if (com_mod.cplBC.coupled && cEq == 0) { + #ifdef debug_integrator_step + dmsg << "Set coupled BCs " << std::endl; + #endif + set_bc::set_bc_cpl(com_mod, cm_mod); + set_bc::set_bc_dir(com_mod, An, Yn, Dn); + } + + // Initiator step for Generalized α-Method (quantities at n+am, n+af). + #ifdef debug_integrator_step + dmsg << "Initiator step ..." << std::endl; + #endif + initiator_step(); + Ag_.write("Ag_pic" + istr); + Yg_.write("Yg_pic" + istr); + Dg_.write("Dg_pic" + istr); + Yn.write("Yn_pic" + istr); + + if (com_mod.Rd.size() != 0) { + com_mod.Rd = 0.0; + com_mod.Kd = 0.0; + } + + // Allocate com_mod.R and com_mod.Val arrays + #ifdef debug_integrator_step + dmsg << "Allocating the RHS and LHS" << std::endl; + #endif + allocate_linear_system(eq); + com_mod.Val.write("Val_alloc" + istr); + + // Compute body forces + #ifdef debug_integrator_step + dmsg << "Set body forces ..." << std::endl; + #endif + set_body_forces(); + com_mod.Val.write("Val_bf" + istr); + + // Assemble equations + #ifdef debug_integrator_step + dmsg << "Assembling equation: " << eq.sym; + #endif + assemble_equations(); + com_mod.R.write("R_as" + istr); + com_mod.Val.write("Val_as" + istr); + + // Treatment of boundary conditions on faces + #ifdef debug_integrator_step + dmsg << "Apply boundary conditions ..." << std::endl; + #endif + apply_boundary_conditions(); + com_mod.Val.write("Val_neu" + istr); + com_mod.R.write("R_neu" + istr); + Yg_.write("Yg_neu" + istr); + Dg_.write("Dg_neu" + istr); + + // Synchronize R across processes + if (!eq.assmTLS) { + #ifdef debug_integrator_step + dmsg << "Synchronize R across processes ..." << std::endl; + #endif + all_fun::commu(com_mod, com_mod.R); + } + + // Update residual in displacement equation for USTRUCT phys + #ifdef debug_integrator_step + dmsg << "com_mod.sstEq: " << com_mod.sstEq; + #endif + if (com_mod.sstEq) { + ustruct::ustruct_r(com_mod, Yg_); + } + + // Set the residual of the continuity equation to 0 on edge nodes + if (std::set{Equation_stokes, Equation_fluid, Equation_ustruct, Equation_FSI}.count(eq.phys) != 0) { + #ifdef debug_integrator_step + dmsg << "thood_val_rc ..." << std::endl; + #endif + fs::thood_val_rc(com_mod); + } + + // Treat Neumann boundaries that are not deforming + #ifdef debug_integrator_step + dmsg << "set_bc_undef_neu ..." << std::endl; + #endif + set_bc::set_bc_undef_neu(com_mod); + + // Update residual and increment arrays + #ifdef debug_integrator_step + dmsg << "Update res() and incL ..." << std::endl; + #endif + update_residual_arrays(eq); + + // Solve equation + #ifdef debug_integrator_step + dmsg << "Solving equation: " << eq.sym; + #endif + solve_linear_system(); + com_mod.Val.write("Val_solve" + istr); + com_mod.R.write("R_solve" + istr); + + // Solution is obtained, now updating (Corrector) and check for convergence + #ifdef debug_integrator_step + dmsg << "Update corrector ..." << std::endl; + #endif + bool all_converged = corrector_and_check_convergence(); + com_mod.Yn.write("Yn_picc" + istr); + + // Check if all equations converged + if (all_converged) { + #ifdef debug_integrator_step + dmsg << ">>> All OK" << std::endl; + dmsg << "iEqOld: " << iEqOld + 1; + #endif + return true; + } + + output::output_result(simulation_, com_mod.timeP, 2, iEqOld); + inner_count_ += 1; + } // End of inner loop + + return false; +} + +//------------------------ +// initiator_step +//------------------------ +void Integrator::initiator_step() { + pic::pici(simulation_, Ag_, Yg_, Dg_); +} + +//------------------------ +// allocate_linear_system +//------------------------ +void Integrator::allocate_linear_system(eqType& eq) { + ls_ns::ls_alloc(simulation_->com_mod, eq); +} + +//------------------------ +// set_body_forces +//------------------------ +void Integrator::set_body_forces() { + bf::set_bf(simulation_->com_mod, Dg_); +} + +//------------------------ +// assemble_equations +//------------------------ +void Integrator::assemble_equations() { + auto& com_mod = simulation_->com_mod; + auto& cep_mod = simulation_->get_cep_mod(); + + for (int iM = 0; iM < com_mod.nMsh; iM++) { + eq_assem::global_eq_assem(com_mod, cep_mod, com_mod.msh[iM], Ag_, Yg_, Dg_); + } +} + +//------------------------ +// apply_boundary_conditions +//------------------------ +void Integrator::apply_boundary_conditions() { + auto& com_mod = simulation_->com_mod; + auto& cm_mod = simulation_->cm_mod; + + Yg_.write("Yg_vor_neu_" + std::to_string(com_mod.cTS) + "_" + std::to_string(inner_count_)); + Dg_.write("Dg_vor_neu_" + std::to_string(com_mod.cTS) + "_" + std::to_string(inner_count_)); + + // Apply Neumman or Traction boundary conditions + set_bc::set_bc_neu(com_mod, cm_mod, Yg_, Dg_); + + // Apply CMM BC conditions + if (!com_mod.cmmInit) { + set_bc::set_bc_cmm(com_mod, cm_mod, Ag_, Dg_); + } + + // Apply weakly applied Dirichlet BCs + set_bc::set_bc_dir_w(com_mod, Yg_, Dg_); + + if (com_mod.risFlag) { + ris::ris_resbc(com_mod, Yg_, Dg_); + } + + if (com_mod.ris0DFlag) { + ris::ris0d_bc(com_mod, cm_mod, Yg_, Dg_); + } + + // Apply contact model and add its contribution to residual + if (com_mod.iCntct) { + contact::construct_contact_pnlty(com_mod, cm_mod, Dg_); + } +} + +//------------------------ +// solve_linear_system +//------------------------ +void Integrator::solve_linear_system() { + auto& com_mod = simulation_->com_mod; + auto& eq = com_mod.eq[com_mod.cEq]; + + ls_ns::ls_solve(com_mod, eq, incL_, res_); +} + +//------------------------ +// corrector_and_check_convergence +//------------------------ +bool Integrator::corrector_and_check_convergence() { + auto& com_mod = simulation_->com_mod; + + pic::picc(simulation_); + + // Check if all equations converged + return std::count_if(com_mod.eq.begin(), com_mod.eq.end(), + [](eqType& eq) { return eq.ok; }) == com_mod.eq.size(); +} + +//------------------------ +// update_residual_arrays +//------------------------ +void Integrator::update_residual_arrays(eqType& eq) { + auto& com_mod = simulation_->com_mod; + int nFacesLS = com_mod.nFacesLS; + double dt = com_mod.dt; + + incL_ = 0; + if (eq.phys == Equation_mesh) { + incL_(nFacesLS - 1) = 1; + } + + if (com_mod.cmmInit) { + incL_(nFacesLS - 1) = 1; + } + + for (int iBc = 0; iBc < eq.nBc; iBc++) { + int i = eq.bc[iBc].lsPtr; + if (i != -1) { + // Resistance term for coupled Neumann BC tangent contribution + res_(i) = eq.gam * dt * eq.bc[iBc].r; + incL_(i) = 1; + } + } +} diff --git a/Code/Source/solver/integrator.h b/Code/Source/solver/integrator.h new file mode 100644 index 000000000..4b62b923a --- /dev/null +++ b/Code/Source/solver/integrator.h @@ -0,0 +1,122 @@ +/* Copyright (c) Stanford University, The Regents of the University of California, and others. + * + * All Rights Reserved. + * + * See Copyright-SimVascular.txt for additional details. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject + * to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUDAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef INTEGRATOR_H +#define INTEGRATOR_H + +#include "Array.h" +#include "Vector.h" +#include "Simulation.h" + +/// @brief Integrator class encapsulates the Newton iteration loop for time integration. +/// +/// This class handles: +/// - Solution variables (Ag, Yg, Dg) +/// - Newton iteration loop +/// - Linear system assembly and solve +/// - Boundary condition application +/// +/// Related to GitHub issue #442: Encapsulate the Newton iteration in main.cpp +class Integrator { + +public: + /// @brief Constructor + /// @param simulation Pointer to the Simulation object + Integrator(Simulation* simulation); + + /// @brief Destructor + ~Integrator(); + + /// @brief Execute one Newton iteration loop for the current time step + /// @return True if all equations converged, false otherwise + bool step(); + + /// @brief Get reference to solution variable Ag (time derivative of variables) + Array& get_Ag() { return Ag_; } + + /// @brief Get reference to solution variable Yg (variables) + Array& get_Yg() { return Yg_; } + + /// @brief Get reference to solution variable Dg (integrated variables) + Array& get_Dg() { return Dg_; } + +private: + /// @brief Pointer to the simulation object + Simulation* simulation_; + + /// @brief Solution variables at generalized-alpha time levels + /// Time derivative of variables (acceleration) + Array Ag_; + + /// Variables (velocity) + Array Yg_; + + /// Integrated variables (displacement) + Array Dg_; + + /// @brief Residual for face-based quantities + Vector res_; + + /// @brief Increment flag for faces + Vector incL_; + + /// @brief Inner iteration counter + int inner_count_; + + /// @brief Initialize solution arrays + void initialize_arrays(); + + /// @brief Perform initiator step for Generalized alpha-Method + void initiator_step(); + + /// @brief Allocate RHS and LHS arrays + void allocate_linear_system(eqType& eq); + + /// @brief Set body forces + void set_body_forces(); + + /// @brief Assemble global equations + void assemble_equations(); + + /// @brief Apply boundary conditions + void apply_boundary_conditions(); + + /// @brief Solve linear system + void solve_linear_system(); + + /// @brief Perform corrector step and check convergence + /// @return True if all equations converged + bool corrector_and_check_convergence(); + + /// @brief Update residual and increment arrays + void update_residual_arrays(eqType& eq); +}; + +#endif // INTEGRATOR_H From c4609d589bf77bef04809686b43b5d3b54a829a2 Mon Sep 17 00:00:00 2001 From: Shiyi Chen Date: Mon, 13 Oct 2025 02:07:18 +0000 Subject: [PATCH 03/33] Refactor main.cpp to use Integrator class - Replace Newton iteration loop with Integrator::step() call - Remove local Ag, Yg, Dg arrays (now managed by Integrator) - Simplify iterate_solution() function - Add integrator.h include Addresses #442: Encapsulate Newton iteration in main.cpp --- Code/Source/solver/main.cpp | 274 ++---------------------------------- 1 file changed, 9 insertions(+), 265 deletions(-) diff --git a/Code/Source/solver/main.cpp b/Code/Source/solver/main.cpp index e1fdac1fb..9b22e8c2c 100644 --- a/Code/Source/solver/main.cpp +++ b/Code/Source/solver/main.cpp @@ -35,6 +35,7 @@ // svMultiPhysics XML_FILE_NAME // #include "Simulation.h" +#include "integrator.h" #include "all_fun.h" #include "bf.h" @@ -233,11 +234,8 @@ void iterate_solution(Simulation* simulation) dmsg << "cmmInit: " << com_mod.cmmInit; #endif - Array Ag(tDof,tnNo); - Array Yg(tDof,tnNo); - Array Dg(tDof,tnNo); - Vector res(nFacesLS); - Vector incL(nFacesLS); + // Create Integrator object to handle Newton iterations + Integrator integrator(simulation); // current time step int& cTS = com_mod.cTS; @@ -365,270 +363,16 @@ void iterate_solution(Simulation* simulation) iterate_precomputed_time(simulation); - // Inner loop for Newton iteration + // Inner loop for Newton iteration - now encapsulated in Integrator class // - int inner_count = 1; - int reply; - int iEqOld; - - // Looping over Newton iterations - while (true) { - #ifdef debug_iterate_solution - dmsg << "---------- Inner Loop " + std::to_string(inner_count) << " -----------" << std::endl; - dmsg << "cEq: " << cEq; - dmsg << "com_mod.eq[cEq].sym: " << com_mod.eq[cEq].sym; - //simulation->com_mod.timer.set_time(); - #endif - //std::cout << "-------------------------------------" << std::endl; - //std::cout << "inner_count: " << inner_count << std::endl; - - auto istr = "_" + std::to_string(cTS) + "_" + std::to_string(inner_count); - iEqOld = cEq; - auto& eq = com_mod.eq[cEq]; - - if (com_mod.cplBC.coupled && cEq == 0) { - #ifdef debug_iterate_solution - dmsg << "Set coupled BCs " << std::endl; - #endif - set_bc::set_bc_cpl(com_mod, cm_mod); - - set_bc::set_bc_dir(com_mod, An, Yn, Dn); - } - - // Initiator step for Generalized α− Method (quantities at n+am, n+af). - // - // Modifes - // Ag((tDof, tnNo) - - // Yg((tDof, tnNo) - - // Dg((tDof, tnNo) - - // - #ifdef debug_iterate_solution - dmsg << "Initiator step ..." << std::endl; - #endif - pic::pici(simulation, Ag, Yg, Dg); - Ag.write("Ag_pic"+ istr); - Yg.write("Yg_pic"+ istr); - Dg.write("Dg_pic"+ istr); - Yn.write("Yn_pic"+ istr); - - if (Rd.size() != 0) { - Rd = 0.0; - Kd = 0.0; - } - - // Allocate com_mod.R and com_mod.Val arrays. - // - // com_mod.R(dof,tnNo) - // com_mod.Val(dof*dof, com_mod.lhs.nnz) - // - // If Trilinos is used then allocate - // com_mod.tls.W(dof,tnNo) - // com_mod.tls.R(dof,tnNo) - // - #ifdef debug_iterate_solution - dmsg << "Allocating the RHS and LHS" << std::endl; - #endif - - ls_ns::ls_alloc(com_mod, eq); - com_mod.Val.write("Val_alloc"+ istr); - - // Compute body forces. If phys is shells or CMM (init), apply - // contribution from body forces (pressure) to residual - // - // Modifes: com_mod.Bf, Dg - // - #ifdef debug_iterate_solution - dmsg << "Set body forces ..." << std::endl; - #endif - - bf::set_bf(com_mod, Dg); - com_mod.Val.write("Val_bf"+ istr); - - // Assemble equations. - // - #ifdef debug_iterate_solution - dmsg << "Assembling equation: " << eq.sym; - #endif - - for (int iM = 0; iM < com_mod.nMsh; iM++) { - eq_assem::global_eq_assem(com_mod, cep_mod, com_mod.msh[iM], Ag, Yg, Dg); - } - com_mod.R.write("R_as"+ istr); - com_mod.Val.write("Val_as"+ istr); - - // Treatment of boundary conditions on faces - // Apply Neumman or Traction boundary conditions - // - // Modifies: com_mod.R - // - #ifdef debug_iterate_solution - dmsg << "Apply Neumman or Traction BCs ... " << std::endl; - #endif - - Yg.write("Yg_vor_neu"+ istr); - Dg.write("Dg_vor_neu"+ istr); - - set_bc::set_bc_neu(com_mod, cm_mod, Yg, Dg); - - com_mod.Val.write("Val_neu"+ istr); - com_mod.R.write("R_neu"+ istr); - Yg.write("Yg_neu"+ istr); - Dg.write("Dg_neu"+ istr); - - // Apply CMM BC conditions - // - if (!com_mod.cmmInit) { - #ifdef debug_iterate_solution - dmsg << "Apply CMM BC conditions ... " << std::endl; - #endif - set_bc::set_bc_cmm(com_mod, cm_mod, Ag, Dg); - } - - // Apply weakly applied Dirichlet BCs - // - #ifdef debug_iterate_solution - dmsg << "Apply weakly applied Dirichlet BCs ... " << std::endl; - #endif - - set_bc::set_bc_dir_w(com_mod, Yg, Dg); - - if (com_mod.risFlag) { - ris::ris_resbc(com_mod, Yg, Dg); - } - - if (com_mod.ris0DFlag) { - ris::ris0d_bc(com_mod, cm_mod, Yg, Dg); - } - - // Apply contact model and add its contribution to residual - // - if (com_mod.iCntct) { - contact::construct_contact_pnlty(com_mod, cm_mod, Dg); - -#if 0 - if (cTS <= 2050) { - Array::write_enabled = true; - com_mod.R.write("R_"+ std::to_string(cTS)); - //exit(0); - } -#endif - } - - // Synchronize R across processes. Note: that it is important - // to synchronize residual, R before treating immersed bodies as - // ib.R is already communicated across processes - // - if (!eq.assmTLS) { - #ifdef debug_iterate_solution - dmsg << "Synchronize R across processes ..." << std::endl; - #endif - all_fun::commu(com_mod, com_mod.R); - } - - // Update residual in displacement equation for USTRUCT phys. - // Note that this step is done only first iteration. Residual - // will be 0 for subsequent iterations - // - // Modifies com_mod.Rd. - // - #ifdef debug_iterate_solution - dmsg << "com_mod.sstEq: " << com_mod.sstEq; - #endif - if (com_mod.sstEq) { - ustruct::ustruct_r(com_mod, Yg); - } - - // Set the residual of the continuity equation and its tangent matrix - // due to variation with pressure to 0 on all the edge nodes. - // - if (std::set{Equation_stokes, Equation_fluid, Equation_ustruct, Equation_FSI}.count(eq.phys) != 0) { - #ifdef debug_iterate_solution - dmsg << "thood_val_rc ..." << std::endl; - #endif - fs::thood_val_rc(com_mod); - } - - // Treat Neumann boundaries that are not deforming - // - #ifdef debug_iterate_solution - dmsg << "set_bc_undef_neu ..." << std::endl; - #endif - - set_bc::set_bc_undef_neu(com_mod); - - // IB treatment: for explicit coupling, simply construct residual. - // - /* [NOTE] not implemented. - if (com_mod.ibFlag) { - if (com_mod.ib.cpld == ibCpld_I) { - //CALL IB_IMPLICIT(Ag, Yg, Dg) - } - // CALL IB_CONSTRUCT() - } - */ - - #ifdef debug_iterate_solution - dmsg << "Update res() and incL ..." << std::endl; - dmsg << "nFacesLS: " << nFacesLS; - #endif - incL = 0; - if (eq.phys == Equation_mesh) { - incL(nFacesLS-1) = 1; - } - - if (com_mod.cmmInit) { - incL(nFacesLS-1) = 1; - } - - for (int iBc = 0; iBc < eq.nBc; iBc++) { - int i = eq.bc[iBc].lsPtr; - if (i != -1) { - // Resistance term for coupled Neumann BC tangent contribution - res(i) = eq.gam * dt * eq.bc[iBc].r; - incL(i) = 1; - } - } - - // Solve equation. - // - // Modifies: com_mod.R, com_mod.Val - // - #ifdef debug_iterate_solution - dmsg << "Solving equation: " << eq.sym; - #endif - - ls_ns::ls_solve(com_mod, eq, incL, res); - - com_mod.Val.write("Val_solve"+ istr); - com_mod.R.write("R_solve"+ istr); - - // Solution is obtained, now updating (Corrector) and check for convergence - // - // Modifies: com_mod.An com_mod.Dn com_mod.Yn cep_mod.Xion com_mod.pS0 com_mod.pSa - // com_mod.pSn com_mod.cEq eq.FSILS.RI.iNorm eq.pNorm - // - #ifdef debug_iterate_solution - dmsg << "Update corrector ..." << std::endl; - #endif - - pic::picc(simulation); - com_mod.Yn.write("Yn_picc"+ istr); - - // Writing out the time passed, residual, and etc. - if (std::count_if(com_mod.eq.begin(),com_mod.eq.end(),[](eqType& eq){return eq.ok;}) == com_mod.eq.size()) { - #ifdef debug_iterate_solution - dmsg << ">>> All OK" << std::endl; - dmsg << "iEqOld: " << iEqOld+1; - #endif - break; - } - output::output_result(simulation, com_mod.timeP, 2, iEqOld); + #ifdef debug_iterate_solution + dmsg << "Starting Newton iteration via Integrator ..." << std::endl; + #endif - inner_count += 1; - } // Inner loop + integrator.step(); #ifdef debug_iterate_solution - dmsg << ">>> End of inner loop " << std::endl; + dmsg << ">>> End of Newton iteration" << std::endl; #endif // IB treatment: interpolate flow data on IB mesh from background From 7eec4302920a0cc9b8a4cddec2f3d3a5e0b09617 Mon Sep 17 00:00:00 2001 From: Shiyi Chen Date: Mon, 13 Oct 2025 02:23:06 +0000 Subject: [PATCH 04/33] Fix: Add missing iEqOld variable for output calls The iEqOld variable is needed for output::output_result() calls after the Newton iteration completes. This variable tracks which equation was solved in the last iteration. --- Code/Source/solver/main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Code/Source/solver/main.cpp b/Code/Source/solver/main.cpp index 9b22e8c2c..a22b9ab5c 100644 --- a/Code/Source/solver/main.cpp +++ b/Code/Source/solver/main.cpp @@ -369,6 +369,7 @@ void iterate_solution(Simulation* simulation) dmsg << "Starting Newton iteration via Integrator ..." << std::endl; #endif + int iEqOld = cEq; integrator.step(); #ifdef debug_iterate_solution From 1d7c5cf14c91c369424912294489ba0d565c46b9 Mon Sep 17 00:00:00 2001 From: Martin Pfaller Date: Fri, 17 Oct 2025 11:53:20 -0700 Subject: [PATCH 05/33] change license header --- Code/Source/solver/integrator.cpp | 31 ++----------------------------- Code/Source/solver/integrator.h | 31 ++----------------------------- 2 files changed, 4 insertions(+), 58 deletions(-) diff --git a/Code/Source/solver/integrator.cpp b/Code/Source/solver/integrator.cpp index f5afd854c..2789845f4 100644 --- a/Code/Source/solver/integrator.cpp +++ b/Code/Source/solver/integrator.cpp @@ -1,32 +1,5 @@ -/* Copyright (c) Stanford University, The Regents of the University of California, and others. - * - * All Rights Reserved. - * - * See Copyright-SimVascular.txt for additional details. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject - * to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ +// SPDX-FileCopyrightText: Copyright (c) Stanford University, The Regents of the University of California, and others. +// SPDX-License-Identifier: BSD-3-Clause #include "integrator.h" #include "all_fun.h" diff --git a/Code/Source/solver/integrator.h b/Code/Source/solver/integrator.h index 4b62b923a..d708d0059 100644 --- a/Code/Source/solver/integrator.h +++ b/Code/Source/solver/integrator.h @@ -1,32 +1,5 @@ -/* Copyright (c) Stanford University, The Regents of the University of California, and others. - * - * All Rights Reserved. - * - * See Copyright-SimVascular.txt for additional details. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject - * to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS - * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUDAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ +// SPDX-FileCopyrightText: Copyright (c) Stanford University, The Regents of the University of California, and others. +// SPDX-License-Identifier: BSD-3-Clause #ifndef INTEGRATOR_H #define INTEGRATOR_H From fbe9c343b1b842dfe3b6bd1b8e7c8e66b9db1c8d Mon Sep 17 00:00:00 2001 From: Shiyi Chen Date: Thu, 23 Oct 2025 02:36:07 +0000 Subject: [PATCH 06/33] Rename integrator files to Integrator to follow class naming convention - Rename integrator.h to Integrator.h - Rename integrator.cpp to Integrator.cpp - Update all #include statements in main.cpp and Integrator.cpp - Update CMakeLists.txt reference Addresses PR #450 review feedback on file naming convention. --- Code/Source/solver/CMakeLists.txt | 2 +- Code/Source/solver/{integrator.cpp => Integrator.cpp} | 2 +- Code/Source/solver/{integrator.h => Integrator.h} | 0 Code/Source/solver/main.cpp | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) rename Code/Source/solver/{integrator.cpp => Integrator.cpp} (99%) rename Code/Source/solver/{integrator.h => Integrator.h} (100%) diff --git a/Code/Source/solver/CMakeLists.txt b/Code/Source/solver/CMakeLists.txt index c364bd10d..e3125c01f 100644 --- a/Code/Source/solver/CMakeLists.txt +++ b/Code/Source/solver/CMakeLists.txt @@ -181,7 +181,7 @@ set(CSRCS heatf.h heatf.cpp heats.h heats.cpp initialize.h initialize.cpp - integrator.h integrator.cpp + Integrator.h Integrator.cpp l_elas.h l_elas.cpp lhsa.h lhsa.cpp ls.h ls.cpp diff --git a/Code/Source/solver/integrator.cpp b/Code/Source/solver/Integrator.cpp similarity index 99% rename from Code/Source/solver/integrator.cpp rename to Code/Source/solver/Integrator.cpp index 2789845f4..b521a779d 100644 --- a/Code/Source/solver/integrator.cpp +++ b/Code/Source/solver/Integrator.cpp @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: Copyright (c) Stanford University, The Regents of the University of California, and others. // SPDX-License-Identifier: BSD-3-Clause -#include "integrator.h" +#include "Integrator.h" #include "all_fun.h" #include "bf.h" #include "contact.h" diff --git a/Code/Source/solver/integrator.h b/Code/Source/solver/Integrator.h similarity index 100% rename from Code/Source/solver/integrator.h rename to Code/Source/solver/Integrator.h diff --git a/Code/Source/solver/main.cpp b/Code/Source/solver/main.cpp index 884996f58..c26cccd6a 100644 --- a/Code/Source/solver/main.cpp +++ b/Code/Source/solver/main.cpp @@ -8,7 +8,7 @@ // svMultiPhysics XML_FILE_NAME // #include "Simulation.h" -#include "integrator.h" +#include "Integrator.h" #include "all_fun.h" #include "bf.h" From d3d942f80287890f9e56434e25d0754b9817813b Mon Sep 17 00:00:00 2001 From: Shiyi Chen Date: Thu, 23 Oct 2025 02:44:51 +0000 Subject: [PATCH 07/33] Convert Integrator class documentation to Doxygen format - Use JavaDoc-style /** */ comments throughout Integrator.h - Add @brief, @param, and @return tags following svZeroDSolver conventions - Document all public methods and private members - Improve descriptions for solution variables (Ag, Yg, Dg) and helper methods Addresses PR #450 review feedback on Doxygen documentation format. --- Code/Source/solver/Integrator.h | 120 ++++++++++++++++++++++---------- 1 file changed, 85 insertions(+), 35 deletions(-) diff --git a/Code/Source/solver/Integrator.h b/Code/Source/solver/Integrator.h index d708d0059..2c550d1d6 100644 --- a/Code/Source/solver/Integrator.h +++ b/Code/Source/solver/Integrator.h @@ -8,87 +8,137 @@ #include "Vector.h" #include "Simulation.h" -/// @brief Integrator class encapsulates the Newton iteration loop for time integration. -/// -/// This class handles: -/// - Solution variables (Ag, Yg, Dg) -/// - Newton iteration loop -/// - Linear system assembly and solve -/// - Boundary condition application -/// -/// Related to GitHub issue #442: Encapsulate the Newton iteration in main.cpp +/** + * @brief Integrator class encapsulates the Newton iteration loop for time integration + * + * This class handles the nonlinear Newton iteration scheme for solving coupled + * multi-physics equations in svMultiPhysics. It manages: + * - Solution variables (Ag, Yg, Dg) at generalized-alpha time levels + * - Newton iteration loop with convergence checking + * - Linear system assembly and solve + * - Boundary condition application + * + * Related to GitHub issue #442: Encapsulate the Newton iteration in main.cpp + */ class Integrator { public: - /// @brief Constructor - /// @param simulation Pointer to the Simulation object + /** + * @brief Construct a new Integrator object + * + * @param simulation Pointer to the Simulation object containing problem data + */ Integrator(Simulation* simulation); - /// @brief Destructor + /** + * @brief Destroy the Integrator object + */ ~Integrator(); - /// @brief Execute one Newton iteration loop for the current time step - /// @return True if all equations converged, false otherwise + /** + * @brief Execute one time step with Newton iteration loop + * + * Performs the complete Newton iteration sequence including initialization, + * assembly, boundary condition application, linear solve, and convergence check. + * + * @return True if all equations converged, false otherwise + */ bool step(); - /// @brief Get reference to solution variable Ag (time derivative of variables) + /** + * @brief Get reference to solution variable Ag (time derivative of variables) + * + * @return Reference to Ag array (acceleration in structural mechanics) + */ Array& get_Ag() { return Ag_; } - /// @brief Get reference to solution variable Yg (variables) + /** + * @brief Get reference to solution variable Yg (variables) + * + * @return Reference to Yg array (velocity in structural mechanics) + */ Array& get_Yg() { return Yg_; } - /// @brief Get reference to solution variable Dg (integrated variables) + /** + * @brief Get reference to solution variable Dg (integrated variables) + * + * @return Reference to Dg array (displacement in structural mechanics) + */ Array& get_Dg() { return Dg_; } private: - /// @brief Pointer to the simulation object + /** @brief Pointer to the simulation object */ Simulation* simulation_; - /// @brief Solution variables at generalized-alpha time levels - /// Time derivative of variables (acceleration) + /** @brief Time derivative of variables (acceleration in structural mechanics) */ Array Ag_; - /// Variables (velocity) + /** @brief Variables (velocity in structural mechanics) */ Array Yg_; - /// Integrated variables (displacement) + /** @brief Integrated variables (displacement in structural mechanics) */ Array Dg_; - /// @brief Residual for face-based quantities + /** @brief Residual vector for face-based quantities */ Vector res_; - /// @brief Increment flag for faces + /** @brief Increment flag for faces in linear solver */ Vector incL_; - /// @brief Inner iteration counter + /** @brief Newton iteration counter for current time step */ int inner_count_; - /// @brief Initialize solution arrays + /** + * @brief Initialize solution arrays for Ag, Yg, Dg based on problem size + */ void initialize_arrays(); - /// @brief Perform initiator step for Generalized alpha-Method + /** + * @brief Perform initiator step for Generalized-alpha Method + * + * Computes quantities at intermediate time levels (n+alpha_m, n+alpha_f) + */ void initiator_step(); - /// @brief Allocate RHS and LHS arrays + /** + * @brief Allocate right-hand side (RHS) and left-hand side (LHS) arrays + * + * @param eq Reference to the equation being solved + */ void allocate_linear_system(eqType& eq); - /// @brief Set body forces + /** + * @brief Set body forces for the current time step + */ void set_body_forces(); - /// @brief Assemble global equations + /** + * @brief Assemble global equations for all meshes + */ void assemble_equations(); - /// @brief Apply boundary conditions + /** + * @brief Apply all boundary conditions (Neumann, Dirichlet, CMM, contact, etc.) + */ void apply_boundary_conditions(); - /// @brief Solve linear system + /** + * @brief Solve the assembled linear system + */ void solve_linear_system(); - /// @brief Perform corrector step and check convergence - /// @return True if all equations converged + /** + * @brief Perform corrector step and check convergence of all equations + * + * @return True if all equations converged, false otherwise + */ bool corrector_and_check_convergence(); - /// @brief Update residual and increment arrays + /** + * @brief Update residual and increment arrays for linear solver + * + * @param eq Reference to the equation being solved + */ void update_residual_arrays(eqType& eq); }; From 0113997a150abf3ab55992aa41303c786ee2cce0 Mon Sep 17 00:00:00 2001 From: Shiyi Chen Date: Thu, 23 Oct 2025 03:01:47 +0000 Subject: [PATCH 08/33] Refactor istr to be a class member variable - Add istr_ as private member variable in Integrator class - Update step() method to set istr_ instead of using local variable - Replace all istr references with istr_ throughout the code - Simplify debug write statements in apply_boundary_conditions() This change enables individual helper functions to access istr_ for their own debug outputs, preparing for the next step of moving write statements into individual functions. Addresses PR #450 review feedback on variable management. --- Code/Source/solver/Integrator.cpp | 36 +++++++++++++++---------------- Code/Source/solver/Integrator.h | 3 +++ 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/Code/Source/solver/Integrator.cpp b/Code/Source/solver/Integrator.cpp index b521a779d..b1dfdfa87 100644 --- a/Code/Source/solver/Integrator.cpp +++ b/Code/Source/solver/Integrator.cpp @@ -89,7 +89,7 @@ bool Integrator::step() { dmsg << "com_mod.eq[cEq].sym: " << com_mod.eq[cEq].sym; #endif - auto istr = "_" + std::to_string(cTS) + "_" + std::to_string(inner_count_); + istr_ = "_" + std::to_string(cTS) + "_" + std::to_string(inner_count_); iEqOld = cEq; auto& eq = com_mod.eq[cEq]; @@ -106,10 +106,10 @@ bool Integrator::step() { dmsg << "Initiator step ..." << std::endl; #endif initiator_step(); - Ag_.write("Ag_pic" + istr); - Yg_.write("Yg_pic" + istr); - Dg_.write("Dg_pic" + istr); - Yn.write("Yn_pic" + istr); + Ag_.write("Ag_pic" + istr_); + Yg_.write("Yg_pic" + istr_); + Dg_.write("Dg_pic" + istr_); + Yn.write("Yn_pic" + istr_); if (com_mod.Rd.size() != 0) { com_mod.Rd = 0.0; @@ -121,32 +121,32 @@ bool Integrator::step() { dmsg << "Allocating the RHS and LHS" << std::endl; #endif allocate_linear_system(eq); - com_mod.Val.write("Val_alloc" + istr); + com_mod.Val.write("Val_alloc" + istr_); // Compute body forces #ifdef debug_integrator_step dmsg << "Set body forces ..." << std::endl; #endif set_body_forces(); - com_mod.Val.write("Val_bf" + istr); + com_mod.Val.write("Val_bf" + istr_); // Assemble equations #ifdef debug_integrator_step dmsg << "Assembling equation: " << eq.sym; #endif assemble_equations(); - com_mod.R.write("R_as" + istr); - com_mod.Val.write("Val_as" + istr); + com_mod.R.write("R_as" + istr_); + com_mod.Val.write("Val_as" + istr_); // Treatment of boundary conditions on faces #ifdef debug_integrator_step dmsg << "Apply boundary conditions ..." << std::endl; #endif apply_boundary_conditions(); - com_mod.Val.write("Val_neu" + istr); - com_mod.R.write("R_neu" + istr); - Yg_.write("Yg_neu" + istr); - Dg_.write("Dg_neu" + istr); + com_mod.Val.write("Val_neu" + istr_); + com_mod.R.write("R_neu" + istr_); + Yg_.write("Yg_neu" + istr_); + Dg_.write("Dg_neu" + istr_); // Synchronize R across processes if (!eq.assmTLS) { @@ -189,15 +189,15 @@ bool Integrator::step() { dmsg << "Solving equation: " << eq.sym; #endif solve_linear_system(); - com_mod.Val.write("Val_solve" + istr); - com_mod.R.write("R_solve" + istr); + com_mod.Val.write("Val_solve" + istr_); + com_mod.R.write("R_solve" + istr_); // Solution is obtained, now updating (Corrector) and check for convergence #ifdef debug_integrator_step dmsg << "Update corrector ..." << std::endl; #endif bool all_converged = corrector_and_check_convergence(); - com_mod.Yn.write("Yn_picc" + istr); + com_mod.Yn.write("Yn_picc" + istr_); // Check if all equations converged if (all_converged) { @@ -255,8 +255,8 @@ void Integrator::apply_boundary_conditions() { auto& com_mod = simulation_->com_mod; auto& cm_mod = simulation_->cm_mod; - Yg_.write("Yg_vor_neu_" + std::to_string(com_mod.cTS) + "_" + std::to_string(inner_count_)); - Dg_.write("Dg_vor_neu_" + std::to_string(com_mod.cTS) + "_" + std::to_string(inner_count_)); + Yg_.write("Yg_vor_neu" + istr_); + Dg_.write("Dg_vor_neu" + istr_); // Apply Neumman or Traction boundary conditions set_bc::set_bc_neu(com_mod, cm_mod, Yg_, Dg_); diff --git a/Code/Source/solver/Integrator.h b/Code/Source/solver/Integrator.h index 2c550d1d6..3b584e1a0 100644 --- a/Code/Source/solver/Integrator.h +++ b/Code/Source/solver/Integrator.h @@ -88,6 +88,9 @@ class Integrator { /** @brief Newton iteration counter for current time step */ int inner_count_; + /** @brief Debug output suffix string combining time step and iteration number */ + std::string istr_; + /** * @brief Initialize solution arrays for Ag, Yg, Dg based on problem size */ From 9955e3d576dab56c9302988aa85884f22cee4879 Mon Sep 17 00:00:00 2001 From: Shiyi Chen Date: Thu, 23 Oct 2025 03:09:45 +0000 Subject: [PATCH 09/33] De-clutter step() method by moving debug writes to individual functions - Move all .write() debug statements from step() to their respective helper functions - initiator_step() now handles its own debug output (Ag, Yg, Dg, Yn) - allocate_linear_system() now handles Val output - set_body_forces() now handles Val output - assemble_equations() now handles R and Val output - apply_boundary_conditions() now handles Val, R, Yg, Dg output - solve_linear_system() now handles Val and R output - corrector_and_check_convergence() now handles Yn output This makes step() cleaner and more focused on orchestration, while each helper function manages its own debug logging. All functions now use the istr_ class member variable for consistent debug naming. Addresses PR #450 review feedback on code organization. --- Code/Source/solver/Integrator.cpp | 44 ++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/Code/Source/solver/Integrator.cpp b/Code/Source/solver/Integrator.cpp index b1dfdfa87..32191a4e8 100644 --- a/Code/Source/solver/Integrator.cpp +++ b/Code/Source/solver/Integrator.cpp @@ -106,10 +106,6 @@ bool Integrator::step() { dmsg << "Initiator step ..." << std::endl; #endif initiator_step(); - Ag_.write("Ag_pic" + istr_); - Yg_.write("Yg_pic" + istr_); - Dg_.write("Dg_pic" + istr_); - Yn.write("Yn_pic" + istr_); if (com_mod.Rd.size() != 0) { com_mod.Rd = 0.0; @@ -121,32 +117,24 @@ bool Integrator::step() { dmsg << "Allocating the RHS and LHS" << std::endl; #endif allocate_linear_system(eq); - com_mod.Val.write("Val_alloc" + istr_); // Compute body forces #ifdef debug_integrator_step dmsg << "Set body forces ..." << std::endl; #endif set_body_forces(); - com_mod.Val.write("Val_bf" + istr_); // Assemble equations #ifdef debug_integrator_step dmsg << "Assembling equation: " << eq.sym; #endif assemble_equations(); - com_mod.R.write("R_as" + istr_); - com_mod.Val.write("Val_as" + istr_); // Treatment of boundary conditions on faces #ifdef debug_integrator_step dmsg << "Apply boundary conditions ..." << std::endl; #endif apply_boundary_conditions(); - com_mod.Val.write("Val_neu" + istr_); - com_mod.R.write("R_neu" + istr_); - Yg_.write("Yg_neu" + istr_); - Dg_.write("Dg_neu" + istr_); // Synchronize R across processes if (!eq.assmTLS) { @@ -189,15 +177,12 @@ bool Integrator::step() { dmsg << "Solving equation: " << eq.sym; #endif solve_linear_system(); - com_mod.Val.write("Val_solve" + istr_); - com_mod.R.write("R_solve" + istr_); // Solution is obtained, now updating (Corrector) and check for convergence #ifdef debug_integrator_step dmsg << "Update corrector ..." << std::endl; #endif bool all_converged = corrector_and_check_convergence(); - com_mod.Yn.write("Yn_picc" + istr_); // Check if all equations converged if (all_converged) { @@ -220,6 +205,12 @@ bool Integrator::step() { //------------------------ void Integrator::initiator_step() { pic::pici(simulation_, Ag_, Yg_, Dg_); + + // Debug output + Ag_.write("Ag_pic" + istr_); + Yg_.write("Yg_pic" + istr_); + Dg_.write("Dg_pic" + istr_); + simulation_->com_mod.Yn.write("Yn_pic" + istr_); } //------------------------ @@ -227,6 +218,9 @@ void Integrator::initiator_step() { //------------------------ void Integrator::allocate_linear_system(eqType& eq) { ls_ns::ls_alloc(simulation_->com_mod, eq); + + // Debug output + simulation_->com_mod.Val.write("Val_alloc" + istr_); } //------------------------ @@ -234,6 +228,9 @@ void Integrator::allocate_linear_system(eqType& eq) { //------------------------ void Integrator::set_body_forces() { bf::set_bf(simulation_->com_mod, Dg_); + + // Debug output + simulation_->com_mod.Val.write("Val_bf" + istr_); } //------------------------ @@ -246,6 +243,10 @@ void Integrator::assemble_equations() { for (int iM = 0; iM < com_mod.nMsh; iM++) { eq_assem::global_eq_assem(com_mod, cep_mod, com_mod.msh[iM], Ag_, Yg_, Dg_); } + + // Debug output + com_mod.R.write("R_as" + istr_); + com_mod.Val.write("Val_as" + istr_); } //------------------------ @@ -281,6 +282,12 @@ void Integrator::apply_boundary_conditions() { if (com_mod.iCntct) { contact::construct_contact_pnlty(com_mod, cm_mod, Dg_); } + + // Debug output + com_mod.Val.write("Val_neu" + istr_); + com_mod.R.write("R_neu" + istr_); + Yg_.write("Yg_neu" + istr_); + Dg_.write("Dg_neu" + istr_); } //------------------------ @@ -291,6 +298,10 @@ void Integrator::solve_linear_system() { auto& eq = com_mod.eq[com_mod.cEq]; ls_ns::ls_solve(com_mod, eq, incL_, res_); + + // Debug output + com_mod.Val.write("Val_solve" + istr_); + com_mod.R.write("R_solve" + istr_); } //------------------------ @@ -301,6 +312,9 @@ bool Integrator::corrector_and_check_convergence() { pic::picc(simulation_); + // Debug output + com_mod.Yn.write("Yn_picc" + istr_); + // Check if all equations converged return std::count_if(com_mod.eq.begin(), com_mod.eq.end(), [](eqType& eq) { return eq.ok; }) == com_mod.eq.size(); From 8dbde2f1f0ed1b4bdc55760c16d6fa770111ab20 Mon Sep 17 00:00:00 2001 From: Shiyi Chen Date: Thu, 23 Oct 2025 03:22:36 +0000 Subject: [PATCH 10/33] Standardize terminology to use 'Newton iteration' instead of 'inner loop' - Rename inner_count_ to newton_count_ throughout Integrator class - Update comments to use 'Newton iteration' instead of 'inner loop' - Update debug messages to show 'Newton Iteration' instead of 'Inner Loop' This makes the terminology more precise and consistent with standard computational mechanics nomenclature, clarifying that we're referring to the Newton iteration within each time step (as opposed to the outer time loop). Addresses PR #450 review feedback on terminology consistency. --- Code/Source/solver/Integrator.cpp | 14 +++++++------- Code/Source/solver/Integrator.h | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Code/Source/solver/Integrator.cpp b/Code/Source/solver/Integrator.cpp index 32191a4e8..481ec6b81 100644 --- a/Code/Source/solver/Integrator.cpp +++ b/Code/Source/solver/Integrator.cpp @@ -24,7 +24,7 @@ using namespace consts; // Integrator Constructor //------------------------ Integrator::Integrator(Simulation* simulation) - : simulation_(simulation), inner_count_(0) + : simulation_(simulation), newton_count_(0) { initialize_arrays(); } @@ -76,20 +76,20 @@ bool Integrator::step() { dmsg.banner(); #endif - // Inner loop for Newton iteration - inner_count_ = 1; + // Newton iteration loop + newton_count_ = 1; int reply; int iEqOld; // Looping over Newton iterations while (true) { #ifdef debug_integrator_step - dmsg << "---------- Inner Loop " + std::to_string(inner_count_) << " -----------" << std::endl; + dmsg << "---------- Newton Iteration " + std::to_string(newton_count_) << " -----------" << std::endl; dmsg << "cEq: " << cEq; dmsg << "com_mod.eq[cEq].sym: " << com_mod.eq[cEq].sym; #endif - istr_ = "_" + std::to_string(cTS) + "_" + std::to_string(inner_count_); + istr_ = "_" + std::to_string(cTS) + "_" + std::to_string(newton_count_); iEqOld = cEq; auto& eq = com_mod.eq[cEq]; @@ -194,8 +194,8 @@ bool Integrator::step() { } output::output_result(simulation_, com_mod.timeP, 2, iEqOld); - inner_count_ += 1; - } // End of inner loop + newton_count_ += 1; + } // End of Newton iteration loop return false; } diff --git a/Code/Source/solver/Integrator.h b/Code/Source/solver/Integrator.h index 3b584e1a0..4b612570f 100644 --- a/Code/Source/solver/Integrator.h +++ b/Code/Source/solver/Integrator.h @@ -86,7 +86,7 @@ class Integrator { Vector incL_; /** @brief Newton iteration counter for current time step */ - int inner_count_; + int newton_count_; /** @brief Debug output suffix string combining time step and iteration number */ std::string istr_; From 7065339e9c3d3222eab01f025e20c6d96c56a14d Mon Sep 17 00:00:00 2001 From: Shiyi Chen Date: Fri, 24 Oct 2025 19:48:03 +0000 Subject: [PATCH 11/33] Move dmsg debug statements into respective Integrator helper functions - Move debug print statements from step() into individual helper functions - Each function now handles its own debug output: * initiator_step() * allocate_linear_system() * set_body_forces() * assemble_equations() * apply_boundary_conditions() * update_residual_arrays() * solve_linear_system() * corrector_and_check_convergence() - Makes step() method cleaner and more focused on orchestration - Each helper function is now self-contained with its own debug logging This addresses PR #450 review feedback on code organization. --- Code/Source/solver/Integrator.cpp | 72 ++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 24 deletions(-) diff --git a/Code/Source/solver/Integrator.cpp b/Code/Source/solver/Integrator.cpp index 481ec6b81..2467cd7f3 100644 --- a/Code/Source/solver/Integrator.cpp +++ b/Code/Source/solver/Integrator.cpp @@ -102,9 +102,6 @@ bool Integrator::step() { } // Initiator step for Generalized α-Method (quantities at n+am, n+af). - #ifdef debug_integrator_step - dmsg << "Initiator step ..." << std::endl; - #endif initiator_step(); if (com_mod.Rd.size() != 0) { @@ -113,27 +110,15 @@ bool Integrator::step() { } // Allocate com_mod.R and com_mod.Val arrays - #ifdef debug_integrator_step - dmsg << "Allocating the RHS and LHS" << std::endl; - #endif allocate_linear_system(eq); // Compute body forces - #ifdef debug_integrator_step - dmsg << "Set body forces ..." << std::endl; - #endif set_body_forces(); // Assemble equations - #ifdef debug_integrator_step - dmsg << "Assembling equation: " << eq.sym; - #endif assemble_equations(); // Treatment of boundary conditions on faces - #ifdef debug_integrator_step - dmsg << "Apply boundary conditions ..." << std::endl; - #endif apply_boundary_conditions(); // Synchronize R across processes @@ -167,21 +152,12 @@ bool Integrator::step() { set_bc::set_bc_undef_neu(com_mod); // Update residual and increment arrays - #ifdef debug_integrator_step - dmsg << "Update res() and incL ..." << std::endl; - #endif update_residual_arrays(eq); // Solve equation - #ifdef debug_integrator_step - dmsg << "Solving equation: " << eq.sym; - #endif solve_linear_system(); // Solution is obtained, now updating (Corrector) and check for convergence - #ifdef debug_integrator_step - dmsg << "Update corrector ..." << std::endl; - #endif bool all_converged = corrector_and_check_convergence(); // Check if all equations converged @@ -204,6 +180,12 @@ bool Integrator::step() { // initiator_step //------------------------ void Integrator::initiator_step() { + #define n_debug_integrator_step + #ifdef debug_integrator_step + DebugMsg dmsg(__func__, simulation_->com_mod.cm.idcm()); + dmsg << "Initiator step ..." << std::endl; + #endif + pic::pici(simulation_, Ag_, Yg_, Dg_); // Debug output @@ -217,6 +199,12 @@ void Integrator::initiator_step() { // allocate_linear_system //------------------------ void Integrator::allocate_linear_system(eqType& eq) { + #define n_debug_integrator_step + #ifdef debug_integrator_step + DebugMsg dmsg(__func__, simulation_->com_mod.cm.idcm()); + dmsg << "Allocating the RHS and LHS" << std::endl; + #endif + ls_ns::ls_alloc(simulation_->com_mod, eq); // Debug output @@ -227,6 +215,12 @@ void Integrator::allocate_linear_system(eqType& eq) { // set_body_forces //------------------------ void Integrator::set_body_forces() { + #define n_debug_integrator_step + #ifdef debug_integrator_step + DebugMsg dmsg(__func__, simulation_->com_mod.cm.idcm()); + dmsg << "Set body forces ..." << std::endl; + #endif + bf::set_bf(simulation_->com_mod, Dg_); // Debug output @@ -240,6 +234,12 @@ void Integrator::assemble_equations() { auto& com_mod = simulation_->com_mod; auto& cep_mod = simulation_->get_cep_mod(); + #define n_debug_integrator_step + #ifdef debug_integrator_step + DebugMsg dmsg(__func__, com_mod.cm.idcm()); + dmsg << "Assembling equation: " << com_mod.eq[com_mod.cEq].sym; + #endif + for (int iM = 0; iM < com_mod.nMsh; iM++) { eq_assem::global_eq_assem(com_mod, cep_mod, com_mod.msh[iM], Ag_, Yg_, Dg_); } @@ -256,6 +256,12 @@ void Integrator::apply_boundary_conditions() { auto& com_mod = simulation_->com_mod; auto& cm_mod = simulation_->cm_mod; + #define n_debug_integrator_step + #ifdef debug_integrator_step + DebugMsg dmsg(__func__, com_mod.cm.idcm()); + dmsg << "Apply boundary conditions ..." << std::endl; + #endif + Yg_.write("Yg_vor_neu" + istr_); Dg_.write("Dg_vor_neu" + istr_); @@ -297,6 +303,12 @@ void Integrator::solve_linear_system() { auto& com_mod = simulation_->com_mod; auto& eq = com_mod.eq[com_mod.cEq]; + #define n_debug_integrator_step + #ifdef debug_integrator_step + DebugMsg dmsg(__func__, com_mod.cm.idcm()); + dmsg << "Solving equation: " << eq.sym; + #endif + ls_ns::ls_solve(com_mod, eq, incL_, res_); // Debug output @@ -310,6 +322,12 @@ void Integrator::solve_linear_system() { bool Integrator::corrector_and_check_convergence() { auto& com_mod = simulation_->com_mod; + #define n_debug_integrator_step + #ifdef debug_integrator_step + DebugMsg dmsg(__func__, com_mod.cm.idcm()); + dmsg << "Update corrector ..." << std::endl; + #endif + pic::picc(simulation_); // Debug output @@ -328,6 +346,12 @@ void Integrator::update_residual_arrays(eqType& eq) { int nFacesLS = com_mod.nFacesLS; double dt = com_mod.dt; + #define n_debug_integrator_step + #ifdef debug_integrator_step + DebugMsg dmsg(__func__, com_mod.cm.idcm()); + dmsg << "Update res() and incL ..." << std::endl; + #endif + incL_ = 0; if (eq.phys == Equation_mesh) { incL_(nFacesLS - 1) = 1; From f2ee52013514276a4ebd135d688961a22f379a06 Mon Sep 17 00:00:00 2001 From: Shiyi Chen Date: Thu, 6 Nov 2025 17:14:09 +0000 Subject: [PATCH 12/33] Remove pic namespace and integrate functions into Integrator class Moved all pic namespace functions (picp, pici, picc, pic_eth) into the Integrator class as member functions: - picp -> predictor() (public method, called from main.cpp) - pici -> pici() (private method) - picc -> picc() (private method) - pic_eth -> pic_eth() (private method) Updated all call sites to use the new member functions. Removed pic.h and pic.cpp files and updated CMakeLists.txt. Related to GitHub issue #459. --- Code/Source/solver/CMakeLists.txt | 1 - Code/Source/solver/Integrator.cpp | 674 ++++++++++++++++++++++++++++- Code/Source/solver/Integrator.h | 38 ++ Code/Source/solver/main.cpp | 3 +- Code/Source/solver/pic.cpp | 691 ------------------------------ Code/Source/solver/pic.h | 22 - 6 files changed, 710 insertions(+), 719 deletions(-) delete mode 100644 Code/Source/solver/pic.cpp delete mode 100644 Code/Source/solver/pic.h diff --git a/Code/Source/solver/CMakeLists.txt b/Code/Source/solver/CMakeLists.txt index e3125c01f..c5197c4e4 100644 --- a/Code/Source/solver/CMakeLists.txt +++ b/Code/Source/solver/CMakeLists.txt @@ -192,7 +192,6 @@ set(CSRCS nn.h nn.cpp output.h output.cpp load_msh.h load_msh.cpp - pic.h pic.cpp post.h post.cpp read_files.h read_files.cpp read_msh.h read_msh.cpp diff --git a/Code/Source/solver/Integrator.cpp b/Code/Source/solver/Integrator.cpp index 481ec6b81..20e62c269 100644 --- a/Code/Source/solver/Integrator.cpp +++ b/Code/Source/solver/Integrator.cpp @@ -4,15 +4,17 @@ #include "Integrator.h" #include "all_fun.h" #include "bf.h" +#include "cep_ion.h" #include "contact.h" #include "eq_assem.h" #include "fs.h" #include "ls.h" +#include "nn.h" #include "output.h" -#include "pic.h" #include "ris.h" #include "set_bc.h" #include "ustruct.h" +#include "utils.h" #include #include @@ -204,7 +206,7 @@ bool Integrator::step() { // initiator_step //------------------------ void Integrator::initiator_step() { - pic::pici(simulation_, Ag_, Yg_, Dg_); + pici(Ag_, Yg_, Dg_); // Debug output Ag_.write("Ag_pic" + istr_); @@ -310,7 +312,7 @@ void Integrator::solve_linear_system() { bool Integrator::corrector_and_check_convergence() { auto& com_mod = simulation_->com_mod; - pic::picc(simulation_); + picc(); // Debug output com_mod.Yn.write("Yn_picc" + istr_); @@ -346,3 +348,669 @@ void Integrator::update_residual_arrays(eqType& eq) { } } } + +//------------------------ +// predictor (picp) +//------------------------ +/// @brief Predictor step for next time step +/// +/// Modifies: +/// pS0 +/// Ad +/// Ao +/// Yo +/// Do +/// An +/// Yn +/// Dn +/// +void Integrator::predictor() +{ + using namespace consts; + + auto& com_mod = simulation_->com_mod; + + #define n_debug_picp + #ifdef debug_picp + DebugMsg dmsg(__func__, com_mod.cm.idcm()); + dmsg.banner(); + dmsg << "pstEq: " << com_mod.pstEq; + #endif + + // Variables for prestress calculations + auto& pS0 = com_mod.pS0; + auto& pSn = com_mod.pSn; + + // time derivative of displacement + auto& Ad = com_mod.Ad; + + auto& Ao = com_mod.Ao; + auto& An = com_mod.An; + auto& Yo = com_mod.Yo; + auto& Yn = com_mod.Yn; + auto& Do = com_mod.Do; + auto& Dn = com_mod.Dn; + + // Prestress initialization + if (com_mod.pstEq) { + pS0 = pS0 + pSn; + Ao = 0.0; + Yo = 0.0; + Do = 0.0; + } + + // IB treatment: Set dirichlet BC and update traces. For explicit + // coupling, compute FSI forcing and freeze it for the time step. + // For implicit coupling, project IB displacement on background + // mesh and predict quantities at next time step + // + // [NOTE] not implemented. + /* + if (ibFlag) { + // Set IB Dirichlet BCs + CALL IB_SETBCDIR(ib.Yb, ib.Ubo) + + // Update IB location and tracers + CALL IB_UPDATE(Do) + + if (ib.cpld == ibCpld_E) { + // FSI forcing for immersed bodies (explicit coupling) + CALL IB_CALCFFSI(Ao, Yo, Do, ib.Auo, ib.Ubo) + + } else { if (ib.cpld == ibCpld_I) { + // Project IB displacement (Ubn) to background mesh + CALL IB_PRJCTU(Do) + + // Predictor step for implicit coupling + CALL IB_PICP() + } + } + */ + + const auto& dt = com_mod.dt; + #ifdef debug_picp + dmsg << "dt: " << dt; + dmsg << "dFlag: " << com_mod.dFlag; + #endif + + for (int iEq = 0; iEq < com_mod.nEq; iEq++) { + auto& eq = com_mod.eq[iEq]; + int s = eq.s; // start row + int e = eq.e; // end row + + #ifdef debug_picp + dmsg << "----- iEq " << iEq << " -----"; + dmsg << "s: " << s; + dmsg << "e: " << e; + dmsg << "eq.gam: " << eq.gam; + dmsg << "coef: " << coef; + #endif + + // [TODO:DaveP] careful here with s amd e. + double coef = (eq.gam - 1.0) / eq.gam; + for (int i = s; i <= e; i++) { + for (int j = 0; j < Ao.ncols(); j++) { + // eqn 87 of Bazilevs 2007 + An(i,j) = Ao(i,j) * coef; + } + } + + // electrophysiology + if (eq.phys == Equation_CEP) { + cep_ion::cep_integ(simulation_, iEq, e, Do); + } + + // eqn 86 of Bazilevs 2007 + Yn.set_rows(s,e, Yo.rows(s,e)); + + if (com_mod.dFlag) { + + // struct, lElas, FSI (struct, mesh) + if (!com_mod.sstEq) { + double coef = dt*dt*(0.5*eq.gam - eq.beta) / (eq.gam - 1.0); + Dn.set_rows(s,e, Do.rows(s,e) + Yn.rows(s,e)*dt + An.rows(s,e)*coef); + + // ustruct, FSI + // + } else { + + if (eq.phys == Equation_ustruct || eq.phys == Equation_FSI) { + double coef = (eq.gam - 1.0) / eq.gam; + Ad = Ad*coef; + Dn.set_rows(s,e, Do.rows(s,e)); + + } else if (eq.phys == Equation_mesh) { + double coef = dt*dt*(0.5*eq.gam - eq.beta) / (eq.gam - 1.0); + Dn.set_rows(s,e, Do.rows(s,e) + Yn.rows(s,e)*dt + An.rows(s,e)*coef); + } + } + } else { + Dn.set_rows(s,e, Do.rows(s,e)); + } + } +} + +//------------------------ +// pici +//------------------------ +/// @brief Initiator for Generalized α-Method +/// +/// Uses Generalized α− Method for time stepping. +/// +/// Modifes Ag from combination of An and Ao defined by coefs from eq.am, eq.af, +/// Ag = (1 - eq.am) * Ao + eq.am * An +/// Yg = (1 - eq.af) * Yo + eq.af * Yn +/// Dg = (1 - eq.af) * Do + eq.af * Dn +/// +/// Modifies: +/// Ag - acceleration +/// Yg - velocity +/// Dg - displacement +/// +void Integrator::pici(Array& Ag, Array& Yg, Array& Dg) +{ + using namespace consts; + + auto& com_mod = simulation_->com_mod; + + #define n_debug_pici + #ifdef debug_pici + DebugMsg dmsg(__func__, com_mod.cm.idcm()); + dmsg.banner(); + #endif + + const int cEq = com_mod.cEq; + const int tnNo = com_mod.tnNo; + auto& eq = com_mod.eq[cEq]; + auto& dof = com_mod.dof; + eq.itr = eq.itr + 1; + + // [NOTE] Setting gobal variable 'dof'. + dof = eq.dof; + #ifdef debug_pici + dmsg << "cEq: " << cEq; + dmsg << "eq.itr: " << eq.itr; + dmsg << "dof: " << dof; + dmsg << "tnNo: " << tnNo; + dmsg << "com_mod.pstEq: " << com_mod.pstEq; + #endif + + const auto& Ao = com_mod.Ao; + const auto& An = com_mod.An; + const auto& Do = com_mod.Do; + const auto& Dn = com_mod.Dn; + const auto& Yo = com_mod.Yo; + const auto& Yn = com_mod.Yn; + + for (int i = 0; i < com_mod.nEq; i++) { + auto& eq = com_mod.eq[i]; + int s = eq.s; + int e = eq.e; + Vector coef(4); + coef(0) = 1.0 - eq.am; + coef(1) = eq.am; + coef(2) = 1.0 - eq.af; + coef(3) = eq.af; + #ifdef debug_pici + dmsg << "s: " << s; + dmsg << "e: " << e; + dmsg << "coef: " << coef[0] << " " << coef[1] << " " << coef[2] << " " << coef[3]; + #endif + + if ((eq.phys == Equation_heatF) && (com_mod.usePrecomp)){ + for (int a = 0; a < tnNo; a++) { + for (int j = 0; j < com_mod.nsd; j++) { + //Ag(j, a) = An(j, a); + //Yg(j, a) = Yn(j, a); + //Dg(j, a) = Dn(j, a); + Ag(j, a) = Ao(j, a) * coef(0) + An(j, a) * coef(1); + Yg(j, a) = Yo(j, a) * coef(2) + Yn(j, a) * coef(3); + Dg(j, a) = Do(j, a) * coef(2) + Dn(j, a) * coef(3); + } + } + for (int a = 0; a < tnNo; a++) { + for (int j = s; j <= e; j++) { + Ag(j, a) = Ao(j, a) * coef(0) + An(j, a) * coef(1); + Yg(j, a) = Yo(j, a) * coef(2) + Yn(j, a) * coef(3); + Dg(j, a) = Do(j, a) * coef(2) + Dn(j, a) * coef(3); + } + } + } else { + for (int a = 0; a < tnNo; a++) { + for (int j = s; j <= e; j++) { + // eqn 89 of Bazilevs 2007 + Ag(j, a) = Ao(j, a) * coef(0) + An(j, a) * coef(1); + + // eqn 90 of Bazilevs 2007 + Yg(j, a) = Yo(j, a) * coef(2) + Yn(j, a) * coef(3); + + Dg(j, a) = Do(j, a) * coef(2) + Dn(j, a) * coef(3); + } + } + } + } + + // prestress + if (com_mod.pstEq) { + com_mod.pSn = 0.0; + com_mod.pSa = 0.0; + } +} +//------------------------ +// picc +//------------------------ +/// @brief Corrector with convergence check +/// +/// Decision for next eqn is also made here (modifies cEq global). +/// +/// Modifies: +/// \code {.cpp} +/// com_mod.Ad +/// com_mod.An +/// com_mod.Dn +/// com_mod.Yn +/// cep_mod.Xion +/// com_mod.pS0 +/// com_mod.pSa +/// com_mod.pSn +/// +/// com_mod.cEq +/// eq.FSILS.RI.iNorm +/// eq.pNorm +/// \endcode +// +void Integrator::picc() +{ + using namespace consts; + + auto& com_mod = simulation_->com_mod; + auto& cep_mod = simulation_->get_cep_mod(); + + #define n_debug_picc + #ifdef debug_picc + DebugMsg dmsg(__func__, com_mod.cm.idcm()); + dmsg.banner(); + #endif + + const int nsd = com_mod.nsd; + const int tnNo = com_mod.tnNo; + const double dt = com_mod.dt; + + const auto& R = com_mod.R; + const auto& Rd = com_mod.Rd; + + auto& cEq = com_mod.cEq; + auto& eq = com_mod.eq[cEq]; + + auto& An = com_mod.An; + auto& Ad = com_mod.Ad; + auto& Dn = com_mod.Dn; + auto& Yn = com_mod.Yn; + + auto& pS0 = com_mod.pS0; + auto& pSa = com_mod.pSa; + auto& pSn = com_mod.pSn; + auto& Xion = cep_mod.Xion; + + int s = eq.s; + int e = eq.e; + + std::array coef; + coef[0] = eq.gam * dt; + coef[1] = eq.beta*dt*dt; + coef[2] = 1.0 / eq.am; + coef[3] = eq.af*coef[0]*coef[2]; + + #ifdef debug_picc + dmsg << "cEq: " << cEq; + dmsg << "s: " << s; + dmsg << "e: " << e; + dmsg << "coef: " << coef[0] << " " << coef[1] << " " << coef[2] << " " << coef[3]; + dmsg << "sstEq: " << com_mod.sstEq; + dmsg << "An nrows: " << An.nrows_; + dmsg << " ncols: " << An.ncols_; + #endif + + // ustruct, FSI (ustruct) + // + if (com_mod.sstEq) { + if (eq.phys == EquationType::phys_ustruct || eq.phys == EquationType::phys_FSI) { + Vector dUl(nsd); + + for (int a = 0; a < tnNo; a++) { + for (int i = 0; i < e-s+1; i++) { + An(i+s,a) = An(i+s,a) - R(i,a); + Yn(i+s,a) = Yn(i+s,a) - R(i,a)*coef[0]; + } + + for (int i = 0; i < e-s; i++) { + dUl(i) = Rd(i,a)*coef[2] + R(i,a)*coef[3]; + Ad(i,a) = Ad(i,a) - dUl(i); + Dn(i+s,a) = Dn(i+s,a) - dUl(i)*coef[0]; + } + } + + } else if (eq.phys == EquationType::phys_mesh) { + for (int a = 0; a < tnNo; a++) { + for (int i = 0; i < e-s+1; i++) { + An(i+s,a) = An(i+s,a) - R(i,a); + Yn(i+s,a) = Yn(i+s,a) - R(i,a)*coef[0]; + Dn(i+s,a) = Dn(i+s,a) - R(i,a)*coef[1]; + } + } + } + + } else { + for (int a = 0; a < tnNo; a++) { + for (int i = 0; i < e-s+1; i++) { + // eqn 94 of Bazilevs 2007 // here, -R contains the acceleration update (obtained from Newton solve))? + An(i+s,a) = An(i+s,a) - R(i,a); + + // eqn 95 of Bazilevs 2007 + Yn(i+s,a) = Yn(i+s,a) - R(i,a)*coef[0]; + + Dn(i+s,a) = Dn(i+s,a) - R(i,a)*coef[1]; + } + } + } + + if (std::set{Equation_stokes, Equation_fluid, Equation_ustruct, Equation_FSI}.count(eq.phys) != 0) { + pic_eth(); + } + + if (eq.phys == Equation_FSI) { + int s = com_mod.eq[1].s; + int e = com_mod.eq[1].e; + #ifdef debug_picc + dmsg << "eq.phys == Equation_FSI "; + dmsg << "com_mod.eq[1].sym: " << com_mod.eq[1].sym; + dmsg << "s: " << s; + dmsg << "e: " << e; + #endif + + for (int Ac = 0; Ac < tnNo; Ac++) { + if (all_fun::is_domain(com_mod, eq, Ac, Equation_struct) || + all_fun::is_domain(com_mod, eq, Ac, Equation_ustruct) || + all_fun::is_domain(com_mod, eq, Ac, Equation_lElas)) { + for (int i = 0; i < e-s+1; i++) { + An(i+s,Ac) = An(i,Ac); + Yn(i+s,Ac) = Yn(i,Ac); + Dn(i+s,Ac) = Dn(i,Ac); + } + } + } + } + + // Update Xion for cardiac electrophysiology + // + if (eq.phys == Equation_CEP) { + int s = eq.s; + for (int a = 0; a < tnNo; a++) { + Xion(0,a) = Yn(s,a); + } + } + + // Update prestress at the nodes and re-initialize + // + if (com_mod.pstEq) { + all_fun::commu(com_mod, pSn); + all_fun::commu(com_mod, pSa); + + for (int a = 0; a < tnNo; a++) { + if (!utils::is_zero(pSa(a))) { + for (int i = 0; i < pSn.nrows(); i++) { + pSn(i,a) = pSn(i,a) / pSa(a); + } + } + } + + pSa = 0.0; + } + + // Filter out the non-wall displacements for CMM equation + // + if (eq.phys == Equation_CMM && !com_mod.cmmInit) { + for (int a = 0; a < tnNo; a++) { + double r1 = static_cast(com_mod.cmmBdry(a)); + for (int i = 0; i < e-s; i++) { + Dn(i+s,a) = Dn(i+s,a)*r1; + } + } + } + + // IB treatment + //if (ibFlag) CALL IB_PICC() + + // Computes norms and check for convergence of Newton iterations + double eps = std::numeric_limits::epsilon(); + + if (utils::is_zero(eq.FSILS.RI.iNorm)) { + eq.FSILS.RI.iNorm = eps; + } + + if (utils::is_zero(eq.iNorm)) { + eq.iNorm = eq.FSILS.RI.iNorm; + #ifdef debug_picc + dmsg << "eq.iNorm: " << eq.iNorm; + #endif + } + + if (eq.itr == 1) { + eq.pNorm = eq.FSILS.RI.iNorm / eq.iNorm; + #ifdef debug_picc + dmsg << "eq.itr: " << eq.itr; + dmsg << "eq.pNorm: " << eq.pNorm; + #endif + } + + double r1 = eq.FSILS.RI.iNorm / eq.iNorm; + bool l1 = (eq.itr >= eq.maxItr); + bool l2 = (r1 <= eq.tol); + bool l3 = (r1 <= eq.tol*eq.pNorm); + bool l4 = (eq.itr >= eq.minItr); + + #ifdef debug_picc + dmsg << "eq.itr: " << eq.itr; + dmsg << "eq.minItr: " << eq.minItr; + dmsg << "r1: " << r1; + dmsg << "l1: " << l1; + dmsg << "l2: " << l2; + dmsg << "l3: " << l3; + dmsg << "l4: " << l4; + #endif + + if (l1 || ((l2 || l3) && l4)) { + eq.ok = true; + #ifdef debug_picc + dmsg << "eq.ok: " << eq.ok; + dmsg << "com_mod.eq[0].ok: " << com_mod.eq[0].ok; + dmsg << "com_mod.eq[1].ok: " << com_mod.eq[1].ok; + #endif + } + + auto& eqs = com_mod.eq; + if (std::count_if(eqs.begin(),eqs.end(),[](eqType& eq){return eq.ok;}) == eqs.size()) { + #ifdef debug_picc + dmsg << "all ok"; + #endif + return; + } + //if (ALL(eq.ok)) RETURN + + if (eq.coupled) { + cEq = cEq + 1; + #ifdef debug_picc + dmsg << "eq " << " coupled "; + dmsg << "1st update cEq: " << cEq; + #endif + + auto& eqs = com_mod.eq; + if (std::count_if(eqs.begin(),eqs.end(),[](eqType& eq){return !eq.coupled || eq.ok;}) == eqs.size()) { + while (cEq < com_mod.nEq) { + if (!eqs[cEq].coupled) { + break; + } + cEq = cEq + 1; + } + + } else { + if (cEq >= com_mod.nEq) { + cEq = 0; + } + + while (!eqs[cEq].coupled) { + cEq = cEq + 1; + if (cEq >= com_mod.nEq) { + cEq = 0; + } + } + } + + } else { + if (eq.ok) { + cEq = cEq + 1; + } + } + #ifdef debug_picc + dmsg << "eq " << " coupled "; + dmsg << "2nd update cEq: " << cEq; + #endif +} + +//------------------------ +// pic_eth +//------------------------ +/// @brief Pressure correction at edge nodes for Taylor-Hood type element +/// +/// Here, we interpolate pressure at the edge nodes by interpolating +/// using a reduced basis (such as P1) applied on element vertices +/// (i.e., corner nodes). For e.g., for a P2 element, pressure is +/// interpolated at the edge nodes using P1 vertices. +/// +/// Modifies: com_mod.Yn +/// +void Integrator::pic_eth() +{ + using namespace consts; + + auto& com_mod = simulation_->com_mod; + auto& cep_mod = simulation_->get_cep_mod(); + + const int nsd = com_mod.nsd; + const int tnNo = com_mod.tnNo; + const double dt = com_mod.dt; + const auto& cEq = com_mod.cEq; + const auto& eq = com_mod.eq[cEq]; + + auto& cDmn = com_mod.cDmn; + auto& Yn = com_mod.Yn; + + // Check for something ... + // + bool THflag = false; + + for (int iM = 0; iM < com_mod.nMsh; iM++) { + if (com_mod.msh[iM].nFs == 2) { + THflag = true; + break; + } + } + + if (!THflag) { + return; + } + + Vector sA(tnNo), sF(tnNo); + int s = eq.s; + + for (int iM = 0; iM < com_mod.nMsh; iM++) { + auto& msh = com_mod.msh[iM]; + if (msh.nFs == 1) { + continue; + } + + auto eType = msh.fs[1].eType; + int eNoN = msh.fs[0].eNoN; + int eNoNq = msh.fs[1].eNoN; + + Array xl(nsd,eNoN), xql(nsd,eNoNq), Nqx(nsd,eNoNq); + Vector pl(eNoNq), Nq(eNoNq); + + Vector xp(nsd), xi0(nsd), xi(nsd); + Array ksix(nsd,nsd); + + for (int g = 0; g < msh.fs[1].nG; g++) { + for (int i = 0; i < nsd; i++) { + xi0(i) = xi0(i) + msh.fs[1].xi(i,g); + } + } + + xi0 = xi0 / static_cast(msh.fs[1].nG); + + for (int e = 0; e < msh.nEl; e++) { + cDmn = all_fun::domain(com_mod, msh, cEq, e); // setting global cDmn + if ((eq.dmn[cDmn].phys != Equation_stokes) && + (eq.dmn[cDmn].phys != Equation_fluid) && + (eq.dmn[cDmn].phys != Equation_ustruct)) { + continue; + } + + for (int a = 0; a < eNoN; a++) { + int Ac = msh.IEN(a,e); + for (int i = 0; i < nsd; i++) { + xl(i,a) = com_mod.x(i,Ac); + } + } + + for (int a = 0; a < eNoNq; a++) { + int Ac = msh.IEN(a,e); + pl(a) = Yn(s+nsd,Ac); + for (int i = 0; i < nsd; i++) { + xql(i,a) = xl(i,a); + } + } + + double eVol = 0.0; + double Jac = 0.0; + + for (int g = 0; g < msh.fs[1].nG; g++) { + if (g == 0 || !msh.fs[1].lShpF) { + auto Nx = msh.fs[1].Nx.slice(g); + nn::gnn(eNoNq, nsd, nsd, Nx, xql, Nqx, Jac, ksix); + + if (utils::is_zero(Jac)) { + throw std::runtime_error("[pic_eth] Jacobian for element " + std::to_string(e) + " is < 0."); + } + } + + eVol = eVol + msh.fs[1].w(g)*Jac; + } + + for (int a = eNoNq; a < eNoN; a++) { + int Ac = msh.IEN(a,e); + for (int i = 0; i < nsd; i++) { + xp(i) = xl(i,a); + } + xi = xi0; + nn::get_nnx(nsd, eType, eNoNq, xql, msh.fs[1].xib, msh.fs[1].Nb, xp, xi, Nq, Nqx); + + double p = 0.0; + for (int b = 0; b < eNoNq; b++) { + p = p + pl(b)*Nq(b); + } + + sF(Ac) = sF(Ac) + p*eVol; + sA(Ac) = sA(Ac) + eVol; + } + } // e-loop + } // iM-loop + + all_fun::commu(com_mod, sA); + all_fun::commu(com_mod, sF); + + for (int a = 0; a < tnNo; a++) { + if (!utils::is_zero(sA(a))) { + Yn(s+nsd,a) = sF(a) / sA(a); + } + } +} diff --git a/Code/Source/solver/Integrator.h b/Code/Source/solver/Integrator.h index 4b612570f..b351e7859 100644 --- a/Code/Source/solver/Integrator.h +++ b/Code/Source/solver/Integrator.h @@ -45,6 +45,15 @@ class Integrator { */ bool step(); + /** + * @brief Perform predictor step for next time step + * + * Performs predictor step using generalized-alpha method to estimate + * solution at n+1 time level based on current solution at n time level. + * This should be called once per time step before the Newton iteration loop. + */ + void predictor(); + /** * @brief Get reference to solution variable Ag (time derivative of variables) * @@ -143,6 +152,35 @@ class Integrator { * @param eq Reference to the equation being solved */ void update_residual_arrays(eqType& eq); + + /** + * @brief Initiator function for generalized-alpha method (pici) + * + * Computes solution variables at intermediate time levels using + * generalized-alpha parameters (am, af) for time integration. + * Updates Ag, Yg, Dg based on An, Ao, Yn, Yo, Dn, Do. + * + * @param Ag Time derivative array at generalized-alpha level + * @param Yg Solution variable array at generalized-alpha level + * @param Dg Integrated variable array at generalized-alpha level + */ + void pici(Array& Ag, Array& Yg, Array& Dg); + + /** + * @brief Corrector function with convergence check (picc) + * + * Updates solution at n+1 time level and checks convergence of Newton + * iterations. Also handles equation switching for coupled problems. + */ + void picc(); + + /** + * @brief Pressure correction for Taylor-Hood elements (pic_eth) + * + * Interpolates pressure at edge nodes using reduced basis applied + * on element vertices for Taylor-Hood type elements. + */ + void pic_eth(); }; #endif // INTEGRATOR_H diff --git a/Code/Source/solver/main.cpp b/Code/Source/solver/main.cpp index c26cccd6a..b66717a45 100644 --- a/Code/Source/solver/main.cpp +++ b/Code/Source/solver/main.cpp @@ -19,7 +19,6 @@ #include "initialize.h" #include "ls.h" #include "output.h" -#include "pic.h" #include "read_files.h" #include "read_msh.h" #include "remesh.h" @@ -316,7 +315,7 @@ void iterate_solution(Simulation* simulation) #ifdef debug_iterate_solution dmsg << "Predictor step ... " << std::endl; #endif - pic::picp(simulation); + integrator.predictor(); // Apply Dirichlet BCs strongly // diff --git a/Code/Source/solver/pic.cpp b/Code/Source/solver/pic.cpp deleted file mode 100644 index 34a274def..000000000 --- a/Code/Source/solver/pic.cpp +++ /dev/null @@ -1,691 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (c) Stanford University, The Regents of the University of California, and others. -// SPDX-License-Identifier: BSD-3-Clause - -// The code here replicates the Fortran code in PIC.f. -// -// See the publications below, section 4.4 for theory and derivation: -// 1. Bazilevs, et al. "Isogeometric fluid-structure interaction: -// theory, algorithms, and computations.", Computational Mechanics, -// 43 (2008): 3-37. doi: 10.1007/s00466-008-0315-x -// 2. Bazilevs, et al. "Variational multiscale residual-based -// turbulence modeling for large eddy simulation of incompressible -// flows.", CMAME (2007) - -#include "pic.h" - -#include "Simulation.h" -#include "all_fun.h" -#include "cep_ion.h" -#include "nn.h" -#include "utils.h" - -#include "mpi.h" - -#include -#include - -namespace pic { - -/// @brief This is the corrector. Decision for next eqn is also made here (modifies cEq global). -/// -/// Modifies: -/// \code {.cpp} -/// com_mod.Ad -/// com_mod.An -/// com_mod.Dn -/// com_mod.Yn -/// cep_mod.Xion -/// com_mod.pS0 -/// com_mod.pSa -/// com_mod.pSn -/// -/// com_mod.cEq -/// eq.FSILS.RI.iNorm -/// eq.pNorm -/// \endcode -// -void picc(Simulation* simulation) -{ - using namespace consts; - - auto& com_mod = simulation->com_mod; - auto& cep_mod = simulation->get_cep_mod(); - - #define n_debug_picc - #ifdef debug_picc - DebugMsg dmsg(__func__, com_mod.cm.idcm()); - dmsg.banner(); - #endif - - const int nsd = com_mod.nsd; - const int tnNo = com_mod.tnNo; - const double dt = com_mod.dt; - - const auto& R = com_mod.R; - const auto& Rd = com_mod.Rd; - - auto& cEq = com_mod.cEq; - auto& eq = com_mod.eq[cEq]; - - auto& An = com_mod.An; - auto& Ad = com_mod.Ad; - auto& Dn = com_mod.Dn; - auto& Yn = com_mod.Yn; - - auto& pS0 = com_mod.pS0; - auto& pSa = com_mod.pSa; - auto& pSn = com_mod.pSn; - auto& Xion = cep_mod.Xion; - - int s = eq.s; - int e = eq.e; - - std::array coef; - coef[0] = eq.gam * dt; - coef[1] = eq.beta*dt*dt; - coef[2] = 1.0 / eq.am; - coef[3] = eq.af*coef[0]*coef[2]; - - #ifdef debug_picc - dmsg << "cEq: " << cEq; - dmsg << "s: " << s; - dmsg << "e: " << e; - dmsg << "coef: " << coef[0] << " " << coef[1] << " " << coef[2] << " " << coef[3]; - dmsg << "sstEq: " << com_mod.sstEq; - dmsg << "An nrows: " << An.nrows_; - dmsg << " ncols: " << An.ncols_; - #endif - - // ustruct, FSI (ustruct) - // - if (com_mod.sstEq) { - if (eq.phys == EquationType::phys_ustruct || eq.phys == EquationType::phys_FSI) { - Vector dUl(nsd); - - for (int a = 0; a < tnNo; a++) { - for (int i = 0; i < e-s+1; i++) { - An(i+s,a) = An(i+s,a) - R(i,a); - Yn(i+s,a) = Yn(i+s,a) - R(i,a)*coef[0]; - } - - for (int i = 0; i < e-s; i++) { - dUl(i) = Rd(i,a)*coef[2] + R(i,a)*coef[3]; - Ad(i,a) = Ad(i,a) - dUl(i); - Dn(i+s,a) = Dn(i+s,a) - dUl(i)*coef[0]; - } - } - - } else if (eq.phys == EquationType::phys_mesh) { - for (int a = 0; a < tnNo; a++) { - for (int i = 0; i < e-s+1; i++) { - An(i+s,a) = An(i+s,a) - R(i,a); - Yn(i+s,a) = Yn(i+s,a) - R(i,a)*coef[0]; - Dn(i+s,a) = Dn(i+s,a) - R(i,a)*coef[1]; - } - } - } - - } else { - for (int a = 0; a < tnNo; a++) { - for (int i = 0; i < e-s+1; i++) { - // eqn 94 of Bazilevs 2007 // here, -R contains the acceleration update (obtained from Newton solve))? - An(i+s,a) = An(i+s,a) - R(i,a); - - // eqn 95 of Bazilevs 2007 - Yn(i+s,a) = Yn(i+s,a) - R(i,a)*coef[0]; - - Dn(i+s,a) = Dn(i+s,a) - R(i,a)*coef[1]; - } - } - } - - if (std::set{Equation_stokes, Equation_fluid, Equation_ustruct, Equation_FSI}.count(eq.phys) != 0) { - pic_eth(simulation); - } - - if (eq.phys == Equation_FSI) { - int s = com_mod.eq[1].s; - int e = com_mod.eq[1].e; - #ifdef debug_picc - dmsg << "eq.phys == Equation_FSI "; - dmsg << "com_mod.eq[1].sym: " << com_mod.eq[1].sym; - dmsg << "s: " << s; - dmsg << "e: " << e; - #endif - - for (int Ac = 0; Ac < tnNo; Ac++) { - if (all_fun::is_domain(com_mod, eq, Ac, Equation_struct) || - all_fun::is_domain(com_mod, eq, Ac, Equation_ustruct) || - all_fun::is_domain(com_mod, eq, Ac, Equation_lElas)) { - for (int i = 0; i < e-s+1; i++) { - An(i+s,Ac) = An(i,Ac); - Yn(i+s,Ac) = Yn(i,Ac); - Dn(i+s,Ac) = Dn(i,Ac); - } - } - } - } - - // Update Xion for cardiac electrophysiology - // - if (eq.phys == Equation_CEP) { - int s = eq.s; - for (int a = 0; a < tnNo; a++) { - Xion(0,a) = Yn(s,a); - } - } - - // Update prestress at the nodes and re-initialize - // - if (com_mod.pstEq) { - all_fun::commu(com_mod, pSn); - all_fun::commu(com_mod, pSa); - - for (int a = 0; a < tnNo; a++) { - if (!utils::is_zero(pSa(a))) { - for (int i = 0; i < pSn.nrows(); i++) { - pSn(i,a) = pSn(i,a) / pSa(a); - } - } - } - - pSa = 0.0; - } - - // Filter out the non-wall displacements for CMM equation - // - if (eq.phys == Equation_CMM && !com_mod.cmmInit) { - for (int a = 0; a < tnNo; a++) { - double r1 = static_cast(com_mod.cmmBdry(a)); - for (int i = 0; i < e-s; i++) { - Dn(i+s,a) = Dn(i+s,a)*r1; - } - } - } - - // IB treatment - //if (ibFlag) CALL IB_PICC() - - // Computes norms and check for convergence of Newton iterations - double eps = std::numeric_limits::epsilon(); - - if (utils::is_zero(eq.FSILS.RI.iNorm)) { - eq.FSILS.RI.iNorm = eps; - } - - if (utils::is_zero(eq.iNorm)) { - eq.iNorm = eq.FSILS.RI.iNorm; - #ifdef debug_picc - dmsg << "eq.iNorm: " << eq.iNorm; - #endif - } - - if (eq.itr == 1) { - eq.pNorm = eq.FSILS.RI.iNorm / eq.iNorm; - #ifdef debug_picc - dmsg << "eq.itr: " << eq.itr; - dmsg << "eq.pNorm: " << eq.pNorm; - #endif - } - - double r1 = eq.FSILS.RI.iNorm / eq.iNorm; - bool l1 = (eq.itr >= eq.maxItr); - bool l2 = (r1 <= eq.tol); - bool l3 = (r1 <= eq.tol*eq.pNorm); - bool l4 = (eq.itr >= eq.minItr); - - #ifdef debug_picc - dmsg << "eq.itr: " << eq.itr; - dmsg << "eq.minItr: " << eq.minItr; - dmsg << "r1: " << r1; - dmsg << "l1: " << l1; - dmsg << "l2: " << l2; - dmsg << "l3: " << l3; - dmsg << "l4: " << l4; - #endif - - if (l1 || ((l2 || l3) && l4)) { - eq.ok = true; - #ifdef debug_picc - dmsg << "eq.ok: " << eq.ok; - dmsg << "com_mod.eq[0].ok: " << com_mod.eq[0].ok; - dmsg << "com_mod.eq[1].ok: " << com_mod.eq[1].ok; - #endif - } - - auto& eqs = com_mod.eq; - if (std::count_if(eqs.begin(),eqs.end(),[](eqType& eq){return eq.ok;}) == eqs.size()) { - #ifdef debug_picc - dmsg << "all ok"; - #endif - return; - } - //if (ALL(eq.ok)) RETURN - - if (eq.coupled) { - cEq = cEq + 1; - #ifdef debug_picc - dmsg << "eq " << " coupled "; - dmsg << "1st update cEq: " << cEq; - #endif - - auto& eqs = com_mod.eq; - if (std::count_if(eqs.begin(),eqs.end(),[](eqType& eq){return !eq.coupled || eq.ok;}) == eqs.size()) { - while (cEq < com_mod.nEq) { - if (!eqs[cEq].coupled) { - break; - } - cEq = cEq + 1; - } - - } else { - if (cEq >= com_mod.nEq) { - cEq = 0; - } - - while (!eqs[cEq].coupled) { - cEq = cEq + 1; - if (cEq >= com_mod.nEq) { - cEq = 0; - } - } - } - - } else { - if (eq.ok) { - cEq = cEq + 1; - } - } - #ifdef debug_picc - dmsg << "eq " << " coupled "; - dmsg << "2nd update cEq: " << cEq; - #endif -} - -//--------- -// pic_eth -//--------- -// Pressure correction at edge nodes for Taylor-Hood type element. -// Here, we interpolate pressure at the edge nodes by interpolating -// using a reduced basis (such as P1) applied on element vertices -// (i.e., corner nodes). For e.g., for a P2 element, pressure is -// interpolated at the edge nodes using P1 vertices. -// -// Modifies: com_mod.Yn -// -void pic_eth(Simulation* simulation) -{ - using namespace consts; - - auto& com_mod = simulation->com_mod; - auto& cep_mod = simulation->get_cep_mod(); - - const int nsd = com_mod.nsd; - const int tnNo = com_mod.tnNo; - const double dt = com_mod.dt; - const auto& cEq = com_mod.cEq; - const auto& eq = com_mod.eq[cEq]; - - auto& cDmn = com_mod.cDmn; - auto& Yn = com_mod.Yn; - - // Check for something ... - // - bool THflag = false; - - for (int iM = 0; iM < com_mod.nMsh; iM++) { - if (com_mod.msh[iM].nFs == 2) { - THflag = true; - break; - } - } - - if (!THflag) { - return; - } - - Vector sA(tnNo), sF(tnNo); - int s = eq.s; - - for (int iM = 0; iM < com_mod.nMsh; iM++) { - auto& msh = com_mod.msh[iM]; - if (msh.nFs == 1) { - continue; - } - - auto eType = msh.fs[1].eType; - int eNoN = msh.fs[0].eNoN; - int eNoNq = msh.fs[1].eNoN; - - Array xl(nsd,eNoN), xql(nsd,eNoNq), Nqx(nsd,eNoNq); - Vector pl(eNoNq), Nq(eNoNq); - - Vector xp(nsd), xi0(nsd), xi(nsd); - Array ksix(nsd,nsd); - - for (int g = 0; g < msh.fs[1].nG; g++) { - for (int i = 0; i < nsd; i++) { - xi0(i) = xi0(i) + msh.fs[1].xi(i,g); - } - } - - xi0 = xi0 / static_cast(msh.fs[1].nG); - - for (int e = 0; e < msh.nEl; e++) { - cDmn = all_fun::domain(com_mod, msh, cEq, e); // setting global cDmn - if ((eq.dmn[cDmn].phys != Equation_stokes) && - (eq.dmn[cDmn].phys != Equation_fluid) && - (eq.dmn[cDmn].phys != Equation_ustruct)) { - continue; - } - - for (int a = 0; a < eNoN; a++) { - int Ac = msh.IEN(a,e); - for (int i = 0; i < nsd; i++) { - xl(i,a) = com_mod.x(i,Ac); - } - } - - for (int a = 0; a < eNoNq; a++) { - int Ac = msh.IEN(a,e); - pl(a) = Yn(s+nsd,Ac); - for (int i = 0; i < nsd; i++) { - xql(i,a) = xl(i,a); - } - } - - double eVol = 0.0; - double Jac = 0.0; - - for (int g = 0; g < msh.fs[1].nG; g++) { - if (g == 0 || !msh.fs[1].lShpF) { - auto Nx = msh.fs[1].Nx.slice(g); - nn::gnn(eNoNq, nsd, nsd, Nx, xql, Nqx, Jac, ksix); - - if (utils::is_zero(Jac)) { - throw std::runtime_error("[pic_eth] Jacobian for element " + std::to_string(e) + " is < 0."); - } - } - - eVol = eVol + msh.fs[1].w(g)*Jac; - } - - for (int a = eNoNq; a < eNoN; a++) { - int Ac = msh.IEN(a,e); - for (int i = 0; i < nsd; i++) { - xp(i) = xl(i,a); - } - xi = xi0; - nn::get_nnx(nsd, eType, eNoNq, xql, msh.fs[1].xib, msh.fs[1].Nb, xp, xi, Nq, Nqx); - - double p = 0.0; - for (int b = 0; b < eNoNq; b++) { - p = p + pl(b)*Nq(b); - } - - sF(Ac) = sF(Ac) + p*eVol; - sA(Ac) = sA(Ac) + eVol; - } - } // e-loop - } // iM-loop - - all_fun::commu(com_mod, sA); - all_fun::commu(com_mod, sF); - - for (int a = 0; a < tnNo; a++) { - if (!utils::is_zero(sA(a))) { - Yn(s+nsd,a) = sF(a) / sA(a); - } - } -} - -//------ -// pici -//------ -// This is the initiator. -// -// Uses Generalized α− Method for time stepping. -// -// Modifes Ag from combination of An and Ao defined by coefs from eq.am, eq.af, -// Ag = (1 - eq.am) * Ao + eq.am * An -// Yg = (1 - eq.af) * Yo + eq.af * Yn -// Dg = (1 - eq.af) * Do + eq.af * Dn -// -// Modifies: -// Ag - acceleration -// Yg - velocity -// Dg - displacement -// -void pici(Simulation* simulation, Array& Ag, Array& Yg, Array& Dg) -{ - using namespace consts; - - auto& com_mod = simulation->com_mod; - - #define n_debug_pici - #ifdef debug_pici - DebugMsg dmsg(__func__, com_mod.cm.idcm()); - dmsg.banner(); - #endif - - const int cEq = com_mod.cEq; - const int tnNo = com_mod.tnNo; - auto& eq = com_mod.eq[cEq]; - auto& dof = com_mod.dof; - eq.itr = eq.itr + 1; - - // [NOTE] Setting gobal variable 'dof'. - dof = eq.dof; - #ifdef debug_pici - dmsg << "cEq: " << cEq; - dmsg << "eq.itr: " << eq.itr; - dmsg << "dof: " << dof; - dmsg << "tnNo: " << tnNo; - dmsg << "com_mod.pstEq: " << com_mod.pstEq; - #endif - - const auto& Ao = com_mod.Ao; - const auto& An = com_mod.An; - const auto& Do = com_mod.Do; - const auto& Dn = com_mod.Dn; - const auto& Yo = com_mod.Yo; - const auto& Yn = com_mod.Yn; - - for (int i = 0; i < com_mod.nEq; i++) { - auto& eq = com_mod.eq[i]; - int s = eq.s; - int e = eq.e; - Vector coef(4); - coef(0) = 1.0 - eq.am; - coef(1) = eq.am; - coef(2) = 1.0 - eq.af; - coef(3) = eq.af; - #ifdef debug_pici - dmsg << "s: " << s; - dmsg << "e: " << e; - dmsg << "coef: " << coef[0] << " " << coef[1] << " " << coef[2] << " " << coef[3]; - #endif - - if ((eq.phys == Equation_heatF) && (com_mod.usePrecomp)){ - for (int a = 0; a < tnNo; a++) { - for (int j = 0; j < com_mod.nsd; j++) { - //Ag(j, a) = An(j, a); - //Yg(j, a) = Yn(j, a); - //Dg(j, a) = Dn(j, a); - Ag(j, a) = Ao(j, a) * coef(0) + An(j, a) * coef(1); - Yg(j, a) = Yo(j, a) * coef(2) + Yn(j, a) * coef(3); - Dg(j, a) = Do(j, a) * coef(2) + Dn(j, a) * coef(3); - } - } - for (int a = 0; a < tnNo; a++) { - for (int j = s; j <= e; j++) { - Ag(j, a) = Ao(j, a) * coef(0) + An(j, a) * coef(1); - Yg(j, a) = Yo(j, a) * coef(2) + Yn(j, a) * coef(3); - Dg(j, a) = Do(j, a) * coef(2) + Dn(j, a) * coef(3); - } - } - } else { - for (int a = 0; a < tnNo; a++) { - for (int j = s; j <= e; j++) { - // eqn 89 of Bazilevs 2007 - Ag(j, a) = Ao(j, a) * coef(0) + An(j, a) * coef(1); - - // eqn 90 of Bazilevs 2007 - Yg(j, a) = Yo(j, a) * coef(2) + Yn(j, a) * coef(3); - - Dg(j, a) = Do(j, a) * coef(2) + Dn(j, a) * coef(3); - } - } - } - } - - // prestress - if (com_mod.pstEq) { - com_mod.pSn = 0.0; - com_mod.pSa = 0.0; - } -} - -//------ -// picp -//------ -// This is the predictor. -// -// Modifies: -// pS0 -// Ad -// Ao -// Yo -// Do -// An -// Yn -// Dn -// -void picp(Simulation* simulation) -{ - using namespace consts; - - auto& com_mod = simulation->com_mod; - - #define n_debug_picp - #ifdef debug_picp - DebugMsg dmsg(__func__, com_mod.cm.idcm()); - dmsg.banner(); - dmsg << "pstEq: " << com_mod.pstEq; - #endif - - // Variables for prestress calculations - auto& pS0 = com_mod.pS0; - auto& pSn = com_mod.pSn; - - // time derivative of displacement - auto& Ad = com_mod.Ad; - - auto& Ao = com_mod.Ao; - auto& An = com_mod.An; - auto& Yo = com_mod.Yo; - auto& Yn = com_mod.Yn; - auto& Do = com_mod.Do; - auto& Dn = com_mod.Dn; - - // Prestress initialization - if (com_mod.pstEq) { - pS0 = pS0 + pSn; - Ao = 0.0; - Yo = 0.0; - Do = 0.0; - } - - // IB treatment: Set dirichlet BC and update traces. For explicit - // coupling, compute FSI forcing and freeze it for the time step. - // For implicit coupling, project IB displacement on background - // mesh and predict quantities at next time step - // - // [NOTE] not implemented. - /* - if (ibFlag) { - // Set IB Dirichlet BCs - CALL IB_SETBCDIR(ib.Yb, ib.Ubo) - - // Update IB location and tracers - CALL IB_UPDATE(Do) - - if (ib.cpld == ibCpld_E) { - // FSI forcing for immersed bodies (explicit coupling) - CALL IB_CALCFFSI(Ao, Yo, Do, ib.Auo, ib.Ubo) - - } else { if (ib.cpld == ibCpld_I) { - // Project IB displacement (Ubn) to background mesh - CALL IB_PRJCTU(Do) - - // Predictor step for implicit coupling - CALL IB_PICP() - } - } - */ - - const auto& dt = com_mod.dt; - #ifdef debug_picp - dmsg << "dt: " << dt; - dmsg << "dFlag: " << com_mod.dFlag; - #endif - - for (int iEq = 0; iEq < com_mod.nEq; iEq++) { - auto& eq = com_mod.eq[iEq]; - int s = eq.s; // start row - int e = eq.e; // end row - - #ifdef debug_picp - dmsg << "----- iEq " << iEq << " -----"; - dmsg << "s: " << s; - dmsg << "e: " << e; - dmsg << "eq.gam: " << eq.gam; - dmsg << "coef: " << coef; - #endif - - // [TODO:DaveP] careful here with s amd e. - double coef = (eq.gam - 1.0) / eq.gam; - for (int i = s; i <= e; i++) { - for (int j = 0; j < Ao.ncols(); j++) { - // eqn 87 of Bazilevs 2007 - An(i,j) = Ao(i,j) * coef; - } - } - - // electrophysiology - if (eq.phys == Equation_CEP) { - cep_ion::cep_integ(simulation, iEq, e, Do); - } - - // eqn 86 of Bazilevs 2007 - Yn.set_rows(s,e, Yo.rows(s,e)); - - if (com_mod.dFlag) { - - // struct, lElas, FSI (struct, mesh) - if (!com_mod.sstEq) { - double coef = dt*dt*(0.5*eq.gam - eq.beta) / (eq.gam - 1.0); - Dn.set_rows(s,e, Do.rows(s,e) + Yn.rows(s,e)*dt + An.rows(s,e)*coef); - - // ustruct, FSI - // - } else { - - if (eq.phys == Equation_ustruct || eq.phys == Equation_FSI) { - double coef = (eq.gam - 1.0) / eq.gam; - Ad = Ad*coef; - Dn.set_rows(s,e, Do.rows(s,e)); - - } else if (eq.phys == Equation_mesh) { - double coef = dt*dt*(0.5*eq.gam - eq.beta) / (eq.gam - 1.0); - Dn.set_rows(s,e, Do.rows(s,e) + Yn.rows(s,e)*dt + An.rows(s,e)*coef); - } - } - } else { - Dn.set_rows(s,e, Do.rows(s,e)); - } - } -} - -}; - diff --git a/Code/Source/solver/pic.h b/Code/Source/solver/pic.h deleted file mode 100644 index af7aaf397..000000000 --- a/Code/Source/solver/pic.h +++ /dev/null @@ -1,22 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (c) Stanford University, The Regents of the University of California, and others. -// SPDX-License-Identifier: BSD-3-Clause - -#include "Simulation.h" - -#ifndef PIC_H -#define PIC_H - -namespace pic { - -void picc(Simulation* simulation); - -void pic_eth(Simulation* simulation); - -void pici(Simulation* simulation, Array& Ag, Array& Yg, Array& Dg); - -void picp(Simulation* simulation); - -}; - -#endif - From 98d09f02d96ece74750ea1a0169d6cfa2b172280 Mon Sep 17 00:00:00 2001 From: Shiyi Chen Date: Fri, 7 Nov 2025 17:21:20 +0000 Subject: [PATCH 13/33] Extract An, Dn, and Yn from ComMod to Integrator class Move time integration variables An (acceleration), Dn (displacement), and Yn (velocity) from the global ComMod structure into the Integrator class. These variables are now passed as function parameters throughout the codebase instead of accessing them through ComMod. Changes include: - Add An_, Dn_, Yn_ members to Integrator with public getters - Initialize from Ao, Do, Yo in Integrator::initialize_arrays() - Update 19 files to pass these variables as Array& parameters - Remove An, Dn, Yn declarations from ComMod.h --- Code/Source/solver/ComMod.h | 9 ------ Code/Source/solver/Integrator.cpp | 52 +++++++++++++++++++------------ Code/Source/solver/Integrator.h | 30 ++++++++++++++++++ Code/Source/solver/baf_ini.cpp | 2 +- Code/Source/solver/initialize.cpp | 23 ++++++-------- Code/Source/solver/main.cpp | 28 ++++++++--------- Code/Source/solver/nn.cpp | 10 ++++-- Code/Source/solver/nn.h | 2 +- Code/Source/solver/output.cpp | 14 +++------ Code/Source/solver/output.h | 4 +-- Code/Source/solver/remesh.cpp | 4 +-- Code/Source/solver/ris.cpp | 32 +++++++++---------- Code/Source/solver/ris.h | 8 ++--- Code/Source/solver/set_bc.cpp | 20 ++++++------ Code/Source/solver/set_bc.h | 8 ++--- Code/Source/solver/txt.cpp | 14 ++++----- Code/Source/solver/txt.h | 2 +- Code/Source/solver/uris.cpp | 8 ++--- Code/Source/solver/uris.h | 4 +-- 19 files changed, 147 insertions(+), 127 deletions(-) diff --git a/Code/Source/solver/ComMod.h b/Code/Source/solver/ComMod.h index c8d800cdd..7fe4eb6b5 100644 --- a/Code/Source/solver/ComMod.h +++ b/Code/Source/solver/ComMod.h @@ -1745,15 +1745,9 @@ class ComMod { /// @brief Old time derivative of variables (acceleration); known result at current time step Array Ao; - /// @brief New time derivative of variables (acceleration); unknown result at next time step - Array An; - /// @brief Old integrated variables (displacement) Array Do; - /// @brief New integrated variables (displacement) - Array Dn; - /// @brief Residual vector Array R; @@ -1766,9 +1760,6 @@ class ComMod { /// @brief Old variables (velocity); known result at current time step Array Yo; - /// @brief New variables (velocity); unknown result at next time step - Array Yn; - /// @brief Body force Array Bf; diff --git a/Code/Source/solver/Integrator.cpp b/Code/Source/solver/Integrator.cpp index 20e62c269..2cb3a0d52 100644 --- a/Code/Source/solver/Integrator.cpp +++ b/Code/Source/solver/Integrator.cpp @@ -50,8 +50,18 @@ void Integrator::initialize_arrays() { Ag_.resize(tDof, tnNo); Yg_.resize(tDof, tnNo); Dg_.resize(tDof, tnNo); + An_.resize(tDof, tnNo); + Dn_.resize(tDof, tnNo); + Yn_.resize(tDof, tnNo); res_.resize(nFacesLS); incL_.resize(nFacesLS); + + // Initialize An_ = Ao (same as what was done in initialize.cpp:760) + An_ = com_mod.Ao; + // Initialize Dn_ = Do (same as what was done in initialize.cpp:761) + Dn_ = com_mod.Do; + // Initialize Yn_ = Yo (same as what was done in initialize.cpp:760) + Yn_ = com_mod.Yo; } //------------------------ @@ -65,9 +75,9 @@ bool Integrator::step() { auto& cm_mod = simulation_->cm_mod; auto& cep_mod = simulation_->get_cep_mod(); - auto& An = com_mod.An; - auto& Yn = com_mod.Yn; - auto& Dn = com_mod.Dn; + auto& An = An_; // Use member variable + auto& Yn = Yn_; + auto& Dn = Dn_; int& cTS = com_mod.cTS; int& cEq = com_mod.cEq; @@ -99,7 +109,7 @@ bool Integrator::step() { #ifdef debug_integrator_step dmsg << "Set coupled BCs " << std::endl; #endif - set_bc::set_bc_cpl(com_mod, cm_mod); + set_bc::set_bc_cpl(com_mod, cm_mod, Yn); set_bc::set_bc_dir(com_mod, An, Yn, Dn); } @@ -212,7 +222,7 @@ void Integrator::initiator_step() { Ag_.write("Ag_pic" + istr_); Yg_.write("Yg_pic" + istr_); Dg_.write("Dg_pic" + istr_); - simulation_->com_mod.Yn.write("Yn_pic" + istr_); + Yn_.write("Yn_pic" + istr_); } //------------------------ @@ -258,11 +268,13 @@ void Integrator::apply_boundary_conditions() { auto& com_mod = simulation_->com_mod; auto& cm_mod = simulation_->cm_mod; + auto& Yn = Yn_; + Yg_.write("Yg_vor_neu" + istr_); Dg_.write("Dg_vor_neu" + istr_); // Apply Neumman or Traction boundary conditions - set_bc::set_bc_neu(com_mod, cm_mod, Yg_, Dg_); + set_bc::set_bc_neu(com_mod, cm_mod, Yg_, Dg_, Yn); // Apply CMM BC conditions if (!com_mod.cmmInit) { @@ -277,7 +289,7 @@ void Integrator::apply_boundary_conditions() { } if (com_mod.ris0DFlag) { - ris::ris0d_bc(com_mod, cm_mod, Yg_, Dg_); + ris::ris0d_bc(com_mod, cm_mod, Yg_, Dg_, Yn); } // Apply contact model and add its contribution to residual @@ -315,7 +327,7 @@ bool Integrator::corrector_and_check_convergence() { picc(); // Debug output - com_mod.Yn.write("Yn_picc" + istr_); + Yn_.write("Yn_picc" + istr_); // Check if all equations converged return std::count_if(com_mod.eq.begin(), com_mod.eq.end(), @@ -385,11 +397,11 @@ void Integrator::predictor() auto& Ad = com_mod.Ad; auto& Ao = com_mod.Ao; - auto& An = com_mod.An; + auto& An = An_; // Use member variable auto& Yo = com_mod.Yo; - auto& Yn = com_mod.Yn; + auto& Yn = Yn_; auto& Do = com_mod.Do; - auto& Dn = com_mod.Dn; + auto& Dn = Dn_; // Prestress initialization if (com_mod.pstEq) { @@ -536,11 +548,11 @@ void Integrator::pici(Array& Ag, Array& Yg, Array& Dg) #endif const auto& Ao = com_mod.Ao; - const auto& An = com_mod.An; + const auto& An = An_; // Use member variable const auto& Do = com_mod.Do; - const auto& Dn = com_mod.Dn; + const auto& Dn = Dn_; const auto& Yo = com_mod.Yo; - const auto& Yn = com_mod.Yn; + const auto& Yn = Yn_; for (int i = 0; i < com_mod.nEq; i++) { auto& eq = com_mod.eq[i]; @@ -606,7 +618,7 @@ void Integrator::pici(Array& Ag, Array& Yg, Array& Dg) /// Modifies: /// \code {.cpp} /// com_mod.Ad -/// com_mod.An +/// An_ (member variable) /// com_mod.Dn /// com_mod.Yn /// cep_mod.Xion @@ -642,10 +654,10 @@ void Integrator::picc() auto& cEq = com_mod.cEq; auto& eq = com_mod.eq[cEq]; - auto& An = com_mod.An; + auto& An = An_; // Use member variable auto& Ad = com_mod.Ad; - auto& Dn = com_mod.Dn; - auto& Yn = com_mod.Yn; + auto& Dn = Dn_; + auto& Yn = Yn_; auto& pS0 = com_mod.pS0; auto& pSa = com_mod.pSa; @@ -887,7 +899,7 @@ void Integrator::picc() /// (i.e., corner nodes). For e.g., for a P2 element, pressure is /// interpolated at the edge nodes using P1 vertices. /// -/// Modifies: com_mod.Yn +/// Modifies: Yn_ /// void Integrator::pic_eth() { @@ -903,7 +915,7 @@ void Integrator::pic_eth() const auto& eq = com_mod.eq[cEq]; auto& cDmn = com_mod.cDmn; - auto& Yn = com_mod.Yn; + auto& Yn = Yn_; // Check for something ... // diff --git a/Code/Source/solver/Integrator.h b/Code/Source/solver/Integrator.h index b351e7859..3a9ef350a 100644 --- a/Code/Source/solver/Integrator.h +++ b/Code/Source/solver/Integrator.h @@ -75,6 +75,27 @@ class Integrator { */ Array& get_Dg() { return Dg_; } + /** + * @brief Get reference to An (new time derivative of variables at n+1) + * + * @return Reference to An array (acceleration at next time step) + */ + Array& get_An() { return An_; } + + /** + * @brief Get reference to Dn (new integrated variables at n+1) + * + * @return Reference to Dn array (displacement at next time step) + */ + Array& get_Dn() { return Dn_; } + + /** + * @brief Get reference to Yn (new variables at n+1) + * + * @return Reference to Yn array (velocity at next time step) + */ + Array& get_Yn() { return Yn_; } + private: /** @brief Pointer to the simulation object */ Simulation* simulation_; @@ -88,6 +109,15 @@ class Integrator { /** @brief Integrated variables (displacement in structural mechanics) */ Array Dg_; + /** @brief New time derivative of variables at n+1 (acceleration at next time step) */ + Array An_; + + /** @brief New integrated variables at n+1 (displacement at next time step) */ + Array Dn_; + + /** @brief New variables at n+1 (velocity at next time step) */ + Array Yn_; + /** @brief Residual vector for face-based quantities */ Vector res_; diff --git a/Code/Source/solver/baf_ini.cpp b/Code/Source/solver/baf_ini.cpp index b10b3100e..c411545a3 100644 --- a/Code/Source/solver/baf_ini.cpp +++ b/Code/Source/solver/baf_ini.cpp @@ -145,7 +145,7 @@ void baf_ini(Simulation* simulation) } if (com_mod.cplBC.schm != CplBCType::cplBC_E) { - set_bc::calc_der_cpl_bc(com_mod, cm_mod); + set_bc::calc_der_cpl_bc(com_mod, cm_mod, com_mod.Yo); } } diff --git a/Code/Source/solver/initialize.cpp b/Code/Source/solver/initialize.cpp index 7f1e1ae84..50142276d 100644 --- a/Code/Source/solver/initialize.cpp +++ b/Code/Source/solver/initialize.cpp @@ -621,13 +621,13 @@ void initialize(Simulation* simulation, Vector& timeP) com_mod.ltg, com_mod.rowPtr, com_mod.colPtr, nFacesLS); // Variable allocation and initialization - int tnNo = com_mod.tnNo; - com_mod.Ao.resize(tDof,tnNo); - com_mod.An.resize(tDof,tnNo); - com_mod.Yo.resize(tDof,tnNo); - com_mod.Yn.resize(tDof,tnNo); - com_mod.Do.resize(tDof,tnNo); - com_mod.Dn.resize(tDof,tnNo); + int tnNo = com_mod.tnNo; + com_mod.Ao.resize(tDof,tnNo); + // An moved to Integrator class + com_mod.Yo.resize(tDof,tnNo); + // Yn moved to Integrator class + com_mod.Do.resize(tDof,tnNo); + // Dn moved to Integrator class com_mod.Bf.resize(nsd,tnNo); // [TODO] DaveP not implemented? @@ -756,10 +756,7 @@ void initialize(Simulation* simulation, Vector& timeP) } // resetSim // Initialize new variables - // - com_mod.An = com_mod.Ao; - com_mod.Yn = com_mod.Yo; - com_mod.Dn = com_mod.Do; + // An, Yn, Dn moved to Integrator class (initialized there from Ao, Yo, Do) for (int iM = 0; iM < nMsh; iM++) { if (cm.mas(cm_mod)) { @@ -837,8 +834,8 @@ void initialize(Simulation* simulation, Vector& timeP) // set_bc::set_bc_dir(com_mod, com_mod.Ao, com_mod.Yo, com_mod.Do); - // Preparing TXT files - txt_ns::txt(simulation, true); + // Preparing TXT files (pass Ao, Do, and Yo since An, Dn, and Yn haven't been created in Integrator yet) + txt_ns::txt(simulation, true, com_mod.Ao, com_mod.Do, com_mod.Yo); // Printing the first line and initializing timeP int co = 1; diff --git a/Code/Source/solver/main.cpp b/Code/Source/solver/main.cpp index b66717a45..78fe7703d 100644 --- a/Code/Source/solver/main.cpp +++ b/Code/Source/solver/main.cpp @@ -80,7 +80,7 @@ void read_files(Simulation* simulation, const std::string& file_name) /// @brief Iterate the precomputed state-variables in time using linear interpolation to the current time step size // -void iterate_precomputed_time(Simulation* simulation) { +void iterate_precomputed_time(Simulation* simulation, Array& An, Array& Yn) { using namespace consts; auto& com_mod = simulation->com_mod; @@ -103,9 +103,7 @@ void iterate_precomputed_time(Simulation* simulation) { 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 + // An is now passed as a parameter (from integrator.get_An()) int& cTS = com_mod.cTS; int& nITs = com_mod.nITs; @@ -239,9 +237,9 @@ void iterate_solution(Simulation* simulation) auto& Yo = com_mod.Yo; // Old variables (velocity) auto& Do = com_mod.Do; // Old integrated variables (displacement) - auto& An = com_mod.An; // New time derivative of variables (acceleration) - auto& Yn = com_mod.Yn; // New variables (velocity) - auto& Dn = com_mod.Dn; // New integrated variables (displacement) + auto& An = integrator.get_An(); // New time derivative of variables (acceleration) + auto& Yn = integrator.get_Yn(); // New variables (velocity) + auto& Dn = integrator.get_Dn(); // New integrated variables (displacement) bool l1 = false; bool l2 = false; @@ -333,7 +331,7 @@ void iterate_solution(Simulation* simulation) if (com_mod.urisFlag) {uris::uris_calc_sdf(com_mod);} - iterate_precomputed_time(simulation); + iterate_precomputed_time(simulation, integrator.get_An(), integrator.get_Yn()); // Inner loop for Newton iteration - now encapsulated in Integrator class // @@ -363,7 +361,7 @@ void iterate_solution(Simulation* simulation) */ if (com_mod.risFlag) { - ris::ris_meanq(com_mod, cm_mod); + ris::ris_meanq(com_mod, cm_mod, An, Dn, Yn); ris::ris_status(com_mod, cm_mod); if (cm.mas(cm_mod)) { std::cout << "Iteration: " << com_mod.cTS << std::endl; @@ -381,7 +379,7 @@ void iterate_solution(Simulation* simulation) std::cout << "Valve status just changed. Do not update" << std::endl; } } else { - ris::ris_updater(com_mod, cm_mod); + ris::ris_updater(com_mod, cm_mod, An, Dn, Yn); } // goto label_11; } @@ -393,7 +391,7 @@ void iterate_solution(Simulation* simulation) dmsg << "Saving the TXT files containing ECGs ..." << std::endl; #endif - txt_ns::txt(simulation, false); + txt_ns::txt(simulation, false, An, Dn, Yn); // If remeshing is required then save current solution. // @@ -457,7 +455,7 @@ void iterate_solution(Simulation* simulation) // Saving the result to restart bin file if (l1 || l2) { - output::write_restart(simulation, com_mod.timeP); + output::write_restart(simulation, com_mod.timeP, An, Dn, Yn); } // Writing results into the disk with VTU format @@ -499,7 +497,7 @@ void iterate_solution(Simulation* simulation) // [HZ] Part related to RIS0D if (cEq == 0 && com_mod.ris0DFlag) { - ris::ris0d_status(com_mod, cm_mod); + ris::ris0d_status(com_mod, cm_mod, An, Dn, Yn); } // [HZ] Part related to unfitted RIS @@ -508,12 +506,12 @@ void iterate_solution(Simulation* simulation) for (int iUris = 0; iUris < com_mod.nUris; iUris++) { com_mod.uris[iUris].cnt++; if (com_mod.uris[iUris].clsFlg) { - uris::uris_meanp(com_mod, cm_mod, iUris); + uris::uris_meanp(com_mod, cm_mod, iUris, Yn); // if (com_mod.uris[iUris].cnt == 1) { // // GOTO 11 // The GOTO Statement in the Fortran code // } } else { - uris::uris_meanv(com_mod, cm_mod, iUris); + uris::uris_meanv(com_mod, cm_mod, iUris, Yn); } if (cm.mas(cm_mod)) { std::cout << " URIS surface: " << com_mod.uris[iUris].name << ", count: " << com_mod.uris[iUris].cnt << std::endl; diff --git a/Code/Source/solver/nn.cpp b/Code/Source/solver/nn.cpp index 6a78ca100..757c6846e 100644 --- a/Code/Source/solver/nn.cpp +++ b/Code/Source/solver/nn.cpp @@ -522,8 +522,8 @@ void gnn(const int eNoN, const int nsd, const int insd, Array& Nxi, Arra /// /// Reproduce Fortran 'GNNB'. // -void gnnb(const ComMod& com_mod, const faceType& lFa, const int e, const int g, const int nsd, const int insd, - const int eNoNb, const Array& Nx, Vector& n, MechanicalConfigurationType cfg) +void gnnb(const ComMod& com_mod, const faceType& lFa, const int e, const int g, const int nsd, const int insd, + const int eNoNb, const Array& Nx, Vector& n, MechanicalConfigurationType cfg, const Array* Dn) { auto& cm = com_mod.cm; @@ -625,7 +625,11 @@ void gnnb(const ComMod& com_mod, const faceType& lFa, const int e, const int g, case MechanicalConfigurationType::new_timestep: for (int i = 0; i < lX.nrows(); i++) { // Add displacement at timestep n+1 - lX(i,a) = lX(i,a) + com_mod.Dn(i,Ac); + if (Dn != nullptr) { + lX(i,a) = lX(i,a) + (*Dn)(i,Ac); + } else { + lX(i,a) = lX(i,a) + com_mod.Do(i,Ac); // Fallback to Do if Dn not provided + } } break; default: diff --git a/Code/Source/solver/nn.h b/Code/Source/solver/nn.h index 758ac491a..b6e9344a6 100644 --- a/Code/Source/solver/nn.h +++ b/Code/Source/solver/nn.h @@ -38,7 +38,7 @@ namespace nn { double& Jac, Array& ks); void gnnb(const ComMod& com_mod, const faceType& lFa, const int e, const int g, const int nsd, const int insd, - const int eNoNb, const Array& Nx, Vector& n, consts::MechanicalConfigurationType cfg=consts::MechanicalConfigurationType::reference); + const int eNoNb, const Array& Nx, Vector& n, consts::MechanicalConfigurationType cfg=consts::MechanicalConfigurationType::reference, const Array* Dn=nullptr); void gnns(const int nsd, const int eNoN, const Array& Nxi, Array& xl, Vector& nV, Array& gCov, Array& gCnv); diff --git a/Code/Source/solver/output.cpp b/Code/Source/solver/output.cpp index cd575ed4a..05ee1b1ad 100644 --- a/Code/Source/solver/output.cpp +++ b/Code/Source/solver/output.cpp @@ -172,7 +172,7 @@ void read_restart_header(ComMod& com_mod, std::array& tStamp, double& tim /// @brief Reproduces the Fortran 'WRITERESTART' subroutine. // -void write_restart(Simulation* simulation, std::array& timeP) +void write_restart(Simulation* simulation, std::array& timeP, Array& An, Array& Dn, Array& Yn) { auto& com_mod = simulation->com_mod; #define n_debug_write_restart @@ -193,7 +193,7 @@ void write_restart(Simulation* simulation, std::array& timeP) const bool ibFlag = com_mod.ibFlag; const bool dFlag = com_mod.dFlag; - const bool sstEq = com_mod.sstEq; + const bool sstEq = com_mod.sstEq; const bool pstEq = com_mod.pstEq; const bool cepEq = cep_mod.cepEq; const bool risFlag = com_mod.risFlag; @@ -202,10 +202,8 @@ void write_restart(Simulation* simulation, std::array& timeP) auto& cplBC = com_mod.cplBC; auto& Ad = com_mod.Ad; - auto& An = com_mod.An; - auto& Dn = com_mod.Dn; + // An, Dn, and Yn are now passed as parameters (from integrator getters) auto& pS0 = com_mod.pS0; - auto& Yn = com_mod.Yn; auto& Xion = cep_mod.Xion; auto& cem = cep_mod.cem; @@ -395,13 +393,11 @@ void write_restart_header(ComMod& com_mod, std::array& timeP, std::ofs /// /// Reproduces: WRITE(fid, REC=myID) stamp, cTS, time,CPUT()-timeP(1), eq.iNorm, cplBC.xn, Yn, An, Dn // -void write_results(ComMod& com_mod, const std::array& timeP, const std::string& fName, const bool sstEq) +void write_results(ComMod& com_mod, const std::array& timeP, const std::string& fName, const bool sstEq, Array& An, Array& Dn, Array& Yn) { int cTS = com_mod.cTS; - auto& An = com_mod.An; - auto& Dn = com_mod.Dn; - auto& Yn = com_mod.Yn; + // An, Dn, and Yn are now passed as parameters (from integrator getters) auto& stamp = com_mod.stamp; diff --git a/Code/Source/solver/output.h b/Code/Source/solver/output.h index f0285d948..b90fd77c6 100644 --- a/Code/Source/solver/output.h +++ b/Code/Source/solver/output.h @@ -15,11 +15,11 @@ void output_result(Simulation* simulation, std::array& timeP, const i void read_restart_header(ComMod& com_mod, std::array& tStamp, double& timeP, std::ifstream& restart_file); -void write_restart(Simulation* simulation, std::array& timeP); +void write_restart(Simulation* simulation, std::array& timeP, Array& An, Array& Dn, Array& Yn); void write_restart_header(ComMod& com_mod, std::array& timeP, std::ofstream& restart_file); -void write_results(ComMod& com_mod, const std::array& timeP, const std::string& fName, const bool sstEq); +void write_results(ComMod& com_mod, const std::array& timeP, const std::string& fName, const bool sstEq, Array& An, Array& Dn, Array& Yn); }; diff --git a/Code/Source/solver/remesh.cpp b/Code/Source/solver/remesh.cpp index c8db1ed1c..10eef533e 100644 --- a/Code/Source/solver/remesh.cpp +++ b/Code/Source/solver/remesh.cpp @@ -1889,13 +1889,11 @@ void remesh_restart(Simulation* simulation) com_mod.cmmBdry.clear(); com_mod.iblank.clear(); com_mod.Ao.clear(); - com_mod.An.clear(); + // An, Dn, and Yn moved to Integrator class com_mod.Do.clear(); - com_mod.Dn.clear(); com_mod.R.clear(); com_mod.Val.clear(); com_mod.Yo.clear(); - com_mod.Yn.clear(); com_mod.Bf.clear(); cplBC.nFa = 0; diff --git a/Code/Source/solver/ris.cpp b/Code/Source/solver/ris.cpp index d55a768d9..79b5022ef 100644 --- a/Code/Source/solver/ris.cpp +++ b/Code/Source/solver/ris.cpp @@ -12,8 +12,8 @@ namespace ris { -/// @brief This subroutine computes the mean pressure and flux on the ris surface -void ris_meanq(ComMod& com_mod, CmMod& cm_mod) +/// @brief This subroutine computes the mean pressure and flux on the ris surface +void ris_meanq(ComMod& com_mod, CmMod& cm_mod, Array& An, Array& Dn, Array& Yn) { #define n_debug_ris_meanq #ifdef debug_ris_meanq @@ -32,10 +32,8 @@ void ris_meanq(ComMod& com_mod, CmMod& cm_mod) const int nsd = com_mod.nsd; const int cEq = com_mod.cEq; - auto& An = com_mod.An; + // An, Dn, and Yn are now passed as parameters auto& Ad = com_mod.Ad; - auto& Dn = com_mod.Dn; - auto& Yn = com_mod.Yn; Array tmpV(maxNSD, com_mod.tnNo); @@ -152,9 +150,9 @@ void setbc_ris(ComMod& com_mod, const bcType& lBc, const mshType& lM, const face } -/// @brief This subroutine updates the resistance and activation flag for the -/// closed and open configurations of the RIS surfaces -void ris_updater(ComMod& com_mod, CmMod& cm_mod) +/// @brief This subroutine updates the resistance and activation flag for the +/// closed and open configurations of the RIS surfaces +void ris_updater(ComMod& com_mod, CmMod& cm_mod, Array& An, Array& Dn, Array& Yn) { #define n_debug_ris_updater #ifdef debug_ris_updater @@ -184,9 +182,9 @@ void ris_updater(ComMod& com_mod, CmMod& cm_mod) // goes from close to open to prevent the valve goes back // to close at the next iteration. This is needed only for // close to open and cannot be used for open to close. - com_mod.Ao = com_mod.An; - com_mod.Yo = com_mod.Yn; - if (com_mod.dFlag) {com_mod.Do = com_mod.Dn;} + com_mod.Ao = An; + com_mod.Yo = Yn; + if (com_mod.dFlag) {com_mod.Do = Dn;} com_mod.cplBC.xo = com_mod.cplBC.xn; } } else { @@ -353,7 +351,7 @@ void setbcdir_ris(ComMod& com_mod, Array& lA, Array& lY, Array& Yg, const Array& Dg) +void ris0d_bc(ComMod& com_mod, CmMod& cm_mod, const Array& Yg, const Array& Dg, Array& Yn) { using namespace consts; @@ -397,15 +395,15 @@ void ris0d_bc(ComMod& com_mod, CmMod& cm_mod, const Array& Yg, const Arr lBc.gx.clear(); lBc.eDrn.clear(); } else { - // Apply Neu bc - set_bc::set_bc_neu_l(com_mod, cm_mod, eq[cEq].bc[iBc], msh[iM].fa[iFa], Yg, Dg); + // Apply Neu bc + set_bc::set_bc_neu_l(com_mod, cm_mod, eq[cEq].bc[iBc], msh[iM].fa[iFa], Yg, Dg, Yn); } } } -void ris0d_status(ComMod& com_mod, CmMod& cm_mod)//, const Array& Yg, const Array& Dg) +void ris0d_status(ComMod& com_mod, CmMod& cm_mod, Array& An, Array& Dn, Array& Yn) { using namespace consts; @@ -423,10 +421,8 @@ void ris0d_status(ComMod& com_mod, CmMod& cm_mod)//, const Array& Yg, co const int nsd = com_mod.nsd; const int cEq = com_mod.cEq; - auto& An = com_mod.An; + // An, Dn, and Yn are now passed as parameters auto& Ad = com_mod.Ad; - auto& Dn = com_mod.Dn; - auto& Yn = com_mod.Yn; bcType lBc; faceType lFa; diff --git a/Code/Source/solver/ris.h b/Code/Source/solver/ris.h index 5d55d3db1..ed7b71a26 100644 --- a/Code/Source/solver/ris.h +++ b/Code/Source/solver/ris.h @@ -8,12 +8,12 @@ namespace ris { -void ris_meanq(ComMod& com_mod, CmMod& cm_mod); +void ris_meanq(ComMod& com_mod, CmMod& cm_mod, Array& An, Array& Dn, Array& Yn); void ris_resbc(ComMod& com_mod, const Array& Yg, const Array& Dg); void setbc_ris(ComMod& com_mod, const bcType& lBc, const mshType& lM, const faceType& lFa, const Array& Yg, const Array& Dg); -void ris_updater(ComMod& com_mod, CmMod& cm_mod); +void ris_updater(ComMod& com_mod, CmMod& cm_mod, Array& An, Array& Dn, Array& Yn); void ris_status(ComMod& com_mod, CmMod& cm_mod); void doassem_ris(ComMod& com_mod, const int d, const Vector& eqN, @@ -26,8 +26,8 @@ void clean_r_ris(ComMod& com_mod); void setbcdir_ris(ComMod& com_mod, Array& lA, Array& lY, Array& lD); // TODO: RIS 0D code -void ris0d_bc(ComMod& com_mod, CmMod& cm_mod, const Array& Yg, const Array& Dg); -void ris0d_status(ComMod& com_mod, CmMod& cm_mod); //, const Array& Yg, const Array& Dg); +void ris0d_bc(ComMod& com_mod, CmMod& cm_mod, const Array& Yg, const Array& Dg, Array& Yn); +void ris0d_status(ComMod& com_mod, CmMod& cm_mod, Array& An, Array& Dn, Array& Yn); }; diff --git a/Code/Source/solver/set_bc.cpp b/Code/Source/solver/set_bc.cpp index 884f0b5c8..b428f9b0f 100644 --- a/Code/Source/solver/set_bc.cpp +++ b/Code/Source/solver/set_bc.cpp @@ -27,7 +27,7 @@ namespace set_bc { /// matrix M ~ dP/dQ stored in eq.bc[iBc].r. /// @param com_mod /// @param cm_mod -void calc_der_cpl_bc(ComMod& com_mod, const CmMod& cm_mod) +void calc_der_cpl_bc(ComMod& com_mod, const CmMod& cm_mod, Array& Yn) { using namespace consts; @@ -111,7 +111,7 @@ void calc_der_cpl_bc(ComMod& com_mod, const CmMod& cm_mod) throw std::runtime_error("[calc_der_cpl_bc] Invalid physics type for 0D coupling"); } cplBC.fa[ptr].Qo = all_fun::integ(com_mod, cm_mod, fa, com_mod.Yo, 0, nsd-1, false, cfg_o); - cplBC.fa[ptr].Qn = all_fun::integ(com_mod, cm_mod, fa, com_mod.Yn, 0, nsd-1, false, cfg_n); + cplBC.fa[ptr].Qn = all_fun::integ(com_mod, cm_mod, fa, Yn, 0, nsd-1, false, cfg_n); cplBC.fa[ptr].Po = 0.0; cplBC.fa[ptr].Pn = 0.0; #ifdef debug_calc_der_cpl_bc @@ -125,7 +125,7 @@ void calc_der_cpl_bc(ComMod& com_mod, const CmMod& cm_mod) else if (utils::btest(bc.bType, iBC_Dir)) { double area = fa.area; cplBC.fa[ptr].Po = all_fun::integ(com_mod, cm_mod, fa, com_mod.Yo, nsd) / area; - cplBC.fa[ptr].Pn = all_fun::integ(com_mod, cm_mod, fa, com_mod.Yn, nsd) / area; + cplBC.fa[ptr].Pn = all_fun::integ(com_mod, cm_mod, fa, Yn, nsd) / area; cplBC.fa[ptr].Qo = 0.0; cplBC.fa[ptr].Qn = 0.0; #ifdef debug_calc_der_cpl_bc @@ -645,7 +645,7 @@ void set_bc_cmm_l(ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, con /// @brief Coupled BC quantities are computed here. /// Reproduces the Fortran 'SETBCCPL()' subrotutine. // -void set_bc_cpl(ComMod& com_mod, CmMod& cm_mod) +void set_bc_cpl(ComMod& com_mod, CmMod& cm_mod, Array& Yn) { static double absTol = 1.E-8, relTol = 1.E-5; @@ -655,7 +655,6 @@ void set_bc_cpl(ComMod& com_mod, CmMod& cm_mod) const int tnNo = com_mod.tnNo; auto& cplBC = com_mod.cplBC; auto& Yo = com_mod.Yo; - auto& Yn = com_mod.Yn; const int iEq = 0; auto& eq = com_mod.eq[iEq]; @@ -668,8 +667,8 @@ void set_bc_cpl(ComMod& com_mod, CmMod& cm_mod) // If coupling scheme is implicit, calculate updated pressure and flowrate // from 0D, as well as resistance from 0D using finite difference. - if (cplBC.schm == CplBCType::cplBC_I) { - calc_der_cpl_bc(com_mod, cm_mod); + if (cplBC.schm == CplBCType::cplBC_I) { + calc_der_cpl_bc(com_mod, cm_mod, Yn); // If coupling scheme is semi-implicit or explicit, only calculated updated // pressure and flowrate from 0D @@ -1293,7 +1292,7 @@ void set_bc_dir_wl(ComMod& com_mod, const bcType& lBc, const mshType& lM, const /// @brief Set outlet BCs. // -void set_bc_neu(ComMod& com_mod, const CmMod& cm_mod, const Array& Yg, const Array& Dg) +void set_bc_neu(ComMod& com_mod, const CmMod& cm_mod, const Array& Yg, const Array& Dg, Array& Yn) { using namespace consts; @@ -1325,7 +1324,7 @@ void set_bc_neu(ComMod& com_mod, const CmMod& cm_mod, const Array& Yg, c dmsg << "iFa: " << iFa+1; dmsg << "name: " << com_mod.msh[iM].fa[iFa].name; #endif - set_bc_neu_l(com_mod, cm_mod, bc, com_mod.msh[iM].fa[iFa], Yg, Dg); + set_bc_neu_l(com_mod, cm_mod, bc, com_mod.msh[iM].fa[iFa], Yg, Dg, Yn); } else if (utils::btest(bc.bType,iBC_trac)) { set_bc_trac_l(com_mod, cm_mod, bc, com_mod.msh[iM].fa[iFa]); @@ -1335,7 +1334,7 @@ void set_bc_neu(ComMod& com_mod, const CmMod& cm_mod, const Array& Yg, c /// @brief Set Neumann BC // -void set_bc_neu_l(ComMod& com_mod, const CmMod& cm_mod, const bcType& lBc, const faceType& lFa, const Array& Yg, const Array& Dg) +void set_bc_neu_l(ComMod& com_mod, const CmMod& cm_mod, const bcType& lBc, const faceType& lFa, const Array& Yg, const Array& Dg, Array& Yn) { using namespace consts; @@ -1349,7 +1348,6 @@ void set_bc_neu_l(ComMod& com_mod, const CmMod& cm_mod, const bcType& lBc, const auto& eq = com_mod.eq[cEq]; int tnNo = com_mod.tnNo; int nsd = com_mod.nsd; - auto& Yn = com_mod.Yn; int nNo = lFa.nNo; Vector h(1), rtmp(1); diff --git a/Code/Source/solver/set_bc.h b/Code/Source/solver/set_bc.h index 5f3be8657..04ecd4284 100644 --- a/Code/Source/solver/set_bc.h +++ b/Code/Source/solver/set_bc.h @@ -12,7 +12,7 @@ namespace set_bc { -void calc_der_cpl_bc(ComMod& com_mod, const CmMod& cm_mod); +void calc_der_cpl_bc(ComMod& com_mod, const CmMod& cm_mod, Array& Yn); void cplBC_Integ_X(ComMod& com_mod, const CmMod& cm_mod, const bool RCRflag); @@ -25,15 +25,15 @@ void RCR_Integ_X(ComMod& com_mod, const CmMod& cm_mod, int istat); void set_bc_cmm(ComMod& com_mod, const CmMod& cm_mod, const Array& Ag, const Array& Dg); void set_bc_cmm_l(ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, const Array& Ag, const Array& Dg ); -void set_bc_cpl(ComMod& com_mod, CmMod& cm_mod); +void set_bc_cpl(ComMod& com_mod, CmMod& cm_mod, Array& Yn); void set_bc_dir(ComMod& com_mod, Array& lA, Array& lY, Array& lD); void set_bc_dir_l(ComMod& com_mod, const bcType& lBc, const faceType& lFa, Array& lA, Array& lY, int lDof); void set_bc_dir_w(ComMod& com_mod, const Array& Yg, const Array& Dg); void set_bc_dir_wl(ComMod& com_mod, const bcType& lBc, const mshType& lM, const faceType& lFa, const Array& Yg, const Array& Dg); -void set_bc_neu(ComMod& com_mod, const CmMod& cm_mod, const Array& Yg, const Array& Dg); -void set_bc_neu_l(ComMod& com_mod, const CmMod& cm_mod, const bcType& lBc, const faceType& lFa, const Array& Yg, const Array& Dg); +void set_bc_neu(ComMod& com_mod, const CmMod& cm_mod, const Array& Yg, const Array& Dg, Array& Yn); +void set_bc_neu_l(ComMod& com_mod, const CmMod& cm_mod, const bcType& lBc, const faceType& lFa, const Array& Yg, const Array& Dg, Array& Yn); void set_bc_rbnl(ComMod& com_mod, const faceType& lFa, const RobinBoundaryCondition& robin_bc, const Array& Yg, const Array& Dg); diff --git a/Code/Source/solver/txt.cpp b/Code/Source/solver/txt.cpp index 4b52cca07..d18d29740 100644 --- a/Code/Source/solver/txt.cpp +++ b/Code/Source/solver/txt.cpp @@ -140,7 +140,7 @@ void create_volume_integral_file(const ComMod& com_mod, CmMod& cm_mod, const eqT // init_write - if true then this is the start of the simulation and // so create a new file to initialize output. // -void txt(Simulation* simulation, const bool init_write) +void txt(Simulation* simulation, const bool init_write, Array& An, Array& Dn, Array& Yn) { using namespace consts; using namespace utils; @@ -269,7 +269,7 @@ void txt(Simulation* simulation, const bool init_write) case OutputNameType::outGrp_A: for (int j = 0; j < tnNo; j++) { for (int i = 0; i < l; i++) { - tmpV(i,j) = com_mod.An(i+s,j); + tmpV(i,j) = An(i+s,j); } } break; @@ -277,7 +277,7 @@ void txt(Simulation* simulation, const bool init_write) case OutputNameType::outGrp_Y: for (int j = 0; j < tnNo; j++) { for (int i = 0; i < l; i++) { - tmpV(i,j) = com_mod.Yn(i+s,j); + tmpV(i,j) = Yn(i+s,j); } } @@ -289,7 +289,7 @@ void txt(Simulation* simulation, const bool init_write) case OutputNameType::outGrp_D: for (int j = 0; j < tnNo; j++) { for (int i = 0; i < l; i++) { - tmpV(i,j) = com_mod.Dn(i+s,j); + tmpV(i,j) = Dn(i+s,j); } } break; @@ -297,7 +297,7 @@ void txt(Simulation* simulation, const bool init_write) case OutputNameType::outGrp_WSS: case OutputNameType::outGrp_vort: case OutputNameType::outGrp_trac: - post::all_post(simulation, tmpV, com_mod.Yn, com_mod.Dn, oGrp, iEq); + post::all_post(simulation, tmpV, Yn, Dn, oGrp, iEq); for (int a = 0; a < tnNo; a++) { auto vec = tmpV.col(a, {0,nsd-1}); tmpV(0,a) = sqrt(norm(vec)); @@ -310,13 +310,13 @@ void txt(Simulation* simulation, const bool init_write) case OutputNameType::outGrp_divV: case OutputNameType::outGrp_J: case OutputNameType::outGrp_mises: - post::all_post(simulation, tmpV, com_mod.Yn, com_mod.Dn, oGrp, iEq); + post::all_post(simulation, tmpV, Yn, Dn, oGrp, iEq); break; case OutputNameType::outGrp_absV: for (int a = 0; a < tnNo; a++) { for (int i = 0; i < l; i++) { - tmpV(i,a) = com_mod.Yn(i,a) - com_mod.Yn(i+nsd+1,a); + tmpV(i,a) = Yn(i,a) - Yn(i+nsd+1,a); } } break; diff --git a/Code/Source/solver/txt.h b/Code/Source/solver/txt.h index c957c0c66..70a9ed9e0 100644 --- a/Code/Source/solver/txt.h +++ b/Code/Source/solver/txt.h @@ -16,7 +16,7 @@ void create_boundary_integral_file(const ComMod& com_mod, CmMod& cm_mod, const e void create_volume_integral_file(const ComMod& com_mod, CmMod& cm_mod, const eqType& lEq, const std::string& file_name); -void txt(Simulation* simulation, const bool flag); +void txt(Simulation* simulation, const bool flag, Array& An, Array& Dn, Array& Yn); void write_boundary_integral_data(const ComMod& com_mod, CmMod& cm_mod, const eqType& lEq, const int m, const std::string file_name, const Array& tmpV, const bool div, const bool pFlag); diff --git a/Code/Source/solver/uris.cpp b/Code/Source/solver/uris.cpp index 055a0c110..a99c5a8bc 100644 --- a/Code/Source/solver/uris.cpp +++ b/Code/Source/solver/uris.cpp @@ -19,7 +19,7 @@ namespace uris { /// @brief This subroutine computes the mean pressure and flux on the /// immersed surface -void uris_meanp(ComMod& com_mod, CmMod& cm_mod, const int iUris) { +void uris_meanp(ComMod& com_mod, CmMod& cm_mod, const int iUris, Array& Yn) { #define n_debug_uris_meanp #ifdef debug_uris_meanp DebugMsg dmsg(__func__, com_mod.cm.idcm()); @@ -41,7 +41,7 @@ void uris_meanp(ComMod& com_mod, CmMod& cm_mod, const int iUris) { // auto& An = com_mod.An; // auto& Ad = com_mod.Ad; // auto& Dn = com_mod.Dn; - auto& Yn = com_mod.Yn; + // Yn is now passed as a parameter // Let's conpute the mean pressure in the two regions of the fluid mesh // For the moment let's define a flag IdSubDmn(size the number of elements) @@ -151,7 +151,7 @@ void uris_meanp(ComMod& com_mod, CmMod& cm_mod, const int iUris) { /// @brief This subroutine computes the mean velocity in the fluid elements /// near the immersed surface -void uris_meanv(ComMod& com_mod, CmMod& cm_mod, const int iUris) { +void uris_meanv(ComMod& com_mod, CmMod& cm_mod, const int iUris, Array& Yn) { #define n_debug_uris_meanv #ifdef debug_uris_meanv DebugMsg dmsg(__func__, com_mod.cm.idcm()); @@ -173,7 +173,7 @@ void uris_meanv(ComMod& com_mod, CmMod& cm_mod, const int iUris) { // auto& An = com_mod.An; // auto& Ad = com_mod.Ad; // auto& Dn = com_mod.Dn; - auto& Yn = com_mod.Yn; + // Yn is now passed as a parameter // Let's compute the neighboring region below the valve normal. When // the valve is open, this region should roughly be valve oriface. diff --git a/Code/Source/solver/uris.h b/Code/Source/solver/uris.h index cb83ba299..aaefb61c2 100644 --- a/Code/Source/solver/uris.h +++ b/Code/Source/solver/uris.h @@ -9,9 +9,9 @@ namespace uris { -void uris_meanp(ComMod& com_mod, CmMod& cm_mod, const int iUris); // done +void uris_meanp(ComMod& com_mod, CmMod& cm_mod, const int iUris, Array& Yn); // done -void uris_meanv(ComMod& com_mod, CmMod& cm_mod, const int iUris); // done +void uris_meanv(ComMod& com_mod, CmMod& cm_mod, const int iUris, Array& Yn); // done void uris_update_disp(ComMod& com_mod, CmMod& cm_mod); From 8e2f9d69275782f790b6b68f58957180286da217 Mon Sep 17 00:00:00 2001 From: Shiyi Chen Date: Fri, 7 Nov 2025 18:57:07 +0000 Subject: [PATCH 14/33] Extract Ao, Do, Yo from ComMod to Integrator class This commit completes the extraction of time-level variables from the global ComMod structure to the Integrator class. Ao, Do, Yo (old acceleration, displacement, velocity at time level n) join An, Dn, Yn as Integrator members. Key changes: - ComMod.h: Removed Ao, Do, Yo member variables - Integrator.h/cpp: Added Ao_, Do_, Yo_ members with move constructor and getters - Simulation.h/cpp: Added initialize_integrator() to transfer ownership - initialize.cpp: Made Ao, Do, Yo local variables, moved to Integrator - Updated 25+ files with function signatures to pass Ao/Do/Yo parameters - Fixed default parameter placement (declarations only, not definitions) All time integration state is now encapsulated in the Integrator class, improving modularity and preparing for future multi-physics enhancements. --- Code/Source/solver/ComMod.h | 9 +-- Code/Source/solver/Integrator.cpp | 43 ++++++------ Code/Source/solver/Integrator.h | 35 +++++++++- Code/Source/solver/Simulation.cpp | 26 +++++++ Code/Source/solver/Simulation.h | 13 ++++ Code/Source/solver/all_fun.cpp | 18 +++-- Code/Source/solver/all_fun.h | 6 +- Code/Source/solver/baf_ini.cpp | 12 ++-- Code/Source/solver/baf_ini.h | 4 +- Code/Source/solver/cep_ion.cpp | 4 +- Code/Source/solver/cep_ion.h | 2 +- Code/Source/solver/eq_assem.cpp | 6 +- Code/Source/solver/eq_assem.h | 2 +- Code/Source/solver/initialize.cpp | 108 +++++++++++++++--------------- Code/Source/solver/initialize.h | 8 ++- Code/Source/solver/main.cpp | 34 +++++----- Code/Source/solver/mesh.cpp | 6 +- Code/Source/solver/mesh.h | 2 +- Code/Source/solver/nn.cpp | 16 +++-- Code/Source/solver/nn.h | 2 +- Code/Source/solver/post.cpp | 11 ++- Code/Source/solver/read_msh.cpp | 40 +++++------ Code/Source/solver/read_msh.h | 8 +-- Code/Source/solver/remesh.cpp | 4 +- Code/Source/solver/ris.cpp | 10 +-- Code/Source/solver/ris.h | 2 +- Code/Source/solver/set_bc.cpp | 44 ++++++------ Code/Source/solver/set_bc.h | 8 +-- Code/Source/solver/uris.cpp | 12 ++-- Code/Source/solver/uris.h | 2 +- 30 files changed, 290 insertions(+), 207 deletions(-) diff --git a/Code/Source/solver/ComMod.h b/Code/Source/solver/ComMod.h index 7fe4eb6b5..873a026d5 100644 --- a/Code/Source/solver/ComMod.h +++ b/Code/Source/solver/ComMod.h @@ -1742,11 +1742,7 @@ class ComMod { /// @brief RIS mapping array, with global (total) enumeration std::vector grisMapList; - /// @brief Old time derivative of variables (acceleration); known result at current time step - Array Ao; - - /// @brief Old integrated variables (displacement) - Array Do; + /// @brief Ao, Do, Yo moved to Integrator class (complete ownership transfer) /// @brief Residual vector Array R; @@ -1757,9 +1753,6 @@ class ComMod { /// @brief Position vector of mesh nodes (in ref config) Array x; - /// @brief Old variables (velocity); known result at current time step - Array Yo; - /// @brief Body force Array Bf; diff --git a/Code/Source/solver/Integrator.cpp b/Code/Source/solver/Integrator.cpp index 2cb3a0d52..372378b0b 100644 --- a/Code/Source/solver/Integrator.cpp +++ b/Code/Source/solver/Integrator.cpp @@ -25,8 +25,8 @@ using namespace consts; //------------------------ // Integrator Constructor //------------------------ -Integrator::Integrator(Simulation* simulation) - : simulation_(simulation), newton_count_(0) +Integrator::Integrator(Simulation* simulation, Array&& Ao, Array&& Do, Array&& Yo) + : simulation_(simulation), newton_count_(0), Ao_(std::move(Ao)), Do_(std::move(Do)), Yo_(std::move(Yo)) { initialize_arrays(); } @@ -56,12 +56,11 @@ void Integrator::initialize_arrays() { res_.resize(nFacesLS); incL_.resize(nFacesLS); - // Initialize An_ = Ao (same as what was done in initialize.cpp:760) - An_ = com_mod.Ao; - // Initialize Dn_ = Do (same as what was done in initialize.cpp:761) - Dn_ = com_mod.Do; - // Initialize Yn_ = Yo (same as what was done in initialize.cpp:760) - Yn_ = com_mod.Yo; + // Ao_, Do_, Yo_ already initialized via move in constructor + // Initialize new variables from old variables + An_ = Ao_; + Dn_ = Do_; + Yn_ = Yo_; } //------------------------ @@ -109,8 +108,8 @@ bool Integrator::step() { #ifdef debug_integrator_step dmsg << "Set coupled BCs " << std::endl; #endif - set_bc::set_bc_cpl(com_mod, cm_mod, Yn); - set_bc::set_bc_dir(com_mod, An, Yn, Dn); + set_bc::set_bc_cpl(com_mod, cm_mod, Yn_, Yo_, Ao_, Do_); + set_bc::set_bc_dir(com_mod, An_, Yn_, Dn_, Yo_, Ao_, Do_); } // Initiator step for Generalized α-Method (quantities at n+am, n+af). @@ -253,7 +252,7 @@ void Integrator::assemble_equations() { auto& cep_mod = simulation_->get_cep_mod(); for (int iM = 0; iM < com_mod.nMsh; iM++) { - eq_assem::global_eq_assem(com_mod, cep_mod, com_mod.msh[iM], Ag_, Yg_, Dg_); + eq_assem::global_eq_assem(com_mod, cep_mod, com_mod.msh[iM], Ag_, Yg_, Dg_, Do_); } // Debug output @@ -396,12 +395,12 @@ void Integrator::predictor() // time derivative of displacement auto& Ad = com_mod.Ad; - auto& Ao = com_mod.Ao; + auto& Ao = Ao_; // Use member variable auto& An = An_; // Use member variable - auto& Yo = com_mod.Yo; - auto& Yn = Yn_; - auto& Do = com_mod.Do; - auto& Dn = Dn_; + auto& Yo = Yo_; // Use member variable + auto& Yn = Yn_; // Use member variable + auto& Do = Do_; // Use member variable + auto& Dn = Dn_; // Use member variable // Prestress initialization if (com_mod.pstEq) { @@ -469,7 +468,7 @@ void Integrator::predictor() // electrophysiology if (eq.phys == Equation_CEP) { - cep_ion::cep_integ(simulation_, iEq, e, Do); + cep_ion::cep_integ(simulation_, iEq, e, Do, Yo_); } // eqn 86 of Bazilevs 2007 @@ -547,12 +546,12 @@ void Integrator::pici(Array& Ag, Array& Yg, Array& Dg) dmsg << "com_mod.pstEq: " << com_mod.pstEq; #endif - const auto& Ao = com_mod.Ao; + const auto& Ao = Ao_; // Use member variable const auto& An = An_; // Use member variable - const auto& Do = com_mod.Do; - const auto& Dn = Dn_; - const auto& Yo = com_mod.Yo; - const auto& Yn = Yn_; + const auto& Do = Do_; // Use member variable + const auto& Dn = Dn_; // Use member variable + const auto& Yo = Yo_; // Use member variable + const auto& Yn = Yn_; // Use member variable for (int i = 0; i < com_mod.nEq; i++) { auto& eq = com_mod.eq[i]; diff --git a/Code/Source/solver/Integrator.h b/Code/Source/solver/Integrator.h index 3a9ef350a..64148ee9c 100644 --- a/Code/Source/solver/Integrator.h +++ b/Code/Source/solver/Integrator.h @@ -27,8 +27,11 @@ class Integrator { * @brief Construct a new Integrator object * * @param simulation Pointer to the Simulation object containing problem data + * @param Ao Old acceleration array (takes ownership via move) + * @param Do Old displacement array (takes ownership via move) + * @param Yo Old velocity array (takes ownership via move) */ - Integrator(Simulation* simulation); + Integrator(Simulation* simulation, Array&& Ao, Array&& Do, Array&& Yo); /** * @brief Destroy the Integrator object @@ -96,6 +99,27 @@ class Integrator { */ Array& get_Yn() { return Yn_; } + /** + * @brief Get reference to Ao (old time derivative of variables at n) + * + * @return Reference to Ao array (acceleration at current time step) + */ + Array& get_Ao() { return Ao_; } + + /** + * @brief Get reference to Do (old integrated variables at n) + * + * @return Reference to Do array (displacement at current time step) + */ + Array& get_Do() { return Do_; } + + /** + * @brief Get reference to Yo (old variables at n) + * + * @return Reference to Yo array (velocity at current time step) + */ + Array& get_Yo() { return Yo_; } + private: /** @brief Pointer to the simulation object */ Simulation* simulation_; @@ -118,6 +142,15 @@ class Integrator { /** @brief New variables at n+1 (velocity at next time step) */ Array Yn_; + /** @brief Old time derivative of variables at n (acceleration at current time step) */ + Array Ao_; + + /** @brief Old integrated variables at n (displacement at current time step) */ + Array Do_; + + /** @brief Old variables at n (velocity at current time step) */ + Array Yo_; + /** @brief Residual vector for face-based quantities */ Vector res_; diff --git a/Code/Source/solver/Simulation.cpp b/Code/Source/solver/Simulation.cpp index 145ae182e..76876cc39 100644 --- a/Code/Source/solver/Simulation.cpp +++ b/Code/Source/solver/Simulation.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: BSD-3-Clause #include "Simulation.h" +#include "Integrator.h" #include "all_fun.h" #include "load_msh.h" @@ -9,6 +10,7 @@ #include "mpi.h" #include +#include Simulation::Simulation() { @@ -88,3 +90,27 @@ void Simulation::set_module_parameters() fTmp = general.simulation_initialization_file_path.value(); roInf = general.spectral_radius_of_infinite_time_step.value(); } + +/// @brief Initialize the Integrator object after simulation setup is complete +/// +/// This should be called at the end of initialize() after Ao, Do, Yo have been +/// fully initialized. The Integrator takes ownership of these arrays. +/// +/// @param Ao Old acceleration array (moved into Integrator) +/// @param Do Old displacement array (moved into Integrator) +/// @param Yo Old velocity array (moved into Integrator) +void Simulation::initialize_integrator(Array&& Ao, Array&& Do, Array&& Yo) +{ + integrator_ = std::make_unique(this, std::move(Ao), std::move(Do), std::move(Yo)); +} + +/// @brief Get reference to the Integrator object +/// +/// @return Reference to the Integrator +Integrator& Simulation::get_integrator() +{ + if (!integrator_) { + throw std::runtime_error("Integrator not initialized. Call initialize_integrator() first."); + } + return *integrator_; +} diff --git a/Code/Source/solver/Simulation.h b/Code/Source/solver/Simulation.h index e0ad1b7b5..741aa3be3 100644 --- a/Code/Source/solver/Simulation.h +++ b/Code/Source/solver/Simulation.h @@ -10,6 +10,10 @@ #include "LinearAlgebra.h" #include +#include + +// Forward declaration +class Integrator; class Simulation { @@ -22,6 +26,11 @@ class Simulation { CepMod& get_cep_mod() { return cep_mod; }; ChnlMod& get_chnl_mod() { return chnl_mod; }; ComMod& get_com_mod() { return com_mod; }; + Integrator& get_integrator(); + + // Initialize the Integrator object after simulation setup is complete + // Takes ownership of Ao, Do, Yo arrays via move semantics + void initialize_integrator(Array&& Ao, Array&& Do, Array&& Yo); // Read a solver paramerer input XML file. void read_parameters(const std::string& fileName); @@ -61,6 +70,10 @@ class Simulation { std::string history_file_name; LinearAlgebra* linear_algebra = nullptr; + + private: + // Time integrator for Newton iteration loop + std::unique_ptr integrator_; }; #endif diff --git a/Code/Source/solver/all_fun.cpp b/Code/Source/solver/all_fun.cpp index 6d205544a..db5c00771 100644 --- a/Code/Source/solver/all_fun.cpp +++ b/Code/Source/solver/all_fun.cpp @@ -276,7 +276,7 @@ global(const ComMod& com_mod, const CmMod& cm_mod, const mshType& lM, const Arra /// @param s an array containing a scalar value for each node in the mesh /// Replicates 'FUNCTION vIntegM(dId, s, l, u, pFlag)' defined in ALLFUN.f. // -double integ(const ComMod& com_mod, const CmMod& cm_mod, int iM, const Array& s) +double integ(const ComMod& com_mod, const CmMod& cm_mod, int iM, const Array& s, const Array* Do) { using namespace consts; @@ -367,8 +367,11 @@ double integ(const ComMod& com_mod, const CmMod& cm_mod, int iM, const Array& s, int l, int u, bool pFlag) +double integ(const ComMod& com_mod, const CmMod& cm_mod, int dId, const Array& s, int l, int u, bool pFlag, const Array* Do) { using namespace consts; @@ -556,8 +559,11 @@ double integ(const ComMod& com_mod, const CmMod& cm_mod, int dId, const Array global(const ComMod& com_mod, const CmMod& cm_mod, const mshType& lM, const Array& U); - double integ(const ComMod& com_mod, const CmMod& cm_mod, int iM, const Array& s); + double integ(const ComMod& com_mod, const CmMod& cm_mod, int iM, const Array& s, const Array* Do=nullptr); - double integ(const ComMod& com_mod, const CmMod& cm_mod, int dId, const Array& s, int l, int u, - bool pFlag=false); + double integ(const ComMod& com_mod, const CmMod& cm_mod, int dId, const Array& s, int l, int u, + bool pFlag=false, const Array* Do=nullptr); double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, const Vector& s, bool pFlag=false, consts::MechanicalConfigurationType cfg=consts::MechanicalConfigurationType::reference); diff --git a/Code/Source/solver/baf_ini.cpp b/Code/Source/solver/baf_ini.cpp index c411545a3..b00b809bd 100644 --- a/Code/Source/solver/baf_ini.cpp +++ b/Code/Source/solver/baf_ini.cpp @@ -39,7 +39,7 @@ namespace baf_ini_ns { /// /// Replicates 'SUBROUTINE BAFINI()' defined in BAFINIT.f // -void baf_ini(Simulation* simulation) +void baf_ini(Simulation* simulation, Array& Do, Array& Yo) { using namespace consts; using namespace fsi_linear_solver; @@ -67,7 +67,7 @@ void baf_ini(Simulation* simulation) continue; } auto& face = msh.fa[iFa]; - face_ini(simulation, msh, face); + face_ini(simulation, msh, face, Do); } if (msh.lShl) { shl_ini(com_mod, cm_mod, com_mod.msh[iM]); @@ -133,7 +133,7 @@ void baf_ini(Simulation* simulation) } if (!com_mod.stFileFlag) { - set_bc::rcr_init(com_mod, cm_mod); + set_bc::rcr_init(com_mod, cm_mod, Yo); } if (com_mod.cplBC.useGenBC) { @@ -145,7 +145,7 @@ void baf_ini(Simulation* simulation) } if (com_mod.cplBC.schm != CplBCType::cplBC_E) { - set_bc::calc_der_cpl_bc(com_mod, cm_mod, com_mod.Yo); + set_bc::calc_der_cpl_bc(com_mod, cm_mod, Yo, Yo); } } @@ -413,7 +413,7 @@ void bc_ini(const ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, faceType& l // face_ini //---------- // -void face_ini(Simulation* simulation, mshType& lM, faceType& lFa) +void face_ini(Simulation* simulation, mshType& lM, faceType& lFa, Array& Do) { using namespace consts; auto& com_mod = simulation->com_mod; @@ -549,7 +549,7 @@ void face_ini(Simulation* simulation, mshType& lM, faceType& lFa) if (com_mod.mvMsh) { for (int i = 0; i < nsd; i++) { - xl(i,a) = xl(i,a) + com_mod.Do(i+nsd+1,Ac); + xl(i,a) = xl(i,a) + Do(i+nsd+1,Ac); } } } diff --git a/Code/Source/solver/baf_ini.h b/Code/Source/solver/baf_ini.h index 5197934e6..cf7f41635 100644 --- a/Code/Source/solver/baf_ini.h +++ b/Code/Source/solver/baf_ini.h @@ -9,11 +9,11 @@ namespace baf_ini_ns { -void baf_ini(Simulation* simulation); +void baf_ini(Simulation* simulation, Array& Do, Array& Yo); void bc_ini(const ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, faceType& lFa); -void face_ini(Simulation* simulation, mshType& lm, faceType& la); +void face_ini(Simulation* simulation, mshType& lm, faceType& la, Array& Do); void fsi_ls_ini(ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, const faceType& lFa, int& lsPtr); diff --git a/Code/Source/solver/cep_ion.cpp b/Code/Source/solver/cep_ion.cpp index 2f805e66a..24ac944f6 100644 --- a/Code/Source/solver/cep_ion.cpp +++ b/Code/Source/solver/cep_ion.cpp @@ -141,7 +141,7 @@ void cep_init_l(CepMod& cep_mod, cepModelType& cep, int nX, int nG, Vector& Dg) +void cep_integ(Simulation* simulation, const int iEq, const int iDof, const Array& Dg, Array& Yo) { static bool IPASS = true; @@ -164,7 +164,7 @@ void cep_integ(Simulation* simulation, const int iEq, const int iDof, const Arra auto& cem = cep_mod.cem; auto& eq = com_mod.eq[iEq]; - auto& Yo = com_mod.Yo; + // Yo is now passed as parameter auto& Xion = cep_mod.Xion; int nXion = cep_mod.nXion; diff --git a/Code/Source/solver/cep_ion.h b/Code/Source/solver/cep_ion.h index d5831da89..01227020c 100644 --- a/Code/Source/solver/cep_ion.h +++ b/Code/Source/solver/cep_ion.h @@ -19,7 +19,7 @@ void cep_init(Simulation* simulation); void cep_init_l(CepMod& cep_mod, cepModelType& cep, int nX, int nG, Vector& X, Vector& Xg); -void cep_integ(Simulation* simulation, const int iEq, const int iDof, const Array& Dg); +void cep_integ(Simulation* simulation, const int iEq, const int iDof, const Array& Dg, Array& Yo); void cep_integ_l(CepMod& cep_mod, cepModelType& cep, int nX, int nG, Vector& X, Vector& Xg, const double t1, double& yl, const double I4f, const double dt); diff --git a/Code/Source/solver/eq_assem.cpp b/Code/Source/solver/eq_assem.cpp index 588737e03..dcea0cdbd 100644 --- a/Code/Source/solver/eq_assem.cpp +++ b/Code/Source/solver/eq_assem.cpp @@ -347,8 +347,8 @@ void fsi_ls_upd(ComMod& com_mod, const bcType& lBc, const faceType& lFa) /// /// Ag(tDof,tnNo), Yg(tDof,tnNo), Dg(tDof,tnNo) // -void global_eq_assem(ComMod& com_mod, CepMod& cep_mod, const mshType& lM, const Array& Ag, - const Array& Yg, const Array& Dg) +void global_eq_assem(ComMod& com_mod, CepMod& cep_mod, const mshType& lM, const Array& Ag, + const Array& Yg, const Array& Dg, const Array& Do) { #define n_debug_global_eq_assem #ifdef debug_global_eq_assem @@ -407,7 +407,7 @@ void global_eq_assem(ComMod& com_mod, CepMod& cep_mod, const mshType& lM, const break; case EquationType::phys_mesh: - mesh::construct_mesh(com_mod, cep_mod, lM, Ag, Dg); + mesh::construct_mesh(com_mod, cep_mod, lM, Ag, Dg, Do); break; case EquationType::phys_CEP: diff --git a/Code/Source/solver/eq_assem.h b/Code/Source/solver/eq_assem.h index 653daa097..7d60ee3b4 100644 --- a/Code/Source/solver/eq_assem.h +++ b/Code/Source/solver/eq_assem.h @@ -15,7 +15,7 @@ void b_neu_folw_p(ComMod& com_mod, const bcType& lBc, const faceType& lFa, const void fsi_ls_upd(ComMod& com_mod, const bcType& lBc, const faceType& lFa); -void global_eq_assem(ComMod& com_mod, CepMod& cep_mod, const mshType& lM, const Array& Ag, const Array& Yg, const Array& Dg); +void global_eq_assem(ComMod& com_mod, CepMod& cep_mod, const mshType& lM, const Array& Ag, const Array& Yg, const Array& Dg, const Array& Do); }; diff --git a/Code/Source/solver/initialize.cpp b/Code/Source/solver/initialize.cpp index 50142276d..2d7c2dbe5 100644 --- a/Code/Source/solver/initialize.cpp +++ b/Code/Source/solver/initialize.cpp @@ -48,12 +48,13 @@ void finalize(Simulation* simulation) /// /// Reprodices 'SUBROUTINE INITFROMBIN(fName, timeP)' defined in INITIALIZE.f. // -void init_from_bin(Simulation* simulation, const std::string& fName, std::array& timeP) +void init_from_bin(Simulation* simulation, const std::string& fName, std::array& timeP, + Array& Ao, Array& Do, Array& Yo) { auto& com_mod = simulation->com_mod; auto& cm = com_mod.cm; int task_id = cm.idcm(); - #ifdef debug_init_from_bin + #ifdef debug_init_from_bin DebugMsg dmsg(__func__, com_mod.cm.idcm()); dmsg.banner(); #endif @@ -75,12 +76,12 @@ void init_from_bin(Simulation* simulation, const std::string& fName, std::array< com_mod.timeP[1] = timeP[1]; com_mod.timeP[2] = timeP[2]; - #ifdef debug_init_from_bin + #ifdef debug_init_from_bin dmsg << "dFlag: " << dFlag; dmsg << "sstEq: " << sstEq; dmsg << "pstEq: " << pstEq; dmsg << "cepEq: " << cepEq; - dmsg << "cm.tF(): " << cm.tF(cm_mod); + dmsg << "cm.tF(): " << cm.tF(cm_mod); #endif // Open file and position at the location in the file @@ -95,11 +96,9 @@ void init_from_bin(Simulation* simulation, const std::string& fName, std::array< std::array tStamp; auto& cplBC = com_mod.cplBC; auto& Ad = com_mod.Ad; - auto& Ao = com_mod.Ao; - auto& Do = com_mod.Do; + // Ao, Do, Yo now passed as parameters auto& pS0 = com_mod.pS0; auto& Xion = cep_mod.Xion; - auto& Yo = com_mod.Yo; output::read_restart_header(com_mod, tStamp, timeP[0], bin_file); bin_file.read((char*)cplBC.xo.data(), cplBC.xo.msize()); @@ -260,7 +259,8 @@ void init_from_bin(Simulation* simulation, const std::string& fName, std::array< /// /// Reproduces the Fortran 'INITFROMVTU' subroutine. // -void init_from_vtu(Simulation* simulation, const std::string& fName, std::array& timeP) +void init_from_vtu(Simulation* simulation, const std::string& fName, std::array& timeP, + Array& Ao, Array& Do, Array& Yo) { auto& com_mod = simulation->com_mod; auto& cm_mod = simulation->cm_mod; @@ -285,17 +285,17 @@ void init_from_vtu(Simulation* simulation, const std::string& fName, std::array< Array tmpA, tmpY, tmpD; if (cm.mas(cm_mod)) { - tmpA.resize(tDof,gtnNo); - tmpY.resize(tDof,gtnNo); + tmpA.resize(tDof,gtnNo); + tmpY.resize(tDof,gtnNo); tmpD.resize(tDof,gtnNo); vtk_xml::read_vtus(simulation, tmpA, tmpY, tmpD, fName); - } else { + } else { //ALLOCATE(tmpA(0,0), tmpY(0,0), tmpD(0,0)) - } + } - com_mod.Ao = all_fun::local(com_mod, cm_mod, cm, tmpA); - com_mod.Yo = all_fun::local(com_mod, cm_mod, cm, tmpY); - com_mod.Do = all_fun::local(com_mod, cm_mod, cm, tmpD); + Ao = all_fun::local(com_mod, cm_mod, cm, tmpA); + Yo = all_fun::local(com_mod, cm_mod, cm, tmpY); + Do = all_fun::local(com_mod, cm_mod, cm, tmpD); } /// @brief Initialize or finalize svFSI variables/structures. @@ -622,12 +622,13 @@ void initialize(Simulation* simulation, Vector& timeP) // Variable allocation and initialization int tnNo = com_mod.tnNo; - com_mod.Ao.resize(tDof,tnNo); - // An moved to Integrator class - com_mod.Yo.resize(tDof,tnNo); - // Yn moved to Integrator class - com_mod.Do.resize(tDof,tnNo); - // Dn moved to Integrator class + + // Ao, Do, Yo are local variables that will be moved to Integrator at end + Array Ao(tDof, tnNo); + Array Yo(tDof, tnNo); + Array Do(tDof, tnNo); + // An, Yn, Dn moved to Integrator class + com_mod.Bf.resize(nsd,tnNo); // [TODO] DaveP not implemented? @@ -688,14 +689,14 @@ void initialize(Simulation* simulation, Vector& timeP) flag = false; } - if (flag) { + if (flag) { auto& iniFilePath = com_mod.iniFilePath; auto& timeP = com_mod.timeP; - if (iniFilePath.find(".bin") != std::string::npos) { - init_from_bin(simulation, iniFilePath, timeP); + if (iniFilePath.find(".bin") != std::string::npos) { + init_from_bin(simulation, iniFilePath, timeP, Ao, Do, Yo); } else { - init_from_vtu(simulation, iniFilePath, timeP); + init_from_vtu(simulation, iniFilePath, timeP, Ao, Do, Yo); } } else { @@ -705,13 +706,13 @@ void initialize(Simulation* simulation, Vector& timeP) if (FILE *file = fopen(fTmp.c_str(), "r")) { fclose(file); auto& timeP = com_mod.timeP; - init_from_bin(simulation, fTmp, timeP); + init_from_bin(simulation, fTmp, timeP, Ao, Do, Yo); } else { if (cm.mas(cm_mod)) { std::cout << "WARNING: No '" + fTmp + "' file to restart simulation from; Resetting restart flag to false"; } com_mod.stFileFlag = false; - zero_init(simulation); + zero_init(simulation, Ao, Do, Yo); } if (rmsh.isReqd) { @@ -722,13 +723,13 @@ void initialize(Simulation* simulation, Vector& timeP) for (int i = 0; i < rmsh.iNorm.size(); i++) { rmsh.iNorm(i) = com_mod.eq[i].iNorm; } - rmsh.A0 = com_mod.Ao; - rmsh.Y0 = com_mod.Yo; - rmsh.D0 = com_mod.Do; + rmsh.A0 = Ao; + rmsh.Y0 = Yo; + rmsh.D0 = Do; } } else { - zero_init(simulation); + zero_init(simulation, Ao, Do, Yo); } } @@ -741,18 +742,18 @@ void initialize(Simulation* simulation, Vector& timeP) com_mod.eq[i].iNorm = rmsh.iNorm[i]; } - com_mod.Ao = all_fun::local(com_mod, cm_mod, cm, rmsh.A0); - com_mod.Yo = all_fun::local(com_mod, cm_mod, cm, rmsh.Y0); - com_mod.Do = all_fun::local(com_mod, cm_mod, cm, rmsh.D0); + Ao = all_fun::local(com_mod, cm_mod, cm, rmsh.A0); + Yo = all_fun::local(com_mod, cm_mod, cm, rmsh.Y0); + Do = all_fun::local(com_mod, cm_mod, cm, rmsh.D0); - rmsh.A0.resize(tDof,tnNo); - rmsh.A0 = com_mod.Ao; + rmsh.A0.resize(tDof,tnNo); + rmsh.A0 = Ao; - rmsh.Y0.resize(tDof,tnNo); - rmsh.Y0 = com_mod.Yo; + rmsh.Y0.resize(tDof,tnNo); + rmsh.Y0 = Yo; - rmsh.D0.resize(tDof,tnNo); - rmsh.D0 = com_mod.Do; + rmsh.D0.resize(tDof,tnNo); + rmsh.D0 = Do; } // resetSim // Initialize new variables @@ -815,7 +816,7 @@ void initialize(Simulation* simulation, Vector& timeP) // Preparing faces and BCs // - baf_ini_ns::baf_ini(simulation); + baf_ini_ns::baf_ini(simulation, Do, Yo); // As all the arrays are allocated, call BIN to VTK for conversion // @@ -827,15 +828,12 @@ void initialize(Simulation* simulation, Vector& timeP) // Making sure the old solution satisfies BCs // - // Modifes - // com_mod.Ao - Old time derivative of variables (acceleration) - // com_mod.Yo - Old variables (velocity) - // com_mod.Do - Old integrated variables (dissplacement) + // Modifies Ao, Yo, Do (local variables) // - set_bc::set_bc_dir(com_mod, com_mod.Ao, com_mod.Yo, com_mod.Do); + set_bc::set_bc_dir(com_mod, Ao, Yo, Do, Yo, Ao, Do); - // Preparing TXT files (pass Ao, Do, and Yo since An, Dn, and Yn haven't been created in Integrator yet) - txt_ns::txt(simulation, true, com_mod.Ao, com_mod.Do, com_mod.Yo); + // Preparing TXT files (pass local Ao, Do, and Yo since An, Dn, and Yn haven't been created in Integrator yet) + txt_ns::txt(simulation, true, Ao, Do, Yo); // Printing the first line and initializing timeP int co = 1; @@ -844,6 +842,10 @@ void initialize(Simulation* simulation, Vector& timeP) std::fill(com_mod.rmsh.flag.begin(), com_mod.rmsh.flag.end(), false); com_mod.resetSim = false; + + // Create Integrator now that Ao, Do, Yo are fully initialized + // The Integrator takes ownership of Ao, Do, Yo via move semantics + simulation->initialize_integrator(std::move(Ao), std::move(Do), std::move(Yo)); } //----------- @@ -851,7 +853,7 @@ void initialize(Simulation* simulation, Vector& timeP) //----------- // Initialize state variables Yo, Ao and Do. // -void zero_init(Simulation* simulation) +void zero_init(Simulation* simulation, Array& Ao, Array& Do, Array& Yo) { auto& com_mod = simulation->com_mod; auto& cm = com_mod.cm; @@ -872,7 +874,7 @@ void zero_init(Simulation* simulation) for (int a = 0; a < com_mod.tnNo; a++) { // In the future this should depend on the equation type. for (int i = 0; i < nsd; i++) { - com_mod.Yo(i,a) = msh.Ys(i,a,0); + Yo(i,a) = msh.Ys(i,a,0); } } } @@ -886,7 +888,7 @@ void zero_init(Simulation* simulation) #endif for (int a = 0; a < com_mod.tnNo; a++) { for (int i = 0; i < nsd; i++) { - com_mod.Yo(i,a) = com_mod.Vinit(i,a); + Yo(i,a) = com_mod.Vinit(i,a); } } } @@ -897,7 +899,7 @@ void zero_init(Simulation* simulation) #endif for (int a = 0; a < com_mod.tnNo; a++) { for (int i = 0; i < nsd; i++) { - com_mod.Yo(nsd,a) = com_mod.Pinit(a); + Yo(nsd,a) = com_mod.Pinit(a); } } } @@ -908,7 +910,7 @@ void zero_init(Simulation* simulation) #endif for (int a = 0; a < com_mod.tnNo; a++) { for (int i = 0; i < nsd; i++) { - com_mod.Do(i,a) = com_mod.Dinit(i,a); + Do(i,a) = com_mod.Dinit(i,a); } } } diff --git a/Code/Source/solver/initialize.h b/Code/Source/solver/initialize.h index ae3fe309a..cc858e0c4 100644 --- a/Code/Source/solver/initialize.h +++ b/Code/Source/solver/initialize.h @@ -8,13 +8,15 @@ void finalize(Simulation* simulation); -void init_from_bin(Simulation* simulation, const std::string& fName, std::array& timeP); +void init_from_bin(Simulation* simulation, const std::string& fName, std::array& timeP, + Array& Ao, Array& Do, Array& Yo); -void init_from_vtu(Simulation* simulation, const std::string& fName, std::array& timeP); +void init_from_vtu(Simulation* simulation, const std::string& fName, std::array& timeP, + Array& Ao, Array& Do, Array& Yo); void initialize(Simulation* simulation, Vector& timeP); -void zero_init(Simulation* simulation); +void zero_init(Simulation* simulation, Array& Ao, Array& Do, Array& Yo); #endif diff --git a/Code/Source/solver/main.cpp b/Code/Source/solver/main.cpp index 78fe7703d..c830bcc0d 100644 --- a/Code/Source/solver/main.cpp +++ b/Code/Source/solver/main.cpp @@ -80,7 +80,7 @@ void read_files(Simulation* simulation, const std::string& file_name) /// @brief Iterate the precomputed state-variables in time using linear interpolation to the current time step size // -void iterate_precomputed_time(Simulation* simulation, Array& An, Array& Yn) { +void iterate_precomputed_time(Simulation* simulation, Array& An, Array& Yn, Array& Ao, Array& Yo, Array& Do) { using namespace consts; auto& com_mod = simulation->com_mod; @@ -99,11 +99,7 @@ void iterate_precomputed_time(Simulation* simulation, Array& An, Arrayget_integrator(); // current time step int& cTS = com_mod.cTS; @@ -233,9 +229,9 @@ void iterate_solution(Simulation* simulation) 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 (displacement) + auto& Ao = integrator.get_Ao(); // Old time derivative of variables (acceleration) + auto& Yo = integrator.get_Yo(); // Old variables (velocity) + auto& Do = integrator.get_Do(); // Old integrated variables (displacement) auto& An = integrator.get_An(); // New time derivative of variables (acceleration) auto& Yn = integrator.get_Yn(); // New variables (velocity) @@ -299,7 +295,7 @@ void iterate_solution(Simulation* simulation) // Compute mesh properties to check if remeshing is required // if (com_mod.mvMsh && com_mod.rmsh.isReqd) { - read_msh_ns::calc_mesh_props(com_mod, cm_mod, com_mod.nMsh, com_mod.msh); + read_msh_ns::calc_mesh_props(com_mod, cm_mod, com_mod.nMsh, com_mod.msh, integrator.get_Do()); if (com_mod.resetSim) { #ifdef debug_iterate_solution dmsg << "#### resetSim is true " << std::endl; @@ -327,11 +323,11 @@ void iterate_solution(Simulation* simulation) dmsg << "Apply Dirichlet BCs strongly ..." << std::endl; #endif - set_bc::set_bc_dir(com_mod, An, Yn, Dn); + set_bc::set_bc_dir(com_mod, An, Yn, Dn, Yo, Ao, Do); if (com_mod.urisFlag) {uris::uris_calc_sdf(com_mod);} - iterate_precomputed_time(simulation, integrator.get_An(), integrator.get_Yn()); + iterate_precomputed_time(simulation, integrator.get_An(), integrator.get_Yn(), integrator.get_Ao(), integrator.get_Yo(), integrator.get_Do()); // Inner loop for Newton iteration - now encapsulated in Integrator class // @@ -379,7 +375,7 @@ void iterate_solution(Simulation* simulation) std::cout << "Valve status just changed. Do not update" << std::endl; } } else { - ris::ris_updater(com_mod, cm_mod, An, Dn, Yn); + ris::ris_updater(com_mod, cm_mod, An, Dn, Yn, Ao, Do, Yo); } // goto label_11; } @@ -407,9 +403,9 @@ void iterate_solution(Simulation* simulation) com_mod.rmsh.iNorm(i) = com_mod.eq[i].iNorm; } - com_mod.rmsh.A0 = com_mod.Ao; - com_mod.rmsh.Y0 = com_mod.Yo; - com_mod.rmsh.D0 = com_mod.Do; + com_mod.rmsh.A0 = Ao; + com_mod.rmsh.Y0 = Yo; + com_mod.rmsh.D0 = Do; } } @@ -519,7 +515,7 @@ void iterate_solution(Simulation* simulation) } if (com_mod.mvMsh) { - uris::uris_update_disp(com_mod, cm_mod); + uris::uris_update_disp(com_mod, cm_mod, Do); } if (cm.mas(cm_mod)) { diff --git a/Code/Source/solver/mesh.cpp b/Code/Source/solver/mesh.cpp index 6a4ac44b3..2963516c0 100644 --- a/Code/Source/solver/mesh.cpp +++ b/Code/Source/solver/mesh.cpp @@ -19,9 +19,9 @@ namespace mesh { -void construct_mesh(ComMod& com_mod, CepMod& cep_mod, const mshType& lM, const Array& Ag, const Array& Dg) +void construct_mesh(ComMod& com_mod, CepMod& cep_mod, const mshType& lM, const Array& Ag, const Array& Dg, const Array& Do) { - #define n_debug_construct_mesh + #define n_debug_construct_mesh #ifdef debug_construct_mesh DebugMsg dmsg(__func__, com_mod.cm.idcm()); dmsg.banner(); @@ -37,7 +37,7 @@ void construct_mesh(ComMod& com_mod, CepMod& cep_mod, const mshType& lM, const A const auto& eq = com_mod.eq[cEq]; auto& cDmn = com_mod.cDmn; const int nsymd = com_mod.nsymd; - auto& Do = com_mod.Do; + // Do now passed as parameter auto& pS0 = com_mod.pS0; auto& pSn = com_mod.pSn; auto& pSa = com_mod.pSa; diff --git a/Code/Source/solver/mesh.h b/Code/Source/solver/mesh.h index f6bae13f3..7df11f0be 100644 --- a/Code/Source/solver/mesh.h +++ b/Code/Source/solver/mesh.h @@ -10,7 +10,7 @@ namespace mesh { -void construct_mesh(ComMod& com_mod, CepMod& cep_mod, const mshType& lM, const Array& Ag, const Array& Dg); +void construct_mesh(ComMod& com_mod, CepMod& cep_mod, const mshType& lM, const Array& Ag, const Array& Dg, const Array& Do); }; diff --git a/Code/Source/solver/nn.cpp b/Code/Source/solver/nn.cpp index 757c6846e..4c1e2f3d6 100644 --- a/Code/Source/solver/nn.cpp +++ b/Code/Source/solver/nn.cpp @@ -523,7 +523,7 @@ void gnn(const int eNoN, const int nsd, const int insd, Array& Nxi, Arra /// Reproduce Fortran 'GNNB'. // void gnnb(const ComMod& com_mod, const faceType& lFa, const int e, const int g, const int nsd, const int insd, - const int eNoNb, const Array& Nx, Vector& n, MechanicalConfigurationType cfg, const Array* Dn) + const int eNoNb, const Array& Nx, Vector& n, MechanicalConfigurationType cfg, const Array* Dn, const Array* Do) { auto& cm = com_mod.cm; @@ -606,9 +606,12 @@ void gnnb(const ComMod& com_mod, const faceType& lFa, const int e, const int g, lX(i,a) = com_mod.x(i,Ac); } if (com_mod.mvMsh) { + if (!Do) { + throw std::runtime_error("gnnb: Do parameter required for moving mesh but not provided"); + } for (int i = 0; i < lX.nrows(); i++) { // Add mesh displacement - lX(i,a) = lX(i,a) + com_mod.Do(i+nsd+1,Ac); + lX(i,a) = lX(i,a) + (*Do)(i+nsd+1,Ac); } } else { @@ -617,9 +620,12 @@ void gnnb(const ComMod& com_mod, const faceType& lFa, const int e, const int g, // Do nothing break; case MechanicalConfigurationType::old_timestep: + if (!Do) { + throw std::runtime_error("gnnb: Do parameter required for old_timestep configuration but not provided"); + } for (int i = 0; i < lX.nrows(); i++) { // Add displacement at timestep n - lX(i,a) = lX(i,a) + com_mod.Do(i,Ac); + lX(i,a) = lX(i,a) + (*Do)(i,Ac); } break; case MechanicalConfigurationType::new_timestep: @@ -627,8 +633,10 @@ void gnnb(const ComMod& com_mod, const faceType& lFa, const int e, const int g, // Add displacement at timestep n+1 if (Dn != nullptr) { lX(i,a) = lX(i,a) + (*Dn)(i,Ac); + } else if (Do != nullptr) { + lX(i,a) = lX(i,a) + (*Do)(i,Ac); // Fallback to Do if Dn not provided } else { - lX(i,a) = lX(i,a) + com_mod.Do(i,Ac); // Fallback to Do if Dn not provided + throw std::runtime_error("gnnb: Either Dn or Do parameter required for new_timestep configuration but neither provided"); } } break; diff --git a/Code/Source/solver/nn.h b/Code/Source/solver/nn.h index b6e9344a6..52d7c8843 100644 --- a/Code/Source/solver/nn.h +++ b/Code/Source/solver/nn.h @@ -38,7 +38,7 @@ namespace nn { double& Jac, Array& ks); void gnnb(const ComMod& com_mod, const faceType& lFa, const int e, const int g, const int nsd, const int insd, - const int eNoNb, const Array& Nx, Vector& n, consts::MechanicalConfigurationType cfg=consts::MechanicalConfigurationType::reference, const Array* Dn=nullptr); + const int eNoNb, const Array& Nx, Vector& n, consts::MechanicalConfigurationType cfg=consts::MechanicalConfigurationType::reference, const Array* Dn=nullptr, const Array* Do=nullptr); void gnns(const int nsd, const int eNoN, const Array& Nxi, Array& xl, Vector& nV, Array& gCov, Array& gCnv); diff --git a/Code/Source/solver/post.cpp b/Code/Source/solver/post.cpp index 7aefe7486..4e2cc7707 100644 --- a/Code/Source/solver/post.cpp +++ b/Code/Source/solver/post.cpp @@ -1164,12 +1164,19 @@ void ppbin2vtk(Simulation* simulation) continue; } + // Create local arrays for Ao, Do, Yo + const int tDof = com_mod.tDof; + const int tnNo = com_mod.tnNo; + Array Ao(tDof, tnNo); + Array Yo(tDof, tnNo); + Array Do(tDof, tnNo); + std::array rtmp; - init_from_bin(simulation, fName, rtmp); + init_from_bin(simulation, fName, rtmp, Ao, Do, Yo); bool lAve = false; - vtk_xml::write_vtus(simulation, com_mod.Ao, com_mod.Yo, com_mod.Do, lAve); + vtk_xml::write_vtus(simulation, Ao, Yo, Do, lAve); } } diff --git a/Code/Source/solver/read_msh.cpp b/Code/Source/solver/read_msh.cpp index 0fdb19000..18d062d85 100644 --- a/Code/Source/solver/read_msh.cpp +++ b/Code/Source/solver/read_msh.cpp @@ -52,9 +52,9 @@ std::map> check_element_conn /// @brief Calculate element Aspect Ratio of a given mesh // -void calc_elem_ar(ComMod& com_mod, const CmMod& cm_mod, mshType& lM, bool& rflag) +void calc_elem_ar(ComMod& com_mod, const CmMod& cm_mod, mshType& lM, bool& rflag, const Array& Do) { - #define n_debug_calc_elem_ar + #define n_debug_calc_elem_ar #ifdef debug_calc_elem_ar DebugMsg dmsg(__func__, com_mod.cm.idcm()); dmsg.banner(); @@ -65,7 +65,7 @@ void calc_elem_ar(ComMod& com_mod, const CmMod& cm_mod, mshType& lM, bool& rflag if (lM.eType != ElementType::TET4 && lM.eType != ElementType::TRI3) { // wrn = "AR is computed for TRI and TET elements only" - return; + return; } const int nsd = com_mod.nsd; @@ -85,7 +85,7 @@ void calc_elem_ar(ComMod& com_mod, const CmMod& cm_mod, mshType& lM, bool& rflag xl.set_col(a, com_mod.x.col(Ac)); if (com_mod.mvMsh) { for (int i = 0; i < nsd; i++) { - dol(i,a) = com_mod.Do(i+nsd+1,Ac); + dol(i,a) = Do(i+nsd+1,Ac); } } } @@ -147,10 +147,10 @@ void calc_elem_ar(ComMod& com_mod, const CmMod& cm_mod, mshType& lM, bool& rflag /// @brief Calculate element Jacobian of a given mesh. // -void calc_elem_jac(ComMod& com_mod, const CmMod& cm_mod, mshType& lM, bool& rflag) +void calc_elem_jac(ComMod& com_mod, const CmMod& cm_mod, mshType& lM, bool& rflag, const Array& Do) { - #define n_debug_calc_elem_jac - #ifdef debug_calc_elem_jac + #define n_debug_calc_elem_jac + #ifdef debug_calc_elem_jac DebugMsg dmsg(__func__, com_mod.cm.idcm()); dmsg.banner(); dmsg << "lM.nEl: " << lM.nEl; @@ -161,7 +161,7 @@ void calc_elem_jac(ComMod& com_mod, const CmMod& cm_mod, mshType& lM, bool& rfla #endif using namespace consts; const int nsd = com_mod.nsd; - rflag = false; + rflag = false; // Careful here, lM.nEl can be 0. // @@ -182,8 +182,8 @@ void calc_elem_jac(ComMod& com_mod, const CmMod& cm_mod, mshType& lM, bool& rfla xl.set_col(a, com_mod.x.col(Ac)); if (com_mod.mvMsh) { for (int i = 0; i < nsd; i++) { - dol(i,a) = com_mod.Do(i+nsd+1,Ac); - //dol(i,a) = com_mod.Do(i+nsd,Ac); + dol(i,a) = Do(i+nsd+1,Ac); + //dol(i,a) = Do(i+nsd,Ac); } } } @@ -267,7 +267,7 @@ void calc_elem_jac(ComMod& com_mod, const CmMod& cm_mod, mshType& lM, bool& rfla /// @brief Calculate element Skewness of a given mesh. // -void calc_elem_skew(ComMod& com_mod, const CmMod& cm_mod, mshType& lM, bool& rflag) +void calc_elem_skew(ComMod& com_mod, const CmMod& cm_mod, mshType& lM, bool& rflag, const Array& Do) { #define n_debug_calc_elem_skew #ifdef debug_calc_elem_skew @@ -299,7 +299,7 @@ void calc_elem_skew(ComMod& com_mod, const CmMod& cm_mod, mshType& lM, bool& rfl xl.set_col(a, com_mod.x.col(Ac)); if (com_mod.mvMsh) { for (int i = 0; i < nsd; i++) { - dol(i,a) = com_mod.Do(i+nsd+1,Ac); + dol(i,a) = Do(i+nsd+1,Ac); } } } @@ -355,7 +355,7 @@ void calc_elem_skew(ComMod& com_mod, const CmMod& cm_mod, mshType& lM, bool& rfl #endif } -void calc_mesh_props(ComMod& com_mod, const CmMod& cm_mod, const int nMesh, std::vector& mesh) +void calc_mesh_props(ComMod& com_mod, const CmMod& cm_mod, const int nMesh, std::vector& mesh, const Array& Do) { #define n_debug_calc_mesh_props #ifdef debug_calc_mesh_props @@ -366,11 +366,11 @@ void calc_mesh_props(ComMod& com_mod, const CmMod& cm_mod, const int nMesh, std: using namespace consts; auto& rmsh = com_mod.rmsh; #ifdef debug_calc_mesh_props - dmsg << "nMesh: " << nMesh; - dmsg << "resetSim: " << com_mod.resetSim; + dmsg << "nMesh: " << nMesh; + dmsg << "resetSim: " << com_mod.resetSim; dmsg << "com_mod.cTS: " << com_mod.cTS; - dmsg << "rmsh.fTS: " << rmsh.fTS; - dmsg << "rmsh.freq: " << rmsh.freq; + dmsg << "rmsh.fTS: " << rmsh.fTS; + dmsg << "rmsh.freq: " << rmsh.freq; #endif for (int iM = 0; iM < nMesh; iM++) { @@ -378,9 +378,9 @@ void calc_mesh_props(ComMod& com_mod, const CmMod& cm_mod, const int nMesh, std: dmsg << "----- mesh " + mesh[iM].name << " -----"; #endif bool flag = false; - calc_elem_jac(com_mod, cm_mod, mesh[iM], flag); - calc_elem_skew(com_mod, cm_mod, mesh[iM], flag); - calc_elem_ar(com_mod, cm_mod, mesh[iM], flag); + calc_elem_jac(com_mod, cm_mod, mesh[iM], flag, Do); + calc_elem_skew(com_mod, cm_mod, mesh[iM], flag, Do); + calc_elem_ar(com_mod, cm_mod, mesh[iM], flag, Do); rmsh.flag[iM] = flag; #ifdef debug_calc_mesh_props dmsg << "mesh[iM].flag: " << rmsh.flag[iM]; diff --git a/Code/Source/solver/read_msh.h b/Code/Source/solver/read_msh.h index 600f174fd..bff955768 100644 --- a/Code/Source/solver/read_msh.h +++ b/Code/Source/solver/read_msh.h @@ -21,11 +21,11 @@ namespace read_msh_ns { Vector gN; }; - void calc_elem_ar(ComMod& com_mod, const CmMod& cm_mod, mshType& lM, bool& rflag); - void calc_elem_jac(ComMod& com_mod, const CmMod& cm_mod, mshType& lM, bool& rflag); - void calc_elem_skew(ComMod& com_mod, const CmMod& cm_mod, mshType& lM, bool& rflag); + void calc_elem_ar(ComMod& com_mod, const CmMod& cm_mod, mshType& lM, bool& rflag, const Array& Do); + void calc_elem_jac(ComMod& com_mod, const CmMod& cm_mod, mshType& lM, bool& rflag, const Array& Do); + void calc_elem_skew(ComMod& com_mod, const CmMod& cm_mod, mshType& lM, bool& rflag, const Array& Do); - void calc_mesh_props(ComMod& com_mod, const CmMod& cm_mod, const int nMesh, std::vector& mesh); + void calc_mesh_props(ComMod& com_mod, const CmMod& cm_mod, const int nMesh, std::vector& mesh, const Array& Do); void calc_nbc(mshType& mesh, faceType& face); diff --git a/Code/Source/solver/remesh.cpp b/Code/Source/solver/remesh.cpp index 10eef533e..290c4bc68 100644 --- a/Code/Source/solver/remesh.cpp +++ b/Code/Source/solver/remesh.cpp @@ -1888,12 +1888,10 @@ void remesh_restart(Simulation* simulation) com_mod.idMap.clear(); com_mod.cmmBdry.clear(); com_mod.iblank.clear(); - com_mod.Ao.clear(); + // Ao, Do, Yo moved to Integrator class (no longer in ComMod) // An, Dn, and Yn moved to Integrator class - com_mod.Do.clear(); com_mod.R.clear(); com_mod.Val.clear(); - com_mod.Yo.clear(); com_mod.Bf.clear(); cplBC.nFa = 0; diff --git a/Code/Source/solver/ris.cpp b/Code/Source/solver/ris.cpp index 79b5022ef..db3d9b6a8 100644 --- a/Code/Source/solver/ris.cpp +++ b/Code/Source/solver/ris.cpp @@ -152,7 +152,7 @@ void setbc_ris(ComMod& com_mod, const bcType& lBc, const mshType& lM, const face /// @brief This subroutine updates the resistance and activation flag for the /// closed and open configurations of the RIS surfaces -void ris_updater(ComMod& com_mod, CmMod& cm_mod, Array& An, Array& Dn, Array& Yn) +void ris_updater(ComMod& com_mod, CmMod& cm_mod, Array& An, Array& Dn, Array& Yn, Array& Ao, Array& Do, Array& Yo) { #define n_debug_ris_updater #ifdef debug_ris_updater @@ -178,13 +178,13 @@ void ris_updater(ComMod& com_mod, CmMod& cm_mod, Array& An, Array& Yg, const Array& Dg void setbc_ris(ComMod& com_mod, const bcType& lBc, const mshType& lM, const faceType& lFa, const Array& Yg, const Array& Dg); -void ris_updater(ComMod& com_mod, CmMod& cm_mod, Array& An, Array& Dn, Array& Yn); +void ris_updater(ComMod& com_mod, CmMod& cm_mod, Array& An, Array& Dn, Array& Yn, Array& Ao, Array& Do, Array& Yo); void ris_status(ComMod& com_mod, CmMod& cm_mod); void doassem_ris(ComMod& com_mod, const int d, const Vector& eqN, diff --git a/Code/Source/solver/set_bc.cpp b/Code/Source/solver/set_bc.cpp index b428f9b0f..3208af55c 100644 --- a/Code/Source/solver/set_bc.cpp +++ b/Code/Source/solver/set_bc.cpp @@ -25,9 +25,9 @@ namespace set_bc { /// as well as the resistance matrix M ~ dP/dQ from 0D using finite difference. /// Updates the pressure or flowrates stored in cplBC.fa[i].y and the resistance /// matrix M ~ dP/dQ stored in eq.bc[iBc].r. -/// @param com_mod -/// @param cm_mod -void calc_der_cpl_bc(ComMod& com_mod, const CmMod& cm_mod, Array& Yn) +/// @param com_mod +/// @param cm_mod +void calc_der_cpl_bc(ComMod& com_mod, const CmMod& cm_mod, Array& Yn, const Array& Yo) { using namespace consts; @@ -110,21 +110,21 @@ void calc_der_cpl_bc(ComMod& com_mod, const CmMod& cm_mod, Array& Yn) else { throw std::runtime_error("[calc_der_cpl_bc] Invalid physics type for 0D coupling"); } - cplBC.fa[ptr].Qo = all_fun::integ(com_mod, cm_mod, fa, com_mod.Yo, 0, nsd-1, false, cfg_o); + cplBC.fa[ptr].Qo = all_fun::integ(com_mod, cm_mod, fa, Yo, 0, nsd-1, false, cfg_o); cplBC.fa[ptr].Qn = all_fun::integ(com_mod, cm_mod, fa, Yn, 0, nsd-1, false, cfg_n); cplBC.fa[ptr].Po = 0.0; cplBC.fa[ptr].Pn = 0.0; - #ifdef debug_calc_der_cpl_bc + #ifdef debug_calc_der_cpl_bc dmsg << "iBC_Neu "; dmsg << "cplBC.fa[ptr].Qo: " << cplBC.fa[ptr].Qo; dmsg << "cplBC.fa[ptr].Qn: " << cplBC.fa[ptr].Qn; #endif } - // Compute avg pressures at 3D Dirichlet boundaries at timesteps n and n+1 + // Compute avg pressures at 3D Dirichlet boundaries at timesteps n and n+1 else if (utils::btest(bc.bType, iBC_Dir)) { double area = fa.area; - cplBC.fa[ptr].Po = all_fun::integ(com_mod, cm_mod, fa, com_mod.Yo, nsd) / area; + cplBC.fa[ptr].Po = all_fun::integ(com_mod, cm_mod, fa, Yo, nsd) / area; cplBC.fa[ptr].Pn = all_fun::integ(com_mod, cm_mod, fa, Yn, nsd) / area; cplBC.fa[ptr].Qo = 0.0; cplBC.fa[ptr].Qn = 0.0; @@ -525,7 +525,7 @@ void RCR_Integ_X(ComMod& com_mod, const CmMod& cm_mod, int istat) /// /// Replaces 'SUBROUTINE RCRINIT()' // -void rcr_init(ComMod& com_mod, const CmMod& cm_mod) +void rcr_init(ComMod& com_mod, const CmMod& cm_mod, const Array& Yo) { using namespace consts; @@ -541,15 +541,15 @@ void rcr_init(ComMod& com_mod, const CmMod& cm_mod) int ptr = bc.cplBCptr; if (!utils::btest(bc.bType, iBC_RCR)) { - continue; + continue; } if (ptr != -1) { if (cplBC.initRCR) { auto& fa = com_mod.msh[iM].fa[iFa]; double area = fa.area; - double Qo = all_fun::integ(com_mod, cm_mod, fa, com_mod.Yo, 0, nsd-1); - double Po = all_fun::integ(com_mod, cm_mod, fa, com_mod.Yo, nsd) / area; + double Qo = all_fun::integ(com_mod, cm_mod, fa, Yo, 0, nsd-1); + double Po = all_fun::integ(com_mod, cm_mod, fa, Yo, nsd) / area; cplBC.xo[ptr] = Po - (Qo * cplBC.fa[ptr].RCR.Rp); } else { cplBC.xo[ptr] = cplBC.fa[ptr].RCR.Xo; @@ -645,7 +645,7 @@ void set_bc_cmm_l(ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, con /// @brief Coupled BC quantities are computed here. /// Reproduces the Fortran 'SETBCCPL()' subrotutine. // -void set_bc_cpl(ComMod& com_mod, CmMod& cm_mod, Array& Yn) +void set_bc_cpl(ComMod& com_mod, CmMod& cm_mod, Array& Yn, const Array& Yo, const Array& Ao, const Array& Do) { static double absTol = 1.E-8, relTol = 1.E-5; @@ -654,7 +654,7 @@ void set_bc_cpl(ComMod& com_mod, CmMod& cm_mod, Array& Yn) const int nsd = com_mod.nsd; const int tnNo = com_mod.tnNo; auto& cplBC = com_mod.cplBC; - auto& Yo = com_mod.Yo; + // Yo, Ao, Do now passed as parameters const int iEq = 0; auto& eq = com_mod.eq[iEq]; @@ -665,10 +665,10 @@ void set_bc_cpl(ComMod& com_mod, CmMod& cm_mod, Array& Yn) auto cfg_o = MechanicalConfigurationType::reference; auto cfg_n = MechanicalConfigurationType::reference; - // If coupling scheme is implicit, calculate updated pressure and flowrate + // If coupling scheme is implicit, calculate updated pressure and flowrate // from 0D, as well as resistance from 0D using finite difference. if (cplBC.schm == CplBCType::cplBC_I) { - calc_der_cpl_bc(com_mod, cm_mod, Yn); + calc_der_cpl_bc(com_mod, cm_mod, Yn, Yo); // If coupling scheme is semi-implicit or explicit, only calculated updated // pressure and flowrate from 0D @@ -770,7 +770,7 @@ void set_bc_cpl(ComMod& com_mod, CmMod& cm_mod, Array& Yn) /// /// Reproduces 'SUBROUTINE SETBCDIR(lA, lY, lD)' // -void set_bc_dir(ComMod& com_mod, Array& lA, Array& lY, Array& lD) +void set_bc_dir(ComMod& com_mod, Array& lA, Array& lY, Array& lD, const Array& Yo, const Array& Ao, const Array& Do) { using namespace consts; @@ -931,8 +931,8 @@ void set_bc_dir(ComMod& com_mod, Array& lA, Array& lY, Array& lA, Array& lY, Array& lA, Array& lY, Array& lA, Array& lY, Array& Yn); +void calc_der_cpl_bc(ComMod& com_mod, const CmMod& cm_mod, Array& Yn, const Array& Yo); void cplBC_Integ_X(ComMod& com_mod, const CmMod& cm_mod, const bool RCRflag); void genBC_Integ_X(ComMod& com_mod, const CmMod& cm_mod, const std::string& genFlag); -void rcr_init(ComMod& com_mod, const CmMod& cm_mod); +void rcr_init(ComMod& com_mod, const CmMod& cm_mod, const Array& Yo); void RCR_Integ_X(ComMod& com_mod, const CmMod& cm_mod, int istat); void set_bc_cmm(ComMod& com_mod, const CmMod& cm_mod, const Array& Ag, const Array& Dg); void set_bc_cmm_l(ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, const Array& Ag, const Array& Dg ); -void set_bc_cpl(ComMod& com_mod, CmMod& cm_mod, Array& Yn); +void set_bc_cpl(ComMod& com_mod, CmMod& cm_mod, Array& Yn, const Array& Yo, const Array& Ao, const Array& Do); -void set_bc_dir(ComMod& com_mod, Array& lA, Array& lY, Array& lD); +void set_bc_dir(ComMod& com_mod, Array& lA, Array& lY, Array& lD, const Array& Yo, const Array& Ao, const Array& Do); void set_bc_dir_l(ComMod& com_mod, const bcType& lBc, const faceType& lFa, Array& lA, Array& lY, int lDof); void set_bc_dir_w(ComMod& com_mod, const Array& Yg, const Array& Dg); void set_bc_dir_wl(ComMod& com_mod, const bcType& lBc, const mshType& lM, const faceType& lFa, const Array& Yg, const Array& Dg); diff --git a/Code/Source/solver/uris.cpp b/Code/Source/solver/uris.cpp index a99c5a8bc..607658e4c 100644 --- a/Code/Source/solver/uris.cpp +++ b/Code/Source/solver/uris.cpp @@ -247,8 +247,8 @@ void uris_meanv(ComMod& com_mod, CmMod& cm_mod, const int iUris, Array& /// @brief This subroutine computes the displacement of the immersed /// surface with fem projection -void uris_update_disp(ComMod& com_mod, CmMod& cm_mod) { - #define n_debug_uris_update_disp +void uris_update_disp(ComMod& com_mod, CmMod& cm_mod, const Array& Do) { + #define n_debug_uris_update_disp #ifdef debug_uris_update_disp DebugMsg dmsg(__func__, com_mod.cm.idcm()); dmsg.banner(); @@ -313,10 +313,10 @@ void uris_update_disp(ComMod& com_mod, CmMod& cm_mod) { d = 0.0; for (int a = 0; a < mesh.eNoN; a++) { int Ac = mesh.IEN(a, iEln); - //We have to use Do because Dn contains the result coming from the solid - d(0) += N(a)*com_mod.Do(nsd+1, Ac); - d(1) += N(a)*com_mod.Do(nsd+2, Ac); - d(2) += N(a)*com_mod.Do(nsd+3, Ac); + //We have to use Do because Dn contains the result coming from the solid + d(0) += N(a)*Do(nsd+1, Ac); + d(1) += N(a)*Do(nsd+2, Ac); + d(2) += N(a)*Do(nsd+3, Ac); } // update uris disp localYd.set_col(nd, d); diff --git a/Code/Source/solver/uris.h b/Code/Source/solver/uris.h index aaefb61c2..46fd693f4 100644 --- a/Code/Source/solver/uris.h +++ b/Code/Source/solver/uris.h @@ -13,7 +13,7 @@ void uris_meanp(ComMod& com_mod, CmMod& cm_mod, const int iUris, Array& void uris_meanv(ComMod& com_mod, CmMod& cm_mod, const int iUris, Array& Yn); // done -void uris_update_disp(ComMod& com_mod, CmMod& cm_mod); +void uris_update_disp(ComMod& com_mod, CmMod& cm_mod, const Array& Do); void uris_find_tetra(ComMod& com_mod, CmMod& cm_mod, const int iUris); From 9b52ad50cd491b705f90129e4cb1ea928d2141b4 Mon Sep 17 00:00:00 2001 From: Shiyi Chen Date: Wed, 12 Nov 2025 23:50:25 +0000 Subject: [PATCH 15/33] Thread Do/Dn displacement parameters through all boundary condition and integration functions Following the extraction of Ao/Do/Yo from ComMod to Integrator class, this commit completes the parameter threading work by updating all functions that perform face integration or boundary condition operations to accept and pass Do/Dn parameters. Changes include: Boundary Condition Functions: - bc_ini(): Add Do parameter, update 3 integ() calls for parabolic profiles and flux normalization - set_bc_cmm(), set_bc_cmm_l(): Add Do parameter for CMM boundary conditions - set_bc_neu(), set_bc_neu_l(): Add Do parameter for Neumann boundary conditions - set_bc_dir_w(), set_bc_dir_wl(): Add Do parameter for Dirichlet wall conditions - set_bc_trac_l(): Add Do parameter for traction boundary conditions - set_bc_rbnl(): Add Do parameter for Robin boundary conditions - set_bc_cpl(): Update to pass Do to bc_ini() for coupled BC area recalculation FSI and Mesh Functions: - fsi_ls_upd(): Add both Dn and Do parameters for level set updates - fsi_ls_ini(): Add Do parameter for FSI initialization - b_assem_neu_bc(), b_neu_folw_p(): Add Do parameter for Neumann BC assembly RIS (Reduced Immersed Surface) Functions: - ris_meanq(): Add Do parameter, update 2 integ() calls for pressure/flow computation - ris0d_status(): Add Do parameter, update 3 integ() calls for 0D coupling - ris_resbc(), setbc_ris(), ris0d_bc(): Add Do parameter for RIS boundary conditions CMM (Coupled Momentum Method): - cmm_b(): Add Do parameter, update nn::gnnb() call with full parameters Integration Functions: - All face-based integ() calls updated to pass Do parameter via pointer - Updated calls to use proper signatures with pFlag, cfg, Dn, and Do parameters - Enhanced error reporting in nn::gnnb() to include face name, mesh name, and element Main Integration Loop: - Integrator::iterate(): Updated all set_bc calls to pass Do_ parameter - main.cpp: Updated ris_meanq() and ris0d_status() calls to pass Do --- Code/Source/solver/Integrator.cpp | 12 ++--- Code/Source/solver/all_fun.cpp | 22 ++++----- Code/Source/solver/all_fun.h | 10 ++-- Code/Source/solver/baf_ini.cpp | 36 +++++++------- Code/Source/solver/baf_ini.h | 8 ++-- Code/Source/solver/cmm.cpp | 8 ++-- Code/Source/solver/cmm.h | 6 +-- Code/Source/solver/eq_assem.cpp | 38 +++++++-------- Code/Source/solver/eq_assem.h | 6 +-- Code/Source/solver/initialize.cpp | 4 +- Code/Source/solver/main.cpp | 8 ++-- Code/Source/solver/nn.cpp | 2 +- Code/Source/solver/ris.cpp | 36 +++++++------- Code/Source/solver/ris.h | 12 ++--- Code/Source/solver/set_bc.cpp | 80 +++++++++++++++---------------- Code/Source/solver/set_bc.h | 22 ++++----- Code/Source/solver/uris.cpp | 16 +++---- Code/Source/solver/uris.h | 4 +- 18 files changed, 165 insertions(+), 165 deletions(-) diff --git a/Code/Source/solver/Integrator.cpp b/Code/Source/solver/Integrator.cpp index 325b694d8..c4ee89dec 100644 --- a/Code/Source/solver/Integrator.cpp +++ b/Code/Source/solver/Integrator.cpp @@ -108,7 +108,7 @@ bool Integrator::step() { #ifdef debug_integrator_step dmsg << "Set coupled BCs " << std::endl; #endif - set_bc::set_bc_cpl(com_mod, cm_mod, Yn_, Yo_, Ao_, Do_); + set_bc::set_bc_cpl(com_mod, cm_mod, An_, Yn_, Dn_, Yo_, Ao_, Do_); set_bc::set_bc_dir(com_mod, An_, Yn_, Dn_, Yo_, Ao_, Do_); } @@ -279,22 +279,22 @@ void Integrator::apply_boundary_conditions() { Dg_.write("Dg_vor_neu" + istr_); // Apply Neumman or Traction boundary conditions - set_bc::set_bc_neu(com_mod, cm_mod, Yg_, Dg_, Yn); + set_bc::set_bc_neu(com_mod, cm_mod, Yg_, Dg_, Yn, Do_); // Apply CMM BC conditions if (!com_mod.cmmInit) { - set_bc::set_bc_cmm(com_mod, cm_mod, Ag_, Dg_); + set_bc::set_bc_cmm(com_mod, cm_mod, Ag_, Dg_, Do_); } // Apply weakly applied Dirichlet BCs - set_bc::set_bc_dir_w(com_mod, Yg_, Dg_); + set_bc::set_bc_dir_w(com_mod, Yg_, Dg_, Do_); if (com_mod.risFlag) { - ris::ris_resbc(com_mod, Yg_, Dg_); + ris::ris_resbc(com_mod, Yg_, Dg_, Do_); } if (com_mod.ris0DFlag) { - ris::ris0d_bc(com_mod, cm_mod, Yg_, Dg_, Yn); + ris::ris0d_bc(com_mod, cm_mod, Yg_, Dg_, Yn, Do_); } // Apply contact model and add its contribution to residual diff --git a/Code/Source/solver/all_fun.cpp b/Code/Source/solver/all_fun.cpp index db5c00771..0de99c898 100644 --- a/Code/Source/solver/all_fun.cpp +++ b/Code/Source/solver/all_fun.cpp @@ -684,7 +684,7 @@ double integ(const ComMod& com_mod, const CmMod& cm_mod, int dId, const Array& s, bool pFlag, MechanicalConfigurationType cfg) +double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, const Vector& s, bool pFlag, MechanicalConfigurationType cfg, const Array* Dn, const Array* Do) { using namespace consts; #define n_debug_integ_s @@ -809,7 +809,7 @@ double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, co if (!isIB) { // Get normal vector in cfg configuration auto Nx = fs.Nx.slice(g); - nn::gnnb(com_mod, lFa, e, g, nsd, insd, fs.eNoN, Nx, n, cfg); + nn::gnnb(com_mod, lFa, e, g, nsd, insd, fs.eNoN, Nx, n, cfg, Dn, Do); } // Calculating the Jacobian (encodes area of face element) @@ -847,8 +847,8 @@ double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, co /// @param pFlag flag for using Taylor-Hood function space for pressure /// @param cfg denotes which configuration (reference/timestep 0, old/timestep n, or new/timestep n+1). Default reference. // -double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, - const Array& s, MechanicalConfigurationType cfg) +double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, + const Array& s, MechanicalConfigurationType cfg, const Array* Dn, const Array* Do) { using namespace consts; @@ -929,7 +929,7 @@ double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, if (!isIB) { // Get normal vector in cfg configuration auto Nx = lFa.Nx.slice(g); - nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, lFa.eNoN, Nx, n, cfg); + nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, lFa.eNoN, Nx, n, cfg, Dn, Do); //CALL GNNB(lFa, e, g, nsd-1, lFa.eNoN, lFa.Nx(:,:,g), n) } else { //CALL GNNIB(lFa, e, g, n) @@ -981,8 +981,8 @@ double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, /// @param cfg denotes which configuration (reference/timestep 0, old/timestep n, or new/timestep n+1). Default reference. /// // -double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, - const Array& s, const int l, std::optional uo, bool THflag, MechanicalConfigurationType cfg) +double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, + const Array& s, const int l, std::optional uo, bool THflag, MechanicalConfigurationType cfg, const Array* Dn, const Array* Do) { using namespace consts; @@ -1031,21 +1031,21 @@ double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, double result = 0.0; // If s vector, integrate as vector (dot with surface normal) - if (u-l+1 == nsd) { + if (u-l+1 == nsd) { Array vec(nsd,nNo); for (int a = 0; a < nNo; a++) { for (int i = l, n = 0; i <= u; i++, n++) { - vec(n,a) = s(i,a); + vec(n,a) = s(i,a); } } - result = integ(com_mod, cm_mod, lFa, vec, cfg); + result = integ(com_mod, cm_mod, lFa, vec, cfg, Dn, Do); // If s scalar, integrate as scalar } else if (l == u) { Vector sclr(nNo); for (int a = 0; a < nNo; a++) { sclr(a) = s(l,a); } - result = integ(com_mod, cm_mod, lFa, sclr, flag, cfg); + result = integ(com_mod, cm_mod, lFa, sclr, flag, cfg, Dn, Do); } else { throw std::runtime_error("Unexpected dof in integ"); } diff --git a/Code/Source/solver/all_fun.h b/Code/Source/solver/all_fun.h index 04de9cc3a..2f95b7455 100644 --- a/Code/Source/solver/all_fun.h +++ b/Code/Source/solver/all_fun.h @@ -34,13 +34,13 @@ namespace all_fun { double integ(const ComMod& com_mod, const CmMod& cm_mod, int dId, const Array& s, int l, int u, bool pFlag=false, const Array* Do=nullptr); - double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, const Vector& s, - bool pFlag=false, consts::MechanicalConfigurationType cfg=consts::MechanicalConfigurationType::reference); + double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, const Vector& s, + bool pFlag=false, consts::MechanicalConfigurationType cfg=consts::MechanicalConfigurationType::reference, const Array* Dn=nullptr, const Array* Do=nullptr); - double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, const Array& s, - const int l, std::optional uo=std::nullopt, bool THflag=false, consts::MechanicalConfigurationType cfg=consts::MechanicalConfigurationType::reference); + double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, const Array& s, + const int l, std::optional uo=std::nullopt, bool THflag=false, consts::MechanicalConfigurationType cfg=consts::MechanicalConfigurationType::reference, const Array* Dn=nullptr, const Array* Do=nullptr); - double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, const Array& s, consts::MechanicalConfigurationType cfg=consts::MechanicalConfigurationType::reference); + double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, const Array& s, consts::MechanicalConfigurationType cfg=consts::MechanicalConfigurationType::reference, const Array* Dn=nullptr, const Array* Do=nullptr); bool is_domain(const ComMod& com_mod, const eqType& eq, const int node, const consts::EquationType phys); diff --git a/Code/Source/solver/baf_ini.cpp b/Code/Source/solver/baf_ini.cpp index b00b809bd..a766dba89 100644 --- a/Code/Source/solver/baf_ini.cpp +++ b/Code/Source/solver/baf_ini.cpp @@ -39,7 +39,7 @@ namespace baf_ini_ns { /// /// Replicates 'SUBROUTINE BAFINI()' defined in BAFINIT.f // -void baf_ini(Simulation* simulation, Array& Do, Array& Yo) +void baf_ini(Simulation* simulation, const Array& Ao, Array& Do, Array& Yo) { using namespace consts; using namespace fsi_linear_solver; @@ -82,10 +82,10 @@ void baf_ini(Simulation* simulation, Array& Do, Array& Yo) auto& bc = eq.bc[iBc]; int iFa = bc.iFa; int iM = bc.iM; - bc_ini(com_mod, cm_mod, bc, com_mod.msh[iM].fa[iFa]); + bc_ini(com_mod, cm_mod, bc, com_mod.msh[iM].fa[iFa], Do); if (com_mod.msh[iM].lShl) { - shl_bc_ini(com_mod, cm_mod, bc, com_mod.msh[iM].fa[iFa], com_mod.msh[iM]); + shl_bc_ini(com_mod, cm_mod, bc, com_mod.msh[iM].fa[iFa], com_mod.msh[iM], Do); } } } @@ -133,7 +133,7 @@ void baf_ini(Simulation* simulation, Array& Do, Array& Yo) } if (!com_mod.stFileFlag) { - set_bc::rcr_init(com_mod, cm_mod, Yo); + set_bc::rcr_init(com_mod, cm_mod, Ao, Do, Yo); } if (com_mod.cplBC.useGenBC) { @@ -145,7 +145,7 @@ void baf_ini(Simulation* simulation, Array& Do, Array& Yo) } if (com_mod.cplBC.schm != CplBCType::cplBC_E) { - set_bc::calc_der_cpl_bc(com_mod, cm_mod, Yo, Yo); + set_bc::calc_der_cpl_bc(com_mod, cm_mod, Yo, Yo, Do, Yo, Ao, Do); } } @@ -163,7 +163,7 @@ void baf_ini(Simulation* simulation, Array& Do, Array& Yo) int iFa = bc.iFa; int iM = bc.iM; bc.lsPtr = 0; - fsi_ls_ini(com_mod, cm_mod, bc, com_mod.msh[iM].fa[iFa], lsPtr); + fsi_ls_ini(com_mod, cm_mod, bc, com_mod.msh[iM].fa[iFa], lsPtr, Do); } } @@ -225,7 +225,7 @@ void baf_ini(Simulation* simulation, Array& Do, Array& Yo) // bc_ini //--------- // -void bc_ini(const ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, faceType& lFa) +void bc_ini(const ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, faceType& lFa, const Array& Do) { using namespace consts; using namespace utils; @@ -233,7 +233,7 @@ void bc_ini(const ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, faceType& l auto& cm = com_mod.cm; int nsd = com_mod.nsd; int tnNo = com_mod.tnNo; - + #define n_debug_bc_ini #ifdef debug_bc_ini DebugMsg dmsg(__func__, com_mod.cm.idcm()); @@ -272,7 +272,7 @@ void bc_ini(const ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, faceType& l Vector disp(cm.np()); // Just a constant value for Flat profile - if (btest(lBc.bType, iBC_flat)) { + if (btest(lBc.bType, iBC_flat)) { for (int a = 0; a < lFa.nNo; a++) { int Ac = lFa.gN(a); s(Ac) = 1.0; @@ -284,10 +284,10 @@ void bc_ini(const ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, faceType& l // 3- maximize ew(i).e where e is the unit vector from current // point to the center 4- Use the point i as the diam here // - } else if (btest(lBc.bType, iBC_para)) { + } else if (btest(lBc.bType, iBC_para)) { Vector center(3); for (int i = 0; i < nsd; i++) { - center(i) = all_fun::integ(com_mod, cm_mod, lFa, com_mod.x, i) / lFa.area; + center(i) = all_fun::integ(com_mod, cm_mod, lFa, com_mod.x, i, std::nullopt, false, consts::MechanicalConfigurationType::reference, nullptr, &Do) / lFa.area; } // gNodes is one if a node located on the boundary (beside iFa) @@ -395,8 +395,8 @@ void bc_ini(const ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, faceType& l // Normalizing the profile for flux // double tmp = 1.0; - if (btest(lBc.bType, enum_int(BoundaryConditionType::bType_flx))) { - tmp = all_fun::integ(com_mod, cm_mod, lFa, s); + if (btest(lBc.bType, enum_int(BoundaryConditionType::bType_flx))) { + tmp = all_fun::integ(com_mod, cm_mod, lFa, s, false, consts::MechanicalConfigurationType::reference, nullptr, &Do); if (is_zero(tmp)) { tmp = 1.0; throw std::runtime_error("Face '" + lFa.name + "' used for a BC has no non-zero node."); @@ -436,7 +436,7 @@ void face_ini(Simulation* simulation, mshType& lM, faceType& lFa, Array& // Vector sA(com_mod.tnNo); sA = 1.0; - double area = all_fun::integ(com_mod, cm_mod, lFa, sA); + double area = all_fun::integ(com_mod, cm_mod, lFa, sA, false, consts::MechanicalConfigurationType::reference, nullptr, &Do); #ifdef debug_face_ini dmsg << "Face '" << lFa.name << "' area: " << area; #endif @@ -478,7 +478,7 @@ void face_ini(Simulation* simulation, mshType& lM, faceType& lFa, Array& for (int g = 0; g < lFa.nG; g++) { auto Nx = lFa.Nx.slice(g); - nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, lFa.eNoN, Nx, nV); + nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, lFa.eNoN, Nx, nV, consts::MechanicalConfigurationType::reference, nullptr, &Do); for (int a = 0; a < lFa.eNoN; a++) { int Ac = lFa.IEN(a,e); @@ -661,7 +661,7 @@ void face_ini(Simulation* simulation, mshType& lM, faceType& lFa, Array& // // Replicates 'SUBROUTINE FSILSINI'. // -void fsi_ls_ini(ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, const faceType& lFa, int& lsPtr) +void fsi_ls_ini(ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, const faceType& lFa, int& lsPtr, const Array& Do) { using namespace consts; using namespace utils; @@ -728,7 +728,7 @@ void fsi_ls_ini(ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, const faceTyp for (int g = 0; g < lFa.nG; g++) { Vector n(nsd); auto Nx = lFa.Nx.slice(g); - nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, lFa.eNoN, Nx, n); + nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, lFa.eNoN, Nx, n, consts::MechanicalConfigurationType::reference, nullptr, &Do); for (int a = 0; a < lFa.eNoN; a++) { int Ac = lFa.IEN(a,e); @@ -868,7 +868,7 @@ void set_shl_xien(Simulation* simulation, mshType& lM) // // Reproduces 'SUBROUTINE SHLBCINI(lBc, lFa, lM)'. // -void shl_bc_ini(const ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, faceType& lFa, mshType& lM) +void shl_bc_ini(const ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, faceType& lFa, mshType& lM, const Array& Do) { using namespace consts; using namespace utils; diff --git a/Code/Source/solver/baf_ini.h b/Code/Source/solver/baf_ini.h index cf7f41635..694a73d96 100644 --- a/Code/Source/solver/baf_ini.h +++ b/Code/Source/solver/baf_ini.h @@ -9,17 +9,17 @@ namespace baf_ini_ns { -void baf_ini(Simulation* simulation, Array& Do, Array& Yo); +void baf_ini(Simulation* simulation, const Array& Ao, Array& Do, Array& Yo); -void bc_ini(const ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, faceType& lFa); +void bc_ini(const ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, faceType& lFa, const Array& Do); void face_ini(Simulation* simulation, mshType& lm, faceType& la, Array& Do); -void fsi_ls_ini(ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, const faceType& lFa, int& lsPtr); +void fsi_ls_ini(ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, const faceType& lFa, int& lsPtr, const Array& Do); void set_shl_xien(Simulation* simulation, mshType& mesh); -void shl_bc_ini(const ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, faceType& lFa, mshType& lM); +void shl_bc_ini(const ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, faceType& lFa, mshType& lM, const Array& Do); void shl_ini(const ComMod& com_mod, const CmMod& cm_mod, mshType& lM); diff --git a/Code/Source/solver/cmm.cpp b/Code/Source/solver/cmm.cpp index 1f60588d5..38280ace7 100644 --- a/Code/Source/solver/cmm.cpp +++ b/Code/Source/solver/cmm.cpp @@ -260,9 +260,9 @@ void cmm_3d(ComMod& com_mod, const int eNoN, const double w, const Vector& al, const Array& dl, - const Array& xl, const Array& bfl, const Vector& pS0l, const Vector& vwp, - const Vector& ptr) +void cmm_b(ComMod& com_mod, const faceType& lFa, const int e, const Array& al, const Array& dl, + const Array& xl, const Array& bfl, const Vector& pS0l, const Vector& vwp, + const Vector& ptr, const Array& Do) { const int nsd = com_mod.nsd; const int dof = com_mod.dof; @@ -282,7 +282,7 @@ void cmm_b(ComMod& com_mod, const faceType& lFa, const int e, const Array nV(nsd); auto Nx = lFa.Nx.slice(g); - nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, 3, Nx, nV); + nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, 3, Nx, nV, consts::MechanicalConfigurationType::reference, nullptr, &Do); double Jac = sqrt(utils::norm(nV)); nV = nV / Jac; double w = lFa.w(g)*Jac; diff --git a/Code/Source/solver/cmm.h b/Code/Source/solver/cmm.h index 1f1086a7a..049c2f026 100644 --- a/Code/Source/solver/cmm.h +++ b/Code/Source/solver/cmm.h @@ -14,9 +14,9 @@ void cmm_3d(ComMod& com_mod, const int eNoN, const double w, const Vector& al, const Array& yl, const Array& bfl, const Array& Kxi, Array& lR, Array3& lK); -void cmm_b(ComMod& com_mod, const faceType& lFa, const int e, const Array& al, const Array& dl, - const Array& xl, const Array& bfl, const Vector& pS0l, const Vector& vwp, - const Vector& ptr); +void cmm_b(ComMod& com_mod, const faceType& lFa, const int e, const Array& al, const Array& dl, + const Array& xl, const Array& bfl, const Vector& pS0l, const Vector& vwp, + const Vector& ptr, const Array& Do); void bcmmi(ComMod& com_mod, const int eNoN, const int idof, const double w, const Vector& N, const Array& Nxi, const Array& xl, const Array& tfl, Array& lR); diff --git a/Code/Source/solver/eq_assem.cpp b/Code/Source/solver/eq_assem.cpp index dcea0cdbd..460388593 100644 --- a/Code/Source/solver/eq_assem.cpp +++ b/Code/Source/solver/eq_assem.cpp @@ -28,7 +28,7 @@ namespace eq_assem { -void b_assem_neu_bc(ComMod& com_mod, const faceType& lFa, const Vector& hg, const Array& Yg) +void b_assem_neu_bc(ComMod& com_mod, const faceType& lFa, const Vector& hg, const Array& Yg, const Array& Do) { #define n_debug_b_assem_neu_bc #ifdef debug_b_assem_neu_bc @@ -54,9 +54,9 @@ void b_assem_neu_bc(ComMod& com_mod, const faceType& lFa, const Vector& cDmn = all_fun::domain(com_mod, msh, cEq, Ec); auto cPhys = eq.dmn[cDmn].phys; - Vector ptr(eNoN); - Vector N(eNoN), hl(eNoN); - Array yl(tDof,eNoN), lR(dof,eNoN); + Vector ptr(eNoN); + Vector N(eNoN), hl(eNoN); + Array yl(tDof,eNoN), lR(dof,eNoN); Array3 lK(dof*dof,eNoN,eNoN); for (int a = 0; a < eNoN; a++) { @@ -76,7 +76,7 @@ void b_assem_neu_bc(ComMod& com_mod, const faceType& lFa, const Vector& for (int g = 0; g < lFa.nG; g++) { Vector nV(nsd); auto Nx = lFa.Nx.rslice(g); - nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, eNoN, Nx, nV); + nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, eNoN, Nx, nV, consts::MechanicalConfigurationType::reference, nullptr, &Do); double Jac = sqrt(utils::norm(nV)); nV = nV / Jac; double w = lFa.w(g)*Jac; @@ -156,13 +156,13 @@ void b_assem_neu_bc(ComMod& com_mod, const faceType& lFa, const Vector& /// @param lFa /// @param hg Pressure magnitude /// @param Dg -void b_neu_folw_p(ComMod& com_mod, const bcType& lBc, const faceType& lFa, const Vector& hg, const Array& Dg) +void b_neu_folw_p(ComMod& com_mod, const bcType& lBc, const faceType& lFa, const Vector& hg, const Array& Dg, const Array& Do) { using namespace consts; using namespace utils; #define n_debug_b_neu_folw_p - #ifdef debug_b_neu_folw_p + #ifdef debug_b_neu_folw_p DebugMsg dmsg(__func__, com_mod.cm.idcm()); dmsg.banner(); dmsg << "lFa.name: " << lFa.name; @@ -181,7 +181,7 @@ void b_neu_folw_p(ComMod& com_mod, const bcType& lBc, const faceType& lFa, const auto& eq = com_mod.eq[cEq]; auto& cDmn = com_mod.cDmn; - #ifdef debug_b_neu_folw_p + #ifdef debug_b_neu_folw_p dmsg << "nsd: " << nsd; dmsg << "eNoN: " << nsd; #endif @@ -191,13 +191,13 @@ void b_neu_folw_p(ComMod& com_mod, const bcType& lBc, const faceType& lFa, const cDmn = all_fun::domain(com_mod, msh, cEq, Ec); // Changes global auto cPhys = eq.dmn[cDmn].phys; - Vector ptr(eNoN); - Vector hl(eNoN); - Array xl(nsd,eNoN); + Vector ptr(eNoN); + Vector hl(eNoN); + Array xl(nsd,eNoN); Array dl(tDof,eNoN); - Vector N(eNoN); - Array Nxi(nsd,eNoN); - Array Nx(nsd,eNoN); + Vector N(eNoN); + Array Nxi(nsd,eNoN); + Array Nx(nsd,eNoN); Array lR(dof,eNoN); Array3 lK(dof*dof,eNoN,eNoN); Array3 lKd; @@ -245,7 +245,7 @@ void b_neu_folw_p(ComMod& com_mod, const bcType& lBc, const faceType& lFa, const // Get surface normal vector Vector nV(nsd); auto Nx_g = lFa.Nx.rslice(g); - nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, eNoNb, Nx_g, nV); + nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, eNoNb, Nx_g, nV, consts::MechanicalConfigurationType::reference, nullptr, &Do); Jac = sqrt(utils::norm(nV)); nV = nV / Jac; double w = lFa.w(g)*Jac; @@ -286,7 +286,7 @@ void b_neu_folw_p(ComMod& com_mod, const bcType& lBc, const faceType& lFa, const /// is eventually used in ADDBCMUL() in the linear solver to add the contribution /// from the resistance BC to the matrix-vector product of the tangent matrix and /// an arbitrary vector. -void fsi_ls_upd(ComMod& com_mod, const bcType& lBc, const faceType& lFa) +void fsi_ls_upd(ComMod& com_mod, const bcType& lBc, const faceType& lFa, const Array& Dn, const Array& Do) { using namespace consts; using namespace utils; @@ -306,8 +306,8 @@ void fsi_ls_upd(ComMod& com_mod, const bcType& lBc, const faceType& lFa) int iM = lFa.iM; int nNo = lFa.nNo; - Array sVl(nsd,nNo); - Array sV(nsd,tnNo); + Array sVl(nsd,nNo); + Array sV(nsd,tnNo); // Updating the value of the surface integral of the normal vector // using the deformed configuration ('n' = new = timestep n+1) @@ -322,7 +322,7 @@ void fsi_ls_upd(ComMod& com_mod, const bcType& lBc, const faceType& lFa) auto cfg = MechanicalConfigurationType::new_timestep; - nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, lFa.eNoN, Nx, n, cfg); + nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, lFa.eNoN, Nx, n, cfg, &Dn, &Do); // for (int a = 0; a < lFa.eNoN; a++) { int Ac = lFa.IEN(a,e); diff --git a/Code/Source/solver/eq_assem.h b/Code/Source/solver/eq_assem.h index 7d60ee3b4..eeb0d92ae 100644 --- a/Code/Source/solver/eq_assem.h +++ b/Code/Source/solver/eq_assem.h @@ -9,11 +9,11 @@ namespace eq_assem { -void b_assem_neu_bc(ComMod& com_mod, const faceType& lFa, const Vector& hg, const Array& Yg); +void b_assem_neu_bc(ComMod& com_mod, const faceType& lFa, const Vector& hg, const Array& Yg, const Array& Do); -void b_neu_folw_p(ComMod& com_mod, const bcType& lBc, const faceType& lFa, const Vector& hg, const Array& Dg); +void b_neu_folw_p(ComMod& com_mod, const bcType& lBc, const faceType& lFa, const Vector& hg, const Array& Dg, const Array& Do); -void fsi_ls_upd(ComMod& com_mod, const bcType& lBc, const faceType& lFa); +void fsi_ls_upd(ComMod& com_mod, const bcType& lBc, const faceType& lFa, const Array& Dn, const Array& Do); void global_eq_assem(ComMod& com_mod, CepMod& cep_mod, const mshType& lM, const Array& Ag, const Array& Yg, const Array& Dg, const Array& Do); diff --git a/Code/Source/solver/initialize.cpp b/Code/Source/solver/initialize.cpp index 2d7c2dbe5..7f61a82bb 100644 --- a/Code/Source/solver/initialize.cpp +++ b/Code/Source/solver/initialize.cpp @@ -806,7 +806,7 @@ void initialize(Simulation* simulation, Vector& timeP) for (int iDmn = 0; iDmn < eq.nDmn; iDmn++) { int i = eq.dmn[iDmn].Id; - eq.dmn[iDmn].v = all_fun::integ(com_mod, cm_mod, i, s, 0, 0); + eq.dmn[iDmn].v = all_fun::integ(com_mod, cm_mod, i, s, 0, 0, false, &Do); if (!com_mod.shlEq && !com_mod.cmmInit) { //std = " Volume of domain <"//STR(i)//"> is "// 2 STR(eq(iEq)%dmn(iDmn)%v) //IF (ISZERO(eq(iEq)%dmn(iDmn)%v)) wrn = "<< Volume of "// "domain "//iDmn//" of equation "//iEq//" is zero >>" @@ -816,7 +816,7 @@ void initialize(Simulation* simulation, Vector& timeP) // Preparing faces and BCs // - baf_ini_ns::baf_ini(simulation, Do, Yo); + baf_ini_ns::baf_ini(simulation, Ao, Do, Yo); // As all the arrays are allocated, call BIN to VTK for conversion // diff --git a/Code/Source/solver/main.cpp b/Code/Source/solver/main.cpp index c830bcc0d..1a3847c8d 100644 --- a/Code/Source/solver/main.cpp +++ b/Code/Source/solver/main.cpp @@ -357,7 +357,7 @@ void iterate_solution(Simulation* simulation) */ if (com_mod.risFlag) { - ris::ris_meanq(com_mod, cm_mod, An, Dn, Yn); + ris::ris_meanq(com_mod, cm_mod, An, Dn, Yn, Do); ris::ris_status(com_mod, cm_mod); if (cm.mas(cm_mod)) { std::cout << "Iteration: " << com_mod.cTS << std::endl; @@ -493,7 +493,7 @@ void iterate_solution(Simulation* simulation) // [HZ] Part related to RIS0D if (cEq == 0 && com_mod.ris0DFlag) { - ris::ris0d_status(com_mod, cm_mod, An, Dn, Yn); + ris::ris0d_status(com_mod, cm_mod, An, Dn, Yn, Do); } // [HZ] Part related to unfitted RIS @@ -502,12 +502,12 @@ void iterate_solution(Simulation* simulation) for (int iUris = 0; iUris < com_mod.nUris; iUris++) { com_mod.uris[iUris].cnt++; if (com_mod.uris[iUris].clsFlg) { - uris::uris_meanp(com_mod, cm_mod, iUris, Yn); + uris::uris_meanp(com_mod, cm_mod, iUris, Dn, Yn, Do); // if (com_mod.uris[iUris].cnt == 1) { // // GOTO 11 // The GOTO Statement in the Fortran code // } } else { - uris::uris_meanv(com_mod, cm_mod, iUris, Yn); + uris::uris_meanv(com_mod, cm_mod, iUris, Dn, Yn, Do); } if (cm.mas(cm_mod)) { std::cout << " URIS surface: " << com_mod.uris[iUris].name << ", count: " << com_mod.uris[iUris].cnt << std::endl; diff --git a/Code/Source/solver/nn.cpp b/Code/Source/solver/nn.cpp index 4c1e2f3d6..76f9510c5 100644 --- a/Code/Source/solver/nn.cpp +++ b/Code/Source/solver/nn.cpp @@ -607,7 +607,7 @@ void gnnb(const ComMod& com_mod, const faceType& lFa, const int e, const int g, } if (com_mod.mvMsh) { if (!Do) { - throw std::runtime_error("gnnb: Do parameter required for moving mesh but not provided"); + throw std::runtime_error("gnnb: Do parameter required for moving mesh but not provided. Face: '" + lFa.name + "', Mesh: '" + msh.name + "', Element: " + std::to_string(e)); } for (int i = 0; i < lX.nrows(); i++) { // Add mesh displacement diff --git a/Code/Source/solver/ris.cpp b/Code/Source/solver/ris.cpp index db3d9b6a8..b653bdabc 100644 --- a/Code/Source/solver/ris.cpp +++ b/Code/Source/solver/ris.cpp @@ -13,7 +13,7 @@ namespace ris { /// @brief This subroutine computes the mean pressure and flux on the ris surface -void ris_meanq(ComMod& com_mod, CmMod& cm_mod, Array& An, Array& Dn, Array& Yn) +void ris_meanq(ComMod& com_mod, CmMod& cm_mod, Array& An, Array& Dn, Array& Yn, const Array& Do) { #define n_debug_ris_meanq #ifdef debug_ris_meanq @@ -56,17 +56,17 @@ void ris_meanq(ComMod& com_mod, CmMod& cm_mod, Array& An, Array& int iM = RIS.lst(i,0,iProj); int iFa = RIS.lst(i,1,iProj); double tmp = msh[iM].fa[iFa].area; - RIS.meanP(iProj,i) = all_fun::integ(com_mod, cm_mod, msh[iM].fa[iFa], tmpV, 0)/tmp; + RIS.meanP(iProj,i) = all_fun::integ(com_mod, cm_mod, msh[iM].fa[iFa], tmpV, 0, std::nullopt, false, consts::MechanicalConfigurationType::reference, nullptr, &Do)/tmp; } } // For the velocity - m = nsd; + m = nsd; s = eq[iEq].s; e = s + m - 1; for (int iProj = 0; iProj < nPrj; iProj++) { - // tmpV[0:m,:] = Yn[s:e,:]; + // tmpV[0:m,:] = Yn[s:e,:]; for (int i = 0; i < m; i++) { for (int j = 0; j < Yn.ncols(); j++) { tmpV(i,j) = Yn(s+i,j); @@ -74,11 +74,11 @@ void ris_meanq(ComMod& com_mod, CmMod& cm_mod, Array& An, Array& } int iM = RIS.lst(0,0,iProj); int iFa = RIS.lst(0,1,iProj); - RIS.meanFl(iProj) = all_fun::integ(com_mod, cm_mod, msh[iM].fa[iFa], tmpV, 0, m-1); + RIS.meanFl(iProj) = all_fun::integ(com_mod, cm_mod, msh[iM].fa[iFa], tmpV, 0, m-1, false, consts::MechanicalConfigurationType::reference, nullptr, &Do); if (cm.mas(cm_mod)) { std::cout << "For RIS projection: " << iProj << std::endl; - std::cout << " The average pressure is: " << RIS.meanP(iProj,0) << ", " + std::cout << " The average pressure is: " << RIS.meanP(iProj,0) << ", " << RIS.meanP(iProj,1) << std::endl; std::cout << " The average flow is: " << RIS.meanFl(iProj) << std::endl; } @@ -86,7 +86,7 @@ void ris_meanq(ComMod& com_mod, CmMod& cm_mod, Array& An, Array& } /// @brief Weak treatment of RIS resistance boundary conditions -void ris_resbc(ComMod& com_mod, const Array& Yg, const Array& Dg) +void ris_resbc(ComMod& com_mod, const Array& Yg, const Array& Dg, const Array& Do) { using namespace consts; #define n_debug_ris_resbc @@ -134,7 +134,7 @@ void ris_resbc(ComMod& com_mod, const Array& Yg, const Array& Dg if (cPhys == EquationType::phys_fluid) { // Build the correct BC - set_bc::set_bc_dir_wl(com_mod, lBc, msh[iM], msh[iM].fa[iFa], Yg, Dg); + set_bc::set_bc_dir_wl(com_mod, lBc, msh[iM], msh[iM].fa[iFa], Yg, Dg, Do); } lBc.gx.clear(); } @@ -143,8 +143,8 @@ void ris_resbc(ComMod& com_mod, const Array& Yg, const Array& Dg } -void setbc_ris(ComMod& com_mod, const bcType& lBc, const mshType& lM, const faceType& lFa, - const Array& Yg, const Array& Dg) +void setbc_ris(ComMod& com_mod, const bcType& lBc, const mshType& lM, const faceType& lFa, + const Array& Yg, const Array& Dg, const Array& Do) { // [HZ] looks not needed in the current implementation } @@ -351,7 +351,7 @@ void setbcdir_ris(ComMod& com_mod, Array& lA, Array& lY, Array& Yg, const Array& Dg, Array& Yn) +void ris0d_bc(ComMod& com_mod, CmMod& cm_mod, const Array& Yg, const Array& Dg, Array& Yn, const Array& Do) { using namespace consts; @@ -388,22 +388,22 @@ void ris0d_bc(ComMod& com_mod, CmMod& cm_mod, const Array& Yg, const Arr lBc.eDrn.resize(nsd); lBc.eDrn = 0; - // Apply bc Dir + // Apply bc Dir lBc.gx.resize(msh[iM].fa[iFa].nNo); lBc.gx = 1.0; - set_bc::set_bc_dir_wl(com_mod, lBc, msh[iM], msh[iM].fa[iFa], Yg, Dg); + set_bc::set_bc_dir_wl(com_mod, lBc, msh[iM], msh[iM].fa[iFa], Yg, Dg, Do); lBc.gx.clear(); lBc.eDrn.clear(); } else { // Apply Neu bc - set_bc::set_bc_neu_l(com_mod, cm_mod, eq[cEq].bc[iBc], msh[iM].fa[iFa], Yg, Dg, Yn); + set_bc::set_bc_neu_l(com_mod, cm_mod, eq[cEq].bc[iBc], msh[iM].fa[iFa], Yg, Dg, Yn, Do); } } } -void ris0d_status(ComMod& com_mod, CmMod& cm_mod, Array& An, Array& Dn, Array& Yn) +void ris0d_status(ComMod& com_mod, CmMod& cm_mod, Array& An, Array& Dn, Array& Yn, const Array& Do) { using namespace consts; @@ -456,8 +456,8 @@ void ris0d_status(ComMod& com_mod, CmMod& cm_mod, Array& An, Array& An, Array& An, Array& Dn, Array& Yn); -void ris_resbc(ComMod& com_mod, const Array& Yg, const Array& Dg); -void setbc_ris(ComMod& com_mod, const bcType& lBc, const mshType& lM, const faceType& lFa, - const Array& Yg, const Array& Dg); +void ris_meanq(ComMod& com_mod, CmMod& cm_mod, Array& An, Array& Dn, Array& Yn, const Array& Do); +void ris_resbc(ComMod& com_mod, const Array& Yg, const Array& Dg, const Array& Do); +void setbc_ris(ComMod& com_mod, const bcType& lBc, const mshType& lM, const faceType& lFa, + const Array& Yg, const Array& Dg, const Array& Do); void ris_updater(ComMod& com_mod, CmMod& cm_mod, Array& An, Array& Dn, Array& Yn, Array& Ao, Array& Do, Array& Yo); void ris_status(ComMod& com_mod, CmMod& cm_mod); @@ -26,8 +26,8 @@ void clean_r_ris(ComMod& com_mod); void setbcdir_ris(ComMod& com_mod, Array& lA, Array& lY, Array& lD); // TODO: RIS 0D code -void ris0d_bc(ComMod& com_mod, CmMod& cm_mod, const Array& Yg, const Array& Dg, Array& Yn); -void ris0d_status(ComMod& com_mod, CmMod& cm_mod, Array& An, Array& Dn, Array& Yn); +void ris0d_bc(ComMod& com_mod, CmMod& cm_mod, const Array& Yg, const Array& Dg, Array& Yn, const Array& Do); +void ris0d_status(ComMod& com_mod, CmMod& cm_mod, Array& An, Array& Dn, Array& Yn, const Array& Do); }; diff --git a/Code/Source/solver/set_bc.cpp b/Code/Source/solver/set_bc.cpp index 3208af55c..219fff094 100644 --- a/Code/Source/solver/set_bc.cpp +++ b/Code/Source/solver/set_bc.cpp @@ -27,7 +27,7 @@ namespace set_bc { /// matrix M ~ dP/dQ stored in eq.bc[iBc].r. /// @param com_mod /// @param cm_mod -void calc_der_cpl_bc(ComMod& com_mod, const CmMod& cm_mod, Array& Yn, const Array& Yo) +void calc_der_cpl_bc(ComMod& com_mod, const CmMod& cm_mod, const Array& An, Array& Yn, const Array& Dn, const Array& Yo, const Array& Ao, const Array& Do) { using namespace consts; @@ -110,8 +110,8 @@ void calc_der_cpl_bc(ComMod& com_mod, const CmMod& cm_mod, Array& Yn, co else { throw std::runtime_error("[calc_der_cpl_bc] Invalid physics type for 0D coupling"); } - cplBC.fa[ptr].Qo = all_fun::integ(com_mod, cm_mod, fa, Yo, 0, nsd-1, false, cfg_o); - cplBC.fa[ptr].Qn = all_fun::integ(com_mod, cm_mod, fa, Yn, 0, nsd-1, false, cfg_n); + cplBC.fa[ptr].Qo = all_fun::integ(com_mod, cm_mod, fa, Yo, 0, nsd-1, false, cfg_o, &Ao, &Do); + cplBC.fa[ptr].Qn = all_fun::integ(com_mod, cm_mod, fa, Yn, 0, nsd-1, false, cfg_n, &An, &Dn); cplBC.fa[ptr].Po = 0.0; cplBC.fa[ptr].Pn = 0.0; #ifdef debug_calc_der_cpl_bc @@ -124,8 +124,8 @@ void calc_der_cpl_bc(ComMod& com_mod, const CmMod& cm_mod, Array& Yn, co // Compute avg pressures at 3D Dirichlet boundaries at timesteps n and n+1 else if (utils::btest(bc.bType, iBC_Dir)) { double area = fa.area; - cplBC.fa[ptr].Po = all_fun::integ(com_mod, cm_mod, fa, Yo, nsd) / area; - cplBC.fa[ptr].Pn = all_fun::integ(com_mod, cm_mod, fa, Yn, nsd) / area; + cplBC.fa[ptr].Po = all_fun::integ(com_mod, cm_mod, fa, Yo, nsd, std::nullopt, false, MechanicalConfigurationType::reference, &Ao, &Do) / area; + cplBC.fa[ptr].Pn = all_fun::integ(com_mod, cm_mod, fa, Yn, nsd, std::nullopt, false, MechanicalConfigurationType::reference, &An, &Dn) / area; cplBC.fa[ptr].Qo = 0.0; cplBC.fa[ptr].Qn = 0.0; #ifdef debug_calc_der_cpl_bc @@ -525,7 +525,7 @@ void RCR_Integ_X(ComMod& com_mod, const CmMod& cm_mod, int istat) /// /// Replaces 'SUBROUTINE RCRINIT()' // -void rcr_init(ComMod& com_mod, const CmMod& cm_mod, const Array& Yo) +void rcr_init(ComMod& com_mod, const CmMod& cm_mod, const Array& Ao, const Array& Do, const Array& Yo) { using namespace consts; @@ -548,8 +548,8 @@ void rcr_init(ComMod& com_mod, const CmMod& cm_mod, const Array& Yo) if (cplBC.initRCR) { auto& fa = com_mod.msh[iM].fa[iFa]; double area = fa.area; - double Qo = all_fun::integ(com_mod, cm_mod, fa, Yo, 0, nsd-1); - double Po = all_fun::integ(com_mod, cm_mod, fa, Yo, nsd) / area; + double Qo = all_fun::integ(com_mod, cm_mod, fa, Yo, 0, nsd-1, false, MechanicalConfigurationType::reference, &Ao, &Do); + double Po = all_fun::integ(com_mod, cm_mod, fa, Yo, nsd, std::nullopt, false, MechanicalConfigurationType::reference, &Ao, &Do) / area; cplBC.xo[ptr] = Po - (Qo * cplBC.fa[ptr].RCR.Rp); } else { cplBC.xo[ptr] = cplBC.fa[ptr].RCR.Xo; @@ -560,7 +560,7 @@ void rcr_init(ComMod& com_mod, const CmMod& cm_mod, const Array& Yo) /// @brief Below defines the SET_BC methods for the Coupled Momentum Method (CMM) // -void set_bc_cmm(ComMod& com_mod, const CmMod& cm_mod, const Array& Ag, const Array& Dg ) +void set_bc_cmm(ComMod& com_mod, const CmMod& cm_mod, const Array& Ag, const Array& Dg, const Array& Do) { using namespace consts; @@ -571,7 +571,7 @@ void set_bc_cmm(ComMod& com_mod, const CmMod& cm_mod, const Array& Ag, c auto& bc = eq.bc[iBc]; if (!utils::btest(bc.bType,iBC_CMM)) { - continue; + continue; } int iFa = bc.iFa; @@ -581,11 +581,11 @@ void set_bc_cmm(ComMod& com_mod, const CmMod& cm_mod, const Array& Ag, c throw std::runtime_error("[set_bc_cmm] CMM equation is formulated for tetrahedral elements (volume) and triangular (surface) elements"); } - set_bc_cmm_l(com_mod, cm_mod, com_mod.msh[iM].fa[iFa], Ag, Dg); + set_bc_cmm_l(com_mod, cm_mod, com_mod.msh[iM].fa[iFa], Ag, Dg, Do); } } -void set_bc_cmm_l(ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, const Array& Ag, const Array& Dg ) +void set_bc_cmm_l(ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, const Array& Ag, const Array& Dg, const Array& Do) { using namespace consts; @@ -637,7 +637,7 @@ void set_bc_cmm_l(ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, con vwp = vwp / 3.0; // Add CMM BCs contributions to the LHS/RHS - cmm::cmm_b(com_mod, lFa, e, al, dl, xl, bfl, pSl, vwp, ptr); + cmm::cmm_b(com_mod, lFa, e, al, dl, xl, bfl, pSl, vwp, ptr, Do); } } @@ -645,7 +645,7 @@ void set_bc_cmm_l(ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, con /// @brief Coupled BC quantities are computed here. /// Reproduces the Fortran 'SETBCCPL()' subrotutine. // -void set_bc_cpl(ComMod& com_mod, CmMod& cm_mod, Array& Yn, const Array& Yo, const Array& Ao, const Array& Do) +void set_bc_cpl(ComMod& com_mod, CmMod& cm_mod, const Array& An, Array& Yn, const Array& Dn, const Array& Yo, const Array& Ao, const Array& Do) { static double absTol = 1.E-8, relTol = 1.E-5; @@ -668,7 +668,7 @@ void set_bc_cpl(ComMod& com_mod, CmMod& cm_mod, Array& Yn, const Array& Yn, const Array sA(com_mod.tnNo); sA = 1.0; - double area = all_fun::integ(com_mod, cm_mod, lFa, sA); - baf_ini_ns::bc_ini(com_mod, cm_mod, eq.bc[iBc], lFa); + double area = all_fun::integ(com_mod, cm_mod, lFa, sA, false, consts::MechanicalConfigurationType::reference, nullptr, &Do); + baf_ini_ns::bc_ini(com_mod, cm_mod, eq.bc[iBc], lFa, Do); int ptr = bc.cplBCptr; @@ -719,15 +719,15 @@ void set_bc_cpl(ComMod& com_mod, CmMod& cm_mod, Array& Yn, const Array& Yg, const Array& Dg) +void set_bc_dir_w(ComMod& com_mod, const Array& Yg, const Array& Dg, const Array& Do) { using namespace consts; @@ -1057,13 +1057,13 @@ void set_bc_dir_w(ComMod& com_mod, const Array& Yg, const Array& if (!bc.weakDir) { continue; } - set_bc_dir_wl(com_mod, bc, com_mod.msh[iM], com_mod.msh[iM].fa[iFa], Yg, Dg); + set_bc_dir_wl(com_mod, bc, com_mod.msh[iM], com_mod.msh[iM].fa[iFa], Yg, Dg, Do); } } /// @brief Reproduces Fortran 'SETBCDIRWL'. // -void set_bc_dir_wl(ComMod& com_mod, const bcType& lBc, const mshType& lM, const faceType& lFa, const Array& Yg, const Array& Dg) +void set_bc_dir_wl(ComMod& com_mod, const bcType& lBc, const mshType& lM, const faceType& lFa, const Array& Yg, const Array& Dg, const Array& Do) { using namespace consts; @@ -1251,7 +1251,7 @@ void set_bc_dir_wl(ComMod& com_mod, const bcType& lBc, const mshType& lM, const for (int g = 0; g < lFa.nG; g++) { Vector nV(nsd); auto Nx = lFa.Nx.slice(g); - nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, eNoNb, Nx, nV); + nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, eNoNb, Nx, nV, consts::MechanicalConfigurationType::reference, nullptr, &Do); double Jac = sqrt(utils::norm(nV)); nV = nV / Jac; double w = lFa.w(g) * Jac; @@ -1292,7 +1292,7 @@ void set_bc_dir_wl(ComMod& com_mod, const bcType& lBc, const mshType& lM, const /// @brief Set outlet BCs. // -void set_bc_neu(ComMod& com_mod, const CmMod& cm_mod, const Array& Yg, const Array& Dg, Array& Yn) +void set_bc_neu(ComMod& com_mod, const CmMod& cm_mod, const Array& Yg, const Array& Dg, Array& Yn, const Array& Do) { using namespace consts; @@ -1324,17 +1324,17 @@ void set_bc_neu(ComMod& com_mod, const CmMod& cm_mod, const Array& Yg, c dmsg << "iFa: " << iFa+1; dmsg << "name: " << com_mod.msh[iM].fa[iFa].name; #endif - set_bc_neu_l(com_mod, cm_mod, bc, com_mod.msh[iM].fa[iFa], Yg, Dg, Yn); + set_bc_neu_l(com_mod, cm_mod, bc, com_mod.msh[iM].fa[iFa], Yg, Dg, Yn, Do); - } else if (utils::btest(bc.bType,iBC_trac)) { - set_bc_trac_l(com_mod, cm_mod, bc, com_mod.msh[iM].fa[iFa]); + } else if (utils::btest(bc.bType,iBC_trac)) { + set_bc_trac_l(com_mod, cm_mod, bc, com_mod.msh[iM].fa[iFa], Do); } } } /// @brief Set Neumann BC // -void set_bc_neu_l(ComMod& com_mod, const CmMod& cm_mod, const bcType& lBc, const faceType& lFa, const Array& Yg, const Array& Dg, Array& Yn) +void set_bc_neu_l(ComMod& com_mod, const CmMod& cm_mod, const bcType& lBc, const faceType& lFa, const Array& Yg, const Array& Dg, Array& Yn, const Array& Do) { using namespace consts; @@ -1424,10 +1424,10 @@ void set_bc_neu_l(ComMod& com_mod, const CmMod& cm_mod, const bcType& lBc, const // Add Neumann BCs contribution to the residual (and tangent if flwP) // if (lBc.flwP) { - eq_assem::b_neu_folw_p(com_mod, lBc, lFa, hg, Dg); + eq_assem::b_neu_folw_p(com_mod, lBc, lFa, hg, Dg, Do); } else { - eq_assem::b_assem_neu_bc(com_mod, lFa, hg, Yg); + eq_assem::b_assem_neu_bc(com_mod, lFa, hg, Yg, Do); } @@ -1437,19 +1437,19 @@ void set_bc_neu_l(ComMod& com_mod, const CmMod& cm_mod, const bcType& lBc, const // a follower pressure load (struct/ustruct) or a moving mesh (FSI) if (utils::btest(lBc.bType, iBC_res)) { if (lBc.flwP || com_mod.mvMsh) { - eq_assem::fsi_ls_upd(com_mod, lBc, lFa); + eq_assem::fsi_ls_upd(com_mod, lBc, lFa, Dg, Do); } } // Now treat Robin BC (stiffness and damping) here if (lBc.robin_bc.is_initialized()) { - set_bc_rbnl(com_mod, lFa, lBc.robin_bc, Yg, Dg); + set_bc_rbnl(com_mod, lFa, lBc.robin_bc, Yg, Dg, Do); } } /// @brief Set Robin BC contribution to residual and tangent // void set_bc_rbnl(ComMod& com_mod, const faceType& lFa, const RobinBoundaryCondition& robin_bc, - const Array& Yg, const Array& Dg) + const Array& Yg, const Array& Dg, const Array& Do) { using namespace consts; @@ -1504,7 +1504,7 @@ void set_bc_rbnl(ComMod& com_mod, const faceType& lFa, const RobinBoundaryCondit for (int g = 0; g < lFa.nG; g++) { Vector nV(nsd); auto Nx = lFa.Nx.slice(g); - nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, eNoN, Nx, nV); + nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, eNoN, Nx, nV, consts::MechanicalConfigurationType::reference, nullptr, &Do); double Jac = sqrt(utils::norm(nV)); nV = nV / Jac; double w = lFa.w(g) * Jac; @@ -1698,12 +1698,12 @@ void set_bc_rbnl(ComMod& com_mod, const faceType& lFa, const RobinBoundaryCondit /// @brief Set Traction BC // -void set_bc_trac_l(ComMod& com_mod, const CmMod& cm_mod, const bcType& lBc, const faceType& lFa) +void set_bc_trac_l(ComMod& com_mod, const CmMod& cm_mod, const bcType& lBc, const faceType& lFa, const Array& Do) { using namespace consts; - #define n_debug_set_bc_trac_l - #ifdef debug_set_bc_trac_l + #define n_debug_set_bc_trac_l + #ifdef debug_set_bc_trac_l DebugMsg dmsg(__func__, com_mod.cm.idcm()); dmsg.banner(); #endif @@ -1784,7 +1784,7 @@ void set_bc_trac_l(ComMod& com_mod, const CmMod& cm_mod, const bcType& lBc, cons for (int g = 0; g < lFa.nG; g++) { Vector nV(nsd); auto Nx = lFa.Nx.slice(g); - nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, eNoN, Nx, nV); + nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, eNoN, Nx, nV, consts::MechanicalConfigurationType::reference, nullptr, &Do); double Jac = sqrt(utils::norm(nV)); double w = lFa.w(g)*Jac; N = lFa.N.col(g); diff --git a/Code/Source/solver/set_bc.h b/Code/Source/solver/set_bc.h index 596925b05..65fc9ea94 100644 --- a/Code/Source/solver/set_bc.h +++ b/Code/Source/solver/set_bc.h @@ -12,33 +12,33 @@ namespace set_bc { -void calc_der_cpl_bc(ComMod& com_mod, const CmMod& cm_mod, Array& Yn, const Array& Yo); +void calc_der_cpl_bc(ComMod& com_mod, const CmMod& cm_mod, const Array& An, Array& Yn, const Array& Dn, const Array& Yo, const Array& Ao, const Array& Do); void cplBC_Integ_X(ComMod& com_mod, const CmMod& cm_mod, const bool RCRflag); void genBC_Integ_X(ComMod& com_mod, const CmMod& cm_mod, const std::string& genFlag); -void rcr_init(ComMod& com_mod, const CmMod& cm_mod, const Array& Yo); +void rcr_init(ComMod& com_mod, const CmMod& cm_mod, const Array& Ao, const Array& Do, const Array& Yo); void RCR_Integ_X(ComMod& com_mod, const CmMod& cm_mod, int istat); -void set_bc_cmm(ComMod& com_mod, const CmMod& cm_mod, const Array& Ag, const Array& Dg); -void set_bc_cmm_l(ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, const Array& Ag, const Array& Dg ); +void set_bc_cmm(ComMod& com_mod, const CmMod& cm_mod, const Array& Ag, const Array& Dg, const Array& Do); +void set_bc_cmm_l(ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, const Array& Ag, const Array& Dg, const Array& Do); -void set_bc_cpl(ComMod& com_mod, CmMod& cm_mod, Array& Yn, const Array& Yo, const Array& Ao, const Array& Do); +void set_bc_cpl(ComMod& com_mod, CmMod& cm_mod, const Array& An, Array& Yn, const Array& Dn, const Array& Yo, const Array& Ao, const Array& Do); void set_bc_dir(ComMod& com_mod, Array& lA, Array& lY, Array& lD, const Array& Yo, const Array& Ao, const Array& Do); void set_bc_dir_l(ComMod& com_mod, const bcType& lBc, const faceType& lFa, Array& lA, Array& lY, int lDof); -void set_bc_dir_w(ComMod& com_mod, const Array& Yg, const Array& Dg); -void set_bc_dir_wl(ComMod& com_mod, const bcType& lBc, const mshType& lM, const faceType& lFa, const Array& Yg, const Array& Dg); +void set_bc_dir_w(ComMod& com_mod, const Array& Yg, const Array& Dg, const Array& Do); +void set_bc_dir_wl(ComMod& com_mod, const bcType& lBc, const mshType& lM, const faceType& lFa, const Array& Yg, const Array& Dg, const Array& Do); -void set_bc_neu(ComMod& com_mod, const CmMod& cm_mod, const Array& Yg, const Array& Dg, Array& Yn); -void set_bc_neu_l(ComMod& com_mod, const CmMod& cm_mod, const bcType& lBc, const faceType& lFa, const Array& Yg, const Array& Dg, Array& Yn); +void set_bc_neu(ComMod& com_mod, const CmMod& cm_mod, const Array& Yg, const Array& Dg, Array& Yn, const Array& Do); +void set_bc_neu_l(ComMod& com_mod, const CmMod& cm_mod, const bcType& lBc, const faceType& lFa, const Array& Yg, const Array& Dg, Array& Yn, const Array& Do); void set_bc_rbnl(ComMod& com_mod, const faceType& lFa, const RobinBoundaryCondition& robin_bc, - const Array& Yg, const Array& Dg); + const Array& Yg, const Array& Dg, const Array& Do); -void set_bc_trac_l(ComMod& com_mod, const CmMod& cm_mod, const bcType& lBc, const faceType& lFa); +void set_bc_trac_l(ComMod& com_mod, const CmMod& cm_mod, const bcType& lBc, const faceType& lFa, const Array& Do); void set_bc_undef_neu(ComMod& com_mod); diff --git a/Code/Source/solver/uris.cpp b/Code/Source/solver/uris.cpp index 607658e4c..476ca2c4f 100644 --- a/Code/Source/solver/uris.cpp +++ b/Code/Source/solver/uris.cpp @@ -19,7 +19,7 @@ namespace uris { /// @brief This subroutine computes the mean pressure and flux on the /// immersed surface -void uris_meanp(ComMod& com_mod, CmMod& cm_mod, const int iUris, Array& Yn) { +void uris_meanp(ComMod& com_mod, CmMod& cm_mod, const int iUris, const Array& Dn, Array& Yn, const Array& Do) { #define n_debug_uris_meanp #ifdef debug_uris_meanp DebugMsg dmsg(__func__, com_mod.cm.idcm()); @@ -68,7 +68,7 @@ void uris_meanp(ComMod& com_mod, CmMod& cm_mod, const int iUris, Array& } for (int iM = 0; iM < com_mod.nMsh; iM++) { - volU += all_fun::integ(com_mod, cm_mod, iM, sUPS); + volU += all_fun::integ(com_mod, cm_mod, iM, sUPS, &Do); } @@ -84,7 +84,7 @@ void uris_meanp(ComMod& com_mod, CmMod& cm_mod, const int iUris, Array& } for (int iM = 0; iM < com_mod.nMsh; iM++) { - volD += all_fun::integ(com_mod, cm_mod, iM, sDST); + volD += all_fun::integ(com_mod, cm_mod, iM, sDST, &Do); } // Print volume messages. @@ -106,7 +106,7 @@ void uris_meanp(ComMod& com_mod, CmMod& cm_mod, const int iUris, Array& tmpV(0,j) = Yn(s,j)*sUPS(j); } for (int iM = 0; iM < com_mod.nMsh; iM++) { - meanPU += all_fun::integ(com_mod, cm_mod, iM, tmpV); + meanPU += all_fun::integ(com_mod, cm_mod, iM, tmpV, &Do); } meanPU = meanPU / volU; @@ -114,7 +114,7 @@ void uris_meanp(ComMod& com_mod, CmMod& cm_mod, const int iUris, Array& tmpV(0,j) = Yn(s,j)*sDST(j); } for (int iM = 0; iM < com_mod.nMsh; iM++) { - meanPD += all_fun::integ(com_mod, cm_mod,iM, tmpV); + meanPD += all_fun::integ(com_mod, cm_mod,iM, tmpV, &Do); } meanPD = meanPD / volD; @@ -151,7 +151,7 @@ void uris_meanp(ComMod& com_mod, CmMod& cm_mod, const int iUris, Array& /// @brief This subroutine computes the mean velocity in the fluid elements /// near the immersed surface -void uris_meanv(ComMod& com_mod, CmMod& cm_mod, const int iUris, Array& Yn) { +void uris_meanv(ComMod& com_mod, CmMod& cm_mod, const int iUris, const Array& Dn, Array& Yn, const Array& Do) { #define n_debug_uris_meanv #ifdef debug_uris_meanv DebugMsg dmsg(__func__, com_mod.cm.idcm()); @@ -193,7 +193,7 @@ void uris_meanv(ComMod& com_mod, CmMod& cm_mod, const int iUris, Array& } for (int iM = 0; iM < com_mod.nMsh; iM++) { - volI += all_fun::integ(com_mod, cm_mod, iM, sImm); + volI += all_fun::integ(com_mod, cm_mod, iM, sImm, &Do); } if (cm.mas(cm_mod)) { std::cout << "volume inside " << volI << " for: " << uris_obj.name << std::endl; @@ -219,7 +219,7 @@ void uris_meanv(ComMod& com_mod, CmMod& cm_mod, const int iUris, Array& double meanV = 0.0; for (int iM = 0; iM < com_mod.nMsh; iM++) { - meanV += all_fun::integ(com_mod, cm_mod, iM, tmpVNrm)/volI; + meanV += all_fun::integ(com_mod, cm_mod, iM, tmpVNrm, &Do)/volI; } if (cm.mas(cm_mod)) { diff --git a/Code/Source/solver/uris.h b/Code/Source/solver/uris.h index 46fd693f4..eb4314182 100644 --- a/Code/Source/solver/uris.h +++ b/Code/Source/solver/uris.h @@ -9,9 +9,9 @@ namespace uris { -void uris_meanp(ComMod& com_mod, CmMod& cm_mod, const int iUris, Array& Yn); // done +void uris_meanp(ComMod& com_mod, CmMod& cm_mod, const int iUris, const Array& Dn, Array& Yn, const Array& Do); // done -void uris_meanv(ComMod& com_mod, CmMod& cm_mod, const int iUris, Array& Yn); // done +void uris_meanv(ComMod& com_mod, CmMod& cm_mod, const int iUris, const Array& Dn, Array& Yn, const Array& Do); // done void uris_update_disp(ComMod& com_mod, CmMod& cm_mod, const Array& Do); From 316d6da4135902174e01845834a1f1b9db06b175 Mon Sep 17 00:00:00 2001 From: Shiyi Chen Date: Thu, 13 Nov 2025 16:30:00 +0000 Subject: [PATCH 16/33] Fix Do/Dn displacement parameter threading for moving mesh simulations This commit fixes systematic issues with displacement parameter passing throughout the solver: 1. Corrected parameter confusion in set_bc.cpp where An/Ao were incorrectly used instead of Dn/Do 2. Replaced nullptr with proper Dn/Do parameters in 14 integ() calls across ris.cpp, txt.cpp, baf_ini.cpp, and set_bc.cpp 3. Fixed critical bug in txt.cpp:520 where missing pFlag parameter caused &Do to be misinterpreted as boolean 4. Enhanced error messages in all_fun.cpp to identify exact failure locations These fixes resolve 12 test failures in moving mesh simulations (genBC and RIS tests). --- Code/Source/solver/all_fun.cpp | 4 ++-- Code/Source/solver/baf_ini.cpp | 6 +++--- Code/Source/solver/initialize.cpp | 2 +- Code/Source/solver/main.cpp | 2 +- Code/Source/solver/ris.cpp | 10 +++++----- Code/Source/solver/set_bc.cpp | 24 ++++++++++++------------ Code/Source/solver/txt.cpp | 26 +++++++++++++------------- Code/Source/solver/txt.h | 10 +++++----- 8 files changed, 42 insertions(+), 42 deletions(-) diff --git a/Code/Source/solver/all_fun.cpp b/Code/Source/solver/all_fun.cpp index 0de99c898..bef711ea3 100644 --- a/Code/Source/solver/all_fun.cpp +++ b/Code/Source/solver/all_fun.cpp @@ -368,7 +368,7 @@ double integ(const ComMod& com_mod, const CmMod& cm_mod, int iM, const Array center(3); for (int i = 0; i < nsd; i++) { - center(i) = all_fun::integ(com_mod, cm_mod, lFa, com_mod.x, i, std::nullopt, false, consts::MechanicalConfigurationType::reference, nullptr, &Do) / lFa.area; + center(i) = all_fun::integ(com_mod, cm_mod, lFa, com_mod.x, i, std::nullopt, false, consts::MechanicalConfigurationType::reference, &Do, &Do) / lFa.area; } // gNodes is one if a node located on the boundary (beside iFa) @@ -396,7 +396,7 @@ void bc_ini(const ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, faceType& l // double tmp = 1.0; if (btest(lBc.bType, enum_int(BoundaryConditionType::bType_flx))) { - tmp = all_fun::integ(com_mod, cm_mod, lFa, s, false, consts::MechanicalConfigurationType::reference, nullptr, &Do); + tmp = all_fun::integ(com_mod, cm_mod, lFa, s, false, consts::MechanicalConfigurationType::reference, &Do, &Do); if (is_zero(tmp)) { tmp = 1.0; throw std::runtime_error("Face '" + lFa.name + "' used for a BC has no non-zero node."); @@ -436,7 +436,7 @@ void face_ini(Simulation* simulation, mshType& lM, faceType& lFa, Array& // Vector sA(com_mod.tnNo); sA = 1.0; - double area = all_fun::integ(com_mod, cm_mod, lFa, sA, false, consts::MechanicalConfigurationType::reference, nullptr, &Do); + double area = all_fun::integ(com_mod, cm_mod, lFa, sA, false, consts::MechanicalConfigurationType::reference, &Do, &Do); #ifdef debug_face_ini dmsg << "Face '" << lFa.name << "' area: " << area; #endif diff --git a/Code/Source/solver/initialize.cpp b/Code/Source/solver/initialize.cpp index 7f61a82bb..4eab0af0a 100644 --- a/Code/Source/solver/initialize.cpp +++ b/Code/Source/solver/initialize.cpp @@ -833,7 +833,7 @@ void initialize(Simulation* simulation, Vector& timeP) set_bc::set_bc_dir(com_mod, Ao, Yo, Do, Yo, Ao, Do); // Preparing TXT files (pass local Ao, Do, and Yo since An, Dn, and Yn haven't been created in Integrator yet) - txt_ns::txt(simulation, true, Ao, Do, Yo); + txt_ns::txt(simulation, true, Ao, Do, Yo, Do); // Printing the first line and initializing timeP int co = 1; diff --git a/Code/Source/solver/main.cpp b/Code/Source/solver/main.cpp index 1a3847c8d..18957eb42 100644 --- a/Code/Source/solver/main.cpp +++ b/Code/Source/solver/main.cpp @@ -387,7 +387,7 @@ void iterate_solution(Simulation* simulation) dmsg << "Saving the TXT files containing ECGs ..." << std::endl; #endif - txt_ns::txt(simulation, false, An, Dn, Yn); + txt_ns::txt(simulation, false, An, Dn, Yn, Do); // If remeshing is required then save current solution. // diff --git a/Code/Source/solver/ris.cpp b/Code/Source/solver/ris.cpp index b653bdabc..40fb932a5 100644 --- a/Code/Source/solver/ris.cpp +++ b/Code/Source/solver/ris.cpp @@ -56,7 +56,7 @@ void ris_meanq(ComMod& com_mod, CmMod& cm_mod, Array& An, Array& int iM = RIS.lst(i,0,iProj); int iFa = RIS.lst(i,1,iProj); double tmp = msh[iM].fa[iFa].area; - RIS.meanP(iProj,i) = all_fun::integ(com_mod, cm_mod, msh[iM].fa[iFa], tmpV, 0, std::nullopt, false, consts::MechanicalConfigurationType::reference, nullptr, &Do)/tmp; + RIS.meanP(iProj,i) = all_fun::integ(com_mod, cm_mod, msh[iM].fa[iFa], tmpV, 0, std::nullopt, false, consts::MechanicalConfigurationType::reference, &Dn, &Do)/tmp; } } @@ -74,7 +74,7 @@ void ris_meanq(ComMod& com_mod, CmMod& cm_mod, Array& An, Array& } int iM = RIS.lst(0,0,iProj); int iFa = RIS.lst(0,1,iProj); - RIS.meanFl(iProj) = all_fun::integ(com_mod, cm_mod, msh[iM].fa[iFa], tmpV, 0, m-1, false, consts::MechanicalConfigurationType::reference, nullptr, &Do); + RIS.meanFl(iProj) = all_fun::integ(com_mod, cm_mod, msh[iM].fa[iFa], tmpV, 0, m-1, false, consts::MechanicalConfigurationType::reference, &Dn, &Do); if (cm.mas(cm_mod)) { std::cout << "For RIS projection: " << iProj << std::endl; @@ -456,8 +456,8 @@ void ris0d_status(ComMod& com_mod, CmMod& cm_mod, Array& An, Array& An, Array& else { throw std::runtime_error("[calc_der_cpl_bc] Invalid physics type for 0D coupling"); } - cplBC.fa[ptr].Qo = all_fun::integ(com_mod, cm_mod, fa, Yo, 0, nsd-1, false, cfg_o, &Ao, &Do); - cplBC.fa[ptr].Qn = all_fun::integ(com_mod, cm_mod, fa, Yn, 0, nsd-1, false, cfg_n, &An, &Dn); + cplBC.fa[ptr].Qo = all_fun::integ(com_mod, cm_mod, fa, Yo, 0, nsd-1, false, cfg_o, &Do, &Do); + cplBC.fa[ptr].Qn = all_fun::integ(com_mod, cm_mod, fa, Yn, 0, nsd-1, false, cfg_n, &Dn, &Do); cplBC.fa[ptr].Po = 0.0; cplBC.fa[ptr].Pn = 0.0; #ifdef debug_calc_der_cpl_bc @@ -124,8 +124,8 @@ void calc_der_cpl_bc(ComMod& com_mod, const CmMod& cm_mod, const Array& // Compute avg pressures at 3D Dirichlet boundaries at timesteps n and n+1 else if (utils::btest(bc.bType, iBC_Dir)) { double area = fa.area; - cplBC.fa[ptr].Po = all_fun::integ(com_mod, cm_mod, fa, Yo, nsd, std::nullopt, false, MechanicalConfigurationType::reference, &Ao, &Do) / area; - cplBC.fa[ptr].Pn = all_fun::integ(com_mod, cm_mod, fa, Yn, nsd, std::nullopt, false, MechanicalConfigurationType::reference, &An, &Dn) / area; + cplBC.fa[ptr].Po = all_fun::integ(com_mod, cm_mod, fa, Yo, nsd, std::nullopt, false, MechanicalConfigurationType::reference, &Do, &Do) / area; + cplBC.fa[ptr].Pn = all_fun::integ(com_mod, cm_mod, fa, Yn, nsd, std::nullopt, false, MechanicalConfigurationType::reference, &Dn, &Do) / area; cplBC.fa[ptr].Qo = 0.0; cplBC.fa[ptr].Qn = 0.0; #ifdef debug_calc_der_cpl_bc @@ -548,8 +548,8 @@ void rcr_init(ComMod& com_mod, const CmMod& cm_mod, const Array& Ao, con if (cplBC.initRCR) { auto& fa = com_mod.msh[iM].fa[iFa]; double area = fa.area; - double Qo = all_fun::integ(com_mod, cm_mod, fa, Yo, 0, nsd-1, false, MechanicalConfigurationType::reference, &Ao, &Do); - double Po = all_fun::integ(com_mod, cm_mod, fa, Yo, nsd, std::nullopt, false, MechanicalConfigurationType::reference, &Ao, &Do) / area; + double Qo = all_fun::integ(com_mod, cm_mod, fa, Yo, 0, nsd-1, false, MechanicalConfigurationType::reference, &Do, &Do); + double Po = all_fun::integ(com_mod, cm_mod, fa, Yo, nsd, std::nullopt, false, MechanicalConfigurationType::reference, &Do, &Do) / area; cplBC.xo[ptr] = Po - (Qo * cplBC.fa[ptr].RCR.Rp); } else { cplBC.xo[ptr] = cplBC.fa[ptr].RCR.Xo; @@ -684,7 +684,7 @@ void set_bc_cpl(ComMod& com_mod, CmMod& cm_mod, const Array& An, Array sA(com_mod.tnNo); sA = 1.0; - double area = all_fun::integ(com_mod, cm_mod, lFa, sA, false, consts::MechanicalConfigurationType::reference, nullptr, &Do); + double area = all_fun::integ(com_mod, cm_mod, lFa, sA, false, consts::MechanicalConfigurationType::reference, &Do, &Do); baf_ini_ns::bc_ini(com_mod, cm_mod, eq.bc[iBc], lFa, Do); int ptr = bc.cplBCptr; @@ -719,15 +719,15 @@ void set_bc_cpl(ComMod& com_mod, CmMod& cm_mod, const Array& An, Array& An, Array& Dn, Array& Yn) +void txt(Simulation* simulation, const bool init_write, Array& An, Array& Dn, Array& Yn, const Array& Do) { using namespace consts; using namespace utils; @@ -367,10 +367,10 @@ void txt(Simulation* simulation, const bool init_write, Array& An, Array } else { if (output_options.boundary_integral) { - write_boundary_integral_data(com_mod, cm_mod, eq, l, boundary_file_name, tmpV, div, pflag); + write_boundary_integral_data(com_mod, cm_mod, eq, l, boundary_file_name, tmpV, div, pflag, Do); } if (output_options.volume_integral) { - write_volume_integral_data(com_mod, cm_mod, eq, l, volume_file_name, tmpV, div, pflag); + write_volume_integral_data(com_mod, cm_mod, eq, l, volume_file_name, tmpV, div, pflag, Do); } } } @@ -407,8 +407,8 @@ void txt(Simulation* simulation, const bool init_write, Array& An, Array /// /// NOTE: Be carefu of a potential indexing problem here because 'm' is a length and not an index. // -void write_boundary_integral_data(const ComMod& com_mod, CmMod& cm_mod, const eqType& lEq, const int m, - const std::string file_name, const Array& tmpV, const bool div, const bool pFlag) +void write_boundary_integral_data(const ComMod& com_mod, CmMod& cm_mod, const eqType& lEq, const int m, + const std::string file_name, const Array& tmpV, const bool div, const bool pFlag, const Array& Do) { #define n_debug_write_boundary_integral_data #ifdef debug_write_boundary_integral_data @@ -451,17 +451,17 @@ void write_boundary_integral_data(const ComMod& com_mod, CmMod& cm_mod, const eq if (m == 1) { if (div) { tmp = fa.area; - tmp = all_fun::integ(com_mod, cm_mod, fa, tmpV, 0) / tmp; + tmp = all_fun::integ(com_mod, cm_mod, fa, tmpV, 0, std::nullopt, false, consts::MechanicalConfigurationType::reference, &Do, &Do) / tmp; } else { if (pFlag && lTH) { - tmp = all_fun::integ(com_mod, cm_mod, fa, tmpV, 0, true); + tmp = all_fun::integ(com_mod, cm_mod, fa, tmpV, 0, std::nullopt, true, consts::MechanicalConfigurationType::reference, &Do, &Do); } else { - tmp = all_fun::integ(com_mod, cm_mod, fa, tmpV, 0); + tmp = all_fun::integ(com_mod, cm_mod, fa, tmpV, 0, std::nullopt, false, consts::MechanicalConfigurationType::reference, &Do, &Do); } } } else if (m == nsd) { - tmp = all_fun::integ(com_mod, cm_mod, fa, tmpV, 0, m-1); + tmp = all_fun::integ(com_mod, cm_mod, fa, tmpV, 0, m-1, false, consts::MechanicalConfigurationType::reference, &Do, &Do); } else { throw std::runtime_error("WTXT only accepts 1 and nsd"); } @@ -482,8 +482,8 @@ void write_boundary_integral_data(const ComMod& com_mod, CmMod& cm_mod, const eq /// /// NOTE: Be carefu of a potential indexing problem here because 'm' is a length and not an index. // -void write_volume_integral_data(const ComMod& com_mod, CmMod& cm_mod, const eqType& lEq, const int m, - const std::string file_name, const Array& tmpV, const bool div, const bool pFlag) +void write_volume_integral_data(const ComMod& com_mod, CmMod& cm_mod, const eqType& lEq, const int m, + const std::string file_name, const Array& tmpV, const bool div, const bool pFlag, const Array& Do) { #define n_debug_write_volume_integral_data #ifdef debug_write_volume_integral_data @@ -517,9 +517,9 @@ void write_volume_integral_data(const ComMod& com_mod, CmMod& cm_mod, const eqTy if (div) { tmp = dmn.v; - tmp = all_fun::integ(com_mod, cm_mod, dmn.Id, tmpV, 0, m-1) / tmp; + tmp = all_fun::integ(com_mod, cm_mod, dmn.Id, tmpV, 0, m-1, pFlag, &Do) / tmp; } else { - tmp = all_fun::integ(com_mod, cm_mod, dmn.Id, tmpV, 0, m-1, pFlag); + tmp = all_fun::integ(com_mod, cm_mod, dmn.Id, tmpV, 0, m-1, pFlag, &Do); } if (com_mod.cm.mas(cm_mod)) { diff --git a/Code/Source/solver/txt.h b/Code/Source/solver/txt.h index 70a9ed9e0..8b4c77207 100644 --- a/Code/Source/solver/txt.h +++ b/Code/Source/solver/txt.h @@ -16,13 +16,13 @@ void create_boundary_integral_file(const ComMod& com_mod, CmMod& cm_mod, const e void create_volume_integral_file(const ComMod& com_mod, CmMod& cm_mod, const eqType& lEq, const std::string& file_name); -void txt(Simulation* simulation, const bool flag, Array& An, Array& Dn, Array& Yn); +void txt(Simulation* simulation, const bool flag, Array& An, Array& Dn, Array& Yn, const Array& Do); -void write_boundary_integral_data(const ComMod& com_mod, CmMod& cm_mod, const eqType& lEq, const int m, - const std::string file_name, const Array& tmpV, const bool div, const bool pFlag); +void write_boundary_integral_data(const ComMod& com_mod, CmMod& cm_mod, const eqType& lEq, const int m, + const std::string file_name, const Array& tmpV, const bool div, const bool pFlag, const Array& Do); -void write_volume_integral_data(const ComMod& com_mod, CmMod& cm_mod, const eqType& lEq, const int m, - const std::string file_name, const Array& tmpV, const bool div, const bool pFlag); +void write_volume_integral_data(const ComMod& com_mod, CmMod& cm_mod, const eqType& lEq, const int m, + const std::string file_name, const Array& tmpV, const bool div, const bool pFlag, const Array& Do); }; From 65d3eecc0b4535d43c9992e47d2140366e8e5c5a Mon Sep 17 00:00:00 2001 From: shiyi Date: Tue, 6 Jan 2026 11:22:53 +0000 Subject: [PATCH 17/33] address mrp089's comments on renaming methods and remove redundant variables --- Code/Source/solver/ComMod.h | 2 - Code/Source/solver/Integrator.cpp | 65 +++++++++++++------------------ Code/Source/solver/Integrator.h | 12 +++--- Code/Source/solver/main.cpp | 2 +- Code/Source/solver/nn.cpp | 4 +- 5 files changed, 36 insertions(+), 49 deletions(-) diff --git a/Code/Source/solver/ComMod.h b/Code/Source/solver/ComMod.h index d16a0badb..b3ea3c728 100644 --- a/Code/Source/solver/ComMod.h +++ b/Code/Source/solver/ComMod.h @@ -1742,8 +1742,6 @@ class ComMod { /// @brief RIS mapping array, with global (total) enumeration std::vector grisMapList; - /// @brief Ao, Do, Yo moved to Integrator class (complete ownership transfer) - /// @brief Residual vector Array R; diff --git a/Code/Source/solver/Integrator.cpp b/Code/Source/solver/Integrator.cpp index c4ee89dec..8e677f92b 100644 --- a/Code/Source/solver/Integrator.cpp +++ b/Code/Source/solver/Integrator.cpp @@ -74,10 +74,6 @@ bool Integrator::step() { auto& cm_mod = simulation_->cm_mod; auto& cep_mod = simulation_->get_cep_mod(); - auto& An = An_; // Use member variable - auto& Yn = Yn_; - auto& Dn = Dn_; - int& cTS = com_mod.cTS; int& cEq = com_mod.cEq; @@ -197,7 +193,7 @@ void Integrator::initiator_step() { dmsg << "Initiator step ..." << std::endl; #endif - pici(Ag_, Yg_, Dg_); + initiator(Ag_, Yg_, Dg_); // Debug output Ag_.write("Ag_pic" + istr_); @@ -273,13 +269,11 @@ void Integrator::apply_boundary_conditions() { dmsg << "Apply boundary conditions ..." << std::endl; #endif - auto& Yn = Yn_; - Yg_.write("Yg_vor_neu" + istr_); Dg_.write("Dg_vor_neu" + istr_); // Apply Neumman or Traction boundary conditions - set_bc::set_bc_neu(com_mod, cm_mod, Yg_, Dg_, Yn, Do_); + set_bc::set_bc_neu(com_mod, cm_mod, Yg_, Dg_, Yn_, Do_); // Apply CMM BC conditions if (!com_mod.cmmInit) { @@ -294,7 +288,7 @@ void Integrator::apply_boundary_conditions() { } if (com_mod.ris0DFlag) { - ris::ris0d_bc(com_mod, cm_mod, Yg_, Dg_, Yn, Do_); + ris::ris0d_bc(com_mod, cm_mod, Yg_, Dg_, Yn_, Do_); } // Apply contact model and add its contribution to residual @@ -341,10 +335,10 @@ bool Integrator::corrector_and_check_convergence() { dmsg << "Update corrector ..." << std::endl; #endif - picc(); + corrector(); // Debug output - Yn_.write("Yn_picc" + istr_); + Yn_.write("Yn_corrector" + istr_); // Check if all equations converged return std::count_if(com_mod.eq.begin(), com_mod.eq.end(), @@ -526,7 +520,7 @@ void Integrator::predictor() } //------------------------ -// pici +// initiator //------------------------ /// @brief Initiator for Generalized α-Method /// @@ -542,14 +536,14 @@ void Integrator::predictor() /// Yg - velocity /// Dg - displacement /// -void Integrator::pici(Array& Ag, Array& Yg, Array& Dg) +void Integrator::initiator(Array& Ag, Array& Yg, Array& Dg) { using namespace consts; auto& com_mod = simulation_->com_mod; - #define n_debug_pici - #ifdef debug_pici + #define n_debug_initiator + #ifdef debug_initiator DebugMsg dmsg(__func__, com_mod.cm.idcm()); dmsg.banner(); #endif @@ -562,7 +556,7 @@ void Integrator::pici(Array& Ag, Array& Yg, Array& Dg) // [NOTE] Setting gobal variable 'dof'. dof = eq.dof; - #ifdef debug_pici + #ifdef debug_initiator dmsg << "cEq: " << cEq; dmsg << "eq.itr: " << eq.itr; dmsg << "dof: " << dof; @@ -586,7 +580,7 @@ void Integrator::pici(Array& Ag, Array& Yg, Array& Dg) coef(1) = eq.am; coef(2) = 1.0 - eq.af; coef(3) = eq.af; - #ifdef debug_pici + #ifdef debug_initiator dmsg << "s: " << s; dmsg << "e: " << e; dmsg << "coef: " << coef[0] << " " << coef[1] << " " << coef[2] << " " << coef[3]; @@ -632,7 +626,7 @@ void Integrator::pici(Array& Ag, Array& Yg, Array& Dg) } } //------------------------ -// picc +// corrector //------------------------ /// @brief Corrector with convergence check /// @@ -654,15 +648,15 @@ void Integrator::pici(Array& Ag, Array& Yg, Array& Dg) /// eq.pNorm /// \endcode // -void Integrator::picc() +void Integrator::corrector() { using namespace consts; auto& com_mod = simulation_->com_mod; auto& cep_mod = simulation_->get_cep_mod(); - #define n_debug_picc - #ifdef debug_picc + #define n_debug_corrector + #ifdef debug_corrector DebugMsg dmsg(__func__, com_mod.cm.idcm()); dmsg.banner(); #endif @@ -696,7 +690,7 @@ void Integrator::picc() coef[2] = 1.0 / eq.am; coef[3] = eq.af*coef[0]*coef[2]; - #ifdef debug_picc + #ifdef debug_corrector dmsg << "cEq: " << cEq; dmsg << "s: " << s; dmsg << "e: " << e; @@ -750,13 +744,13 @@ void Integrator::picc() } if (std::set{Equation_stokes, Equation_fluid, Equation_ustruct, Equation_FSI}.count(eq.phys) != 0) { - pic_eth(); + corrector_taylor_hood(); } if (eq.phys == Equation_FSI) { int s = com_mod.eq[1].s; int e = com_mod.eq[1].e; - #ifdef debug_picc + #ifdef debug_corrector dmsg << "eq.phys == Equation_FSI "; dmsg << "com_mod.eq[1].sym: " << com_mod.eq[1].sym; dmsg << "s: " << s; @@ -813,9 +807,6 @@ void Integrator::picc() } } - // IB treatment - //if (ibFlag) CALL IB_PICC() - // Computes norms and check for convergence of Newton iterations double eps = std::numeric_limits::epsilon(); @@ -825,14 +816,14 @@ void Integrator::picc() if (utils::is_zero(eq.iNorm)) { eq.iNorm = eq.FSILS.RI.iNorm; - #ifdef debug_picc + #ifdef debug_corrector dmsg << "eq.iNorm: " << eq.iNorm; #endif } if (eq.itr == 1) { eq.pNorm = eq.FSILS.RI.iNorm / eq.iNorm; - #ifdef debug_picc + #ifdef debug_corrector dmsg << "eq.itr: " << eq.itr; dmsg << "eq.pNorm: " << eq.pNorm; #endif @@ -844,7 +835,7 @@ void Integrator::picc() bool l3 = (r1 <= eq.tol*eq.pNorm); bool l4 = (eq.itr >= eq.minItr); - #ifdef debug_picc + #ifdef debug_corrector dmsg << "eq.itr: " << eq.itr; dmsg << "eq.minItr: " << eq.minItr; dmsg << "r1: " << r1; @@ -856,7 +847,7 @@ void Integrator::picc() if (l1 || ((l2 || l3) && l4)) { eq.ok = true; - #ifdef debug_picc + #ifdef debug_corrector dmsg << "eq.ok: " << eq.ok; dmsg << "com_mod.eq[0].ok: " << com_mod.eq[0].ok; dmsg << "com_mod.eq[1].ok: " << com_mod.eq[1].ok; @@ -865,7 +856,7 @@ void Integrator::picc() auto& eqs = com_mod.eq; if (std::count_if(eqs.begin(),eqs.end(),[](eqType& eq){return eq.ok;}) == eqs.size()) { - #ifdef debug_picc + #ifdef debug_corrector dmsg << "all ok"; #endif return; @@ -874,7 +865,7 @@ void Integrator::picc() if (eq.coupled) { cEq = cEq + 1; - #ifdef debug_picc + #ifdef debug_corrector dmsg << "eq " << " coupled "; dmsg << "1st update cEq: " << cEq; #endif @@ -906,14 +897,14 @@ void Integrator::picc() cEq = cEq + 1; } } - #ifdef debug_picc + #ifdef debug_corrector dmsg << "eq " << " coupled "; dmsg << "2nd update cEq: " << cEq; #endif } //------------------------ -// pic_eth +// corrector_taylor_hood //------------------------ /// @brief Pressure correction at edge nodes for Taylor-Hood type element /// @@ -924,7 +915,7 @@ void Integrator::picc() /// /// Modifies: Yn_ /// -void Integrator::pic_eth() +void Integrator::corrector_taylor_hood() { using namespace consts; @@ -1014,7 +1005,7 @@ void Integrator::pic_eth() nn::gnn(eNoNq, nsd, nsd, Nx, xql, Nqx, Jac, ksix); if (utils::is_zero(Jac)) { - throw std::runtime_error("[pic_eth] Jacobian for element " + std::to_string(e) + " is < 0."); + throw std::runtime_error("[corrector_taylor_hood] Jacobian for element " + std::to_string(e) + " is < 0."); } } diff --git a/Code/Source/solver/Integrator.h b/Code/Source/solver/Integrator.h index 64148ee9c..60751209c 100644 --- a/Code/Source/solver/Integrator.h +++ b/Code/Source/solver/Integrator.h @@ -217,7 +217,7 @@ class Integrator { void update_residual_arrays(eqType& eq); /** - * @brief Initiator function for generalized-alpha method (pici) + * @brief Initiator function for generalized-alpha method (initiator) * * Computes solution variables at intermediate time levels using * generalized-alpha parameters (am, af) for time integration. @@ -227,23 +227,23 @@ class Integrator { * @param Yg Solution variable array at generalized-alpha level * @param Dg Integrated variable array at generalized-alpha level */ - void pici(Array& Ag, Array& Yg, Array& Dg); + void initiator(Array& Ag, Array& Yg, Array& Dg); /** - * @brief Corrector function with convergence check (picc) + * @brief Corrector function with convergence check (corrector) * * Updates solution at n+1 time level and checks convergence of Newton * iterations. Also handles equation switching for coupled problems. */ - void picc(); + void corrector(); /** - * @brief Pressure correction for Taylor-Hood elements (pic_eth) + * @brief Pressure correction for Taylor-Hood elements (corrector_taylor_hood) * * Interpolates pressure at edge nodes using reduced basis applied * on element vertices for Taylor-Hood type elements. */ - void pic_eth(); + void corrector_taylor_hood(); }; #endif // INTEGRATOR_H diff --git a/Code/Source/solver/main.cpp b/Code/Source/solver/main.cpp index 58a0ffe97..32b566a91 100644 --- a/Code/Source/solver/main.cpp +++ b/Code/Source/solver/main.cpp @@ -334,7 +334,7 @@ void iterate_solution(Simulation* simulation) iterate_precomputed_time(simulation, integrator.get_An(), integrator.get_Yn(), integrator.get_Ao(), integrator.get_Yo(), integrator.get_Do()); - // Inner loop for Newton iteration - now encapsulated in Integrator class + // Inner loop for Newton iteration // #ifdef debug_iterate_solution dmsg << "Starting Newton iteration via Integrator ..." << std::endl; diff --git a/Code/Source/solver/nn.cpp b/Code/Source/solver/nn.cpp index 76f9510c5..08f5430ae 100644 --- a/Code/Source/solver/nn.cpp +++ b/Code/Source/solver/nn.cpp @@ -633,10 +633,8 @@ void gnnb(const ComMod& com_mod, const faceType& lFa, const int e, const int g, // Add displacement at timestep n+1 if (Dn != nullptr) { lX(i,a) = lX(i,a) + (*Dn)(i,Ac); - } else if (Do != nullptr) { - lX(i,a) = lX(i,a) + (*Do)(i,Ac); // Fallback to Do if Dn not provided } else { - throw std::runtime_error("gnnb: Either Dn or Do parameter required for new_timestep configuration but neither provided"); + throw std::runtime_error("gnnb: Dn required for new_timestep configuration but neither provided"); } } break; From 22459d860b20befab5d2cffca2d1a428abeab2a2 Mon Sep 17 00:00:00 2001 From: shiyi Date: Thu, 8 Jan 2026 08:23:47 -0500 Subject: [PATCH 18/33] remove Do checks and some comments of Ao, Yo, Do --- Code/Source/solver/all_fun.cpp | 6 ------ Code/Source/solver/cep_ion.cpp | 1 - Code/Source/solver/mesh.cpp | 1 - Code/Source/solver/nn.cpp | 6 ------ Code/Source/solver/output.cpp | 1 - Code/Source/solver/remesh.cpp | 2 -- Code/Source/solver/ris.cpp | 4 ---- Code/Source/solver/uris.cpp | 2 -- 8 files changed, 23 deletions(-) diff --git a/Code/Source/solver/all_fun.cpp b/Code/Source/solver/all_fun.cpp index bef711ea3..40ae5e547 100644 --- a/Code/Source/solver/all_fun.cpp +++ b/Code/Source/solver/all_fun.cpp @@ -367,9 +367,6 @@ double integ(const ComMod& com_mod, const CmMod& cm_mod, int iM, const Array& timeP, Array& An, Array& const int nsd = com_mod.nsd; const int cEq = com_mod.cEq; - - // An, Dn, and Yn are now passed as parameters auto& Ad = com_mod.Ad; Array tmpV(maxNSD, com_mod.tnNo); @@ -420,8 +418,6 @@ void ris0d_status(ComMod& com_mod, CmMod& cm_mod, Array& An, Array Date: Fri, 9 Jan 2026 07:24:02 +0000 Subject: [PATCH 19/33] Lump An, Dn, Yn, Ao, Do, Yo into solu_state_vars --- Code/Source/solver/Integrator.cpp | 77 ++++++++++++++++--------------- Code/Source/solver/Integrator.h | 48 ++++++++++--------- 2 files changed, 65 insertions(+), 60 deletions(-) diff --git a/Code/Source/solver/Integrator.cpp b/Code/Source/solver/Integrator.cpp index 8e677f92b..0fde1ef1f 100644 --- a/Code/Source/solver/Integrator.cpp +++ b/Code/Source/solver/Integrator.cpp @@ -26,8 +26,11 @@ using namespace consts; // Integrator Constructor //------------------------ Integrator::Integrator(Simulation* simulation, Array&& Ao, Array&& Do, Array&& Yo) - : simulation_(simulation), newton_count_(0), Ao_(std::move(Ao)), Do_(std::move(Do)), Yo_(std::move(Yo)) + : simulation_(simulation), newton_count_(0) { + solu_state_vars_.Ao = std::move(Ao); + solu_state_vars_.Do = std::move(Do); + solu_state_vars_.Yo = std::move(Yo); initialize_arrays(); } @@ -50,17 +53,17 @@ void Integrator::initialize_arrays() { Ag_.resize(tDof, tnNo); Yg_.resize(tDof, tnNo); Dg_.resize(tDof, tnNo); - An_.resize(tDof, tnNo); - Dn_.resize(tDof, tnNo); - Yn_.resize(tDof, tnNo); + solu_state_vars_.An.resize(tDof, tnNo); + solu_state_vars_.Dn.resize(tDof, tnNo); + solu_state_vars_.Yn.resize(tDof, tnNo); res_.resize(nFacesLS); incL_.resize(nFacesLS); - // Ao_, Do_, Yo_ already initialized via move in constructor + // Ao, Do, Yo already initialized via move in constructor // Initialize new variables from old variables - An_ = Ao_; - Dn_ = Do_; - Yn_ = Yo_; + solu_state_vars_.An = solu_state_vars_.Ao; + solu_state_vars_.Dn = solu_state_vars_.Do; + solu_state_vars_.Yn = solu_state_vars_.Yo; } //------------------------ @@ -104,8 +107,8 @@ bool Integrator::step() { #ifdef debug_integrator_step dmsg << "Set coupled BCs " << std::endl; #endif - set_bc::set_bc_cpl(com_mod, cm_mod, An_, Yn_, Dn_, Yo_, Ao_, Do_); - set_bc::set_bc_dir(com_mod, An_, Yn_, Dn_, Yo_, Ao_, Do_); + set_bc::set_bc_cpl(com_mod, cm_mod, solu_state_vars_.An, solu_state_vars_.Yn, solu_state_vars_.Dn, solu_state_vars_.Yo, solu_state_vars_.Ao, solu_state_vars_.Do); + set_bc::set_bc_dir(com_mod, solu_state_vars_.An, solu_state_vars_.Yn, solu_state_vars_.Dn, solu_state_vars_.Yo, solu_state_vars_.Ao, solu_state_vars_.Do); } // Initiator step for Generalized α-Method (quantities at n+am, n+af). @@ -199,7 +202,7 @@ void Integrator::initiator_step() { Ag_.write("Ag_pic" + istr_); Yg_.write("Yg_pic" + istr_); Dg_.write("Dg_pic" + istr_); - Yn_.write("Yn_pic" + istr_); + solu_state_vars_.Yn.write("solu_state_vars_.Ynpic" + istr_); } //------------------------ @@ -248,7 +251,7 @@ void Integrator::assemble_equations() { #endif for (int iM = 0; iM < com_mod.nMsh; iM++) { - eq_assem::global_eq_assem(com_mod, cep_mod, com_mod.msh[iM], Ag_, Yg_, Dg_, Do_); + eq_assem::global_eq_assem(com_mod, cep_mod, com_mod.msh[iM], Ag_, Yg_, Dg_, solu_state_vars_.Do); } // Debug output @@ -273,22 +276,22 @@ void Integrator::apply_boundary_conditions() { Dg_.write("Dg_vor_neu" + istr_); // Apply Neumman or Traction boundary conditions - set_bc::set_bc_neu(com_mod, cm_mod, Yg_, Dg_, Yn_, Do_); + set_bc::set_bc_neu(com_mod, cm_mod, Yg_, Dg_, solu_state_vars_.Yn, solu_state_vars_.Do); // Apply CMM BC conditions if (!com_mod.cmmInit) { - set_bc::set_bc_cmm(com_mod, cm_mod, Ag_, Dg_, Do_); + set_bc::set_bc_cmm(com_mod, cm_mod, Ag_, Dg_, solu_state_vars_.Do); } // Apply weakly applied Dirichlet BCs - set_bc::set_bc_dir_w(com_mod, Yg_, Dg_, Do_); + set_bc::set_bc_dir_w(com_mod, Yg_, Dg_, solu_state_vars_.Do); if (com_mod.risFlag) { - ris::ris_resbc(com_mod, Yg_, Dg_, Do_); + ris::ris_resbc(com_mod, Yg_, Dg_, solu_state_vars_.Do); } if (com_mod.ris0DFlag) { - ris::ris0d_bc(com_mod, cm_mod, Yg_, Dg_, Yn_, Do_); + ris::ris0d_bc(com_mod, cm_mod, Yg_, Dg_, solu_state_vars_.Yn, solu_state_vars_.Do); } // Apply contact model and add its contribution to residual @@ -338,7 +341,7 @@ bool Integrator::corrector_and_check_convergence() { corrector(); // Debug output - Yn_.write("Yn_corrector" + istr_); + solu_state_vars_.Yn.write("solu_state_vars_.Yncorrector" + istr_); // Check if all equations converged return std::count_if(com_mod.eq.begin(), com_mod.eq.end(), @@ -413,12 +416,12 @@ void Integrator::predictor() // time derivative of displacement auto& Ad = com_mod.Ad; - auto& Ao = Ao_; // Use member variable - auto& An = An_; // Use member variable - auto& Yo = Yo_; // Use member variable - auto& Yn = Yn_; // Use member variable - auto& Do = Do_; // Use member variable - auto& Dn = Dn_; // Use member variable + auto& Ao = solu_state_vars_.Ao; // Use member variable + auto& An = solu_state_vars_.An; // Use member variable + auto& Yo = solu_state_vars_.Yo; // Use member variable + auto& Yn = solu_state_vars_.Yn; // Use member variable + auto& Do = solu_state_vars_.Do; // Use member variable + auto& Dn = solu_state_vars_.Dn; // Use member variable // Prestress initialization if (com_mod.pstEq) { @@ -486,7 +489,7 @@ void Integrator::predictor() // electrophysiology if (eq.phys == Equation_CEP) { - cep_ion::cep_integ(simulation_, iEq, e, Do, Yo_); + cep_ion::cep_integ(simulation_, iEq, e, Do, solu_state_vars_.Yo); } // eqn 86 of Bazilevs 2007 @@ -564,12 +567,12 @@ void Integrator::initiator(Array& Ag, Array& Yg, Array& dmsg << "com_mod.pstEq: " << com_mod.pstEq; #endif - const auto& Ao = Ao_; // Use member variable - const auto& An = An_; // Use member variable - const auto& Do = Do_; // Use member variable - const auto& Dn = Dn_; // Use member variable - const auto& Yo = Yo_; // Use member variable - const auto& Yn = Yn_; // Use member variable + const auto& Ao = solu_state_vars_.Ao; // Use member variable + const auto& An = solu_state_vars_.An; // Use member variable + const auto& Do = solu_state_vars_.Do; // Use member variable + const auto& Dn = solu_state_vars_.Dn; // Use member variable + const auto& Yo = solu_state_vars_.Yo; // Use member variable + const auto& Yn = solu_state_vars_.Yn; // Use member variable for (int i = 0; i < com_mod.nEq; i++) { auto& eq = com_mod.eq[i]; @@ -635,7 +638,7 @@ void Integrator::initiator(Array& Ag, Array& Yg, Array& /// Modifies: /// \code {.cpp} /// com_mod.Ad -/// An_ (member variable) +/// solu_state_vars_.An (member variable) /// com_mod.Dn /// com_mod.Yn /// cep_mod.Xion @@ -671,10 +674,10 @@ void Integrator::corrector() auto& cEq = com_mod.cEq; auto& eq = com_mod.eq[cEq]; - auto& An = An_; // Use member variable + auto& An = solu_state_vars_.An; // Use member variable auto& Ad = com_mod.Ad; - auto& Dn = Dn_; - auto& Yn = Yn_; + auto& Dn = solu_state_vars_.Dn; + auto& Yn = solu_state_vars_.Yn; auto& pS0 = com_mod.pS0; auto& pSa = com_mod.pSa; @@ -913,7 +916,7 @@ void Integrator::corrector() /// (i.e., corner nodes). For e.g., for a P2 element, pressure is /// interpolated at the edge nodes using P1 vertices. /// -/// Modifies: Yn_ +/// Modifies: solu_state_vars_.Yn /// void Integrator::corrector_taylor_hood() { @@ -929,7 +932,7 @@ void Integrator::corrector_taylor_hood() const auto& eq = com_mod.eq[cEq]; auto& cDmn = com_mod.cDmn; - auto& Yn = Yn_; + auto& Yn = solu_state_vars_.Yn; // Check for something ... // diff --git a/Code/Source/solver/Integrator.h b/Code/Source/solver/Integrator.h index 60751209c..c90d8a8ce 100644 --- a/Code/Source/solver/Integrator.h +++ b/Code/Source/solver/Integrator.h @@ -8,6 +8,16 @@ #include "Vector.h" #include "Simulation.h" +/** + * @brief Solution state variables container + * + * Contains solution arrays at two time levels (n and n+1) for time integration + */ +struct soluStateVars { + Array An, Dn, Yn; // New (n+1): acceleration, displacement, velocity at next time step + Array Ao, Do, Yo; // Old (n): acceleration, displacement, velocity at current time step +}; + /** * @brief Integrator class encapsulates the Newton iteration loop for time integration * @@ -83,42 +93,49 @@ class Integrator { * * @return Reference to An array (acceleration at next time step) */ - Array& get_An() { return An_; } + Array& get_An() { return solu_state_vars_.An; } /** * @brief Get reference to Dn (new integrated variables at n+1) * * @return Reference to Dn array (displacement at next time step) */ - Array& get_Dn() { return Dn_; } + Array& get_Dn() { return solu_state_vars_.Dn; } /** * @brief Get reference to Yn (new variables at n+1) * * @return Reference to Yn array (velocity at next time step) */ - Array& get_Yn() { return Yn_; } + Array& get_Yn() { return solu_state_vars_.Yn; } /** * @brief Get reference to Ao (old time derivative of variables at n) * * @return Reference to Ao array (acceleration at current time step) */ - Array& get_Ao() { return Ao_; } + Array& get_Ao() { return solu_state_vars_.Ao; } /** * @brief Get reference to Do (old integrated variables at n) * * @return Reference to Do array (displacement at current time step) */ - Array& get_Do() { return Do_; } + Array& get_Do() { return solu_state_vars_.Do; } /** * @brief Get reference to Yo (old variables at n) * * @return Reference to Yo array (velocity at current time step) */ - Array& get_Yo() { return Yo_; } + Array& get_Yo() { return solu_state_vars_.Yo; } + + /** + * @brief Get reference to solution state variables struct + * + * @return Reference to soluStateVars struct containing all solution arrays + */ + soluStateVars& get_solu_state_vars() { return solu_state_vars_; } private: /** @brief Pointer to the simulation object */ @@ -133,23 +150,8 @@ class Integrator { /** @brief Integrated variables (displacement in structural mechanics) */ Array Dg_; - /** @brief New time derivative of variables at n+1 (acceleration at next time step) */ - Array An_; - - /** @brief New integrated variables at n+1 (displacement at next time step) */ - Array Dn_; - - /** @brief New variables at n+1 (velocity at next time step) */ - Array Yn_; - - /** @brief Old time derivative of variables at n (acceleration at current time step) */ - Array Ao_; - - /** @brief Old integrated variables at n (displacement at current time step) */ - Array Do_; - - /** @brief Old variables at n (velocity at current time step) */ - Array Yo_; + /** @brief Solution state variables (An, Dn, Yn, Ao, Do, Yo) */ + soluStateVars solu_state_vars_; /** @brief Residual vector for face-based quantities */ Vector res_; From ccf7ecde8e9ec4ab990b1e666422447a20b06253 Mon Sep 17 00:00:00 2001 From: Shiyi Chen Date: Wed, 14 Jan 2026 12:54:58 +0000 Subject: [PATCH 20/33] Change `solutions` struct to be nested, for example `solution.old.A` and `solution.current.A`. However, getter method for each variables (`get_Ao` for example) still exists for backward compatibility purpose. --- Code/Source/solver/Integrator.cpp | 80 +++++++++++++++---------------- Code/Source/solver/Integrator.h | 46 +++++++++++------- 2 files changed, 70 insertions(+), 56 deletions(-) diff --git a/Code/Source/solver/Integrator.cpp b/Code/Source/solver/Integrator.cpp index 0fde1ef1f..9e66a9b66 100644 --- a/Code/Source/solver/Integrator.cpp +++ b/Code/Source/solver/Integrator.cpp @@ -28,9 +28,9 @@ using namespace consts; Integrator::Integrator(Simulation* simulation, Array&& Ao, Array&& Do, Array&& Yo) : simulation_(simulation), newton_count_(0) { - solu_state_vars_.Ao = std::move(Ao); - solu_state_vars_.Do = std::move(Do); - solu_state_vars_.Yo = std::move(Yo); + solutions_.old.A = std::move(Ao); + solutions_.old.D = std::move(Do); + solutions_.old.Y = std::move(Yo); initialize_arrays(); } @@ -53,17 +53,17 @@ void Integrator::initialize_arrays() { Ag_.resize(tDof, tnNo); Yg_.resize(tDof, tnNo); Dg_.resize(tDof, tnNo); - solu_state_vars_.An.resize(tDof, tnNo); - solu_state_vars_.Dn.resize(tDof, tnNo); - solu_state_vars_.Yn.resize(tDof, tnNo); + solutions_.current.A.resize(tDof, tnNo); + solutions_.current.D.resize(tDof, tnNo); + solutions_.current.Y.resize(tDof, tnNo); res_.resize(nFacesLS); incL_.resize(nFacesLS); - // Ao, Do, Yo already initialized via move in constructor - // Initialize new variables from old variables - solu_state_vars_.An = solu_state_vars_.Ao; - solu_state_vars_.Dn = solu_state_vars_.Do; - solu_state_vars_.Yn = solu_state_vars_.Yo; + // old solution already initialized via move in constructor + // Initialize current solution from old solution + solutions_.current.A = solutions_.old.A; + solutions_.current.D = solutions_.old.D; + solutions_.current.Y = solutions_.old.Y; } //------------------------ @@ -107,8 +107,8 @@ bool Integrator::step() { #ifdef debug_integrator_step dmsg << "Set coupled BCs " << std::endl; #endif - set_bc::set_bc_cpl(com_mod, cm_mod, solu_state_vars_.An, solu_state_vars_.Yn, solu_state_vars_.Dn, solu_state_vars_.Yo, solu_state_vars_.Ao, solu_state_vars_.Do); - set_bc::set_bc_dir(com_mod, solu_state_vars_.An, solu_state_vars_.Yn, solu_state_vars_.Dn, solu_state_vars_.Yo, solu_state_vars_.Ao, solu_state_vars_.Do); + set_bc::set_bc_cpl(com_mod, cm_mod, solutions_.current.A, solutions_.current.Y, solutions_.current.D, solutions_.old.Y, solutions_.old.A, solutions_.old.D); + set_bc::set_bc_dir(com_mod, solutions_.current.A, solutions_.current.Y, solutions_.current.D, solutions_.old.Y, solutions_.old.A, solutions_.old.D); } // Initiator step for Generalized α-Method (quantities at n+am, n+af). @@ -202,7 +202,7 @@ void Integrator::initiator_step() { Ag_.write("Ag_pic" + istr_); Yg_.write("Yg_pic" + istr_); Dg_.write("Dg_pic" + istr_); - solu_state_vars_.Yn.write("solu_state_vars_.Ynpic" + istr_); + solutions_.current.Y.write("solutions_.current.Ypic" + istr_); } //------------------------ @@ -251,7 +251,7 @@ void Integrator::assemble_equations() { #endif for (int iM = 0; iM < com_mod.nMsh; iM++) { - eq_assem::global_eq_assem(com_mod, cep_mod, com_mod.msh[iM], Ag_, Yg_, Dg_, solu_state_vars_.Do); + eq_assem::global_eq_assem(com_mod, cep_mod, com_mod.msh[iM], Ag_, Yg_, Dg_, solutions_.old.D); } // Debug output @@ -276,22 +276,22 @@ void Integrator::apply_boundary_conditions() { Dg_.write("Dg_vor_neu" + istr_); // Apply Neumman or Traction boundary conditions - set_bc::set_bc_neu(com_mod, cm_mod, Yg_, Dg_, solu_state_vars_.Yn, solu_state_vars_.Do); + set_bc::set_bc_neu(com_mod, cm_mod, Yg_, Dg_, solutions_.current.Y, solutions_.old.D); // Apply CMM BC conditions if (!com_mod.cmmInit) { - set_bc::set_bc_cmm(com_mod, cm_mod, Ag_, Dg_, solu_state_vars_.Do); + set_bc::set_bc_cmm(com_mod, cm_mod, Ag_, Dg_, solutions_.old.D); } // Apply weakly applied Dirichlet BCs - set_bc::set_bc_dir_w(com_mod, Yg_, Dg_, solu_state_vars_.Do); + set_bc::set_bc_dir_w(com_mod, Yg_, Dg_, solutions_.old.D); if (com_mod.risFlag) { - ris::ris_resbc(com_mod, Yg_, Dg_, solu_state_vars_.Do); + ris::ris_resbc(com_mod, Yg_, Dg_, solutions_.old.D); } if (com_mod.ris0DFlag) { - ris::ris0d_bc(com_mod, cm_mod, Yg_, Dg_, solu_state_vars_.Yn, solu_state_vars_.Do); + ris::ris0d_bc(com_mod, cm_mod, Yg_, Dg_, solutions_.current.Y, solutions_.old.D); } // Apply contact model and add its contribution to residual @@ -341,7 +341,7 @@ bool Integrator::corrector_and_check_convergence() { corrector(); // Debug output - solu_state_vars_.Yn.write("solu_state_vars_.Yncorrector" + istr_); + solutions_.current.Y.write("solutions_.current.Ycorrector" + istr_); // Check if all equations converged return std::count_if(com_mod.eq.begin(), com_mod.eq.end(), @@ -416,12 +416,12 @@ void Integrator::predictor() // time derivative of displacement auto& Ad = com_mod.Ad; - auto& Ao = solu_state_vars_.Ao; // Use member variable - auto& An = solu_state_vars_.An; // Use member variable - auto& Yo = solu_state_vars_.Yo; // Use member variable - auto& Yn = solu_state_vars_.Yn; // Use member variable - auto& Do = solu_state_vars_.Do; // Use member variable - auto& Dn = solu_state_vars_.Dn; // Use member variable + auto& Ao = solutions_.old.A; // Use member variable + auto& An = solutions_.current.A; // Use member variable + auto& Yo = solutions_.old.Y; // Use member variable + auto& Yn = solutions_.current.Y; // Use member variable + auto& Do = solutions_.old.D; // Use member variable + auto& Dn = solutions_.current.D; // Use member variable // Prestress initialization if (com_mod.pstEq) { @@ -489,7 +489,7 @@ void Integrator::predictor() // electrophysiology if (eq.phys == Equation_CEP) { - cep_ion::cep_integ(simulation_, iEq, e, Do, solu_state_vars_.Yo); + cep_ion::cep_integ(simulation_, iEq, e, Do, solutions_.old.Y); } // eqn 86 of Bazilevs 2007 @@ -567,12 +567,12 @@ void Integrator::initiator(Array& Ag, Array& Yg, Array& dmsg << "com_mod.pstEq: " << com_mod.pstEq; #endif - const auto& Ao = solu_state_vars_.Ao; // Use member variable - const auto& An = solu_state_vars_.An; // Use member variable - const auto& Do = solu_state_vars_.Do; // Use member variable - const auto& Dn = solu_state_vars_.Dn; // Use member variable - const auto& Yo = solu_state_vars_.Yo; // Use member variable - const auto& Yn = solu_state_vars_.Yn; // Use member variable + const auto& Ao = solutions_.old.A; // Use member variable + const auto& An = solutions_.current.A; // Use member variable + const auto& Do = solutions_.old.D; // Use member variable + const auto& Dn = solutions_.current.D; // Use member variable + const auto& Yo = solutions_.old.Y; // Use member variable + const auto& Yn = solutions_.current.Y; // Use member variable for (int i = 0; i < com_mod.nEq; i++) { auto& eq = com_mod.eq[i]; @@ -638,7 +638,7 @@ void Integrator::initiator(Array& Ag, Array& Yg, Array& /// Modifies: /// \code {.cpp} /// com_mod.Ad -/// solu_state_vars_.An (member variable) +/// solutions_.current.A (member variable) /// com_mod.Dn /// com_mod.Yn /// cep_mod.Xion @@ -674,10 +674,10 @@ void Integrator::corrector() auto& cEq = com_mod.cEq; auto& eq = com_mod.eq[cEq]; - auto& An = solu_state_vars_.An; // Use member variable + auto& An = solutions_.current.A; // Use member variable auto& Ad = com_mod.Ad; - auto& Dn = solu_state_vars_.Dn; - auto& Yn = solu_state_vars_.Yn; + auto& Dn = solutions_.current.D; + auto& Yn = solutions_.current.Y; auto& pS0 = com_mod.pS0; auto& pSa = com_mod.pSa; @@ -916,7 +916,7 @@ void Integrator::corrector() /// (i.e., corner nodes). For e.g., for a P2 element, pressure is /// interpolated at the edge nodes using P1 vertices. /// -/// Modifies: solu_state_vars_.Yn +/// Modifies: solutions_.current.Y /// void Integrator::corrector_taylor_hood() { @@ -932,7 +932,7 @@ void Integrator::corrector_taylor_hood() const auto& eq = com_mod.eq[cEq]; auto& cDmn = com_mod.cDmn; - auto& Yn = solu_state_vars_.Yn; + auto& Yn = solutions_.current.Y; // Check for something ... // diff --git a/Code/Source/solver/Integrator.h b/Code/Source/solver/Integrator.h index c90d8a8ce..6fe90852b 100644 --- a/Code/Source/solver/Integrator.h +++ b/Code/Source/solver/Integrator.h @@ -9,13 +9,27 @@ #include "Simulation.h" /** - * @brief Solution state variables container + * @brief Represents solution variables at a single time level * - * Contains solution arrays at two time levels (n and n+1) for time integration + * Contains the three primary solution arrays used in time integration: + * A (time derivative), D (integrated variable), and Y (variable) */ -struct soluStateVars { - Array An, Dn, Yn; // New (n+1): acceleration, displacement, velocity at next time step - Array Ao, Do, Yo; // Old (n): acceleration, displacement, velocity at current time step +struct Solution { + Array A; ///< Time derivative (acceleration in structural mechanics) + Array D; ///< Integrated variable (displacement in structural mechanics) + Array Y; ///< Variable (velocity in structural mechanics) +}; + +/** + * @brief Holds solution state at old and current time levels + * + * Contains solution arrays at two time levels for time integration: + * - old: Previous converged solution at time n + * - current: Current solution being computed at time n+1 + */ +struct SolutionStates { + Solution old; ///< Previous converged solution at time n (Ao, Do, Yo) + Solution current; ///< Current solution being computed at time n+1 (An, Dn, Yn) }; /** @@ -93,49 +107,49 @@ class Integrator { * * @return Reference to An array (acceleration at next time step) */ - Array& get_An() { return solu_state_vars_.An; } + Array& get_An() { return solutions_.current.A; } /** * @brief Get reference to Dn (new integrated variables at n+1) * * @return Reference to Dn array (displacement at next time step) */ - Array& get_Dn() { return solu_state_vars_.Dn; } + Array& get_Dn() { return solutions_.current.D; } /** * @brief Get reference to Yn (new variables at n+1) * * @return Reference to Yn array (velocity at next time step) */ - Array& get_Yn() { return solu_state_vars_.Yn; } + Array& get_Yn() { return solutions_.current.Y; } /** * @brief Get reference to Ao (old time derivative of variables at n) * * @return Reference to Ao array (acceleration at current time step) */ - Array& get_Ao() { return solu_state_vars_.Ao; } + Array& get_Ao() { return solutions_.old.A; } /** * @brief Get reference to Do (old integrated variables at n) * * @return Reference to Do array (displacement at current time step) */ - Array& get_Do() { return solu_state_vars_.Do; } + Array& get_Do() { return solutions_.old.D; } /** * @brief Get reference to Yo (old variables at n) * * @return Reference to Yo array (velocity at current time step) */ - Array& get_Yo() { return solu_state_vars_.Yo; } + Array& get_Yo() { return solutions_.old.Y; } /** - * @brief Get reference to solution state variables struct + * @brief Get reference to solution states struct * - * @return Reference to soluStateVars struct containing all solution arrays + * @return Reference to SolutionStates struct containing all solution arrays */ - soluStateVars& get_solu_state_vars() { return solu_state_vars_; } + SolutionStates& get_solutions() { return solutions_; } private: /** @brief Pointer to the simulation object */ @@ -150,8 +164,8 @@ class Integrator { /** @brief Integrated variables (displacement in structural mechanics) */ Array Dg_; - /** @brief Solution state variables (An, Dn, Yn, Ao, Do, Yo) */ - soluStateVars solu_state_vars_; + /** @brief Solution states at old and current time levels */ + SolutionStates solutions_; /** @brief Residual vector for face-based quantities */ Vector res_; From ec07838cfdae3b8ad2a142d6325ad87ef4d00aab Mon Sep 17 00:00:00 2001 From: shiyi Date: Mon, 19 Jan 2026 16:28:01 +0000 Subject: [PATCH 21/33] Change the argument positions at `all_fun.h`. Now Dn and Do no longer take default argument `nullptr`. --- Code/Source/solver/all_fun.cpp | 12 ++++++------ Code/Source/solver/all_fun.h | 12 ++++++------ Code/Source/solver/baf_ini.cpp | 6 +++--- Code/Source/solver/initialize.cpp | 2 +- Code/Source/solver/main.cpp | 2 -- Code/Source/solver/ris.cpp | 10 +++++----- Code/Source/solver/set_bc.cpp | 24 ++++++++++++------------ Code/Source/solver/txt.cpp | 12 ++++++------ 8 files changed, 39 insertions(+), 41 deletions(-) diff --git a/Code/Source/solver/all_fun.cpp b/Code/Source/solver/all_fun.cpp index 40ae5e547..647212c84 100644 --- a/Code/Source/solver/all_fun.cpp +++ b/Code/Source/solver/all_fun.cpp @@ -425,7 +425,7 @@ double integ(const ComMod& com_mod, const CmMod& cm_mod, int iM, const Array& s, int l, int u, bool pFlag, const Array* Do) +double integ(const ComMod& com_mod, const CmMod& cm_mod, int dId, const Array& s, int l, int u, const Array* Do, bool pFlag) { using namespace consts; @@ -678,7 +678,7 @@ double integ(const ComMod& com_mod, const CmMod& cm_mod, int dId, const Array& s, bool pFlag, MechanicalConfigurationType cfg, const Array* Dn, const Array* Do) +double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, const Vector& s, const Array* Dn, const Array* Do, bool pFlag, MechanicalConfigurationType cfg) { using namespace consts; #define n_debug_integ_s @@ -842,7 +842,7 @@ double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, co /// @param cfg denotes which configuration (reference/timestep 0, old/timestep n, or new/timestep n+1). Default reference. // double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, - const Array& s, MechanicalConfigurationType cfg, const Array* Dn, const Array* Do) + const Array& s, const Array* Dn, const Array* Do, MechanicalConfigurationType cfg) { using namespace consts; @@ -976,7 +976,7 @@ double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, /// // double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, - const Array& s, const int l, std::optional uo, bool THflag, MechanicalConfigurationType cfg, const Array* Dn, const Array* Do) + const Array& s, const int l, const Array* Dn, const Array* Do, std::optional uo, bool THflag, MechanicalConfigurationType cfg) { using namespace consts; @@ -1032,14 +1032,14 @@ double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, vec(n,a) = s(i,a); } } - result = integ(com_mod, cm_mod, lFa, vec, cfg, Dn, Do); + result = integ(com_mod, cm_mod, lFa, vec, Dn, Do, cfg); // If s scalar, integrate as scalar } else if (l == u) { Vector sclr(nNo); for (int a = 0; a < nNo; a++) { sclr(a) = s(l,a); } - result = integ(com_mod, cm_mod, lFa, sclr, flag, cfg, Dn, Do); + result = integ(com_mod, cm_mod, lFa, sclr, Dn, Do, flag, cfg); } else { throw std::runtime_error("Unexpected dof in integ"); } diff --git a/Code/Source/solver/all_fun.h b/Code/Source/solver/all_fun.h index 2f95b7455..37ca972ce 100644 --- a/Code/Source/solver/all_fun.h +++ b/Code/Source/solver/all_fun.h @@ -29,18 +29,18 @@ namespace all_fun { Array global(const ComMod& com_mod, const CmMod& cm_mod, const mshType& lM, const Array& U); - double integ(const ComMod& com_mod, const CmMod& cm_mod, int iM, const Array& s, const Array* Do=nullptr); + double integ(const ComMod& com_mod, const CmMod& cm_mod, int iM, const Array& s, const Array* Do); - double integ(const ComMod& com_mod, const CmMod& cm_mod, int dId, const Array& s, int l, int u, - bool pFlag=false, const Array* Do=nullptr); + double integ(const ComMod& com_mod, const CmMod& cm_mod, int dId, const Array& s, int l, int u, + const Array* Do, bool pFlag=false); double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, const Vector& s, - bool pFlag=false, consts::MechanicalConfigurationType cfg=consts::MechanicalConfigurationType::reference, const Array* Dn=nullptr, const Array* Do=nullptr); + const Array* Dn, const Array* Do, bool pFlag=false, consts::MechanicalConfigurationType cfg=consts::MechanicalConfigurationType::reference); double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, const Array& s, - const int l, std::optional uo=std::nullopt, bool THflag=false, consts::MechanicalConfigurationType cfg=consts::MechanicalConfigurationType::reference, const Array* Dn=nullptr, const Array* Do=nullptr); + const int l, const Array* Dn, const Array* Do, std::optional uo=std::nullopt, bool THflag=false, consts::MechanicalConfigurationType cfg=consts::MechanicalConfigurationType::reference); - double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, const Array& s, consts::MechanicalConfigurationType cfg=consts::MechanicalConfigurationType::reference, const Array* Dn=nullptr, const Array* Do=nullptr); + double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, const Array& s, const Array* Dn, const Array* Do, consts::MechanicalConfigurationType cfg=consts::MechanicalConfigurationType::reference); bool is_domain(const ComMod& com_mod, const eqType& eq, const int node, const consts::EquationType phys); diff --git a/Code/Source/solver/baf_ini.cpp b/Code/Source/solver/baf_ini.cpp index ffbcda24c..6a9e1e340 100644 --- a/Code/Source/solver/baf_ini.cpp +++ b/Code/Source/solver/baf_ini.cpp @@ -287,7 +287,7 @@ void bc_ini(const ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, faceType& l } else if (btest(lBc.bType, iBC_para)) { Vector center(3); for (int i = 0; i < nsd; i++) { - center(i) = all_fun::integ(com_mod, cm_mod, lFa, com_mod.x, i, std::nullopt, false, consts::MechanicalConfigurationType::reference, &Do, &Do) / lFa.area; + center(i) = all_fun::integ(com_mod, cm_mod, lFa, com_mod.x, i, &Do, &Do, std::nullopt, false, consts::MechanicalConfigurationType::reference) / lFa.area; } // gNodes is one if a node located on the boundary (beside iFa) @@ -396,7 +396,7 @@ void bc_ini(const ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, faceType& l // double tmp = 1.0; if (btest(lBc.bType, enum_int(BoundaryConditionType::bType_flx))) { - tmp = all_fun::integ(com_mod, cm_mod, lFa, s, false, consts::MechanicalConfigurationType::reference, &Do, &Do); + tmp = all_fun::integ(com_mod, cm_mod, lFa, s, &Do, &Do, false, consts::MechanicalConfigurationType::reference); if (is_zero(tmp)) { tmp = 1.0; throw std::runtime_error("Face '" + lFa.name + "' used for a BC has no non-zero node."); @@ -436,7 +436,7 @@ void face_ini(Simulation* simulation, mshType& lM, faceType& lFa, Array& // Vector sA(com_mod.tnNo); sA = 1.0; - double area = all_fun::integ(com_mod, cm_mod, lFa, sA, false, consts::MechanicalConfigurationType::reference, &Do, &Do); + double area = all_fun::integ(com_mod, cm_mod, lFa, sA, &Do, &Do, false, consts::MechanicalConfigurationType::reference); #ifdef debug_face_ini dmsg << "Face '" << lFa.name << "' area: " << area; #endif diff --git a/Code/Source/solver/initialize.cpp b/Code/Source/solver/initialize.cpp index 4eab0af0a..737a9d261 100644 --- a/Code/Source/solver/initialize.cpp +++ b/Code/Source/solver/initialize.cpp @@ -806,7 +806,7 @@ void initialize(Simulation* simulation, Vector& timeP) for (int iDmn = 0; iDmn < eq.nDmn; iDmn++) { int i = eq.dmn[iDmn].Id; - eq.dmn[iDmn].v = all_fun::integ(com_mod, cm_mod, i, s, 0, 0, false, &Do); + eq.dmn[iDmn].v = all_fun::integ(com_mod, cm_mod, i, s, 0, 0, &Do, false); if (!com_mod.shlEq && !com_mod.cmmInit) { //std = " Volume of domain <"//STR(i)//"> is "// 2 STR(eq(iEq)%dmn(iDmn)%v) //IF (ISZERO(eq(iEq)%dmn(iDmn)%v)) wrn = "<< Volume of "// "domain "//iDmn//" of equation "//iEq//" is zero >>" diff --git a/Code/Source/solver/main.cpp b/Code/Source/solver/main.cpp index 32b566a91..d1ea8d56b 100644 --- a/Code/Source/solver/main.cpp +++ b/Code/Source/solver/main.cpp @@ -104,8 +104,6 @@ void iterate_precomputed_time(Simulation* simulation, Array& An, Array& An, Array& int iM = RIS.lst(i,0,iProj); int iFa = RIS.lst(i,1,iProj); double tmp = msh[iM].fa[iFa].area; - RIS.meanP(iProj,i) = all_fun::integ(com_mod, cm_mod, msh[iM].fa[iFa], tmpV, 0, std::nullopt, false, consts::MechanicalConfigurationType::reference, &Dn, &Do)/tmp; + RIS.meanP(iProj,i) = all_fun::integ(com_mod, cm_mod, msh[iM].fa[iFa], tmpV, 0, &Dn, &Do, std::nullopt, false, consts::MechanicalConfigurationType::reference)/tmp; } } @@ -72,7 +72,7 @@ void ris_meanq(ComMod& com_mod, CmMod& cm_mod, Array& An, Array& } int iM = RIS.lst(0,0,iProj); int iFa = RIS.lst(0,1,iProj); - RIS.meanFl(iProj) = all_fun::integ(com_mod, cm_mod, msh[iM].fa[iFa], tmpV, 0, m-1, false, consts::MechanicalConfigurationType::reference, &Dn, &Do); + RIS.meanFl(iProj) = all_fun::integ(com_mod, cm_mod, msh[iM].fa[iFa], tmpV, 0, &Dn, &Do, m-1, false, consts::MechanicalConfigurationType::reference); if (cm.mas(cm_mod)) { std::cout << "For RIS projection: " << iProj << std::endl; @@ -452,8 +452,8 @@ void ris0d_status(ComMod& com_mod, CmMod& cm_mod, Array& An, Array& An, Array& else { throw std::runtime_error("[calc_der_cpl_bc] Invalid physics type for 0D coupling"); } - cplBC.fa[ptr].Qo = all_fun::integ(com_mod, cm_mod, fa, Yo, 0, nsd-1, false, cfg_o, &Do, &Do); - cplBC.fa[ptr].Qn = all_fun::integ(com_mod, cm_mod, fa, Yn, 0, nsd-1, false, cfg_n, &Dn, &Do); + cplBC.fa[ptr].Qo = all_fun::integ(com_mod, cm_mod, fa, Yo, 0, &Do, &Do, nsd-1, false, cfg_o); + cplBC.fa[ptr].Qn = all_fun::integ(com_mod, cm_mod, fa, Yn, 0, &Dn, &Do, nsd-1, false, cfg_n); cplBC.fa[ptr].Po = 0.0; cplBC.fa[ptr].Pn = 0.0; #ifdef debug_calc_der_cpl_bc @@ -124,8 +124,8 @@ void calc_der_cpl_bc(ComMod& com_mod, const CmMod& cm_mod, const Array& // Compute avg pressures at 3D Dirichlet boundaries at timesteps n and n+1 else if (utils::btest(bc.bType, iBC_Dir)) { double area = fa.area; - cplBC.fa[ptr].Po = all_fun::integ(com_mod, cm_mod, fa, Yo, nsd, std::nullopt, false, MechanicalConfigurationType::reference, &Do, &Do) / area; - cplBC.fa[ptr].Pn = all_fun::integ(com_mod, cm_mod, fa, Yn, nsd, std::nullopt, false, MechanicalConfigurationType::reference, &Dn, &Do) / area; + cplBC.fa[ptr].Po = all_fun::integ(com_mod, cm_mod, fa, Yo, nsd, &Do, &Do, std::nullopt, false, MechanicalConfigurationType::reference) / area; + cplBC.fa[ptr].Pn = all_fun::integ(com_mod, cm_mod, fa, Yn, nsd, &Dn, &Do, std::nullopt, false, MechanicalConfigurationType::reference) / area; cplBC.fa[ptr].Qo = 0.0; cplBC.fa[ptr].Qn = 0.0; #ifdef debug_calc_der_cpl_bc @@ -548,8 +548,8 @@ void rcr_init(ComMod& com_mod, const CmMod& cm_mod, const Array& Ao, con if (cplBC.initRCR) { auto& fa = com_mod.msh[iM].fa[iFa]; double area = fa.area; - double Qo = all_fun::integ(com_mod, cm_mod, fa, Yo, 0, nsd-1, false, MechanicalConfigurationType::reference, &Do, &Do); - double Po = all_fun::integ(com_mod, cm_mod, fa, Yo, nsd, std::nullopt, false, MechanicalConfigurationType::reference, &Do, &Do) / area; + double Qo = all_fun::integ(com_mod, cm_mod, fa, Yo, 0, &Do, &Do, nsd-1, false, MechanicalConfigurationType::reference); + double Po = all_fun::integ(com_mod, cm_mod, fa, Yo, nsd, &Do, &Do, std::nullopt, false, MechanicalConfigurationType::reference) / area; cplBC.xo[ptr] = Po - (Qo * cplBC.fa[ptr].RCR.Rp); } else { cplBC.xo[ptr] = cplBC.fa[ptr].RCR.Xo; @@ -684,7 +684,7 @@ void set_bc_cpl(ComMod& com_mod, CmMod& cm_mod, const Array& An, Array sA(com_mod.tnNo); sA = 1.0; - double area = all_fun::integ(com_mod, cm_mod, lFa, sA, false, consts::MechanicalConfigurationType::reference, &Do, &Do); + double area = all_fun::integ(com_mod, cm_mod, lFa, sA, &Do, &Do, false, consts::MechanicalConfigurationType::reference); baf_ini_ns::bc_ini(com_mod, cm_mod, eq.bc[iBc], lFa, Do); int ptr = bc.cplBCptr; @@ -719,15 +719,15 @@ void set_bc_cpl(ComMod& com_mod, CmMod& cm_mod, const Array& An, Array Date: Tue, 20 Jan 2026 10:08:29 +0000 Subject: [PATCH 22/33] Fix the function signature gnnb at nn.cpp to make Dn and Do not take default value nullptr --- Code/Source/solver/all_fun.cpp | 4 ++-- Code/Source/solver/baf_ini.cpp | 4 ++-- Code/Source/solver/cmm.cpp | 2 +- Code/Source/solver/eq_assem.cpp | 6 +++--- Code/Source/solver/nn.cpp | 2 +- Code/Source/solver/nn.h | 2 +- Code/Source/solver/set_bc.cpp | 6 +++--- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Code/Source/solver/all_fun.cpp b/Code/Source/solver/all_fun.cpp index 647212c84..9ecf55515 100644 --- a/Code/Source/solver/all_fun.cpp +++ b/Code/Source/solver/all_fun.cpp @@ -803,7 +803,7 @@ double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, co if (!isIB) { // Get normal vector in cfg configuration auto Nx = fs.Nx.slice(g); - nn::gnnb(com_mod, lFa, e, g, nsd, insd, fs.eNoN, Nx, n, cfg, Dn, Do); + nn::gnnb(com_mod, lFa, e, g, nsd, insd, fs.eNoN, Nx, n, Dn, Do, cfg); } // Calculating the Jacobian (encodes area of face element) @@ -923,7 +923,7 @@ double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, if (!isIB) { // Get normal vector in cfg configuration auto Nx = lFa.Nx.slice(g); - nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, lFa.eNoN, Nx, n, cfg, Dn, Do); + nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, lFa.eNoN, Nx, n, Dn, Do, cfg); //CALL GNNB(lFa, e, g, nsd-1, lFa.eNoN, lFa.Nx(:,:,g), n) } else { //CALL GNNIB(lFa, e, g, n) diff --git a/Code/Source/solver/baf_ini.cpp b/Code/Source/solver/baf_ini.cpp index 6a9e1e340..faeec7b59 100644 --- a/Code/Source/solver/baf_ini.cpp +++ b/Code/Source/solver/baf_ini.cpp @@ -478,7 +478,7 @@ void face_ini(Simulation* simulation, mshType& lM, faceType& lFa, Array& for (int g = 0; g < lFa.nG; g++) { auto Nx = lFa.Nx.slice(g); - nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, lFa.eNoN, Nx, nV, consts::MechanicalConfigurationType::reference, nullptr, &Do); + nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, lFa.eNoN, Nx, nV, nullptr, &Do, consts::MechanicalConfigurationType::reference); for (int a = 0; a < lFa.eNoN; a++) { int Ac = lFa.IEN(a,e); @@ -728,7 +728,7 @@ void fsi_ls_ini(ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, const faceTyp for (int g = 0; g < lFa.nG; g++) { Vector n(nsd); auto Nx = lFa.Nx.slice(g); - nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, lFa.eNoN, Nx, n, consts::MechanicalConfigurationType::reference, nullptr, &Do); + nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, lFa.eNoN, Nx, n, nullptr, &Do, consts::MechanicalConfigurationType::reference); for (int a = 0; a < lFa.eNoN; a++) { int Ac = lFa.IEN(a,e); diff --git a/Code/Source/solver/cmm.cpp b/Code/Source/solver/cmm.cpp index 38280ace7..b60de90a5 100644 --- a/Code/Source/solver/cmm.cpp +++ b/Code/Source/solver/cmm.cpp @@ -282,7 +282,7 @@ void cmm_b(ComMod& com_mod, const faceType& lFa, const int e, const Array nV(nsd); auto Nx = lFa.Nx.slice(g); - nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, 3, Nx, nV, consts::MechanicalConfigurationType::reference, nullptr, &Do); + nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, 3, Nx, nV, nullptr, &Do, consts::MechanicalConfigurationType::reference); double Jac = sqrt(utils::norm(nV)); nV = nV / Jac; double w = lFa.w(g)*Jac; diff --git a/Code/Source/solver/eq_assem.cpp b/Code/Source/solver/eq_assem.cpp index 460388593..6521eea1d 100644 --- a/Code/Source/solver/eq_assem.cpp +++ b/Code/Source/solver/eq_assem.cpp @@ -76,7 +76,7 @@ void b_assem_neu_bc(ComMod& com_mod, const faceType& lFa, const Vector& for (int g = 0; g < lFa.nG; g++) { Vector nV(nsd); auto Nx = lFa.Nx.rslice(g); - nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, eNoN, Nx, nV, consts::MechanicalConfigurationType::reference, nullptr, &Do); + nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, eNoN, Nx, nV, nullptr, &Do, consts::MechanicalConfigurationType::reference); double Jac = sqrt(utils::norm(nV)); nV = nV / Jac; double w = lFa.w(g)*Jac; @@ -245,7 +245,7 @@ void b_neu_folw_p(ComMod& com_mod, const bcType& lBc, const faceType& lFa, const // Get surface normal vector Vector nV(nsd); auto Nx_g = lFa.Nx.rslice(g); - nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, eNoNb, Nx_g, nV, consts::MechanicalConfigurationType::reference, nullptr, &Do); + nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, eNoNb, Nx_g, nV, nullptr, &Do, consts::MechanicalConfigurationType::reference); Jac = sqrt(utils::norm(nV)); nV = nV / Jac; double w = lFa.w(g)*Jac; @@ -322,7 +322,7 @@ void fsi_ls_upd(ComMod& com_mod, const bcType& lBc, const faceType& lFa, const A auto cfg = MechanicalConfigurationType::new_timestep; - nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, lFa.eNoN, Nx, n, cfg, &Dn, &Do); + nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, lFa.eNoN, Nx, n, &Dn, &Do, cfg); // for (int a = 0; a < lFa.eNoN; a++) { int Ac = lFa.IEN(a,e); diff --git a/Code/Source/solver/nn.cpp b/Code/Source/solver/nn.cpp index 95cc88389..91526ed67 100644 --- a/Code/Source/solver/nn.cpp +++ b/Code/Source/solver/nn.cpp @@ -523,7 +523,7 @@ void gnn(const int eNoN, const int nsd, const int insd, Array& Nxi, Arra /// Reproduce Fortran 'GNNB'. // void gnnb(const ComMod& com_mod, const faceType& lFa, const int e, const int g, const int nsd, const int insd, - const int eNoNb, const Array& Nx, Vector& n, MechanicalConfigurationType cfg, const Array* Dn, const Array* Do) + const int eNoNb, const Array& Nx, Vector& n, const Array* Dn, const Array* Do, MechanicalConfigurationType cfg) { auto& cm = com_mod.cm; diff --git a/Code/Source/solver/nn.h b/Code/Source/solver/nn.h index 52d7c8843..d5046cd96 100644 --- a/Code/Source/solver/nn.h +++ b/Code/Source/solver/nn.h @@ -38,7 +38,7 @@ namespace nn { double& Jac, Array& ks); void gnnb(const ComMod& com_mod, const faceType& lFa, const int e, const int g, const int nsd, const int insd, - const int eNoNb, const Array& Nx, Vector& n, consts::MechanicalConfigurationType cfg=consts::MechanicalConfigurationType::reference, const Array* Dn=nullptr, const Array* Do=nullptr); + const int eNoNb, const Array& Nx, Vector& n, const Array* Dn, const Array* Do, consts::MechanicalConfigurationType cfg=consts::MechanicalConfigurationType::reference); void gnns(const int nsd, const int eNoN, const Array& Nxi, Array& xl, Vector& nV, Array& gCov, Array& gCnv); diff --git a/Code/Source/solver/set_bc.cpp b/Code/Source/solver/set_bc.cpp index f026aa4c2..87b1c6e39 100644 --- a/Code/Source/solver/set_bc.cpp +++ b/Code/Source/solver/set_bc.cpp @@ -1251,7 +1251,7 @@ void set_bc_dir_wl(ComMod& com_mod, const bcType& lBc, const mshType& lM, const for (int g = 0; g < lFa.nG; g++) { Vector nV(nsd); auto Nx = lFa.Nx.slice(g); - nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, eNoNb, Nx, nV, consts::MechanicalConfigurationType::reference, nullptr, &Do); + nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, eNoNb, Nx, nV, nullptr, &Do, consts::MechanicalConfigurationType::reference); double Jac = sqrt(utils::norm(nV)); nV = nV / Jac; double w = lFa.w(g) * Jac; @@ -1504,7 +1504,7 @@ void set_bc_rbnl(ComMod& com_mod, const faceType& lFa, const RobinBoundaryCondit for (int g = 0; g < lFa.nG; g++) { Vector nV(nsd); auto Nx = lFa.Nx.slice(g); - nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, eNoN, Nx, nV, consts::MechanicalConfigurationType::reference, nullptr, &Do); + nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, eNoN, Nx, nV, nullptr, &Do, consts::MechanicalConfigurationType::reference); double Jac = sqrt(utils::norm(nV)); nV = nV / Jac; double w = lFa.w(g) * Jac; @@ -1784,7 +1784,7 @@ void set_bc_trac_l(ComMod& com_mod, const CmMod& cm_mod, const bcType& lBc, cons for (int g = 0; g < lFa.nG; g++) { Vector nV(nsd); auto Nx = lFa.Nx.slice(g); - nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, eNoN, Nx, nV, consts::MechanicalConfigurationType::reference, nullptr, &Do); + nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, eNoN, Nx, nV, nullptr, &Do, consts::MechanicalConfigurationType::reference); double Jac = sqrt(utils::norm(nV)); double w = lFa.w(g)*Jac; N = lFa.N.col(g); From 1f4acb834da8b52d2320db9a00627f8704ccfe32 Mon Sep 17 00:00:00 2001 From: shiyi Date: Fri, 23 Jan 2026 22:12:46 +0000 Subject: [PATCH 23/33] Add Solution getters to ComMod.h and update Integrator to use them --- Code/Source/solver/ComMod.h | 34 +++++++++++++ Code/Source/solver/Integrator.cpp | 77 +++++++++++++++--------------- Code/Source/solver/Integrator.h | 79 ++++--------------------------- 3 files changed, 83 insertions(+), 107 deletions(-) diff --git a/Code/Source/solver/ComMod.h b/Code/Source/solver/ComMod.h index b3ea3c728..20280bf14 100644 --- a/Code/Source/solver/ComMod.h +++ b/Code/Source/solver/ComMod.h @@ -40,6 +40,40 @@ class LinearAlgebra; +/** + * @brief Represents solution variables at a single time level + * + * Contains the three primary solution arrays used in time integration: + * A (time derivative), D (integrated variable), and Y (variable) + */ +struct Solution { + Array A; ///< Time derivative (acceleration in structural mechanics) + Array D; ///< Integrated variable (displacement in structural mechanics) + Array Y; ///< Variable (velocity in structural mechanics) + + // Semantic getters for improved readability + Array& get_acceleration() { return A; } + const Array& get_acceleration() const { return A; } + + Array& get_velocity() { return Y; } + const Array& get_velocity() const { return Y; } + + Array& get_displacement() { return D; } + const Array& get_displacement() const { return D; } +}; + +/** + * @brief Holds solution state at old and current time levels + * + * Contains solution arrays at two time levels for time integration: + * - old: Previous converged solution at time n + * - current: Current solution being computed at time n+1 + */ +struct SolutionStates { + Solution old; ///< Previous converged solution at time n (Ao, Do, Yo) + Solution current; ///< Current solution being computed at time n+1 (An, Dn, Yn) +}; + /// @brief Fourier coefficients that are used to specify unsteady BCs // class fcType diff --git a/Code/Source/solver/Integrator.cpp b/Code/Source/solver/Integrator.cpp index 9e66a9b66..faf920343 100644 --- a/Code/Source/solver/Integrator.cpp +++ b/Code/Source/solver/Integrator.cpp @@ -25,12 +25,9 @@ using namespace consts; //------------------------ // Integrator Constructor //------------------------ -Integrator::Integrator(Simulation* simulation, Array&& Ao, Array&& Do, Array&& Yo) - : simulation_(simulation), newton_count_(0) +Integrator::Integrator(Simulation* simulation, SolutionStates&& solutions) + : simulation_(simulation), solutions_(std::move(solutions)), newton_count_(0) { - solutions_.old.A = std::move(Ao); - solutions_.old.D = std::move(Do); - solutions_.old.Y = std::move(Yo); initialize_arrays(); } @@ -53,17 +50,17 @@ void Integrator::initialize_arrays() { Ag_.resize(tDof, tnNo); Yg_.resize(tDof, tnNo); Dg_.resize(tDof, tnNo); - solutions_.current.A.resize(tDof, tnNo); - solutions_.current.D.resize(tDof, tnNo); - solutions_.current.Y.resize(tDof, tnNo); + solutions_.current.get_acceleration().resize(tDof, tnNo); + solutions_.current.get_displacement().resize(tDof, tnNo); + solutions_.current.get_velocity().resize(tDof, tnNo); res_.resize(nFacesLS); incL_.resize(nFacesLS); // old solution already initialized via move in constructor // Initialize current solution from old solution - solutions_.current.A = solutions_.old.A; - solutions_.current.D = solutions_.old.D; - solutions_.current.Y = solutions_.old.Y; + solutions_.current.get_acceleration() = solutions_.old.get_acceleration(); + solutions_.current.get_displacement() = solutions_.old.get_displacement(); + solutions_.current.get_velocity() = solutions_.old.get_velocity(); } //------------------------ @@ -107,8 +104,12 @@ bool Integrator::step() { #ifdef debug_integrator_step dmsg << "Set coupled BCs " << std::endl; #endif - set_bc::set_bc_cpl(com_mod, cm_mod, solutions_.current.A, solutions_.current.Y, solutions_.current.D, solutions_.old.Y, solutions_.old.A, solutions_.old.D); - set_bc::set_bc_dir(com_mod, solutions_.current.A, solutions_.current.Y, solutions_.current.D, solutions_.old.Y, solutions_.old.A, solutions_.old.D); + set_bc::set_bc_cpl(com_mod, cm_mod, solutions_.current.get_acceleration(), solutions_.current.get_velocity(), + solutions_.current.get_displacement(), solutions_.old.get_velocity(), + solutions_.old.get_acceleration(), solutions_.old.get_displacement()); + set_bc::set_bc_dir(com_mod, solutions_.current.get_acceleration(), solutions_.current.get_velocity(), + solutions_.current.get_displacement(), solutions_.old.get_velocity(), + solutions_.old.get_acceleration(), solutions_.old.get_displacement()); } // Initiator step for Generalized α-Method (quantities at n+am, n+af). @@ -202,7 +203,7 @@ void Integrator::initiator_step() { Ag_.write("Ag_pic" + istr_); Yg_.write("Yg_pic" + istr_); Dg_.write("Dg_pic" + istr_); - solutions_.current.Y.write("solutions_.current.Ypic" + istr_); + solutions_.current.get_velocity().write("solutions_.current.Ypic" + istr_); } //------------------------ @@ -251,7 +252,7 @@ void Integrator::assemble_equations() { #endif for (int iM = 0; iM < com_mod.nMsh; iM++) { - eq_assem::global_eq_assem(com_mod, cep_mod, com_mod.msh[iM], Ag_, Yg_, Dg_, solutions_.old.D); + eq_assem::global_eq_assem(com_mod, cep_mod, com_mod.msh[iM], Ag_, Yg_, Dg_, solutions_.old.get_displacement()); } // Debug output @@ -276,22 +277,22 @@ void Integrator::apply_boundary_conditions() { Dg_.write("Dg_vor_neu" + istr_); // Apply Neumman or Traction boundary conditions - set_bc::set_bc_neu(com_mod, cm_mod, Yg_, Dg_, solutions_.current.Y, solutions_.old.D); + set_bc::set_bc_neu(com_mod, cm_mod, Yg_, Dg_, solutions_.current.get_velocity(), solutions_.old.get_displacement()); // Apply CMM BC conditions if (!com_mod.cmmInit) { - set_bc::set_bc_cmm(com_mod, cm_mod, Ag_, Dg_, solutions_.old.D); + set_bc::set_bc_cmm(com_mod, cm_mod, Ag_, Dg_, solutions_.old.get_displacement()); } // Apply weakly applied Dirichlet BCs - set_bc::set_bc_dir_w(com_mod, Yg_, Dg_, solutions_.old.D); + set_bc::set_bc_dir_w(com_mod, Yg_, Dg_, solutions_.old.get_displacement()); if (com_mod.risFlag) { - ris::ris_resbc(com_mod, Yg_, Dg_, solutions_.old.D); + ris::ris_resbc(com_mod, Yg_, Dg_, solutions_.old.get_displacement()); } if (com_mod.ris0DFlag) { - ris::ris0d_bc(com_mod, cm_mod, Yg_, Dg_, solutions_.current.Y, solutions_.old.D); + ris::ris0d_bc(com_mod, cm_mod, Yg_, Dg_, solutions_.current.get_velocity(), solutions_.old.get_displacement()); } // Apply contact model and add its contribution to residual @@ -341,7 +342,7 @@ bool Integrator::corrector_and_check_convergence() { corrector(); // Debug output - solutions_.current.Y.write("solutions_.current.Ycorrector" + istr_); + solutions_.current.get_velocity().write("solutions_.current.Ycorrector" + istr_); // Check if all equations converged return std::count_if(com_mod.eq.begin(), com_mod.eq.end(), @@ -416,12 +417,12 @@ void Integrator::predictor() // time derivative of displacement auto& Ad = com_mod.Ad; - auto& Ao = solutions_.old.A; // Use member variable - auto& An = solutions_.current.A; // Use member variable - auto& Yo = solutions_.old.Y; // Use member variable - auto& Yn = solutions_.current.Y; // Use member variable - auto& Do = solutions_.old.D; // Use member variable - auto& Dn = solutions_.current.D; // Use member variable + auto& Ao = solutions_.old.get_acceleration(); + auto& An = solutions_.current.get_acceleration(); + auto& Yo = solutions_.old.get_velocity(); + auto& Yn = solutions_.current.get_velocity(); + auto& Do = solutions_.old.get_displacement(); + auto& Dn = solutions_.current.get_displacement(); // Prestress initialization if (com_mod.pstEq) { @@ -489,7 +490,7 @@ void Integrator::predictor() // electrophysiology if (eq.phys == Equation_CEP) { - cep_ion::cep_integ(simulation_, iEq, e, Do, solutions_.old.Y); + cep_ion::cep_integ(simulation_, iEq, e, Do, solutions_.old.get_velocity()); } // eqn 86 of Bazilevs 2007 @@ -567,12 +568,12 @@ void Integrator::initiator(Array& Ag, Array& Yg, Array& dmsg << "com_mod.pstEq: " << com_mod.pstEq; #endif - const auto& Ao = solutions_.old.A; // Use member variable - const auto& An = solutions_.current.A; // Use member variable - const auto& Do = solutions_.old.D; // Use member variable - const auto& Dn = solutions_.current.D; // Use member variable - const auto& Yo = solutions_.old.Y; // Use member variable - const auto& Yn = solutions_.current.Y; // Use member variable + const auto& Ao = solutions_.old.get_acceleration(); + const auto& An = solutions_.current.get_acceleration(); + const auto& Do = solutions_.old.get_displacement(); + const auto& Dn = solutions_.current.get_displacement(); + const auto& Yo = solutions_.old.get_velocity(); + const auto& Yn = solutions_.current.get_velocity(); for (int i = 0; i < com_mod.nEq; i++) { auto& eq = com_mod.eq[i]; @@ -674,10 +675,10 @@ void Integrator::corrector() auto& cEq = com_mod.cEq; auto& eq = com_mod.eq[cEq]; - auto& An = solutions_.current.A; // Use member variable + auto& An = solutions_.current.get_acceleration(); auto& Ad = com_mod.Ad; - auto& Dn = solutions_.current.D; - auto& Yn = solutions_.current.Y; + auto& Dn = solutions_.current.get_displacement(); + auto& Yn = solutions_.current.get_velocity(); auto& pS0 = com_mod.pS0; auto& pSa = com_mod.pSa; @@ -932,7 +933,7 @@ void Integrator::corrector_taylor_hood() const auto& eq = com_mod.eq[cEq]; auto& cDmn = com_mod.cDmn; - auto& Yn = solutions_.current.Y; + auto& Yn = solutions_.current.get_velocity(); // Check for something ... // diff --git a/Code/Source/solver/Integrator.h b/Code/Source/solver/Integrator.h index 6fe90852b..486056e01 100644 --- a/Code/Source/solver/Integrator.h +++ b/Code/Source/solver/Integrator.h @@ -8,29 +8,8 @@ #include "Vector.h" #include "Simulation.h" -/** - * @brief Represents solution variables at a single time level - * - * Contains the three primary solution arrays used in time integration: - * A (time derivative), D (integrated variable), and Y (variable) - */ -struct Solution { - Array A; ///< Time derivative (acceleration in structural mechanics) - Array D; ///< Integrated variable (displacement in structural mechanics) - Array Y; ///< Variable (velocity in structural mechanics) -}; - -/** - * @brief Holds solution state at old and current time levels - * - * Contains solution arrays at two time levels for time integration: - * - old: Previous converged solution at time n - * - current: Current solution being computed at time n+1 - */ -struct SolutionStates { - Solution old; ///< Previous converged solution at time n (Ao, Do, Yo) - Solution current; ///< Current solution being computed at time n+1 (An, Dn, Yn) -}; +// Note: Solution and SolutionStates structs are defined in ComMod.h +// and available via Simulation.h include chain /** * @brief Integrator class encapsulates the Newton iteration loop for time integration @@ -51,11 +30,9 @@ class Integrator { * @brief Construct a new Integrator object * * @param simulation Pointer to the Simulation object containing problem data - * @param Ao Old acceleration array (takes ownership via move) - * @param Do Old displacement array (takes ownership via move) - * @param Yo Old velocity array (takes ownership via move) + * @param solutions Solution states containing old time level arrays (takes ownership via move) */ - Integrator(Simulation* simulation, Array&& Ao, Array&& Do, Array&& Yo); + Integrator(Simulation* simulation, SolutionStates&& solutions); /** * @brief Destroy the Integrator object @@ -102,51 +79,15 @@ class Integrator { */ Array& get_Dg() { return Dg_; } - /** - * @brief Get reference to An (new time derivative of variables at n+1) - * - * @return Reference to An array (acceleration at next time step) - */ - Array& get_An() { return solutions_.current.A; } - - /** - * @brief Get reference to Dn (new integrated variables at n+1) - * - * @return Reference to Dn array (displacement at next time step) - */ - Array& get_Dn() { return solutions_.current.D; } - - /** - * @brief Get reference to Yn (new variables at n+1) - * - * @return Reference to Yn array (velocity at next time step) - */ - Array& get_Yn() { return solutions_.current.Y; } - - /** - * @brief Get reference to Ao (old time derivative of variables at n) - * - * @return Reference to Ao array (acceleration at current time step) - */ - Array& get_Ao() { return solutions_.old.A; } - - /** - * @brief Get reference to Do (old integrated variables at n) - * - * @return Reference to Do array (displacement at current time step) - */ - Array& get_Do() { return solutions_.old.D; } - - /** - * @brief Get reference to Yo (old variables at n) - * - * @return Reference to Yo array (velocity at current time step) - */ - Array& get_Yo() { return solutions_.old.Y; } - /** * @brief Get reference to solution states struct * + * Provides access to all solution arrays at old (n) and current (n+1) time levels. + * Use this to access An, Dn, Yn (current) and Ao, Do, Yo (old) via: + * auto& solutions = integrator.get_solutions(); + * auto& An = solutions.current.get_acceleration(); + * auto& Do = solutions.old.get_displacement(); + * * @return Reference to SolutionStates struct containing all solution arrays */ SolutionStates& get_solutions() { return solutions_; } From 695f9d64bb08bd5c2cb646dcc24f5a57b44d7047 Mon Sep 17 00:00:00 2001 From: shiyi Date: Sun, 25 Jan 2026 19:48:16 +0000 Subject: [PATCH 24/33] Update boundary condition functions to use SolutionStates --- Code/Source/solver/Integrator.cpp | 14 ++--- Code/Source/solver/Simulation.cpp | 12 ++-- Code/Source/solver/Simulation.h | 4 +- Code/Source/solver/Vector.h | 1 + Code/Source/solver/baf_ini.cpp | 17 +++++- Code/Source/solver/initialize.cpp | 21 ++++++- Code/Source/solver/main.cpp | 22 +++++--- Code/Source/solver/ris.cpp | 14 ++++- Code/Source/solver/set_bc.cpp | 91 +++++++++++++++++++++++++------ Code/Source/solver/set_bc.h | 24 ++++---- 10 files changed, 156 insertions(+), 64 deletions(-) diff --git a/Code/Source/solver/Integrator.cpp b/Code/Source/solver/Integrator.cpp index faf920343..21a75e920 100644 --- a/Code/Source/solver/Integrator.cpp +++ b/Code/Source/solver/Integrator.cpp @@ -104,12 +104,8 @@ bool Integrator::step() { #ifdef debug_integrator_step dmsg << "Set coupled BCs " << std::endl; #endif - set_bc::set_bc_cpl(com_mod, cm_mod, solutions_.current.get_acceleration(), solutions_.current.get_velocity(), - solutions_.current.get_displacement(), solutions_.old.get_velocity(), - solutions_.old.get_acceleration(), solutions_.old.get_displacement()); - set_bc::set_bc_dir(com_mod, solutions_.current.get_acceleration(), solutions_.current.get_velocity(), - solutions_.current.get_displacement(), solutions_.old.get_velocity(), - solutions_.old.get_acceleration(), solutions_.old.get_displacement()); + set_bc::set_bc_cpl(com_mod, cm_mod, solutions_); + set_bc::set_bc_dir(com_mod, solutions_); } // Initiator step for Generalized α-Method (quantities at n+am, n+af). @@ -277,15 +273,15 @@ void Integrator::apply_boundary_conditions() { Dg_.write("Dg_vor_neu" + istr_); // Apply Neumman or Traction boundary conditions - set_bc::set_bc_neu(com_mod, cm_mod, Yg_, Dg_, solutions_.current.get_velocity(), solutions_.old.get_displacement()); + set_bc::set_bc_neu(com_mod, cm_mod, Yg_, Dg_, solutions_); // Apply CMM BC conditions if (!com_mod.cmmInit) { - set_bc::set_bc_cmm(com_mod, cm_mod, Ag_, Dg_, solutions_.old.get_displacement()); + set_bc::set_bc_cmm(com_mod, cm_mod, Ag_, Dg_, solutions_); } // Apply weakly applied Dirichlet BCs - set_bc::set_bc_dir_w(com_mod, Yg_, Dg_, solutions_.old.get_displacement()); + set_bc::set_bc_dir_w(com_mod, Yg_, Dg_, solutions_); if (com_mod.risFlag) { ris::ris_resbc(com_mod, Yg_, Dg_, solutions_.old.get_displacement()); diff --git a/Code/Source/solver/Simulation.cpp b/Code/Source/solver/Simulation.cpp index 76876cc39..7e6d56523 100644 --- a/Code/Source/solver/Simulation.cpp +++ b/Code/Source/solver/Simulation.cpp @@ -93,15 +93,13 @@ void Simulation::set_module_parameters() /// @brief Initialize the Integrator object after simulation setup is complete /// -/// This should be called at the end of initialize() after Ao, Do, Yo have been -/// fully initialized. The Integrator takes ownership of these arrays. +/// This should be called at the end of initialize() after solution states have been +/// fully initialized. The Integrator takes ownership of these solution states. /// -/// @param Ao Old acceleration array (moved into Integrator) -/// @param Do Old displacement array (moved into Integrator) -/// @param Yo Old velocity array (moved into Integrator) -void Simulation::initialize_integrator(Array&& Ao, Array&& Do, Array&& Yo) +/// @param solutions Solution states containing old acceleration, displacement, and velocity +void Simulation::initialize_integrator(SolutionStates&& solutions) { - integrator_ = std::make_unique(this, std::move(Ao), std::move(Do), std::move(Yo)); + integrator_ = std::make_unique(this, std::move(solutions)); } /// @brief Get reference to the Integrator object diff --git a/Code/Source/solver/Simulation.h b/Code/Source/solver/Simulation.h index 741aa3be3..680cdddfc 100644 --- a/Code/Source/solver/Simulation.h +++ b/Code/Source/solver/Simulation.h @@ -29,8 +29,8 @@ class Simulation { Integrator& get_integrator(); // Initialize the Integrator object after simulation setup is complete - // Takes ownership of Ao, Do, Yo arrays via move semantics - void initialize_integrator(Array&& Ao, Array&& Do, Array&& Yo); + // Takes ownership of solution states via move semantics + void initialize_integrator(SolutionStates&& solutions); // Read a solver paramerer input XML file. void read_parameters(const std::string& fileName); diff --git a/Code/Source/solver/Vector.h b/Code/Source/solver/Vector.h index d809546c9..d6b40f985 100644 --- a/Code/Source/solver/Vector.h +++ b/Code/Source/solver/Vector.h @@ -5,6 +5,7 @@ #define VECTOR_H #include +#include #include #include #include diff --git a/Code/Source/solver/baf_ini.cpp b/Code/Source/solver/baf_ini.cpp index faeec7b59..77171bc81 100644 --- a/Code/Source/solver/baf_ini.cpp +++ b/Code/Source/solver/baf_ini.cpp @@ -133,7 +133,12 @@ void baf_ini(Simulation* simulation, const Array& Ao, Array& Do, } if (!com_mod.stFileFlag) { - set_bc::rcr_init(com_mod, cm_mod, Ao, Do, Yo); + // Create temporary SolutionStates for set_bc calls + SolutionStates temp_solutions; + temp_solutions.old.A = Ao; + temp_solutions.old.D = Do; + temp_solutions.old.Y = Yo; + set_bc::rcr_init(com_mod, cm_mod, temp_solutions); } if (com_mod.cplBC.useGenBC) { @@ -145,7 +150,15 @@ void baf_ini(Simulation* simulation, const Array& Ao, Array& Do, } if (com_mod.cplBC.schm != CplBCType::cplBC_E) { - set_bc::calc_der_cpl_bc(com_mod, cm_mod, Yo, Yo, Do, Yo, Ao, Do); + // Create temporary SolutionStates for set_bc calls + SolutionStates temp_solutions; + temp_solutions.old.A = Ao; + temp_solutions.old.D = Do; + temp_solutions.old.Y = Yo; + temp_solutions.current.A = Yo; + temp_solutions.current.Y = Yo; + temp_solutions.current.D = Do; + set_bc::calc_der_cpl_bc(com_mod, cm_mod, temp_solutions); } } diff --git a/Code/Source/solver/initialize.cpp b/Code/Source/solver/initialize.cpp index 737a9d261..3c253b207 100644 --- a/Code/Source/solver/initialize.cpp +++ b/Code/Source/solver/initialize.cpp @@ -830,7 +830,18 @@ void initialize(Simulation* simulation, Vector& timeP) // // Modifies Ao, Yo, Do (local variables) // - set_bc::set_bc_dir(com_mod, Ao, Yo, Do, Yo, Ao, Do); + SolutionStates temp_solutions; + temp_solutions.old.A = Ao; + temp_solutions.old.Y = Yo; + temp_solutions.old.D = Do; + temp_solutions.current.A = Ao; + temp_solutions.current.Y = Yo; + temp_solutions.current.D = Do; + set_bc::set_bc_dir(com_mod, temp_solutions); + // Copy back modified values + Ao = temp_solutions.current.A; + Yo = temp_solutions.current.Y; + Do = temp_solutions.current.D; // Preparing TXT files (pass local Ao, Do, and Yo since An, Dn, and Yn haven't been created in Integrator yet) txt_ns::txt(simulation, true, Ao, Do, Yo, Do); @@ -845,7 +856,13 @@ void initialize(Simulation* simulation, Vector& timeP) // Create Integrator now that Ao, Do, Yo are fully initialized // The Integrator takes ownership of Ao, Do, Yo via move semantics - simulation->initialize_integrator(std::move(Ao), std::move(Do), std::move(Yo)); + // Create SolutionStates and move arrays into it + SolutionStates initial_solutions; + initial_solutions.old.A = std::move(Ao); + initial_solutions.old.D = std::move(Do); + initial_solutions.old.Y = std::move(Yo); + + simulation->initialize_integrator(std::move(initial_solutions)); } //----------- diff --git a/Code/Source/solver/main.cpp b/Code/Source/solver/main.cpp index d1ea8d56b..a11e3a960 100644 --- a/Code/Source/solver/main.cpp +++ b/Code/Source/solver/main.cpp @@ -232,13 +232,17 @@ void iterate_solution(Simulation* simulation) auto& Rd = com_mod.Rd; // Residual of the displacement equation auto& Kd = com_mod.Kd; // LHS matrix for displacement equation - auto& Ao = integrator.get_Ao(); // Old time derivative of variables (acceleration) - auto& Yo = integrator.get_Yo(); // Old variables (velocity) - auto& Do = integrator.get_Do(); // Old integrated variables (displacement) + // Get reference to solution states from integrator + auto& solutions = integrator.get_solutions(); - auto& An = integrator.get_An(); // New time derivative of variables (acceleration) - auto& Yn = integrator.get_Yn(); // New variables (velocity) - auto& Dn = integrator.get_Dn(); // New integrated variables (displacement) + // Local aliases for convenience + auto& Ao = solutions.old.get_acceleration(); // Old time derivative of variables (acceleration) + auto& Yo = solutions.old.get_velocity(); // Old variables (velocity) + auto& Do = solutions.old.get_displacement(); // Old integrated variables (displacement) + + auto& An = solutions.current.get_acceleration(); // New time derivative of variables (acceleration) + auto& Yn = solutions.current.get_velocity(); // New variables (velocity) + auto& Dn = solutions.current.get_displacement(); // New integrated variables (displacement) bool l1 = false; bool l2 = false; @@ -298,7 +302,7 @@ void iterate_solution(Simulation* simulation) // Compute mesh properties to check if remeshing is required // if (com_mod.mvMsh && com_mod.rmsh.isReqd) { - read_msh_ns::calc_mesh_props(com_mod, cm_mod, com_mod.nMsh, com_mod.msh, integrator.get_Do()); + read_msh_ns::calc_mesh_props(com_mod, cm_mod, com_mod.nMsh, com_mod.msh, Do); if (com_mod.resetSim) { #ifdef debug_iterate_solution dmsg << "#### resetSim is true " << std::endl; @@ -326,11 +330,11 @@ void iterate_solution(Simulation* simulation) dmsg << "Apply Dirichlet BCs strongly ..." << std::endl; #endif - set_bc::set_bc_dir(com_mod, An, Yn, Dn, Yo, Ao, Do); + set_bc::set_bc_dir(com_mod, solutions); if (com_mod.urisFlag) {uris::uris_calc_sdf(com_mod);} - iterate_precomputed_time(simulation, integrator.get_An(), integrator.get_Yn(), integrator.get_Ao(), integrator.get_Yo(), integrator.get_Do()); + iterate_precomputed_time(simulation, An, Yn, Ao, Yo, Do); // Inner loop for Newton iteration // diff --git a/Code/Source/solver/ris.cpp b/Code/Source/solver/ris.cpp index 962a290e0..aa4de6da7 100644 --- a/Code/Source/solver/ris.cpp +++ b/Code/Source/solver/ris.cpp @@ -132,7 +132,9 @@ void ris_resbc(ComMod& com_mod, const Array& Yg, const Array& Dg if (cPhys == EquationType::phys_fluid) { // Build the correct BC - set_bc::set_bc_dir_wl(com_mod, lBc, msh[iM], msh[iM].fa[iFa], Yg, Dg, Do); + SolutionStates temp_solutions; + temp_solutions.old.D = Do; + set_bc::set_bc_dir_wl(com_mod, lBc, msh[iM], msh[iM].fa[iFa], Yg, Dg, temp_solutions); } lBc.gx.clear(); } @@ -389,12 +391,18 @@ void ris0d_bc(ComMod& com_mod, CmMod& cm_mod, const Array& Yg, const Arr // Apply bc Dir lBc.gx.resize(msh[iM].fa[iFa].nNo); lBc.gx = 1.0; - set_bc::set_bc_dir_wl(com_mod, lBc, msh[iM], msh[iM].fa[iFa], Yg, Dg, Do); + SolutionStates temp_solutions; + temp_solutions.old.D = Do; + set_bc::set_bc_dir_wl(com_mod, lBc, msh[iM], msh[iM].fa[iFa], Yg, Dg, temp_solutions); lBc.gx.clear(); lBc.eDrn.clear(); } else { // Apply Neu bc - set_bc::set_bc_neu_l(com_mod, cm_mod, eq[cEq].bc[iBc], msh[iM].fa[iFa], Yg, Dg, Yn, Do); + SolutionStates temp_solutions; + temp_solutions.current.Y = Yn; + temp_solutions.old.D = Do; + set_bc::set_bc_neu_l(com_mod, cm_mod, eq[cEq].bc[iBc], msh[iM].fa[iFa], Yg, Dg, temp_solutions); + Yn = temp_solutions.current.Y; } } diff --git a/Code/Source/solver/set_bc.cpp b/Code/Source/solver/set_bc.cpp index 87b1c6e39..7c871899e 100644 --- a/Code/Source/solver/set_bc.cpp +++ b/Code/Source/solver/set_bc.cpp @@ -27,8 +27,16 @@ namespace set_bc { /// matrix M ~ dP/dQ stored in eq.bc[iBc].r. /// @param com_mod /// @param cm_mod -void calc_der_cpl_bc(ComMod& com_mod, const CmMod& cm_mod, const Array& An, Array& Yn, const Array& Dn, const Array& Yo, const Array& Ao, const Array& Do) +void calc_der_cpl_bc(ComMod& com_mod, const CmMod& cm_mod, SolutionStates& solutions) { + // Local aliases for solution arrays + auto& An = solutions.current.get_acceleration(); + auto& Yn = solutions.current.get_velocity(); + auto& Dn = solutions.current.get_displacement(); + const auto& Ao = solutions.old.get_acceleration(); + const auto& Yo = solutions.old.get_velocity(); + const auto& Do = solutions.old.get_displacement(); + using namespace consts; #define n_debug_calc_der_cpl_bc @@ -525,8 +533,13 @@ void RCR_Integ_X(ComMod& com_mod, const CmMod& cm_mod, int istat) /// /// Replaces 'SUBROUTINE RCRINIT()' // -void rcr_init(ComMod& com_mod, const CmMod& cm_mod, const Array& Ao, const Array& Do, const Array& Yo) +void rcr_init(ComMod& com_mod, const CmMod& cm_mod, SolutionStates& solutions) { + // Local aliases for old solution arrays + const auto& Ao = solutions.old.get_acceleration(); + const auto& Do = solutions.old.get_displacement(); + const auto& Yo = solutions.old.get_velocity(); + using namespace consts; const int iEq = 0; @@ -560,8 +573,11 @@ void rcr_init(ComMod& com_mod, const CmMod& cm_mod, const Array& Ao, con /// @brief Below defines the SET_BC methods for the Coupled Momentum Method (CMM) // -void set_bc_cmm(ComMod& com_mod, const CmMod& cm_mod, const Array& Ag, const Array& Dg, const Array& Do) +void set_bc_cmm(ComMod& com_mod, const CmMod& cm_mod, const Array& Ag, const Array& Dg, SolutionStates& solutions) { + // Local alias for old displacement + const auto& Do = solutions.old.get_displacement(); + using namespace consts; int cEq = com_mod.cEq; @@ -581,12 +597,15 @@ void set_bc_cmm(ComMod& com_mod, const CmMod& cm_mod, const Array& Ag, c throw std::runtime_error("[set_bc_cmm] CMM equation is formulated for tetrahedral elements (volume) and triangular (surface) elements"); } - set_bc_cmm_l(com_mod, cm_mod, com_mod.msh[iM].fa[iFa], Ag, Dg, Do); + set_bc_cmm_l(com_mod, cm_mod, com_mod.msh[iM].fa[iFa], Ag, Dg, solutions); } } -void set_bc_cmm_l(ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, const Array& Ag, const Array& Dg, const Array& Do) +void set_bc_cmm_l(ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, const Array& Ag, const Array& Dg, SolutionStates& solutions) { + // Local alias for old displacement + const auto& Do = solutions.old.get_displacement(); + using namespace consts; const int nsd = com_mod.nsd; @@ -645,8 +664,16 @@ void set_bc_cmm_l(ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, con /// @brief Coupled BC quantities are computed here. /// Reproduces the Fortran 'SETBCCPL()' subrotutine. // -void set_bc_cpl(ComMod& com_mod, CmMod& cm_mod, const Array& An, Array& Yn, const Array& Dn, const Array& Yo, const Array& Ao, const Array& Do) +void set_bc_cpl(ComMod& com_mod, CmMod& cm_mod, SolutionStates& solutions) { + // Local aliases for solution arrays + auto& An = solutions.current.get_acceleration(); + auto& Yn = solutions.current.get_velocity(); + auto& Dn = solutions.current.get_displacement(); + const auto& Ao = solutions.old.get_acceleration(); + const auto& Yo = solutions.old.get_velocity(); + const auto& Do = solutions.old.get_displacement(); + static double absTol = 1.E-8, relTol = 1.E-5; using namespace consts; @@ -668,7 +695,7 @@ void set_bc_cpl(ComMod& com_mod, CmMod& cm_mod, const Array& An, Array& An, Array& lA, Array& lY, Array& lD, const Array& Yo, const Array& Ao, const Array& Do) +void set_bc_dir(ComMod& com_mod, SolutionStates& solutions) { + // Local aliases for solution arrays + auto& lA = solutions.current.get_acceleration(); + auto& lY = solutions.current.get_velocity(); + auto& lD = solutions.current.get_displacement(); + const auto& Yo = solutions.old.get_velocity(); + const auto& Ao = solutions.old.get_acceleration(); + const auto& Do = solutions.old.get_displacement(); + using namespace consts; #define n_set_bc_dir @@ -1043,8 +1078,11 @@ void set_bc_dir_l(ComMod& com_mod, const bcType& lBc, const faceType& lFa, Array /// @brief Weak treatment of Dirichlet boundary conditions // -void set_bc_dir_w(ComMod& com_mod, const Array& Yg, const Array& Dg, const Array& Do) +void set_bc_dir_w(ComMod& com_mod, const Array& Yg, const Array& Dg, SolutionStates& solutions) { + // Local alias for old displacement + const auto& Do = solutions.old.get_displacement(); + using namespace consts; const int cEq = com_mod.cEq; @@ -1057,14 +1095,17 @@ void set_bc_dir_w(ComMod& com_mod, const Array& Yg, const Array& if (!bc.weakDir) { continue; } - set_bc_dir_wl(com_mod, bc, com_mod.msh[iM], com_mod.msh[iM].fa[iFa], Yg, Dg, Do); + set_bc_dir_wl(com_mod, bc, com_mod.msh[iM], com_mod.msh[iM].fa[iFa], Yg, Dg, solutions); } } /// @brief Reproduces Fortran 'SETBCDIRWL'. // -void set_bc_dir_wl(ComMod& com_mod, const bcType& lBc, const mshType& lM, const faceType& lFa, const Array& Yg, const Array& Dg, const Array& Do) +void set_bc_dir_wl(ComMod& com_mod, const bcType& lBc, const mshType& lM, const faceType& lFa, const Array& Yg, const Array& Dg, SolutionStates& solutions) { + // Local alias for old displacement + const auto& Do = solutions.old.get_displacement(); + using namespace consts; #define n_debug_set_bc_dir_wl @@ -1292,8 +1333,12 @@ void set_bc_dir_wl(ComMod& com_mod, const bcType& lBc, const mshType& lM, const /// @brief Set outlet BCs. // -void set_bc_neu(ComMod& com_mod, const CmMod& cm_mod, const Array& Yg, const Array& Dg, Array& Yn, const Array& Do) +void set_bc_neu(ComMod& com_mod, const CmMod& cm_mod, const Array& Yg, const Array& Dg, SolutionStates& solutions) { + // Local aliases for solution arrays + auto& Yn = solutions.current.get_velocity(); + const auto& Do = solutions.old.get_displacement(); + using namespace consts; #define n_debug_set_bc_neu @@ -1324,18 +1369,22 @@ void set_bc_neu(ComMod& com_mod, const CmMod& cm_mod, const Array& Yg, c dmsg << "iFa: " << iFa+1; dmsg << "name: " << com_mod.msh[iM].fa[iFa].name; #endif - set_bc_neu_l(com_mod, cm_mod, bc, com_mod.msh[iM].fa[iFa], Yg, Dg, Yn, Do); + set_bc_neu_l(com_mod, cm_mod, bc, com_mod.msh[iM].fa[iFa], Yg, Dg, solutions); } else if (utils::btest(bc.bType,iBC_trac)) { - set_bc_trac_l(com_mod, cm_mod, bc, com_mod.msh[iM].fa[iFa], Do); + set_bc_trac_l(com_mod, cm_mod, bc, com_mod.msh[iM].fa[iFa], solutions); } } } /// @brief Set Neumann BC // -void set_bc_neu_l(ComMod& com_mod, const CmMod& cm_mod, const bcType& lBc, const faceType& lFa, const Array& Yg, const Array& Dg, Array& Yn, const Array& Do) +void set_bc_neu_l(ComMod& com_mod, const CmMod& cm_mod, const bcType& lBc, const faceType& lFa, const Array& Yg, const Array& Dg, SolutionStates& solutions) { + // Local aliases for solution arrays + auto& Yn = solutions.current.get_velocity(); + const auto& Do = solutions.old.get_displacement(); + using namespace consts; #define n_debug_set_bc_neu_l @@ -1442,15 +1491,18 @@ void set_bc_neu_l(ComMod& com_mod, const CmMod& cm_mod, const bcType& lBc, const } // Now treat Robin BC (stiffness and damping) here if (lBc.robin_bc.is_initialized()) { - set_bc_rbnl(com_mod, lFa, lBc.robin_bc, Yg, Dg, Do); + set_bc_rbnl(com_mod, lFa, lBc.robin_bc, Yg, Dg, solutions); } } /// @brief Set Robin BC contribution to residual and tangent // void set_bc_rbnl(ComMod& com_mod, const faceType& lFa, const RobinBoundaryCondition& robin_bc, - const Array& Yg, const Array& Dg, const Array& Do) + const Array& Yg, const Array& Dg, SolutionStates& solutions) { + // Local alias for old displacement + const auto& Do = solutions.old.get_displacement(); + using namespace consts; #define n_debug_set_bc_rbnl_l @@ -1698,8 +1750,11 @@ void set_bc_rbnl(ComMod& com_mod, const faceType& lFa, const RobinBoundaryCondit /// @brief Set Traction BC // -void set_bc_trac_l(ComMod& com_mod, const CmMod& cm_mod, const bcType& lBc, const faceType& lFa, const Array& Do) +void set_bc_trac_l(ComMod& com_mod, const CmMod& cm_mod, const bcType& lBc, const faceType& lFa, SolutionStates& solutions) { + // Local alias for old displacement + const auto& Do = solutions.old.get_displacement(); + using namespace consts; #define n_debug_set_bc_trac_l diff --git a/Code/Source/solver/set_bc.h b/Code/Source/solver/set_bc.h index 65fc9ea94..8428152bc 100644 --- a/Code/Source/solver/set_bc.h +++ b/Code/Source/solver/set_bc.h @@ -12,33 +12,33 @@ namespace set_bc { -void calc_der_cpl_bc(ComMod& com_mod, const CmMod& cm_mod, const Array& An, Array& Yn, const Array& Dn, const Array& Yo, const Array& Ao, const Array& Do); +void calc_der_cpl_bc(ComMod& com_mod, const CmMod& cm_mod, SolutionStates& solutions); void cplBC_Integ_X(ComMod& com_mod, const CmMod& cm_mod, const bool RCRflag); void genBC_Integ_X(ComMod& com_mod, const CmMod& cm_mod, const std::string& genFlag); -void rcr_init(ComMod& com_mod, const CmMod& cm_mod, const Array& Ao, const Array& Do, const Array& Yo); +void rcr_init(ComMod& com_mod, const CmMod& cm_mod, SolutionStates& solutions); void RCR_Integ_X(ComMod& com_mod, const CmMod& cm_mod, int istat); -void set_bc_cmm(ComMod& com_mod, const CmMod& cm_mod, const Array& Ag, const Array& Dg, const Array& Do); -void set_bc_cmm_l(ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, const Array& Ag, const Array& Dg, const Array& Do); +void set_bc_cmm(ComMod& com_mod, const CmMod& cm_mod, const Array& Ag, const Array& Dg, SolutionStates& solutions); +void set_bc_cmm_l(ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, const Array& Ag, const Array& Dg, SolutionStates& solutions); -void set_bc_cpl(ComMod& com_mod, CmMod& cm_mod, const Array& An, Array& Yn, const Array& Dn, const Array& Yo, const Array& Ao, const Array& Do); +void set_bc_cpl(ComMod& com_mod, CmMod& cm_mod, SolutionStates& solutions); -void set_bc_dir(ComMod& com_mod, Array& lA, Array& lY, Array& lD, const Array& Yo, const Array& Ao, const Array& Do); +void set_bc_dir(ComMod& com_mod, SolutionStates& solutions); void set_bc_dir_l(ComMod& com_mod, const bcType& lBc, const faceType& lFa, Array& lA, Array& lY, int lDof); -void set_bc_dir_w(ComMod& com_mod, const Array& Yg, const Array& Dg, const Array& Do); -void set_bc_dir_wl(ComMod& com_mod, const bcType& lBc, const mshType& lM, const faceType& lFa, const Array& Yg, const Array& Dg, const Array& Do); +void set_bc_dir_w(ComMod& com_mod, const Array& Yg, const Array& Dg, SolutionStates& solutions); +void set_bc_dir_wl(ComMod& com_mod, const bcType& lBc, const mshType& lM, const faceType& lFa, const Array& Yg, const Array& Dg, SolutionStates& solutions); -void set_bc_neu(ComMod& com_mod, const CmMod& cm_mod, const Array& Yg, const Array& Dg, Array& Yn, const Array& Do); -void set_bc_neu_l(ComMod& com_mod, const CmMod& cm_mod, const bcType& lBc, const faceType& lFa, const Array& Yg, const Array& Dg, Array& Yn, const Array& Do); +void set_bc_neu(ComMod& com_mod, const CmMod& cm_mod, const Array& Yg, const Array& Dg, SolutionStates& solutions); +void set_bc_neu_l(ComMod& com_mod, const CmMod& cm_mod, const bcType& lBc, const faceType& lFa, const Array& Yg, const Array& Dg, SolutionStates& solutions); void set_bc_rbnl(ComMod& com_mod, const faceType& lFa, const RobinBoundaryCondition& robin_bc, - const Array& Yg, const Array& Dg, const Array& Do); + const Array& Yg, const Array& Dg, SolutionStates& solutions); -void set_bc_trac_l(ComMod& com_mod, const CmMod& cm_mod, const bcType& lBc, const faceType& lFa, const Array& Do); +void set_bc_trac_l(ComMod& com_mod, const CmMod& cm_mod, const bcType& lBc, const faceType& lFa, SolutionStates& solutions); void set_bc_undef_neu(ComMod& com_mod); From 75db5170ddf07ed405d3a31a6835d2cc7ccd2ace Mon Sep 17 00:00:00 2001 From: shiyi Date: Sun, 25 Jan 2026 20:22:47 +0000 Subject: [PATCH 25/33] Refactor ris functions to use SolutionStates and remove temp_solutions workarounds --- Code/Source/solver/Integrator.cpp | 4 +-- Code/Source/solver/main.cpp | 6 ++-- Code/Source/solver/ris.cpp | 55 +++++++++++++++++++++---------- Code/Source/solver/ris.h | 14 ++++---- 4 files changed, 49 insertions(+), 30 deletions(-) diff --git a/Code/Source/solver/Integrator.cpp b/Code/Source/solver/Integrator.cpp index 21a75e920..e35579fa2 100644 --- a/Code/Source/solver/Integrator.cpp +++ b/Code/Source/solver/Integrator.cpp @@ -284,11 +284,11 @@ void Integrator::apply_boundary_conditions() { set_bc::set_bc_dir_w(com_mod, Yg_, Dg_, solutions_); if (com_mod.risFlag) { - ris::ris_resbc(com_mod, Yg_, Dg_, solutions_.old.get_displacement()); + ris::ris_resbc(com_mod, Yg_, Dg_, solutions_); } if (com_mod.ris0DFlag) { - ris::ris0d_bc(com_mod, cm_mod, Yg_, Dg_, solutions_.current.get_velocity(), solutions_.old.get_displacement()); + ris::ris0d_bc(com_mod, cm_mod, Yg_, Dg_, solutions_); } // Apply contact model and add its contribution to residual diff --git a/Code/Source/solver/main.cpp b/Code/Source/solver/main.cpp index a11e3a960..fcc62a3e1 100644 --- a/Code/Source/solver/main.cpp +++ b/Code/Source/solver/main.cpp @@ -364,7 +364,7 @@ void iterate_solution(Simulation* simulation) */ if (com_mod.risFlag) { - ris::ris_meanq(com_mod, cm_mod, An, Dn, Yn, Do); + ris::ris_meanq(com_mod, cm_mod, solutions); ris::ris_status(com_mod, cm_mod); if (cm.mas(cm_mod)) { std::cout << "Iteration: " << com_mod.cTS << std::endl; @@ -382,7 +382,7 @@ void iterate_solution(Simulation* simulation) std::cout << "Valve status just changed. Do not update" << std::endl; } } else { - ris::ris_updater(com_mod, cm_mod, An, Dn, Yn, Ao, Do, Yo); + ris::ris_updater(com_mod, cm_mod, solutions); } // goto label_11; } @@ -500,7 +500,7 @@ void iterate_solution(Simulation* simulation) // [HZ] Part related to RIS0D if (cEq == 0 && com_mod.ris0DFlag) { - ris::ris0d_status(com_mod, cm_mod, An, Dn, Yn, Do); + ris::ris0d_status(com_mod, cm_mod, solutions); } // [HZ] Part related to unfitted RIS diff --git a/Code/Source/solver/ris.cpp b/Code/Source/solver/ris.cpp index aa4de6da7..a1426abae 100644 --- a/Code/Source/solver/ris.cpp +++ b/Code/Source/solver/ris.cpp @@ -13,8 +13,14 @@ namespace ris { /// @brief This subroutine computes the mean pressure and flux on the ris surface -void ris_meanq(ComMod& com_mod, CmMod& cm_mod, Array& An, Array& Dn, Array& Yn, const Array& Do) +void ris_meanq(ComMod& com_mod, CmMod& cm_mod, SolutionStates& solutions) { + // Local aliases for solution arrays + auto& An = solutions.current.get_acceleration(); + auto& Yn = solutions.current.get_velocity(); + auto& Dn = solutions.current.get_displacement(); + const auto& Do = solutions.old.get_displacement(); + #define n_debug_ris_meanq #ifdef debug_ris_meanq DebugMsg dmsg(__func__, com_mod.cm.idcm()); @@ -84,8 +90,11 @@ void ris_meanq(ComMod& com_mod, CmMod& cm_mod, Array& An, Array& } /// @brief Weak treatment of RIS resistance boundary conditions -void ris_resbc(ComMod& com_mod, const Array& Yg, const Array& Dg, const Array& Do) +void ris_resbc(ComMod& com_mod, const Array& Yg, const Array& Dg, SolutionStates& solutions) { + // Local alias for old displacement + const auto& Do = solutions.old.get_displacement(); + using namespace consts; #define n_debug_ris_resbc #ifdef debug_ris_resbc @@ -132,9 +141,7 @@ void ris_resbc(ComMod& com_mod, const Array& Yg, const Array& Dg if (cPhys == EquationType::phys_fluid) { // Build the correct BC - SolutionStates temp_solutions; - temp_solutions.old.D = Do; - set_bc::set_bc_dir_wl(com_mod, lBc, msh[iM], msh[iM].fa[iFa], Yg, Dg, temp_solutions); + set_bc::set_bc_dir_wl(com_mod, lBc, msh[iM], msh[iM].fa[iFa], Yg, Dg, solutions); } lBc.gx.clear(); } @@ -144,7 +151,7 @@ void ris_resbc(ComMod& com_mod, const Array& Yg, const Array& Dg void setbc_ris(ComMod& com_mod, const bcType& lBc, const mshType& lM, const faceType& lFa, - const Array& Yg, const Array& Dg, const Array& Do) + const Array& Yg, const Array& Dg, SolutionStates& solutions) { // [HZ] looks not needed in the current implementation } @@ -152,8 +159,16 @@ void setbc_ris(ComMod& com_mod, const bcType& lBc, const mshType& lM, const face /// @brief This subroutine updates the resistance and activation flag for the /// closed and open configurations of the RIS surfaces -void ris_updater(ComMod& com_mod, CmMod& cm_mod, Array& An, Array& Dn, Array& Yn, Array& Ao, Array& Do, Array& Yo) +void ris_updater(ComMod& com_mod, CmMod& cm_mod, SolutionStates& solutions) { + // Local aliases for solution arrays + auto& An = solutions.current.get_acceleration(); + auto& Yn = solutions.current.get_velocity(); + auto& Dn = solutions.current.get_displacement(); + auto& Ao = solutions.old.get_acceleration(); + auto& Yo = solutions.old.get_velocity(); + auto& Do = solutions.old.get_displacement(); + #define n_debug_ris_updater #ifdef debug_ris_updater DebugMsg dmsg(__func__, com_mod.cm.idcm()); @@ -345,14 +360,18 @@ void clean_r_ris(ComMod& com_mod) // [HZ] looks not needed in the current implementation } -void setbcdir_ris(ComMod& com_mod, Array& lA, Array& lY, Array& lD) +void setbcdir_ris(ComMod& com_mod, SolutionStates& solutions) { // [HZ] looks not needed in the current implementation } /// RIS0D code -void ris0d_bc(ComMod& com_mod, CmMod& cm_mod, const Array& Yg, const Array& Dg, Array& Yn, const Array& Do) +void ris0d_bc(ComMod& com_mod, CmMod& cm_mod, const Array& Yg, const Array& Dg, SolutionStates& solutions) { + // Local aliases for solution arrays + auto& Yn = solutions.current.get_velocity(); + const auto& Do = solutions.old.get_displacement(); + using namespace consts; #define n_debug_ris0d_bc @@ -391,26 +410,26 @@ void ris0d_bc(ComMod& com_mod, CmMod& cm_mod, const Array& Yg, const Arr // Apply bc Dir lBc.gx.resize(msh[iM].fa[iFa].nNo); lBc.gx = 1.0; - SolutionStates temp_solutions; - temp_solutions.old.D = Do; - set_bc::set_bc_dir_wl(com_mod, lBc, msh[iM], msh[iM].fa[iFa], Yg, Dg, temp_solutions); + set_bc::set_bc_dir_wl(com_mod, lBc, msh[iM], msh[iM].fa[iFa], Yg, Dg, solutions); lBc.gx.clear(); lBc.eDrn.clear(); } else { // Apply Neu bc - SolutionStates temp_solutions; - temp_solutions.current.Y = Yn; - temp_solutions.old.D = Do; - set_bc::set_bc_neu_l(com_mod, cm_mod, eq[cEq].bc[iBc], msh[iM].fa[iFa], Yg, Dg, temp_solutions); - Yn = temp_solutions.current.Y; + set_bc::set_bc_neu_l(com_mod, cm_mod, eq[cEq].bc[iBc], msh[iM].fa[iFa], Yg, Dg, solutions); } } } -void ris0d_status(ComMod& com_mod, CmMod& cm_mod, Array& An, Array& Dn, Array& Yn, const Array& Do) +void ris0d_status(ComMod& com_mod, CmMod& cm_mod, SolutionStates& solutions) { + // Local aliases for solution arrays + auto& An = solutions.current.get_acceleration(); + auto& Yn = solutions.current.get_velocity(); + auto& Dn = solutions.current.get_displacement(); + const auto& Do = solutions.old.get_displacement(); + using namespace consts; #define n_debug_status diff --git a/Code/Source/solver/ris.h b/Code/Source/solver/ris.h index 2c18a9814..8cc200f6e 100644 --- a/Code/Source/solver/ris.h +++ b/Code/Source/solver/ris.h @@ -8,12 +8,12 @@ namespace ris { -void ris_meanq(ComMod& com_mod, CmMod& cm_mod, Array& An, Array& Dn, Array& Yn, const Array& Do); -void ris_resbc(ComMod& com_mod, const Array& Yg, const Array& Dg, const Array& Do); +void ris_meanq(ComMod& com_mod, CmMod& cm_mod, SolutionStates& solutions); +void ris_resbc(ComMod& com_mod, const Array& Yg, const Array& Dg, SolutionStates& solutions); void setbc_ris(ComMod& com_mod, const bcType& lBc, const mshType& lM, const faceType& lFa, - const Array& Yg, const Array& Dg, const Array& Do); + const Array& Yg, const Array& Dg, SolutionStates& solutions); -void ris_updater(ComMod& com_mod, CmMod& cm_mod, Array& An, Array& Dn, Array& Yn, Array& Ao, Array& Do, Array& Yo); +void ris_updater(ComMod& com_mod, CmMod& cm_mod, SolutionStates& solutions); void ris_status(ComMod& com_mod, CmMod& cm_mod); void doassem_ris(ComMod& com_mod, const int d, const Vector& eqN, @@ -23,11 +23,11 @@ void doassem_velris(ComMod& com_mod, const int d, const Array& eqN, const Array3& lK, const Array& lR); void clean_r_ris(ComMod& com_mod); -void setbcdir_ris(ComMod& com_mod, Array& lA, Array& lY, Array& lD); +void setbcdir_ris(ComMod& com_mod, SolutionStates& solutions); // TODO: RIS 0D code -void ris0d_bc(ComMod& com_mod, CmMod& cm_mod, const Array& Yg, const Array& Dg, Array& Yn, const Array& Do); -void ris0d_status(ComMod& com_mod, CmMod& cm_mod, Array& An, Array& Dn, Array& Yn, const Array& Do); +void ris0d_bc(ComMod& com_mod, CmMod& cm_mod, const Array& Yg, const Array& Dg, SolutionStates& solutions); +void ris0d_status(ComMod& com_mod, CmMod& cm_mod, SolutionStates& solutions); }; From f0eacd7fe5dec667712aaa03755bf53a7185bf1b Mon Sep 17 00:00:00 2001 From: shiyi Date: Sun, 25 Jan 2026 20:33:41 +0000 Subject: [PATCH 26/33] Update eq_assem functions to use SolutionStates --- Code/Source/solver/Integrator.cpp | 2 +- Code/Source/solver/eq_assem.cpp | 21 +++++++++++++++++---- Code/Source/solver/eq_assem.h | 8 ++++---- Code/Source/solver/set_bc.cpp | 6 +++--- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/Code/Source/solver/Integrator.cpp b/Code/Source/solver/Integrator.cpp index e35579fa2..976aea6c2 100644 --- a/Code/Source/solver/Integrator.cpp +++ b/Code/Source/solver/Integrator.cpp @@ -248,7 +248,7 @@ void Integrator::assemble_equations() { #endif for (int iM = 0; iM < com_mod.nMsh; iM++) { - eq_assem::global_eq_assem(com_mod, cep_mod, com_mod.msh[iM], Ag_, Yg_, Dg_, solutions_.old.get_displacement()); + eq_assem::global_eq_assem(com_mod, cep_mod, com_mod.msh[iM], Ag_, Yg_, Dg_, solutions_); } // Debug output diff --git a/Code/Source/solver/eq_assem.cpp b/Code/Source/solver/eq_assem.cpp index 6521eea1d..b157cdcaf 100644 --- a/Code/Source/solver/eq_assem.cpp +++ b/Code/Source/solver/eq_assem.cpp @@ -28,8 +28,11 @@ namespace eq_assem { -void b_assem_neu_bc(ComMod& com_mod, const faceType& lFa, const Vector& hg, const Array& Yg, const Array& Do) +void b_assem_neu_bc(ComMod& com_mod, const faceType& lFa, const Vector& hg, const Array& Yg, SolutionStates& solutions) { + // Local alias for old displacement + const auto& Do = solutions.old.get_displacement(); + #define n_debug_b_assem_neu_bc #ifdef debug_b_assem_neu_bc DebugMsg dmsg(__func__, com_mod.cm.idcm()); @@ -156,8 +159,11 @@ void b_assem_neu_bc(ComMod& com_mod, const faceType& lFa, const Vector& /// @param lFa /// @param hg Pressure magnitude /// @param Dg -void b_neu_folw_p(ComMod& com_mod, const bcType& lBc, const faceType& lFa, const Vector& hg, const Array& Dg, const Array& Do) +void b_neu_folw_p(ComMod& com_mod, const bcType& lBc, const faceType& lFa, const Vector& hg, const Array& Dg, SolutionStates& solutions) { + // Local alias for old displacement + const auto& Do = solutions.old.get_displacement(); + using namespace consts; using namespace utils; @@ -286,8 +292,12 @@ void b_neu_folw_p(ComMod& com_mod, const bcType& lBc, const faceType& lFa, const /// is eventually used in ADDBCMUL() in the linear solver to add the contribution /// from the resistance BC to the matrix-vector product of the tangent matrix and /// an arbitrary vector. -void fsi_ls_upd(ComMod& com_mod, const bcType& lBc, const faceType& lFa, const Array& Dn, const Array& Do) +void fsi_ls_upd(ComMod& com_mod, const bcType& lBc, const faceType& lFa, SolutionStates& solutions) { + // Local aliases for displacement arrays + const auto& Dn = solutions.current.get_displacement(); + const auto& Do = solutions.old.get_displacement(); + using namespace consts; using namespace utils; using namespace fsi_linear_solver; @@ -348,8 +358,11 @@ void fsi_ls_upd(ComMod& com_mod, const bcType& lBc, const faceType& lFa, const A /// Ag(tDof,tnNo), Yg(tDof,tnNo), Dg(tDof,tnNo) // void global_eq_assem(ComMod& com_mod, CepMod& cep_mod, const mshType& lM, const Array& Ag, - const Array& Yg, const Array& Dg, const Array& Do) + const Array& Yg, const Array& Dg, SolutionStates& solutions) { + // Local alias for old displacement + const auto& Do = solutions.old.get_displacement(); + #define n_debug_global_eq_assem #ifdef debug_global_eq_assem DebugMsg dmsg(__func__, com_mod.cm.idcm()); diff --git a/Code/Source/solver/eq_assem.h b/Code/Source/solver/eq_assem.h index eeb0d92ae..1c9ab65bf 100644 --- a/Code/Source/solver/eq_assem.h +++ b/Code/Source/solver/eq_assem.h @@ -9,13 +9,13 @@ namespace eq_assem { -void b_assem_neu_bc(ComMod& com_mod, const faceType& lFa, const Vector& hg, const Array& Yg, const Array& Do); +void b_assem_neu_bc(ComMod& com_mod, const faceType& lFa, const Vector& hg, const Array& Yg, SolutionStates& solutions); -void b_neu_folw_p(ComMod& com_mod, const bcType& lBc, const faceType& lFa, const Vector& hg, const Array& Dg, const Array& Do); +void b_neu_folw_p(ComMod& com_mod, const bcType& lBc, const faceType& lFa, const Vector& hg, const Array& Dg, SolutionStates& solutions); -void fsi_ls_upd(ComMod& com_mod, const bcType& lBc, const faceType& lFa, const Array& Dn, const Array& Do); +void fsi_ls_upd(ComMod& com_mod, const bcType& lBc, const faceType& lFa, SolutionStates& solutions); -void global_eq_assem(ComMod& com_mod, CepMod& cep_mod, const mshType& lM, const Array& Ag, const Array& Yg, const Array& Dg, const Array& Do); +void global_eq_assem(ComMod& com_mod, CepMod& cep_mod, const mshType& lM, const Array& Ag, const Array& Yg, const Array& Dg, SolutionStates& solutions); }; diff --git a/Code/Source/solver/set_bc.cpp b/Code/Source/solver/set_bc.cpp index 7c871899e..e899bb3d2 100644 --- a/Code/Source/solver/set_bc.cpp +++ b/Code/Source/solver/set_bc.cpp @@ -1473,10 +1473,10 @@ void set_bc_neu_l(ComMod& com_mod, const CmMod& cm_mod, const bcType& lBc, const // Add Neumann BCs contribution to the residual (and tangent if flwP) // if (lBc.flwP) { - eq_assem::b_neu_folw_p(com_mod, lBc, lFa, hg, Dg, Do); + eq_assem::b_neu_folw_p(com_mod, lBc, lFa, hg, Dg, solutions); } else { - eq_assem::b_assem_neu_bc(com_mod, lFa, hg, Yg, Do); + eq_assem::b_assem_neu_bc(com_mod, lFa, hg, Yg, solutions); } @@ -1486,7 +1486,7 @@ void set_bc_neu_l(ComMod& com_mod, const CmMod& cm_mod, const bcType& lBc, const // a follower pressure load (struct/ustruct) or a moving mesh (FSI) if (utils::btest(lBc.bType, iBC_res)) { if (lBc.flwP || com_mod.mvMsh) { - eq_assem::fsi_ls_upd(com_mod, lBc, lFa, Dg, Do); + eq_assem::fsi_ls_upd(com_mod, lBc, lFa, solutions); } } // Now treat Robin BC (stiffness and damping) here From 5917389e2d900d1c8529cb7c9bcdc417beb4b016 Mon Sep 17 00:00:00 2001 From: shiyi Date: Sun, 25 Jan 2026 20:38:10 +0000 Subject: [PATCH 27/33] Update txt functions to use SolutionStates --- Code/Source/solver/initialize.cpp | 9 +++++++-- Code/Source/solver/main.cpp | 2 +- Code/Source/solver/txt.cpp | 22 +++++++++++++++++----- Code/Source/solver/txt.h | 6 +++--- 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/Code/Source/solver/initialize.cpp b/Code/Source/solver/initialize.cpp index 3c253b207..0da973aff 100644 --- a/Code/Source/solver/initialize.cpp +++ b/Code/Source/solver/initialize.cpp @@ -843,8 +843,13 @@ void initialize(Simulation* simulation, Vector& timeP) Yo = temp_solutions.current.Y; Do = temp_solutions.current.D; - // Preparing TXT files (pass local Ao, Do, and Yo since An, Dn, and Yn haven't been created in Integrator yet) - txt_ns::txt(simulation, true, Ao, Do, Yo, Do); + // Preparing TXT files (pass solution states for initial output) + SolutionStates init_txt_solutions; + init_txt_solutions.current.A = Ao; + init_txt_solutions.current.Y = Yo; + init_txt_solutions.current.D = Do; + init_txt_solutions.old.D = Do; + txt_ns::txt(simulation, true, init_txt_solutions); // Printing the first line and initializing timeP int co = 1; diff --git a/Code/Source/solver/main.cpp b/Code/Source/solver/main.cpp index fcc62a3e1..372730844 100644 --- a/Code/Source/solver/main.cpp +++ b/Code/Source/solver/main.cpp @@ -394,7 +394,7 @@ void iterate_solution(Simulation* simulation) dmsg << "Saving the TXT files containing ECGs ..." << std::endl; #endif - txt_ns::txt(simulation, false, An, Dn, Yn, Do); + txt_ns::txt(simulation, false, solutions); // If remeshing is required then save current solution. // diff --git a/Code/Source/solver/txt.cpp b/Code/Source/solver/txt.cpp index c038c5a55..e5ebcc90d 100644 --- a/Code/Source/solver/txt.cpp +++ b/Code/Source/solver/txt.cpp @@ -140,8 +140,14 @@ void create_volume_integral_file(const ComMod& com_mod, CmMod& cm_mod, const eqT // init_write - if true then this is the start of the simulation and // so create a new file to initialize output. // -void txt(Simulation* simulation, const bool init_write, Array& An, Array& Dn, Array& Yn, const Array& Do) +void txt(Simulation* simulation, const bool init_write, SolutionStates& solutions) { + // Local aliases for solution arrays + auto& An = solutions.current.get_acceleration(); + auto& Yn = solutions.current.get_velocity(); + auto& Dn = solutions.current.get_displacement(); + const auto& Do = solutions.old.get_displacement(); + using namespace consts; using namespace utils; @@ -367,10 +373,10 @@ void txt(Simulation* simulation, const bool init_write, Array& An, Array } else { if (output_options.boundary_integral) { - write_boundary_integral_data(com_mod, cm_mod, eq, l, boundary_file_name, tmpV, div, pflag, Do); + write_boundary_integral_data(com_mod, cm_mod, eq, l, boundary_file_name, tmpV, div, pflag, solutions); } if (output_options.volume_integral) { - write_volume_integral_data(com_mod, cm_mod, eq, l, volume_file_name, tmpV, div, pflag, Do); + write_volume_integral_data(com_mod, cm_mod, eq, l, volume_file_name, tmpV, div, pflag, solutions); } } } @@ -408,8 +414,11 @@ void txt(Simulation* simulation, const bool init_write, Array& An, Array /// NOTE: Be carefu of a potential indexing problem here because 'm' is a length and not an index. // void write_boundary_integral_data(const ComMod& com_mod, CmMod& cm_mod, const eqType& lEq, const int m, - const std::string file_name, const Array& tmpV, const bool div, const bool pFlag, const Array& Do) + const std::string file_name, const Array& tmpV, const bool div, const bool pFlag, SolutionStates& solutions) { + // Local alias for old displacement + const auto& Do = solutions.old.get_displacement(); + #define n_debug_write_boundary_integral_data #ifdef debug_write_boundary_integral_data DebugMsg dmsg(__func__, com_mod.cm.idcm()); @@ -483,8 +492,11 @@ void write_boundary_integral_data(const ComMod& com_mod, CmMod& cm_mod, const eq /// NOTE: Be carefu of a potential indexing problem here because 'm' is a length and not an index. // void write_volume_integral_data(const ComMod& com_mod, CmMod& cm_mod, const eqType& lEq, const int m, - const std::string file_name, const Array& tmpV, const bool div, const bool pFlag, const Array& Do) + const std::string file_name, const Array& tmpV, const bool div, const bool pFlag, SolutionStates& solutions) { + // Local alias for old displacement + const auto& Do = solutions.old.get_displacement(); + #define n_debug_write_volume_integral_data #ifdef debug_write_volume_integral_data DebugMsg dmsg(__func__, com_mod.cm.idcm()); diff --git a/Code/Source/solver/txt.h b/Code/Source/solver/txt.h index 8b4c77207..33b886de8 100644 --- a/Code/Source/solver/txt.h +++ b/Code/Source/solver/txt.h @@ -16,13 +16,13 @@ void create_boundary_integral_file(const ComMod& com_mod, CmMod& cm_mod, const e void create_volume_integral_file(const ComMod& com_mod, CmMod& cm_mod, const eqType& lEq, const std::string& file_name); -void txt(Simulation* simulation, const bool flag, Array& An, Array& Dn, Array& Yn, const Array& Do); +void txt(Simulation* simulation, const bool flag, SolutionStates& solutions); void write_boundary_integral_data(const ComMod& com_mod, CmMod& cm_mod, const eqType& lEq, const int m, - const std::string file_name, const Array& tmpV, const bool div, const bool pFlag, const Array& Do); + const std::string file_name, const Array& tmpV, const bool div, const bool pFlag, SolutionStates& solutions); void write_volume_integral_data(const ComMod& com_mod, CmMod& cm_mod, const eqType& lEq, const int m, - const std::string file_name, const Array& tmpV, const bool div, const bool pFlag, const Array& Do); + const std::string file_name, const Array& tmpV, const bool div, const bool pFlag, SolutionStates& solutions); }; From c49aff3dec77ae4e1854f1bf3ab1d30247fe4f9f Mon Sep 17 00:00:00 2001 From: shiyi Date: Sun, 25 Jan 2026 20:39:33 +0000 Subject: [PATCH 28/33] Update output functions to use SolutionStates --- Code/Source/solver/main.cpp | 2 +- Code/Source/solver/output.cpp | 16 ++++++++++++---- Code/Source/solver/output.h | 4 ++-- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Code/Source/solver/main.cpp b/Code/Source/solver/main.cpp index 372730844..3d0d4b969 100644 --- a/Code/Source/solver/main.cpp +++ b/Code/Source/solver/main.cpp @@ -458,7 +458,7 @@ void iterate_solution(Simulation* simulation) // Saving the result to restart bin file if (l1 || l2) { - output::write_restart(simulation, com_mod.timeP, An, Dn, Yn); + output::write_restart(simulation, com_mod.timeP, solutions); } // Writing results into the disk with VTU format diff --git a/Code/Source/solver/output.cpp b/Code/Source/solver/output.cpp index 62838ed06..2330cff4e 100644 --- a/Code/Source/solver/output.cpp +++ b/Code/Source/solver/output.cpp @@ -172,8 +172,13 @@ void read_restart_header(ComMod& com_mod, std::array& tStamp, double& tim /// @brief Reproduces the Fortran 'WRITERESTART' subroutine. // -void write_restart(Simulation* simulation, std::array& timeP, Array& An, Array& Dn, Array& Yn) +void write_restart(Simulation* simulation, std::array& timeP, SolutionStates& solutions) { + // Local aliases for solution arrays + auto& An = solutions.current.get_acceleration(); + auto& Yn = solutions.current.get_velocity(); + auto& Dn = solutions.current.get_displacement(); + auto& com_mod = simulation->com_mod; #define n_debug_write_restart #ifdef debug_write_restart @@ -392,11 +397,14 @@ void write_restart_header(ComMod& com_mod, std::array& timeP, std::ofs /// /// Reproduces: WRITE(fid, REC=myID) stamp, cTS, time,CPUT()-timeP(1), eq.iNorm, cplBC.xn, Yn, An, Dn // -void write_results(ComMod& com_mod, const std::array& timeP, const std::string& fName, const bool sstEq, Array& An, Array& Dn, Array& Yn) +void write_results(ComMod& com_mod, const std::array& timeP, const std::string& fName, const bool sstEq, SolutionStates& solutions) { - int cTS = com_mod.cTS; + // Local aliases for solution arrays + auto& An = solutions.current.get_acceleration(); + auto& Yn = solutions.current.get_velocity(); + auto& Dn = solutions.current.get_displacement(); - // An, Dn, and Yn are now passed as parameters (from integrator getters) + int cTS = com_mod.cTS; auto& stamp = com_mod.stamp; diff --git a/Code/Source/solver/output.h b/Code/Source/solver/output.h index b90fd77c6..b7a4a8fd3 100644 --- a/Code/Source/solver/output.h +++ b/Code/Source/solver/output.h @@ -15,11 +15,11 @@ void output_result(Simulation* simulation, std::array& timeP, const i void read_restart_header(ComMod& com_mod, std::array& tStamp, double& timeP, std::ifstream& restart_file); -void write_restart(Simulation* simulation, std::array& timeP, Array& An, Array& Dn, Array& Yn); +void write_restart(Simulation* simulation, std::array& timeP, SolutionStates& solutions); void write_restart_header(ComMod& com_mod, std::array& timeP, std::ofstream& restart_file); -void write_results(ComMod& com_mod, const std::array& timeP, const std::string& fName, const bool sstEq, Array& An, Array& Dn, Array& Yn); +void write_results(ComMod& com_mod, const std::array& timeP, const std::string& fName, const bool sstEq, SolutionStates& solutions); }; From 730907550d14ef368895ef2cc131cfe47aa9dce6 Mon Sep 17 00:00:00 2001 From: shiyi Date: Sun, 25 Jan 2026 21:22:20 +0000 Subject: [PATCH 29/33] Update initialization functions to use SolutionStates --- Code/Source/solver/baf_ini.cpp | 35 +++++++++++++----- Code/Source/solver/baf_ini.h | 10 +++--- Code/Source/solver/initialize.cpp | 59 +++++++++++++++++++------------ Code/Source/solver/initialize.h | 6 ++-- Code/Source/solver/post.cpp | 13 +++---- 5 files changed, 78 insertions(+), 45 deletions(-) diff --git a/Code/Source/solver/baf_ini.cpp b/Code/Source/solver/baf_ini.cpp index 77171bc81..16b2ccdf6 100644 --- a/Code/Source/solver/baf_ini.cpp +++ b/Code/Source/solver/baf_ini.cpp @@ -39,8 +39,13 @@ namespace baf_ini_ns { /// /// Replicates 'SUBROUTINE BAFINI()' defined in BAFINIT.f // -void baf_ini(Simulation* simulation, const Array& Ao, Array& Do, Array& Yo) +void baf_ini(Simulation* simulation, SolutionStates& solutions) { + // Local aliases for solution arrays + const auto& Ao = solutions.old.get_acceleration(); + auto& Do = solutions.old.get_displacement(); + auto& Yo = solutions.old.get_velocity(); + using namespace consts; using namespace fsi_linear_solver; @@ -67,7 +72,7 @@ void baf_ini(Simulation* simulation, const Array& Ao, Array& Do, continue; } auto& face = msh.fa[iFa]; - face_ini(simulation, msh, face, Do); + face_ini(simulation, msh, face, solutions); } if (msh.lShl) { shl_ini(com_mod, cm_mod, com_mod.msh[iM]); @@ -82,10 +87,10 @@ void baf_ini(Simulation* simulation, const Array& Ao, Array& Do, auto& bc = eq.bc[iBc]; int iFa = bc.iFa; int iM = bc.iM; - bc_ini(com_mod, cm_mod, bc, com_mod.msh[iM].fa[iFa], Do); + bc_ini(com_mod, cm_mod, bc, com_mod.msh[iM].fa[iFa], solutions); if (com_mod.msh[iM].lShl) { - shl_bc_ini(com_mod, cm_mod, bc, com_mod.msh[iM].fa[iFa], com_mod.msh[iM], Do); + shl_bc_ini(com_mod, cm_mod, bc, com_mod.msh[iM].fa[iFa], com_mod.msh[iM], solutions); } } } @@ -176,7 +181,7 @@ void baf_ini(Simulation* simulation, const Array& Ao, Array& Do, int iFa = bc.iFa; int iM = bc.iM; bc.lsPtr = 0; - fsi_ls_ini(com_mod, cm_mod, bc, com_mod.msh[iM].fa[iFa], lsPtr, Do); + fsi_ls_ini(com_mod, cm_mod, bc, com_mod.msh[iM].fa[iFa], lsPtr, solutions); } } @@ -238,8 +243,11 @@ void baf_ini(Simulation* simulation, const Array& Ao, Array& Do, // bc_ini //--------- // -void bc_ini(const ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, faceType& lFa, const Array& Do) +void bc_ini(const ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, faceType& lFa, SolutionStates& solutions) { + // Local alias for old displacement + const auto& Do = solutions.old.get_displacement(); + using namespace consts; using namespace utils; @@ -426,8 +434,11 @@ void bc_ini(const ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, faceType& l // face_ini //---------- // -void face_ini(Simulation* simulation, mshType& lM, faceType& lFa, Array& Do) +void face_ini(Simulation* simulation, mshType& lM, faceType& lFa, SolutionStates& solutions) { + // Local alias for old displacement + auto& Do = solutions.old.get_displacement(); + using namespace consts; auto& com_mod = simulation->com_mod; auto& cm = com_mod.cm; @@ -674,8 +685,11 @@ void face_ini(Simulation* simulation, mshType& lM, faceType& lFa, Array& // // Replicates 'SUBROUTINE FSILSINI'. // -void fsi_ls_ini(ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, const faceType& lFa, int& lsPtr, const Array& Do) +void fsi_ls_ini(ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, const faceType& lFa, int& lsPtr, SolutionStates& solutions) { + // Local alias for old displacement + const auto& Do = solutions.old.get_displacement(); + using namespace consts; using namespace utils; using namespace fsi_linear_solver; @@ -881,8 +895,11 @@ void set_shl_xien(Simulation* simulation, mshType& lM) // // Reproduces 'SUBROUTINE SHLBCINI(lBc, lFa, lM)'. // -void shl_bc_ini(const ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, faceType& lFa, mshType& lM, const Array& Do) +void shl_bc_ini(const ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, faceType& lFa, mshType& lM, SolutionStates& solutions) { + // Local alias for old displacement + const auto& Do = solutions.old.get_displacement(); + using namespace consts; using namespace utils; diff --git a/Code/Source/solver/baf_ini.h b/Code/Source/solver/baf_ini.h index 694a73d96..0dff9169d 100644 --- a/Code/Source/solver/baf_ini.h +++ b/Code/Source/solver/baf_ini.h @@ -9,17 +9,17 @@ namespace baf_ini_ns { -void baf_ini(Simulation* simulation, const Array& Ao, Array& Do, Array& Yo); +void baf_ini(Simulation* simulation, SolutionStates& solutions); -void bc_ini(const ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, faceType& lFa, const Array& Do); +void bc_ini(const ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, faceType& lFa, SolutionStates& solutions); -void face_ini(Simulation* simulation, mshType& lm, faceType& la, Array& Do); +void face_ini(Simulation* simulation, mshType& lm, faceType& la, SolutionStates& solutions); -void fsi_ls_ini(ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, const faceType& lFa, int& lsPtr, const Array& Do); +void fsi_ls_ini(ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, const faceType& lFa, int& lsPtr, SolutionStates& solutions); void set_shl_xien(Simulation* simulation, mshType& mesh); -void shl_bc_ini(const ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, faceType& lFa, mshType& lM, const Array& Do); +void shl_bc_ini(const ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, faceType& lFa, mshType& lM, SolutionStates& solutions); void shl_ini(const ComMod& com_mod, const CmMod& cm_mod, mshType& lM); diff --git a/Code/Source/solver/initialize.cpp b/Code/Source/solver/initialize.cpp index 0da973aff..c90b4183f 100644 --- a/Code/Source/solver/initialize.cpp +++ b/Code/Source/solver/initialize.cpp @@ -49,8 +49,13 @@ void finalize(Simulation* simulation) /// Reprodices 'SUBROUTINE INITFROMBIN(fName, timeP)' defined in INITIALIZE.f. // void init_from_bin(Simulation* simulation, const std::string& fName, std::array& timeP, - Array& Ao, Array& Do, Array& Yo) + SolutionStates& solutions) { + // Local aliases for solution arrays + auto& Ao = solutions.old.get_acceleration(); + auto& Do = solutions.old.get_displacement(); + auto& Yo = solutions.old.get_velocity(); + auto& com_mod = simulation->com_mod; auto& cm = com_mod.cm; int task_id = cm.idcm(); @@ -260,8 +265,13 @@ void init_from_bin(Simulation* simulation, const std::string& fName, std::array< /// Reproduces the Fortran 'INITFROMVTU' subroutine. // void init_from_vtu(Simulation* simulation, const std::string& fName, std::array& timeP, - Array& Ao, Array& Do, Array& Yo) + SolutionStates& solutions) { + // Local aliases for solution arrays + auto& Ao = solutions.old.get_acceleration(); + auto& Do = solutions.old.get_displacement(); + auto& Yo = solutions.old.get_velocity(); + auto& com_mod = simulation->com_mod; auto& cm_mod = simulation->cm_mod; auto& cm = com_mod.cm; @@ -623,11 +633,17 @@ void initialize(Simulation* simulation, Vector& timeP) // Variable allocation and initialization int tnNo = com_mod.tnNo; - // Ao, Do, Yo are local variables that will be moved to Integrator at end - Array Ao(tDof, tnNo); - Array Yo(tDof, tnNo); - Array Do(tDof, tnNo); - // An, Yn, Dn moved to Integrator class + // Create SolutionStates that will be moved to Integrator at end + SolutionStates initial_solutions; + initial_solutions.old.A.resize(tDof, tnNo); + initial_solutions.old.Y.resize(tDof, tnNo); + initial_solutions.old.D.resize(tDof, tnNo); + // An, Yn, Dn will be created in Integrator class + + // Local aliases for convenience (these reference initial_solutions members) + auto& Ao = initial_solutions.old.get_acceleration(); + auto& Yo = initial_solutions.old.get_velocity(); + auto& Do = initial_solutions.old.get_displacement(); com_mod.Bf.resize(nsd,tnNo); @@ -694,9 +710,9 @@ void initialize(Simulation* simulation, Vector& timeP) auto& timeP = com_mod.timeP; if (iniFilePath.find(".bin") != std::string::npos) { - init_from_bin(simulation, iniFilePath, timeP, Ao, Do, Yo); + init_from_bin(simulation, iniFilePath, timeP, initial_solutions); } else { - init_from_vtu(simulation, iniFilePath, timeP, Ao, Do, Yo); + init_from_vtu(simulation, iniFilePath, timeP, initial_solutions); } } else { @@ -706,13 +722,13 @@ void initialize(Simulation* simulation, Vector& timeP) if (FILE *file = fopen(fTmp.c_str(), "r")) { fclose(file); auto& timeP = com_mod.timeP; - init_from_bin(simulation, fTmp, timeP, Ao, Do, Yo); + init_from_bin(simulation, fTmp, timeP, initial_solutions); } else { if (cm.mas(cm_mod)) { std::cout << "WARNING: No '" + fTmp + "' file to restart simulation from; Resetting restart flag to false"; } com_mod.stFileFlag = false; - zero_init(simulation, Ao, Do, Yo); + zero_init(simulation, initial_solutions); } if (rmsh.isReqd) { @@ -729,7 +745,7 @@ void initialize(Simulation* simulation, Vector& timeP) } } else { - zero_init(simulation, Ao, Do, Yo); + zero_init(simulation, initial_solutions); } } @@ -816,7 +832,7 @@ void initialize(Simulation* simulation, Vector& timeP) // Preparing faces and BCs // - baf_ini_ns::baf_ini(simulation, Ao, Do, Yo); + baf_ini_ns::baf_ini(simulation, initial_solutions); // As all the arrays are allocated, call BIN to VTK for conversion // @@ -859,14 +875,8 @@ void initialize(Simulation* simulation, Vector& timeP) std::fill(com_mod.rmsh.flag.begin(), com_mod.rmsh.flag.end(), false); com_mod.resetSim = false; - // Create Integrator now that Ao, Do, Yo are fully initialized - // The Integrator takes ownership of Ao, Do, Yo via move semantics - // Create SolutionStates and move arrays into it - SolutionStates initial_solutions; - initial_solutions.old.A = std::move(Ao); - initial_solutions.old.D = std::move(Do); - initial_solutions.old.Y = std::move(Yo); - + // Create Integrator now that initial_solutions (Ao, Do, Yo) are fully initialized + // The Integrator takes ownership via move semantics simulation->initialize_integrator(std::move(initial_solutions)); } @@ -875,8 +885,13 @@ void initialize(Simulation* simulation, Vector& timeP) //----------- // Initialize state variables Yo, Ao and Do. // -void zero_init(Simulation* simulation, Array& Ao, Array& Do, Array& Yo) +void zero_init(Simulation* simulation, SolutionStates& solutions) { + // Local aliases for solution arrays + auto& Ao = solutions.old.get_acceleration(); + auto& Do = solutions.old.get_displacement(); + auto& Yo = solutions.old.get_velocity(); + auto& com_mod = simulation->com_mod; auto& cm = com_mod.cm; const int nsd = com_mod.nsd; diff --git a/Code/Source/solver/initialize.h b/Code/Source/solver/initialize.h index cc858e0c4..cd65d67cd 100644 --- a/Code/Source/solver/initialize.h +++ b/Code/Source/solver/initialize.h @@ -9,14 +9,14 @@ void finalize(Simulation* simulation); void init_from_bin(Simulation* simulation, const std::string& fName, std::array& timeP, - Array& Ao, Array& Do, Array& Yo); + SolutionStates& solutions); void init_from_vtu(Simulation* simulation, const std::string& fName, std::array& timeP, - Array& Ao, Array& Do, Array& Yo); + SolutionStates& solutions); void initialize(Simulation* simulation, Vector& timeP); -void zero_init(Simulation* simulation, Array& Ao, Array& Do, Array& Yo); +void zero_init(Simulation* simulation, SolutionStates& solutions); #endif diff --git a/Code/Source/solver/post.cpp b/Code/Source/solver/post.cpp index 906e2f93d..bb0a6c166 100644 --- a/Code/Source/solver/post.cpp +++ b/Code/Source/solver/post.cpp @@ -1164,19 +1164,20 @@ void ppbin2vtk(Simulation* simulation) continue; } - // Create local arrays for Ao, Do, Yo + // Create local SolutionStates for loading bin file const int tDof = com_mod.tDof; const int tnNo = com_mod.tnNo; - Array Ao(tDof, tnNo); - Array Yo(tDof, tnNo); - Array Do(tDof, tnNo); + SolutionStates temp_solutions; + temp_solutions.old.A.resize(tDof, tnNo); + temp_solutions.old.Y.resize(tDof, tnNo); + temp_solutions.old.D.resize(tDof, tnNo); std::array rtmp; - init_from_bin(simulation, fName, rtmp, Ao, Do, Yo); + init_from_bin(simulation, fName, rtmp, temp_solutions); bool lAve = false; - vtk_xml::write_vtus(simulation, Ao, Yo, Do, lAve); + vtk_xml::write_vtus(simulation, temp_solutions.old.A, temp_solutions.old.Y, temp_solutions.old.D, lAve); } } From a73c52800ada87886bb483be2f9687db176f0af7 Mon Sep 17 00:00:00 2001 From: shiyi Date: Sun, 25 Jan 2026 21:44:48 +0000 Subject: [PATCH 30/33] Update all_fun integ functions and uris functions to use SolutionStates --- Code/Source/solver/all_fun.cpp | 40 +++++++++++++++++++++++-------- Code/Source/solver/all_fun.h | 12 +++++----- Code/Source/solver/baf_ini.cpp | 6 ++--- Code/Source/solver/initialize.cpp | 2 +- Code/Source/solver/main.cpp | 6 ++--- Code/Source/solver/uris.cpp | 34 ++++++++++++++++---------- Code/Source/solver/uris.h | 6 ++--- 7 files changed, 67 insertions(+), 39 deletions(-) diff --git a/Code/Source/solver/all_fun.cpp b/Code/Source/solver/all_fun.cpp index 9ecf55515..64c425140 100644 --- a/Code/Source/solver/all_fun.cpp +++ b/Code/Source/solver/all_fun.cpp @@ -276,7 +276,7 @@ global(const ComMod& com_mod, const CmMod& cm_mod, const mshType& lM, const Arra /// @param s an array containing a scalar value for each node in the mesh /// Replicates 'FUNCTION vIntegM(dId, s, l, u, pFlag)' defined in ALLFUN.f. // -double integ(const ComMod& com_mod, const CmMod& cm_mod, int iM, const Array& s, const Array* Do) +double integ(const ComMod& com_mod, const CmMod& cm_mod, int iM, const Array& s, SolutionStates& solutions) { using namespace consts; @@ -288,6 +288,9 @@ double integ(const ComMod& com_mod, const CmMod& cm_mod, int iM, const Array& s, int l, int u, const Array* Do, bool pFlag) +double integ(const ComMod& com_mod, const CmMod& cm_mod, int dId, const Array& s, int l, int u, + SolutionStates& solutions, bool pFlag) { using namespace consts; @@ -439,6 +443,9 @@ double integ(const ComMod& com_mod, const CmMod& cm_mod, int dId, const Array& s, const Array* Dn, const Array* Do, bool pFlag, MechanicalConfigurationType cfg) +double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, const Vector& s, + SolutionStates& solutions, bool pFlag, MechanicalConfigurationType cfg) { using namespace consts; #define n_debug_integ_s @@ -689,7 +697,11 @@ double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, co dmsg << "lFa.iM: " << lFa.iM+1; dmsg << "lFa.name: " << lFa.name; dmsg << "lFa.eType: " << lFa.eType; - #endif + #endif + + // Local aliases for solution arrays + const auto* Dn = &solutions.current.get_displacement(); + const auto* Do = &solutions.old.get_displacement(); bool flag = pFlag; int nsd = com_mod.nsd; @@ -842,7 +854,7 @@ double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, co /// @param cfg denotes which configuration (reference/timestep 0, old/timestep n, or new/timestep n+1). Default reference. // double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, - const Array& s, const Array* Dn, const Array* Do, MechanicalConfigurationType cfg) + const Array& s, SolutionStates& solutions, MechanicalConfigurationType cfg) { using namespace consts; @@ -854,6 +866,10 @@ double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, dmsg << "lFa.name: " << lFa.name; #endif + // Local aliases for solution arrays + const auto* Dn = &solutions.current.get_displacement(); + const auto* Do = &solutions.old.get_displacement(); + auto& cm = com_mod.cm; int nsd = com_mod.nsd; int insd = nsd - 1; @@ -976,7 +992,7 @@ double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, /// // double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, - const Array& s, const int l, const Array* Dn, const Array* Do, std::optional uo, bool THflag, MechanicalConfigurationType cfg) + const Array& s, const int l, SolutionStates& solutions, std::optional uo, bool THflag, MechanicalConfigurationType cfg) { using namespace consts; @@ -989,6 +1005,10 @@ double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, dmsg << "uo: " << uo; #endif + // Local aliases for solution arrays + const auto* Dn = &solutions.current.get_displacement(); + const auto* Do = &solutions.old.get_displacement(); + auto& cm = com_mod.cm; int nsd = com_mod.nsd; int insd = nsd - 1; @@ -1032,14 +1052,14 @@ double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, vec(n,a) = s(i,a); } } - result = integ(com_mod, cm_mod, lFa, vec, Dn, Do, cfg); + result = integ(com_mod, cm_mod, lFa, vec, solutions, cfg); // If s scalar, integrate as scalar } else if (l == u) { Vector sclr(nNo); for (int a = 0; a < nNo; a++) { sclr(a) = s(l,a); } - result = integ(com_mod, cm_mod, lFa, sclr, Dn, Do, flag, cfg); + result = integ(com_mod, cm_mod, lFa, sclr, solutions, flag, cfg); } else { throw std::runtime_error("Unexpected dof in integ"); } diff --git a/Code/Source/solver/all_fun.h b/Code/Source/solver/all_fun.h index 37ca972ce..f79dfe94c 100644 --- a/Code/Source/solver/all_fun.h +++ b/Code/Source/solver/all_fun.h @@ -29,18 +29,18 @@ namespace all_fun { Array global(const ComMod& com_mod, const CmMod& cm_mod, const mshType& lM, const Array& U); - double integ(const ComMod& com_mod, const CmMod& cm_mod, int iM, const Array& s, const Array* Do); + double integ(const ComMod& com_mod, const CmMod& cm_mod, int iM, const Array& s, SolutionStates& solutions); - double integ(const ComMod& com_mod, const CmMod& cm_mod, int dId, const Array& s, int l, int u, - const Array* Do, bool pFlag=false); + double integ(const ComMod& com_mod, const CmMod& cm_mod, int dId, const Array& s, int l, int u, + SolutionStates& solutions, bool pFlag=false); double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, const Vector& s, - const Array* Dn, const Array* Do, bool pFlag=false, consts::MechanicalConfigurationType cfg=consts::MechanicalConfigurationType::reference); + SolutionStates& solutions, bool pFlag=false, consts::MechanicalConfigurationType cfg=consts::MechanicalConfigurationType::reference); double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, const Array& s, - const int l, const Array* Dn, const Array* Do, std::optional uo=std::nullopt, bool THflag=false, consts::MechanicalConfigurationType cfg=consts::MechanicalConfigurationType::reference); + const int l, SolutionStates& solutions, std::optional uo=std::nullopt, bool THflag=false, consts::MechanicalConfigurationType cfg=consts::MechanicalConfigurationType::reference); - double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, const Array& s, const Array* Dn, const Array* Do, consts::MechanicalConfigurationType cfg=consts::MechanicalConfigurationType::reference); + double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, const Array& s, SolutionStates& solutions, consts::MechanicalConfigurationType cfg=consts::MechanicalConfigurationType::reference); bool is_domain(const ComMod& com_mod, const eqType& eq, const int node, const consts::EquationType phys); diff --git a/Code/Source/solver/baf_ini.cpp b/Code/Source/solver/baf_ini.cpp index 16b2ccdf6..7833492ce 100644 --- a/Code/Source/solver/baf_ini.cpp +++ b/Code/Source/solver/baf_ini.cpp @@ -308,7 +308,7 @@ void bc_ini(const ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, faceType& l } else if (btest(lBc.bType, iBC_para)) { Vector center(3); for (int i = 0; i < nsd; i++) { - center(i) = all_fun::integ(com_mod, cm_mod, lFa, com_mod.x, i, &Do, &Do, std::nullopt, false, consts::MechanicalConfigurationType::reference) / lFa.area; + center(i) = all_fun::integ(com_mod, cm_mod, lFa, com_mod.x, i, solutions, std::nullopt, false, consts::MechanicalConfigurationType::reference) / lFa.area; } // gNodes is one if a node located on the boundary (beside iFa) @@ -417,7 +417,7 @@ void bc_ini(const ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, faceType& l // double tmp = 1.0; if (btest(lBc.bType, enum_int(BoundaryConditionType::bType_flx))) { - tmp = all_fun::integ(com_mod, cm_mod, lFa, s, &Do, &Do, false, consts::MechanicalConfigurationType::reference); + tmp = all_fun::integ(com_mod, cm_mod, lFa, s, solutions, false, consts::MechanicalConfigurationType::reference); if (is_zero(tmp)) { tmp = 1.0; throw std::runtime_error("Face '" + lFa.name + "' used for a BC has no non-zero node."); @@ -460,7 +460,7 @@ void face_ini(Simulation* simulation, mshType& lM, faceType& lFa, SolutionStates // Vector sA(com_mod.tnNo); sA = 1.0; - double area = all_fun::integ(com_mod, cm_mod, lFa, sA, &Do, &Do, false, consts::MechanicalConfigurationType::reference); + double area = all_fun::integ(com_mod, cm_mod, lFa, sA, solutions, false, consts::MechanicalConfigurationType::reference); #ifdef debug_face_ini dmsg << "Face '" << lFa.name << "' area: " << area; #endif diff --git a/Code/Source/solver/initialize.cpp b/Code/Source/solver/initialize.cpp index c90b4183f..8f4cdaad1 100644 --- a/Code/Source/solver/initialize.cpp +++ b/Code/Source/solver/initialize.cpp @@ -822,7 +822,7 @@ void initialize(Simulation* simulation, Vector& timeP) for (int iDmn = 0; iDmn < eq.nDmn; iDmn++) { int i = eq.dmn[iDmn].Id; - eq.dmn[iDmn].v = all_fun::integ(com_mod, cm_mod, i, s, 0, 0, &Do, false); + eq.dmn[iDmn].v = all_fun::integ(com_mod, cm_mod, i, s, 0, 0, initial_solutions, false); if (!com_mod.shlEq && !com_mod.cmmInit) { //std = " Volume of domain <"//STR(i)//"> is "// 2 STR(eq(iEq)%dmn(iDmn)%v) //IF (ISZERO(eq(iEq)%dmn(iDmn)%v)) wrn = "<< Volume of "// "domain "//iDmn//" of equation "//iEq//" is zero >>" diff --git a/Code/Source/solver/main.cpp b/Code/Source/solver/main.cpp index 3d0d4b969..6a2f066af 100644 --- a/Code/Source/solver/main.cpp +++ b/Code/Source/solver/main.cpp @@ -509,12 +509,12 @@ void iterate_solution(Simulation* simulation) for (int iUris = 0; iUris < com_mod.nUris; iUris++) { com_mod.uris[iUris].cnt++; if (com_mod.uris[iUris].clsFlg) { - uris::uris_meanp(com_mod, cm_mod, iUris, Dn, Yn, Do); + uris::uris_meanp(com_mod, cm_mod, iUris, solutions); // if (com_mod.uris[iUris].cnt == 1) { // // GOTO 11 // The GOTO Statement in the Fortran code // } } else { - uris::uris_meanv(com_mod, cm_mod, iUris, Dn, Yn, Do); + uris::uris_meanv(com_mod, cm_mod, iUris, solutions); } if (cm.mas(cm_mod)) { std::cout << " URIS surface: " << com_mod.uris[iUris].name << ", count: " << com_mod.uris[iUris].cnt << std::endl; @@ -522,7 +522,7 @@ void iterate_solution(Simulation* simulation) } if (com_mod.mvMsh) { - uris::uris_update_disp(com_mod, cm_mod, Do); + uris::uris_update_disp(com_mod, cm_mod, solutions); } if (cm.mas(cm_mod)) { diff --git a/Code/Source/solver/uris.cpp b/Code/Source/solver/uris.cpp index ca1d19198..a0051ee92 100644 --- a/Code/Source/solver/uris.cpp +++ b/Code/Source/solver/uris.cpp @@ -17,9 +17,12 @@ namespace uris { -/// @brief This subroutine computes the mean pressure and flux on the -/// immersed surface -void uris_meanp(ComMod& com_mod, CmMod& cm_mod, const int iUris, const Array& Dn, Array& Yn, const Array& Do) { +/// @brief This subroutine computes the mean pressure and flux on the +/// immersed surface +void uris_meanp(ComMod& com_mod, CmMod& cm_mod, const int iUris, SolutionStates& solutions) { + // Local aliases for solution arrays + auto& Yn = solutions.current.get_velocity(); + auto& Do = solutions.old.get_displacement(); #define n_debug_uris_meanp #ifdef debug_uris_meanp DebugMsg dmsg(__func__, com_mod.cm.idcm()); @@ -67,7 +70,7 @@ void uris_meanp(ComMod& com_mod, CmMod& cm_mod, const int iUris, const Array& Dn, Array& Yn, const Array& Do) { +/// @brief This subroutine computes the mean velocity in the fluid elements +/// near the immersed surface +void uris_meanv(ComMod& com_mod, CmMod& cm_mod, const int iUris, SolutionStates& solutions) { + // Local aliases for solution arrays + auto& Yn = solutions.current.get_velocity(); + auto& Do = solutions.old.get_displacement(); #define n_debug_uris_meanv #ifdef debug_uris_meanv DebugMsg dmsg(__func__, com_mod.cm.idcm()); @@ -191,7 +197,7 @@ void uris_meanv(ComMod& com_mod, CmMod& cm_mod, const int iUris, const Array& Do) { +void uris_update_disp(ComMod& com_mod, CmMod& cm_mod, SolutionStates& solutions) { + // Local alias for solution array + const auto& Do = solutions.old.get_displacement(); #define n_debug_uris_update_disp #ifdef debug_uris_update_disp DebugMsg dmsg(__func__, com_mod.cm.idcm()); diff --git a/Code/Source/solver/uris.h b/Code/Source/solver/uris.h index eb4314182..5c04aa121 100644 --- a/Code/Source/solver/uris.h +++ b/Code/Source/solver/uris.h @@ -9,11 +9,11 @@ namespace uris { -void uris_meanp(ComMod& com_mod, CmMod& cm_mod, const int iUris, const Array& Dn, Array& Yn, const Array& Do); // done +void uris_meanp(ComMod& com_mod, CmMod& cm_mod, const int iUris, SolutionStates& solutions); // done -void uris_meanv(ComMod& com_mod, CmMod& cm_mod, const int iUris, const Array& Dn, Array& Yn, const Array& Do); // done +void uris_meanv(ComMod& com_mod, CmMod& cm_mod, const int iUris, SolutionStates& solutions); // done -void uris_update_disp(ComMod& com_mod, CmMod& cm_mod, const Array& Do); +void uris_update_disp(ComMod& com_mod, CmMod& cm_mod, SolutionStates& solutions); void uris_find_tetra(ComMod& com_mod, CmMod& cm_mod, const int iUris); From d6919af5791bbc7732c0b355ef06a42d53bdb570 Mon Sep 17 00:00:00 2001 From: shiyi Date: Wed, 28 Jan 2026 02:28:10 +0000 Subject: [PATCH 31/33] Update txt functions and uris functions to use SolutionStates --- Code/Source/solver/ris.cpp | 10 +++++----- Code/Source/solver/set_bc.cpp | 26 +++++++++++++------------- Code/Source/solver/txt.cpp | 12 ++++++------ 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/Code/Source/solver/ris.cpp b/Code/Source/solver/ris.cpp index a1426abae..0fe3318bc 100644 --- a/Code/Source/solver/ris.cpp +++ b/Code/Source/solver/ris.cpp @@ -60,7 +60,7 @@ void ris_meanq(ComMod& com_mod, CmMod& cm_mod, SolutionStates& solutions) int iM = RIS.lst(i,0,iProj); int iFa = RIS.lst(i,1,iProj); double tmp = msh[iM].fa[iFa].area; - RIS.meanP(iProj,i) = all_fun::integ(com_mod, cm_mod, msh[iM].fa[iFa], tmpV, 0, &Dn, &Do, std::nullopt, false, consts::MechanicalConfigurationType::reference)/tmp; + RIS.meanP(iProj,i) = all_fun::integ(com_mod, cm_mod, msh[iM].fa[iFa], tmpV, 0, solutions, std::nullopt, false, consts::MechanicalConfigurationType::reference)/tmp; } } @@ -78,7 +78,7 @@ void ris_meanq(ComMod& com_mod, CmMod& cm_mod, SolutionStates& solutions) } int iM = RIS.lst(0,0,iProj); int iFa = RIS.lst(0,1,iProj); - RIS.meanFl(iProj) = all_fun::integ(com_mod, cm_mod, msh[iM].fa[iFa], tmpV, 0, &Dn, &Do, m-1, false, consts::MechanicalConfigurationType::reference); + RIS.meanFl(iProj) = all_fun::integ(com_mod, cm_mod, msh[iM].fa[iFa], tmpV, 0, solutions, m-1, false, consts::MechanicalConfigurationType::reference); if (cm.mas(cm_mod)) { std::cout << "For RIS projection: " << iProj << std::endl; @@ -479,8 +479,8 @@ void ris0d_status(ComMod& com_mod, CmMod& cm_mod, SolutionStates& solutions) sA = 1.0; lFa = msh[iM].fa[iFa]; // such update may be not correct - tmp_new = all_fun::integ(com_mod, cm_mod, lFa, sA, &Dn, &Do, false, consts::MechanicalConfigurationType::reference); - meanP = all_fun::integ(com_mod, cm_mod, msh[iM].fa[iFa], tmpV, 0, &Dn, &Do, m-1, false, consts::MechanicalConfigurationType::reference)/tmp_new; + tmp_new = all_fun::integ(com_mod, cm_mod, lFa, sA, solutions, false, consts::MechanicalConfigurationType::reference); + meanP = all_fun::integ(com_mod, cm_mod, msh[iM].fa[iFa], tmpV, 0, solutions, m-1, false, consts::MechanicalConfigurationType::reference)/tmp_new; // For the velocity m = nsd; @@ -495,7 +495,7 @@ void ris0d_status(ComMod& com_mod, CmMod& cm_mod, SolutionStates& solutions) } } - meanFl = all_fun::integ(com_mod, cm_mod, msh[iM].fa[iFa], tmpV, 0, &Dn, &Do, m-1, false, consts::MechanicalConfigurationType::reference); + meanFl = all_fun::integ(com_mod, cm_mod, msh[iM].fa[iFa], tmpV, 0, solutions, m-1, false, consts::MechanicalConfigurationType::reference); std::cout << "The average pressure is: " << meanP << std::endl; std::cout << "The pressure from 0D is: " << eq[cEq].bc[iBc].g << std::endl; diff --git a/Code/Source/solver/set_bc.cpp b/Code/Source/solver/set_bc.cpp index e899bb3d2..325c3c3a5 100644 --- a/Code/Source/solver/set_bc.cpp +++ b/Code/Source/solver/set_bc.cpp @@ -118,8 +118,8 @@ void calc_der_cpl_bc(ComMod& com_mod, const CmMod& cm_mod, SolutionStates& solut else { throw std::runtime_error("[calc_der_cpl_bc] Invalid physics type for 0D coupling"); } - cplBC.fa[ptr].Qo = all_fun::integ(com_mod, cm_mod, fa, Yo, 0, &Do, &Do, nsd-1, false, cfg_o); - cplBC.fa[ptr].Qn = all_fun::integ(com_mod, cm_mod, fa, Yn, 0, &Dn, &Do, nsd-1, false, cfg_n); + cplBC.fa[ptr].Qo = all_fun::integ(com_mod, cm_mod, fa, Yo, 0, solutions, nsd-1, false, cfg_o); + cplBC.fa[ptr].Qn = all_fun::integ(com_mod, cm_mod, fa, Yn, 0, solutions, nsd-1, false, cfg_n); cplBC.fa[ptr].Po = 0.0; cplBC.fa[ptr].Pn = 0.0; #ifdef debug_calc_der_cpl_bc @@ -132,8 +132,8 @@ void calc_der_cpl_bc(ComMod& com_mod, const CmMod& cm_mod, SolutionStates& solut // Compute avg pressures at 3D Dirichlet boundaries at timesteps n and n+1 else if (utils::btest(bc.bType, iBC_Dir)) { double area = fa.area; - cplBC.fa[ptr].Po = all_fun::integ(com_mod, cm_mod, fa, Yo, nsd, &Do, &Do, std::nullopt, false, MechanicalConfigurationType::reference) / area; - cplBC.fa[ptr].Pn = all_fun::integ(com_mod, cm_mod, fa, Yn, nsd, &Dn, &Do, std::nullopt, false, MechanicalConfigurationType::reference) / area; + cplBC.fa[ptr].Po = all_fun::integ(com_mod, cm_mod, fa, Yo, nsd, solutions, std::nullopt, false, MechanicalConfigurationType::reference) / area; + cplBC.fa[ptr].Pn = all_fun::integ(com_mod, cm_mod, fa, Yn, nsd, solutions, std::nullopt, false, MechanicalConfigurationType::reference) / area; cplBC.fa[ptr].Qo = 0.0; cplBC.fa[ptr].Qn = 0.0; #ifdef debug_calc_der_cpl_bc @@ -561,8 +561,8 @@ void rcr_init(ComMod& com_mod, const CmMod& cm_mod, SolutionStates& solutions) if (cplBC.initRCR) { auto& fa = com_mod.msh[iM].fa[iFa]; double area = fa.area; - double Qo = all_fun::integ(com_mod, cm_mod, fa, Yo, 0, &Do, &Do, nsd-1, false, MechanicalConfigurationType::reference); - double Po = all_fun::integ(com_mod, cm_mod, fa, Yo, nsd, &Do, &Do, std::nullopt, false, MechanicalConfigurationType::reference) / area; + double Qo = all_fun::integ(com_mod, cm_mod, fa, Yo, 0, solutions, nsd-1, false, MechanicalConfigurationType::reference); + double Po = all_fun::integ(com_mod, cm_mod, fa, Yo, nsd, solutions, std::nullopt, false, MechanicalConfigurationType::reference) / area; cplBC.xo[ptr] = Po - (Qo * cplBC.fa[ptr].RCR.Rp); } else { cplBC.xo[ptr] = cplBC.fa[ptr].RCR.Xo; @@ -711,8 +711,8 @@ void set_bc_cpl(ComMod& com_mod, CmMod& cm_mod, SolutionStates& solutions) faceType& lFa = com_mod.msh[iM].fa[iFa]; Vector sA(com_mod.tnNo); sA = 1.0; - double area = all_fun::integ(com_mod, cm_mod, lFa, sA, &Do, &Do, false, consts::MechanicalConfigurationType::reference); - baf_ini_ns::bc_ini(com_mod, cm_mod, eq.bc[iBc], lFa, Do); + double area = all_fun::integ(com_mod, cm_mod, lFa, sA, solutions, false, consts::MechanicalConfigurationType::reference); + baf_ini_ns::bc_ini(com_mod, cm_mod, eq.bc[iBc], lFa, solutions); int ptr = bc.cplBCptr; @@ -746,15 +746,15 @@ void set_bc_cpl(ComMod& com_mod, CmMod& cm_mod, SolutionStates& solutions) throw std::runtime_error("[set_bc_cpl] Invalid physics type for 0D coupling"); } - cplBC.fa[ptr].Qo = all_fun::integ(com_mod, cm_mod, com_mod.msh[iM].fa[iFa], Yo, 0, &Do, &Do, nsd-1, false, cfg_o); - cplBC.fa[ptr].Qn = all_fun::integ(com_mod, cm_mod, com_mod.msh[iM].fa[iFa], Yn, 0, &Dn, &Do, nsd-1, false, cfg_n); + cplBC.fa[ptr].Qo = all_fun::integ(com_mod, cm_mod, com_mod.msh[iM].fa[iFa], Yo, 0, solutions, nsd-1, false, cfg_o); + cplBC.fa[ptr].Qn = all_fun::integ(com_mod, cm_mod, com_mod.msh[iM].fa[iFa], Yn, 0, solutions, nsd-1, false, cfg_n); cplBC.fa[ptr].Po = 0.0; cplBC.fa[ptr].Pn = 0.0; } // Compute avg pressures at 3D Dirichlet boundaries at timesteps n and n+1 else if (utils::btest(bc.bType,iBC_Dir)) { - cplBC.fa[ptr].Po = all_fun::integ(com_mod, cm_mod, com_mod.msh[iM].fa[iFa], Yo, nsd, &Do, &Do, std::nullopt, false, MechanicalConfigurationType::reference) / area; - cplBC.fa[ptr].Pn = all_fun::integ(com_mod, cm_mod, com_mod.msh[iM].fa[iFa], Yn, nsd, &Do, &Do, std::nullopt, false, MechanicalConfigurationType::reference) / area; + cplBC.fa[ptr].Po = all_fun::integ(com_mod, cm_mod, com_mod.msh[iM].fa[iFa], Yo, nsd, solutions, std::nullopt, false, MechanicalConfigurationType::reference) / area; + cplBC.fa[ptr].Pn = all_fun::integ(com_mod, cm_mod, com_mod.msh[iM].fa[iFa], Yn, nsd, solutions, std::nullopt, false, MechanicalConfigurationType::reference) / area; cplBC.fa[ptr].Qo = 0.0; cplBC.fa[ptr].Qn = 0.0; } @@ -1432,7 +1432,7 @@ void set_bc_neu_l(ComMod& com_mod, const CmMod& cm_mod, const bcType& lBc, const } } else if (utils::btest(lBc.bType,iBC_res)) { - h(0) = lBc.r * all_fun::integ(com_mod, cm_mod, lFa, Yn, eq.s, &Do, &Do, eq.s+nsd-1, false, consts::MechanicalConfigurationType::reference); + h(0) = lBc.r * all_fun::integ(com_mod, cm_mod, lFa, Yn, eq.s, solutions, eq.s+nsd-1, false, consts::MechanicalConfigurationType::reference); } else if (utils::btest(lBc.bType,iBC_std)) { h(0) = lBc.g; diff --git a/Code/Source/solver/txt.cpp b/Code/Source/solver/txt.cpp index e5ebcc90d..ce35a916c 100644 --- a/Code/Source/solver/txt.cpp +++ b/Code/Source/solver/txt.cpp @@ -460,17 +460,17 @@ void write_boundary_integral_data(const ComMod& com_mod, CmMod& cm_mod, const eq if (m == 1) { if (div) { tmp = fa.area; - tmp = all_fun::integ(com_mod, cm_mod, fa, tmpV, 0, &Do, &Do, std::nullopt, false, consts::MechanicalConfigurationType::reference) / tmp; + tmp = all_fun::integ(com_mod, cm_mod, fa, tmpV, 0, solutions, std::nullopt, false, consts::MechanicalConfigurationType::reference) / tmp; } else { if (pFlag && lTH) { - tmp = all_fun::integ(com_mod, cm_mod, fa, tmpV, 0, &Do, &Do, std::nullopt, true, consts::MechanicalConfigurationType::reference); + tmp = all_fun::integ(com_mod, cm_mod, fa, tmpV, 0, solutions, std::nullopt, true, consts::MechanicalConfigurationType::reference); } else { - tmp = all_fun::integ(com_mod, cm_mod, fa, tmpV, 0, &Do, &Do, std::nullopt, false, consts::MechanicalConfigurationType::reference); + tmp = all_fun::integ(com_mod, cm_mod, fa, tmpV, 0, solutions, std::nullopt, false, consts::MechanicalConfigurationType::reference); } } } else if (m == nsd) { - tmp = all_fun::integ(com_mod, cm_mod, fa, tmpV, 0, &Do, &Do, m-1, false, consts::MechanicalConfigurationType::reference); + tmp = all_fun::integ(com_mod, cm_mod, fa, tmpV, 0, solutions, m-1, false, consts::MechanicalConfigurationType::reference); } else { throw std::runtime_error("WTXT only accepts 1 and nsd"); } @@ -529,9 +529,9 @@ void write_volume_integral_data(const ComMod& com_mod, CmMod& cm_mod, const eqTy if (div) { tmp = dmn.v; - tmp = all_fun::integ(com_mod, cm_mod, dmn.Id, tmpV, 0, m-1, &Do, pFlag) / tmp; + tmp = all_fun::integ(com_mod, cm_mod, dmn.Id, tmpV, 0, m-1, solutions, pFlag) / tmp; } else { - tmp = all_fun::integ(com_mod, cm_mod, dmn.Id, tmpV, 0, m-1, &Do, pFlag); + tmp = all_fun::integ(com_mod, cm_mod, dmn.Id, tmpV, 0, m-1, solutions, pFlag); } if (com_mod.cm.mas(cm_mod)) { From 3b234974484be6c9841ce3774fd219d17cbd0fbe Mon Sep 17 00:00:00 2001 From: shiyi Date: Wed, 28 Jan 2026 02:30:41 +0000 Subject: [PATCH 32/33] Fix missed integ call in uris_meanp --- Code/Source/solver/uris.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Code/Source/solver/uris.cpp b/Code/Source/solver/uris.cpp index a0051ee92..01d2960f4 100644 --- a/Code/Source/solver/uris.cpp +++ b/Code/Source/solver/uris.cpp @@ -116,7 +116,7 @@ void uris_meanp(ComMod& com_mod, CmMod& cm_mod, const int iUris, SolutionStates& tmpV(0,j) = Yn(s,j)*sDST(j); } for (int iM = 0; iM < com_mod.nMsh; iM++) { - meanPD += all_fun::integ(com_mod, cm_mod,iM, tmpV, &Do); + meanPD += all_fun::integ(com_mod, cm_mod,iM, tmpV, solutions); } meanPD = meanPD / volD; From b5ca9739b96eb8f90866ddb578a25e06d1b262fb Mon Sep 17 00:00:00 2001 From: shiyi Date: Fri, 13 Feb 2026 22:48:34 +0000 Subject: [PATCH 33/33] Add const to read-only SolutionStates& params and pass SolutionStates to gnnb/cep_integ Address PR review comments: make SolutionStates& const wherever the function only reads solution arrays, update nn::gnnb to accept const SolutionStates& instead of individual Dn/Do pointers, update cep_integ to accept SolutionStates& instead of individual arrays, and remove leftover pointer aliases that were only needed for the old gnnb interface. Co-Authored-By: Claude Opus 4.6 --- Code/Source/solver/Integrator.cpp | 2 +- Code/Source/solver/all_fun.cpp | 28 ++++++++-------------------- Code/Source/solver/all_fun.h | 10 +++++----- Code/Source/solver/baf_ini.cpp | 10 +++++----- Code/Source/solver/baf_ini.h | 6 +++--- Code/Source/solver/cep_ion.cpp | 5 ++++- Code/Source/solver/cep_ion.h | 2 +- Code/Source/solver/cmm.cpp | 4 ++-- Code/Source/solver/cmm.h | 2 +- Code/Source/solver/eq_assem.cpp | 12 ++++++------ Code/Source/solver/eq_assem.h | 6 +++--- Code/Source/solver/nn.cpp | 15 +++++++-------- Code/Source/solver/nn.h | 2 +- Code/Source/solver/output.cpp | 4 ++-- Code/Source/solver/output.h | 4 ++-- Code/Source/solver/ris.cpp | 4 ++-- Code/Source/solver/ris.h | 4 ++-- Code/Source/solver/set_bc.cpp | 18 ++++++------------ Code/Source/solver/set_bc.h | 2 +- Code/Source/solver/txt.cpp | 6 +++--- Code/Source/solver/txt.h | 6 +++--- Code/Source/solver/uris.cpp | 4 ++-- Code/Source/solver/uris.h | 4 ++-- 23 files changed, 72 insertions(+), 88 deletions(-) diff --git a/Code/Source/solver/Integrator.cpp b/Code/Source/solver/Integrator.cpp index 976aea6c2..a041f5a1e 100644 --- a/Code/Source/solver/Integrator.cpp +++ b/Code/Source/solver/Integrator.cpp @@ -486,7 +486,7 @@ void Integrator::predictor() // electrophysiology if (eq.phys == Equation_CEP) { - cep_ion::cep_integ(simulation_, iEq, e, Do, solutions_.old.get_velocity()); + cep_ion::cep_integ(simulation_, iEq, e, solutions_); } // eqn 86 of Bazilevs 2007 diff --git a/Code/Source/solver/all_fun.cpp b/Code/Source/solver/all_fun.cpp index 64c425140..d8c9f3846 100644 --- a/Code/Source/solver/all_fun.cpp +++ b/Code/Source/solver/all_fun.cpp @@ -276,7 +276,7 @@ global(const ComMod& com_mod, const CmMod& cm_mod, const mshType& lM, const Arra /// @param s an array containing a scalar value for each node in the mesh /// Replicates 'FUNCTION vIntegM(dId, s, l, u, pFlag)' defined in ALLFUN.f. // -double integ(const ComMod& com_mod, const CmMod& cm_mod, int iM, const Array& s, SolutionStates& solutions) +double integ(const ComMod& com_mod, const CmMod& cm_mod, int iM, const Array& s, const SolutionStates& solutions) { using namespace consts; @@ -429,7 +429,7 @@ double integ(const ComMod& com_mod, const CmMod& cm_mod, int iM, const Array& s, int l, int u, - SolutionStates& solutions, bool pFlag) + const SolutionStates& solutions, bool pFlag) { using namespace consts; @@ -686,7 +686,7 @@ double integ(const ComMod& com_mod, const CmMod& cm_mod, int dId, const Array& s, - SolutionStates& solutions, bool pFlag, MechanicalConfigurationType cfg) + const SolutionStates& solutions, bool pFlag, MechanicalConfigurationType cfg) { using namespace consts; #define n_debug_integ_s @@ -699,11 +699,7 @@ double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, co dmsg << "lFa.eType: " << lFa.eType; #endif - // Local aliases for solution arrays - const auto* Dn = &solutions.current.get_displacement(); - const auto* Do = &solutions.old.get_displacement(); - - bool flag = pFlag; + bool flag = pFlag; int nsd = com_mod.nsd; int insd = nsd - 1; @@ -815,7 +811,7 @@ double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, co if (!isIB) { // Get normal vector in cfg configuration auto Nx = fs.Nx.slice(g); - nn::gnnb(com_mod, lFa, e, g, nsd, insd, fs.eNoN, Nx, n, Dn, Do, cfg); + nn::gnnb(com_mod, lFa, e, g, nsd, insd, fs.eNoN, Nx, n, solutions, cfg); } // Calculating the Jacobian (encodes area of face element) @@ -854,7 +850,7 @@ double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, co /// @param cfg denotes which configuration (reference/timestep 0, old/timestep n, or new/timestep n+1). Default reference. // double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, - const Array& s, SolutionStates& solutions, MechanicalConfigurationType cfg) + const Array& s, const SolutionStates& solutions, MechanicalConfigurationType cfg) { using namespace consts; @@ -866,10 +862,6 @@ double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, dmsg << "lFa.name: " << lFa.name; #endif - // Local aliases for solution arrays - const auto* Dn = &solutions.current.get_displacement(); - const auto* Do = &solutions.old.get_displacement(); - auto& cm = com_mod.cm; int nsd = com_mod.nsd; int insd = nsd - 1; @@ -939,7 +931,7 @@ double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, if (!isIB) { // Get normal vector in cfg configuration auto Nx = lFa.Nx.slice(g); - nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, lFa.eNoN, Nx, n, Dn, Do, cfg); + nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, lFa.eNoN, Nx, n, solutions, cfg); //CALL GNNB(lFa, e, g, nsd-1, lFa.eNoN, lFa.Nx(:,:,g), n) } else { //CALL GNNIB(lFa, e, g, n) @@ -992,7 +984,7 @@ double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, /// // double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, - const Array& s, const int l, SolutionStates& solutions, std::optional uo, bool THflag, MechanicalConfigurationType cfg) + const Array& s, const int l, const SolutionStates& solutions, std::optional uo, bool THflag, MechanicalConfigurationType cfg) { using namespace consts; @@ -1005,10 +997,6 @@ double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, dmsg << "uo: " << uo; #endif - // Local aliases for solution arrays - const auto* Dn = &solutions.current.get_displacement(); - const auto* Do = &solutions.old.get_displacement(); - auto& cm = com_mod.cm; int nsd = com_mod.nsd; int insd = nsd - 1; diff --git a/Code/Source/solver/all_fun.h b/Code/Source/solver/all_fun.h index f79dfe94c..219327523 100644 --- a/Code/Source/solver/all_fun.h +++ b/Code/Source/solver/all_fun.h @@ -29,18 +29,18 @@ namespace all_fun { Array global(const ComMod& com_mod, const CmMod& cm_mod, const mshType& lM, const Array& U); - double integ(const ComMod& com_mod, const CmMod& cm_mod, int iM, const Array& s, SolutionStates& solutions); + double integ(const ComMod& com_mod, const CmMod& cm_mod, int iM, const Array& s, const SolutionStates& solutions); double integ(const ComMod& com_mod, const CmMod& cm_mod, int dId, const Array& s, int l, int u, - SolutionStates& solutions, bool pFlag=false); + const SolutionStates& solutions, bool pFlag=false); double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, const Vector& s, - SolutionStates& solutions, bool pFlag=false, consts::MechanicalConfigurationType cfg=consts::MechanicalConfigurationType::reference); + const SolutionStates& solutions, bool pFlag=false, consts::MechanicalConfigurationType cfg=consts::MechanicalConfigurationType::reference); double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, const Array& s, - const int l, SolutionStates& solutions, std::optional uo=std::nullopt, bool THflag=false, consts::MechanicalConfigurationType cfg=consts::MechanicalConfigurationType::reference); + const int l, const SolutionStates& solutions, std::optional uo=std::nullopt, bool THflag=false, consts::MechanicalConfigurationType cfg=consts::MechanicalConfigurationType::reference); - double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, const Array& s, SolutionStates& solutions, consts::MechanicalConfigurationType cfg=consts::MechanicalConfigurationType::reference); + double integ(const ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, const Array& s, const SolutionStates& solutions, consts::MechanicalConfigurationType cfg=consts::MechanicalConfigurationType::reference); bool is_domain(const ComMod& com_mod, const eqType& eq, const int node, const consts::EquationType phys); diff --git a/Code/Source/solver/baf_ini.cpp b/Code/Source/solver/baf_ini.cpp index 7833492ce..3a66d4cb4 100644 --- a/Code/Source/solver/baf_ini.cpp +++ b/Code/Source/solver/baf_ini.cpp @@ -243,7 +243,7 @@ void baf_ini(Simulation* simulation, SolutionStates& solutions) // bc_ini //--------- // -void bc_ini(const ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, faceType& lFa, SolutionStates& solutions) +void bc_ini(const ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, faceType& lFa, const SolutionStates& solutions) { // Local alias for old displacement const auto& Do = solutions.old.get_displacement(); @@ -502,7 +502,7 @@ void face_ini(Simulation* simulation, mshType& lM, faceType& lFa, SolutionStates for (int g = 0; g < lFa.nG; g++) { auto Nx = lFa.Nx.slice(g); - nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, lFa.eNoN, Nx, nV, nullptr, &Do, consts::MechanicalConfigurationType::reference); + nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, lFa.eNoN, Nx, nV, solutions, consts::MechanicalConfigurationType::reference); for (int a = 0; a < lFa.eNoN; a++) { int Ac = lFa.IEN(a,e); @@ -685,7 +685,7 @@ void face_ini(Simulation* simulation, mshType& lM, faceType& lFa, SolutionStates // // Replicates 'SUBROUTINE FSILSINI'. // -void fsi_ls_ini(ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, const faceType& lFa, int& lsPtr, SolutionStates& solutions) +void fsi_ls_ini(ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, const faceType& lFa, int& lsPtr, const SolutionStates& solutions) { // Local alias for old displacement const auto& Do = solutions.old.get_displacement(); @@ -755,7 +755,7 @@ void fsi_ls_ini(ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, const faceTyp for (int g = 0; g < lFa.nG; g++) { Vector n(nsd); auto Nx = lFa.Nx.slice(g); - nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, lFa.eNoN, Nx, n, nullptr, &Do, consts::MechanicalConfigurationType::reference); + nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, lFa.eNoN, Nx, n, solutions, consts::MechanicalConfigurationType::reference); for (int a = 0; a < lFa.eNoN; a++) { int Ac = lFa.IEN(a,e); @@ -895,7 +895,7 @@ void set_shl_xien(Simulation* simulation, mshType& lM) // // Reproduces 'SUBROUTINE SHLBCINI(lBc, lFa, lM)'. // -void shl_bc_ini(const ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, faceType& lFa, mshType& lM, SolutionStates& solutions) +void shl_bc_ini(const ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, faceType& lFa, mshType& lM, const SolutionStates& solutions) { // Local alias for old displacement const auto& Do = solutions.old.get_displacement(); diff --git a/Code/Source/solver/baf_ini.h b/Code/Source/solver/baf_ini.h index 0dff9169d..fd086b981 100644 --- a/Code/Source/solver/baf_ini.h +++ b/Code/Source/solver/baf_ini.h @@ -11,15 +11,15 @@ namespace baf_ini_ns { void baf_ini(Simulation* simulation, SolutionStates& solutions); -void bc_ini(const ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, faceType& lFa, SolutionStates& solutions); +void bc_ini(const ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, faceType& lFa, const SolutionStates& solutions); void face_ini(Simulation* simulation, mshType& lm, faceType& la, SolutionStates& solutions); -void fsi_ls_ini(ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, const faceType& lFa, int& lsPtr, SolutionStates& solutions); +void fsi_ls_ini(ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, const faceType& lFa, int& lsPtr, const SolutionStates& solutions); void set_shl_xien(Simulation* simulation, mshType& mesh); -void shl_bc_ini(const ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, faceType& lFa, mshType& lM, SolutionStates& solutions); +void shl_bc_ini(const ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, faceType& lFa, mshType& lM, const SolutionStates& solutions); void shl_ini(const ComMod& com_mod, const CmMod& cm_mod, mshType& lM); diff --git a/Code/Source/solver/cep_ion.cpp b/Code/Source/solver/cep_ion.cpp index 35343efe8..25dd1049f 100644 --- a/Code/Source/solver/cep_ion.cpp +++ b/Code/Source/solver/cep_ion.cpp @@ -141,8 +141,11 @@ void cep_init_l(CepMod& cep_mod, cepModelType& cep, int nX, int nG, Vector& Dg, Array& Yo) +void cep_integ(Simulation* simulation, const int iEq, const int iDof, SolutionStates& solutions) { + // Local aliases for solution arrays + const auto& Dg = solutions.old.get_displacement(); + auto& Yo = solutions.old.get_velocity(); static bool IPASS = true; using namespace consts; diff --git a/Code/Source/solver/cep_ion.h b/Code/Source/solver/cep_ion.h index 01227020c..cca100f3b 100644 --- a/Code/Source/solver/cep_ion.h +++ b/Code/Source/solver/cep_ion.h @@ -19,7 +19,7 @@ void cep_init(Simulation* simulation); void cep_init_l(CepMod& cep_mod, cepModelType& cep, int nX, int nG, Vector& X, Vector& Xg); -void cep_integ(Simulation* simulation, const int iEq, const int iDof, const Array& Dg, Array& Yo); +void cep_integ(Simulation* simulation, const int iEq, const int iDof, SolutionStates& solutions); void cep_integ_l(CepMod& cep_mod, cepModelType& cep, int nX, int nG, Vector& X, Vector& Xg, const double t1, double& yl, const double I4f, const double dt); diff --git a/Code/Source/solver/cmm.cpp b/Code/Source/solver/cmm.cpp index b60de90a5..ff7b7092f 100644 --- a/Code/Source/solver/cmm.cpp +++ b/Code/Source/solver/cmm.cpp @@ -262,7 +262,7 @@ void cmm_3d(ComMod& com_mod, const int eNoN, const double w, const Vector& al, const Array& dl, const Array& xl, const Array& bfl, const Vector& pS0l, const Vector& vwp, - const Vector& ptr, const Array& Do) + const Vector& ptr, const SolutionStates& solutions) { const int nsd = com_mod.nsd; const int dof = com_mod.dof; @@ -282,7 +282,7 @@ void cmm_b(ComMod& com_mod, const faceType& lFa, const int e, const Array nV(nsd); auto Nx = lFa.Nx.slice(g); - nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, 3, Nx, nV, nullptr, &Do, consts::MechanicalConfigurationType::reference); + nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, 3, Nx, nV, solutions, consts::MechanicalConfigurationType::reference); double Jac = sqrt(utils::norm(nV)); nV = nV / Jac; double w = lFa.w(g)*Jac; diff --git a/Code/Source/solver/cmm.h b/Code/Source/solver/cmm.h index 049c2f026..b6bb80d56 100644 --- a/Code/Source/solver/cmm.h +++ b/Code/Source/solver/cmm.h @@ -16,7 +16,7 @@ void cmm_3d(ComMod& com_mod, const int eNoN, const double w, const Vector& al, const Array& dl, const Array& xl, const Array& bfl, const Vector& pS0l, const Vector& vwp, - const Vector& ptr, const Array& Do); + const Vector& ptr, const SolutionStates& solutions); void bcmmi(ComMod& com_mod, const int eNoN, const int idof, const double w, const Vector& N, const Array& Nxi, const Array& xl, const Array& tfl, Array& lR); diff --git a/Code/Source/solver/eq_assem.cpp b/Code/Source/solver/eq_assem.cpp index b157cdcaf..86eaa9760 100644 --- a/Code/Source/solver/eq_assem.cpp +++ b/Code/Source/solver/eq_assem.cpp @@ -28,7 +28,7 @@ namespace eq_assem { -void b_assem_neu_bc(ComMod& com_mod, const faceType& lFa, const Vector& hg, const Array& Yg, SolutionStates& solutions) +void b_assem_neu_bc(ComMod& com_mod, const faceType& lFa, const Vector& hg, const Array& Yg, const SolutionStates& solutions) { // Local alias for old displacement const auto& Do = solutions.old.get_displacement(); @@ -79,7 +79,7 @@ void b_assem_neu_bc(ComMod& com_mod, const faceType& lFa, const Vector& for (int g = 0; g < lFa.nG; g++) { Vector nV(nsd); auto Nx = lFa.Nx.rslice(g); - nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, eNoN, Nx, nV, nullptr, &Do, consts::MechanicalConfigurationType::reference); + nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, eNoN, Nx, nV, solutions, consts::MechanicalConfigurationType::reference); double Jac = sqrt(utils::norm(nV)); nV = nV / Jac; double w = lFa.w(g)*Jac; @@ -159,7 +159,7 @@ void b_assem_neu_bc(ComMod& com_mod, const faceType& lFa, const Vector& /// @param lFa /// @param hg Pressure magnitude /// @param Dg -void b_neu_folw_p(ComMod& com_mod, const bcType& lBc, const faceType& lFa, const Vector& hg, const Array& Dg, SolutionStates& solutions) +void b_neu_folw_p(ComMod& com_mod, const bcType& lBc, const faceType& lFa, const Vector& hg, const Array& Dg, const SolutionStates& solutions) { // Local alias for old displacement const auto& Do = solutions.old.get_displacement(); @@ -251,7 +251,7 @@ void b_neu_folw_p(ComMod& com_mod, const bcType& lBc, const faceType& lFa, const // Get surface normal vector Vector nV(nsd); auto Nx_g = lFa.Nx.rslice(g); - nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, eNoNb, Nx_g, nV, nullptr, &Do, consts::MechanicalConfigurationType::reference); + nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, eNoNb, Nx_g, nV, solutions, consts::MechanicalConfigurationType::reference); Jac = sqrt(utils::norm(nV)); nV = nV / Jac; double w = lFa.w(g)*Jac; @@ -332,7 +332,7 @@ void fsi_ls_upd(ComMod& com_mod, const bcType& lBc, const faceType& lFa, Solutio auto cfg = MechanicalConfigurationType::new_timestep; - nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, lFa.eNoN, Nx, n, &Dn, &Do, cfg); + nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, lFa.eNoN, Nx, n, solutions, cfg); // for (int a = 0; a < lFa.eNoN; a++) { int Ac = lFa.IEN(a,e); @@ -358,7 +358,7 @@ void fsi_ls_upd(ComMod& com_mod, const bcType& lBc, const faceType& lFa, Solutio /// Ag(tDof,tnNo), Yg(tDof,tnNo), Dg(tDof,tnNo) // void global_eq_assem(ComMod& com_mod, CepMod& cep_mod, const mshType& lM, const Array& Ag, - const Array& Yg, const Array& Dg, SolutionStates& solutions) + const Array& Yg, const Array& Dg, const SolutionStates& solutions) { // Local alias for old displacement const auto& Do = solutions.old.get_displacement(); diff --git a/Code/Source/solver/eq_assem.h b/Code/Source/solver/eq_assem.h index 1c9ab65bf..7684c2d6a 100644 --- a/Code/Source/solver/eq_assem.h +++ b/Code/Source/solver/eq_assem.h @@ -9,13 +9,13 @@ namespace eq_assem { -void b_assem_neu_bc(ComMod& com_mod, const faceType& lFa, const Vector& hg, const Array& Yg, SolutionStates& solutions); +void b_assem_neu_bc(ComMod& com_mod, const faceType& lFa, const Vector& hg, const Array& Yg, const SolutionStates& solutions); -void b_neu_folw_p(ComMod& com_mod, const bcType& lBc, const faceType& lFa, const Vector& hg, const Array& Dg, SolutionStates& solutions); +void b_neu_folw_p(ComMod& com_mod, const bcType& lBc, const faceType& lFa, const Vector& hg, const Array& Dg, const SolutionStates& solutions); void fsi_ls_upd(ComMod& com_mod, const bcType& lBc, const faceType& lFa, SolutionStates& solutions); -void global_eq_assem(ComMod& com_mod, CepMod& cep_mod, const mshType& lM, const Array& Ag, const Array& Yg, const Array& Dg, SolutionStates& solutions); +void global_eq_assem(ComMod& com_mod, CepMod& cep_mod, const mshType& lM, const Array& Ag, const Array& Yg, const Array& Dg, const SolutionStates& solutions); }; diff --git a/Code/Source/solver/nn.cpp b/Code/Source/solver/nn.cpp index 91526ed67..f842b345e 100644 --- a/Code/Source/solver/nn.cpp +++ b/Code/Source/solver/nn.cpp @@ -523,8 +523,11 @@ void gnn(const int eNoN, const int nsd, const int insd, Array& Nxi, Arra /// Reproduce Fortran 'GNNB'. // void gnnb(const ComMod& com_mod, const faceType& lFa, const int e, const int g, const int nsd, const int insd, - const int eNoNb, const Array& Nx, Vector& n, const Array* Dn, const Array* Do, MechanicalConfigurationType cfg) + const int eNoNb, const Array& Nx, Vector& n, const SolutionStates& solutions, MechanicalConfigurationType cfg) { + // Local aliases for displacement arrays + const auto& Dn = solutions.current.get_displacement(); + const auto& Do = solutions.old.get_displacement(); auto& cm = com_mod.cm; #define n_debug_gnnb @@ -608,7 +611,7 @@ void gnnb(const ComMod& com_mod, const faceType& lFa, const int e, const int g, if (com_mod.mvMsh) { for (int i = 0; i < lX.nrows(); i++) { // Add mesh displacement - lX(i,a) = lX(i,a) + (*Do)(i+nsd+1,Ac); + lX(i,a) = lX(i,a) + Do(i+nsd+1,Ac); } } else { @@ -619,17 +622,13 @@ void gnnb(const ComMod& com_mod, const faceType& lFa, const int e, const int g, case MechanicalConfigurationType::old_timestep: for (int i = 0; i < lX.nrows(); i++) { // Add displacement at timestep n - lX(i,a) = lX(i,a) + (*Do)(i,Ac); + lX(i,a) = lX(i,a) + Do(i,Ac); } break; case MechanicalConfigurationType::new_timestep: for (int i = 0; i < lX.nrows(); i++) { // Add displacement at timestep n+1 - if (Dn != nullptr) { - lX(i,a) = lX(i,a) + (*Dn)(i,Ac); - } else { - throw std::runtime_error("gnnb: Dn required for new_timestep configuration but neither provided"); - } + lX(i,a) = lX(i,a) + Dn(i,Ac); } break; default: diff --git a/Code/Source/solver/nn.h b/Code/Source/solver/nn.h index d5046cd96..123e8ef31 100644 --- a/Code/Source/solver/nn.h +++ b/Code/Source/solver/nn.h @@ -38,7 +38,7 @@ namespace nn { double& Jac, Array& ks); void gnnb(const ComMod& com_mod, const faceType& lFa, const int e, const int g, const int nsd, const int insd, - const int eNoNb, const Array& Nx, Vector& n, const Array* Dn, const Array* Do, consts::MechanicalConfigurationType cfg=consts::MechanicalConfigurationType::reference); + const int eNoNb, const Array& Nx, Vector& n, const SolutionStates& solutions, consts::MechanicalConfigurationType cfg=consts::MechanicalConfigurationType::reference); void gnns(const int nsd, const int eNoN, const Array& Nxi, Array& xl, Vector& nV, Array& gCov, Array& gCnv); diff --git a/Code/Source/solver/output.cpp b/Code/Source/solver/output.cpp index 2330cff4e..cba75d51c 100644 --- a/Code/Source/solver/output.cpp +++ b/Code/Source/solver/output.cpp @@ -172,7 +172,7 @@ void read_restart_header(ComMod& com_mod, std::array& tStamp, double& tim /// @brief Reproduces the Fortran 'WRITERESTART' subroutine. // -void write_restart(Simulation* simulation, std::array& timeP, SolutionStates& solutions) +void write_restart(Simulation* simulation, std::array& timeP, const SolutionStates& solutions) { // Local aliases for solution arrays auto& An = solutions.current.get_acceleration(); @@ -397,7 +397,7 @@ void write_restart_header(ComMod& com_mod, std::array& timeP, std::ofs /// /// Reproduces: WRITE(fid, REC=myID) stamp, cTS, time,CPUT()-timeP(1), eq.iNorm, cplBC.xn, Yn, An, Dn // -void write_results(ComMod& com_mod, const std::array& timeP, const std::string& fName, const bool sstEq, SolutionStates& solutions) +void write_results(ComMod& com_mod, const std::array& timeP, const std::string& fName, const bool sstEq, const SolutionStates& solutions) { // Local aliases for solution arrays auto& An = solutions.current.get_acceleration(); diff --git a/Code/Source/solver/output.h b/Code/Source/solver/output.h index b7a4a8fd3..737678964 100644 --- a/Code/Source/solver/output.h +++ b/Code/Source/solver/output.h @@ -15,11 +15,11 @@ void output_result(Simulation* simulation, std::array& timeP, const i void read_restart_header(ComMod& com_mod, std::array& tStamp, double& timeP, std::ifstream& restart_file); -void write_restart(Simulation* simulation, std::array& timeP, SolutionStates& solutions); +void write_restart(Simulation* simulation, std::array& timeP, const SolutionStates& solutions); void write_restart_header(ComMod& com_mod, std::array& timeP, std::ofstream& restart_file); -void write_results(ComMod& com_mod, const std::array& timeP, const std::string& fName, const bool sstEq, SolutionStates& solutions); +void write_results(ComMod& com_mod, const std::array& timeP, const std::string& fName, const bool sstEq, const SolutionStates& solutions); }; diff --git a/Code/Source/solver/ris.cpp b/Code/Source/solver/ris.cpp index 0fe3318bc..d53ff688f 100644 --- a/Code/Source/solver/ris.cpp +++ b/Code/Source/solver/ris.cpp @@ -90,7 +90,7 @@ void ris_meanq(ComMod& com_mod, CmMod& cm_mod, SolutionStates& solutions) } /// @brief Weak treatment of RIS resistance boundary conditions -void ris_resbc(ComMod& com_mod, const Array& Yg, const Array& Dg, SolutionStates& solutions) +void ris_resbc(ComMod& com_mod, const Array& Yg, const Array& Dg, const SolutionStates& solutions) { // Local alias for old displacement const auto& Do = solutions.old.get_displacement(); @@ -151,7 +151,7 @@ void ris_resbc(ComMod& com_mod, const Array& Yg, const Array& Dg void setbc_ris(ComMod& com_mod, const bcType& lBc, const mshType& lM, const faceType& lFa, - const Array& Yg, const Array& Dg, SolutionStates& solutions) + const Array& Yg, const Array& Dg, const SolutionStates& solutions) { // [HZ] looks not needed in the current implementation } diff --git a/Code/Source/solver/ris.h b/Code/Source/solver/ris.h index 8cc200f6e..26bb88ac1 100644 --- a/Code/Source/solver/ris.h +++ b/Code/Source/solver/ris.h @@ -9,9 +9,9 @@ namespace ris { void ris_meanq(ComMod& com_mod, CmMod& cm_mod, SolutionStates& solutions); -void ris_resbc(ComMod& com_mod, const Array& Yg, const Array& Dg, SolutionStates& solutions); +void ris_resbc(ComMod& com_mod, const Array& Yg, const Array& Dg, const SolutionStates& solutions); void setbc_ris(ComMod& com_mod, const bcType& lBc, const mshType& lM, const faceType& lFa, - const Array& Yg, const Array& Dg, SolutionStates& solutions); + const Array& Yg, const Array& Dg, const SolutionStates& solutions); void ris_updater(ComMod& com_mod, CmMod& cm_mod, SolutionStates& solutions); void ris_status(ComMod& com_mod, CmMod& cm_mod); diff --git a/Code/Source/solver/set_bc.cpp b/Code/Source/solver/set_bc.cpp index 325c3c3a5..720a75e4e 100644 --- a/Code/Source/solver/set_bc.cpp +++ b/Code/Source/solver/set_bc.cpp @@ -575,9 +575,6 @@ void rcr_init(ComMod& com_mod, const CmMod& cm_mod, SolutionStates& solutions) // void set_bc_cmm(ComMod& com_mod, const CmMod& cm_mod, const Array& Ag, const Array& Dg, SolutionStates& solutions) { - // Local alias for old displacement - const auto& Do = solutions.old.get_displacement(); - using namespace consts; int cEq = com_mod.cEq; @@ -603,9 +600,6 @@ void set_bc_cmm(ComMod& com_mod, const CmMod& cm_mod, const Array& Ag, c void set_bc_cmm_l(ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, const Array& Ag, const Array& Dg, SolutionStates& solutions) { - // Local alias for old displacement - const auto& Do = solutions.old.get_displacement(); - using namespace consts; const int nsd = com_mod.nsd; @@ -656,7 +650,7 @@ void set_bc_cmm_l(ComMod& com_mod, const CmMod& cm_mod, const faceType& lFa, con vwp = vwp / 3.0; // Add CMM BCs contributions to the LHS/RHS - cmm::cmm_b(com_mod, lFa, e, al, dl, xl, bfl, pSl, vwp, ptr, Do); + cmm::cmm_b(com_mod, lFa, e, al, dl, xl, bfl, pSl, vwp, ptr, solutions); } } @@ -1101,7 +1095,7 @@ void set_bc_dir_w(ComMod& com_mod, const Array& Yg, const Array& /// @brief Reproduces Fortran 'SETBCDIRWL'. // -void set_bc_dir_wl(ComMod& com_mod, const bcType& lBc, const mshType& lM, const faceType& lFa, const Array& Yg, const Array& Dg, SolutionStates& solutions) +void set_bc_dir_wl(ComMod& com_mod, const bcType& lBc, const mshType& lM, const faceType& lFa, const Array& Yg, const Array& Dg, const SolutionStates& solutions) { // Local alias for old displacement const auto& Do = solutions.old.get_displacement(); @@ -1292,7 +1286,7 @@ void set_bc_dir_wl(ComMod& com_mod, const bcType& lBc, const mshType& lM, const for (int g = 0; g < lFa.nG; g++) { Vector nV(nsd); auto Nx = lFa.Nx.slice(g); - nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, eNoNb, Nx, nV, nullptr, &Do, consts::MechanicalConfigurationType::reference); + nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, eNoNb, Nx, nV, solutions, consts::MechanicalConfigurationType::reference); double Jac = sqrt(utils::norm(nV)); nV = nV / Jac; double w = lFa.w(g) * Jac; @@ -1556,10 +1550,10 @@ void set_bc_rbnl(ComMod& com_mod, const faceType& lFa, const RobinBoundaryCondit for (int g = 0; g < lFa.nG; g++) { Vector nV(nsd); auto Nx = lFa.Nx.slice(g); - nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, eNoN, Nx, nV, nullptr, &Do, consts::MechanicalConfigurationType::reference); + nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, eNoN, Nx, nV, solutions, consts::MechanicalConfigurationType::reference); double Jac = sqrt(utils::norm(nV)); nV = nV / Jac; - double w = lFa.w(g) * Jac; + double w = lFa.w(g) * Jac; N = lFa.N.col(g); Vector u(nsd), ud(nsd); @@ -1839,7 +1833,7 @@ void set_bc_trac_l(ComMod& com_mod, const CmMod& cm_mod, const bcType& lBc, cons for (int g = 0; g < lFa.nG; g++) { Vector nV(nsd); auto Nx = lFa.Nx.slice(g); - nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, eNoN, Nx, nV, nullptr, &Do, consts::MechanicalConfigurationType::reference); + nn::gnnb(com_mod, lFa, e, g, nsd, nsd-1, eNoN, Nx, nV, solutions, consts::MechanicalConfigurationType::reference); double Jac = sqrt(utils::norm(nV)); double w = lFa.w(g)*Jac; N = lFa.N.col(g); diff --git a/Code/Source/solver/set_bc.h b/Code/Source/solver/set_bc.h index 8428152bc..9cfda19b5 100644 --- a/Code/Source/solver/set_bc.h +++ b/Code/Source/solver/set_bc.h @@ -30,7 +30,7 @@ void set_bc_cpl(ComMod& com_mod, CmMod& cm_mod, SolutionStates& solutions); void set_bc_dir(ComMod& com_mod, SolutionStates& solutions); void set_bc_dir_l(ComMod& com_mod, const bcType& lBc, const faceType& lFa, Array& lA, Array& lY, int lDof); void set_bc_dir_w(ComMod& com_mod, const Array& Yg, const Array& Dg, SolutionStates& solutions); -void set_bc_dir_wl(ComMod& com_mod, const bcType& lBc, const mshType& lM, const faceType& lFa, const Array& Yg, const Array& Dg, SolutionStates& solutions); +void set_bc_dir_wl(ComMod& com_mod, const bcType& lBc, const mshType& lM, const faceType& lFa, const Array& Yg, const Array& Dg, const SolutionStates& solutions); void set_bc_neu(ComMod& com_mod, const CmMod& cm_mod, const Array& Yg, const Array& Dg, SolutionStates& solutions); void set_bc_neu_l(ComMod& com_mod, const CmMod& cm_mod, const bcType& lBc, const faceType& lFa, const Array& Yg, const Array& Dg, SolutionStates& solutions); diff --git a/Code/Source/solver/txt.cpp b/Code/Source/solver/txt.cpp index ce35a916c..40a6e9157 100644 --- a/Code/Source/solver/txt.cpp +++ b/Code/Source/solver/txt.cpp @@ -140,7 +140,7 @@ void create_volume_integral_file(const ComMod& com_mod, CmMod& cm_mod, const eqT // init_write - if true then this is the start of the simulation and // so create a new file to initialize output. // -void txt(Simulation* simulation, const bool init_write, SolutionStates& solutions) +void txt(Simulation* simulation, const bool init_write, const SolutionStates& solutions) { // Local aliases for solution arrays auto& An = solutions.current.get_acceleration(); @@ -414,7 +414,7 @@ void txt(Simulation* simulation, const bool init_write, SolutionStates& solution /// NOTE: Be carefu of a potential indexing problem here because 'm' is a length and not an index. // void write_boundary_integral_data(const ComMod& com_mod, CmMod& cm_mod, const eqType& lEq, const int m, - const std::string file_name, const Array& tmpV, const bool div, const bool pFlag, SolutionStates& solutions) + const std::string file_name, const Array& tmpV, const bool div, const bool pFlag, const SolutionStates& solutions) { // Local alias for old displacement const auto& Do = solutions.old.get_displacement(); @@ -492,7 +492,7 @@ void write_boundary_integral_data(const ComMod& com_mod, CmMod& cm_mod, const eq /// NOTE: Be carefu of a potential indexing problem here because 'm' is a length and not an index. // void write_volume_integral_data(const ComMod& com_mod, CmMod& cm_mod, const eqType& lEq, const int m, - const std::string file_name, const Array& tmpV, const bool div, const bool pFlag, SolutionStates& solutions) + const std::string file_name, const Array& tmpV, const bool div, const bool pFlag, const SolutionStates& solutions) { // Local alias for old displacement const auto& Do = solutions.old.get_displacement(); diff --git a/Code/Source/solver/txt.h b/Code/Source/solver/txt.h index 33b886de8..b70a223b9 100644 --- a/Code/Source/solver/txt.h +++ b/Code/Source/solver/txt.h @@ -16,13 +16,13 @@ void create_boundary_integral_file(const ComMod& com_mod, CmMod& cm_mod, const e void create_volume_integral_file(const ComMod& com_mod, CmMod& cm_mod, const eqType& lEq, const std::string& file_name); -void txt(Simulation* simulation, const bool flag, SolutionStates& solutions); +void txt(Simulation* simulation, const bool flag, const SolutionStates& solutions); void write_boundary_integral_data(const ComMod& com_mod, CmMod& cm_mod, const eqType& lEq, const int m, - const std::string file_name, const Array& tmpV, const bool div, const bool pFlag, SolutionStates& solutions); + const std::string file_name, const Array& tmpV, const bool div, const bool pFlag, const SolutionStates& solutions); void write_volume_integral_data(const ComMod& com_mod, CmMod& cm_mod, const eqType& lEq, const int m, - const std::string file_name, const Array& tmpV, const bool div, const bool pFlag, SolutionStates& solutions); + const std::string file_name, const Array& tmpV, const bool div, const bool pFlag, const SolutionStates& solutions); }; diff --git a/Code/Source/solver/uris.cpp b/Code/Source/solver/uris.cpp index 01d2960f4..4b073348a 100644 --- a/Code/Source/solver/uris.cpp +++ b/Code/Source/solver/uris.cpp @@ -19,7 +19,7 @@ namespace uris { /// @brief This subroutine computes the mean pressure and flux on the /// immersed surface -void uris_meanp(ComMod& com_mod, CmMod& cm_mod, const int iUris, SolutionStates& solutions) { +void uris_meanp(ComMod& com_mod, CmMod& cm_mod, const int iUris, const SolutionStates& solutions) { // Local aliases for solution arrays auto& Yn = solutions.current.get_velocity(); auto& Do = solutions.old.get_displacement(); @@ -153,7 +153,7 @@ void uris_meanp(ComMod& com_mod, CmMod& cm_mod, const int iUris, SolutionStates& /// @brief This subroutine computes the mean velocity in the fluid elements /// near the immersed surface -void uris_meanv(ComMod& com_mod, CmMod& cm_mod, const int iUris, SolutionStates& solutions) { +void uris_meanv(ComMod& com_mod, CmMod& cm_mod, const int iUris, const SolutionStates& solutions) { // Local aliases for solution arrays auto& Yn = solutions.current.get_velocity(); auto& Do = solutions.old.get_displacement(); diff --git a/Code/Source/solver/uris.h b/Code/Source/solver/uris.h index 5c04aa121..90678a854 100644 --- a/Code/Source/solver/uris.h +++ b/Code/Source/solver/uris.h @@ -9,9 +9,9 @@ namespace uris { -void uris_meanp(ComMod& com_mod, CmMod& cm_mod, const int iUris, SolutionStates& solutions); // done +void uris_meanp(ComMod& com_mod, CmMod& cm_mod, const int iUris, const SolutionStates& solutions); // done -void uris_meanv(ComMod& com_mod, CmMod& cm_mod, const int iUris, SolutionStates& solutions); // done +void uris_meanv(ComMod& com_mod, CmMod& cm_mod, const int iUris, const SolutionStates& solutions); // done void uris_update_disp(ComMod& com_mod, CmMod& cm_mod, SolutionStates& solutions);