LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Slow speed code in formula node

Solved!
Go to solution

Hi,

Attached the .vi. It works correctly, I have verified and it is what I was searching for. No need others.

Thank you very much for supporting me.

 

Best regards,

Mal

0 Kudos
Message 11 of 18
(564 Views)
Solution
Accepted by Mal123

A few simple suggestions:

 

  • Use complex math to do the input processing.
  • x2 and /2 should be done using scale by powers of two because it is especially easy in binary.
  • I am not sure if the compound multiply really constant folds the (0.0005x pi x pi), so I would take that out.
  • I would recommend to save the VI so the controls are in view.
  • it is useful if the controls have some default values.

 

altenbach_0-1697553977437.png

 

Message 12 of 18
(540 Views)

Another level of a smart mind.

Thanks Altenbach!

0 Kudos
Message 13 of 18
(516 Views)

Hi,
I would like to convert attached Open Office BASIC code to LabVIEW, it is related to inductance of a solenoid.


Is it possible then to adapt it for more layers?

 

A section of it was already done by Bob_Schor and Altenbach.

0 Kudos
Message 14 of 18
(153 Views)

@Mal123 wrote:

Hi,
I would like to convert attached Open Office BASIC code to LabVIEW, it is related to inductance of a solenoid.


Is it possible then to adapt it for more layers?

 

A section of it was already done by Bob_Schor and Altenbach.


The easiest way is probably to convert the given BASIC code to C using any available AI assistant (I'm serious), then wrap it in a DLL and use it in LabVIEW. I don't think there will be significant performance improvement (DLL could be a bit slower in this case), but at least it will save you time wiring such code.

This is what I've got from Microsoft Copilot:

Spoiler
double Mut(double r1, double r2, double x) {
	double a = sqrt(pow(r1 + r2, 2) + pow(x, 2));
	double b = sqrt(pow(r1 - r2, 2) + pow(x, 2));
	double c = a - b;
	double ci = 1;
	double cs = c * c;
	double ao, co;

	do {
		ao = (a + b) / 2;
		b = sqrt(a * b);
		a = ao;
		co = c;
		c = a - b;
		ci *= 2;
		cs += ci * c * c;
	} while (c < co);

	return 0.0005 * pow(M_PI, 2) * cs / a;
}


double LayeredCoil(double d, double r0, double kx, double ky, 
				   int n1, int n2, int n3, int n4, int n5, int n6, int n7, int n8, int n9, int n10) 
{
	int Nturns[10] = {n1, n2, n3, n4, n5, n6, n7, n8, n9, n10};
	double xoffset[10] = {0}, yoffset[10] = {0};
	int MaxN = Nturns[0];
	int N = 0;
	double g = exp(-0.25) * d / 2;
	double L = 0;
	double M = 0;
	int i, j, iLayer, jLayer;
	double ix, iy, jx, jy;

	// Find the layer with the maximum number of turns
	for (i = 1; i < 10; i++) {
		if (MaxN < Nturns[i]) {
			MaxN = Nturns[i];
		}
	}

	// Calculate the x and y offsets for each layer, total turns, and self-inductance
	for (i = 0; i < 10; i++) {
		N += Nturns[i];
		xoffset[i] = (MaxN - Nturns[i]) / 2.0 * kx;
		yoffset[i] = r0 + ky * i;
		L += Nturns[i] * Mut(yoffset[i], yoffset[i], g);
	}

	// Change Nturns array to running total of turns
	for (i = 1; i < 10; i++) {
		Nturns[i] += Nturns[i - 1];
	}

	// Calculate mutual inductance for every pair of turns i and j
	iLayer = 0;
	ix = xoffset[iLayer];
	iy = yoffset[iLayer];
	for (i = 0; i < N - 1; i++) {
		if (Nturns[iLayer] <= i) {
			iLayer++;
			ix = xoffset[iLayer];
			iy = yoffset[iLayer];
		}
		jLayer = iLayer;
		jx = ix + kx;
		jy = yoffset[jLayer];
		for (j = i + 1; j < N; j++) {
			if (Nturns[jLayer] <= j) {
				jLayer++;
				jx = xoffset[jLayer];
				jy = yoffset[jLayer];
			}
			M += Mut(iy, jy, ix - jx);
			jx += kx;
		}
		ix += kx;
	}

	return L + 2 * M;
}

No idea if the result is correct or not (but at least Mut seems to be not so bad).

Attached code (LabVIEW 2018 + NI CVI 2020).

0 Kudos
Message 15 of 18
(137 Views)

Hi Andrey Dmitriev,

You have been very fast!

Thank you, but I cannot use dll, I need LabVIEW code, or at least a formula node...

...is it possible to put your code in a formula node?

 

 

 

0 Kudos
Message 16 of 18
(127 Views)

@Mal123 wrote:

Hi Andrey Dmitriev,

You have been very fast!

Thank you, but I cannot use dll, I need LabVIEW code, or at least a formula node...

...is it possible to put your code in a formula node?

 

 

 


Yes, of course, you can use provided C code as "getting started" for Formula Node (and then you will get your performance penalties back), or accurately rewrite everything in pure LabVIEW (there are trivial operations), but here you will need to invest some time for development.

0 Kudos
Message 17 of 18
(121 Views)

Hi,

Thank you, my problem is not the time, but my competences, I don't know how to do it.

 

Best regards,

Mal

0 Kudos
Message 18 of 18
(117 Views)