Exemple #1
0
    def add_fields(self):
        Field.start_recording()

        params = self.params.copy_recursive()
        if not self.params.debug:
            params["save"] = False
            params["plot"] = False
        params.pop("debug")
        params.pop("use_timeaverage")
        params.pop("finalize")
        T0, T1 = self.params.start_time, self.params.end_time
        assert T0 != Field.default_params().start_time
        assert T1 != Field.default_params().end_time

        u = "Velocity"
        if self.params.use_timeaverage:
            u = TimeAverage(u, params=params).name

        class VD(Field):
            def __init__(self, valuename, nu, subdomain, *args, **kwargs):
                Field.__init__(self, *args, **kwargs)
                self.valuename = valuename
                mf = subdomain[0]
                idx = subdomain[1]
                self.dx = dx(idx, domain=mf.mesh(), subdomain_data=mf)
                self.vol = assemble(Constant(1) * self.dx)

                self.nu = nu

            def compute(self, get):
                u = get(self.valuename)
                if u == None:
                    return None

                return 1.0 / self.vol * assemble(
                    2 * self.nu * inner(epsilon(u), epsilon(u)) * self.dx)

        fa = VD(u, 1.0, self.aneurysm, params=params, label="aneurysm")
        fnv = VD(u, 1.0, self.near_vessel, params=params, label="nv")

        f = fa / fnv

        if not self.params.use_timeaverage:
            f = TimeAverage(f, params=params)

        self.valuename = f.name

        recorded_fields = Field.stop_recording()
        return recorded_fields
Exemple #2
0
    def add_fields(self):
        Field.start_recording()

        params = self.params.copy_recursive()
        if not self.params.debug:
            params["save"] = False
            params["plot"] = False
        params.pop("debug")
        params.pop("use_timeaverage")
        params.pop("finalize")
        T0, T1 = self.params.start_time, self.params.end_time
        assert T0 != Field.default_params().start_time
        assert T1 != Field.default_params().end_time

        u = "Velocity"
        if self.params.use_timeaverage:
            u = TimeAverage(u, params=params).name

        class VD(Field):
            def __init__(self, valuename, nu, subdomain,*args, **kwargs):
                Field.__init__(self, *args, **kwargs)
                self.valuename = valuename
                mf = subdomain[0]
                idx = subdomain[1]
                self.dx = dx(idx, domain=mf.mesh(), subdomain_data=mf)
                self.vol = assemble(Constant(1)*self.dx)

                self.nu = nu

            def compute(self, get):
                u = get(self.valuename)
                if u == None:
                    return None

                return 1.0/self.vol*assemble(2*self.nu*inner(epsilon(u), epsilon(u))*self.dx)

        fa = VD(u, 1.0, self.aneurysm, params=params, label="aneurysm")
        fnv = VD(u, 1.0, self.near_vessel, params=params, label="nv")
        
        f = fa/fnv

        if not self.params.use_timeaverage:
            f = TimeAverage(f, params=params)

        self.valuename = f.name

        recorded_fields = Field.stop_recording()
        return recorded_fields
Exemple #3
0
    def add_fields(self):
        Field.start_recording()

        params = self.params.copy_recursive()
        if not self.params.debug:
            params["save"] = False
            params["plot"] = False
        params.pop("debug")
        params.pop("use_timeaverage")
        params.pop("finalize")
        T0, T1 = self.params.start_time, self.params.end_time
        assert T0 != Field.default_params().start_time
        assert T1 != Field.default_params().end_time

        tau = Magnitude("WSS")
        if self.params.use_timeaverage:
            tau = TimeAverage(tau, params=params)

        threshold = DomainAvg(tau, cell_domains=self.near_vessel[0], indicator=self.near_vessel[1], label="nv") + \
                    DomainSD(tau, cell_domains=self.aneurysm[0], indicator=self.aneurysm[1], label="aneurysm")
        threshold.name = "threshold_sci_nv"
        mask = Threshold(tau, threshold, dict(threshold_by="above"))

        mf = self.aneurysm[0]
        idx = self.aneurysm[1]

        Aa = ConstantField(assemble(Constant(1)*dx(idx, domain=mf.mesh(), subdomain_data=mf)))
        Aa.name = "AneurysmArea"
        Fh = Aa*DomainAvg(tau*mask, cell_domains=mf, indicator=idx, params=params)
        Fh.name = "HighShear"
        Ah = Aa*DomainAvg(mask, cell_domains=mf, indicator=idx, params=params)+ConstantField(1e-12)
        Ah.name = "HighShearArea"
        Fa = Aa*DomainAvg(tau, cell_domains=mf, indicator=idx, params=params)
        Fa.name = "TotalShear"

        f = (Fh/Fa)/(Ah/Aa)

        if not self.params.use_timeaverage:
            f = TimeAverage(f, params=params)

        self.valuename = f.name

        fields = Field.stop_recording()
        return fields
