SimVascular / svZeroDSolver

A C++ lumped-parameter solver for blood flow and pressure in hemodynamic networks
Other
6 stars 18 forks source link

Output file: long string name causes wrong format #100

Open chlookaburra opened 7 months ago

chlookaburra commented 7 months ago

Description

If the string name of a blood vessel is too long, then it will append to the pressure_out column, instead of at the start of a new row.

See the attached file, where the first row has the usual time, flow_in, flow_out, pressure_in, pressure_out columns. However, the second and third rows have the name of the next blood vessel in the pressure_out column, which can cut off the value of pressure_out (as in the third row).

Screenshot 2024-02-12 at 7 56 41 PM

Reproduction

One could try naming a blood vessel "RightCommonCarotidArtery," which will reproduce this result.

Expected behavior

We would like svZeroDSolver to throw an error if we enter a blood vessel name that is too long or accept long strings.

Additional context

No response

Code of Conduct

mrp089 commented 6 months ago

While @chlookaburra and I were looking at the code, we noticed two occasions where we're using a fixed-size buffer: https://github.com/SimVascular/svZeroDSolver/blob/7c722a51d58fa2784418b0cc012d103024d27344/src/solve/csv_writer.cpp#L50-L52 https://github.com/SimVascular/svZeroDSolver/blob/7c722a51d58fa2784418b0cc012d103024d27344/src/solve/csv_writer.cpp#L182-L184 I could see a full buffer causing this problem (I don't know if those sizes are hard-coded for performance). As a first step, try increasing them and see if that solves the problem. If yes, we could either dynamically allocate the size (if that doesn't reduce performance) or throw an error if things would be written incorrectly.

ktbolt commented 4 months ago

Output should use iostream with iomanip not fixed-size char arrays.