I am developing a 0D model for the cardiac circulation and I would like to compute the workload as the internal area of the Pressure Volume -loop. Do you know any method that allow me to do this even if my PV loop is extracted and defined just by the points (ventricular volume, ventricular pressure ) ?
This is a julia programming forum, the general julia programmer will probably not know what PV, VLV or PLV refers to. You may want to introduce your problem a bit better for the audience expected to read it here.
I’d say you probably want to use the area of a polygon.
It’s very hard to tell what you’re asking for without more detail. Could you either edit your initial post or add a reply that explains what exactly you’re trying to compute (I’m assuming you mean W = \int P dV, but I’m not sure), along with what you have so far? In particular, if you have a PV diagram of this loop, that could be very helpful for understanding what you’re trying to accomplish.
It sounds like you are trying to solve a numerical-integration problem, also called “quadrature”. There are lots of quadrature algorithms, but a key question is whether you can choose the points. If you can, then you can get a much more accurate result for the same number of points (e.g. by applying Gaussian quadrature to something like the Green’s theorem formulae below).
This corresponds to numerical integration by the trapezoidal rule.
e.g. you could use the shoelace formula for the polygon area, which is closely related to a trapezoidal rule applied to the Green’s theorem formulae \text{area} = \oint_C x \, dy = - \oint_C y\, dx.
The problem is that my Pv loop is defined just through points, I compute the pressure and the volume separately and then match the pressure with the corresponding volume in time. So far I am just interested on its plot p3=plot(V_LV_vec[t_vec.>t_end-5], PLV[t_vec.>t_end-5].*Pa2mmHg; label=“LV”, xlabel=“Volume [ml]”, ylabel=“Pressure [mmHg]”,color=lv_color)
You can still use the trapezoidal rule / polygon area, of course, for low-order accuracy.
If you can choose the time points, and you have the time derivative of either the pressure or volume, you can still use a higher-order quadrature rule, since \oint_C x dy = \int x\frac{dy}{dt} dt. (Here, x is pressure and y is volume or vice versa.)
How are you computing pressure and volume as a function of time? If it is an ODE solver like DifferentialEquations.jl (for your 0D cardiac model), that will be able to (a) give you the time derivatives too and (b) compute the time when the loop closes to high-order accuracy using a continuous callback, and (c) let the ODE solver accumulate the area integral for you (so that you don’t need a separate quadrature rule, you just add another equation \frac{dA}{dt} = x \frac{dy}{dt}.