Exemple #4
0
    def add_fields(self):
        Field.start_recording()

        params = self.params.copy_recursive()
        if not self.params.debug:
            params["save"] = False
            params["plot"] = False
        params.pop("debug")
        params.pop("use_timeaverage")
        params.pop("finalize")
        params.pop("method")

        T0, T1 = self.params.start_time, self.params.end_time
        assert T0 != Field.default_params().start_time
        assert T1 != Field.default_params().end_time

        tau = Magnitude("WSS", params=params)
        if self.params.use_timeaverage:
            tau = TimeAverage(tau, params=params, label="%2g-%2g" %(T0,T1))


        if self.params.method == "Xiang":
            threshold = 0.1*DomainAvg(tau, cell_domains=self.parent_artery[0], indicator=self.parent_artery[1])
        elif self.params.method == "Cebral":
            threshold = DomainAvg(tau, cell_domains=self.parent_artery[0], indicator=self.parent_artery[1]) - \
                        DomainSD(tau, cell_domains=self.aneurysm_domain[0], indicator=self.aneurysm_domain[1])
        else:
            raise RuntimeError("Unknown method: "+str(self.params.method))

        f = DomainAvg(Threshold(tau, threshold, params=params.copy_recursive().update(threshold_by="below")),
                                cell_domains=self.aneurysm_domain[0], indicator=self.aneurysm_domain[1], params=params)

        if not self.params.use_timeaverage:
            f = TimeAverage(f, params=params, label="%2g-%2g" %(T0,T1))

        self.valuename = f.name

        fields = Field.stop_recording()
        return fields
Exemple #5
0
    def add_fields(self):
        Field.start_recording()
        params = self.params.copy()
        if not self.params.debug:
            params["save"] = False
            params["plot"] = False
        params.pop("debug")
        params.pop("use_timeaverage")
        params.pop("finalize")

        T0, T1 = self.params.start_time, self.params.end_time
        assert T0 != Field.default_params().start_time
        assert T1 != Field.default_params().end_time

        fields = []
        dep_fields = []
        if self.params.use_timeaverage:
            f = TimeAverage("Velocity",
                            params=params,
                            label="%2g-%2g" % (T0, T1))
            velocity = f.name
            fields.append(f)

            f = TimeAverage("Pressure",
                            params=params,
                            label="%2g-%2g" % (T0, T1))
            pressure = f.name
            fields.append(f)
        else:
            velocity = "Velocity"
            pressure = "Pressure"

        upstream_fields = []
        dynamic_upstream = []
        for i, plane in enumerate(self.upstream_planes):
            fu = DomainAvg(Magnitude(SubFunction(velocity,
                                                 plane,
                                                 params=params,
                                                 label="PLC_upstream_" +
                                                 str(i)),
                                     params=params),
                           params=params)
            fp = DomainAvg(SubFunction(pressure,
                                       plane,
                                       params=params,
                                       label="PLC_upstream_" + str(i)),
                           params=params)

            f = 0.5 * self.rho * fu * fu
            f.params.update(params)

            f.name = "PLC_DynamicUpstream_%d" % i
            dynamic_upstream.append(f)

            f += fp
            f.params.update(params)
            f.name = "PLC_Upstream_%d" % i

            upstream_fields.append(f)

        downstream_fields = []
        for i, plane in enumerate(self.downstream_planes):
            fu = DomainAvg(Magnitude(SubFunction(velocity,
                                                 plane,
                                                 params=params,
                                                 label="PLC_downstream_" +
                                                 str(i)),
                                     params=params),
                           params=params)
            fp = DomainAvg(SubFunction(pressure,
                                       plane,
                                       params=params,
                                       label="PLC_downstream_" + str(i)),
                           params=params)

            f = 0.5 * self.rho * fu * fu + fp
            f.params.update(params)
            f.name = "PLC_Downstream%d" % i
            downstream_fields.append(f)

        fu = sum(upstream_fields)
        fu *= 1. / len(upstream_fields)
        fu.params.update(params)
        fu.name = "PLC_Upstream_Avg"

        fd = sum(downstream_fields)
        fd *= 1. / len(downstream_fields)
        fd.params.update(params)
        fd.name = "PLC_Downstream_Avg"

        fdu = sum(dynamic_upstream)
        fdu *= 1. / len(dynamic_upstream)
        fdu.params.update(params)
        fdu.name = "PLC_DynamicUpstream_Avg"
        f = (fu - fd) / fdu
        f.params.update(params)

        if not self.params.use_timeaverage:
            f = TimeAverage(f, params=params)
        self.valuename = f.name

        recorded_fields = Field.stop_recording()

        return recorded_fields
