Questions tagged [c++]

A powerful object oriented programming language.

Filter by
Sorted by
Tagged with
6
votes
4answers
4k views

How to efficiently assemble global stiffness matrix in sparse storage format (c++)

I am writing a finite element solver in C++. The main bottle neck is assembling the global stiffness matrix in sparse compressed row storage (so far I am only solving steady problems). Because I don't ...
6
votes
2answers
6k views

Programming Finite Element Methods in C++

I am trying to develop a library for finite element methods in C++ and for that I am looking at the data structures for meshes. Based on what I've read up on fenics and deal.ii, the general ...
6
votes
1answer
402 views

Using Log Gamma function to avoid overflow

I have to do some numerical calculus using gamma functions. I am using the tgamma incluided in the C++ cmath library. The ...
6
votes
2answers
2k views

Which libraries have good implementations of Basis splines?

I'm looking to use the finite element method with B-splines as my function basis. Which C/C++ libraries have good B-spline support? Specifically, I'm looking for an implementation of a stable ...
6
votes
2answers
165 views

Generating set of points on a surface defined by constraint

I'm writing a differential geometry library, and one minor convenience I'd like to offer is to generate a set of points on a surface given by a constraint. For example, for a sphere, $$x^2+y^2+z^2-r^...
6
votes
2answers
938 views

How to implement adaptive mesh refinement using conformal triangles

I am trying to implement adaptive mesh refinement for a finite element code. The code uses (at least for now) linear triangles and so when I do the mesh refinement I want the triangular mesh to remain ...
6
votes
1answer
2k views

Why does std::complex<> initialize its value to 0 upon default construction?

Doing so strikes me as a waste of time. Consider std::complex<double> *a = new std::complex<double>[1<<28]; This could be near-instantaneous ...
6
votes
1answer
2k views

Flexible Mesh Framework

I am looking for flexible and easy to learn mesh framework which provides data structure for representing and manipulating meshes in 2D i 3D. I've already found a few: MSTK https://software.lanl.gov/...
5
votes
3answers
1k views

Efficiently computing the product of a multi-dimensional matrix (or tensor) and vectors

