Skip to content

Commit

Permalink
Merge pull request #77 from JoeyDelp/testing
Browse files Browse the repository at this point in the history
Testing
  • Loading branch information
JoeyDelp authored Aug 17, 2022
2 parents af52cf0 + 469ac34 commit 22a9ae2
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 61 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)

project(JoSIM VERSION 2.6.4)
project(JoSIM VERSION 2.6.5)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ Referencing:
---

## Changelog
### v2.6.5
- Updated the CPR specification in the JJ model to allow multiple simulataneos harmonics.
- Added a Notepad++ UDL syntax highlighting script to the scripts folder.

### v2.6.4
- Added the ability to specify CPR in the JJ model to enable non-sinusoidal CPRs needed for pi-junctions.

Expand Down
1 change: 1 addition & 0 deletions include/JoSIM/Errors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ enum class ControlErrors : int64_t {

enum class ModelErrors : int64_t {
PARAM_TYPE_ERROR,
PARAM_PARENTHESIS,
UNKNOWN_MODEL_TYPE,
BAD_MODEL_DEFINITION
};
Expand Down
8 changes: 4 additions & 4 deletions include/JoSIM/Model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Model {
std::string modelName_;
double vg_;
double ic_;
double cpr_;
std::vector<double> cpr_;
int64_t rtype_;
double rn_;
double r0_;
Expand All @@ -30,7 +30,7 @@ class Model {
Model()
: vg_(2.8E-3),
ic_(1E-3),
cpr_(1.0),
cpr_({1.0}),
rtype_(1),
rn_(5),
r0_(30),
Expand All @@ -49,8 +49,8 @@ class Model {
void vg(const double& v) { vg_ = v; }
double ic() const { return ic_; }
void ic(const double& i) { ic_ = i; }
double cpr() const { return cpr_; }
void cpr(const double& i) { cpr_ = i; }
std::vector<double> cpr() const { return cpr_; }
void cpr(const std::vector<double>& i) { cpr_ = i; }
int64_t rtype() const { return rtype_; }
void rtype(const int64_t& r) { rtype_ = r; }
double rn() const { return rn_; }
Expand Down
64 changes: 64 additions & 0 deletions scripts/JoSIM_n++_UDL.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<NotepadPlus>
<UserLang name="JoSIM" ext="cir" udlVersion="2.1">
<Settings>
<Global caseIgnored="yes" allowFoldOfComments="no" foldCompact="no" forcePureLC="2" decimalSeparator="0" />
<Prefix Keywords1="no" Keywords2="yes" Keywords3="yes" Keywords4="yes" Keywords5="no" Keywords6="no" Keywords7="no" Keywords8="no" />
</Settings>
<KeywordLists>
<Keywords name="Comments">00* 00# 01 02 03 04</Keywords>
<Keywords name="Numbers, prefix1"></Keywords>
<Keywords name="Numbers, prefix2"></Keywords>
<Keywords name="Numbers, extras1"></Keywords>
<Keywords name="Numbers, extras2"></Keywords>
<Keywords name="Numbers, suffix1">f p n u m k meg x g t</Keywords>
<Keywords name="Numbers, suffix2"></Keywords>
<Keywords name="Numbers, range"></Keywords>
<Keywords name="Operators1">=</Keywords>
<Keywords name="Operators2"></Keywords>
<Keywords name="Folders in code1, open"></Keywords>
<Keywords name="Folders in code1, middle"></Keywords>
<Keywords name="Folders in code1, close"></Keywords>
<Keywords name="Folders in code2, open">.subc .control</Keywords>
<Keywords name="Folders in code2, middle"></Keywords>
<Keywords name="Folders in code2, close">.ends .endc .end</Keywords>
<Keywords name="Folders in comment, open"></Keywords>
<Keywords name="Folders in comment, middle"></Keywords>
<Keywords name="Folders in comment, close"></Keywords>
<Keywords name="Keywords1">pwl sin pulse cus dc noise exp v i p jj</Keywords>
<Keywords name="Keywords2">b c e f g h i k l p r t v</Keywords>
<Keywords name="Keywords3">.model .tran .iv .plot .print .save .param .file .iv .include .spread .noise .neb .temp</Keywords>
<Keywords name="Keywords4">rtype vg vgap ic icrit rn r0 c cap t tc delv d icfct icfact phi cpr td z0 spread neb area</Keywords>
<Keywords name="Keywords5"></Keywords>
<Keywords name="Keywords6"></Keywords>
<Keywords name="Keywords7"></Keywords>
<Keywords name="Keywords8"></Keywords>
<Keywords name="Delimiters">00( 01 02) 03{ 04 05} 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23</Keywords>
</KeywordLists>
<Styles>
<WordsStyle name="DEFAULT" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
<WordsStyle name="COMMENTS" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
<WordsStyle name="LINE COMMENTS" fgColor="808040" bgColor="FFFFFF" fontStyle="0" nesting="0" />
<WordsStyle name="NUMBERS" fgColor="FF8000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS1" fgColor="FF0080" bgColor="FFFFFF" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS2" fgColor="0000FF" bgColor="FFFFFF" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS3" fgColor="FF0000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS4" fgColor="FF80FF" bgColor="FFFFFF" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS5" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS6" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS7" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS8" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
<WordsStyle name="OPERATORS" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
<WordsStyle name="FOLDER IN CODE1" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
<WordsStyle name="FOLDER IN CODE2" fgColor="FF0000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
<WordsStyle name="FOLDER IN COMMENT" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS1" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="67117058" />
<WordsStyle name="DELIMITERS2" fgColor="FF8000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS3" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS4" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS5" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS6" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS7" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS8" fgColor="000000" bgColor="FFFFFF" fontStyle="0" nesting="0" />
</Styles>
</UserLang>
</NotepadPlus>
4 changes: 4 additions & 0 deletions src/Errors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,10 @@ void Errors::model_errors(ModelErrors errorCode, string_o message) {
"Please consult the syntax guide for more information.";
warning_message(formattedMessage);
break;
case ModelErrors::PARAM_PARENTHESIS:
formattedMessage += "Model parameter has non-closing parenthesis.\n";
formattedMessage += "Model line: " + message.value_or("");
throw std::runtime_error(formattedMessage);
case ModelErrors::UNKNOWN_MODEL_TYPE:
formattedMessage += "Unknown model type specified.\n";
formattedMessage += "Model line: " + message.value_or("");
Expand Down
106 changes: 66 additions & 40 deletions src/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,27 @@ void Model::parse_model(const std::pair<tokens_t, string_o>& s,
// Create a temporary tokens variable containing the model parameters
tokens_t tokens(s.first.begin() + 2, s.first.end());
tokens = Misc::tokenize(Misc::vector_to_string(tokens).substr(2), "=(), ");
// Add any tokens surrounded by curly braces to the same token
int par_open = -1;
for (int i = 0; i < tokens.size(); ++i) {
if (par_open != -1) {
tokens.at(par_open) += "," + tokens.at(i);
tokens.erase(tokens.begin() + i);
--i;
if (tokens.at(par_open).back() == '}') {
tokens.at(par_open).pop_back();
par_open = -1;
}
}
if (tokens.at(i).front() == '{') {
par_open = i;
tokens.at(i) = tokens.at(i).substr(1);
}
}
if (par_open != -1) {
Errors::model_errors(JoSIM::ModelErrors::PARAM_PARENTHESIS,
Misc::vector_to_string(s.first));
}
// Sanity check, there should be an even number of tokens (parameter=value)
if (tokens.size() % 2 != 0) {
Errors::model_errors(ModelErrors::BAD_MODEL_DEFINITION,
Expand All @@ -37,48 +58,53 @@ void Model::parse_model(const std::pair<tokens_t, string_o>& s,
double value = 0.0;
// Loop through the parameter tokens
for (int64_t i = 0; i < tokens.size(); i += 2) {
// Every even odd token should be a value (otherwise complain)
value = parse_param(tokens.at(i + 1), p, s.second);
if (std::isnan(value)) {
Errors::model_errors(ModelErrors::BAD_MODEL_DEFINITION,
Misc::vector_to_string(s.first));
}
// Assign the relevant model parameters
if (tokens.at(i) == "VG" || tokens.at(i) == "VGAP") {
temp.vg(value);
} else if (tokens.at(i) == "IC" || tokens.at(i) == "ICRIT") {
temp.ic(value);
} else if (tokens.at(i) == "RTYPE") {
temp.rtype((int64_t)value);
} else if (tokens.at(i) == "RN") {
temp.rn(value);
} else if (tokens.at(i) == "R0") {
temp.r0(value);
} else if (tokens.at(i) == "CAP" || tokens.at(i) == "C") {
temp.c(value);
} else if (tokens.at(i) == "T") {
temp.t(value);
temp.tDep(true);
} else if (tokens.at(i) == "TC") {
temp.tc(value);
temp.tDep(true);
} else if (tokens.at(i) == "DELV") {
temp.deltaV(value);
} else if (tokens.at(i) == "D") {
temp.d(value);
temp.tDep(true);
} else if (tokens.at(i) == "ICFACT" || tokens.at(i) == "ICFCT") {
temp.icFct(value);
} else if (tokens.at(i) == "PHI") {
temp.phiOff(value);
} else if (tokens.at(i) == "CPR") {
temp.cpr(value);
if (tokens.at(i) == "CPR") {
std::vector<double> v;
tokens_t t = Misc::tokenize(tokens.at(i + 1), ",");
for (auto& val : t) v.emplace_back(parse_param(val, p, s.second));
temp.cpr(v);
} else {
// Incompatible parameter
Errors::model_errors(
ModelErrors::PARAM_TYPE_ERROR,
Misc::vector_to_string(tokens_t{Misc::vector_to_string(s.first),
// Every even odd token should be a value (otherwise complain)
value = parse_param(tokens.at(i + 1), p, s.second);
if (std::isnan(value)) {
Errors::model_errors(ModelErrors::BAD_MODEL_DEFINITION,
Misc::vector_to_string(s.first));
}
// Assign the relevant model parameters
if (tokens.at(i) == "VG" || tokens.at(i) == "VGAP") {
temp.vg(value);
} else if (tokens.at(i) == "IC" || tokens.at(i) == "ICRIT") {
temp.ic(value);
} else if (tokens.at(i) == "RTYPE") {
temp.rtype((int64_t)value);
} else if (tokens.at(i) == "RN") {
temp.rn(value);
} else if (tokens.at(i) == "R0") {
temp.r0(value);
} else if (tokens.at(i) == "CAP" || tokens.at(i) == "C") {
temp.c(value);
} else if (tokens.at(i) == "T") {
temp.t(value);
temp.tDep(true);
} else if (tokens.at(i) == "TC") {
temp.tc(value);
temp.tDep(true);
} else if (tokens.at(i) == "DELV") {
temp.deltaV(value);
} else if (tokens.at(i) == "D") {
temp.d(value);
temp.tDep(true);
} else if (tokens.at(i) == "ICFACT" || tokens.at(i) == "ICFCT") {
temp.icFct(value);
} else if (tokens.at(i) == "PHI") {
temp.phiOff(value);
} else {
// Incompatible parameter
Errors::model_errors(ModelErrors::PARAM_TYPE_ERROR,
Misc::vector_to_string(
tokens_t{Misc::vector_to_string(s.first),
"\nThe parameter: ", tokens.at(i)}));
}
}
}

Expand Down
25 changes: 18 additions & 7 deletions src/Simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,21 +394,32 @@ void Simulation::handle_jj(Matrix &mObj, int64_t &i, double &step,
}
}
// Ic * sin (phi * (φ0 - φ))
double ic_sin_phi =
temp.model_.ic() *
sin(temp.model_.cpr() * (temp.phi0_ - temp.model_.phiOff()));
double ic_sin_phi = 0.0;
auto &cpr = temp.model_.cpr();
for (int harm = 0; harm < cpr.size(); ++harm) {
ic_sin_phi += temp.model_.ic() *
(cpr.at(harm) *
sin((harm + 1) * (temp.phi0_ - temp.model_.phiOff())));
}
if (!temp.model_.tDep()) {
// -(hR / h + 2RC) * (Ic sin (φ0) - 2C / h Vp1 + C/2h Vp2 + It)
b_.at(temp.indexInfo.currentIndex_.value()) =
(temp.matrixInfo.nonZeros_.back()) *
(ic_sin_phi - (((2 * model.c()) / (stepSize_)) * temp.vn1_) +
((model.c() / (2.0 * (stepSize_))) * temp.vn2_) + temp.it_);
} else {
double sin2_half_phi =
sin(temp.model_.cpr() * (temp.phi0_ - temp.model_.phiOff()) / 2);
double sin2_half_phi = 0.0;
for (int harm = 0; harm < cpr.size(); ++harm) {
sin2_half_phi +=
cpr.at(harm) *
sin((harm + 1) * (temp.phi0_ - temp.model_.phiOff()) / 2);
}
sin2_half_phi = sin2_half_phi * sin2_half_phi;
double sin_phi =
sin(temp.model_.cpr() * (temp.phi0_ - temp.model_.phiOff()));
double sin_phi = 0.0;
for (int harm = 0; harm < cpr.size(); ++harm) {
sin_phi += cpr.at(harm) *
sin((harm + 1) * (temp.phi0_ - temp.model_.phiOff()));
}
double sqrt_part = sqrt(1 - model.d() * sin2_half_phi);
b_.at(temp.indexInfo.currentIndex_.value()) =
// -(hR / h + 2RC) *(
Expand Down
9 changes: 0 additions & 9 deletions src/josim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,14 @@ int main(int argc, const char** argv) {
IV ivObj(iObj);
// Identify the simulation parameters
Transient::identify_simulation(iObj.controls, iObj.transSim);
// Add noise (if any)
// Noise::add_noise_sources(iObj);
// Create matrix object
Matrix mObj;
// Create the matrix in csr format
mObj.create_matrix(iObj);
// Do verbosity
Verbose::handle_verbosity(iObj.argVerb, iObj, mObj);
//// Dump expanded Netlist since it is no longer needed
// iObj.netlist.expNetlist.clear();
// iObj.netlist.expNetlist.shrink_to_fit();
// Find the relevant traces to store
find_relevant_traces(iObj, mObj);
int sum = 0.0;
for (auto& i : mObj.ci) {
sum += i;
}
// Create a simulation object
Simulation sObj(iObj, mObj);
// Create an output object
Expand Down

0 comments on commit 22a9ae2

Please sign in to comment.