简体   繁体   English

我应该在'gamma' function 中更改什么?

[英]What should I change in the 'gamma' function?

My algorithm calculates the electromagnetic shielding of multiple glasses, I have a problem with the gamma function, the debugger returns this error:我的算法计算了多个眼镜的电磁屏蔽,我的伽玛 function 有问题,调试器返回此错误:

[Warning] conflicting types for built-in function 'gamma'; [警告] 内置 function 'gamma' 的类型冲突; expected 'double(double)' [-Wbuiltin-declaration-mismatch].预期“双(双)”[-Wbuiltin-declaration-mismatch]。

The error on the debugger is reported on line 34 of the file"struttura_dati.h"在文件“struttura_dati.h”的第34行报告了调试器上的错误

main.c main.c

#include "struttura_dati.h"

int
main (int argc, char *argv[])
{
  struct_layer *layer;
  struct_interf *interf;
  int n_layer = 6, il, nfreq, ifreq;
  double freq = 1.0E9;
  double se;
  double fmin = 100.0E6, fmax = 10.0E9, fstep = 1.0E6;
  FILE *pfo = NULL;
  char string[255];


  /* Structure allocation */
  layer = (struct_layer *) malloc (sizeof (struct_layer) * (size_t) n_layer);
  interf = (struct_interf *) malloc (sizeof (struct_interf) * ((size_t) n_layer - 1));

  /* Layer values (first test) */
  layer[0].epsr = 1.0;
  layer[0].mur = 1.0;
  layer[0].sigma = 0.0;
  layer[0].thick = 0.0;     // infinite thickness
  layer[1].epsr = 5.0;
  layer[1].mur = 1.0;
  layer[1].sigma = 1.0E-3;
  layer[1].thick = 0.004;
  layer[2].epsr = 1.0;
  layer[2].mur = 1.0E3;
  layer[2].sigma = 1.0E4;
  layer[2].thick = 5.0E-6;
  layer[3].epsr = 1.0;
  layer[3].mur = 1.0;
  layer[3].sigma = 0.0;
  layer[3].thick = 0.01;
  layer[4].epsr = 5.0;
  layer[4].mur = 1.0;
  layer[4].sigma = 1.0E-3;
  layer[4].thick = 0.004;
  layer[5].epsr = 1.0;
  layer[5].mur = 1.0;
  layer[5].sigma = 0.0;
  layer[5].thick = 0.0;     // infinite thickness

  /* Layer values (Ezio - AGC values) */
  layer[0].epsr = 1.0;
  layer[0].mur = 1.0;
  layer[0].sigma = 0.0;
  layer[0].thick = 0.0;     // infinite thickness
  layer[1].epsr = 7.0;
  layer[1].mur = 1.0;
  layer[1].sigma = 0.001;
  layer[1].thick = 0.006;
  layer[2].epsr = 1.0;
  layer[2].mur = 1;
  layer[2].sigma = 61730000;
  layer[2].thick = 6.0E-9;
  layer[3].epsr = 1.0;
  layer[3].mur = 1.0;
  layer[3].sigma = 0.0;
  layer[3].thick = 0.015;
  layer[4].epsr = 7.0;
  layer[4].mur = 1.0;
  layer[4].sigma = 0.001;
  layer[4].thick = 0.004;
  layer[5].epsr = 1.0;
  layer[5].mur = 1.0;
  layer[5].sigma = 0.0;
  layer[5].thick = 0.0;     // infinite thickness

  /* Scan of the whole band */
  sprintf (string, "SE_Multilayer_dB.txt");
  if ((pfo = fopen (string, "w")) == NULL)
    exit (EXIT_FAILURE);

  nfreq = (fmax - fmin) / fstep + 1;
  for (ifreq = 0; ifreq < nfreq; ifreq++)
    {
      freq = fmin + ifreq * fstep;

      /* Compute the layer parameters */
      for (il = 0; il < n_layer; il++)
    gamma (&layer[il], freq);

      /* Compute the layer interfaces */
      for (il = 0; il < n_layer - 1; il++)
    interf2layer (&layer[il], &layer[il + 1], &interf[il]);

      /* Compute the layer fields */
      layer[5].e_piu = 1.0 + I * 0.0;
      layer[5].e_meno = 0.0 + I * 0.0;
      //fields_last(&layer[4], &layer[5], &interf[4], (double complex) 1, (double complex) 0);
      for (il = n_layer - 2; il >= 0; il--)
    fields (&layer[il], &layer[il + 1], &interf[il], layer[il + 1].e_piu, layer[il + 1].e_meno);

      se = 20 * log10 (cabs (layer[0].e_piu));

      fprintf (pfo, "%g\t%g\n", freq * 1.0E-9, se);
      printf ("Frequency: %g (GHz) - Shielding Effectiveness (dB): %g \n", freq*1.0E-9,se); 
    }
  fclose (pfo);
  printf ("Computed %d points in the band %g - %g (GHz)\n", nfreq, fmin * 1.0E-9, fmax * 1.0E-9);
  printf ("Results are in the file: %s\n", string);

  /* Structure free */
  free (layer);
  free (interf);
  exit (0);
}