Update: Thank you very much for all of you who answered below. I'm studying each answer now. In the long term, I'm more interested in solutions that work for sparse tensors (sorry I should have ...
5
votes
1answer
128 views

Whittaker-Shannon interpolation: Accuracy dies with speedup; can it be fixed?

With a truncated Whitaker-Shannon series (cardinal series) $$ f(t) = \sum_{j = 0}^{n-1} y_{j} \frac{\sin\left(\pi( \frac{t-t_0}{h} -j)\right)}{\pi\left(\frac{t-t_0}{h}-j\right)} $$ we can naively ...
5
votes
1answer
1k views

Why do libraries need hand-vectorized code instead of compiler auto vectorization

C++ eigen library does vectorization for different architecture, like SSE, NEON etc. In their documentation they mentioned that, Eigen vectorization is not compiler dependent. But most modern ...
5
votes
2answers
245 views

Recommended language/environment for large scale semi-continuous biological models

We have a fairly large (maybe 1000 equations) differential-algebraic equation model written in ACSLX, an obsolete modelling environment similar to Modelica. The model represents the evolution of a ...
5
votes
3answers
816 views

What do C, C++ and Java have that Fortran 2003 don't? [closed]

As you may know, Fortran is widely and longly (?) used in science. I've heard a lot of people saying that we natural scientists should all migrate to C++ or Java. I've seen people increasingly ...
5
votes
2answers
523 views

Machine precision and local error

I'm working with an RKF45 integrator that I have programmed using CUDA C++ on my GPU and am pondering a few questions as I'm trying to track down some issues with my code. I'm using double ...
5
votes
3answers
997 views

Efficient eigen-decomposition of covariance matrix

I am looking for an C/C++/Python algorithm implementation that calculates eigenvalues and eigenvectors of a symmetric, positive semidefinite covariance matrix. A general-purpose eigen-decomposition ...
5
votes
2answers
10k views

C++ libraries for Fast Fourier Transform in high precision

I am looking for a C++ library for Fast Fourier Transform (FFT) in high precision (e.g., using high precision real data types similar to mpfr_t in MPFR or ...
5
votes
1answer
590 views

2D numerical integration with infinite limit (C++)

In order to integrate a two dimensional function of the form $$\int_{1}^\infty \int_{-\sqrt{x^2-1}}^{\sqrt{x^2-1}} e^{-x} \rm{d}y \rm{d}x,$$ I have been attempting to use the following code (written ...
5
votes
2answers
1k views

Three-body problem

I wrote the following program to solve the three body problem (Sun, Earth, Jupiter), initializing the system such that the total angular momentum is 0. The result of the simulation is really bad (and ...
5
votes
1answer
130 views

Use Butterworth and Chebychev filters

I need to calculate frequency response, phase response and apply to signals the Butterworth, Chebychev1 and Chebychev2 band-pass filters. I'm developing in C++ with Qt, and I'm looking for algorithms ...
4
votes
3answers
468 views

Literature material discussing generic frameworks to solve PDEs

I am trying to gather literature material to study how people propose to implement generic frameworks to solve partial differential equations in C++. Despite my effort to search the web, the only ...
4
votes
2answers
334 views

Can the Levenberg-Marquardt algorithm be used for minimization and not fitting

Can the Levenberg-Marquardt algorithm be used for minimization and not fitting? Usually we input the derivative of the function we want to fit in the minimizer. Now if I assume I have an objective ...
4
votes
3answers
2k views

A good, simple book/resource on Parallel Programming in C++ for scientific computing

I am a Mechanical Engineering grad student, currently working on a project which will be scaled up in the new future to require quite some processing power. I am using C++ for the code that I have, ...
4
votes
3answers
3k views

Beating typical BLAS libraries matrix multiplication performance

A dull matrix multiplication algorithm where we use the formula $$C_{ij}=\sum_{k}A_{ik}B_{kj}$$ By literally following this in 3 loops we'll get a very slow program, because we don't utilize ...
4
votes
3answers
430 views

How to obtain finite difference, which is continuous

I want to calculate a finite difference (something like this SO Post). My data is as follows: I have x-values that are powers of two (4, 8, 16, 32 and 64). Corresponding to them are y-values, such ...
4
votes
5answers
1k views

Finding the correct Molecular Dynamics library

I just started working on some Biophysics research, and I was looking around for a good MD library to use. There is one right now at the university set up in C, with openMC parallelization, but the ...
4
votes
3answers
257 views

Best software to do big number calculations quickly

I am trying to do some work on some math conjecture. I am testing the conjecture numbers using very large math numbers (100+ digits ). I am currently using python to test these numbers. In the ...
4
votes
1answer
126 views

Using GSL for basic operations

I am learning C/C++ for Scientific Computing and I have a question regarding the usage of scientific libraries for basic operations. Suppose I have to write a small program in C for a bioinformatics ...
4
votes
2answers
405 views

overflow upper incomplete gamma function

I want to calculate the following equation: $$\frac{\theta \Gamma \left(\kappa+1,\frac{o}{\theta }\right)-o \Gamma \left(\kappa,\frac{o}{\theta }\right)}{\Gamma (\kappa)}+o+s$$ with $s>0, o>0, ...
4
votes
1answer
226 views

What is the most efficient way to obtain the max eigenvalue of a specific symmetric matrix via Eigen C++

Suppose I have a symmetric matrix $A_{1000\times 1000}$, which can be represented by: $A = J G J^T$ where $J$ in 1000x3 is full column rank dense matrix; $G$ in 3x3 is a nonsingular dense matrix. ...
4
votes
3answers
582 views

Minimization of non-linear function

Problem Summary I am trying to estimate the (x,y) coordinates of each node in a graph, where I know the distances between connected nodes. For example Given this ...
4
votes
1answer
136 views

Simple Monte Carlo in C++, result dependent from seed

I implemented as an exercise a program to sample the statistics of the escape time of a Brownian particle in a potential well. I used the Euler-Maruyama method to numerically integrate the ...
4
votes
1answer
982 views

Solver suggestion for many small quadratic problem in C++

I have a C++ program/model that in some parts already use IPOPT (with ADOL-C and ColPack) to solve some pretty large non linear problems. Now in an other part of the program I need to solve a large ...
4
votes
2answers
328 views

Advice on handling many “small” matrices in parallel

I'm working on a small fun project on the side for a numerical method I've been working a bit with. Roughly, the computational problem I have to solve is the following: Assume you have a collection of ...
4
votes
0answers
219 views

Adaptive mesh data structure for Fast Marching Method to overcome RAM limit

On an uniform mesh of positions in space $\ (x_i,y_j,z_k)$: $$\ x_i = x_0 + i\Delta x,\quad i=0,\ldots,n_x$$ $$\ y_j = y_0 + j\Delta y,\quad j=0,\ldots,n_y$$ $$\ z_k = z_0 + k\Delta z,\quad k=0,\...
3
votes
3answers
2k views

What modern OOP features should a computational scientist use? [closed]

Many computational scientists that I know of, including myself for example, are not computer scientists. As such they are often not very well aware more advanced techniques in OOP. On the other hand, ...
3
votes
2answers
1k views

Stabilizing a 3x3 real symmetric matrix eigenvalue calculation

I have many 3x3 real symmetric matrices for which I need to determine the eigenvalues. Wikipedia gives a nice non-iterative algorithm for this case, which I have translated into C++: ...
3
votes
2answers
496 views

I am searching for a C++ code implementing the complex polygamma function

I googled about some code on the complex polygamma function especially C++ code, but can't find anything. Does anyone know where to find such code? The complex digamma function does exist but not the ...
3
votes
3answers
320 views

Simple way to store/read data from file in C++

I've been running various simulations with C++, and doing so has often involved saving lots of data to file (real/complex matrices, arrays, etc) and then reading them into other programs later. ...
3
votes
1answer
185 views

Fastest method forfinding a solution to x*log(x)

more specifically, $C x \log_2(x)- K = 0$, where $C$ and $K$ are constants ($\log_2$ means log base 2). I was solving a topcoder problem, SortEstimate, which requires us to solve the aforementioned ...
3
votes
2answers
624 views

literature on scientific computing

Maybe, this is a dump question. But anyway. I developed a finite difference code for a class of problems in dynamo theory. I used GNU Octave (MATLAB) which is good for testing. The problem size ...
3
votes
2answers
662 views

How to re-use the coefficient matrix decomposition result when solving linear systems by Eigen C++

My problem needs to solve dense symmetric linear systems something like: A x = b, A y = x, ...
3
votes
2answers
1k views

How Do I solve large systems given UMFPACK memory limitations?

I am trying to solve a system of equations (A x = b) for 3D heat diffusion (i.e. each equation has at most 7 terms not including the constant "b" term) using UMFPACK with boost numeric bindings to C++....
3
votes
2answers
832 views

FEniCS: extracting points from a cell

I'd like to loop over all edges of a simplex (in a mesh). To this end: How can I extract the the points from a cell? This is for the eval method of a C++ ...
3
votes
2answers
235 views

FEM libraries with weak forms

I need to implement a structural analysis code, and I turn to you for advice. My needs are simple: Library must be integrable in a C++ code I want to express a weak form, without manual intervention ...
3
votes
3answers
1k views

Leave openMP theads ready

I have a C++ program that has a double for loop that I'd like to parallelize using opeMP. It is simple (a polynomial product) of varying length (between 100 and ...
3
votes
1answer
3k views

How to change the dimensions of an Eigen Matrix in a loop?

I have a while loop, in which I use a Matrix A, vectors B and x with varying dimensions: <...
3
votes
3answers
124 views

GPGPU computing, software selection

I am using an existing GCC C++ x86 Qt application that filters, displays and stores results computed by some C code. Since the computation by now got too complex for CPUs I intend to port the small C ...
3
votes
2answers
625 views

Why is SIMD programming on such a low level in CPU's compared to GPU's?

Just speaking from my experience in c++ - Its really tricky to take advantage of the SIMD capabilities of modern CPU's for more complex algorithms. If I see an opportunity from a high level OO ...
3
votes
3answers
3k views

C++ Libraries for solving Complex Linear systems Ax=b [duplicate]

I am interested in solving a sparse complex linear system Ax=b where A is a square matrix of complex numbers and b is vector of complex numbers. If possible I would like such a library to be ...
3
votes
2answers
662 views

How to avoid precision loss when handling very long integer constant involved multiple precision computation?

I have a numerical computation problem which requires solving nonlinear equations (with long integers) in multiple precision. I tried an MPFR C++ wrapper from this link by Pavel: mpfr C++ wrapper by ...