⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cfunc.mod

📁 ngspice又一个电子CAD仿真软件代码.功能更全
💻 MOD
📖 第 1 页 / 共 2 页
字号:
/* $Id: cfunc.mod,v 1.3 2004/07/09 18:38:04 pnenzi Exp $ *//*.......1.........2.........3.........4.........5.........6.........7.........8================================================================================FILE core/cfunc.modCopyright 1991Georgia Tech Research Corporation, Atlanta, Ga. 30332All Rights ReservedPROJECT A-8503-405               AUTHORS                          24 Apr 1991     Jeffrey P. MurrayMODIFICATIONS       24 Apr 1991    Jeffrey P. Murray    26 Sep 1991    Jeffrey P. Murray                                   SUMMARY    This file contains the functional description of the core    code model.INTERFACES           FILE                 ROUTINE CALLED         CMmacros.h           cm_message_send();                       CMutil.c             void cm_smooth_corner(); REFERENCED FILES    Inputs from and outputs to ARGS structure.                     NON-STANDARD FEATURES    NONE===============================================================================*//*=== INCLUDE FILES ====================*/#include "core.h"                                      /*=== CONSTANTS ========================*//*=== MACROS ===========================*/  /*=== LOCAL VARIABLES & TYPEDEFS =======*/                                        /*=== FUNCTION PROTOTYPE DEFINITIONS ===*/                   /*==============================================================================FUNCTION cm_core()AUTHORS                          24 Apr 1991     Jeffrey P. MurrayMODIFICATIONS       24 Apr 1991    Jeffrey P. Murray    26 Sep 1991    Jeffrey P. MurraySUMMARY    This function implements the core code model.INTERFACES           FILE                 ROUTINE CALLED         CMmacros.h           cm_message_send();                       CMutil.c             void cm_smooth_corner(); RETURNED VALUE        Returns inputs and outputs via ARGS structure.GLOBAL VARIABLES        NONENON-STANDARD FEATURES    NONE==============================================================================*/#include <stdlib.h>/*=== CM_CORE ROUTINE ===*/                                                   /*******************************************************************//*                                                                 */         /*  CORE Model:                                                    */          /*                                                                 */          /*     The core model is designed to operate in one of two modes.  *//*  The first of these, and the one most likely to be used by      *//*  the engineer, is a modified version of the pwl model. This     *//*  behavior occurs when the model is in pwl mode (the default).   *//*  If the model is set to hyst mode, its behavior mimics that of  *//*  the hysteresis block. The following provides additional        *//*  detail:                                                        */          /*                                                                 */          /*                          PWL Mode                               *//*                                                                 */          /*     In pwl mode, the core model is a modified version of the    *//*  PWL model...                                                   *//*  it has a single two-terminal input/output, and accepts as      */          /*  input the mmf value, represented by a voltage. Its output is   */          /*  a flux value, which is represented as a current. Additional    */          /*  inputs include the cross-sectional area of the physical        */          /*  core, and the median length of the core, seen from the         */          /*  perspective of the flux that traverses it.                     */          /*                                                                 */          /*     The core model in pwl mode DOES NOT include hysteresis...   *//*  current thinking is that such provides                         *//*  little benefit to the designer, aside from the ability to      */          /*  calculate eddy losses in a modeled device...the nonlinear      */          /*  B vs. H behavior, however, is of great importance.             */          /*                                                                 */          /*     Note that the user must input a piece-wise-linear           */          /*  description, in the form of a series of coordinate B vs. H     */          /*  values, in order to model a particular core material type.     */          /*  Such curves may be found in textbooks, or from manufacturer's  */          /*  databooks. In this model, the "x" values are assumed to        */          /*  represent the magnetic field (H), and the "y" values are       */          /*  assumed to represent the flux density (B).                     */          /*                                                                 */          /*                           Hyst Mode                             *//*                                                                 */          /*     In hyst mode, the core model is a modified version of the   *//*  HYST code model...                                             *//*  it has a single two-terminal input/output, and accepts as      */          /*  input the mmf value, represented by a voltage. Its output is   */          /*  a flux value, which is represented as a current. Additional    */          /*  inputs include the input high and low values for the           *//*  hysteretic behavior, and the output high and low values.       *//*  Also, a value of hysteresis must be included, as must an       *//*  input_domain value, and a fraction value, which tell the model *//*  whether to interpret the input_domain as an absolute value     *//*  or as a relative figure.                                       *//*                                                                 *//*  When the hyst mode is invoked on the core model, the user is   *//*  in the position of having to define reasonable values for the  *//*  upper and lower output limiting values. These can be very      *//*  difficule to nail down accurately. Current thinking is tha     *//*  the hysteresis capability will be of only nominal benefit to   *//*  the engineer, as it will not typically allow for as accurate   *//*  tailoring of the response as is possible in the pwl mode.      *//*                                                                 */          /*  4/24/91                                             J.P.Murray */          /*  Last modified: 10/24/91                                        */          /*******************************************************************/void cm_core(ARGS)  /* structure holding parms,                                    inputs, outputs, etc.     */{    /*** The following declarations pertain to PWL mode ***/    int i;               /* generic loop counter index */    int size;            /* size of the x_array        */    int mode;            /* mode parameter which determines whether                            pwl or hyst will be used in analysis. */    double input_domain;    /* smoothing range */    double *H;              /* pointer to the H-field array */    double *B;              /* pointer to the B-field array */    double lower_seg;       /* x segment below which input resides */    double upper_seg;       /* x segment above which the input resides */    double lower_slope;     /* slope of the lower segment */    double upper_slope;     /* slope of the upper segment */    double mmf_input;       /* input mmf value */    double H_input;         /* calculated input H value */    double B_out;           /* output B value */    double flux_out;        /* calculated output flux */    double dout_din;        /* partial derivative of the output wrt input */    double threshold_lower; /* value below which the output begins                                   smoothing */    double threshold_upper; /* value above which the output begins smoothing */    double area;            /* cross-sectional area of the core (in meters)*/    double length;          /* length of core (in meters) */    Mif_Complex_t ac_gain;                                               char *allocation_error="\n***ERROR***\nCORE: Allocation calloc failed!\n";    char *limit_error="\n***ERROR***\nCORE: Violation of 50% rule in breakpoints!\n";    /*** The following declarations pertain to HYSTERESIS mode... ***/    double        in, /* input to hysteresis block      */                 out, /* output from hysteresis block   */              in_low, /* lower input value for hyst=0 at which                          the transfer curve changes from constant                          to linear                               */             in_high, /* upper input value for hyst=0 at which                          the transfer curve changes from constant                          to linear                               */                hyst, /* the hysteresis value (see above diagram)    */     out_lower_limit, /* the minimum output value from the block */     out_upper_limit, /* the maximum output value from the block */               slope, /* calculated rise and fall slope for the block  */            pout_pin, /* partial derivative of output w.r.t. input */       x_rise_linear, /* = in_low + hyst                           */         x_rise_zero, /* = in_high + hyst                          */       x_fall_linear, /* = in_high - hyst                          */         x_fall_zero; /* = in_low - hyst                           */    Boolean_t     *hyst_state, /* TRUE => input is on lower leg of                                   hysteresis curve, between -infinity                                  and in_high + hyst.                                  FALSE => input is on upper leg                                  of hysteresis curve, between                                   in_low - hyst and +infinity      */              *old_hyst_state; /* previous value of *hyst_state    */    /* Retrieve mode parameter... */    mode = PARAM(mode);    /** Based on mode value, switch to the appropriate model code... **/    /******** pwl mode *****************/    if ( HYSTERESIS != mode ) {         /* Retrieve frequently used parameters... */        input_domain = PARAM(input_domain);        area = PARAM(area);        length = PARAM(length);        size = PARAM_SIZE(H_array);                   /* Allocate storage for breakpoint domain & range values */        H = (double *) calloc(size, sizeof(double));        if (H == '\0') {            cm_message_send(allocation_error);             return;        }        B = (double *) calloc(size, sizeof(double));        if (B == '\0') {            cm_message_send(allocation_error);              return;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -