Dear all,
For my application I am trying to compute “strain-histories” of particles inside a fluid domain.
I am using LEoPart to initiate and track the particles inside the fluid domain.
Using the particle.interpolate()
function, I can compute the instantaneous strain that every particle is exposed to for every timestep.
Now, because I am interested in the accumulation of strain “experience” for the particles, I would like to sum the strain values for every timestep. Using ‘particle.interpolate()’, the new values are used to overwrite the old values, whereas I would like to add the new values to the old values.
The cpp code for interpolate() is as follows:
void particles::interpolate(const Function& phih,
const std::size_t property_idx)
{
std::size_t space_dimension, value_size_loc;
space_dimension = phih.function_space()->element()->space_dimension();
value_size_loc = 1;
for (std::size_t i = 0; i < phih.function_space()->element()->value_rank();
i++)
value_size_loc *= phih.function_space()->element()->value_dimension(i);
if (value_size_loc != _ptemplate[property_idx])
dolfin_error("particles::interpolate", "get property idx",
"Local value size mismatches particle template property");
for (CellIterator cell(*(_mesh)); !cell.end(); ++cell)
{
std::vector<double> coeffs;
Utils::return_expansion_coeffs(coeffs, *cell, &phih);
for (std::size_t pidx = 0; pidx < num_cell_particles(cell->index()); pidx++)
{
Eigen::MatrixXd basis_mat(value_size_loc, space_dimension);
Utils::return_basis_matrix(basis_mat.data(), x(cell->index(), pidx),
*cell, phih.function_space()->element());
Eigen::Map<Eigen::VectorXd> exp_coeffs(coeffs.data(), space_dimension);
Eigen::VectorXd phi_p = basis_mat * exp_coeffs;
// Then update
Point phi_point(_ptemplate[property_idx], phi_p.data());
_cell2part[cell->index()][pidx][property_idx] = phi_point;
}
}
}
I have no experience in cpp, but this might be the moment to start learning.
However, looking at this section of code I believe I need to modify this section:
// Then update
Point phi_point(_ptemplate[property_idx], phi_p.data());
_cell2part[cell->index()][pidx][property_idx] = phi_point;
Instead of “=phi_point”, I would like to do something like “old value”+phi_point.
Using compound assignment, would the following code work according to my needs?
// Then update
Point phi_point(_ptemplate[property_idx], phi_p.data());
_cell2part[cell->index()][pidx][property_idx] += phi_point;
If not, I will address this using python and in the meantime I will be learning cpp.
If yes, how can I compile the c++ code after making the edit?
Thank you in advance,
With kind regards,