function.c function.c

#include "struttura_dati.h"

void
gamma (struct_layer * layer, double freq)
{
  double omega, epsr2, tgd2;

  omega = 2 * PI * freq;
  epsr2 = layer->sigma / (omega * EPS0);
  tgd2 = epsr2 * epsr2 / (layer->epsr * layer->epsr);
  layer->alfa = omega * sqrt (layer->mur * MU0 * layer->epsr * EPS0 * 0.5 * (sqrt (1 + tgd2) - 1));
  layer->beta = omega * sqrt (layer->mur * MU0 * layer->epsr * EPS0 * 0.5 * (sqrt (1 + tgd2) + 1));
  layer->gamma = layer->alfa + I * layer->beta;
  layer->eta = csqrt (layer->mur * MU0 / ((layer->epsr - I * epsr2) * EPS0));
}

/* evaluates the transmission and reflection coefficients between two layers (from l1 to l2) */
void
interf2layer (struct_layer * l1, struct_layer * l2, struct_interf * interf)
{
  double complex rho, tt;

  rho = (l2->eta - l1->eta) / (l2->eta + l1->eta);
  tt = 1 + rho;
  interf->rho = rho;
  interf->tt = tt;
}

/* evaluates the forward and backward field in a layer from the fields of next layer */
void
fields (struct_layer * l1, struct_layer * l2, struct_interf * interf, double complex enext_piu,
    double complex enext_meno)
{
  double complex exp_piu, exp_meno;

  exp_piu = cexp (l2->gamma * l2->thick);
  exp_meno = cexp (-l2->gamma * l2->thick);

  l1->e_piu = (exp_piu * enext_piu + interf->rho * exp_meno * enext_meno) / interf->tt;
  l1->e_meno = (interf->rho * exp_piu * enext_piu + exp_meno * enext_meno) / interf->tt;

}

/* evaluates the forward and backward field in the second to last layer from the fields of next layer */
void
fields_last (struct_layer * l1, struct_layer * l2, struct_interf * interf, double complex enext_piu,
         double complex enext_meno)
{
  double complex exp_piu, exp_meno;

  exp_piu = 1.0 + I * 0;
  exp_meno = 1.0 + I * 0;

  l1->e_piu = (exp_piu * enext_piu + interf->rho * exp_meno * enext_meno) / interf->tt;
  l1->e_meno = (interf->rho * exp_piu * enext_piu + exp_meno * enext_meno) / interf->tt;

}

struttura_dati.h struttura_dati.h

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <complex.h>

#define PI 3.1415926535897932384626
#define EPS0 8.8541878176203898505366E-12
#define MU0 1.2566370614359172953E-06
#define C0 299792458.0      /* Mettere il `.0` finale altrimenti lo potrebbe prendere come intero */
#define ETA0 376.7303134617706554682

typedef struct
{
/* Layer values */
  double epsr;
  double mur;
  double sigma;
  double thick;
  double alfa;
  double beta;
  double complex gamma;
  double complex eta;
  double complex e_piu;
  double complex e_meno;
} struct_layer;

typedef struct
{
/* Layer interfaces */
  double complex rho;
  double complex tt;
} struct_interf;

void gamma (struct_layer * layer, double freq);
void interf2layer (struct_layer * l1, struct_layer * l2, struct_interf * interf);
void fields (struct_layer * l1, struct_layer * l2, struct_interf * interf, double complex enext_piu,
         double complex enext_meno);
void fields_last (struct_layer * l1, struct_layer * l2, struct_interf * interf, double complex enext_piu,
          double complex enext_meno);

Name conflict名称冲突

To avoid the warning为了避免警告

[Warning] conflicting types for built-in function 'gamma'; [警告] 内置 function 'gamma' 的类型冲突; expected 'double(double)' [-Wbuiltin-declaration-mismatch].预期“双(双)”[-Wbuiltin-declaration-mismatch]。

Use a different name.使用不同的名称。 Although gamma() is not in the C17 standard library, it is likely a library extension in OP's math library.尽管gamma()不在 C17 标准库中,但它可能是 OP 数学库中的库扩展。

Turn off your library's extension of functions like gamma() .关闭库的扩展功能,如gamma()

Alternatively, do not include <math.h> , but that then loses sqrt() , etc.或者,不要包含<math.h> ,但会丢失sqrt()等。

Could use static gamma() and some other clever name-space tricks, yet certainly easiest to change OPs's gamma() to something else.可以使用static gamma()和其他一些巧妙的命名空间技巧,但当然最容易将 OP 的gamma()更改为其他内容。


namespace pollution命名空间污染

struttura_dati.h defines macros and objects all over the namespace and unnecessarily includes various <.h> files. struttura_dati.h定义了整个命名空间的宏和对象,并且不必要地包含各种<.h>文件。 I'd reduce what is in struttura_dati.h o the minimum and employ a more uniform naming.我会尽量减少struttura_dati.h中的内容,并采用更统一的命名。


Minor: Reduce precision loss次要:减少精度损失

I'd experiment with hypot() to reduce precision loss.我会尝试使用hypot()来减少精度损失。

// tgd2 = epsr2 * epsr2 / (layer->epsr * layer->epsr);
// layer->alfa = omega * sqrt (layer->mur * MU0 * layer->epsr * EPS0 * 0.5 * 
//     (sqrt (1 + tgd2) - 1));

double tgd = epsr2 / layer->epsr;
layer->alfa = omega * sqrt (layer->mur * MU0 * layer->epsr * EPS0 * 0.5 * 
    (hypot(1, tgd) - 1));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我应该在我的函数中改变什么才能计算实数? - what should i change in my function so it calculates real numbers? 我应该在此代码中进行哪些更改以使其打印某些内容? 插入 function 是否需要是 struct 类型才能插入节点? - What should I change in this code to make it print something? Does the insert function need to be of type struct to insert a node? 我应该从这段代码中改变什么 - what thing i should change from this code 我应该向这个函数发送什么参数 - What arguments should I send to this function 我在下面所做的编码的“性别”部分应该有什么变化? - What should be change in the “gender” part of the coding I have done below? 如何使用XF86VidModeSetGamma()更改第二台显示器的gamma? - How do I change gamma of my second monitor with XF86VidModeSetGamma()? 函数什么时候应该返回什么? - When should a function return what? 我应该在括号之间写什么来定义我希望变量更改为的数据类型? - What should I write in between parentheses to define the data type I want a variable to change to? 我应该在自下而上的合并排序中将什么样的参数传递给我的合并函数? - What kind of parameter should I be passing to my merge function in Bottom Up Merge Sort? 如果那段时间条件发生变化(不再成立),我应该用什么来停止 C 中的 sleep() function? - What should I use to stop the sleep() function in C if a condition changes in that period of time (doesn't hold anymore)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM