-3

I'm currently trying to optimise a program I've written in C++. It's a finite element method simulation of arbitrary electrostatics systems, using user defined boundary conditions.

It works, but in order to keep the boundary conditions - which can be arbitrary shapes - constant I am rewriting those elements at the start of each loop.

In the interest of - possibly - improving computation time and code conciseness, I'd like to set those elements once and have them protected. All I've managed to find so far is how to initialise an entire const array, not individual protected elements.

Is this possible in C++, or are there any libraries that would allow this to be done?

Stephen
  • 1
  • 1
  • 3
    Wrap the array into a class, and provide a `const` getter function. – πάντα ῥεῖ Feb 05 '15 at 11:51
  • I don't see how any of this would improve computation time or code conciseness – M.M Feb 05 '15 at 11:59
  • At the moment I'm running a loop to write boundary conditions - which can be arbitrary shapes within the array, not just values at the edges. I'm then running row by row and calculating values for each element using FEM. I assumed not having to run a boundary value loop for each iteration would save time. Maybe I'm wrong though. – Stephen Feb 05 '15 at 12:04

1 Answers1

0

The easiest solution is to not loop over these elements in your update funciton. If you have int x[10] with boundary conditions x[0]=x[9]=0, just update x[1] to x[8].

MSalters
  • 173,980
  • 10
  • 155
  • 350