Exemple #6
0
    def add_fields(self):
        Field.start_recording()
        params = self.params.copy()
        if not self.params.debug:
            params["save"] = False
            params["plot"] = False
        params.pop("debug")
        params.pop("use_timeaverage")
        params.pop("finalize")
            
        T0, T1 = self.params.start_time, self.params.end_time
        assert T0 != Field.default_params().start_time
        assert T1 != Field.default_params().end_time

        fields = []
        dep_fields = []
        if self.params.use_timeaverage:
            f = TimeAverage("Velocity", params=params, label="%2g-%2g" %(T0,T1))
            velocity = f.name
            fields.append(f)
            
            f = TimeAverage("Pressure", params=params, label="%2g-%2g" %(T0,T1))
            pressure = f.name
            fields.append(f)
        else:
            velocity = "Velocity"
            pressure = "Pressure"

        upstream_fields = []
        dynamic_upstream = []
        for i, plane in enumerate(self.upstream_planes):
            fu = DomainAvg(Magnitude(SubFunction(velocity, plane, params=params, label="PLC_upstream_"+str(i)), params=params), params=params)
            fp = DomainAvg(SubFunction(pressure, plane, params=params, label="PLC_upstream_"+str(i)), params=params)

            f = 0.5*self.rho*fu*fu
            f.params.update(params)

            f.name = "PLC_DynamicUpstream_%d" %i
            dynamic_upstream.append(f)

            f += fp
            f.params.update(params)
            f.name = "PLC_Upstream_%d" %i

            upstream_fields.append(f)

        downstream_fields = []
        for i, plane in enumerate(self.downstream_planes):
            fu = DomainAvg(Magnitude(SubFunction(velocity, plane, params=params, label="PLC_downstream_"+str(i)), params=params), params=params)
            fp = DomainAvg(SubFunction(pressure, plane, params=params, label="PLC_downstream_"+str(i)), params=params)

            f = 0.5*self.rho*fu*fu+fp
            f.params.update(params)
            f.name = "PLC_Downstream%d" %i
            downstream_fields.append(f)

        fu = sum(upstream_fields)
        fu *= 1./len(upstream_fields)
        fu.params.update(params)
        fu.name = "PLC_Upstream_Avg"
        
        fd = sum(downstream_fields)
        fd *= 1./len(downstream_fields)
        fd.params.update(params)
        fd.name = "PLC_Downstream_Avg"
        
        fdu = sum(dynamic_upstream)
        fdu *= 1./len(dynamic_upstream)
        fdu.params.update(params)
        fdu.name = "PLC_DynamicUpstream_Avg"
        f = (fu-fd)/fdu
        f.params.update(params)
        
        if not self.params.use_timeaverage:
            f = TimeAverage(f, params=params)
        self.valuename = f.name

        recorded_fields = Field.stop_recording()

        return recorded_fields
