mirror of
https://github.com/ra3xdh/qucs_s
synced 2025-03-28 21:13:26 +00:00
Refactored math. functions conversion
This commit is contained in:
parent
f047905d60
commit
cc2e78d18a
@ -93,7 +93,7 @@ QString EqnDefined::netlist()
|
||||
return s+e;
|
||||
}
|
||||
|
||||
QString EqnDefined::spice_netlist(bool)
|
||||
QString EqnDefined::spice_netlist(bool isXyce)
|
||||
{
|
||||
QString s;
|
||||
|
||||
@ -120,6 +120,7 @@ QString EqnDefined::spice_netlist(bool)
|
||||
Ieqn.replace("^","**");
|
||||
QStringList Itokens;
|
||||
spicecompat::splitEqn(Ieqn,Itokens);
|
||||
spicecompat::convert_functions(Itokens,isXyce);
|
||||
qDebug()<<Itokens;
|
||||
subsVoltages(Itokens,Nbranch);
|
||||
subsCurrents(Itokens);
|
||||
@ -138,6 +139,7 @@ QString EqnDefined::spice_netlist(bool)
|
||||
Qeqn.replace("^","**");
|
||||
QStringList Qtokens;
|
||||
spicecompat::splitEqn(Qeqn,Qtokens);
|
||||
spicecompat::convert_functions(Qtokens,isXyce);
|
||||
qDebug()<<Qtokens;
|
||||
subsVoltages(Qtokens,Nbranch);
|
||||
subsCurrents(Qtokens);
|
||||
@ -207,8 +209,8 @@ void EqnDefined::subsCurrents(QStringList &tokens)
|
||||
for (QStringList::iterator it = tokens.begin();it != tokens.end();it++) {
|
||||
if (curr_pattern.exactMatch(*it)) {
|
||||
QString curr = *it;
|
||||
int branch = curr.remove('V').toInt();
|
||||
*it = QString("i(V_%1sens_%2)").arg(Name).arg(branch);
|
||||
int branch = curr.remove('I').toInt();
|
||||
*it = QString("i(V_%1sens_%2)").arg(Name).arg(branch-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -111,10 +111,7 @@ QString Equation::getExpression(bool isXyce)
|
||||
QStringList tokens;
|
||||
QString eqn = Props.at(i)->Value;
|
||||
spicecompat::splitEqn(eqn,tokens);
|
||||
for(QStringList::iterator it = tokens.begin();it != tokens.end(); it++) {
|
||||
qDebug()<<spicecompat::convert_functions(*it,isXyce);
|
||||
*it = spicecompat::convert_functions(*it,isXyce);
|
||||
}
|
||||
spicecompat::convert_functions(tokens,isXyce);
|
||||
eqn = tokens.join("");
|
||||
if (isXyce) eqn.replace("^","**");
|
||||
QRegExp fp_pattern("^[\\+\\-]*\\d*\\.\\d+$"); // float
|
||||
@ -187,9 +184,7 @@ QString Equation::getNgspiceScript()
|
||||
QStringList tokens;
|
||||
QString eqn = Props.at(i)->Value;
|
||||
spicecompat::splitEqn(eqn,tokens);
|
||||
for(QStringList::iterator it = tokens.begin();it != tokens.end(); it++) {
|
||||
*it = spicecompat::convert_functions(*it,false);
|
||||
}
|
||||
spicecompat::convert_functions(tokens,false);
|
||||
eqn = tokens.join("");
|
||||
|
||||
if (!spicecompat::containNodes(tokens,ng_vars)) {
|
||||
|
@ -382,9 +382,7 @@ QString qucs2spice::convert_edd(QString line, QStringList &EqnsAndVars)
|
||||
QStringList Itokens;
|
||||
spicecompat::splitEqn(Ieqn,Itokens);
|
||||
subsVoltages(Itokens,nods);
|
||||
for(QStringList::iterator it = Itokens.begin();it != Itokens.end(); it++) {
|
||||
*it = spicecompat::convert_functions(*it,false);
|
||||
}
|
||||
spicecompat::convert_functions(Itokens,false);
|
||||
QString plus = nods.at(2*i+1);
|
||||
QString minus = nods.at(2*i);
|
||||
|
||||
|
@ -68,7 +68,7 @@ QString spicecompat::normalize_value(QString Value)
|
||||
* \param isXyce[in] True if Xyce is used, False by default.
|
||||
* \return
|
||||
*/
|
||||
QString spicecompat::convert_functions(QString tok, bool isXyce)
|
||||
QString spicecompat::convert_function(QString tok, bool isXyce)
|
||||
{
|
||||
QStringList conv_list_ngspice; // Put here functions need to be converted
|
||||
conv_list_ngspice<<"q"<<"1.6021765e-19"
|
||||
@ -91,6 +91,19 @@ QString spicecompat::convert_functions(QString tok, bool isXyce)
|
||||
return tok;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief spicecompat::convert_functions Convert Qucs mathematical function name
|
||||
* to Spice mathematical function name
|
||||
* \param tokens[in/out] String list in which to put tokens
|
||||
* \param isXyce[in] True if Xyce is used, False by default.
|
||||
*/
|
||||
void spicecompat::convert_functions(QStringList &tokens, bool isXyce)
|
||||
{
|
||||
for(QStringList::iterator it = tokens.begin();it != tokens.end(); it++) {
|
||||
*it = spicecompat::convert_function(*it,isXyce);
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief spicecompat::splitEqn Split Equation into tokens. Token delimenters are mathamatical
|
||||
* operation signs: = ^ + - * / and parentheses ()
|
||||
|
@ -12,7 +12,8 @@
|
||||
namespace spicecompat {
|
||||
QString check_refdes(QString &Name, QString &Model);
|
||||
QString normalize_value(QString Value);
|
||||
QString convert_functions(QString tok, bool isXyce);
|
||||
QString convert_function(QString tok, bool isXyce);
|
||||
void convert_functions(QStringList &tokens, bool isXyce);
|
||||
void splitEqn(QString &eqn, QStringList &tokens);
|
||||
bool containNodes(QStringList &tokens, QStringList &vars);
|
||||
void convertNodeNames(QStringList &tokens, QString &sim);
|
||||
|
Loading…
x
Reference in New Issue
Block a user