淘宝官方店     推荐课程     在线工具     联系方式     关于我们  
 
 

微波射频仿真设计   Ansoft Designer 中文培训教程   |   HFSS视频培训教程套装

 

Agilent ADS 视频培训教程   |   CST微波工作室视频教程   |   AWR Microwave Office

          首页 >> Ansoft Designer >> Ansoft Designer在线帮助文档


Ansoft Designer / Ansys Designer 在线帮助文档:


Nexxim Simulator >
Support for External Models and Interfaces >
   C Model Library Support >
       C Model API Functions >
           API Functions for VI Models Only               


API Functions for VI Models Only

The functions in this section are required for Voltage-Current (VI) models. They do not apply to models specified with S-parameters or Y-parameters.

Get Branch Count

This function returns the number of branches in the model. The syntax is:

int get_branch_count();

For example:

int get_branch_count(){return 3;} // Three current paths

Get Branch Name

This function returns a branch name in the model each time it is called. The syntax is:

char* get_branch_name(int index);

If no names are provided, a default naming system (br_0, br_1, ...) is used. For example:

char* get_branch_name(int index)

{

static char* branch_names[] = {R1”, “L1”, “C1”};

return branch_names[index];

}

Nexxim uses the return from get_branch_count to set the zero-based index values.

 

Get Branch Connectivity

This function generates the connectivity matrix that describe the circuit. The return value is a flag indicating success. The syntax is:

int get_branch_connectivity(int* connectivity_matrix);

The connectivity_matrix contains (num_branches * 2) zero-based node indexes.

For a model with two nodes and one branch (e.g., a resistor) the connectivity_matrix would contain [0 1]. For a model with four nodes and two branches, the connectivity_matrix could be [0 1 2 3], that is, the first branch goes from node 0 to node 1, and the second branch goes from node 2 to node 3.

For example:

int get_branch_connectivity(int* connectivity_matrix)

{

// The branch is connected from node 0 to node 1

connectivity_matrix[0] = 0;

connectivity_matrix[1] = 1;

return UDM_SUCCESS;

}

Macros for Branches and Nodes

The macros BR(n) and ND(m) help the model developer distinguish node and branch indices. The value of BR(n) is just n, and the value of ND(m) is just m. The previous example could be written:

// The branch is connected from node 0 to node 1

connectivity_matrix[0] = ND(0);

connectivity_matrix[1] = ND(1);

 

Eval

This function specifies the equations that define the component. The syntax is:

int eval(

// inputs

double* currents,

double* voltages,

double time

// outputs

double* rhs,

double** drhs_di,

double** drhs_dv,

double* drhs_dt,

double* charges,

double** dcharge_di,

double** dcharge_dv,

double* dcharge_dt

);

The currents and voltages are passed to the method from Nexxim. Currents are indexed by branch, voltages are indexed by node. The time input supplies the current simulation time.

The model developer can specify the formulas for the constituent equations (rhs and charges) and for the derivatives (dxxx) directly, or can set up the constituent equations and have Nexxim calculate the derivatives.

Direct Formulas

For example, a resistor model might specify its constituent equations and derivatives directly with code such as:

int eval(double* voltages, double* currents, double time
double* rhs, double** drhs_dv, double** drhs_di,
double* drht_dt,
double* charges, double** dcharge_dv,
double** dcharge_di, double* dchagre_dt)

{

// i = (v1 - v2)/R, i - dv/R = 0;

double dv = voltages[0] - voltages[1];

rhs[0] = currents[0] - dv/R;

drhs_di[0][0] = 1.0;

drhs_dv[0][0] = -1/R;

drhs_dv[0][1] = 1/R;

 

// no charges

return UDM_SUCCESS; // no error

}

A capacitor model might have the following:

int eval(double* voltages, double* currents,
double* rhs, double** drhs_dv, double** drhs_di,
double* charges, double** dcharge_dv,
double** dcharge_di)

{

double dv = voltages[0] - voltages[1];

rhs[0] = currents[0];

drhs_di[0][0] = 1.0;

drhs_dv[0][0] = 0.0;

drhs_dv[0][1] = 0.0;

charges[0] = -C * dv;

dcharge_dv[0][0] = -C;

dcharge_dv[0][1] = C;

// no dcharge_di

return UDM_SUCCESS; // no error

}

For the double** derivatives, the first index is the branch index and second is a node index for voltages or a branch index for currents.

Calculated Derivatives

To have Nexxim calculate the derivative formulas, the model code uses an expanded version of eval. First, the code associates the model equations with the inputs using the function init_terminal_exprs. The syntax for init_terminal_exprs is:

static void init_terminal_exprs(

double* currents, double* voltages, double time,
expr *i_expr, expr *v_expr, expr &t_expr)
{ Details not shown }

Next, the model defines the equations themselves. The expr data type is a differentiable expression, defined in the header file udm_expression.hpp.

Last, the eval code calls calc_outputs to calculate the derivatives. Here is an example:

int eval(double* currents, double* voltages, double time,
double* rhs, double** drhs_di, double** drhs_dv,
double* drhs_dt,
double* charges, double** dcharge_di,
double** dcharge_dv, double* dcharge_dt)

// Associate currents, voltages, and time inputs with i_expr, v_expr, t_expr expressions which support differentiation

expr i_expr[e_branch_count], v_expr[e_node_count],
t_expr;

expr::init_terminal_exprs(currents, voltages, time,
i_expr, v_expr, t_expr);

// Set up expressions

expr rhs_expr[e_branch_count],
charge_expr[e_branch_count];

 

expr dvr1 = v_expr[ND(0)] - v_expr[ND(1)];

rhs_expr[BR(0)] = i_expr[BR(0)] - dvr1/R1;

 

expr dvr2 = v_expr[ND(1)] - v_expr[ND(2)];

rhs_expr[BR(1)] = i_expr[BR(1)] - dvr2/R2;

 

expr dvc = v_expr[ND(1)] - v_expr[ND(2)];

rhs_expr[BR(2)] = i_expr[BR(2)];

charge_expr[BR(2)] = -C * dvc;

// Calculate derivative outputs

int j;

for (j=0; j < e_branch_count; j++)

{

rhs_expr[BR(j)].calc_outputs(

rhs[BR(j)], drhs_di[BR(j)], drhs_dv[BR(j)],
drhs_dt[BR(j)]);

}

 

for (j=0; j < e_branch_count; j++)

{

charge_expr[BR(j)].calc_outputs(

charges[BR(j)], dcharge_di[BR(j)],
dcharge_dv[BR(j)], dcharge_dt[BR(j)]);

}

 

return UDM_SUCCESS;

}

 

private:

// expression with support of differentiation

typedef udm_expr<e_branch_count, e_node_count> expr;

 

// parameters

double R1;

double R2;

double C;

};




HFSS视频教学培训教程 ADS2011视频培训教程 CST微波工作室教程 Ansoft Designer 教程

                HFSS视频教程                                      ADS视频教程                               CST视频教程                           Ansoft Designer 中文教程


 

      Copyright © 2006 - 2013   微波EDA网, All Rights Reserved    业务联系:mweda@163.com