Exemple #7
0
    def add_fields(self):
        Field.start_recording()

        params = self.params.copy_recursive()
        if not self.params.debug:
            params["save"] = False
            params["plot"] = False
        params.pop("debug")
        params.pop("use_timeaverage")
        params.pop("finalize")
        T0, T1 = self.params.start_time, self.params.end_time
        assert T0 != Field.default_params().start_time
        assert T1 != Field.default_params().end_time
        if self.params.use_timeaverage:
            u = TimeAverage("Velocity", params=params)
            velocity = u.name
        else:
            velocity = "Velocity"

        uneck = SubFunction(velocity, self.neck, params=params, label="neck")

        A = assemble(Constant(1) * dx(domain=self.neck))
        Qin = Dot(ConstantField(self.necknormal), uneck, params=params)

        t = Threshold(Qin, ConstantField(0), dict(threshold_by="above"))
        t.params.update(params)
        t.name = "threshold_neck"

        Ain = A * DomainAvg(t)
        Ain.name = "Ain"
        Ain.params.update(params)
        Qin = A * DomainAvg(Dot(Qin, t, params=params))
        Qin.name = "Qin"
        Qin.params.update(params)

        Qpa = 0
        for i, (plane, n) in enumerate(self.pa_planes):
            upa = SubFunction(velocity,
                              plane,
                              params=params,
                              label="pa_%d" % i)

            Ai = assemble(Constant(1) * dx(domain=plane))
            Q = Ai * DomainAvg(Dot(ConstantField(n), upa, params=params))
            Q.name = "Qpa%d" % i
            Q.params.update(params)
            Qpa += Magnitude(Q)
            Qpa.params.update(params)
        Qpa.name = "Sum_Qpa"
        f = (Qin / Qpa) / (Ain / A)

        if not self.params.use_timeaverage:
            f = TimeAverage(f.name, params=params)

        self.valuename = f.name

        self.Qin = Qin.name
        self.Qpa = Qpa.name
        self.Ain = Ain.name
        self.A = A

        fields = Field.stop_recording()

        return fields
Exemple #8
0
    def add_fields(self):
        Field.start_recording()

        params = self.params.copy_recursive()
        if not self.params.debug:
            params["save"] = False
            params["plot"] = False
        params.pop("debug")
        params.pop("use_timeaverage")
        params.pop("finalize")
        T0, T1 = self.params.start_time, self.params.end_time
        assert T0 != Field.default_params().start_time
        assert T1 != Field.default_params().end_time
        if self.params.use_timeaverage:
            u = TimeAverage("Velocity", params=params)
            velocity = u.name
        else:
            velocity = "Velocity"
        

        uneck = SubFunction(velocity, self.neck, params=params, label="neck")

        A = assemble(Constant(1)*dx(domain=self.neck))
        Qin = Dot(ConstantField(self.necknormal), uneck, params=params)

        t = Threshold(Qin, ConstantField(0), dict(threshold_by="above"))
        t.params.update(params)
        t.name = "threshold_neck"

        Ain = A*DomainAvg(t)
        Ain.name = "Ain"
        Ain.params.update(params)
        Qin = A*DomainAvg(Dot(Qin,t, params=params))
        Qin.name = "Qin"
        Qin.params.update(params)
        
        Qpa = 0
        for i, (plane, n) in enumerate(self.pa_planes):
            upa = SubFunction(velocity, plane, params=params, label="pa_%d" %i)
            
            Ai = assemble(Constant(1)*dx(domain=plane))
            Q = Ai*DomainAvg(Dot(ConstantField(n), upa, params=params))
            Q.name = "Qpa%d" %i
            Q.params.update(params)
            Qpa += Magnitude(Q)
            Qpa.params.update(params)
        Qpa.name = "Sum_Qpa"
        f = (Qin/Qpa)/(Ain/A)

        if not self.params.use_timeaverage:
            f = TimeAverage(f.name, params=params)
        
        self.valuename = f.name
        
        self.Qin = Qin.name
        self.Qpa = Qpa.name
        self.Ain = Ain.name
        self.A = A
        

        fields = Field.stop_recording()

        return fields