Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pulse Physiology Suite
engine
Commits
2e6c4df0
Commit
2e6c4df0
authored
Oct 17, 2018
by
Aaron Bray
Browse files
WIP Enum updates from encapsulating serialization code into new class space
parent
a430239c
Changes
256
Hide whitespace changes
Inline
Side-by-side
Pulse.cmake
View file @
2e6c4df0
...
...
@@ -112,7 +112,7 @@ include(${CMAKE_CURRENT_SOURCE_DIR}/PulseJNI.cmake)
include
(
${
CMAKE_CURRENT_SOURCE_DIR
}
/PulseCLR.cmake
)
set_property
(
GLOBAL PROPERTY USE_FOLDERS ON
)
set_target_properties
(
libprotobuf libprotobuf-lite libprotoc protoc
js_embed
PROPERTIES FOLDER protobufs
)
set_target_properties
(
libprotobuf libprotobuf-lite libprotoc protoc PROPERTIES FOLDER protobufs
)
file
(
COPY
${
CMAKE_SOURCE_DIR
}
/bin DESTINATION
${
CMAKE_INSTALL_PREFIX
}
)
...
...
SuperBuild.cmake
View file @
2e6c4df0
...
...
@@ -64,8 +64,8 @@ list(APPEND Pulse_DEPENDENCIES log4cplus)
###################################################
message
(
STATUS
"External project - protobuf"
)
set
(
protobuf_VERSION
"3.6.
0.
1"
)
set
(
protobuf_MD5
"
0b33849480f5a469ba54b9ec10004e7b
"
)
set
(
protobuf_VERSION
"3.6.1"
)
set
(
protobuf_MD5
"
e09a2a7d3b34a271aedfc0b38ac2a4dc
"
)
set
(
protobuf_SRC
"
${
CMAKE_BINARY_DIR
}
/protobuf/src/protobuf"
)
ExternalProject_Add
(
protobuf
...
...
cdm/CDM.cmake
View file @
2e6c4df0
...
...
@@ -40,7 +40,7 @@ list(APPEND SOURCE ${COMPARTMENT_TISSUE_FILES})
# Compartment/Managers
file
(
GLOB COMPARTMENT_MANAGERS_FILES
"cpp/compartment/managers/*.h"
"cpp/compartment/managers/*.cpp"
)
source_group
(
"Compartment
\\
Managers"
FILES
${
COMPARTMENT_MANAGERS_FILES
}
)
list
(
APPEND SOURCE
${
COMPARTMENT_MANAGERS_FILES
}
)
list
(
APPEND SOURCE
${
COMPARTMENT_MANAGERS_FILES
}
)
# Substance Quantity
file
(
GLOB SUBSTANCE_QUANTITY_FILES
"cpp/compartment/substances/*.h"
"cpp/compartment/substances/*.cpp"
"cpp/compartment/substances/*.inl"
)
source_group
(
"Compartment
\\
Substances"
FILES
${
SUBSTANCE_QUANTITY_FILES
}
)
...
...
@@ -106,7 +106,6 @@ file(GLOB INHALER_FILES "cpp/system/equipment/inhaler/*.h" "cpp/system/equipment
source_group
(
"System
\\
Equipment
\\
Inhaler"
FILES
${
INHALER_FILES
}
)
file
(
GLOB INHALER_ACTION_FILES
"cpp/system/equipment/inhaler/actions/*.h"
"cpp/system/equipment/inhaler/actions/*.cpp"
)
source_group
(
"System
\\
Equipment
\\
Inhaler
\\
Actions"
FILES
${
INHALER_ACTION_FILES
}
)
list
(
APPEND SOURCE
${
ANESTHESIA_FILES
}
)
list
(
APPEND SOURCE
${
ANESTHESIA_ACTION_FILES
}
)
list
(
APPEND SOURCE
${
ECG_FILES
}
)
...
...
@@ -137,6 +136,10 @@ list(APPEND SOURCE ${UTILS_FILES})
list
(
APPEND SOURCE
${
UTILS_TESTING_FILES
}
)
list
(
APPEND SOURCE
${
UTILS_UCE_FILES
}
)
#list(APPEND SOURCE ${UTILS_XPSTL_FILES})
# I/O
include
(
cpp/io/protobuf/CMakeLists.txt
)
source_group
(
${
IO_GROUP
}
FILES
${
IO_FILES
}
)
list
(
APPEND SOURCE
${
IO_FILES
}
)
# The DLL we are building
add_library
(
CommonDataModel
${
SOURCE
}
)
...
...
cdm/cpp/CommonDataModel.cpp
0 → 100644
View file @
2e6c4df0
/* Distributed under the Apache License, Version 2.0.
See accompanying NOTICE file for details.*/
#include
"stdafx.h"
#include
"bind/cdm/Enums.pb.h"
const
std
::
string
&
eSide_Name
(
eSide
m
)
{
return
cdm
::
eSide_Name
((
cdm
::
eSide
)
m
);
}
const
std
::
string
&
eGate_Name
(
eGate
m
)
{
return
cdm
::
eGate_Name
((
cdm
::
eGate
)
m
);
}
const
std
::
string
&
eSwitch_Name
(
eSwitch
m
)
{
return
cdm
::
eSwitch_Name
((
cdm
::
eSwitch
)
m
);
}
const
std
::
string
&
eCharge_Name
(
eCharge
m
)
{
return
cdm
::
eCharge_Name
((
cdm
::
eCharge
)
m
);
}
\ No newline at end of file
cdm/cpp/CommonDataModel.h
View file @
2e6c4df0
...
...
@@ -26,6 +26,9 @@
#endif
#define CDM_BIND_DECL(type) namespace cdm { class type; }
#define CDM_DECL_BIND(type) \
class SE##type;\
namespace cdm { class type##Data; }
#include
<memory>
#include
<stdio.h>
...
...
@@ -113,7 +116,23 @@ struct CommonDataModelException : public std::runtime_error
#include
"Macros.h"
#include
"utils/Logger.h"
#include
"bind/cdm/Enums.pb.h"
// General Enums
// Keep enums in sync with appropriate schema/cdm/Enums.proto file !!
//
enum
class
eSide
{
NullSide
=
0
,
Left
,
Right
};
extern
const
std
::
string
&
eSide_Name
(
eSide
m
);
enum
class
eGate
{
NullGate
=
0
,
Open
,
Closed
};
extern
const
std
::
string
&
eGate_Name
(
eGate
m
);
enum
class
eSwitch
{
NullSwitch
=
0
,
Off
,
On
};
extern
const
std
::
string
&
eSwitch_Name
(
eSwitch
m
);
enum
class
eCharge
{
NullCharge
=
0
,
Negative
,
Neutral
,
Positive
};
extern
const
std
::
string
&
eCharge_Name
(
eCharge
m
);
//
// End General Enum
class
CCompoundUnit
;
...
...
cdm/cpp/PhysiologyEngine.h
View file @
2e6c4df0
...
...
@@ -34,8 +34,6 @@ class SEConditionManager;
class
SEEngineTracker
;
class
SEEngineConfiguration
;
#include
<google/protobuf/message.h>
/**
* @brief
* Base exception class that all CDM classes throw when an error occurs
...
...
@@ -74,7 +72,7 @@ public:
/// Engine will be in a cleared state if this method fails.
/// Note the provided configuration will overwrite any configuration options in the state with its contents (Use with caution!)
//--------------------------------------------------------------------------------------------------
virtual
bool
LoadState
(
const
google
::
protobuf
::
Message
&
state
,
const
SEScalarTime
*
simTime
=
nullptr
,
const
SEEngineConfiguration
*
config
=
nullptr
)
=
0
;
virtual
bool
LoadState
(
const
void
*
state
,
const
SEScalarTime
*
simTime
=
nullptr
,
const
SEEngineConfiguration
*
config
=
nullptr
)
=
0
;
//--------------------------------------------------------------------------------------------------
/// \brief
...
...
@@ -83,7 +81,7 @@ public:
/// State object will be returned.
/// Engine will be in a cleared state if this method fails.
//--------------------------------------------------------------------------------------------------
virtual
std
::
unique_ptr
<
google
::
protobuf
::
Message
>
SaveState
(
const
std
::
string
&
filename
=
""
)
=
0
;
virtual
void
*
SaveState
(
const
std
::
string
&
filename
=
""
)
=
0
;
//--------------------------------------------------------------------------------------------------
/// \brief
...
...
cdm/cpp/circuit/SECircuit.h
View file @
2e6c4df0
...
...
@@ -5,12 +5,13 @@
#include
"circuit/SECircuitNode.h"
#include
"circuit/SECircuitPath.h"
#define CIRCUIT_TEMPLATE typename
CircuitBindType, typename NodeType, typename CircuitNodeBindType, typename PathType, typename CircuitPathBind
Type
#define CIRCUIT_TYPES
CircuitBindType,NodeType,CircuitNodeBindType,PathType,CircuitPathBind
Type
#define CIRCUIT_TEMPLATE typename
NodeType, typename Path
Type
#define CIRCUIT_TYPES
NodeType,Path
Type
template
<
CIRCUIT_TEMPLATE
>
class
SECircuit
:
public
Loggable
{
friend
class
PBCircuit
;
//friend the serialization class
public:
SECircuit
(
const
std
::
string
&
name
,
Logger
*
logger
);
...
...
@@ -18,13 +19,6 @@ public:
virtual
void
Clear
();
//clear memory
static
void
Load
(
const
CircuitBindType
&
src
,
SECircuit
&
dst
,
const
std
::
map
<
std
::
string
,
NodeType
*>&
nodes
,
const
std
::
map
<
std
::
string
,
PathType
*>&
paths
);
static
CircuitBindType
*
Unload
(
const
SECircuit
&
src
);
protected:
static
void
Serialize
(
const
CircuitBindType
&
src
,
SECircuit
&
dst
,
const
std
::
map
<
std
::
string
,
NodeType
*>&
nodes
,
const
std
::
map
<
std
::
string
,
PathType
*>&
paths
);
static
void
Serialize
(
const
SECircuit
&
src
,
CircuitBindType
&
dst
);
public:
virtual
std
::
string
GetName
()
const
;
virtual
bool
HasReferenceNode
()
const
;
...
...
cdm/cpp/circuit/SECircuit.inl
View file @
2e6c4df0
...
...
@@ -35,59 +35,6 @@ void SECircuit<CIRCUIT_TYPES>::Clear()
m_PolarizedElementPaths.clear();
}
template<CIRCUIT_TEMPLATE>
void SECircuit<CIRCUIT_TYPES>::Load(const CircuitBindType& src, SECircuit& dst, const std::map<std::string, NodeType*>& nodes, const std::map<std::string, PathType*>& paths)
{
SECircuit::Serialize(src, dst, nodes, paths);
dst.StateChange();
}
template<CIRCUIT_TEMPLATE>
void SECircuit<CIRCUIT_TYPES>::Serialize(const CircuitBindType& src, SECircuit& dst, const std::map<std::string, NodeType*>& nodes, const std::map<std::string, PathType*>& paths)
{// note: not clearing here as the derived class needs to clear and call this super class Load last to get the ref node hooked up
dst.Clear();
const cdm::CircuitData& srcC = src.circuit();
dst.m_Name = srcC.name();
for (int i=0; i<srcC.node_size(); i++)
{
const std::string name = srcC.node(i);
auto idx = nodes.find(name);
if (idx == nodes.end())
{
dst.Error(dst.m_Name + " could not find node " + name.c_str());
return;
}
dst.AddNode(*idx->second);
}
for (int i = 0; i<srcC.path_size(); i++)
{
const std::string name = srcC.path(i);
auto idx = paths.find(name);
if (idx == paths.end())
{
dst.Error(dst.m_Name + " could not find path " + name.c_str());
return;
}
dst.AddPath(*idx->second);
}
}
template<CIRCUIT_TEMPLATE>
CircuitBindType* SECircuit<CIRCUIT_TYPES>::Unload(const SECircuit& src)
{
CircuitBindType* dst = new CircuitBindType();
Serialize(src,*dst);
return dst;
}
template<CIRCUIT_TEMPLATE>
void SECircuit<CIRCUIT_TYPES>::Serialize(const SECircuit& src, CircuitBindType& dst)
{
cdm::CircuitData* dstC = dst.mutable_circuit();
dstC->set_name(src.m_Name);
for (auto* n : src.m_Nodes)
dstC->add_node(n->GetName());
for (auto* p : src.m_Paths)
dstC->add_path(p->GetName());
}
template<CIRCUIT_TEMPLATE>
void SECircuit<CIRCUIT_TYPES>::StateChange()
{
...
...
cdm/cpp/circuit/SECircuitCalculator.h
View file @
2e6c4df0
...
...
@@ -4,6 +4,7 @@
#pragma once
#include
"Eigen/Core"
#include
"utils/SmartEnum.h"
#include
<set>
#define CIRCUIT_CALCULATOR_TEMPLATE typename CircuitType, typename NodeType, typename PathType, typename CapacitanceUnit, typename FluxUnit, typename InductanceUnit, typename PotentialUnit, typename QuantityUnit, typename ResistanceUnit
#define CIRCUIT_CALCULATOR_TYPES CircuitType,NodeType,PathType,CapacitanceUnit,FluxUnit,InductanceUnit,PotentialUnit,QuantityUnit,ResistanceUnit
...
...
cdm/cpp/circuit/SECircuitCalculator.inl
View file @
2e6c4df0
...
...
@@ -70,7 +70,7 @@ void SECircuitCalculator<CIRCUIT_CALCULATOR_TYPES>::Process(CircuitType& circuit
for (PathType* p : circuit.GetPolarizedElementPaths())
{
if (p->HasNextPolarizedState())
p->SetNextPolarizedState(
cdm::
eGate::Closed);
p->SetNextPolarizedState(eGate::Closed);
}
//When we parse everything into our Ax=b matrices/vectors for the linear solver,
...
...
@@ -189,8 +189,8 @@ void SECircuitCalculator<CIRCUIT_CALCULATOR_TYPES>::ParseIn()
//We have to do this outside of the KCL loop below because we only want to account for each one once.
if (p->HasNextPotentialSource() ||
(p->NumberOfNextElements() < 1) ||
(p->HasNextValve() && p->GetNextValve() ==
cdm::
eGate::Closed) ||
(p->HasNextSwitch() && p->GetNextSwitch() ==
cdm::
eGate::Closed))
(p->HasNextValve() && p->GetNextValve() == eGate::Closed) ||
(p->HasNextSwitch() && p->GetNextSwitch() == eGate::Closed))
{
m_potentialSources[p] = numNodes + idx++;
}
...
...
@@ -225,7 +225,7 @@ void SECircuitCalculator<CIRCUIT_CALCULATOR_TYPES>::ParseIn()
NodeType* nSrc = &p->GetSourceNode();
NodeType* nTgt = &p->GetTargetNode();
if (p->HasNextPolarizedState() && p->GetNextPolarizedState() ==
cdm::
eGate::Open)
if (p->HasNextPolarizedState() && p->GetNextPolarizedState() == eGate::Open)
{ //Polarized elements that are open are done exactly the same as a open switch.
//We'll check to see if the resulting pressure difference is valid later.
//Model as an open switch
...
...
@@ -239,7 +239,7 @@ void SECircuitCalculator<CIRCUIT_CALCULATOR_TYPES>::ParseIn()
//The variables in the x vector are the unknown Node Pressures and Flows for Pressure Sources.
if (p->HasNextSwitch())
{
if (p->GetNextSwitch() ==
cdm::
eGate::Open)
if (p->GetNextSwitch() == eGate::Open)
{
//Model as a resistor with a ridiculously high resistance (basically an open circuit)
double dMultiplier = 1.0 / OPEN_RESISTANCE;
...
...
@@ -366,7 +366,7 @@ void SECircuitCalculator<CIRCUIT_CALCULATOR_TYPES>::ParseIn()
{
//Valves are done exactly the same as switches.
//We'll check to see if the resulting flow and pressure difference is valid later.
if (p->GetNextValve() ==
cdm::
eGate::Open)
if (p->GetNextValve() == eGate::Open)
{
//Model as a resistor with a ridiculously high resistance (basically an open circuit)
double dMultiplier = 1.0 / OPEN_RESISTANCE;
...
...
@@ -671,9 +671,9 @@ void SECircuitCalculator<CIRCUIT_CALCULATOR_TYPES>::CalculateFluxes()
{
Override<FluxUnit>(p->GetNextFluxSource(), p->GetNextFlux());
}
else if ((p->HasNextSwitch() && p->GetNextSwitch() ==
cdm::
eGate::Open) ||
(p->HasNextValve() && p->GetNextValve() ==
cdm::
eGate::Open) ||
(p->HasNextPolarizedState() && p->GetNextPolarizedState() ==
cdm::
eGate::Open))
else if ((p->HasNextSwitch() && p->GetNextSwitch() == eGate::Open) ||
(p->HasNextValve() && p->GetNextValve() == eGate::Open) ||
(p->HasNextPolarizedState() && p->GetNextPolarizedState() == eGate::Open))
{
ValueOverride<FluxUnit>(p->GetNextFlux(), 0, m_FluxUnit);
}
...
...
@@ -756,13 +756,13 @@ void SECircuitCalculator<CIRCUIT_CALCULATOR_TYPES>::CalculateQuantities()
//dStartingPressDiff is at time = T + deltaT
double dEndingPressDiff = std::abs(p->GetSourceNode().GetNextPotential().GetValue(m_PotentialUnit) - p->GetTargetNode().GetNextPotential().GetValue(m_PotentialUnit));
if (p->GetPolarizedState() ==
cdm::
eGate::Open)
if (p->GetPolarizedState() == eGate::Open)
{
//If this was a shorted polarized element last time-step, we need to make the starting difference zero
//Otherwise, it will possibly think it was already charged to a certain point
dStartingPressDiff = 0.0;
}
if (p->GetNextPolarizedState() ==
cdm::
eGate::Open)
if (p->GetNextPolarizedState() == eGate::Open)
{
//If it is currently a shorted polarized element, we need to make the starting difference zero
//This will make it go to the non-charged volume
...
...
@@ -815,10 +815,10 @@ bool SECircuitCalculator<CIRCUIT_CALCULATOR_TYPES>::CheckAndModifyValves()
for (PathType* p : m_circuit->GetValvePaths())
{
if ((p->GetNextValve() ==
cdm::
eGate::Closed &&
if ((p->GetNextValve() == eGate::Closed &&
p->GetNextFlux().GetValue(m_FluxUnit) < -ZERO_APPROX)
||
(p->GetNextValve() ==
cdm::
eGate::Open &&
(p->GetNextValve() == eGate::Open &&
(p->GetSourceNode().GetNextPotential().GetValue(m_PotentialUnit) -
p->GetTargetNode().GetNextPotential().GetValue(m_PotentialUnit)) > ZERO_APPROX))
{
...
...
@@ -833,7 +833,7 @@ bool SECircuitCalculator<CIRCUIT_CALCULATOR_TYPES>::CheckAndModifyValves()
for (PathType* p : m_circuit->GetPolarizedElementPaths())
{
if (p->GetNextPolarizedState() ==
cdm::
eGate::Closed &&
if (p->GetNextPolarizedState() == eGate::Closed &&
(p->GetSourceNode().GetNextPotential().GetValue(m_PotentialUnit) -
p->GetTargetNode().GetNextPotential().GetValue(m_PotentialUnit)) < -ZERO_APPROX)
{
...
...
@@ -871,13 +871,13 @@ bool SECircuitCalculator<CIRCUIT_CALCULATOR_TYPES>::IsCurrentValveStateUnique()
/// so this bit order is important.
for (PathType* pValve : m_circuit->GetValvePaths())
{
if (pValve->GetNextValve() ==
cdm::
eGate::Closed)
if (pValve->GetNextValve() == eGate::Closed)
currentState |= index;
index = index << static_cast<uint64_t>(1);
}
for (PathType* pPolarizedElement : m_circuit->GetPolarizedElementPaths())
{
if (pPolarizedElement->GetNextPolarizedState() ==
cdm::
eGate::Closed)
if (pPolarizedElement->GetNextPolarizedState() == eGate::Closed)
currentState |= index;
index = index << static_cast<uint64_t>(1);
}
...
...
cdm/cpp/circuit/SECircuitManager.cpp
View file @
2e6c4df0
...
...
@@ -15,7 +15,6 @@
#include
"circuit/electrical/SEElectricalCircuitNode.h"
#include
"circuit/electrical/SEElectricalCircuitPath.h"
#include
<google/protobuf/text_format.h>
template
<
CIRCUIT_LEDGER_TEMPLATE
>
void
SECircuitLedger
<
CIRCUIT_LEDGER_TYPES
>::
Clear
()
...
...
@@ -41,158 +40,6 @@ void SECircuitManager::Clear()
m_ThermalLedger
.
Clear
();
}
bool
SECircuitManager
::
LoadFile
(
const
std
::
string
&
filename
)
{
cdm
::
CircuitManagerData
src
;
std
::
ifstream
file_stream
(
filename
,
std
::
ios
::
in
);
std
::
string
fmsg
((
std
::
istreambuf_iterator
<
char
>
(
file_stream
)),
std
::
istreambuf_iterator
<
char
>
());
if
(
!
google
::
protobuf
::
TextFormat
::
ParseFromString
(
fmsg
,
&
src
))
return
false
;
SECircuitManager
::
Load
(
src
,
*
this
);
return
true
;
// If its a binary string in the file...
//std::ifstream binary_istream(filename, std::ios::in | std::ios::binary);
//src.ParseFromIstream(&binary_istream);
}
void
SECircuitManager
::
SaveFile
(
const
std
::
string
&
filename
)
{
std
::
string
content
;
cdm
::
CircuitManagerData
*
src
=
SECircuitManager
::
Unload
(
*
this
);
google
::
protobuf
::
TextFormat
::
PrintToString
(
*
src
,
&
content
);
std
::
ofstream
ascii_ostream
(
filename
,
std
::
ios
::
out
|
std
::
ios
::
trunc
);
ascii_ostream
<<
content
;
ascii_ostream
.
flush
();
ascii_ostream
.
close
();
delete
src
;
}
void
SECircuitManager
::
Load
(
const
cdm
::
CircuitManagerData
&
src
,
SECircuitManager
&
dst
)
{
SECircuitManager
::
Serialize
(
src
,
dst
);
dst
.
StateChange
();
}
void
SECircuitManager
::
Serialize
(
const
cdm
::
CircuitManagerData
&
src
,
SECircuitManager
&
dst
)
{
dst
.
Clear
();
// Electrical
for
(
int
i
=
0
;
i
<
src
.
electricalnode_size
();
i
++
)
{
const
cdm
::
ElectricalCircuitNodeData
&
n
=
src
.
electricalnode
(
i
);
SEElectricalCircuitNode
::
Load
(
n
,
dst
.
CreateNode
<
ELECTRICAL_LEDGER_TYPES
>
(
n
.
circuitnode
().
name
(),
dst
.
m_ElectricalLedger
));
}
for
(
int
i
=
0
;
i
<
src
.
electricalpath_size
();
i
++
)
{
const
cdm
::
ElectricalCircuitPathData
&
p
=
src
.
electricalpath
(
i
);
SEElectricalCircuitNode
*
src
=
dst
.
GetNode
(
p
.
circuitpath
().
sourcenode
(),
dst
.
m_ElectricalLedger
);
if
(
src
==
nullptr
)
{
dst
.
Error
(
"Could not find source node "
+
p
.
circuitpath
().
sourcenode
()
+
" from path "
+
p
.
circuitpath
().
name
().
c_str
());
continue
;
}
SEElectricalCircuitNode
*
tgt
=
dst
.
GetNode
(
p
.
circuitpath
().
targetnode
(),
dst
.
m_ElectricalLedger
);
if
(
tgt
==
nullptr
)
{
dst
.
Error
(
"Could not find target node "
+
p
.
circuitpath
().
targetnode
()
+
" from path "
+
p
.
circuitpath
().
name
().
c_str
());
continue
;
}
SEElectricalCircuitPath
::
Load
(
p
,
dst
.
CreatePath
<
ELECTRICAL_LEDGER_TYPES
>
(
*
src
,
*
tgt
,
p
.
circuitpath
().
name
(),
dst
.
m_ElectricalLedger
));
}
for
(
int
i
=
0
;
i
<
src
.
electricalcircuit_size
();
i
++
)
{
const
cdm
::
ElectricalCircuitData
&
c
=
src
.
electricalcircuit
(
i
);
SEElectricalCircuit
::
Load
(
c
,
dst
.
CreateCircuit
<
ELECTRICAL_LEDGER_TYPES
>
(
c
.
circuit
().
name
(),
dst
.
m_ElectricalLedger
),
dst
.
m_ElectricalLedger
.
nodes
,
dst
.
m_ElectricalLedger
.
paths
);
}
// Fluid
for
(
int
i
=
0
;
i
<
src
.
fluidnode_size
();
i
++
)
{
const
cdm
::
FluidCircuitNodeData
&
n
=
src
.
fluidnode
(
i
);
SEFluidCircuitNode
::
Load
(
n
,
dst
.
CreateNode
<
FLUID_LEDGER_TYPES
>
(
n
.
circuitnode
().
name
(),
dst
.
m_FluidLedger
));
}
for
(
int
i
=
0
;
i
<
src
.
fluidpath_size
();
i
++
)
{
const
cdm
::
FluidCircuitPathData
&
p
=
src
.
fluidpath
(
i
);
SEFluidCircuitNode
*
src
=
dst
.
GetNode
(
p
.
circuitpath
().
sourcenode
(),
dst
.
m_FluidLedger
);
if
(
src
==
nullptr
)
{
dst
.
Error
(
"Could not find source node "
+
p
.
circuitpath
().
sourcenode
()
+
" from path "
+
p
.
circuitpath
().
name
().
c_str
());
continue
;
}
SEFluidCircuitNode
*
tgt
=
dst
.
GetNode
(
p
.
circuitpath
().
targetnode
(),
dst
.
m_FluidLedger
);
if
(
tgt
==
nullptr
)
{
dst
.
Error
(
"Could not find target node "
+
p
.
circuitpath
().
targetnode
()
+
" from path "
+
p
.
circuitpath
().
name
().
c_str
());
continue
;
}
SEFluidCircuitPath
::
Load
(
p
,
dst
.
CreatePath
<
FLUID_LEDGER_TYPES
>
(
*
src
,
*
tgt
,
p
.
circuitpath
().
name
(),
dst
.
m_FluidLedger
));
}
for
(
int
i
=
0
;
i
<
src
.
fluidcircuit_size
();
i
++
)
{
const
cdm
::
FluidCircuitData
&
c
=
src
.
fluidcircuit
(
i
);
SEFluidCircuit
::
Load
(
c
,
dst
.
CreateCircuit
<
FLUID_LEDGER_TYPES
>
(
c
.
circuit
().
name
(),
dst
.
m_FluidLedger
),
dst
.
m_FluidLedger
.
nodes
,
dst
.
m_FluidLedger
.
paths
);
}
// Thermal
for
(
int
i
=
0
;
i
<
src
.
thermalnode_size
();
i
++
)
{
const
cdm
::
ThermalCircuitNodeData
&
n
=
src
.
thermalnode
(
i
);
SEThermalCircuitNode
::
Load
(
n
,
dst
.
CreateNode
<
THERMAL_LEDGER_TYPES
>
(
n
.
circuitnode
().
name
(),
dst
.
m_ThermalLedger
));
}
for
(
int
i
=
0
;
i
<
src
.
thermalpath_size
();
i
++
)
{
const
cdm
::
ThermalCircuitPathData
&
p
=
src
.
thermalpath
(
i
);
SEThermalCircuitNode
*
src
=
dst
.
GetNode
(
p
.
circuitpath
().
sourcenode
(),
dst
.
m_ThermalLedger
);
if
(
src
==
nullptr
)
{
dst
.
Error
(
"Could not find source node "
+
p
.
circuitpath
().
sourcenode
()
+
" from path "
+
p
.
circuitpath
().
name
().
c_str
());
continue
;
}
SEThermalCircuitNode
*
tgt
=
dst
.
GetNode
(
p
.
circuitpath
().
targetnode
(),
dst
.
m_ThermalLedger
);
if
(
tgt
==
nullptr
)
{
dst
.
Error
(
"Could not find target node "
+
p
.
circuitpath
().
targetnode
()
+
" from path "
+
p
.
circuitpath
().
name
().
c_str
());
continue
;
}
SEThermalCircuitPath
::
Load
(
p
,
dst
.
CreatePath
<
THERMAL_LEDGER_TYPES
>
(
*
src
,
*
tgt
,
p
.
circuitpath
().
name
(),
dst
.
m_ThermalLedger
));
}
for
(
int
i
=
0
;
i
<
src
.
thermalcircuit_size
();
i
++
)
{
const
cdm
::
ThermalCircuitData
&
c
=
src
.
thermalcircuit
(
i
);
SEThermalCircuit
::
Load
(
c
,
dst
.
CreateCircuit
<
THERMAL_LEDGER_TYPES
>
(
c
.
circuit
().
name
(),
dst
.
m_ThermalLedger
),
dst
.
m_ThermalLedger
.
nodes
,
dst
.
m_ThermalLedger
.
paths
);
}
}
cdm
::
CircuitManagerData
*
SECircuitManager
::
Unload
(
const
SECircuitManager
&
src
)
{
cdm
::
CircuitManagerData
*
dst
=
new
cdm
::
CircuitManagerData
();
SECircuitManager
::
Serialize
(
src
,
*
dst
);
return
dst
;
}
void
SECircuitManager
::
Serialize
(
const
SECircuitManager
&
src
,
cdm
::
CircuitManagerData
&
dst
)
{
for
(
auto
itr
:
src
.
m_ElectricalLedger
.
nodes
)
dst
.
mutable_electricalnode
()
->
AddAllocated
(
SEElectricalCircuitNode
::
Unload
(
*
itr
.
second
));
for
(
auto
itr
:
src
.
m_ElectricalLedger
.
paths
)
dst
.
mutable_electricalpath
()
->
AddAllocated
(
SEElectricalCircuitPath
::
Unload
(
*
itr
.
second
));
for
(
auto
itr
:
src
.
m_ElectricalLedger
.
circuits
)
dst
.
mutable_electricalcircuit
()
->
AddAllocated
(
SEElectricalCircuit
::
Unload
(
*
itr
.
second
));
for
(
auto
itr
:
src
.
m_FluidLedger
.
nodes
)
dst
.
mutable_fluidnode
()
->
AddAllocated
(
SEFluidCircuitNode
::
Unload
(
*
itr
.
second
));
for
(
auto
itr
:
src
.
m_FluidLedger
.
paths
)
dst
.
mutable_fluidpath
()
->
AddAllocated
(
SEFluidCircuitPath
::
Unload
(
*
itr
.
second
));
for
(
auto
itr
:
src
.
m_FluidLedger
.
circuits
)
dst
.
mutable_fluidcircuit
()
->
AddAllocated
(
SEFluidCircuit
::
Unload
(
*
itr
.
second
));
for
(
auto
itr
:
src
.
m_ThermalLedger
.
nodes
)
dst
.
mutable_thermalnode
()
->
AddAllocated
(
SEThermalCircuitNode
::
Unload
(
*
itr
.
second
));
for
(
auto
itr
:
src
.
m_ThermalLedger
.
paths
)
dst
.
mutable_thermalpath
()
->
AddAllocated
(
SEThermalCircuitPath
::
Unload
(
*
itr
.
second
));
for
(
auto
itr
:
src
.
m_ThermalLedger
.
circuits
)
dst
.
mutable_thermalcircuit
()
->
AddAllocated
(
SEThermalCircuit
::
Unload
(
*
itr
.
second
));
}
void
SECircuitManager
::
SetReadOnly
(
bool
b
)
{
...
...
cdm/cpp/circuit/SECircuitManager.h
View file @
2e6c4df0
...
...
@@ -11,8 +11,6 @@ class SEThermalCircuitPath;
class
SEElectricalCircuit
;
class
SEElectricalCircuitNode
;
class
SEElectricalCircuitPath
;
CDM_BIND_DECL
(
CircuitManagerData
)
#define CIRCUIT_LEDGER_TEMPLATE typename NodeType, typename PathType, typename CircuitType
#define CIRCUIT_LEDGER_TYPES NodeType,PathType,CircuitType
...
...
@@ -20,6 +18,7 @@ CDM_BIND_DECL(CircuitManagerData)
template
<
CIRCUIT_LEDGER_TEMPLATE
>
class
SECircuitLedger
{
friend
class
PBCircuit
;
//friend the serialization class
friend
class
SECircuitManager
;
protected:
SECircuitLedger
()
{};
...
...
@@ -37,6 +36,7 @@ public:
class
CDM_DECL
SECircuitManager
:
public
Loggable
{
friend
class
PBCircuit
;
//friend the serialization class
public:
SECircuitManager
(
Logger
*
logger
);
virtual
~
SECircuitManager
();
...
...
@@ -44,16 +44,7 @@ public:
virtual
void
Clear
();
//clear memory
virtual
void
StateChange
()
{
};
bool
LoadFile
(
const
std
::
string
&
filename
);
void
SaveFile
(
const
std
::
string
&
filename
);
static
void
Load
(
const
cdm
::
CircuitManagerData
&
src
,
SECircuitManager
&
dst
);
static
cdm
::
CircuitManagerData
*
Unload
(
const
SECircuitManager
&
src
);
protected:
static
void
Serialize
(
const
cdm
::
CircuitManagerData
&
src
,
SECircuitManager
&
dst
);
static
void
Serialize
(
const
SECircuitManager
&
src
,
cdm
::
CircuitManagerData
&
dst
);
public:
void
SetReadOnly
(
bool
b
);
protected:
...
...
cdm/cpp/circuit/SECircuitNode.h
View file @
2e6c4df0
...
...
@@ -2,14 +2,10 @@
See accompanying NOTICE file for details.*/
#pragma once
CDM_BIND_DECL
(
CircuitNodeData
)
#include
"properties/SEScalarElectricCharge.h"
#include
"properties/SEScalarElectricPotential.h"
#include
"properties/SEScalarPressure.h"
#include
"properties/SEScalarVolume.h"
#include
"properties/SEScalarTemperature.h"
#include
"properties/SEScalarEnergy.h"
...
...
@@ -22,7 +18,8 @@ CDM_BIND_DECL(CircuitNodeData)
template
<
CIRCUIT_NODE_TEMPLATE
>
class
SECircuitNode
:
public
Loggable
{
template
<
typename
CircuitBindType
,
typename
NodeType
,
typename
CircuitNodeBindType
,
typename
PathType
,
typename
CircuitPathBindType
>
friend
class
SECircuit
;
friend
class
PBCircuit
;
//friend the serialization class
template
<
typename
NodeType
,
typename
PathType
>
friend
class
SECircuit
;
protected:
SECircuitNode
(
const
std
::
string
&
name
,
Logger
*
logger
);
public:
...
...
@@ -30,11 +27,6 @@ public:
virtual
void
Clear
();
//clear memory
protected:
static
void
Serialize
(
const
cdm
::
CircuitNodeData
&
src
,
SECircuitNode
&
dst
);
static
void
Serialize
(
const
SECircuitNode
&
src
,
cdm
::
CircuitNodeData
&
dst
);
public:
virtual
std
::
string
GetName
()
const
;
virtual
bool
HasPotential
()
const
;
...
...
cdm/cpp/circuit/SECircuitNode.inl
View file @
2e6c4df0
...
...
@@ -2,7 +2,6 @@
See accompanying NOTICE file for details.*/
#include "circuit/SECircuitNode.h"
#include "bind/cdm/Circuit.pb.h"
template<CIRCUIT_NODE_TEMPLATE>
SECircuitNode<CIRCUIT_NODE_TYPES>::SECircuitNode(const std::string& name, Logger* logger) : Loggable(logger), m_Name(name)
...
...
@@ -30,21 +29,6 @@ void SECircuitNode<CIRCUIT_NODE_TYPES>::Clear()
SAFE_DELETE(m_QuantityBaseline);
}
template<CIRCUIT_NODE_TEMPLATE>
void SECircuitNode<CIRCUIT_NODE_TYPES>::Serialize(const cdm::CircuitNodeData& src, SECircuitNode<CIRCUIT_NODE_TYPES>& dst)
{