Пример #1
0
    def __setattr__(self, attributeName, value):

        super(CableModel, self).__setattr__(attributeName, value)

        if (attributeName == "coeff_dx2" or attributeName == "coeff_v"):
            try:
                getattr(self, "coeff_dx2")
                getattr(self, "coeff_font")

                if self.coeff_dx2 is not None and self.initialCondition is not None:
                    if self.coeff_font is None:
                        self.coeff_font = 1

                    self.currentM = self.initialM * ones(
                        len(self.initialCondition))
                    self.currentN = self.initialN * ones(
                        len(self.initialCondition))
                    self.currentH = self.initialH * ones(
                        len(self.initialCondition))

                    self.coeffs = {
                        Components().Diffusion:
                        self.coeff_dx2,
                        Components().Reaction:
                        self.coeffReaction(),
                        Components().Font:
                        self.coeffFont(m=self.currentM,
                                       n=self.currentN,
                                       h=self.currentH)
                    }

            except AttributeError:
                e = sys.exc_info()
                print(e)
                raise Exception(e)
Пример #2
0
    def solve(self, **arguments):

        t_start = time.clock()

        # definig Function space on this mesh using Lagrange
        #polynoimals of degree 1.
        H = FunctionSpace(self.mesh, "CG", 1)

        # Setting up the variational problem
        v = TrialFunction(H)
        w = TestFunction(H)

        epsilon = Constant(arguments[Components().Diffusion])
        f = Expression("(1 - epsilon*4*pow(pi,2))*cos(2*pi*x[0])",\
                       epsilon=epsilon, degree=1)

        a = (epsilon * inner(grad(v), grad(w)) + inner(v, w)) * dx
        L = f * w * dx

        # solving the variational problem.
        v = Function(H)
        solve(a == L, v)

        self.solution.extend(v.vector().array())

        return [self.solution, time.clock() - t_start]
Пример #3
0
    def solve(self, **arguments):

        t_start = time.clock()

        # definig Function space on this mesh using Lagrange
        #polynoimals of degree 1.
        H = FunctionSpace(self.mesh, "CG", 1)

        # Setting up the variational problem
        v = TrialFunction(H)
        w = TestFunction(H)

        epsilon = Constant(arguments[Components().Diffusion])
        f = Constant(0)

        a = (epsilon * inner(grad(v), grad(w)) + inner(v, w)) * dx
        #Still have to figure it how to use a Neumann Condition here
        L = f * w * dx

        # solving the variational problem.
        v = Function(H)
        solve(a == L, v)

        self.solution.extend(v.vector().array())

        return [self.solution, time.clock() - t_start]
Пример #4
0
    def __setattr__(self, attributeName, value):

        super(CableModel, self).__setattr__(attributeName, value)

        if (attributeName == "coeff_dx2" or attributeName == "coeff_v"):
            try:
                getattr(self, "coeff_dx2")
                getattr(self, "coeff_v")
                getattr(self, "coeff_font")

                if not self.coeff_dx2 and not self.coeff_v:
                    if self.coeff_font is None:
                        self.coeff_font = 1

                    self.coeffs = {
                        Components().Diffusion: self.coeff_dx2,
                        Components().Reaction: self.coeff_v,
                        Components().Font: self.coeff_font
                    }

            except AttributeError:
                e = sys.exc_info()
                print(e)
                raise Exception(e)
Пример #5
0
    def createEquations(self):

        diffusionCoeff = self.coeffs[Components().Diffusion]
        reactionCoeff = self.coeffs[Components().Reaction]
        fontCoeff = self.coeffs[Components().Font]

        if self.timeApproximation is not None:
            diffusionCoeff = self.timeApproximation.modifyCoeff(
                Components().Diffusion, diffusionCoeff)
            reactionCoeff = self.timeApproximation.modifyCoeff(
                Components().Reaction, reactionCoeff)
            fontCoeff = self.timeApproximation.modifyCoeff(
                Components().Font, fontCoeff)

        leftEquation = self.iApproximation.create_composed(name="Left Side")

        leftEquation.addEquation(self.iApproximation.\
                      create_diffusion(diffusionCoeff))

        discreteComponent = self.iApproximation.create_discrete(self.iApproximation.\
                      create_reaction(reactionCoeff))

        discreteComponent.discreteElements

        leftEquation.addEquation(self.iApproximation.\
                      create_reaction(reactionCoeff))

        #print("Left Start")
        rightEquation = self.iApproximation.create_composed(name="Right Side")

        rightEquation.addEquation(self.iApproximation.\
                      create_font(fontCoeff))

        if self.timeApproximation is not None:
            rightEquation.addEquation(self.iApproximation.\
                          create_previous(self.timeApproximation.coeffT))

        #print("Right Start")

        self.equation[Sides().Left] = leftEquation
        self.equation[Sides().Right] = rightEquation
Пример #6
0
    def __call__(self, **arguments):

        if Components().Discrete in arguments.keys():
            self.discreteElements = arguments[Components().Discrete]

        return super(Discrete, self).__call__(**arguments)