use of gov.sandia.n2a.eqset.Variable in project n2a by frothga.
the class JobC method addImplicitDependencies.
/**
* Depends on the results of: addAttributes(), findDeath()
*/
public void addImplicitDependencies(EquationSet s) {
if (T.equals("int")) {
// Force top-level model to keep $t', so it can retrieve time exponent.
Variable dt = s.find(new Variable("$t", 1));
dt.addUser(s);
}
addImplicitDependenciesRecursive(s);
}
use of gov.sandia.n2a.eqset.Variable in project n2a by frothga.
the class JobC method generateCode.
public void generateCode(Path source) throws Exception {
StringBuilder result = new StringBuilder();
RendererC context;
if (T.equals("int"))
context = new RendererCfp(this, result);
else
context = new RendererC(this, result);
result.append("#include \"runtime.h\"\n");
if (kokkos) {
result.append("#include \"profiling.h\"\n");
}
result.append("#include \"Matrix.tcc\"\n");
result.append("#include \"MatrixFixed.tcc\"\n");
if (T.equals("int")) {
result.append("#include \"fixedpoint.tcc\"\n");
}
for (ProvideOperator po : extensions) {
Path include = po.include(this);
if (include == null)
continue;
result.append("#include <" + include.getFileName() + ">\n");
}
result.append("\n");
result.append("#include <iostream>\n");
result.append("#include <vector>\n");
result.append("#include <cmath>\n");
result.append("#include <csignal>\n");
result.append("\n");
result.append("using namespace std;\n");
result.append("using namespace fl;\n");
result.append("\n");
if (cli) {
result.append("Parameters<" + T + "> params;\n");
}
generateStatic(context, digestedModel);
result.append("\n");
generateClassList(digestedModel, result);
result.append("class Wrapper;\n");
result.append("\n");
generateDeclarations(digestedModel, result);
result.append("class Wrapper : public WrapperBase<" + T + ">\n");
result.append("{\n");
result.append("public:\n");
result.append(" " + prefix(digestedModel) + "_Population " + mangle(digestedModel.name) + ";\n");
result.append("\n");
result.append(" Wrapper ()\n");
result.append(" {\n");
result.append(" population = &" + mangle(digestedModel.name) + ";\n");
result.append(" " + mangle(digestedModel.name) + ".container = this;\n");
result.append(" }\n");
result.append("};\n");
result.append("\n");
generateDefinitions(context, digestedModel);
// Main
result.append("int main (int argc, char * argv[])\n");
result.append("{\n");
result.append(" signal (SIGFPE, signalHandler);\n");
result.append(" signal (SIGINT, signalHandler);\n");
result.append(" signal (SIGTERM, signalHandler);\n");
result.append("\n");
result.append(" try\n");
result.append(" {\n");
if (kokkos) {
result.append(" get_callbacks ();\n");
}
if (cli) {
result.append(" params.parse (argc, argv);\n");
}
generateMainInitializers(context);
result.append("\n");
if (seed >= 0) {
result.append(" srand (" + seed + ");\n");
}
if (T.equals("int")) {
Variable dt = digestedModel.find(new Variable("$t", 1));
result.append(" Event<int>::exponent = " + dt.exponent + ";\n");
}
String integrator = digestedModel.metadata.getOrDefault("Euler", "backend", "all", "integrator");
if (integrator.equalsIgnoreCase("RungeKutta"))
integrator = "RungeKutta";
else
integrator = "Euler";
result.append(" Simulator<" + T + ">::instance.integrator = new " + integrator + "<" + T + ">;\n");
result.append(" Simulator<" + T + ">::instance.after = " + after + ";\n");
result.append(" Wrapper wrapper;\n");
result.append(" Simulator<" + T + ">::instance.run (wrapper);\n");
result.append("\n");
result.append(" outputClose ();\n");
if (kokkos) {
result.append(" finalize_profiling ();\n");
}
result.append(" }\n");
result.append(" catch (const char * message)\n");
result.append(" {\n");
result.append(" cerr << \"Exception: \" << message << endl;\n");
result.append(" return 1;\n");
result.append(" }\n");
result.append(" return 0;\n");
result.append("}\n");
Files.copy(new ByteArrayInputStream(result.toString().getBytes("UTF-8")), source);
}
use of gov.sandia.n2a.eqset.Variable in project n2a by frothga.
the class RendererC method moduloParam.
public void moduloParam(Operator a) {
if (a.isScalar()) {
double d = a.getDouble();
result.append(String.valueOf(d));
if (job.T.equals("float"))
result.append("f");
return;
}
if (a instanceof AccessVariable) {
// Trap variables that are declared int
Variable v = ((AccessVariable) a).reference.variable;
if (v.name.equals("$index") || v.name.equals("$n") && v.hasAttribute("initOnly")) {
result.append("(" + job.T + ") ");
}
a.render(this);
return;
}
// The general case
result.append("(" + job.T + ") (");
a.render(this);
result.append(")");
}
use of gov.sandia.n2a.eqset.Variable in project n2a by frothga.
the class EventSpikeMulti method run.
public void run(Simulator simulator) {
setFlag();
for (Instance i : targets) simulator.integrate(i);
for (Instance i : targets) i.update(simulator);
for (Instance i : targets) {
boolean live = i.finish(simulator);
InternalBackendData bed = (InternalBackendData) i.equations.backendData;
for (Variable v : bed.eventReferences) ((Instance) i.valuesObject[v.reference.index]).finishEvent(v.reference.variable);
if (!live)
i.dequeue();
}
}
use of gov.sandia.n2a.eqset.Variable in project n2a by frothga.
the class EventSpikeSingle method run.
public void run(Simulator simulator) {
setFlag();
simulator.integrate(target);
target.update(simulator);
boolean live = target.finish(simulator);
InternalBackendData bed = (InternalBackendData) target.equations.backendData;
for (Variable v : bed.eventReferences) ((Instance) target.valuesObject[v.reference.index]).finishEvent(v.reference.variable);
if (!live)
target.dequeue();
}
Aggregations