Exemple #1
0
    def function(self, m):
        from pyadjoint.reduced_functional_numpy import set_local
        set_local(self.rhovec, m)  # Set rhovec to the control, rho
        integralNotFrozen = self.smassNotFrozen.inner(self.volfrac -
                                                      self.rhovec.vector())
        integralFrozen = self.smassFrozen.inner(self.volfrac -
                                                self.rhovecFrozen.vector())

        return integralNotFrozen + integralFrozen
Exemple #2
0
        def jacobian(self, m):
            from pyadjoint.reduced_functional_numpy import set_local
            set_local(self.tmpvec, m)

            with stop_annotating():
                gradients = self.Phat.derivative()
                with gradients.dat.vec as v:
                    v.scale(-1.0 / self.Pdrop)
            return [gradients]
Exemple #3
0
        def function(self, m):
            from pyadjoint.reduced_functional_numpy import set_local
            set_local(self.tmpvec, m)

            # Compute the integral of the control over the domain

            integral = self.smass.inner(self.tmpvec.vector())
            if MPI.rank(MPI.comm_world) == 0:
                print("Current control integral: ", integral)
            return [self.V - integral]
Exemple #4
0
        def function(self, m):
            from pyadjoint.reduced_functional_numpy import set_local
            set_local(self.tmpvec, m)

            # Compute the integral of the control over the domain
            integral = self.Pcontrol.tape_value()
            print(
                "Pressure drop: {0:.6f}, Pressure constraint: {1:.4f}".format(
                    integral, self.Pdrop),
                flush=True)
            with stop_annotating():
                value = -integral / self.Pdrop + 1.0
            return [value]
Exemple #5
0
        def function(self, m):
            from pyadjoint.reduced_functional_numpy import set_local
            len_m = int(len(m) / 2)
            set_local(self.tmpvec_eta1, m[0:len_m])
            set_local(self.tmpvec_eta2, m[len_m:])
            # Compute the integral of the control over the domain
            integral_f1 = self.compute_integral_f1(self.tmpvec_eta1, self.tmpvec_eta2)
            integral_f2 = self.compute_integral_f2(self.tmpvec_eta1, self.tmpvec_eta2)
            if MPI.rank(MPI.comm_world) == 0:
                print("***** Current control integral_f1: ", integral_f1)
                print("***** Current constraint g_f1: ", str(self.phi_f1 - integral_f1))
                print("***** Current control integral_f2: ", integral_f2)
                print("***** Current constraint g_f2: ", str(self.phi_f2 - integral_f2))

            return [(self.phi_f1 - integral_f1), (self.phi_f2 - integral_f2)]
Exemple #6
0
        def jacobian(self, m):
            len_m = len(m)

            from pyadjoint.reduced_functional_numpy import set_local
            set_local(self.tmpvec_eta1, m[0:len_m])
            set_local(self.tmpvec_eta2, m[len_m:])

            jacobian_eta1_f1 = assemble(TestFunction(meshes.A) * (self.tmpvec_eta2 - Constant(1)) * dx)
            jacobian_eta2_f1 = assemble(TestFunction(meshes.A) * self.tmpvec_eta1 * dx)
            jacobian_f1 = np.concatenate([jacobian_eta1_f1.get_local(), jacobian_eta2_f1.get_local()])

            jacobian_eta1_f2 = assemble( - TestFunction(meshes.A) * self.tmpvec_eta2 * dx)
            jacobian_eta2_f2 = assemble( - TestFunction(meshes.A) * self.tmpvec_eta1 * dx)
            jacobian_f2 = np.concatenate([jacobian_eta1_f2.get_local(), jacobian_eta2_f2.get_local()])

            return [jacobian_f1, jacobian_f2]