31 auto daeComp = std::dynamic_pointer_cast<DAEInterface>(comp);
32 std::cout <<
"Added Comp" << std::endl;
37 mComponents.push_back(comp);
40 for (
auto baseNode :
mSystem.mNodes) {
42 if (!baseNode->isGround()) {
43 auto node = std::dynamic_pointer_cast<CPS::SimNode<Complex>>(baseNode);
44 mNodes.push_back(node);
45 std::cout <<
"Added Node" << std::endl;
49 mNEQ = mComponents.size() + (2 * mNodes.size());
50 std::cout << std::endl;
51 std::cout <<
"Number of Eqn. " << mNEQ << std::endl;
53 std::cout <<
"Processing Nodes" << std::endl;
54 UInt matrixNodeIndexIdx = 0;
56 for (
UInt idx = 0; idx < mNodes.size(); ++idx) {
58 mNodes[idx]->setMatrixNodeIndex(0, matrixNodeIndexIdx);
61 mNodes[idx]->setMatrixNodeIndex(1, matrixNodeIndexIdx);
63 mNodes[idx]->setMatrixNodeIndex(2, matrixNodeIndexIdx);
68 std::cout <<
"Nodes Setup Done" << std::endl;
76 realtype *sval = NULL, *s_dtval = NULL;
77 std::cout <<
"Init states" << std::endl;
83 std::cout <<
"State Init done" << std::endl;
84 std::cout <<
"Pointer Init" << std::endl;
85 sval = N_VGetArrayPointer_Serial(
state);
86 s_dtval = N_VGetArrayPointer_Serial(
dstate_dt);
87 std::cout <<
"Pointer Init done" << std::endl << std::endl;
93 tempVolt = std::real(node->initialSingleVoltage(phase));
95 std::cout <<
"Node Volt " << counter <<
": " << tempVolt << std::endl;
96 sval[counter++] = tempVolt;
100 auto emtComp = std::dynamic_pointer_cast<SimPowerComp<Complex>>(comp);
102 emtComp->initializeFromNodesAndTerminals(
106 auto daeComp = std::dynamic_pointer_cast<DAEInterface>(comp);
111 sval[counter++] = std::real(daeComp->daeInitialize());
112 std::cout <<
"Comp Volt " << counter - 1 <<
": " << sval[counter - 1]
119 [daeComp](
double ttime,
const double state[],
const double dstate_dt[],
120 double resid[], std::vector<int> &off) {
125 for (
int j = 0; j < (int)
mNodes.size(); j++) {
128 std::cout <<
"Nodal Equation value " << sval[counter - 1] << std::endl;
131 std::cout << std::endl;
134 for (
int i = 0; i < (
mNEQ); i++) {
136 std::cout <<
"derivative " << i <<
": " << s_dtval[i] << std::endl;
139 std::cout << std::endl;
141 std::cout <<
"Init Tolerances" << std::endl;
142 rtol = RCONST(1.0e-10);
144 std::cout <<
"Init Tolerances done" << std::endl;
148 std::cout <<
"Memory Ok" << std::endl;
149 std::cout <<
"Define Userdata" << std::endl;
151 ret = IDASetUserData(
mem,
this);
153 std::cout <<
"Call IDAInit" << std::endl;
158 std::cout <<
"Call IDATolerances" << std::endl;
161 std::cout <<
"Call IDA Solver Stuff" << std::endl;
164 LS = SUNDenseLinearSolver(
state,
A);
165 ret = IDADlsSetLinearSolver(
mem,
LS,
A);
185 double *residual = NV_DATA_S(resid);
186 double *tempstate = NV_DATA_S(
state);
188 for (
auto node :
mNodes) {
192 tempVolt += std::real(node->singleVoltage());
200 resFn(ttime, NV_DATA_S(
state), NV_DATA_S(
dstate_dt), NV_DATA_S(resid),
212 std::cout <<
"Current Time " << NextTime << std::endl;
216 if (ret == IDA_SUCCESS) {
219 std::cout <<
"Ida Error " << ret << std::endl;
223 std::cout <<
"Interal steps: " <<
interalSteps << std::endl;
224 std::cout <<
"Res Eval :" <<
resEval << std::endl;
std::shared_ptr< IdentifiedObject > Ptr
void * mem
Memory block allocated by IDA.
N_Vector state
Vector of problem variables.
N_Vector dstate_dt
Derivates of the state vector with respect to time.
SUNLinearSolver LS
Linear solver object.
std::vector< CPS::DAEInterface::ResFn > mResidualFunctions
Real step(Real time)
Solve system for the current time.
Int mNEQ
Number of equations in problem.
CPS::Task::List getTasks() override
Get tasks for scheduler.
CPS::SystemTopology mSystem
int residualFunction(realtype ttime, N_Vector state, N_Vector dstate_dt, N_Vector resid)
std::vector< Int > mOffsets
Offsets vector for adding new equations to the residual vector.
Real mTimestep
Constant time step.
~DAESolver()
Deallocate all memory.
CPS::SimNode< Complex >::List mNodes
Nodes of the Problem.
DAESolver(String name, const CPS::SystemTopology &system, Real dt, Real mT0)
Create solve object with given parameters.
realtype rtol
Relative tolerance.
realtype abstol
Scalar absolute tolerance.
void initialize() final
Initialize Components & Nodes with initial values.
CPS::IdentifiedObject::List mComponents
Components of the Problem.
static int residualFunctionWrapper(realtype ttime, N_Vector state, N_Vector dstate_dt, N_Vector resid, void *user_data)
Residual Function of entire System.
realtype tret
Time IDA reached while solving.
SUNMatrix A
Template Jacobian Matrix.
Solver(String name, CPS::Logger::Level logLevel)