Quickstart

CoSApp Overview

CoSApp is a multidisciplinary oriented tool for the simulation of systems. Its goal is to provide a user-friendly and efficient environnement to build, exchange and solve physical models.

Get started

Import core python package

[1]:
# import cosapp base classes
from cosapp.base import System, Port

Create a simple system

  • from scratch (for more information, see tutorials)

[2]:
class XPort(Port):
    def setup(self):
        self.add_variable('x', 1.0)

class Multiply(System):

    def setup(self):
        """Defines system structure"""
        self.add_inward('K1', 5.0)      # define a new data variable
        self.add_input(XPort, 'p_in')   # define a new input port
        self.add_output(XPort, 'p_out') # define a new output port

    def compute(self):
        """Defines what the system does"""
        self.p_out.x = self.p_in.x * self.K1

s1 = Multiply('mult') # instanciate the class, it *creates* a new object with those properties
quickstart system
  • reuse an existing System from a library (here the default cosapp unit test library)

[3]:
from cosapp.tests.library.systems import Multiply1
s2 = Multiply1('mult')

Run it!

  • change inputs or data if necessary

[4]:
s1.p_in.x = 10.
s2.p_in.x = 15.
  • make a simple run of your model

[5]:
s1.run_once()
s2.run_once()
  • have a look at your inputs, inwards and outputs

[6]:
print(s1.p_in, s2.p_in)
print(s1.inwards, s2.inwards)
print(s1.p_out, s2.p_out)
XPort: {'x': 10.0} XPort: {'x': 15.0}
ExtensiblePort: {'K1': 5.0} ExtensiblePort: {'K1': 5.0}
XPort: {'x': 50.0} XPort: {'x': 75.0}

Congrats! You’ve run your first CoSApp model!

Let’s continue

Because CoSApp is much more, have a look at the tutorials